30 #define DBG_AI LOG_STREAM(debug, log_formula_ai)
31 #define LOG_AI LOG_STREAM(info, log_formula_ai)
32 #define WRN_AI LOG_STREAM(warn, log_formula_ai)
33 #define ERR_AI LOG_STREAM(err, log_formula_ai)
38 auto fai = std::dynamic_pointer_cast<const formula_ai>(for_fai);
39 assert(fai !=
nullptr);
40 return *std::const_pointer_cast<formula_ai>(fai)->ai_ptr_;
51 std::vector<variant> vars;
52 for(move_map::const_iterator
i = srcdst_.begin();
i != srcdst_.end(); ++
i) {
53 if(
i->first ==
i->second || units_.count(
i->second) == 0) {
54 auto item = std::make_shared<move_callable>(
i->first,
i->second);
55 vars.emplace_back(item);
60 }
else if(key ==
"has_moves") {
61 return variant(!srcdst_.empty());
69 add_input(inputs,
"moves");
75 if(mv_callable ==
nullptr) {
82 if (
int cmp = src_.do_compare(other_src)) {
104 if(mv_callable ==
nullptr) {
111 if (
int cmp = src_.do_compare(other_src)) {
131 if(key ==
"chance") {
139 add_input(inputs,
"chance");
143 if(key ==
"hitpoints_left") {
145 }
else if(key ==
"probability") {
147 }
else if(key ==
"possible_status") {
155 add_input(inputs,
"hitpoints_left");
156 add_input(inputs,
"probability");
157 add_input(inputs,
"possible_status");
162 : move_from_(move_from), src_(
src), dst_(
dst),
170 if(key ==
"attack_from") {
171 return variant(std::make_shared<location_callable>(
src_));
172 }
else if(key ==
"defender") {
173 return variant(std::make_shared<location_callable>(
dst_));
174 }
else if(key ==
"move_from") {
190 if(a_callable ==
nullptr) {
207 const int other_weapon = a_callable->
weapon();
208 if (
int cmp = (this->
weapon() - other_weapon)) {
217 bool gamestate_changed =
false;
242 return variant(gamestate_changed);
246 if(key ==
"attacks") {
247 std::vector<variant> vars;
286 auto item = std::make_shared<attack_callable>(attacker_location, attack_position, adj, -1);
287 vars.emplace_back(item);
295 return variant(std::make_shared<location_callable>(
loc_));
319 if( key ==
"unit_type")
321 if( key ==
"recruit_loc")
322 return variant(std::make_shared<location_callable>(
loc_));
351 return variant(std::make_shared<location_callable>(
loc_));
387 ERR_AI <<
"ERROR #" << status <<
" while executing 'set_unit_var' formula function";
388 return variant(std::make_shared<safe_call_result>(
fake_ptr(), status));
Managing the AI-Game interaction - AI actions and their results.
bool is_gamestate_changed() const
virtual const map_location & get_unit_location() const
virtual const team & current_team() const override
virtual const move_map & get_srcdst() const override
virtual side_number get_side() const override
Get the side number.
virtual side_number get_side() const =0
Get the side number.
virtual const unit_map & units() const override
bool is_enemy(int n) const
Container associating units to locations.
std::size_t count(const map_location &loc) const
unit_iterator find(std::size_t id)
This class represents a single unit of a specific type.
const map_location & src() const
const map_location & move_from() const
void get_inputs(formula_input_vector &inputs) const override
attack_callable(const map_location &move_from, const map_location &src, const map_location &dst, int weapon)
variant execute_self(variant ctxt) override
const map_location & dst() const
variant get_value(const std::string &key) const override
int do_compare(const formula_callable *callable) const override
Compare two attacks in deterministic way or compare pointers (nondeterministic in consequent game run...
int defender_weapon() const
variant get_value(const std::string &key) const override
const ai::formula_ai & ai_
void collect_possible_attacks(std::vector< variant > &vars, map_location attacker_location, map_location attack_position) const
void get_inputs(formula_input_vector &inputs) const override
variant execute_self(variant ctxt) override
variant execute_self(variant ctxt) override
int do_compare(const formula_callable *callable) const override
void get_inputs(formula_input_vector &inputs) const override
variant get_value(const std::string &key) const override
int do_compare(const formula_callable *callable) const override
variant execute_self(variant ctxt) override
variant get_value(const std::string &key) const override
void get_inputs(formula_input_vector &inputs) const override
void get_inputs(formula_input_vector &inputs) const override
variant get_value(const std::string &key) const override
void get_inputs(formula_input_vector &inputs) const override
variant execute_self(variant ctxt) override
variant get_value(const std::string &key) const override
void get_inputs(formula_input_vector &inputs) const override
variant execute_self(variant ctxt) override
variant get_value(const std::string &key) const override
const std::string & key() const
void get_inputs(formula_input_vector &inputs) const override
variant execute_self(variant ctxt) override
variant get_value(const std::string &key) const override
const_formula_callable_ptr as_callable() const
std::string to_debug_string(bool verbose=false, formula_seen_stack *seen=nullptr) const
Game information for the AI.
bool invisible(const map_location &loc, bool see_all=true) const
unit_formula_manager & formula_manager() const
Get the unit formula manager.
bool incapacitated() const
Check if the unit has been petrified.
int side() const
The side this unit belongs to.
const map_location & get_location() const
The current map location this unit is at.
void get_adjacent_tiles(const map_location &a, map_location *res)
Function which, given a location, will place all adjacent locations in res.
Standard logging facilities (interface).
A small explanation about what's going on here: Each action has access to two game_info objects First...
std::shared_ptr< recruit_result > recruit_result_ptr
ai_context & get_ai_context(wfl::const_formula_callable_ptr for_fai)
std::shared_ptr< attack_result > attack_result_ptr
std::shared_ptr< move_result > move_result_ptr
std::shared_ptr< recall_result > recall_result_ptr
std::vector< formula_input > formula_input_vector
std::shared_ptr< const formula_callable > const_formula_callable_ptr
rect dst
Location on the final composed sheet.
rect src
Non-transparent portion of the surface to compose.
Encapsulates the map of the game.
int do_compare(const map_location &a) const
three-way comparator