From 19fda90656c7aac3ef1fd63028ac5ba4449b1f94 Mon Sep 17 00:00:00 2001 From: Langbart Date: Wed, 8 Jan 2025 01:35:37 +0100 Subject: [PATCH] fix: reset promoted worker metadata fix: #7471 (cherry picked from commit 6b87a9b932bf0a58906caffade7c8a6ca3252b8b) Signed-off-by: Itms --- .../public/simulation/ai/petra/baseManager.js | 2 +- .../public/simulation/ai/petra/basesManager.js | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/binaries/data/mods/public/simulation/ai/petra/baseManager.js b/binaries/data/mods/public/simulation/ai/petra/baseManager.js index 68e1773f39..3ba07c198a 100644 --- a/binaries/data/mods/public/simulation/ai/petra/baseManager.js +++ b/binaries/data/mods/public/simulation/ai/petra/baseManager.js @@ -657,7 +657,7 @@ PETRA.BaseManager.prototype.reassignIdleWorkers = function(gameState, idleWorker // Support elephant can only be builders if (ent.hasClass("Support") && ent.hasClass("Elephant")) { - ent.setMetadata(PlayerID, "subrole", "idle"); + ent.setMetadata(PlayerID, "subrole", PETRA.Worker.SUBROLE_IDLE); continue; } diff --git a/binaries/data/mods/public/simulation/ai/petra/basesManager.js b/binaries/data/mods/public/simulation/ai/petra/basesManager.js index 33bd4bd3e1..90e4a26a1a 100644 --- a/binaries/data/mods/public/simulation/ai/petra/basesManager.js +++ b/binaries/data/mods/public/simulation/ai/petra/basesManager.js @@ -157,10 +157,17 @@ PETRA.BasesManager.prototype.checkEvents = function(gameState, events) const base = this.getBaseByID(baseID); // Promoted workers should be reset - their new gathering rates/capabilities might differ meaningfully. - if (ent.getMetadata(PlayerID, "role") === PETRA.Worker.ROLE_WORKER) { - ent.deleteAllMetadata(PlayerID); - ent.setMetadata(PlayerID, "base", baseID); - base.assignRolelessUnits(undefined, [ent]); + if (ent.getMetadata(PlayerID, "role") === PETRA.Worker.ROLE_WORKER) + { + ent.setMetadata(PlayerID, "subrole", PETRA.Worker.SUBROLE_IDLE); + if (!ent.isGatherer()) + { + // TODO: Find a way to properly reset the metadata, as this is currently done selectively + ent.setMetadata(PlayerID, "gather-type", undefined); + ent.setMetadata(PlayerID, "supply", undefined); + ent.setMetadata(PlayerID, "role", undefined); + base.assignRolelessUnits(gameState, [ent]); + } continue; }