From 8c84f012c6b435b523fd19b7c4b289f62fff8bd5 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Mon, 10 Nov 2014 17:15:34 +0100 Subject: [PATCH] Level state loading via CLevelParser --- src/object/auto/auto.cpp | 12 ++-- src/object/auto/auto.h | 2 +- src/object/auto/autoconvert.cpp | 11 ++- src/object/auto/autoconvert.h | 2 +- src/object/auto/autoderrick.cpp | 11 ++- src/object/auto/autoderrick.h | 2 +- src/object/auto/autodestroyer.cpp | 11 ++- src/object/auto/autodestroyer.h | 2 +- src/object/auto/autoegg.cpp | 17 +++-- src/object/auto/autoegg.h | 2 +- src/object/auto/autoenergy.cpp | 11 ++- src/object/auto/autoenergy.h | 2 +- src/object/auto/autofactory.cpp | 11 ++- src/object/auto/autofactory.h | 2 +- src/object/auto/autoinfo.cpp | 11 ++- src/object/auto/autoinfo.h | 2 +- src/object/auto/autolabo.cpp | 13 ++-- src/object/auto/autolabo.h | 2 +- src/object/auto/automush.cpp | 13 ++-- src/object/auto/automush.h | 2 +- src/object/auto/autonest.cpp | 13 ++-- src/object/auto/autonest.h | 2 +- src/object/auto/autonuclear.cpp | 11 ++- src/object/auto/autonuclear.h | 2 +- src/object/auto/autopara.cpp | 11 ++- src/object/auto/autopara.h | 2 +- src/object/auto/autorepair.cpp | 11 ++- src/object/auto/autorepair.h | 2 +- src/object/auto/autoresearch.cpp | 13 ++-- src/object/auto/autoresearch.h | 2 +- src/object/auto/autosafe.cpp | 11 ++- src/object/auto/autosafe.h | 2 +- src/object/auto/autotower.cpp | 21 +++--- src/object/auto/autotower.h | 2 +- src/object/brain.cpp | 4 +- src/object/brain.h | 2 +- src/object/motion/motion.cpp | 8 +-- src/object/motion/motion.h | 2 +- src/object/object.cpp | 113 ++++++++++++++++-------------- src/object/object.h | 2 +- src/object/robotmain.cpp | 98 ++++++++++++-------------- src/object/robotmain.h | 4 +- src/physics/physics.cpp | 8 +-- src/physics/physics.h | 2 +- 44 files changed, 233 insertions(+), 256 deletions(-) diff --git a/src/object/auto/auto.cpp b/src/object/auto/auto.cpp index a8386c54..4f12f2ff 100644 --- a/src/object/auto/auto.cpp +++ b/src/object/auto/auto.cpp @@ -440,13 +440,13 @@ bool CAuto::Write(CLevelParserLine* line) // Return all settings to the controller. -bool CAuto::Read(char *line) +bool CAuto::Read(CLevelParserLine* line) { - m_type = static_cast(OpInt(line, "aType", OBJECT_NULL)); - m_bBusy = OpInt(line, "aBusy", 0); - m_time = OpFloat(line, "aTime", 0.0f); - m_progressTime = OpFloat(line, "aProgressTime", 0.0f); - m_progressTotal = OpFloat(line, "aProgressTotal", 0.0f); + m_type = line->GetParam("aType")->AsObjectType(); + m_bBusy = line->GetParam("aBusy")->AsBool(); + m_time = line->GetParam("aTime")->AsFloat(); + m_progressTime = line->GetParam("aProgressTime")->AsFloat(); + m_progressTotal = line->GetParam("aProgressTotal")->AsFloat(); return false; } diff --git a/src/object/auto/auto.h b/src/object/auto/auto.h index 610c39bc..7053aa2b 100644 --- a/src/object/auto/auto.h +++ b/src/object/auto/auto.h @@ -82,7 +82,7 @@ public: virtual void SetMotor(bool bMotor); virtual bool Write(CLevelParserLine* line); - virtual bool Read(char *line); + virtual bool Read(CLevelParserLine* line); protected: void CheckInterface(Ui::CWindow *pw, EventType event, bool bState); diff --git a/src/object/auto/autoconvert.cpp b/src/object/auto/autoconvert.cpp index c588b94d..23e41a1c 100644 --- a/src/object/auto/autoconvert.cpp +++ b/src/object/auto/autoconvert.cpp @@ -380,15 +380,14 @@ bool CAutoConvert::Write(CLevelParserLine* line) // Restores all parameters of the controller. -bool CAutoConvert::Read(char *line) +bool CAutoConvert::Read(CLevelParserLine* line) { - if ( OpInt(line, "aExist", 0) == 0 ) return false; + if ( !line->GetParam("aExist")->AsBool(false) ) return false; CAuto::Read(line); - - m_phase = static_cast< AutoConvertPhase >(OpInt(line, "aPhase", ACP_WAIT)); - m_progress = OpFloat(line, "aProgress", 0.0f); - m_speed = OpFloat(line, "aSpeed", 1.0f); + m_phase = static_cast< AutoConvertPhase >(line->GetParam("aPhase")->AsInt(ACP_WAIT)); + m_progress = line->GetParam("aProgress")->AsFloat(0.0f); + m_speed = line->GetParam("aSpeed")->AsFloat(1.0f); m_lastParticle = 0.0f; diff --git a/src/object/auto/autoconvert.h b/src/object/auto/autoconvert.h index f28f0ac3..4fab9b0e 100644 --- a/src/object/auto/autoconvert.h +++ b/src/object/auto/autoconvert.h @@ -53,7 +53,7 @@ public: bool CreateInterface(bool bSelect); bool Write(CLevelParserLine* line); - bool Read(char *line); + bool Read(CLevelParserLine* line); protected: CObject* SearchStone(ObjectType type); diff --git a/src/object/auto/autoderrick.cpp b/src/object/auto/autoderrick.cpp index 6f067176..c8e93769 100644 --- a/src/object/auto/autoderrick.cpp +++ b/src/object/auto/autoderrick.cpp @@ -446,15 +446,14 @@ bool CAutoDerrick::Write(CLevelParserLine* line) // Restores all parameters of the controller. -bool CAutoDerrick::Read(char *line) +bool CAutoDerrick::Read(CLevelParserLine* line) { - if ( OpInt(line, "aExist", 0) == 0 ) return false; + if ( !line->GetParam("aExist")->AsBool(false) ) return false; CAuto::Read(line); - - m_phase = static_cast< AutoDerrickPhase >(OpInt(line, "aPhase", ADP_WAIT)); - m_progress = OpFloat(line, "aProgress", 0.0f); - m_speed = OpFloat(line, "aSpeed", 1.0f); + m_phase = static_cast< AutoDerrickPhase >(line->GetParam("aPhase")->AsInt(ADP_WAIT)); + m_progress = line->GetParam("aProgress")->AsFloat(0.0f); + m_speed = line->GetParam("aSpeed")->AsFloat(1.0f); m_lastParticle = 0.0f; diff --git a/src/object/auto/autoderrick.h b/src/object/auto/autoderrick.h index 052a4c26..36825083 100644 --- a/src/object/auto/autoderrick.h +++ b/src/object/auto/autoderrick.h @@ -52,7 +52,7 @@ public: bool CreateInterface(bool bSelect); bool Write(CLevelParserLine* line); - bool Read(char *line); + bool Read(CLevelParserLine* line); protected: CObject* SearchFret(); diff --git a/src/object/auto/autodestroyer.cpp b/src/object/auto/autodestroyer.cpp index 068a51e6..fa5c130f 100644 --- a/src/object/auto/autodestroyer.cpp +++ b/src/object/auto/autodestroyer.cpp @@ -375,15 +375,14 @@ bool CAutoDestroyer::Write(CLevelParserLine* line) // Restores all parameters of the controller. -bool CAutoDestroyer::Read(char *line) +bool CAutoDestroyer::Read(CLevelParserLine* line) { - if ( OpInt(line, "aExist", 0) == 0 ) return false; + if ( !line->GetParam("aExist")->AsBool(false) ) return false; CAuto::Read(line); - - m_phase = static_cast< AutoDestroyerPhase >(OpInt(line, "aPhase", ADEP_WAIT)); - m_progress = OpFloat(line, "aProgress", 0.0f); - m_speed = OpFloat(line, "aSpeed", 1.0f); + m_phase = static_cast< AutoDestroyerPhase >(line->GetParam("aPhase")->AsInt(ADEP_WAIT)); + m_progress = line->GetParam("aProgress")->AsFloat(0.0f); + m_speed = line->GetParam("aSpeed")->AsFloat(1.0f); m_lastParticle = 0.0f; diff --git a/src/object/auto/autodestroyer.h b/src/object/auto/autodestroyer.h index 73a2d340..5b3b86a2 100644 --- a/src/object/auto/autodestroyer.h +++ b/src/object/auto/autodestroyer.h @@ -53,7 +53,7 @@ public: bool CreateInterface(bool bSelect); bool Write(CLevelParserLine* line); - bool Read(char *line); + bool Read(CLevelParserLine* line); protected: CObject* SearchPlastic(); diff --git a/src/object/auto/autoegg.cpp b/src/object/auto/autoegg.cpp index 91ba585d..2a2af34f 100644 --- a/src/object/auto/autoegg.cpp +++ b/src/object/auto/autoegg.cpp @@ -331,18 +331,17 @@ bool CAutoEgg::Write(CLevelParserLine* line) // Restores all parameters of the controller. -bool CAutoEgg::Read(char *line) +bool CAutoEgg::Read(CLevelParserLine* line) { - if ( OpInt(line, "aExist", 0) == 0 ) return false; + if ( !line->GetParam("aExist")->AsBool(false) ) return false; CAuto::Read(line); - - m_phase = static_cast< AutoEggPhase >(OpInt(line, "aPhase", AEP_NULL)); - m_progress = OpFloat(line, "aProgress", 0.0f); - m_speed = OpFloat(line, "aSpeed", 1.0f); - m_type = OpTypeObject(line, "aParamType", OBJECT_NULL); - m_value = OpFloat(line, "aParamValue1", 0.0f); - OpString(line, "aParamString", m_string); + m_phase = static_cast< AutoEggPhase >(line->GetParam("aPhase")->AsInt(AEP_NULL)); + m_progress = line->GetParam("aProgress")->AsFloat(0.0f); + m_speed = line->GetParam("aSpeed")->AsFloat(1.0f); + m_type = line->GetParam("aParamType")->AsObjectType(OBJECT_NULL); + m_value = line->GetParam("aParamValue1")->AsFloat(0.0f); + strcpy(m_string, line->GetParam("aParamString")->AsString("").c_str()); return true; } diff --git a/src/object/auto/autoegg.h b/src/object/auto/autoegg.h index 79a583f2..e28eef1d 100644 --- a/src/object/auto/autoegg.h +++ b/src/object/auto/autoegg.h @@ -55,7 +55,7 @@ public: bool SetString(char *string); bool Write(CLevelParserLine* line); - bool Read(char *line); + bool Read(CLevelParserLine* line); protected: CObject* SearchAlien(); diff --git a/src/object/auto/autoenergy.cpp b/src/object/auto/autoenergy.cpp index 3e359561..b2371f1e 100644 --- a/src/object/auto/autoenergy.cpp +++ b/src/object/auto/autoenergy.cpp @@ -628,15 +628,14 @@ bool CAutoEnergy::Write(CLevelParserLine* line) // Restores all parameters of the controller. -bool CAutoEnergy::Read(char *line) +bool CAutoEnergy::Read(CLevelParserLine* line) { - if ( OpInt(line, "aExist", 0) == 0 ) return false; + if ( !line->GetParam("aExist")->AsBool(false) ) return false; CAuto::Read(line); - - m_phase = static_cast< AutoEnergyPhase >(OpInt(line, "aPhase", AENP_WAIT)); - m_progress = OpFloat(line, "aProgress", 0.0f); - m_speed = OpFloat(line, "aSpeed", 1.0f); + m_phase = static_cast< AutoEnergyPhase >(line->GetParam("aPhase")->AsInt(AENP_WAIT)); + m_progress = line->GetParam("aProgress")->AsFloat(0.0f); + m_speed = line->GetParam("aSpeed")->AsFloat(1.0f); m_lastUpdateTime = 0.0f; m_lastParticle = 0.0f; diff --git a/src/object/auto/autoenergy.h b/src/object/auto/autoenergy.h index ed11fb71..ec3cce12 100644 --- a/src/object/auto/autoenergy.h +++ b/src/object/auto/autoenergy.h @@ -52,7 +52,7 @@ public: bool CreateInterface(bool bSelect); bool Write(CLevelParserLine* line); - bool Read(char *line); + bool Read(CLevelParserLine* line); protected: void UpdateInterface(float rTime); diff --git a/src/object/auto/autofactory.cpp b/src/object/auto/autofactory.cpp index 67dc60bd..dc6bab1a 100644 --- a/src/object/auto/autofactory.cpp +++ b/src/object/auto/autofactory.cpp @@ -532,15 +532,14 @@ bool CAutoFactory::Write(CLevelParserLine* line) // Restores all parameters of the controller -bool CAutoFactory::Read(char *line) +bool CAutoFactory::Read(CLevelParserLine* line) { - if ( OpInt(line, "aExist", 0) == 0 ) return false; + if ( !line->GetParam("aExist")->AsBool(false) ) return false; CAuto::Read(line); - - m_phase = static_cast< AutoFactoryPhase >(OpInt(line, "aPhase", AFP_WAIT)); - m_progress = OpFloat(line, "aProgress", 0.0f); - m_speed = OpFloat(line, "aSpeed", 1.0f); + m_phase = static_cast< AutoFactoryPhase >(line->GetParam("aPhase")->AsInt(AFP_WAIT)); + m_progress = line->GetParam("aProgress")->AsFloat(0.0f); + m_speed = line->GetParam("aSpeed")->AsFloat(1.0f); m_lastParticle = 0.0f; m_fretPos = m_object->GetPosition(0); diff --git a/src/object/auto/autofactory.h b/src/object/auto/autofactory.h index a2320301..65186ff0 100644 --- a/src/object/auto/autofactory.h +++ b/src/object/auto/autofactory.h @@ -56,7 +56,7 @@ public: bool CreateInterface(bool bSelect); bool Write(CLevelParserLine* line); - bool Read(char *line); + bool Read(CLevelParserLine* line); protected: void UpdateInterface(); diff --git a/src/object/auto/autoinfo.cpp b/src/object/auto/autoinfo.cpp index b5a3db45..e1da37a8 100644 --- a/src/object/auto/autoinfo.cpp +++ b/src/object/auto/autoinfo.cpp @@ -495,15 +495,14 @@ bool CAutoInfo::Write(CLevelParserLine* line) // Restores all parameters of the controller. -bool CAutoInfo::Read(char *line) +bool CAutoInfo::Read(CLevelParserLine* line) { - if ( OpInt(line, "aExist", 0) == 0 ) return false; + if ( !line->GetParam("aExist")->AsBool(false) ) return false; CAuto::Read(line); - - m_phase = static_cast< AutoInfoPhase > (OpInt(line, "aPhase", AIP_WAIT)); - m_progress = OpFloat(line, "aProgress", 0.0f); - m_speed = OpFloat(line, "aSpeed", 1.0f); + m_phase = static_cast< AutoInfoPhase >(line->GetParam("aPhase")->AsInt(AIP_WAIT)); + m_progress = line->GetParam("aProgress")->AsFloat(0.0f); + m_speed = line->GetParam("aSpeed")->AsFloat(1.0f); m_lastParticle = 0.0f; diff --git a/src/object/auto/autoinfo.h b/src/object/auto/autoinfo.h index 5923cd03..ac9f729d 100644 --- a/src/object/auto/autoinfo.h +++ b/src/object/auto/autoinfo.h @@ -52,7 +52,7 @@ public: bool CreateInterface(bool bSelect); bool Write(CLevelParserLine* line); - bool Read(char *line); + bool Read(CLevelParserLine* line); protected: void UpdateInterface(float rTime); diff --git a/src/object/auto/autolabo.cpp b/src/object/auto/autolabo.cpp index 8145fa13..f9ae1041 100644 --- a/src/object/auto/autolabo.cpp +++ b/src/object/auto/autolabo.cpp @@ -604,16 +604,15 @@ bool CAutoLabo::Write(CLevelParserLine* line) // Restores all parameters of the controller. -bool CAutoLabo::Read(char *line) +bool CAutoLabo::Read(CLevelParserLine* line) { - if ( OpInt(line, "aExist", 0) == 0 ) return false; + if ( !line->GetParam("aExist")->AsBool(false) ) return false; CAuto::Read(line); - - m_phase = static_cast< AutoLaboPhase >(OpInt(line, "aPhase", ALAP_WAIT)); - m_progress = OpFloat(line, "aProgress", 0.0f); - m_speed = OpFloat(line, "aSpeed", 1.0f); - m_research = static_cast< ResearchType >(OpInt(line, "aResearch", 0)); + m_phase = static_cast< AutoLaboPhase >(line->GetParam("aPhase")->AsInt(ALAP_WAIT)); + m_progress = line->GetParam("aProgress")->AsFloat(0.0f); + m_speed = line->GetParam("aSpeed")->AsFloat(1.0f); + m_research = static_cast< ResearchType >(line->GetParam("aResearch")->AsInt(0)); m_lastParticle = 0.0f; diff --git a/src/object/auto/autolabo.h b/src/object/auto/autolabo.h index 8828dd94..84d3f677 100644 --- a/src/object/auto/autolabo.h +++ b/src/object/auto/autolabo.h @@ -56,7 +56,7 @@ public: bool CreateInterface(bool bSelect); bool Write(CLevelParserLine* line); - bool Read(char *line); + bool Read(CLevelParserLine* line); protected: void UpdateInterface(); diff --git a/src/object/auto/automush.cpp b/src/object/auto/automush.cpp index 958f3b32..836056c5 100644 --- a/src/object/auto/automush.cpp +++ b/src/object/auto/automush.cpp @@ -34,7 +34,7 @@ // Object's constructor. - CAutoMush::CAutoMush(CObject* object) : CAuto(object) +CAutoMush::CAutoMush(CObject* object) : CAuto(object) { Init(); } @@ -319,15 +319,14 @@ bool CAutoMush::Write(CLevelParserLine* line) // Restores all parameters of the controller. -bool CAutoMush::Read(char *line) +bool CAutoMush::Read(CLevelParserLine* line) { - if ( OpInt(line, "aExist", 0) == 0 ) return false; + if ( !line->GetParam("aExist")->AsBool(false) ) return false; CAuto::Read(line); - - m_phase = static_cast< AutoMushPhase >(OpInt(line, "aPhase", AMP_WAIT)); - m_progress = OpFloat(line, "aProgress", 0.0f); - m_speed = OpFloat(line, "aSpeed", 1.0f); + m_phase = static_cast< AutoMushPhase >(line->GetParam("aPhase")->AsInt(AMP_WAIT)); + m_progress = line->GetParam("aProgress")->AsFloat(0.0f); + m_speed = line->GetParam("aSpeed")->AsFloat(1.0f); m_lastParticle = 0.0f; diff --git a/src/object/auto/automush.h b/src/object/auto/automush.h index 183914de..273dcc40 100644 --- a/src/object/auto/automush.h +++ b/src/object/auto/automush.h @@ -50,7 +50,7 @@ public: Error GetError(); bool Write(CLevelParserLine* line); - bool Read(char *line); + bool Read(CLevelParserLine* line); protected: bool SearchTarget(); diff --git a/src/object/auto/autonest.cpp b/src/object/auto/autonest.cpp index 9855730b..94e09f6e 100644 --- a/src/object/auto/autonest.cpp +++ b/src/object/auto/autonest.cpp @@ -35,7 +35,7 @@ // Object's constructor. - CAutoNest::CAutoNest(CObject* object) : CAuto(object) +CAutoNest::CAutoNest(CObject* object) : CAuto(object) { Init(); } @@ -250,15 +250,14 @@ bool CAutoNest::Write(CLevelParserLine* line) // Restores all parameters of the controller. -bool CAutoNest::Read(char *line) +bool CAutoNest::Read(CLevelParserLine* line) { - if ( OpInt(line, "aExist", 0) == 0 ) return false; + if ( !line->GetParam("aExist")->AsBool(false) ) return false; CAuto::Read(line); - - m_phase = static_cast< AutoNestPhase >(OpInt(line, "aPhase", ANP_WAIT)); - m_progress = OpFloat(line, "aProgress", 0.0f); - m_speed = OpFloat(line, "aSpeed", 1.0f); + m_phase = static_cast< AutoNestPhase >(line->GetParam("aPhase")->AsInt(ANP_WAIT)); + m_progress = line->GetParam("aProgress")->AsFloat(0.0f); + m_speed = line->GetParam("aSpeed")->AsFloat(1.0f); m_lastParticle = 0.0f; diff --git a/src/object/auto/autonest.h b/src/object/auto/autonest.h index acbc6600..c3279dfe 100644 --- a/src/object/auto/autonest.h +++ b/src/object/auto/autonest.h @@ -47,7 +47,7 @@ public: Error GetError(); bool Write(CLevelParserLine* line); - bool Read(char *line); + bool Read(CLevelParserLine* line); protected: bool SearchFree(Math::Vector pos); diff --git a/src/object/auto/autonuclear.cpp b/src/object/auto/autonuclear.cpp index 54a0edac..a779bd3b 100644 --- a/src/object/auto/autonuclear.cpp +++ b/src/object/auto/autonuclear.cpp @@ -463,15 +463,14 @@ bool CAutoNuclear::Write(CLevelParserLine* line) // Restores all parameters of the controller. -bool CAutoNuclear::Read(char *line) +bool CAutoNuclear::Read(CLevelParserLine* line) { - if ( OpInt(line, "aExist", 0) == 0 ) return false; + if ( !line->GetParam("aExist")->AsBool(false) ) return false; CAuto::Read(line); - - m_phase = static_cast< AutoNuclearPhase >(OpInt(line, "aPhase", ANUP_WAIT)); - m_progress = OpFloat(line, "aProgress", 0.0f); - m_speed = OpFloat(line, "aSpeed", 1.0f); + m_phase = static_cast< AutoNuclearPhase >(line->GetParam("aPhase")->AsInt(ANUP_WAIT)); + m_progress = line->GetParam("aProgress")->AsFloat(0.0f); + m_speed = line->GetParam("aSpeed")->AsFloat(1.0f); m_lastParticle = 0.0f; diff --git a/src/object/auto/autonuclear.h b/src/object/auto/autonuclear.h index f513e5b5..e21ecc20 100644 --- a/src/object/auto/autonuclear.h +++ b/src/object/auto/autonuclear.h @@ -52,7 +52,7 @@ public: bool CreateInterface(bool bSelect); bool Write(CLevelParserLine* line); - bool Read(char *line); + bool Read(CLevelParserLine* line); protected: CObject* SearchUranium(); diff --git a/src/object/auto/autopara.cpp b/src/object/auto/autopara.cpp index 779a897c..0149f8ba 100644 --- a/src/object/auto/autopara.cpp +++ b/src/object/auto/autopara.cpp @@ -307,15 +307,14 @@ bool CAutoPara::Write(CLevelParserLine* line) // Restores all parameters of the controller. -bool CAutoPara::Read(char *line) +bool CAutoPara::Read(CLevelParserLine* line) { - if ( OpInt(line, "aExist", 0) == 0 ) return false; + if ( !line->GetParam("aExist")->AsBool(false) ) return false; CAuto::Read(line); - - m_phase = static_cast< AutoParaPhase >(OpInt(line, "aPhase", APAP_WAIT)); - m_progress = OpFloat(line, "aProgress", 0.0f); - m_speed = OpFloat(line, "aSpeed", 1.0f); + m_phase = static_cast< AutoParaPhase >(line->GetParam("aPhase")->AsInt(APAP_WAIT)); + m_progress = line->GetParam("aProgress")->AsFloat(0.0f); + m_speed = line->GetParam("aSpeed")->AsFloat(1.0f); m_lastParticle = 0.0f; diff --git a/src/object/auto/autopara.h b/src/object/auto/autopara.h index 27a3fc35..ec2c9722 100644 --- a/src/object/auto/autopara.h +++ b/src/object/auto/autopara.h @@ -51,7 +51,7 @@ public: bool CreateInterface(bool bSelect); bool Write(CLevelParserLine* line); - bool Read(char *line); + bool Read(CLevelParserLine* line); protected: void ChargeObject(float rTime); diff --git a/src/object/auto/autorepair.cpp b/src/object/auto/autorepair.cpp index 0e49d5cc..5a88df2f 100644 --- a/src/object/auto/autorepair.cpp +++ b/src/object/auto/autorepair.cpp @@ -320,15 +320,14 @@ bool CAutoRepair::Write(CLevelParserLine* line) // Restores all parameters of the controller. -bool CAutoRepair::Read(char *line) +bool CAutoRepair::Read(CLevelParserLine* line) { - if ( OpInt(line, "aExist", 0) == 0 ) return false; + if ( !line->GetParam("aExist")->AsBool(false) ) return false; CAuto::Read(line); - - m_phase = static_cast< AutoRepairPhase >(OpInt(line, "aPhase", ARP_WAIT)); - m_progress = OpFloat(line, "aProgress", 0.0f); - m_speed = OpFloat(line, "aSpeed", 1.0f); + m_phase = static_cast< AutoRepairPhase >(line->GetParam("aPhase")->AsInt(ARP_WAIT)); + m_progress = line->GetParam("aProgress")->AsFloat(0.0f); + m_speed = line->GetParam("aSpeed")->AsFloat(1.0f); m_lastParticle = 0.0f; diff --git a/src/object/auto/autorepair.h b/src/object/auto/autorepair.h index d59083fb..a82a4797 100644 --- a/src/object/auto/autorepair.h +++ b/src/object/auto/autorepair.h @@ -52,7 +52,7 @@ public: bool CreateInterface(bool bSelect); bool Write(CLevelParserLine* line); - bool Read(char *line); + bool Read(CLevelParserLine* line); protected: CObject* SearchVehicle(); diff --git a/src/object/auto/autoresearch.cpp b/src/object/auto/autoresearch.cpp index d36342c6..dc9e437b 100644 --- a/src/object/auto/autoresearch.cpp +++ b/src/object/auto/autoresearch.cpp @@ -581,16 +581,15 @@ bool CAutoResearch::Write(CLevelParserLine* line) // Restores all parameters of the controller. -bool CAutoResearch::Read(char *line) +bool CAutoResearch::Read(CLevelParserLine* line) { - if ( OpInt(line, "aExist", 0) == 0 ) return false; + if ( !line->GetParam("aExist")->AsBool(false) ) return false; CAuto::Read(line); - - m_phase = static_cast< AutoResearchPhase >(OpInt(line, "aPhase", ALP_WAIT)); - m_progress = OpFloat(line, "aProgress", 0.0f); - m_speed = OpFloat(line, "aSpeed", 1.0f); - m_research = static_cast< ResearchType >(OpInt(line, "aResearch", 0)); + m_phase = static_cast< AutoResearchPhase >(line->GetParam("aPhase")->AsInt(ALP_WAIT)); + m_progress = line->GetParam("aProgress")->AsFloat(0.0f); + m_speed = line->GetParam("aSpeed")->AsFloat(1.0f); + m_research = static_cast< ResearchType >(line->GetParam("aResearch")->AsInt(0)); m_lastUpdateTime = 0.0f; m_lastParticle = 0.0f; diff --git a/src/object/auto/autoresearch.h b/src/object/auto/autoresearch.h index 9cb7c28d..c819d520 100644 --- a/src/object/auto/autoresearch.h +++ b/src/object/auto/autoresearch.h @@ -50,7 +50,7 @@ public: bool CreateInterface(bool bSelect); bool Write(CLevelParserLine* line); - bool Read(char *line); + bool Read(CLevelParserLine* line); protected: void UpdateInterface(); diff --git a/src/object/auto/autosafe.cpp b/src/object/auto/autosafe.cpp index 1f4a0ac1..f51243c9 100644 --- a/src/object/auto/autosafe.cpp +++ b/src/object/auto/autosafe.cpp @@ -370,15 +370,14 @@ bool CAutoSafe::Write(CLevelParserLine* line) // Restores all parameters of the controller. -bool CAutoSafe::Read(char *line) +bool CAutoSafe::Read(CLevelParserLine* line) { - if ( OpInt(line, "aExist", 0) == 0 ) return false; + if ( !line->GetParam("aExist")->AsBool(false) ) return false; CAuto::Read(line); - - m_phase = static_cast< AutoSafePhase >(OpInt(line, "aPhase", ASAP_WAIT)); - m_progress = OpFloat(line, "aProgress", 0.0f); - m_speed = OpFloat(line, "aSpeed", 1.0f); + m_phase = static_cast< AutoSafePhase >(line->GetParam("aPhase")->AsInt(ASAP_WAIT)); + m_progress = line->GetParam("aProgress")->AsFloat(0.0f); + m_speed = line->GetParam("aSpeed")->AsFloat(1.0f); m_lastParticle = 0.0f; diff --git a/src/object/auto/autosafe.h b/src/object/auto/autosafe.h index 7885a421..fa8ed834 100644 --- a/src/object/auto/autosafe.h +++ b/src/object/auto/autosafe.h @@ -50,7 +50,7 @@ public: bool CreateInterface(bool bSelect); bool Write(CLevelParserLine* line); - bool Read(char *line); + bool Read(CLevelParserLine* line); protected: int CountKeys(); diff --git a/src/object/auto/autotower.cpp b/src/object/auto/autotower.cpp index 39233a1a..7e676716 100644 --- a/src/object/auto/autotower.cpp +++ b/src/object/auto/autotower.cpp @@ -508,20 +508,19 @@ bool CAutoTower::Write(CLevelParserLine* line) // Restores all parameters of the controller. -bool CAutoTower::Read(char *line) +bool CAutoTower::Read(CLevelParserLine* line) { - if ( OpInt(line, "aExist", 0) == 0 ) return false; + if ( !line->GetParam("aExist")->AsBool(false) ) return false; CAuto::Read(line); - - m_phase = static_cast< AutoTowerPhase >(OpInt(line, "aPhase", ATP_WAIT)); - m_progress = OpFloat(line, "aProgress", 0.0f); - m_speed = OpFloat(line, "aSpeed", 1.0f); - m_targetPos = OpDir(line, "aTargetPos"); - m_angleYactual = OpFloat(line, "aAngleYactual", 0.0f); - m_angleZactual = OpFloat(line, "aAngleZactual", 0.0f); - m_angleYfinal = OpFloat(line, "aAngleYfinal", 0.0f); - m_angleZfinal = OpFloat(line, "aAngleZfinal", 0.0f); + m_phase = static_cast< AutoTowerPhase >(line->GetParam("aPhase")->AsInt(ATP_WAIT)); + m_progress = line->GetParam("aProgress")->AsFloat(0.0f); + m_speed = line->GetParam("aSpeed")->AsFloat(1.0f); + m_targetPos = line->GetParam("aTargetPos")->AsPoint(Math::Vector()); + m_angleYactual = line->GetParam("aAngleYactual")->AsFloat(0.0f); + m_angleZactual = line->GetParam("aAngleZactual")->AsFloat(0.0f); + m_angleYfinal = line->GetParam("aAngleYfinal")->AsFloat(0.0f); + m_angleZfinal = line->GetParam("aAngleZfinal")->AsFloat(0.0f); m_lastUpdateTime = 0.0f; diff --git a/src/object/auto/autotower.h b/src/object/auto/autotower.h index 3333ee33..67982399 100644 --- a/src/object/auto/autotower.h +++ b/src/object/auto/autotower.h @@ -52,7 +52,7 @@ public: bool CreateInterface(bool bSelect); bool Write(CLevelParserLine* line); - bool Read(char *line); + bool Read(CLevelParserLine* line); protected: void UpdateInterface(float rTime); diff --git a/src/object/brain.cpp b/src/object/brain.cpp index d8a810af..0a723b09 100644 --- a/src/object/brain.cpp +++ b/src/object/brain.cpp @@ -180,9 +180,9 @@ bool CBrain::Write(CLevelParserLine* line) // Restores all parameters of the object. -bool CBrain::Read(char *line) +bool CBrain::Read(CLevelParserLine* line) { - m_bActiveVirus = OpInt(line, "bVirusActive", 0); + m_bActiveVirus = line->GetParam("bVirusActive")->AsBool(false); return true; } diff --git a/src/object/brain.h b/src/object/brain.h index 5d2983b8..c1172695 100644 --- a/src/object/brain.h +++ b/src/object/brain.h @@ -94,7 +94,7 @@ public: bool CreateInterface(bool bSelect); bool Write(CLevelParserLine* line); - bool Read(char *line); + bool Read(CLevelParserLine* line); bool IsBusy(); void SetActivity(bool bMode); diff --git a/src/object/motion/motion.cpp b/src/object/motion/motion.cpp index 225cc714..d7044937 100644 --- a/src/object/motion/motion.cpp +++ b/src/object/motion/motion.cpp @@ -186,11 +186,11 @@ bool CMotion::Write(CLevelParserLine* line) // Restores all parameters of the object. -bool CMotion::Read(char *line) +bool CMotion::Read(CLevelParserLine* line) { - m_actionType = OpInt(line, "mType", -1); - m_actionTime = OpFloat(line, "mTime", 0.0f); - m_progress = OpFloat(line, "mProgress", 0.0f); + m_actionType = line->GetParam("mType")->AsInt(-1); + m_actionTime = line->GetParam("mTime")->AsFloat(0.0f); + m_progress = line->GetParam("mProgress")->AsFloat(0.0f); return false; } diff --git a/src/object/motion/motion.h b/src/object/motion/motion.h index d534eb5d..a116b3fc 100644 --- a/src/object/motion/motion.h +++ b/src/object/motion/motion.h @@ -64,7 +64,7 @@ public: virtual float GetParam(int rank); virtual bool Write(CLevelParserLine* line); - virtual bool Read(char *line); + virtual bool Read(CLevelParserLine* line); virtual void SetLinVibration(Math::Vector dir); virtual Math::Vector GetLinVibration(); diff --git a/src/object/object.cpp b/src/object/object.cpp index 1c5f930c..c2c7f7b7 100644 --- a/src/object/object.cpp +++ b/src/object/object.cpp @@ -78,6 +78,7 @@ #include "object/objman.h" #include "object/level/parserline.h" #include "object/level/parserparam.h" +#include "object/level/parserexceptions.h" #include "physics/physics.h" @@ -1084,29 +1085,29 @@ bool CObject::Write(CLevelParserLine* line) for ( i=0 ; i 0) line->AddParam("cmdline", new CLevelParserParam(cmdline)); - if ( m_motion != 0 ) + if ( m_motion != nullptr ) { m_motion->Write(line); } - if ( m_brain != 0 ) + if ( m_brain != nullptr ) { m_brain->Write(line); } - if ( m_physics != 0 ) + if ( m_physics != nullptr ) { m_physics->Write(line); } - if ( m_auto != 0 ) + if ( m_auto != nullptr ) { m_auto->Write(line); } @@ -1116,87 +1117,91 @@ bool CObject::Write(CLevelParserLine* line) // Returns all parameters of the object. -bool CObject::Read(char *line) +bool CObject::Read(CLevelParserLine* line) { Math::Vector pos, dir; - Info info; Gfx::CameraType cType; - char op[20]; - char text[100]; - char* p; - float value; int i; - cType = OpCamera(line, "camera"); + cType = line->GetParam("camera")->AsCameraType(Gfx::CAM_TYPE_NULL); if ( cType != Gfx::CAM_TYPE_NULL ) { SetCameraType(cType); } - SetCameraLock(OpInt(line, "cameraLock", 0)); - SetEnergy(OpFloat(line, "energy", 0.0f)); - SetCapacity(OpFloat(line, "capacity", 1.0f)); - SetShield(OpFloat(line, "shield", 1.0f)); - SetRange(OpFloat(line, "range", 1.0f)); - SetSelectable(OpInt(line, "selectable", 1)); - SetEnable(OpInt(line, "enable", 1)); - SetFixed(OpInt(line, "fixed", 0)); - SetClip(OpInt(line, "clip", 1)); - SetLock(OpInt(line, "lock", 0)); - SetProxyActivate(OpInt(line, "proxyActivate", 0)); - SetProxyDistance(OpFloat(line, "proxyDistance", 15.0f)*g_unit); - SetRange(OpFloat(line, "range", 30.0f)); - SetMagnifyDamage(OpFloat(line, "magnifyDamage", 1.0f)); - SetGunGoalV(OpFloat(line, "aimV", 0.0f)); - SetGunGoalH(OpFloat(line, "aimH", 0.0f)); - SetParam(OpFloat(line, "param", 0.0f)); - SetResetCap(static_cast(OpInt(line, "resetCap", 0))); - SetResetPosition(OpDir(line, "resetPos")*g_unit); - SetResetAngle(OpDir(line, "resetAngle")*(Math::PI/180.0f)); - SetResetRun(OpInt(line, "resetRun", 0)); - m_bBurn = OpInt(line, "burnMode", 0); - m_bVirusMode = OpInt(line, "virusMode", 0); - m_virusTime = OpFloat(line, "virusTime", 0.0f); + SetCameraLock(line->GetParam("cameraLock")->AsBool(false)); + SetEnergy(line->GetParam("energy")->AsFloat(0.0f)); + SetCapacity(line->GetParam("capacity")->AsFloat(1.0f)); + SetShield(line->GetParam("shield")->AsFloat(1.0f)); + SetRange(line->GetParam("range")->AsFloat(1.0f)); + SetSelectable(line->GetParam("selectable")->AsBool(true)); + SetEnable(line->GetParam("enable")->AsBool(true)); + SetFixed(line->GetParam("fixed")->AsBool(false)); + SetClip(line->GetParam("clip")->AsBool(true)); + SetLock(line->GetParam("lock")->AsBool(false)); + SetProxyActivate(line->GetParam("proxyActivate")->AsBool(false)); + SetProxyDistance(line->GetParam("proxyDistance")->AsFloat(15.0f)*g_unit); + SetRange(line->GetParam("range")->AsFloat(30.0f)); + SetMagnifyDamage(line->GetParam("magnifyDamage")->AsFloat(1.0f)); + SetGunGoalV(line->GetParam("aimV")->AsFloat(0.0f)); + SetGunGoalH(line->GetParam("aimH")->AsFloat(0.0f)); + SetParam(line->GetParam("param")->AsFloat(0.0f)); + SetResetCap(static_cast(line->GetParam("resetCap")->AsInt(0))); + SetResetPosition(line->GetParam("resetPos")->AsPoint(Math::Vector())*g_unit); + SetResetAngle(line->GetParam("resetAngle")->AsPoint(Math::Vector())*(Math::PI/180.0f)); + SetResetRun(line->GetParam("resetRun")->AsInt(0)); + m_bBurn = line->GetParam("burnMode")->AsBool(false); + m_bVirusMode = line->GetParam("virusMode")->AsBool(false); + m_virusTime = line->GetParam("virusTime")->AsFloat(0.0f); // Puts information in terminal (OBJECT_INFO). for ( i=0 ; iZoomMap(OpFloat(line, "zoom", 1.0f)); - - if (Cmd(line, "DoneResearch")) - g_researchDone = OpInt(line, "bits", 0); - - if (Cmd(line, "BlitzMode")) - { - float sleep = OpFloat(line, "sleep", 0.0f); - float delay = OpFloat(line, "delay", 3.0f); - float magnetic = OpFloat(line, "magnetic", 50.0f)*g_unit; - float progress = OpFloat(line, "progress", 0.0f); + float sleep = line->GetParam("sleep")->AsFloat(); + float delay = line->GetParam("delay")->AsFloat(); + float magnetic = line->GetParam("magnetic")->AsFloat()*g_unit; + float progress = line->GetParam("progress")->AsFloat(); m_lightning->SetStatus(sleep, delay, magnetic, progress); } - if (Cmd(line, "CreateFret")) + if (line->GetCommand() == "CreateFret") fret = IOReadObject(line, filename, -1); - if (Cmd(line, "CreatePower")) + if (line->GetCommand() == "CreatePower") power = IOReadObject(line, filename, -1); - if (Cmd(line, "CreateObject")) + if (line->GetCommand() == "CreateObject") { CObject* obj = IOReadObject(line, filename, objRank++); - if (OpInt(line, "select", 0)) + if (line->GetParam("select")->AsBool(false)) sel = obj; if (fret != nullptr) @@ -5999,7 +5987,7 @@ CObject* CRobotMain::IOReadScene(const char *filename, const char *filecbot) power = nullptr; } } - fclose(file); + delete level; #if CBOT_STACK CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); @@ -6026,7 +6014,7 @@ CObject* CRobotMain::IOReadScene(const char *filename, const char *filecbot) while (nbError > 0 && nbError != lastError); // Reads the file of stacks of execution. - file = fOpen(filecbot, "rb"); + FILE* file = fOpen(filecbot, "rb"); if (file != NULL) { long version; diff --git a/src/object/robotmain.h b/src/object/robotmain.h index 60eb6844..f83d9301 100644 --- a/src/object/robotmain.h +++ b/src/object/robotmain.h @@ -384,8 +384,8 @@ public: bool IsBusy(); bool IOWriteScene(const char *filename, const char *filecbot, char *info); CObject* IOReadScene(const char *filename, const char *filecbot); - void IOWriteObject(CLevelParserLine *file, CObject* pObj); - CObject* IOReadObject(char *line, const char* filename, int objRank); + void IOWriteObject(CLevelParserLine *line, CObject* obj); + CObject* IOReadObject(CLevelParserLine *line, const char* filename, int objRank); int CreateSpot(Math::Vector pos, Gfx::Color color); diff --git a/src/physics/physics.cpp b/src/physics/physics.cpp index d98334a4..6de35dc1 100644 --- a/src/physics/physics.cpp +++ b/src/physics/physics.cpp @@ -188,14 +188,14 @@ bool CPhysics::Write(CLevelParserLine* line) // Restores all parameters of the object. -bool CPhysics::Read(char *line) +bool CPhysics::Read(CLevelParserLine* line) { - m_motorSpeed = OpDir(line, "motor"); + m_motorSpeed = line->GetParam("motor")->AsPoint(); if ( m_type == TYPE_FLYING ) { - SetReactorRange(OpFloat(line, "reactorRange", 0.0f)); - SetLand(OpInt(line, "land", 0)); + SetReactorRange(line->GetParam("reactorRange")->AsFloat()); + SetLand(line->GetParam("land")->AsBool()); } return true; diff --git a/src/physics/physics.h b/src/physics/physics.h index 831bbfce..e8996aee 100644 --- a/src/physics/physics.h +++ b/src/physics/physics.h @@ -112,7 +112,7 @@ public: PhysicsType GetType(); bool Write(CLevelParserLine* line); - bool Read(char *line); + bool Read(CLevelParserLine* line); void SetGravity(float value); float GetGravity();