summaryrefslogtreecommitdiffstats
path: root/source/cPlayer.cpp
diff options
context:
space:
mode:
authorfaketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6>2011-11-01 22:57:08 +0100
committerfaketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6>2011-11-01 22:57:08 +0100
commitb5b920dedaa62302795b0b8f3db84a0650d236e0 (patch)
treef46d1ec70d6519fff2a75f45c08fe37bf4b5538c /source/cPlayer.cpp
parentforogt to update all of cPlayer.cpp for player based gamemode. (diff)
downloadcuberite-b5b920dedaa62302795b0b8f3db84a0650d236e0.tar
cuberite-b5b920dedaa62302795b0b8f3db84a0650d236e0.tar.gz
cuberite-b5b920dedaa62302795b0b8f3db84a0650d236e0.tar.bz2
cuberite-b5b920dedaa62302795b0b8f3db84a0650d236e0.tar.lz
cuberite-b5b920dedaa62302795b0b8f3db84a0650d236e0.tar.xz
cuberite-b5b920dedaa62302795b0b8f3db84a0650d236e0.tar.zst
cuberite-b5b920dedaa62302795b0b8f3db84a0650d236e0.zip
Diffstat (limited to 'source/cPlayer.cpp')
-rw-r--r--source/cPlayer.cpp38
1 files changed, 14 insertions, 24 deletions
diff --git a/source/cPlayer.cpp b/source/cPlayer.cpp
index fe3f5a7d6..69e163629 100644
--- a/source/cPlayer.cpp
+++ b/source/cPlayer.cpp
@@ -15,6 +15,7 @@
#include "cItem.h"
#include "cTracer.h"
#include "cRoot.h"
+#include "cMakeDir.h"
#include "packets/cPacket_NamedEntitySpawn.h"
#include "packets/cPacket_EntityLook.h"
@@ -86,13 +87,16 @@ cPlayer::cPlayer(cClientHandle* a_Client, const char* a_PlayerName)
if( !LoadFromDisk() )
{
m_Inventory->Clear();
- SetPosX( cRoot::Get()->GetWorld()->GetSpawnX() ); // TODO - Get from the correct world?
- SetPosY( cRoot::Get()->GetWorld()->GetSpawnY() );
- SetPosZ( cRoot::Get()->GetWorld()->GetSpawnZ() );
+ SetPosX( cRoot::Get()->GetDefaultWorld()->GetSpawnX() );
+ SetPosY( cRoot::Get()->GetDefaultWorld()->GetSpawnY() );
+ SetPosZ( cRoot::Get()->GetDefaultWorld()->GetSpawnZ() );
}
+}
- //MoveToCorrectChunk();
- cRoot::Get()->GetWorld()->AddPlayer( this ); // TODO - Add to correct world? Or get rid of this?
+void cPlayer::Initialize( cWorld* a_World )
+{
+ cPawn::Initialize( a_World );
+ GetWorld()->AddPlayer( this );
}
cPlayer::~cPlayer(void)
@@ -618,7 +622,7 @@ void cPlayer::TossItem( bool a_bDraggingItem, int a_Amount /* = 1 */ )
}
}
-bool cPlayer::LoadFromDisk()
+bool cPlayer::LoadFromDisk() // TODO - This should also get/set/whatever the correct world for this player
{
cIniFile IniFile("users.ini");
if( IniFile.ReadFile() )
@@ -653,7 +657,7 @@ bool cPlayer::LoadFromDisk()
}
char SourceFile[128];
- sprintf_s(SourceFile, 128, "world/player/%s.json", m_pState->PlayerName.c_str() );
+ sprintf_s(SourceFile, 128, "players/%s.json", m_pState->PlayerName.c_str() );
FILE* f;
#ifdef _WIN32
@@ -696,7 +700,7 @@ bool cPlayer::LoadFromDisk()
m_Rot->z = (float)JSON_PlayerRotation[(unsigned int)2].asDouble();
}
- m_Health = root.get("health", 0 ).asInt();
+ m_Health = (short)root.get("health", 0 ).asInt();
m_Inventory->LoadFromJson(root["inventory"]);
return true;
@@ -706,21 +710,7 @@ bool cPlayer::LoadFromDisk()
bool cPlayer::SaveToDisk()
{
- #ifdef _WIN32
- { // Make sure some folders exist
- SECURITY_ATTRIBUTES Attrib;
- Attrib.nLength = sizeof(SECURITY_ATTRIBUTES);
- Attrib.lpSecurityDescriptor = NULL;
- Attrib.bInheritHandle = false;
- ::CreateDirectory("world", &Attrib);
- ::CreateDirectory("world/player", &Attrib);
- }
- #else
- {
- mkdir("world", S_IRWXU | S_IRWXG | S_IRWXO);
- mkdir("world/player", S_IRWXU | S_IRWXG | S_IRWXO);
- }
- #endif
+ cMakeDir::MakeDir("players");
// create the JSON data
Json::Value JSON_PlayerPosition;
@@ -746,7 +736,7 @@ bool cPlayer::SaveToDisk()
std::string JsonData = writer.write( root );
char SourceFile[128];
- sprintf_s(SourceFile, 128, "world/player/%s.json", m_pState->PlayerName.c_str() );
+ sprintf_s(SourceFile, 128, "players/%s.json", m_pState->PlayerName.c_str() );
FILE* f;
#ifdef _WIN32