Update to allow the light map to remain the same, but allow alteration of sky light values based on time.

master
Samuel Barney 2013-10-29 10:44:51 -06:00
parent d7a490a992
commit e1a06153b2
7 changed files with 73 additions and 17 deletions

View File

@ -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

View File

@ -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; }

View File

@ -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)

View File

@ -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

View File

@ -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");

View File

@ -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;
}

View File

@ -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;
@ -728,6 +733,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);
}; // tolua_export