Refactor level parser code

* replace manual memory management with std::unique_ptr
 * remove unnecessary dynamic allocations
 * make coding style consistent
master
Piotr Dziwinski 2015-06-21 20:59:23 +02:00
parent 5f1d3c21d4
commit 02ffdcfe23
34 changed files with 1579 additions and 1454 deletions

View File

@ -424,11 +424,11 @@ void CAuto::SetMotor(bool bMotor)
bool CAuto::Write(CLevelParserLine* line) bool CAuto::Write(CLevelParserLine* line)
{ {
line->AddParam("aType", new CLevelParserParam(m_type)); line->AddParam("aType", CLevelParserParamUPtr{new CLevelParserParam(m_type)});
line->AddParam("aBusy", new CLevelParserParam(m_bBusy)); line->AddParam("aBusy", CLevelParserParamUPtr{new CLevelParserParam(m_bBusy)});
line->AddParam("aTime", new CLevelParserParam(m_time)); line->AddParam("aTime", CLevelParserParamUPtr{new CLevelParserParam(m_time)});
line->AddParam("aProgressTime", new CLevelParserParam(m_progressTime)); line->AddParam("aProgressTime", CLevelParserParamUPtr{new CLevelParserParam(m_progressTime)});
line->AddParam("aProgressTotal", new CLevelParserParam(m_progressTotal)); line->AddParam("aProgressTotal", CLevelParserParamUPtr{new CLevelParserParam(m_progressTotal)});
return false; return false;
} }

View File

@ -365,11 +365,11 @@ bool CAutoConvert::Write(CLevelParserLine* line)
if ( m_phase == ACP_STOP || if ( m_phase == ACP_STOP ||
m_phase == ACP_WAIT ) return false; m_phase == ACP_WAIT ) return false;
line->AddParam("aExist", new CLevelParserParam(true)); line->AddParam("aExist", CLevelParserParamUPtr{new CLevelParserParam(true)});
CAuto::Write(line); CAuto::Write(line);
line->AddParam("aPhase", new CLevelParserParam(static_cast<int>(m_phase))); line->AddParam("aPhase", CLevelParserParamUPtr{new CLevelParserParam(static_cast<int>(m_phase))});
line->AddParam("aProgress", new CLevelParserParam(m_progress)); line->AddParam("aProgress", CLevelParserParamUPtr{new CLevelParserParam(m_progress)});
line->AddParam("aSpeed", new CLevelParserParam(m_speed)); line->AddParam("aSpeed", CLevelParserParamUPtr{new CLevelParserParam(m_speed)});
return true; return true;
} }

View File

@ -430,12 +430,12 @@ bool CAutoDerrick::CreateInterface(bool bSelect)
bool CAutoDerrick::Write(CLevelParserLine* line) bool CAutoDerrick::Write(CLevelParserLine* line)
{ {
if ( m_phase == ADP_WAIT ) return false; if ( m_phase == ADP_WAIT ) return false;
line->AddParam("aExist", new CLevelParserParam(true)); line->AddParam("aExist", CLevelParserParamUPtr{new CLevelParserParam(true)});
CAuto::Write(line); CAuto::Write(line);
line->AddParam("aPhase", new CLevelParserParam(static_cast<int>(m_phase))); line->AddParam("aPhase", CLevelParserParamUPtr{new CLevelParserParam(static_cast<int>(m_phase))});
line->AddParam("aProgress", new CLevelParserParam(m_progress)); line->AddParam("aProgress", CLevelParserParamUPtr{new CLevelParserParam(m_progress)});
line->AddParam("aSpeed", new CLevelParserParam(m_speed)); line->AddParam("aSpeed", CLevelParserParamUPtr{new CLevelParserParam(m_speed)});
return true; return true;
} }
@ -524,7 +524,7 @@ bool CAutoDerrick::ExistKey()
m_type != OBJECT_KEYb && m_type != OBJECT_KEYb &&
m_type != OBJECT_KEYc && m_type != OBJECT_KEYc &&
m_type != OBJECT_KEYd ) return false; m_type != OBJECT_KEYd ) return false;
return CObjectManager::GetInstancePointer()->FindNearest(nullptr, m_type) != nullptr; return CObjectManager::GetInstancePointer()->FindNearest(nullptr, m_type) != nullptr;
} }

View File

@ -353,12 +353,12 @@ Error CAutoDestroyer::GetError()
bool CAutoDestroyer::Write(CLevelParserLine* line) bool CAutoDestroyer::Write(CLevelParserLine* line)
{ {
if ( m_phase == ADEP_WAIT ) return false; if ( m_phase == ADEP_WAIT ) return false;
line->AddParam("aExist", new CLevelParserParam(true)); line->AddParam("aExist", CLevelParserParamUPtr{new CLevelParserParam(true)});
CAuto::Write(line); CAuto::Write(line);
line->AddParam("aPhase", new CLevelParserParam(static_cast<int>(m_phase))); line->AddParam("aPhase", CLevelParserParamUPtr{new CLevelParserParam(static_cast<int>(m_phase))});
line->AddParam("aProgress", new CLevelParserParam(m_progress)); line->AddParam("aProgress", CLevelParserParamUPtr{new CLevelParserParam(m_progress)});
line->AddParam("aSpeed", new CLevelParserParam(m_speed)); line->AddParam("aSpeed", CLevelParserParamUPtr{new CLevelParserParam(m_speed)});
return true; return true;
} }

View File

@ -301,15 +301,15 @@ CObject* CAutoEgg::SearchAlien()
bool CAutoEgg::Write(CLevelParserLine* line) bool CAutoEgg::Write(CLevelParserLine* line)
{ {
if ( m_phase == AEP_NULL ) return false; if ( m_phase == AEP_NULL ) return false;
line->AddParam("aExist", new CLevelParserParam(true)); line->AddParam("aExist", CLevelParserParamUPtr{new CLevelParserParam(true)});
CAuto::Write(line); CAuto::Write(line);
line->AddParam("aPhase", new CLevelParserParam(static_cast<int>(m_phase))); line->AddParam("aPhase", CLevelParserParamUPtr{new CLevelParserParam(static_cast<int>(m_phase))});
line->AddParam("aProgress", new CLevelParserParam(m_progress)); line->AddParam("aProgress", CLevelParserParamUPtr{new CLevelParserParam(m_progress)});
line->AddParam("aSpeed", new CLevelParserParam(m_speed)); line->AddParam("aSpeed", CLevelParserParamUPtr{new CLevelParserParam(m_speed)});
line->AddParam("aParamType", new CLevelParserParam(m_type)); line->AddParam("aParamType", CLevelParserParamUPtr{new CLevelParserParam(m_type)});
line->AddParam("aParamValue1", new CLevelParserParam(m_value)); line->AddParam("aParamValue1", CLevelParserParamUPtr{new CLevelParserParam(m_value)});
line->AddParam("aParamString", new CLevelParserParam(std::string(m_string))); line->AddParam("aParamString", CLevelParserParamUPtr{new CLevelParserParam(std::string(m_string))});
return true; return true;
} }

View File

@ -585,12 +585,12 @@ bool CAutoEnergy::Write(CLevelParserLine* line)
{ {
if ( m_phase == AENP_STOP || if ( m_phase == AENP_STOP ||
m_phase == AENP_WAIT ) return false; m_phase == AENP_WAIT ) return false;
line->AddParam("aExist", new CLevelParserParam(true)); line->AddParam("aExist", CLevelParserParamUPtr{new CLevelParserParam(true)});
CAuto::Write(line); CAuto::Write(line);
line->AddParam("aPhase", new CLevelParserParam(static_cast<int>(m_phase))); line->AddParam("aPhase", CLevelParserParamUPtr{new CLevelParserParam(static_cast<int>(m_phase))});
line->AddParam("aProgress", new CLevelParserParam(m_progress)); line->AddParam("aProgress", CLevelParserParamUPtr{new CLevelParserParam(m_progress)});
line->AddParam("aSpeed", new CLevelParserParam(m_speed)); line->AddParam("aSpeed", CLevelParserParamUPtr{new CLevelParserParam(m_speed)});
return true; return true;
} }

View File

@ -515,12 +515,12 @@ bool CAutoFactory::EventProcess(const Event &event)
bool CAutoFactory::Write(CLevelParserLine* line) bool CAutoFactory::Write(CLevelParserLine* line)
{ {
if ( m_phase == AFP_WAIT ) return false; if ( m_phase == AFP_WAIT ) return false;
line->AddParam("aExist", new CLevelParserParam(true)); line->AddParam("aExist", CLevelParserParamUPtr{new CLevelParserParam(true)});
CAuto::Write(line); CAuto::Write(line);
line->AddParam("aPhase", new CLevelParserParam(static_cast<int>(m_phase))); line->AddParam("aPhase", CLevelParserParamUPtr{new CLevelParserParam(static_cast<int>(m_phase))});
line->AddParam("aProgress", new CLevelParserParam(m_progress)); line->AddParam("aProgress", CLevelParserParamUPtr{new CLevelParserParam(m_progress)});
line->AddParam("aSpeed", new CLevelParserParam(m_speed)); line->AddParam("aSpeed", CLevelParserParamUPtr{new CLevelParserParam(m_speed)});
return true; return true;
} }

View File

@ -483,12 +483,12 @@ void CAutoInfo::UpdateListVirus()
bool CAutoInfo::Write(CLevelParserLine* line) bool CAutoInfo::Write(CLevelParserLine* line)
{ {
if ( m_phase == AIP_WAIT ) return false; if ( m_phase == AIP_WAIT ) return false;
line->AddParam("aExist", new CLevelParserParam(true)); line->AddParam("aExist", CLevelParserParamUPtr{new CLevelParserParam(true)});
CAuto::Write(line); CAuto::Write(line);
line->AddParam("aPhase", new CLevelParserParam(static_cast<int>(m_phase))); line->AddParam("aPhase", CLevelParserParamUPtr{new CLevelParserParam(static_cast<int>(m_phase))});
line->AddParam("aProgress", new CLevelParserParam(m_progress)); line->AddParam("aProgress", CLevelParserParamUPtr{new CLevelParserParam(m_progress)});
line->AddParam("aSpeed", new CLevelParserParam(m_speed)); line->AddParam("aSpeed", CLevelParserParamUPtr{new CLevelParserParam(m_speed)});
return true; return true;
} }

View File

@ -32,16 +32,16 @@ public:
CAutoJostle(CObject* object); CAutoJostle(CObject* object);
~CAutoJostle(); ~CAutoJostle();
void DeleteObject(bool bAll=false); void DeleteObject(bool bAll=false) OVERRIDE;
void Init(); void Init() OVERRIDE;
void Start(int param, float force); void Start(int param, float force);
bool EventProcess(const Event &event); bool EventProcess(const Event &event) OVERRIDE;
Error IsEnded(); Error IsEnded() OVERRIDE;
private: private:
// Overriden to avoid warning about hiding virtual function // Overriden to avoid warning about hiding virtual function
virtual void Start(int param) OVERRIDE; void Start(int param) OVERRIDE;
protected: protected:
float m_force; float m_force;

View File

