From 4e80a8f028f7fd7a25f05b3472555b0874a88c9e Mon Sep 17 00:00:00 2001 From: mattsc Date: Wed, 27 Nov 2019 16:41:59 -0800 Subject: [PATCH] ai_helper.next_hop: add option to use pre-evaluated path --- data/ai/lua/ai_helper.lua | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/data/ai/lua/ai_helper.lua b/data/ai/lua/ai_helper.lua index c778b568d0e..25ad69dc80a 100644 --- a/data/ai/lua/ai_helper.lua +++ b/data/ai/lua/ai_helper.lua @@ -1388,10 +1388,16 @@ function ai_helper.next_hop(unit, x, y, cfg) -- viewing_side: see comments at beginning of this file. Defaults to side of @unit -- plus: -- ignore_own_units: if set to true, then own units that can move out of the way are ignored + -- path: if given, find the next hop along this path, rather than doing new path finding + -- In this case, it is assumed that the path is possible, in other words, that cost has been checked - local path, cost = ai_helper.find_path_with_shroud(unit, x, y, cfg) - - if cost >= ai_helper.no_path then return nil, cost end + local path, cost + if cfg and cfg.path then + path = cfg.path + else + path, cost = ai_helper.find_path_with_shroud(unit, x, y, cfg) + if cost >= ai_helper.no_path then return nil, cost end + end -- If none of the hexes are unoccupied, use current position as default local next_hop, nh_cost = { unit.x, unit.y }, 0