diff options
author | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-08-25 23:46:18 +0200 |
---|---|---|
committer | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-08-25 23:46:18 +0200 |
commit | 7157ebc061b496d84c685070107045e8440a6ef0 (patch) | |
tree | 46ae305d432f61b0fef5363b49ea534bcafdab10 /source/cWorld.cpp | |
parent | Removed cPackets from cChunk. (diff) | |
download | cuberite-7157ebc061b496d84c685070107045e8440a6ef0.tar cuberite-7157ebc061b496d84c685070107045e8440a6ef0.tar.gz cuberite-7157ebc061b496d84c685070107045e8440a6ef0.tar.bz2 cuberite-7157ebc061b496d84c685070107045e8440a6ef0.tar.lz cuberite-7157ebc061b496d84c685070107045e8440a6ef0.tar.xz cuberite-7157ebc061b496d84c685070107045e8440a6ef0.tar.zst cuberite-7157ebc061b496d84c685070107045e8440a6ef0.zip |
Diffstat (limited to '')
-rw-r--r-- | source/cWorld.cpp | 110 |
1 files changed, 70 insertions, 40 deletions
diff --git a/source/cWorld.cpp b/source/cWorld.cpp index 232e3a44f..e5462fd93 100644 --- a/source/cWorld.cpp +++ b/source/cWorld.cpp @@ -43,12 +43,6 @@ #include "Trees.h" #include "cPluginManager.h" #include "blocks/Block.h" - - -#include "packets/cPacket_TimeUpdate.h" -#include "packets/cPacket_NewInvalidState.h" -#include "packets/cPacket_Thunderbolt.h" - #include "Vector3d.h" #include "tolua++.h" @@ -312,38 +306,24 @@ cWorld::cWorld( const AString & a_WorldName ) -void cWorld::SetWeather( eWeather a_Weather ) +void cWorld::SetWeather(eWeather a_Weather) { - switch( a_Weather ) + switch (a_Weather) { - case eWeather_Sunny: - { - m_Weather = a_Weather; - cPacket_NewInvalidState WeatherPacket; - WeatherPacket.m_Reason = 2; //stop rain - Broadcast ( WeatherPacket ); - } - break; - case eWeather_Rain: + case eWeather_Sunny: + case eWeather_Rain: + case eWeather_ThunderStorm: { m_Weather = a_Weather; - cPacket_NewInvalidState WeatherPacket; - WeatherPacket.m_Reason = 1; //begin rain - Broadcast ( WeatherPacket ); + BroadcastWeather(a_Weather); + break; } - break; - case eWeather_ThunderStorm: + + default: { - m_Weather = a_Weather; - cPacket_NewInvalidState WeatherPacket; - WeatherPacket.m_Reason = 1; //begin rain - Broadcast ( WeatherPacket ); - CastThunderbolt ( 0, 0, 0 ); //start thunderstorm with a lightning strike at 0, 0, 0. >:D + LOGWARN("Trying to set unknown weather %d", a_Weather); + break; } - break; - default: - LOGWARN("Trying to set unknown weather %d", a_Weather ); - break; } } @@ -351,20 +331,24 @@ void cWorld::SetWeather( eWeather a_Weather ) -void cWorld::CastThunderbolt ( int a_X, int a_Y, int a_Z ) +void cWorld::CastThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ) { - cPacket_Thunderbolt ThunderboltPacket; - ThunderboltPacket.m_xLBPos = a_X; - ThunderboltPacket.m_yLBPos = a_Y; - ThunderboltPacket.m_zLBPos = a_Z; - BroadcastToChunkOfBlock(a_X, a_Y, a_Z, &ThunderboltPacket); + BroadcastThunderbolt(a_BlockX, a_BlockY, a_BlockZ); } + + + + void cWorld::SetNextBlockTick(int a_BlockX, int a_BlockY, int a_BlockZ) { return m_ChunkMap->SetNextBlockTick(a_BlockX, a_BlockY, a_BlockZ); } + + + + void cWorld::InitializeSpawn(void) { int ChunkX = 0, ChunkY = 0, ChunkZ = 0; @@ -447,16 +431,17 @@ void cWorld::Tick(float a_Dt) bool bSendTime = false; m_WorldTimeFraction += a_Dt / 1000.f; - while ( m_WorldTimeFraction > 1.f ) + while (m_WorldTimeFraction > 1.f) { m_WorldTimeFraction -= 1.f; m_WorldTime += 20; bSendTime = true; } m_WorldTime %= 24000; // 24000 units in a day - if ( bSendTime ) + + if (bSendTime) { - Broadcast( cPacket_TimeUpdate( (m_WorldTime) ) ); + BroadcastTimeUpdate(); } { @@ -1408,6 +1393,51 @@ void cWorld::BroadcastCollectPickup(const cPickup & a_Pickup, const cPlayer & a_ +void cWorld::BroadcastWeather(eWeather a_Weather, const cClientHandle * a_Exclude) +{ + cCSLock Lock(m_CSPlayers); + for (cPlayerList::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr) + { + cClientHandle * ch = (*itr)->GetClientHandle(); + if ((ch == a_Exclude) || (ch == NULL) || !ch->IsLoggedIn() || ch->IsDestroyed()) + { + continue; + } + ch->SendWeather(a_Weather); + } +} + + + + + +void cWorld::BroadcastThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude) +{ + m_ChunkMap->BroadcastThunderbolt(a_BlockX, a_BlockY, a_BlockZ, a_Exclude); +} + + + + + +void cWorld::BroadcastTimeUpdate(const cClientHandle * a_Exclude) +{ + cCSLock Lock(m_CSPlayers); + for (cPlayerList::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr) + { + cClientHandle * ch = (*itr)->GetClientHandle(); + if ((ch == a_Exclude) || (ch == NULL) || !ch->IsLoggedIn() || ch->IsDestroyed()) + { + continue; + } + ch->SendTimeUpdate(m_WorldTime); + } +} + + + + + void cWorld::BroadcastBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude) { m_ChunkMap->BroadcastBlockEntity(a_BlockX, a_BlockY, a_BlockZ, a_Exclude); |