@ -591,13 +591,13 @@ void CAutoLabo::SoundManip(float time, float amplitude, float frequency)
bool CAutoLabo::Write(CLevelParserLine* line) bool CAutoLabo::Write(CLevelParserLine* line)
{ {
if ( m_phase == ALAP_WAIT ) return false; if ( m_phase == ALAP_WAIT ) return false;
line->AddParam("aExist", new CLevelParserParam(true)); line->AddParam("aExist", CLevelParserParamUPtr{new CLevelParserParam(true)});
CAuto::Write(line); CAuto::Write(line);
line->AddParam("aPhase", new CLevelParserParam(static_cast<int>(m_phase))); line->AddParam("aPhase", CLevelParserParamUPtr{new CLevelParserParam(static_cast<int>(m_phase))});
line->AddParam("aProgress", new CLevelParserParam(m_progress)); line->AddParam("aProgress", CLevelParserParamUPtr{new CLevelParserParam(m_progress)});
line->AddParam("aSpeed", new CLevelParserParam(m_speed)); line->AddParam("aSpeed", CLevelParserParamUPtr{new CLevelParserParam(m_speed)});
line->AddParam("aResearch", new CLevelParserParam(static_cast<int>(m_research))); line->AddParam("aResearch", CLevelParserParamUPtr{new CLevelParserParam(static_cast<int>(m_research))});
return true; return true;
} }

View File

@ -297,12 +297,12 @@ Error CAutoMush::GetError()
bool CAutoMush::Write(CLevelParserLine* line) bool CAutoMush::Write(CLevelParserLine* line)
{ {
if ( m_phase == AMP_WAIT ) return false; if ( m_phase == AMP_WAIT ) return false;
line->AddParam("aExist", new CLevelParserParam(true)); line->AddParam("aExist", CLevelParserParamUPtr{new CLevelParserParam(true)});
CAuto::Write(line); CAuto::Write(line);
line->AddParam("aPhase", new CLevelParserParam(static_cast<int>(m_phase))); line->AddParam("aPhase", CLevelParserParamUPtr{new CLevelParserParam(static_cast<int>(m_phase))});
line->AddParam("aProgress", new CLevelParserParam(m_progress)); line->AddParam("aProgress", CLevelParserParamUPtr{new CLevelParserParam(m_progress)});
line->AddParam("aSpeed", new CLevelParserParam(m_speed)); line->AddParam("aSpeed", CLevelParserParamUPtr{new CLevelParserParam(m_speed)});
return true; return true;
} }

View File

@ -212,12 +212,12 @@ Error CAutoNest::GetError()
bool CAutoNest::Write(CLevelParserLine* line) bool CAutoNest::Write(CLevelParserLine* line)
{ {
if ( m_phase == ANP_WAIT ) return false; if ( m_phase == ANP_WAIT ) return false;
line->AddParam("aExist", new CLevelParserParam(true)); line->AddParam("aExist", CLevelParserParamUPtr{new CLevelParserParam(true)});
CAuto::Write(line); CAuto::Write(line);
line->AddParam("aPhase", new CLevelParserParam(static_cast<int>(m_phase))); line->AddParam("aPhase", CLevelParserParamUPtr{new CLevelParserParam(static_cast<int>(m_phase))});
line->AddParam("aProgress", new CLevelParserParam(m_progress)); line->AddParam("aProgress", CLevelParserParamUPtr{new CLevelParserParam(m_progress)});
line->AddParam("aSpeed", new CLevelParserParam(m_speed)); line->AddParam("aSpeed", CLevelParserParamUPtr{new CLevelParserParam(m_speed)});
return true; return true;
} }

View File

@ -430,12 +430,12 @@ bool CAutoNuclear::Write(CLevelParserLine* line)
{ {
if ( m_phase == ANUP_STOP || if ( m_phase == ANUP_STOP ||
m_phase == ANUP_WAIT ) return false; m_phase == ANUP_WAIT ) return false;
line->AddParam("aExist", new CLevelParserParam(true)); line->AddParam("aExist", CLevelParserParamUPtr{new CLevelParserParam(true)});
CAuto::Write(line); CAuto::Write(line);
line->AddParam("aPhase", new CLevelParserParam(static_cast<int>(m_phase))); line->AddParam("aPhase", CLevelParserParamUPtr{new CLevelParserParam(static_cast<int>(m_phase))});
line->AddParam("aProgress", new CLevelParserParam(m_progress)); line->AddParam("aProgress", CLevelParserParamUPtr{new CLevelParserParam(m_progress)});
line->AddParam("aSpeed", new CLevelParserParam(m_speed)); line->AddParam("aSpeed", CLevelParserParamUPtr{new CLevelParserParam(m_speed)});
return true; return true;
} }

View File

@ -285,12 +285,12 @@ void CAutoPara::ChargeObject(float rTime)
bool CAutoPara::Write(CLevelParserLine* line) bool CAutoPara::Write(CLevelParserLine* line)
{ {
if ( m_phase == APAP_WAIT ) return false; if ( m_phase == APAP_WAIT ) return false;
line->AddParam("aExist", new CLevelParserParam(true)); line->AddParam("aExist", CLevelParserParamUPtr{new CLevelParserParam(true)});
CAuto::Write(line); CAuto::Write(line);
line->AddParam("aPhase", new CLevelParserParam(static_cast<int>(m_phase))); line->AddParam("aPhase", CLevelParserParamUPtr{new CLevelParserParam(static_cast<int>(m_phase))});
line->AddParam("aProgress", new CLevelParserParam(m_progress)); line->AddParam("aProgress", CLevelParserParamUPtr{new CLevelParserParam(m_progress)});
line->AddParam("aSpeed", new CLevelParserParam(m_speed)); line->AddParam("aSpeed", CLevelParserParamUPtr{new CLevelParserParam(m_speed)});
return true; return true;
} }

View File

@ -297,12 +297,12 @@ Error CAutoRepair::GetError()
bool CAutoRepair::Write(CLevelParserLine* line) bool CAutoRepair::Write(CLevelParserLine* line)
{ {
if ( m_phase == ARP_WAIT ) return false; if ( m_phase == ARP_WAIT ) return false;
line->AddParam("aExist", new CLevelParserParam(true)); line->AddParam("aExist", CLevelParserParamUPtr{new CLevelParserParam(true)});
CAuto::Write(line); CAuto::Write(line);
line->AddParam("aPhase", new CLevelParserParam(static_cast<int>(m_phase))); line->AddParam("aPhase", CLevelParserParamUPtr{new CLevelParserParam(static_cast<int>(m_phase))});
line->AddParam("aProgress", new CLevelParserParam(m_progress)); line->AddParam("aProgress", CLevelParserParamUPtr{new CLevelParserParam(m_progress)});
line->AddParam("aSpeed", new CLevelParserParam(m_speed)); line->AddParam("aSpeed", CLevelParserParamUPtr{new CLevelParserParam(m_speed)});
return true; return true;
} }

View File

@ -568,13 +568,13 @@ void CAutoResearch::FireStopUpdate(float progress, bool bLightOn)
bool CAutoResearch::Write(CLevelParserLine* line) bool CAutoResearch::Write(CLevelParserLine* line)
{ {
if ( m_phase == ALP_WAIT ) return false; if ( m_phase == ALP_WAIT ) return false;
line->AddParam("aExist", new CLevelParserParam(true)); line->AddParam("aExist", CLevelParserParamUPtr{new CLevelParserParam(true)});
CAuto::Write(line); CAuto::Write(line);
line->AddParam("aPhase", new CLevelParserParam(static_cast<int>(m_phase))); line->AddParam("aPhase", CLevelParserParamUPtr{new CLevelParserParam(static_cast<int>(m_phase))});
line->AddParam("aProgress", new CLevelParserParam(m_progress)); line->AddParam("aProgress", CLevelParserParamUPtr{new CLevelParserParam(m_progress)});
line->AddParam("aSpeed", new CLevelParserParam(m_speed)); line->AddParam("aSpeed", CLevelParserParamUPtr{new CLevelParserParam(m_speed)});
line->AddParam("aResearch", new CLevelParserParam(static_cast<int>(m_research))); line->AddParam("aResearch", CLevelParserParamUPtr{new CLevelParserParam(static_cast<int>(m_research))});
return true; return true;
} }

View File

@ -354,12 +354,12 @@ Error CAutoSafe::GetError()
bool CAutoSafe::Write(CLevelParserLine* line) bool CAutoSafe::Write(CLevelParserLine* line)
{ {
if ( m_phase == ASAP_WAIT ) return false; if ( m_phase == ASAP_WAIT ) return false;
line->AddParam("aExist", new CLevelParserParam(true)); line->AddParam("aExist", CLevelParserParamUPtr{new CLevelParserParam(true)});
CAuto::Write(line); CAuto::Write(line);
line->AddParam("aPhase", new CLevelParserParam(static_cast<int>(m_phase))); line->AddParam("aPhase", CLevelParserParamUPtr{new CLevelParserParam(static_cast<int>(m_phase))});
line->AddParam("aProgress", new CLevelParserParam(m_progress)); line->AddParam("aProgress", CLevelParserParamUPtr{new CLevelParserParam(m_progress)});
line->AddParam("aSpeed", new CLevelParserParam(m_speed)); line->AddParam("aSpeed", CLevelParserParamUPtr{new CLevelParserParam(m_speed)});
return true; return true;
} }

View File

@ -482,17 +482,17 @@ void CAutoTower::UpdateInterface(float rTime)
bool CAutoTower::Write(CLevelParserLine* line) bool CAutoTower::Write(CLevelParserLine* line)
{ {
if ( m_phase == ATP_WAIT ) return false; if ( m_phase == ATP_WAIT ) return false;
line->AddParam("aExist", new CLevelParserParam(true)); line->AddParam("aExist", CLevelParserParamUPtr{new CLevelParserParam(true)});
CAuto::Write(line); CAuto::Write(line);
line->AddParam("aPhase", new CLevelParserParam(static_cast<int>(m_phase))); line->AddParam("aPhase", CLevelParserParamUPtr{new CLevelParserParam(static_cast<int>(m_phase))});
line->AddParam("aProgress", new CLevelParserParam(m_progress)); line->AddParam("aProgress", CLevelParserParamUPtr{new CLevelParserParam(m_progress)});
line->AddParam("aSpeed", new CLevelParserParam(m_speed)); line->AddParam("aSpeed", CLevelParserParamUPtr{new CLevelParserParam(m_speed)});
line->AddParam("aTargetPos", new CLevelParserParam(m_targetPos)); line->AddParam("aTargetPos", CLevelParserParamUPtr{new CLevelParserParam(m_targetPos)});
line->AddParam("aAngleYactual", new CLevelParserParam(m_angleYactual)); line->AddParam("aAngleYactual", CLevelParserParamUPtr{new CLevelParserParam(m_angleYactual)});
line->AddParam("aAngleZactual", new CLevelParserParam(m_angleZactual)); line->AddParam("aAngleZactual", CLevelParserParamUPtr{new CLevelParserParam(m_angleZactual)});
line->AddParam("aAngleYfinal", new CLevelParserParam(m_angleYfinal)); line->AddParam("aAngleYfinal", CLevelParserParamUPtr{new CLevelParserParam(m_angleYfinal)});
line->AddParam("aAngleZfinal", new CLevelParserParam(m_angleZfinal)); line->AddParam("aAngleZfinal", CLevelParserParamUPtr{new CLevelParserParam(m_angleZfinal)});
return true; return true;
} }

