summaryrefslogtreecommitdiffstats
path: root/source/cWorld.cpp
diff options
context:
space:
mode:
authorcedeel@gmail.com <cedeel@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-06-13 02:46:23 +0200
committercedeel@gmail.com <cedeel@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-06-13 02:46:23 +0200
commit900c26dc3008fb790d817e4d816491b09b00aa49 (patch)
tree2fe3a7952fb07f723f014564bf938a6f4c1780ba /source/cWorld.cpp
parentAdded working crafting hooks HOOK_PRE_CRAFTING, HOOK_CRAFTING_NO_RECIPE and HOOK_POST_CRAFTING (diff)
downloadcuberite-900c26dc3008fb790d817e4d816491b09b00aa49.tar
cuberite-900c26dc3008fb790d817e4d816491b09b00aa49.tar.gz
cuberite-900c26dc3008fb790d817e4d816491b09b00aa49.tar.bz2
cuberite-900c26dc3008fb790d817e4d816491b09b00aa49.tar.lz
cuberite-900c26dc3008fb790d817e4d816491b09b00aa49.tar.xz
cuberite-900c26dc3008fb790d817e4d816491b09b00aa49.tar.zst
cuberite-900c26dc3008fb790d817e4d816491b09b00aa49.zip
Diffstat (limited to 'source/cWorld.cpp')
-rw-r--r--source/cWorld.cpp97
1 files changed, 69 insertions, 28 deletions
diff --git a/source/cWorld.cpp b/source/cWorld.cpp
index 225660d7b..41915926f 100644
--- a/source/cWorld.cpp
+++ b/source/cWorld.cpp
@@ -356,7 +356,7 @@ void cWorld::CastThunderbolt ( int a_X, int a_Y, int a_Z )
ThunderboltPacket.m_xLBPos = a_X;
ThunderboltPacket.m_yLBPos = a_Y;
ThunderboltPacket.m_zLBPos = a_Z;
- Broadcast( ThunderboltPacket ); // FIXME: Broadcast to chunk instead of entire world
+ BroadcastToChunkOfBlock(a_X, a_Y, a_Z, &ThunderboltPacket);
}
@@ -619,43 +619,84 @@ void cWorld::Tick(float a_Dt)
-void cWorld::TickWeather(float a_Dt)
+void cWorld::ChangeWeather()
{
- if ( GetWeather() == 0 ) // if sunny
+ unsigned randWeather = (m_TickRand.randInt() % 99);
+
+ if (GetWeather() == eWeather_Sunny)
{
- if( CurrentTick % 19 == 0 ) //every 20 ticks random weather
+ if (randWeather < 20)
{
- unsigned randWeather = (m_TickRand.randInt() % 10000);
- if (randWeather == 0)
- {
- LOG("Starting Rainstorm!");
- SetWeather ( eWeather_Rain );
- }
- else if (randWeather == 1)
- {
- LOG("Starting Thunderstorm!");
- SetWeather ( eWeather_ThunderStorm );
- }
+ LOG("Starting rainstorm!");
+ SetWeather( eWeather_Rain );
}
}
+
+ else if (GetWeather() == eWeather_Rain)
+ {
+ if (randWeather < 5)
+ {
+ LOG("Thunderstorm!");
+ SetWeather( eWeather_ThunderStorm );
+ }
+
+ else if (randWeather < 60)
+ {
+ LOG("Back to sunshine");
+ SetWeather( eWeather_Sunny );
+ }
+ }
+
+ else if (GetWeather() == eWeather_ThunderStorm)
+ {
+ if (randWeather < 70)
+ {
+ SetWeather(eWeather_Sunny);
+ LOG("Thunder ended abruptly, returning to lovely sunshine");
+ }
+ else if (randWeather < 85)
+ {
+ SetWeather(eWeather_Rain);
+ LOG("Thunder ended, but rain persists.");
+ }
+ else
+ {
+ return;
+ }
+ }
+}
+
+
+
+
- if ( GetWeather() != 0 ) // if raining or thunderstorm
+void cWorld::TickWeather(float a_Dt)
+{
+ if(m_WeatherInterval == 0)
{
- if ( CurrentTick % 19 == 0 ) // every 20 ticks random weather
+ ChangeWeather();
+
+ switch(GetWeather())
{
- unsigned randWeather = (m_TickRand.randInt() % 4999);
- if (randWeather == 0) //2% chance per second
- {
- LOG("Back to sunny!");
- SetWeather ( eWeather_Sunny );
- }
- else if ( (randWeather > 4000) && (GetWeather() != 2) ) // random chance for rainstorm to turn into thunderstorm.
- {
- LOG("Starting Thunderstorm!");
- SetWeather ( eWeather_ThunderStorm );
- }
+ case eWeather_Sunny:
+ m_WeatherInterval = 14400 + (m_TickRand.randInt() % 4800); // 12 - 16 minutes
+ break;
+ case eWeather_Rain:
+ m_WeatherInterval = 9600 + (m_TickRand.randInt() % 7200); // 8 - 14 minutes
+ break;
+ case eWeather_ThunderStorm:
+ m_WeatherInterval = 2400 + (m_TickRand.randInt() % 4800); // 2 - 6 minutes
+ break;
+ default:
+ LOG("Unknown weather occurred");
+ break;
}
}
+
+ else
+ {
+ m_WeatherInterval--;
+ }
if ( GetWeather() == 2 ) // if thunderstorm
{