WFL: Allow using locations_in_radius without the game state

This commit is contained in:
Celtic Minstrel 2023-01-24 23:46:11 -05:00
parent 9f57ca0ea2
commit b649374b9f

View File

@ -22,6 +22,7 @@
#include "game_display.hpp"
#include "global.hpp"
#include "log.hpp"
#include "pathutils.hpp"
#include <boost/math/constants/constants.hpp>
#include <cctype>
@ -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<location_callable>()->loc();
int range = args()[1]->evaluate(variables, fdb).as_int();
if(range < 0) {
return variant();
}
if(!range) {
return variant(std::make_shared<location_callable>(loc));
}
std::vector<map_location> res;
get_tiles_in_radius(loc, range, res);
std::vector<variant> v;
v.reserve(res.size() + 1);
v.emplace_back(std::make_shared<location_callable>(loc));
for(std::size_t n = 0; n != res.size(); ++n) {
v.emplace_back(std::make_shared<location_callable>(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> 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);