View File

@ -171,11 +171,11 @@ void CBrain::SetMotion(CMotion* motion)
bool CBrain::Write(CLevelParserLine* line) 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 ) 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; return true;
@ -736,11 +736,11 @@ bool CBrain::EventProcess(const Event &event)
{ {
err = StartTaskSearch(); err = StartTaskSearch();
} }
if ( action == EVENT_OBJECT_DELSEARCH ) if ( action == EVENT_OBJECT_DELSEARCH )
{ {
err = StartTaskDeleteMark(); err = StartTaskDeleteMark();
} }
if ( action == EVENT_OBJECT_TERRAFORM ) if ( action == EVENT_OBJECT_TERRAFORM )
{ {

View File

@ -34,6 +34,7 @@
#include <exception> #include <exception>
#include <sstream> #include <sstream>
#include <iomanip> #include <iomanip>
#include <set>
#include <boost/algorithm/string/trim.hpp> #include <boost/algorithm/string/trim.hpp>
#include <boost/algorithm/string/replace.hpp> #include <boost/algorithm/string/replace.hpp>
@ -54,19 +55,11 @@ CLevelParser::CLevelParser(std::string category, int chapter, int rank)
m_filename = BuildScenePath(category, chapter, rank); m_filename = BuildScenePath(category, chapter, rank);
} }
CLevelParser::~CLevelParser()
{
for(auto line : m_lines)
{
delete line;
}
}
std::string CLevelParser::BuildCategoryPath(std::string category) std::string CLevelParser::BuildCategoryPath(std::string category)
{ {
std::ostringstream outstream; std::ostringstream outstream;
outstream << "levels/"; outstream << "levels/";
if(category == "perso" || category == "win" || category == "lost") if (category == "perso" || category == "win" || category == "lost")
{ {
outstream << "other/"; outstream << "other/";
} }
@ -81,12 +74,12 @@ std::string CLevelParser::BuildScenePath(std::string category, int chapter, int
{ {
std::ostringstream outstream; std::ostringstream outstream;
outstream << BuildCategoryPath(category); outstream << BuildCategoryPath(category);
if(category == "custom") if (category == "custom")
{ {
outstream << CRobotMain::GetInstancePointer()->GetUserLevelName(chapter); outstream << CRobotMain::GetInstancePointer()->GetUserLevelName(chapter);
if(rank == 000) if (rank == 000)
{ {
if(sceneFile) if (sceneFile)
{ {
outstream << "/chaptertitle.txt"; outstream << "/chaptertitle.txt";
} }
@ -94,26 +87,26 @@ std::string CLevelParser::BuildScenePath(std::string category, int chapter, int
else else
{ {
outstream << "/level" << std::setfill('0') << std::setw(3) << rank; outstream << "/level" << std::setfill('0') << std::setw(3) << rank;
if(sceneFile) if (sceneFile)
{ {
outstream << "/scene.txt"; outstream << "/scene.txt";
} }
} }
} }
else if(category == "perso") else if (category == "perso")
{ {
outstream << "perso.txt"; 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 else
{ {
outstream << "chapter" << std::setfill('0') << std::setw(3) << chapter; outstream << "chapter" << std::setfill('0') << std::setw(3) << chapter;
if(rank == 000) if (rank == 000)
{ {
if(sceneFile) if (sceneFile)
{ {
outstream << "/chaptertitle.txt"; outstream << "/chaptertitle.txt";
} }
@ -121,7 +114,7 @@ std::string CLevelParser::BuildScenePath(std::string category, int chapter, int
else else
{ {
outstream << "/level" << std::setfill('0') << std::setw(3) << rank; outstream << "/level" << std::setfill('0') << std::setw(3) << rank;
if(sceneFile) if (sceneFile)
{ {
outstream << "/scene.txt"; outstream << "/scene.txt";
} }
@ -139,97 +132,124 @@ void CLevelParser::Load()
{ {
CInputStream file; CInputStream file;
file.open(m_filename); file.open(m_filename);
if(!file.is_open()) if (!file.is_open())
throw CLevelParserException("Failed to open file: "+m_filename); throw CLevelParserException("Failed to open file: " + m_filename);
char lang = CApplication::GetInstancePointer()->GetLanguageChar(); char lang = CApplication::GetInstancePointer()->GetLanguageChar();
std::string line; std::string line;
int lineNumber = 0; int lineNumber = 0;
std::map<std::string, CLevelParserLine*> translatableLines; std::set<std::string> translatableLines;
while(getline(file,line)) while (getline(file, line))
{ {
lineNumber++; lineNumber++;
boost::replace_all(line, "\t", " "); // replace tab by space boost::replace_all(line, "\t", " "); // replace tab by space
// ignore comments // ignore comments
std::size_t comment = line.find("//"); std::size_t comment = line.find("//");
if(comment != std::string::npos) if (comment != std::string::npos)
line = line.substr(0, comment); line = line.substr(0, comment);
boost::algorithm::trim(line); boost::algorithm::trim(line);
std::size_t pos = line.find_first_of(" \t\n"); std::size_t pos = line.find_first_of(" \t\n");
std::string command = line.substr(0, pos); std::string command = line.substr(0, pos);
if(pos != std::string::npos) { if (pos != std::string::npos)
line = line.substr(pos+1); {
line = line.substr(pos + 1);
boost::algorithm::trim(line); boost::algorithm::trim(line);
} else { }
else
{
line = ""; line = "";
} }
if(command.empty()) continue;
if (command.empty())
CLevelParserLine* parserLine = new CLevelParserLine(lineNumber, command); continue;
std::string baseCommand = command; CLevelParserLineUPtr parserLine{new CLevelParserLine(lineNumber, command)};
if(command[command.length()-2] == '.') {
baseCommand = command.substr(0, command.length()-2); if (command.length() > 2 && command[command.length() - 2] == '.')
if(command[command.length()-1] == 'E' && translatableLines[baseCommand] == nullptr) { {
parserLine->SetCommand(baseCommand); std::string baseCommand = command.substr(0, command.length() - 2);
translatableLines[baseCommand] = parserLine; parserLine->SetCommand(baseCommand);
} else if(command[command.length()-1] == lang) {
if(translatableLines[baseCommand] != nullptr) { char languageChar = command[command.length() - 1];
m_lines.erase(std::remove(m_lines.begin(), m_lines.end(), translatableLines[baseCommand]), m_lines.end()); if (languageChar == 'E' && translatableLines.count(baseCommand) == 0)
delete translatableLines[baseCommand]; {
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; translatableLines.insert(baseCommand);
} else { }
delete parserLine; else
{
continue; continue;
} }
} }
while(!line.empty()) { while (!line.empty())
{
pos = line.find_first_of("="); pos = line.find_first_of("=");
std::string paramName = line.substr(0, pos); std::string paramName = line.substr(0, pos);
boost::algorithm::trim(paramName); boost::algorithm::trim(paramName);
line = line.substr(pos+1); line = line.substr(pos + 1);
boost::algorithm::trim(line); boost::algorithm::trim(line);
if(line[0] == '\"') { if (line[0] == '\"')
{
pos = line.find_first_of("\"", 1); pos = line.find_first_of("\"", 1);
if(pos == std::string::npos) if (pos == std::string::npos)
throw CLevelParserException("Unclosed \" in "+m_filename+":"+boost::lexical_cast<std::string>(lineNumber)); throw CLevelParserException("Unclosed \" in " + m_filename + ":" + boost::lexical_cast<std::string>(lineNumber));
} else if(line[0] == '\'') { }
else if (line[0] == '\'')
{
pos = line.find_first_of("'", 1); pos = line.find_first_of("'", 1);
if(pos == std::string::npos) if (pos == std::string::npos)
throw CLevelParserException("Unclosed ' in "+m_filename+":"+boost::lexical_cast<std::string>(lineNumber)); throw CLevelParserException("Unclosed ' in " + m_filename + ":" + boost::lexical_cast<std::string>(lineNumber));
} else { }
else
{
pos = line.find_first_of("="); 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)); 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; pos = pos2;
} else { }
else
{
pos = line.length()-1; pos = line.length()-1;
} }
} }
std::string paramValue = line.substr(0, pos+1); std::string paramValue = line.substr(0, pos + 1);
boost::algorithm::trim(paramValue); boost::algorithm::trim(paramValue);
parserLine->AddParam(paramName, new CLevelParserParam(paramName, paramValue)); parserLine->AddParam(paramName, CLevelParserParamUPtr{new CLevelParserParam(paramName, paramValue)});
if(pos == std::string::npos) if (pos == std::string::npos)
break; break;
line = line.substr(pos+1); line = line.substr(pos + 1);
boost::algorithm::trim(line); boost::algorithm::trim(line);
} }
AddLine(parserLine); AddLine(std::move(parserLine));
} }
file.close(); file.close();
} }
@ -237,17 +257,14 @@ void CLevelParser::Save()
{ {
COutputStream file; COutputStream file;
file.open(m_filename); file.open(m_filename);
if(!file.is_open()) if (!file.is_open())
throw CLevelParserException("Failed to open file: "+m_filename); throw CLevelParserException("Failed to open file: " + m_filename);
for(CLevelParserLine* line : m_lines) { for (auto& line : m_lines)
file << line->GetCommand(); {
for(auto param : line->GetParams()) { file << line.get() << "\n";
file << " " << param.first << "=" << param.second->GetValue();
}
file << "\n";
} }
file.close(); file.close();
} }
@ -256,22 +273,18 @@ const std::string& CLevelParser::GetFilename()
return m_filename; return m_filename;
} }
std::vector<CLevelParserLine*> CLevelParser::GetLines() void CLevelParser::AddLine(CLevelParserLineUPtr line)
{
return m_lines;
}
void CLevelParser::AddLine(CLevelParserLine* line)
{ {
line->SetLevel(this); line->SetLevel(this);
m_lines.push_back(line); m_lines.push_back(std::move(line));
} }
CLevelParserLine* CLevelParser::Get(std::string command) CLevelParserLine* CLevelParser::Get(std::string command)
{ {
for(auto& line : m_lines) { for (auto& line : m_lines)
if(line->GetCommand() == command) {
return line; if (line->GetCommand() == command)
return line.get();
} }
throw CLevelParserException("Command not found: "+command); throw CLevelParserException("Command not found: " + command);
} }

View File

@ -30,6 +30,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <memory>
class CLevelParser class CLevelParser
{ {
@ -40,33 +41,35 @@ public:
CLevelParser(std::string filename); CLevelParser(std::string filename);
//! Load given level //! Load given level
CLevelParser(std::string category, int chapter, int rank); CLevelParser(std::string category, int chapter, int rank);
~CLevelParser();
//! Build category path //! Build category path
static std::string BuildCategoryPath(std::string category); static std::string BuildCategoryPath(std::string category);
//! Build level filename //! Build level filename
static std::string BuildScenePath(std::string category, int chapter, int rank, bool sceneFile = true); static std::string BuildScenePath(std::string category, int chapter, int rank, bool sceneFile = true);
//! Check if level file exists //! Check if level file exists
bool Exists(); bool Exists();
//! Load file //! Load file
void Load(); void Load();
//! Save file //! Save file
void Save(); void Save();
//! Get filename //! Get filename
const std::string& GetFilename(); const std::string& GetFilename();
//! Get all lines from file //! Get all lines from file
std::vector<CLevelParserLine*> GetLines(); inline const std::vector<CLevelParserLineUPtr>& GetLines()
{
return m_lines;
}
//! Insert new line to file //! Insert new line to file
void AddLine(CLevelParserLine* line); void AddLine(CLevelParserLineUPtr line);
//! Find first line with given command //! Find first line with given command
CLevelParserLine* Get(std::string command); CLevelParserLine* Get(std::string command);
private: private:
std::string m_filename; std::string m_filename;
std::vector<CLevelParserLine*> m_lines; std::vector<CLevelParserLineUPtr> m_lines;
}; };

View File

@ -19,14 +19,13 @@
#include "object/level/parserexceptions.h" #include "object/level/parserexceptions.h"
#include "object/level/parser.h" #include "object/level/parser.h"
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
CLevelParserException::CLevelParserException(std::string message) NOEXCEPT CLevelParserException::CLevelParserException(std::string message) NOEXCEPT
: m_message(message)
{ {
m_message = message;
} }
const char* CLevelParserException::what() const NOEXCEPT const char* CLevelParserException::what() const NOEXCEPT
@ -34,12 +33,29 @@ const char* CLevelParserException::what() const NOEXCEPT
return m_message.c_str(); return m_message.c_str();
} }
std::string formatMissingParamError(CLevelParserParam* thisParam) NOEXCEPT
{
auto paramName = thisParam->GetName();
auto lineNumber = boost::lexical_cast<std::string>(thisParam->GetLine()->GetLineNumber());
auto fileName = thisParam->GetLine()->GetLevel()->GetFilename();
return "Missing required param '" + paramName + "' (in " + fileName + ":" + lineNumber + ")";
}
CLevelParserExceptionMissingParam::CLevelParserExceptionMissingParam(CLevelParserParam* thisParam) NOEXCEPT CLevelParserExceptionMissingParam::CLevelParserExceptionMissingParam(CLevelParserParam* thisParam) NOEXCEPT
: CLevelParserException("Missing required param "+thisParam->GetName()+" (in "+thisParam->GetLine()->GetLevel()->GetFilename()+":"+boost::lexical_cast<std::string>(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<std::string>(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 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<std::string>(thisParam->GetLine()->GetLineNumber())+")") : CLevelParserException(formatBadParamError(thisParam, requestedType))
{ {
} }

View File

@ -52,4 +52,4 @@ class CLevelParserExceptionBadParam : public CLevelParserException
public: public:
CLevelParserExceptionBadParam(CLevelParserParam* thisParam, std::string requestedType) NOEXCEPT; CLevelParserExceptionBadParam(CLevelParserParam* thisParam, std::string requestedType) NOEXCEPT;
virtual ~CLevelParserExceptionBadParam() NOEXCEPT {} virtual ~CLevelParserExceptionBadParam() NOEXCEPT {}
}; };

View File

@ -19,7 +19,6 @@
#include "object/level/parserline.h" #include "object/level/parserline.h"
#include "object/level/parser.h" #include "object/level/parser.h"
#include "common/logger.h" #include "common/logger.h"
@ -35,14 +34,6 @@ CLevelParserLine::CLevelParserLine(int lineNumber, std::string command)
m_lineNumber = lineNumber; m_lineNumber = lineNumber;
} }
CLevelParserLine::~CLevelParserLine()
{
for(auto param : m_params)
{
delete param.second;
}
}
int CLevelParserLine::GetLineNumber() int CLevelParserLine::GetLineNumber()
{ {
return m_lineNumber; return m_lineNumber;
@ -70,21 +61,31 @@ void CLevelParserLine::SetCommand(std::string command)
CLevelParserParam* CLevelParserLine::GetParam(std::string name) CLevelParserParam* CLevelParserLine::GetParam(std::string name)
{ {
if(m_params[name] == nullptr) { auto it = m_params.find(name);
CLevelParserParam* param = new CLevelParserParam(name, true); if (it != m_params.end())
param->SetLine(this); {
m_params[name] = param; 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); value->SetLine(this);
m_params[name] = value; m_params.insert(std::make_pair(name, std::move(value)));
} }
const std::map<std::string, CLevelParserParam*>& CLevelParserLine::GetParams() std::ostream& operator<<(std::ostream& str, const CLevelParserLine& line)
{ {
return m_params; str << line.m_command;
} for (const auto& param : line.m_params)
{
str << " " << param.first << "=" << param.second->GetValue();
}
return str;
}

View File

@ -24,37 +24,41 @@
#pragma once #pragma once
#include "object/level/parserparam.h"
#include <string> #include <string>
#include <map> #include <map>
#include <memory>
class CLevelParser; class CLevelParser;
class CLevelParserParam; class CLevelParserLine;
using CLevelParserLineUPtr = std::unique_ptr<CLevelParserLine>;
class CLevelParserLine class CLevelParserLine
{ {
public: public:
CLevelParserLine(int lineNumber, std::string command); CLevelParserLine(int lineNumber, std::string command);
CLevelParserLine(std::string command); CLevelParserLine(std::string command);
~CLevelParserLine();
//! Get line number //! Get line number
int GetLineNumber(); int GetLineNumber();
//! Get CLevelParser this line is part of //! Get CLevelParser this line is part of
CLevelParser* GetLevel(); CLevelParser* GetLevel();
//! Set CLevelParser this line is part of //! Set CLevelParser this line is part of
void SetLevel(CLevelParser* level); void SetLevel(CLevelParser* level);
std::string GetCommand(); std::string GetCommand();
void SetCommand(std::string command); void SetCommand(std::string command);
CLevelParserParam* GetParam(std::string name); CLevelParserParam* GetParam(std::string name);
void AddParam(std::string name, CLevelParserParam* value); void AddParam(std::string name, CLevelParserParamUPtr value);
const std::map<std::string, CLevelParserParam*>& GetParams();
friend std::ostream& operator<<(std::ostream& str, const CLevelParserLine& line);
private: private:
CLevelParser* m_level; CLevelParser* m_level;
int m_lineNumber; int m_lineNumber;
std::string m_command; std::string m_command;
std::map<std::string, CLevelParserParam*> m_params; std::map<std::string, CLevelParserParamUPtr> m_params;
}; };

File diff suppressed because it is too large Load Diff

View File

@ -24,16 +24,24 @@
#pragma once #pragma once
#include <object/object.h> #include "graphics/core/color.h"
#include <graphics/core/color.h> #include "graphics/engine/water.h"
#include <graphics/engine/water.h> #include "graphics/engine/pyro.h"
#include <graphics/engine/pyro.h>
#include <math/point.h> #include "math/point.h"
#include "object/object.h"
#include <string> #include <string>
#include <vector>
#include <memory>
class CLevelParserLine; class CLevelParserLine;
class CLevelParserParam;
using CLevelParserParamUPtr = std::unique_ptr<CLevelParserParam>;
using CLevelParserParamVec = std::vector<CLevelParserParamUPtr>;
class CLevelParserParam class CLevelParserParam
{ {
public: public:
@ -48,15 +56,13 @@ public:
CLevelParserParam(Math::Vector value); CLevelParserParam(Math::Vector value);
CLevelParserParam(ObjectType value); CLevelParserParam(ObjectType value);
CLevelParserParam(Gfx::CameraType value); CLevelParserParam(Gfx::CameraType value);
CLevelParserParam(const std::vector<CLevelParserParam*>& value); CLevelParserParam(CLevelParserParamVec&& array);
//@} //@}
//! Create param from string //! Create param from string
CLevelParserParam(std::string name, std::string value); CLevelParserParam(std::string name, std::string value);
//! Create empty parser param //! Create empty parser param
CLevelParserParam(std::string name, bool empty); CLevelParserParam(std::string name, bool empty);
~CLevelParserParam();
//! Get value (throws exception if not found or unable to process) //! Get value (throws exception if not found or unable to process)
//@{ //@{
int AsInt(); int AsInt();
@ -75,9 +81,9 @@ public:
int AsResearchFlag(); int AsResearchFlag();
Gfx::PyroType AsPyroType(); Gfx::PyroType AsPyroType();
Gfx::CameraType AsCameraType(); Gfx::CameraType AsCameraType();
const std::vector<CLevelParserParam*>& AsArray(); const CLevelParserParamVec& AsArray();
//@} //@}
//! Get value (returns default if not found, throws exception if unable to process) //! Get value (returns default if not found, throws exception if unable to process)
//@{ //@{
int AsInt(int def); int AsInt(int def);
@ -97,23 +103,23 @@ public:
Gfx::PyroType AsPyroType(Gfx::PyroType def); Gfx::PyroType AsPyroType(Gfx::PyroType def);
Gfx::CameraType AsCameraType(Gfx::CameraType def); Gfx::CameraType AsCameraType(Gfx::CameraType def);
//@} //@}
//! Set line this param is part of //! Set line this param is part of
void SetLine(CLevelParserLine* line); void SetLine(CLevelParserLine* line);
//! Get line this param is part of //! Get line this param is part of
CLevelParserLine* GetLine(); CLevelParserLine* GetLine();
std::string GetName(); std::string GetName();
std::string GetValue(); std::string GetValue();
bool IsDefined(); bool IsDefined();
private: private:
void ParseArray(); void ParseArray();
void LoadArray(); void LoadArray();
template<typename T> T Cast(std::string value, std::string requestedType); template<typename T> T Cast(std::string value, std::string requestedType);
template<typename T> T Cast(std::string requestedType); template<typename T> T Cast(std::string requestedType);
std::string ToPath(std::string path, const std::string defaultDir); std::string ToPath(std::string path, const std::string defaultDir);
ObjectType ToObjectType(std::string value); ObjectType ToObjectType(std::string value);
DriveType ToDriveType(std::string value); DriveType ToDriveType(std::string value);
@ -124,14 +130,15 @@ private:
int ToResearchFlag(std::string value); int ToResearchFlag(std::string value);
Gfx::PyroType ToPyroType(std::string value); Gfx::PyroType ToPyroType(std::string value);
Gfx::CameraType ToCameraType(std::string value); Gfx::CameraType ToCameraType(std::string value);
const std::string FromObjectType(ObjectType value); const std::string FromObjectType(ObjectType value);
const std::string FromCameraType(Gfx::CameraType value); const std::string FromCameraType(Gfx::CameraType value);
private: private:
CLevelParserLine* m_line; CLevelParserLine* m_line = nullptr;
bool m_empty; bool m_empty = false;
std::string m_name; std::string m_name;
std::string m_value; std::string m_value;
std::vector<CLevelParserParam*> m_array; CLevelParserParamVec m_array;
}; };

View File

@ -161,10 +161,10 @@ float CMotion::GetParam(int rank)
bool CMotion::Write(CLevelParserLine* line) bool CMotion::Write(CLevelParserLine* line)
{ {
if ( m_actionType == -1 ) return false; if ( m_actionType == -1 ) return false;
line->AddParam("mType", new CLevelParserParam(m_actionType)); line->AddParam("mType", CLevelParserParamUPtr{new CLevelParserParam(m_actionType)});
line->AddParam("mTime", new CLevelParserParam(m_actionTime)); line->AddParam("mTime", CLevelParserParamUPtr{new CLevelParserParam(m_actionTime)});
line->AddParam("mProgress", new CLevelParserParam(m_progress)); line->AddParam("mProgress", CLevelParserParamUPtr{new CLevelParserParam(m_progress)});
return false; return false;
} }

View File

@ -35,8 +35,6 @@
const float START_TIME = 1000.0f; // beginning of the relative time
// Object's constructor. // Object's constructor.

View File

@ -357,7 +357,7 @@ void CObject::DeleteObject(bool bAll)
m_camera->SetControllingObject(0); m_camera->SetControllingObject(0);
} }
CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); CInstanceManager* iMan = CInstanceManager::GetInstancePointer();
for (CObject* obj : CObjectManager::GetInstancePointer()->GetAllObjects()) for (CObject* obj : CObjectManager::GetInstancePointer()->GetAllObjects())
@ -950,69 +950,69 @@ bool CObject::Write(CLevelParserLine* line)
float value; float value;
int i; int i;
line->AddParam("camera", new CLevelParserParam(GetCameraType())); line->AddParam("camera", CLevelParserParamUPtr{new CLevelParserParam(GetCameraType())});
if ( GetCameraLock() ) if ( GetCameraLock() )
line->AddParam("cameraLock", new CLevelParserParam(GetCameraLock())); line->AddParam("cameraLock", CLevelParserParamUPtr{new CLevelParserParam(GetCameraLock())});
if ( GetEnergy() != 0.0f ) if ( GetEnergy() != 0.0f )
line->AddParam("energy", new CLevelParserParam(GetEnergy())); line->AddParam("energy", CLevelParserParamUPtr{new CLevelParserParam(GetEnergy())});
if ( GetCapacity() != 1.0f ) if ( GetCapacity() != 1.0f )
line->AddParam("capacity", new CLevelParserParam(GetCapacity())); line->AddParam("capacity", CLevelParserParamUPtr{new CLevelParserParam(GetCapacity())});
if ( GetShield() != 1.0f ) if ( GetShield() != 1.0f )
line->AddParam("shield", new CLevelParserParam(GetShield())); line->AddParam("shield", CLevelParserParamUPtr{new CLevelParserParam(GetShield())});
if ( GetRange() != 1.0f ) if ( GetRange() != 1.0f )
line->AddParam("range", new CLevelParserParam(GetRange())); line->AddParam("range", CLevelParserParamUPtr{new CLevelParserParam(GetRange())});
if ( !GetSelectable() ) if ( !GetSelectable() )
line->AddParam("selectable", new CLevelParserParam(GetSelectable())); line->AddParam("selectable", CLevelParserParamUPtr{new CLevelParserParam(GetSelectable())});
if ( !GetEnable() ) if ( !GetEnable() )
line->AddParam("enable", new CLevelParserParam(GetEnable())); line->AddParam("enable", CLevelParserParamUPtr{new CLevelParserParam(GetEnable())});
if ( GetFixed() ) if ( GetFixed() )
line->AddParam("fixed", new CLevelParserParam(GetFixed())); line->AddParam("fixed", CLevelParserParamUPtr{new CLevelParserParam(GetFixed())});
if ( !GetClip() ) if ( !GetClip() )
line->AddParam("clip", new CLevelParserParam(GetClip())); line->AddParam("clip", CLevelParserParamUPtr{new CLevelParserParam(GetClip())});
if ( GetLock() ) if ( GetLock() )
line->AddParam("lock", new CLevelParserParam(GetLock())); line->AddParam("lock", CLevelParserParamUPtr{new CLevelParserParam(GetLock())});
if ( GetProxyActivate() ) if ( GetProxyActivate() )
{ {
line->AddParam("proxyActivate", new CLevelParserParam(GetProxyActivate())); line->AddParam("proxyActivate", CLevelParserParamUPtr{new CLevelParserParam(GetProxyActivate())});
line->AddParam("proxyDistance", new CLevelParserParam(GetProxyDistance()/g_unit)); line->AddParam("proxyDistance", CLevelParserParamUPtr{new CLevelParserParam(GetProxyDistance()/g_unit)});
} }
if ( GetMagnifyDamage() != 1.0f ) if ( GetMagnifyDamage() != 1.0f )
line->AddParam("magnifyDamage", new CLevelParserParam(GetMagnifyDamage())); line->AddParam("magnifyDamage", CLevelParserParamUPtr{new CLevelParserParam(GetMagnifyDamage())});
if ( GetGunGoalV() != 0.0f ) if ( GetGunGoalV() != 0.0f )
line->AddParam("aimV", new CLevelParserParam(GetGunGoalV())); line->AddParam("aimV", CLevelParserParamUPtr{new CLevelParserParam(GetGunGoalV())});
if ( GetGunGoalH() != 0.0f ) if ( GetGunGoalH() != 0.0f )
line->AddParam("aimH", new CLevelParserParam(GetGunGoalH())); line->AddParam("aimH", CLevelParserParamUPtr{new CLevelParserParam(GetGunGoalH())});
if ( GetParam() != 0.0f ) if ( GetParam() != 0.0f )
line->AddParam("param", new CLevelParserParam(GetParam())); line->AddParam("param", CLevelParserParamUPtr{new CLevelParserParam(GetParam())});
if ( GetResetCap() != 0 ) if ( GetResetCap() != 0 )
{ {
line->AddParam("resetCap", new CLevelParserParam(static_cast<int>(GetResetCap()))); line->AddParam("resetCap", CLevelParserParamUPtr{new CLevelParserParam(static_cast<int>(GetResetCap()))});
line->AddParam("resetPos", new CLevelParserParam(GetResetPosition()/g_unit)); line->AddParam("resetPos", CLevelParserParamUPtr{new CLevelParserParam(GetResetPosition()/g_unit)});
line->AddParam("resetAngle", new CLevelParserParam(GetResetAngle()/(Math::PI/180.0f))); line->AddParam("resetAngle", CLevelParserParamUPtr{new CLevelParserParam(GetResetAngle()/(Math::PI/180.0f))});
line->AddParam("resetRun", new CLevelParserParam(m_brain->GetProgramIndex(GetResetRun()))); line->AddParam("resetRun", CLevelParserParamUPtr{new CLevelParserParam(m_brain->GetProgramIndex(GetResetRun()))});
} }
if ( m_bVirusMode ) if ( m_bVirusMode )
line->AddParam("virusMode", new CLevelParserParam(m_bVirusMode)); line->AddParam("virusMode", CLevelParserParamUPtr{new CLevelParserParam(m_bVirusMode)});
if ( m_virusTime != 0.0f ) 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). // Puts information in terminal (OBJECT_INFO).
for ( i=0 ; i<m_infoTotal ; i++ ) for ( i=0 ; i<m_infoTotal ; i++ )
@ -1020,20 +1020,20 @@ bool CObject::Write(CLevelParserLine* line)
info = GetInfo(i); info = GetInfo(i);
if ( info.name[0] == 0 ) break; if ( info.name[0] == 0 ) break;
line->AddParam("info"+boost::lexical_cast<std::string>(i+1), new CLevelParserParam(std::string(info.name)+"="+boost::lexical_cast<std::string>(info.value))); line->AddParam("info"+boost::lexical_cast<std::string>(i+1), CLevelParserParamUPtr{new CLevelParserParam(std::string(info.name)+"="+boost::lexical_cast<std::string>(info.value))});
} }
// Sets the parameters of the command line. // Sets the parameters of the command line.
std::vector<CLevelParserParam*> cmdline; CLevelParserParamVec cmdline;
for ( i=0 ; i<OBJECTMAXCMDLINE ; i++ ) for ( i=0 ; i<OBJECTMAXCMDLINE ; i++ )
{ {
value = GetCmdLine(i); value = GetCmdLine(i);
if ( std::isnan(value) ) break; if ( std::isnan(value) ) break;
cmdline.push_back(new CLevelParserParam(value)); cmdline.push_back(CLevelParserParamUPtr{new CLevelParserParam(value)});
} }
if(cmdline.size() > 0) if (cmdline.size() > 0)
line->AddParam("cmdline", new CLevelParserParam(cmdline)); line->AddParam("cmdline", CLevelParserParamUPtr{new CLevelParserParam(std::move(cmdline))});
if ( m_motion != nullptr ) if ( m_motion != nullptr )
{ {
@ -1101,30 +1101,33 @@ bool CObject::Read(CLevelParserLine* line)
for ( i=0 ; i<OBJECTMAXINFO ; i++ ) for ( i=0 ; i<OBJECTMAXINFO ; i++ )
{ {
std::string op = std::string("info")+boost::lexical_cast<std::string>(i+1); std::string op = std::string("info")+boost::lexical_cast<std::string>(i+1);
if(!line->GetParam(op)->IsDefined()) break; if (!line->GetParam(op)->IsDefined()) break;
std::string text = line->GetParam(op)->AsString(); std::string text = line->GetParam(op)->AsString();
std::size_t p = text.find_first_of("="); std::size_t p = text.find_first_of("=");
if(p == std::string::npos) if (p == std::string::npos)
throw CLevelParserExceptionBadParam(line->GetParam(op), "info"); throw CLevelParserExceptionBadParam(line->GetParam(op), "info");
Info info; Info info;
strcpy(info.name, text.substr(0, p).c_str()); strcpy(info.name, text.substr(0, p).c_str());
try { try
{
info.value = boost::lexical_cast<float>(text.substr(p+1).c_str()); info.value = boost::lexical_cast<float>(text.substr(p+1).c_str());
} }
catch(...) catch (...)
{ {
throw CLevelParserExceptionBadParam(line->GetParam(op), "info.value (float)"); 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.
i = 0; i = 0;
if(line->GetParam("cmdline")->IsDefined()) { if (line->GetParam("cmdline")->IsDefined())
for(auto& p : line->GetParam("cmdline")->AsArray()) { {
if(i >= OBJECTMAXCMDLINE) break; for (auto& p : line->GetParam("cmdline")->AsArray())
{
if (i >= OBJECTMAXCMDLINE) break;
SetCmdLine(i, p->AsFloat()); SetCmdLine(i, p->AsFloat());
i++; i++;
} }
@ -3905,35 +3908,36 @@ void CObject::SetTraceWidth(float width)
DriveType CObject::GetDriveFromObject(ObjectType type) DriveType CObject::GetDriveFromObject(ObjectType type)
{ {
switch(type) { switch(type)
{
case OBJECT_MOBILEwt: case OBJECT_MOBILEwt:
case OBJECT_MOBILEwa: case OBJECT_MOBILEwa:
case OBJECT_MOBILEwc: case OBJECT_MOBILEwc:
case OBJECT_MOBILEwi: case OBJECT_MOBILEwi:
case OBJECT_MOBILEws: case OBJECT_MOBILEws:
return DRIVE_WHEELED; return DRIVE_WHEELED;
case OBJECT_MOBILEtt: case OBJECT_MOBILEtt:
case OBJECT_MOBILEta: case OBJECT_MOBILEta:
case OBJECT_MOBILEtc: case OBJECT_MOBILEtc:
case OBJECT_MOBILEti: case OBJECT_MOBILEti:
case OBJECT_MOBILEts: case OBJECT_MOBILEts:
return DRIVE_TRACKED; return DRIVE_TRACKED;
case OBJECT_MOBILEft: case OBJECT_MOBILEft:
case OBJECT_MOBILEfa: case OBJECT_MOBILEfa:
case OBJECT_MOBILEfc: case OBJECT_MOBILEfc:
case OBJECT_MOBILEfi: case OBJECT_MOBILEfi:
case OBJECT_MOBILEfs: case OBJECT_MOBILEfs:
return DRIVE_WINGED; return DRIVE_WINGED;
case OBJECT_MOBILEit: case OBJECT_MOBILEit:
case OBJECT_MOBILEia: case OBJECT_MOBILEia:
case OBJECT_MOBILEic: case OBJECT_MOBILEic:
case OBJECT_MOBILEii: case OBJECT_MOBILEii:
case OBJECT_MOBILEis: case OBJECT_MOBILEis:
return DRIVE_LEGGED; return DRIVE_LEGGED;
default: default:
return DRIVE_OTHER; return DRIVE_OTHER;
} }
@ -3941,31 +3945,32 @@ DriveType CObject::GetDriveFromObject(ObjectType type)
ToolType CObject::GetToolFromObject(ObjectType type) ToolType CObject::GetToolFromObject(ObjectType type)
{ {
switch(type) { switch(type)
{
case OBJECT_MOBILEwa: case OBJECT_MOBILEwa:
case OBJECT_MOBILEta: case OBJECT_MOBILEta:
case OBJECT_MOBILEfa: case OBJECT_MOBILEfa:
case OBJECT_MOBILEia: case OBJECT_MOBILEia:
return TOOL_GRABBER; return TOOL_GRABBER;
case OBJECT_MOBILEws: case OBJECT_MOBILEws:
case OBJECT_MOBILEts: case OBJECT_MOBILEts:
case OBJECT_MOBILEfs: case OBJECT_MOBILEfs:
case OBJECT_MOBILEis: case OBJECT_MOBILEis:
return TOOL_SNIFFER; return TOOL_SNIFFER;
case OBJECT_MOBILEwc: case OBJECT_MOBILEwc:
case OBJECT_MOBILEtc: case OBJECT_MOBILEtc:
case OBJECT_MOBILEfc: case OBJECT_MOBILEfc:
case OBJECT_MOBILEic: case OBJECT_MOBILEic:
return TOOL_SHOOTER; return TOOL_SHOOTER;
case OBJECT_MOBILEwi: case OBJECT_MOBILEwi:
case OBJECT_MOBILEti: case OBJECT_MOBILEti:
case OBJECT_MOBILEfi: case OBJECT_MOBILEfi:
case OBJECT_MOBILEii: case OBJECT_MOBILEii:
return TOOL_ORGASHOOTER; return TOOL_ORGASHOOTER;
default: default:
return TOOL_OTHER; return TOOL_OTHER;
} }

File diff suppressed because it is too large Load Diff

View File

@ -1294,7 +1294,7 @@ bool CTaskGoto::GetHotPoint(CObject *pObj, Math::Vector &pos,
bool CTaskGoto::LeakSearch(Math::Vector &pos, float &delay) bool CTaskGoto::LeakSearch(Math::Vector &pos, float &delay)
{ {
CObject *pObj, *pObstacle = nullptr; CObject *pObstacle = nullptr;
Math::Vector iPos, oPos, bPos; Math::Vector iPos, oPos, bPos;
float iRadius, oRadius, bRadius, dist, min, dir; float iRadius, oRadius, bRadius, dist, min, dir;
int j; int j;

View File

@ -175,12 +175,12 @@ PhysicsType CPhysics::GetType()
bool CPhysics::Write(CLevelParserLine* line) 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 ) if ( m_type == TYPE_FLYING )
{ {
line->AddParam("reactorRange", new CLevelParserParam(GetReactorRange())); line->AddParam("reactorRange", CLevelParserParamUPtr{new CLevelParserParam(GetReactorRange())});
line->AddParam("land", new CLevelParserParam(GetLand())); line->AddParam("land", CLevelParserParamUPtr{new CLevelParserParam(GetLand())});
} }
return true; return true;

View File

@ -197,7 +197,7 @@ void CMainDialog::Create()
m_engine = Gfx::CEngine::GetInstancePointer(); m_engine = Gfx::CEngine::GetInstancePointer();
m_particle = m_engine->GetParticle(); m_particle = m_engine->GetParticle();
m_pause = CPauseManager::GetInstancePointer(); m_pause = CPauseManager::GetInstancePointer();
m_setupFull = m_app->GetVideoConfig().fullScreen; m_setupFull = m_app->GetVideoConfig().fullScreen;
} }
@ -269,7 +269,7 @@ void CMainDialog::ChangePhase(Phase phase)
ddim.x = 0.30f; ddim.x = 0.30f;
ddim.y = 0.30f; ddim.y = 0.30f;
pw->CreateGroup(pos, ddim, 4, EVENT_INTERFACE_GLINTr); // blue corner pw->CreateGroup(pos, ddim, 4, EVENT_INTERFACE_GLINTr); // blue corner
ddim.x = 0.20f; ddim.x = 0.20f;
ddim.y = dim.y*2.4f; ddim.y = dim.y*2.4f;
pos.x = 0.40f; pos.x = 0.40f;
@ -289,7 +289,7 @@ void CMainDialog::ChangePhase(Phase phase)
pos.y = oy+sy*1.9f; pos.y = oy+sy*1.9f;
pg = pw->CreateGroup(pos, ddim, 26, EVENT_LABEL1); // red pg = pw->CreateGroup(pos, ddim, 26, EVENT_LABEL1); // red
pg->SetState(STATE_SHADOW); pg->SetState(STATE_SHADOW);
ddim.x = 0.18f; ddim.x = 0.18f;
ddim.y = dim.y*1; ddim.y = dim.y*1;
pos.x = 0.41f; pos.x = 0.41f;
@ -332,19 +332,22 @@ void CMainDialog::ChangePhase(Phase phase)
ddim.x = 0.09f; ddim.x = 0.09f;
pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_USER); pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_USER);
pb->SetState(STATE_SHADOW); pb->SetState(STATE_SHADOW);
try { try
CLevelParser* level = new CLevelParser("levels/custom/config.txt"); {
if(level->Exists()) { CLevelParser levelParser("levels/custom/config.txt");
level->Load(); if (levelParser.Exists())
CLevelParserLine* line = level->Get("Button"); {
if(line->GetParam("name")->IsDefined()) levelParser.Load();
CLevelParserLine* line = levelParser.Get("Button");
if (line->GetParam("name")->IsDefined())
pb->SetName(line->GetParam("name")->AsString()); pb->SetName(line->GetParam("name")->AsString());
if(line->GetParam("tooltip")->IsDefined()) if (line->GetParam("tooltip")->IsDefined())
pb->SetTooltip(line->GetParam("tooltip")->AsString()); pb->SetTooltip(line->GetParam("tooltip")->AsString());
} }
} }
catch(CLevelParserException& e) { catch (CLevelParserException& e)
{
CLogger::GetInstancePointer()->Error("Failed loading userlevel button name: %s\n", e.what()); 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 = pw->CreateCheck(pos, ddim, -1, EVENT_INTERFACE_FULL);
pc->SetState(STATE_SHADOW); pc->SetState(STATE_SHADOW);
pc->SetState(STATE_CHECK, m_setupFull); pc->SetState(STATE_CHECK, m_setupFull);
#if !PLATFORM_LINUX #if !PLATFORM_LINUX
ddim.x = 0.9f; ddim.x = 0.9f;
ddim.y = 0.1f; ddim.y = 0.1f;
@ -1211,7 +1214,7 @@ void CMainDialog::ChangePhase(Phase phase)
ddim.y = dim.y*1; ddim.y = dim.y*1;
pos.x = ox+sx*10; pos.x = ox+sx*10;
pos.y = oy+sy*2; pos.y = oy+sy*2;
pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_MIN); pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_MIN);
pb->SetState(STATE_SHADOW); pb->SetState(STATE_SHADOW);
pos.x += ddim.x; pos.x += ddim.x;
@ -1234,7 +1237,7 @@ void CMainDialog::ChangePhase(Phase phase)
//? pc = pw->CreateCheck(pos, ddim, -1, EVENT_INTERFACE_TOTO); //? pc = pw->CreateCheck(pos, ddim, -1, EVENT_INTERFACE_TOTO);
//? pc->SetState(STATE_SHADOW); //? pc->SetState(STATE_SHADOW);
//? pos.y -= 0.048f; //? pos.y -= 0.048f;
pc = pw->CreateCheck(pos, ddim, -1, EVENT_INTERFACE_MOVIES); pc = pw->CreateCheck(pos, ddim, -1, EVENT_INTERFACE_MOVIES);
pc->SetState(STATE_SHADOW); pc->SetState(STATE_SHADOW);
pos.y -= 0.048f; pos.y -= 0.048f;
@ -1257,7 +1260,7 @@ void CMainDialog::ChangePhase(Phase phase)
pc = pw->CreateCheck(pos, ddim, -1, EVENT_INTERFACE_AUTOSAVE_ENABLE); pc = pw->CreateCheck(pos, ddim, -1, EVENT_INTERFACE_AUTOSAVE_ENABLE);
pc->SetState(STATE_SHADOW); pc->SetState(STATE_SHADOW);
pos.y -= 0.048f; pos.y -= 0.048f;
pos.y -= ddim.y; pos.y -= ddim.y;
ddim.x = dim.x*2.5f; ddim.x = dim.x*2.5f;
psl = pw->CreateSlider(pos, ddim, -1, EVENT_INTERFACE_AUTOSAVE_INTERVAL); 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 = pw->CreateLabel(pos, ddim, 0, EVENT_LABEL1, name);
pl->SetTextAlign(Gfx::TEXT_ALIGN_LEFT); pl->SetTextAlign(Gfx::TEXT_ALIGN_LEFT);
pos.y -= ddim.y/2; pos.y -= ddim.y/2;
//? pos.y -= 0.048f; //? pos.y -= 0.048f;
//? pc = pw->CreateCheck(pos, ddim, -1, EVENT_INTERFACE_NICERST); //? pc = pw->CreateCheck(pos, ddim, -1, EVENT_INTERFACE_NICERST);
//? pc->SetState(STATE_SHADOW); //? pc->SetState(STATE_SHADOW);
@ -1717,7 +1720,7 @@ void CMainDialog::ChangePhase(Phase phase)
pl = pw->CreateLabel(pos, ddim, 0, EVENT_LABEL4, name); pl = pw->CreateLabel(pos, ddim, 0, EVENT_LABEL4, name);
pl->SetFontType(Gfx::FONT_COURIER); pl->SetFontType(Gfx::FONT_COURIER);
pl->SetFontSize(Gfx::FONT_SIZE_SMALL); pl->SetFontSize(Gfx::FONT_SIZE_SMALL);
pos.x = 306.0f/640.0f; pos.x = 306.0f/640.0f;
pos.y = 17.0f/480.0f; pos.y = 17.0f/480.0f;
ddim.x = 30.0f/640.0f; ddim.x = 30.0f/640.0f;
@ -1859,7 +1862,7 @@ bool CMainDialog::EventProcess(const Event &event)
{ {
m_shotDelay --; m_shotDelay --;
if ( m_shotDelay == 0 ) if ( m_shotDelay == 0 )
{ {
Math::IntPoint windowSize = m_engine->GetWindowSize(); Math::IntPoint windowSize = m_engine->GetWindowSize();
m_engine->WriteScreenShot(m_shotName, windowSize.x, windowSize.y); m_engine->WriteScreenShot(m_shotName, windowSize.x, windowSize.y);
@ -2601,19 +2604,19 @@ bool CMainDialog::EventProcess(const Event &event)
ChangeSetupButtons(); ChangeSetupButtons();
UpdateSetupButtons(); UpdateSetupButtons();
break; break;
case EVENT_INTERFACE_AUTOSAVE_ENABLE: case EVENT_INTERFACE_AUTOSAVE_ENABLE:
m_bAutosave = !m_bAutosave; m_bAutosave = !m_bAutosave;
m_main->SetAutosave(m_bAutosave); m_main->SetAutosave(m_bAutosave);
ChangeSetupButtons(); ChangeSetupButtons();
UpdateSetupButtons(); UpdateSetupButtons();
break; break;
case EVENT_INTERFACE_AUTOSAVE_INTERVAL: case EVENT_INTERFACE_AUTOSAVE_INTERVAL:
ChangeSetupButtons(); ChangeSetupButtons();
UpdateSetupButtons(); UpdateSetupButtons();
break; break;
case EVENT_INTERFACE_AUTOSAVE_SLOTS: case EVENT_INTERFACE_AUTOSAVE_SLOTS:
ChangeSetupButtons(); ChangeSetupButtons();
UpdateSetupButtons(); UpdateSetupButtons();
@ -2645,7 +2648,7 @@ bool CMainDialog::EventProcess(const Event &event)
break; break;
default: 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); ChangeKey(event.type);
UpdateKey(); UpdateKey();
@ -3345,7 +3348,7 @@ void CMainDialog::BuildScenePath(std::string &filename, char *base, int rank, bo
//TODO: Support for more than 9 chapters //TODO: Support for more than 9 chapters
int chapter = rank/100; int chapter = rank/100;
int new_rank = rank%100; int new_rank = rank%100;
filename = CLevelParser::BuildScenePath(std::string(base), chapter, new_rank, sceneFile); 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<std::string>(m_chap[m_index]+1); resume = std::string(m_sceneName) + " " + boost::lexical_cast<std::string>(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 try
{ {
level->Load(); levelParser.Load();
resume = level->Get("Title")->GetParam("resume")->AsString(); resume = levelParser.Get("Title")->GetParam("resume")->AsString();
} }
catch(CLevelParserException& e) catch (CLevelParserException& e)
{ {
CLogger::GetInstancePointer()->Warn("%s\n", e.what()); CLogger::GetInstancePointer()->Warn("%s\n", e.what());
} }
@ -3994,7 +3997,6 @@ void CMainDialog::IOReadName()
time(&now); time(&now);
TimeToAsciiClean(now, line); TimeToAsciiClean(now, line);
sprintf(name, "%s - %s %d", line, resume.c_str(), m_sel[m_index]+1); sprintf(name, "%s - %s %d", line, resume.c_str(), m_sel[m_index]+1);
delete level;
pe->SetText(name); pe->SetText(name);
pe->SetCursor(strlen(name), 0); pe->SetCursor(strlen(name), 0);
@ -4018,7 +4020,7 @@ void CMainDialog::IOReadList()
auto saveDirs = CResourceManager::ListDirectories(userSaveDir); auto saveDirs = CResourceManager::ListDirectories(userSaveDir);
//std::sort(saveDirs.begin(), saveDirs.end()); //std::sort(saveDirs.begin(), saveDirs.end());
std::map<int, std::string> sortedSaveDirs; std::map<int, std::string> sortedSaveDirs;
std::map<int, std::string> names; std::map<int, std::string> names;
@ -4027,15 +4029,14 @@ void CMainDialog::IOReadList()
std::string savegameFile = userSaveDir + "/" + dir + "/" + "data.sav"; std::string savegameFile = userSaveDir + "/" + dir + "/" + "data.sav";
if (CResourceManager::Exists(savegameFile)) if (CResourceManager::Exists(savegameFile))
{ {
CLevelParser* level = new CLevelParser(savegameFile); CLevelParser levelParser(savegameFile);
level->Load(); levelParser.Load();
int time = level->Get("Created")->GetParam("date")->AsInt(); int time = levelParser.Get("Created")->GetParam("date")->AsInt();
sortedSaveDirs[time] = userSaveDir + "/" + dir; sortedSaveDirs[time] = userSaveDir + "/" + dir;
names[time] = level->Get("Title")->GetParam("text")->AsString(); names[time] = levelParser.Get("Title")->GetParam("text")->AsString();
delete level;
} }
} }
for (auto dir : sortedSaveDirs) for (auto dir : sortedSaveDirs)
{ {
pl->SetItemName(m_saveList.size(), names[dir.first].c_str()); pl->SetItemName(m_saveList.size(), names[dir.first].c_str());
@ -4052,10 +4053,10 @@ void CMainDialog::IOReadList()
pl->SetSelect(m_saveList.size()); pl->SetSelect(m_saveList.size());
pl->ShowSelect(false); // shows the selected columns pl->ShowSelect(false); // shows the selected columns
unsigned int i; unsigned int i;
std::string screenName; std::string screenName;
for ( i=0; i < m_saveList.size(); i++ ) for ( i=0; i < m_saveList.size(); i++ )
{ {
screenName = "textures/../" + m_saveList.at(i) + "/screen.png"; 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); m_main->IOWriteScene(savegameFileName.c_str(), fileCBot.c_str(), info);
MakeSaveScreenshot(dir + "/screen.png"); MakeSaveScreenshot(dir + "/screen.png");
return true; return true;
} }
@ -4229,17 +4230,17 @@ bool CMainDialog::IOReadScene()
std::string fileName = m_saveList.at(sel) + "/" + "data.sav"; std::string fileName = m_saveList.at(sel) + "/" + "data.sav";
std::string fileCbot = CResourceManager::GetSaveLocation()+"/"+m_saveList.at(sel) + "/" + "cbot.run"; std::string fileCbot = CResourceManager::GetSaveLocation()+"/"+m_saveList.at(sel) + "/" + "cbot.run";
CLevelParser* level = new CLevelParser(fileName); CLevelParser levelParser(fileName);
level->Load(); levelParser.Load();
CLevelParserLine* line = level->Get("Mission"); CLevelParserLine* line = levelParser.Get("Mission");
strcpy(m_sceneName, line->GetParam("base")->AsString().c_str()); strcpy(m_sceneName, line->GetParam("base")->AsString().c_str());
m_sceneRank = line->GetParam("rank")->AsInt(); m_sceneRank = line->GetParam("rank")->AsInt();
if(std::string(m_sceneName) == "custom") if (std::string(m_sceneName) == "custom")
{ {
m_sceneRank = m_sceneRank%100; m_sceneRank = m_sceneRank%100;
std::string dir = line->GetParam("dir")->AsString(); std::string dir = line->GetParam("dir")->AsString();
for ( i=0 ; i<m_userTotal ; i++ ) for ( i=0 ; i<m_userTotal ; i++ )
{ {
@ -4251,12 +4252,9 @@ bool CMainDialog::IOReadScene()
} }
if ( m_sceneRank/100 == 0 ) if ( m_sceneRank/100 == 0 )
{ {
delete level;
return false; return false;
} }
} }
delete level;
m_chap[m_index] = (m_sceneRank / 100)-1; m_chap[m_index] = (m_sceneRank / 100)-1;
m_sel[m_index] = (m_sceneRank % 100)-1; m_sel[m_index] = (m_sceneRank % 100)-1;
@ -4331,14 +4329,14 @@ void CMainDialog::UpdateSceneChap(int &chap)
for ( j=0 ; j<m_userTotal ; j++ ) for ( j=0 ; j<m_userTotal ; j++ )
{ {
try { try
CLevelParser* level = new CLevelParser("custom", j+1, 0); {
level->Load(); CLevelParser levelParser("custom", j+1, 0);
pl->SetItemName(j, level->Get("Title")->GetParam("text")->AsString().c_str()); levelParser.Load();
pl->SetItemName(j, levelParser.Get("Title")->GetParam("text")->AsString().c_str());
pl->SetEnable(j, true); pl->SetEnable(j, true);
delete level;
} }
catch(CLevelParserException& e) catch (CLevelParserException& e)
{ {
pl->SetItemName(j, (std::string("[ERROR]: ")+e.what()).c_str()); pl->SetItemName(j, (std::string("[ERROR]: ")+e.what()).c_str());
pl->SetEnable(j, false); pl->SetEnable(j, false);
@ -4349,17 +4347,18 @@ void CMainDialog::UpdateSceneChap(int &chap)
{ {
for ( j=0 ; j<9 ; j++ ) for ( j=0 ; j<9 ; j++ )
{ {
CLevelParser* level = new CLevelParser(m_sceneName, j+1, 0); CLevelParser levelParser(m_sceneName, j+1, 0);
if(!level->Exists()) if (!levelParser.Exists())
break; break;
try { try
level->Load(); {
sprintf(line, "%d: %s", j+1, level->Get("Title")->GetParam("text")->AsString().c_str()); 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()); sprintf(line, "%s", (std::string("[ERROR]: ")+e.what()).c_str());
} }
delete level;
bPassed = GetGamerInfoPassed((j+1)*100); bPassed = GetGamerInfoPassed((j+1)*100);
pl->SetItemName(j, line); pl->SetItemName(j, line);
@ -4405,28 +4404,32 @@ void CMainDialog::UpdateSceneList(int chap, int &sel)
if ( pl == 0 ) return; if ( pl == 0 ) return;
pl->Flush(); pl->Flush();
if(chap < 0) return; if (chap < 0) return;
bool readAll = true; bool readAll = true;
for ( j=0 ; j<99 ; j++ ) for ( j=0 ; j<99 ; j++ )
{ {
CLevelParser* level = new CLevelParser(m_sceneName, chap+1, j+1); CLevelParser levelParser(m_sceneName, chap+1, j+1);
if(!level->Exists()) { if (!levelParser.Exists())
{
readAll = true; readAll = true;
break; break;
} else { }
if(!readAll) else
{
if (!readAll)
break; break;
} }
try { try
level->Load(); {
sprintf(line, "%d: %s", j+1, level->Get("Title")->GetParam("text")->AsString().c_str()); 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()); sprintf(line, "%s", (std::string("[ERROR]: ")+e.what()).c_str());
} }
delete level;
bPassed = GetGamerInfoPassed((chap+1)*100+(j+1)); bPassed = GetGamerInfoPassed((chap+1)*100+(j+1));
pl->SetItemName(j, line); pl->SetItemName(j, line);
@ -4439,7 +4442,7 @@ void CMainDialog::UpdateSceneList(int chap, int &sel)
} }
} }
if(readAll) if (readAll)
{ {
m_maxList = j; m_maxList = j;
} }
@ -4526,15 +4529,16 @@ void CMainDialog::UpdateSceneResume(int rank)
m_bSceneSoluce = false; m_bSceneSoluce = false;
} }
} }
if(rank<100) return; if (rank<100) return;
try { try
CLevelParser* level = new CLevelParser(m_sceneName, rank/100, rank%100); {
level->Load(); CLevelParser levelParser(m_sceneName, rank/100, rank%100);
pe->SetText(level->Get("Resume")->GetParam("text")->AsString().c_str()); 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()); pe->SetText((std::string("[ERROR]: ")+e.what()).c_str());
} }
@ -4588,9 +4592,9 @@ void CMainDialog::ChangeDisplay()
if ( pc == 0 ) return; if ( pc == 0 ) return;
bFull = pc->TestState(STATE_CHECK); bFull = pc->TestState(STATE_CHECK);
m_setupFull = bFull; m_setupFull = bFull;
SetupMemorize(); SetupMemorize();
#if !PLATFORM_LINUX #if !PLATFORM_LINUX
// Windows causes problems, so we'll restart the game // Windows causes problems, so we'll restart the game
// Mac OS was not tested so let's restart just to be sure // Mac OS was not tested so let's restart just to be sure
@ -4598,7 +4602,7 @@ void CMainDialog::ChangeDisplay()
#else #else
std::vector<Math::IntPoint> modes; std::vector<Math::IntPoint> modes;
m_app->GetVideoResolutionList(modes, true, true); m_app->GetVideoResolutionList(modes, true, true);
Gfx::DeviceConfig config = m_app->GetVideoConfig(); Gfx::DeviceConfig config = m_app->GetVideoConfig();
config.size = modes[m_setupSelMode]; config.size = modes[m_setupSelMode];
config.fullScreen = bFull; config.fullScreen = bFull;
@ -4744,21 +4748,21 @@ void CMainDialog::UpdateSetupButtons()
{ {
pc->SetState(STATE_CHECK, m_bBlood); pc->SetState(STATE_CHECK, m_bBlood);
} }
pc = static_cast<CCheck*>(pw->SearchControl(EVENT_INTERFACE_AUTOSAVE_ENABLE)); pc = static_cast<CCheck*>(pw->SearchControl(EVENT_INTERFACE_AUTOSAVE_ENABLE));
if ( pc != 0 ) if ( pc != 0 )
{ {
pc->SetState(STATE_CHECK, m_bAutosave); pc->SetState(STATE_CHECK, m_bAutosave);
} }
ps = static_cast<CSlider*>(pw->SearchControl(EVENT_INTERFACE_AUTOSAVE_INTERVAL)); ps = static_cast<CSlider*>(pw->SearchControl(EVENT_INTERFACE_AUTOSAVE_INTERVAL));
if ( ps != 0 ) if ( ps != 0 )
{ {
ps->SetState(STATE_ENABLE, m_bAutosave); ps->SetState(STATE_ENABLE, m_bAutosave);
ps->SetVisibleValue(m_main->GetAutosaveInterval()); ps->SetVisibleValue(m_main->GetAutosaveInterval());
} }
ps = static_cast<CSlider*>(pw->SearchControl(EVENT_INTERFACE_AUTOSAVE_SLOTS)); ps = static_cast<CSlider*>(pw->SearchControl(EVENT_INTERFACE_AUTOSAVE_SLOTS));
if ( ps != 0 ) if ( ps != 0 )
{ {
@ -4930,14 +4934,14 @@ void CMainDialog::ChangeSetupButtons()
value = ps->GetVisibleValue(); value = ps->GetVisibleValue();
m_sound->SetMusicVolume(static_cast<int>(value)); m_sound->SetMusicVolume(static_cast<int>(value));
} }
ps = static_cast<CSlider*>(pw->SearchControl(EVENT_INTERFACE_AUTOSAVE_INTERVAL)); ps = static_cast<CSlider*>(pw->SearchControl(EVENT_INTERFACE_AUTOSAVE_INTERVAL));
if ( ps != 0 ) if ( ps != 0 )
{ {
value = ps->GetVisibleValue(); value = ps->GetVisibleValue();
m_main->SetAutosaveInterval(static_cast<int>(value)); m_main->SetAutosaveInterval(static_cast<int>(value));
} }
ps = static_cast<CSlider*>(pw->SearchControl(EVENT_INTERFACE_AUTOSAVE_SLOTS)); ps = static_cast<CSlider*>(pw->SearchControl(EVENT_INTERFACE_AUTOSAVE_SLOTS));
if ( ps != 0 ) if ( ps != 0 )
{ {
@ -5108,22 +5112,22 @@ void CMainDialog::SetupRecall()
{ {
m_bBlood = iValue; m_bBlood = iValue;
} }
if ( GetProfile().GetIntProperty("Setup", "Autosave", iValue) ) if ( GetProfile().GetIntProperty("Setup", "Autosave", iValue) )
{ {
m_bAutosave = iValue; m_bAutosave = iValue;
} }
if ( GetProfile().GetIntProperty("Setup", "AutosaveInterval", iValue) ) if ( GetProfile().GetIntProperty("Setup", "AutosaveInterval", iValue) )
{ {
m_main->SetAutosaveInterval(iValue); m_main->SetAutosaveInterval(iValue);
} }
if ( GetProfile().GetIntProperty("Setup", "AutosaveSlots", iValue) ) if ( GetProfile().GetIntProperty("Setup", "AutosaveSlots", iValue) )
{ {
m_main->SetAutosaveSlots(iValue); m_main->SetAutosaveSlots(iValue);
} }
if ( GetProfile().GetIntProperty("Setup", "GroundShadow", iValue) ) if ( GetProfile().GetIntProperty("Setup", "GroundShadow", iValue) )
{ {
m_engine->SetShadow(iValue); m_engine->SetShadow(iValue);
@ -5232,15 +5236,18 @@ void CMainDialog::SetupRecall()
std::getline(resolution, ws, 'x'); std::getline(resolution, ws, 'x');
std::getline(resolution, hs, 'x'); std::getline(resolution, hs, 'x');
int w = 800, h = 600; int w = 800, h = 600;
if(!ws.empty() && !hs.empty()) { if (!ws.empty() && !hs.empty())
{
w = atoi(ws.c_str()); w = atoi(ws.c_str());
h = atoi(hs.c_str()); h = atoi(hs.c_str());
} }
std::vector<Math::IntPoint> modes; std::vector<Math::IntPoint> modes;
m_app->GetVideoResolutionList(modes, true, true); m_app->GetVideoResolutionList(modes, true, true);
for(auto it = modes.begin(); it != modes.end(); ++it) { for (auto it = modes.begin(); it != modes.end(); ++it)
if(it->x == w && it->y == h) { {
if (it->x == w && it->y == h)
{
m_setupSelMode = it - modes.begin(); m_setupSelMode = it - modes.begin();
break; break;
} }
@ -5959,24 +5966,26 @@ bool CMainDialog::GetHimselfDamage()
void CMainDialog::WriteGamerPerso(char *gamer) void CMainDialog::WriteGamerPerso(char *gamer)
{ {
try { try
CLevelParser* perso = new CLevelParser(GetSavegameDir()+"/"+gamer+"/face.gam"); {
CLevelParserLine* line; CLevelParser persoParser(GetSavegameDir()+"/"+gamer+"/face.gam");
CLevelParserLineUPtr 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);
perso->Save(); line.reset(new CLevelParserLine("Head"));
delete perso; line->AddParam("face", CLevelParserParamUPtr{new CLevelParserParam(m_perso.face)});
} catch(CLevelParserException& e) { 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()); 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; m_perso.face = 0;
DefPerso(); DefPerso();
if(!CResourceManager::Exists(GetSavegameDir()+"/"+gamer+"/face.gam")) if (!CResourceManager::Exists(GetSavegameDir()+"/"+gamer+"/face.gam"))
return; return;
try { try
CLevelParser* perso = new CLevelParser(GetSavegameDir()+"/"+gamer+"/face.gam"); {
perso->Load(); CLevelParser persoParser(GetSavegameDir()+"/"+gamer+"/face.gam");
persoParser.Load();
CLevelParserLine* line; CLevelParserLine* line;
line = perso->Get("Head"); line = persoParser.Get("Head");
m_perso.face = line->GetParam("face")->AsInt(); m_perso.face = line->GetParam("face")->AsInt();
m_perso.glasses = line->GetParam("glasses")->AsInt(); m_perso.glasses = line->GetParam("glasses")->AsInt();
m_perso.colorHair = line->GetParam("hair")->AsColor(); m_perso.colorHair = line->GetParam("hair")->AsColor();
line = perso->Get("Body"); line = persoParser.Get("Body");
m_perso.colorCombi = line->GetParam("combi")->AsColor(); m_perso.colorCombi = line->GetParam("combi")->AsColor();
m_perso.colorBand = line->GetParam("band")->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()); 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; 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; return false;
CInputStream file; CInputStream file;
file.open(GetSavegameDir()+"/"+m_main->GetGamerName()+"/"+m_sceneName+".gam"); 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"); CLogger::GetInstancePointer()->Error("Unable to read list of finished missions\n");
return false; return false;
} }
std::getline(file, line); std::getline(file, line);
sscanf(line.c_str(), "CurrentChapter=%d CurrentSel=%d\n", &chap, &i); sscanf(line.c_str(), "CurrentChapter=%d CurrentSel=%d\n", &chap, &i);
m_chap[m_index] = chap-1; m_chap[m_index] = chap-1;
m_sel[m_index] = i-1; m_sel[m_index] = i-1;
while(!file.eof()) while (!file.eof())
{ {
std::getline(file, line); std::getline(file, line);
if(line == "") if (line == "")
{ {
break; break;
} }
sscanf(line.c_str(), "Chapter %d: Scene %d: numTry=%d passed=%d\n", sscanf(line.c_str(), "Chapter %d: Scene %d: numTry=%d passed=%d\n",
&chap, &i, &numTry, &passed); &chap, &i, &numTry, &passed);
@ -6125,7 +6136,8 @@ bool CMainDialog::WriteGamerInfo()
COutputStream file; COutputStream file;
file.open(GetSavegameDir()+"/"+m_main->GetGamerName()+"/"+m_sceneName+".gam"); 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"); CLogger::GetInstancePointer()->Error("Unable to read list of finished missions\n");
return false; return false;
} }