Goto Micro AI: fix checks of avoid_enemies key
Numerical values are sometimes transferred from WML to Lua using the string type. This applies, for example, to very small numbers, such as 0.0000000000001. This needs to be taken into account when checking whether avoid_enemies is a number.
This commit is contained in:
parent
dff7b7d90d
commit
fd0c00cfb0
1 changed files with 5 additions and 4 deletions
|
@ -98,11 +98,12 @@ end
|
|||
function ca_goto:execution(cfg, data)
|
||||
local units, locs = GO_units, GO_locs
|
||||
|
||||
local enemy_map, enemy_attack_map
|
||||
local enemy_map, enemy_attack_map, avoid_enemies
|
||||
if cfg.avoid_enemies then
|
||||
if (type(cfg.avoid_enemies) ~= 'number') then
|
||||
avoid_enemies = tonumber(cfg.avoid_enemies)
|
||||
if (not avoid_enemies) then
|
||||
wml.error("Goto AI avoid_enemies= requires a number as argument")
|
||||
elseif (cfg.avoid_enemies <= 0) then
|
||||
elseif (avoid_enemies <= 0) then
|
||||
wml.error("Goto AI avoid_enemies= argument must be >0")
|
||||
end
|
||||
|
||||
|
@ -149,7 +150,7 @@ function ca_goto:execution(cfg, data)
|
|||
end
|
||||
else -- Otherwise find the best path to take
|
||||
local path, cost
|
||||
if GO_avoid_map or cfg.avoid_enemies then
|
||||
if GO_avoid_map or avoid_enemies then
|
||||
path, cost = wesnoth.find_path(unit, loc[1], loc[2], {
|
||||
calculate = function(x, y, current_cost)
|
||||
return custom_cost(x, y, unit, GO_avoid_map, enemy_map, enemy_attack_map, cfg.avoid_enemies)
|
||||
|
|
Loading…
Add table
Reference in a new issue