Skip to content

Commit

Permalink
Merge pull request #649 from Wargus/unitref
Browse files Browse the repository at this point in the history
Unitref
  • Loading branch information
Jarod42 authored Apr 4, 2024
2 parents 8fc31ab + b1680e0 commit b48e434
Show file tree
Hide file tree
Showing 14 changed files with 18 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/action/action_attack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ void COrder_Attack::Save(CFile &file, const CUnit &unit) const /* override */
file.printf(" \"finished\", ");
}
if (this->HasGoal()) {
file.printf(" \"goal\", \"%s\",", UnitReference(this->GetGoal()).c_str());
file.printf(" \"goal\", \"%s\",", UnitReference(*this->GetGoal()).c_str());
}
file.printf(" \"tile\", {%d, %d},", this->goalPos.x, this->goalPos.y);
file.printf(" \"amove-tile\", {%d, %d},", this->attackMovePos.x, this->attackMovePos.y);
Expand Down
2 changes: 1 addition & 1 deletion src/action/action_board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ enum {
}
file.printf(" \"range\", %d,", this->Range);
if (this->HasGoal()) {
file.printf(" \"goal\", \"%s\",", UnitReference(this->GetGoal()).c_str());
file.printf(" \"goal\", \"%s\",", UnitReference(*this->GetGoal()).c_str());
}
file.printf(" \"state\", %d", this->State);

Expand Down
2 changes: 1 addition & 1 deletion src/action/action_build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void COrder_Build::Save(CFile &file, const CUnit &unit) const /* override */
file.printf(" \"tile\", {%d, %d},", this->goalPos.x, this->goalPos.y);

if (this->BuildingUnit != nullptr) {
file.printf(" \"building\", \"%s\",", UnitReference(this->BuildingUnit).c_str());
file.printf(" \"building\", \"%s\",", UnitReference(*this->BuildingUnit).c_str());
}
file.printf(" \"type\", \"%s\",", this->Type->Ident.c_str());
file.printf(" \"state\", %d", this->State);
Expand Down
2 changes: 1 addition & 1 deletion src/action/action_built.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void COrder_Built::Save(CFile &file, const CUnit &unit) const /* override */
file.printf(" \"finished\", ");
}
if (this->Worker != nullptr) {
file.printf("\"worker\", \"%s\", ", UnitReference(this->Worker).c_str());
file.printf("\"worker\", \"%s\", ", UnitReference(*this->Worker).c_str());
}
const int frame = this->Frame;
file.printf("\"progress\", %d, \"frame\", %d", this->ProgressCounter, frame);
Expand Down
2 changes: 1 addition & 1 deletion src/action/action_defend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void COrder_Defend::Save(CFile &file, const CUnit &unit) const /* override */
}
file.printf(" \"range\", %d,", this->Range);
if (this->HasGoal()) {
file.printf(" \"goal\", \"%s\",", UnitReference(this->GetGoal()).c_str());
file.printf(" \"goal\", \"%s\",", UnitReference(*this->GetGoal()).c_str());
}
file.printf(" \"tile\", {%d, %d},", this->goalPos.x, this->goalPos.y);

Expand Down
2 changes: 1 addition & 1 deletion src/action/action_follow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void COrder_Follow::Save(CFile &file, const CUnit &unit) const /* override */
}
file.printf(" \"range\", %d,", this->Range);
if (this->HasGoal()) {
file.printf(" \"goal\", \"%s\",", UnitReference(this->GetGoal()).c_str());
file.printf(" \"goal\", \"%s\",", UnitReference(*this->GetGoal()).c_str());
}
file.printf(" \"tile\", {%d, %d},", this->goalPos.x, this->goalPos.y);

Expand Down
4 changes: 2 additions & 2 deletions src/action/action_repair.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ void COrder_Repair::Save(CFile &file, const CUnit &unit) const /* override */
file.printf(" \"finished\", ");
}
if (this->HasGoal()) {
file.printf(" \"goal\", \"%s\",", UnitReference(this->GetGoal()).c_str());
file.printf(" \"goal\", \"%s\",", UnitReference(*this->GetGoal()).c_str());
}
file.printf(" \"tile\", {%d, %d},", this->goalPos.x, this->goalPos.y);

if (this->ReparableTarget != nullptr) {
file.printf(" \"repair-target\", \"%s\",", UnitReference(this->GetReparableTarget()).c_str());
file.printf(" \"repair-target\", \"%s\",", UnitReference(*this->GetReparableTarget()).c_str());
}

file.printf(" \"repaircycle\", %d,", this->RepairCycle);
Expand Down
8 changes: 4 additions & 4 deletions src/action/action_resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,20 +251,20 @@ void COrder_Resource::Save(CFile &file, const CUnit &unit) const /* override */
file.printf(" \"finished\",");
}
if (this->HasGoal()) {
file.printf(" \"goal\", \"%s\",", UnitReference(this->GetGoal()).c_str());
file.printf(" \"goal\", \"%s\",", UnitReference(*this->GetGoal()).c_str());
}
file.printf(" \"tile\", {%d, %d},", this->goalPos.x, this->goalPos.y);

