Skip to content

Commit

Permalink
Fast Micro AI: make code robust against events removing units
Browse files Browse the repository at this point in the history
The previous version caused errors under some circumstances when an
event removed units other than the attacker during or immediately after
an AI attack.
  • Loading branch information
mattsc committed Feb 11, 2018
1 parent e22c812 commit 85b46f3
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions data/ai/micro_ais/cas/ca_fast_combat.lua
Expand Up @@ -79,10 +79,10 @@ function ca_fast_combat:evaluation(cfg, data)

for i = #data.fast_combat_units,1,-1 do
local unit = data.fast_combat_units[i]
local unit_info = FAU.get_unit_info(unit, data.gamedata)
local unit_copy = FAU.get_unit_copy(unit.id, data.gamedata)

if (unit.attacks_left > 0) and (#unit.attacks > 0) then
if unit and unit.valid and (unit.attacks_left > 0) and (#unit.attacks > 0) then
local unit_info = FAU.get_unit_info(unit, data.gamedata)
local unit_copy = FAU.get_unit_copy(unit.id, data.gamedata)
local attacks = AH.get_attacks({ unit }, { include_occupied = cfg.include_occupied_attack_hexes, viewing_side = viewing_side })

if (#attacks > 0) then
Expand Down

0 comments on commit 85b46f3

Please sign in to comment.