summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHowaner <franzi.moos@googlemail.com>2014-03-02 21:04:01 +0100
committerHowaner <franzi.moos@googlemail.com>2014-03-02 21:04:01 +0100
commit1d67345989ac1e55bd0ed18baaf80becfbf37e74 (patch)
treeaee52d974ab83b0394e7acf130a6ce215fb25599
parentMore documentation (thanks to madmaxoft) and use GetBlockTypeMeta (diff)
downloadcuberite-1d67345989ac1e55bd0ed18baaf80becfbf37e74.tar
cuberite-1d67345989ac1e55bd0ed18baaf80becfbf37e74.tar.gz
cuberite-1d67345989ac1e55bd0ed18baaf80becfbf37e74.tar.bz2
cuberite-1d67345989ac1e55bd0ed18baaf80becfbf37e74.tar.lz
cuberite-1d67345989ac1e55bd0ed18baaf80becfbf37e74.tar.xz
cuberite-1d67345989ac1e55bd0ed18baaf80becfbf37e74.tar.zst
cuberite-1d67345989ac1e55bd0ed18baaf80becfbf37e74.zip
-rw-r--r--src/World.cpp53
-rw-r--r--src/World.h3
2 files changed, 43 insertions, 13 deletions
diff --git a/src/World.cpp b/src/World.cpp
index 6c9ea7453..88cc19559 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -307,25 +307,52 @@ void cWorld::CastThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ)
+int cWorld::GetDefaultWeatherInterval(eWeather a_Weather)
+{
+ switch (a_Weather)
+ {
+ case eWeather_Sunny:
+ {
+ return 14400 + (m_TickRand.randInt() % 4800); // 12 - 16 minutes
+ }
+ case eWeather_Rain:
+ {
+ return 9600 + (m_TickRand.randInt() % 7200); // 8 - 14 minutes
+ }
+ case eWeather_ThunderStorm:
+ {
+ return 2400 + (m_TickRand.randInt() % 4800); // 2 - 6 minutes
+ }
+ default:
+ {
+ LOGWARNING("Missing default weather interval for weather %d.", a_Weather);
+ return 1200;
+ }
+ } // switch (Weather)
+}
+
+
+
+
+
void cWorld::SetWeather(eWeather a_NewWeather)
{
// Do the plugins agree? Do they want a different weather?
- cRoot::Get()->GetPluginManager()->CallHookWeatherChanging(*this, a_NewWeather);
+ if (cRoot::Get()->GetPluginManager()->CallHookWeatherChanging(*this, a_NewWeather))
+ {
+ m_WeatherInterval = GetDefaultWeatherInterval(m_Weather);
+ return;
+ }
// Set new period for the selected weather:
- switch (a_NewWeather)
+ m_WeatherInterval = GetDefaultWeatherInterval(a_NewWeather);
+
+ // The weather can't be found:
+ if (m_WeatherInterval == 1200)
{
- case eWeather_Sunny: m_WeatherInterval = 14400 + (m_TickRand.randInt() % 4800); break; // 12 - 16 minutes
- case eWeather_Rain: m_WeatherInterval = 9600 + (m_TickRand.randInt() % 7200); break; // 8 - 14 minutes
- case eWeather_ThunderStorm: m_WeatherInterval = 2400 + (m_TickRand.randInt() % 4800); break; // 2 - 6 minutes
- default:
- {
- LOGWARNING("Requested unknown weather %d, setting sunny for a minute instead.", a_NewWeather);
- a_NewWeather = eWeather_Sunny;
- m_WeatherInterval = 1200;
- break;
- }
- } // switch (NewWeather)
+ return;
+ }
+
m_Weather = a_NewWeather;
BroadcastWeather(m_Weather);
diff --git a/src/World.h b/src/World.h
index 25b42888c..27f1482e5 100644
--- a/src/World.h
+++ b/src/World.h
@@ -139,6 +139,9 @@ public:
BroadcastTimeUpdate();
}
+ /** Returns the default weather interval for the specific weather type */
+ int GetDefaultWeatherInterval(eWeather a_Weather);
+
/** Returns the current game mode. Partly OBSOLETE, you should use IsGameModeXXX() functions wherever applicable */
eGameMode GetGameMode(void) const { return m_GameMode; }