summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--source/Bindings.cpp107
-rw-r--r--source/Bindings.h2
-rw-r--r--source/cClientHandle.cpp24
-rw-r--r--source/cWorld.cpp71
-rw-r--r--source/cWorld.h7
5 files changed, 191 insertions, 20 deletions
diff --git a/source/Bindings.cpp b/source/Bindings.cpp
index 9040c7070..045065396 100644
--- a/source/Bindings.cpp
+++ b/source/Bindings.cpp
@@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
-** Generated automatically by tolua++-1.0.92 on 11/09/11 15:37:09.
+** Generated automatically by tolua++-1.0.92 on 11/09/11 17:20:10.
*/
#ifndef __cplusplus
@@ -8746,6 +8746,108 @@ static int tolua_AllToLua_cWorld_GetName00(lua_State* tolua_S)
}
#endif //#ifndef TOLUA_DISABLE
+/* method: CastThunderbolt of class cWorld */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cWorld_CastThunderbolt00
+static int tolua_AllToLua_cWorld_CastThunderbolt00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"cWorld",0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,2,0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,3,0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,4,0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,5,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ cWorld* self = (cWorld*) tolua_tousertype(tolua_S,1,0);
+ int tolua_var_1 = ((int) tolua_tonumber(tolua_S,2,0));
+ int tolua_var_2 = ((int) tolua_tonumber(tolua_S,3,0));
+ int tolua_var_3 = ((int) tolua_tonumber(tolua_S,4,0));
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'CastThunderbolt'", NULL);
+#endif
+ {
+ self->CastThunderbolt(tolua_var_1,tolua_var_2,tolua_var_3);
+ }
+ }
+ return 0;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'CastThunderbolt'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* method: SetWeather of class cWorld */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cWorld_SetWeather00
+static int tolua_AllToLua_cWorld_SetWeather00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"cWorld",0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,2,0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,3,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ cWorld* self = (cWorld*) tolua_tousertype(tolua_S,1,0);
+ int tolua_var_4 = ((int) tolua_tonumber(tolua_S,2,0));
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SetWeather'", NULL);
+#endif
+ {
+ self->SetWeather(tolua_var_4);
+ }
+ }
+ return 0;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'SetWeather'.",&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)
+{
+#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 'GetWeather'", NULL);
+#endif
+ {
+ int tolua_ret = (int) self->GetWeather();
+ tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
+ }
+ }
+ return 1;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'GetWeather'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
/* method: Clear of class cInventory */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cInventory_Clear00
static int tolua_AllToLua_cInventory_Clear00(lua_State* tolua_S)
@@ -15839,6 +15941,9 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_function(tolua_S,"GrowTree",tolua_AllToLua_cWorld_GrowTree00);
tolua_function(tolua_S,"GetWorldSeed",tolua_AllToLua_cWorld_GetWorldSeed00);
tolua_function(tolua_S,"GetName",tolua_AllToLua_cWorld_GetName00);
+ tolua_function(tolua_S,"CastThunderbolt",tolua_AllToLua_cWorld_CastThunderbolt00);
+ tolua_function(tolua_S,"SetWeather",tolua_AllToLua_cWorld_SetWeather00);
+ tolua_function(tolua_S,"GetWeather",tolua_AllToLua_cWorld_GetWeather00);
tolua_endmodule(tolua_S);
tolua_cclass(tolua_S,"cInventory","cInventory","",NULL);
tolua_beginmodule(tolua_S,"cInventory");
diff --git a/source/Bindings.h b/source/Bindings.h
index 917cf80d1..dd6c6335f 100644
--- a/source/Bindings.h
+++ b/source/Bindings.h
@@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
-** Generated automatically by tolua++-1.0.92 on 11/09/11 15:37:10.
+** Generated automatically by tolua++-1.0.92 on 11/09/11 17:20:10.
*/
/* Exported function */
diff --git a/source/cClientHandle.cpp b/source/cClientHandle.cpp
index 4cc176db6..7ce7e38c0 100644
--- a/source/cClientHandle.cpp
+++ b/source/cClientHandle.cpp
@@ -59,7 +59,6 @@
#include "packets/cPacket_EntityEquipment.h"
#include "packets/cPacket_CreateInventoryAction.h"
#include "packets/cPacket_NewInvalidState.h"
-#include "packets/cPacket_Thunderbolt.h" //for testing.
#include "packets/cPacket_UseEntity.h"
#include "packets/cPacket_WindowClose.h"
#include "packets/cPacket_13.h"
@@ -693,17 +692,6 @@ void cClientHandle::HandlePacket( cPacket* a_Packet )
break;
case E_BLOCK_WORKBENCH:
{
- ////////////// For testing V
- cPacket_NewInvalidState RainPacket;
- RainPacket.m_Reason = 1; //begin rain
- cRoot::Get()->GetServer()->Broadcast( RainPacket );
- //also strike table with lightning for test purposes
- cPacket_Thunderbolt ThunderboltPacket;
- ThunderboltPacket.m_xLBPos = PacketData->m_PosX;
- ThunderboltPacket.m_yLBPos = PacketData->m_PosY;
- ThunderboltPacket.m_zLBPos = PacketData->m_PosZ;
- cRoot::Get()->GetServer()->Broadcast( ThunderboltPacket );
- ////////////// For testing ^
bPlaceBlock = false;
cWindow* Window = new cCraftingWindow( 0, true );
m_Player->OpenWindow( Window );
@@ -712,11 +700,6 @@ void cClientHandle::HandlePacket( cPacket* a_Packet )
case E_BLOCK_FURNACE:
case E_BLOCK_CHEST:
{
- ////////////// For testing V
- cPacket_NewInvalidState RainPacket;
- RainPacket.m_Reason = 2; //end rain
- cRoot::Get()->GetServer()->Broadcast( RainPacket );
- ////////////// For testing ^
bPlaceBlock = false;
cBlockEntity* BlockEntity = m_Player->GetWorld()->GetBlockEntity( PacketData->m_PosX, PacketData->m_PosY, PacketData->m_PosZ );
if( BlockEntity )
@@ -1091,6 +1074,13 @@ void cClientHandle::Tick(float a_Dt)
LoginResponse.m_Dimension = 0;
Send( LoginResponse );
+ // Send Weather if raining:
+ if ( (World->GetWeather() == 1) || (World->GetWeather() == 2) ) {
+ cPacket_NewInvalidState RainPacket;
+ RainPacket.m_Reason = 1; //begin rain
+ Send( RainPacket );
+ }
+
// Send position
Send( cPacket_PlayerMoveLook( m_Player ) );
diff --git a/source/cWorld.cpp b/source/cWorld.cpp
index 3457f47dd..95a640902 100644
--- a/source/cWorld.cpp
+++ b/source/cWorld.cpp
@@ -36,6 +36,8 @@
#include "packets/cPacket_TimeUpdate.h"
+#include "packets/cPacket_NewInvalidState.h"
+#include "packets/cPacket_Thunderbolt.h"
#include "Vector3d.h"
@@ -114,6 +116,7 @@ cWorld::cWorld( const char* a_WorldName )
: m_pState( new sWorldState )
, m_SpawnMonsterTime( 0.f )
, m_RSList ( 0 )
+ , m_Weather ( 0 )
{
LOG("cWorld::cWorld(%s)", a_WorldName);
m_pState->WorldName = a_WorldName;
@@ -288,6 +291,37 @@ cWorld::cWorld( const char* a_WorldName )
}
+void cWorld::SetWeather( int Weather )
+{
+ if (Weather == 2) { //thunder storm
+ m_Weather = 2;
+ 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
+ }
+ if (Weather == 1) { //rainstorm
+ m_Weather = 1;
+ cPacket_NewInvalidState WeatherPacket;
+ WeatherPacket.m_Reason = 1; //begin rain
+ Broadcast ( WeatherPacket );
+ }
+ if (Weather == 0) { //sunny
+ m_Weather = 0;
+ cPacket_NewInvalidState WeatherPacket;
+ WeatherPacket.m_Reason = 2; //stop rain
+ Broadcast ( WeatherPacket );
+ }
+}
+
+void cWorld::CastThunderbolt ( int X, int Y, int Z ) {
+ cPacket_Thunderbolt ThunderboltPacket;
+ ThunderboltPacket.m_xLBPos = X;
+ ThunderboltPacket.m_yLBPos = Y;
+ ThunderboltPacket.m_zLBPos = Z;
+ Broadcast( ThunderboltPacket );
+}
+
void cWorld::InitializeSpawn()
{
int ChunkX = 0, ChunkY = 0, ChunkZ = 0;
@@ -306,6 +340,7 @@ void cWorld::InitializeSpawn()
void cWorld::Tick(float a_Dt)
{
+ int randWeather = 0;
m_Time+=a_Dt/1000.f;
CurrentTick++;
@@ -355,6 +390,42 @@ void cWorld::Tick(float a_Dt)
m_LavaSimulator->Simulate(a_Dt);
UnlockChunks();
+
+////////////////Weather///////////////////////
+ if ( GetWeather() == 0 ) { //if sunny
+ if( CurrentTick % 19 == 0 ) { //every 20 ticks random weather
+ randWeather = (rand() %100);
+ if (randWeather == 0) {
+ LOG("Starting Rainstorm!");
+ SetWeather ( 1 );
+ } else if (randWeather == 1) {
+ LOG("Starting Thunderstorm!");
+ SetWeather ( 2 );
+ }
+ }
+ }
+
+ if ( GetWeather() != 0 ) { //if raining or thunderstorm
+ if( CurrentTick % 19 == 0 ) { //every 20 ticks random weather
+ randWeather = (rand() %49);
+ if (randWeather == 0) { //2% chance per second
+ LOG("Back to sunny!");
+ SetWeather ( 0 );
+ } else if ( (randWeather > 40) && (GetWeather() != 2) ) { //random chance for rainstorm to turn into thunderstorm.
+ LOG("Starting Thunderstorm!");
+ SetWeather ( 2 );
+ }
+ }
+ }
+
+ if ( GetWeather() == 2 ) { //if thunderstorm
+ if (rand() %99 == 0) { //1% chance per tick of thunderbolt
+ CastThunderbolt ( 0, 0, 0 ); //todo: find random possitions near players to cast thunderbolts.
+ }
+ }
+////////////////Weather///////////////////////
+
+
if( m_Time - m_LastSave > 60*5 ) // Save each 5 minutes
{
SaveAllChunks();
diff --git a/source/cWorld.h b/source/cWorld.h
index cff627d50..7278fa0a4 100644
--- a/source/cWorld.h
+++ b/source/cWorld.h
@@ -31,7 +31,6 @@ public:
std::vector<int> m_RSList;
-
static cWorld* GetWorld(); //tolua_export
// Return time in seconds
@@ -130,6 +129,11 @@ public:
void InitializeSpawn();
+ void CastThunderbolt ( int, int, int ); //tolua_export
+ void SetWeather ( int ); //tolua_export
+ int GetWeather() { return m_Weather; }; //tolua_export
+
+
private:
friend class cRoot;
cWorld( const char* a_WorldName );
@@ -172,4 +176,5 @@ private:
float m_SpawnMonsterRate;
unsigned int m_WorldSeed;
+ int m_Weather;
}; //tolua_export