From 900c26dc3008fb790d817e4d816491b09b00aa49 Mon Sep 17 00:00:00 2001 From: "cedeel@gmail.com" Date: Wed, 13 Jun 2012 00:46:23 +0000 Subject: Revamped the weather system. git-svn-id: http://mc-server.googlecode.com/svn/trunk@599 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/Bindings.cpp | 38 +++++++++++++++++++-- source/Bindings.h | 2 +- source/cWorld.cpp | 97 +++++++++++++++++++++++++++++++++++++---------------- source/cWorld.h | 2 ++ 4 files changed, 107 insertions(+), 32 deletions(-) diff --git a/source/Bindings.cpp b/source/Bindings.cpp index 5fa802a88..90cb4aa47 100644 --- a/source/Bindings.cpp +++ b/source/Bindings.cpp @@ -1,6 +1,6 @@ /* ** Lua binding: AllToLua -** Generated automatically by tolua++-1.0.92 on 06/12/12 23:23:39. +** Generated automatically by tolua++-1.0.92 on Wed Jun 13 02:33:14 2012. */ #ifndef __cplusplus @@ -13,8 +13,8 @@ /* Exported function */ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S); -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules -#include "tolua_base.h" +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules +#include "tolua_base.h" #include "cTorch.h" #include "cStairs.h" #include "cStep.h" @@ -11296,6 +11296,37 @@ static int tolua_AllToLua_cWorld_SetWeather00(lua_State* tolua_S) } #endif //#ifndef TOLUA_DISABLE +/* method: ChangeWeather of class cWorld */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cWorld_ChangeWeather00 +static int tolua_AllToLua_cWorld_ChangeWeather00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"cWorld",0,&tolua_err) || + !tolua_isnoobj(tolua_S,2,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + cWorld* self = (cWorld*) tolua_tousertype(tolua_S,1,0); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'ChangeWeather'", NULL); +#endif + { + self->ChangeWeather(); + } + } + return 0; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'ChangeWeather'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + /* method: GetWeather of class cWorld */ #ifndef TOLUA_DISABLE_tolua_AllToLua_cWorld_GetWeather00 static int tolua_AllToLua_cWorld_GetWeather00(lua_State* tolua_S) @@ -19801,6 +19832,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S) tolua_function(tolua_S,"GetStorageSaveQueueLength",tolua_AllToLua_cWorld_GetStorageSaveQueueLength00); tolua_function(tolua_S,"CastThunderbolt",tolua_AllToLua_cWorld_CastThunderbolt00); tolua_function(tolua_S,"SetWeather",tolua_AllToLua_cWorld_SetWeather00); + tolua_function(tolua_S,"ChangeWeather",tolua_AllToLua_cWorld_ChangeWeather00); tolua_function(tolua_S,"GetWeather",tolua_AllToLua_cWorld_GetWeather00); tolua_function(tolua_S,"SetNextBlockTick",tolua_AllToLua_cWorld_SetNextBlockTick00); tolua_function(tolua_S,"GetMaxSugarcaneHeight",tolua_AllToLua_cWorld_GetMaxSugarcaneHeight00); diff --git a/source/Bindings.h b/source/Bindings.h index a65d01ff1..00b4b9cdc 100644 --- a/source/Bindings.h +++ b/source/Bindings.h @@ -1,6 +1,6 @@ /* ** Lua binding: AllToLua -** Generated automatically by tolua++-1.0.92 on 06/12/12 23:23:39. +** Generated automatically by tolua++-1.0.92 on Wed Jun 13 02:33:15 2012. */ /* Exported function */ 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 { diff --git a/source/cWorld.h b/source/cWorld.h index 70b3ad88e..7c4e8b654 100644 --- a/source/cWorld.h +++ b/source/cWorld.h @@ -302,6 +302,7 @@ public: void CastThunderbolt (int a_X, int a_Y, int a_Z); //tolua_export void SetWeather ( eWeather a_Weather ); //tolua_export + void ChangeWeather(); //tolua_export eWeather GetWeather() { return m_Weather; }; //tolua_export cChunkGenerator & GetGenerator(void) { return m_Generator; } @@ -363,6 +364,7 @@ private: float m_SpawnMonsterRate; eWeather m_Weather; + int m_WeatherInterval; int m_MaxCactusHeight; int m_MaxSugarcaneHeight; -- cgit v1.2.3