Level state loading via CLevelParser

dev-mp
krzys-h 2014-11-10 17:15:34 +01:00
parent 3dade17f89
commit 8c84f012c6
44 changed files with 233 additions and 256 deletions

View File

@ -440,13 +440,13 @@ bool CAuto::Write(CLevelParserLine* line)
// Return all settings to the controller. // Return all settings to the controller.
bool CAuto::Read(char *line) bool CAuto::Read(CLevelParserLine* line)
{ {
m_type = static_cast<ObjectType>(OpInt(line, "aType", OBJECT_NULL)); m_type = line->GetParam("aType")->AsObjectType();
m_bBusy = OpInt(line, "aBusy", 0); m_bBusy = line->GetParam("aBusy")->AsBool();
m_time = OpFloat(line, "aTime", 0.0f); m_time = line->GetParam("aTime")->AsFloat();
m_progressTime = OpFloat(line, "aProgressTime", 0.0f); m_progressTime = line->GetParam("aProgressTime")->AsFloat();
m_progressTotal = OpFloat(line, "aProgressTotal", 0.0f); m_progressTotal = line->GetParam("aProgressTotal")->AsFloat();
return false; return false;
} }

View File

@ -82,7 +82,7 @@ public:
virtual void SetMotor(bool bMotor); virtual void SetMotor(bool bMotor);
virtual bool Write(CLevelParserLine* line); virtual bool Write(CLevelParserLine* line);
virtual bool Read(char *line); virtual bool Read(CLevelParserLine* line);
protected: protected:
void CheckInterface(Ui::CWindow *pw, EventType event, bool bState); void CheckInterface(Ui::CWindow *pw, EventType event, bool bState);

View File

