From b649374b9fbe1570c0306468e2afb2dd1c770047 Mon Sep 17 00:00:00 2001 From: Celtic Minstrel Date: Tue, 24 Jan 2023 23:46:11 -0500 Subject: [PATCH] WFL: Allow using locations_in_radius without the game state --- src/formula/function.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/formula/function.cpp b/src/formula/function.cpp index ae1e5d84679..2993a500ffe 100644 --- a/src/formula/function.cpp +++ b/src/formula/function.cpp @@ -22,6 +22,7 @@ #include "game_display.hpp" #include "global.hpp" #include "log.hpp" +#include "pathutils.hpp" #include #include @@ -1268,6 +1269,35 @@ DEFINE_WFL_FUNCTION(adjacent_locs, 1, 1) return variant(v); } +DEFINE_WFL_FUNCTION(locations_in_radius, 2, 2) +{ + const map_location loc = args()[0]->evaluate(variables, fdb).convert_to()->loc(); + + int range = args()[1]->evaluate(variables, fdb).as_int(); + + if(range < 0) { + return variant(); + } + + if(!range) { + return variant(std::make_shared(loc)); + } + + std::vector res; + + get_tiles_in_radius(loc, range, res); + + std::vector v; + v.reserve(res.size() + 1); + v.emplace_back(std::make_shared(loc)); + + for(std::size_t n = 0; n != res.size(); ++n) { + v.emplace_back(std::make_shared(res[n])); + } + + return variant(v); +} + DEFINE_WFL_FUNCTION(are_adjacent, 2, 2) { const map_location loc1 = args()[0] @@ -1540,6 +1570,7 @@ std::shared_ptr function_symbol_table::get_builtins() DECLARE_WFL_FUNCTION(loc); DECLARE_WFL_FUNCTION(distance_between); DECLARE_WFL_FUNCTION(adjacent_locs); + DECLARE_WFL_FUNCTION(locations_in_radius); DECLARE_WFL_FUNCTION(are_adjacent); DECLARE_WFL_FUNCTION(relative_dir); DECLARE_WFL_FUNCTION(direction_from);