diff options
author | Samuel Barney <samjbarney@gmail.com> | 2013-10-28 23:38:34 +0100 |
---|---|---|
committer | Samuel Barney <samjbarney@gmail.com> | 2013-10-28 23:38:34 +0100 |
commit | 47283f9daa4a19514c211ceb1dc1e4bc7c06b26d (patch) | |
tree | f4aefc7cb346fee23b4cf681c75f5ad2ee7a8f14 /source | |
parent | Made mob spawning code use the chunk so that it could use varying sizes of areas for different mobs. (diff) | |
download | cuberite-47283f9daa4a19514c211ceb1dc1e4bc7c06b26d.tar cuberite-47283f9daa4a19514c211ceb1dc1e4bc7c06b26d.tar.gz cuberite-47283f9daa4a19514c211ceb1dc1e4bc7c06b26d.tar.bz2 cuberite-47283f9daa4a19514c211ceb1dc1e4bc7c06b26d.tar.lz cuberite-47283f9daa4a19514c211ceb1dc1e4bc7c06b26d.tar.xz cuberite-47283f9daa4a19514c211ceb1dc1e4bc7c06b26d.tar.zst cuberite-47283f9daa4a19514c211ceb1dc1e4bc7c06b26d.zip |
Diffstat (limited to '')
-rw-r--r-- | source/Chunk.cpp | 3 | ||||
-rw-r--r-- | source/MobSpawner.cpp | 30 | ||||
-rw-r--r-- | source/MobSpawner.h | 4 |
3 files changed, 23 insertions, 14 deletions
diff --git a/source/Chunk.cpp b/source/Chunk.cpp index 637b72b2b..038831896 100644 --- a/source/Chunk.cpp +++ b/source/Chunk.cpp @@ -533,7 +533,8 @@ void cChunk::SpawnMobs(cMobSpawner& a_MobSpawner) if (IsLightValid()) { - cEntity* newMob = a_MobSpawner.TryToSpawnHere(this, Try_X, Try_Y, Try_Z, Biome, MaxNbOfSuccess); + int TimeOfDay = m_World->GetTimeOfDay(); + cEntity* newMob = a_MobSpawner.TryToSpawnHere(this, Try_X, Try_Y, Try_Z, Biome, TimeOfDay, MaxNbOfSuccess); if (newMob) { int WorldX, WorldY, WorldZ; diff --git a/source/MobSpawner.cpp b/source/MobSpawner.cpp index a076eaf00..7dff56d61 100644 --- a/source/MobSpawner.cpp +++ b/source/MobSpawner.cpp @@ -124,7 +124,7 @@ cMonster::eType cMobSpawner::ChooseMobType(EMCSBiome a_Biome) -bool cMobSpawner::CanSpawnHere(const cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ, cMonster::eType a_MobType, EMCSBiome a_Biome) +bool cMobSpawner::CanSpawnHere(const cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ, cMonster::eType a_MobType, int a_TimeOfDay, EMCSBiome a_Biome) { BLOCKTYPE TargetBlock; BLOCKTYPE BlockAbove; @@ -144,7 +144,7 @@ bool cMobSpawner::CanSpawnHere(const cChunk * a_Chunk, int a_RelX, int a_RelY, i return IsBlockWater(TargetBlock) && (a_RelY >= 45) && (a_RelY <= 62); case cMonster::mtBat: - return (a_RelY <= 63) && (BlockLight <= 4) && (SkyLight <= 4) && (TargetBlock == E_BLOCK_AIR) && (!g_BlockTransparent[BlockAbove]); + return (a_RelY <= 63) && (BlockLight <= 4) && (SkyLight <= 4 || a_TimeOfDay > 12500) && (TargetBlock == E_BLOCK_AIR) && (!g_BlockTransparent[BlockAbove]); case cMonster::mtChicken: case cMonster::mtCow: @@ -153,7 +153,7 @@ bool cMobSpawner::CanSpawnHere(const cChunk * a_Chunk, int a_RelX, int a_RelY, i case cMonster::mtSheep: { return (TargetBlock == E_BLOCK_AIR) && (BlockAbove == E_BLOCK_AIR) && (!g_BlockTransparent[BlockBelow]) && - (BlockBelow == E_BLOCK_GRASS) && (SkyLight >= 9); + (BlockBelow == E_BLOCK_GRASS) && (SkyLight >= 9) && (a_TimeOfDay <= 12500); } case cMonster::mtOcelot: @@ -168,34 +168,42 @@ bool cMobSpawner::CanSpawnHere(const cChunk * a_Chunk, int a_RelX, int a_RelY, i BLOCKTYPE BlockTop; a_Chunk->UnboundedRelGetBlockType(a_RelX, a_RelY + 2, a_RelZ, BlockTop); return (TargetBlock == E_BLOCK_AIR) && (BlockAbove == E_BLOCK_AIR) && (BlockTop == E_BLOCK_AIR) && (!g_BlockTransparent[BlockBelow]) && - (SkyLight <= 7) && (BlockLight <= 7); + ((SkyLight <= 7) || a_TimeOfDay > 12500 ) && (BlockLight <= 7) ; } break; } case cMonster::mtSpider: { bool CanSpawn = true; - for (int x = -1; x < 2; ++x) + bool HaveFloor = false; + for (int x = 0; x < 2; ++x) { - for(int z = -1; z < 2; ++x) + for(int z = 0; z < 2; ++z) { CanSpawn = a_Chunk->UnboundedRelGetBlockType(a_RelX + x, a_RelY, a_RelZ + z, TargetBlock); CanSpawn = CanSpawn && (TargetBlock == E_BLOCK_AIR); if (!CanSpawn) + { return false; + } + if (!HaveFloor) + { + a_Chunk->UnboundedRelGetBlockType(a_RelX + x, a_RelY - 1, a_RelZ + z, TargetBlock); + HaveFloor = HaveFloor || !g_BlockTransparent[TargetBlock]; + } } } - return CanSpawn && (!g_BlockTransparent[BlockBelow]) && (SkyLight <= 7) && (BlockLight <= 7); + return CanSpawn && HaveFloor && ((SkyLight <= 7) || a_TimeOfDay > 12500) && (BlockLight <= 7); } case cMonster::mtCreeper: case cMonster::mtZombie: return (TargetBlock == E_BLOCK_AIR) && (BlockAbove == E_BLOCK_AIR) && (!g_BlockTransparent[BlockBelow]) && - (SkyLight <= 7) && (BlockLight <= 7) && (m_Random.NextInt(2,a_Biome) == 0); + ((SkyLight <= 7) || a_TimeOfDay > 12500) && (BlockLight <= 7) && (m_Random.NextInt(2,a_Biome) == 0); case cMonster::mtSlime: return (TargetBlock == E_BLOCK_AIR) && (BlockAbove == E_BLOCK_AIR) && (!g_BlockTransparent[BlockBelow]) && - (a_RelY <= 40); + ((a_RelY <= 40) || a_Biome == biSwampland); case cMonster::mtGhast: case cMonster::mtZombiePigman: return (TargetBlock == E_BLOCK_AIR) && (BlockAbove == E_BLOCK_AIR) && (!g_BlockTransparent[BlockBelow]) && @@ -212,7 +220,7 @@ bool cMobSpawner::CanSpawnHere(const cChunk * a_Chunk, int a_RelX, int a_RelY, i -cMonster* cMobSpawner::TryToSpawnHere(const cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ, EMCSBiome a_Biome, int& a_MaxPackSize) +cMonster* cMobSpawner::TryToSpawnHere(const cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ, EMCSBiome a_Biome, int a_TimeOfDay, int& a_MaxPackSize) { cMonster* toReturn = NULL; if (m_NewPack) @@ -234,7 +242,7 @@ cMonster* cMobSpawner::TryToSpawnHere(const cChunk * a_Chunk, int a_RelX, int a_ } - if (CanSpawnHere(a_Chunk, a_RelX, a_RelY, a_RelZ, m_MobType, a_Biome)) + if (CanSpawnHere(a_Chunk, a_RelX, a_RelY, a_RelZ, m_MobType, a_TimeOfDay, a_Biome)) { cMonster * newMob = cMonster::NewMonsterFromType(m_MobType); if (newMob) diff --git a/source/MobSpawner.h b/source/MobSpawner.h index 22adb00f4..3b9ede7c6 100644 --- a/source/MobSpawner.h +++ b/source/MobSpawner.h @@ -39,7 +39,7 @@ public : // 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 // MaxPackSize is set to the maximal size for a pack this type of mob - cMonster * TryToSpawnHere(const cChunk * a_Chunk, int A_RelX, int a_RelY, int a_RelZ, EMCSBiome a_Biome, int& a_MaxPackSize); + cMonster * TryToSpawnHere(const cChunk * a_Chunk, int A_RelX, int a_RelY, int a_RelZ, EMCSBiome a_Biome, int a_TimeOfDay, int& a_MaxPackSize); // mark the beginning of a new Pack // all mobs of the same Pack are the same type @@ -53,7 +53,7 @@ public : protected : // return true if specified type of mob can spawn on specified block - bool CanSpawnHere(const cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ, cMonster::eType a_MobType, EMCSBiome a_Biome); + bool CanSpawnHere(const cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ, cMonster::eType a_MobType, int a_TimeOfDay, EMCSBiome a_Biome); // return a random type that can spawn on specified biome. // returns E_ENTITY_TYPE_DONOTUSE if none is possible |