Add owner key to terrain space callable
This commit is contained in:
parent
4fb25532f2
commit
a46468e3d3
5 changed files with 28 additions and 17 deletions
|
@ -32,6 +32,8 @@ Version 1.13.8+dev:
|
|||
* Miscellaneous and Bug Fixes:
|
||||
* Add --report/-R command line switch for printing the same report from the
|
||||
Game Version dialog's clipboard function to stdout.
|
||||
* WFL Engine
|
||||
* Add owner key to terrain space callable, for villages
|
||||
* WML Engine
|
||||
* If ai_algorithm is used in [modify_side][ai], it now replaces the whole AI
|
||||
with the contents of [modify_side][ai], instead of appending these parameters.
|
||||
|
|
|
@ -534,7 +534,7 @@ variant formula_ai::get_value(const std::string& key) const
|
|||
return get_keeps();
|
||||
} else if(key == "map")
|
||||
{
|
||||
return variant(std::make_shared<gamemap_callable>(resources::gameboard->map()));
|
||||
return variant(std::make_shared<gamemap_callable>(*resources::gameboard));
|
||||
} else if(key == "villages")
|
||||
{
|
||||
return villages_from_set(resources::gameboard->map().villages());
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include "config.hpp"
|
||||
#include "formula/function.hpp"
|
||||
#include "map/map.hpp"
|
||||
#include "display_context.hpp"
|
||||
#include "team.hpp"
|
||||
#include "units/formula_manager.hpp"
|
||||
#include "log.hpp"
|
||||
|
@ -484,6 +485,11 @@ int config_callable::do_compare(const formula_callable* callable) const
|
|||
return cfg_.hash().compare(cfg_callable->get_config().hash());
|
||||
}
|
||||
|
||||
terrain_callable::terrain_callable(const display_context& dc, const map_location& loc) : loc_(loc), t_(dc.map().get_terrain_info(loc)), owner_(dc.village_owner(loc))
|
||||
{
|
||||
type_ = TERRAIN_C;
|
||||
}
|
||||
|
||||
variant terrain_callable::get_value(const std::string& key) const
|
||||
{
|
||||
if(key == "x") {
|
||||
|
@ -512,6 +518,8 @@ variant terrain_callable::get_value(const std::string& key) const
|
|||
return variant(t_.is_keep());
|
||||
} else if(key == "healing") {
|
||||
return variant(t_.gives_healing());
|
||||
} else if(key == "owner") {
|
||||
return variant(owner_);
|
||||
}
|
||||
|
||||
return variant();
|
||||
|
@ -532,6 +540,7 @@ void terrain_callable::get_inputs(formula_input_vector& inputs) const
|
|||
add_input(inputs, "castle");
|
||||
add_input(inputs, "keep");
|
||||
add_input(inputs, "healing");
|
||||
add_input(inputs, "owner");
|
||||
}
|
||||
|
||||
int terrain_callable::do_compare(const formula_callable* callable) const
|
||||
|
@ -545,6 +554,10 @@ int terrain_callable::do_compare(const formula_callable* callable) const
|
|||
return loc_.do_compare(other_loc);
|
||||
}
|
||||
|
||||
const gamemap& gamemap_callable::get_gamemap() const {
|
||||
return board_.map();
|
||||
}
|
||||
|
||||
void gamemap_callable::get_inputs(formula_input_vector& inputs) const
|
||||
{
|
||||
add_input(inputs, "gamemap");
|
||||
|
@ -556,22 +569,22 @@ void gamemap_callable::get_inputs(formula_input_vector& inputs) const
|
|||
variant gamemap_callable::get_value(const std::string& key) const
|
||||
{
|
||||
if(key == "terrain") {
|
||||
int w = gamemap_.w();
|
||||
int h = gamemap_.h();
|
||||
int w = get_gamemap().w();
|
||||
int h = get_gamemap().h();
|
||||
|
||||
std::vector<variant> vars;
|
||||
for(int i = 0; i < w; i++) {
|
||||
for(int j = 0; j < h; j++) {
|
||||
const map_location loc(i, j);
|
||||
vars.emplace_back(std::make_shared<terrain_callable>(gamemap_.get_terrain_info(loc), loc));
|
||||
vars.emplace_back(std::make_shared<terrain_callable>(board_, loc));
|
||||
}
|
||||
}
|
||||
|
||||
return variant(vars);
|
||||
} else if(key == "w") {
|
||||
return variant(gamemap_.w());
|
||||
return variant(get_gamemap().w());
|
||||
} else if(key == "h") {
|
||||
return variant(gamemap_.h());
|
||||
return variant(get_gamemap().h());
|
||||
} else {
|
||||
return variant();
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
class team;
|
||||
class terrain_type;
|
||||
class display_context;
|
||||
|
||||
namespace wfl
|
||||
{
|
||||
|
@ -28,10 +29,7 @@ namespace wfl
|
|||
class terrain_callable : public formula_callable
|
||||
{
|
||||
public:
|
||||
terrain_callable(const terrain_type& t, const map_location& loc) : loc_(loc), t_(t)
|
||||
{
|
||||
type_ = TERRAIN_C;
|
||||
}
|
||||
terrain_callable(const display_context& m, const map_location& loc);
|
||||
|
||||
variant get_value(const std::string& key) const override;
|
||||
void get_inputs(formula_input_vector& inputs) const override;
|
||||
|
@ -41,21 +39,22 @@ public:
|
|||
private:
|
||||
const map_location loc_;
|
||||
const terrain_type& t_;
|
||||
const int owner_;
|
||||
};
|
||||
|
||||
class gamemap_callable : public formula_callable
|
||||
{
|
||||
public:
|
||||
explicit gamemap_callable(const gamemap& g) : gamemap_(g)
|
||||
explicit gamemap_callable(const display_context& g) : board_(g)
|
||||
{}
|
||||
|
||||
void get_inputs(formula_input_vector& inputs) const override;
|
||||
variant get_value(const std::string& key) const override;
|
||||
|
||||
const gamemap& get_gamemap() const { return gamemap_; }
|
||||
const gamemap& get_gamemap() const;
|
||||
|
||||
private:
|
||||
const gamemap& gamemap_;
|
||||
const display_context& board_;
|
||||
};
|
||||
|
||||
class location_callable : public formula_callable
|
||||
|
|
|
@ -326,10 +326,7 @@ bool terrain_filter::match_internal(const map_location& loc, const bool ignore_x
|
|||
|
||||
if(cfg_.has_attribute("formula")) {
|
||||
try {
|
||||
const gamemap& map = fc_->get_disp_context().map();
|
||||
t_translation::terrain_code t = map.get_terrain(loc);
|
||||
const terrain_type& ter = map.tdata()->get_terrain_info(t);
|
||||
const wfl::terrain_callable callable(ter,loc);
|
||||
const wfl::terrain_callable callable(fc_->get_disp_context(), loc);
|
||||
const wfl::formula form(cfg_["formula"]);
|
||||
if(!form.evaluate(callable).as_bool()) {
|
||||
return false;
|
||||
|
|
Loading…
Add table
Reference in a new issue