battle_calcs.attack_rating: bug fix for when AI side has no leader
Check for AI side's leader's existence before trying to calculate distance from leader.
This commit is contained in:
parent
a8171d07a0
commit
ea915d36c2
1 changed files with 7 additions and 5 deletions
|
@ -859,11 +859,13 @@ function battle_calcs.attack_rating(attacker, defender, dst, cfg, cache)
|
|||
|
||||
-- Get a very small bonus for hexes in between defender and AI leader
|
||||
-- 'relative_distances' is larger for attack hexes closer to the side leader (possible values: -1 .. 1)
|
||||
local relative_distances =
|
||||
H.distance_between(defender.x, defender.y, leader.x, leader.y)
|
||||
- H.distance_between(dst[1], dst[2], leader.x, leader.y)
|
||||
value_fraction = value_fraction + relative_distances * distance_leader_weight
|
||||
--print(' relative_distances:', relative_distances, value_fraction)
|
||||
if leader then
|
||||
local relative_distances =
|
||||
H.distance_between(defender.x, defender.y, leader.x, leader.y)
|
||||
- H.distance_between(dst[1], dst[2], leader.x, leader.y)
|
||||
value_fraction = value_fraction + relative_distances * distance_leader_weight
|
||||
--print(' relative_distances:', relative_distances, value_fraction)
|
||||
end
|
||||
|
||||
-- Add a very small penalty for attack hexes occupied by other units
|
||||
-- Note: it must be checked previously that the unit on the hex can move away
|
||||
|
|
Loading…
Add table
Reference in a new issue