From cd8af9660770fcba3e6e0bf7915826ccfcbdaf7d Mon Sep 17 00:00:00 2001 From: mattsc Date: Thu, 25 Oct 2018 07:22:13 -0700 Subject: [PATCH] ai_helper.find_best_move: return nil instead of {} if no move found This is done for consistency with similar functions in mainline. In principle this breaks backward compatibility. However, while it is theoretically possible for this to happen, this function will generally always return at least the hex the unit is on, so it is very unlikely that this actually makes a difference somewhere. --- data/ai/lua/ai_helper.lua | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/data/ai/lua/ai_helper.lua b/data/ai/lua/ai_helper.lua index 1757a00c0be6..93a43fe03c83 100644 --- a/data/ai/lua/ai_helper.lua +++ b/data/ai/lua/ai_helper.lua @@ -1416,16 +1416,14 @@ function ai_helper.find_best_move(units, rating_function, cfg) -- best_hex: format { x, y } -- best_unit: unit for which this rating function produced the maximum value -- max_rating: the rating found for this hex/unit combination - -- If no valid moves were found, best_unit and best_hex are empty arrays - - -- TODO: change return value to nil if no unit/hex is found later in 1.13., but keep as is in 1.12 + -- If no valid moves were found, best_unit and best_hex are nil cfg = cfg or {} -- If this is an individual unit, turn it into an array if units.hitpoints then units = { units } end - local max_rating, best_hex, best_unit = - math.huge, {}, {} + local max_rating, best_hex, best_unit = - math.huge for _,unit in ipairs(units) do -- Hexes each unit can reach local reach_map = ai_helper.get_reachable_unocc(unit, cfg)