indentation, repeatable random, small corrections

master
p-mcgowan 2014-12-02 11:21:51 -08:00
parent 978c9967ad
commit 585662e63f
1 changed files with 87 additions and 92 deletions

View File

@ -956,27 +956,27 @@ cFinishGenPassiveMobs::cFinishGenPassiveMobs(int a_Seed, cIniFile & a_IniFile, e
int DefaultAnimalSpawnChunkPercentage = DEF_ANIMAL_SPAWN_PERCENT; int DefaultAnimalSpawnChunkPercentage = DEF_ANIMAL_SPAWN_PERCENT;
switch (a_Dimension) switch (a_Dimension)
{ {
case dimOverworld: case dimOverworld:
{ {
DefaultAnimalSpawnChunkPercentage = DEF_ANIMAL_SPAWN_PERCENT; DefaultAnimalSpawnChunkPercentage = DEF_ANIMAL_SPAWN_PERCENT;
break; break;
} }
case dimNether: case dimNether:
case dimEnd: // No nether or end animals (currently) case dimEnd: // No nether or end animals (currently)
{ {
DefaultAnimalSpawnChunkPercentage = DEF_NO_ANIMALS; DefaultAnimalSpawnChunkPercentage = DEF_NO_ANIMALS;
break; break;
} }
default: default:
{ {
ASSERT(!"Unhandled world dimension"); ASSERT(!"Unhandled world dimension");
break; break;
} }
} // switch (dimension) } // switch (dimension)
m_AnimalProbability = a_IniFile.GetValueSetI(SectionName, "AnimalSpawnChunkPercentage", DefaultAnimalSpawnChunkPercentage); m_AnimalProbability = a_IniFile.GetValueSetI(SectionName, "AnimalSpawnChunkPercentage", DefaultAnimalSpawnChunkPercentage);
if (m_AnimalProbability < 0 || m_AnimalProbability > 100) if (m_AnimalProbability < 0 || m_AnimalProbability > 100)
{ {
LOGWARNING("[Animals]: AnimalSpawnChunkPercentage is invalid, using the default of \"%d\".", DefaultAnimalSpawnChunkPercentage); LOGWARNING("[Animals]: AnimalSpawnChunkPercentage is invalid, using the default of \"%d\".", DefaultAnimalSpawnChunkPercentage);
} }
} }
@ -986,33 +986,32 @@ cFinishGenPassiveMobs::cFinishGenPassiveMobs(int a_Seed, cIniFile & a_IniFile, e
void cFinishGenPassiveMobs::GenFinish(cChunkDesc & a_ChunkDesc) void cFinishGenPassiveMobs::GenFinish(cChunkDesc & a_ChunkDesc)
{ {
int ChanceRnd = m_Random.NextInt(100); int ChanceRnd = (m_Noise.IntNoise2DInt(chunkX, chunkZ) / 7) % 100;
if (ChanceRnd > m_AnimalProbability) if (ChanceRnd > m_AnimalProbability)
{ {
return; return;
} }
eMonsterType RandomMob = GetRandomMob(a_ChunkDesc); eMonsterType RandomMob = GetRandomMob(a_ChunkDesc);
if (RandomMob == mtInvalidType) if (RandomMob == mtInvalidType)
{ {
LOGWARNING("Attempted to spawn invalid mob type."); LOGWARNING("Attempted to spawn invalid mob type.");
return; return;
} }
// Try spawning a pack center 10 times, should get roughly the same probability // Try spawning a pack center 10 times, should get roughly the same probability
for (int Tries = 0; Tries < 10; Tries++) for (int Tries = 0; Tries < 10; Tries++)
{ {
int PackCenterX = m_Random.NextInt(cChunkDef::Width - 1); int PackCenterX = (m_Noise.IntNoise2DInt(chunkX, chunkZ) / 7) % cChunkDef::Width;
int PackCenterZ = m_Random.NextInt(cChunkDef::Width - 1); int PackCenterZ = (m_Noise.IntNoise2DInt(chunkX, chunkZ) / 7) % cChunkDef::Width;
if (TrySpawnAnimals(a_ChunkDesc, PackCenterX, a_ChunkDesc.GetHeight(PackCenterX, PackCenterZ), PackCenterZ, RandomMob)) if (TrySpawnAnimals(a_ChunkDesc, PackCenterX, a_ChunkDesc.GetHeight(PackCenterX, PackCenterZ), PackCenterZ, RandomMob))
{ {
for (int i = 0; i < 5; i++) for (int i = 0; i < 5; i++)
{ {
int OffsetX = m_Random.NextInt(cChunkDef::Width - 1); int OffsetX = (m_Noise.IntNoise2DInt(chunkX, chunkZ) / 7) % cChunkDef::Width;
int OffsetZ = m_Random.NextInt(cChunkDef::Width - 1); int OffsetZ = (m_Noise.IntNoise2DInt(chunkX, chunkZ) / 7) % cChunkDef::Width;
TrySpawnAnimals(a_ChunkDesc, OffsetX, a_ChunkDesc.GetHeight(OffsetX, OffsetZ), OffsetZ, RandomMob); TrySpawnAnimals(a_ChunkDesc, OffsetX, a_ChunkDesc.GetHeight(OffsetX, OffsetZ), OffsetZ, RandomMob);
} }
return; return;
} // if pack center spawn successful } // if pack center spawn successful
@ -1032,27 +1031,24 @@ bool cFinishGenPassiveMobs::TrySpawnAnimals(cChunkDesc & a_ChunkDesc, int a_RelX
// Check block below (opaque, grass, water), and above (air) // Check block below (opaque, grass, water), and above (air)
if (AnimalToSpawn == mtSquid && BlockAtFeet != E_BLOCK_WATER) if (AnimalToSpawn == mtSquid && BlockAtFeet != E_BLOCK_WATER)
{ {
return false; return false;
} }
if ( if ((AnimalToSpawn != mtSquid) &&
(AnimalToSpawn != mtSquid) && (BlockAtHead != E_BLOCK_AIR) &&
(BlockAtHead != E_BLOCK_AIR) && (BlockAtFeet != E_BLOCK_AIR) &&
(BlockAtFeet != E_BLOCK_AIR) && (!cBlockInfo::IsTransparent(BlockUnderFeet))
(!cBlockInfo::IsTransparent(BlockUnderFeet))
) )
{ {
return false; return false;
} }
if ( if ((BlockUnderFeet != E_BLOCK_GRASS) &&
(BlockUnderFeet != E_BLOCK_GRASS) && ((AnimalToSpawn == mtSheep) || (AnimalToSpawn == mtChicken) || (AnimalToSpawn == mtPig)))
(
(AnimalToSpawn == mtSheep) ||
(AnimalToSpawn == mtChicken) ||
(AnimalToSpawn == mtPig)
)
)
{ {
return false; return false;
}
if (AnimalToSpawn == mtMooshroom && BlockUnderFeet != E_BLOCK_MYCELIUM)
{
return false;
} }
int AnimalX, AnimalY, AnimalZ; int AnimalX, AnimalY, AnimalZ;
@ -1078,75 +1074,74 @@ eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc)
std::set<eMonsterType> ListOfSpawnables; std::set<eMonsterType> ListOfSpawnables;
std::set<eMonsterType>::iterator MobIter = ListOfSpawnables.begin(); std::set<eMonsterType>::iterator MobIter = ListOfSpawnables.begin();
int x = m_Random.NextInt(cChunkDef::Width - 1); int x = (m_Noise.IntNoise2DInt(chunkX, chunkZ) / 7) % cChunkDef::Width;
int z = m_Random.NextInt(cChunkDef::Width - 1); int z = (m_Noise.IntNoise2DInt(chunkX, 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 // No animals
case biNether: case biNether:
case biEnd: case biEnd:
return mtInvalidType; return mtInvalidType;
// Squid only // Squid only
case biOcean: case biOcean:
case biFrozenOcean: case biFrozenOcean:
case biFrozenRiver: case biFrozenRiver:
case biRiver: case biRiver:
case biDeepOcean: case biDeepOcean:
ListOfSpawnables.insert(MobIter, mtSquid); ListOfSpawnables.insert(MobIter, mtSquid);
break; break;
// Mooshroom only // Mooshroom only
case biMushroomIsland: case biMushroomIsland:
case biMushroomShore: case biMushroomShore:
ListOfSpawnables.insert(MobIter, mtMooshroom); ListOfSpawnables.insert(MobIter, mtMooshroom);
break; break;
case biJungle: case biJungle:
case biJungleHills: case biJungleHills:
case biJungleEdge: case biJungleEdge:
case biJungleM: case biJungleM:
case biJungleEdgeM: case biJungleEdgeM:
ListOfSpawnables.insert(MobIter, mtOcelot); ListOfSpawnables.insert(MobIter, mtOcelot);
case biPlains: case biPlains:
case biSunflowerPlains: case biSunflowerPlains:
case biSavanna: case biSavanna:
case biSavannaPlateau: case biSavannaPlateau:
case biSavannaM: case biSavannaM:
case biSavannaPlateauM: case biSavannaPlateauM:
ListOfSpawnables.insert(MobIter, mtHorse); ListOfSpawnables.insert(MobIter, mtHorse);
// ListOfSpawnables.insert(mtDonkey); // ListOfSpawnables.insert(mtDonkey);
// Wolves only // Wolves only
case biForest: case biForest:
case biTaiga: case biTaiga:
case biMegaTaiga: case biMegaTaiga:
case biColdTaiga: case biColdTaiga:
case biColdTaigaM: case biColdTaigaM:
ListOfSpawnables.insert(MobIter, mtWolf); ListOfSpawnables.insert(MobIter, mtWolf);
// All other mobs // All other mobs
default: default:
ListOfSpawnables.insert(MobIter, mtChicken); ListOfSpawnables.insert(MobIter, mtChicken);
ListOfSpawnables.insert(MobIter, mtCow); ListOfSpawnables.insert(MobIter, mtCow);
ListOfSpawnables.insert(MobIter, mtPig); ListOfSpawnables.insert(MobIter, mtPig);
ListOfSpawnables.insert(MobIter, mtSheep); ListOfSpawnables.insert(MobIter, mtSheep);
} }
if (ListOfSpawnables.size() == 0) if (ListOfSpawnables.empty())
{ {
LOGD("Tried to spawn an animal from an empty list."); return mtInvalidType;
return mtInvalidType;
} }
int RandMob = m_Random.NextInt(ListOfSpawnables.size()); int RandMob = m_Random.NextInt(ListOfSpawnables.size());
MobIter=ListOfSpawnables.begin(); MobIter=ListOfSpawnables.begin();
for (int i = 0; i < RandMob; i++) for (int i = 0; i < RandMob; i++)
{ {
++MobIter; ++MobIter;
} }
return *MobIter; return *MobIter;