From 3dade17f89445559c093bf38af5c8f48114866ca Mon Sep 17 00:00:00 2001 From: krzys-h Date: Mon, 10 Nov 2014 14:16:32 +0100 Subject: [PATCH] Level saving through CLevelParser --- src/app/app.cpp | 4 +- src/object/auto/auto.cpp | 26 ++-- src/object/auto/auto.h | 3 +- src/object/auto/autoconvert.cpp | 23 ++-- src/object/auto/autoconvert.h | 2 +- src/object/auto/autoderrick.cpp | 25 ++-- src/object/auto/autoderrick.h | 2 +- src/object/auto/autodestroyer.cpp | 25 ++-- src/object/auto/autodestroyer.h | 2 +- src/object/auto/autoegg.cpp | 37 ++---- src/object/auto/autoegg.h | 2 +- src/object/auto/autoenergy.cpp | 25 ++-- src/object/auto/autoenergy.h | 2 +- src/object/auto/autofactory.cpp | 24 ++-- src/object/auto/autofactory.h | 2 +- src/object/auto/autoinfo.cpp | 27 ++-- src/object/auto/autoinfo.h | 2 +- src/object/auto/autolabo.cpp | 31 ++--- src/object/auto/autolabo.h | 2 +- src/object/auto/automush.cpp | 28 ++--- src/object/auto/automush.h | 2 +- src/object/auto/autonest.cpp | 28 ++--- src/object/auto/autonest.h | 2 +- src/object/auto/autonuclear.cpp | 25 ++-- src/object/auto/autonuclear.h | 2 +- src/object/auto/autopara.cpp | 25 ++-- src/object/auto/autopara.h | 2 +- src/object/auto/autorepair.cpp | 25 ++-- src/object/auto/autorepair.h | 2 +- src/object/auto/autoresearch.cpp | 28 ++--- src/object/auto/autoresearch.h | 2 +- src/object/auto/autosafe.cpp | 24 ++-- src/object/auto/autosafe.h | 2 +- src/object/auto/autotower.cpp | 45 +++---- src/object/auto/autotower.h | 2 +- src/object/brain.cpp | 9 +- src/object/brain.h | 3 +- src/object/level/parser.cpp | 1 - src/object/level/parser.h | 1 - src/object/level/parserparam.cpp | 2 +- src/object/motion/motion.cpp | 19 ++- src/object/motion/motion.h | 3 +- src/object/object.cpp | 145 +++++++-------------- src/object/object.h | 3 +- src/object/robotmain.cpp | 203 +++++++++++------------------- src/object/robotmain.h | 8 +- src/physics/physics.cpp | 16 +-- src/physics/physics.h | 3 +- src/ui/maindialog.cpp | 8 -- 49 files changed, 323 insertions(+), 611 deletions(-) diff --git a/src/app/app.cpp b/src/app/app.cpp index 6f333895..fb2656c4 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -1799,8 +1799,8 @@ void CApplication::SetLanguage(Language language) putenv(S_LANGUAGE); 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()); bind_textdomain_codeset("colobot", "UTF-8"); diff --git a/src/object/auto/auto.cpp b/src/object/auto/auto.cpp index fb6698b7..a8386c54 100644 --- a/src/object/auto/auto.cpp +++ b/src/object/auto/auto.cpp @@ -26,6 +26,9 @@ #include "common/event.h" #include "common/iman.h" +#include "object/level/parserline.h" +#include "object/level/parserparam.h" + #include "script/cmdtoken.h" #include "ui/interface.h" @@ -424,24 +427,13 @@ void CAuto::SetMotor(bool bMotor) // Saves all parameters of the controller. -bool CAuto::Write(char *line) +bool CAuto::Write(CLevelParserLine* line) { - char name[100]; - - sprintf(name, " aType=%d", m_type); - strcat(line, name); - - 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); + line->AddParam("aType", new CLevelParserParam(m_type)); + line->AddParam("aBusy", new CLevelParserParam(m_bBusy)); + line->AddParam("aTime", new CLevelParserParam(m_time)); + line->AddParam("aProgressTime", new CLevelParserParam(m_progressTime)); + line->AddParam("aProgressTotal", new CLevelParserParam(m_progressTotal)); return false; } diff --git a/src/object/auto/auto.h b/src/object/auto/auto.h index af7766cc..610c39bc 100644 --- a/src/object/auto/auto.h +++ b/src/object/auto/auto.h @@ -29,6 +29,7 @@ class CInstanceManager; class CRobotMain; class CSoundInterface; +class CLevelParserLine; namespace Ui { class CInterface; @@ -80,7 +81,7 @@ public: virtual bool GetMotor(); virtual void SetMotor(bool bMotor); - virtual bool Write(char *line); + virtual bool Write(CLevelParserLine* line); virtual bool Read(char *line); protected: diff --git a/src/object/auto/autoconvert.cpp b/src/object/auto/autoconvert.cpp index 5dc80e94..c588b94d 100644 --- a/src/object/auto/autoconvert.cpp +++ b/src/object/auto/autoconvert.cpp @@ -24,6 +24,9 @@ #include "math/geometry.h" +#include "object/level/parserline.h" +#include "object/level/parserparam.h" + #include "script/cmdtoken.h" #include "ui/interface.h" @@ -361,26 +364,16 @@ bool CAutoConvert::CreateInterface(bool bSelect) // Saves all parameters of the controller. -bool CAutoConvert::Write(char *line) +bool CAutoConvert::Write(CLevelParserLine* line) { - char name[100]; - if ( m_phase == ACP_STOP || m_phase == ACP_WAIT ) return false; - sprintf(name, " aExist=%d", 1); - strcat(line, name); - + line->AddParam("aExist", new CLevelParserParam(true)); CAuto::Write(line); - - sprintf(name, " aPhase=%d", m_phase); - strcat(line, name); - - sprintf(name, " aProgress=%.2f", m_progress); - strcat(line, name); - - sprintf(name, " aSpeed=%.2f", m_speed); - strcat(line, name); + line->AddParam("aPhase", new CLevelParserParam(static_cast(m_phase))); + line->AddParam("aProgress", new CLevelParserParam(m_progress)); + line->AddParam("aSpeed", new CLevelParserParam(m_speed)); return true; } diff --git a/src/object/auto/autoconvert.h b/src/object/auto/autoconvert.h index 54cdb986..f28f0ac3 100644 --- a/src/object/auto/autoconvert.h +++ b/src/object/auto/autoconvert.h @@ -52,7 +52,7 @@ public: bool CreateInterface(bool bSelect); - bool Write(char *line); + bool Write(CLevelParserLine* line); bool Read(char *line); protected: diff --git a/src/object/auto/autoderrick.cpp b/src/object/auto/autoderrick.cpp index f797ed97..6f067176 100644 --- a/src/object/auto/autoderrick.cpp +++ b/src/object/auto/autoderrick.cpp @@ -26,6 +26,9 @@ #include "math/geometry.h" +#include "object/level/parserline.h" +#include "object/level/parserparam.h" + #include "script/cmdtoken.h" #include "ui/interface.h" @@ -428,25 +431,15 @@ bool CAutoDerrick::CreateInterface(bool bSelect) // 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; - - sprintf(name, " aExist=%d", 1); - strcat(line, name); - + + line->AddParam("aExist", new CLevelParserParam(true)); CAuto::Write(line); - - sprintf(name, " aPhase=%d", m_phase); - strcat(line, name); - - sprintf(name, " aProgress=%.2f", m_progress); - strcat(line, name); - - sprintf(name, " aSpeed=%.2f", m_speed); - strcat(line, name); + line->AddParam("aPhase", new CLevelParserParam(static_cast(m_phase))); + line->AddParam("aProgress", new CLevelParserParam(m_progress)); + line->AddParam("aSpeed", new CLevelParserParam(m_speed)); return true; } diff --git a/src/object/auto/autoderrick.h b/src/object/auto/autoderrick.h index dd2f4d98..052a4c26 100644 --- a/src/object/auto/autoderrick.h +++ b/src/object/auto/autoderrick.h @@ -51,7 +51,7 @@ public: bool CreateInterface(bool bSelect); - bool Write(char *line); + bool Write(CLevelParserLine* line); bool Read(char *line); protected: diff --git a/src/object/auto/autodestroyer.cpp b/src/object/auto/autodestroyer.cpp index bc392f55..068a51e6 100644 --- a/src/object/auto/autodestroyer.cpp +++ b/src/object/auto/autodestroyer.cpp @@ -22,6 +22,9 @@ #include "common/iman.h" +#include "object/level/parserline.h" +#include "object/level/parserparam.h" + #include "script/cmdtoken.h" #include "ui/interface.h" @@ -357,25 +360,15 @@ Error CAutoDestroyer::GetError() // 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; - - sprintf(name, " aExist=%d", 1); - strcat(line, name); - + + line->AddParam("aExist", new CLevelParserParam(true)); CAuto::Write(line); - - sprintf(name, " aPhase=%d", m_phase); - strcat(line, name); - - sprintf(name, " aProgress=%.2f", m_progress); - strcat(line, name); - - sprintf(name, " aSpeed=%.2f", m_speed); - strcat(line, name); + line->AddParam("aPhase", new CLevelParserParam(static_cast(m_phase))); + line->AddParam("aProgress", new CLevelParserParam(m_progress)); + line->AddParam("aSpeed", new CLevelParserParam(m_speed)); return true; } diff --git a/src/object/auto/autodestroyer.h b/src/object/auto/autodestroyer.h index 14949e26..73a2d340 100644 --- a/src/object/auto/autodestroyer.h +++ b/src/object/auto/autodestroyer.h @@ -52,7 +52,7 @@ public: bool CreateInterface(bool bSelect); - bool Write(char *line); + bool Write(CLevelParserLine* line); bool Read(char *line); protected: diff --git a/src/object/auto/autoegg.cpp b/src/object/auto/autoegg.cpp index 828821a0..91ba585d 100644 --- a/src/object/auto/autoegg.cpp +++ b/src/object/auto/autoegg.cpp @@ -24,6 +24,9 @@ #include "math/geometry.h" +#include "object/level/parserline.h" +#include "object/level/parserparam.h" + #include "script/cmdtoken.h" #include @@ -310,34 +313,18 @@ CObject* CAutoEgg::SearchAlien() // 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; - - sprintf(name, " aExist=%d", 1); - strcat(line, name); - + + line->AddParam("aExist", new CLevelParserParam(true)); CAuto::Write(line); - - sprintf(name, " aPhase=%d", m_phase); - strcat(line, name); - - sprintf(name, " aProgress=%.2f", m_progress); - strcat(line, name); - - 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); + line->AddParam("aPhase", new CLevelParserParam(static_cast(m_phase))); + line->AddParam("aProgress", new CLevelParserParam(m_progress)); + line->AddParam("aSpeed", new CLevelParserParam(m_speed)); + line->AddParam("aParamType", new CLevelParserParam(m_type)); + line->AddParam("aParamValue1", new CLevelParserParam(m_value)); + line->AddParam("aParamString", new CLevelParserParam(m_string)); return true; } diff --git a/src/object/auto/autoegg.h b/src/object/auto/autoegg.h index 54c6e34c..79a583f2 100644 --- a/src/object/auto/autoegg.h +++ b/src/object/auto/autoegg.h @@ -54,7 +54,7 @@ public: bool SetValue(int rank, float value); bool SetString(char *string); - bool Write(char *line); + bool Write(CLevelParserLine* line); bool Read(char *line); protected: diff --git a/src/object/auto/autoenergy.cpp b/src/object/auto/autoenergy.cpp index ea97cc80..3e359561 100644 --- a/src/object/auto/autoenergy.cpp +++ b/src/object/auto/autoenergy.cpp @@ -26,6 +26,9 @@ #include "math/geometry.h" +#include "object/level/parserline.h" +#include "object/level/parserparam.h" + #include "script/cmdtoken.h" #include "ui/interface.h" @@ -609,26 +612,16 @@ void CAutoEnergy::UpdateInterface(float rTime) // Saves all parameters of the controller. -bool CAutoEnergy::Write(char *line) +bool CAutoEnergy::Write(CLevelParserLine* line) { - char name[100]; - if ( m_phase == AENP_STOP || m_phase == AENP_WAIT ) return false; - - sprintf(name, " aExist=%d", 1); - strcat(line, name); - + + line->AddParam("aExist", new CLevelParserParam(true)); CAuto::Write(line); - - sprintf(name, " aPhase=%d", m_phase); - strcat(line, name); - - sprintf(name, " aProgress=%.2f", m_progress); - strcat(line, name); - - sprintf(name, " aSpeed=%.2f", m_speed); - strcat(line, name); + line->AddParam("aPhase", new CLevelParserParam(static_cast(m_phase))); + line->AddParam("aProgress", new CLevelParserParam(m_progress)); + line->AddParam("aSpeed", new CLevelParserParam(m_speed)); return true; } diff --git a/src/object/auto/autoenergy.h b/src/object/auto/autoenergy.h index fc6f470b..ed11fb71 100644 --- a/src/object/auto/autoenergy.h +++ b/src/object/auto/autoenergy.h @@ -51,7 +51,7 @@ public: bool CreateInterface(bool bSelect); - bool Write(char *line); + bool Write(CLevelParserLine* line); bool Read(char *line); protected: diff --git a/src/object/auto/autofactory.cpp b/src/object/auto/autofactory.cpp index 825ea53f..67dc60bd 100644 --- a/src/object/auto/autofactory.cpp +++ b/src/object/auto/autofactory.cpp @@ -27,6 +27,8 @@ #include "object/robotmain.h" #include "object/brain.h" +#include "object/level/parserline.h" +#include "object/level/parserparam.h" #include "physics/physics.h" @@ -515,25 +517,15 @@ bool CAutoFactory::EventProcess(const Event &event) // 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; - - sprintf(name, " aExist=%d", 1); - strcat(line, name); - + + line->AddParam("aExist", new CLevelParserParam(true)); CAuto::Write(line); - - sprintf(name, " aPhase=%d", m_phase); - strcat(line, name); - - sprintf(name, " aProgress=%.2f", m_progress); - strcat(line, name); - - sprintf(name, " aSpeed=%.2f", m_speed); - strcat(line, name); + line->AddParam("aPhase", new CLevelParserParam(static_cast(m_phase))); + line->AddParam("aProgress", new CLevelParserParam(m_progress)); + line->AddParam("aSpeed", new CLevelParserParam(m_speed)); return true; } diff --git a/src/object/auto/autofactory.h b/src/object/auto/autofactory.h index 60a44fba..a2320301 100644 --- a/src/object/auto/autofactory.h +++ b/src/object/auto/autofactory.h @@ -55,7 +55,7 @@ public: bool CreateInterface(bool bSelect); - bool Write(char *line); + bool Write(CLevelParserLine* line); bool Read(char *line); protected: diff --git a/src/object/auto/autoinfo.cpp b/src/object/auto/autoinfo.cpp index 7b8622f9..b5a3db45 100644 --- a/src/object/auto/autoinfo.cpp +++ b/src/object/auto/autoinfo.cpp @@ -20,7 +20,12 @@ #include "object/auto/autoinfo.h" + +#include "object/level/parserline.h" +#include "object/level/parserparam.h" + #include "script/cmdtoken.h" + #include "ui/interface.h" #include "ui/list.h" #include "ui/window.h" @@ -475,25 +480,15 @@ void CAutoInfo::UpdateListVirus() // 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; - - sprintf(name, " aExist=%d", 1); - strcat(line, name); - + + line->AddParam("aExist", new CLevelParserParam(true)); CAuto::Write(line); - - sprintf(name, " aPhase=%d", m_phase); - strcat(line, name); - - sprintf(name, " aProgress=%.2f", m_progress); - strcat(line, name); - - sprintf(name, " aSpeed=%.2f", m_speed); - strcat(line, name); + line->AddParam("aPhase", new CLevelParserParam(static_cast(m_phase))); + line->AddParam("aProgress", new CLevelParserParam(m_progress)); + line->AddParam("aSpeed", new CLevelParserParam(m_speed)); return true; } diff --git a/src/object/auto/autoinfo.h b/src/object/auto/autoinfo.h index 632edf8f..5923cd03 100644 --- a/src/object/auto/autoinfo.h +++ b/src/object/auto/autoinfo.h @@ -51,7 +51,7 @@ public: bool CreateInterface(bool bSelect); - bool Write(char *line); + bool Write(CLevelParserLine* line); bool Read(char *line); protected: diff --git a/src/object/auto/autolabo.cpp b/src/object/auto/autolabo.cpp index 3a0be92e..8145fa13 100644 --- a/src/object/auto/autolabo.cpp +++ b/src/object/auto/autolabo.cpp @@ -26,6 +26,8 @@ #include "math/geometry.h" #include "object/robotmain.h" +#include "object/level/parserline.h" +#include "object/level/parserparam.h" #include "script/cmdtoken.h" @@ -586,29 +588,16 @@ void CAutoLabo::SoundManip(float time, float amplitude, float frequency) // 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; - - sprintf(name, " aExist=%d", 1); - strcat(line, name); - + + line->AddParam("aExist", new CLevelParserParam(true)); CAuto::Write(line); - - sprintf(name, " aPhase=%d", m_phase); - strcat(line, name); - - 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); + line->AddParam("aPhase", new CLevelParserParam(static_cast(m_phase))); + line->AddParam("aProgress", new CLevelParserParam(m_progress)); + line->AddParam("aSpeed", new CLevelParserParam(m_speed)); + line->AddParam("aResearch", new CLevelParserParam(static_cast(m_research))); return true; } @@ -617,8 +606,6 @@ bool CAutoLabo::Write(char *line) bool CAutoLabo::Read(char *line) { - Math::Vector pos; - if ( OpInt(line, "aExist", 0) == 0 ) return false; CAuto::Read(line); diff --git a/src/object/auto/autolabo.h b/src/object/auto/autolabo.h index b62668ee..8828dd94 100644 --- a/src/object/auto/autolabo.h +++ b/src/object/auto/autolabo.h @@ -55,7 +55,7 @@ public: bool CreateInterface(bool bSelect); - bool Write(char *line); + bool Write(CLevelParserLine* line); bool Read(char *line); protected: diff --git a/src/object/auto/automush.cpp b/src/object/auto/automush.cpp index c05878dd..958f3b32 100644 --- a/src/object/auto/automush.cpp +++ b/src/object/auto/automush.cpp @@ -22,6 +22,9 @@ #include "common/iman.h" +#include "object/level/parserline.h" +#include "object/level/parserparam.h" + #include "script/cmdtoken.h" @@ -301,26 +304,15 @@ Error CAutoMush::GetError() // 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; - - sprintf(name, " aExist=%d", 1); - strcat(line, name); - + + line->AddParam("aExist", new CLevelParserParam(true)); CAuto::Write(line); - - sprintf(name, " aPhase=%d", m_phase); - strcat(line, name); - - sprintf(name, " aProgress=%.2f", m_progress); - strcat(line, name); - - sprintf(name, " aSpeed=%.2f", m_speed); - strcat(line, name); + line->AddParam("aPhase", new CLevelParserParam(static_cast(m_phase))); + line->AddParam("aProgress", new CLevelParserParam(m_progress)); + line->AddParam("aSpeed", new CLevelParserParam(m_speed)); return true; } @@ -329,8 +321,6 @@ bool CAutoMush::Write(char *line) bool CAutoMush::Read(char *line) { - Math::Vector pos; - if ( OpInt(line, "aExist", 0) == 0 ) return false; CAuto::Read(line); diff --git a/src/object/auto/automush.h b/src/object/auto/automush.h index 2d70eaa0..183914de 100644 --- a/src/object/auto/automush.h +++ b/src/object/auto/automush.h @@ -49,7 +49,7 @@ public: bool EventProcess(const Event &event); Error GetError(); - bool Write(char *line); + bool Write(CLevelParserLine* line); bool Read(char *line); protected: diff --git a/src/object/auto/autonest.cpp b/src/object/auto/autonest.cpp index 1c3b834e..9855730b 100644 --- a/src/object/auto/autonest.cpp +++ b/src/object/auto/autonest.cpp @@ -24,6 +24,9 @@ #include "graphics/engine/terrain.h" +#include "object/level/parserline.h" +#include "object/level/parserparam.h" + #include "script/cmdtoken.h" #include @@ -232,26 +235,15 @@ Error CAutoNest::GetError() // 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; - - sprintf(name, " aExist=%d", 1); - strcat(line, name); - + + line->AddParam("aExist", new CLevelParserParam(true)); CAuto::Write(line); - - sprintf(name, " aPhase=%d", m_phase); - strcat(line, name); - - sprintf(name, " aProgress=%.2f", m_progress); - strcat(line, name); - - sprintf(name, " aSpeed=%.2f", m_speed); - strcat(line, name); + line->AddParam("aPhase", new CLevelParserParam(static_cast(m_phase))); + line->AddParam("aProgress", new CLevelParserParam(m_progress)); + line->AddParam("aSpeed", new CLevelParserParam(m_speed)); return true; } @@ -260,8 +252,6 @@ bool CAutoNest::Write(char *line) bool CAutoNest::Read(char *line) { - Math::Vector pos; - if ( OpInt(line, "aExist", 0) == 0 ) return false; CAuto::Read(line); diff --git a/src/object/auto/autonest.h b/src/object/auto/autonest.h index df16367c..acbc6600 100644 --- a/src/object/auto/autonest.h +++ b/src/object/auto/autonest.h @@ -46,7 +46,7 @@ public: bool EventProcess(const Event &event); Error GetError(); - bool Write(char *line); + bool Write(CLevelParserLine* line); bool Read(char *line); protected: diff --git a/src/object/auto/autonuclear.cpp b/src/object/auto/autonuclear.cpp index 8fc74616..54a0edac 100644 --- a/src/object/auto/autonuclear.cpp +++ b/src/object/auto/autonuclear.cpp @@ -24,6 +24,9 @@ #include "math/geometry.h" +#include "object/level/parserline.h" +#include "object/level/parserparam.h" + #include "script/cmdtoken.h" #include "ui/interface.h" @@ -444,26 +447,16 @@ Error CAutoNuclear::GetError() // Saves all parameters of the controller. -bool CAutoNuclear::Write(char *line) +bool CAutoNuclear::Write(CLevelParserLine* line) { - char name[100]; - if ( m_phase == ANUP_STOP || m_phase == ANUP_WAIT ) return false; - - sprintf(name, " aExist=%d", 1); - strcat(line, name); - + + line->AddParam("aExist", new CLevelParserParam(true)); CAuto::Write(line); - - sprintf(name, " aPhase=%d", m_phase); - strcat(line, name); - - sprintf(name, " aProgress=%.2f", m_progress); - strcat(line, name); - - sprintf(name, " aSpeed=%.2f", m_speed); - strcat(line, name); + line->AddParam("aPhase", new CLevelParserParam(static_cast(m_phase))); + line->AddParam("aProgress", new CLevelParserParam(m_progress)); + line->AddParam("aSpeed", new CLevelParserParam(m_speed)); return true; } diff --git a/src/object/auto/autonuclear.h b/src/object/auto/autonuclear.h index 83d8a912..f513e5b5 100644 --- a/src/object/auto/autonuclear.h +++ b/src/object/auto/autonuclear.h @@ -51,7 +51,7 @@ public: bool CreateInterface(bool bSelect); - bool Write(char *line); + bool Write(CLevelParserLine* line); bool Read(char *line); protected: diff --git a/src/object/auto/autopara.cpp b/src/object/auto/autopara.cpp index 4a8e6081..779a897c 100644 --- a/src/object/auto/autopara.cpp +++ b/src/object/auto/autopara.cpp @@ -25,6 +25,9 @@ #include "math/geometry.h" +#include "object/level/parserline.h" +#include "object/level/parserparam.h" + #include "script/cmdtoken.h" #include "ui/interface.h" @@ -289,25 +292,15 @@ void CAutoPara::ChargeObject(float rTime) // 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; - - sprintf(name, " aExist=%d", 1); - strcat(line, name); - + + line->AddParam("aExist", new CLevelParserParam(true)); CAuto::Write(line); - - sprintf(name, " aPhase=%d", m_phase); - strcat(line, name); - - sprintf(name, " aProgress=%.2f", m_progress); - strcat(line, name); - - sprintf(name, " aSpeed=%.2f", m_speed); - strcat(line, name); + line->AddParam("aPhase", new CLevelParserParam(static_cast(m_phase))); + line->AddParam("aProgress", new CLevelParserParam(m_progress)); + line->AddParam("aSpeed", new CLevelParserParam(m_speed)); return true; } diff --git a/src/object/auto/autopara.h b/src/object/auto/autopara.h index 059d813f..27a3fc35 100644 --- a/src/object/auto/autopara.h +++ b/src/object/auto/autopara.h @@ -50,7 +50,7 @@ public: bool CreateInterface(bool bSelect); - bool Write(char *line); + bool Write(CLevelParserLine* line); bool Read(char *line); protected: diff --git a/src/object/auto/autorepair.cpp b/src/object/auto/autorepair.cpp index f118ab5d..0e49d5cc 100644 --- a/src/object/auto/autorepair.cpp +++ b/src/object/auto/autorepair.cpp @@ -22,6 +22,9 @@ #include "common/iman.h" +#include "object/level/parserline.h" +#include "object/level/parserparam.h" + #include "physics/physics.h" #include "script/cmdtoken.h" @@ -302,25 +305,15 @@ Error CAutoRepair::GetError() // 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; - - sprintf(name, " aExist=%d", 1); - strcat(line, name); - + + line->AddParam("aExist", new CLevelParserParam(true)); CAuto::Write(line); - - sprintf(name, " aPhase=%d", m_phase); - strcat(line, name); - - sprintf(name, " aProgress=%.2f", m_progress); - strcat(line, name); - - sprintf(name, " aSpeed=%.2f", m_speed); - strcat(line, name); + line->AddParam("aPhase", new CLevelParserParam(static_cast(m_phase))); + line->AddParam("aProgress", new CLevelParserParam(m_progress)); + line->AddParam("aSpeed", new CLevelParserParam(m_speed)); return true; } diff --git a/src/object/auto/autorepair.h b/src/object/auto/autorepair.h index e3772795..d59083fb 100644 --- a/src/object/auto/autorepair.h +++ b/src/object/auto/autorepair.h @@ -51,7 +51,7 @@ public: bool CreateInterface(bool bSelect); - bool Write(char *line); + bool Write(CLevelParserLine* line); bool Read(char *line); protected: diff --git a/src/object/auto/autoresearch.cpp b/src/object/auto/autoresearch.cpp index ed6ce9d6..d36342c6 100644 --- a/src/object/auto/autoresearch.cpp +++ b/src/object/auto/autoresearch.cpp @@ -25,6 +25,8 @@ #include "math/geometry.h" #include "object/robotmain.h" +#include "object/level/parserline.h" +#include "object/level/parserparam.h" #include "script/cmdtoken.h" @@ -563,28 +565,16 @@ void CAutoResearch::FireStopUpdate(float progress, bool bLightOn) // 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; - - sprintf(name, " aExist=%d", 1); - strcat(line, name); - + + line->AddParam("aExist", new CLevelParserParam(true)); CAuto::Write(line); - - sprintf(name, " aPhase=%d", m_phase); - strcat(line, name); - - 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); + line->AddParam("aPhase", new CLevelParserParam(static_cast(m_phase))); + line->AddParam("aProgress", new CLevelParserParam(m_progress)); + line->AddParam("aSpeed", new CLevelParserParam(m_speed)); + line->AddParam("aResearch", new CLevelParserParam(static_cast(m_research))); return true; } diff --git a/src/object/auto/autoresearch.h b/src/object/auto/autoresearch.h index 6b76b3d7..9cb7c28d 100644 --- a/src/object/auto/autoresearch.h +++ b/src/object/auto/autoresearch.h @@ -49,7 +49,7 @@ public: bool CreateInterface(bool bSelect); - bool Write(char *line); + bool Write(CLevelParserLine* line); bool Read(char *line); protected: diff --git a/src/object/auto/autosafe.cpp b/src/object/auto/autosafe.cpp index 7337c1bf..1f4a0ac1 100644 --- a/src/object/auto/autosafe.cpp +++ b/src/object/auto/autosafe.cpp @@ -25,6 +25,8 @@ #include "math/geometry.h" #include "object/robotmain.h" +#include "object/level/parserline.h" +#include "object/level/parserparam.h" #include "script/cmdtoken.h" @@ -353,25 +355,15 @@ Error CAutoSafe::GetError() // 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; - - sprintf(name, " aExist=%d", 1); - strcat(line, name); - + + line->AddParam("aExist", new CLevelParserParam(true)); CAuto::Write(line); - - sprintf(name, " aPhase=%d", m_phase); - strcat(line, name); - - sprintf(name, " aProgress=%.2f", m_progress); - strcat(line, name); - - sprintf(name, " aSpeed=%.2f", m_speed); - strcat(line, name); + line->AddParam("aPhase", new CLevelParserParam(static_cast(m_phase))); + line->AddParam("aProgress", new CLevelParserParam(m_progress)); + line->AddParam("aSpeed", new CLevelParserParam(m_speed)); return true; } diff --git a/src/object/auto/autosafe.h b/src/object/auto/autosafe.h index 60219dd9..7885a421 100644 --- a/src/object/auto/autosafe.h +++ b/src/object/auto/autosafe.h @@ -49,7 +49,7 @@ public: bool CreateInterface(bool bSelect); - bool Write(char *line); + bool Write(CLevelParserLine* line); bool Read(char *line); protected: diff --git a/src/object/auto/autotower.cpp b/src/object/auto/autotower.cpp index c06fa55c..39233a1a 100644 --- a/src/object/auto/autotower.cpp +++ b/src/object/auto/autotower.cpp @@ -24,6 +24,9 @@ #include "math/geometry.h" +#include "object/level/parserline.h" +#include "object/level/parserparam.h" + #include "physics/physics.h" #include "script/cmdtoken.h" @@ -485,40 +488,20 @@ void CAutoTower::UpdateInterface(float rTime) // 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; - - sprintf(name, " aExist=%d", 1); - strcat(line, name); - + + line->AddParam("aExist", new CLevelParserParam(true)); CAuto::Write(line); - - sprintf(name, " aPhase=%d", m_phase); - strcat(line, name); - - sprintf(name, " aProgress=%.2f", m_progress); - strcat(line, name); - - sprintf(name, " aSpeed=%.2f", m_speed); - 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); + line->AddParam("aPhase", new CLevelParserParam(static_cast(m_phase))); + line->AddParam("aProgress", new CLevelParserParam(m_progress)); + line->AddParam("aSpeed", new CLevelParserParam(m_speed)); + line->AddParam("aTargetPos", new CLevelParserParam(m_targetPos)); + line->AddParam("aAngleYactual", new CLevelParserParam(m_angleYactual)); + line->AddParam("aAngleZactual", new CLevelParserParam(m_angleZactual)); + line->AddParam("aAngleYfinal", new CLevelParserParam(m_angleYfinal)); + line->AddParam("aAngleZfinal", new CLevelParserParam(m_angleZfinal)); return true; } diff --git a/src/object/auto/autotower.h b/src/object/auto/autotower.h index 0158b22e..3333ee33 100644 --- a/src/object/auto/autotower.h +++ b/src/object/auto/autotower.h @@ -51,7 +51,7 @@ public: bool CreateInterface(bool bSelect); - bool Write(char *line); + bool Write(CLevelParserLine* line); bool Read(char *line); protected: diff --git a/src/object/brain.cpp b/src/object/brain.cpp index f10faac3..d8a810af 100644 --- a/src/object/brain.cpp +++ b/src/object/brain.cpp @@ -30,6 +30,8 @@ #include "object/motion/motion.h" #include "object/task/taskmanager.h" +#include "object/level/parserline.h" +#include "object/level/parserparam.h" #include "physics/physics.h" @@ -169,12 +171,9 @@ void CBrain::SetMotion(CMotion* motion) // Saves all parameters of the object. -bool CBrain::Write(char *line) +bool CBrain::Write(CLevelParserLine* line) { - char name[100]; - - sprintf(name, " bVirusActive=%d", m_bActiveVirus); - strcat(line, name); + line->AddParam("bVirusActive", new CLevelParserParam(m_bActiveVirus)); return true; } diff --git a/src/object/brain.h b/src/object/brain.h index a0d18698..5d2983b8 100644 --- a/src/object/brain.h +++ b/src/object/brain.h @@ -41,6 +41,7 @@ class CTaskManager; class CScript; class CRobotMain; class CSoundInterface; +class CLevelParserLine; namespace Ui { class CStudio; @@ -92,7 +93,7 @@ public: bool EventProcess(const Event &event); bool CreateInterface(bool bSelect); - bool Write(char *line); + bool Write(CLevelParserLine* line); bool Read(char *line); bool IsBusy(); diff --git a/src/object/level/parser.cpp b/src/object/level/parser.cpp index 2b0f6302..7c612af6 100644 --- a/src/object/level/parser.cpp +++ b/src/object/level/parser.cpp @@ -236,7 +236,6 @@ void CLevelParser::Save() } file.close(); - } const std::string& CLevelParser::GetFilename() diff --git a/src/object/level/parser.h b/src/object/level/parser.h index 105c0d79..e0458b5b 100644 --- a/src/object/level/parser.h +++ b/src/object/level/parser.h @@ -65,7 +65,6 @@ public: CLevelParserLine* Get(std::string command); private: - std::string m_filename; std::vector m_lines; }; \ No newline at end of file diff --git a/src/object/level/parserparam.cpp b/src/object/level/parserparam.cpp index 6408e036..a6393623 100644 --- a/src/object/level/parserparam.cpp +++ b/src/object/level/parserparam.cpp @@ -975,7 +975,7 @@ CLevelParserParam::CLevelParserParam(std::string value) } CLevelParserParam::CLevelParserParam(bool value) { - m_value = value ? "true" : "false"; + m_value = value ? "1" : "0"; } CLevelParserParam::CLevelParserParam(Gfx::Color value) { diff --git a/src/object/motion/motion.cpp b/src/object/motion/motion.cpp index 66933178..225cc714 100644 --- a/src/object/motion/motion.cpp +++ b/src/object/motion/motion.cpp @@ -23,6 +23,8 @@ #include "app/app.h" #include "object/robotmain.h" +#include "object/level/parserline.h" +#include "object/level/parserparam.h" #include "script/cmdtoken.h" @@ -171,20 +173,13 @@ float CMotion::GetParam(int rank) // 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; - - sprintf(name, " mType=%d", m_actionType); - strcat(line, name); - - sprintf(name, " mTime=%.2f", m_actionTime); - strcat(line, name); - - sprintf(name, " mProgress=%.2f", m_progress); - strcat(line, name); + + line->AddParam("mType", new CLevelParserParam(m_actionType)); + line->AddParam("mTime", new CLevelParserParam(m_actionTime)); + line->AddParam("mProgress", new CLevelParserParam(m_progress)); return false; } diff --git a/src/object/motion/motion.h b/src/object/motion/motion.h index 81350b7d..d534eb5d 100644 --- a/src/object/motion/motion.h +++ b/src/object/motion/motion.h @@ -42,6 +42,7 @@ class CPhysics; class CObject; class CRobotMain; class CSoundInterface; +class CLevelParserLine; class CMotion @@ -62,7 +63,7 @@ public: virtual bool SetParam(int rank, float value); virtual float GetParam(int rank); - virtual bool Write(char *line); + virtual bool Write(CLevelParserLine* line); virtual bool Read(char *line); virtual void SetLinVibration(Math::Vector dir); diff --git a/src/object/object.cpp b/src/object/object.cpp index a64bcb5d..1c5f930c 100644 --- a/src/object/object.cpp +++ b/src/object/object.cpp @@ -76,12 +76,16 @@ #include "object/motion/motionworm.h" #include "object/robotmain.h" #include "object/objman.h" +#include "object/level/parserline.h" +#include "object/level/parserparam.h" #include "physics/physics.h" #include "script/cbottoken.h" #include "script/cmdtoken.h" +#include + #define ADJUST_ONBOARD false // true -> adjusts the camera ONBOARD @@ -995,137 +999,76 @@ int CObject::GetID() // Saves all the parameters of the object. -bool CObject::Write(char *line) +bool CObject::Write(CLevelParserLine* line) { Math::Vector pos; Info info; - char name[100]; float value; int i; - sprintf(name, " camera=%s", GetCamera(GetCameraType())); - strcat(line, name); + line->AddParam("camera", new CLevelParserParam(GetCameraType())); - if ( GetCameraLock() != 0 ) - { - sprintf(name, " cameraLock=%d", GetCameraLock()); - strcat(line, name); - } + if ( GetCameraLock() ) + line->AddParam("cameraLock", new CLevelParserParam(GetCameraLock())); if ( GetEnergy() != 0.0f ) - { - sprintf(name, " energy=%.2f", GetEnergy()); - strcat(line, name); - } + line->AddParam("energy", new CLevelParserParam(GetEnergy())); if ( GetCapacity() != 1.0f ) - { - sprintf(name, " capacity=%.2f", GetCapacity()); - strcat(line, name); - } - + line->AddParam("capacity", new CLevelParserParam(GetCapacity())); + if ( GetShield() != 1.0f ) - { - sprintf(name, " shield=%.2f", GetShield()); - strcat(line, name); - } + line->AddParam("shield", new CLevelParserParam(GetShield())); if ( GetRange() != 1.0f ) - { - sprintf(name, " range=%.2f", GetRange()); - strcat(line, name); - } + line->AddParam("range", new CLevelParserParam(GetRange())); + + if ( !GetSelectable() ) + line->AddParam("selectable", new CLevelParserParam(GetSelectable())); - if ( GetSelectable() != 1 ) - { - sprintf(name, " selectable=%d", GetSelectable()); - strcat(line, name); - } + if ( !GetEnable() ) + line->AddParam("enable", new CLevelParserParam(GetEnable())); - if ( GetEnable() != 1 ) - { - sprintf(name, " enable=%d", GetEnable()); - strcat(line, name); - } + if ( GetFixed() ) + line->AddParam("fixed", new CLevelParserParam(GetFixed())); - if ( GetFixed() != 0 ) - { - sprintf(name, " fixed=%d", GetFixed()); - strcat(line, name); - } + if ( !GetClip() ) + line->AddParam("clip", new CLevelParserParam(GetClip())); - if ( GetClip() != 1 ) - { - sprintf(name, " clip=%d", GetClip()); - strcat(line, name); - } + if ( GetLock() ) + line->AddParam("lock", new CLevelParserParam(GetLock())); - if ( GetLock() != 0 ) + if ( GetProxyActivate() ) { - sprintf(name, " lock=%d", GetLock()); - strcat(line, name); - } - - if ( GetProxyActivate() != 0 ) - { - sprintf(name, " proxyActivate=%d", GetProxyActivate()); - strcat(line, name); - - sprintf(name, " proxyDistance=%.2f", GetProxyDistance()/g_unit); - strcat(line, name); + line->AddParam("proxyActivate", new CLevelParserParam(GetProxyActivate())); + line->AddParam("proxyActivate", new CLevelParserParam(GetProxyDistance()/g_unit)); } if ( GetMagnifyDamage() != 1.0f ) - { - sprintf(name, " magnifyDamage=%.2f", GetMagnifyDamage()); - strcat(line, name); - } + line->AddParam("magnifyDamage", new CLevelParserParam(GetMagnifyDamage())); if ( GetGunGoalV() != 0.0f ) - { - sprintf(name, " aimV=%.2f", GetGunGoalV()); - strcat(line, name); - } + line->AddParam("aimV", new CLevelParserParam(GetGunGoalV())); + if ( GetGunGoalH() != 0.0f ) - { - sprintf(name, " aimH=%.2f", GetGunGoalH()); - strcat(line, name); - } + line->AddParam("aimH", new CLevelParserParam(GetGunGoalH())); if ( GetParam() != 0.0f ) - { - sprintf(name, " param=%.2f", GetParam()); - strcat(line, name); - } + line->AddParam("param", new CLevelParserParam(GetParam())); if ( GetResetCap() != 0 ) { - sprintf(name, " resetCap=%d", GetResetCap()); - strcat(line, name); - - pos = GetResetPosition()/g_unit; - 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); + line->AddParam("resetCap", new CLevelParserParam(static_cast(GetResetCap()))); + line->AddParam("resetPos", new CLevelParserParam(GetResetPosition()/g_unit)); + line->AddParam("resetAngle", new CLevelParserParam(GetResetAngle()/(Math::PI/180.0f))); + line->AddParam("resetRun", new CLevelParserParam(GetResetRun())); } - if ( m_bVirusMode != 0 ) - { - sprintf(name, " virusMode=%d", m_bVirusMode); - strcat(line, name); - } + if ( m_bVirusMode ) + line->AddParam("virusMode", new CLevelParserParam(m_bVirusMode)); if ( m_virusTime != 0.0f ) - { - sprintf(name, " virusTime=%.2f", m_virusTime); - strcat(line, name); - } + line->AddParam("virusTime", new CLevelParserParam(m_virusTime)); // Puts information in terminal (OBJECT_INFO). for ( i=0 ; iAddParam("info"+boost::lexical_cast(i+1), new CLevelParserParam(std::string(info.name)+"="+boost::lexical_cast(info.value))); } // Sets the parameters of the command line. + std::vector cmdline; for ( i=0 ; i 0) + line->AddParam("cmdline", new CLevelParserParam(cmdline)); if ( m_motion != 0 ) { diff --git a/src/object/object.h b/src/object/object.h index 9283c9bd..2be760ea 100644 --- a/src/object/object.h +++ b/src/object/object.h @@ -40,6 +40,7 @@ class CDisplayText; class CRobotMain; class CBotVar; class CScript; +class CLevelParserLine; /** @@ -379,7 +380,7 @@ public: void SetID(int id); int GetID(); - bool Write(char *line); + bool Write(CLevelParserLine* line); bool Read(char *line); void SetDrawWorld(bool bDraw); diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index 393f71dc..4a0780f8 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -3781,8 +3781,6 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) int rankGadget = 0; CObject* sel = 0; - SetNumericLocale(); - /* * NOTE: Moving frequently used lines to the top * may speed up loading @@ -4774,8 +4772,6 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) } m_dialog->SetSceneRead(""); m_dialog->SetStackRead(""); - - RestoreNumericLocale(); if(m_app->GetSceneTestMode()) m_eventQueue->AddEvent(Event(EVENT_WIN)); @@ -5665,37 +5661,17 @@ bool CRobotMain::IsBusy() } //! 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; - SetNumericLocale(); - - char line[3000]; - char name[100]; - - strcpy(line, cmd); - - sprintf(name, " type=%s", GetTypeObject(obj->GetType())); - strcat(line, name); - - sprintf(name, " id=%d", obj->GetID()); - strcat(line, name); + line->AddParam("type", new CLevelParserParam(obj->GetType())); + line->AddParam("id", new CLevelParserParam(obj->GetID())); + line->AddParam("pos", new CLevelParserParam(obj->GetPosition(0)/g_unit)); + line->AddParam("angle", new CLevelParserParam(obj->GetAngle(0)/(Math::PI/180.0f))); + line->AddParam("zoom", new CLevelParserParam(obj->GetZoom(0))); 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++) { if (obj->GetObjectRank(i) == -1) continue; @@ -5704,64 +5680,43 @@ void CRobotMain::IOWriteObject(FILE *file, CObject* obj, const char *cmd) if (pos.x != 0.0f || pos.y != 0.0f || pos.z != 0.0f) { pos /= g_unit; - sprintf(name, " p%d=%.2f;%.2f;%.2f", i, pos.x, pos.y, pos.z); - strcat(line, name); + line->AddParam("p"+boost::lexical_cast(i), new CLevelParserParam(pos)); } pos = obj->GetAngle(i); if (pos.x != 0.0f || pos.y != 0.0f || pos.z != 0.0f) { pos /= (Math::PI/180.0f); - sprintf(name, " a%d=%.2f;%.2f;%.2f", i, pos.x, pos.y, pos.z); - strcat(line, name); + line->AddParam("a"+boost::lexical_cast(i), new CLevelParserParam(pos)); } pos = obj->GetZoom(i); 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); - strcat(line, name); + line->AddParam("z"+boost::lexical_cast(i), new CLevelParserParam(pos)); } } - sprintf(name, " trainer=%d", obj->GetTrainer()); - strcat(line, name); + line->AddParam("trainer", new CLevelParserParam(obj->GetTrainer())); + 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); - - if (obj->GetType() == OBJECT_BASE) - { - sprintf(name, " run=3"); // stops and open (PARAM_FIXSCENE) - strcat(line, name); - } - + + if(obj->GetType() == OBJECT_BASE) + line->AddParam("run", new CLevelParserParam(3)); // stops and open (PARAM_FIXSCENE) + CBrain* brain = obj->GetBrain(); if (brain != nullptr) { int run = brain->GetProgram(); if (run != -1) { - sprintf(name, " run=%d", run+1); - strcat(line, name); + line->AddParam("run", new CLevelParserParam(run+1)); } } - - strcat(line, "\n"); - fputs(line, file); - - RestoreNumericLocale(); } //! Saves the current game @@ -5773,53 +5728,46 @@ bool CRobotMain::IOWriteScene(const char *filename, const char *filecbot, char * boost::replace_all(savedir, "\\", "/"); boost::replace_all(fnstr, savedir, ""); //TODO: Refactor to get physfs path here - /*CLevelParser* level = new CLevelParser(fnstr); - CLevelParserLine* line1 = new CLevelParserLine("TestCommand"); - line1->AddParam("test", new CLevelParserParam(1.0f)); - level->AddLine(line1); - CLevelParserLine* line2 = new CLevelParserLine("TestCommand2"); - line2->AddParam("testStr", new CLevelParserParam("12345")); - line2->AddParam("testBool", new CLevelParserParam(true)); - level->AddLine(line2); - level->Save(); - delete level; - return true;*/ + CLevelParser* level = new CLevelParser(fnstr); + CLevelParserLine* line; + + line = new CLevelParserLine("Title"); + line->AddParam("text", new CLevelParserParam(std::string(info))); + level->AddLine(line); - FILE* file = fopen(filename, "w"); - if (file == NULL) return false; - - SetNumericLocale(); - - char line[500]; - - sprintf(line, "Title text=\"%s\"\n", info); - fputs(line, file); - - sprintf(line, "Version maj=%d min=%d\n", 0, 1); - fputs(line, file); + //TODO: Do we need that? It's not used anyway + line = new CLevelParserLine("Version"); + line->AddParam("maj", new CLevelParserParam(0)); + line->AddParam("min", new CLevelParserParam(1)); + level->AddLine(line); 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 - { - sprintf(line, "Mission base=\"%s\" rank=%.3d\n", name, m_dialog->GetSceneRank()); - } - fputs(line, file); + level->AddLine(line); - sprintf(line, "Map zoom=%.2f\n", m_map->GetZoomMap()); - fputs(line, file); + line = new CLevelParserLine("Map"); + line->AddParam("zoom", new CLevelParserParam(m_map->GetZoomMap())); + level->AddLine(line); - sprintf(line, "DoneResearch bits=%d\n", static_cast(g_researchDone)); - fputs(line, file); + line = new CLevelParserLine("DoneResearch"); + line->AddParam("bits", new CLevelParserParam(static_cast(g_researchDone))); + level->AddLine(line); float 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); - fputs(line, file); + line = new CLevelParserLine("BlitzMode"); + 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(); @@ -5840,23 +5788,36 @@ bool CRobotMain::IOWriteScene(const char *filename, const char *filecbot, char * CObject* power = obj->GetPower(); CObject* fret = obj->GetFret(); - if (fret != nullptr) // object transported? - IOWriteObject(file, fret, "CreateFret"); + if (fret != nullptr){ // object transported? + line = new CLevelParserLine("CreateFret"); + IOWriteObject(line, fret); + level->AddLine(line); + } - if (power != nullptr) // battery transported? - IOWriteObject(file, power, "CreatePower"); - - IOWriteObject(file, obj, "CreateObject"); + if (power != nullptr) { // battery transported? + line = new CLevelParserLine("CreatePower"); + IOWriteObject(line, power); + level->AddLine(line); + } + + line = new CLevelParserLine("CreateObject"); + IOWriteObject(line, obj); + level->AddLine(line); SaveFileScript(obj, filename, objRank++); } - fclose(file); - - RestoreNumericLocale(); + try { + level->Save(); + } catch(CLevelParserException& e) { + CLogger::GetInstancePointer()->Error("Failed to save level state - %s\n", e.what()); + delete level; + return false; + } + delete level; #if CBOT_STACK // Writes the file of stacks of execution. - file = fOpen(filecbot, "wb"); + FILE* file = fOpen(filecbot, "wb"); if (file == NULL) return false; long version = 1; @@ -5898,8 +5859,6 @@ CObject* CRobotMain::IOReadObject(char *line, const char* filename, int objRank) if (type == OBJECT_NULL) return nullptr; - SetNumericLocale(); - int trainer = OpInt(line, "trainer", 0); int toy = OpInt(line, "toy", 0); int option = OpInt(line, "option", 0); @@ -5966,8 +5925,6 @@ CObject* CRobotMain::IOReadObject(char *line, const char* filename, int objRank) automat->Start(run); // starts the film } - RestoreNumericLocale(); - return obj; } @@ -5979,8 +5936,6 @@ CObject* CRobotMain::IOReadScene(const char *filename, const char *filecbot) FILE* file = fopen(filename, "r"); if (file == NULL) return 0; - SetNumericLocale(); - CObject* fret = nullptr; CObject* power = nullptr; CObject* sel = nullptr; @@ -6102,8 +6057,6 @@ CObject* CRobotMain::IOReadScene(const char *filename, const char *filecbot) } #endif - RestoreNumericLocale(); - return sel; } @@ -7004,20 +6957,6 @@ void CRobotMain::ClearInterface() 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) { m_displayText->DisplayError(err, pObj, time); diff --git a/src/object/robotmain.h b/src/object/robotmain.h index 9522c2b2..60eb6844 100644 --- a/src/object/robotmain.h +++ b/src/object/robotmain.h @@ -76,6 +76,7 @@ enum Phase class CEventQueue; class CSoundInterface; +class CLevelParserLine; namespace Gfx { class CEngine; @@ -383,14 +384,11 @@ public: bool IsBusy(); bool IOWriteScene(const char *filename, const char *filecbot, char *info); CObject* IOReadScene(const char *filename, const char *filecbot); - void IOWriteObject(FILE *file, CObject* pObj, const char *cmd); + void IOWriteObject(CLevelParserLine *file, CObject* pObj); CObject* IOReadObject(char *line, const char* filename, int objRank); int CreateSpot(Math::Vector pos, Gfx::Color color); - void SetNumericLocale(); - void RestoreNumericLocale(); - CObject* GetSelect(); void DisplayError(Error err, CObject* pObj, float time=10.0f); @@ -588,8 +586,6 @@ protected: Gfx::Color m_colorRefWater; Gfx::Color m_colorNewWater; float m_colorShiftWater; - - std::string m_oldLocale; bool m_missionTimerEnabled; bool m_missionTimerStarted; diff --git a/src/physics/physics.cpp b/src/physics/physics.cpp index 6dd9d321..d98334a4 100644 --- a/src/physics/physics.cpp +++ b/src/physics/physics.cpp @@ -40,6 +40,8 @@ #include "object/motion/motion.h" #include "object/motion/motionhuman.h" #include "object/task/task.h" +#include "object/level/parserline.h" +#include "object/level/parserparam.h" #include "script/cmdtoken.h" @@ -171,20 +173,14 @@ PhysicsType CPhysics::GetType() // Saves all parameters of the object. -bool CPhysics::Write(char *line) +bool CPhysics::Write(CLevelParserLine* line) { - char name[100]; - - sprintf(name, " motor=%.2f;%.2f;%.2f", m_motorSpeed.x, m_motorSpeed.y, m_motorSpeed.z); - strcat(line, name); + line->AddParam("motor", new CLevelParserParam(m_motorSpeed)); if ( m_type == TYPE_FLYING ) { - sprintf(name, " reactorRange=%.2f", GetReactorRange()); - strcat(line, name); - - sprintf(name, " land=%d", GetLand()); - strcat(line, name); + line->AddParam("reactorRange", new CLevelParserParam(GetReactorRange())); + line->AddParam("land", new CLevelParserParam(GetLand())); } return true; diff --git a/src/physics/physics.h b/src/physics/physics.h index ace5b58d..831bbfce 100644 --- a/src/physics/physics.h +++ b/src/physics/physics.h @@ -36,6 +36,7 @@ class CObject; class CBrain; class CMotion; class CSoundInterface; +class CLevelParserLine; namespace Gfx { class CCamera; @@ -110,7 +111,7 @@ public: void SetType(PhysicsType type); PhysicsType GetType(); - bool Write(char *line); + bool Write(CLevelParserLine* line); bool Read(char *line); void SetGravity(float value); diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index 0bb1e369..051d4212 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -6070,8 +6070,6 @@ void CMainDialog::WriteGamerPerso(char *gamer) file = fopen(filename, "w"); if ( file == NULL ) return; - 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); @@ -6083,8 +6081,6 @@ void CMainDialog::WriteGamerPerso(char *gamer) fputs(line, file); fclose(file); - - m_main->RestoreNumericLocale(); } // Reads the personalized player. @@ -6103,8 +6099,6 @@ void CMainDialog::ReadGamerPerso(char *gamer) file = fopen(filename, "r"); if ( file == NULL ) return; - m_main->SetNumericLocale(); - while ( fgets(line, 100, file) != NULL ) { if ( Cmd(line, "Head") ) @@ -6136,8 +6130,6 @@ void CMainDialog::ReadGamerPerso(char *gamer) } fclose(file); - - m_main->RestoreNumericLocale(); } // Specifies the face of the player.