From 13fc7cc3b379e92f94170a1631651f615c67de61 Mon Sep 17 00:00:00 2001 From: cryham Date: Tue, 30 Apr 2024 23:10:56 +0200 Subject: [PATCH] career xml --- src/game/data/CareerXml.cpp | 43 +++++++++++++++++++++++++-------- src/game/data/CareerXml.h | 4 +-- src/vdrift/cardynamics_load.cpp | 2 +- 3 files changed, 36 insertions(+), 13 deletions(-) diff --git a/src/game/data/CareerXml.cpp b/src/game/data/CareerXml.cpp index d33b5cd0..9feac2ed 100644 --- a/src/game/data/CareerXml.cpp +++ b/src/game/data/CareerXml.cpp @@ -28,21 +28,22 @@ bool ProgressCareer::LoadXml(std::string file) XMLElement* ec = root->FirstChildElement("career"), *e; if (ec) { - a = ec->Attribute("mode"); mode = s2i(a); - a = ec->Attribute("money"); money = s2r(a); - a = ec->Attribute("diff"); diff_rank = s2i(a); + e = ec->FirstChildElement("cur"); + a = e->Attribute("mode"); if (a) mode = s2i(a); + a = e->Attribute("money"); if (a) money = s2r(a); + a = e->Attribute("diff"); if (a) diff_rank = s2i(a); e = ec->FirstChildElement("fuels"); - a = e->Attribute("car"); if (a) fuels.car = s2r(a); + a = e->Attribute("car"); if (a) fuels.car = s2r(a); // stats e = ec->FirstChildElement("stats"); - a = e->Attribute("time"); totalTime = s2r(a); - a = e->Attribute("raced"); raced = s2i(a); + a = e->Attribute("time"); if (a) totalTime = s2r(a); + a = e->Attribute("raced"); if (a) raced = s2i(a); - a = e->Attribute("pos1"); pos1 = s2i(a); a = e->Attribute("pos2"); pos2 = s2i(a); - a = e->Attribute("pos3"); pos3 = s2i(a); a = e->Attribute("pos4"); pos4 = s2i(a); - a = e->Attribute("pos5"); pos5up = s2i(a); + a = e->Attribute("pos1"); if (a) pos1 = s2i(a); a = e->Attribute("pos2"); if (a) pos2 = s2i(a); + a = e->Attribute("pos3"); if (a) pos3 = s2i(a); a = e->Attribute("pos4"); if (a) pos4 = s2i(a); + a = e->Attribute("pos5"); if (a) pos5up = s2i(a); // cars / vehicles XMLElement* ev = ec->FirstChildElement("veh"); @@ -62,10 +63,32 @@ bool ProgressCareer::LoadXml(std::string file) } // Save career xml +//------------------------------------------------------------------------------------------------------------- bool ProgressCareer::SaveXml(std::string file) { XMLDocument xml; - XMLElement* root = xml.NewElement("career"); + XMLElement* root = xml.NewElement("career"), *e; + + e = xml.NewElement("cur"); + e->SetAttribute("mode", toStrC( mode )); + e->SetAttribute("money", toStrC( money )); + e->SetAttribute("diff", toStrC( diff_rank )); + root->InsertEndChild(e); + + e = xml.NewElement("fuels"); + e->SetAttribute("car", toStrC( fuels.car )); + root->InsertEndChild(e); + + e = xml.NewElement("stats"); + e->SetAttribute("time", toStrC( totalTime )); + e->SetAttribute("raced", toStrC( raced )); + + e->SetAttribute("pos1", toStrC( pos1 )); + e->SetAttribute("pos2", toStrC( pos2 )); + e->SetAttribute("pos3", toStrC( pos3 )); + e->SetAttribute("pos4", toStrC( pos4 )); + e->SetAttribute("pos5", toStrC( pos5up )); + root->InsertEndChild(e); for (int i=0; i < cars.size(); ++i) { diff --git a/src/game/data/CareerXml.h b/src/game/data/CareerXml.h index 082fa03a..75445bb3 100644 --- a/src/game/data/CareerXml.h +++ b/src/game/data/CareerXml.h @@ -68,7 +68,7 @@ class ProgressCareer public: int mode = 0; // easy, medium, hard float money = 0.f; // credits amount - int diff_rank; // difficulty rank + int diff_rank = 0; // difficulty rank std::vector cars; // owned vehicles struct SFuels @@ -90,7 +90,7 @@ class ProgressCareer int raced = 0.f; // tracks raced // tracks race places counts // i.e. how many times won 1st place on any track - int pos1 =0, pos2 =0, pos3 =0, pos4, pos5up =0; + int pos1 =0, pos2 =0, pos3 =0, pos4 =0, pos5up =0; bool LoadXml(std::string file), SaveXml(std::string file); }; diff --git a/src/vdrift/cardynamics_load.cpp b/src/vdrift/cardynamics_load.cpp index bb0c133a..014a0e62 100644 --- a/src/vdrift/cardynamics_load.cpp +++ b/src/vdrift/cardynamics_load.cpp @@ -301,7 +301,7 @@ bool CARDYNAMICS::Load(GAME* game, CONFIGFILE& c) diff_center3.SetFinalDrive(final); diff_center3.SetAntiSlip(a, a_tq, a_tq_dec); } else - { LogO(".car Error: Unknown drive type: "+drive); + { LogO(".car Error: Unknown drive type: "+drivet); return false; } }