Skip to content

Commit

Permalink
Goto/Assassin MAIs: fix AIs not always working with tunnels
Browse files Browse the repository at this point in the history
The old syntax for using a custom cost function ignored teleports/tunnels. Using calculate= in the path options table allows also setting the ignore_teleports option (but in this syntax it defaults to 'false', so it does not need to be done specifically).
  • Loading branch information
mattsc committed Dec 31, 2018
1 parent 7875f4f commit 152eb37
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions changelog.md
Expand Up @@ -3,6 +3,7 @@
* Micro AIs
* Add [avoid] tag functionality to Multipack Wolves, Wolves, Swarm and Goto Micro AIs
* Support named locations for [micro_ai] tag location keys
* Goto and Assassin: fix MAIs not working with tunnels when using custom path finding cost functions
* Experimental AI
* Deprecate EXPERIMENTAL_AI macro: use ai_algorithm=experimental_ai in the [ai] tag instead
* Convert to using external candidate actions
Expand Down
6 changes: 3 additions & 3 deletions data/ai/micro_ais/cas/ca_assassin_move.lua
Expand Up @@ -138,11 +138,11 @@ function ca_assassin_move:execution(cfg)
end
end

local path, cost = wesnoth.find_path(unit, target.x, target.y,
function(x, y, current_cost)
local path, cost = wesnoth.find_path(unit, target.x, target.y, {
calculate = function(x, y, current_cost)
return custom_cost(x, y, unit, enemy_rating_map, prefer_map)
end
)
})

local path_map = LS.of_pairs(path)

Expand Down
6 changes: 3 additions & 3 deletions data/ai/micro_ais/cas/ca_goto.lua
Expand Up @@ -150,11 +150,11 @@ function ca_goto:execution(cfg, data)
else -- Otherwise find the best path to take
local path, cost
if GO_avoid_map or cfg.avoid_enemies then
path, cost = wesnoth.find_path(unit, loc[1], loc[2],
function(x, y, current_cost)
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)
end
)
})
else
local enemy_at_goal
if cfg.ignore_enemy_at_goal then
Expand Down

0 comments on commit 152eb37

Please sign in to comment.