mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-11-08 10:29:00 +00:00
assignUnit looped over all the foes of the army for every unit assigned and, for each (unit, foe) pair, fetched the foe entity and its position, tested its class, read its UnitAI order data (up to four times) and, when the foe was close to saturation, tested the Hero and siege classes again. None of this depends on the unit being assigned. - Add the module function getFoeInfo(), which gathers once for all the foes of the army the entity, its position, the unit it is attacking (if any) and, lazily, whether it is a hero or a siege unit and its access index. The army keeps the result in foeInfo, which is reset when a foe is added, removed or renamed, and at the beginning of update(), as positions and orders change from one turn to the next. - assignUnit reads that table instead of querying the entities. The foes are still visited in the same order and with the same checks, so the chosen foe is unchanged. assignedAgainst is still read live, as it changes while units are assigned. - Read ent.position() only once.