Merge branch 'dev-physfs-save' into dev

dev-mp
krzys-h 2014-11-10 19:39:56 +01:00
commit fca746fdb4
57 changed files with 882 additions and 1302 deletions

View File

@ -1799,8 +1799,8 @@ void CApplication::SetLanguage(Language language)
putenv(S_LANGUAGE); putenv(S_LANGUAGE);
GetLogger()->Trace("SetLanguage: Set LANGUAGE=%s in environment\n", locale.c_str()); GetLogger()->Trace("SetLanguage: Set LANGUAGE=%s in environment\n", locale.c_str());
} }
setlocale(LC_ALL, ""); std::locale::global(std::locale(std::locale(""), "C", std::locale::numeric));
bindtextdomain("colobot", m_langPath.c_str()); bindtextdomain("colobot", m_langPath.c_str());
bind_textdomain_codeset("colobot", "UTF-8"); bind_textdomain_codeset("colobot", "UTF-8");

View File

@ -167,7 +167,7 @@ bool CResourceManager::CreateDirectory(const std::string& directory)
return PHYSFS_mkdir(CleanPath(directory).c_str()); return PHYSFS_mkdir(CleanPath(directory).c_str());
} }
//TODO: Don't use boost filesystem here //TODO: Don't use boost::filesystem here
bool CResourceManager::RemoveDirectory(const std::string& directory) bool CResourceManager::RemoveDirectory(const std::string& directory)
{ {
bool success = true; bool success = true;
@ -219,6 +219,28 @@ std::vector<std::string> CResourceManager::ListDirectories(const std::string &di
return result; return result;
} }
long long CResourceManager::GetFileSize(const std::string& filename)
{
if(PHYSFS_isInit())
{
PHYSFS_File* file = PHYSFS_openRead(CleanPath(filename).c_str());
if(file == nullptr) return -1;
long long size = PHYSFS_fileLength(file);
PHYSFS_close(file);
return size;
}
return -1;
}
long long CResourceManager::GetLastModificationTime(const std::string& filename)
{
if(PHYSFS_isInit())
{
return PHYSFS_getLastModTime(CleanPath(filename).c_str());
}
return -1;
}
int CResourceManager::SDLClose(SDL_RWops *context) int CResourceManager::SDLClose(SDL_RWops *context)
{ {

View File

@ -56,6 +56,12 @@ public:
static std::vector<std::string> ListFiles(const std::string &directory); static std::vector<std::string> ListFiles(const std::string &directory);
//! List directories contained in directory //! List directories contained in directory
static std::vector<std::string> ListDirectories(const std::string &directory); static std::vector<std::string> ListDirectories(const std::string &directory);
//! Returns file size in bytes
static long long GetFileSize(const std::string &filename);
//! Returns last modification date as timestamp
static long long GetLastModificationTime(const std::string &filename);
private: private:
static int SDLSeek(SDL_RWops *context, int offset, int whence); static int SDLSeek(SDL_RWops *context, int offset, int whence);

View File

@ -26,6 +26,9 @@
#include "common/event.h" #include "common/event.h"
#include "common/iman.h" #include "common/iman.h"
#include "object/level/parserline.h"
#include "object/level/parserparam.h"
#include "script/cmdtoken.h" #include "script/cmdtoken.h"
#include "ui/interface.h" #include "ui/interface.h"
@ -424,37 +427,26 @@ void CAuto::SetMotor(bool bMotor)
// Saves all parameters of the controller. // Saves all parameters of the controller.
bool CAuto::Write(char *line) bool CAuto::Write(CLevelParserLine* line)
{ {
char name[100]; line->AddParam("aType", new CLevelParserParam(m_type));
line->AddParam("aBusy", new CLevelParserParam(m_bBusy));
sprintf(name, " aType=%d", m_type); line->AddParam("aTime", new CLevelParserParam(m_time));
strcat(line, name); line->AddParam("aProgressTime", new CLevelParserParam(m_progressTime));
line->AddParam("aProgressTotal", new CLevelParserParam(m_progressTotal));
sprintf(name, " aBusy=%d", m_bBusy);
strcat(line, name);
sprintf(name, " aTime=%.2f", m_time);
strcat(line, name);
sprintf(name, " aProgressTime=%.2f", m_progressTime);
strcat(line, name);
sprintf(name, " aProgressTotal=%.2f", m_progressTotal);
strcat(line, name);
return false; return false;
} }
// Return all settings to the controller. // Return all settings to the controller.
bool CAuto::Read(char *line) bool CAuto::Read(CLevelParserLine* line)
{ {
m_type = static_cast<ObjectType>(OpInt(line, "aType", OBJECT_NULL)); m_type = line->GetParam("aType")->AsObjectType();
m_bBusy = OpInt(line, "aBusy", 0); m_bBusy = line->GetParam("aBusy")->AsBool();
m_time = OpFloat(line, "aTime", 0.0f); m_time = line->GetParam("aTime")->AsFloat();
m_progressTime = OpFloat(line, "aProgressTime", 0.0f); m_progressTime = line->GetParam("aProgressTime")->AsFloat();
m_progressTotal = OpFloat(line, "aProgressTotal", 0.0f); m_progressTotal = line->GetParam("aProgressTotal")->AsFloat();
return false; return false;
} }

View File

@ -29,6 +29,7 @@
class CInstanceManager; class CInstanceManager;
class CRobotMain; class CRobotMain;
class CSoundInterface; class CSoundInterface;
class CLevelParserLine;
namespace Ui { namespace Ui {
class CInterface; class CInterface;
@ -80,8 +81,8 @@ public:
virtual bool GetMotor(); virtual bool GetMotor();
virtual void SetMotor(bool bMotor); virtual void SetMotor(bool bMotor);
virtual bool Write(char *line); virtual bool Write(CLevelParserLine* line);
virtual bool Read(char *line); virtual bool Read(CLevelParserLine* line);
protected: protected:
void CheckInterface(Ui::CWindow *pw, EventType event, bool bState); void CheckInterface(Ui::CWindow *pw, EventType event, bool bState);

View File

@ -24,6 +24,9 @@
#include "math/geometry.h" #include "math/geometry.h"
#include "object/level/parserline.h"
#include "object/level/parserparam.h"
#include "script/cmdtoken.h" #include "script/cmdtoken.h"
#include "ui/interface.h" #include "ui/interface.h"
@ -361,41 +364,30 @@ bool CAutoConvert::CreateInterface(bool bSelect)
// Saves all parameters of the controller. // Saves all parameters of the controller.
bool CAutoConvert::Write(char *line) bool CAutoConvert::Write(CLevelParserLine* line)
{ {
char name[100];
if ( m_phase == ACP_STOP || if ( m_phase == ACP_STOP ||
m_phase == ACP_WAIT ) return false; m_phase == ACP_WAIT ) return false;
sprintf(name, " aExist=%d", 1); line->AddParam("aExist", new CLevelParserParam(true));
strcat(line, name);
CAuto::Write(line); CAuto::Write(line);
line->AddParam("aPhase", new CLevelParserParam(static_cast<int>(m_phase)));
sprintf(name, " aPhase=%d", m_phase); line->AddParam("aProgress", new CLevelParserParam(m_progress));
strcat(line, name); line->AddParam("aSpeed", new CLevelParserParam(m_speed));
sprintf(name, " aProgress=%.2f", m_progress);
strcat(line, name);
sprintf(name, " aSpeed=%.2f", m_speed);
strcat(line, name);
return true; return true;
} }
// Restores all parameters of the controller. // Restores all parameters of the controller.
bool CAutoConvert::Read(char *line) bool CAutoConvert::Read(CLevelParserLine* line)
{ {
if ( OpInt(line, "aExist", 0) == 0 ) return false; if ( !line->GetParam("aExist")->AsBool(false) ) return false;
CAuto::Read(line); CAuto::Read(line);
m_phase = static_cast< AutoConvertPhase >(line->GetParam("aPhase")->AsInt(ACP_WAIT));
m_phase = static_cast< AutoConvertPhase >(OpInt(line, "aPhase", ACP_WAIT)); m_progress = line->GetParam("aProgress")->AsFloat(0.0f);
m_progress = OpFloat(line, "aProgress", 0.0f); m_speed = line->GetParam("aSpeed")->AsFloat(1.0f);
m_speed = OpFloat(line, "aSpeed", 1.0f);
m_lastParticle = 0.0f; m_lastParticle = 0.0f;

View File

@ -52,8 +52,8 @@ public:
bool CreateInterface(bool bSelect); bool CreateInterface(bool bSelect);
bool Write(char *line); bool Write(CLevelParserLine* line);
bool Read(char *line); bool Read(CLevelParserLine* line);
protected: protected:
CObject* SearchStone(ObjectType type); CObject* SearchStone(ObjectType type);

View File

@ -26,6 +26,9 @@
#include "math/geometry.h" #include "math/geometry.h"
#include "object/level/parserline.h"
#include "object/level/parserparam.h"
#include "script/cmdtoken.h" #include "script/cmdtoken.h"
#include "ui/interface.h" #include "ui/interface.h"
@ -428,40 +431,29 @@ bool CAutoDerrick::CreateInterface(bool bSelect)
// Saves all parameters of the controller. // Saves all parameters of the controller.
bool CAutoDerrick::Write(char *line) bool CAutoDerrick::Write(CLevelParserLine* line)
{ {
char name[100];
if ( m_phase == ADP_WAIT ) return false; if ( m_phase == ADP_WAIT ) return false;
sprintf(name, " aExist=%d", 1); line->AddParam("aExist", new CLevelParserParam(true));
strcat(line, name);
CAuto::Write(line); CAuto::Write(line);
line->AddParam("aPhase", new CLevelParserParam(static_cast<int>(m_phase)));
sprintf(name, " aPhase=%d", m_phase); line->AddParam("aProgress", new CLevelParserParam(m_progress));
strcat(line, name); line->AddParam("aSpeed", new CLevelParserParam(m_speed));
sprintf(name, " aProgress=%.2f", m_progress);
strcat(line, name);
sprintf(name, " aSpeed=%.2f", m_speed);
strcat(line, name);
return true; return true;
} }
// Restores all parameters of the controller. // Restores all parameters of the controller.
bool CAutoDerrick::Read(char *line) bool CAutoDerrick::Read(CLevelParserLine* line)
{ {
if ( OpInt(line, "aExist", 0) == 0 ) return false; if ( !line->GetParam("aExist")->AsBool(false) ) return false;
CAuto::Read(line); CAuto::Read(line);
m_phase = static_cast< AutoDerrickPhase >(line->GetParam("aPhase")->AsInt(ADP_WAIT));
m_phase = static_cast< AutoDerrickPhase >(OpInt(line, "aPhase", ADP_WAIT)); m_progress = line->GetParam("aProgress")->AsFloat(0.0f);
m_progress = OpFloat(line, "aProgress", 0.0f); m_speed = line->GetParam("aSpeed")->AsFloat(1.0f);
m_speed = OpFloat(line, "aSpeed", 1.0f);
m_lastParticle = 0.0f; m_lastParticle = 0.0f;

View File

@ -51,8 +51,8 @@ public:
bool CreateInterface(bool bSelect); bool CreateInterface(bool bSelect);
bool Write(char *line); bool Write(CLevelParserLine* line);
bool Read(char *line); bool Read(CLevelParserLine* line);
protected: protected:
CObject* SearchFret(); CObject* SearchFret();

View File

@ -22,6 +22,9 @@
#include "common/iman.h" #include "common/iman.h"
#include "object/level/parserline.h"
#include "object/level/parserparam.h"
#include "script/cmdtoken.h" #include "script/cmdtoken.h"
#include "ui/interface.h" #include "ui/interface.h"
@ -357,40 +360,29 @@ Error CAutoDestroyer::GetError()
// Saves all parameters of the controller. // Saves all parameters of the controller.
bool CAutoDestroyer::Write(char *line) bool CAutoDestroyer::Write(CLevelParserLine* line)
{ {
char name[100];
if ( m_phase == ADEP_WAIT ) return false; if ( m_phase == ADEP_WAIT ) return false;
sprintf(name, " aExist=%d", 1); line->AddParam("aExist", new CLevelParserParam(true));
strcat(line, name);
CAuto::Write(line); CAuto::Write(line);
line->AddParam("aPhase", new CLevelParserParam(static_cast<int>(m_phase)));
sprintf(name, " aPhase=%d", m_phase); line->AddParam("aProgress", new CLevelParserParam(m_progress));
strcat(line, name); line->AddParam("aSpeed", new CLevelParserParam(m_speed));
sprintf(name, " aProgress=%.2f", m_progress);
strcat(line, name);
sprintf(name, " aSpeed=%.2f", m_speed);
strcat(line, name);
return true; return true;
} }
// Restores all parameters of the controller. // Restores all parameters of the controller.
bool CAutoDestroyer::Read(char *line) bool CAutoDestroyer::Read(CLevelParserLine* line)
{ {
if ( OpInt(line, "aExist", 0) == 0 ) return false; if ( !line->GetParam("aExist")->AsBool(false) ) return false;
CAuto::Read(line); CAuto::Read(line);
m_phase = static_cast< AutoDestroyerPhase >(line->GetParam("aPhase")->AsInt(ADEP_WAIT));
m_phase = static_cast< AutoDestroyerPhase >(OpInt(line, "aPhase", ADEP_WAIT)); m_progress = line->GetParam("aProgress")->AsFloat(0.0f);
m_progress = OpFloat(line, "aProgress", 0.0f); m_speed = line->GetParam("aSpeed")->AsFloat(1.0f);
m_speed = OpFloat(line, "aSpeed", 1.0f);
m_lastParticle = 0.0f; m_lastParticle = 0.0f;

View File

@ -52,8 +52,8 @@ public:
bool CreateInterface(bool bSelect); bool CreateInterface(bool bSelect);
bool Write(char *line); bool Write(CLevelParserLine* line);
bool Read(char *line); bool Read(CLevelParserLine* line);
protected: protected:
CObject* SearchPlastic(); CObject* SearchPlastic();

View File

@ -24,6 +24,9 @@
#include "math/geometry.h" #include "math/geometry.h"
#include "object/level/parserline.h"
#include "object/level/parserparam.h"
#include "script/cmdtoken.h" #include "script/cmdtoken.h"
#include <stdio.h> #include <stdio.h>
@ -310,52 +313,35 @@ CObject* CAutoEgg::SearchAlien()
// Saves all parameters of the controller. // Saves all parameters of the controller.
bool CAutoEgg::Write(char *line) bool CAutoEgg::Write(CLevelParserLine* line)
{ {
char name[100];
if ( m_phase == AEP_NULL ) return false; if ( m_phase == AEP_NULL ) return false;
sprintf(name, " aExist=%d", 1); line->AddParam("aExist", new CLevelParserParam(true));
strcat(line, name);
CAuto::Write(line); CAuto::Write(line);
line->AddParam("aPhase", new CLevelParserParam(static_cast<int>(m_phase)));
sprintf(name, " aPhase=%d", m_phase); line->AddParam("aProgress", new CLevelParserParam(m_progress));
strcat(line, name); line->AddParam("aSpeed", new CLevelParserParam(m_speed));
line->AddParam("aParamType", new CLevelParserParam(m_type));
sprintf(name, " aProgress=%.2f", m_progress); line->AddParam("aParamValue1", new CLevelParserParam(m_value));
strcat(line, name); line->AddParam("aParamString", new CLevelParserParam(m_string));
sprintf(name, " aSpeed=%.5f", m_speed);
strcat(line, name);
sprintf(name, " aParamType=%s", GetTypeObject(m_type));
strcat(line, name);
sprintf(name, " aParamValue1=%.2f", m_value);
strcat(line, name);
sprintf(name, " aParamString=\"%s\"", m_string);
strcat(line, name);
return true; return true;
} }
// Restores all parameters of the controller. // Restores all parameters of the controller.
bool CAutoEgg::Read(char *line) bool CAutoEgg::Read(CLevelParserLine* line)
{ {
if ( OpInt(line, "aExist", 0) == 0 ) return false; if ( !line->GetParam("aExist")->AsBool(false) ) return false;
CAuto::Read(line); CAuto::Read(line);
m_phase = static_cast< AutoEggPhase >(line->GetParam("aPhase")->AsInt(AEP_NULL));
m_phase = static_cast< AutoEggPhase >(OpInt(line, "aPhase", AEP_NULL)); m_progress = line->GetParam("aProgress")->AsFloat(0.0f);
m_progress = OpFloat(line, "aProgress", 0.0f); m_speed = line->GetParam("aSpeed")->AsFloat(1.0f);
m_speed = OpFloat(line, "aSpeed", 1.0f); m_type = line->GetParam("aParamType")->AsObjectType(OBJECT_NULL);
m_type = OpTypeObject(line, "aParamType", OBJECT_NULL); m_value = line->GetParam("aParamValue1")->AsFloat(0.0f);
m_value = OpFloat(line, "aParamValue1", 0.0f); strcpy(m_string, line->GetParam("aParamString")->AsString("").c_str());
OpString(line, "aParamString", m_string);
return true; return true;
} }

View File

@ -54,8 +54,8 @@ public:
bool SetValue(int rank, float value); bool SetValue(int rank, float value);
bool SetString(char *string); bool SetString(char *string);
bool Write(char *line); bool Write(CLevelParserLine* line);
bool Read(char *line); bool Read(CLevelParserLine* line);
protected: protected:
CObject* SearchAlien(); CObject* SearchAlien();

View File

@ -26,6 +26,9 @@
#include "math/geometry.h" #include "math/geometry.h"
#include "object/level/parserline.h"
#include "object/level/parserparam.h"
#include "script/cmdtoken.h" #include "script/cmdtoken.h"
#include "ui/interface.h" #include "ui/interface.h"
@ -609,41 +612,30 @@ void CAutoEnergy::UpdateInterface(float rTime)
// Saves all parameters of the controller. // Saves all parameters of the controller.
bool CAutoEnergy::Write(char *line) bool CAutoEnergy::Write(CLevelParserLine* line)
{ {
char name[100];
if ( m_phase == AENP_STOP || if ( m_phase == AENP_STOP ||
m_phase == AENP_WAIT ) return false; m_phase == AENP_WAIT ) return false;
sprintf(name, " aExist=%d", 1); line->AddParam("aExist", new CLevelParserParam(true));
strcat(line, name);
CAuto::Write(line); CAuto::Write(line);
line->AddParam("aPhase", new CLevelParserParam(static_cast<int>(m_phase)));
sprintf(name, " aPhase=%d", m_phase); line->AddParam("aProgress", new CLevelParserParam(m_progress));
strcat(line, name); line->AddParam("aSpeed", new CLevelParserParam(m_speed));
sprintf(name, " aProgress=%.2f", m_progress);
strcat(line, name);
sprintf(name, " aSpeed=%.2f", m_speed);
strcat(line, name);
return true; return true;
} }
// Restores all parameters of the controller. // Restores all parameters of the controller.
bool CAutoEnergy::Read(char *line) bool CAutoEnergy::Read(CLevelParserLine* line)
{ {
if ( OpInt(line, "aExist", 0) == 0 ) return false; if ( !line->GetParam("aExist")->AsBool(false) ) return false;
CAuto::Read(line); CAuto::Read(line);
m_phase = static_cast< AutoEnergyPhase >(line->GetParam("aPhase")->AsInt(AENP_WAIT));
m_phase = static_cast< AutoEnergyPhase >(OpInt(line, "aPhase", AENP_WAIT)); m_progress = line->GetParam("aProgress")->AsFloat(0.0f);
m_progress = OpFloat(line, "aProgress", 0.0f); m_speed = line->GetParam("aSpeed")->AsFloat(1.0f);
m_speed = OpFloat(line, "aSpeed", 1.0f);
m_lastUpdateTime = 0.0f; m_lastUpdateTime = 0.0f;
m_lastParticle = 0.0f; m_lastParticle = 0.0f;

View File

@ -51,8 +51,8 @@ public:
bool CreateInterface(bool bSelect); bool CreateInterface(bool bSelect);
bool Write(char *line); bool Write(CLevelParserLine* line);
bool Read(char *line); bool Read(CLevelParserLine* line);
protected: protected:
void UpdateInterface(float rTime); void UpdateInterface(float rTime);

View File

@ -27,6 +27,8 @@
#include "object/robotmain.h" #include "object/robotmain.h"
#include "object/brain.h" #include "object/brain.h"
#include "object/level/parserline.h"
#include "object/level/parserparam.h"
#include "physics/physics.h" #include "physics/physics.h"
@ -515,40 +517,29 @@ bool CAutoFactory::EventProcess(const Event &event)
// Saves all parameters of the controller. // Saves all parameters of the controller.
bool CAutoFactory::Write(char *line) bool CAutoFactory::Write(CLevelParserLine* line)
{ {
char name[100];
if ( m_phase == AFP_WAIT ) return false; if ( m_phase == AFP_WAIT ) return false;
sprintf(name, " aExist=%d", 1); line->AddParam("aExist", new CLevelParserParam(true));
strcat(line, name);
CAuto::Write(line); CAuto::Write(line);
line->AddParam("aPhase", new CLevelParserParam(static_cast<int>(m_phase)));
sprintf(name, " aPhase=%d", m_phase); line->AddParam("aProgress", new CLevelParserParam(m_progress));
strcat(line, name); line->AddParam("aSpeed", new CLevelParserParam(m_speed));
sprintf(name, " aProgress=%.2f", m_progress);
strcat(line, name);
sprintf(name, " aSpeed=%.2f", m_speed);
strcat(line, name);
return true; return true;
} }
// Restores all parameters of the controller // Restores all parameters of the controller
bool CAutoFactory::Read(char *line) bool CAutoFactory::Read(CLevelParserLine* line)
{ {
if ( OpInt(line, "aExist", 0) == 0 ) return false; if ( !line->GetParam("aExist")->AsBool(false) ) return false;
CAuto::Read(line); CAuto::Read(line);
m_phase = static_cast< AutoFactoryPhase >(line->GetParam("aPhase")->AsInt(AFP_WAIT));
m_phase = static_cast< AutoFactoryPhase >(OpInt(line, "aPhase", AFP_WAIT)); m_progress = line->GetParam("aProgress")->AsFloat(0.0f);
m_progress = OpFloat(line, "aProgress", 0.0f); m_speed = line->GetParam("aSpeed")->AsFloat(1.0f);
m_speed = OpFloat(line, "aSpeed", 1.0f);
m_lastParticle = 0.0f; m_lastParticle = 0.0f;
m_fretPos = m_object->GetPosition(0); m_fretPos = m_object->GetPosition(0);

View File

@ -55,8 +55,8 @@ public:
bool CreateInterface(bool bSelect); bool CreateInterface(bool bSelect);
bool Write(char *line); bool Write(CLevelParserLine* line);
bool Read(char *line); bool Read(CLevelParserLine* line);
protected: protected:
void UpdateInterface(); void UpdateInterface();

View File

@ -20,7 +20,12 @@
#include "object/auto/autoinfo.h" #include "object/auto/autoinfo.h"
#include "object/level/parserline.h"
#include "object/level/parserparam.h"
#include "script/cmdtoken.h" #include "script/cmdtoken.h"
#include "ui/interface.h" #include "ui/interface.h"
#include "ui/list.h" #include "ui/list.h"
#include "ui/window.h" #include "ui/window.h"
@ -475,40 +480,29 @@ void CAutoInfo::UpdateListVirus()
// Saves all parameters of the controller. // Saves all parameters of the controller.
bool CAutoInfo::Write(char *line) bool CAutoInfo::Write(CLevelParserLine* line)
{ {
char name[100];
if ( m_phase == AIP_WAIT ) return false; if ( m_phase == AIP_WAIT ) return false;
sprintf(name, " aExist=%d", 1); line->AddParam("aExist", new CLevelParserParam(true));
strcat(line, name);
CAuto::Write(line); CAuto::Write(line);
line->AddParam("aPhase", new CLevelParserParam(static_cast<int>(m_phase)));
sprintf(name, " aPhase=%d", m_phase); line->AddParam("aProgress", new CLevelParserParam(m_progress));
strcat(line, name); line->AddParam("aSpeed", new CLevelParserParam(m_speed));
sprintf(name, " aProgress=%.2f", m_progress);
strcat(line, name);
sprintf(name, " aSpeed=%.2f", m_speed);
strcat(line, name);
return true; return true;
} }
// Restores all parameters of the controller. // Restores all parameters of the controller.
bool CAutoInfo::Read(char *line) bool CAutoInfo::Read(CLevelParserLine* line)
{ {
if ( OpInt(line, "aExist", 0) == 0 ) return false; if ( !line->GetParam("aExist")->AsBool(false) ) return false;
CAuto::Read(line); CAuto::Read(line);
m_phase = static_cast< AutoInfoPhase >(line->GetParam("aPhase")->AsInt(AIP_WAIT));
m_phase = static_cast< AutoInfoPhase > (OpInt(line, "aPhase", AIP_WAIT)); m_progress = line->GetParam("aProgress")->AsFloat(0.0f);
m_progress = OpFloat(line, "aProgress", 0.0f); m_speed = line->GetParam("aSpeed")->AsFloat(1.0f);
m_speed = OpFloat(line, "aSpeed", 1.0f);
m_lastParticle = 0.0f; m_lastParticle = 0.0f;

View File

@ -51,8 +51,8 @@ public:
bool CreateInterface(bool bSelect); bool CreateInterface(bool bSelect);
bool Write(char *line); bool Write(CLevelParserLine* line);
bool Read(char *line); bool Read(CLevelParserLine* line);
protected: protected:
void UpdateInterface(float rTime); void UpdateInterface(float rTime);

View File

@ -26,6 +26,8 @@
#include "math/geometry.h" #include "math/geometry.h"
#include "object/robotmain.h" #include "object/robotmain.h"
#include "object/level/parserline.h"
#include "object/level/parserparam.h"
#include "script/cmdtoken.h" #include "script/cmdtoken.h"
@ -586,47 +588,31 @@ void CAutoLabo::SoundManip(float time, float amplitude, float frequency)
// Saves all parameters of the controller. // Saves all parameters of the controller.
bool CAutoLabo::Write(char *line) bool CAutoLabo::Write(CLevelParserLine* line)
{ {
Math::Vector pos;
char name[100];
if ( m_phase == ALAP_WAIT ) return false; if ( m_phase == ALAP_WAIT ) return false;
sprintf(name, " aExist=%d", 1); line->AddParam("aExist", new CLevelParserParam(true));
strcat(line, name);
CAuto::Write(line); CAuto::Write(line);
line->AddParam("aPhase", new CLevelParserParam(static_cast<int>(m_phase)));
sprintf(name, " aPhase=%d", m_phase); line->AddParam("aProgress", new CLevelParserParam(m_progress));
strcat(line, name); line->AddParam("aSpeed", new CLevelParserParam(m_speed));
line->AddParam("aResearch", new CLevelParserParam(static_cast<int>(m_research)));
sprintf(name, " aProgress=%.2f", m_progress);
strcat(line, name);
sprintf(name, " aSpeed=%.2f", m_speed);
strcat(line, name);
sprintf(name, " aResearch=%d", m_research);
strcat(line, name);
return true; return true;
} }
// Restores all parameters of the controller. // Restores all parameters of the controller.
bool CAutoLabo::Read(char *line) bool CAutoLabo::Read(CLevelParserLine* line)
{ {
Math::Vector pos; if ( !line->GetParam("aExist")->AsBool(false) ) return false;
if ( OpInt(line, "aExist", 0) == 0 ) return false;
CAuto::Read(line); CAuto::Read(line);
m_phase = static_cast< AutoLaboPhase >(line->GetParam("aPhase")->AsInt(ALAP_WAIT));
m_phase = static_cast< AutoLaboPhase >(OpInt(line, "aPhase", ALAP_WAIT)); m_progress = line->GetParam("aProgress")->AsFloat(0.0f);
m_progress = OpFloat(line, "aProgress", 0.0f); m_speed = line->GetParam("aSpeed")->AsFloat(1.0f);
m_speed = OpFloat(line, "aSpeed", 1.0f); m_research = static_cast< ResearchType >(line->GetParam("aResearch")->AsInt(0));
m_research = static_cast< ResearchType >(OpInt(line, "aResearch", 0));
m_lastParticle = 0.0f; m_lastParticle = 0.0f;

View File

@ -55,8 +55,8 @@ public:
bool CreateInterface(bool bSelect); bool CreateInterface(bool bSelect);
bool Write(char *line); bool Write(CLevelParserLine* line);
bool Read(char *line); bool Read(CLevelParserLine* line);
protected: protected:
void UpdateInterface(); void UpdateInterface();

View File

@ -22,6 +22,9 @@
#include "common/iman.h" #include "common/iman.h"
#include "object/level/parserline.h"
#include "object/level/parserparam.h"
#include "script/cmdtoken.h" #include "script/cmdtoken.h"
@ -31,7 +34,7 @@
// Object's constructor. // Object's constructor.
CAutoMush::CAutoMush(CObject* object) : CAuto(object) CAutoMush::CAutoMush(CObject* object) : CAuto(object)
{ {
Init(); Init();
} }
@ -301,43 +304,29 @@ Error CAutoMush::GetError()
// Saves all parameters of the controller. // Saves all parameters of the controller.
bool CAutoMush::Write(char *line) bool CAutoMush::Write(CLevelParserLine* line)
{ {
Math::Vector pos;
char name[100];
if ( m_phase == AMP_WAIT ) return false; if ( m_phase == AMP_WAIT ) return false;
sprintf(name, " aExist=%d", 1); line->AddParam("aExist", new CLevelParserParam(true));
strcat(line, name);
CAuto::Write(line); CAuto::Write(line);
line->AddParam("aPhase", new CLevelParserParam(static_cast<int>(m_phase)));
sprintf(name, " aPhase=%d", m_phase); line->AddParam("aProgress", new CLevelParserParam(m_progress));
strcat(line, name); line->AddParam("aSpeed", new CLevelParserParam(m_speed));
sprintf(name, " aProgress=%.2f", m_progress);
strcat(line, name);
sprintf(name, " aSpeed=%.2f", m_speed);
strcat(line, name);
return true; return true;
} }
// Restores all parameters of the controller. // Restores all parameters of the controller.
bool CAutoMush::Read(char *line) bool CAutoMush::Read(CLevelParserLine* line)
{ {
Math::Vector pos; if ( !line->GetParam("aExist")->AsBool(false) ) return false;
if ( OpInt(line, "aExist", 0) == 0 ) return false;
CAuto::Read(line); CAuto::Read(line);
m_phase = static_cast< AutoMushPhase >(line->GetParam("aPhase")->AsInt(AMP_WAIT));
m_phase = static_cast< AutoMushPhase >(OpInt(line, "aPhase", AMP_WAIT)); m_progress = line->GetParam("aProgress")->AsFloat(0.0f);
m_progress = OpFloat(line, "aProgress", 0.0f); m_speed = line->GetParam("aSpeed")->AsFloat(1.0f);
m_speed = OpFloat(line, "aSpeed", 1.0f);
m_lastParticle = 0.0f; m_lastParticle = 0.0f;

View File

@ -49,8 +49,8 @@ public:
bool EventProcess(const Event &event); bool EventProcess(const Event &event);
Error GetError(); Error GetError();
bool Write(char *line); bool Write(CLevelParserLine* line);
bool Read(char *line); bool Read(CLevelParserLine* line);
protected: protected:
bool SearchTarget(); bool SearchTarget();

View File

@ -24,6 +24,9 @@
#include "graphics/engine/terrain.h" #include "graphics/engine/terrain.h"
#include "object/level/parserline.h"
#include "object/level/parserparam.h"
#include "script/cmdtoken.h" #include "script/cmdtoken.h"
#include <stdio.h> #include <stdio.h>
@ -32,7 +35,7 @@
// Object's constructor. // Object's constructor.
CAutoNest::CAutoNest(CObject* object) : CAuto(object) CAutoNest::CAutoNest(CObject* object) : CAuto(object)
{ {
Init(); Init();
} }
@ -232,43 +235,29 @@ Error CAutoNest::GetError()
// Saves all parameters of the controller. // Saves all parameters of the controller.
bool CAutoNest::Write(char *line) bool CAutoNest::Write(CLevelParserLine* line)
{ {
Math::Vector pos;
char name[100];
if ( m_phase == ANP_WAIT ) return false; if ( m_phase == ANP_WAIT ) return false;
sprintf(name, " aExist=%d", 1); line->AddParam("aExist", new CLevelParserParam(true));
strcat(line, name);
CAuto::Write(line); CAuto::Write(line);
line->AddParam("aPhase", new CLevelParserParam(static_cast<int>(m_phase)));
sprintf(name, " aPhase=%d", m_phase); line->AddParam("aProgress", new CLevelParserParam(m_progress));
strcat(line, name); line->AddParam("aSpeed", new CLevelParserParam(m_speed));
sprintf(name, " aProgress=%.2f", m_progress);
strcat(line, name);
sprintf(name, " aSpeed=%.2f", m_speed);
strcat(line, name);
return true; return true;
} }
// Restores all parameters of the controller. // Restores all parameters of the controller.
bool CAutoNest::Read(char *line) bool CAutoNest::Read(CLevelParserLine* line)
{ {
Math::Vector pos; if ( !line->GetParam("aExist")->AsBool(false) ) return false;
if ( OpInt(line, "aExist", 0) == 0 ) return false;
CAuto::Read(line); CAuto::Read(line);
m_phase = static_cast< AutoNestPhase >(line->GetParam("aPhase")->AsInt(ANP_WAIT));
m_phase = static_cast< AutoNestPhase >(OpInt(line, "aPhase", ANP_WAIT)); m_progress = line->GetParam("aProgress")->AsFloat(0.0f);
m_progress = OpFloat(line, "aProgress", 0.0f); m_speed = line->GetParam("aSpeed")->AsFloat(1.0f);
m_speed = OpFloat(line, "aSpeed", 1.0f);
m_lastParticle = 0.0f; m_lastParticle = 0.0f;

View File

@ -46,8 +46,8 @@ public:
bool EventProcess(const Event &event); bool EventProcess(const Event &event);
Error GetError(); Error GetError();
bool Write(char *line); bool Write(CLevelParserLine* line);
bool Read(char *line); bool Read(CLevelParserLine* line);
protected: protected:
bool SearchFree(Math::Vector pos); bool SearchFree(Math::Vector pos);

View File

@ -24,6 +24,9 @@
#include "math/geometry.h" #include "math/geometry.h"
#include "object/level/parserline.h"
#include "object/level/parserparam.h"
#include "script/cmdtoken.h" #include "script/cmdtoken.h"
#include "ui/interface.h" #include "ui/interface.h"
@ -444,41 +447,30 @@ Error CAutoNuclear::GetError()
// Saves all parameters of the controller. // Saves all parameters of the controller.
bool CAutoNuclear::Write(char *line) bool CAutoNuclear::Write(CLevelParserLine* line)
{ {
char name[100];
if ( m_phase == ANUP_STOP || if ( m_phase == ANUP_STOP ||
m_phase == ANUP_WAIT ) return false; m_phase == ANUP_WAIT ) return false;
sprintf(name, " aExist=%d", 1); line->AddParam("aExist", new CLevelParserParam(true));
strcat(line, name);
CAuto::Write(line); CAuto::Write(line);
line->AddParam("aPhase", new CLevelParserParam(static_cast<int>(m_phase)));
sprintf(name, " aPhase=%d", m_phase); line->AddParam("aProgress", new CLevelParserParam(m_progress));
strcat(line, name); line->AddParam("aSpeed", new CLevelParserParam(m_speed));
sprintf(name, " aProgress=%.2f", m_progress);
strcat(line, name);
sprintf(name, " aSpeed=%.2f", m_speed);
strcat(line, name);
return true; return true;
} }
// Restores all parameters of the controller. // Restores all parameters of the controller.
bool CAutoNuclear::Read(char *line) bool CAutoNuclear::Read(CLevelParserLine* line)
{ {
if ( OpInt(line, "aExist", 0) == 0 ) return false; if ( !line->GetParam("aExist")->AsBool(false) ) return false;
CAuto::Read(line); CAuto::Read(line);
m_phase = static_cast< AutoNuclearPhase >(line->GetParam("aPhase")->AsInt(ANUP_WAIT));
m_phase = static_cast< AutoNuclearPhase >(OpInt(line, "aPhase", ANUP_WAIT)); m_progress = line->GetParam("aProgress")->AsFloat(0.0f);
m_progress = OpFloat(line, "aProgress", 0.0f); m_speed = line->GetParam("aSpeed")->AsFloat(1.0f);
m_speed = OpFloat(line, "aSpeed", 1.0f);
m_lastParticle = 0.0f; m_lastParticle = 0.0f;

View File

@ -51,8 +51,8 @@ public:
bool CreateInterface(bool bSelect); bool CreateInterface(bool bSelect);
bool Write(char *line); bool Write(CLevelParserLine* line);
bool Read(char *line); bool Read(CLevelParserLine* line);
protected: protected:
CObject* SearchUranium(); CObject* SearchUranium();

View File

@ -25,6 +25,9 @@
#include "math/geometry.h" #include "math/geometry.h"
#include "object/level/parserline.h"
#include "object/level/parserparam.h"
#include "script/cmdtoken.h" #include "script/cmdtoken.h"
#include "ui/interface.h" #include "ui/interface.h"
@ -289,40 +292,29 @@ void CAutoPara::ChargeObject(float rTime)
// Saves all parameters of the controller. // Saves all parameters of the controller.
bool CAutoPara::Write(char *line) bool CAutoPara::Write(CLevelParserLine* line)
{ {
char name[100];
if ( m_phase == APAP_WAIT ) return false; if ( m_phase == APAP_WAIT ) return false;
sprintf(name, " aExist=%d", 1); line->AddParam("aExist", new CLevelParserParam(true));
strcat(line, name);
CAuto::Write(line); CAuto::Write(line);
line->AddParam("aPhase", new CLevelParserParam(static_cast<int>(m_phase)));
sprintf(name, " aPhase=%d", m_phase); line->AddParam("aProgress", new CLevelParserParam(m_progress));
strcat(line, name); line->AddParam("aSpeed", new CLevelParserParam(m_speed));
sprintf(name, " aProgress=%.2f", m_progress);
strcat(line, name);
sprintf(name, " aSpeed=%.2f", m_speed);
strcat(line, name);
return true; return true;
} }
// Restores all parameters of the controller. // Restores all parameters of the controller.
bool CAutoPara::Read(char *line) bool CAutoPara::Read(CLevelParserLine* line)
{ {
if ( OpInt(line, "aExist", 0) == 0 ) return false; if ( !line->GetParam("aExist")->AsBool(false) ) return false;
CAuto::Read(line); CAuto::Read(line);
m_phase = static_cast< AutoParaPhase >(line->GetParam("aPhase")->AsInt(APAP_WAIT));
m_phase = static_cast< AutoParaPhase >(OpInt(line, "aPhase", APAP_WAIT)); m_progress = line->GetParam("aProgress")->AsFloat(0.0f);
m_progress = OpFloat(line, "aProgress", 0.0f); m_speed = line->GetParam("aSpeed")->AsFloat(1.0f);
m_speed = OpFloat(line, "aSpeed", 1.0f);
m_lastParticle = 0.0f; m_lastParticle = 0.0f;

View File

@ -50,8 +50,8 @@ public:
bool CreateInterface(bool bSelect); bool CreateInterface(bool bSelect);
bool Write(char *line); bool Write(CLevelParserLine* line);
bool Read(char *line); bool Read(CLevelParserLine* line);
protected: protected:
void ChargeObject(float rTime); void ChargeObject(float rTime);

View File

@ -22,6 +22,9 @@
#include "common/iman.h" #include "common/iman.h"
#include "object/level/parserline.h"
#include "object/level/parserparam.h"
#include "physics/physics.h" #include "physics/physics.h"
#include "script/cmdtoken.h" #include "script/cmdtoken.h"
@ -302,40 +305,29 @@ Error CAutoRepair::GetError()
// Saves all parameters of the controller. // Saves all parameters of the controller.
bool CAutoRepair::Write(char *line) bool CAutoRepair::Write(CLevelParserLine* line)
{ {
char name[100];
if ( m_phase == ARP_WAIT ) return false; if ( m_phase == ARP_WAIT ) return false;
sprintf(name, " aExist=%d", 1); line->AddParam("aExist", new CLevelParserParam(true));
strcat(line, name);
CAuto::Write(line); CAuto::Write(line);
line->AddParam("aPhase", new CLevelParserParam(static_cast<int>(m_phase)));
sprintf(name, " aPhase=%d", m_phase); line->AddParam("aProgress", new CLevelParserParam(m_progress));
strcat(line, name); line->AddParam("aSpeed", new CLevelParserParam(m_speed));
sprintf(name, " aProgress=%.2f", m_progress);
strcat(line, name);
sprintf(name, " aSpeed=%.2f", m_speed);
strcat(line, name);
return true; return true;
} }
// Restores all parameters of the controller. // Restores all parameters of the controller.
bool CAutoRepair::Read(char *line) bool CAutoRepair::Read(CLevelParserLine* line)
{ {
if ( OpInt(line, "aExist", 0) == 0 ) return false; if ( !line->GetParam("aExist")->AsBool(false) ) return false;
CAuto::Read(line); CAuto::Read(line);
m_phase = static_cast< AutoRepairPhase >(line->GetParam("aPhase")->AsInt(ARP_WAIT));
m_phase = static_cast< AutoRepairPhase >(OpInt(line, "aPhase", ARP_WAIT)); m_progress = line->GetParam("aProgress")->AsFloat(0.0f);
m_progress = OpFloat(line, "aProgress", 0.0f); m_speed = line->GetParam("aSpeed")->AsFloat(1.0f);
m_speed = OpFloat(line, "aSpeed", 1.0f);
m_lastParticle = 0.0f; m_lastParticle = 0.0f;

View File

@ -51,8 +51,8 @@ public:
bool CreateInterface(bool bSelect); bool CreateInterface(bool bSelect);
bool Write(char *line); bool Write(CLevelParserLine* line);
bool Read(char *line); bool Read(CLevelParserLine* line);
protected: protected:
CObject* SearchVehicle(); CObject* SearchVehicle();

View File

@ -25,6 +25,8 @@
#include "math/geometry.h" #include "math/geometry.h"
#include "object/robotmain.h" #include "object/robotmain.h"
#include "object/level/parserline.h"
#include "object/level/parserparam.h"
#include "script/cmdtoken.h" #include "script/cmdtoken.h"
@ -563,44 +565,31 @@ void CAutoResearch::FireStopUpdate(float progress, bool bLightOn)
// Saves all parameters of the controller. // Saves all parameters of the controller.
bool CAutoResearch::Write(char *line) bool CAutoResearch::Write(CLevelParserLine* line)
{ {
char name[100];
if ( m_phase == ALP_WAIT ) return false; if ( m_phase == ALP_WAIT ) return false;
sprintf(name, " aExist=%d", 1); line->AddParam("aExist", new CLevelParserParam(true));
strcat(line, name);
CAuto::Write(line); CAuto::Write(line);
line->AddParam("aPhase", new CLevelParserParam(static_cast<int>(m_phase)));
sprintf(name, " aPhase=%d", m_phase); line->AddParam("aProgress", new CLevelParserParam(m_progress));
strcat(line, name); line->AddParam("aSpeed", new CLevelParserParam(m_speed));
line->AddParam("aResearch", new CLevelParserParam(static_cast<int>(m_research)));
sprintf(name, " aProgress=%.2f", m_progress);
strcat(line, name);
sprintf(name, " aSpeed=%.2f", m_speed);
strcat(line, name);
sprintf(name, " aResearch=%d", m_research);
strcat(line, name);
return true; return true;
} }
// Restores all parameters of the controller. // Restores all parameters of the controller.
bool CAutoResearch::Read(char *line) bool CAutoResearch::Read(CLevelParserLine* line)
{ {
if ( OpInt(line, "aExist", 0) == 0 ) return false; if ( !line->GetParam("aExist")->AsBool(false) ) return false;
CAuto::Read(line); CAuto::Read(line);
m_phase = static_cast< AutoResearchPhase >(line->GetParam("aPhase")->AsInt(ALP_WAIT));
m_phase = static_cast< AutoResearchPhase >(OpInt(line, "aPhase", ALP_WAIT)); m_progress = line->GetParam("aProgress")->AsFloat(0.0f);
m_progress = OpFloat(line, "aProgress", 0.0f); m_speed = line->GetParam("aSpeed")->AsFloat(1.0f);
m_speed = OpFloat(line, "aSpeed", 1.0f); m_research = static_cast< ResearchType >(line->GetParam("aResearch")->AsInt(0));
m_research = static_cast< ResearchType >(OpInt(line, "aResearch", 0));
m_lastUpdateTime = 0.0f; m_lastUpdateTime = 0.0f;
m_lastParticle = 0.0f; m_lastParticle = 0.0f;

View File

@ -49,8 +49,8 @@ public:
bool CreateInterface(bool bSelect); bool CreateInterface(bool bSelect);
bool Write(char *line); bool Write(CLevelParserLine* line);
bool Read(char *line); bool Read(CLevelParserLine* line);
protected: protected:
void UpdateInterface(); void UpdateInterface();

View File

@ -25,6 +25,8 @@
#include "math/geometry.h" #include "math/geometry.h"
#include "object/robotmain.h" #include "object/robotmain.h"
#include "object/level/parserline.h"
#include "object/level/parserparam.h"
#include "script/cmdtoken.h" #include "script/cmdtoken.h"
@ -353,40 +355,29 @@ Error CAutoSafe::GetError()
// Saves all parameters of the controller. // Saves all parameters of the controller.
bool CAutoSafe::Write(char *line) bool CAutoSafe::Write(CLevelParserLine* line)
{ {
char name[100];
if ( m_phase == ASAP_WAIT ) return false; if ( m_phase == ASAP_WAIT ) return false;
sprintf(name, " aExist=%d", 1); line->AddParam("aExist", new CLevelParserParam(true));
strcat(line, name);
CAuto::Write(line); CAuto::Write(line);
line->AddParam("aPhase", new CLevelParserParam(static_cast<int>(m_phase)));
sprintf(name, " aPhase=%d", m_phase); line->AddParam("aProgress", new CLevelParserParam(m_progress));
strcat(line, name); line->AddParam("aSpeed", new CLevelParserParam(m_speed));
sprintf(name, " aProgress=%.2f", m_progress);
strcat(line, name);
sprintf(name, " aSpeed=%.2f", m_speed);
strcat(line, name);
return true; return true;
} }
// Restores all parameters of the controller. // Restores all parameters of the controller.
bool CAutoSafe::Read(char *line) bool CAutoSafe::Read(CLevelParserLine* line)
{ {
if ( OpInt(line, "aExist", 0) == 0 ) return false; if ( !line->GetParam("aExist")->AsBool(false) ) return false;
CAuto::Read(line); CAuto::Read(line);
m_phase = static_cast< AutoSafePhase >(line->GetParam("aPhase")->AsInt(ASAP_WAIT));
m_phase = static_cast< AutoSafePhase >(OpInt(line, "aPhase", ASAP_WAIT)); m_progress = line->GetParam("aProgress")->AsFloat(0.0f);
m_progress = OpFloat(line, "aProgress", 0.0f); m_speed = line->GetParam("aSpeed")->AsFloat(1.0f);
m_speed = OpFloat(line, "aSpeed", 1.0f);
m_lastParticle = 0.0f; m_lastParticle = 0.0f;

View File

@ -49,8 +49,8 @@ public:
bool CreateInterface(bool bSelect); bool CreateInterface(bool bSelect);
bool Write(char *line); bool Write(CLevelParserLine* line);
bool Read(char *line); bool Read(CLevelParserLine* line);
protected: protected:
int CountKeys(); int CountKeys();

View File

@ -24,6 +24,9 @@
#include "math/geometry.h" #include "math/geometry.h"
#include "object/level/parserline.h"
#include "object/level/parserparam.h"
#include "physics/physics.h" #include "physics/physics.h"
#include "script/cmdtoken.h" #include "script/cmdtoken.h"
@ -485,60 +488,39 @@ void CAutoTower::UpdateInterface(float rTime)
// Saves all parameters of the controller. // Saves all parameters of the controller.
bool CAutoTower::Write(char *line) bool CAutoTower::Write(CLevelParserLine* line)
{ {
char name[100];
if ( m_phase == ATP_WAIT ) return false; if ( m_phase == ATP_WAIT ) return false;
sprintf(name, " aExist=%d", 1); line->AddParam("aExist", new CLevelParserParam(true));
strcat(line, name);
CAuto::Write(line); CAuto::Write(line);
line->AddParam("aPhase", new CLevelParserParam(static_cast<int>(m_phase)));
sprintf(name, " aPhase=%d", m_phase); line->AddParam("aProgress", new CLevelParserParam(m_progress));
strcat(line, name); line->AddParam("aSpeed", new CLevelParserParam(m_speed));
line->AddParam("aTargetPos", new CLevelParserParam(m_targetPos));
sprintf(name, " aProgress=%.2f", m_progress); line->AddParam("aAngleYactual", new CLevelParserParam(m_angleYactual));
strcat(line, name); line->AddParam("aAngleZactual", new CLevelParserParam(m_angleZactual));
line->AddParam("aAngleYfinal", new CLevelParserParam(m_angleYfinal));
sprintf(name, " aSpeed=%.2f", m_speed); line->AddParam("aAngleZfinal", new CLevelParserParam(m_angleZfinal));
strcat(line, name);
sprintf(name, " aTargetPos=%.2f;%.2f;%.2f", m_targetPos.x, m_targetPos.y, m_targetPos.z);
strcat(line, name);
sprintf(name, " aAngleYactual=%.2f", m_angleYactual);
strcat(line, name);
sprintf(name, " aAngleZactual=%.2f", m_angleZactual);
strcat(line, name);
sprintf(name, " aAngleYfinal=%.2f", m_angleYfinal);
strcat(line, name);
sprintf(name, " aAngleZfinal=%.2f", m_angleZfinal);
strcat(line, name);
return true; return true;
} }
// Restores all parameters of the controller. // Restores all parameters of the controller.
bool CAutoTower::Read(char *line) bool CAutoTower::Read(CLevelParserLine* line)
{ {
if ( OpInt(line, "aExist", 0) == 0 ) return false; if ( !line->GetParam("aExist")->AsBool(false) ) return false;
CAuto::Read(line); CAuto::Read(line);
m_phase = static_cast< AutoTowerPhase >(line->GetParam("aPhase")->AsInt(ATP_WAIT));
m_phase = static_cast< AutoTowerPhase >(OpInt(line, "aPhase", ATP_WAIT)); m_progress = line->GetParam("aProgress")->AsFloat(0.0f);
m_progress = OpFloat(line, "aProgress", 0.0f); m_speed = line->GetParam("aSpeed")->AsFloat(1.0f);
m_speed = OpFloat(line, "aSpeed", 1.0f); m_targetPos = line->GetParam("aTargetPos")->AsPoint(Math::Vector());
m_targetPos = OpDir(line, "aTargetPos"); m_angleYactual = line->GetParam("aAngleYactual")->AsFloat(0.0f);
m_angleYactual = OpFloat(line, "aAngleYactual", 0.0f); m_angleZactual = line->GetParam("aAngleZactual")->AsFloat(0.0f);
m_angleZactual = OpFloat(line, "aAngleZactual", 0.0f); m_angleYfinal = line->GetParam("aAngleYfinal")->AsFloat(0.0f);
m_angleYfinal = OpFloat(line, "aAngleYfinal", 0.0f); m_angleZfinal = line->GetParam("aAngleZfinal")->AsFloat(0.0f);
m_angleZfinal = OpFloat(line, "aAngleZfinal", 0.0f);
m_lastUpdateTime = 0.0f; m_lastUpdateTime = 0.0f;

View File

@ -51,8 +51,8 @@ public:
bool CreateInterface(bool bSelect); bool CreateInterface(bool bSelect);
bool Write(char *line); bool Write(CLevelParserLine* line);
bool Read(char *line); bool Read(CLevelParserLine* line);
protected: protected:
void UpdateInterface(float rTime); void UpdateInterface(float rTime);

View File

@ -30,6 +30,8 @@
#include "object/motion/motion.h" #include "object/motion/motion.h"
#include "object/task/taskmanager.h" #include "object/task/taskmanager.h"
#include "object/level/parserline.h"
#include "object/level/parserparam.h"
#include "physics/physics.h" #include "physics/physics.h"
@ -169,21 +171,18 @@ void CBrain::SetMotion(CMotion* motion)
// Saves all parameters of the object. // Saves all parameters of the object.
bool CBrain::Write(char *line) bool CBrain::Write(CLevelParserLine* line)
{ {
char name[100]; line->AddParam("bVirusActive", new CLevelParserParam(m_bActiveVirus));
sprintf(name, " bVirusActive=%d", m_bActiveVirus);
strcat(line, name);
return true; return true;
} }
// Restores all parameters of the object. // Restores all parameters of the object.
bool CBrain::Read(char *line) bool CBrain::Read(CLevelParserLine* line)
{ {
m_bActiveVirus = OpInt(line, "bVirusActive", 0); m_bActiveVirus = line->GetParam("bVirusActive")->AsBool(false);
return true; return true;
} }

View File

@ -41,6 +41,7 @@ class CTaskManager;
class CScript; class CScript;
class CRobotMain; class CRobotMain;
class CSoundInterface; class CSoundInterface;
class CLevelParserLine;
namespace Ui { namespace Ui {
class CStudio; class CStudio;
@ -92,8 +93,8 @@ public:
bool EventProcess(const Event &event); bool EventProcess(const Event &event);
bool CreateInterface(bool bSelect); bool CreateInterface(bool bSelect);
bool Write(char *line); bool Write(CLevelParserLine* line);
bool Read(char *line); bool Read(CLevelParserLine* line);
bool IsBusy(); bool IsBusy();
void SetActivity(bool bMode); void SetActivity(bool bMode);

View File

@ -24,6 +24,7 @@
#include "common/resources/resourcemanager.h" #include "common/resources/resourcemanager.h"
#include "common/resources/inputstream.h" #include "common/resources/inputstream.h"
#include "common/resources/outputstream.h"
#include "object/level/parserexceptions.h" #include "object/level/parserexceptions.h"
@ -219,9 +220,22 @@ void CLevelParser::Load()
file.close(); file.close();
} }
void CLevelParser::Save(std::string filename) void CLevelParser::Save()
{ {
assert(false); //TODO COutputStream file;
file.open(m_filename);
if(!file.is_open())
throw CLevelParserException("Failed to open file: "+m_filename);
for(CLevelParserLine* line : m_lines) {
file << line->GetCommand();
for(auto param : line->GetParams()) {
file << " " << param.first << "=" << param.second->GetValue();
}
file << "\n";
}
file.close();
} }
const std::string& CLevelParser::GetFilename() const std::string& CLevelParser::GetFilename()

View File

@ -51,7 +51,7 @@ public:
//! Load file //! Load file
void Load(); void Load();
//! Save file //! Save file
void Save(std::string filename); void Save();
//! Get filename //! Get filename
const std::string& GetFilename(); const std::string& GetFilename();
@ -65,7 +65,6 @@ public:
CLevelParserLine* Get(std::string command); CLevelParserLine* Get(std::string command);
private: private:
std::string m_filename; std::string m_filename;
std::vector<CLevelParserLine*> m_lines; std::vector<CLevelParserLine*> m_lines;
}; };

View File

@ -43,11 +43,6 @@ CLevelParserLine::~CLevelParserLine()
} }
} }
std::string CLevelParserLine::GetLine()
{
assert(false); //TODO
}
int CLevelParserLine::GetLineNumber() int CLevelParserLine::GetLineNumber()
{ {
return m_lineNumber; return m_lineNumber;
@ -87,4 +82,9 @@ void CLevelParserLine::AddParam(std::string name, CLevelParserParam* value)
{ {
value->SetLine(this); value->SetLine(this);
m_params[name] = value; m_params[name] = value;
}
const std::map<std::string, CLevelParserParam*>& CLevelParserLine::GetParams()
{
return m_params;
} }

View File

@ -37,9 +37,6 @@ public:
CLevelParserLine(std::string command); CLevelParserLine(std::string command);
~CLevelParserLine(); ~CLevelParserLine();
//! Get line to be saved in level file
std::string GetLine();
//! Get line number //! Get line number
int GetLineNumber(); int GetLineNumber();
@ -53,6 +50,7 @@ public:
CLevelParserParam* GetParam(std::string name); CLevelParserParam* GetParam(std::string name);
void AddParam(std::string name, CLevelParserParam* value); void AddParam(std::string name, CLevelParserParam* value);
const std::map<std::string, CLevelParserParam*>& GetParams();
private: private:
CLevelParser* m_level; CLevelParser* m_level;

View File

@ -939,6 +939,18 @@ void CLevelParserParam::ParseArray()
} }
} }
void CLevelParserParam::LoadArray()
{
m_value = "";
bool first = true;
for(auto& value : m_array) {
if(!first)
m_value += ";";
m_value += value->GetValue();
first = false;
}
}
const std::vector<CLevelParserParam*>& CLevelParserParam::AsArray() const std::vector<CLevelParserParam*>& CLevelParserParam::AsArray()
{ {
if(m_empty) if(m_empty)
@ -947,4 +959,56 @@ const std::vector<CLevelParserParam*>& CLevelParserParam::AsArray()
ParseArray(); ParseArray();
return m_array; return m_array;
} }
CLevelParserParam::CLevelParserParam(int value)
{
m_value = boost::lexical_cast<std::string>(value);
}
CLevelParserParam::CLevelParserParam(float value)
{
m_value = boost::lexical_cast<std::string>(value);
}
CLevelParserParam::CLevelParserParam(std::string value)
{
m_value = "\""+value+"\"";
}
CLevelParserParam::CLevelParserParam(bool value)
{
m_value = value ? "1" : "0";
}
CLevelParserParam::CLevelParserParam(Gfx::Color value)
{
m_array.push_back(new CLevelParserParam(value.r));
m_array.push_back(new CLevelParserParam(value.g));
m_array.push_back(new CLevelParserParam(value.b));
m_array.push_back(new CLevelParserParam(value.a));
LoadArray();
}
CLevelParserParam::CLevelParserParam(Math::Point value)
{
m_array.push_back(new CLevelParserParam(value.x));
m_array.push_back(new CLevelParserParam(value.y));
LoadArray();
}
CLevelParserParam::CLevelParserParam(Math::Vector value)
{
m_array.push_back(new CLevelParserParam(value.x));
m_array.push_back(new CLevelParserParam(value.y));
m_array.push_back(new CLevelParserParam(value.z));
LoadArray();
}
CLevelParserParam::CLevelParserParam(ObjectType value)
{
m_value = FromObjectType(value);
}
CLevelParserParam::CLevelParserParam(Gfx::CameraType value)
{
m_value = FromCameraType(value);
}
CLevelParserParam::CLevelParserParam(const std::vector<CLevelParserParam*>& value)
{
m_array = value;
LoadArray();
}

View File

@ -45,6 +45,7 @@ public:
CLevelParserParam(bool value); CLevelParserParam(bool value);
CLevelParserParam(Gfx::Color value); CLevelParserParam(Gfx::Color value);
CLevelParserParam(Math::Point value); CLevelParserParam(Math::Point value);
CLevelParserParam(Math::Vector value);
CLevelParserParam(ObjectType value); CLevelParserParam(ObjectType value);
CLevelParserParam(Gfx::CameraType value); CLevelParserParam(Gfx::CameraType value);
CLevelParserParam(const std::vector<CLevelParserParam*>& value); CLevelParserParam(const std::vector<CLevelParserParam*>& value);
@ -110,6 +111,7 @@ public:
private: private:
void ParseArray(); void ParseArray();
void LoadArray();
template<typename T> T Cast(std::string value, std::string requestedType); template<typename T> T Cast(std::string value, std::string requestedType);
template<typename T> T Cast(std::string requestedType); template<typename T> T Cast(std::string requestedType);

View File

@ -23,6 +23,8 @@
#include "app/app.h" #include "app/app.h"
#include "object/robotmain.h" #include "object/robotmain.h"
#include "object/level/parserline.h"
#include "object/level/parserparam.h"
#include "script/cmdtoken.h" #include "script/cmdtoken.h"
@ -171,31 +173,24 @@ float CMotion::GetParam(int rank)
// Saves all parameters of the object. // Saves all parameters of the object.
bool CMotion::Write(char *line) bool CMotion::Write(CLevelParserLine* line)
{ {
char name[100];
if ( m_actionType == -1 ) return false; if ( m_actionType == -1 ) return false;
sprintf(name, " mType=%d", m_actionType); line->AddParam("mType", new CLevelParserParam(m_actionType));
strcat(line, name); line->AddParam("mTime", new CLevelParserParam(m_actionTime));
line->AddParam("mProgress", new CLevelParserParam(m_progress));
sprintf(name, " mTime=%.2f", m_actionTime);
strcat(line, name);
sprintf(name, " mProgress=%.2f", m_progress);
strcat(line, name);
return false; return false;
} }
// Restores all parameters of the object. // Restores all parameters of the object.
bool CMotion::Read(char *line) bool CMotion::Read(CLevelParserLine* line)
{ {
m_actionType = OpInt(line, "mType", -1); m_actionType = line->GetParam("mType")->AsInt(-1);
m_actionTime = OpFloat(line, "mTime", 0.0f); m_actionTime = line->GetParam("mTime")->AsFloat(0.0f);
m_progress = OpFloat(line, "mProgress", 0.0f); m_progress = line->GetParam("mProgress")->AsFloat(0.0f);
return false; return false;
} }

View File

@ -42,6 +42,7 @@ class CPhysics;
class CObject; class CObject;
class CRobotMain; class CRobotMain;
class CSoundInterface; class CSoundInterface;
class CLevelParserLine;
class CMotion class CMotion
@ -62,8 +63,8 @@ public:
virtual bool SetParam(int rank, float value); virtual bool SetParam(int rank, float value);
virtual float GetParam(int rank); virtual float GetParam(int rank);
virtual bool Write(char *line); virtual bool Write(CLevelParserLine* line);
virtual bool Read(char *line); virtual bool Read(CLevelParserLine* line);
virtual void SetLinVibration(Math::Vector dir); virtual void SetLinVibration(Math::Vector dir);
virtual Math::Vector GetLinVibration(); virtual Math::Vector GetLinVibration();

View File

@ -76,12 +76,17 @@
#include "object/motion/motionworm.h" #include "object/motion/motionworm.h"
#include "object/robotmain.h" #include "object/robotmain.h"
#include "object/objman.h" #include "object/objman.h"
#include "object/level/parserline.h"
#include "object/level/parserparam.h"
#include "object/level/parserexceptions.h"
#include "physics/physics.h" #include "physics/physics.h"
#include "script/cbottoken.h" #include "script/cbottoken.h"
#include "script/cmdtoken.h" #include "script/cmdtoken.h"
#include <boost/lexical_cast.hpp>
#define ADJUST_ONBOARD false // true -> adjusts the camera ONBOARD #define ADJUST_ONBOARD false // true -> adjusts the camera ONBOARD
@ -995,137 +1000,76 @@ int CObject::GetID()
// Saves all the parameters of the object. // Saves all the parameters of the object.
bool CObject::Write(char *line) bool CObject::Write(CLevelParserLine* line)
{ {
Math::Vector pos; Math::Vector pos;
Info info; Info info;
char name[100];
float value; float value;
int i; int i;
sprintf(name, " camera=%s", GetCamera(GetCameraType())); line->AddParam("camera", new CLevelParserParam(GetCameraType()));
strcat(line, name);
if ( GetCameraLock() != 0 ) if ( GetCameraLock() )
{ line->AddParam("cameraLock", new CLevelParserParam(GetCameraLock()));
sprintf(name, " cameraLock=%d", GetCameraLock());
strcat(line, name);
}
if ( GetEnergy() != 0.0f ) if ( GetEnergy() != 0.0f )
{ line->AddParam("energy", new CLevelParserParam(GetEnergy()));
sprintf(name, " energy=%.2f", GetEnergy());
strcat(line, name);
}
if ( GetCapacity() != 1.0f ) if ( GetCapacity() != 1.0f )
{ line->AddParam("capacity", new CLevelParserParam(GetCapacity()));
sprintf(name, " capacity=%.2f", GetCapacity());
strcat(line, name);
}
if ( GetShield() != 1.0f ) if ( GetShield() != 1.0f )
{ line->AddParam("shield", new CLevelParserParam(GetShield()));
sprintf(name, " shield=%.2f", GetShield());
strcat(line, name);
}
if ( GetRange() != 1.0f ) if ( GetRange() != 1.0f )
{ line->AddParam("range", new CLevelParserParam(GetRange()));
sprintf(name, " range=%.2f", GetRange());
strcat(line, name); if ( !GetSelectable() )
} line->AddParam("selectable", new CLevelParserParam(GetSelectable()));
if ( GetSelectable() != 1 ) if ( !GetEnable() )
{ line->AddParam("enable", new CLevelParserParam(GetEnable()));
sprintf(name, " selectable=%d", GetSelectable());
strcat(line, name);
}
if ( GetEnable() != 1 ) if ( GetFixed() )
{ line->AddParam("fixed", new CLevelParserParam(GetFixed()));
sprintf(name, " enable=%d", GetEnable());
strcat(line, name);
}
if ( GetFixed() != 0 ) if ( !GetClip() )
{ line->AddParam("clip", new CLevelParserParam(GetClip()));
sprintf(name, " fixed=%d", GetFixed());
strcat(line, name);
}
if ( GetClip() != 1 ) if ( GetLock() )
{ line->AddParam("lock", new CLevelParserParam(GetLock()));
sprintf(name, " clip=%d", GetClip());
strcat(line, name);
}
if ( GetLock() != 0 ) if ( GetProxyActivate() )
{ {
sprintf(name, " lock=%d", GetLock()); line->AddParam("proxyActivate", new CLevelParserParam(GetProxyActivate()));
strcat(line, name); line->AddParam("proxyDistance", new CLevelParserParam(GetProxyDistance()/g_unit));
}
if ( GetProxyActivate() != 0 )
{
sprintf(name, " proxyActivate=%d", GetProxyActivate());
strcat(line, name);
sprintf(name, " proxyDistance=%.2f", GetProxyDistance()/g_unit);
strcat(line, name);
} }
if ( GetMagnifyDamage() != 1.0f ) if ( GetMagnifyDamage() != 1.0f )
{ line->AddParam("magnifyDamage", new CLevelParserParam(GetMagnifyDamage()));
sprintf(name, " magnifyDamage=%.2f", GetMagnifyDamage());
strcat(line, name);
}
if ( GetGunGoalV() != 0.0f ) if ( GetGunGoalV() != 0.0f )
{ line->AddParam("aimV", new CLevelParserParam(GetGunGoalV()));
sprintf(name, " aimV=%.2f", GetGunGoalV());
strcat(line, name);
}
if ( GetGunGoalH() != 0.0f ) if ( GetGunGoalH() != 0.0f )
{ line->AddParam("aimH", new CLevelParserParam(GetGunGoalH()));
sprintf(name, " aimH=%.2f", GetGunGoalH());
strcat(line, name);
}
if ( GetParam() != 0.0f ) if ( GetParam() != 0.0f )
{ line->AddParam("param", new CLevelParserParam(GetParam()));
sprintf(name, " param=%.2f", GetParam());
strcat(line, name);
}
if ( GetResetCap() != 0 ) if ( GetResetCap() != 0 )
{ {
sprintf(name, " resetCap=%d", GetResetCap()); line->AddParam("resetCap", new CLevelParserParam(static_cast<int>(GetResetCap())));
strcat(line, name); line->AddParam("resetPos", new CLevelParserParam(GetResetPosition()/g_unit));
line->AddParam("resetAngle", new CLevelParserParam(GetResetAngle()/(Math::PI/180.0f)));
pos = GetResetPosition()/g_unit; line->AddParam("resetRun", new CLevelParserParam(GetResetRun()));
sprintf(name, " resetPos=%.2f;%.2f;%.2f", pos.x, pos.y, pos.z);
strcat(line, name);
pos = GetResetAngle()/(Math::PI/180.0f);
sprintf(name, " resetAngle=%.2f;%.2f;%.2f", pos.x, pos.y, pos.z);
strcat(line, name);
sprintf(name, " resetRun=%d", GetResetRun());
strcat(line, name);
} }
if ( m_bVirusMode != 0 ) if ( m_bVirusMode )
{ line->AddParam("virusMode", new CLevelParserParam(m_bVirusMode));
sprintf(name, " virusMode=%d", m_bVirusMode);
strcat(line, name);
}
if ( m_virusTime != 0.0f ) if ( m_virusTime != 0.0f )
{ line->AddParam("virusTime", new CLevelParserParam(m_virusTime));
sprintf(name, " virusTime=%.2f", m_virusTime);
strcat(line, name);
}
// Puts information in terminal (OBJECT_INFO). // Puts information in terminal (OBJECT_INFO).
for ( i=0 ; i<m_infoTotal ; i++ ) for ( i=0 ; i<m_infoTotal ; i++ )
@ -1133,37 +1077,37 @@ bool CObject::Write(char *line)
info = GetInfo(i); info = GetInfo(i);
if ( info.name[0] == 0 ) break; if ( info.name[0] == 0 ) break;
sprintf(name, " info%d=\"%s=%.2f\"", i+1, info.name, info.value); line->AddParam("info"+boost::lexical_cast<std::string>(i+1), new CLevelParserParam(std::string(info.name)+"="+boost::lexical_cast<std::string>(info.value)));
strcat(line, name);
} }
// Sets the parameters of the command line. // Sets the parameters of the command line.
std::vector<CLevelParserParam*> cmdline;
for ( i=0 ; i<OBJECTMAXCMDLINE ; i++ ) for ( i=0 ; i<OBJECTMAXCMDLINE ; i++ )
{ {
value = GetCmdLine(i); value = GetCmdLine(i);
if ( value == NAN ) break; if ( isnan(value) ) break;
if ( i == 0 ) sprintf(name, " cmdline=%.2f", value); cmdline.push_back(new CLevelParserParam(value));
else sprintf(name, ";%.2f", value);
strcat(line, name);
} }
if(cmdline.size() > 0)
line->AddParam("cmdline", new CLevelParserParam(cmdline));
if ( m_motion != 0 ) if ( m_motion != nullptr )
{ {
m_motion->Write(line); m_motion->Write(line);
} }
if ( m_brain != 0 ) if ( m_brain != nullptr )
{ {
m_brain->Write(line); m_brain->Write(line);
} }
if ( m_physics != 0 ) if ( m_physics != nullptr )
{ {
m_physics->Write(line); m_physics->Write(line);
} }
if ( m_auto != 0 ) if ( m_auto != nullptr )
{ {
m_auto->Write(line); m_auto->Write(line);
} }
@ -1173,87 +1117,91 @@ bool CObject::Write(char *line)
// Returns all parameters of the object. // Returns all parameters of the object.
bool CObject::Read(char *line) bool CObject::Read(CLevelParserLine* line)
{ {
Math::Vector pos, dir; Math::Vector pos, dir;
Info info;
Gfx::CameraType cType; Gfx::CameraType cType;
char op[20];
char text[100];
char* p;
float value;
int i; int i;
cType = OpCamera(line, "camera"); cType = line->GetParam("camera")->AsCameraType(Gfx::CAM_TYPE_NULL);
if ( cType != Gfx::CAM_TYPE_NULL ) if ( cType != Gfx::CAM_TYPE_NULL )
{ {
SetCameraType(cType); SetCameraType(cType);
} }
SetCameraLock(OpInt(line, "cameraLock", 0)); SetCameraLock(line->GetParam("cameraLock")->AsBool(false));
SetEnergy(OpFloat(line, "energy", 0.0f)); SetEnergy(line->GetParam("energy")->AsFloat(0.0f));
SetCapacity(OpFloat(line, "capacity", 1.0f)); SetCapacity(line->GetParam("capacity")->AsFloat(1.0f));
SetShield(OpFloat(line, "shield", 1.0f)); SetShield(line->GetParam("shield")->AsFloat(1.0f));
SetRange(OpFloat(line, "range", 1.0f)); SetRange(line->GetParam("range")->AsFloat(1.0f));
SetSelectable(OpInt(line, "selectable", 1)); SetSelectable(line->GetParam("selectable")->AsBool(true));
SetEnable(OpInt(line, "enable", 1)); SetEnable(line->GetParam("enable")->AsBool(true));
SetFixed(OpInt(line, "fixed", 0)); SetFixed(line->GetParam("fixed")->AsBool(false));
SetClip(OpInt(line, "clip", 1)); SetClip(line->GetParam("clip")->AsBool(true));
SetLock(OpInt(line, "lock", 0)); SetLock(line->GetParam("lock")->AsBool(false));
SetProxyActivate(OpInt(line, "proxyActivate", 0)); SetProxyActivate(line->GetParam("proxyActivate")->AsBool(false));
SetProxyDistance(OpFloat(line, "proxyDistance", 15.0f)*g_unit); SetProxyDistance(line->GetParam("proxyDistance")->AsFloat(15.0f)*g_unit);
SetRange(OpFloat(line, "range", 30.0f)); SetRange(line->GetParam("range")->AsFloat(30.0f));
SetMagnifyDamage(OpFloat(line, "magnifyDamage", 1.0f)); SetMagnifyDamage(line->GetParam("magnifyDamage")->AsFloat(1.0f));
SetGunGoalV(OpFloat(line, "aimV", 0.0f)); SetGunGoalV(line->GetParam("aimV")->AsFloat(0.0f));
SetGunGoalH(OpFloat(line, "aimH", 0.0f)); SetGunGoalH(line->GetParam("aimH")->AsFloat(0.0f));
SetParam(OpFloat(line, "param", 0.0f)); SetParam(line->GetParam("param")->AsFloat(0.0f));
SetResetCap(static_cast<ResetCap>(OpInt(line, "resetCap", 0))); SetResetCap(static_cast<ResetCap>(line->GetParam("resetCap")->AsInt(0)));
SetResetPosition(OpDir(line, "resetPos")*g_unit); SetResetPosition(line->GetParam("resetPos")->AsPoint(Math::Vector())*g_unit);
SetResetAngle(OpDir(line, "resetAngle")*(Math::PI/180.0f)); SetResetAngle(line->GetParam("resetAngle")->AsPoint(Math::Vector())*(Math::PI/180.0f));
SetResetRun(OpInt(line, "resetRun", 0)); SetResetRun(line->GetParam("resetRun")->AsInt(0));
m_bBurn = OpInt(line, "burnMode", 0); m_bBurn = line->GetParam("burnMode")->AsBool(false);
m_bVirusMode = OpInt(line, "virusMode", 0); m_bVirusMode = line->GetParam("virusMode")->AsBool(false);
m_virusTime = OpFloat(line, "virusTime", 0.0f); m_virusTime = line->GetParam("virusTime")->AsFloat(0.0f);
// Puts information in terminal (OBJECT_INFO). // Puts information in terminal (OBJECT_INFO).
for ( i=0 ; i<OBJECTMAXINFO ; i++ ) for ( i=0 ; i<OBJECTMAXINFO ; i++ )
{ {
sprintf(op, "info%d", i+1); std::string op = std::string("info")+boost::lexical_cast<std::string>(i+1);
OpString(line, op, text); if(!line->GetParam(op)->IsDefined()) break;
if ( text[0] == 0 ) break; std::string text = line->GetParam(op)->AsString();
p = strchr(text, '=');
if ( p == 0 ) break; std::size_t p = text.find_first_of("=");
*p = 0; if(p == std::string::npos)
strcpy(info.name, text); throw CLevelParserExceptionBadParam(line->GetParam(op), "info");
sscanf(p+1, "%f", &info.value); Info info;
strcpy(info.name, text.substr(0, p).c_str());
try {
info.value = boost::lexical_cast<float>(text.substr(p+1).c_str());
}
catch(...)
{
throw CLevelParserExceptionBadParam(line->GetParam(op), "info.value (float)");
}
SetInfo(i, info); SetInfo(i, info);
} }
// Sets the parameters of the command line. // Sets the parameters of the command line.
p = SearchOp(line, "cmdline"); i = 0;
for ( i=0 ; i<OBJECTMAXCMDLINE ; i++ ) if(line->GetParam("cmdline")->IsDefined()) {
{ for(auto& p : line->GetParam("cmdline")->AsArray()) {
value = GetFloat(p, i, NAN); if(i >= OBJECTMAXCMDLINE) break;
if ( value == NAN ) break; SetCmdLine(i, p->AsFloat());
SetCmdLine(i, value); }
} }
if ( m_motion != 0 ) if ( m_motion != nullptr )
{ {
m_motion->Read(line); m_motion->Read(line);
} }
if ( m_brain != 0 ) if ( m_brain != nullptr )
{ {
m_brain->Read(line); m_brain->Read(line);
} }
if ( m_physics != 0 ) if ( m_physics != nullptr )
{ {
m_physics->Read(line); m_physics->Read(line);
} }
if ( m_auto != 0 ) if ( m_auto != nullptr )
{ {
m_auto->Read(line); m_auto->Read(line);
} }

View File

@ -40,6 +40,7 @@ class CDisplayText;
class CRobotMain; class CRobotMain;
class CBotVar; class CBotVar;
class CScript; class CScript;
class CLevelParserLine;
/** /**
@ -379,8 +380,8 @@ public:
void SetID(int id); void SetID(int id);
int GetID(); int GetID();
bool Write(char *line); bool Write(CLevelParserLine* line);
bool Read(char *line); bool Read(CLevelParserLine* line);
void SetDrawWorld(bool bDraw); void SetDrawWorld(bool bDraw);
void SetDrawFront(bool bDraw); void SetDrawFront(bool bDraw);

View File

@ -34,6 +34,7 @@
#include "common/resources/resourcemanager.h" #include "common/resources/resourcemanager.h"
#include "common/resources/inputstream.h" #include "common/resources/inputstream.h"
#include "common/resources/outputstream.h"
#include "graphics/engine/camera.h" #include "graphics/engine/camera.h"
#include "graphics/engine/cloud.h" #include "graphics/engine/cloud.h"
@ -99,7 +100,6 @@ const int MAX_FNAME = 255;
#define CBOT_STACK true // saves the stack of programs CBOT
const float UNIT = 4.0f; const float UNIT = 4.0f;
@ -3781,8 +3781,6 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
int rankGadget = 0; int rankGadget = 0;
CObject* sel = 0; CObject* sel = 0;
SetNumericLocale();
/* /*
* NOTE: Moving frequently used lines to the top * NOTE: Moving frequently used lines to the top
* may speed up loading * may speed up loading
@ -4774,8 +4772,6 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
} }
m_dialog->SetSceneRead(""); m_dialog->SetSceneRead("");
m_dialog->SetStackRead(""); m_dialog->SetStackRead("");
RestoreNumericLocale();
if(m_app->GetSceneTestMode()) if(m_app->GetSceneTestMode())
m_eventQueue->AddEvent(Event(EVENT_WIN)); m_eventQueue->AddEvent(Event(EVENT_WIN));
@ -5341,23 +5337,6 @@ void CRobotMain::FrameShowLimit(float rTime)
} }
//! Returns a pointer to the last slash in a filename.
char* SearchLastDir(char *filename)
{
char* p = filename;
while (*p++ != 0);
p --; // ^on the zero terminator
while (p != filename)
{
if (*(--p) == '/' || *p == '\\') return p;
}
return 0;
}
//! Compiles all scripts of robots //! Compiles all scripts of robots
void CRobotMain::CompileScript(bool soluce) void CRobotMain::CompileScript(bool soluce)
{ {
@ -5460,7 +5439,7 @@ void CRobotMain::LoadOneScript(CObject *obj, int &nbError)
char filename[MAX_FNAME]; char filename[MAX_FNAME];
sprintf(filename, "%s/%s/%c%.3d%.3d%.1d.txt", sprintf(filename, "%s/%s/%c%.3d%.3d%.1d.txt",
GetPHYSFSSavegameDir(), m_gamerName.c_str(), name[0], rank, objRank, i); GetSavegameDir(), m_gamerName.c_str(), name[0], rank, objRank, i);
brain->ReadProgram(i, filename); brain->ReadProgram(i, filename);
if (!brain->GetCompile(i)) nbError++; if (!brain->GetCompile(i)) nbError++;
} }
@ -5478,23 +5457,13 @@ void CRobotMain::LoadFileScript(CObject *obj, const char* filename, int objRank,
ObjectType type = obj->GetType(); ObjectType type = obj->GetType();
if (type == OBJECT_HUMAN) return; if (type == OBJECT_HUMAN) return;
std::string dirname = filename;
dirname = dirname.substr(0, dirname.find_last_of("/"));
std::string fnstr = filename; char fn[MAX_FNAME]; //TODO: Refactor to std::string
std::string savedir = CResourceManager::GetSaveLocation()+"/";
boost::replace_all(fnstr, "\\", "/");
boost::replace_all(savedir, "\\", "/");
boost::replace_all(fnstr, savedir, ""); //TODO: Refactor to get physfs path here
//TODO: Refactor to std::string
char fn[MAX_FNAME];
strcpy(fn, fnstr.c_str());
char* ldir = SearchLastDir(fn);
if (ldir == 0) return;
for (int i = 0; i < BRAINMAXSCRIPT; i++) for (int i = 0; i < BRAINMAXSCRIPT; i++)
{ {
if (brain->GetCompile(i)) continue; sprintf(fn, "%s/prog%.3d%.1d.txt", dirname.c_str(), objRank, i);
sprintf(ldir, "/prog%.3d%.1d.txt", objRank, i);
brain->ReadProgram(i, fn); brain->ReadProgram(i, fn);
if (!brain->GetCompile(i)) nbError++; if (!brain->GetCompile(i)) nbError++;
} }
@ -5536,7 +5505,7 @@ void CRobotMain::SaveOneScript(CObject *obj)
{ {
char filename[MAX_FNAME]; char filename[MAX_FNAME];
sprintf(filename, "%s/%s/%c%.3d%.3d%.1d.txt", sprintf(filename, "%s/%s/%c%.3d%.3d%.1d.txt",
GetPHYSFSSavegameDir(), m_gamerName.c_str(), name[0], rank, objRank, i); GetSavegameDir(), m_gamerName.c_str(), name[0], rank, objRank, i);
brain->WriteProgram(i, filename); brain->WriteProgram(i, filename);
} }
} }
@ -5552,21 +5521,14 @@ void CRobotMain::SaveFileScript(CObject *obj, const char* filename, int objRank)
ObjectType type = obj->GetType(); ObjectType type = obj->GetType();
if (type == OBJECT_HUMAN) return; if (type == OBJECT_HUMAN) return;
std::string fnstr = filename; std::string dirname = filename;
std::string savedir = CResourceManager::GetSaveLocation()+"/"; dirname = dirname.substr(0, dirname.find_last_of("/"));
boost::replace_all(fnstr, "\\", "/");
boost::replace_all(savedir, "\\", "/"); char fn[MAX_FNAME]; //TODO: Refactor to std::string
boost::replace_all(fnstr, savedir, ""); //TODO: Refactor to get physfs path here
//TODO: Refactor to std::string
char fn[MAX_FNAME];
strcpy(fn, fnstr.c_str());
char* ldir = SearchLastDir(fn);
if (ldir == 0) return;
for (int i = 0; i < BRAINMAXSCRIPT; i++) for (int i = 0; i < BRAINMAXSCRIPT; i++)
{ {
sprintf(ldir, "/prog%.3d%.1d.txt", objRank, i); sprintf(fn, "%s/prog%.3d%.1d.txt", dirname.c_str(), objRank, i);
brain->WriteProgram(i, fn); brain->WriteProgram(i, fn);
} }
} }
@ -5665,37 +5627,17 @@ bool CRobotMain::IsBusy()
} }
//! Writes an object into the backup file //! Writes an object into the backup file
void CRobotMain::IOWriteObject(FILE *file, CObject* obj, const char *cmd) void CRobotMain::IOWriteObject(CLevelParserLine* line, CObject* obj)
{ {
if (obj->GetType() == OBJECT_FIX) return; if (obj->GetType() == OBJECT_FIX) return;
SetNumericLocale(); line->AddParam("type", new CLevelParserParam(obj->GetType()));
line->AddParam("id", new CLevelParserParam(obj->GetID()));
char line[3000]; line->AddParam("pos", new CLevelParserParam(obj->GetPosition(0)/g_unit));
char name[100]; line->AddParam("angle", new CLevelParserParam(obj->GetAngle(0)/(Math::PI/180.0f)));
line->AddParam("zoom", new CLevelParserParam(obj->GetZoom(0)));
strcpy(line, cmd);
sprintf(name, " type=%s", GetTypeObject(obj->GetType()));
strcat(line, name);
sprintf(name, " id=%d", obj->GetID());
strcat(line, name);
Math::Vector pos; Math::Vector pos;
pos = obj->GetPosition(0)/g_unit;
sprintf(name, " pos=%.2f;%.2f;%.2f", pos.x, pos.y, pos.z);
strcat(line, name);
pos = obj->GetAngle(0)/(Math::PI/180.0f);
sprintf(name, " angle=%.2f;%.2f;%.2f", pos.x, pos.y, pos.z);
strcat(line, name);
pos = obj->GetZoom(0);
sprintf(name, " zoom=%.2f;%.2f;%.2f", pos.x, pos.y, pos.z);
strcat(line, name);
for (int i = 1; i < OBJECTMAXPART; i++) for (int i = 1; i < OBJECTMAXPART; i++)
{ {
if (obj->GetObjectRank(i) == -1) continue; if (obj->GetObjectRank(i) == -1) continue;
@ -5704,104 +5646,94 @@ void CRobotMain::IOWriteObject(FILE *file, CObject* obj, const char *cmd)
if (pos.x != 0.0f || pos.y != 0.0f || pos.z != 0.0f) if (pos.x != 0.0f || pos.y != 0.0f || pos.z != 0.0f)
{ {
pos /= g_unit; pos /= g_unit;
sprintf(name, " p%d=%.2f;%.2f;%.2f", i, pos.x, pos.y, pos.z); line->AddParam("p"+boost::lexical_cast<std::string>(i), new CLevelParserParam(pos));
strcat(line, name);
} }
pos = obj->GetAngle(i); pos = obj->GetAngle(i);
if (pos.x != 0.0f || pos.y != 0.0f || pos.z != 0.0f) if (pos.x != 0.0f || pos.y != 0.0f || pos.z != 0.0f)
{ {
pos /= (Math::PI/180.0f); pos /= (Math::PI/180.0f);
sprintf(name, " a%d=%.2f;%.2f;%.2f", i, pos.x, pos.y, pos.z); line->AddParam("a"+boost::lexical_cast<std::string>(i), new CLevelParserParam(pos));
strcat(line, name);
} }
pos = obj->GetZoom(i); pos = obj->GetZoom(i);
if (pos.x != 1.0f || pos.y != 1.0f || pos.z != 1.0f) if (pos.x != 1.0f || pos.y != 1.0f || pos.z != 1.0f)
{ {
sprintf(name, " z%d=%.2f;%.2f;%.2f", i, pos.x, pos.y, pos.z); line->AddParam("z"+boost::lexical_cast<std::string>(i), new CLevelParserParam(pos));
strcat(line, name);
} }
} }
sprintf(name, " trainer=%d", obj->GetTrainer()); line->AddParam("trainer", new CLevelParserParam(obj->GetTrainer()));
strcat(line, name); line->AddParam("ignoreBuildCheck", new CLevelParserParam(obj->GetIgnoreBuildCheck()));
line->AddParam("option", new CLevelParserParam(obj->GetOption()));
if (obj == m_infoObject)
line->AddParam("select", new CLevelParserParam(1));
sprintf(name, " ignoreBuildCheck=%d", obj->GetIgnoreBuildCheck());
strcat(line, name);
sprintf(name, " option=%d", obj->GetOption());
strcat(line, name);
if (obj == m_infoObject) // selects object?
{
sprintf(name, " select=1");
strcat(line, name);
}
obj->Write(line); obj->Write(line);
if (obj->GetType() == OBJECT_BASE) if(obj->GetType() == OBJECT_BASE)
{ line->AddParam("run", new CLevelParserParam(3)); // stops and open (PARAM_FIXSCENE)
sprintf(name, " run=3"); // stops and open (PARAM_FIXSCENE)
strcat(line, name);
}
CBrain* brain = obj->GetBrain(); CBrain* brain = obj->GetBrain();
if (brain != nullptr) if (brain != nullptr)
{ {
int run = brain->GetProgram(); int run = brain->GetProgram();
if (run != -1) if (run != -1)
{ {
sprintf(name, " run=%d", run+1); line->AddParam("run", new CLevelParserParam(run+1));
strcat(line, name);
} }
} }
strcat(line, "\n");
fputs(line, file);
RestoreNumericLocale();
} }
//! Saves the current game //! Saves the current game
bool CRobotMain::IOWriteScene(const char *filename, const char *filecbot, char *info) bool CRobotMain::IOWriteScene(const char *filename, const char *filecbot, char *info)
{ {
FILE* file = fopen(filename, "w"); std::string fnstr = filename;
if (file == NULL) return false; std::string savedir = CResourceManager::GetSaveLocation()+"/";
boost::replace_all(fnstr, "\\", "/");
boost::replace_all(savedir, "\\", "/");
boost::replace_all(fnstr, savedir, ""); //TODO: Refactor to get physfs path here
CLevelParser* level = new CLevelParser(fnstr);
CLevelParserLine* line;
SetNumericLocale(); line = new CLevelParserLine("Title");
line->AddParam("text", new CLevelParserParam(std::string(info)));
char line[500]; level->AddLine(line);
sprintf(line, "Title text=\"%s\"\n", info); //TODO: Do we need that? It's not used anyway
fputs(line, file); line = new CLevelParserLine("Version");
line->AddParam("maj", new CLevelParserParam(0));
sprintf(line, "Version maj=%d min=%d\n", 0, 1); line->AddParam("min", new CLevelParserParam(1));
fputs(line, file); level->AddLine(line);
char* name = m_dialog->GetSceneName(); char* name = m_dialog->GetSceneName();
if (strcmp(name, "user") == 0) line = new CLevelParserLine("Mission");
line->AddParam("base", new CLevelParserParam(std::string(name)));
line->AddParam("rank", new CLevelParserParam(m_dialog->GetSceneRank()));
if (std::string(name) == "custom")
{ {
sprintf(line, "Mission base=\"%s\" rank=%.3d dir=\"%s\"\n", name, m_dialog->GetSceneRank(), m_dialog->GetSceneDir()); line->AddParam("dir", new CLevelParserParam(std::string(m_dialog->GetSceneDir())));
} }
else level->AddLine(line);
{
sprintf(line, "Mission base=\"%s\" rank=%.3d\n", name, m_dialog->GetSceneRank());
}
fputs(line, file);
sprintf(line, "Map zoom=%.2f\n", m_map->GetZoomMap()); line = new CLevelParserLine("Map");
fputs(line, file); line->AddParam("zoom", new CLevelParserParam(m_map->GetZoomMap()));
level->AddLine(line);
sprintf(line, "DoneResearch bits=%d\n", static_cast<int>(g_researchDone)); line = new CLevelParserLine("DoneResearch");
fputs(line, file); line->AddParam("bits", new CLevelParserParam(static_cast<int>(g_researchDone)));
level->AddLine(line);
float sleep, delay, magnetic, progress; float sleep, delay, magnetic, progress;
if (m_lightning->GetStatus(sleep, delay, magnetic, progress)) if (m_lightning->GetStatus(sleep, delay, magnetic, progress))
{ {
sprintf(line, "BlitzMode sleep=%.2f delay=%.2f magnetic=%.2f progress=%.2f\n", sleep, delay, magnetic/g_unit, progress); line = new CLevelParserLine("BlitzMode");
fputs(line, file); line->AddParam("sleep", new CLevelParserParam(sleep));
line->AddParam("delay", new CLevelParserParam(delay));
line->AddParam("magnetic", new CLevelParserParam(magnetic/g_unit));
line->AddParam("progress", new CLevelParserParam(progress));
level->AddLine(line);
} }
CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); CInstanceManager* iMan = CInstanceManager::GetInstancePointer();
@ -5822,23 +5754,35 @@ bool CRobotMain::IOWriteScene(const char *filename, const char *filecbot, char *
CObject* power = obj->GetPower(); CObject* power = obj->GetPower();
CObject* fret = obj->GetFret(); CObject* fret = obj->GetFret();
if (fret != nullptr) // object transported? if (fret != nullptr){ // object transported?
IOWriteObject(file, fret, "CreateFret"); line = new CLevelParserLine("CreateFret");
IOWriteObject(line, fret);
level->AddLine(line);
}
if (power != nullptr) // battery transported? if (power != nullptr) { // battery transported?
IOWriteObject(file, power, "CreatePower"); line = new CLevelParserLine("CreatePower");
IOWriteObject(line, power);
IOWriteObject(file, obj, "CreateObject"); level->AddLine(line);
}
line = new CLevelParserLine("CreateObject");
IOWriteObject(line, obj);
level->AddLine(line);
SaveFileScript(obj, filename, objRank++); SaveFileScript(obj, filename, objRank++);
} }
fclose(file); try {
level->Save();
} catch(CLevelParserException& e) {
CLogger::GetInstancePointer()->Error("Failed to save level state - %s\n", e.what());
delete level;
return false;
}
delete level;
RestoreNumericLocale();
#if CBOT_STACK
// Writes the file of stacks of execution. // Writes the file of stacks of execution.
file = fOpen(filecbot, "wb"); FILE* file = fOpen(filecbot, "wb");
if (file == NULL) return false; if (file == NULL) return false;
long version = 1; long version = 1;
@ -5862,35 +5806,30 @@ bool CRobotMain::IOWriteScene(const char *filename, const char *filecbot, char *
} }
CBotClass::SaveStaticState(file); CBotClass::SaveStaticState(file);
fClose(file); fClose(file);
#endif
m_delayWriteMessage = 4; // displays message in 3 frames m_delayWriteMessage = 4; // displays message in 3 frames
return true; return true;
} }
//! Resumes the game //! Resumes the game
CObject* CRobotMain::IOReadObject(char *line, const char* filename, int objRank) CObject* CRobotMain::IOReadObject(CLevelParserLine *line, const char* filename, int objRank)
{ {
Math::Vector pos = OpDir(line, "pos")*g_unit; Math::Vector pos = line->GetParam("pos")->AsPoint()*g_unit;
Math::Vector dir = OpDir(line, "angle")*(Math::PI/180.0f); Math::Vector dir = line->GetParam("angle")->AsPoint()*(Math::PI/180.0f);
Math::Vector zoom = OpDir(line, "zoom"); Math::Vector zoom = line->GetParam("zoom")->AsPoint();
ObjectType type = OpTypeObject(line, "type", OBJECT_NULL); ObjectType type = line->GetParam("type")->AsObjectType();
int id = OpInt(line, "id", 0); int id = line->GetParam("id")->AsInt();
if (type == OBJECT_NULL)
return nullptr;
SetNumericLocale(); bool trainer = line->GetParam("trainer")->AsBool(false);
bool toy = line->GetParam("toy")->AsBool(false);
int trainer = OpInt(line, "trainer", 0); int option = line->GetParam("option")->AsInt(0);
int toy = OpInt(line, "toy", 0);
int option = OpInt(line, "option", 0);
CObject* obj = CObjectManager::GetInstancePointer()->CreateObject(pos, dir.y, type, 0.0f, 1.0f, 0.0f, trainer, toy, option); CObject* obj = CObjectManager::GetInstancePointer()->CreateObject(pos, dir.y, type, 0.0f, 1.0f, 0.0f, trainer, toy, option);
obj->SetDefRank(objRank); obj->SetDefRank(objRank);
obj->SetPosition(0, pos); obj->SetPosition(0, pos);
obj->SetAngle(0, dir); obj->SetAngle(0, dir);
obj->SetIgnoreBuildCheck(OpInt(line, "ignoreBuildCheck", 0)); obj->SetIgnoreBuildCheck(line->GetParam("ignoreBuildCheck")->AsBool(false));
obj->SetID(id); obj->SetID(id);
if (g_id < id) g_id = id; if (g_id < id) g_id = id;
@ -5901,23 +5840,19 @@ CObject* CRobotMain::IOReadObject(char *line, const char* filename, int objRank)
{ {
if (obj->GetObjectRank(i) == -1) continue; if (obj->GetObjectRank(i) == -1) continue;
char op[10]; pos = line->GetParam(std::string("p")+boost::lexical_cast<std::string>(i))->AsPoint(Math::Vector());
sprintf(op, "p%d", i);
pos = OpDir(line, op);
if (pos.x != 0.0f || pos.y != 0.0f || pos.z != 0.0f) if (pos.x != 0.0f || pos.y != 0.0f || pos.z != 0.0f)
{ {
obj->SetPosition(i, pos*g_unit); obj->SetPosition(i, pos*g_unit);
} }
sprintf(op, "a%d", i); dir = line->GetParam(std::string("a")+boost::lexical_cast<std::string>(i))->AsPoint(Math::Vector());
dir = OpDir(line, op);
if (dir.x != 0.0f || dir.y != 0.0f || dir.z != 0.0f) if (dir.x != 0.0f || dir.y != 0.0f || dir.z != 0.0f)
{ {
obj->SetAngle(i, dir*(Math::PI/180.0f)); obj->SetAngle(i, dir*(Math::PI/180.0f));
} }
sprintf(op, "z%d", i); zoom = line->GetParam(std::string("z")+boost::lexical_cast<std::string>(i))->AsPoint(Math::Vector());
zoom = OpDir(line, op);
if (zoom.x != 0.0f || zoom.y != 0.0f || zoom.z != 0.0f) if (zoom.x != 0.0f || zoom.y != 0.0f || zoom.z != 0.0f)
{ {
obj->SetZoom(i, zoom); obj->SetZoom(i, zoom);
@ -5928,84 +5863,62 @@ CObject* CRobotMain::IOReadObject(char *line, const char* filename, int objRank)
obj->Read(line); obj->Read(line);
#if CBOT_STACK int run = line->GetParam("run")->AsInt(-1);
#else
LoadFileScript(obj, filename, objRank, i);
#endif
int run = OpInt(line, "run", -1);
if (run != -1) if (run != -1)
{ {
#if CBOT_STACK
#else
CBrain* brain = obj->GetBrain();
if (brain != nullptr)
brain->RunProgram(run-1); // starts the program
#endif
CAuto* automat = obj->GetAuto(); CAuto* automat = obj->GetAuto();
if (automat != nullptr) if (automat != nullptr)
automat->Start(run); // starts the film automat->Start(run); // starts the film
} }
RestoreNumericLocale();
return obj; return obj;
} }
//! Resumes some part of the game //! Resumes some part of the game
CObject* CRobotMain::IOReadScene(const char *filename, const char *filecbot) CObject* CRobotMain::IOReadScene(const char *filename, const char *filecbot)
{ {
std::string fnstr = filename;
std::string savedir = CResourceManager::GetSaveLocation()+"/";
boost::replace_all(fnstr, "\\", "/");
boost::replace_all(savedir, "\\", "/");
boost::replace_all(fnstr, savedir, ""); //TODO: Refactor to get physfs path here
CLevelParser* level = new CLevelParser(fnstr);
level->Load();
m_base = nullptr; m_base = nullptr;
FILE* file = fopen(filename, "r");
if (file == NULL) return 0;
SetNumericLocale();
CObject* fret = nullptr; CObject* fret = nullptr;
CObject* power = nullptr; CObject* power = nullptr;
CObject* sel = nullptr; CObject* sel = nullptr;
int objRank = 0; int objRank = 0;
char line[3000]; for(auto& line : level->GetLines())
while (fgets(line, 3000, file) != NULL)
{ {
for (int i = 0; i < 3000; i++) if (line->GetCommand() == "Map")
m_map->ZoomMap(line->GetParam("zoom")->AsFloat());
if (line->GetCommand() == "DoneResearch")
g_researchDone = line->GetParam("bits")->AsInt();
if (line->GetCommand() == "BlitzMode")
{ {
if (line[i] == '\t') line[i] = ' '; // replace tab by space float sleep = line->GetParam("sleep")->AsFloat();
if (line[i] == '/' && line[i+1] == '/') float delay = line->GetParam("delay")->AsFloat();
{ float magnetic = line->GetParam("magnetic")->AsFloat()*g_unit;
line[i] = 0; float progress = line->GetParam("progress")->AsFloat();
break;
}
}
if (Cmd(line, "Map"))
m_map->ZoomMap(OpFloat(line, "zoom", 1.0f));
if (Cmd(line, "DoneResearch"))
g_researchDone = OpInt(line, "bits", 0);
if (Cmd(line, "BlitzMode"))
{
float sleep = OpFloat(line, "sleep", 0.0f);
float delay = OpFloat(line, "delay", 3.0f);
float magnetic = OpFloat(line, "magnetic", 50.0f)*g_unit;
float progress = OpFloat(line, "progress", 0.0f);
m_lightning->SetStatus(sleep, delay, magnetic, progress); m_lightning->SetStatus(sleep, delay, magnetic, progress);
} }
if (Cmd(line, "CreateFret")) if (line->GetCommand() == "CreateFret")
fret = IOReadObject(line, filename, -1); fret = IOReadObject(line, filename, -1);
if (Cmd(line, "CreatePower")) if (line->GetCommand() == "CreatePower")
power = IOReadObject(line, filename, -1); power = IOReadObject(line, filename, -1);
if (Cmd(line, "CreateObject")) if (line->GetCommand() == "CreateObject")
{ {
CObject* obj = IOReadObject(line, filename, objRank++); CObject* obj = IOReadObject(line, filename, objRank++);
if (OpInt(line, "select", 0)) if (line->GetParam("select")->AsBool(false))
sel = obj; sel = obj;
if (fret != nullptr) if (fret != nullptr)
@ -6026,9 +5939,8 @@ CObject* CRobotMain::IOReadScene(const char *filename, const char *filecbot)
power = nullptr; power = nullptr;
} }
} }
fclose(file); delete level;
#if CBOT_STACK
CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); CInstanceManager* iMan = CInstanceManager::GetInstancePointer();
// Compiles scripts. // Compiles scripts.
@ -6053,7 +5965,7 @@ CObject* CRobotMain::IOReadScene(const char *filename, const char *filecbot)
while (nbError > 0 && nbError != lastError); while (nbError > 0 && nbError != lastError);
// Reads the file of stacks of execution. // Reads the file of stacks of execution.
file = fOpen(filecbot, "rb"); FILE* file = fOpen(filecbot, "rb");
if (file != NULL) if (file != NULL)
{ {
long version; long version;
@ -6082,9 +5994,6 @@ CObject* CRobotMain::IOReadScene(const char *filename, const char *filecbot)
CBotClass::RestoreStaticState(file); CBotClass::RestoreStaticState(file);
fClose(file); fClose(file);
} }
#endif
RestoreNumericLocale();
return sel; return sel;
} }
@ -6098,15 +6007,17 @@ void CRobotMain::WriteFreeParam()
if (m_gamerName == "") return; if (m_gamerName == "") return;
char filename[MAX_FNAME]; COutputStream file;
sprintf(filename, "%s/%s/research.gam", GetSavegameDir(), m_gamerName.c_str()); file.open(std::string(GetSavegameDir())+"/"+m_gamerName+"/research.gam");
FILE* file = fopen(filename, "w"); if(!file.is_open())
if (file == NULL) return; {
CLogger::GetInstancePointer()->Error("Unable to write free game unlock state\n");
char line[100]; return;
sprintf(line, "research=%d build=%d\n", m_freeResearch, m_freeBuild); }
fputs(line, file);
fclose(file); file << "research=" << m_freeResearch << " build=" << m_freeBuild << "\n";
file.close();
} }
//! Reads the global parameters for free play //! Reads the global parameters for free play
@ -6117,16 +6028,23 @@ void CRobotMain::ReadFreeParam()
if (m_gamerName == "") return; if (m_gamerName == "") return;
char filename[MAX_FNAME]; if(!CResourceManager::Exists(std::string(GetSavegameDir())+"/"+m_gamerName+"/research.gam"))
sprintf(filename, "%s/%s/research.gam", GetSavegameDir(), m_gamerName.c_str()); return;
FILE* file = fopen(filename, "r");
if (file == NULL) return; CInputStream file;
file.open(std::string(GetSavegameDir())+"/"+m_gamerName+"/research.gam");
if(!file.is_open())
{
CLogger::GetInstancePointer()->Error("Unable to read free game unlock state\n");
return;
}
char line[100]; std::string line;
if (fgets(line, 100, file) != NULL) std::getline(file, line);
sscanf(line, "research=%d build=%d\n", &m_freeResearch, &m_freeBuild);
sscanf(line.c_str(), "research=%d build=%d\n", &m_freeResearch, &m_freeBuild);
fclose(file); file.close();
} }
@ -6694,12 +6612,6 @@ bool CRobotMain::GetRadar()
return false; return false;
} }
//TODO: Use PHYSFS everywhere
const char* CRobotMain::GetPHYSFSSavegameDir()
{
return m_dialog->GetPHYSFSSavegameDir().c_str();
}
const char* CRobotMain::GetSavegameDir() const char* CRobotMain::GetSavegameDir()
{ {
return m_dialog->GetSavegameDir().c_str(); return m_dialog->GetSavegameDir().c_str();
@ -6986,20 +6898,6 @@ void CRobotMain::ClearInterface()
m_tooltipName.clear(); // really removes the tooltip m_tooltipName.clear(); // really removes the tooltip
} }
void CRobotMain::SetNumericLocale()
{
char *locale = setlocale(LC_NUMERIC, nullptr);
if (locale != nullptr)
m_oldLocale = locale;
setlocale(LC_NUMERIC, "C");
}
void CRobotMain::RestoreNumericLocale()
{
setlocale(LC_NUMERIC, m_oldLocale.c_str());
}
void CRobotMain::DisplayError(Error err, CObject* pObj, float time) void CRobotMain::DisplayError(Error err, CObject* pObj, float time)
{ {
m_displayText->DisplayError(err, pObj, time); m_displayText->DisplayError(err, pObj, time);

View File

@ -76,6 +76,7 @@ enum Phase
class CEventQueue; class CEventQueue;
class CSoundInterface; class CSoundInterface;
class CLevelParserLine;
namespace Gfx { namespace Gfx {
class CEngine; class CEngine;
@ -331,7 +332,6 @@ public:
bool GetSceneSoluce(); bool GetSceneSoluce();
bool GetShowAll(); bool GetShowAll();
bool GetRadar(); bool GetRadar();
const char* GetPHYSFSSavegameDir();
const char* GetSavegameDir(); const char* GetSavegameDir();
const char* GetPublicDir(); const char* GetPublicDir();
const char* GetFilesDir(); const char* GetFilesDir();
@ -383,14 +383,11 @@ public:
bool IsBusy(); bool IsBusy();
bool IOWriteScene(const char *filename, const char *filecbot, char *info); bool IOWriteScene(const char *filename, const char *filecbot, char *info);
CObject* IOReadScene(const char *filename, const char *filecbot); CObject* IOReadScene(const char *filename, const char *filecbot);
void IOWriteObject(FILE *file, CObject* pObj, const char *cmd); void IOWriteObject(CLevelParserLine *line, CObject* obj);
CObject* IOReadObject(char *line, const char* filename, int objRank); CObject* IOReadObject(CLevelParserLine *line, const char* filename, int objRank);
int CreateSpot(Math::Vector pos, Gfx::Color color); int CreateSpot(Math::Vector pos, Gfx::Color color);
void SetNumericLocale();
void RestoreNumericLocale();
CObject* GetSelect(); CObject* GetSelect();
void DisplayError(Error err, CObject* pObj, float time=10.0f); void DisplayError(Error err, CObject* pObj, float time=10.0f);
@ -588,8 +585,6 @@ protected:
Gfx::Color m_colorRefWater; Gfx::Color m_colorRefWater;
Gfx::Color m_colorNewWater; Gfx::Color m_colorNewWater;
float m_colorShiftWater; float m_colorShiftWater;
std::string m_oldLocale;
bool m_missionTimerEnabled; bool m_missionTimerEnabled;
bool m_missionTimerStarted; bool m_missionTimerStarted;

View File

@ -40,6 +40,8 @@
#include "object/motion/motion.h" #include "object/motion/motion.h"
#include "object/motion/motionhuman.h" #include "object/motion/motionhuman.h"
#include "object/task/task.h" #include "object/task/task.h"
#include "object/level/parserline.h"
#include "object/level/parserparam.h"
#include "script/cmdtoken.h" #include "script/cmdtoken.h"
@ -171,20 +173,14 @@ PhysicsType CPhysics::GetType()
// Saves all parameters of the object. // Saves all parameters of the object.
bool CPhysics::Write(char *line) bool CPhysics::Write(CLevelParserLine* line)
{ {
char name[100]; line->AddParam("motor", new CLevelParserParam(m_motorSpeed));
sprintf(name, " motor=%.2f;%.2f;%.2f", m_motorSpeed.x, m_motorSpeed.y, m_motorSpeed.z);
strcat(line, name);
if ( m_type == TYPE_FLYING ) if ( m_type == TYPE_FLYING )
{ {
sprintf(name, " reactorRange=%.2f", GetReactorRange()); line->AddParam("reactorRange", new CLevelParserParam(GetReactorRange()));
strcat(line, name); line->AddParam("land", new CLevelParserParam(GetLand()));
sprintf(name, " land=%d", GetLand());
strcat(line, name);
} }
return true; return true;
@ -192,14 +188,14 @@ bool CPhysics::Write(char *line)
// Restores all parameters of the object. // Restores all parameters of the object.
bool CPhysics::Read(char *line) bool CPhysics::Read(CLevelParserLine* line)
{ {
m_motorSpeed = OpDir(line, "motor"); m_motorSpeed = line->GetParam("motor")->AsPoint();
if ( m_type == TYPE_FLYING ) if ( m_type == TYPE_FLYING )
{ {
SetReactorRange(OpFloat(line, "reactorRange", 0.0f)); SetReactorRange(line->GetParam("reactorRange")->AsFloat());
SetLand(OpInt(line, "land", 0)); SetLand(line->GetParam("land")->AsBool());
} }
return true; return true;

View File

@ -36,6 +36,7 @@ class CObject;
class CBrain; class CBrain;
class CMotion; class CMotion;
class CSoundInterface; class CSoundInterface;
class CLevelParserLine;
namespace Gfx { namespace Gfx {
class CCamera; class CCamera;
@ -110,8 +111,8 @@ public:
void SetType(PhysicsType type); void SetType(PhysicsType type);
PhysicsType GetType(); PhysicsType GetType();
bool Write(char *line); bool Write(CLevelParserLine* line);
bool Read(char *line); bool Read(CLevelParserLine* line);
void SetGravity(float value); void SetGravity(float value);
float GetGravity(); float GetGravity();

View File

@ -63,8 +63,6 @@
#include <sstream> #include <sstream>
#include <iomanip> #include <iomanip>
#include <vector> #include <vector>
#include <boost/filesystem.hpp>
#include <boost/foreach.hpp>
//TODO Get rid of all sprintf's //TODO Get rid of all sprintf's
@ -115,8 +113,6 @@ static int perso_color[3*10*3] =
0, 0, 0, // 0, 0, 0, //
}; };
namespace fs = boost::filesystem;
// Constructor of robot application. // Constructor of robot application.
CMainDialog::CMainDialog() CMainDialog::CMainDialog()
@ -183,9 +179,8 @@ CMainDialog::CMainDialog()
} }
m_savegameDir = "savegame"; m_savegameDir = "savegame";
m_publicDir = CResourceManager::GetSaveLocation()+"/program"; //TODO: Refactor to use PHYSFS m_publicDir = "program";
m_filesDir = CResourceManager::GetSaveLocation()+"/files"; //TODO: Refactor to use PHYSFS m_filesDir = "files";
CLogger::GetInstancePointer()->Trace("Savegame path: normal=%s, physfs=%s\n", GetSavegameDir().c_str(), GetPHYSFSSavegameDir().c_str());
m_setupFull = m_app->GetVideoConfig().fullScreen; m_setupFull = m_app->GetVideoConfig().fullScreen;
@ -3336,50 +3331,16 @@ std::string & CMainDialog::GetFilesDir()
void CMainDialog::ReadNameList() void CMainDialog::ReadNameList()
{ {
CWindow* pw; CWindow* pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
CList* pl; if (pw == nullptr) return;
//struct _finddata_t fBuffer; CList* pl = static_cast<CList*>(pw->SearchControl(EVENT_INTERFACE_NLIST));
char dir[MAX_FNAME]; if (pl == nullptr) return;
// char filenames[MAX_FNAME][100];
std::vector<std::string> fileNames;
pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
if ( pw == 0 ) return;
pl = static_cast<CList*>(pw->SearchControl(EVENT_INTERFACE_NLIST));
if ( pl == 0 ) return;
pl->Flush(); pl->Flush();
auto userSaveDirs = CResourceManager::ListDirectories(m_savegameDir);
try for (int i = 0; i < static_cast<int>(userSaveDirs.size()); ++i)
{ {
if (! fs::exists(GetSavegameDir()) && fs::is_directory(GetSavegameDir())) pl->SetItemName(i, userSaveDirs.at(i).c_str());
{
GetLogger()->Error("Savegame dir does not exist %s\n",dir);
}
else
{
fs::directory_iterator dirIt(GetSavegameDir()), dirEndIt;
for (; dirIt != dirEndIt; ++dirIt)
{
const fs::path& p = *dirIt;
if (fs::is_directory(p))
{
fileNames.push_back(p.leaf().string());
}
}
}
}
catch (std::exception & e)
{
GetLogger()->Error("Error on listing savegame directory : %s\n", e.what());
return;
}
for (size_t i=0 ; i<fileNames.size() ; ++i )
{
pl->SetItemName(i, fileNames.at(i).c_str());
} }
} }
@ -3562,7 +3523,6 @@ void CMainDialog::NameCreate()
CWindow* pw; CWindow* pw;
CEdit* pe; CEdit* pe;
char name[100]; char name[100];
std::string dir;
char c; char c;
int len, i, j; int len, i, j;
@ -3603,16 +3563,10 @@ void CMainDialog::NameCreate()
return; return;
} }
std::string userSaveDir = m_savegameDir + "/" + name;
if(!CResourceManager::DirectoryExists(GetPHYSFSSavegameDir())) if (!CResourceManager::DirectoryExists(userSaveDir))
CResourceManager::CreateDirectory(GetPHYSFSSavegameDir());
dir = GetSavegameDir() + "/" + name;
if (!fs::exists(dir))
{ {
fs::create_directories(dir); CResourceManager::CreateDirectory(userSaveDir);
if(!CResourceManager::DirectoryExists(GetPHYSFSSavegameDir()+"/"+name))
CResourceManager::CreateDirectory(GetPHYSFSSavegameDir()+"/"+name);
} }
else else
{ {
@ -3629,58 +3583,26 @@ void CMainDialog::NameCreate()
m_main->ChangePhase(PHASE_INIT); m_main->ChangePhase(PHASE_INIT);
} }
// Deletes a folder and all its offspring.
bool RemoveDir(char *dirName)
{
try
{
if (!fs::exists(dirName) && fs::is_directory(dirName))
{
GetLogger()->Error("Directory does not exist %s\n",dirName);
return false;
}
else
{
fs::remove_all(dirName);
}
}
catch (std::exception & e)
{
GetLogger()->Error("Error on removing directory %s : %s\n", dirName, e.what());
return false;
}
return true;
}
// Removes a player. // Removes a player.
void CMainDialog::NameDelete() void CMainDialog::NameDelete()
{ {
CWindow* pw; CWindow* pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
CList* pl; if (pw == nullptr) return;
int sel; CList* pl = static_cast<CList*>(pw->SearchControl(EVENT_INTERFACE_NLIST));
char* gamer; if (pl == nullptr) return;
char dir[100];
pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5)); int sel = pl->GetSelect();
if ( pw == 0 ) return; if (sel == -1)
pl = static_cast<CList*>(pw->SearchControl(EVENT_INTERFACE_NLIST));
if ( pl == 0 ) return;
sel = pl->GetSelect();
if ( sel == -1 )
{ {
m_sound->Play(SOUND_TZOING); m_sound->Play(SOUND_TZOING);
return; return;
} }
gamer = pl->GetItemName(sel);
// Deletes all the contents of the file. char* gamer = pl->GetItemName(sel);
sprintf(dir, "%s/%s", GetSavegameDir().c_str(), gamer);
if ( !RemoveDir(dir) ) std::string userSaveDir = m_savegameDir + "/" + gamer;
if (!CResourceManager::RemoveDirectory(userSaveDir))
{ {
m_sound->Play(SOUND_TZOING); m_sound->Play(SOUND_TZOING);
return; return;
@ -3990,17 +3912,13 @@ void CMainDialog::DefPerso()
bool CMainDialog::IsIOReadScene() bool CMainDialog::IsIOReadScene()
{ {
fs::directory_iterator end_iter; std::string userSaveDir = m_savegameDir + "/" + m_main->GetGamerName();
auto saveDirs = CResourceManager::ListDirectories(userSaveDir);
fs::path saveDir(GetSavegameDir() + "/" + m_main->GetGamerName()); for (auto dir : saveDirs)
if (fs::exists(saveDir) && fs::is_directory(saveDir))
{ {
for( fs::directory_iterator dir_iter(saveDir) ; dir_iter != end_iter ; ++dir_iter) if (CResourceManager::Exists(userSaveDir + "/" + dir + "/" + "data.sav"))
{ {
if ( fs::is_directory(dir_iter->status()) && fs::exists(dir_iter->path() / "data.sav") ) return true;
{
return true;
}
} }
} }
@ -4074,59 +3992,30 @@ void CMainDialog::IOReadName()
void CMainDialog::IOReadList() void CMainDialog::IOReadList()
{ {
FILE* file = NULL; CWindow* pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
CWindow* pw; if (pw == nullptr) return;
CList* pl; CList* pl = static_cast<CList*>(pw->SearchControl(EVENT_INTERFACE_IOLIST));
char line[500]; if (pl == nullptr) return;
char name[100];
int i;
std::vector<fs::path> v;
pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
if ( pw == 0 ) return;
pl = static_cast<CList*>(pw->SearchControl(EVENT_INTERFACE_IOLIST));
if ( pl == 0 ) return;
pl->Flush(); pl->Flush();
fs::path saveDir(GetSavegameDir() + "/" + m_main->GetGamerName());
m_saveList.clear(); m_saveList.clear();
if (fs::exists(saveDir) && fs::is_directory(saveDir)) std::string userSaveDir = m_savegameDir + "/" + m_main->GetGamerName();
auto saveDirs = CResourceManager::ListDirectories(userSaveDir);
std::sort(saveDirs.begin(), saveDirs.end());
for (auto dir : saveDirs)
{ {
copy(fs::directory_iterator(saveDir), fs::directory_iterator(), back_inserter(v)); std::string savegameFile = userSaveDir + "/" + dir + "/" + "data.sav";
std::sort(v.begin(), v.end()); if (CResourceManager::Exists(savegameFile))
for( std::vector<fs::path>::iterator iter = v.begin(); iter != v.end(); ++iter)
{ {
if ( fs::is_directory(*iter) && fs::exists(*iter / "data.sav") ) CLevelParser* level = new CLevelParser(savegameFile);
{ level->Load();
pl->SetItemName(m_saveList.size(), level->Get("Title")->GetParam("text")->AsString().c_str());
file = fopen((*iter / "data.sav").make_preferred().string().c_str(), "r"); m_saveList.push_back(userSaveDir + "/" + dir);
if ( file == NULL ) continue; delete level;
while ( fgets(line, 500, file) != NULL )
{
for ( i=0 ; i<500 ; i++ )
{
if ( line[i] == '\t' ) line[i] = ' '; // replaces tab by space
if ( line[i] == '/' && line[i+1] == '/' )
{
line[i] = 0;
break;
}
}
if ( Cmd(line, "Title") )
{
OpString(line, "text", name);
break;
}
}
fclose(file);
pl->SetItemName(m_saveList.size(), name);
m_saveList.push_back(*iter);
}
} }
} }
@ -4165,12 +4054,7 @@ void CMainDialog::IOUpdateList()
if (m_saveList.size() <= static_cast<unsigned int>(sel)) if (m_saveList.size() <= static_cast<unsigned int>(sel))
return; return;
std::string filename = (m_saveList.at(sel) / "screen.png").make_preferred().string(); std::string filename = "../"+m_saveList.at(sel) + "/screen.png";
std::string savedir = CResourceManager::GetSaveLocation()+"/";
boost::replace_all(filename, "\\", "/");
boost::replace_all(savedir, "\\", "/");
boost::replace_all(filename, savedir, ""); //TODO: Refactor everything to PHYSFS, see issue #334
filename = "../"+filename;
if ( m_phase == PHASE_WRITE || m_phase == PHASE_WRITEs ) if ( m_phase == PHASE_WRITE || m_phase == PHASE_WRITEs )
{ {
if ( sel < max-1 ) if ( sel < max-1 )
@ -4214,16 +4098,9 @@ void CMainDialog::IODeleteScene()
return; return;
} }
try if (CResourceManager::DirectoryExists(m_saveList.at(sel)))
{ {
if (fs::exists(m_saveList.at(sel)) && fs::is_directory(m_saveList.at(sel))) CResourceManager::RemoveDirectory(m_saveList.at(sel));
{
fs::remove_all(m_saveList.at(sel));
}
}
catch (std::exception & e)
{
GetLogger()->Error("Error removing save %s : %s\n", pl->GetItemName(sel), e.what());
} }
IOReadList(); IOReadList();
@ -4267,28 +4144,28 @@ bool CMainDialog::IOWriteScene()
return false; return false;
} }
fs::path dir; std::string dir;
pe->GetText(info, 100); pe->GetText(info, 100);
if (static_cast<unsigned int>(sel) >= m_saveList.size()) if (static_cast<unsigned int>(sel) >= m_saveList.size())
{ {
dir = fs::path(GetSavegameDir()) / m_main->GetGamerName() / ("save" + clearName(info)); dir = m_savegameDir + "/" + m_main->GetGamerName() + "/save" + clearName(info);
} }
else else
{ {
dir = m_saveList.at(sel); dir = m_saveList.at(sel);
} }
if (!fs::exists(dir)) if (!CResourceManager::DirectoryExists(dir))
{ {
fs::create_directories(dir); CResourceManager::CreateDirectory(dir);
} }
std::string fileName = (dir / "data.sav").make_preferred().string(); std::string savegameFileName = dir + "/data.sav";
std::string fileCBot = (dir / "cbot.run").make_preferred().string(); std::string fileCBot = CResourceManager::GetSaveLocation() + "/" + dir + "/cbot.run";
m_main->IOWriteScene(fileName.c_str(), fileCBot.c_str(), info); m_main->IOWriteScene(savegameFileName.c_str(), fileCBot.c_str(), info);
m_shotDelay = 3; m_shotDelay = 3;
m_shotName = (dir / "screen.png").make_preferred().string(); m_shotName = CResourceManager::GetSaveLocation() + "/" + dir + "/screen.png"; //TODO: Use PHYSFS?
return true; return true;
} }
@ -4297,11 +4174,8 @@ bool CMainDialog::IOWriteScene()
bool CMainDialog::IOReadScene() bool CMainDialog::IOReadScene()
{ {
FILE* file;
CWindow* pw; CWindow* pw;
CList* pl; CList* pl;
char line[500];
char dir[100];
int sel, i; int sel, i;
pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5)); pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
@ -4315,53 +4189,37 @@ bool CMainDialog::IOReadScene()
return false; return false;
} }
std::string fileName = (m_saveList.at(sel) / "data.sav").make_preferred().string(); std::string fileName = m_saveList.at(sel) + "/" + "data.sav";
std::string fileCbot = (m_saveList.at(sel) / "cbot.run").make_preferred().string(); std::string fileCbot = CResourceManager::GetSaveLocation()+"/"+m_saveList.at(sel) + "/" + "cbot.run";
file = fopen(fileName.c_str(), "r"); CLevelParser* level = new CLevelParser(fileName);
if ( file == NULL ) level->Load();
CLevelParserLine* line = level->Get("Mission");
strcpy(m_sceneName, line->GetParam("base")->AsString().c_str());
m_sceneRank = line->GetParam("rank")->AsInt();
if(std::string(m_sceneName) == "custom")
{ {
return false; m_sceneRank = m_sceneRank%100;
}
std::string dir = line->GetParam("dir")->AsString();
while ( fgets(line, 500, file) != NULL ) for ( i=0 ; i<m_userTotal ; i++ )
{
for ( i=0 ; i<500 ; i++ )
{ {
if ( line[i] == '\t' ) line[i] = ' '; // replaces tab by space if ( m_userList[i] == dir )
if ( line[i] == '/' && line[i+1] == '/' )
{ {
line[i] = 0; m_sceneRank += (i+1)*100;
break; break;
} }
} }
if ( m_sceneRank/100 == 0 )
if ( Cmd(line, "Mission") )
{ {
OpString(line, "base", m_sceneName); delete level;
m_sceneRank = OpInt(line, "rank", 0); return false;
if ( strcmp(m_sceneName, "user") == 0 )
{
m_sceneRank = m_sceneRank%100;
OpString(line, "dir", dir);
for ( i=0 ; i<m_userTotal ; i++ )
{
if ( strcmp(m_userList[i].c_str(), dir) == 0 )
{
m_sceneRank += (i+1)*100;
break;
}
}
if ( m_sceneRank/100 == 0 )
{
fclose(file);
return false;
}
}
} }
} }
fclose(file);
delete level;
m_chap[m_index] = (m_sceneRank / 100)-1; m_chap[m_index] = (m_sceneRank / 100)-1;
m_sel[m_index] = (m_sceneRank % 100)-1; m_sel[m_index] = (m_sceneRank % 100)-1;
@ -6002,13 +5860,7 @@ bool CMainDialog::GetSceneSoluce()
// Returns the name of the folder to save. // Returns the name of the folder to save.
std::string CMainDialog::GetSavegameDir() std::string & CMainDialog::GetSavegameDir()
{
return CResourceManager::GetSaveLocation()+"/"+m_savegameDir;
}
//TODO: Use PHYSFS everywhere
std::string & CMainDialog::GetPHYSFSSavegameDir()
{ {
return m_savegameDir; return m_savegameDir;
} }
@ -6062,82 +5914,56 @@ bool CMainDialog::GetHimselfDamage()
void CMainDialog::WriteGamerPerso(char *gamer) void CMainDialog::WriteGamerPerso(char *gamer)
{ {
FILE* file; try {
char filename[100]; CLevelParser* perso = new CLevelParser(GetSavegameDir()+"/"+gamer+"/face.gam");
char line[100]; CLevelParserLine* line;
line = new CLevelParserLine("Head");
line->AddParam("face", new CLevelParserParam(m_perso.face));
line->AddParam("glasses", new CLevelParserParam(m_perso.glasses));
line->AddParam("hair", new CLevelParserParam(m_perso.colorHair));
perso->AddLine(line);
line = new CLevelParserLine("Body");
line->AddParam("combi", new CLevelParserParam(m_perso.colorCombi));
line->AddParam("band", new CLevelParserParam(m_perso.colorBand));
perso->AddLine(line);
sprintf(filename, "%s/%s/face.gam", GetSavegameDir().c_str(), gamer); perso->Save();
file = fopen(filename, "w"); delete perso;
if ( file == NULL ) return; } catch(CLevelParserException& e) {
CLogger::GetInstancePointer()->Error("Unable to write personalized player apperance: %s\n", e.what());
m_main->SetNumericLocale(); }
sprintf(line, "Head face=%d glasses=%d hair=%.2f;%.2f;%.2f;%.2f\n",
m_perso.face, m_perso.glasses,
m_perso.colorHair.r, m_perso.colorHair.g, m_perso.colorHair.b, m_perso.colorHair.a);
fputs(line, file);
sprintf(line, "Body combi=%.2f;%.2f;%.2f;%.2f band=%.2f;%.2f;%.2f;%.2f\n",
m_perso.colorCombi.r, m_perso.colorCombi.g, m_perso.colorCombi.b, m_perso.colorCombi.a,
m_perso.colorBand.r, m_perso.colorBand.g, m_perso.colorBand.b, m_perso.colorBand.a);
fputs(line, file);
fclose(file);
m_main->RestoreNumericLocale();
} }
// Reads the personalized player. // Reads the personalized player.
void CMainDialog::ReadGamerPerso(char *gamer) void CMainDialog::ReadGamerPerso(char *gamer)
{ {
FILE* file;
char filename[100];
char line[100];
Gfx::Color color;
m_perso.face = 0; m_perso.face = 0;
DefPerso(); DefPerso();
if(!CResourceManager::Exists(GetSavegameDir()+"/"+gamer+"/face.gam"))
return;
sprintf(filename, "%s/%s/face.gam", GetSavegameDir().c_str(), gamer); try {
file = fopen(filename, "r"); CLevelParser* perso = new CLevelParser(GetSavegameDir()+"/"+gamer+"/face.gam");
if ( file == NULL ) return; perso->Load();
CLevelParserLine* line;
line = perso->Get("Head");
m_perso.face = line->GetParam("face")->AsInt();
m_perso.glasses = line->GetParam("glasses")->AsInt();
m_perso.colorHair = line->GetParam("hair")->AsColor();
line = perso->Get("Body");
m_perso.colorCombi = line->GetParam("combi")->AsColor();
m_perso.colorBand = line->GetParam("band")->AsColor();
m_main->SetNumericLocale(); delete perso;
} catch(CLevelParserException& e) {
while ( fgets(line, 100, file) != NULL ) CLogger::GetInstancePointer()->Error("Unable to read personalized player apperance: %s\n", e.what());
{
if ( Cmd(line, "Head") )
{
m_perso.face = OpInt(line, "face", 0);
m_perso.glasses = OpInt(line, "glasses", 0);
color.r = 0.0f;
color.g = 0.0f;
color.b = 0.0f;
color.a = 0.0f;
m_perso.colorHair = OpColor(line, "hair", color);
}
if ( Cmd(line, "Body") )
{
color.r = 0.0f;
color.g = 0.0f;
color.b = 0.0f;
color.a = 0.0f;
m_perso.colorCombi = OpColor(line, "combi", color);
color.r = 0.0f;
color.g = 0.0f;
color.b = 0.0f;
color.a = 0.0f;
m_perso.colorBand = OpColor(line, "band", color);
}
} }
fclose(file);
m_main->RestoreNumericLocale();
} }
// Specifies the face of the player. // Specifies the face of the player.
@ -6198,9 +6024,8 @@ Gfx::Color CMainDialog::GetGamerColorBand()
bool CMainDialog::ReadGamerInfo() bool CMainDialog::ReadGamerInfo()
{ {
FILE* file; std::string line;
char line[100]; int chap, i, numTry, passed;
int chap, i, numTry, passed;
for ( i=0 ; i<MAXSCENE ; i++ ) for ( i=0 ; i<MAXSCENE ; i++ )
{ {
@ -6208,20 +6033,25 @@ bool CMainDialog::ReadGamerInfo()
m_sceneInfo[i].bPassed = false; m_sceneInfo[i].bPassed = false;
} }
sprintf(line, "%s/%s/%s.gam", GetSavegameDir().c_str(), m_main->GetGamerName(), m_sceneName); if(!CResourceManager::Exists(GetSavegameDir()+"/"+m_main->GetGamerName()+"/"+m_sceneName+".gam"))
file = fopen(line, "r"); return false;
if ( file == NULL ) return false;
CInputStream file;
if ( fgets(line, 100, file) != NULL ) file.open(GetSavegameDir()+"/"+m_main->GetGamerName()+"/"+m_sceneName+".gam");
{ if(!file.is_open()) {
sscanf(line, "CurrentChapter=%d CurrentSel=%d\n", &chap, &i); CLogger::GetInstancePointer()->Error("Unable to read list of finished missions\n");
m_chap[m_index] = chap-1; return false;
m_sel[m_index] = i-1;
} }
std::getline(file, line);
sscanf(line.c_str(), "CurrentChapter=%d CurrentSel=%d\n", &chap, &i);
m_chap[m_index] = chap-1;
m_sel[m_index] = i-1;
while ( fgets(line, 100, file) != NULL ) while(!file.eof())
{ {
sscanf(line, "Chapter %d: Scene %d: numTry=%d passed=%d\n", std::getline(file, line);
sscanf(line.c_str(), "Chapter %d: Scene %d: numTry=%d passed=%d\n",
&chap, &i, &numTry, &passed); &chap, &i, &numTry, &passed);
i += chap*100; i += chap*100;
@ -6232,7 +6062,7 @@ bool CMainDialog::ReadGamerInfo()
} }
} }
fclose(file); file.close();
return true; return true;
} }
@ -6240,28 +6070,25 @@ bool CMainDialog::ReadGamerInfo()
bool CMainDialog::WriteGamerInfo() bool CMainDialog::WriteGamerInfo()
{ {
FILE* file;
char line[100];
int i; int i;
sprintf(line, "%s/%s/%s.gam", GetSavegameDir().c_str(), m_main->GetGamerName(), m_sceneName); COutputStream file;
file = fopen(line, "w"); file.open(GetSavegameDir()+"/"+m_main->GetGamerName()+"/"+m_sceneName+".gam");
if ( file == NULL ) return false; if(!file.is_open()) {
CLogger::GetInstancePointer()->Error("Unable to read list of finished missions\n");
return false;
}
sprintf(line, "CurrentChapter=%d CurrentSel=%d\n", file << "CurrentChapter=" << m_chap[m_index]+1 << " CurrentSel=" << m_sel[m_index]+1 << "\n";
m_chap[m_index]+1, m_sel[m_index]+1);
fputs(line, file);
for ( i=0 ; i<MAXSCENE ; i++ ) for ( i=0 ; i<MAXSCENE ; i++ )
{ {
if ( m_sceneInfo[i].numTry == 0 && !m_sceneInfo[i].bPassed ) continue; if ( m_sceneInfo[i].numTry == 0 && !m_sceneInfo[i].bPassed ) continue;
sprintf(line, "Chapter %d: Scene %d: numTry=%d passed=%d\n", file << "Chapter " << i/100 << ": Scene " << i%100 << ": numTry=" << m_sceneInfo[i].numTry << " passed=1" << m_sceneInfo[i].bPassed << "\n";
i/100, i%100, m_sceneInfo[i].numTry, m_sceneInfo[i].bPassed);
fputs(line, file);
} }
fclose(file); file.close();
return true; return true;
} }

View File

@ -28,13 +28,8 @@
#include "app/pausemanager.h" #include "app/pausemanager.h"
#include <boost/filesystem.hpp>
#include <boost/algorithm/string.hpp>
#include <vector> #include <vector>
namespace fs = boost::filesystem;
class CEventQueue; class CEventQueue;
class CSoundInterface; class CSoundInterface;
@ -91,8 +86,7 @@ public:
int GetSceneRank(); int GetSceneRank();
const char* GetSceneDir(); const char* GetSceneDir();
bool GetSceneSoluce(); bool GetSceneSoluce();
std::string GetSavegameDir(); std::string & GetSavegameDir();
std::string & GetPHYSFSSavegameDir();
std::string & GetPublicDir(); std::string & GetPublicDir();
bool GetTooltip(); bool GetTooltip();
@ -268,7 +262,7 @@ protected:
SceneInfo m_sceneInfo[MAXSCENE]; SceneInfo m_sceneInfo[MAXSCENE];
std::vector<fs::path> m_saveList; std::vector<std::string> m_saveList;
}; };
} // namespace Ui } // namespace Ui

View File

@ -1496,7 +1496,6 @@ void CStudio::UpdateDialogList()
{ {
CWindow* pw; CWindow* pw;
CList* pl; CList* pl;
fs::path path;
int i = 0; int i = 0;
char time[100]; char time[100];
@ -1506,52 +1505,38 @@ void CStudio::UpdateDialogList()
if ( pl == nullptr ) return; if ( pl == nullptr ) return;
pl->Flush(); pl->Flush();
path = fs::path(SearchDirectory(false)); if(!CResourceManager::DirectoryExists(SearchDirectory(false)))
fs::directory_iterator end_iter; return;
if ( fs::exists(path) && fs::is_directory(path) )
{ std::vector<std::string> programs = CResourceManager::ListFiles(SearchDirectory(false));
for( fs::directory_iterator file(path); file != end_iter; file++) for(auto& prog : programs) {
{ std::ostringstream temp;
if (fs::is_regular_file(file->status()) ) TimeToAscii(CResourceManager::GetLastModificationTime(SearchDirectory(false) + prog), time);
{ temp << prog << '\t' << CResourceManager::GetFileSize(SearchDirectory(false) + prog) << " \t" << time;
std::ostringstream temp; pl->SetItemName(i++, temp.str().c_str());
TimeToAscii(fs::last_write_time(file->path()), time);
temp << file->path().filename().string() << '\t' << fs::file_size(file->path()) << " \t" << time;
pl->SetItemName(i++, temp.str().c_str());
}
}
} }
} }
// Constructs the name of the folder or open/save. // Constructs the name of the folder or open/save.
// If the folder does not exist, it will be created. // If the folder does not exist, it will be created.
//TODO: Refactor to PHYSFS std::string CStudio::SearchDirectory(bool bCreate)
std::string CStudio::SearchDirectory(bool bCreate, bool physfsReady)
{ {
char dir[MAX_FNAME]; std::string dir;
if ( m_main->GetIOPublic() ) if ( m_main->GetIOPublic() )
{ {
sprintf(dir, "%s/", m_main->GetPublicDir()); dir = std::string(m_main->GetPublicDir()) + "/";
} }
else else
{ {
sprintf(dir, "%s/%s/Program/", m_main->GetSavegameDir(), m_main->GetGamerName()); dir = std::string(m_main->GetSavegameDir()) + "/" + std::string(m_main->GetGamerName()) + "/program/";
} }
if ( bCreate ) if ( bCreate )
{ {
fs::path path = fs::path(dir); if(!CResourceManager::DirectoryExists(dir))
fs::create_directories(path); CResourceManager::CreateDirectory(dir);
} }
return dir;
std::string dir2 = dir;
if(physfsReady) {
std::string savedir = CResourceManager::GetSaveLocation()+"/";
boost::replace_all(dir2, "\\", "/");
boost::replace_all(savedir, "\\", "/");
boost::replace_all(dir2, savedir, "");
}
return dir2;
} }
// Reads a new program. // Reads a new program.
@ -1577,7 +1562,7 @@ bool CStudio::ReadProgram()
{ {
strcat(filename, ".txt"); strcat(filename, ".txt");
} }
strcpy(dir, SearchDirectory(true, true).c_str()); strcpy(dir, SearchDirectory(true).c_str());
strcat(dir, filename); strcat(dir, filename);
pw = static_cast< CWindow* >(m_interface->SearchControl(EVENT_WINDOW3)); pw = static_cast< CWindow* >(m_interface->SearchControl(EVENT_WINDOW3));
@ -1615,7 +1600,7 @@ bool CStudio::WriteProgram()
{ {
strcat(filename, ".txt"); strcat(filename, ".txt");
} }
strcpy(dir, SearchDirectory(true, true).c_str()); strcpy(dir, SearchDirectory(true).c_str());
strcat(dir, filename); strcat(dir, filename);
pw = static_cast< CWindow* >(m_interface->SearchControl(EVENT_WINDOW3)); pw = static_cast< CWindow* >(m_interface->SearchControl(EVENT_WINDOW3));

View File

@ -88,7 +88,7 @@ protected:
void UpdateDialogAction(); void UpdateDialogAction();
void UpdateDialogPublic(); void UpdateDialogPublic();
void UpdateDialogList(); void UpdateDialogList();
std::string SearchDirectory(bool bCreate, bool physfsReady=false); std::string SearchDirectory(bool bCreate);
bool ReadProgram(); bool ReadProgram();
bool WriteProgram(); bool WriteProgram();