From 064c24e02368e481fbbe767c4085b93c1ae1aafd Mon Sep 17 00:00:00 2001 From: MarcoJayUsai Date: Mon, 18 Nov 2024 21:56:01 +0100 Subject: [PATCH 1/2] fix(map): reconnecting players will not be displayed with wrong name or wrong coalition --- backend/core/src/unit.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/backend/core/src/unit.cpp b/backend/core/src/unit.cpp index 4bd03fba..5c5050f0 100644 --- a/backend/core/src/unit.cpp +++ b/backend/core/src/unit.cpp @@ -57,6 +57,21 @@ void Unit::initialize(json::value json) void Unit::update(json::value json, double dt) { + if (json.has_string_field(L"name")) + setName(to_string(json[L"name"])); + + if (json.has_string_field(L"unitName")) + setUnitName(to_string(json[L"unitName"])); + + if (json.has_string_field(L"groupName")) + setGroupName(to_string(json[L"groupName"])); + + if (json.has_string_field(L"callsign")) + setCallsign(to_string(json[L"callsign"])); + + if (json.has_number_field(L"coalitionID")) + setCoalition(json[L"coalitionID"].as_number().to_int32()); + if (json.has_object_field(L"position")) { setPosition({ From 89051c3e85b15371c67fffe65ecc9f3f4e206e45 Mon Sep 17 00:00:00 2001 From: MarcoJayUsai Date: Tue, 19 Nov 2024 13:58:16 +0100 Subject: [PATCH 2/2] refactor(unit): moved data update code from initialize to update; made initialize and update final --- backend/core/include/unit.h | 4 ++-- backend/core/src/unit.cpp | 28 ++++++---------------------- 2 files changed, 8 insertions(+), 24 deletions(-) diff --git a/backend/core/include/unit.h b/backend/core/include/unit.h index a4ded619..83f39c4b 100644 --- a/backend/core/include/unit.h +++ b/backend/core/include/unit.h @@ -19,12 +19,12 @@ public: ~Unit(); /********** Methods **********/ - void initialize(json::value json); + virtual void initialize(json::value json) final; virtual void setDefaults(bool force = false); void runAILoop(); - void update(json::value json, double dt); + virtual void update(json::value json, double dt) final; void refreshLeaderData(unsigned long long time); unsigned int getID() { return ID; } diff --git a/backend/core/src/unit.cpp b/backend/core/src/unit.cpp index 5c5050f0..0ad51970 100644 --- a/backend/core/src/unit.cpp +++ b/backend/core/src/unit.cpp @@ -28,28 +28,6 @@ Unit::~Unit() void Unit::initialize(json::value json) { - if (json.has_string_field(L"name")) - setName(to_string(json[L"name"])); - - if (json.has_string_field(L"unitName")) - setUnitName(to_string(json[L"unitName"])); - - if (json.has_string_field(L"groupName")) - setGroupName(to_string(json[L"groupName"])); - - if (json.has_string_field(L"callsign")) - setCallsign(to_string(json[L"callsign"])); - - if (json.has_number_field(L"coalitionID")) - setCoalition(json[L"coalitionID"].as_number().to_int32()); - - //if (json.has_number_field(L"Country")) - // setCountry(json[L"Country"].as_number().to_int32()); - - /* All units which contain the name "Olympus" are automatically under AI control */ - if (getUnitName().find("Olympus") != string::npos) - setControlled(true); - update(json, 0); setDefaults(); } @@ -71,6 +49,12 @@ void Unit::update(json::value json, double dt) if (json.has_number_field(L"coalitionID")) setCoalition(json[L"coalitionID"].as_number().to_int32()); + //if (json.has_number_field(L"Country")) + // setCountry(json[L"Country"].as_number().to_int32()); + + /* All units which contain the name "Olympus" are automatically under AI control */ + if (getUnitName().find("Olympus") != string::npos) + setControlled(true); if (json.has_object_field(L"position")) {