From 7fb2c86c3b502f07116dd43387a25fbefeded856 Mon Sep 17 00:00:00 2001 From: Celtic Minstrel Date: Sat, 23 Nov 2019 01:04:27 -0500 Subject: [PATCH] Add alternate mode of access to WFL map (currently only in FormulaAI) This also hides the map's terrain from the string conversion. --- changelog.md | 3 ++- src/formula/callable_objects.cpp | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/changelog.md b/changelog.md index db0c6aa528e..31db307e606 100644 --- a/changelog.md +++ b/changelog.md @@ -66,7 +66,8 @@ * Unit movetype functions (excluding resistance) can take a location instead of a terrain code, for convenience ### WFL engine * New functions resistance_on(), vision_cost(), jamming_cost() that work in gameplay contexts (eg filters) - * Unit object now has resistance, defense, movement_cost, vision_cost, jamming_cost, flying variables + * Unit object now has resistance, defense, movement_cost, vision_cost, jamming_cost, flying + * For FormulaAI, the game map object has an alternate access mode - `map.gamemap[loc(x,y)]` ### WML engine * Support upkeep in StandardUnitFilter * [effect]apply_to=variation now supports heal_full diff --git a/src/formula/callable_objects.cpp b/src/formula/callable_objects.cpp index 4d462ff427d..4a6b3066f81 100644 --- a/src/formula/callable_objects.cpp +++ b/src/formula/callable_objects.cpp @@ -607,8 +607,6 @@ const gamemap& gamemap_callable::get_gamemap() const { void gamemap_callable::get_inputs(formula_input_vector& inputs) const { - add_input(inputs, "gamemap"); - add_input(inputs, "terrain"); add_input(inputs, "w"); add_input(inputs, "h"); } @@ -627,6 +625,19 @@ variant gamemap_callable::get_value(const std::string& key) const } } + return variant(vars); + } else if(key == "gamemap") { + int w = get_gamemap().w(); + int h = get_gamemap().h(); + + std::map vars; + for(int i = 0; i < w; i++) { + for(int j = 0; j < h; j++) { + const map_location loc(i, j); + vars.emplace(std::make_shared(loc), std::make_shared(board_, loc)); + } + } + return variant(vars); } else if(key == "w") { return variant(get_gamemap().w());