Current Mob Spawning code.
This commit is contained in:
parent
5174d9cbd6
commit
d73a0cd8b0
@ -539,7 +539,21 @@ void cChunk::SpawnMobs(cMobSpawner& a_MobSpawner)
|
|||||||
// MG TODO: fix the "light" thing, I'm pretty sure that UnboundedRelGetBlock s not returning the right thing
|
// MG TODO: fix the "light" thing, I'm pretty sure that UnboundedRelGetBlock s not returning the right thing
|
||||||
|
|
||||||
// MG TODO : check that "Level" really means Y
|
// MG TODO : check that "Level" really means Y
|
||||||
cEntity* newMob = a_MobSpawner.TryToSpawnHere(BlockType, BlockMeta, BlockType_below, BlockMeta_below, BlockType_above, BlockMeta_above, Biome, Try_Y, MaxNbOfSuccess);
|
NIBBLETYPE SkyLight = GetSkyLight(Try_X, Try_Y+1, Try_Z);
|
||||||
|
if (!SkyLight)
|
||||||
|
SkyLight = GetSkyLight(Try_X, Try_Y, Try_Z);
|
||||||
|
if (!SkyLight)
|
||||||
|
SkyLight = GetSkyLight(Try_X, Try_Y - 1, Try_Z);
|
||||||
|
|
||||||
|
NIBBLETYPE BlockLight = GetBlockLight(Try_X, Try_Y+1, Try_Z);
|
||||||
|
if (!BlockLight)
|
||||||
|
BlockLight = GetBlockLight(Try_X, Try_Y, Try_Z);
|
||||||
|
if (!BlockLight)
|
||||||
|
BlockLight = GetBlockLight(Try_X, Try_Y - 1, Try_Z);
|
||||||
|
|
||||||
|
if (IsLightValid())
|
||||||
|
{
|
||||||
|
cEntity* newMob = a_MobSpawner.TryToSpawnHere(BlockType, BlockMeta, BlockType_below, BlockMeta_below, BlockType_above, BlockMeta_above, SkyLight, BlockLight, Biome, Try_Y, MaxNbOfSuccess);
|
||||||
if (newMob)
|
if (newMob)
|
||||||
{
|
{
|
||||||
int WorldX, WorldY, WorldZ;
|
int WorldX, WorldY, WorldZ;
|
||||||
@ -549,6 +563,7 @@ void cChunk::SpawnMobs(cMobSpawner& a_MobSpawner)
|
|||||||
NumberOfSuccess++;
|
NumberOfSuccess++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
NumberOfTries++;
|
NumberOfTries++;
|
||||||
}
|
}
|
||||||
|
@ -124,7 +124,7 @@ 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 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, NIBBLETYPE a_Skylight, NIBBLETYPE a_Blocklight, EMCSBiome a_Biome, int a_Level)
|
||||||
{
|
{
|
||||||
bool toReturn = false;
|
bool toReturn = false;
|
||||||
std::set<cMonster::eType>::iterator itr = m_AllowedTypes.find(a_MobType);
|
std::set<cMonster::eType>::iterator itr = m_AllowedTypes.find(a_MobType);
|
||||||
@ -154,31 +154,31 @@ bool cMobSpawner::CanSpawnHere(cMonster::eType a_MobType, BLOCKTYPE a_BlockType,
|
|||||||
if (a_MobType == cMonster::mtChicken || a_MobType == cMonster::mtPig || a_MobType == cMonster::mtCow || a_MobType == cMonster::mtSheep)
|
if (a_MobType == cMonster::mtChicken || a_MobType == cMonster::mtPig || a_MobType == cMonster::mtCow || a_MobType == cMonster::mtSheep)
|
||||||
{
|
{
|
||||||
toReturn = (
|
toReturn = (
|
||||||
a_BlockType_below == E_BLOCK_GRASS /*&& // MG TODO
|
(a_BlockType_below == E_BLOCK_GRASS) &&
|
||||||
a_LightLevel >= 9 */
|
(a_Skylight >= 9 )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else if (a_MobType == cMonster::mtOcelot)
|
else if (a_MobType == cMonster::mtOcelot)
|
||||||
{
|
{
|
||||||
toReturn = (
|
toReturn = (
|
||||||
a_Level >= 62 &&
|
(a_Level >= 62) &&
|
||||||
(
|
(
|
||||||
a_BlockType_below == E_BLOCK_GRASS ||
|
(a_BlockType_below == E_BLOCK_GRASS) ||
|
||||||
a_BlockType_below == E_BLOCK_LEAVES
|
(a_BlockType_below == E_BLOCK_LEAVES)
|
||||||
) &&
|
) &&
|
||||||
m_Random.NextInt(3,a_Biome) != 0
|
(m_Random.NextInt(3,a_Biome) != 0)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else if (a_MobType == cMonster::mtCreeper || a_MobType == cMonster::mtSkeleton || a_MobType == cMonster::mtZombie || a_MobType == cMonster::mtSpider || a_MobType == cMonster::mtEnderman || a_MobType == cMonster::mtZombiePigman)
|
else if (a_MobType == cMonster::mtCreeper || a_MobType == cMonster::mtSkeleton || a_MobType == cMonster::mtZombie || a_MobType == cMonster::mtSpider || a_MobType == cMonster::mtEnderman || a_MobType == cMonster::mtZombiePigman)
|
||||||
{
|
{
|
||||||
toReturn = true /*a_LightLevel <= 7 MG TODO*/;
|
toReturn = (a_Skylight <= 7) && (a_Blocklight <= 7);
|
||||||
/*if (a_SunLight) MG TODO
|
if (a_Skylight)
|
||||||
{
|
{
|
||||||
if (m_Random.NextInt(2,a_Biome) != 0)
|
if (m_Random.NextInt(2,a_Biome) != 0)
|
||||||
{
|
{
|
||||||
toReturn = false;
|
toReturn = false;
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
}
|
}
|
||||||
else if (a_MobType == cMonster::mtSlime)
|
else if (a_MobType == cMonster::mtSlime)
|
||||||
{
|
{
|
||||||
@ -192,7 +192,7 @@ bool cMobSpawner::CanSpawnHere(cMonster::eType a_MobType, BLOCKTYPE a_BlockType,
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
LOGD("MG TODO : check I've got a Rule to write for type %d",a_MobType);
|
LOGD("MG TODO : check I've got a Rule to write for type %d",a_MobType);
|
||||||
toReturn = true;
|
toReturn = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -204,7 +204,7 @@ 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* cMobSpawner::TryToSpawnHere(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, BLOCKTYPE a_BlockType_below, NIBBLETYPE a_BlockMeta_below, BLOCKTYPE a_BlockType_above, NIBBLETYPE a_BlockMeta_above, NIBBLETYPE a_Skylight, NIBBLETYPE a_Blocklight, EMCSBiome a_Biome, int a_Level, int& a_MaxPackSize)
|
||||||
{
|
{
|
||||||
cMonster* toReturn = NULL;
|
cMonster* toReturn = NULL;
|
||||||
if (m_NewPack)
|
if (m_NewPack)
|
||||||
@ -226,7 +226,7 @@ cMonster* cMobSpawner::TryToSpawnHere(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockM
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (CanSpawnHere(m_MobType, a_BlockType, a_BlockMeta, a_BlockType_below, a_BlockMeta_below, a_BlockType_above, a_BlockMeta_above, a_Biome, a_Level))
|
if (CanSpawnHere(m_MobType, a_BlockType, a_BlockMeta, a_BlockType_below, a_BlockMeta_below, a_BlockType_above, a_BlockMeta_above, a_Skylight, a_Blocklight, a_Biome, a_Level))
|
||||||
{
|
{
|
||||||
cMonster * newMob = cMonster::NewMonsterFromType(m_MobType);
|
cMonster * newMob = cMonster::NewMonsterFromType(m_MobType);
|
||||||
if (newMob)
|
if (newMob)
|
||||||
|
@ -38,7 +38,7 @@ public :
|
|||||||
// if this is the first of a Pack : determine the type of monster
|
// if this is the first of a Pack : determine the type of monster
|
||||||
// BlockType & BlockMeta are used to decide 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
|
// 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, NIBBLETYPE a_Skylight, NIBBLETYPE a_Blocklight, EMCSBiome a_Biome, int a_Level, int& a_MaxPackSize);
|
||||||
|
|
||||||
// mark the beginning of a new Pack
|
// mark the beginning of a new Pack
|
||||||
// all mobs of the same Pack are the same type
|
// all mobs of the same Pack are the same type
|
||||||
@ -52,7 +52,7 @@ public :
|
|||||||
|
|
||||||
protected :
|
protected :
|
||||||
// return true if specified type of mob can spawn on specified block
|
// return true if specified type of mob can spawn on specified block
|
||||||
bool 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 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, NIBBLETYPE a_Skylight, NIBBLETYPE a_Blocklight, EMCSBiome a_Biome, int a_Level);
|
||||||
|
|
||||||
// return a random type that can spawn on specified biome.
|
// return a random type that can spawn on specified biome.
|
||||||
// returns E_ENTITY_TYPE_DONOTUSE if none is possible
|
// returns E_ENTITY_TYPE_DONOTUSE if none is possible
|
||||||
|
Loading…
Reference in New Issue
Block a user