Skip to content

Commit

Permalink
career xml
Browse files Browse the repository at this point in the history
  • Loading branch information
cryham committed Apr 30, 2024
1 parent caba6ee commit 13fc7cc
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 13 deletions.
43 changes: 33 additions & 10 deletions src/game/data/CareerXml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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)
{
Expand Down
4 changes: 2 additions & 2 deletions src/game/data/CareerXml.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<ProgressCar> cars; // owned vehicles

struct SFuels
Expand All @@ -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);
};
Expand Down
2 changes: 1 addition & 1 deletion src/vdrift/cardynamics_load.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down

0 comments on commit 13fc7cc

Please sign in to comment.