1
0

FinishGenPassiveMobs: Cosmetic changes.

This commit is contained in:
Mattes D 2014-12-05 22:46:46 +01:00
parent 5712fadf31
commit c5dc5ac45f
2 changed files with 33 additions and 30 deletions

View File

@ -1078,16 +1078,14 @@ bool cFinishGenPassiveMobs::TrySpawnAnimals(cChunkDesc & a_ChunkDesc, int a_RelX
return false; return false;
} }
int AnimalX, AnimalY, AnimalZ; double AnimalX = static_cast<double>(a_ChunkDesc.GetChunkX() * cChunkDef::Width + a_RelX + 0.5);
AnimalX = (double)(a_ChunkDesc.GetChunkX()*cChunkDef::Width + a_RelX + 0.5); double AnimalY = a_RelY;
AnimalY = a_RelY; double AnimalZ = static_cast<double>(a_ChunkDesc.GetChunkZ() * cChunkDef::Width + a_RelZ + 0.5);
AnimalZ = (double)(a_ChunkDesc.GetChunkZ()*cChunkDef::Width + a_RelZ + 0.5);
cEntityList ChunkEntities = a_ChunkDesc.GetEntities();
cMonster * NewMob = cMonster::NewMonsterFromType(AnimalToSpawn); cMonster * NewMob = cMonster::NewMonsterFromType(AnimalToSpawn);
NewMob->SetPosition(AnimalX, AnimalY, AnimalZ); NewMob->SetPosition(AnimalX, AnimalY, AnimalZ);
ChunkEntities.push_back(NewMob); a_ChunkDesc.GetEntities().push_back(NewMob);
LOGD("Spawning %s #%i at {%d, %d, %d}", NewMob->GetClass(), NewMob->GetUniqueID(), AnimalX, AnimalY, AnimalZ); LOGD("Spawning %s #%i at {%.02f, %.02f, %.02f}", NewMob->GetClass(), NewMob->GetUniqueID(), AnimalX, AnimalY, AnimalZ);
return true; return true;
} }
@ -1100,13 +1098,12 @@ eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc)
{ {
std::set<eMonsterType> ListOfSpawnables; std::set<eMonsterType> ListOfSpawnables;
std::set<eMonsterType>::iterator MobIter = ListOfSpawnables.begin();
int chunkX = a_ChunkDesc.GetChunkX(); int chunkX = a_ChunkDesc.GetChunkX();
int chunkZ = a_ChunkDesc.GetChunkZ(); int chunkZ = a_ChunkDesc.GetChunkZ();
int x = (m_Noise.IntNoise2DInt(chunkX, chunkZ + 10) / 7) % cChunkDef::Width; int x = (m_Noise.IntNoise2DInt(chunkX, chunkZ + 10) / 7) % cChunkDef::Width;
int z = (m_Noise.IntNoise2DInt(chunkX + chunkZ, chunkZ) / 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)) switch (a_ChunkDesc.GetBiome(x, z))
{ {
// No animals in deserts or non-overworld dimensions // No animals in deserts or non-overworld dimensions
@ -1118,12 +1115,14 @@ eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc)
{ {
return mtInvalidType; return mtInvalidType;
} }
// Mooshroom only - no other mobs on mushroom islands // Mooshroom only - no other mobs on mushroom islands
case biMushroomIsland: case biMushroomIsland:
case biMushroomShore: case biMushroomShore:
{ {
return mtMooshroom; return mtMooshroom;
} }
// Add squid in ocean biomes // Add squid in ocean biomes
case biOcean: case biOcean:
case biFrozenOcean: case biFrozenOcean:
@ -1131,9 +1130,10 @@ eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc)
case biRiver: case biRiver:
case biDeepOcean: case biDeepOcean:
{ {
ListOfSpawnables.insert(MobIter, mtSquid); ListOfSpawnables.insert(mtSquid);
break; break;
} }
// Add ocelots in jungle biomes // Add ocelots in jungle biomes
case biJungle: case biJungle:
case biJungleHills: case biJungleHills:
@ -1141,9 +1141,11 @@ eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc)
case biJungleM: case biJungleM:
case biJungleEdgeM: case biJungleEdgeM:
{ {
ListOfSpawnables.insert(MobIter, mtOcelot); ListOfSpawnables.insert(mtOcelot);
break; break;
} }
// Add horses in plains-like biomes
case biPlains: case biPlains:
case biSunflowerPlains: case biSunflowerPlains:
case biSavanna: case biSavanna:
@ -1151,10 +1153,10 @@ eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc)
case biSavannaM: case biSavannaM:
case biSavannaPlateauM: case biSavannaPlateauM:
{ {
ListOfSpawnables.insert(MobIter, mtHorse); ListOfSpawnables.insert(mtHorse);
// ListOfSpawnables.insert(mtDonkey);
break; break;
} }
// Add wolves in forest and spruce forests // Add wolves in forest and spruce forests
case biForest: case biForest:
case biTaiga: case biTaiga:
@ -1162,7 +1164,7 @@ eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc)
case biColdTaiga: case biColdTaiga:
case biColdTaigaM: case biColdTaigaM:
{ {
ListOfSpawnables.insert(MobIter, mtWolf); ListOfSpawnables.insert(mtWolf);
break; break;
} }
// Nothing special about this biome // Nothing special about this biome
@ -1171,10 +1173,10 @@ eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc)
break; break;
} }
} }
ListOfSpawnables.insert(MobIter, mtChicken); ListOfSpawnables.insert(mtChicken);
ListOfSpawnables.insert(MobIter, mtCow); ListOfSpawnables.insert(mtCow);
ListOfSpawnables.insert(MobIter, mtPig); ListOfSpawnables.insert(mtPig);
ListOfSpawnables.insert(MobIter, mtSheep); ListOfSpawnables.insert(mtSheep);
if (ListOfSpawnables.empty()) 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(); int RandMob = (m_Noise.IntNoise2DInt(chunkX - chunkZ + 2, chunkX + 5) / 7) % ListOfSpawnables.size();
MobIter = ListOfSpawnables.begin(); auto MobIter = ListOfSpawnables.begin();
for (int i = 0; i < RandMob; i++) std::advance(MobIter, RandMob);
{
++MobIter;
}
return *MobIter; return *MobIter;
} }

View File

@ -312,7 +312,7 @@ protected:
// cFinishGen override: // cFinishGen override:
virtual void GenFinish(cChunkDesc & a_ChunkDesc) 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); 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 /** 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 : class cFinishGenPassiveMobs :
public cFinishGen public cFinishGen
{ {
@ -332,16 +331,21 @@ public:
protected: protected:
/** The noise used as the source of randomness */
cNoise m_Noise; cNoise m_Noise;
int m_AnimalProbability; // Chance, [0..100], that an animal pack will be generated in a chunk
/** Chance, [0..100], that an animal pack will be generated in a chunk */
int m_AnimalProbability;
// cFinishGen override: // cFinishGen override:
virtual void GenFinish(cChunkDesc & a_ChunkDesc) 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); 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); eMonsterType GetRandomMob(cChunkDesc & a_ChunkDesc);
} ; } ;