@ -380,15 +380,14 @@ bool CAutoConvert::Write(CLevelParserLine* line)
// Restores all parameters of the controller. // Restores all parameters of the controller.
bool CAutoConvert::Read(char *line) bool CAutoConvert::Read(CLevelParserLine* line)
{ {
if ( OpInt(line, "aExist", 0) == 0 ) return false; if ( !line->GetParam("aExist")->AsBool(false) ) return false;
CAuto::Read(line); CAuto::Read(line);
m_phase = static_cast< AutoConvertPhase >(line->GetParam("aPhase")->AsInt(ACP_WAIT));
m_phase = static_cast< AutoConvertPhase >(OpInt(line, "aPhase", ACP_WAIT)); m_progress = line->GetParam("aProgress")->AsFloat(0.0f);
m_progress = OpFloat(line, "aProgress", 0.0f); m_speed = line->GetParam("aSpeed")->AsFloat(1.0f);
m_speed = OpFloat(line, "aSpeed", 1.0f);
m_lastParticle = 0.0f; m_lastParticle = 0.0f;

View File

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

View File

@ -446,15 +446,14 @@ bool CAutoDerrick::Write(CLevelParserLine* line)
// Restores all parameters of the controller. // Restores all parameters of the controller.
bool CAutoDerrick::Read(char *line) bool CAutoDerrick::Read(CLevelParserLine* line)
{ {
if ( OpInt(line, "aExist", 0) == 0 ) return false; if ( !line->GetParam("aExist")->AsBool(false) ) return false;
CAuto::Read(line); CAuto::Read(line);
m_phase = static_cast< AutoDerrickPhase >(line->GetParam("aPhase")->AsInt(ADP_WAIT));
m_phase = static_cast< AutoDerrickPhase >(OpInt(line, "aPhase", ADP_WAIT)); m_progress = line->GetParam("aProgress")->AsFloat(0.0f);
m_progress = OpFloat(line, "aProgress", 0.0f); m_speed = line->GetParam("aSpeed")->AsFloat(1.0f);
m_speed = OpFloat(line, "aSpeed", 1.0f);
m_lastParticle = 0.0f; m_lastParticle = 0.0f;

View File

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

View File

@ -375,15 +375,14 @@ bool CAutoDestroyer::Write(CLevelParserLine* line)
// Restores all parameters of the controller. // Restores all parameters of the controller.
bool CAutoDestroyer::Read(char *line) bool CAutoDestroyer::Read(CLevelParserLine* line)
{ {
if ( OpInt(line, "aExist", 0) == 0 ) return false; if ( !line->GetParam("aExist")->AsBool(false) ) return false;
CAuto::Read(line); CAuto::Read(line);
m_phase = static_cast< AutoDestroyerPhase >(line->GetParam("aPhase")->AsInt(ADEP_WAIT));
m_phase = static_cast< AutoDestroyerPhase >(OpInt(line, "aPhase", ADEP_WAIT)); m_progress = line->GetParam("aProgress")->AsFloat(0.0f);
m_progress = OpFloat(line, "aProgress", 0.0f); m_speed = line->GetParam("aSpeed")->AsFloat(1.0f);
m_speed = OpFloat(line, "aSpeed", 1.0f);
m_lastParticle = 0.0f; m_lastParticle = 0.0f;

View File

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

View File

@ -331,18 +331,17 @@ bool CAutoEgg::Write(CLevelParserLine* line)
// Restores all parameters of the controller. // Restores all parameters of the controller.
bool CAutoEgg::Read(char *line) bool CAutoEgg::Read(CLevelParserLine* line)
{ {
if ( OpInt(line, "aExist", 0) == 0 ) return false; if ( !line->GetParam("aExist")->AsBool(false) ) return false;
CAuto::Read(line); CAuto::Read(line);
m_phase = static_cast< AutoEggPhase >(line->GetParam("aPhase")->AsInt(AEP_NULL));
m_phase = static_cast< AutoEggPhase >(OpInt(line, "aPhase", AEP_NULL)); m_progress = line->GetParam("aProgress")->AsFloat(0.0f);
m_progress = OpFloat(line, "aProgress", 0.0f); m_speed = line->GetParam("aSpeed")->AsFloat(1.0f);
m_speed = OpFloat(line, "aSpeed", 1.0f); m_type = line->GetParam("aParamType")->AsObjectType(OBJECT_NULL);
m_type = OpTypeObject(line, "aParamType", OBJECT_NULL); m_value = line->GetParam("aParamValue1")->AsFloat(0.0f);
m_value = OpFloat(line, "aParamValue1", 0.0f); strcpy(m_string, line->GetParam("aParamString")->AsString("").c_str());
OpString(line, "aParamString", m_string);
return true; return true;
} }

View File

@ -55,7 +55,7 @@ public:
bool SetString(char *string); bool SetString(char *string);
bool Write(CLevelParserLine* line); bool Write(CLevelParserLine* line);
bool Read(char *line); bool Read(CLevelParserLine* line);
protected: protected:
CObject* SearchAlien(); CObject* SearchAlien();

View File

@ -628,15 +628,14 @@ bool CAutoEnergy::Write(CLevelParserLine* line)
// Restores all parameters of the controller. // Restores all parameters of the controller.
bool CAutoEnergy::Read(char *line) bool CAutoEnergy::Read(CLevelParserLine* line)
{ {
if ( OpInt(line, "aExist", 0) == 0 ) return false; if ( !line->GetParam("aExist")->AsBool(false) ) return false;
CAuto::Read(line); CAuto::Read(line);
m_phase = static_cast< AutoEnergyPhase >(line->GetParam("aPhase")->AsInt(AENP_WAIT));
m_phase = static_cast< AutoEnergyPhase >(OpInt(line, "aPhase", AENP_WAIT)); m_progress = line->GetParam("aProgress")->AsFloat(0.0f);
m_progress = OpFloat(line, "aProgress", 0.0f); m_speed = line->GetParam("aSpeed")->AsFloat(1.0f);
m_speed = OpFloat(line, "aSpeed", 1.0f);
m_lastUpdateTime = 0.0f; m_lastUpdateTime = 0.0f;
m_lastParticle = 0.0f; m_lastParticle = 0.0f;

View File

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

View File

@ -532,15 +532,14 @@ bool CAutoFactory::Write(CLevelParserLine* line)
// Restores all parameters of the controller // Restores all parameters of the controller
bool CAutoFactory::Read(char *line) bool CAutoFactory::Read(CLevelParserLine* line)
{ {
if ( OpInt(line, "aExist", 0) == 0 ) return false; if ( !line->GetParam("aExist")->AsBool(false) ) return false;
CAuto::Read(line); CAuto::Read(line);
m_phase = static_cast< AutoFactoryPhase >(line->GetParam("aPhase")->AsInt(AFP_WAIT));
m_phase = static_cast< AutoFactoryPhase >(OpInt(line, "aPhase", AFP_WAIT)); m_progress = line->GetParam("aProgress")->AsFloat(0.0f);
m_progress = OpFloat(line, "aProgress", 0.0f); m_speed = line->GetParam("aSpeed")->AsFloat(1.0f);
m_speed = OpFloat(line, "aSpeed", 1.0f);
m_lastParticle = 0.0f; m_lastParticle = 0.0f;
m_fretPos = m_object->GetPosition(0); m_fretPos = m_object->GetPosition(0);

View File

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

View File

@ -495,15 +495,14 @@ bool CAutoInfo::Write(CLevelParserLine* line)
// Restores all parameters of the controller. // Restores all parameters of the controller.
bool CAutoInfo::Read(char *line) bool CAutoInfo::Read(CLevelParserLine* line)
{ {
if ( OpInt(line, "aExist", 0) == 0 ) return false; if ( !line->GetParam("aExist")->AsBool(false) ) return false;
CAuto::Read(line); CAuto::Read(line);
m_phase = static_cast< AutoInfoPhase >(line->GetParam("aPhase")->AsInt(AIP_WAIT));
m_phase = static_cast< AutoInfoPhase > (OpInt(line, "aPhase", AIP_WAIT)); m_progress = line->GetParam("aProgress")->AsFloat(0.0f);
m_progress = OpFloat(line, "aProgress", 0.0f); m_speed = line->GetParam("aSpeed")->AsFloat(1.0f);
m_speed = OpFloat(line, "aSpeed", 1.0f);
m_lastParticle = 0.0f; m_lastParticle = 0.0f;

View File

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

View File

@ -604,16 +604,15 @@ bool CAutoLabo::Write(CLevelParserLine* line)
// Restores all parameters of the controller. // 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); CAuto::Read(line);
m_phase = static_cast< AutoLaboPhase >(line->GetParam("aPhase")->AsInt(ALAP_WAIT));
m_phase = static_cast< AutoLaboPhase >(OpInt(line, "aPhase", ALAP_WAIT)); m_progress = line->GetParam("aProgress")->AsFloat(0.0f);
m_progress = OpFloat(line, "aProgress", 0.0f); m_speed = line->GetParam("aSpeed")->AsFloat(1.0f);
m_speed = OpFloat(line, "aSpeed", 1.0f); m_research = static_cast< ResearchType >(line->GetParam("aResearch")->AsInt(0));
m_research = static_cast< ResearchType >(OpInt(line, "aResearch", 0));
m_lastParticle = 0.0f; m_lastParticle = 0.0f;

View File

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

View File

@ -34,7 +34,7 @@
// Object's constructor. // Object's constructor.
CAutoMush::CAutoMush(CObject* object) : CAuto(object) CAutoMush::CAutoMush(CObject* object) : CAuto(object)
{ {
Init(); Init();
} }
@ -319,15 +319,14 @@ bool CAutoMush::Write(CLevelParserLine* line)
// Restores all parameters of the controller. // 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); CAuto::Read(line);
m_phase = static_cast< AutoMushPhase >(line->GetParam("aPhase")->AsInt(AMP_WAIT));
m_phase = static_cast< AutoMushPhase >(OpInt(line, "aPhase", AMP_WAIT)); m_progress = line->GetParam("aProgress")->AsFloat(0.0f);
m_progress = OpFloat(line, "aProgress", 0.0f); m_speed = line->GetParam("aSpeed")->AsFloat(1.0f);
m_speed = OpFloat(line, "aSpeed", 1.0f);
m_lastParticle = 0.0f; m_lastParticle = 0.0f;

View File

@ -50,7 +50,7 @@ public:
Error GetError(); Error GetError();
bool Write(CLevelParserLine* line); bool Write(CLevelParserLine* line);
bool Read(char *line); bool Read(CLevelParserLine* line);
protected: protected:
bool SearchTarget(); bool SearchTarget();

View File

@ -35,7 +35,7 @@
// Object's constructor. // Object's constructor.
CAutoNest::CAutoNest(CObject* object) : CAuto(object) CAutoNest::CAutoNest(CObject* object) : CAuto(object)
{ {
Init(); Init();
} }
@ -250,15 +250,14 @@ bool CAutoNest::Write(CLevelParserLine* line)
// Restores all parameters of the controller. // 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); CAuto::Read(line);
m_phase = static_cast< AutoNestPhase >(line->GetParam("aPhase")->AsInt(ANP_WAIT));
m_phase = static_cast< AutoNestPhase >(OpInt(line, "aPhase", ANP_WAIT)); m_progress = line->GetParam("aProgress")->AsFloat(0.0f);
m_progress = OpFloat(line, "aProgress", 0.0f); m_speed = line->GetParam("aSpeed")->AsFloat(1.0f);
m_speed = OpFloat(line, "aSpeed", 1.0f);
m_lastParticle = 0.0f; m_lastParticle = 0.0f;

View File

@ -47,7 +47,7 @@ public:
Error GetError(); Error GetError();
bool Write(CLevelParserLine* line); bool Write(CLevelParserLine* line);
bool Read(char *line); bool Read(CLevelParserLine* line);
protected: protected:
bool SearchFree(Math::Vector pos); bool SearchFree(Math::Vector pos);

View File

@ -463,15 +463,14 @@ bool CAutoNuclear::Write(CLevelParserLine* line)
// Restores all parameters of the controller. // Restores all parameters of the controller.
bool CAutoNuclear::Read(char *line) bool CAutoNuclear::Read(CLevelParserLine* line)
{ {
if ( OpInt(line, "aExist", 0) == 0 ) return false; if ( !line->GetParam("aExist")->AsBool(false) ) return false;
CAuto::Read(line); CAuto::Read(line);
m_phase = static_cast< AutoNuclearPhase >(line->GetParam("aPhase")->AsInt(ANUP_WAIT));
m_phase = static_cast< AutoNuclearPhase >(OpInt(line, "aPhase", ANUP_WAIT)); m_progress = line->GetParam("aProgress")->AsFloat(0.0f);
m_progress = OpFloat(line, "aProgress", 0.0f); m_speed = line->GetParam("aSpeed")->AsFloat(1.0f);
m_speed = OpFloat(line, "aSpeed", 1.0f);
m_lastParticle = 0.0f; m_lastParticle = 0.0f;

View File

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

View File

@ -307,15 +307,14 @@ bool CAutoPara::Write(CLevelParserLine* line)
// Restores all parameters of the controller. // Restores all parameters of the controller.
bool CAutoPara::Read(char *line) bool CAutoPara::Read(CLevelParserLine* line)
{ {
if ( OpInt(line, "aExist", 0) == 0 ) return false; if ( !line->GetParam("aExist")->AsBool(false) ) return false;
CAuto::Read(line); CAuto::Read(line);
m_phase = static_cast< AutoParaPhase >(line->GetParam("aPhase")->AsInt(APAP_WAIT));
m_phase = static_cast< AutoParaPhase >(OpInt(line, "aPhase", APAP_WAIT)); m_progress = line->GetParam("aProgress")->AsFloat(0.0f);
m_progress = OpFloat(line, "aProgress", 0.0f); m_speed = line->GetParam("aSpeed")->AsFloat(1.0f);
m_speed = OpFloat(line, "aSpeed", 1.0f);
m_lastParticle = 0.0f; m_lastParticle = 0.0f;

View File

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

View File

@ -320,15 +320,14 @@ bool CAutoRepair::Write(CLevelParserLine* line)
// Restores all parameters of the controller. // Restores all parameters of the controller.
bool CAutoRepair::Read(char *line) bool CAutoRepair::Read(CLevelParserLine* line)
{ {
if ( OpInt(line, "aExist", 0) == 0 ) return false; if ( !line->GetParam("aExist")->AsBool(false) ) return false;
CAuto::Read(line); CAuto::Read(line);
m_phase = static_cast< AutoRepairPhase >(line->GetParam("aPhase")->AsInt(ARP_WAIT));
m_phase = static_cast< AutoRepairPhase >(OpInt(line, "aPhase", ARP_WAIT)); m_progress = line->GetParam("aProgress")->AsFloat(0.0f);
m_progress = OpFloat(line, "aProgress", 0.0f); m_speed = line->GetParam("aSpeed")->AsFloat(1.0f);
m_speed = OpFloat(line, "aSpeed", 1.0f);
m_lastParticle = 0.0f; m_lastParticle = 0.0f;

View File

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

View File

@ -581,16 +581,15 @@ bool CAutoResearch::Write(CLevelParserLine* line)
// Restores all parameters of the controller. // Restores all parameters of the controller.
bool CAutoResearch::Read(char *line) bool CAutoResearch::Read(CLevelParserLine* line)
{ {
if ( OpInt(line, "aExist", 0) == 0 ) return false; if ( !line->GetParam("aExist")->AsBool(false) ) return false;
CAuto::Read(line); CAuto::Read(line);
m_phase = static_cast< AutoResearchPhase >(line->GetParam("aPhase")->AsInt(ALP_WAIT));
m_phase = static_cast< AutoResearchPhase >(OpInt(line, "aPhase", ALP_WAIT)); m_progress = line->GetParam("aProgress")->AsFloat(0.0f);
m_progress = OpFloat(line, "aProgress", 0.0f); m_speed = line->GetParam("aSpeed")->AsFloat(1.0f);
m_speed = OpFloat(line, "aSpeed", 1.0f); m_research = static_cast< ResearchType >(line->GetParam("aResearch")->AsInt(0));
m_research = static_cast< ResearchType >(OpInt(line, "aResearch", 0));
m_lastUpdateTime = 0.0f; m_lastUpdateTime = 0.0f;
m_lastParticle = 0.0f; m_lastParticle = 0.0f;

View File

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

View File

@ -370,15 +370,14 @@ bool CAutoSafe::Write(CLevelParserLine* line)
// Restores all parameters of the controller. // Restores all parameters of the controller.
bool CAutoSafe::Read(char *line) bool CAutoSafe::Read(CLevelParserLine* line)
{ {
if ( OpInt(line, "aExist", 0) == 0 ) return false; if ( !line->GetParam("aExist")->AsBool(false) ) return false;
CAuto::Read(line); CAuto::Read(line);
m_phase = static_cast< AutoSafePhase >(line->GetParam("aPhase")->AsInt(ASAP_WAIT));
m_phase = static_cast< AutoSafePhase >(OpInt(line, "aPhase", ASAP_WAIT)); m_progress = line->GetParam("aProgress")->AsFloat(0.0f);
m_progress = OpFloat(line, "aProgress", 0.0f); m_speed = line->GetParam("aSpeed")->AsFloat(1.0f);
m_speed = OpFloat(line, "aSpeed", 1.0f);
m_lastParticle = 0.0f; m_lastParticle = 0.0f;

View File

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

View File

@ -508,20 +508,19 @@ bool CAutoTower::Write(CLevelParserLine* line)
// Restores all parameters of the controller. // Restores all parameters of the controller.
bool CAutoTower::Read(char *line) bool CAutoTower::Read(CLevelParserLine* line)
{ {
if ( OpInt(line, "aExist", 0) == 0 ) return false; if ( !line->GetParam("aExist")->AsBool(false) ) return false;
CAuto::Read(line); CAuto::Read(line);
m_phase = static_cast< AutoTowerPhase >(line->GetParam("aPhase")->AsInt(ATP_WAIT));
m_phase = static_cast< AutoTowerPhase >(OpInt(line, "aPhase", ATP_WAIT)); m_progress = line->GetParam("aProgress")->AsFloat(0.0f);
m_progress = OpFloat(line, "aProgress", 0.0f); m_speed = line->GetParam("aSpeed")->AsFloat(1.0f);
m_speed = OpFloat(line, "aSpeed", 1.0f); m_targetPos = line->GetParam("aTargetPos")->AsPoint(Math::Vector());
m_targetPos = OpDir(line, "aTargetPos"); m_angleYactual = line->GetParam("aAngleYactual")->AsFloat(0.0f);
m_angleYactual = OpFloat(line, "aAngleYactual", 0.0f); m_angleZactual = line->GetParam("aAngleZactual")->AsFloat(0.0f);
m_angleZactual = OpFloat(line, "aAngleZactual", 0.0f); m_angleYfinal = line->GetParam("aAngleYfinal")->AsFloat(0.0f);
m_angleYfinal = OpFloat(line, "aAngleYfinal", 0.0f); m_angleZfinal = line->GetParam("aAngleZfinal")->AsFloat(0.0f);
m_angleZfinal = OpFloat(line, "aAngleZfinal", 0.0f);
m_lastUpdateTime = 0.0f; m_lastUpdateTime = 0.0f;

View File

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

View File

@ -180,9 +180,9 @@ bool CBrain::Write(CLevelParserLine* line)
// Restores all parameters of the object. // Restores all parameters of the object.
bool CBrain::Read(char *line) bool CBrain::Read(CLevelParserLine* line)
{ {
m_bActiveVirus = OpInt(line, "bVirusActive", 0); m_bActiveVirus = line->GetParam("bVirusActive")->AsBool(false);
return true; return true;
} }

View File

@ -94,7 +94,7 @@ public:
bool CreateInterface(bool bSelect); bool CreateInterface(bool bSelect);
bool Write(CLevelParserLine* line); bool Write(CLevelParserLine* line);
bool Read(char *line); bool Read(CLevelParserLine* line);
bool IsBusy(); bool IsBusy();
void SetActivity(bool bMode); void SetActivity(bool bMode);

View File

@ -186,11 +186,11 @@ bool CMotion::Write(CLevelParserLine* line)
// Restores all parameters of the object. // Restores all parameters of the object.
bool CMotion::Read(char *line) bool CMotion::Read(CLevelParserLine* line)
{ {
m_actionType = OpInt(line, "mType", -1); m_actionType = line->GetParam("mType")->AsInt(-1);
m_actionTime = OpFloat(line, "mTime", 0.0f); m_actionTime = line->GetParam("mTime")->AsFloat(0.0f);
m_progress = OpFloat(line, "mProgress", 0.0f); m_progress = line->GetParam("mProgress")->AsFloat(0.0f);
return false; return false;
} }

View File

@ -64,7 +64,7 @@ public:
virtual float GetParam(int rank); virtual float GetParam(int rank);
virtual bool Write(CLevelParserLine* line); virtual bool Write(CLevelParserLine* line);
virtual bool Read(char *line); virtual bool Read(CLevelParserLine* line);
virtual void SetLinVibration(Math::Vector dir); virtual void SetLinVibration(Math::Vector dir);
virtual Math::Vector GetLinVibration(); virtual Math::Vector GetLinVibration();

View File

@ -78,6 +78,7 @@
#include "object/objman.h" #include "object/objman.h"
#include "object/level/parserline.h" #include "object/level/parserline.h"
#include "object/level/parserparam.h" #include "object/level/parserparam.h"
#include "object/level/parserexceptions.h"
#include "physics/physics.h" #include "physics/physics.h"
@ -1084,29 +1085,29 @@ bool CObject::Write(CLevelParserLine* line)
for ( i=0 ; i<OBJECTMAXCMDLINE ; i++ ) for ( i=0 ; i<OBJECTMAXCMDLINE ; i++ )
{ {
value = GetCmdLine(i); value = GetCmdLine(i);
if ( value == NAN ) break; if ( isnan(value) ) break;
cmdline.push_back(new CLevelParserParam(value)); cmdline.push_back(new CLevelParserParam(value));
} }
if(cmdline.size() > 0) if(cmdline.size() > 0)
line->AddParam("cmdline", new CLevelParserParam(cmdline)); line->AddParam("cmdline", new CLevelParserParam(cmdline));
if ( m_motion != 0 ) if ( m_motion != nullptr )
{ {
m_motion->Write(line); m_motion->Write(line);
} }
if ( m_brain != 0 ) if ( m_brain != nullptr )
{ {
m_brain->Write(line); m_brain->Write(line);
} }
if ( m_physics != 0 ) if ( m_physics != nullptr )
{ {
m_physics->Write(line); m_physics->Write(line);
} }
if ( m_auto != 0 ) if ( m_auto != nullptr )
{ {
m_auto->Write(line); m_auto->Write(line);
} }
@ -1116,87 +1117,91 @@ bool CObject::Write(CLevelParserLine* line)
// Returns all parameters of the object. // Returns all parameters of the object.
bool CObject::Read(char *line) bool CObject::Read(CLevelParserLine* line)
{ {
Math::Vector pos, dir; Math::Vector pos, dir;
Info info;
Gfx::CameraType cType; Gfx::CameraType cType;
char op[20];
char text[100];
char* p;
float value;
int i; int i;
cType = OpCamera(line, "camera"); cType = line->GetParam("camera")->AsCameraType(Gfx::CAM_TYPE_NULL);
if ( cType != Gfx::CAM_TYPE_NULL ) if ( cType != Gfx::CAM_TYPE_NULL )
{ {
SetCameraType(cType); SetCameraType(cType);
} }
SetCameraLock(OpInt(line, "cameraLock", 0)); SetCameraLock(line->GetParam("cameraLock")->AsBool(false));
SetEnergy(OpFloat(line, "energy", 0.0f)); SetEnergy(line->GetParam("energy")->AsFloat(0.0f));
SetCapacity(OpFloat(line, "capacity", 1.0f)); SetCapacity(line->GetParam("capacity")->AsFloat(1.0f));
SetShield(OpFloat(line, "shield", 1.0f)); SetShield(line->GetParam("shield")->AsFloat(1.0f));
SetRange(OpFloat(line, "range", 1.0f)); SetRange(line->GetParam("range")->AsFloat(1.0f));
SetSelectable(OpInt(line, "selectable", 1)); SetSelectable(line->GetParam("selectable")->AsBool(true));
SetEnable(OpInt(line, "enable", 1)); SetEnable(line->GetParam("enable")->AsBool(true));
SetFixed(OpInt(line, "fixed", 0)); SetFixed(line->GetParam("fixed")->AsBool(false));
SetClip(OpInt(line, "clip", 1)); SetClip(line->GetParam("clip")->AsBool(true));
SetLock(OpInt(line, "lock", 0)); SetLock(line->GetParam("lock")->AsBool(false));
SetProxyActivate(OpInt(line, "proxyActivate", 0)); SetProxyActivate(line->GetParam("proxyActivate")->AsBool(false));
SetProxyDistance(OpFloat(line, "proxyDistance", 15.0f)*g_unit); SetProxyDistance(line->GetParam("proxyDistance")->AsFloat(15.0f)*g_unit);
SetRange(OpFloat(line, "range", 30.0f)); SetRange(line->GetParam("range")->AsFloat(30.0f));
SetMagnifyDamage(OpFloat(line, "magnifyDamage", 1.0f)); SetMagnifyDamage(line->GetParam("magnifyDamage")->AsFloat(1.0f));
SetGunGoalV(OpFloat(line, "aimV", 0.0f)); SetGunGoalV(line->GetParam("aimV")->AsFloat(0.0f));
SetGunGoalH(OpFloat(line, "aimH", 0.0f)); SetGunGoalH(line->GetParam("aimH")->AsFloat(0.0f));
SetParam(OpFloat(line, "param", 0.0f)); SetParam(line->GetParam("param")->AsFloat(0.0f));
SetResetCap(static_cast<ResetCap>(OpInt(line, "resetCap", 0))); SetResetCap(static_cast<ResetCap>(line->GetParam("resetCap")->AsInt(0)));
SetResetPosition(OpDir(line, "resetPos")*g_unit); SetResetPosition(line->GetParam("resetPos")->AsPoint(Math::Vector())*g_unit);
SetResetAngle(OpDir(line, "resetAngle")*(Math::PI/180.0f)); SetResetAngle(line->GetParam("resetAngle")->AsPoint(Math::Vector())*(Math::PI/180.0f));
SetResetRun(OpInt(line, "resetRun", 0)); SetResetRun(line->GetParam("resetRun")->AsInt(0));
m_bBurn = OpInt(line, "burnMode", 0); m_bBurn = line->GetParam("burnMode")->AsBool(false);
m_bVirusMode = OpInt(line, "virusMode", 0); m_bVirusMode = line->GetParam("virusMode")->AsBool(false);
m_virusTime = OpFloat(line, "virusTime", 0.0f); m_virusTime = line->GetParam("virusTime")->AsFloat(0.0f);
// Puts information in terminal (OBJECT_INFO). // Puts information in terminal (OBJECT_INFO).
for ( i=0 ; i<OBJECTMAXINFO ; i++ ) for ( i=0 ; i<OBJECTMAXINFO ; i++ )
{ {
sprintf(op, "info%d", i+1); std::string op = std::string("info")+boost::lexical_cast<std::string>(i+1);
OpString(line, op, text); if(!line->GetParam(op)->IsDefined()) break;
if ( text[0] == 0 ) break; std::string text = line->GetParam(op)->AsString();
p = strchr(text, '=');
if ( p == 0 ) break; std::size_t p = text.find_first_of("=");
*p = 0; if(p == std::string::npos)
strcpy(info.name, text); throw CLevelParserExceptionBadParam(line->GetParam(op), "info");
sscanf(p+1, "%f", &info.value); Info info;
strcpy(info.name, text.substr(0, p).c_str());
try {
info.value = boost::lexical_cast<float>(text.substr(p+1).c_str());
}
catch(...)
{
throw CLevelParserExceptionBadParam(line->GetParam(op), "info.value (float)");
}
SetInfo(i, info); SetInfo(i, info);
} }
// Sets the parameters of the command line. // Sets the parameters of the command line.
p = SearchOp(line, "cmdline"); i = 0;
for ( i=0 ; i<OBJECTMAXCMDLINE ; i++ ) if(line->GetParam("cmdline")->IsDefined()) {
{ for(auto& p : line->GetParam("cmdline")->AsArray()) {
value = GetFloat(p, i, NAN); if(i >= OBJECTMAXCMDLINE) break;
if ( value == NAN ) break; SetCmdLine(i, p->AsFloat());
SetCmdLine(i, value); }
} }
if ( m_motion != 0 ) if ( m_motion != nullptr )
{ {
m_motion->Read(line); m_motion->Read(line);
} }
if ( m_brain != 0 ) if ( m_brain != nullptr )
{ {
m_brain->Read(line); m_brain->Read(line);
} }
if ( m_physics != 0 ) if ( m_physics != nullptr )
{ {
m_physics->Read(line); m_physics->Read(line);
} }
if ( m_auto != 0 ) if ( m_auto != nullptr )
{ {
m_auto->Read(line); m_auto->Read(line);
} }

View File

@ -381,7 +381,7 @@ public:
int GetID(); int GetID();
bool Write(CLevelParserLine* line); bool Write(CLevelParserLine* line);
bool Read(char *line); bool Read(CLevelParserLine* line);
void SetDrawWorld(bool bDraw); void SetDrawWorld(bool bDraw);
void SetDrawFront(bool bDraw); void SetDrawFront(bool bDraw);

View File

@ -5848,26 +5848,24 @@ bool CRobotMain::IOWriteScene(const char *filename, const char *filecbot, char *
} }
//! Resumes the game //! Resumes the game
CObject* CRobotMain::IOReadObject(char *line, const char* filename, int objRank) CObject* CRobotMain::IOReadObject(CLevelParserLine *line, const char* filename, int objRank)
{ {
Math::Vector pos = OpDir(line, "pos")*g_unit; Math::Vector pos = line->GetParam("pos")->AsPoint()*g_unit;
Math::Vector dir = OpDir(line, "angle")*(Math::PI/180.0f); Math::Vector dir = line->GetParam("angle")->AsPoint()*(Math::PI/180.0f);
Math::Vector zoom = OpDir(line, "zoom"); Math::Vector zoom = line->GetParam("zoom")->AsPoint();
ObjectType type = OpTypeObject(line, "type", OBJECT_NULL); ObjectType type = line->GetParam("type")->AsObjectType();
int id = OpInt(line, "id", 0); int id = line->GetParam("id")->AsInt();
if (type == OBJECT_NULL)
return nullptr;
int trainer = OpInt(line, "trainer", 0); bool trainer = line->GetParam("trainer")->AsBool(false);
int toy = OpInt(line, "toy", 0); bool toy = line->GetParam("toy")->AsBool(false);
int option = OpInt(line, "option", 0); int option = line->GetParam("option")->AsInt(0);
CObject* obj = CObjectManager::GetInstancePointer()->CreateObject(pos, dir.y, type, 0.0f, 1.0f, 0.0f, trainer, toy, option); CObject* obj = CObjectManager::GetInstancePointer()->CreateObject(pos, dir.y, type, 0.0f, 1.0f, 0.0f, trainer, toy, option);
obj->SetDefRank(objRank); obj->SetDefRank(objRank);
obj->SetPosition(0, pos); obj->SetPosition(0, pos);
obj->SetAngle(0, dir); obj->SetAngle(0, dir);
obj->SetIgnoreBuildCheck(OpInt(line, "ignoreBuildCheck", 0)); obj->SetIgnoreBuildCheck(line->GetParam("ignoreBuildCheck")->AsBool(false));
obj->SetID(id); obj->SetID(id);
if (g_id < id) g_id = id; if (g_id < id) g_id = id;
@ -5878,23 +5876,19 @@ CObject* CRobotMain::IOReadObject(char *line, const char* filename, int objRank)
{ {
if (obj->GetObjectRank(i) == -1) continue; if (obj->GetObjectRank(i) == -1) continue;
char op[10]; pos = line->GetParam(std::string("p")+boost::lexical_cast<std::string>(i))->AsPoint(Math::Vector());
sprintf(op, "p%d", i);
pos = OpDir(line, op);
if (pos.x != 0.0f || pos.y != 0.0f || pos.z != 0.0f) if (pos.x != 0.0f || pos.y != 0.0f || pos.z != 0.0f)
{ {
obj->SetPosition(i, pos*g_unit); obj->SetPosition(i, pos*g_unit);
} }
sprintf(op, "a%d", i); dir = line->GetParam(std::string("a")+boost::lexical_cast<std::string>(i))->AsPoint(Math::Vector());
dir = OpDir(line, op);
if (dir.x != 0.0f || dir.y != 0.0f || dir.z != 0.0f) if (dir.x != 0.0f || dir.y != 0.0f || dir.z != 0.0f)
{ {
obj->SetAngle(i, dir*(Math::PI/180.0f)); obj->SetAngle(i, dir*(Math::PI/180.0f));
} }
sprintf(op, "z%d", i); zoom = line->GetParam(std::string("z")+boost::lexical_cast<std::string>(i))->AsPoint(Math::Vector());
zoom = OpDir(line, op);
if (zoom.x != 0.0f || zoom.y != 0.0f || zoom.z != 0.0f) if (zoom.x != 0.0f || zoom.y != 0.0f || zoom.z != 0.0f)
{ {
obj->SetZoom(i, zoom); obj->SetZoom(i, zoom);
@ -5910,7 +5904,7 @@ CObject* CRobotMain::IOReadObject(char *line, const char* filename, int objRank)
LoadFileScript(obj, filename, objRank, i); LoadFileScript(obj, filename, objRank, i);
#endif #endif
int run = OpInt(line, "run", -1); int run = line->GetParam("run")->AsInt(-1);
if (run != -1) if (run != -1)
{ {
#if CBOT_STACK #if CBOT_STACK
@ -5931,54 +5925,48 @@ CObject* CRobotMain::IOReadObject(char *line, const char* filename, int objRank)
//! Resumes some part of the game //! Resumes some part of the game
CObject* CRobotMain::IOReadScene(const char *filename, const char *filecbot) CObject* CRobotMain::IOReadScene(const char *filename, const char *filecbot)
{ {
std::string fnstr = filename;
std::string savedir = CResourceManager::GetSaveLocation()+"/";
boost::replace_all(fnstr, "\\", "/");
boost::replace_all(savedir, "\\", "/");
boost::replace_all(fnstr, savedir, ""); //TODO: Refactor to get physfs path here
CLevelParser* level = new CLevelParser(fnstr);
level->Load();
m_base = nullptr; m_base = nullptr;
FILE* file = fopen(filename, "r");
if (file == NULL) return 0;
CObject* fret = nullptr; CObject* fret = nullptr;
CObject* power = nullptr; CObject* power = nullptr;
CObject* sel = nullptr; CObject* sel = nullptr;
int objRank = 0; int objRank = 0;
char line[3000]; for(auto& line : level->GetLines())
while (fgets(line, 3000, file) != NULL)
{ {
for (int i = 0; i < 3000; i++) if (line->GetCommand() == "Map")
m_map->ZoomMap(line->GetParam("zoom")->AsFloat());
if (line->GetCommand() == "DoneResearch")
g_researchDone = line->GetParam("bits")->AsInt();
if (line->GetCommand() == "BlitzMode")
{ {
if (line[i] == '\t') line[i] = ' '; // replace tab by space float sleep = line->GetParam("sleep")->AsFloat();
if (line[i] == '/' && line[i+1] == '/') float delay = line->GetParam("delay")->AsFloat();
{ float magnetic = line->GetParam("magnetic")->AsFloat()*g_unit;
line[i] = 0; float progress = line->GetParam("progress")->AsFloat();
break;
}
}
if (Cmd(line, "Map"))
m_map->ZoomMap(OpFloat(line, "zoom", 1.0f));
if (Cmd(line, "DoneResearch"))
g_researchDone = OpInt(line, "bits", 0);
if (Cmd(line, "BlitzMode"))
{
float sleep = OpFloat(line, "sleep", 0.0f);
float delay = OpFloat(line, "delay", 3.0f);
float magnetic = OpFloat(line, "magnetic", 50.0f)*g_unit;
float progress = OpFloat(line, "progress", 0.0f);
m_lightning->SetStatus(sleep, delay, magnetic, progress); m_lightning->SetStatus(sleep, delay, magnetic, progress);
} }
if (Cmd(line, "CreateFret")) if (line->GetCommand() == "CreateFret")
fret = IOReadObject(line, filename, -1); fret = IOReadObject(line, filename, -1);
if (Cmd(line, "CreatePower")) if (line->GetCommand() == "CreatePower")
power = IOReadObject(line, filename, -1); power = IOReadObject(line, filename, -1);
if (Cmd(line, "CreateObject")) if (line->GetCommand() == "CreateObject")
{ {
CObject* obj = IOReadObject(line, filename, objRank++); CObject* obj = IOReadObject(line, filename, objRank++);
if (OpInt(line, "select", 0)) if (line->GetParam("select")->AsBool(false))
sel = obj; sel = obj;
if (fret != nullptr) if (fret != nullptr)
@ -5999,7 +5987,7 @@ CObject* CRobotMain::IOReadScene(const char *filename, const char *filecbot)
power = nullptr; power = nullptr;
} }
} }
fclose(file); delete level;
#if CBOT_STACK #if CBOT_STACK
CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); CInstanceManager* iMan = CInstanceManager::GetInstancePointer();
@ -6026,7 +6014,7 @@ CObject* CRobotMain::IOReadScene(const char *filename, const char *filecbot)
while (nbError > 0 && nbError != lastError); while (nbError > 0 && nbError != lastError);
// Reads the file of stacks of execution. // Reads the file of stacks of execution.
file = fOpen(filecbot, "rb"); FILE* file = fOpen(filecbot, "rb");
if (file != NULL) if (file != NULL)
{ {
long version; long version;

View File

@ -384,8 +384,8 @@ public:
bool IsBusy(); bool IsBusy();
bool IOWriteScene(const char *filename, const char *filecbot, char *info); bool IOWriteScene(const char *filename, const char *filecbot, char *info);
CObject* IOReadScene(const char *filename, const char *filecbot); CObject* IOReadScene(const char *filename, const char *filecbot);
void IOWriteObject(CLevelParserLine *file, CObject* pObj); void IOWriteObject(CLevelParserLine *line, CObject* obj);
CObject* IOReadObject(char *line, const char* filename, int objRank); CObject* IOReadObject(CLevelParserLine *line, const char* filename, int objRank);
int CreateSpot(Math::Vector pos, Gfx::Color color); int CreateSpot(Math::Vector pos, Gfx::Color color);

View File

@ -188,14 +188,14 @@ bool CPhysics::Write(CLevelParserLine* line)
// Restores all parameters of the object. // Restores all parameters of the object.
bool CPhysics::Read(char *line) bool CPhysics::Read(CLevelParserLine* line)
{ {
m_motorSpeed = OpDir(line, "motor"); m_motorSpeed = line->GetParam("motor")->AsPoint();
if ( m_type == TYPE_FLYING ) if ( m_type == TYPE_FLYING )
{ {
SetReactorRange(OpFloat(line, "reactorRange", 0.0f)); SetReactorRange(line->GetParam("reactorRange")->AsFloat());
SetLand(OpInt(line, "land", 0)); SetLand(line->GetParam("land")->AsBool());
} }
return true; return true;

View File

@ -112,7 +112,7 @@ public:
PhysicsType GetType(); PhysicsType GetType();
bool Write(CLevelParserLine* line); bool Write(CLevelParserLine* line);
bool Read(char *line); bool Read(CLevelParserLine* line);
void SetGravity(float value); void SetGravity(float value);
float GetGravity(); float GetGravity();