add a team_callable object and a 'teams' global variable to access it.
this is not completely filled but the structure is there. Sirp, please proofread the commit since it's my first in that area
This commit is contained in:
parent
41d0df91e8
commit
f11874d7c1
2 changed files with 42 additions and 1 deletions
|
@ -2249,6 +2249,12 @@ variant ai_interface::get_value(const std::string& key) const
|
|||
return villages_from_set(info_.map.villages(), ¤t_team().villages());
|
||||
} else if(key == "map") {
|
||||
return variant(new gamemap_callable(info_.map));
|
||||
} else if(key == "teams") {
|
||||
std::vector<variant> vars;
|
||||
for(std::vector<team>::const_iterator i = info_.state.teams->begin(); i != info_.state.teams->end(); ++i) {
|
||||
vars.push_back(variant(new team_callable(*i)));
|
||||
}
|
||||
return variant(&vars);
|
||||
}
|
||||
return variant();
|
||||
}
|
||||
|
@ -2264,6 +2270,7 @@ void ai_interface::get_inputs(std::vector<game_logic::formula_input>* inputs) co
|
|||
inputs->push_back(game_logic::formula_input("my_villages", FORMULA_READ_ONLY));
|
||||
inputs->push_back(game_logic::formula_input("enemy_and_unowned_villages", FORMULA_READ_ONLY));
|
||||
inputs->push_back(game_logic::formula_input("map", FORMULA_READ_ONLY));
|
||||
inputs->push_back(game_logic::formula_input("teams", FORMULA_READ_ONLY));
|
||||
}
|
||||
|
||||
variant ai::attack_analysis::get_value(const std::string& key) const
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "formula_callable.hpp"
|
||||
#include "map.hpp"
|
||||
#include "unit.hpp"
|
||||
#include "foreach.hpp"
|
||||
|
||||
#define CALLABLE_WRAPPER_START(klass) \
|
||||
class klass##_callable : public game_logic::formula_callable { \
|
||||
|
@ -15,8 +16,14 @@ public: \
|
|||
{} \
|
||||
\
|
||||
const klass& get_##klass() const { return object_; } \
|
||||
void get_inputs(std::vector<game_logic::formula_input>* /*inputs*/) const \
|
||||
void get_inputs(std::vector<game_logic::formula_input>* inputs) const \
|
||||
{ \
|
||||
using game_logic::FORMULA_READ_ONLY;
|
||||
|
||||
#define CALLABLE_WRAPPER_INPUT(VAR) \
|
||||
inputs->push_back(game_logic::formula_input(#VAR, FORMULA_READ_ONLY));
|
||||
|
||||
#define CALLABLE_WRAPPER_INPUT_END \
|
||||
} \
|
||||
\
|
||||
variant get_value(const std::string& key) const {
|
||||
|
@ -31,6 +38,8 @@ public: \
|
|||
return variant(object_.VAR()); \
|
||||
} else
|
||||
|
||||
|
||||
|
||||
#define CALLABLE_WRAPPER_END \
|
||||
{ return variant(); } \
|
||||
} \
|
||||
|
@ -51,6 +60,10 @@ private:
|
|||
};
|
||||
|
||||
CALLABLE_WRAPPER_START(gamemap)
|
||||
CALLABLE_WRAPPER_INPUT(terrain)
|
||||
CALLABLE_WRAPPER_INPUT(w)
|
||||
CALLABLE_WRAPPER_INPUT(h)
|
||||
CALLABLE_WRAPPER_INPUT_END
|
||||
if(key == "terrain") {
|
||||
int w = object_.w();
|
||||
int h = object_.h();
|
||||
|
@ -139,4 +152,25 @@ private:
|
|||
const unit& u_;
|
||||
};
|
||||
|
||||
CALLABLE_WRAPPER_START(team)
|
||||
CALLABLE_WRAPPER_INPUT(gold)
|
||||
CALLABLE_WRAPPER_INPUT(start_gold)
|
||||
CALLABLE_WRAPPER_INPUT(base_income)
|
||||
CALLABLE_WRAPPER_INPUT(village_gold)
|
||||
CALLABLE_WRAPPER_INPUT(name)
|
||||
CALLABLE_WRAPPER_INPUT(is_human)
|
||||
CALLABLE_WRAPPER_INPUT(is_ai)
|
||||
CALLABLE_WRAPPER_INPUT(is_network)
|
||||
CALLABLE_WRAPPER_INPUT_END
|
||||
CALLABLE_WRAPPER_FN(gold)
|
||||
if(key == "start_gold") { \
|
||||
return variant(lexical_cast<int>(object_.start_gold())); \
|
||||
} else
|
||||
CALLABLE_WRAPPER_FN(base_income)
|
||||
CALLABLE_WRAPPER_FN(village_gold)
|
||||
CALLABLE_WRAPPER_FN(name)
|
||||
CALLABLE_WRAPPER_FN(is_human)
|
||||
CALLABLE_WRAPPER_FN(is_ai)
|
||||
CALLABLE_WRAPPER_FN(is_network)
|
||||
CALLABLE_WRAPPER_END
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue