diff options
author | Samuel Barney <samjbarney@gmail.com> | 2013-10-29 17:44:51 +0100 |
---|---|---|
committer | Samuel Barney <samjbarney@gmail.com> | 2013-10-29 17:44:51 +0100 |
commit | e1a06153b2e93473af58e1d801998ff7f388dc6d (patch) | |
tree | 080e0f9744333fe7936bcda1da47757dfa9fb10f /source | |
parent | Merge branch 'master' of https://github.com/SamJBarney/MCServer into MobSpawning (diff) | |
download | cuberite-e1a06153b2e93473af58e1d801998ff7f388dc6d.tar cuberite-e1a06153b2e93473af58e1d801998ff7f388dc6d.tar.gz cuberite-e1a06153b2e93473af58e1d801998ff7f388dc6d.tar.bz2 cuberite-e1a06153b2e93473af58e1d801998ff7f388dc6d.tar.lz cuberite-e1a06153b2e93473af58e1d801998ff7f388dc6d.tar.xz cuberite-e1a06153b2e93473af58e1d801998ff7f388dc6d.tar.zst cuberite-e1a06153b2e93473af58e1d801998ff7f388dc6d.zip |
Diffstat (limited to 'source')
-rw-r--r-- | source/Chunk.cpp | 13 | ||||
-rw-r--r-- | source/Chunk.h | 3 | ||||
-rw-r--r-- | source/MobSpawner.cpp | 25 | ||||
-rw-r--r-- | source/MobSpawner.h | 4 | ||||
-rw-r--r-- | source/Mobs/Monster.cpp | 6 | ||||
-rw-r--r-- | source/World.cpp | 32 | ||||
-rw-r--r-- | source/World.h | 7 |
7 files changed, 73 insertions, 17 deletions
diff --git a/source/Chunk.cpp b/source/Chunk.cpp index c419cf7f2..b38f5ea19 100644 --- a/source/Chunk.cpp +++ b/source/Chunk.cpp @@ -533,8 +533,7 @@ void cChunk::SpawnMobs(cMobSpawner& a_MobSpawner) if (IsLightValid()) { - int TimeOfDay = m_World->GetTimeOfDay(); - cEntity* newMob = a_MobSpawner.TryToSpawnHere(this, Try_X, Try_Y, Try_Z, Biome, TimeOfDay, MaxNbOfSuccess); + cEntity* newMob = a_MobSpawner.TryToSpawnHere(this, Try_X, Try_Y, Try_Z, Biome, MaxNbOfSuccess); if (newMob) { int WorldX, WorldY, WorldZ; @@ -2787,6 +2786,16 @@ Vector3i cChunk::PositionToWorldPosition(int a_RelX, int a_RelY, int a_RelZ) +NIBBLETYPE cChunk::GetTimeAlteredLight(NIBBLETYPE a_Skylight) const +{ + a_Skylight -= m_World->GetSkyDarkness(); + return (a_Skylight < 16)? a_Skylight : 0; +} + + + + + #if !C_CHUNK_USE_INLINE # include "cChunk.inl.h" #endif diff --git a/source/Chunk.h b/source/Chunk.h index 591e29ad9..8648bdd24 100644 --- a/source/Chunk.h +++ b/source/Chunk.h @@ -329,6 +329,9 @@ public: /// Same as QueueTickBlock(), but relative coords needn't be in this chunk (uses m_Neighbor-s in such a case), ignores unsuccessful attempts void UnboundedQueueTickBlock(int a_RelX, int a_RelY, int a_RelZ); + // Light alterations based on time + NIBBLETYPE GetTimeAlteredLight(NIBBLETYPE a_Skylight) const; + // Simulator data: cFireSimulatorChunkData & GetFireSimulatorData (void) { return m_FireSimulatorData; } diff --git a/source/MobSpawner.cpp b/source/MobSpawner.cpp index 7dff56d61..7c7b25b60 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, int a_TimeOfDay, 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) { BLOCKTYPE TargetBlock; BLOCKTYPE BlockAbove; @@ -138,13 +138,16 @@ bool cMobSpawner::CanSpawnHere(const cChunk * a_Chunk, int a_RelX, int a_RelY, i a_Chunk->UnboundedRelGetBlockSkyLight(a_RelX, a_RelY, a_RelZ, SkyLight); a_Chunk->UnboundedRelGetBlockType(a_RelX, a_RelY + 1, a_RelZ, BlockAbove); a_Chunk->UnboundedRelGetBlockType(a_RelX, a_RelY - 1, a_RelZ, BlockBelow); + + SkyLight = a_Chunk->GetTimeAlteredLight(SkyLight); + switch(a_MobType) { case cMonster::mtSquid: return IsBlockWater(TargetBlock) && (a_RelY >= 45) && (a_RelY <= 62); case cMonster::mtBat: - return (a_RelY <= 63) && (BlockLight <= 4) && (SkyLight <= 4 || a_TimeOfDay > 12500) && (TargetBlock == E_BLOCK_AIR) && (!g_BlockTransparent[BlockAbove]); + return (a_RelY <= 63) && (BlockLight <= 4) && (SkyLight <= 4) && (TargetBlock == E_BLOCK_AIR) && (!g_BlockTransparent[BlockAbove]); case cMonster::mtChicken: case cMonster::mtCow: @@ -153,7 +156,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) && (a_TimeOfDay <= 12500); + (BlockBelow == E_BLOCK_GRASS) && (SkyLight >= 9); } case cMonster::mtOcelot: @@ -167,8 +170,12 @@ 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) || a_TimeOfDay > 12500 ) && (BlockLight <= 7) ; + if (BlockTop == E_BLOCK_AIR) + { + a_Chunk->UnboundedRelGetBlockType(a_RelX, a_RelY + 3, a_RelZ, BlockTop); + return (TargetBlock == E_BLOCK_AIR) && (BlockAbove == E_BLOCK_AIR) && (BlockTop == E_BLOCK_AIR) && (!g_BlockTransparent[BlockBelow]) && + (SkyLight <= 7) && (BlockLight <= 7); + } } break; } @@ -193,13 +200,13 @@ bool cMobSpawner::CanSpawnHere(const cChunk * a_Chunk, int a_RelX, int a_RelY, i } } } - return CanSpawn && HaveFloor && ((SkyLight <= 7) || a_TimeOfDay > 12500) && (BlockLight <= 7); + return CanSpawn && HaveFloor && (SkyLight <= 7) && (BlockLight <= 7); } case cMonster::mtCreeper: case cMonster::mtZombie: return (TargetBlock == E_BLOCK_AIR) && (BlockAbove == E_BLOCK_AIR) && (!g_BlockTransparent[BlockBelow]) && - ((SkyLight <= 7) || a_TimeOfDay > 12500) && (BlockLight <= 7) && (m_Random.NextInt(2,a_Biome) == 0); + (SkyLight <= 7) && (BlockLight <= 7) && (m_Random.NextInt(2,a_Biome) == 0); case cMonster::mtSlime: return (TargetBlock == E_BLOCK_AIR) && (BlockAbove == E_BLOCK_AIR) && (!g_BlockTransparent[BlockBelow]) && @@ -220,7 +227,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_TimeOfDay, int& a_MaxPackSize) +cMonster* cMobSpawner::TryToSpawnHere(const cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ, EMCSBiome a_Biome, int& a_MaxPackSize) { cMonster* toReturn = NULL; if (m_NewPack) @@ -242,7 +249,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_TimeOfDay, a_Biome)) + if (CanSpawnHere(a_Chunk, a_RelX, a_RelY, a_RelZ, m_MobType, a_Biome)) { cMonster * newMob = cMonster::NewMonsterFromType(m_MobType); if (newMob) diff --git a/source/MobSpawner.h b/source/MobSpawner.h index 3b9ede7c6..22adb00f4 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_TimeOfDay, int& a_MaxPackSize); + cMonster * TryToSpawnHere(const cChunk * a_Chunk, int A_RelX, int a_RelY, int a_RelZ, EMCSBiome a_Biome, 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, int a_TimeOfDay, EMCSBiome a_Biome); + bool CanSpawnHere(const cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ, cMonster::eType a_MobType, EMCSBiome a_Biome); // return a random type that can spawn on specified biome. // returns E_ENTITY_TYPE_DONOTUSE if none is possible diff --git a/source/Mobs/Monster.cpp b/source/Mobs/Monster.cpp index 9b1f2fc4c..72dfb2583 100644 --- a/source/Mobs/Monster.cpp +++ b/source/Mobs/Monster.cpp @@ -609,9 +609,9 @@ int cMonster::GetSpawnDelay(cMonster::eFamily a_MobFamily) { switch (a_MobFamily) { - case mfHostile: return 1; - case mfPassive: return 400; - case mfAmbient: return 400; + case mfHostile: return 40; + case mfPassive: return 40; + case mfAmbient: return 40; case mfWater: return 400; } ASSERT(!"Unhandled mob family"); diff --git a/source/World.cpp b/source/World.cpp index 786d97a4d..dcd51afcf 100644 --- a/source/World.cpp +++ b/source/World.cpp @@ -229,7 +229,8 @@ cWorld::cWorld(const AString & a_WorldName) : m_RSList(0), m_Weather(eWeather_Sunny), m_WeatherInterval(24000), // Guaranteed 1 day of sunshine at server start :) - m_TickThread(*this) + m_TickThread(*this), + m_SkyDarkness(0) { LOGD("cWorld::cWorld(\"%s\")", a_WorldName.c_str()); @@ -608,6 +609,8 @@ void cWorld::Tick(float a_Dt) m_WorldAge = (Int64)(m_WorldAgeSecs * 20.0); m_TimeOfDay = (Int64)(m_TimeOfDaySecs * 20.0); + UpdateSkyDarkness(); + // Broadcast time update every 40 ticks (2 seconds) if (m_LastTimeUpdate < m_WorldAge - 40) { @@ -2676,3 +2679,30 @@ void cWorld::cTaskSaveAllChunks::Run(cWorld & a_World) + +#define TIME_SUNSET 12000 +#define TIME_NIGHT_START 13187 +#define TIME_NIGHT_END 22812 +#define TIME_SUNRISE 23999 +#define TIME_SPAWN_DIVIZOR 148 + + + + + +void cWorld::UpdateSkyDarkness() +{ + int TempTime = m_TimeOfDay; + if (TempTime <= TIME_SUNSET) + m_SkyDarkness = 0; + else if (TempTime <= TIME_NIGHT_START) + m_SkyDarkness = (TIME_NIGHT_START - TempTime)/TIME_SPAWN_DIVIZOR; + else if (TempTime <= TIME_NIGHT_END) + m_SkyDarkness = 8; + else + m_SkyDarkness = (TIME_SUNRISE - TempTime)/TIME_SPAWN_DIVIZOR; +} + + + + diff --git a/source/World.h b/source/World.h index f174a1c2c..5976321e1 100644 --- a/source/World.h +++ b/source/World.h @@ -592,6 +592,9 @@ public: /// Appends all usernames starting with a_Text (case-insensitive) into Results
void TabCompleteUserName(const AString & a_Text, AStringVector & a_Results);
+ /// Get the current darkness level based on the time
+ Int64 GetSkyDarkness() { return m_SkyDarkness; }
+
private:
friend class cRoot;
@@ -636,6 +639,8 @@ private: Int64 m_LastSave; // The last WorldAge (in ticks) in which save-all was triggerred
std::map<cMonster::eFamily,Int64> m_LastSpawnMonster; // The last WorldAge (in ticks) in which a monster was spawned (for each megatype of monster) // MG TODO : find a way to optimize without creating unmaintenability (if mob IDs are becoming unrowed)
+ Int64 m_SkyDarkness;
+
eGameMode m_GameMode;
bool m_bEnabledPVP;
bool m_IsDeepSnowEnabled;
@@ -727,6 +732,8 @@ private: /// Ticks all clients that are in this world
void TickClients(float a_Dt);
+
+ void UpdateSkyDarkness();
/// Creates a new fluid simulator, loads its settings from the inifile (a_FluidName section)
cFluidSimulator * InitializeFluidSimulator(cIniFile & a_IniFile, const char * a_FluidName, BLOCKTYPE a_SimulateBlock, BLOCKTYPE a_StationaryBlock);
|