Merge pull request #948 from Pax1601/bugfix/v1/wrong-unit-on-reconnection

Bugfix/v1/wrong unit on reconnection
This commit is contained in:
Pax1601 2024-11-25 10:17:14 +01:00 committed by GitHub
commit a6e28e9064
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 11 deletions

View File

@ -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; }

View File

@ -27,6 +27,13 @@ Unit::~Unit()
}
void Unit::initialize(json::value json)
{
update(json, 0);
setDefaults();
}
void Unit::update(json::value json, double dt)
{
if (json.has_string_field(L"name"))
setName(to_string(json[L"name"]));
@ -42,21 +49,13 @@ void Unit::initialize(json::value json)
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();
}
void Unit::update(json::value json, double dt)
{
if (json.has_object_field(L"position"))
{
setPosition({