Assert(this->worker != nullptr && worker->IsAlive());
file.printf(" \"worker\", \"%s\",", UnitReference(worker).c_str());
file.printf(" \"worker\", \"%s\",", UnitReference(*worker).c_str());
file.printf(" \"current-res\", %d,", this->CurrentResource);

file.printf(" \"res-pos\", {%d, %d},", this->Resource.Pos.x, this->Resource.Pos.y);
if (this->Resource.Mine != nullptr) {
file.printf(" \"res-mine\", \"%s\",", UnitReference(this->Resource.Mine).c_str());
file.printf(" \"res-mine\", \"%s\",", UnitReference(*this->Resource.Mine).c_str());
}
if (this->Depot != nullptr) {
file.printf(" \"res-depot\", \"%s\",", UnitReference(this->Depot).c_str());
file.printf(" \"res-depot\", \"%s\",", UnitReference(*this->Depot).c_str());
}
if (this->DoneHarvesting) {
file.printf(" \"done-harvesting\",");
Expand Down
2 changes: 1 addition & 1 deletion src/action/action_spellcast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void COrder_SpellCast::Save(CFile &file, const CUnit &unit) const /* override */
}
file.printf(" \"range\", %d,", this->Range);
if (this->HasGoal()) {
file.printf(" \"goal\", \"%s\",", UnitReference(this->GetGoal()).c_str());
file.printf(" \"goal\", \"%s\",", UnitReference(*this->GetGoal()).c_str());
}
file.printf(" \"tile\", {%d, %d},", this->goalPos.x, this->goalPos.y);

Expand Down
2 changes: 1 addition & 1 deletion src/action/action_unload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void COrder_Unload::Save(CFile &file, const CUnit &unit) const /* override */
}
file.printf(" \"retries\", %d,", this->Retries);
if (this->HasGoal()) {
file.printf(" \"goal\", \"%s\",", UnitReference(this->GetGoal()).c_str());
file.printf(" \"goal\", \"%s\",", UnitReference(*this->GetGoal()).c_str());
}
file.printf(" \"tile\", {%d, %d}, ", this->goalPos.x, this->goalPos.y);
file.printf("\"state\", %d", this->State);
Expand Down
2 changes: 0 additions & 2 deletions src/include/unit.h
Original file line number Diff line number Diff line change
Expand Up @@ -652,8 +652,6 @@ extern bool CanTransport(const CUnit &transporter, const CUnit &unit);

/// Generate a unit reference, a printable unique string for unit
extern std::string UnitReference(const CUnit &unit);
/// Generate a unit reference, a printable unique string for unit
extern std::string UnitReference(const CUnitPtr &unit);

/// save unit-structure
extern void SaveUnit(const CUnit &unit, CFile &file);
Expand Down
3 changes: 2 additions & 1 deletion src/include/unitptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ class CUnitPtr
{
public:
CUnitPtr() : unit(nullptr) {}
CUnitPtr(CUnit *u);
CUnitPtr(std::nullptr_t) : unit(nullptr) {}
explicit CUnitPtr(CUnit *u);
CUnitPtr(const CUnitPtr &u);
~CUnitPtr() { Reset(); }

Expand Down
4 changes: 2 additions & 2 deletions src/missile/missile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1212,10 +1212,10 @@ void Missile::SaveMissile(CFile &file) const
file.printf(",\n \"frame\", %d, \"state\", %d, \"anim-wait\", %d, \"wait\", %d, \"delay\", %d,\n ",
this->SpriteFrame, this->State, this->AnimWait, this->Wait, this->Delay);
if (this->SourceUnit != nullptr) {
file.printf(" \"source\", \"%s\",", UnitReference(this->SourceUnit).c_str());
file.printf(" \"source\", \"%s\",", UnitReference(*this->SourceUnit).c_str());
}
if (this->TargetUnit != nullptr) {
file.printf(" \"target\", \"%s\",", UnitReference(this->TargetUnit).c_str());
file.printf(" \"target\", \"%s\",", UnitReference(*this->TargetUnit).c_str());
}
file.printf(" \"damage\", %d,", this->Damage);
file.printf(" \"ttl\", %d,", this->TTL);
Expand Down
9 changes: 0 additions & 9 deletions src/unit/unit_save.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,6 @@ std::string UnitReference(const CUnit &unit)
return ss.str();
}

/**
** Generate a unit reference, a printable unique string for unit.
*/
std::string UnitReference(const CUnitPtr &unit)
{
Assert(unit != nullptr);
return UnitReference(*unit);
}

void PathFinderInput::Save(CFile &file) const
{
file.printf("\"pathfinder-input\", {");
Expand Down

0 comments on commit b48e434

Please sign in to comment.