summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfaketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-03-07 14:36:30 +0100
committerfaketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-03-07 14:36:30 +0100
commit787382caf8d3f7f8df4598b29586b44b7b071c53 (patch)
tree347e1249bbe371f820cf408d99549fb8734e0ac0
parentNo need to reset zlib (copypasta error) (diff)
downloadcuberite-787382caf8d3f7f8df4598b29586b44b7b071c53.tar
cuberite-787382caf8d3f7f8df4598b29586b44b7b071c53.tar.gz
cuberite-787382caf8d3f7f8df4598b29586b44b7b071c53.tar.bz2
cuberite-787382caf8d3f7f8df4598b29586b44b7b071c53.tar.lz
cuberite-787382caf8d3f7f8df4598b29586b44b7b071c53.tar.xz
cuberite-787382caf8d3f7f8df4598b29586b44b7b071c53.tar.zst
cuberite-787382caf8d3f7f8df4598b29586b44b7b071c53.zip
-rw-r--r--source/Bindings.cpp182
-rw-r--r--source/Bindings.h2
-rw-r--r--source/Defines.h30
-rw-r--r--source/cClientHandle.cpp1
-rw-r--r--source/cEntity.cpp2
-rw-r--r--source/cEntity.h7
-rw-r--r--source/cPlayer.cpp24
-rw-r--r--source/cPlayer.h27
-rw-r--r--source/cRoot.cpp4
-rw-r--r--source/cRoot.h2
-rw-r--r--source/cWorld.cpp76
-rw-r--r--source/cWorld.h55
-rw-r--r--source/packets/cPacket_CreativeInventoryAction.cpp1
13 files changed, 306 insertions, 107 deletions
diff --git a/source/Bindings.cpp b/source/Bindings.cpp
index 6368dc156..8329dbab5 100644
--- a/source/Bindings.cpp
+++ b/source/Bindings.cpp
@@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
-** Generated automatically by tolua++-1.0.92 on 03/04/12 14:40:53.
+** Generated automatically by tolua++-1.0.92 on 03/07/12 14:22:38.
*/
#ifndef __cplusplus
@@ -5116,7 +5116,7 @@ static int tolua_AllToLua_cPlayer_GetGameMode00(lua_State* tolua_S)
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetGameMode'", NULL);
#endif
{
- int tolua_ret = (int) self->GetGameMode();
+ eGameMode tolua_ret = (eGameMode) self->GetGameMode();
tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
}
}
@@ -5305,7 +5305,7 @@ static int tolua_AllToLua_cPlayer_SetGameMode00(lua_State* tolua_S)
#endif
{
cPlayer* self = (cPlayer*) tolua_tousertype(tolua_S,1,0);
- int a_GameMode = ((int) tolua_tonumber(tolua_S,2,0));
+ eGameMode a_GameMode = ((eGameMode) (int) tolua_tonumber(tolua_S,2,0));
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SetGameMode'", NULL);
#endif
@@ -9473,6 +9473,38 @@ static int tolua_AllToLua_cWorld_GetTime00(lua_State* tolua_S)
}
#endif //#ifndef TOLUA_DISABLE
+/* method: GetGameMode of class cWorld */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cWorld_GetGameMode00
+static int tolua_AllToLua_cWorld_GetGameMode00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"const cWorld",0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,2,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ const cWorld* self = (const cWorld*) tolua_tousertype(tolua_S,1,0);
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetGameMode'", NULL);
+#endif
+ {
+ eGameMode tolua_ret = (eGameMode) self->GetGameMode();
+ tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
+ }
+ }
+ return 1;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'GetGameMode'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
/* method: SetWorldTime of class cWorld */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cWorld_SetWorldTime00
static int tolua_AllToLua_cWorld_SetWorldTime00(lua_State* tolua_S)
@@ -9542,6 +9574,71 @@ static int tolua_AllToLua_cWorld_GetHeight00(lua_State* tolua_S)
}
#endif //#ifndef TOLUA_DISABLE
+/* method: GetMaxPlayers of class cWorld */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cWorld_GetMaxPlayers00
+static int tolua_AllToLua_cWorld_GetMaxPlayers00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"const cWorld",0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,2,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ const cWorld* self = (const cWorld*) tolua_tousertype(tolua_S,1,0);
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetMaxPlayers'", NULL);
+#endif
+ {
+ unsigned int tolua_ret = (unsigned int) self->GetMaxPlayers();
+ tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
+ }
+ }
+ return 1;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'GetMaxPlayers'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* method: SetMaxPlayers of class cWorld */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cWorld_SetMaxPlayers00
+static int tolua_AllToLua_cWorld_SetMaxPlayers00(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 iMax = ((int) tolua_tonumber(tolua_S,2,0));
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SetMaxPlayers'", NULL);
+#endif
+ {
+ self->SetMaxPlayers(iMax);
+ }
+ }
+ return 0;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'SetMaxPlayers'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
/* method: GetNumPlayers of class cWorld */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cWorld_GetNumPlayers00
static int tolua_AllToLua_cWorld_GetNumPlayers00(lua_State* tolua_S)
@@ -9608,6 +9705,55 @@ static int tolua_AllToLua_cWorld_GetPlayer00(lua_State* tolua_S)
}
#endif //#ifndef TOLUA_DISABLE
+/* method: UpdateSign of class cWorld */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cWorld_UpdateSign00
+static int tolua_AllToLua_cWorld_UpdateSign00(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_iscppstring(tolua_S,5,0,&tolua_err) ||
+ !tolua_iscppstring(tolua_S,6,0,&tolua_err) ||
+ !tolua_iscppstring(tolua_S,7,0,&tolua_err) ||
+ !tolua_iscppstring(tolua_S,8,0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,9,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ cWorld* self = (cWorld*) tolua_tousertype(tolua_S,1,0);
+ int a_X = ((int) tolua_tonumber(tolua_S,2,0));
+ int a_Y = ((int) tolua_tonumber(tolua_S,3,0));
+ int a_Z = ((int) tolua_tonumber(tolua_S,4,0));
+ const AString a_Line1 = ((const AString) tolua_tocppstring(tolua_S,5,0));
+ const AString a_Line2 = ((const AString) tolua_tocppstring(tolua_S,6,0));
+ const AString a_Line3 = ((const AString) tolua_tocppstring(tolua_S,7,0));
+ const AString a_Line4 = ((const AString) tolua_tocppstring(tolua_S,8,0));
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'UpdateSign'", NULL);
+#endif
+ {
+ self->UpdateSign(a_X,a_Y,a_Z,a_Line1,a_Line2,a_Line3,a_Line4);
+ tolua_pushcppstring(tolua_S,(const char*)a_Line1);
+ tolua_pushcppstring(tolua_S,(const char*)a_Line2);
+ tolua_pushcppstring(tolua_S,(const char*)a_Line3);
+ tolua_pushcppstring(tolua_S,(const char*)a_Line4);
+ }
+ }
+ return 4;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'UpdateSign'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
/* method: SetBlock of class cWorld */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cWorld_SetBlock00
static int tolua_AllToLua_cWorld_SetBlock00(lua_State* tolua_S)
@@ -10288,14 +10434,14 @@ static int tolua_AllToLua_cWorld_CastThunderbolt00(lua_State* tolua_S)
#endif
{
cWorld* self = (cWorld*) tolua_tousertype(tolua_S,1,0);
- int tolua_var_2 = ((int) tolua_tonumber(tolua_S,2,0));
- int tolua_var_3 = ((int) tolua_tonumber(tolua_S,3,0));
- int tolua_var_4 = ((int) tolua_tonumber(tolua_S,4,0));
+ int a_X = ((int) tolua_tonumber(tolua_S,2,0));
+ int a_Y = ((int) tolua_tonumber(tolua_S,3,0));
+ int a_Z = ((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_2,tolua_var_3,tolua_var_4);
+ self->CastThunderbolt(a_X,a_Y,a_Z);
}
}
return 0;
@@ -10323,12 +10469,12 @@ static int tolua_AllToLua_cWorld_SetWeather00(lua_State* tolua_S)
#endif
{
cWorld* self = (cWorld*) tolua_tousertype(tolua_S,1,0);
- int tolua_var_5 = ((int) tolua_tonumber(tolua_S,2,0));
+ eWeather a_Weather = ((eWeather) (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_5);
+ self->SetWeather(a_Weather);
}
}
return 0;
@@ -10359,7 +10505,7 @@ static int tolua_AllToLua_cWorld_GetWeather00(lua_State* tolua_S)
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetWeather'", NULL);
#endif
{
- int tolua_ret = (int) self->GetWeather();
+ eWeather tolua_ret = (eWeather) self->GetWeather();
tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
}
}
@@ -12191,23 +12337,24 @@ static int tolua_AllToLua_cRoot_GetWorld01(lua_State* tolua_S)
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"cRoot",0,&tolua_err) ||
- !tolua_isstring(tolua_S,2,0,&tolua_err) ||
+ !tolua_iscppstring(tolua_S,2,0,&tolua_err) ||
!tolua_isnoobj(tolua_S,3,&tolua_err)
)
goto tolua_lerror;
else
{
cRoot* self = (cRoot*) tolua_tousertype(tolua_S,1,0);
- const char* a_WorldName = ((const char*) tolua_tostring(tolua_S,2,0));
+ const AString a_WorldName = ((const AString) tolua_tocppstring(tolua_S,2,0));
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetWorld'", NULL);
#endif
{
cWorld* tolua_ret = (cWorld*) self->GetWorld(a_WorldName);
tolua_pushusertype(tolua_S,(void*)tolua_ret,"cWorld");
+ tolua_pushcppstring(tolua_S,(const char*)a_WorldName);
}
}
- return 1;
+ return 2;
tolua_lerror:
return tolua_AllToLua_cRoot_GetWorld00(tolua_S);
}
@@ -17317,6 +17464,11 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_function(tolua_S,"IsValidBlock",tolua_AllToLua_IsValidBlock00);
tolua_function(tolua_S,"IsValidItem",tolua_AllToLua_IsValidItem00);
tolua_function(tolua_S,"AddDirection",tolua_AllToLua_AddDirection00);
+ tolua_constant(tolua_S,"eGameMode_Survival",eGameMode_Survival);
+ tolua_constant(tolua_S,"eGameMode_Creative",eGameMode_Creative);
+ tolua_constant(tolua_S,"eWeather_Sunny",eWeather_Sunny);
+ tolua_constant(tolua_S,"eWeather_Rain",eWeather_Rain);
+ tolua_constant(tolua_S,"eWeather_ThunderStorm",eWeather_ThunderStorm);
tolua_function(tolua_S,"GetTime",tolua_AllToLua_GetTime00);
tolua_function(tolua_S,"GetChar",tolua_AllToLua_GetChar00);
tolua_cclass(tolua_S,"cStringMap","cStringMap","",NULL);
@@ -17605,10 +17757,14 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_beginmodule(tolua_S,"cWorld");
tolua_function(tolua_S,"GetWorld",tolua_AllToLua_cWorld_GetWorld00);
tolua_function(tolua_S,"GetTime",tolua_AllToLua_cWorld_GetTime00);
+ tolua_function(tolua_S,"GetGameMode",tolua_AllToLua_cWorld_GetGameMode00);
tolua_function(tolua_S,"SetWorldTime",tolua_AllToLua_cWorld_SetWorldTime00);
tolua_function(tolua_S,"GetHeight",tolua_AllToLua_cWorld_GetHeight00);
+ tolua_function(tolua_S,"GetMaxPlayers",tolua_AllToLua_cWorld_GetMaxPlayers00);
+ tolua_function(tolua_S,"SetMaxPlayers",tolua_AllToLua_cWorld_SetMaxPlayers00);
tolua_function(tolua_S,"GetNumPlayers",tolua_AllToLua_cWorld_GetNumPlayers00);
tolua_function(tolua_S,"GetPlayer",tolua_AllToLua_cWorld_GetPlayer00);
+ tolua_function(tolua_S,"UpdateSign",tolua_AllToLua_cWorld_UpdateSign00);
tolua_function(tolua_S,"SetBlock",tolua_AllToLua_cWorld_SetBlock00);
tolua_function(tolua_S,"FastSetBlock",tolua_AllToLua_cWorld_FastSetBlock00);
tolua_function(tolua_S,"GetBlock",tolua_AllToLua_cWorld_GetBlock00);
diff --git a/source/Bindings.h b/source/Bindings.h
index eb2915d3f..e86f8c962 100644
--- a/source/Bindings.h
+++ b/source/Bindings.h
@@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
-** Generated automatically by tolua++-1.0.92 on 03/04/12 14:40:54.
+** Generated automatically by tolua++-1.0.92 on 03/07/12 14:22:38.
*/
/* Exported function */
diff --git a/source/Defines.h b/source/Defines.h
index bd35ec3f4..5f49362b2 100644
--- a/source/Defines.h
+++ b/source/Defines.h
@@ -122,12 +122,12 @@ inline void AddDirection( int & a_X, unsigned char & a_Y, int & a_Z, char a_Dire
#define MAX(a,b) (((a)>(b))?(a):(b))
inline void EulerToVector( float a_Pan, float a_Pitch, float & a_X, float & a_Y, float & a_Z )
{
-// a_X = sinf ( a_Pan / 180 * PI ) * cosf ( a_Pitch / 180 * PI );
-// a_Y = -sinf ( a_Pitch / 180 * PI );
-// a_Z = -cosf ( a_Pan / 180 * PI ) * cosf ( a_Pitch / 180 * PI );
-a_X = cos(a_Pan / 180 * PI)*cos(a_Pitch / 180 * PI);
-a_Y = sin(a_Pan / 180 * PI)*cos(a_Pitch / 180 * PI);
-a_Z = sin(a_Pitch / 180 * PI);
+ // a_X = sinf ( a_Pan / 180 * PI ) * cosf ( a_Pitch / 180 * PI );
+ // a_Y = -sinf ( a_Pitch / 180 * PI );
+ // a_Z = -cosf ( a_Pan / 180 * PI ) * cosf ( a_Pitch / 180 * PI );
+ a_X = cos(a_Pan / 180 * PI)*cos(a_Pitch / 180 * PI);
+ a_Y = sin(a_Pan / 180 * PI)*cos(a_Pitch / 180 * PI);
+ a_Z = sin(a_Pitch / 180 * PI);
}
inline void VectorToEuler( float a_X, float a_Y, float a_Z, float & a_Pan, float & a_Pitch )
@@ -179,4 +179,20 @@ namespace ItemCategory
|| a_ItemID == E_ITEM_GOLD_SWORD
|| a_ItemID == E_ITEM_DIAMOND_SWORD;
}
-} \ No newline at end of file
+}
+
+//tolua_begin
+enum eGameMode
+{
+ eGameMode_Survival = 0,
+ eGameMode_Creative = 1,
+};
+
+enum eWeather
+{
+ eWeather_Sunny = 0,
+ eWeather_Rain = 1,
+ eWeather_ThunderStorm = 2,
+
+};
+//tolua_end \ No newline at end of file
diff --git a/source/cClientHandle.cpp b/source/cClientHandle.cpp
index ee9f0ab3a..c722b4305 100644
--- a/source/cClientHandle.cpp
+++ b/source/cClientHandle.cpp
@@ -187,7 +187,6 @@ cClientHandle::~cClientHandle()
if (m_Player != NULL)
{
- m_Player->SetClientHandle(NULL);
m_Player->Destroy();
m_Player = NULL;
}
diff --git a/source/cEntity.cpp b/source/cEntity.cpp
index d75c35002..f6627fd20 100644
--- a/source/cEntity.cpp
+++ b/source/cEntity.cpp
@@ -181,6 +181,8 @@ void cEntity::Destroy()
m_World->BroadcastToChunk(m_ChunkX, m_ChunkY, m_ChunkZ, cPacket_DestroyEntity(this));
m_bDestroyed = true;
+
+ Destroyed();
}
diff --git a/source/cEntity.h b/source/cEntity.h
index 0165276b6..58c0b69f4 100644
--- a/source/cEntity.h
+++ b/source/cEntity.h
@@ -87,15 +87,15 @@ public: //tolua_export
void SetPosX( const double & a_PosX ); //tolua_export
void SetPosY( const double & a_PosY ); //tolua_export
void SetPosZ( const double & a_PosZ ); //tolua_export
- void SetPosition( const double & a_PosX, const double & a_PosY, const double & a_PosZ ); //tolua_export
+ void SetPosition( const double & a_PosX, const double & a_PosY, const double & a_PosZ );//tolua_export
void SetPosition( const Vector3d & a_Pos ); //tolua_export
void SetRot( const Vector3f & a_Rot ); //tolua_export
void SetRotation( float a_Rotation ); //tolua_export
void SetPitch( float a_Pitch ); //tolua_export
void SetRoll( float a_Roll ); //tolua_export
- inline int GetUniqueID(void) const { return m_UniqueID; } //tolua_export
- inline bool IsDestroyed(void) const { return m_bDestroyed; } //tolua_export
+ inline int GetUniqueID(void) const { return m_UniqueID; } //tolua_export
+ inline bool IsDestroyed(void) const { return m_bDestroyed; } //tolua_export
void Destroy(); //tolua_export
void RemoveFromChunk(void); // for internal use in cChunk
@@ -108,6 +108,7 @@ public: //tolua_export
void WrapRotation();
protected:
+ virtual void Destroyed() {} // Called after the entity has been destroyed
void SetWorld( cWorld* a_World ) { m_World = a_World; }
void MoveToCorrectChunk(bool a_bIgnoreOldChunk = false);
diff --git a/source/cPlayer.cpp b/source/cPlayer.cpp
index 673d0b41a..c6893b076 100644
--- a/source/cPlayer.cpp
+++ b/source/cPlayer.cpp
@@ -65,7 +65,7 @@ struct cPlayer::sPlayerState
};
cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName)
- : m_GameMode( 0 )
+ : m_GameMode( eGameMode_Survival )
, m_IP("")
, m_LastBlockActionTime( 0 )
, m_LastBlockActionCnt( 0 )
@@ -132,7 +132,6 @@ cPlayer::~cPlayer(void)
m_ClientHandle = NULL;
- CloseWindow(-1);
delete m_Inventory;
m_Inventory = NULL;
@@ -147,6 +146,16 @@ cPlayer::~cPlayer(void)
+void cPlayer::Destroyed()
+{
+ CloseWindow(-1);
+ m_ClientHandle = NULL;
+}
+
+
+
+
+
cPacket * cPlayer::GetSpawnPacket(void) const
{
LOGD("cPlayer::GetSpawnPacket for \"%s\" at pos {%.2f, %.2f, %.2f}",
@@ -431,6 +440,7 @@ void cPlayer::CloseWindow(char a_WindowType)
}
if (m_CurrentWindow)
{
+ // FIXME: If the player entity is destroyed while having a chest window open, the chest will not close
if (a_WindowType == 1 && strcmp(m_CurrentWindow->GetWindowTitle().c_str(), "UberChest") == 0) { // Chest
cBlockEntity *block = m_CurrentWindow->GetOwner()->GetEntity();
cPacket_BlockAction ChestClose;
@@ -469,14 +479,14 @@ void cPlayer::SetLastBlockActionCnt( int a_LastBlockActionCnt )
-void cPlayer::SetGameMode( int a_GameMode )
+void cPlayer::SetGameMode( eGameMode a_GameMode )
{
if ( (a_GameMode < 2) && (a_GameMode >= 0) )
{
if (m_GameMode != a_GameMode)
{
cInventory *OldInventory = 0;
- if(m_GameMode == 0)
+ if(m_GameMode == eGameMode_Survival)
OldInventory = m_Inventory;
else
OldInventory = m_CreativeInventory;
@@ -497,7 +507,7 @@ void cPlayer::SetGameMode( int a_GameMode )
-void cPlayer::LoginSetGameMode( int a_GameMode )
+void cPlayer::LoginSetGameMode( eGameMode a_GameMode )
{
m_GameMode = a_GameMode;
}
@@ -998,9 +1008,9 @@ cPlayer::StringList cPlayer::GetResolvedPermissions()
-const char* cPlayer::GetLoadedWorldName()
+const AString & cPlayer::GetLoadedWorldName()
{
- return m_pState->LoadedWorldName.c_str();
+ return m_pState->LoadedWorldName;
}
diff --git a/source/cPlayer.h b/source/cPlayer.h
index 105a4924c..ef94b3fc7 100644
--- a/source/cPlayer.h
+++ b/source/cPlayer.h
@@ -4,6 +4,7 @@
#include "cPawn.h"
#include "cSurvivalInventory.h"
#include "cCreativeInventory.h"
+#include "Defines.h"
@@ -21,9 +22,10 @@ class cClientHandle;
class cPlayer : public cPawn //tolua_export
{ //tolua_export
public:
+ typedef cPawn super;
CLASS_PROTOTYPE();
- cPlayer(cClientHandle* a_Client, const AString & a_PlayerName);
+ cPlayer(cClientHandle * a_Client, const AString & a_PlayerName);
virtual ~cPlayer();
virtual void Initialize( cWorld* a_World ); //tolua_export
@@ -37,18 +39,18 @@ public:
Vector3d GetEyePosition(); //tolua_export
inline bool GetFlying() { return m_bTouchGround; } //tolua_export
inline const double & GetStance() { return m_Stance; } //tolua_export
- inline cInventory & GetInventory() { if(GetGameMode() == 0) return *m_Inventory; else return *m_CreativeInventory; } //tolua_export
+ inline cInventory & GetInventory() { if(GetGameMode() == eGameMode_Survival) return *m_Inventory; else return *m_CreativeInventory; } //tolua_export
virtual void TeleportTo( const double & a_PosX, const double & a_PosY, const double & a_PosZ ); //tolua_export
- int GetGameMode() { return m_GameMode; } //tolua_export
+ eGameMode GetGameMode() { return m_GameMode; } //tolua_export
std::string GetIP() { return m_IP; } //tolua_export
float GetLastBlockActionTime() { return m_LastBlockActionTime; } //tolua_export
int GetLastBlockActionCnt() { return m_LastBlockActionCnt; } //tolua_export
void SetLastBlockActionCnt( int ); //tolua_export
void SetLastBlockActionTime(); //tolua_export
- void SetGameMode( int a_GameMode ); //tolua_export
- void LoginSetGameMode( int a_GameMode );
+ void SetGameMode( eGameMode a_GameMode ); //tolua_export
+ void LoginSetGameMode( eGameMode a_GameMode );
void SetIP( std::string a_IP );
// Tries to move to a new position, with collision checks and stuff
@@ -58,13 +60,12 @@ public:
void OpenWindow( cWindow* a_Window );
void CloseWindow(char a_WindowType);
- cClientHandle* GetClientHandle() { return m_ClientHandle; } //tolua_export
- void SetClientHandle( cClientHandle* a_Client ) { m_ClientHandle = a_Client; }
+ cClientHandle * GetClientHandle() { return m_ClientHandle; } //tolua_export
void SendMessage( const char* a_Message ); //tolua_export
- const AString & GetName(void) const; //tolua_export
- void SetName(const AString & a_Name); //tolua_export
+ const AString & GetName(void) const; //tolua_export
+ void SetName(const AString & a_Name); //tolua_export
typedef std::list< cGroup* > GroupList;
typedef std::list< std::string > StringList;
@@ -75,7 +76,7 @@ public:
StringList GetResolvedPermissions(); // >> EXPORTED IN MANUALBINDINGS <<
bool IsInGroup( const char* a_Group ); //tolua_export
- AString GetColor(void) const; //tolua_export
+ AString GetColor(void) const; //tolua_export
void TossItem( bool a_bDraggingItem, int a_Amount = 1 ); //tolua_export
@@ -94,12 +95,14 @@ public:
bool LoadFromDisk();
void LoadPermissionsFromDisk(); //tolua_export
- const char* GetLoadedWorldName();
+ const AString & GetLoadedWorldName();
void UseEquippedItem();
protected:
+ virtual void Destroyed();
+
struct sPlayerState;
sPlayerState* m_pState;
@@ -121,7 +124,7 @@ protected:
float m_LastBlockActionTime;
int m_LastBlockActionCnt;
- int m_GameMode;
+ eGameMode m_GameMode;
std::string m_IP;
long long m_LastPlayerListTime;
diff --git a/source/cRoot.cpp b/source/cRoot.cpp
index 4178a4569..165c908ae 100644
--- a/source/cRoot.cpp
+++ b/source/cRoot.cpp
@@ -26,7 +26,7 @@
cRoot* cRoot::s_Root = 0;
-typedef std::map< std::string, cWorld* > WorldMap;
+typedef std::map< AString, cWorld* > WorldMap;
struct cRoot::sRootState
{
cWorld* pDefaultWorld;
@@ -291,7 +291,7 @@ cWorld* cRoot::GetDefaultWorld()
-cWorld* cRoot::GetWorld( const char* a_WorldName )
+cWorld* cRoot::GetWorld( const AString & a_WorldName )
{
WorldMap::iterator itr = m_pState->WorldsByName.find( a_WorldName );
if( itr != m_pState->WorldsByName.end() )
diff --git a/source/cRoot.h b/source/cRoot.h
index 0b5e9c7af..85b12eb12 100644
--- a/source/cRoot.h
+++ b/source/cRoot.h
@@ -37,7 +37,7 @@ public:
cServer* GetServer() { return m_Server; } //tolua_export
OBSOLETE cWorld* GetWorld(); //tolua_export
cWorld* GetDefaultWorld(); //tolua_export
- cWorld* GetWorld( const char* a_WorldName ); //tolua_export
+ cWorld* GetWorld( const AString & a_WorldName ); //tolua_export
cMonsterConfig *GetMonsterConfig() { return m_MonsterConfig;}
cGroupManager* GetGroupManager() { return m_GroupManager; } //tolua_export
diff --git a/source/cWorld.cpp b/source/cWorld.cpp
index 33219ae95..de79d5d76 100644
--- a/source/cWorld.cpp
+++ b/source/cWorld.cpp
@@ -179,7 +179,7 @@ cWorld::~cWorld()
cWorld::cWorld( const AString & a_WorldName )
: m_SpawnMonsterTime( 0.f )
, m_RSList ( 0 )
- , m_Weather ( 0 )
+ , m_Weather ( eWeather_Sunny )
{
LOG("cWorld::cWorld(%s)", a_WorldName.c_str());
m_WorldName = a_WorldName;
@@ -191,7 +191,7 @@ cWorld::cWorld( const AString & a_WorldName )
m_SpawnY = cChunk::c_ChunkHeight;
m_SpawnZ = (double)((r1.randInt()%1000)-500);
m_WorldSeed = r1.randInt();
- m_GameMode = 0;
+ m_GameMode = eGameMode_Creative;
AString GeneratorName;
AString StorageSchema("Default");
@@ -203,7 +203,7 @@ cWorld::cWorld( const AString & a_WorldName )
m_SpawnY = IniFile.GetValueF("SpawnPosition", "Y", m_SpawnY );
m_SpawnZ = IniFile.GetValueF("SpawnPosition", "Z", m_SpawnZ );
m_WorldSeed = IniFile.GetValueI("Seed", "Seed", m_WorldSeed );
- m_GameMode = IniFile.GetValueI("GameMode", "GameMode", m_GameMode );
+ m_GameMode = (eGameMode)IniFile.GetValueI("GameMode", "GameMode", m_GameMode );
GeneratorName = IniFile.GetValue("Generator", "GeneratorName", GeneratorName);
StorageSchema = IniFile.GetValue("Storage", "Schema", StorageSchema);
}
@@ -359,26 +359,38 @@ cWorld::cWorld( const AString & a_WorldName )
-void cWorld::SetWeather( int Weather )
+void cWorld::SetWeather( eWeather a_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 );
+ 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:
+ {
+ m_Weather = a_Weather;
+ cPacket_NewInvalidState WeatherPacket;
+ WeatherPacket.m_Reason = 1; //begin rain
+ Broadcast ( WeatherPacket );
+ }
+ break;
+ case eWeather_ThunderStorm:
+ {
+ 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
+ }
+ break;
+ default:
+ LOGWARN("Trying to set unknown weather %d", a_Weather );
+ break;
}
}
@@ -386,13 +398,13 @@ void cWorld::SetWeather( int Weather )
-void cWorld::CastThunderbolt ( int X, int Y, int Z )
+void cWorld::CastThunderbolt ( int a_X, int a_Y, int a_Z )
{
cPacket_Thunderbolt ThunderboltPacket;
- ThunderboltPacket.m_xLBPos = X;
- ThunderboltPacket.m_yLBPos = Y;
- ThunderboltPacket.m_zLBPos = Z;
- Broadcast( ThunderboltPacket );
+ 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
}
@@ -556,12 +568,12 @@ void cWorld::TickWeather(float a_Dt)
if (randWeather == 0)
{
LOG("Starting Rainstorm!");
- SetWeather ( 1 );
+ SetWeather ( eWeather_Rain );
}
else if (randWeather == 1)
{
LOG("Starting Thunderstorm!");
- SetWeather ( 2 );
+ SetWeather ( eWeather_ThunderStorm );
}
}
}
@@ -574,12 +586,12 @@ void cWorld::TickWeather(float a_Dt)
if (randWeather == 0) //2% chance per second
{
LOG("Back to sunny!");
- SetWeather ( 0 );
+ SetWeather ( eWeather_Sunny );
}
else if ( (randWeather > 4000) && (GetWeather() != 2) ) // random chance for rainstorm to turn into thunderstorm.
{
LOG("Starting Thunderstorm!");
- SetWeather ( 2 );
+ SetWeather ( eWeather_ThunderStorm );
}
}
}
@@ -588,7 +600,7 @@ void cWorld::TickWeather(float a_Dt)
{
if (m_TickRand.randInt() % 199 == 0) // 0.5% chance per tick of thunderbolt
{
- CastThunderbolt ( 0, 0, 0 ); // todo: find random possitions near players to cast thunderbolts.
+ CastThunderbolt ( 0, 0, 0 ); // TODO: find random possitions near players to cast thunderbolts.
}
}
}
diff --git a/source/cWorld.h b/source/cWorld.h
index bd562ce6f..093fc149f 100644
--- a/source/cWorld.h
+++ b/source/cWorld.h
@@ -16,6 +16,7 @@
#include "cChunkGenerator.h"
#include "Vector3i.h"
#include "ChunkSender.h"
+#include "Defines.h"
@@ -54,9 +55,9 @@ public:
{
return m_Time;
}
- long long GetWorldTime(void) const { return m_WorldTime; } //tolua_export
+ long long GetWorldTime(void) const { return m_WorldTime; } //tolua_export
- int GetGameMode(void) const { return m_GameMode; } //return gamemode for world
+ eGameMode GetGameMode(void) const { return m_GameMode; } //tolua_export
void SetWorldTime(long long a_WorldTime) { m_WorldTime = a_WorldTime; } //tolua_export
@@ -85,11 +86,11 @@ public:
void CollectPickupsByPlayer(cPlayer * a_Player);
// MOTD
- const AString & GetDescription(void) const {return m_Description; }
+ const AString & GetDescription(void) const {return m_Description; } // FIXME: This should not be in cWorld
// Max Players
- unsigned int GetMaxPlayers(void) const {return m_MaxPlayers; }
- void SetMaxPlayers(int iMax);
+ unsigned int GetMaxPlayers(void) const {return m_MaxPlayers; } //tolua_export
+ void SetMaxPlayers(int iMax); //tolua_export
void AddPlayer( cPlayer* a_Player );
void RemovePlayer( cPlayer* a_Player );
@@ -100,7 +101,7 @@ public:
unsigned int GetNumPlayers(); //tolua_export
// TODO: This interface is dangerous - rewrite to DoWithPlayer(playername, action)
- cPlayer * GetPlayer( const char * a_PlayerName ); //tolua_export
+ cPlayer * GetPlayer( const char * a_PlayerName ); //tolua_export
// TODO: This interface is dangerous - rewrite to DoWithClosestPlayer(pos, sight, action)
cPlayer * FindClosestPlayer(const Vector3f & a_Pos, float a_SightLimit);
@@ -148,7 +149,7 @@ public:
/// Marks the chunk as failed-to-load:
void ChunkLoadFailed(int a_ChunkX, int a_ChunkY, int a_ChunkZ);
- void UpdateSign(int a_X, int a_Y, int a_Z, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4);
+ void UpdateSign(int a_X, int a_Y, int a_Z, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4); //tolua_export
/// Marks (a_Stay == true) or unmarks (a_Stay == false) chunks as non-unloadable. To be used only by cChunkStay!
void ChunksStay(const cChunkCoordsList & a_Chunks, bool a_Stay = true);
@@ -156,20 +157,20 @@ public:
// TODO: Export to Lua
bool DoWithEntity( int a_UniqueID, cEntityCallback & a_Callback );
- void SetBlock( int a_X, int a_Y, int a_Z, char a_BlockType, char a_BlockMeta ); //tolua_export
- void FastSetBlock( int a_X, int a_Y, int a_Z, char a_BlockType, char a_BlockMeta ); //tolua_export
- char GetBlock( int a_X, int a_Y, int a_Z ); //tolua_export
- char GetBlock( const Vector3i & a_Pos ) { return GetBlock( a_Pos.x, a_Pos.y, a_Pos.z ); } //tolua_export
- char GetBlockMeta( int a_X, int a_Y, int a_Z ); //tolua_export
- char GetBlockMeta( const Vector3i & a_Pos ) { return GetBlockMeta( a_Pos.x, a_Pos.y, a_Pos.z ); } //tolua_export
- void SetBlockMeta( int a_X, int a_Y, int a_Z, char a_MetaData ); //tolua_export
+ void SetBlock( int a_X, int a_Y, int a_Z, char a_BlockType, char a_BlockMeta ); //tolua_export
+ void FastSetBlock( int a_X, int a_Y, int a_Z, char a_BlockType, char a_BlockMeta ); //tolua_export
+ char GetBlock( int a_X, int a_Y, int a_Z ); //tolua_export
+ char GetBlock( const Vector3i & a_Pos ) { return GetBlock( a_Pos.x, a_Pos.y, a_Pos.z ); } //tolua_export
+ char GetBlockMeta( int a_X, int a_Y, int a_Z ); //tolua_export
+ char GetBlockMeta( const Vector3i & a_Pos ) { return GetBlockMeta( a_Pos.x, a_Pos.y, a_Pos.z ); } //tolua_export
+ void SetBlockMeta( int a_X, int a_Y, int a_Z, char a_MetaData ); //tolua_export
void SetBlockMeta( const Vector3i & a_Pos, char a_MetaData ) { SetBlockMeta( a_Pos.x, a_Pos.y, a_Pos.z, a_MetaData ); } //tolua_export
- bool DigBlock( int a_X, int a_Y, int a_Z, cItem & a_PickupItem ); //tolua_export
- void SendBlockTo( int a_X, int a_Y, int a_Z, cPlayer* a_Player ); //tolua_export
+ bool DigBlock( int a_X, int a_Y, int a_Z, cItem & a_PickupItem ); //tolua_export
+ void SendBlockTo( int a_X, int a_Y, int a_Z, cPlayer* a_Player ); //tolua_export
- const double & GetSpawnX() { return m_SpawnX; } //tolua_export
- const double & GetSpawnY(); //tolua_export
- const double & GetSpawnZ() { return m_SpawnZ; } //tolua_export
+ const double & GetSpawnX() { return m_SpawnX; } //tolua_export
+ const double & GetSpawnY(); //tolua_export
+ const double & GetSpawnZ() { return m_SpawnZ; } //tolua_export
inline cSimulatorManager *GetSimulatorManager() { return m_SimulatorManager; }
inline cWaterSimulator *GetWaterSimulator() { return m_WaterSimulator; }
@@ -182,10 +183,10 @@ public:
/// a_Player is using block entity at [x, y, z], handle that:
void UseBlockEntity(cPlayer * a_Player, int a_X, int a_Y, int a_Z) {m_ChunkMap->UseBlockEntity(a_Player, a_X, a_Y, a_Z); }
- void GrowTree( int a_X, int a_Y, int a_Z ); //tolua_export
+ void GrowTree( int a_X, int a_Y, int a_Z ); //tolua_export
unsigned int GetWorldSeed(void) const { return m_WorldSeed; } //tolua_export
- const AString & GetName(void) const {return m_WorldName; } //tolua_export
+ const AString & GetName(void) const { return m_WorldName; } //tolua_export
inline static void AbsoluteToRelative( int & a_X, int & a_Y, int & a_Z, int & a_ChunkX, int & a_ChunkY, int & a_ChunkZ )
{
@@ -214,7 +215,7 @@ public:
if(a_Z < 0 && a_Z % cChunk::c_ChunkWidth != 0) a_ChunkZ--;
}
- void SaveAllChunks(); //tolua_export
+ void SaveAllChunks(); //tolua_export
int GetNumChunks() const; //tolua_export
void Tick(float a_Dt);
@@ -224,9 +225,9 @@ public:
void InitializeSpawn();
- void CastThunderbolt ( int, int, int ); //tolua_export
- void SetWeather ( int ); //tolua_export
- int GetWeather() { return m_Weather; }; //tolua_export
+ void CastThunderbolt (int a_X, int a_Y, int a_Z); //tolua_export
+ void SetWeather ( eWeather a_Weather ); //tolua_export
+ eWeather GetWeather() { return m_Weather; }; //tolua_export
cChunkGenerator & GetGenerator(void) { return m_Generator; }
cWorldStorage & GetStorage (void) { return m_Storage; }
@@ -248,7 +249,7 @@ private:
static float m_Time; // Time in seconds
long long m_WorldTime; // Time in seconds*20, this is sent to clients (is wrapped)
unsigned long long CurrentTick;
- int m_GameMode;
+ eGameMode m_GameMode;
float m_WorldTimeFraction; // When this > 1.f m_WorldTime is incremented by 20
// The cRedstone class simulates redstone and needs access to m_RSList
@@ -280,7 +281,7 @@ private:
unsigned int m_WorldSeed;
- int m_Weather;
+ eWeather m_Weather;
cEntityList m_RemoveEntityQueue;
cEntityList m_AllEntities;
diff --git a/source/packets/cPacket_CreativeInventoryAction.cpp b/source/packets/cPacket_CreativeInventoryAction.cpp
index af500e503..de6cc1488 100644
--- a/source/packets/cPacket_CreativeInventoryAction.cpp
+++ b/source/packets/cPacket_CreativeInventoryAction.cpp
@@ -56,7 +56,6 @@ void cPacket_CreativeInventoryAction::Serialize(AString & a_Data) const
// WARNING: HERE ITS -1, BUT IN NAMED ENTITY SPAWN PACKET ITS 0 !!
}
- unsigned int i = 0;
AppendByte (a_Data, m_PacketID);
AppendShort (a_Data, m_Slot);