mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-07-04 05:55:47 -07:00
Fix AI errors when promoting an athenian spearman to champion.
Ideally the AI would try to carry on and recover gracefully but the code is setup in such a way that this seems like it would lead to a lot of different bugs down the line.
With help from @langbart on QA and code.
Fixes #7425
(cherry picked from commit c20ca02911)
Signed-off-by: Itms <itms@wildfiregames.com>
This commit is contained in:
parent
85363e861e
commit
9798b9180b
2 changed files with 15 additions and 3 deletions
|
|
@ -549,7 +549,7 @@ PETRA.BaseManager.prototype.assignRolelessUnits = function(gameState, roleless)
|
|||
if (ent.hasClasses(["Worker", "CitizenSoldier", "FishingBoat"]))
|
||||
ent.setMetadata(PlayerID, "role", PETRA.Worker.ROLE_WORKER);
|
||||
else if (ent.hasClass("Support") && ent.hasClass("Elephant"))
|
||||
ent.setMetadata(PlayerID, "role", "worker");
|
||||
ent.setMetadata(PlayerID, "role", PETRA.Worker.ROLE_WORKER);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -150,9 +150,21 @@ PETRA.BasesManager.prototype.checkEvents = function(gameState, events)
|
|||
for (const evt of events.EntityRenamed)
|
||||
{
|
||||
const ent = gameState.getEntityById(evt.newentity);
|
||||
if (!ent || ent.owner() != PlayerID || ent.getMetadata(PlayerID, "base") === undefined)
|
||||
const baseID = ent?.getMetadata(PlayerID, "base");
|
||||
if (!ent || ent.owner() != PlayerID || baseID === undefined)
|
||||
continue;
|
||||
const base = this.getBaseByID(ent.getMetadata(PlayerID, "base"));
|
||||
|
||||
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]);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Handle cases where a base anchor changes
|
||||
if (!base.anchorId || base.anchorId != evt.entity)
|
||||
continue;
|
||||
base.anchorId = evt.newentity;
|
||||
|
|
|
|||
Loading…
Reference in a new issue