mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-11-08 10:09:16 +00:00
Cache canAttackTarget per template in DefenseArmy.assignUnit
For a foe which is not capturable, allowCapture has no effect and the result of canAttackTarget only depends on the template of the unit. Cache it in the foe info, which is rebuilt each turn.
This commit is contained in:
1 parent
ec1ed0c84f
commit
9e78a3fe92
1 file changed
+12
-3
@@ -29,9 +29,9 @@ function getFoeInfo(gameState, foeEntities)
|
|||||||
if (orderData && orderData.length && orderData[0].target)
|
if (orderData && orderData.length && orderData[0].target)
|
||||||
attackTarget = orderData[0].target;
|
attackTarget = orderData[0].target;
|
||||||
}
|
}
|
||||||
// "heavy" and "access" are filled lazily.
|
// "heavy", "access" and the entries of "canAttack" are filled lazily.
|
||||||
info.push({ "id": id, "ent": eEnt, "position": position, "attackTarget": attackTarget,
|
info.push({ "id": id, "ent": eEnt, "position": position, "attackTarget": attackTarget,
|
||||||
"heavy": undefined, "access": undefined });
|
"capturable": eEnt.isCapturable(), "canAttack": new Map(), "heavy": undefined, "access": undefined });
|
||||||
}
|
}
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
@@ -346,6 +346,7 @@ export class DefenseArmy
|
|||||||
const pos = ent.position();
|
const pos = ent.position();
|
||||||
if (!pos)
|
if (!pos)
|
||||||
return false;
|
return false;
|
||||||
|
const template = ent.templateName();
|
||||||
|
|
||||||
// try to return its resources, and if any, the attack order will be queued
|
// try to return its resources, and if any, the attack order will be queued
|
||||||
const queued = returnResources(gameState, ent);
|
const queued = returnResources(gameState, ent);
|
||||||
@@ -359,7 +360,15 @@ export class DefenseArmy
|
|||||||
for (const foe of this.foeInfo)
|
for (const foe of this.foeInfo)
|
||||||
{
|
{
|
||||||
const eEnt = foe.ent;
|
const eEnt = foe.ent;
|
||||||
if (!ent.canAttackTarget(eEnt, allowCapture(gameState, ent, eEnt)))
|
// For a foe which is not capturable, allowCapture has no effect, so the result only depends on the template.
|
||||||
|
let canAttack = foe.canAttack.get(template);
|
||||||
|
if (canAttack === undefined)
|
||||||
|
{
|
||||||
|
canAttack = ent.canAttackTarget(eEnt, allowCapture(gameState, ent, eEnt));
|
||||||
|
if (!foe.capturable)
|
||||||
|
foe.canAttack.set(template, canAttack);
|
||||||
|
}
|
||||||
|
if (!canAttack)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (foe.attackTarget === entID)
|
if (foe.attackTarget === entID)
|
||||||
|
|||||||
Reference in new issue
Block a user