animal terrain finisher
This commit is contained in:
parent
9831220a1c
commit
2d93274a90
@ -402,7 +402,7 @@ void cFinishGenSoulsandRims::GenFinish(cChunkDesc & a_ChunkDesc)
|
|||||||
int ChunkZ = a_ChunkDesc.GetChunkZ() * cChunkDef::Width;
|
int ChunkZ = a_ChunkDesc.GetChunkZ() * cChunkDef::Width;
|
||||||
HEIGHTTYPE MaxHeight = a_ChunkDesc.GetMaxHeight();
|
HEIGHTTYPE MaxHeight = a_ChunkDesc.GetMaxHeight();
|
||||||
|
|
||||||
for (int x = 0; x < 16; x++)
|
for (int x = 0; x < 16; x++)
|
||||||
{
|
{
|
||||||
int xx = ChunkX + x;
|
int xx = ChunkX + x;
|
||||||
for (int z = 0; z < 16; z++)
|
for (int z = 0; z < 16; z++)
|
||||||
@ -950,34 +950,34 @@ bool cFinishGenFluidSprings::TryPlaceSpring(cChunkDesc & a_ChunkDesc, int x, int
|
|||||||
// cFinishGenPassiveMobs:
|
// cFinishGenPassiveMobs:
|
||||||
|
|
||||||
cFinishGenPassiveMobs::cFinishGenPassiveMobs(int a_Seed, cIniFile & a_IniFile, eDimension a_Dimension) :
|
cFinishGenPassiveMobs::cFinishGenPassiveMobs(int a_Seed, cIniFile & a_IniFile, eDimension a_Dimension) :
|
||||||
m_Noise(a_Seed)
|
m_Noise(a_Seed)
|
||||||
{
|
{
|
||||||
AString SectionName = "Animals";
|
AString SectionName = "Animals";
|
||||||
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,37 +986,37 @@ 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_Random.NextInt(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_Random.NextInt(cChunkDef::Width - 1);
|
||||||
int PackCenterZ = m_Random.NextInt(cChunkDef::Width - 1);
|
int PackCenterZ = m_Random.NextInt(cChunkDef::Width - 1);
|
||||||
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_Random.NextInt(cChunkDef::Width - 1);
|
||||||
int OffsetZ = m_Random.NextInt(cChunkDef::Width - 1);
|
int OffsetZ = m_Random.NextInt(cChunkDef::Width - 1);
|
||||||
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
|
||||||
} // for tries
|
}// for tries
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1025,48 +1025,48 @@ void cFinishGenPassiveMobs::GenFinish(cChunkDesc & a_ChunkDesc)
|
|||||||
|
|
||||||
bool cFinishGenPassiveMobs::TrySpawnAnimals(cChunkDesc & a_ChunkDesc, int a_RelX, int a_RelY, int a_RelZ, eMonsterType AnimalToSpawn)
|
bool cFinishGenPassiveMobs::TrySpawnAnimals(cChunkDesc & a_ChunkDesc, int a_RelX, int a_RelY, int a_RelZ, eMonsterType AnimalToSpawn)
|
||||||
{
|
{
|
||||||
BLOCKTYPE BlockAtHead = a_ChunkDesc.GetBlockType(a_RelX, a_RelY + 1, a_RelZ);
|
BLOCKTYPE BlockAtHead = a_ChunkDesc.GetBlockType(a_RelX, a_RelY + 1, a_RelZ);
|
||||||
BLOCKTYPE BlockAtFeet = a_ChunkDesc.GetBlockType(a_RelX, a_RelY , a_RelZ);
|
BLOCKTYPE BlockAtFeet = a_ChunkDesc.GetBlockType(a_RelX, a_RelY, a_RelZ);
|
||||||
BLOCKTYPE BlockUnderFeet = a_ChunkDesc.GetBlockType(a_RelX, a_RelY - 1, a_RelZ);
|
BLOCKTYPE BlockUnderFeet = a_ChunkDesc.GetBlockType(a_RelX, a_RelY - 1, a_RelZ);
|
||||||
|
|
||||||
// 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 == mtSheep) ||
|
||||||
(AnimalToSpawn == mtChicken) ||
|
(AnimalToSpawn == mtChicken) ||
|
||||||
(AnimalToSpawn == mtPig)
|
(AnimalToSpawn == mtPig)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int AnimalX, AnimalY, AnimalZ;
|
int AnimalX, AnimalY, AnimalZ;
|
||||||
AnimalX = (double)(a_ChunkDesc.GetChunkX()*cChunkDef::Width + a_RelX + 0.5);
|
AnimalX = (double)(a_ChunkDesc.GetChunkX()*cChunkDef::Width + a_RelX + 0.5);
|
||||||
AnimalY = a_RelY;
|
AnimalY = a_RelY;
|
||||||
AnimalZ = (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();
|
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);
|
ChunkEntities.push_back(NewMob);
|
||||||
LOGD("Spawning %s #%i at {%d, %d, %d}", NewMob->GetClass(), NewMob->GetUniqueID(), AnimalX, AnimalY, AnimalZ);
|
LOGD("Spawning %s #%i at {%d, %d, %d}", NewMob->GetClass(), NewMob->GetUniqueID(), AnimalX, AnimalY, AnimalZ);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1076,80 +1076,80 @@ bool cFinishGenPassiveMobs::TrySpawnAnimals(cChunkDesc & a_ChunkDesc, int a_RelX
|
|||||||
eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc)
|
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_Random.NextInt(cChunkDef::Width - 1);
|
||||||
int z = m_Random.NextInt(cChunkDef::Width - 1);
|
int z = m_Random.NextInt(cChunkDef::Width - 1);
|
||||||
|
|
||||||
// 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.size() == 0)
|
||||||
{
|
{
|
||||||
LOGD("Tried to spawn an animal from an empty list.");
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ class cFinishGenSoulsandRims :
|
|||||||
public cFinishGen
|
public cFinishGen
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
cFinishGenSoulsandRims(int a_Seed) :
|
cFinishGenSoulsandRims(int a_Seed) :
|
||||||
m_Noise(a_Seed)
|
m_Noise(a_Seed)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -319,26 +319,26 @@ protected:
|
|||||||
|
|
||||||
|
|
||||||
class cFinishGenPassiveMobs :
|
class cFinishGenPassiveMobs :
|
||||||
public cFinishGen
|
public cFinishGen
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cFinishGenPassiveMobs(int a_Seed, cIniFile & a_IniFile, eDimension a_Dimension);
|
cFinishGenPassiveMobs(int a_Seed, cIniFile & a_IniFile, eDimension a_Dimension);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
cNoise m_Noise;
|
cNoise m_Noise;
|
||||||
int m_AnimalProbability; // Chance, [0..100], that an animal pack will be generated in a chunk
|
int m_AnimalProbability; // Chance, [0..100], that an animal pack will be generated in a chunk
|
||||||
cFastRandom m_Random;
|
cFastRandom m_Random;
|
||||||
|
|
||||||
// cFinishGen override:
|
// cFinishGen override:
|
||||||
virtual void GenFinish(cChunkDesc & a_ChunkDesc) override;
|
virtual void GenFinish(cChunkDesc & a_ChunkDesc) override;
|
||||||
|
|
||||||
// Tries to spawn a mob in the center of the pack. If successful, spawns 0-5 more.
|
// Tries to spawn a mob in the center of the pack. If successful, spawns 0-5 more.
|
||||||
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 mob from biome-dependant list
|
// Gets a random mob from biome-dependant list
|
||||||
eMonsterType GetRandomMob(cChunkDesc & a_ChunkDesc);
|
eMonsterType GetRandomMob(cChunkDesc & a_ChunkDesc);
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user