diff --git a/src/action/action_attack.cpp b/src/action/action_attack.cpp index 337f904a59..cc39ae1e96 100644 --- a/src/action/action_attack.cpp +++ b/src/action/action_attack.cpp @@ -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); diff --git a/src/action/action_board.cpp b/src/action/action_board.cpp index fd4850343a..cfdc9d4b35 100644 --- a/src/action/action_board.cpp +++ b/src/action/action_board.cpp @@ -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); diff --git a/src/action/action_build.cpp b/src/action/action_build.cpp index 24497193ee..c45a3fb2d8 100644 --- a/src/action/action_build.cpp +++ b/src/action/action_build.cpp @@ -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); diff --git a/src/action/action_built.cpp b/src/action/action_built.cpp index da64a43a5d..b495cf7253 100644 --- a/src/action/action_built.cpp +++ b/src/action/action_built.cpp @@ -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); diff --git a/src/action/action_defend.cpp b/src/action/action_defend.cpp index bb3d6532c7..c0625f6316 100644 --- a/src/action/action_defend.cpp +++ b/src/action/action_defend.cpp @@ -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); diff --git a/src/action/action_follow.cpp b/src/action/action_follow.cpp index a02d6cdcda..3f22c7060e 100644 --- a/src/action/action_follow.cpp +++ b/src/action/action_follow.cpp @@ -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); diff --git a/src/action/action_repair.cpp b/src/action/action_repair.cpp index 64828f45ea..92a1b3bb08 100644 --- a/src/action/action_repair.cpp +++ b/src/action/action_repair.cpp @@ -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); diff --git a/src/action/action_resource.cpp b/src/action/action_resource.cpp index 8b3ef870f3..7783154deb 100644 --- a/src/action/action_resource.cpp +++ b/src/action/action_resource.cpp @@ -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\","); diff --git a/src/action/action_spellcast.cpp b/src/action/action_spellcast.cpp index a49941aa56..5eedd12f3c 100644 --- a/src/action/action_spellcast.cpp +++ b/src/action/action_spellcast.cpp @@ -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); diff --git a/src/action/action_unload.cpp b/src/action/action_unload.cpp index d714f437d1..5c51df8935 100644 --- a/src/action/action_unload.cpp +++ b/src/action/action_unload.cpp @@ -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); diff --git a/src/include/unit.h b/src/include/unit.h index 23af8a7813..f9f6d52f64 100644 --- a/src/include/unit.h +++ b/src/include/unit.h @@ -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); diff --git a/src/include/unitptr.h b/src/include/unitptr.h index e3a31746cd..87323c1144 100644 --- a/src/include/unitptr.h +++ b/src/include/unitptr.h @@ -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(); } diff --git a/src/missile/missile.cpp b/src/missile/missile.cpp index 07ff518621..3b643c2db7 100644 --- a/src/missile/missile.cpp +++ b/src/missile/missile.cpp @@ -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); diff --git a/src/unit/unit_save.cpp b/src/unit/unit_save.cpp index 5b10415abf..ae0a09ff77 100644 --- a/src/unit/unit_save.cpp +++ b/src/unit/unit_save.cpp @@ -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\", {");