From 02ffdcfe23239e401eb6e7b424be00fb279e15cc Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sun, 21 Jun 2015 20:59:23 +0200 Subject: [PATCH] Refactor level parser code * replace manual memory management with std::unique_ptr * remove unnecessary dynamic allocations * make coding style consistent --- src/object/auto/auto.cpp | 10 +- src/object/auto/autoconvert.cpp | 8 +- src/object/auto/autoderrick.cpp | 12 +- src/object/auto/autodestroyer.cpp | 10 +- src/object/auto/autoegg.cpp | 16 +- src/object/auto/autoenergy.cpp | 10 +- src/object/auto/autofactory.cpp | 10 +- src/object/auto/autoinfo.cpp | 10 +- src/object/auto/autojostle.h | 10 +- src/object/auto/autolabo.cpp | 12 +- src/object/auto/automush.cpp | 10 +- src/object/auto/autonest.cpp | 10 +- src/object/auto/autonuclear.cpp | 10 +- src/object/auto/autopara.cpp | 10 +- src/object/auto/autorepair.cpp | 10 +- src/object/auto/autoresearch.cpp | 12 +- src/object/auto/autosafe.cpp | 10 +- src/object/auto/autotower.cpp | 20 +- src/object/brain.cpp | 14 +- src/object/level/parser.cpp | 203 +++-- src/object/level/parser.h | 27 +- src/object/level/parserexceptions.cpp | 24 +- src/object/level/parserexceptions.h | 2 +- src/object/level/parserline.cpp | 39 +- src/object/level/parserline.h | 26 +- src/object/level/parserparam.cpp | 1199 +++++++++++++------------ src/object/level/parserparam.h | 51 +- src/object/motion/motion.cpp | 8 +- src/object/motion/motiontoto.cpp | 2 - src/object/object.cpp | 107 +-- src/object/robotmain.cpp | 831 +++++++++-------- src/object/task/taskgoto.cpp | 2 +- src/physics/physics.cpp | 6 +- src/ui/maindialog.cpp | 292 +++--- 34 files changed, 1579 insertions(+), 1454 deletions(-) diff --git a/src/object/auto/auto.cpp b/src/object/auto/auto.cpp index dd24855a..bb1cef0c 100644 --- a/src/object/auto/auto.cpp +++ b/src/object/auto/auto.cpp @@ -424,11 +424,11 @@ void CAuto::SetMotor(bool bMotor) bool CAuto::Write(CLevelParserLine* line) { - 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)); + line->AddParam("aType", CLevelParserParamUPtr{new CLevelParserParam(m_type)}); + line->AddParam("aBusy", CLevelParserParamUPtr{new CLevelParserParam(m_bBusy)}); + line->AddParam("aTime", CLevelParserParamUPtr{new CLevelParserParam(m_time)}); + line->AddParam("aProgressTime", CLevelParserParamUPtr{new CLevelParserParam(m_progressTime)}); + line->AddParam("aProgressTotal", CLevelParserParamUPtr{new CLevelParserParam(m_progressTotal)}); return false; } diff --git a/src/object/auto/autoconvert.cpp b/src/object/auto/autoconvert.cpp index 40a1d648..ec303a03 100644 --- a/src/object/auto/autoconvert.cpp +++ b/src/object/auto/autoconvert.cpp @@ -365,11 +365,11 @@ bool CAutoConvert::Write(CLevelParserLine* line) if ( m_phase == ACP_STOP || m_phase == ACP_WAIT ) return false; - line->AddParam("aExist", new CLevelParserParam(true)); + line->AddParam("aExist", CLevelParserParamUPtr{new CLevelParserParam(true)}); CAuto::Write(line); - 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("aPhase", CLevelParserParamUPtr{new CLevelParserParam(static_cast(m_phase))}); + line->AddParam("aProgress", CLevelParserParamUPtr{new CLevelParserParam(m_progress)}); + line->AddParam("aSpeed", CLevelParserParamUPtr{new CLevelParserParam(m_speed)}); return true; } diff --git a/src/object/auto/autoderrick.cpp b/src/object/auto/autoderrick.cpp index 76eabf9c..19113dfe 100644 --- a/src/object/auto/autoderrick.cpp +++ b/src/object/auto/autoderrick.cpp @@ -430,12 +430,12 @@ bool CAutoDerrick::CreateInterface(bool bSelect) bool CAutoDerrick::Write(CLevelParserLine* line) { if ( m_phase == ADP_WAIT ) return false; - - line->AddParam("aExist", new CLevelParserParam(true)); + + line->AddParam("aExist", CLevelParserParamUPtr{new CLevelParserParam(true)}); CAuto::Write(line); - 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("aPhase", CLevelParserParamUPtr{new CLevelParserParam(static_cast(m_phase))}); + line->AddParam("aProgress", CLevelParserParamUPtr{new CLevelParserParam(m_progress)}); + line->AddParam("aSpeed", CLevelParserParamUPtr{new CLevelParserParam(m_speed)}); return true; } @@ -524,7 +524,7 @@ bool CAutoDerrick::ExistKey() m_type != OBJECT_KEYb && m_type != OBJECT_KEYc && m_type != OBJECT_KEYd ) return false; - + return CObjectManager::GetInstancePointer()->FindNearest(nullptr, m_type) != nullptr; } diff --git a/src/object/auto/autodestroyer.cpp b/src/object/auto/autodestroyer.cpp index 27356a7a..24fc0664 100644 --- a/src/object/auto/autodestroyer.cpp +++ b/src/object/auto/autodestroyer.cpp @@ -353,12 +353,12 @@ Error CAutoDestroyer::GetError() bool CAutoDestroyer::Write(CLevelParserLine* line) { if ( m_phase == ADEP_WAIT ) return false; - - line->AddParam("aExist", new CLevelParserParam(true)); + + line->AddParam("aExist", CLevelParserParamUPtr{new CLevelParserParam(true)}); CAuto::Write(line); - 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("aPhase", CLevelParserParamUPtr{new CLevelParserParam(static_cast(m_phase))}); + line->AddParam("aProgress", CLevelParserParamUPtr{new CLevelParserParam(m_progress)}); + line->AddParam("aSpeed", CLevelParserParamUPtr{new CLevelParserParam(m_speed)}); return true; } diff --git a/src/object/auto/autoegg.cpp b/src/object/auto/autoegg.cpp index a3ce8d88..d9f57dbf 100644 --- a/src/object/auto/autoegg.cpp +++ b/src/object/auto/autoegg.cpp @@ -301,15 +301,15 @@ CObject* CAutoEgg::SearchAlien() bool CAutoEgg::Write(CLevelParserLine* line) { if ( m_phase == AEP_NULL ) return false; - - line->AddParam("aExist", new CLevelParserParam(true)); + + line->AddParam("aExist", CLevelParserParamUPtr{new CLevelParserParam(true)}); CAuto::Write(line); - 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(std::string(m_string))); + line->AddParam("aPhase", CLevelParserParamUPtr{new CLevelParserParam(static_cast(m_phase))}); + line->AddParam("aProgress", CLevelParserParamUPtr{new CLevelParserParam(m_progress)}); + line->AddParam("aSpeed", CLevelParserParamUPtr{new CLevelParserParam(m_speed)}); + line->AddParam("aParamType", CLevelParserParamUPtr{new CLevelParserParam(m_type)}); + line->AddParam("aParamValue1", CLevelParserParamUPtr{new CLevelParserParam(m_value)}); + line->AddParam("aParamString", CLevelParserParamUPtr{new CLevelParserParam(std::string(m_string))}); return true; } diff --git a/src/object/auto/autoenergy.cpp b/src/object/auto/autoenergy.cpp index 634c414f..317f29d6 100644 --- a/src/object/auto/autoenergy.cpp +++ b/src/object/auto/autoenergy.cpp @@ -585,12 +585,12 @@ bool CAutoEnergy::Write(CLevelParserLine* line) { if ( m_phase == AENP_STOP || m_phase == AENP_WAIT ) return false; - - line->AddParam("aExist", new CLevelParserParam(true)); + + line->AddParam("aExist", CLevelParserParamUPtr{new CLevelParserParam(true)}); CAuto::Write(line); - 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("aPhase", CLevelParserParamUPtr{new CLevelParserParam(static_cast(m_phase))}); + line->AddParam("aProgress", CLevelParserParamUPtr{new CLevelParserParam(m_progress)}); + line->AddParam("aSpeed", CLevelParserParamUPtr{new CLevelParserParam(m_speed)}); return true; } diff --git a/src/object/auto/autofactory.cpp b/src/object/auto/autofactory.cpp index 04e023ec..a09e25e9 100644 --- a/src/object/auto/autofactory.cpp +++ b/src/object/auto/autofactory.cpp @@ -515,12 +515,12 @@ bool CAutoFactory::EventProcess(const Event &event) bool CAutoFactory::Write(CLevelParserLine* line) { if ( m_phase == AFP_WAIT ) return false; - - line->AddParam("aExist", new CLevelParserParam(true)); + + line->AddParam("aExist", CLevelParserParamUPtr{new CLevelParserParam(true)}); CAuto::Write(line); - 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("aPhase", CLevelParserParamUPtr{new CLevelParserParam(static_cast(m_phase))}); + line->AddParam("aProgress", CLevelParserParamUPtr{new CLevelParserParam(m_progress)}); + line->AddParam("aSpeed", CLevelParserParamUPtr{new CLevelParserParam(m_speed)}); return true; } diff --git a/src/object/auto/autoinfo.cpp b/src/object/auto/autoinfo.cpp index e1da37a8..ccd1bc6e 100644 --- a/src/object/auto/autoinfo.cpp +++ b/src/object/auto/autoinfo.cpp @@ -483,12 +483,12 @@ void CAutoInfo::UpdateListVirus() bool CAutoInfo::Write(CLevelParserLine* line) { if ( m_phase == AIP_WAIT ) return false; - - line->AddParam("aExist", new CLevelParserParam(true)); + + line->AddParam("aExist", CLevelParserParamUPtr{new CLevelParserParam(true)}); CAuto::Write(line); - 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("aPhase", CLevelParserParamUPtr{new CLevelParserParam(static_cast(m_phase))}); + line->AddParam("aProgress", CLevelParserParamUPtr{new CLevelParserParam(m_progress)}); + line->AddParam("aSpeed", CLevelParserParamUPtr{new CLevelParserParam(m_speed)}); return true; } diff --git a/src/object/auto/autojostle.h b/src/object/auto/autojostle.h index 463a108c..932ccb79 100644 --- a/src/object/auto/autojostle.h +++ b/src/object/auto/autojostle.h @@ -32,16 +32,16 @@ public: CAutoJostle(CObject* object); ~CAutoJostle(); - void DeleteObject(bool bAll=false); + void DeleteObject(bool bAll=false) OVERRIDE; - void Init(); + void Init() OVERRIDE; void Start(int param, float force); - bool EventProcess(const Event &event); - Error IsEnded(); + bool EventProcess(const Event &event) OVERRIDE; + Error IsEnded() OVERRIDE; private: // Overriden to avoid warning about hiding virtual function - virtual void Start(int param) OVERRIDE; + void Start(int param) OVERRIDE; protected: float m_force; diff --git a/src/object/auto/autolabo.cpp b/src/object/auto/autolabo.cpp index a744b610..b8be8f82 100644 --- a/src/object/auto/autolabo.cpp +++ b/src/object/auto/autolabo.cpp @@ -591,13 +591,13 @@ void CAutoLabo::SoundManip(float time, float amplitude, float frequency) bool CAutoLabo::Write(CLevelParserLine* line) { if ( m_phase == ALAP_WAIT ) return false; - - line->AddParam("aExist", new CLevelParserParam(true)); + + line->AddParam("aExist", CLevelParserParamUPtr{new CLevelParserParam(true)}); CAuto::Write(line); - 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))); + line->AddParam("aPhase", CLevelParserParamUPtr{new CLevelParserParam(static_cast(m_phase))}); + line->AddParam("aProgress", CLevelParserParamUPtr{new CLevelParserParam(m_progress)}); + line->AddParam("aSpeed", CLevelParserParamUPtr{new CLevelParserParam(m_speed)}); + line->AddParam("aResearch", CLevelParserParamUPtr{new CLevelParserParam(static_cast(m_research))}); return true; } diff --git a/src/object/auto/automush.cpp b/src/object/auto/automush.cpp index cb73e704..c1a23446 100644 --- a/src/object/auto/automush.cpp +++ b/src/object/auto/automush.cpp @@ -297,12 +297,12 @@ Error CAutoMush::GetError() bool CAutoMush::Write(CLevelParserLine* line) { if ( m_phase == AMP_WAIT ) return false; - - line->AddParam("aExist", new CLevelParserParam(true)); + + line->AddParam("aExist", CLevelParserParamUPtr{new CLevelParserParam(true)}); CAuto::Write(line); - 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("aPhase", CLevelParserParamUPtr{new CLevelParserParam(static_cast(m_phase))}); + line->AddParam("aProgress", CLevelParserParamUPtr{new CLevelParserParam(m_progress)}); + line->AddParam("aSpeed", CLevelParserParamUPtr{new CLevelParserParam(m_speed)}); return true; } diff --git a/src/object/auto/autonest.cpp b/src/object/auto/autonest.cpp index f95e0fe8..d0ef8acb 100644 --- a/src/object/auto/autonest.cpp +++ b/src/object/auto/autonest.cpp @@ -212,12 +212,12 @@ Error CAutoNest::GetError() bool CAutoNest::Write(CLevelParserLine* line) { if ( m_phase == ANP_WAIT ) return false; - - line->AddParam("aExist", new CLevelParserParam(true)); + + line->AddParam("aExist", CLevelParserParamUPtr{new CLevelParserParam(true)}); CAuto::Write(line); - 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("aPhase", CLevelParserParamUPtr{new CLevelParserParam(static_cast(m_phase))}); + line->AddParam("aProgress", CLevelParserParamUPtr{new CLevelParserParam(m_progress)}); + line->AddParam("aSpeed", CLevelParserParamUPtr{new CLevelParserParam(m_speed)}); return true; } diff --git a/src/object/auto/autonuclear.cpp b/src/object/auto/autonuclear.cpp index c1444b97..97890b68 100644 --- a/src/object/auto/autonuclear.cpp +++ b/src/object/auto/autonuclear.cpp @@ -430,12 +430,12 @@ bool CAutoNuclear::Write(CLevelParserLine* line) { if ( m_phase == ANUP_STOP || m_phase == ANUP_WAIT ) return false; - - line->AddParam("aExist", new CLevelParserParam(true)); + + line->AddParam("aExist", CLevelParserParamUPtr{new CLevelParserParam(true)}); CAuto::Write(line); - 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("aPhase", CLevelParserParamUPtr{new CLevelParserParam(static_cast(m_phase))}); + line->AddParam("aProgress", CLevelParserParamUPtr{new CLevelParserParam(m_progress)}); + line->AddParam("aSpeed", CLevelParserParamUPtr{new CLevelParserParam(m_speed)}); return true; } diff --git a/src/object/auto/autopara.cpp b/src/object/auto/autopara.cpp index 61b324c6..5a76b98b 100644 --- a/src/object/auto/autopara.cpp +++ b/src/object/auto/autopara.cpp @@ -285,12 +285,12 @@ void CAutoPara::ChargeObject(float rTime) bool CAutoPara::Write(CLevelParserLine* line) { if ( m_phase == APAP_WAIT ) return false; - - line->AddParam("aExist", new CLevelParserParam(true)); + + line->AddParam("aExist", CLevelParserParamUPtr{new CLevelParserParam(true)}); CAuto::Write(line); - 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("aPhase", CLevelParserParamUPtr{new CLevelParserParam(static_cast(m_phase))}); + line->AddParam("aProgress", CLevelParserParamUPtr{new CLevelParserParam(m_progress)}); + line->AddParam("aSpeed", CLevelParserParamUPtr{new CLevelParserParam(m_speed)}); return true; } diff --git a/src/object/auto/autorepair.cpp b/src/object/auto/autorepair.cpp index 7002aec7..ec71d816 100644 --- a/src/object/auto/autorepair.cpp +++ b/src/object/auto/autorepair.cpp @@ -297,12 +297,12 @@ Error CAutoRepair::GetError() bool CAutoRepair::Write(CLevelParserLine* line) { if ( m_phase == ARP_WAIT ) return false; - - line->AddParam("aExist", new CLevelParserParam(true)); + + line->AddParam("aExist", CLevelParserParamUPtr{new CLevelParserParam(true)}); CAuto::Write(line); - 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("aPhase", CLevelParserParamUPtr{new CLevelParserParam(static_cast(m_phase))}); + line->AddParam("aProgress", CLevelParserParamUPtr{new CLevelParserParam(m_progress)}); + line->AddParam("aSpeed", CLevelParserParamUPtr{new CLevelParserParam(m_speed)}); return true; } diff --git a/src/object/auto/autoresearch.cpp b/src/object/auto/autoresearch.cpp index dc9e437b..6dd9ae91 100644 --- a/src/object/auto/autoresearch.cpp +++ b/src/object/auto/autoresearch.cpp @@ -568,13 +568,13 @@ void CAutoResearch::FireStopUpdate(float progress, bool bLightOn) bool CAutoResearch::Write(CLevelParserLine* line) { if ( m_phase == ALP_WAIT ) return false; - - line->AddParam("aExist", new CLevelParserParam(true)); + + line->AddParam("aExist", CLevelParserParamUPtr{new CLevelParserParam(true)}); CAuto::Write(line); - 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))); + line->AddParam("aPhase", CLevelParserParamUPtr{new CLevelParserParam(static_cast(m_phase))}); + line->AddParam("aProgress", CLevelParserParamUPtr{new CLevelParserParam(m_progress)}); + line->AddParam("aSpeed", CLevelParserParamUPtr{new CLevelParserParam(m_speed)}); + line->AddParam("aResearch", CLevelParserParamUPtr{new CLevelParserParam(static_cast(m_research))}); return true; } diff --git a/src/object/auto/autosafe.cpp b/src/object/auto/autosafe.cpp index 503ce767..f6437db6 100644 --- a/src/object/auto/autosafe.cpp +++ b/src/object/auto/autosafe.cpp @@ -354,12 +354,12 @@ Error CAutoSafe::GetError() bool CAutoSafe::Write(CLevelParserLine* line) { if ( m_phase == ASAP_WAIT ) return false; - - line->AddParam("aExist", new CLevelParserParam(true)); + + line->AddParam("aExist", CLevelParserParamUPtr{new CLevelParserParam(true)}); CAuto::Write(line); - 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("aPhase", CLevelParserParamUPtr{new CLevelParserParam(static_cast(m_phase))}); + line->AddParam("aProgress", CLevelParserParamUPtr{new CLevelParserParam(m_progress)}); + line->AddParam("aSpeed", CLevelParserParamUPtr{new CLevelParserParam(m_speed)}); return true; } diff --git a/src/object/auto/autotower.cpp b/src/object/auto/autotower.cpp index 6b8a47e9..a133e8eb 100644 --- a/src/object/auto/autotower.cpp +++ b/src/object/auto/autotower.cpp @@ -482,17 +482,17 @@ void CAutoTower::UpdateInterface(float rTime) bool CAutoTower::Write(CLevelParserLine* line) { if ( m_phase == ATP_WAIT ) return false; - - line->AddParam("aExist", new CLevelParserParam(true)); + + line->AddParam("aExist", CLevelParserParamUPtr{new CLevelParserParam(true)}); CAuto::Write(line); - 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)); + line->AddParam("aPhase", CLevelParserParamUPtr{new CLevelParserParam(static_cast(m_phase))}); + line->AddParam("aProgress", CLevelParserParamUPtr{new CLevelParserParam(m_progress)}); + line->AddParam("aSpeed", CLevelParserParamUPtr{new CLevelParserParam(m_speed)}); + line->AddParam("aTargetPos", CLevelParserParamUPtr{new CLevelParserParam(m_targetPos)}); + line->AddParam("aAngleYactual", CLevelParserParamUPtr{new CLevelParserParam(m_angleYactual)}); + line->AddParam("aAngleZactual", CLevelParserParamUPtr{new CLevelParserParam(m_angleZactual)}); + line->AddParam("aAngleYfinal", CLevelParserParamUPtr{new CLevelParserParam(m_angleYfinal)}); + line->AddParam("aAngleZfinal", CLevelParserParamUPtr{new CLevelParserParam(m_angleZfinal)}); return true; } diff --git a/src/object/brain.cpp b/src/object/brain.cpp index ef71e07e..f48d33ca 100644 --- a/src/object/brain.cpp +++ b/src/object/brain.cpp @@ -171,11 +171,11 @@ void CBrain::SetMotion(CMotion* motion) bool CBrain::Write(CLevelParserLine* line) { - line->AddParam("bVirusActive", new CLevelParserParam(m_bActiveVirus)); - + line->AddParam("bVirusActive", CLevelParserParamUPtr{new CLevelParserParam(m_bActiveVirus)}); + if ( m_object->GetType() == OBJECT_MOBILErs ) { - line->AddParam("bShieldActive", new CLevelParserParam(m_secondaryTask != nullptr)); + line->AddParam("bShieldActive", CLevelParserParamUPtr{new CLevelParserParam(m_secondaryTask != nullptr)}); } return true; @@ -736,11 +736,11 @@ bool CBrain::EventProcess(const Event &event) { err = StartTaskSearch(); } - + if ( action == EVENT_OBJECT_DELSEARCH ) - { - err = StartTaskDeleteMark(); - } + { + err = StartTaskDeleteMark(); + } if ( action == EVENT_OBJECT_TERRAFORM ) { diff --git a/src/object/level/parser.cpp b/src/object/level/parser.cpp index 5b36f467..78044bca 100644 --- a/src/object/level/parser.cpp +++ b/src/object/level/parser.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -54,19 +55,11 @@ CLevelParser::CLevelParser(std::string category, int chapter, int rank) m_filename = BuildScenePath(category, chapter, rank); } -CLevelParser::~CLevelParser() -{ - for(auto line : m_lines) - { - delete line; - } -} - std::string CLevelParser::BuildCategoryPath(std::string category) { std::ostringstream outstream; outstream << "levels/"; - if(category == "perso" || category == "win" || category == "lost") + if (category == "perso" || category == "win" || category == "lost") { outstream << "other/"; } @@ -81,12 +74,12 @@ std::string CLevelParser::BuildScenePath(std::string category, int chapter, int { std::ostringstream outstream; outstream << BuildCategoryPath(category); - if(category == "custom") + if (category == "custom") { outstream << CRobotMain::GetInstancePointer()->GetUserLevelName(chapter); - if(rank == 000) + if (rank == 000) { - if(sceneFile) + if (sceneFile) { outstream << "/chaptertitle.txt"; } @@ -94,26 +87,26 @@ std::string CLevelParser::BuildScenePath(std::string category, int chapter, int else { outstream << "/level" << std::setfill('0') << std::setw(3) << rank; - if(sceneFile) + if (sceneFile) { outstream << "/scene.txt"; } } } - else if(category == "perso") + else if (category == "perso") { outstream << "perso.txt"; } - else if(category == "win" || category == "lost") + else if (category == "win" || category == "lost") { - outstream << category << std::setfill('0') << std::setw(3) << chapter*100+rank << ".txt"; + outstream << category << std::setfill('0') << std::setw(3) << chapter*100 + rank << ".txt"; } else { outstream << "chapter" << std::setfill('0') << std::setw(3) << chapter; - if(rank == 000) + if (rank == 000) { - if(sceneFile) + if (sceneFile) { outstream << "/chaptertitle.txt"; } @@ -121,7 +114,7 @@ std::string CLevelParser::BuildScenePath(std::string category, int chapter, int else { outstream << "/level" << std::setfill('0') << std::setw(3) << rank; - if(sceneFile) + if (sceneFile) { outstream << "/scene.txt"; } @@ -139,97 +132,124 @@ void CLevelParser::Load() { CInputStream file; file.open(m_filename); - if(!file.is_open()) - throw CLevelParserException("Failed to open file: "+m_filename); - + if (!file.is_open()) + throw CLevelParserException("Failed to open file: " + m_filename); + char lang = CApplication::GetInstancePointer()->GetLanguageChar(); - + std::string line; int lineNumber = 0; - std::map translatableLines; - while(getline(file,line)) + std::set translatableLines; + while (getline(file, line)) { lineNumber++; - + boost::replace_all(line, "\t", " "); // replace tab by space - + // ignore comments std::size_t comment = line.find("//"); - if(comment != std::string::npos) + if (comment != std::string::npos) line = line.substr(0, comment); - + boost::algorithm::trim(line); - + std::size_t pos = line.find_first_of(" \t\n"); std::string command = line.substr(0, pos); - if(pos != std::string::npos) { - line = line.substr(pos+1); + if (pos != std::string::npos) + { + line = line.substr(pos + 1); boost::algorithm::trim(line); - } else { + } + else + { line = ""; } - if(command.empty()) continue; - - CLevelParserLine* parserLine = new CLevelParserLine(lineNumber, command); - - std::string baseCommand = command; - if(command[command.length()-2] == '.') { - baseCommand = command.substr(0, command.length()-2); - if(command[command.length()-1] == 'E' && translatableLines[baseCommand] == nullptr) { - parserLine->SetCommand(baseCommand); - translatableLines[baseCommand] = parserLine; - } else if(command[command.length()-1] == lang) { - if(translatableLines[baseCommand] != nullptr) { - m_lines.erase(std::remove(m_lines.begin(), m_lines.end(), translatableLines[baseCommand]), m_lines.end()); - delete translatableLines[baseCommand]; + + if (command.empty()) + continue; + + CLevelParserLineUPtr parserLine{new CLevelParserLine(lineNumber, command)}; + + if (command.length() > 2 && command[command.length() - 2] == '.') + { + std::string baseCommand = command.substr(0, command.length() - 2); + parserLine->SetCommand(baseCommand); + + char languageChar = command[command.length() - 1]; + if (languageChar == 'E' && translatableLines.count(baseCommand) == 0) + { + translatableLines.insert(baseCommand); + } + else if (languageChar == lang) + { + if (translatableLines.count(baseCommand) > 0) + { + auto it = std::remove_if( + m_lines.begin(), + m_lines.end(), + [&baseCommand](const CLevelParserLineUPtr& line) + { + return line->GetCommand() == baseCommand; + }); + m_lines.erase(it, m_lines.end()); } - parserLine->SetCommand(baseCommand); - translatableLines[baseCommand] = parserLine; - } else { - delete parserLine; + + translatableLines.insert(baseCommand); + } + else + { continue; } } - - while(!line.empty()) { + + while (!line.empty()) + { pos = line.find_first_of("="); std::string paramName = line.substr(0, pos); boost::algorithm::trim(paramName); - line = line.substr(pos+1); + line = line.substr(pos + 1); boost::algorithm::trim(line); - - if(line[0] == '\"') { + + if (line[0] == '\"') + { pos = line.find_first_of("\"", 1); - if(pos == std::string::npos) - throw CLevelParserException("Unclosed \" in "+m_filename+":"+boost::lexical_cast(lineNumber)); - } else if(line[0] == '\'') { + if (pos == std::string::npos) + throw CLevelParserException("Unclosed \" in " + m_filename + ":" + boost::lexical_cast(lineNumber)); + } + else if (line[0] == '\'') + { pos = line.find_first_of("'", 1); - if(pos == std::string::npos) - throw CLevelParserException("Unclosed ' in "+m_filename+":"+boost::lexical_cast(lineNumber)); - } else { + if (pos == std::string::npos) + throw CLevelParserException("Unclosed ' in " + m_filename + ":" + boost::lexical_cast(lineNumber)); + } + else + { pos = line.find_first_of("="); - if(pos != std::string::npos) { + if (pos != std::string::npos) + { std::size_t pos2 = line.find_last_of(" \t\n", line.find_last_not_of(" \t\n", pos-1)); - if(pos2 != std::string::npos) + if (pos2 != std::string::npos) pos = pos2; - } else { + } + else + { pos = line.length()-1; } } - std::string paramValue = line.substr(0, pos+1); + std::string paramValue = line.substr(0, pos + 1); boost::algorithm::trim(paramValue); - - parserLine->AddParam(paramName, new CLevelParserParam(paramName, paramValue)); - - if(pos == std::string::npos) + + parserLine->AddParam(paramName, CLevelParserParamUPtr{new CLevelParserParam(paramName, paramValue)}); + + if (pos == std::string::npos) break; - line = line.substr(pos+1); + line = line.substr(pos + 1); boost::algorithm::trim(line); } - - AddLine(parserLine); + + AddLine(std::move(parserLine)); } - + file.close(); } @@ -237,17 +257,14 @@ void CLevelParser::Save() { 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"; + if (!file.is_open()) + throw CLevelParserException("Failed to open file: " + m_filename); + + for (auto& line : m_lines) + { + file << line.get() << "\n"; } - + file.close(); } @@ -256,22 +273,18 @@ const std::string& CLevelParser::GetFilename() return m_filename; } -std::vector CLevelParser::GetLines() -{ - return m_lines; -} - -void CLevelParser::AddLine(CLevelParserLine* line) +void CLevelParser::AddLine(CLevelParserLineUPtr line) { line->SetLevel(this); - m_lines.push_back(line); + m_lines.push_back(std::move(line)); } CLevelParserLine* CLevelParser::Get(std::string command) { - for(auto& line : m_lines) { - if(line->GetCommand() == command) - return line; + for (auto& line : m_lines) + { + if (line->GetCommand() == command) + return line.get(); } - throw CLevelParserException("Command not found: "+command); + throw CLevelParserException("Command not found: " + command); } diff --git a/src/object/level/parser.h b/src/object/level/parser.h index fc3b99f4..16b10efe 100644 --- a/src/object/level/parser.h +++ b/src/object/level/parser.h @@ -30,6 +30,7 @@ #include #include +#include class CLevelParser { @@ -40,33 +41,35 @@ public: CLevelParser(std::string filename); //! Load given level CLevelParser(std::string category, int chapter, int rank); - - ~CLevelParser(); - + //! Build category path static std::string BuildCategoryPath(std::string category); //! Build level filename static std::string BuildScenePath(std::string category, int chapter, int rank, bool sceneFile = true); - + //! Check if level file exists bool Exists(); //! Load file void Load(); //! Save file void Save(); - + //! Get filename const std::string& GetFilename(); - + //! Get all lines from file - std::vector GetLines(); + inline const std::vector& GetLines() + { + return m_lines; + } + //! Insert new line to file - void AddLine(CLevelParserLine* line); - + void AddLine(CLevelParserLineUPtr line); + //! Find first line with given command CLevelParserLine* Get(std::string command); - + private: std::string m_filename; - std::vector m_lines; -}; \ No newline at end of file + std::vector m_lines; +}; diff --git a/src/object/level/parserexceptions.cpp b/src/object/level/parserexceptions.cpp index 4473ea57..2747f0db 100644 --- a/src/object/level/parserexceptions.cpp +++ b/src/object/level/parserexceptions.cpp @@ -19,14 +19,13 @@ #include "object/level/parserexceptions.h" - #include "object/level/parser.h" #include CLevelParserException::CLevelParserException(std::string message) NOEXCEPT + : m_message(message) { - m_message = message; } const char* CLevelParserException::what() const NOEXCEPT @@ -34,12 +33,29 @@ const char* CLevelParserException::what() const NOEXCEPT return m_message.c_str(); } +std::string formatMissingParamError(CLevelParserParam* thisParam) NOEXCEPT +{ + auto paramName = thisParam->GetName(); + auto lineNumber = boost::lexical_cast(thisParam->GetLine()->GetLineNumber()); + auto fileName = thisParam->GetLine()->GetLevel()->GetFilename(); + return "Missing required param '" + paramName + "' (in " + fileName + ":" + lineNumber + ")"; +} + CLevelParserExceptionMissingParam::CLevelParserExceptionMissingParam(CLevelParserParam* thisParam) NOEXCEPT -: CLevelParserException("Missing required param "+thisParam->GetName()+" (in "+thisParam->GetLine()->GetLevel()->GetFilename()+":"+boost::lexical_cast(thisParam->GetLine()->GetLineNumber())+")") +: CLevelParserException(formatMissingParamError(thisParam)) { } +std::string formatBadParamError(CLevelParserParam* thisParam, std::string requestedType) NOEXCEPT +{ + auto paramName = thisParam->GetName(); + auto paramValue = thisParam->GetValue(); + auto lineNumber = boost::lexical_cast(thisParam->GetLine()->GetLineNumber()); + auto fileName = thisParam->GetLine()->GetLevel()->GetFilename(); + return "Unable to parse '" + paramValue + "' as " + requestedType + " (param '" + paramName + "' in " + fileName + ":" + lineNumber + ")"; +} + CLevelParserExceptionBadParam::CLevelParserExceptionBadParam(CLevelParserParam* thisParam, std::string requestedType) NOEXCEPT -: CLevelParserException("Unable to parse '"+thisParam->GetValue()+"' as "+requestedType+" (param '"+thisParam->GetName()+"' in "+thisParam->GetLine()->GetLevel()->GetFilename()+":"+boost::lexical_cast(thisParam->GetLine()->GetLineNumber())+")") +: CLevelParserException(formatBadParamError(thisParam, requestedType)) { } diff --git a/src/object/level/parserexceptions.h b/src/object/level/parserexceptions.h index abcfef06..ddb82935 100644 --- a/src/object/level/parserexceptions.h +++ b/src/object/level/parserexceptions.h @@ -52,4 +52,4 @@ class CLevelParserExceptionBadParam : public CLevelParserException public: CLevelParserExceptionBadParam(CLevelParserParam* thisParam, std::string requestedType) NOEXCEPT; virtual ~CLevelParserExceptionBadParam() NOEXCEPT {} -}; \ No newline at end of file +}; diff --git a/src/object/level/parserline.cpp b/src/object/level/parserline.cpp index c838b350..aa34b95d 100644 --- a/src/object/level/parserline.cpp +++ b/src/object/level/parserline.cpp @@ -19,7 +19,6 @@ #include "object/level/parserline.h" - #include "object/level/parser.h" #include "common/logger.h" @@ -35,14 +34,6 @@ CLevelParserLine::CLevelParserLine(int lineNumber, std::string command) m_lineNumber = lineNumber; } -CLevelParserLine::~CLevelParserLine() -{ - for(auto param : m_params) - { - delete param.second; - } -} - int CLevelParserLine::GetLineNumber() { return m_lineNumber; @@ -70,21 +61,31 @@ void CLevelParserLine::SetCommand(std::string command) CLevelParserParam* CLevelParserLine::GetParam(std::string name) { - if(m_params[name] == nullptr) { - CLevelParserParam* param = new CLevelParserParam(name, true); - param->SetLine(this); - m_params[name] = param; + auto it = m_params.find(name); + if (it != m_params.end()) + { + return it->second.get(); } - return m_params[name]; + + CLevelParserParamUPtr paramUPtr(new CLevelParserParam(name, true)); + paramUPtr->SetLine(this); + CLevelParserParam* paramPtr = paramUPtr.get(); + m_params.insert(std::make_pair(name, std::move(paramUPtr))); + return paramPtr; } -void CLevelParserLine::AddParam(std::string name, CLevelParserParam* value) +void CLevelParserLine::AddParam(std::string name, CLevelParserParamUPtr value) { value->SetLine(this); - m_params[name] = value; + m_params.insert(std::make_pair(name, std::move(value))); } -const std::map& CLevelParserLine::GetParams() +std::ostream& operator<<(std::ostream& str, const CLevelParserLine& line) { - return m_params; -} \ No newline at end of file + str << line.m_command; + for (const auto& param : line.m_params) + { + str << " " << param.first << "=" << param.second->GetValue(); + } + return str; +} diff --git a/src/object/level/parserline.h b/src/object/level/parserline.h index 0af0f066..c5cadc0c 100644 --- a/src/object/level/parserline.h +++ b/src/object/level/parserline.h @@ -24,37 +24,41 @@ #pragma once +#include "object/level/parserparam.h" + #include #include +#include class CLevelParser; -class CLevelParserParam; +class CLevelParserLine; +using CLevelParserLineUPtr = std::unique_ptr; class CLevelParserLine { public: CLevelParserLine(int lineNumber, std::string command); CLevelParserLine(std::string command); - ~CLevelParserLine(); - + //! Get line number int GetLineNumber(); - + //! Get CLevelParser this line is part of CLevelParser* GetLevel(); //! Set CLevelParser this line is part of void SetLevel(CLevelParser* level); - + std::string GetCommand(); void SetCommand(std::string command); - + CLevelParserParam* GetParam(std::string name); - void AddParam(std::string name, CLevelParserParam* value); - const std::map& GetParams(); - + void AddParam(std::string name, CLevelParserParamUPtr value); + + friend std::ostream& operator<<(std::ostream& str, const CLevelParserLine& line); + private: CLevelParser* m_level; int m_lineNumber; std::string m_command; - std::map m_params; -}; \ No newline at end of file + std::map m_params; +}; diff --git a/src/object/level/parserparam.cpp b/src/object/level/parserparam.cpp index 8d4adfc5..58c1c98e 100644 --- a/src/object/level/parserparam.cpp +++ b/src/object/level/parserparam.cpp @@ -19,11 +19,12 @@ #include "object/level/parserline.h" - #include "app/app.h" + #include "common/logger.h" #include "common/pathman.h" #include "common/resources/resourcemanager.h" + #include "object/level/parser.h" #include "object/robotmain.h" @@ -31,24 +32,73 @@ #include CLevelParserParam::CLevelParserParam(std::string name, std::string value) -{ - m_name = name; - m_value = value; - m_empty = false; -} + : m_name(name) + , m_value(value) +{} CLevelParserParam::CLevelParserParam(std::string name, bool empty) + : m_empty(empty) + , m_name(name) { assert(empty == true); // we need a second argument because we don't want to create param with value "name" - m_name = name; - m_value = ""; - m_empty = true; } -CLevelParserParam::~CLevelParserParam() +CLevelParserParam::CLevelParserParam(int value) + : m_value(boost::lexical_cast(value)) +{} + +CLevelParserParam::CLevelParserParam(float value) + : m_value(boost::lexical_cast(value)) +{} + +CLevelParserParam::CLevelParserParam(std::string value) + : m_value("\""+value+"\"") +{} + +CLevelParserParam::CLevelParserParam(bool value) + : m_value(value ? "1" : "0") +{} + +CLevelParserParam::CLevelParserParam(Gfx::Color value) { - for(auto& a : m_array) - delete a; + m_array.push_back(CLevelParserParamUPtr{new CLevelParserParam(value.r)}); + m_array.push_back(CLevelParserParamUPtr{new CLevelParserParam(value.g)}); + m_array.push_back(CLevelParserParamUPtr{new CLevelParserParam(value.b)}); + m_array.push_back(CLevelParserParamUPtr{new CLevelParserParam(value.a)}); + + LoadArray(); +} + +CLevelParserParam::CLevelParserParam(Math::Point value) +{ + m_array.push_back(CLevelParserParamUPtr{new CLevelParserParam(value.x)}); + m_array.push_back(CLevelParserParamUPtr{new CLevelParserParam(value.y)}); + + LoadArray(); +} + +CLevelParserParam::CLevelParserParam(Math::Vector value) +{ + m_array.push_back(CLevelParserParamUPtr{new CLevelParserParam(value.x)}); + m_array.push_back(CLevelParserParamUPtr{new CLevelParserParam(value.y)}); + m_array.push_back(CLevelParserParamUPtr{new CLevelParserParam(value.z)}); + + LoadArray(); +} + +CLevelParserParam::CLevelParserParam(ObjectType value) + : m_value(FromObjectType(value)) +{} + +CLevelParserParam::CLevelParserParam(Gfx::CameraType value) + : m_value(FromCameraType(value)) +{} + +CLevelParserParam::CLevelParserParam(CLevelParserParamVec&& array) +{ + m_array.swap(array); + + LoadArray(); } void CLevelParserParam::SetLine(CLevelParserLine* line) @@ -79,7 +129,8 @@ bool CLevelParserParam::IsDefined() template T CLevelParserParam::Cast(std::string value, std::string requestedType) { - try { + try + { return boost::lexical_cast(value); } catch(...) @@ -97,7 +148,7 @@ T CLevelParserParam::Cast(std::string requestedType) int CLevelParserParam::AsInt() { - if(m_empty) + if (m_empty) throw CLevelParserExceptionMissingParam(this); return Cast("int"); } @@ -105,7 +156,7 @@ int CLevelParserParam::AsInt() int CLevelParserParam::AsInt(int def) { - if(m_empty) + if (m_empty) return def; return AsInt(); } @@ -113,14 +164,14 @@ int CLevelParserParam::AsInt(int def) float CLevelParserParam::AsFloat() { - if(m_empty) + if (m_empty) throw CLevelParserExceptionMissingParam(this); return Cast("float"); } float CLevelParserParam::AsFloat(float def) { - if(m_empty) + if (m_empty) return def; return AsFloat(); } @@ -128,19 +179,21 @@ float CLevelParserParam::AsFloat(float def) std::string CLevelParserParam::AsString() { - if(m_empty) + if (m_empty) throw CLevelParserExceptionMissingParam(this); - if((m_value[0] == '\"' && m_value[m_value.length()-1] == '\"') || (m_value[0] == '\'' && m_value[m_value.length()-1] == '\'')) + if ((m_value[0] == '\"' && m_value[m_value.length()-1] == '\"') || (m_value[0] == '\'' && m_value[m_value.length()-1] == '\'')) { return m_value.substr(1, m_value.length()-2); - } else { + } + else + { throw CLevelParserExceptionBadParam(this, "string"); } } std::string CLevelParserParam::AsString(std::string def) { - if(m_empty) + if (m_empty) return def; return AsString(); } @@ -148,18 +201,18 @@ std::string CLevelParserParam::AsString(std::string def) bool CLevelParserParam::AsBool() { - if(m_empty) + if (m_empty) throw CLevelParserExceptionMissingParam(this); std::string value = m_value; boost::to_lower(value); - if(value == "true") return true; - if(value == "false") return false; + if (value == "true") return true; + if (value == "false") return false; return Cast("bool"); } bool CLevelParserParam::AsBool(bool def) { - if(m_empty) + if (m_empty) return def; return AsBool(); } @@ -167,48 +220,51 @@ bool CLevelParserParam::AsBool(bool def) std::string CLevelParserParam::ToPath(std::string path, const std::string defaultDir) { - if(defaultDir == "" && path.find("%lvl%") != std::string::npos) + if (defaultDir == "" && path.find("%lvl%") != std::string::npos) throw CLevelParserException("TODO: Param "+m_name+" does not yet support %lvl%! :("); - + return CPathManager::InjectLevelDir(path, defaultDir); } std::string CLevelParserParam::AsPath(const std::string defaultDir) { - if(m_empty) + if (m_empty) throw CLevelParserExceptionMissingParam(this); - + return ToPath(AsString(), defaultDir); } std::string CLevelParserParam::AsPath(const std::string defaultDir, std::string def) { - if(m_empty) + if (m_empty) return CPathManager::InjectLevelDir(def, defaultDir); - + return ToPath(AsString(def), defaultDir); } Gfx::Color CLevelParserParam::AsColor() { - if(m_empty) + if (m_empty) throw CLevelParserExceptionMissingParam(this); - + ParseArray(); - - if(m_array.size() == 3) { //RGB + + if (m_array.size() == 3) { //RGB return Gfx::Color(m_array[0]->AsFloat(), m_array[1]->AsFloat(), m_array[2]->AsFloat()); - } else if(m_array.size() == 4) { //RGBA + } + else if (m_array.size() == 4) { //RGBA return Gfx::Color(m_array[0]->AsFloat(), m_array[1]->AsFloat(), m_array[2]->AsFloat(), m_array[3]->AsFloat()); - } else { + } + else + { throw CLevelParserExceptionBadParam(this, "color"); } } Gfx::Color CLevelParserParam::AsColor(Gfx::Color def) { - if(m_empty) + if (m_empty) return def; return AsColor(); } @@ -216,23 +272,26 @@ Gfx::Color CLevelParserParam::AsColor(Gfx::Color def) Math::Vector CLevelParserParam::AsPoint() { - if(m_empty) + if (m_empty) throw CLevelParserExceptionMissingParam(this); - + ParseArray(); - - if(m_array.size() == 2) { //XZ + + if (m_array.size() == 2) { //XZ return Math::Vector(m_array[0]->AsFloat(), 0.0f, m_array[1]->AsFloat()); - } else if(m_array.size() == 3) { //XYZ + } + else if (m_array.size() == 3) { //XYZ return Math::Vector(m_array[0]->AsFloat(), m_array[1]->AsFloat(), m_array[2]->AsFloat()); - } else { + } + else + { throw CLevelParserExceptionBadParam(this, "point"); } } Math::Vector CLevelParserParam::AsPoint(Math::Vector def) { - if(m_empty) + if (m_empty) return def; return AsPoint(); } @@ -240,419 +299,419 @@ Math::Vector CLevelParserParam::AsPoint(Math::Vector def) ObjectType CLevelParserParam::ToObjectType(std::string value) { - if(value == "All" ) return OBJECT_NULL; - if(value == "Portico" ) return OBJECT_PORTICO; - if(value == "SpaceShip" ) return OBJECT_BASE; - if(value == "PracticeBot" ) return OBJECT_MOBILEwt; - if(value == "WingedGrabber" ) return OBJECT_MOBILEfa; - if(value == "TrackedGrabber" ) return OBJECT_MOBILEta; - if(value == "WheeledGrabber" ) return OBJECT_MOBILEwa; - if(value == "LeggedGrabber" ) return OBJECT_MOBILEia; - if(value == "WingedShooter" ) return OBJECT_MOBILEfc; - if(value == "TrackedShooter" ) return OBJECT_MOBILEtc; - if(value == "WheeledShooter" ) return OBJECT_MOBILEwc; - if(value == "LeggedShooter" ) return OBJECT_MOBILEic; - if(value == "WingedOrgaShooter" ) return OBJECT_MOBILEfi; - if(value == "TrackedOrgaShooter") return OBJECT_MOBILEti; - if(value == "WheeledOrgaShooter") return OBJECT_MOBILEwi; - if(value == "LeggedOrgaShooter" ) return OBJECT_MOBILEii; - if(value == "WingedSniffer" ) return OBJECT_MOBILEfs; - if(value == "TrackedSniffer" ) return OBJECT_MOBILEts; - if(value == "WheeledSniffer" ) return OBJECT_MOBILEws; - if(value == "LeggedSniffer" ) return OBJECT_MOBILEis; - if(value == "Thumper" ) return OBJECT_MOBILErt; - if(value == "PhazerShooter" ) return OBJECT_MOBILErc; - if(value == "Recycler" ) return OBJECT_MOBILErr; - if(value == "Shielder" ) return OBJECT_MOBILErs; - if(value == "Subber" ) return OBJECT_MOBILEsa; - if(value == "TargetBot" ) return OBJECT_MOBILEtg; - if(value == "Scribbler" ) return OBJECT_MOBILEdr; - if(value == "PowerSpot" ) return OBJECT_MARKPOWER; - if(value == "TitaniumSpot" ) return OBJECT_MARKSTONE; - if(value == "UraniumSpot" ) return OBJECT_MARKURANIUM; - if(value == "PlatinumSpot" ) return OBJECT_MARKURANIUM; - if(value == "KeyASpot" ) return OBJECT_MARKKEYa; - if(value == "KeyBSpot" ) return OBJECT_MARKKEYb; - if(value == "KeyCSpot" ) return OBJECT_MARKKEYc; - if(value == "KeyDSpot" ) return OBJECT_MARKKEYd; - if(value == "WayPoint" ) return OBJECT_WAYPOINT; - if(value == "BlueFlag" ) return OBJECT_FLAGb; - if(value == "RedFlag" ) return OBJECT_FLAGr; - if(value == "GreenFlag" ) return OBJECT_FLAGg; - if(value == "YellowFlag" ) return OBJECT_FLAGy; - if(value == "VioletFlag" ) return OBJECT_FLAGv; - if(value == "PowerCell" ) return OBJECT_POWER; - if(value == "FuelCellPlant" ) return OBJECT_NUCLEAR; - if(value == "FuelCell" ) return OBJECT_ATOMIC; - if(value == "NuclearCell" ) return OBJECT_ATOMIC; - if(value == "TitaniumOre" ) return OBJECT_STONE; - if(value == "UraniumOre" ) return OBJECT_URANIUM; - if(value == "PlatinumOre" ) return OBJECT_URANIUM; - if(value == "Titanium" ) return OBJECT_METAL; - if(value == "OrgaMatter" ) return OBJECT_BULLET; - if(value == "BlackBox" ) return OBJECT_BBOX; - if(value == "KeyA" ) return OBJECT_KEYa; - if(value == "KeyB" ) return OBJECT_KEYb; - if(value == "KeyC" ) return OBJECT_KEYc; - if(value == "KeyD" ) return OBJECT_KEYd; - if(value == "TNT" ) return OBJECT_TNT; - if(value == "Scrap1" ) return OBJECT_SCRAP1; - if(value == "Scrap2" ) return OBJECT_SCRAP2; - if(value == "Scrap3" ) return OBJECT_SCRAP3; - if(value == "Scrap4" ) return OBJECT_SCRAP4; - if(value == "Scrap5" ) return OBJECT_SCRAP5; - if(value == "Mine" ) return OBJECT_BOMB; - if(value == "Firework" ) return OBJECT_WINFIRE; - if(value == "Bag" ) return OBJECT_BAG; - if(value == "Greenery0" ) return OBJECT_PLANT0; - if(value == "Greenery1" ) return OBJECT_PLANT1; - if(value == "Greenery2" ) return OBJECT_PLANT2; - if(value == "Greenery3" ) return OBJECT_PLANT3; - if(value == "Greenery4" ) return OBJECT_PLANT4; - if(value == "Greenery5" ) return OBJECT_PLANT5; - if(value == "Greenery6" ) return OBJECT_PLANT6; - if(value == "Greenery7" ) return OBJECT_PLANT7; - if(value == "Greenery8" ) return OBJECT_PLANT8; - if(value == "Greenery9" ) return OBJECT_PLANT9; - if(value == "Greenery10" ) return OBJECT_PLANT10; - if(value == "Greenery11" ) return OBJECT_PLANT11; - if(value == "Greenery12" ) return OBJECT_PLANT12; - if(value == "Greenery13" ) return OBJECT_PLANT13; - if(value == "Greenery14" ) return OBJECT_PLANT14; - if(value == "Greenery15" ) return OBJECT_PLANT15; - if(value == "Greenery16" ) return OBJECT_PLANT16; - if(value == "Greenery17" ) return OBJECT_PLANT17; - if(value == "Greenery18" ) return OBJECT_PLANT18; - if(value == "Greenery19" ) return OBJECT_PLANT19; - if(value == "Tree0" ) return OBJECT_TREE0; - if(value == "Tree1" ) return OBJECT_TREE1; - if(value == "Tree2" ) return OBJECT_TREE2; - if(value == "Tree3" ) return OBJECT_TREE3; - if(value == "Tree4" ) return OBJECT_TREE4; - if(value == "Tree5" ) return OBJECT_TREE5; - if(value == "Mushroom1" ) return OBJECT_MUSHROOM1; - if(value == "Mushroom2" ) return OBJECT_MUSHROOM2; - if(value == "Home" ) return OBJECT_HOME1; - if(value == "Derrick" ) return OBJECT_DERRICK; - if(value == "BotFactory" ) return OBJECT_FACTORY; - if(value == "PowerStation" ) return OBJECT_STATION; - if(value == "Converter" ) return OBJECT_CONVERT; - if(value == "RepairCenter" ) return OBJECT_REPAIR; - if(value == "Destroyer" ) return OBJECT_DESTROYER; - if(value == "DefenseTower" ) return OBJECT_TOWER; - if(value == "AlienNest" ) return OBJECT_NEST; - if(value == "ResearchCenter" ) return OBJECT_RESEARCH; - if(value == "RadarStation" ) return OBJECT_RADAR; - if(value == "ExchangePost" ) return OBJECT_INFO; - if(value == "PowerPlant" ) return OBJECT_ENERGY; - if(value == "AutoLab" ) return OBJECT_LABO; - if(value == "NuclearPlant" ) return OBJECT_NUCLEAR; - if(value == "PowerCaptor" ) return OBJECT_PARA; - if(value == "Vault" ) return OBJECT_SAFE; - if(value == "Houston" ) return OBJECT_HUSTON; - if(value == "Target1" ) return OBJECT_TARGET1; - if(value == "Target2" ) return OBJECT_TARGET2; - if(value == "StartArea" ) return OBJECT_START; - if(value == "GoalArea" ) return OBJECT_END; - if(value == "AlienQueen" ) return OBJECT_MOTHER; - if(value == "AlienEgg" ) return OBJECT_EGG; - if(value == "AlienAnt" ) return OBJECT_ANT; - if(value == "AlienSpider" ) return OBJECT_SPIDER; - if(value == "AlienWasp" ) return OBJECT_BEE; - if(value == "AlienWorm" ) return OBJECT_WORM; - if(value == "WreckBotw1" ) return OBJECT_RUINmobilew1; - if(value == "WreckBotw2" ) return OBJECT_RUINmobilew2; - if(value == "WreckBott1" ) return OBJECT_RUINmobilet1; - if(value == "WreckBott2" ) return OBJECT_RUINmobilet2; - if(value == "WreckBotr1" ) return OBJECT_RUINmobiler1; - if(value == "WreckBotr2" ) return OBJECT_RUINmobiler2; - if(value == "RuinBotFactory" ) return OBJECT_RUINfactory; - if(value == "RuinDoor" ) return OBJECT_RUINdoor; - if(value == "RuinSupport" ) return OBJECT_RUINsupport; - if(value == "RuinRadar" ) return OBJECT_RUINradar; - if(value == "RuinConvert" ) return OBJECT_RUINconvert; - if(value == "RuinBaseCamp" ) return OBJECT_RUINbase; - if(value == "RuinHeadCamp" ) return OBJECT_RUINhead; - if(value == "Barrier0" ) return OBJECT_BARRIER0; - if(value == "Barrier1" ) return OBJECT_BARRIER1; - if(value == "Barrier2" ) return OBJECT_BARRIER2; - if(value == "Barrier3" ) return OBJECT_BARRIER3; - if(value == "Teen0" ) return OBJECT_TEEN0; - if(value == "Teen1" ) return OBJECT_TEEN1; - if(value == "Teen2" ) return OBJECT_TEEN2; - if(value == "Teen3" ) return OBJECT_TEEN3; - if(value == "Teen4" ) return OBJECT_TEEN4; - if(value == "Teen5" ) return OBJECT_TEEN5; - if(value == "Teen6" ) return OBJECT_TEEN6; - if(value == "Teen7" ) return OBJECT_TEEN7; - if(value == "Teen8" ) return OBJECT_TEEN8; - if(value == "Teen9" ) return OBJECT_TEEN9; - if(value == "Teen10" ) return OBJECT_TEEN10; - if(value == "Teen11" ) return OBJECT_TEEN11; - if(value == "Teen12" ) return OBJECT_TEEN12; - if(value == "Teen13" ) return OBJECT_TEEN13; - if(value == "Teen14" ) return OBJECT_TEEN14; - if(value == "Teen15" ) return OBJECT_TEEN15; - if(value == "Teen16" ) return OBJECT_TEEN16; - if(value == "Teen17" ) return OBJECT_TEEN17; - if(value == "Teen18" ) return OBJECT_TEEN18; - if(value == "Teen19" ) return OBJECT_TEEN19; - if(value == "Teen20" ) return OBJECT_TEEN20; - if(value == "Teen21" ) return OBJECT_TEEN21; - if(value == "Teen22" ) return OBJECT_TEEN22; - if(value == "Teen23" ) return OBJECT_TEEN23; - if(value == "Teen24" ) return OBJECT_TEEN24; - if(value == "Teen25" ) return OBJECT_TEEN25; - if(value == "Teen26" ) return OBJECT_TEEN26; - if(value == "Teen27" ) return OBJECT_TEEN27; - if(value == "Teen28" ) return OBJECT_TEEN28; - if(value == "Teen29" ) return OBJECT_TEEN29; - if(value == "Teen30" ) return OBJECT_TEEN30; - if(value == "Teen31" ) return OBJECT_TEEN31; - if(value == "Teen32" ) return OBJECT_TEEN32; - if(value == "Teen33" ) return OBJECT_TEEN33; - if(value == "Stone" ) return OBJECT_TEEN34; - if(value == "Teen35" ) return OBJECT_TEEN35; - if(value == "Teen36" ) return OBJECT_TEEN36; - if(value == "Teen37" ) return OBJECT_TEEN37; - if(value == "Teen38" ) return OBJECT_TEEN38; - if(value == "Teen39" ) return OBJECT_TEEN39; - if(value == "Teen40" ) return OBJECT_TEEN40; - if(value == "Teen41" ) return OBJECT_TEEN41; - if(value == "Teen42" ) return OBJECT_TEEN42; - if(value == "Teen43" ) return OBJECT_TEEN43; - if(value == "Teen44" ) return OBJECT_TEEN44; - if(value == "Quartz0" ) return OBJECT_QUARTZ0; - if(value == "Quartz1" ) return OBJECT_QUARTZ1; - if(value == "Quartz2" ) return OBJECT_QUARTZ2; - if(value == "Quartz3" ) return OBJECT_QUARTZ3; - if(value == "MegaStalk0" ) return OBJECT_ROOT0; - if(value == "MegaStalk1" ) return OBJECT_ROOT1; - if(value == "MegaStalk2" ) return OBJECT_ROOT2; - if(value == "MegaStalk3" ) return OBJECT_ROOT3; - if(value == "MegaStalk4" ) return OBJECT_ROOT4; - if(value == "MegaStalk5" ) return OBJECT_ROOT5; - if(value == "ApolloLEM" ) return OBJECT_APOLLO1; - if(value == "ApolloJeep" ) return OBJECT_APOLLO2; - if(value == "ApolloFlag" ) return OBJECT_APOLLO3; - if(value == "ApolloModule" ) return OBJECT_APOLLO4; - if(value == "ApolloAntenna" ) return OBJECT_APOLLO5; - if(value == "Me" ) return OBJECT_HUMAN; - if(value == "Tech" ) return OBJECT_TECH; - if(value == "MissionController" ) return OBJECT_CONTROLLER; + if (value == "All" ) return OBJECT_NULL; + if (value == "Portico" ) return OBJECT_PORTICO; + if (value == "SpaceShip" ) return OBJECT_BASE; + if (value == "PracticeBot" ) return OBJECT_MOBILEwt; + if (value == "WingedGrabber" ) return OBJECT_MOBILEfa; + if (value == "TrackedGrabber" ) return OBJECT_MOBILEta; + if (value == "WheeledGrabber" ) return OBJECT_MOBILEwa; + if (value == "LeggedGrabber" ) return OBJECT_MOBILEia; + if (value == "WingedShooter" ) return OBJECT_MOBILEfc; + if (value == "TrackedShooter" ) return OBJECT_MOBILEtc; + if (value == "WheeledShooter" ) return OBJECT_MOBILEwc; + if (value == "LeggedShooter" ) return OBJECT_MOBILEic; + if (value == "WingedOrgaShooter" ) return OBJECT_MOBILEfi; + if (value == "TrackedOrgaShooter") return OBJECT_MOBILEti; + if (value == "WheeledOrgaShooter") return OBJECT_MOBILEwi; + if (value == "LeggedOrgaShooter" ) return OBJECT_MOBILEii; + if (value == "WingedSniffer" ) return OBJECT_MOBILEfs; + if (value == "TrackedSniffer" ) return OBJECT_MOBILEts; + if (value == "WheeledSniffer" ) return OBJECT_MOBILEws; + if (value == "LeggedSniffer" ) return OBJECT_MOBILEis; + if (value == "Thumper" ) return OBJECT_MOBILErt; + if (value == "PhazerShooter" ) return OBJECT_MOBILErc; + if (value == "Recycler" ) return OBJECT_MOBILErr; + if (value == "Shielder" ) return OBJECT_MOBILErs; + if (value == "Subber" ) return OBJECT_MOBILEsa; + if (value == "TargetBot" ) return OBJECT_MOBILEtg; + if (value == "Scribbler" ) return OBJECT_MOBILEdr; + if (value == "PowerSpot" ) return OBJECT_MARKPOWER; + if (value == "TitaniumSpot" ) return OBJECT_MARKSTONE; + if (value == "UraniumSpot" ) return OBJECT_MARKURANIUM; + if (value == "PlatinumSpot" ) return OBJECT_MARKURANIUM; + if (value == "KeyASpot" ) return OBJECT_MARKKEYa; + if (value == "KeyBSpot" ) return OBJECT_MARKKEYb; + if (value == "KeyCSpot" ) return OBJECT_MARKKEYc; + if (value == "KeyDSpot" ) return OBJECT_MARKKEYd; + if (value == "WayPoint" ) return OBJECT_WAYPOINT; + if (value == "BlueFlag" ) return OBJECT_FLAGb; + if (value == "RedFlag" ) return OBJECT_FLAGr; + if (value == "GreenFlag" ) return OBJECT_FLAGg; + if (value == "YellowFlag" ) return OBJECT_FLAGy; + if (value == "VioletFlag" ) return OBJECT_FLAGv; + if (value == "PowerCell" ) return OBJECT_POWER; + if (value == "FuelCellPlant" ) return OBJECT_NUCLEAR; + if (value == "FuelCell" ) return OBJECT_ATOMIC; + if (value == "NuclearCell" ) return OBJECT_ATOMIC; + if (value == "TitaniumOre" ) return OBJECT_STONE; + if (value == "UraniumOre" ) return OBJECT_URANIUM; + if (value == "PlatinumOre" ) return OBJECT_URANIUM; + if (value == "Titanium" ) return OBJECT_METAL; + if (value == "OrgaMatter" ) return OBJECT_BULLET; + if (value == "BlackBox" ) return OBJECT_BBOX; + if (value == "KeyA" ) return OBJECT_KEYa; + if (value == "KeyB" ) return OBJECT_KEYb; + if (value == "KeyC" ) return OBJECT_KEYc; + if (value == "KeyD" ) return OBJECT_KEYd; + if (value == "TNT" ) return OBJECT_TNT; + if (value == "Scrap1" ) return OBJECT_SCRAP1; + if (value == "Scrap2" ) return OBJECT_SCRAP2; + if (value == "Scrap3" ) return OBJECT_SCRAP3; + if (value == "Scrap4" ) return OBJECT_SCRAP4; + if (value == "Scrap5" ) return OBJECT_SCRAP5; + if (value == "Mine" ) return OBJECT_BOMB; + if (value == "Firework" ) return OBJECT_WINFIRE; + if (value == "Bag" ) return OBJECT_BAG; + if (value == "Greenery0" ) return OBJECT_PLANT0; + if (value == "Greenery1" ) return OBJECT_PLANT1; + if (value == "Greenery2" ) return OBJECT_PLANT2; + if (value == "Greenery3" ) return OBJECT_PLANT3; + if (value == "Greenery4" ) return OBJECT_PLANT4; + if (value == "Greenery5" ) return OBJECT_PLANT5; + if (value == "Greenery6" ) return OBJECT_PLANT6; + if (value == "Greenery7" ) return OBJECT_PLANT7; + if (value == "Greenery8" ) return OBJECT_PLANT8; + if (value == "Greenery9" ) return OBJECT_PLANT9; + if (value == "Greenery10" ) return OBJECT_PLANT10; + if (value == "Greenery11" ) return OBJECT_PLANT11; + if (value == "Greenery12" ) return OBJECT_PLANT12; + if (value == "Greenery13" ) return OBJECT_PLANT13; + if (value == "Greenery14" ) return OBJECT_PLANT14; + if (value == "Greenery15" ) return OBJECT_PLANT15; + if (value == "Greenery16" ) return OBJECT_PLANT16; + if (value == "Greenery17" ) return OBJECT_PLANT17; + if (value == "Greenery18" ) return OBJECT_PLANT18; + if (value == "Greenery19" ) return OBJECT_PLANT19; + if (value == "Tree0" ) return OBJECT_TREE0; + if (value == "Tree1" ) return OBJECT_TREE1; + if (value == "Tree2" ) return OBJECT_TREE2; + if (value == "Tree3" ) return OBJECT_TREE3; + if (value == "Tree4" ) return OBJECT_TREE4; + if (value == "Tree5" ) return OBJECT_TREE5; + if (value == "Mushroom1" ) return OBJECT_MUSHROOM1; + if (value == "Mushroom2" ) return OBJECT_MUSHROOM2; + if (value == "Home" ) return OBJECT_HOME1; + if (value == "Derrick" ) return OBJECT_DERRICK; + if (value == "BotFactory" ) return OBJECT_FACTORY; + if (value == "PowerStation" ) return OBJECT_STATION; + if (value == "Converter" ) return OBJECT_CONVERT; + if (value == "RepairCenter" ) return OBJECT_REPAIR; + if (value == "Destroyer" ) return OBJECT_DESTROYER; + if (value == "DefenseTower" ) return OBJECT_TOWER; + if (value == "AlienNest" ) return OBJECT_NEST; + if (value == "ResearchCenter" ) return OBJECT_RESEARCH; + if (value == "RadarStation" ) return OBJECT_RADAR; + if (value == "ExchangePost" ) return OBJECT_INFO; + if (value == "PowerPlant" ) return OBJECT_ENERGY; + if (value == "AutoLab" ) return OBJECT_LABO; + if (value == "NuclearPlant" ) return OBJECT_NUCLEAR; + if (value == "PowerCaptor" ) return OBJECT_PARA; + if (value == "Vault" ) return OBJECT_SAFE; + if (value == "Houston" ) return OBJECT_HUSTON; + if (value == "Target1" ) return OBJECT_TARGET1; + if (value == "Target2" ) return OBJECT_TARGET2; + if (value == "StartArea" ) return OBJECT_START; + if (value == "GoalArea" ) return OBJECT_END; + if (value == "AlienQueen" ) return OBJECT_MOTHER; + if (value == "AlienEgg" ) return OBJECT_EGG; + if (value == "AlienAnt" ) return OBJECT_ANT; + if (value == "AlienSpider" ) return OBJECT_SPIDER; + if (value == "AlienWasp" ) return OBJECT_BEE; + if (value == "AlienWorm" ) return OBJECT_WORM; + if (value == "WreckBotw1" ) return OBJECT_RUINmobilew1; + if (value == "WreckBotw2" ) return OBJECT_RUINmobilew2; + if (value == "WreckBott1" ) return OBJECT_RUINmobilet1; + if (value == "WreckBott2" ) return OBJECT_RUINmobilet2; + if (value == "WreckBotr1" ) return OBJECT_RUINmobiler1; + if (value == "WreckBotr2" ) return OBJECT_RUINmobiler2; + if (value == "RuinBotFactory" ) return OBJECT_RUINfactory; + if (value == "RuinDoor" ) return OBJECT_RUINdoor; + if (value == "RuinSupport" ) return OBJECT_RUINsupport; + if (value == "RuinRadar" ) return OBJECT_RUINradar; + if (value == "RuinConvert" ) return OBJECT_RUINconvert; + if (value == "RuinBaseCamp" ) return OBJECT_RUINbase; + if (value == "RuinHeadCamp" ) return OBJECT_RUINhead; + if (value == "Barrier0" ) return OBJECT_BARRIER0; + if (value == "Barrier1" ) return OBJECT_BARRIER1; + if (value == "Barrier2" ) return OBJECT_BARRIER2; + if (value == "Barrier3" ) return OBJECT_BARRIER3; + if (value == "Teen0" ) return OBJECT_TEEN0; + if (value == "Teen1" ) return OBJECT_TEEN1; + if (value == "Teen2" ) return OBJECT_TEEN2; + if (value == "Teen3" ) return OBJECT_TEEN3; + if (value == "Teen4" ) return OBJECT_TEEN4; + if (value == "Teen5" ) return OBJECT_TEEN5; + if (value == "Teen6" ) return OBJECT_TEEN6; + if (value == "Teen7" ) return OBJECT_TEEN7; + if (value == "Teen8" ) return OBJECT_TEEN8; + if (value == "Teen9" ) return OBJECT_TEEN9; + if (value == "Teen10" ) return OBJECT_TEEN10; + if (value == "Teen11" ) return OBJECT_TEEN11; + if (value == "Teen12" ) return OBJECT_TEEN12; + if (value == "Teen13" ) return OBJECT_TEEN13; + if (value == "Teen14" ) return OBJECT_TEEN14; + if (value == "Teen15" ) return OBJECT_TEEN15; + if (value == "Teen16" ) return OBJECT_TEEN16; + if (value == "Teen17" ) return OBJECT_TEEN17; + if (value == "Teen18" ) return OBJECT_TEEN18; + if (value == "Teen19" ) return OBJECT_TEEN19; + if (value == "Teen20" ) return OBJECT_TEEN20; + if (value == "Teen21" ) return OBJECT_TEEN21; + if (value == "Teen22" ) return OBJECT_TEEN22; + if (value == "Teen23" ) return OBJECT_TEEN23; + if (value == "Teen24" ) return OBJECT_TEEN24; + if (value == "Teen25" ) return OBJECT_TEEN25; + if (value == "Teen26" ) return OBJECT_TEEN26; + if (value == "Teen27" ) return OBJECT_TEEN27; + if (value == "Teen28" ) return OBJECT_TEEN28; + if (value == "Teen29" ) return OBJECT_TEEN29; + if (value == "Teen30" ) return OBJECT_TEEN30; + if (value == "Teen31" ) return OBJECT_TEEN31; + if (value == "Teen32" ) return OBJECT_TEEN32; + if (value == "Teen33" ) return OBJECT_TEEN33; + if (value == "Stone" ) return OBJECT_TEEN34; + if (value == "Teen35" ) return OBJECT_TEEN35; + if (value == "Teen36" ) return OBJECT_TEEN36; + if (value == "Teen37" ) return OBJECT_TEEN37; + if (value == "Teen38" ) return OBJECT_TEEN38; + if (value == "Teen39" ) return OBJECT_TEEN39; + if (value == "Teen40" ) return OBJECT_TEEN40; + if (value == "Teen41" ) return OBJECT_TEEN41; + if (value == "Teen42" ) return OBJECT_TEEN42; + if (value == "Teen43" ) return OBJECT_TEEN43; + if (value == "Teen44" ) return OBJECT_TEEN44; + if (value == "Quartz0" ) return OBJECT_QUARTZ0; + if (value == "Quartz1" ) return OBJECT_QUARTZ1; + if (value == "Quartz2" ) return OBJECT_QUARTZ2; + if (value == "Quartz3" ) return OBJECT_QUARTZ3; + if (value == "MegaStalk0" ) return OBJECT_ROOT0; + if (value == "MegaStalk1" ) return OBJECT_ROOT1; + if (value == "MegaStalk2" ) return OBJECT_ROOT2; + if (value == "MegaStalk3" ) return OBJECT_ROOT3; + if (value == "MegaStalk4" ) return OBJECT_ROOT4; + if (value == "MegaStalk5" ) return OBJECT_ROOT5; + if (value == "ApolloLEM" ) return OBJECT_APOLLO1; + if (value == "ApolloJeep" ) return OBJECT_APOLLO2; + if (value == "ApolloFlag" ) return OBJECT_APOLLO3; + if (value == "ApolloModule" ) return OBJECT_APOLLO4; + if (value == "ApolloAntenna" ) return OBJECT_APOLLO5; + if (value == "Me" ) return OBJECT_HUMAN; + if (value == "Tech" ) return OBJECT_TECH; + if (value == "MissionController" ) return OBJECT_CONTROLLER; return static_cast(Cast(value, "object")); } const std::string CLevelParserParam::FromObjectType(ObjectType value) { - if(value == OBJECT_PORTICO ) return "Portico"; - if(value == OBJECT_BASE ) return "SpaceShip"; - if(value == OBJECT_MOBILEwt ) return "PracticeBot"; - if(value == OBJECT_MOBILEfa ) return "WingedGrabber"; - if(value == OBJECT_MOBILEta ) return "TrackedGrabber"; - if(value == OBJECT_MOBILEwa ) return "WheeledGrabber"; - if(value == OBJECT_MOBILEia ) return "LeggedGrabber"; - if(value == OBJECT_MOBILEfc ) return "WingedShooter"; - if(value == OBJECT_MOBILEtc ) return "TrackedShooter"; - if(value == OBJECT_MOBILEwc ) return "WheeledShooter"; - if(value == OBJECT_MOBILEic ) return "LeggedShooter"; - if(value == OBJECT_MOBILEfi ) return "WingedOrgaShooter"; - if(value == OBJECT_MOBILEti ) return "TrackedOrgaShooter"; - if(value == OBJECT_MOBILEwi ) return "WheeledOrgaShooter"; - if(value == OBJECT_MOBILEii ) return "LeggedOrgaShooter"; - if(value == OBJECT_MOBILEfs ) return "WingedSniffer"; - if(value == OBJECT_MOBILEts ) return "TrackedSniffer"; - if(value == OBJECT_MOBILEws ) return "WheeledSniffer"; - if(value == OBJECT_MOBILEis ) return "LeggedSniffer"; - if(value == OBJECT_MOBILErt ) return "Thumper"; - if(value == OBJECT_MOBILErc ) return "PhazerShooter"; - if(value == OBJECT_MOBILErr ) return "Recycler"; - if(value == OBJECT_MOBILErs ) return "Shielder"; - if(value == OBJECT_MOBILEsa ) return "Subber"; - if(value == OBJECT_MOBILEtg ) return "TargetBot"; - if(value == OBJECT_MOBILEdr ) return "Scribbler"; - if(value == OBJECT_MARKPOWER ) return "PowerSpot"; - if(value == OBJECT_MARKSTONE ) return "TitaniumSpot"; - if(value == OBJECT_MARKURANIUM ) return "UraniumSpot"; - if(value == OBJECT_MARKKEYa ) return "KeyASpot"; - if(value == OBJECT_MARKKEYb ) return "KeyBSpot"; - if(value == OBJECT_MARKKEYc ) return "KeyCSpot"; - if(value == OBJECT_MARKKEYd ) return "KeyDSpot"; - if(value == OBJECT_WAYPOINT ) return "WayPoint"; - if(value == OBJECT_FLAGb ) return "BlueFlag"; - if(value == OBJECT_FLAGr ) return "RedFlag"; - if(value == OBJECT_FLAGg ) return "GreenFlag"; - if(value == OBJECT_FLAGy ) return "YellowFlag"; - if(value == OBJECT_FLAGv ) return "VioletFlag"; - if(value == OBJECT_POWER ) return "PowerCell"; - if(value == OBJECT_ATOMIC ) return "NuclearCell"; - if(value == OBJECT_STONE ) return "TitaniumOre"; - if(value == OBJECT_URANIUM ) return "UraniumOre"; - if(value == OBJECT_METAL ) return "Titanium"; - if(value == OBJECT_BULLET ) return "OrgaMatter"; - if(value == OBJECT_BBOX ) return "BlackBox"; - if(value == OBJECT_KEYa ) return "KeyA"; - if(value == OBJECT_KEYb ) return "KeyB"; - if(value == OBJECT_KEYc ) return "KeyC"; - if(value == OBJECT_KEYd ) return "KeyD"; - if(value == OBJECT_TNT ) return "TNT"; - if(value == OBJECT_SCRAP1 ) return "Scrap1"; - if(value == OBJECT_SCRAP2 ) return "Scrap2"; - if(value == OBJECT_SCRAP3 ) return "Scrap3"; - if(value == OBJECT_SCRAP4 ) return "Scrap4"; - if(value == OBJECT_SCRAP5 ) return "Scrap5"; - if(value == OBJECT_BOMB ) return "Mine"; - if(value == OBJECT_WINFIRE ) return "Firework"; - if(value == OBJECT_BAG ) return "Bag"; - if(value == OBJECT_PLANT0 ) return "Greenery0"; - if(value == OBJECT_PLANT1 ) return "Greenery1"; - if(value == OBJECT_PLANT2 ) return "Greenery2"; - if(value == OBJECT_PLANT3 ) return "Greenery3"; - if(value == OBJECT_PLANT4 ) return "Greenery4"; - if(value == OBJECT_PLANT5 ) return "Greenery5"; - if(value == OBJECT_PLANT6 ) return "Greenery6"; - if(value == OBJECT_PLANT7 ) return "Greenery7"; - if(value == OBJECT_PLANT8 ) return "Greenery8"; - if(value == OBJECT_PLANT9 ) return "Greenery9"; - if(value == OBJECT_PLANT10 ) return "Greenery10"; - if(value == OBJECT_PLANT11 ) return "Greenery11"; - if(value == OBJECT_PLANT12 ) return "Greenery12"; - if(value == OBJECT_PLANT13 ) return "Greenery13"; - if(value == OBJECT_PLANT14 ) return "Greenery14"; - if(value == OBJECT_PLANT15 ) return "Greenery15"; - if(value == OBJECT_PLANT16 ) return "Greenery16"; - if(value == OBJECT_PLANT17 ) return "Greenery17"; - if(value == OBJECT_PLANT18 ) return "Greenery18"; - if(value == OBJECT_PLANT19 ) return "Greenery19"; - if(value == OBJECT_TREE0 ) return "Tree0"; - if(value == OBJECT_TREE1 ) return "Tree1"; - if(value == OBJECT_TREE2 ) return "Tree2"; - if(value == OBJECT_TREE3 ) return "Tree3"; - if(value == OBJECT_TREE4 ) return "Tree4"; - if(value == OBJECT_TREE5 ) return "Tree5"; - if(value == OBJECT_MUSHROOM1 ) return "Mushroom1"; - if(value == OBJECT_MUSHROOM2 ) return "Mushroom2"; - if(value == OBJECT_HOME1 ) return "Home"; - if(value == OBJECT_DERRICK ) return "Derrick"; - if(value == OBJECT_FACTORY ) return "BotFactory"; - if(value == OBJECT_STATION ) return "PowerStation"; - if(value == OBJECT_CONVERT ) return "Converter"; - if(value == OBJECT_REPAIR ) return "RepairCenter"; - if(value == OBJECT_DESTROYER ) return "Destroyer"; - if(value == OBJECT_TOWER ) return "DefenseTower"; - if(value == OBJECT_NEST ) return "AlienNest"; - if(value == OBJECT_RESEARCH ) return "ResearchCenter"; - if(value == OBJECT_RADAR ) return "RadarStation"; - if(value == OBJECT_INFO ) return "ExchangePost"; - if(value == OBJECT_ENERGY ) return "PowerPlant"; - if(value == OBJECT_LABO ) return "AutoLab"; - if(value == OBJECT_NUCLEAR ) return "NuclearPlant"; - if(value == OBJECT_PARA ) return "PowerCaptor"; - if(value == OBJECT_SAFE ) return "Vault"; - if(value == OBJECT_HUSTON ) return "Houston"; - if(value == OBJECT_TARGET1 ) return "Target1"; - if(value == OBJECT_TARGET2 ) return "Target2"; - if(value == OBJECT_START ) return "StartArea"; - if(value == OBJECT_END ) return "GoalArea"; - if(value == OBJECT_MOTHER ) return "AlienQueen"; - if(value == OBJECT_EGG ) return "AlienEgg"; - if(value == OBJECT_ANT ) return "AlienAnt"; - if(value == OBJECT_SPIDER ) return "AlienSpider"; - if(value == OBJECT_BEE ) return "AlienWasp"; - if(value == OBJECT_WORM ) return "AlienWorm"; - if(value == OBJECT_RUINmobilew1) return "WreckBotw1"; - if(value == OBJECT_RUINmobilew2) return "WreckBotw2"; - if(value == OBJECT_RUINmobilet1) return "WreckBott1"; - if(value == OBJECT_RUINmobilet2) return "WreckBott2"; - if(value == OBJECT_RUINmobiler1) return "WreckBotr1"; - if(value == OBJECT_RUINmobiler2) return "WreckBotr2"; - if(value == OBJECT_RUINfactory ) return "RuinBotFactory"; - if(value == OBJECT_RUINdoor ) return "RuinDoor"; - if(value == OBJECT_RUINsupport ) return "RuinSupport"; - if(value == OBJECT_RUINradar ) return "RuinRadar"; - if(value == OBJECT_RUINconvert ) return "RuinConvert"; - if(value == OBJECT_RUINbase ) return "RuinBaseCamp"; - if(value == OBJECT_RUINhead ) return "RuinHeadCamp"; - if(value == OBJECT_BARRIER0 ) return "Barrier0"; - if(value == OBJECT_BARRIER1 ) return "Barrier1"; - if(value == OBJECT_BARRIER2 ) return "Barrier2"; - if(value == OBJECT_BARRIER3 ) return "Barrier3"; - if(value == OBJECT_TEEN0 ) return "Teen0"; - if(value == OBJECT_TEEN1 ) return "Teen1"; - if(value == OBJECT_TEEN2 ) return "Teen2"; - if(value == OBJECT_TEEN3 ) return "Teen3"; - if(value == OBJECT_TEEN4 ) return "Teen4"; - if(value == OBJECT_TEEN5 ) return "Teen5"; - if(value == OBJECT_TEEN6 ) return "Teen6"; - if(value == OBJECT_TEEN7 ) return "Teen7"; - if(value == OBJECT_TEEN8 ) return "Teen8"; - if(value == OBJECT_TEEN9 ) return "Teen9"; - if(value == OBJECT_TEEN10 ) return "Teen10"; - if(value == OBJECT_TEEN11 ) return "Teen11"; - if(value == OBJECT_TEEN12 ) return "Teen12"; - if(value == OBJECT_TEEN13 ) return "Teen13"; - if(value == OBJECT_TEEN14 ) return "Teen14"; - if(value == OBJECT_TEEN15 ) return "Teen15"; - if(value == OBJECT_TEEN16 ) return "Teen16"; - if(value == OBJECT_TEEN17 ) return "Teen17"; - if(value == OBJECT_TEEN18 ) return "Teen18"; - if(value == OBJECT_TEEN19 ) return "Teen19"; - if(value == OBJECT_TEEN20 ) return "Teen20"; - if(value == OBJECT_TEEN21 ) return "Teen21"; - if(value == OBJECT_TEEN22 ) return "Teen22"; - if(value == OBJECT_TEEN23 ) return "Teen23"; - if(value == OBJECT_TEEN24 ) return "Teen24"; - if(value == OBJECT_TEEN25 ) return "Teen25"; - if(value == OBJECT_TEEN26 ) return "Teen26"; - if(value == OBJECT_TEEN27 ) return "Teen27"; - if(value == OBJECT_TEEN28 ) return "Teen28"; - if(value == OBJECT_TEEN29 ) return "Teen29"; - if(value == OBJECT_TEEN30 ) return "Teen30"; - if(value == OBJECT_TEEN31 ) return "Teen31"; - if(value == OBJECT_TEEN32 ) return "Teen32"; - if(value == OBJECT_TEEN33 ) return "Teen33"; - if(value == OBJECT_TEEN34 ) return "Stone"; - if(value == OBJECT_TEEN35 ) return "Teen35"; - if(value == OBJECT_TEEN36 ) return "Teen36"; - if(value == OBJECT_TEEN37 ) return "Teen37"; - if(value == OBJECT_TEEN38 ) return "Teen38"; - if(value == OBJECT_TEEN39 ) return "Teen39"; - if(value == OBJECT_TEEN40 ) return "Teen40"; - if(value == OBJECT_TEEN41 ) return "Teen41"; - if(value == OBJECT_TEEN42 ) return "Teen42"; - if(value == OBJECT_TEEN43 ) return "Teen43"; - if(value == OBJECT_TEEN44 ) return "Teen44"; - if(value == OBJECT_QUARTZ0 ) return "Quartz0"; - if(value == OBJECT_QUARTZ1 ) return "Quartz1"; - if(value == OBJECT_QUARTZ2 ) return "Quartz2"; - if(value == OBJECT_QUARTZ3 ) return "Quartz3"; - if(value == OBJECT_ROOT0 ) return "MegaStalk0"; - if(value == OBJECT_ROOT1 ) return "MegaStalk1"; - if(value == OBJECT_ROOT2 ) return "MegaStalk2"; - if(value == OBJECT_ROOT3 ) return "MegaStalk3"; - if(value == OBJECT_ROOT4 ) return "MegaStalk4"; - if(value == OBJECT_ROOT5 ) return "MegaStalk5"; - if(value == OBJECT_APOLLO1 ) return "ApolloLEM"; - if(value == OBJECT_APOLLO2 ) return "ApolloJeep"; - if(value == OBJECT_APOLLO3 ) return "ApolloFlag"; - if(value == OBJECT_APOLLO4 ) return "ApolloModule"; - if(value == OBJECT_APOLLO5 ) return "ApolloAntenna"; - if(value == OBJECT_HUMAN ) return "Me"; - if(value == OBJECT_TECH ) return "Tech"; - if(value == OBJECT_CONTROLLER ) return "MissionController"; + if (value == OBJECT_PORTICO ) return "Portico"; + if (value == OBJECT_BASE ) return "SpaceShip"; + if (value == OBJECT_MOBILEwt ) return "PracticeBot"; + if (value == OBJECT_MOBILEfa ) return "WingedGrabber"; + if (value == OBJECT_MOBILEta ) return "TrackedGrabber"; + if (value == OBJECT_MOBILEwa ) return "WheeledGrabber"; + if (value == OBJECT_MOBILEia ) return "LeggedGrabber"; + if (value == OBJECT_MOBILEfc ) return "WingedShooter"; + if (value == OBJECT_MOBILEtc ) return "TrackedShooter"; + if (value == OBJECT_MOBILEwc ) return "WheeledShooter"; + if (value == OBJECT_MOBILEic ) return "LeggedShooter"; + if (value == OBJECT_MOBILEfi ) return "WingedOrgaShooter"; + if (value == OBJECT_MOBILEti ) return "TrackedOrgaShooter"; + if (value == OBJECT_MOBILEwi ) return "WheeledOrgaShooter"; + if (value == OBJECT_MOBILEii ) return "LeggedOrgaShooter"; + if (value == OBJECT_MOBILEfs ) return "WingedSniffer"; + if (value == OBJECT_MOBILEts ) return "TrackedSniffer"; + if (value == OBJECT_MOBILEws ) return "WheeledSniffer"; + if (value == OBJECT_MOBILEis ) return "LeggedSniffer"; + if (value == OBJECT_MOBILErt ) return "Thumper"; + if (value == OBJECT_MOBILErc ) return "PhazerShooter"; + if (value == OBJECT_MOBILErr ) return "Recycler"; + if (value == OBJECT_MOBILErs ) return "Shielder"; + if (value == OBJECT_MOBILEsa ) return "Subber"; + if (value == OBJECT_MOBILEtg ) return "TargetBot"; + if (value == OBJECT_MOBILEdr ) return "Scribbler"; + if (value == OBJECT_MARKPOWER ) return "PowerSpot"; + if (value == OBJECT_MARKSTONE ) return "TitaniumSpot"; + if (value == OBJECT_MARKURANIUM ) return "UraniumSpot"; + if (value == OBJECT_MARKKEYa ) return "KeyASpot"; + if (value == OBJECT_MARKKEYb ) return "KeyBSpot"; + if (value == OBJECT_MARKKEYc ) return "KeyCSpot"; + if (value == OBJECT_MARKKEYd ) return "KeyDSpot"; + if (value == OBJECT_WAYPOINT ) return "WayPoint"; + if (value == OBJECT_FLAGb ) return "BlueFlag"; + if (value == OBJECT_FLAGr ) return "RedFlag"; + if (value == OBJECT_FLAGg ) return "GreenFlag"; + if (value == OBJECT_FLAGy ) return "YellowFlag"; + if (value == OBJECT_FLAGv ) return "VioletFlag"; + if (value == OBJECT_POWER ) return "PowerCell"; + if (value == OBJECT_ATOMIC ) return "NuclearCell"; + if (value == OBJECT_STONE ) return "TitaniumOre"; + if (value == OBJECT_URANIUM ) return "UraniumOre"; + if (value == OBJECT_METAL ) return "Titanium"; + if (value == OBJECT_BULLET ) return "OrgaMatter"; + if (value == OBJECT_BBOX ) return "BlackBox"; + if (value == OBJECT_KEYa ) return "KeyA"; + if (value == OBJECT_KEYb ) return "KeyB"; + if (value == OBJECT_KEYc ) return "KeyC"; + if (value == OBJECT_KEYd ) return "KeyD"; + if (value == OBJECT_TNT ) return "TNT"; + if (value == OBJECT_SCRAP1 ) return "Scrap1"; + if (value == OBJECT_SCRAP2 ) return "Scrap2"; + if (value == OBJECT_SCRAP3 ) return "Scrap3"; + if (value == OBJECT_SCRAP4 ) return "Scrap4"; + if (value == OBJECT_SCRAP5 ) return "Scrap5"; + if (value == OBJECT_BOMB ) return "Mine"; + if (value == OBJECT_WINFIRE ) return "Firework"; + if (value == OBJECT_BAG ) return "Bag"; + if (value == OBJECT_PLANT0 ) return "Greenery0"; + if (value == OBJECT_PLANT1 ) return "Greenery1"; + if (value == OBJECT_PLANT2 ) return "Greenery2"; + if (value == OBJECT_PLANT3 ) return "Greenery3"; + if (value == OBJECT_PLANT4 ) return "Greenery4"; + if (value == OBJECT_PLANT5 ) return "Greenery5"; + if (value == OBJECT_PLANT6 ) return "Greenery6"; + if (value == OBJECT_PLANT7 ) return "Greenery7"; + if (value == OBJECT_PLANT8 ) return "Greenery8"; + if (value == OBJECT_PLANT9 ) return "Greenery9"; + if (value == OBJECT_PLANT10 ) return "Greenery10"; + if (value == OBJECT_PLANT11 ) return "Greenery11"; + if (value == OBJECT_PLANT12 ) return "Greenery12"; + if (value == OBJECT_PLANT13 ) return "Greenery13"; + if (value == OBJECT_PLANT14 ) return "Greenery14"; + if (value == OBJECT_PLANT15 ) return "Greenery15"; + if (value == OBJECT_PLANT16 ) return "Greenery16"; + if (value == OBJECT_PLANT17 ) return "Greenery17"; + if (value == OBJECT_PLANT18 ) return "Greenery18"; + if (value == OBJECT_PLANT19 ) return "Greenery19"; + if (value == OBJECT_TREE0 ) return "Tree0"; + if (value == OBJECT_TREE1 ) return "Tree1"; + if (value == OBJECT_TREE2 ) return "Tree2"; + if (value == OBJECT_TREE3 ) return "Tree3"; + if (value == OBJECT_TREE4 ) return "Tree4"; + if (value == OBJECT_TREE5 ) return "Tree5"; + if (value == OBJECT_MUSHROOM1 ) return "Mushroom1"; + if (value == OBJECT_MUSHROOM2 ) return "Mushroom2"; + if (value == OBJECT_HOME1 ) return "Home"; + if (value == OBJECT_DERRICK ) return "Derrick"; + if (value == OBJECT_FACTORY ) return "BotFactory"; + if (value == OBJECT_STATION ) return "PowerStation"; + if (value == OBJECT_CONVERT ) return "Converter"; + if (value == OBJECT_REPAIR ) return "RepairCenter"; + if (value == OBJECT_DESTROYER ) return "Destroyer"; + if (value == OBJECT_TOWER ) return "DefenseTower"; + if (value == OBJECT_NEST ) return "AlienNest"; + if (value == OBJECT_RESEARCH ) return "ResearchCenter"; + if (value == OBJECT_RADAR ) return "RadarStation"; + if (value == OBJECT_INFO ) return "ExchangePost"; + if (value == OBJECT_ENERGY ) return "PowerPlant"; + if (value == OBJECT_LABO ) return "AutoLab"; + if (value == OBJECT_NUCLEAR ) return "NuclearPlant"; + if (value == OBJECT_PARA ) return "PowerCaptor"; + if (value == OBJECT_SAFE ) return "Vault"; + if (value == OBJECT_HUSTON ) return "Houston"; + if (value == OBJECT_TARGET1 ) return "Target1"; + if (value == OBJECT_TARGET2 ) return "Target2"; + if (value == OBJECT_START ) return "StartArea"; + if (value == OBJECT_END ) return "GoalArea"; + if (value == OBJECT_MOTHER ) return "AlienQueen"; + if (value == OBJECT_EGG ) return "AlienEgg"; + if (value == OBJECT_ANT ) return "AlienAnt"; + if (value == OBJECT_SPIDER ) return "AlienSpider"; + if (value == OBJECT_BEE ) return "AlienWasp"; + if (value == OBJECT_WORM ) return "AlienWorm"; + if (value == OBJECT_RUINmobilew1) return "WreckBotw1"; + if (value == OBJECT_RUINmobilew2) return "WreckBotw2"; + if (value == OBJECT_RUINmobilet1) return "WreckBott1"; + if (value == OBJECT_RUINmobilet2) return "WreckBott2"; + if (value == OBJECT_RUINmobiler1) return "WreckBotr1"; + if (value == OBJECT_RUINmobiler2) return "WreckBotr2"; + if (value == OBJECT_RUINfactory ) return "RuinBotFactory"; + if (value == OBJECT_RUINdoor ) return "RuinDoor"; + if (value == OBJECT_RUINsupport ) return "RuinSupport"; + if (value == OBJECT_RUINradar ) return "RuinRadar"; + if (value == OBJECT_RUINconvert ) return "RuinConvert"; + if (value == OBJECT_RUINbase ) return "RuinBaseCamp"; + if (value == OBJECT_RUINhead ) return "RuinHeadCamp"; + if (value == OBJECT_BARRIER0 ) return "Barrier0"; + if (value == OBJECT_BARRIER1 ) return "Barrier1"; + if (value == OBJECT_BARRIER2 ) return "Barrier2"; + if (value == OBJECT_BARRIER3 ) return "Barrier3"; + if (value == OBJECT_TEEN0 ) return "Teen0"; + if (value == OBJECT_TEEN1 ) return "Teen1"; + if (value == OBJECT_TEEN2 ) return "Teen2"; + if (value == OBJECT_TEEN3 ) return "Teen3"; + if (value == OBJECT_TEEN4 ) return "Teen4"; + if (value == OBJECT_TEEN5 ) return "Teen5"; + if (value == OBJECT_TEEN6 ) return "Teen6"; + if (value == OBJECT_TEEN7 ) return "Teen7"; + if (value == OBJECT_TEEN8 ) return "Teen8"; + if (value == OBJECT_TEEN9 ) return "Teen9"; + if (value == OBJECT_TEEN10 ) return "Teen10"; + if (value == OBJECT_TEEN11 ) return "Teen11"; + if (value == OBJECT_TEEN12 ) return "Teen12"; + if (value == OBJECT_TEEN13 ) return "Teen13"; + if (value == OBJECT_TEEN14 ) return "Teen14"; + if (value == OBJECT_TEEN15 ) return "Teen15"; + if (value == OBJECT_TEEN16 ) return "Teen16"; + if (value == OBJECT_TEEN17 ) return "Teen17"; + if (value == OBJECT_TEEN18 ) return "Teen18"; + if (value == OBJECT_TEEN19 ) return "Teen19"; + if (value == OBJECT_TEEN20 ) return "Teen20"; + if (value == OBJECT_TEEN21 ) return "Teen21"; + if (value == OBJECT_TEEN22 ) return "Teen22"; + if (value == OBJECT_TEEN23 ) return "Teen23"; + if (value == OBJECT_TEEN24 ) return "Teen24"; + if (value == OBJECT_TEEN25 ) return "Teen25"; + if (value == OBJECT_TEEN26 ) return "Teen26"; + if (value == OBJECT_TEEN27 ) return "Teen27"; + if (value == OBJECT_TEEN28 ) return "Teen28"; + if (value == OBJECT_TEEN29 ) return "Teen29"; + if (value == OBJECT_TEEN30 ) return "Teen30"; + if (value == OBJECT_TEEN31 ) return "Teen31"; + if (value == OBJECT_TEEN32 ) return "Teen32"; + if (value == OBJECT_TEEN33 ) return "Teen33"; + if (value == OBJECT_TEEN34 ) return "Stone"; + if (value == OBJECT_TEEN35 ) return "Teen35"; + if (value == OBJECT_TEEN36 ) return "Teen36"; + if (value == OBJECT_TEEN37 ) return "Teen37"; + if (value == OBJECT_TEEN38 ) return "Teen38"; + if (value == OBJECT_TEEN39 ) return "Teen39"; + if (value == OBJECT_TEEN40 ) return "Teen40"; + if (value == OBJECT_TEEN41 ) return "Teen41"; + if (value == OBJECT_TEEN42 ) return "Teen42"; + if (value == OBJECT_TEEN43 ) return "Teen43"; + if (value == OBJECT_TEEN44 ) return "Teen44"; + if (value == OBJECT_QUARTZ0 ) return "Quartz0"; + if (value == OBJECT_QUARTZ1 ) return "Quartz1"; + if (value == OBJECT_QUARTZ2 ) return "Quartz2"; + if (value == OBJECT_QUARTZ3 ) return "Quartz3"; + if (value == OBJECT_ROOT0 ) return "MegaStalk0"; + if (value == OBJECT_ROOT1 ) return "MegaStalk1"; + if (value == OBJECT_ROOT2 ) return "MegaStalk2"; + if (value == OBJECT_ROOT3 ) return "MegaStalk3"; + if (value == OBJECT_ROOT4 ) return "MegaStalk4"; + if (value == OBJECT_ROOT5 ) return "MegaStalk5"; + if (value == OBJECT_APOLLO1 ) return "ApolloLEM"; + if (value == OBJECT_APOLLO2 ) return "ApolloJeep"; + if (value == OBJECT_APOLLO3 ) return "ApolloFlag"; + if (value == OBJECT_APOLLO4 ) return "ApolloModule"; + if (value == OBJECT_APOLLO5 ) return "ApolloAntenna"; + if (value == OBJECT_HUMAN ) return "Me"; + if (value == OBJECT_TECH ) return "Tech"; + if (value == OBJECT_CONTROLLER ) return "MissionController"; return boost::lexical_cast(static_cast(value)); } ObjectType CLevelParserParam::AsObjectType() { - if(m_empty) + if (m_empty) throw CLevelParserExceptionMissingParam(this); return ToObjectType(m_value); } ObjectType CLevelParserParam::AsObjectType(ObjectType def) { - if(m_empty) + if (m_empty) return def; return AsObjectType(); } @@ -660,24 +719,24 @@ ObjectType CLevelParserParam::AsObjectType(ObjectType def) DriveType CLevelParserParam::ToDriveType(std::string value) { - if(value == "Wheeled") return DRIVE_WHEELED; - if(value == "Tracked") return DRIVE_TRACKED; - if(value == "Winged" ) return DRIVE_WINGED; - if(value == "Legged" ) return DRIVE_LEGGED; - if(value == "Other" ) return DRIVE_OTHER; + if (value == "Wheeled") return DRIVE_WHEELED; + if (value == "Tracked") return DRIVE_TRACKED; + if (value == "Winged" ) return DRIVE_WINGED; + if (value == "Legged" ) return DRIVE_LEGGED; + if (value == "Other" ) return DRIVE_OTHER; return static_cast(Cast(value, "drive")); } DriveType CLevelParserParam::AsDriveType() { - if(m_empty) + if (m_empty) throw CLevelParserExceptionMissingParam(this); return ToDriveType(m_value); } DriveType CLevelParserParam::AsDriveType(DriveType def) { - if(m_empty) + if (m_empty) return def; return AsDriveType(); } @@ -685,24 +744,24 @@ DriveType CLevelParserParam::AsDriveType(DriveType def) ToolType CLevelParserParam::ToToolType(std::string value) { - if(value == "Grabber" ) return TOOL_GRABBER; - if(value == "Shiffer" ) return TOOL_SNIFFER; - if(value == "Shooter" ) return TOOL_SHOOTER; - if(value == "OrgaShooter") return TOOL_ORGASHOOTER; - if(value == "Other" ) return TOOL_OTHER; + if (value == "Grabber" ) return TOOL_GRABBER; + if (value == "Shiffer" ) return TOOL_SNIFFER; + if (value == "Shooter" ) return TOOL_SHOOTER; + if (value == "OrgaShooter") return TOOL_ORGASHOOTER; + if (value == "Other" ) return TOOL_OTHER; return static_cast(Cast(value, "tool")); } ToolType CLevelParserParam::AsToolType() { - if(m_empty) + if (m_empty) throw CLevelParserExceptionMissingParam(this); return ToToolType(m_value); } ToolType CLevelParserParam::AsToolType(ToolType def) { - if(m_empty) + if (m_empty) return def; return AsToolType(); } @@ -710,24 +769,24 @@ ToolType CLevelParserParam::AsToolType(ToolType def) Gfx::WaterType CLevelParserParam::ToWaterType(std::string value) { - if(value == "NULL") return Gfx::WATER_NULL; - if(value == "TT" ) return Gfx::WATER_TT; - if(value == "TO" ) return Gfx::WATER_TO; - if(value == "CT" ) return Gfx::WATER_CT; - if(value == "CO" ) return Gfx::WATER_CO; + if (value == "NULL") return Gfx::WATER_NULL; + if (value == "TT" ) return Gfx::WATER_TT; + if (value == "TO" ) return Gfx::WATER_TO; + if (value == "CT" ) return Gfx::WATER_CT; + if (value == "CO" ) return Gfx::WATER_CO; return static_cast(Cast(value, "watertype")); } Gfx::WaterType CLevelParserParam::AsWaterType() { - if(m_empty) + if (m_empty) throw CLevelParserExceptionMissingParam(this); return ToWaterType(m_value); } Gfx::WaterType CLevelParserParam::AsWaterType(Gfx::WaterType def) { - if(m_empty) + if (m_empty) return def; return AsWaterType(); } @@ -735,23 +794,23 @@ Gfx::WaterType CLevelParserParam::AsWaterType(Gfx::WaterType def) Gfx::EngineObjectType CLevelParserParam::ToTerrainType(std::string value) { - if(value == "Terrain") return Gfx::ENG_OBJTYPE_TERRAIN; - if(value == "Object" ) return Gfx::ENG_OBJTYPE_FIX; - if(value == "Quartz" ) return Gfx::ENG_OBJTYPE_QUARTZ; - if(value == "Metal" ) return Gfx::ENG_OBJTYPE_METAL; + if (value == "Terrain") return Gfx::ENG_OBJTYPE_TERRAIN; + if (value == "Object" ) return Gfx::ENG_OBJTYPE_FIX; + if (value == "Quartz" ) return Gfx::ENG_OBJTYPE_QUARTZ; + if (value == "Metal" ) return Gfx::ENG_OBJTYPE_METAL; return static_cast(Cast(value, "terraintype")); } Gfx::EngineObjectType CLevelParserParam::AsTerrainType() { - if(m_empty) + if (m_empty) throw CLevelParserExceptionMissingParam(this); return ToTerrainType(m_value); } Gfx::EngineObjectType CLevelParserParam::AsTerrainType(Gfx::EngineObjectType def) { - if(m_empty) + if (m_empty) return def; return AsTerrainType(); } @@ -759,36 +818,36 @@ Gfx::EngineObjectType CLevelParserParam::AsTerrainType(Gfx::EngineObjectType def int CLevelParserParam::ToBuildFlag(std::string value) { - if(value == "BotFactory" ) return BUILD_FACTORY; - if(value == "Derrick" ) return BUILD_DERRICK; - if(value == "Converter" ) return BUILD_CONVERT; - if(value == "RadarStation" ) return BUILD_RADAR; - if(value == "PowerPlant" ) return BUILD_ENERGY; - if(value == "NuclearPlant" ) return BUILD_NUCLEAR; - if(value == "FuelCellPlant" ) return BUILD_NUCLEAR; - if(value == "PowerStation" ) return BUILD_STATION; - if(value == "RepairCenter" ) return BUILD_REPAIR; - if(value == "DefenseTower" ) return BUILD_TOWER; - if(value == "ResearchCenter") return BUILD_RESEARCH; - if(value == "AutoLab" ) return BUILD_LABO; - if(value == "PowerCaptor" ) return BUILD_PARA; - if(value == "ExchangePost" ) return BUILD_INFO; - if(value == "Destroyer" ) return BUILD_DESTROYER; - if(value == "FlatGround" ) return BUILD_GFLAT; - if(value == "Flag" ) return BUILD_FLAG; + if (value == "BotFactory" ) return BUILD_FACTORY; + if (value == "Derrick" ) return BUILD_DERRICK; + if (value == "Converter" ) return BUILD_CONVERT; + if (value == "RadarStation" ) return BUILD_RADAR; + if (value == "PowerPlant" ) return BUILD_ENERGY; + if (value == "NuclearPlant" ) return BUILD_NUCLEAR; + if (value == "FuelCellPlant" ) return BUILD_NUCLEAR; + if (value == "PowerStation" ) return BUILD_STATION; + if (value == "RepairCenter" ) return BUILD_REPAIR; + if (value == "DefenseTower" ) return BUILD_TOWER; + if (value == "ResearchCenter") return BUILD_RESEARCH; + if (value == "AutoLab" ) return BUILD_LABO; + if (value == "PowerCaptor" ) return BUILD_PARA; + if (value == "ExchangePost" ) return BUILD_INFO; + if (value == "Destroyer" ) return BUILD_DESTROYER; + if (value == "FlatGround" ) return BUILD_GFLAT; + if (value == "Flag" ) return BUILD_FLAG; return Cast(value, "buildflag"); } int CLevelParserParam::AsBuildFlag() { - if(m_empty) + if (m_empty) throw CLevelParserExceptionMissingParam(this); return ToBuildFlag(m_value); } int CLevelParserParam::AsBuildFlag(int def) { - if(m_empty) + if (m_empty) return def; return AsBuildFlag(); } @@ -796,32 +855,32 @@ int CLevelParserParam::AsBuildFlag(int def) int CLevelParserParam::ToResearchFlag(std::string value) { - if(value == "TRACKER" ) return RESEARCH_TANK; - if(value == "WINGER" ) return RESEARCH_FLY; - if(value == "THUMPER" ) return RESEARCH_THUMP; - if(value == "SHOOTER" ) return RESEARCH_CANON; - if(value == "TOWER" ) return RESEARCH_TOWER; - if(value == "PHAZER" ) return RESEARCH_PHAZER; - if(value == "SHIELDER") return RESEARCH_SHIELD; - if(value == "ATOMIC" ) return RESEARCH_ATOMIC; - if(value == "iPAW" ) return RESEARCH_iPAW; - if(value == "iGUN" ) return RESEARCH_iGUN; - if(value == "RECYCLER") return RESEARCH_RECYCLER; - if(value == "SUBBER" ) return RESEARCH_SUBM; - if(value == "SNIFFER" ) return RESEARCH_SNIFFER; + if (value == "TRACKER" ) return RESEARCH_TANK; + if (value == "WINGER" ) return RESEARCH_FLY; + if (value == "THUMPER" ) return RESEARCH_THUMP; + if (value == "SHOOTER" ) return RESEARCH_CANON; + if (value == "TOWER" ) return RESEARCH_TOWER; + if (value == "PHAZER" ) return RESEARCH_PHAZER; + if (value == "SHIELDER") return RESEARCH_SHIELD; + if (value == "ATOMIC" ) return RESEARCH_ATOMIC; + if (value == "iPAW" ) return RESEARCH_iPAW; + if (value == "iGUN" ) return RESEARCH_iGUN; + if (value == "RECYCLER") return RESEARCH_RECYCLER; + if (value == "SUBBER" ) return RESEARCH_SUBM; + if (value == "SNIFFER" ) return RESEARCH_SNIFFER; return Cast(value, "researchflag"); } int CLevelParserParam::AsResearchFlag() { - if(m_empty) + if (m_empty) throw CLevelParserExceptionMissingParam(this); return ToResearchFlag(m_value); } int CLevelParserParam::AsResearchFlag(int def) { - if(m_empty) + if (m_empty) return def; return AsResearchFlag(); } @@ -829,37 +888,37 @@ int CLevelParserParam::AsResearchFlag(int def) Gfx::PyroType CLevelParserParam::ToPyroType(std::string value) { - if(value == "FRAGt" ) return Gfx::PT_FRAGT; - if(value == "FRAGo" ) return Gfx::PT_FRAGO; - if(value == "FRAGw" ) return Gfx::PT_FRAGW; - if(value == "EXPLOt") return Gfx::PT_EXPLOT; - if(value == "EXPLOo") return Gfx::PT_EXPLOO; - if(value == "EXPLOw") return Gfx::PT_EXPLOW; - if(value == "SHOTt" ) return Gfx::PT_SHOTT; - if(value == "SHOTh" ) return Gfx::PT_SHOTH; - if(value == "SHOTm" ) return Gfx::PT_SHOTM; - if(value == "SHOTw" ) return Gfx::PT_SHOTW; - if(value == "EGG" ) return Gfx::PT_EGG; - if(value == "BURNt" ) return Gfx::PT_BURNT; - if(value == "BURNo" ) return Gfx::PT_BURNO; - if(value == "SPIDER") return Gfx::PT_SPIDER; - if(value == "FALL" ) return Gfx::PT_FALL; - if(value == "RESET" ) return Gfx::PT_RESET; - if(value == "WIN" ) return Gfx::PT_WIN; - if(value == "LOST" ) return Gfx::PT_LOST; + if (value == "FRAGt" ) return Gfx::PT_FRAGT; + if (value == "FRAGo" ) return Gfx::PT_FRAGO; + if (value == "FRAGw" ) return Gfx::PT_FRAGW; + if (value == "EXPLOt") return Gfx::PT_EXPLOT; + if (value == "EXPLOo") return Gfx::PT_EXPLOO; + if (value == "EXPLOw") return Gfx::PT_EXPLOW; + if (value == "SHOTt" ) return Gfx::PT_SHOTT; + if (value == "SHOTh" ) return Gfx::PT_SHOTH; + if (value == "SHOTm" ) return Gfx::PT_SHOTM; + if (value == "SHOTw" ) return Gfx::PT_SHOTW; + if (value == "EGG" ) return Gfx::PT_EGG; + if (value == "BURNt" ) return Gfx::PT_BURNT; + if (value == "BURNo" ) return Gfx::PT_BURNO; + if (value == "SPIDER") return Gfx::PT_SPIDER; + if (value == "FALL" ) return Gfx::PT_FALL; + if (value == "RESET" ) return Gfx::PT_RESET; + if (value == "WIN" ) return Gfx::PT_WIN; + if (value == "LOST" ) return Gfx::PT_LOST; return static_cast(Cast(value, "pyrotype")); } Gfx::PyroType CLevelParserParam::AsPyroType() { - if(m_empty) + if (m_empty) throw CLevelParserExceptionMissingParam(this); return ToPyroType(m_value); } Gfx::PyroType CLevelParserParam::AsPyroType(Gfx::PyroType def) { - if(m_empty) + if (m_empty) return def; return AsPyroType(); } @@ -867,30 +926,30 @@ Gfx::PyroType CLevelParserParam::AsPyroType(Gfx::PyroType def) Gfx::CameraType CLevelParserParam::ToCameraType(std::string value) { - if(value == "BACK" ) return Gfx::CAM_TYPE_BACK; - if(value == "PLANE" ) return Gfx::CAM_TYPE_PLANE; - if(value == "ONBOARD") return Gfx::CAM_TYPE_ONBOARD; - if(value == "FIX" ) return Gfx::CAM_TYPE_FIX; + if (value == "BACK" ) return Gfx::CAM_TYPE_BACK; + if (value == "PLANE" ) return Gfx::CAM_TYPE_PLANE; + if (value == "ONBOARD") return Gfx::CAM_TYPE_ONBOARD; + if (value == "FIX" ) return Gfx::CAM_TYPE_FIX; return static_cast(Cast(value, "camera")); } const std::string CLevelParserParam::FromCameraType(Gfx::CameraType value) { - if(value == Gfx::CAM_TYPE_ONBOARD) return "ONBOARD"; - if(value == Gfx::CAM_TYPE_FIX ) return "FIX"; + if (value == Gfx::CAM_TYPE_ONBOARD) return "ONBOARD"; + if (value == Gfx::CAM_TYPE_FIX ) return "FIX"; return boost::lexical_cast(static_cast(value)); } Gfx::CameraType CLevelParserParam::AsCameraType() { - if(m_empty) + if (m_empty) throw CLevelParserExceptionMissingParam(this); return ToCameraType(m_value); } Gfx::CameraType CLevelParserParam::AsCameraType(Gfx::CameraType def) { - if(m_empty) + if (m_empty) return def; return AsCameraType(); } @@ -898,18 +957,19 @@ Gfx::CameraType CLevelParserParam::AsCameraType(Gfx::CameraType def) void CLevelParserParam::ParseArray() { - if(m_array.size() != 0) + if (m_array.size() != 0) return; - + std::vector values; boost::split(values, m_value, boost::is_any_of(";")); int i = 0; - for(auto& value : values) { + for (auto& value : values) + { boost::algorithm::trim(value); - if(value.empty()) continue; - CLevelParserParam* param = new CLevelParserParam(m_name+"["+boost::lexical_cast(i)+"]", value); + if (value.empty()) continue; + CLevelParserParamUPtr param{new CLevelParserParam(m_name + "[" + boost::lexical_cast(i) + "]", value)}; param->SetLine(m_line); - m_array.push_back(param); + m_array.push_back(std::move(param)); i++; } } @@ -918,72 +978,21 @@ void CLevelParserParam::LoadArray() { m_value = ""; bool first = true; - for(auto& value : m_array) { - if(!first) + for (auto& value : m_array) + { + if (!first) m_value += ";"; m_value += value->GetValue(); first = false; } } -const std::vector& CLevelParserParam::AsArray() +const CLevelParserParamVec& CLevelParserParam::AsArray() { - if(m_empty) + if (m_empty) throw CLevelParserExceptionMissingParam(this); - + ParseArray(); - + return m_array; } - -CLevelParserParam::CLevelParserParam(int value) -{ - m_value = boost::lexical_cast(value); -} -CLevelParserParam::CLevelParserParam(float value) -{ - m_value = boost::lexical_cast(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& value) -{ - m_array = value; - LoadArray(); -} - diff --git a/src/object/level/parserparam.h b/src/object/level/parserparam.h index 9421f291..f7af4bd0 100644 --- a/src/object/level/parserparam.h +++ b/src/object/level/parserparam.h @@ -24,16 +24,24 @@ #pragma once -#include -#include -#include -#include -#include +#include "graphics/core/color.h" +#include "graphics/engine/water.h" +#include "graphics/engine/pyro.h" + +#include "math/point.h" + +#include "object/object.h" #include +#include +#include class CLevelParserLine; +class CLevelParserParam; +using CLevelParserParamUPtr = std::unique_ptr; +using CLevelParserParamVec = std::vector; + class CLevelParserParam { public: @@ -48,15 +56,13 @@ public: CLevelParserParam(Math::Vector value); CLevelParserParam(ObjectType value); CLevelParserParam(Gfx::CameraType value); - CLevelParserParam(const std::vector& value); + CLevelParserParam(CLevelParserParamVec&& array); //@} //! Create param from string CLevelParserParam(std::string name, std::string value); //! Create empty parser param CLevelParserParam(std::string name, bool empty); - - ~CLevelParserParam(); - + //! Get value (throws exception if not found or unable to process) //@{ int AsInt(); @@ -75,9 +81,9 @@ public: int AsResearchFlag(); Gfx::PyroType AsPyroType(); Gfx::CameraType AsCameraType(); - const std::vector& AsArray(); + const CLevelParserParamVec& AsArray(); //@} - + //! Get value (returns default if not found, throws exception if unable to process) //@{ int AsInt(int def); @@ -97,23 +103,23 @@ public: Gfx::PyroType AsPyroType(Gfx::PyroType def); Gfx::CameraType AsCameraType(Gfx::CameraType def); //@} - + //! Set line this param is part of void SetLine(CLevelParserLine* line); //! Get line this param is part of CLevelParserLine* GetLine(); - + std::string GetName(); std::string GetValue(); bool IsDefined(); - + private: void ParseArray(); void LoadArray(); - + template T Cast(std::string value, std::string requestedType); template T Cast(std::string requestedType); - + std::string ToPath(std::string path, const std::string defaultDir); ObjectType ToObjectType(std::string value); DriveType ToDriveType(std::string value); @@ -124,14 +130,15 @@ private: int ToResearchFlag(std::string value); Gfx::PyroType ToPyroType(std::string value); Gfx::CameraType ToCameraType(std::string value); - + const std::string FromObjectType(ObjectType value); const std::string FromCameraType(Gfx::CameraType value); - + private: - CLevelParserLine* m_line; - bool m_empty; + CLevelParserLine* m_line = nullptr; + bool m_empty = false; std::string m_name; std::string m_value; - std::vector m_array; -}; \ No newline at end of file + CLevelParserParamVec m_array; +}; + diff --git a/src/object/motion/motion.cpp b/src/object/motion/motion.cpp index 425fd840..c5c43ec6 100644 --- a/src/object/motion/motion.cpp +++ b/src/object/motion/motion.cpp @@ -161,10 +161,10 @@ float CMotion::GetParam(int rank) bool CMotion::Write(CLevelParserLine* line) { if ( m_actionType == -1 ) return false; - - line->AddParam("mType", new CLevelParserParam(m_actionType)); - line->AddParam("mTime", new CLevelParserParam(m_actionTime)); - line->AddParam("mProgress", new CLevelParserParam(m_progress)); + + line->AddParam("mType", CLevelParserParamUPtr{new CLevelParserParam(m_actionType)}); + line->AddParam("mTime", CLevelParserParamUPtr{new CLevelParserParam(m_actionTime)}); + line->AddParam("mProgress", CLevelParserParamUPtr{new CLevelParserParam(m_progress)}); return false; } diff --git a/src/object/motion/motiontoto.cpp b/src/object/motion/motiontoto.cpp index 5f2df1ef..3acb4f79 100644 --- a/src/object/motion/motiontoto.cpp +++ b/src/object/motion/motiontoto.cpp @@ -35,8 +35,6 @@ -const float START_TIME = 1000.0f; // beginning of the relative time - // Object's constructor. diff --git a/src/object/object.cpp b/src/object/object.cpp index ca913a1c..673db4f0 100644 --- a/src/object/object.cpp +++ b/src/object/object.cpp @@ -357,7 +357,7 @@ void CObject::DeleteObject(bool bAll) m_camera->SetControllingObject(0); } - + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); for (CObject* obj : CObjectManager::GetInstancePointer()->GetAllObjects()) @@ -950,69 +950,69 @@ bool CObject::Write(CLevelParserLine* line) float value; int i; - line->AddParam("camera", new CLevelParserParam(GetCameraType())); + line->AddParam("camera", CLevelParserParamUPtr{new CLevelParserParam(GetCameraType())}); if ( GetCameraLock() ) - line->AddParam("cameraLock", new CLevelParserParam(GetCameraLock())); + line->AddParam("cameraLock", CLevelParserParamUPtr{new CLevelParserParam(GetCameraLock())}); if ( GetEnergy() != 0.0f ) - line->AddParam("energy", new CLevelParserParam(GetEnergy())); + line->AddParam("energy", CLevelParserParamUPtr{new CLevelParserParam(GetEnergy())}); if ( GetCapacity() != 1.0f ) - line->AddParam("capacity", new CLevelParserParam(GetCapacity())); - + line->AddParam("capacity", CLevelParserParamUPtr{new CLevelParserParam(GetCapacity())}); + if ( GetShield() != 1.0f ) - line->AddParam("shield", new CLevelParserParam(GetShield())); + line->AddParam("shield", CLevelParserParamUPtr{new CLevelParserParam(GetShield())}); if ( GetRange() != 1.0f ) - line->AddParam("range", new CLevelParserParam(GetRange())); - + line->AddParam("range", CLevelParserParamUPtr{new CLevelParserParam(GetRange())}); + if ( !GetSelectable() ) - line->AddParam("selectable", new CLevelParserParam(GetSelectable())); + line->AddParam("selectable", CLevelParserParamUPtr{new CLevelParserParam(GetSelectable())}); if ( !GetEnable() ) - line->AddParam("enable", new CLevelParserParam(GetEnable())); + line->AddParam("enable", CLevelParserParamUPtr{new CLevelParserParam(GetEnable())}); if ( GetFixed() ) - line->AddParam("fixed", new CLevelParserParam(GetFixed())); + line->AddParam("fixed", CLevelParserParamUPtr{new CLevelParserParam(GetFixed())}); if ( !GetClip() ) - line->AddParam("clip", new CLevelParserParam(GetClip())); + line->AddParam("clip", CLevelParserParamUPtr{new CLevelParserParam(GetClip())}); if ( GetLock() ) - line->AddParam("lock", new CLevelParserParam(GetLock())); + line->AddParam("lock", CLevelParserParamUPtr{new CLevelParserParam(GetLock())}); if ( GetProxyActivate() ) { - line->AddParam("proxyActivate", new CLevelParserParam(GetProxyActivate())); - line->AddParam("proxyDistance", new CLevelParserParam(GetProxyDistance()/g_unit)); + line->AddParam("proxyActivate", CLevelParserParamUPtr{new CLevelParserParam(GetProxyActivate())}); + line->AddParam("proxyDistance", CLevelParserParamUPtr{new CLevelParserParam(GetProxyDistance()/g_unit)}); } if ( GetMagnifyDamage() != 1.0f ) - line->AddParam("magnifyDamage", new CLevelParserParam(GetMagnifyDamage())); + line->AddParam("magnifyDamage", CLevelParserParamUPtr{new CLevelParserParam(GetMagnifyDamage())}); if ( GetGunGoalV() != 0.0f ) - line->AddParam("aimV", new CLevelParserParam(GetGunGoalV())); - + line->AddParam("aimV", CLevelParserParamUPtr{new CLevelParserParam(GetGunGoalV())}); + if ( GetGunGoalH() != 0.0f ) - line->AddParam("aimH", new CLevelParserParam(GetGunGoalH())); + line->AddParam("aimH", CLevelParserParamUPtr{new CLevelParserParam(GetGunGoalH())}); if ( GetParam() != 0.0f ) - line->AddParam("param", new CLevelParserParam(GetParam())); + line->AddParam("param", CLevelParserParamUPtr{new CLevelParserParam(GetParam())}); if ( GetResetCap() != 0 ) { - 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(m_brain->GetProgramIndex(GetResetRun()))); + line->AddParam("resetCap", CLevelParserParamUPtr{new CLevelParserParam(static_cast(GetResetCap()))}); + line->AddParam("resetPos", CLevelParserParamUPtr{new CLevelParserParam(GetResetPosition()/g_unit)}); + line->AddParam("resetAngle", CLevelParserParamUPtr{new CLevelParserParam(GetResetAngle()/(Math::PI/180.0f))}); + line->AddParam("resetRun", CLevelParserParamUPtr{new CLevelParserParam(m_brain->GetProgramIndex(GetResetRun()))}); } if ( m_bVirusMode ) - line->AddParam("virusMode", new CLevelParserParam(m_bVirusMode)); + line->AddParam("virusMode", CLevelParserParamUPtr{new CLevelParserParam(m_bVirusMode)}); if ( m_virusTime != 0.0f ) - line->AddParam("virusTime", new CLevelParserParam(m_virusTime)); + line->AddParam("virusTime", CLevelParserParamUPtr{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))); + line->AddParam("info"+boost::lexical_cast(i+1), CLevelParserParamUPtr{new CLevelParserParam(std::string(info.name)+"="+boost::lexical_cast(info.value))}); } // Sets the parameters of the command line. - std::vector cmdline; + CLevelParserParamVec cmdline; for ( i=0 ; i 0) - line->AddParam("cmdline", new CLevelParserParam(cmdline)); + if (cmdline.size() > 0) + line->AddParam("cmdline", CLevelParserParamUPtr{new CLevelParserParam(std::move(cmdline))}); if ( m_motion != nullptr ) { @@ -1101,30 +1101,33 @@ bool CObject::Read(CLevelParserLine* line) for ( i=0 ; i(i+1); - if(!line->GetParam(op)->IsDefined()) break; + if (!line->GetParam(op)->IsDefined()) break; std::string text = line->GetParam(op)->AsString(); - + std::size_t p = text.find_first_of("="); - if(p == std::string::npos) + if (p == std::string::npos) throw CLevelParserExceptionBadParam(line->GetParam(op), "info"); Info info; strcpy(info.name, text.substr(0, p).c_str()); - try { + try + { info.value = boost::lexical_cast(text.substr(p+1).c_str()); } - catch(...) + catch (...) { throw CLevelParserExceptionBadParam(line->GetParam(op), "info.value (float)"); } - + SetInfo(i, info); } // Sets the parameters of the command line. i = 0; - if(line->GetParam("cmdline")->IsDefined()) { - for(auto& p : line->GetParam("cmdline")->AsArray()) { - if(i >= OBJECTMAXCMDLINE) break; + if (line->GetParam("cmdline")->IsDefined()) + { + for (auto& p : line->GetParam("cmdline")->AsArray()) + { + if (i >= OBJECTMAXCMDLINE) break; SetCmdLine(i, p->AsFloat()); i++; } @@ -3905,35 +3908,36 @@ void CObject::SetTraceWidth(float width) DriveType CObject::GetDriveFromObject(ObjectType type) { - switch(type) { + switch(type) + { case OBJECT_MOBILEwt: case OBJECT_MOBILEwa: case OBJECT_MOBILEwc: case OBJECT_MOBILEwi: case OBJECT_MOBILEws: return DRIVE_WHEELED; - + case OBJECT_MOBILEtt: case OBJECT_MOBILEta: case OBJECT_MOBILEtc: case OBJECT_MOBILEti: case OBJECT_MOBILEts: return DRIVE_TRACKED; - + case OBJECT_MOBILEft: case OBJECT_MOBILEfa: case OBJECT_MOBILEfc: case OBJECT_MOBILEfi: case OBJECT_MOBILEfs: return DRIVE_WINGED; - + case OBJECT_MOBILEit: case OBJECT_MOBILEia: case OBJECT_MOBILEic: case OBJECT_MOBILEii: case OBJECT_MOBILEis: return DRIVE_LEGGED; - + default: return DRIVE_OTHER; } @@ -3941,31 +3945,32 @@ DriveType CObject::GetDriveFromObject(ObjectType type) ToolType CObject::GetToolFromObject(ObjectType type) { - switch(type) { + switch(type) + { case OBJECT_MOBILEwa: case OBJECT_MOBILEta: case OBJECT_MOBILEfa: case OBJECT_MOBILEia: return TOOL_GRABBER; - + case OBJECT_MOBILEws: case OBJECT_MOBILEts: case OBJECT_MOBILEfs: case OBJECT_MOBILEis: return TOOL_SNIFFER; - + case OBJECT_MOBILEwc: case OBJECT_MOBILEtc: case OBJECT_MOBILEfc: case OBJECT_MOBILEic: return TOOL_SHOOTER; - + case OBJECT_MOBILEwi: case OBJECT_MOBILEti: case OBJECT_MOBILEfi: case OBJECT_MOBILEii: return TOOL_ORGASHOOTER; - + default: return TOOL_OTHER; } diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index 879f623d..ab5ba28c 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -202,7 +202,7 @@ CRobotMain::CRobotMain(CController* controller) m_friendAim = false; m_resetCreate = false; m_shortCut = true; - + m_movieInfoIndex = -1; m_tooltipPos = Math::Point(0.0f, 0.0f); @@ -212,9 +212,9 @@ CRobotMain::CRobotMain(CController* controller) m_endingWinRank = 0; m_endingLostRank = 0; m_winTerminate = false; - + m_exitAfterMission = false; - + m_autosave = true; m_autosaveInterval = 5; m_autosaveSlots = 3; @@ -241,10 +241,10 @@ CRobotMain::CRobotMain(CController* controller) void CRobotMain::Create(bool loadProfile) { m_app = m_ctrl->GetApplication(); - + m_eventQueue = m_app->GetEventQueue(); m_sound = m_app->GetSound(); - + m_engine = Gfx::CEngine::GetInstancePointer(); m_modelManager = m_engine->GetModelManager(); m_lightMan = m_engine->GetLightManager(); @@ -255,7 +255,7 @@ void CRobotMain::Create(bool loadProfile) m_planet = m_engine->GetPlanet(); m_pause = CPauseManager::GetInstancePointer(); m_input = CInput::GetInstancePointer(); - + m_interface = new Ui::CInterface(); m_terrain = new Gfx::CTerrain(); m_camera = new Gfx::CCamera(); @@ -273,20 +273,20 @@ void CRobotMain::Create(bool loadProfile) this); m_engine->SetTerrain(m_terrain); - + m_engine->SetMovieLock(m_movieLock); - + m_movie->Flush(); - + FlushDisplayInfo(); - + m_fontSize = 19.0f; m_windowPos = Math::Point(0.15f, 0.17f); m_windowDim = Math::Point(0.70f, 0.66f); - + float fValue; int iValue; - + if (loadProfile) { if (GetProfile().GetFloatProperty("Edit", "FontSize", fValue)) m_fontSize = fValue; @@ -295,12 +295,12 @@ void CRobotMain::Create(bool loadProfile) if (GetProfile().GetFloatProperty("Edit", "WindowDimX", fValue)) m_windowDim.x = fValue; if (GetProfile().GetFloatProperty("Edit", "WindowDimY", fValue)) m_windowDim.y = fValue; } - + m_IOPublic = false; m_IODim = Math::Point(320.0f/640.0f, (121.0f+18.0f*8)/480.0f); m_IOPos.x = (1.0f-m_IODim.x)/2.0f; // in the middle m_IOPos.y = (1.0f-m_IODim.y)/2.0f; - + if (loadProfile) { if (GetProfile().GetIntProperty ("Edit", "IOPublic", iValue)) m_IOPublic = iValue; @@ -309,17 +309,17 @@ void CRobotMain::Create(bool loadProfile) if (GetProfile().GetFloatProperty("Edit", "IODimX", fValue)) m_IODim.x = fValue; if (GetProfile().GetFloatProperty("Edit", "IODimY", fValue)) m_IODim.y = fValue; } - + m_short->FlushShortcuts(); InitEye(); - + m_engine->SetTracePrecision(1.0f); - + if (loadProfile) GetProfile().GetStringProperty("Gamer", "LastName", m_gamerName); SetGlobalGamerName(m_gamerName); ReadFreeParam(); - - CScriptFunctions::m_filesDir = CResourceManager::GetSaveLocation()+"/"+m_dialog->GetFilesDir(); //TODO: Refactor to PHYSFS while rewriting CBot engine + + CScriptFunctions::m_filesDir = CResourceManager::GetSaveLocation() + "/" + m_dialog->GetFilesDir(); //TODO: Refactor to PHYSFS while rewriting CBot engine CScriptFunctions::Init(); } @@ -382,7 +382,7 @@ Ui::CDisplayText* CRobotMain::GetDisplayText() void CRobotMain::ResetAfterDeviceChanged() { - if(m_phase == PHASE_SETUPds || + if (m_phase == PHASE_SETUPds || m_phase == PHASE_SETUPgs || m_phase == PHASE_SETUPps || m_phase == PHASE_SETUPcs || @@ -424,7 +424,7 @@ void CRobotMain::ChangePhase(Phase phase) { m_missionTimerEnabled = m_missionTimerStarted = false; m_missionTimer = 0.0f; - + if (m_phase == PHASE_SIMUL) // ends a simulation? { SaveAllScript(); @@ -554,8 +554,9 @@ void CRobotMain::ChangePhase(Phase phase) bool loading = (m_dialog->GetSceneRead()[0] != 0); m_map->CreateMap(); - - try { + + try + { CreateScene(m_dialog->GetSceneSoluce(), false, false); // interactive scene if (m_mapImage) m_map->SetFixImage(m_mapFilename); @@ -569,7 +570,7 @@ void CRobotMain::ChangePhase(Phase phase) m_sound->StopMusic(0.0f); if (m_base == nullptr || loading) StartMusic(); } - catch(const CLevelParserException& e) + catch (const CLevelParserException& e) { CLogger::GetInstancePointer()->Error("An error occured while trying to load a level\n"); CLogger::GetInstancePointer()->Error("%s\n", e.what()); @@ -590,7 +591,8 @@ void CRobotMain::ChangePhase(Phase phase) m_dialog->SetSceneName("win"); m_dialog->SetSceneRank(m_endingWinRank); - try { + try + { CreateScene(false, true, false); // sets scene pos.x = ox+sx*1; pos.y = oy+sy*1; @@ -615,7 +617,7 @@ void CRobotMain::ChangePhase(Phase phase) } StartMusic(); } - catch(const CLevelParserException& e) + catch (const CLevelParserException& e) { CLogger::GetInstancePointer()->Error("An error occured while trying to load win scene\n"); CLogger::GetInstancePointer()->Error("%s\n", e.what()); @@ -636,7 +638,8 @@ void CRobotMain::ChangePhase(Phase phase) m_winTerminate = false; m_dialog->SetSceneName("lost"); m_dialog->SetSceneRank(m_endingLostRank); - try { + try + { CreateScene(false, true, false); // sets scene pos.x = ox+sx*1; pos.y = oy+sy*1; @@ -647,7 +650,7 @@ void CRobotMain::ChangePhase(Phase phase) StartMusic(); } - catch(const CLevelParserException& e) + catch (const CLevelParserException& e) { CLogger::GetInstancePointer()->Error("An error occured while trying to load lost scene\n"); CLogger::GetInstancePointer()->Error("%s\n", e.what()); @@ -690,7 +693,7 @@ bool CRobotMain::ProcessEvent(Event &event) m_interface->EventProcess(event); if (m_displayInfo != nullptr) // current edition? m_displayInfo->EventProcess(event); - + UpdateInfoText(); return EventFrame(event); @@ -700,7 +703,7 @@ bool CRobotMain::ProcessEvent(Event &event) if (event.type == EVENT_KEY_DOWN && event.key.key == KEY(BACKQUOTE)) // Pause ? { - if(m_phase != PHASE_NAME && + if (m_phase != PHASE_NAME && !m_movie->IsExist() && !m_movieLock && !m_editLock && !m_engine->GetPause()) { @@ -904,7 +907,8 @@ bool CRobotMain::ProcessEvent(Event &event) { std::ostringstream ss; CObject* obj = GetSelect(); - if(obj != nullptr) { + if (obj != nullptr) + { ss << "CreateObject type=" << GetTypeObject(obj->GetType()) << " pos=" << std::fixed << std::setprecision(3) << obj->GetPosition(0).x/g_unit << ";" << obj->GetPosition(0).z/g_unit << " dir=" << (obj->GetAngleZ(0)/(Math::PI/180.0f)); } widgetSetClipboardText(ss.str().c_str()); @@ -1074,7 +1078,7 @@ bool CRobotMain::ProcessEvent(Event &event) ChangePhase(PHASE_INIT); else ChangePhase(PHASE_TERM); - + break; default: @@ -2005,7 +2009,7 @@ CObject* CRobotMain::DetectObject(Math::Point pos) { if (!obj->GetActif()) continue; CObject* truck = obj->GetTruck(); - if (truck != nullptr) if (!truck->GetActif()) continue; + if (truck != nullptr && !truck->GetActif()) continue; if (obj->GetProxyActivate()) continue; CObject* target = nullptr; @@ -2119,12 +2123,11 @@ CObject* CRobotMain::DetectObject(Math::Point pos) { target = obj; } - - else if (type == OBJECT_POWER || type == OBJECT_ATOMIC) - { - target = obj->GetTruck(); // battery connected - if (!target) target = obj; // standalone battery - } + else if (type == OBJECT_POWER || type == OBJECT_ATOMIC) + { + target = obj->GetTruck(); // battery connected + if (!target) target = obj; // standalone battery + } for (int j = 0; j < OBJECTMAXPART; j++) { @@ -2588,13 +2591,14 @@ bool CRobotMain::EventFrame(const Event &event) m_displayText->DisplayError(INFO_BEGINSATCOM, Math::Vector(0.0f,0.0f,0.0f)); m_beginSatCom = true; // message appears } - - if(!m_movieLock && m_pause->GetPause() == PAUSE_NONE && m_missionTimerStarted) + + if (!m_movieLock && m_pause->GetPause() == PAUSE_NONE && m_missionTimerStarted) m_missionTimer += event.rTime; - - if(m_pause->GetPause() == PAUSE_NONE && m_autosave && m_gameTime >= m_autosaveLast+(m_autosaveInterval*60) && m_phase == PHASE_SIMUL) { + + if (m_pause->GetPause() == PAUSE_NONE && m_autosave && m_gameTime >= m_autosaveLast+(m_autosaveInterval*60) && m_phase == PHASE_SIMUL) + { std::string base = m_dialog->GetSceneName(); - if(base == "missions" || base == "freemissions" || base == "custom") + if (base == "missions" || base == "freemissions" || base == "custom") { m_autosaveLast = m_gameTime; Autosave(); @@ -2619,7 +2623,7 @@ bool CRobotMain::EventFrame(const Event &event) if (pm != nullptr) pm->FlushObject(); } - + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); CObject* toto = nullptr; @@ -2842,10 +2846,11 @@ void CRobotMain::ScenePerso() m_dialog->SetSceneName("perso"); m_dialog->SetSceneRank(0); - try { + try + { CreateScene(false, true, false); // sets scene } - catch(const CLevelParserException& e) + catch (const CLevelParserException& e) { CLogger::GetInstancePointer()->Error("An error occured while trying to load apperance scene\n"); CLogger::GetInstancePointer()->Error("%s\n", e.what()); @@ -2933,7 +2938,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) m_colorRefWater.b = 240.0f/256.0f; // cyan m_colorRefWater.a = 0.0f; m_colorNewWater = m_colorRefWater; - + m_engine->SetAmbientColor(Gfx::Color(0.5f, 0.5f, 0.5f, 0.5f), 0); m_engine->SetAmbientColor(Gfx::Color(0.5f, 0.5f, 0.5f, 0.5f), 1); m_engine->SetFogColor(Gfx::Color(1.0f, 1.0f, 1.0f, 1.0f), 0); @@ -2956,15 +2961,16 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) m_missionResult = ERR_MISSION_NOTERM; } - + //NOTE: Reset timer always, even when only resetting object positions m_missionTimerEnabled = false; m_missionTimerStarted = false; m_missionTimer = 0.0f; - - try { - CLevelParser* level = new CLevelParser(base, rank/100, rank%100); - level->Load(); + + try + { + CLevelParser levelParser(base, rank/100, rank%100); + levelParser.Load(); int rankObj = 0; int rankGadget = 0; @@ -2975,54 +2981,54 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) * may speed up loading */ - for(auto& line : level->GetLines()) + for (auto& line : levelParser.GetLines()) { - if(line->GetCommand() == "Title" && !resetObject) + if (line->GetCommand() == "Title" && !resetObject) { strcpy(m_title, line->GetParam("text")->AsString().c_str()); continue; } - - if(line->GetCommand() == "Resume" && !resetObject) + + if (line->GetCommand() == "Resume" && !resetObject) { strcpy(m_resume, line->GetParam("text")->AsString().c_str()); continue; } - - if(line->GetCommand() == "ScriptName" && !resetObject) + + if (line->GetCommand() == "ScriptName" && !resetObject) { strcpy(m_scriptName, line->GetParam("text")->AsString().c_str()); continue; } - + if (line->GetCommand() == "ScriptFile" && !resetObject) { strcpy(m_scriptFile, line->GetParam("name")->AsString().c_str()); continue; } - + if (line->GetCommand() == "Instructions" && !resetObject) { strcpy(m_infoFilename[SATCOM_HUSTON], line->GetParam("name")->AsPath("help/%lng%").c_str()); - + m_immediatSatCom = line->GetParam("immediat")->AsBool(false); m_beginSatCom = m_lockedSatCom = line->GetParam("lock")->AsBool(false); if (m_app->GetSceneTestMode()) m_immediatSatCom = false; continue; } - + if (line->GetCommand() == "Satellite" && !resetObject) { strcpy(m_infoFilename[SATCOM_SAT], line->GetParam("name")->AsPath("help/%lng%").c_str()); continue; } - + if (line->GetCommand() == "Loading" && !resetObject) { strcpy(m_infoFilename[SATCOM_LOADING], line->GetParam("name")->AsPath("help/%lng%").c_str()); continue; } - + if (line->GetCommand() == "HelpFile" && !resetObject) { strcpy(m_infoFilename[SATCOM_PROG], line->GetParam("name")->AsPath("help/%lng%").c_str()); @@ -3033,7 +3039,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) strcpy(m_infoFilename[SATCOM_SOLUCE], line->GetParam("name")->AsPath("help/%lng%").c_str()); continue; } - + if (line->GetCommand() == "EndingFile" && !resetObject) { // NOTE: The old default was 0, but I think -1 is more correct - 0 means "ending file 000", while -1 means "no ending file" @@ -3041,28 +3047,29 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) m_endingLostRank = line->GetParam("lost")->AsInt(-1); continue; } - + if (line->GetCommand() == "MessageDelay" && !resetObject) { m_displayText->SetDelay(line->GetParam("factor")->AsFloat()); continue; } - + if (line->GetCommand() == "MissionTimer") { m_missionTimerEnabled = line->GetParam("enabled")->AsBool(); - if(!line->GetParam("program")->AsBool(false)) { + if (!line->GetParam("program")->AsBool(false)) + { m_missionTimerStarted = true; } continue; } - + if (line->GetCommand() == "CacheAudio" && !resetObject) { m_sound->CacheMusic(std::string("../")+line->GetParam("filename")->AsPath("music")); continue; } - + if (line->GetCommand() == "AudioChange" && !resetObject && m_controller == nullptr) { int i = m_audioChangeTotal; @@ -3085,13 +3092,13 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) } continue; } - + if (line->GetCommand() == "Audio" && !resetObject && m_controller == nullptr) { - if(line->GetParam("track")->IsDefined()) + if (line->GetParam("track")->IsDefined()) { - if(line->GetParam("filename")->IsDefined()) - throw new CLevelParserException("You can't use track and filename at the same time"); + if (line->GetParam("filename")->IsDefined()) + throw CLevelParserException("You can't use track and filename at the same time"); CLogger::GetInstancePointer()->Warn("Using track= is deprecated. Please replace this with filename=\n"); int trackid = line->GetParam("track")->AsInt(); @@ -3108,7 +3115,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) } else { - if(line->GetParam("filename")->IsDefined()) + if (line->GetParam("filename")->IsDefined()) { m_audioTrack = std::string("../")+line->GetParam("filename")->AsPath("music"); } @@ -3117,22 +3124,28 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) m_audioTrack = ""; } } - if(!m_audioTrack.empty()) + if (!m_audioTrack.empty()) { m_audioRepeat = line->GetParam("repeat")->AsBool(true); } - - if(line->GetParam("satcom")->IsDefined()) { + + if (line->GetParam("satcom")->IsDefined()) + { m_satcomTrack = std::string("../")+line->GetParam("satcom")->AsPath("music"); m_satcomRepeat = line->GetParam("satcomRepeat")->AsBool(true); - } else { + } + else + { m_satcomTrack = ""; } - - if(line->GetParam("editor")->IsDefined()) { + + if (line->GetParam("editor")->IsDefined()) + { m_editorTrack = std::string("../")+line->GetParam("editor")->AsPath("music"); m_editorRepeat = line->GetParam("editorRepeat")->AsBool(true); - } else { + } + else + { m_editorTrack = ""; } @@ -3141,70 +3154,73 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) if (!m_editorTrack.empty()) m_sound->CacheMusic(m_editorTrack); continue; } - + if (line->GetCommand() == "AmbientColor" && !resetObject) { m_engine->SetAmbientColor(line->GetParam("air")->AsColor(Gfx::Color(0.533f, 0.533f, 0.533f, 0.533f)), 0); m_engine->SetAmbientColor(line->GetParam("water")->AsColor(Gfx::Color(0.533f, 0.533f, 0.533f, 0.533f)), 1); continue; } - + if (line->GetCommand() == "FogColor" && !resetObject) { m_engine->SetFogColor(line->GetParam("air")->AsColor(Gfx::Color(0.533f, 0.533f, 0.533f, 0.533f)), 0); m_engine->SetFogColor(line->GetParam("water")->AsColor(Gfx::Color(0.533f, 0.533f, 0.533f, 0.533f)), 1); continue; } - + if (line->GetCommand() == "VehicleColor" && !resetObject) { m_colorNewBot = line->GetParam("color")->AsColor(Gfx::Color(0.533f, 0.533f, 0.533f, 0.533f)); continue; } - + if (line->GetCommand() == "InsectColor" && !resetObject) { m_colorNewAlien = line->GetParam("color")->AsColor(Gfx::Color(0.533f, 0.533f, 0.533f, 0.533f)); continue; } - + if (line->GetCommand() == "GreeneryColor" && !resetObject) { m_colorNewGreen = line->GetParam("color")->AsColor(Gfx::Color(0.533f, 0.533f, 0.533f, 0.533f)); continue; } - + if (line->GetCommand() == "DeepView" && !resetObject) { m_engine->SetDeepView(line->GetParam("air")->AsFloat(500.0f)*g_unit, 0, true); m_engine->SetDeepView(line->GetParam("water")->AsFloat(100.0f)*g_unit, 1, true); continue; } - + if (line->GetCommand() == "FogStart" && !resetObject) { m_engine->SetFogStart(line->GetParam("air")->AsFloat(0.5f), 0); m_engine->SetFogStart(line->GetParam("water")->AsFloat(0.5f), 1); continue; } - + if (line->GetCommand() == "SecondTexture" && !resetObject) { - if(line->GetParam("rank")->IsDefined()) { + if (line->GetParam("rank")->IsDefined()) + { char tex[20] = { 0 }; sprintf(tex, "dirty%.2d.png", line->GetParam("rank")->AsInt()); m_engine->SetSecondTexture(tex); - } else { - m_engine->SetSecondTexture("../"+line->GetParam("texture")->AsPath("textures")); + } + else + { + m_engine->SetSecondTexture("../" + line->GetParam("texture")->AsPath("textures")); } continue; } - + if (line->GetCommand() == "Background" && !resetObject) { std::string path = ""; - if(line->GetParam("image")->IsDefined()) - path = "../"+line->GetParam("image")->AsPath("textures"); + if (line->GetParam("image")->IsDefined()) + path = "../ " + line->GetParam("image")->AsPath("textures"); m_engine->SetBackground(path.c_str(), line->GetParam("up")->AsColor(Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f)), line->GetParam("down")->AsColor(Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f)), @@ -3213,11 +3229,11 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) line->GetParam("full")->AsBool(false)); continue; } - + if (line->GetCommand() == "Planet" && !resetObject) { Math::Vector ppos, uv1, uv2; - + ppos = line->GetParam("pos")->AsPoint(); uv1 = line->GetParam("uv1")->AsPoint(); uv2 = line->GetParam("uv2")->AsPoint(); @@ -3226,23 +3242,23 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) line->GetParam("dim")->AsFloat(0.2f), line->GetParam("speed")->AsFloat(0.0f), line->GetParam("dir")->AsFloat(0.0f), - "../"+line->GetParam("image")->AsPath("textures"), + "../" + line->GetParam("image")->AsPath("textures"), Math::Point(uv1.x, uv1.z), Math::Point(uv2.x, uv2.z), line->GetParam("image")->AsPath("textures").find("planet") != std::string::npos // TODO: add transparent op or modify textures ); continue; } - + if (line->GetCommand() == "ForegroundName" && !resetObject) { - m_engine->SetForegroundName("../"+line->GetParam("image")->AsPath("textures")); + m_engine->SetForegroundName("../" + line->GetParam("image")->AsPath("textures")); continue; } - + if ((line->GetCommand() == "Global" || line->GetCommand() == "Mission") && !resetObject) { - if(line->GetCommand() == "Global") + if (line->GetCommand() == "Global") CLogger::GetInstancePointer()->Warn("Using Global is deprecated. Please use Mission instead.\n"); g_unit = line->GetParam("unitScale")->AsFloat(4.0f); @@ -3253,7 +3269,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) if (m_retroStyle) GetLogger()->Info("Retro mode enabled.\n"); continue; } - + if (line->GetCommand() == "TerrainGenerate" && !resetObject) { m_terrain->Generate(line->GetParam("mosaic")->AsInt(20), @@ -3264,13 +3280,13 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) line->GetParam("hard")->AsFloat(0.5f)); continue; } - + if (line->GetCommand() == "TerrainWind" && !resetObject) { m_terrain->SetWind(line->GetParam("speed")->AsPoint()); continue; } - + if (line->GetCommand() == "TerrainRelief" && !resetObject) { m_terrain->LoadRelief( @@ -3279,19 +3295,19 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) line->GetParam("border")->AsBool(true)); continue; } - + if (line->GetCommand() == "TerrainRandomRelief" && !resetObject) { m_terrain->RandomizeRelief(); continue; } - + if (line->GetCommand() == "TerrainResource" && !resetObject) { m_terrain->LoadResources(line->GetParam("image")->AsPath("textures")); continue; } - + if (line->GetCommand() == "TerrainWater" && !resetObject) { Math::Vector pos; @@ -3300,7 +3316,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) pos.z = pos.x; m_water->Create(line->GetParam("air")->AsWaterType(Gfx::WATER_TT), line->GetParam("water")->AsWaterType(Gfx::WATER_TT), - "../"+line->GetParam("image")->AsPath("textures"), + "../" + line->GetParam("image")->AsPath("textures"), line->GetParam("diffuse")->AsColor(Gfx::Color(1.0f, 1.0f, 1.0f, 1.0f)), line->GetParam("ambient")->AsColor(Gfx::Color(1.0f, 1.0f, 1.0f, 1.0f)), line->GetParam("level")->AsFloat(100.0f)*g_unit, @@ -3310,25 +3326,25 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) m_colorShiftWater = line->GetParam("brightness")->AsFloat(0.0f); continue; } - + if (line->GetCommand() == "TerrainLava" && !resetObject) { m_water->SetLava(line->GetParam("mode")->AsBool()); continue; } - + if (line->GetCommand() == "TerrainCloud" && !resetObject) { std::string path = ""; - if(line->GetParam("image")->IsDefined()) - path = "../"+line->GetParam("image")->AsPath("textures"); + if (line->GetParam("image")->IsDefined()) + path = "../" + line->GetParam("image")->AsPath("textures"); m_cloud->Create(path, line->GetParam("diffuse")->AsColor(Gfx::Color(1.0f, 1.0f, 1.0f, 1.0f)), line->GetParam("ambient")->AsColor(Gfx::Color(1.0f, 1.0f, 1.0f, 1.0f)), line->GetParam("level")->AsFloat(500.0f)*g_unit); continue; } - + if (line->GetCommand() == "TerrainBlitz" && !resetObject) { m_lightning->Create(line->GetParam("sleep")->AsFloat(0.0f), @@ -3336,57 +3352,62 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) line->GetParam("magnetic")->AsFloat(50.0f)*g_unit); continue; } - + if (line->GetCommand() == "TerrainInitTextures" && !resetObject) { - std::string name = "../"+line->GetParam("image")->AsPath("textures"); - if(name.find(".") == std::string::npos) + std::string name = "../" + line->GetParam("image")->AsPath("textures"); + if (name.find(".") == std::string::npos) name += ".png"; unsigned int dx = line->GetParam("dx")->AsInt(1); unsigned int dy = line->GetParam("dy")->AsInt(1); - + int tt[100]; //TODO: I have no idea how TerrainInitTextures works, but maybe we shuld remove the limit to 100? - if(dx*dy > 100) + if (dx*dy > 100) throw CLevelParserException("In TerrainInitTextures: dx*dy must be <100"); - if(line->GetParam("table")->IsDefined()) { - const std::vector& table = line->GetParam("table")->AsArray(); - - if(table.size() > dx*dy) + if (line->GetParam("table")->IsDefined()) + { + auto& table = line->GetParam("table")->AsArray(); + + if (table.size() > dx*dy) throw CLevelParserException("In TerrainInitTextures: table size must be dx*dy"); - + for (unsigned int i = 0; i < dx*dy; i++) { - if(i >= table.size()) + if (i >= table.size()) { tt[i] = 0; - } else { + } + else + { tt[i] = table[i]->AsInt(); } } - } else { + } + else + { for (unsigned int i = 0; i < dx*dy; i++) { tt[i] = 0; } } - + m_terrain->InitTextures(name.c_str(), tt, dx, dy); continue; } - + if (line->GetCommand() == "TerrainInit" && !resetObject) { m_terrain->InitMaterials(line->GetParam("id")->AsInt(1)); continue; } - + if (line->GetCommand() == "TerrainMaterial" && !resetObject) { std::string name = line->GetParam("image")->AsPath("textures"); - if(name.find(".") == std::string::npos) + if (name.find(".") == std::string::npos) name += ".png"; - name = "../"+name; - + name = "../" + name; + m_terrain->AddMaterial(line->GetParam("id")->AsInt(0), name.c_str(), Math::Point(line->GetParam("u")->AsFloat(), @@ -3398,26 +3419,27 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) line->GetParam("hard")->AsFloat(0.5f)); continue; } - + if (line->GetCommand() == "TerrainLevel" && !resetObject) { int id[50]; //TODO: I have no idea how TerrainLevel works, but maybe we should remove the limit to 50? - if(line->GetParam("id")->IsDefined()) { - const std::vector& id_array = line->GetParam("id")->AsArray(); - - if(id_array.size() > 50) + if (line->GetParam("id")->IsDefined()) + { + auto& idArray = line->GetParam("id")->AsArray(); + + if (idArray.size() > 50) throw CLevelParserException("In TerrainLevel: id array size must be < 50"); - + unsigned int i = 0; while (i < 50) { - id[i] = id_array[i]->AsInt(); + id[i] = idArray[i]->AsInt(); i++; - if(i >= id_array.size()) break; + if (i >= idArray.size()) break; } id[i] = 0; } - + m_terrain->GenerateMaterials(id, line->GetParam("min")->AsFloat(0.0f)*g_unit, line->GetParam("max")->AsFloat(100.0f)*g_unit, @@ -3427,24 +3449,24 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) line->GetParam("radius")->AsFloat(0.0f)*g_unit); continue; } - + if (line->GetCommand() == "TerrainCreate" && !resetObject) { m_terrain->CreateObjects(); continue; } - + if (line->GetCommand() == "BeginObject") { InitEye(); SetMovieLock(false); - + if (read[0] != 0) // loading file ? sel = IOReadScene(read, stack); - + continue; } - + if (line->GetCommand() == "MissionController" && read[0] == 0) { m_controller = m_objMan->CreateObject(Math::Vector(0.0f, 0.0f, 0.0f), 0.0f, OBJECT_CONTROLLER, 100.0f); @@ -3454,17 +3476,17 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) if (brain != nullptr && line->GetParam("script")->IsDefined()) { Program* program = brain->AddProgram(); - program->filename = "../"+line->GetParam("script")->AsPath("ai"); + program->filename = "../" + line->GetParam("script")->AsPath("ai"); program->readOnly = true; brain->SetScriptRun(program); } continue; } - + if (line->GetCommand() == "CreateObject" && read[0] == 0) { ObjectType type = line->GetParam("type")->AsObjectType(); - + int gadget = line->GetParam("gadget")->AsInt(-1); if ( gadget == -1 ) { @@ -3498,7 +3520,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) { if (!TestGadgetQuantity(rankGadget++)) continue; } - + Math::Vector pos = line->GetParam("pos")->AsPoint()*g_unit; float dirAngle = line->GetParam("dir")->AsFloat(0.0f)*Math::PI; bool trainer; @@ -3512,69 +3534,71 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) line->GetParam("toy")->AsBool(false), line->GetParam("option")->AsInt(0) ); - + if (m_fixScene && type == OBJECT_HUMAN) { CMotion* motion = obj->GetMotion(); if (m_phase == PHASE_WIN ) motion->SetAction(MHS_WIN, 0.4f); if (m_phase == PHASE_LOST) motion->SetAction(MHS_LOST, 0.5f); } - + if (obj != nullptr) { obj->SetDefRank(rankObj); - + if (type == OBJECT_BASE) m_base = obj; - + Gfx::CameraType cType = line->GetParam("camera")->AsCameraType(Gfx::CAM_TYPE_NULL); if (cType != Gfx::CAM_TYPE_NULL) obj->SetCameraType(cType); - + obj->SetCameraDist(line->GetParam("cameraDist")->AsFloat(50.0f)); obj->SetCameraLock(line->GetParam("cameraLock")->AsBool(false)); - + Gfx::PyroType pType = line->GetParam("pyro")->AsPyroType(Gfx::PT_NULL); if (pType != Gfx::PT_NULL) { Gfx::CPyro* pyro = new Gfx::CPyro(); pyro->Create(pType, obj); } - + // Puts information in terminal (OBJECT_INFO). for (int i = 0; i < OBJECTMAXINFO; i++) { - std::string op = "info"+boost::lexical_cast(i+1); - if(!line->GetParam(op)->IsDefined()) break; + std::string op = "info" + boost::lexical_cast(i+1); + if (!line->GetParam(op)->IsDefined()) break; std::string text = line->GetParam(op)->AsString(); std::size_t p = text.find_first_of("="); - if(p == std::string::npos) + if (p == std::string::npos) throw CLevelParserExceptionBadParam(line->GetParam(op), "info"); Info info; strcpy(info.name, text.substr(0, p).c_str()); - try { + try + { info.value = boost::lexical_cast(text.substr(p+1).c_str()); } - catch(...) + catch (...) { throw CLevelParserExceptionBadParam(line->GetParam(op), "info.value (float)"); } obj->SetInfo(i, info); } - + // Sets the parameters of the command line. - if(line->GetParam("cmdline")->IsDefined()) { - const std::vector& cmdline = line->GetParam("cmdline")->AsArray(); + if (line->GetParam("cmdline")->IsDefined()) + { + const auto& cmdline = line->GetParam("cmdline")->AsArray(); for (unsigned int i = 0; i < OBJECTMAXCMDLINE && i < cmdline.size(); i++) //TODO: get rid of the limit { obj->SetCmdLine(i, cmdline[i]->AsFloat()); } } - + if (line->GetParam("select")->AsBool(false)) { sel = obj; } - + bool selectable = line->GetParam("selectable")->AsBool(true); obj->SetSelectable(selectable); obj->SetIgnoreBuildCheck(line->GetParam("ignoreBuildCheck")->AsBool(false)); @@ -3591,22 +3615,22 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) { obj->SetManual(!trainer); } - + Math::Vector zoom = line->GetParam("zoom")->AsPoint(Math::Vector(0.0f, 0.0f, 0.0f)); if (zoom.x != 0.0f || zoom.y != 0.0f || zoom.z != 0.0f) obj->SetZoom(0, zoom); - + //TODO: I don't remember what this is used for CMotion* motion = obj->GetMotion(); if (motion != nullptr && line->GetParam("param")->IsDefined()) { - const std::vector& p = line->GetParam("param")->AsArray(); + const auto& p = line->GetParam("param")->AsArray(); for (unsigned int i = 0; i < 10 && i < p.size(); i++) { motion->SetParam(i, p[i]->AsFloat()); } } - + int run = -1; std::map loadedPrograms; CBrain* brain = obj->GetBrain(); @@ -3614,19 +3638,20 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) { for (int i = 0; i < 10; i++) { - std::string op = "script"+boost::lexical_cast(i+1); // script1..script10 - std::string opReadOnly = "scriptReadOnly"+boost::lexical_cast(i+1); // scriptReadOnly1..scriptReadOnly10 - std::string opRunnable = "scriptRunnable"+boost::lexical_cast(i+1); // scriptRunnable1..scriptRunnable10 - if(line->GetParam(op)->IsDefined()) { + std::string op = "script" + boost::lexical_cast(i+1); // script1..script10 + std::string opReadOnly = "scriptReadOnly" + boost::lexical_cast(i+1); // scriptReadOnly1..scriptReadOnly10 + std::string opRunnable = "scriptRunnable" + boost::lexical_cast(i+1); // scriptRunnable1..scriptRunnable10 + if (line->GetParam(op)->IsDefined()) + { Program* program = brain->AddProgram(); - program->filename = "../"+line->GetParam(op)->AsPath("ai"); + program->filename = "../" + line->GetParam(op)->AsPath("ai"); program->readOnly = line->GetParam(opReadOnly)->AsBool(true); program->runnable = line->GetParam(opRunnable)->AsBool(strcmp(base, "exercises") || i+1 != 4); // TODO: I'd rather not have it hardcoded like that loadedPrograms[i] = program; } - + } - + int i = line->GetParam("run")->AsInt(0); if (i != 0) { @@ -3641,11 +3666,11 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) automat->SetType(type); for (int i = 0; i < 5; i++) { - std::string op = "autoValue"+boost::lexical_cast(i+1); // autoValue1..autoValue5 + std::string op = "autoValue" + boost::lexical_cast(i+1); // autoValue1..autoValue5 automat->SetValue(i, line->GetParam(op)->AsFloat(0.0f)); } automat->SetString(const_cast(line->GetParam("autoString")->AsPath("ai", "").c_str())); - + int i = line->GetParam("run")->AsInt(-1); if (i != -1) { @@ -3654,22 +3679,22 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) automat->Start(i); // starts the film } } - + if (soluce && brain != nullptr && line->GetParam("soluce")->IsDefined()) brain->SetSoluceName(const_cast(line->GetParam("soluce")->AsPath("ai").c_str())); - + obj->SetResetPosition(obj->GetPosition(0)); obj->SetResetAngle(obj->GetAngle(0)); obj->SetResetRun(loadedPrograms[run]); - + if (line->GetParam("reset")->AsBool(false)) obj->SetResetCap(RESET_MOVE); } - + rankObj ++; continue; } - + if (line->GetCommand() == "CreateFog" && !resetObject) { Gfx::ParticleType type = static_cast(Gfx::PARTIFOG0+(line->GetParam("type")->AsInt())); @@ -3685,56 +3710,56 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) m_particle->CreateParticle(pos, Math::Vector(0.0f, 0.0f, 0.0f), dim, type, delay, 0.0f, 0.0f); continue; } - + if (line->GetCommand() == "CreateLight" && !resetObject) { Gfx::EngineObjectType type; - + int lightRank = CreateLight(line->GetParam("dir")->AsPoint(), line->GetParam("color")->AsColor(Gfx::Color(0.5f, 0.5f, 0.5f, 1.0f))); - + type = line->GetParam("type")->AsTerrainType(Gfx::ENG_OBJTYPE_NULL); - + if (type == Gfx::ENG_OBJTYPE_TERRAIN) { m_lightMan->SetLightPriority(lightRank, Gfx::LIGHT_PRI_HIGHEST); m_lightMan->SetLightIncludeType(lightRank, Gfx::ENG_OBJTYPE_TERRAIN); } - + if (type == Gfx::ENG_OBJTYPE_QUARTZ) m_lightMan->SetLightIncludeType(lightRank, Gfx::ENG_OBJTYPE_QUARTZ); - + if (type == Gfx::ENG_OBJTYPE_METAL) m_lightMan->SetLightIncludeType(lightRank, Gfx::ENG_OBJTYPE_METAL); - + if (type == Gfx::ENG_OBJTYPE_FIX) m_lightMan->SetLightExcludeType(lightRank, Gfx::ENG_OBJTYPE_TERRAIN); - + continue; } if (line->GetCommand() == "CreateSpot" && !resetObject) { Gfx::EngineObjectType type; - + int rankLight = CreateSpot(line->GetParam("pos")->AsPoint()*g_unit, line->GetParam("color")->AsColor(Gfx::Color(0.5f, 0.5f, 0.5f, 1.0f))); - + type = line->GetParam("type")->AsTerrainType(Gfx::ENG_OBJTYPE_NULL); if (type == Gfx::ENG_OBJTYPE_TERRAIN) m_lightMan->SetLightIncludeType(rankLight, Gfx::ENG_OBJTYPE_TERRAIN); - + if (type == Gfx::ENG_OBJTYPE_QUARTZ) m_lightMan->SetLightIncludeType(rankLight, Gfx::ENG_OBJTYPE_QUARTZ); - + if (type == Gfx::ENG_OBJTYPE_METAL) m_lightMan->SetLightIncludeType(rankLight, Gfx::ENG_OBJTYPE_METAL); - + if (type == Gfx::ENG_OBJTYPE_FIX) m_lightMan->SetLightExcludeType(rankLight, Gfx::ENG_OBJTYPE_TERRAIN); - + continue; } - + if (line->GetCommand() == "GroundSpot" && !resetObject) { rank = m_engine->CreateGroundSpot(); @@ -3749,13 +3774,13 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) } continue; } - + if (line->GetCommand() == "WaterColor" && !resetObject) { m_engine->SetWaterAddColor(line->GetParam("color")->AsColor()); continue; } - + if (line->GetCommand() == "MapColor" && !resetObject) { m_map->FloorColorMap(line->GetParam("floor")->AsColor(Gfx::Color(0.533f, 0.533f, 0.533f, 0.533f)), @@ -3767,7 +3792,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) if (m_mapImage) { Math::Vector offset; - strcpy(m_mapFilename, ("../"+line->GetParam("filename")->AsPath("textures")).c_str()); + strcpy(m_mapFilename, ("../" + line->GetParam("filename")->AsPath("textures")).c_str()); offset = line->GetParam("offset")->AsPoint(Math::Vector(0.0f, 0.0f, 0.0f)); m_map->SetFixParam(line->GetParam("zoom")->AsFloat(1.0f), offset.x, offset.z, @@ -3777,20 +3802,20 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) } continue; } - + if (line->GetCommand() == "MapZoom" && !resetObject) { m_map->ZoomMap(line->GetParam("factor")->AsFloat(2.0f)); m_map->MapEnable(line->GetParam("enable")->AsBool(true)); continue; } - + if (line->GetCommand() == "MaxFlyingHeight" && !resetObject) { m_terrain->SetFlyingMaxHeight(line->GetParam("max")->AsFloat(280.0f)*g_unit); continue; } - + if (line->GetCommand() == "AddFlyingHeight" && !resetObject) { m_terrain->AddFlyingLimit(line->GetParam("center")->AsPoint()*g_unit, @@ -3799,20 +3824,20 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) line->GetParam("maxHeight")->AsFloat(200.0f)); continue; } - + if (line->GetCommand() == "Camera") { m_camera->Init(line->GetParam("eye")->AsPoint(Math::Vector(0.0f, 0.0f, 0.0f))*g_unit, line->GetParam("lookat")->AsPoint(Math::Vector(0.0f, 0.0f, 0.0f))*g_unit, resetObject ? 0.0f : line->GetParam("delay")->AsFloat(0.0f)); - + if (line->GetParam("fadeIn")->AsBool(false)) m_camera->StartOver(Gfx::CAM_OVER_EFFECT_FADEIN_WHITE, Math::Vector(0.0f, 0.0f, 0.0f), 1.0f); - + m_camera->SetFixDirection(line->GetParam("fixDirection")->AsFloat(0.25f)*Math::PI); continue; } - + if (line->GetCommand() == "EndMissionTake" && !resetObject && m_controller == nullptr) { int i = m_endTakeTotal; @@ -3851,7 +3876,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) m_endTakeNever = true; continue; } - + if (line->GetCommand() == "ObligatoryToken" && !resetObject) //NOTE: This was used only in CeeBot, maybe we should add this to some Colobot exercises? { int i = m_obligatoryTotal; @@ -3862,7 +3887,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) } continue; } - + if (line->GetCommand() == "ProhibitedToken" && !resetObject) //NOTE: This was used only in CeeBot, maybe we should add this to some Colobot exercises? { int i = m_prohibitedTotal; @@ -3873,35 +3898,35 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) } continue; } - + if (line->GetCommand() == "EnableBuild" && !resetObject) { g_build |= line->GetParam("type")->AsBuildFlag(); continue; } - + if (line->GetCommand() == "EnableResearch" && !resetObject) { g_researchEnable |= line->GetParam("type")->AsResearchFlag(); continue; } - + if (line->GetCommand() == "DoneResearch" && read[0] == 0 && !resetObject) // not loading file? { g_researchDone |= line->GetParam("type")->AsResearchFlag(); continue; } - + if (line->GetCommand() == "NewScript" && !resetObject) { AddNewScriptName(line->GetParam("type")->AsObjectType(OBJECT_NULL), const_cast(line->GetParam("name")->AsPath("ai").c_str())); continue; } - - if(read[0] != 0) continue; // ignore errors when loading saved game (TODO: don't report ones that are just not loaded when loading saved game) - if(resetObject) continue; // ignore when reseting just objects (TODO: see above) - - throw CLevelParserException("Unknown command: '"+line->GetCommand()+"' in "+line->GetLevel()->GetFilename()+":"+boost::lexical_cast(line->GetLineNumber())); + + if (read[0] != 0) continue; // ignore errors when loading saved game (TODO: don't report ones that are just not loaded when loading saved game) + if (resetObject) continue; // ignore when reseting just objects (TODO: see above) + + throw CLevelParserException("Unknown command: '" + line->GetCommand() + "' in " + line->GetLevel()->GetFilename() + ":" + boost::lexical_cast(line->GetLineNumber())); } if (read[0] == 0) @@ -3970,15 +3995,17 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) m_beginSatCom = true; // message already displayed } - } catch(...) { + } + catch (...) + { m_dialog->SetSceneRead(""); m_dialog->SetStackRead(""); throw; } m_dialog->SetSceneRead(""); m_dialog->SetStackRead(""); - - if(m_app->GetSceneTestMode()) + + if (m_app->GetSceneTestMode()) m_eventQueue->AddEvent(Event(EVENT_QUIT)); } @@ -4549,13 +4576,14 @@ void CRobotMain::CompileScript(bool soluce) CBrain* brain = obj->GetBrain(); if (brain == nullptr) continue; - for(Program* program : brain->GetPrograms()) + for (Program* program : brain->GetPrograms()) { //? if (brain->GetCompile(j)) continue; - if(program->filename.empty()) continue; + if (program->filename.empty()) continue; - std::string name = "ai/"+program->filename; - if(! brain->ReadProgram(program, const_cast(name.c_str()))) { + std::string name = "ai/" + program->filename; + if (! brain->ReadProgram(program, const_cast(name.c_str()))) + { CLogger::GetInstancePointer()->Error("Unable to read script from file \"%s\"\n", name.c_str()); } if (!brain->GetCompile(program)) nbError++; @@ -4617,7 +4645,7 @@ void CRobotMain::LoadOneScript(CObject *obj, int &nbError) char* name = m_dialog->GetSceneName(); int rank = m_dialog->GetSceneRank(); - for(unsigned int i = 0; i <= 999; i++) + for (unsigned int i = 0; i <= 999; i++) { //? if (brain->GetCompile(i)) continue; @@ -4625,7 +4653,7 @@ void CRobotMain::LoadOneScript(CObject *obj, int &nbError) sprintf(filename, "%s/%s/%c%.3d%.3d%.3d.txt", GetSavegameDir(), m_gamerName.c_str(), name[0], rank, objRank, i); - if(CResourceManager::Exists(filename)) + if (CResourceManager::Exists(filename)) { Program* program = brain->GetOrAddProgram(i); brain->ReadProgram(program, filename); @@ -4648,12 +4676,12 @@ void CRobotMain::LoadFileScript(CObject *obj, const char* filename, int objRank, std::string dirname = filename; dirname = dirname.substr(0, dirname.find_last_of("/")); - + char fn[MAX_FNAME]; //TODO: Refactor to std::string - for(unsigned int i = 0; i <= 999; i++) + for (unsigned int i = 0; i <= 999; i++) { sprintf(fn, "%s/prog%.3d%.3d.txt", dirname.c_str(), objRank, i); - if(CResourceManager::Exists(fn)) + if (CResourceManager::Exists(fn)) { Program* program = brain->GetOrAddProgram(i); brain->ReadProgram(program, fn); @@ -4691,12 +4719,12 @@ void CRobotMain::SaveOneScript(CObject *obj) auto programs = brain->GetPrograms(); // TODO: Find a better way to do that - for(unsigned int i = 0; i <= 999; i++) + for (unsigned int i = 0; i <= 999; i++) { char filename[MAX_FNAME]; sprintf(filename, "%s/%s/%c%.3d%.3d%.3d.txt", GetSavegameDir(), m_gamerName.c_str(), name[0], rank, objRank, i); - if(i < programs.size()) + if (i < programs.size()) { brain->WriteProgram(programs[i], filename); } @@ -4718,17 +4746,17 @@ void CRobotMain::SaveFileScript(CObject *obj, const char* filename, int objRank) ObjectType type = obj->GetType(); if (type == OBJECT_HUMAN) return; - + std::string dirname = filename; dirname = dirname.substr(0, dirname.find_last_of("/")); - + char fn[MAX_FNAME]; //TODO: Refactor to std::string auto programs = brain->GetPrograms(); // TODO: Find a better way to do that - for(unsigned int i = 0; i <= 999; i++) + for (unsigned int i = 0; i <= 999; i++) { sprintf(fn, "%s/prog%.3d%.3d.txt", dirname.c_str(), objRank, i); - if(i < programs.size()) + if (i < programs.size()) { brain->WriteProgram(programs[i], fn); } @@ -4832,11 +4860,11 @@ void CRobotMain::IOWriteObject(CLevelParserLine* line, CObject* obj) { if (obj->GetType() == OBJECT_FIX) return; - 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))); + line->AddParam("type", CLevelParserParamUPtr{new CLevelParserParam(obj->GetType())}); + line->AddParam("id", CLevelParserParamUPtr{new CLevelParserParam(obj->GetID())}); + line->AddParam("pos", CLevelParserParamUPtr{new CLevelParserParam(obj->GetPosition(0)/g_unit)}); + line->AddParam("angle", CLevelParserParamUPtr{new CLevelParserParam(obj->GetAngle(0)/(Math::PI/180.0f))}); + line->AddParam("zoom", CLevelParserParamUPtr{new CLevelParserParam(obj->GetZoom(0))}); Math::Vector pos; for (int i = 1; i < OBJECTMAXPART; i++) @@ -4847,49 +4875,49 @@ void CRobotMain::IOWriteObject(CLevelParserLine* line, CObject* obj) if (pos.x != 0.0f || pos.y != 0.0f || pos.z != 0.0f) { pos /= g_unit; - line->AddParam("p"+boost::lexical_cast(i), new CLevelParserParam(pos)); + line->AddParam("p" + boost::lexical_cast(i), CLevelParserParamUPtr{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); - line->AddParam("a"+boost::lexical_cast(i), new CLevelParserParam(pos)); + line->AddParam("a" + boost::lexical_cast(i), CLevelParserParamUPtr{new CLevelParserParam(pos)}); } pos = obj->GetZoom(i); if (pos.x != 1.0f || pos.y != 1.0f || pos.z != 1.0f) { - line->AddParam("z"+boost::lexical_cast(i), new CLevelParserParam(pos)); + line->AddParam("z" + boost::lexical_cast(i), CLevelParserParamUPtr{new CLevelParserParam(pos)}); } } - line->AddParam("trainer", new CLevelParserParam(obj->GetTrainer())); - line->AddParam("ignoreBuildCheck", new CLevelParserParam(obj->GetIgnoreBuildCheck())); - line->AddParam("option", new CLevelParserParam(obj->GetOption())); + line->AddParam("trainer", CLevelParserParamUPtr{new CLevelParserParam(obj->GetTrainer())}); + line->AddParam("ignoreBuildCheck", CLevelParserParamUPtr{new CLevelParserParam(obj->GetIgnoreBuildCheck())}); + line->AddParam("option", CLevelParserParamUPtr{new CLevelParserParam(obj->GetOption())}); if (obj == m_infoObject) - line->AddParam("select", new CLevelParserParam(1)); - + line->AddParam("select", CLevelParserParamUPtr{new CLevelParserParam(1)}); + obj->Write(line); - - if(obj->GetType() == OBJECT_BASE) - line->AddParam("run", new CLevelParserParam(3)); // stops and open (PARAM_FIXSCENE) - + + if (obj->GetType() == OBJECT_BASE) + line->AddParam("run", CLevelParserParamUPtr{new CLevelParserParam(3)}); // stops and open (PARAM_FIXSCENE) + CBrain* brain = obj->GetBrain(); if (brain != nullptr) { int run = brain->GetProgram(); if (run != -1) { - line->AddParam("run", new CLevelParserParam(run+1)); + line->AddParam("run", CLevelParserParamUPtr{new CLevelParserParam(run+1)}); } auto programs = brain->GetPrograms(); - for(unsigned int i = 0; i < programs.size(); i++) + for (unsigned int i = 0; i < programs.size(); i++) { - if(programs[i]->readOnly) + if (programs[i]->readOnly) { - line->AddParam("scriptReadOnly"+boost::lexical_cast(i+1), new CLevelParserParam(true)); + line->AddParam("scriptReadOnly" + boost::lexical_cast(i+1), CLevelParserParamUPtr{new CLevelParserParam(true)}); } } } @@ -4898,55 +4926,55 @@ void CRobotMain::IOWriteObject(CLevelParserLine* line, CObject* obj) //! Saves the current game bool CRobotMain::IOWriteScene(const char *filename, const char *filecbot, char *info) { - CLevelParser* level = new CLevelParser(filename); - CLevelParserLine* line; + CLevelParser levelParser(filename); + CLevelParserLineUPtr line; + + line.reset(new CLevelParserLine("Title")); + line->AddParam("text", CLevelParserParamUPtr{new CLevelParserParam(std::string(info))}); + levelParser.AddLine(std::move(line)); - line = new CLevelParserLine("Title"); - line->AddParam("text", new CLevelParserParam(std::string(info))); - level->AddLine(line); - //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); - + line.reset(new CLevelParserLine("Version")); + line->AddParam("maj", CLevelParserParamUPtr{new CLevelParserParam(0)}); + line->AddParam("min", CLevelParserParamUPtr{new CLevelParserParam(1)}); + levelParser.AddLine(std::move(line)); - line = new CLevelParserLine("Created"); - line->AddParam("date", new CLevelParserParam(GetCurrentTimestamp())); - level->AddLine(line); + + line.reset(new CLevelParserLine("Created")); + line->AddParam("date", CLevelParserParamUPtr{new CLevelParserParam(GetCurrentTimestamp())}); + levelParser.AddLine(std::move(line)); char* name = m_dialog->GetSceneName(); - line = new CLevelParserLine("Mission"); - line->AddParam("base", new CLevelParserParam(std::string(name))); - line->AddParam("rank", new CLevelParserParam(m_dialog->GetSceneRank())); + line.reset(new CLevelParserLine("Mission")); + line->AddParam("base", CLevelParserParamUPtr{new CLevelParserParam(std::string(name))}); + line->AddParam("rank", CLevelParserParamUPtr{new CLevelParserParam(m_dialog->GetSceneRank())}); if (std::string(name) == "custom") { - line->AddParam("dir", new CLevelParserParam(std::string(m_dialog->GetSceneDir()))); + line->AddParam("dir", CLevelParserParamUPtr{new CLevelParserParam(std::string(m_dialog->GetSceneDir()))}); } - level->AddLine(line); + levelParser.AddLine(std::move(line)); - line = new CLevelParserLine("Map"); - line->AddParam("zoom", new CLevelParserParam(m_map->GetZoomMap())); - level->AddLine(line); + line.reset(new CLevelParserLine("Map")); + line->AddParam("zoom", CLevelParserParamUPtr{new CLevelParserParam(m_map->GetZoomMap())}); + levelParser.AddLine(std::move(line)); - line = new CLevelParserLine("DoneResearch"); - line->AddParam("bits", new CLevelParserParam(static_cast(g_researchDone))); - level->AddLine(line); + line.reset(new CLevelParserLine("DoneResearch")); + line->AddParam("bits", CLevelParserParamUPtr{new CLevelParserParam(static_cast(g_researchDone))}); + levelParser.AddLine(std::move(line)); float sleep, delay, magnetic, progress; if (m_lightning->GetStatus(sleep, delay, magnetic, progress)) { - 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); + line.reset(new CLevelParserLine("BlitzMode")); + line->AddParam("sleep", CLevelParserParamUPtr{new CLevelParserParam(sleep)}); + line->AddParam("delay", CLevelParserParamUPtr{new CLevelParserParam(delay)}); + line->AddParam("magnetic", CLevelParserParamUPtr{new CLevelParserParam(magnetic/g_unit)}); + line->AddParam("progress", CLevelParserParamUPtr{new CLevelParserParam(progress)}); + levelParser.AddLine(std::move(line)); } - + int objRank = 0; for (CObject* obj : m_objMan->GetAllObjects()) { @@ -4960,33 +4988,36 @@ bool CRobotMain::IOWriteScene(const char *filename, const char *filecbot, char * CObject* power = obj->GetPower(); CObject* fret = obj->GetFret(); - if (fret != nullptr){ // object transported? - line = new CLevelParserLine("CreateFret"); - IOWriteObject(line, fret); - level->AddLine(line); + if (fret != nullptr) // object transported? + { + line.reset(new CLevelParserLine("CreateFret")); + IOWriteObject(line.get(), fret); + levelParser.AddLine(std::move(line)); } - if (power != nullptr) { // battery transported? - line = new CLevelParserLine("CreatePower"); - IOWriteObject(line, power); - level->AddLine(line); + if (power != nullptr) // battery transported? + { + line.reset(new CLevelParserLine("CreatePower")); + IOWriteObject(line.get(), power); + levelParser.AddLine(std::move(line)); } - - line = new CLevelParserLine("CreateObject"); - IOWriteObject(line, obj); - level->AddLine(line); + + line.reset(new CLevelParserLine("CreateObject")); + IOWriteObject(line.get(), obj); + levelParser.AddLine(std::move(line)); SaveFileScript(obj, filename, objRank++); } - try { - level->Save(); - } catch(CLevelParserException& e) { + try + { + levelParser.Save(); + } + catch (CLevelParserException& e) + { CLogger::GetInstancePointer()->Error("Failed to save level state - %s\n", e.what()); - delete level; return false; } - delete level; // Writes the file of stacks of execution. FILE* file = fOpen(filecbot, "wb"); @@ -5047,13 +5078,13 @@ CObject* CRobotMain::IOReadObject(CLevelParserLine *line, const char* filename, { obj->SetPosition(i, pos*g_unit); } - + dir = line->GetParam(std::string("a")+boost::lexical_cast(i))->AsPoint(Math::Vector()); if (dir.x != 0.0f || dir.y != 0.0f || dir.z != 0.0f) { obj->SetAngle(i, dir*(Math::PI/180.0f)); } - + zoom = line->GetParam(std::string("z")+boost::lexical_cast(i))->AsPoint(Math::Vector()); if (zoom.x != 0.0f || zoom.y != 0.0f || zoom.z != 0.0f) { @@ -5076,15 +5107,15 @@ CObject* CRobotMain::IOReadObject(CLevelParserLine *line, const char* filename, CBrain* brain = obj->GetBrain(); if (brain != nullptr) { - if(run != -1) + if (run != -1) { Program* program = brain->GetOrAddProgram(run-1); brain->SetScriptRun(program); // marks the program to be started } - for(unsigned int i = 0; i <= 999; i++) + for (unsigned int i = 0; i <= 999; i++) { - if(line->GetParam("scriptReadOnly"+boost::lexical_cast(i+1))->AsBool(false)) + if (line->GetParam("scriptReadOnly" + boost::lexical_cast(i+1))->AsBool(false)) { Program* prog = brain->GetOrAddProgram(i); prog->readOnly = true; @@ -5098,15 +5129,15 @@ CObject* CRobotMain::IOReadObject(CLevelParserLine *line, const char* filename, //! Resumes some part of the game CObject* CRobotMain::IOReadScene(const char *filename, const char *filecbot) { - CLevelParser* level = new CLevelParser(filename); - level->Load(); + CLevelParser levelParser(filename); + levelParser.Load(); m_base = nullptr; CObject* fret = nullptr; CObject* power = nullptr; CObject* sel = nullptr; int objRank = 0; - for(auto& line : level->GetLines()) + for (auto& line : levelParser.GetLines()) { if (line->GetCommand() == "Map") m_map->ZoomMap(line->GetParam("zoom")->AsFloat()); @@ -5124,14 +5155,14 @@ CObject* CRobotMain::IOReadScene(const char *filename, const char *filecbot) } if (line->GetCommand() == "CreateFret") - fret = IOReadObject(line, filename, -1); + fret = IOReadObject(line.get(), filename, -1); if (line->GetCommand() == "CreatePower") - power = IOReadObject(line, filename, -1); + power = IOReadObject(line.get(), filename, -1); if (line->GetCommand() == "CreateObject") { - CObject* obj = IOReadObject(line, filename, objRank++); + CObject* obj = IOReadObject(line.get(), filename, objRank++); if (line->GetParam("select")->AsBool(false)) sel = obj; @@ -5154,8 +5185,7 @@ CObject* CRobotMain::IOReadScene(const char *filename, const char *filecbot) power = nullptr; } } - delete level; - + // Compiles scripts. int nbError = 0; int lastError = 0; @@ -5232,15 +5262,15 @@ void CRobotMain::WriteFreeParam() if (m_gamerName == "") return; COutputStream file; - file.open(std::string(GetSavegameDir())+"/"+m_gamerName+"/research.gam"); - if(!file.is_open()) + file.open(std::string(GetSavegameDir()) + "/" + m_gamerName + "/research.gam"); + if (!file.is_open()) { CLogger::GetInstancePointer()->Error("Unable to write free game unlock state\n"); return; } - + file << "research=" << m_freeResearch << " build=" << m_freeBuild << "\n"; - + file.close(); } @@ -5252,12 +5282,12 @@ void CRobotMain::ReadFreeParam() if (m_gamerName == "") return; - if(!CResourceManager::Exists(std::string(GetSavegameDir())+"/"+m_gamerName+"/research.gam")) + if (!CResourceManager::Exists(std::string(GetSavegameDir()) + "/" + m_gamerName + "/research.gam")) return; - + CInputStream file; - file.open(std::string(GetSavegameDir())+"/"+m_gamerName+"/research.gam"); - if(!file.is_open()) + 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; @@ -5265,7 +5295,7 @@ void CRobotMain::ReadFreeParam() std::string line; std::getline(file, line); - + sscanf(line.c_str(), "research=%d build=%d\n", &m_freeResearch, &m_freeBuild); file.close(); @@ -5393,7 +5423,8 @@ void CRobotMain::ResetCreate() m_camera->SetType(Gfx::CAM_TYPE_DIALOG); - try { + try + { CreateScene(m_dialog->GetSceneSoluce(), false, true); if (!GetNiceReset()) return; @@ -5407,7 +5438,7 @@ void CRobotMain::ResetCreate() pyro->Create(Gfx::PT_RESET, obj); } } - catch(const CLevelParserException& e) + catch (const CLevelParserException& e) { CLogger::GetInstancePointer()->Error("An error occured while trying to reset scene\n"); CLogger::GetInstancePointer()->Error("%s\n", e.what()); @@ -5444,13 +5475,20 @@ void CRobotMain::UpdateAudio(bool frame) { type = OBJECT_SCRAP1; } - + ToolType tool = CObject::GetToolFromObject(type); DriveType drive = CObject::GetDriveFromObject(type); - if (m_audioChange[t].tool != TOOL_OTHER) if(tool != m_audioChange[t].tool) continue; - if (m_audioChange[t].drive != DRIVE_OTHER) if(drive != m_audioChange[t].drive) continue; + if (m_audioChange[t].tool != TOOL_OTHER && + tool != m_audioChange[t].tool) + continue; + if (m_audioChange[t].drive != DRIVE_OTHER && + drive != m_audioChange[t].drive) + continue; - if (m_audioChange[t].tool == TOOL_OTHER && m_audioChange[t].drive == DRIVE_OTHER) if (type != m_audioChange[t].type) continue; + if (m_audioChange[t].tool == TOOL_OTHER && + m_audioChange[t].drive == DRIVE_OTHER && + type != m_audioChange[t].type) + continue; float energyLevel = -1; CObject* power = obj->GetPower(); @@ -5458,15 +5496,17 @@ void CRobotMain::UpdateAudio(bool frame) { energyLevel = power->GetEnergy(); if (power->GetType() == OBJECT_ATOMIC) energyLevel *= 100; - } else { - if(obj->GetType() == OBJECT_POWER || obj->GetType() == OBJECT_ATOMIC) + } + else + { + if (obj->GetType() == OBJECT_POWER || obj->GetType() == OBJECT_ATOMIC) { energyLevel = obj->GetEnergy(); if (obj->GetType() == OBJECT_ATOMIC) energyLevel *= 100; } } if (energyLevel < m_audioChange[t].powermin || energyLevel > m_audioChange[t].powermax) - continue; + continue; if (obj->GetTruck() == 0) oPos = obj->GetPosition(0); @@ -5511,7 +5551,7 @@ Error CRobotMain::CheckEndMission(bool frame) m_winDelay = 0.0f; if (m_lostDelay == 0) m_lostDelay = m_endTakeLostDelay; m_displayText->SetEnable(false); - if(m_exitAfterMission) + if (m_exitAfterMission) m_eventQueue->AddEvent(Event(EVENT_QUIT)); } if (m_missionResult == INFO_LOSTq) //mission lost? @@ -5520,21 +5560,23 @@ Error CRobotMain::CheckEndMission(bool frame) m_winDelay = 0.0f; if (m_lostDelay == 0) m_lostDelay = 0.1f; m_displayText->SetEnable(false); - if(m_exitAfterMission) + if (m_exitAfterMission) m_eventQueue->AddEvent(Event(EVENT_QUIT)); } if (frame && m_base != nullptr && m_base->GetSelectable()) return ERR_MISSION_NOTERM; - if (m_missionResult == ERR_OK) { //mission win? + if (m_missionResult == ERR_OK) //mission win? + { m_displayText->DisplayError(INFO_WIN, Math::Vector(0.0f,0.0f,0.0f)); - if(m_missionTimerEnabled && m_missionTimerStarted) { + if (m_missionTimerEnabled && m_missionTimerStarted) + { CLogger::GetInstancePointer()->Info("Mission time: %s\n", TimeFormat(m_missionTimer).c_str()); - m_displayText->DisplayText(("Time: "+TimeFormat(m_missionTimer)).c_str(), Math::Vector(0.0f,0.0f,0.0f)); + m_displayText->DisplayText(("Time: " + TimeFormat(m_missionTimer)).c_str(), Math::Vector(0.0f,0.0f,0.0f)); } m_missionTimerEnabled = m_missionTimerStarted = false; if (m_winDelay == 0) m_winDelay = m_endTakeWinDelay; m_lostDelay = 0.0f; m_displayText->SetEnable(false); - if(m_exitAfterMission) + if (m_exitAfterMission) m_eventQueue->AddEvent(Event(EVENT_QUIT)); } if (m_missionResult == ERR_MISSION_NOTERM) m_displayText->SetEnable(true); @@ -5559,9 +5601,9 @@ Error CRobotMain::CheckEndMission(bool frame) if (obj->GetRuin()) continue; if (!obj->GetEnable()) continue; - if(!m_endTake[t].countTransported) + if (!m_endTake[t].countTransported) { - if(obj->GetTruck() != nullptr) continue; + if (obj->GetTruck() != nullptr) continue; } ObjectType type = obj->GetType(); @@ -5575,10 +5617,18 @@ Error CRobotMain::CheckEndMission(bool frame) ToolType tool = CObject::GetToolFromObject(type); DriveType drive = CObject::GetDriveFromObject(type); - if (m_endTake[t].tool != TOOL_OTHER) if(tool != m_endTake[t].tool) continue; - if (m_endTake[t].drive != DRIVE_OTHER) if(drive != m_endTake[t].drive) continue; + if (m_endTake[t].tool != TOOL_OTHER && + tool != m_endTake[t].tool) + continue; - if (m_endTake[t].tool == TOOL_OTHER && m_endTake[t].drive == DRIVE_OTHER) if (type != m_endTake[t].type) continue; + if (m_endTake[t].drive != DRIVE_OTHER && + drive != m_endTake[t].drive) + continue; + + if (m_endTake[t].tool == TOOL_OTHER && + m_endTake[t].drive == DRIVE_OTHER && + type != m_endTake[t].type) + continue; float energyLevel = -1; CObject* power = obj->GetPower(); @@ -5586,8 +5636,10 @@ Error CRobotMain::CheckEndMission(bool frame) { energyLevel = power->GetEnergy(); if (power->GetType() == OBJECT_ATOMIC) energyLevel *= 100; - } else { - if(obj->GetType() == OBJECT_POWER || obj->GetType() == OBJECT_ATOMIC) + } + else + { + if (obj->GetType() == OBJECT_POWER || obj->GetType() == OBJECT_ATOMIC) { energyLevel = obj->GetEnergy(); if (obj->GetType() == OBJECT_ATOMIC) energyLevel *= 100; @@ -5617,7 +5669,7 @@ Error CRobotMain::CheckEndMission(bool frame) } m_missionTimerEnabled = m_missionTimerStarted = false; m_displayText->SetEnable(false); - if(m_exitAfterMission) + if (m_exitAfterMission) m_eventQueue->AddEvent(Event(EVENT_QUIT)); return INFO_LOSTq; } @@ -5631,7 +5683,7 @@ Error CRobotMain::CheckEndMission(bool frame) } m_missionTimerEnabled = m_missionTimerStarted = false; m_displayText->SetEnable(false); - if(m_exitAfterMission) + if (m_exitAfterMission) m_eventQueue->AddEvent(Event(EVENT_QUIT)); return INFO_LOST; } @@ -5652,7 +5704,7 @@ Error CRobotMain::CheckEndMission(bool frame) } m_missionTimerEnabled = m_missionTimerStarted = false; m_displayText->SetEnable(false); - if(m_exitAfterMission) + if (m_exitAfterMission) m_eventQueue->AddEvent(Event(EVENT_QUIT)); return ERR_OK; // mission ended } @@ -5673,7 +5725,7 @@ Error CRobotMain::CheckEndMission(bool frame) m_lostDelay = 0.0f; m_missionTimerEnabled = m_missionTimerStarted = false; m_displayText->SetEnable(false); - if(m_exitAfterMission) + if (m_exitAfterMission) m_eventQueue->AddEvent(Event(EVENT_QUIT)); return ERR_OK; // mission ended } @@ -5683,15 +5735,16 @@ Error CRobotMain::CheckEndMission(bool frame) if (m_winDelay == 0.0f) { m_displayText->DisplayError(INFO_WIN, Math::Vector(0.0f,0.0f,0.0f)); - if(m_missionTimerEnabled && m_missionTimerStarted) { + if (m_missionTimerEnabled && m_missionTimerStarted) + { CLogger::GetInstancePointer()->Info("Mission time: %s\n", TimeFormat(m_missionTimer).c_str()); - m_displayText->DisplayText(("Time: "+TimeFormat(m_missionTimer)).c_str(), Math::Vector(0.0f,0.0f,0.0f)); + m_displayText->DisplayText(("Time: " + TimeFormat(m_missionTimer)).c_str(), Math::Vector(0.0f,0.0f,0.0f)); } m_missionTimerEnabled = m_missionTimerStarted = false; m_winDelay = m_endTakeWinDelay; // wins in two seconds m_lostDelay = 0.0f; } - if(m_exitAfterMission) + if (m_exitAfterMission) m_eventQueue->AddEvent(Event(EVENT_QUIT)); m_displayText->SetEnable(false); return ERR_OK; // mission ended @@ -5911,7 +5964,7 @@ int CRobotMain::GetSceneRank() //! Changes on the pause mode void CRobotMain::ChangePause(PauseType pause) { - if(pause != PAUSE_NONE) + if (pause != PAUSE_NONE) m_pause->SetPause(pause); else m_pause->ClearPause(); @@ -6095,17 +6148,18 @@ void CRobotMain::StartMusic() //! Starts pause music void CRobotMain::StartPauseMusic(PauseType pause) { - switch(pause) { + switch(pause) + { case PAUSE_EDITOR: - if(m_editorTrack != "") + if (m_editorTrack != "") m_sound->PlayPauseMusic(m_editorTrack, m_editorRepeat); break; - + case PAUSE_SATCOM: - if(m_satcomTrack != "") + if (m_satcomTrack != "") m_sound->PlayPauseMusic(m_satcomTrack, m_satcomRepeat); break; - + default: // Don't change music break; @@ -6136,7 +6190,8 @@ std::string& CRobotMain::GetUserLevelName(int id) void CRobotMain::StartMissionTimer() { - if(m_missionTimerEnabled && !m_missionTimerStarted) { + if (m_missionTimerEnabled && !m_missionTimerStarted) + { CLogger::GetInstancePointer()->Info("Starting mission timer...\n"); m_missionTimerStarted = true; } @@ -6182,25 +6237,25 @@ int CRobotMain::AutosaveRotate(bool freeOne) // Find autosave dirs auto saveDirs = CResourceManager::ListDirectories(std::string(GetSavegameDir()) + "/" + GetGamerName()); std::map autosaveDirs; - for(auto& dir : saveDirs) + for (auto& dir : saveDirs) { try { const std::string autosavePrefix = "autosave"; - if(dir.substr(0, autosavePrefix.length()) == "autosave") + if (dir.substr(0, autosavePrefix.length()) == "autosave") { int id = boost::lexical_cast(dir.substr(autosavePrefix.length())); autosaveDirs[id] = std::string(GetSavegameDir()) + "/" + GetGamerName() + "/" + dir; } } - catch(...) + catch (...) { CLogger::GetInstancePointer()->Info("Bad autosave found: %s\n", dir.c_str()); // skip } } - if(autosaveDirs.size() == 0) return 1; - + if (autosaveDirs.size() == 0) return 1; + // Remove all but last m_autosaveSlots std::map autosavesToKeep; int last_id = autosaveDirs.rbegin()->first; @@ -6208,12 +6263,12 @@ int CRobotMain::AutosaveRotate(bool freeOne) int to_keep = m_autosaveSlots-(freeOne ? 1 : 0); int new_last_id = Math::Min(autosaveDirs.size(), to_keep); bool rotate = false; - for(int i = last_id; i > 0; i--) + for (int i = last_id; i > 0; i--) { - if(autosaveDirs.count(i) > 0) + if (autosaveDirs.count(i) > 0) { count++; - if(count > m_autosaveSlots-(freeOne ? 1 : 0) || !m_autosave) + if (count > m_autosaveSlots-(freeOne ? 1 : 0) || !m_autosave) { CLogger::GetInstancePointer()->Trace("Remove %s\n", autosaveDirs[i].c_str()); CResourceManager::RemoveDirectory(autosaveDirs[i]); @@ -6226,16 +6281,18 @@ int CRobotMain::AutosaveRotate(bool freeOne) } } } - + // Rename autosaves that we kept - if(rotate) { - for(auto& save : autosavesToKeep) { + if (rotate) + { + for (auto& save : autosavesToKeep) + { std::string newDir = std::string(GetSavegameDir()) + "/" + GetGamerName() + "/autosave" + boost::lexical_cast(save.first); CLogger::GetInstancePointer()->Trace("Rename %s -> %s\n", save.second.c_str(), newDir.c_str()); CResourceManager::Move(save.second, newDir); } } - + return rotate ? count : count+1; } @@ -6243,24 +6300,24 @@ void CRobotMain::Autosave() { int id = AutosaveRotate(true); CLogger::GetInstancePointer()->Info("Autosave!\n"); - + std::string dir = std::string(GetSavegameDir()) + "/" + GetGamerName() + "/autosave" + boost::lexical_cast(id); - + if (!CResourceManager::DirectoryExists(dir)) { CResourceManager::CreateDirectory(dir); } - + std::string savegameFileName = dir + "/data.sav"; std::string fileCBot = CResourceManager::GetSaveLocation() + "/" + dir + "/cbot.run"; char timestr[100]; TimeToAscii(time(NULL), timestr); IOWriteScene(savegameFileName.c_str(), fileCBot.c_str(), const_cast((std::string("[AUTOSAVE] ")+timestr).c_str())); - + m_dialog->MakeSaveScreenshot(dir + "/screen.png"); } void CRobotMain::SetExitAfterMission(bool exit) { m_exitAfterMission = exit; -} \ No newline at end of file +} diff --git a/src/object/task/taskgoto.cpp b/src/object/task/taskgoto.cpp index 8c90912e..442e15a4 100644 --- a/src/object/task/taskgoto.cpp +++ b/src/object/task/taskgoto.cpp @@ -1294,7 +1294,7 @@ bool CTaskGoto::GetHotPoint(CObject *pObj, Math::Vector &pos, bool CTaskGoto::LeakSearch(Math::Vector &pos, float &delay) { - CObject *pObj, *pObstacle = nullptr; + CObject *pObstacle = nullptr; Math::Vector iPos, oPos, bPos; float iRadius, oRadius, bRadius, dist, min, dir; int j; diff --git a/src/physics/physics.cpp b/src/physics/physics.cpp index 5822b6c3..4e0d1b13 100644 --- a/src/physics/physics.cpp +++ b/src/physics/physics.cpp @@ -175,12 +175,12 @@ PhysicsType CPhysics::GetType() bool CPhysics::Write(CLevelParserLine* line) { - line->AddParam("motor", new CLevelParserParam(m_motorSpeed)); + line->AddParam("motor", CLevelParserParamUPtr{new CLevelParserParam(m_motorSpeed)}); if ( m_type == TYPE_FLYING ) { - line->AddParam("reactorRange", new CLevelParserParam(GetReactorRange())); - line->AddParam("land", new CLevelParserParam(GetLand())); + line->AddParam("reactorRange", CLevelParserParamUPtr{new CLevelParserParam(GetReactorRange())}); + line->AddParam("land", CLevelParserParamUPtr{new CLevelParserParam(GetLand())}); } return true; diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index 1a78291d..190ca981 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -197,7 +197,7 @@ void CMainDialog::Create() m_engine = Gfx::CEngine::GetInstancePointer(); m_particle = m_engine->GetParticle(); m_pause = CPauseManager::GetInstancePointer(); - + m_setupFull = m_app->GetVideoConfig().fullScreen; } @@ -269,7 +269,7 @@ void CMainDialog::ChangePhase(Phase phase) ddim.x = 0.30f; ddim.y = 0.30f; pw->CreateGroup(pos, ddim, 4, EVENT_INTERFACE_GLINTr); // blue corner - + ddim.x = 0.20f; ddim.y = dim.y*2.4f; pos.x = 0.40f; @@ -289,7 +289,7 @@ void CMainDialog::ChangePhase(Phase phase) pos.y = oy+sy*1.9f; pg = pw->CreateGroup(pos, ddim, 26, EVENT_LABEL1); // red pg->SetState(STATE_SHADOW); - + ddim.x = 0.18f; ddim.y = dim.y*1; pos.x = 0.41f; @@ -332,19 +332,22 @@ void CMainDialog::ChangePhase(Phase phase) ddim.x = 0.09f; pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_USER); pb->SetState(STATE_SHADOW); - - try { - CLevelParser* level = new CLevelParser("levels/custom/config.txt"); - if(level->Exists()) { - level->Load(); - CLevelParserLine* line = level->Get("Button"); - if(line->GetParam("name")->IsDefined()) + + try + { + CLevelParser levelParser("levels/custom/config.txt"); + if (levelParser.Exists()) + { + levelParser.Load(); + CLevelParserLine* line = levelParser.Get("Button"); + if (line->GetParam("name")->IsDefined()) pb->SetName(line->GetParam("name")->AsString()); - if(line->GetParam("tooltip")->IsDefined()) + if (line->GetParam("tooltip")->IsDefined()) pb->SetTooltip(line->GetParam("tooltip")->AsString()); } } - catch(CLevelParserException& e) { + catch (CLevelParserException& e) + { CLogger::GetInstancePointer()->Error("Failed loading userlevel button name: %s\n", e.what()); } } @@ -1063,7 +1066,7 @@ void CMainDialog::ChangePhase(Phase phase) pc = pw->CreateCheck(pos, ddim, -1, EVENT_INTERFACE_FULL); pc->SetState(STATE_SHADOW); pc->SetState(STATE_CHECK, m_setupFull); - + #if !PLATFORM_LINUX ddim.x = 0.9f; ddim.y = 0.1f; @@ -1211,7 +1214,7 @@ void CMainDialog::ChangePhase(Phase phase) ddim.y = dim.y*1; pos.x = ox+sx*10; pos.y = oy+sy*2; - + pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_MIN); pb->SetState(STATE_SHADOW); pos.x += ddim.x; @@ -1234,7 +1237,7 @@ void CMainDialog::ChangePhase(Phase phase) //? pc = pw->CreateCheck(pos, ddim, -1, EVENT_INTERFACE_TOTO); //? pc->SetState(STATE_SHADOW); //? pos.y -= 0.048f; - + pc = pw->CreateCheck(pos, ddim, -1, EVENT_INTERFACE_MOVIES); pc->SetState(STATE_SHADOW); pos.y -= 0.048f; @@ -1257,7 +1260,7 @@ void CMainDialog::ChangePhase(Phase phase) pc = pw->CreateCheck(pos, ddim, -1, EVENT_INTERFACE_AUTOSAVE_ENABLE); pc->SetState(STATE_SHADOW); pos.y -= 0.048f; - + pos.y -= ddim.y; ddim.x = dim.x*2.5f; psl = pw->CreateSlider(pos, ddim, -1, EVENT_INTERFACE_AUTOSAVE_INTERVAL); @@ -1279,8 +1282,8 @@ void CMainDialog::ChangePhase(Phase phase) pl = pw->CreateLabel(pos, ddim, 0, EVENT_LABEL1, name); pl->SetTextAlign(Gfx::TEXT_ALIGN_LEFT); pos.y -= ddim.y/2; - - + + //? pos.y -= 0.048f; //? pc = pw->CreateCheck(pos, ddim, -1, EVENT_INTERFACE_NICERST); //? pc->SetState(STATE_SHADOW); @@ -1717,7 +1720,7 @@ void CMainDialog::ChangePhase(Phase phase) pl = pw->CreateLabel(pos, ddim, 0, EVENT_LABEL4, name); pl->SetFontType(Gfx::FONT_COURIER); pl->SetFontSize(Gfx::FONT_SIZE_SMALL); - + pos.x = 306.0f/640.0f; pos.y = 17.0f/480.0f; ddim.x = 30.0f/640.0f; @@ -1859,7 +1862,7 @@ bool CMainDialog::EventProcess(const Event &event) { m_shotDelay --; if ( m_shotDelay == 0 ) - { + { Math::IntPoint windowSize = m_engine->GetWindowSize(); m_engine->WriteScreenShot(m_shotName, windowSize.x, windowSize.y); @@ -2601,19 +2604,19 @@ bool CMainDialog::EventProcess(const Event &event) ChangeSetupButtons(); UpdateSetupButtons(); break; - + case EVENT_INTERFACE_AUTOSAVE_ENABLE: m_bAutosave = !m_bAutosave; m_main->SetAutosave(m_bAutosave); ChangeSetupButtons(); UpdateSetupButtons(); break; - + case EVENT_INTERFACE_AUTOSAVE_INTERVAL: ChangeSetupButtons(); UpdateSetupButtons(); break; - + case EVENT_INTERFACE_AUTOSAVE_SLOTS: ChangeSetupButtons(); UpdateSetupButtons(); @@ -2645,7 +2648,7 @@ bool CMainDialog::EventProcess(const Event &event) break; default: - if(event.type >= EVENT_INTERFACE_KEY && event.type <= EVENT_INTERFACE_KEY_END) + if (event.type >= EVENT_INTERFACE_KEY && event.type <= EVENT_INTERFACE_KEY_END) { ChangeKey(event.type); UpdateKey(); @@ -3345,7 +3348,7 @@ void CMainDialog::BuildScenePath(std::string &filename, char *base, int rank, bo //TODO: Support for more than 9 chapters int chapter = rank/100; int new_rank = rank%100; - + filename = CLevelParser::BuildScenePath(std::string(base), chapter, new_rank, sceneFile); } @@ -3980,13 +3983,13 @@ void CMainDialog::IOReadName() resume = std::string(m_sceneName) + " " + boost::lexical_cast(m_chap[m_index]+1); - CLevelParser* level = new CLevelParser(m_sceneName, m_chap[m_index]+1, 0); + CLevelParser levelParser(m_sceneName, m_chap[m_index]+1, 0); try { - level->Load(); - resume = level->Get("Title")->GetParam("resume")->AsString(); + levelParser.Load(); + resume = levelParser.Get("Title")->GetParam("resume")->AsString(); } - catch(CLevelParserException& e) + catch (CLevelParserException& e) { CLogger::GetInstancePointer()->Warn("%s\n", e.what()); } @@ -3994,7 +3997,6 @@ void CMainDialog::IOReadName() time(&now); TimeToAsciiClean(now, line); sprintf(name, "%s - %s %d", line, resume.c_str(), m_sel[m_index]+1); - delete level; pe->SetText(name); pe->SetCursor(strlen(name), 0); @@ -4018,7 +4020,7 @@ void CMainDialog::IOReadList() auto saveDirs = CResourceManager::ListDirectories(userSaveDir); //std::sort(saveDirs.begin(), saveDirs.end()); - + std::map sortedSaveDirs; std::map names; @@ -4027,15 +4029,14 @@ void CMainDialog::IOReadList() std::string savegameFile = userSaveDir + "/" + dir + "/" + "data.sav"; if (CResourceManager::Exists(savegameFile)) { - CLevelParser* level = new CLevelParser(savegameFile); - level->Load(); - int time = level->Get("Created")->GetParam("date")->AsInt(); + CLevelParser levelParser(savegameFile); + levelParser.Load(); + int time = levelParser.Get("Created")->GetParam("date")->AsInt(); sortedSaveDirs[time] = userSaveDir + "/" + dir; - names[time] = level->Get("Title")->GetParam("text")->AsString(); - delete level; + names[time] = levelParser.Get("Title")->GetParam("text")->AsString(); } } - + for (auto dir : sortedSaveDirs) { pl->SetItemName(m_saveList.size(), names[dir.first].c_str()); @@ -4052,10 +4053,10 @@ void CMainDialog::IOReadList() pl->SetSelect(m_saveList.size()); pl->ShowSelect(false); // shows the selected columns - + unsigned int i; std::string screenName; - + for ( i=0; i < m_saveList.size(); i++ ) { screenName = "textures/../" + m_saveList.at(i) + "/screen.png"; @@ -4197,7 +4198,7 @@ bool CMainDialog::IOWriteScene() m_main->IOWriteScene(savegameFileName.c_str(), fileCBot.c_str(), info); MakeSaveScreenshot(dir + "/screen.png"); - + return true; } @@ -4229,17 +4230,17 @@ bool CMainDialog::IOReadScene() std::string fileName = m_saveList.at(sel) + "/" + "data.sav"; std::string fileCbot = CResourceManager::GetSaveLocation()+"/"+m_saveList.at(sel) + "/" + "cbot.run"; - CLevelParser* level = new CLevelParser(fileName); - level->Load(); - - CLevelParserLine* line = level->Get("Mission"); + CLevelParser levelParser(fileName); + levelParser.Load(); + + CLevelParserLine* line = levelParser.Get("Mission"); strcpy(m_sceneName, line->GetParam("base")->AsString().c_str()); m_sceneRank = line->GetParam("rank")->AsInt(); - - if(std::string(m_sceneName) == "custom") + + if (std::string(m_sceneName) == "custom") { m_sceneRank = m_sceneRank%100; - + std::string dir = line->GetParam("dir")->AsString(); for ( i=0 ; iLoad(); - pl->SetItemName(j, level->Get("Title")->GetParam("text")->AsString().c_str()); + try + { + CLevelParser levelParser("custom", j+1, 0); + levelParser.Load(); + pl->SetItemName(j, levelParser.Get("Title")->GetParam("text")->AsString().c_str()); pl->SetEnable(j, true); - delete level; } - catch(CLevelParserException& e) + catch (CLevelParserException& e) { pl->SetItemName(j, (std::string("[ERROR]: ")+e.what()).c_str()); pl->SetEnable(j, false); @@ -4349,17 +4347,18 @@ void CMainDialog::UpdateSceneChap(int &chap) { for ( j=0 ; j<9 ; j++ ) { - CLevelParser* level = new CLevelParser(m_sceneName, j+1, 0); - if(!level->Exists()) + CLevelParser levelParser(m_sceneName, j+1, 0); + if (!levelParser.Exists()) break; - try { - level->Load(); - sprintf(line, "%d: %s", j+1, level->Get("Title")->GetParam("text")->AsString().c_str()); + try + { + levelParser.Load(); + sprintf(line, "%d: %s", j+1, levelParser.Get("Title")->GetParam("text")->AsString().c_str()); } - catch(CLevelParserException& e) { + catch (CLevelParserException& e) + { sprintf(line, "%s", (std::string("[ERROR]: ")+e.what()).c_str()); } - delete level; bPassed = GetGamerInfoPassed((j+1)*100); pl->SetItemName(j, line); @@ -4405,28 +4404,32 @@ void CMainDialog::UpdateSceneList(int chap, int &sel) if ( pl == 0 ) return; pl->Flush(); - - if(chap < 0) return; + + if (chap < 0) return; bool readAll = true; for ( j=0 ; j<99 ; j++ ) { - CLevelParser* level = new CLevelParser(m_sceneName, chap+1, j+1); - if(!level->Exists()) { + CLevelParser levelParser(m_sceneName, chap+1, j+1); + if (!levelParser.Exists()) + { readAll = true; break; - } else { - if(!readAll) + } + else + { + if (!readAll) break; } - try { - level->Load(); - sprintf(line, "%d: %s", j+1, level->Get("Title")->GetParam("text")->AsString().c_str()); + try + { + levelParser.Load(); + sprintf(line, "%d: %s", j+1, levelParser.Get("Title")->GetParam("text")->AsString().c_str()); } - catch(CLevelParserException& e) { + catch (CLevelParserException& e) + { sprintf(line, "%s", (std::string("[ERROR]: ")+e.what()).c_str()); } - delete level; bPassed = GetGamerInfoPassed((chap+1)*100+(j+1)); pl->SetItemName(j, line); @@ -4439,7 +4442,7 @@ void CMainDialog::UpdateSceneList(int chap, int &sel) } } - if(readAll) + if (readAll) { m_maxList = j; } @@ -4526,15 +4529,16 @@ void CMainDialog::UpdateSceneResume(int rank) m_bSceneSoluce = false; } } - - if(rank<100) return; - - try { - CLevelParser* level = new CLevelParser(m_sceneName, rank/100, rank%100); - level->Load(); - pe->SetText(level->Get("Resume")->GetParam("text")->AsString().c_str()); + + if (rank<100) return; + + try + { + CLevelParser levelParser(m_sceneName, rank/100, rank%100); + levelParser.Load(); + pe->SetText(levelParser.Get("Resume")->GetParam("text")->AsString().c_str()); } - catch(CLevelParserException& e) + catch (CLevelParserException& e) { pe->SetText((std::string("[ERROR]: ")+e.what()).c_str()); } @@ -4588,9 +4592,9 @@ void CMainDialog::ChangeDisplay() if ( pc == 0 ) return; bFull = pc->TestState(STATE_CHECK); m_setupFull = bFull; - + SetupMemorize(); - + #if !PLATFORM_LINUX // Windows causes problems, so we'll restart the game // Mac OS was not tested so let's restart just to be sure @@ -4598,7 +4602,7 @@ void CMainDialog::ChangeDisplay() #else std::vector modes; m_app->GetVideoResolutionList(modes, true, true); - + Gfx::DeviceConfig config = m_app->GetVideoConfig(); config.size = modes[m_setupSelMode]; config.fullScreen = bFull; @@ -4744,21 +4748,21 @@ void CMainDialog::UpdateSetupButtons() { pc->SetState(STATE_CHECK, m_bBlood); } - + pc = static_cast(pw->SearchControl(EVENT_INTERFACE_AUTOSAVE_ENABLE)); if ( pc != 0 ) { pc->SetState(STATE_CHECK, m_bAutosave); } - + ps = static_cast(pw->SearchControl(EVENT_INTERFACE_AUTOSAVE_INTERVAL)); if ( ps != 0 ) { ps->SetState(STATE_ENABLE, m_bAutosave); ps->SetVisibleValue(m_main->GetAutosaveInterval()); - + } - + ps = static_cast(pw->SearchControl(EVENT_INTERFACE_AUTOSAVE_SLOTS)); if ( ps != 0 ) { @@ -4930,14 +4934,14 @@ void CMainDialog::ChangeSetupButtons() value = ps->GetVisibleValue(); m_sound->SetMusicVolume(static_cast(value)); } - + ps = static_cast(pw->SearchControl(EVENT_INTERFACE_AUTOSAVE_INTERVAL)); if ( ps != 0 ) { value = ps->GetVisibleValue(); m_main->SetAutosaveInterval(static_cast(value)); } - + ps = static_cast(pw->SearchControl(EVENT_INTERFACE_AUTOSAVE_SLOTS)); if ( ps != 0 ) { @@ -5108,22 +5112,22 @@ void CMainDialog::SetupRecall() { m_bBlood = iValue; } - + if ( GetProfile().GetIntProperty("Setup", "Autosave", iValue) ) { m_bAutosave = iValue; } - + if ( GetProfile().GetIntProperty("Setup", "AutosaveInterval", iValue) ) { m_main->SetAutosaveInterval(iValue); } - + if ( GetProfile().GetIntProperty("Setup", "AutosaveSlots", iValue) ) { m_main->SetAutosaveSlots(iValue); } - + if ( GetProfile().GetIntProperty("Setup", "GroundShadow", iValue) ) { m_engine->SetShadow(iValue); @@ -5232,15 +5236,18 @@ void CMainDialog::SetupRecall() std::getline(resolution, ws, 'x'); std::getline(resolution, hs, 'x'); int w = 800, h = 600; - if(!ws.empty() && !hs.empty()) { + if (!ws.empty() && !hs.empty()) + { w = atoi(ws.c_str()); h = atoi(hs.c_str()); } std::vector modes; m_app->GetVideoResolutionList(modes, true, true); - for(auto it = modes.begin(); it != modes.end(); ++it) { - if(it->x == w && it->y == h) { + for (auto it = modes.begin(); it != modes.end(); ++it) + { + if (it->x == w && it->y == h) + { m_setupSelMode = it - modes.begin(); break; } @@ -5959,24 +5966,26 @@ bool CMainDialog::GetHimselfDamage() void CMainDialog::WriteGamerPerso(char *gamer) { - try { - CLevelParser* perso = new CLevelParser(GetSavegameDir()+"/"+gamer+"/face.gam"); - 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); + try + { + CLevelParser persoParser(GetSavegameDir()+"/"+gamer+"/face.gam"); + CLevelParserLineUPtr line; - perso->Save(); - delete perso; - } catch(CLevelParserException& e) { + line.reset(new CLevelParserLine("Head")); + line->AddParam("face", CLevelParserParamUPtr{new CLevelParserParam(m_perso.face)}); + line->AddParam("glasses", CLevelParserParamUPtr{new CLevelParserParam(m_perso.glasses)}); + line->AddParam("hair", CLevelParserParamUPtr{new CLevelParserParam(m_perso.colorHair)}); + persoParser.AddLine(std::move(line)); + + line.reset(new CLevelParserLine("Body")); + line->AddParam("combi", CLevelParserParamUPtr{new CLevelParserParam(m_perso.colorCombi)}); + line->AddParam("band", CLevelParserParamUPtr{new CLevelParserParam(m_perso.colorBand)}); + persoParser.AddLine(std::move(line)); + + persoParser.Save(); + } + catch (CLevelParserException& e) + { CLogger::GetInstancePointer()->Error("Unable to write personalized player apperance: %s\n", e.what()); } } @@ -5987,26 +5996,27 @@ void CMainDialog::ReadGamerPerso(char *gamer) { m_perso.face = 0; DefPerso(); - - if(!CResourceManager::Exists(GetSavegameDir()+"/"+gamer+"/face.gam")) + + if (!CResourceManager::Exists(GetSavegameDir()+"/"+gamer+"/face.gam")) return; - try { - CLevelParser* perso = new CLevelParser(GetSavegameDir()+"/"+gamer+"/face.gam"); - perso->Load(); + try + { + CLevelParser persoParser(GetSavegameDir()+"/"+gamer+"/face.gam"); + persoParser.Load(); CLevelParserLine* line; - - line = perso->Get("Head"); + + line = persoParser.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"); + + line = persoParser.Get("Body"); m_perso.colorCombi = line->GetParam("combi")->AsColor(); m_perso.colorBand = line->GetParam("band")->AsColor(); - - delete perso; - } catch(CLevelParserException& e) { + } + catch (CLevelParserException& e) + { CLogger::GetInstancePointer()->Error("Unable to read personalized player apperance: %s\n", e.what()); } } @@ -6078,30 +6088,31 @@ bool CMainDialog::ReadGamerInfo() m_sceneInfo[i].bPassed = false; } - if(!CResourceManager::Exists(GetSavegameDir()+"/"+m_main->GetGamerName()+"/"+m_sceneName+".gam")) + if (!CResourceManager::Exists(GetSavegameDir()+"/"+m_main->GetGamerName()+"/"+m_sceneName+".gam")) return false; - + CInputStream file; file.open(GetSavegameDir()+"/"+m_main->GetGamerName()+"/"+m_sceneName+".gam"); - if(!file.is_open()) { + if (!file.is_open()) + { CLogger::GetInstancePointer()->Error("Unable to read list of finished missions\n"); return false; } - + 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(!file.eof()) + while (!file.eof()) { std::getline(file, line); - - if(line == "") - { - break; - } - + + if (line == "") + { + break; + } + sscanf(line.c_str(), "Chapter %d: Scene %d: numTry=%d passed=%d\n", &chap, &i, &numTry, &passed); @@ -6125,7 +6136,8 @@ bool CMainDialog::WriteGamerInfo() COutputStream file; file.open(GetSavegameDir()+"/"+m_main->GetGamerName()+"/"+m_sceneName+".gam"); - if(!file.is_open()) { + if (!file.is_open()) + { CLogger::GetInstancePointer()->Error("Unable to read list of finished missions\n"); return false; }