ExpAI castle switch CA: fix error when stored leader has been killed

The castle switch CA stores the leader move because the evaluation is expensive.  If the leader was killed in between storing and reevaluation of the CA, this would previously cause an on-screen error message and the CA to be blacklisted for the turn.

This fixes #6440.
This commit is contained in:
mattsc 2022-06-09 07:48:39 -07:00
parent 81ccaa2cd6
commit 88071c7880

View file

@ -99,6 +99,11 @@ function ca_castle_switch:evaluation(cfg, data, filter_own, recruiting_leader)
return 0
end
-- Also need to check that the stored leader has not been killed
if data.CS_leader and not data.CS_leader.valid then
data.CS_leader, data.CS_leader_target = nil, nil
end
local avoid_map = AH.get_avoid_map(ai, nil, true)
if data.CS_leader and wesnoth.sides[wesnoth.current.side].gold >= AH.get_cheapest_recruit_cost(data.CS_leader)