diff options
author | madmaxoft <github@xoft.cz> | 2013-10-20 13:33:23 +0200 |
---|---|---|
committer | madmaxoft <github@xoft.cz> | 2013-10-20 13:33:23 +0200 |
commit | d16d0a7ab75ca2b63de55a3e68ea58075c42277d (patch) | |
tree | cffe915f423afabb976bee8d3a06fc2b950512ad /source | |
parent | Moved all MobTypesManager functions to cMonster. (diff) | |
download | cuberite-d16d0a7ab75ca2b63de55a3e68ea58075c42277d.tar cuberite-d16d0a7ab75ca2b63de55a3e68ea58075c42277d.tar.gz cuberite-d16d0a7ab75ca2b63de55a3e68ea58075c42277d.tar.bz2 cuberite-d16d0a7ab75ca2b63de55a3e68ea58075c42277d.tar.lz cuberite-d16d0a7ab75ca2b63de55a3e68ea58075c42277d.tar.xz cuberite-d16d0a7ab75ca2b63de55a3e68ea58075c42277d.tar.zst cuberite-d16d0a7ab75ca2b63de55a3e68ea58075c42277d.zip |
Diffstat (limited to '')
-rw-r--r-- | source/MobSpawner.cpp | 76 | ||||
-rw-r--r-- | source/MobSpawner.h | 39 | ||||
-rw-r--r-- | source/World.cpp | 2 |
3 files changed, 55 insertions, 62 deletions
diff --git a/source/MobSpawner.cpp b/source/MobSpawner.cpp index 75232b30f..1b3796f70 100644 --- a/source/MobSpawner.cpp +++ b/source/MobSpawner.cpp @@ -4,46 +4,6 @@ #include "MobSpawner.h" #include "Mobs/IncludeAllMonsters.h" -cMobSpawner::tMobTypes& cMobSpawner::m_MobTypes() -{ - static tMobTypes* value = new tMobTypes(initMobTypesBeforeCx11()); - return *value; -} - -cMobSpawner::tMobTypes cMobSpawner::initMobTypesBeforeCx11() -{ - std::set<cMonster::eType> toReturn; - toReturn.insert(cMonster::mtCreeper); - toReturn.insert(cMonster::mtSkeleton); - toReturn.insert(cMonster::mtSpider); - toReturn.insert(cMonster::mtGiant); - toReturn.insert(cMonster::mtZombie); - toReturn.insert(cMonster::mtSlime); - toReturn.insert(cMonster::mtGhast); - toReturn.insert(cMonster::mtZombiePigman); - toReturn.insert(cMonster::mtEnderman); - toReturn.insert(cMonster::mtCaveSpider); - toReturn.insert(cMonster::mtSilverfish); - toReturn.insert(cMonster::mtBlaze); - toReturn.insert(cMonster::mtMagmaCube); - toReturn.insert(cMonster::mtEnderDragon); - toReturn.insert(cMonster::mtWither); - toReturn.insert(cMonster::mtBat); - toReturn.insert(cMonster::mtWitch); - toReturn.insert(cMonster::mtPig); - toReturn.insert(cMonster::mtSheep); - toReturn.insert(cMonster::mtCow); - toReturn.insert(cMonster::mtChicken); - toReturn.insert(cMonster::mtSquid); - toReturn.insert(cMonster::mtWolf); - toReturn.insert(cMonster::mtMooshroom); - toReturn.insert(cMonster::mtSnowGolem); - toReturn.insert(cMonster::mtOcelot); - toReturn.insert(cMonster::mtIronGolem); - toReturn.insert(cMonster::mtVillager); - return toReturn; -} - @@ -80,6 +40,10 @@ bool cMobSpawner::CheckPackCenter(BLOCKTYPE a_BlockType) } } + + + + void cMobSpawner::addIfAllowed(cMonster::eType toAdd, std::set<cMonster::eType>& toAddIn) { std::set<cMonster::eType>::iterator itr = m_AllowedTypes.find(toAdd); @@ -89,6 +53,10 @@ void cMobSpawner::addIfAllowed(cMonster::eType toAdd, std::set<cMonster::eType>& } } + + + + cMonster::eType cMobSpawner::ChooseMobType(EMCSBiome a_Biome) { std::set<cMonster::eType> allowedMobs; @@ -153,6 +121,9 @@ cMonster::eType cMobSpawner::ChooseMobType(EMCSBiome a_Biome) } + + + bool cMobSpawner::CanSpawnHere(cMonster::eType a_MobType, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, BLOCKTYPE a_BlockType_below, NIBBLETYPE a_BlockMeta_below, BLOCKTYPE a_BlockType_above, NIBBLETYPE a_BlockMeta_above, EMCSBiome a_Biome, int a_Level) { bool toReturn = false; @@ -230,6 +201,9 @@ bool cMobSpawner::CanSpawnHere(cMonster::eType a_MobType, BLOCKTYPE a_BlockType, } + + + cMonster* cMobSpawner::TryToSpawnHere(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, BLOCKTYPE a_BlockType_below, NIBBLETYPE a_BlockMeta_below, BLOCKTYPE a_BlockType_above, NIBBLETYPE a_BlockMeta_above, EMCSBiome a_Biome, int a_Level, int& a_MaxPackSize) { cMonster* toReturn = NULL; @@ -264,17 +238,33 @@ cMonster* cMobSpawner::TryToSpawnHere(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockM return toReturn; } + + + + void cMobSpawner::NewPack() { m_NewPack = true; } -cMobSpawner::tSpawnedContainer& cMobSpawner::getSpawned() + + + + +cMobSpawner::tSpawnedContainer & cMobSpawner::getSpawned(void) { return m_Spawned; } -bool cMobSpawner::CanSpawnSomething() + + + + +bool cMobSpawner::CanSpawnAnything(void) { - return m_AllowedTypes.size() > 0; + return !m_AllowedTypes.empty(); } + + + + diff --git a/source/MobSpawner.h b/source/MobSpawner.h index bb9e95172..ba2a18f2e 100644 --- a/source/MobSpawner.h +++ b/source/MobSpawner.h @@ -7,12 +7,20 @@ #include "FastRandom.h" #include "Mobs/Monster.h" //this is a side-effect of keeping Mobfamily inside Monster class. I'd prefer to keep both (Mobfamily and Monster) inside a "Monster" namespace MG TODO : do it + + + +// fwd: class cChunk; -// This class is used to determine wich monster can be spawned on wich place -// it is essentially static (f.i. Squids spawn in water, Zombie spawn in dark places) -// but it also has dynamic part depending on the world.ini + + + +/** This class is used to determine which monster can be spawned in which place +it is essentially static (eg. Squids spawn in water, Zombies spawn in dark places) +but it also has dynamic part depending on the world.ini settings. +*/ class cMobSpawner { public : @@ -21,26 +29,26 @@ public : // a_AllowedTypes is the set of types allowed for mobs it will spawn. Empty set // would result in no spawn at all // Allowed mobs thah are not of the right Family will not be include (no warning) - cMobSpawner(cMonster::eFamily MobFamily, const std::set<cMonster::eType>& a_AllowedTypes); + cMobSpawner(cMonster::eFamily MobFamily, const std::set<cMonster::eType> & a_AllowedTypes); - // Check if specified block can be a Pack center for this spawner + /// Check if specified block can be a Pack center for this spawner bool CheckPackCenter(BLOCKTYPE a_BlockType); // Try to create a monster here // if this is the first of a Pack : determine the type of monster - // BlockType & BlockMeta are use to know what kind of Mob can Spawn here + // BlockType & BlockMeta are used to decide what kind of Mob can Spawn here // MaxPackSize is set to the maximal size for a pack this type of mob - cMonster* TryToSpawnHere(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, BLOCKTYPE a_BlockType_below, NIBBLETYPE a_BlockMeta_below, BLOCKTYPE a_BlockType_above, NIBBLETYPE a_BlockMeta_above, EMCSBiome a_Biome, int a_Level, int& a_MaxPackSize); + cMonster * TryToSpawnHere(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, BLOCKTYPE a_BlockType_below, NIBBLETYPE a_BlockMeta_below, BLOCKTYPE a_BlockType_above, NIBBLETYPE a_BlockMeta_above, EMCSBiome a_Biome, int a_Level, int& a_MaxPackSize); // mark the beginning of a new Pack // all mobs of the same Pack are the same type - void NewPack(); + void NewPack(void); // return true if there is at least one allowed type - bool CanSpawnSomething(); + bool CanSpawnAnything(void); - typedef const std::set<cMonster*> tSpawnedContainer; - tSpawnedContainer& getSpawned(); + typedef const std::set<cMonster *> tSpawnedContainer; + tSpawnedContainer & getSpawned(void); protected : // return true if specified type of mob can spawn on specified block @@ -51,7 +59,7 @@ protected : cMonster::eType ChooseMobType(EMCSBiome a_Biome); // add toAdd inside toAddIn, if toAdd is in m_AllowedTypes - void addIfAllowed(cMonster::eType toAdd, std::set<cMonster::eType>& toAddIn); + void addIfAllowed(cMonster::eType toAdd, std::set<cMonster::eType> & toAddIn); protected : cMonster::eFamily m_MonsterFamily; @@ -60,13 +68,8 @@ protected : cMonster::eType m_MobType; std::set<cMonster*> m_Spawned; cFastRandom m_Random; +} ; -public : - typedef const std::set<cMonster::eType> tMobTypes; // MG TODO : maybe relocate all those statics set/maps in the same place ? - static tMobTypes& m_MobTypes(); -protected : - static tMobTypes initMobTypesBeforeCx11(); -}; diff --git a/source/World.cpp b/source/World.cpp index 2943209b7..901337879 100644 --- a/source/World.cpp +++ b/source/World.cpp @@ -757,7 +757,7 @@ void cWorld::TickMobs(float a_Dt) if (m_bAnimals) { cMobSpawner Spawner(*itr,m_AllowedMobs); - if (Spawner.CanSpawnSomething()) + if (Spawner.CanSpawnAnything()) { m_ChunkMap->SpawnMobs(Spawner); // do the spawn |