summaryrefslogtreecommitdiffstats
path: root/src/Generating
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/Generating/FinishGen.cpp45
-rw-r--r--src/Generating/FinishGen.h18
2 files changed, 33 insertions, 30 deletions
diff --git a/src/Generating/FinishGen.cpp b/src/Generating/FinishGen.cpp
index ad3dc5293..e6732dbd5 100644
--- a/src/Generating/FinishGen.cpp
+++ b/src/Generating/FinishGen.cpp
@@ -1078,16 +1078,14 @@ bool cFinishGenPassiveMobs::TrySpawnAnimals(cChunkDesc & a_ChunkDesc, int a_RelX
return false;
}
- int AnimalX, AnimalY, AnimalZ;
- AnimalX = (double)(a_ChunkDesc.GetChunkX()*cChunkDef::Width + a_RelX + 0.5);
- AnimalY = a_RelY;
- AnimalZ = (double)(a_ChunkDesc.GetChunkZ()*cChunkDef::Width + a_RelZ + 0.5);
+ double AnimalX = static_cast<double>(a_ChunkDesc.GetChunkX() * cChunkDef::Width + a_RelX + 0.5);
+ double AnimalY = a_RelY;
+ double AnimalZ = static_cast<double>(a_ChunkDesc.GetChunkZ() * cChunkDef::Width + a_RelZ + 0.5);
- cEntityList ChunkEntities = a_ChunkDesc.GetEntities();
cMonster * NewMob = cMonster::NewMonsterFromType(AnimalToSpawn);
NewMob->SetPosition(AnimalX, AnimalY, AnimalZ);
- ChunkEntities.push_back(NewMob);
- LOGD("Spawning %s #%i at {%d, %d, %d}", NewMob->GetClass(), NewMob->GetUniqueID(), AnimalX, AnimalY, AnimalZ);
+ a_ChunkDesc.GetEntities().push_back(NewMob);
+ LOGD("Spawning %s #%i at {%.02f, %.02f, %.02f}", NewMob->GetClass(), NewMob->GetUniqueID(), AnimalX, AnimalY, AnimalZ);
return true;
}
@@ -1100,13 +1098,12 @@ eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc)
{
std::set<eMonsterType> ListOfSpawnables;
- std::set<eMonsterType>::iterator MobIter = ListOfSpawnables.begin();
int chunkX = a_ChunkDesc.GetChunkX();
int chunkZ = a_ChunkDesc.GetChunkZ();
int x = (m_Noise.IntNoise2DInt(chunkX, chunkZ + 10) / 7) % cChunkDef::Width;
int z = (m_Noise.IntNoise2DInt(chunkX + chunkZ, chunkZ) / 7) % cChunkDef::Width;
- /** Check biomes first to get a list of animals */
+ // Check biomes first to get a list of animals
switch (a_ChunkDesc.GetBiome(x, z))
{
// No animals in deserts or non-overworld dimensions
@@ -1118,12 +1115,14 @@ eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc)
{
return mtInvalidType;
}
+
// Mooshroom only - no other mobs on mushroom islands
case biMushroomIsland:
case biMushroomShore:
{
return mtMooshroom;
}
+
// Add squid in ocean biomes
case biOcean:
case biFrozenOcean:
@@ -1131,9 +1130,10 @@ eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc)
case biRiver:
case biDeepOcean:
{
- ListOfSpawnables.insert(MobIter, mtSquid);
+ ListOfSpawnables.insert(mtSquid);
break;
}
+
// Add ocelots in jungle biomes
case biJungle:
case biJungleHills:
@@ -1141,9 +1141,11 @@ eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc)
case biJungleM:
case biJungleEdgeM:
{
- ListOfSpawnables.insert(MobIter, mtOcelot);
+ ListOfSpawnables.insert(mtOcelot);
break;
}
+
+ // Add horses in plains-like biomes
case biPlains:
case biSunflowerPlains:
case biSavanna:
@@ -1151,10 +1153,10 @@ eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc)
case biSavannaM:
case biSavannaPlateauM:
{
- ListOfSpawnables.insert(MobIter, mtHorse);
- // ListOfSpawnables.insert(mtDonkey);
+ ListOfSpawnables.insert(mtHorse);
break;
}
+
// Add wolves in forest and spruce forests
case biForest:
case biTaiga:
@@ -1162,7 +1164,7 @@ eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc)
case biColdTaiga:
case biColdTaigaM:
{
- ListOfSpawnables.insert(MobIter, mtWolf);
+ ListOfSpawnables.insert(mtWolf);
break;
}
// Nothing special about this biome
@@ -1171,10 +1173,10 @@ eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc)
break;
}
}
- ListOfSpawnables.insert(MobIter, mtChicken);
- ListOfSpawnables.insert(MobIter, mtCow);
- ListOfSpawnables.insert(MobIter, mtPig);
- ListOfSpawnables.insert(MobIter, mtSheep);
+ ListOfSpawnables.insert(mtChicken);
+ ListOfSpawnables.insert(mtCow);
+ ListOfSpawnables.insert(mtPig);
+ ListOfSpawnables.insert(mtSheep);
if (ListOfSpawnables.empty())
{
@@ -1182,11 +1184,8 @@ eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc)
}
int RandMob = (m_Noise.IntNoise2DInt(chunkX - chunkZ + 2, chunkX + 5) / 7) % ListOfSpawnables.size();
- MobIter = ListOfSpawnables.begin();
- for (int i = 0; i < RandMob; i++)
- {
- ++MobIter;
- }
+ auto MobIter = ListOfSpawnables.begin();
+ std::advance(MobIter, RandMob);
return *MobIter;
}
diff --git a/src/Generating/FinishGen.h b/src/Generating/FinishGen.h
index 8305908c0..ae6dee590 100644
--- a/src/Generating/FinishGen.h
+++ b/src/Generating/FinishGen.h
@@ -312,7 +312,7 @@ protected:
// cFinishGen override:
virtual void GenFinish(cChunkDesc & a_ChunkDesc) override;
- // Tries to place a spring at the specified coords, checks neighbors. Returns true if successful
+ /** Tries to place a spring at the specified coords, checks neighbors. Returns true if successful. */
bool TryPlaceSpring(cChunkDesc & a_ChunkDesc, int x, int y, int z);
} ;
@@ -321,8 +321,7 @@ protected:
/** This class populates generated chunks with packs of biome-dependant animals
- Animals: cows, sheep, pigs, mooshrooms, squid, horses, wolves, ocelots
- */
+Animals: cows, sheep, pigs, mooshrooms, squid, horses, wolves, ocelots */
class cFinishGenPassiveMobs :
public cFinishGen
{
@@ -332,16 +331,21 @@ public:
protected:
- cNoise m_Noise;
- int m_AnimalProbability; // Chance, [0..100], that an animal pack will be generated in a chunk
+ /** The noise used as the source of randomness */
+ cNoise m_Noise;
+
+ /** Chance, [0..100], that an animal pack will be generated in a chunk */
+ int m_AnimalProbability;
+
// cFinishGen override:
virtual void GenFinish(cChunkDesc & a_ChunkDesc) override;
- // Returns false if an animal cannot spawn at given coords, else adds it to the chunk's entity list and returns true
+ /** Returns false if an animal cannot spawn at given coords, else adds it to the chunk's entity list and returns true */
bool TrySpawnAnimals(cChunkDesc & a_ChunkDesc, int x, int y, int z, eMonsterType AnimalToSpawn);
- // Gets a random animal from biome-dependant list
+ /** Picks a random animal from biome-dependant list for a random position in the chunk.
+ Returns the chosen mob type, or mtInvalid if no mob chosen. */
eMonsterType GetRandomMob(cChunkDesc & a_ChunkDesc);
} ;