From 8e64a5d9ff4e50967dbeb4323256e104aec4c691 Mon Sep 17 00:00:00 2001 From: faketruth Date: Wed, 26 Oct 2011 13:27:16 +0000 Subject: Updated VS2010 project files Made monster spawning code in cWorld.cpp a bit more compact and readable srand() is only supposed to be called once in the whole program, and it's already called in the constructor of cWorld so it doesn't have to be in cWorld::Tick() git-svn-id: http://mc-server.googlecode.com/svn/trunk@14 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- VC2010/MCServer.vcxproj | 28 ++++++++ VC2010/MCServer.vcxproj.filters | 138 +++++++++++++++++++++++++++++++++++-- source/cWorld.cpp | 147 ++++++++++++---------------------------- 3 files changed, 203 insertions(+), 110 deletions(-) diff --git a/VC2010/MCServer.vcxproj b/VC2010/MCServer.vcxproj index 1437d8e18..e4b042c56 100644 --- a/VC2010/MCServer.vcxproj +++ b/VC2010/MCServer.vcxproj @@ -223,17 +223,22 @@ + + + + + @@ -244,16 +249,22 @@ + + + + + + @@ -263,6 +274,9 @@ + + + @@ -333,15 +347,20 @@ + + + + + @@ -353,17 +372,23 @@ + + + + + + @@ -378,6 +403,9 @@ + + + diff --git a/VC2010/MCServer.vcxproj.filters b/VC2010/MCServer.vcxproj.filters index 98f9fcd0d..62e144e32 100644 --- a/VC2010/MCServer.vcxproj.filters +++ b/VC2010/MCServer.vcxproj.filters @@ -322,6 +322,48 @@ {b5725a7d-f912-47c7-b6f0-8efca7c0279c} + + {e40e3231-e432-48fc-9958-d00f7486ee73} + + + {b07e3ca3-b50d-4c47-8ba3-c2678c0af71a} + + + {610c2aba-740a-49cc-ad03-a0613190daf8} + + + {00cab5c0-0d12-418c-b1a4-20c71db757a8} + + + {0bc1c838-402d-4f7e-81a3-81d184590879} + + + {bfc926d1-ba9c-48ef-82c8-2e9b41b7119a} + + + {43e6c131-1a12-4f06-9d71-3cf96e35eae5} + + + {1d900af2-8976-4aae-9f6d-35c2debcc049} + + + {eb718e91-e244-477c-81a7-1648d7b08cde} + + + {420de544-79bb-4ccb-be49-eec9cf5e5a7e} + + + {ee4c0e9a-7754-4b15-a2c9-abf7f6476ce7} + + + {70bb6f00-107b-483f-9778-b315adbdc7c7} + + + {58339a4b-e78c-48db-b4d5-8bd94fb4a9bc} + + + {e4620b72-4739-4233-b326-47d4b5ca23d2} + @@ -427,9 +469,6 @@ cRoot - - cEntity\cPawn\cMonster - cEntity\cPawn @@ -643,6 +682,51 @@ Threading\cSocket + + cEntity\cPawn\cMonster\cCavespider + + + cEntity\cPawn\cMonster\cCow + + + cEntity\cPawn\cMonster\cCreeper + + + cEntity\cPawn\cMonster\cEnderman + + + cEntity\cPawn\cMonster\cGhast + + + cEntity\cPawn\cMonster + + + cEntity\cPawn\cMonster\cPig + + + cEntity\cPawn\cMonster\cSheep + + + cEntity\cPawn\cMonster\cSilverfish + + + cEntity\cPawn\cMonster\cSkeleton + + + cEntity\cPawn\cMonster\cSlime + + + cEntity\cPawn\cMonster\cSquid + + + cEntity\cPawn\cMonster\cWolf + + + cEntity\cPawn\cMonster\cZombie + + + cEntity\cPawn\cMonster\cZombiepigman + @@ -780,9 +864,6 @@ cRoot - - cEntity\cPawn\cMonster - cEntity\cPawn @@ -1002,6 +1083,51 @@ Packets\cPacket_Ping + + cEntity\cPawn\cMonster\cCavespider + + + cEntity\cPawn\cMonster\cCow + + + cEntity\cPawn\cMonster\cCreeper + + + cEntity\cPawn\cMonster\cEnderman + + + cEntity\cPawn\cMonster\cGhast + + + cEntity\cPawn\cMonster + + + cEntity\cPawn\cMonster\cPig + + + cEntity\cPawn\cMonster\cSheep + + + cEntity\cPawn\cMonster\cSilverfish + + + cEntity\cPawn\cMonster\cSkeleton + + + cEntity\cPawn\cMonster\cSlime + + + cEntity\cPawn\cMonster\cSquid + + + cEntity\cPawn\cMonster\cWolf + + + cEntity\cPawn\cMonster\cZombie + + + cEntity\cPawn\cMonster\cZombiepigman + diff --git a/source/cWorld.cpp b/source/cWorld.cpp index aa1c8ba22..54fd090dc 100644 --- a/source/cWorld.cpp +++ b/source/cWorld.cpp @@ -330,26 +330,9 @@ void cWorld::Tick(float a_Dt) m_SpawnMonsterTime = m_Time; if( m_pState->m_Players.size() > 0 ) { + cMonster *Monster = 0; - cChicken *Chicken; - cCow *Cow; - cPig *Pig; - cSheep *Sheep; - cSquid *Squid; - cWolf *Wolf; - - cSpider *Spider; - cZombie *Zombie; - cEnderman *Enderman; - cCreeper *Creeper; - cGhast *Ghast; - cCavespider *Cavespider; - cZombiepigman *Zombiepigman; - cSkeleton *Skeleton; - cSlime *Slime; - cSilverfish *Silverfish; - - srand ( time(NULL) ); //added mob code + //srand ( time(NULL) ); // Only seed random ONCE! Is already done in the cWorld constructor int dayRand = rand() % 6; //added mob code int nightRand = rand() % 10; //added mob code @@ -363,95 +346,51 @@ void cWorld::Tick(float a_Dt) SpawnPos += Vector3d( (double)(rand()%64)-32, (double)(rand()%64)-32, (double)(rand()%64)-32 ); char Height = GetHeight( (int)SpawnPos.x, (int)SpawnPos.z ); - //cMonster* Monster = new cChicken(); if(m_WorldTime >= 12000 + 1000) { - if (nightRand == 0) { //random percent to spawn for night - Spider = new cSpider(); - Spider->Initialize(); - Spider->TeleportTo( SpawnPos.x, (double)(Height)+2, SpawnPos.z ); - Spider->SpawnOn( 0 ); - } else if (nightRand == 1) { - Zombie = new cZombie(); - Zombie->Initialize(); - Zombie->TeleportTo( SpawnPos.x, (double)(Height)+2, SpawnPos.z ); - Zombie->SpawnOn( 0 ); - } else if (nightRand == 2) { - Enderman = new cEnderman(); - Enderman->Initialize(); - Enderman->TeleportTo( SpawnPos.x, (double)(Height)+2, SpawnPos.z ); - Enderman->SpawnOn( 0 ); - } else if (nightRand == 3) { - Creeper = new cCreeper(); - Creeper->Initialize(); - Creeper->TeleportTo( SpawnPos.x, (double)(Height)+2, SpawnPos.z ); - Creeper->SpawnOn( 0 ); - } else if (nightRand == 4) { - Cavespider = new cCavespider(); - Cavespider->Initialize(); - Cavespider->TeleportTo( SpawnPos.x, (double)(Height)+2, SpawnPos.z ); - Cavespider->SpawnOn( 0 ); - } else if (nightRand == 5) { - Ghast = new cGhast(); - Ghast->Initialize(); - Ghast->TeleportTo( SpawnPos.x, (double)(Height)+2, SpawnPos.z ); - Ghast->SpawnOn( 0 ); - } else if (nightRand == 6) { - Zombiepigman = new cZombiepigman(); - Zombiepigman->Initialize(); - Zombiepigman->TeleportTo( SpawnPos.x, (double)(Height)+2, SpawnPos.z ); - Zombiepigman->SpawnOn( 0 ); - } else if (nightRand == 7) { - Slime = new cSlime(); - Slime->Initialize(); - Slime->TeleportTo( SpawnPos.x, (double)(Height)+2, SpawnPos.z ); - Slime->SpawnOn( 0 ); - } else if (nightRand == 8) { - Silverfish = new cSilverfish(); - Silverfish->Initialize(); - Silverfish->TeleportTo( SpawnPos.x, (double)(Height)+2, SpawnPos.z ); - Silverfish->SpawnOn( 0 ); - } else if (nightRand == 9) { - Skeleton = new cSkeleton(); - Skeleton->Initialize(); - Skeleton->TeleportTo( SpawnPos.x, (double)(Height)+2, SpawnPos.z ); - Skeleton->SpawnOn( 0 ); - } //end random percent to spawn for night + if (nightRand == 0) //random percent to spawn for night + Monster = new cSpider(); + else if (nightRand == 1) + Monster = new cZombie(); + else if (nightRand == 2) + Monster = new cEnderman(); + else if (nightRand == 3) + Monster = new cCreeper(); + else if (nightRand == 4) + Monster = new cCavespider(); + else if (nightRand == 5) + Monster = new cGhast(); + else if (nightRand == 6) + Monster = new cZombiepigman(); + else if (nightRand == 7) + Monster = new cSlime(); + else if (nightRand == 8) + Monster = new cSilverfish(); + else if (nightRand == 9) + Monster = new cSkeleton(); + //end random percent to spawn for night } else { - if (dayRand == 0) { //random percent to spawn for day - Chicken = new cChicken(); - Chicken->Initialize(); - Chicken->TeleportTo( SpawnPos.x, (double)(Height)+2, SpawnPos.z ); - Chicken->SpawnOn( 0 ); - } else if (dayRand == 1) { - Cow = new cCow(); - Cow->Initialize(); - Cow->TeleportTo( SpawnPos.x, (double)(Height)+2, SpawnPos.z ); - Cow->SpawnOn( 0 ); - } else if (dayRand == 2) { - Pig = new cPig(); - Pig->Initialize(); - Pig->TeleportTo( SpawnPos.x, (double)(Height)+2, SpawnPos.z ); - Pig->SpawnOn( 0 ); - } else if (dayRand == 3) { - Sheep = new cSheep(); - Sheep->Initialize(); - Sheep->TeleportTo( SpawnPos.x, (double)(Height)+2, SpawnPos.z ); - Sheep->SpawnOn( 0 ); - } else if (dayRand == 4) { - Squid = new cSquid(); - Squid->Initialize(); - Squid->TeleportTo( SpawnPos.x, (double)(Height)+2, SpawnPos.z ); - Squid->SpawnOn( 0 ); - } else if (dayRand == 5) { - Wolf = new cWolf(); - Wolf->Initialize(); - Wolf->TeleportTo( SpawnPos.x, (double)(Height)+2, SpawnPos.z ); - Wolf->SpawnOn( 0 ); - } //end random percent to spawn for day + if (dayRand == 0) //random percent to spawn for day + Monster = new cChicken(); + else if (dayRand == 1) + Monster = new cCow(); + else if (dayRand == 2) + Monster = new cPig(); + else if (dayRand == 3) + Monster = new cSheep(); + else if (dayRand == 4) + Monster = new cSquid(); + else if (dayRand == 5) + Monster = new cWolf(); + //end random percent to spawn for day + } + + if( Monster ) + { + Monster->Initialize(); + Monster->TeleportTo( SpawnPos.x, (double)(Height)+2, SpawnPos.z ); + Monster->SpawnOn( 0 ); } - //Monster->TeleportTo( SpawnPos.x, (double)(Height)+2, SpawnPos.z ); - //Monster->SpawnOn( 0 ); } } } -- cgit v1.2.3