The Battle for Wesnoth  1.19.13+dev
contexts.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2025
3  by Yurii Chernyi <terraninfo@terraninfo.net>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 /**
17  * @file
18  * Helper functions for the object which operates in the context of AI for specific side
19  * this is part of AI interface
20  */
21 
22 #pragma once
23 
24 #include "ai/game_info.hpp" // for move_map, typesafe_aspect_ptr, etc
25 
26 #include "config.hpp" // for config
27 #include "game_errors.hpp"
28 #include "generic_event.hpp" // for observer
29 #include "units/ptr.hpp" // for unit_ptr
30 #include "map/location.hpp" // for map_location
31 
32 #include <map> // for map, map<>::value_compare
33 #include <set> // for set
34 #include <string> // for string
35 #include <utility> // for pair
36 #include <vector> // for vector
37 
38 class gamemap; // lines 41-41
39 class team;
40 class terrain_filter; // lines 43-43
41 class unit_map;
42 class unit_type; // lines 46-46
43 namespace ai { class ai_context; } // lines 51-51
44 namespace ai { class unit_advancements_aspect; }
45 struct battle_context_unit_stats; // lines 39-39
46 
47 namespace ai {
48 
50 
51 // recursion counter
53 public:
54  recursion_counter(int counter)
55  : counter_(++counter)
56  {
57  if (counter > MAX_COUNTER_VALUE ) {
58  throw game::game_error("maximum recursion depth reached!");
59  }
60  }
61 
62  /**
63  * Get the current value of the recursion counter
64  */
65  int get_count() const
66  {
67  return counter_;
68  }
69 
70  //max recursion depth
71  static const int MAX_COUNTER_VALUE = 100;
72 
73  /**
74  * Check if more recursion is allowed
75  */
76  bool is_ok() const
77  {
78  return counter_ < MAX_COUNTER_VALUE;
79  }
80 private:
81 
82  // recursion counter value
83  int counter_;
84 };
85 
86 //defensive position
87 
90  loc(),
91  chance_to_hit(0),
92  vulnerability(0.0),
93  support(0.0)
94  {}
95 
99 };
100 
101 // keeps cache
103 {
104 public:
105  keeps_cache();
106  ~keeps_cache();
107  void handle_generic_event(const std::string& event_name);
108  void clear();
109  const std::set<map_location>& get();
110  void init(const gamemap &map);
111 private:
112  const gamemap *map_;
113  std::set<map_location> keeps_;
114 };
115 
116 // side context
117 
118 
120 public:
121 
122  /**
123  * Get the side number
124  */
125  virtual side_number get_side() const = 0;
126 
127  /**
128  * Set the side number
129  */
130  virtual void set_side(side_number side) = 0;
131 
132  /**
133  * empty destructor
134  */
135  virtual ~side_context(){}
136 
137  /**
138  * empty constructor
139  */
141 
142  /**
143  * unwrap
144  */
146 
147  /**
148  * serialize this context to config
149  */
150  virtual config to_side_context_config() const = 0;
151 
152  /**
153  * Get the value of the recursion counter
154  */
155  virtual int get_recursion_count() const = 0;
156 
157 };
158 
159 class readonly_context : public virtual side_context {
160 public:
162  virtual ~readonly_context(){}
164  virtual void on_readonly_context_create() = 0;
165  virtual const team& current_team() const = 0;
166  virtual void diagnostic(const std::string& msg) = 0;
167  virtual void log_message(const std::string& msg) = 0;
168  virtual attack_result_ptr check_attack_action(const map_location& attacker_loc, const map_location& defender_loc, int attacker_weapon) = 0;
169  virtual move_result_ptr check_move_action(const map_location& from, const map_location& to, bool remove_movement=true, bool unreach_is_ok=false) = 0;
170  virtual recall_result_ptr check_recall_action(const std::string& id, const map_location &where = map_location::null_location(), const map_location &from = map_location::null_location()) = 0;
172  virtual stopunit_result_ptr check_stopunit_action(const map_location& unit_location, bool remove_movement = true, bool remove_attacks = false) = 0;
173  virtual synced_command_result_ptr check_synced_command_action(const std::string& lua_code, const map_location& location = map_location::null_location()) = 0;
174  virtual void calculate_possible_moves(std::map<map_location,pathfind::paths>& possible_moves,
175  move_map& srcdst, move_map& dstsrc, bool enemy,
176  bool assume_full_movement=false,
177  const terrain_filter* remove_destinations=nullptr) const = 0;
178  virtual void calculate_moves(const unit_map& units,
179  std::map<map_location,pathfind::paths>& possible_moves, move_map& srcdst,
180  move_map& dstsrc, bool enemy, bool assume_full_movement=false,
181  const terrain_filter* remove_destinations=nullptr,
182  bool see_all=false) const = 0;
183 
184  virtual const game_info& get_info() const = 0;
185 
186  //@note: following part is in alphabetic order
188  const move_map& dstsrc, const move_map& srcdst, const move_map& enemy_dstsrc) const = 0;
189 
190  virtual std::map<map_location,defensive_position>& defensive_position_cache() const = 0;
191 
192  virtual const unit_advancements_aspect& get_advancements() const = 0;
193 
194  virtual double get_aggression() const = 0;
195 
196  virtual bool get_allow_ally_villages() const = 0;
197 
198  virtual const aspect_map& get_aspects() const = 0;
199 
200  virtual aspect_map& get_aspects() = 0;
201 
202  virtual void add_facet(const std::string &id, const config &cfg) const = 0;
203 
204  virtual void add_aspects(std::vector< aspect_ptr > &aspects ) = 0;
205 
206  virtual const attacks_vector& get_attacks() const = 0;
207 
208  virtual const terrain_filter& get_avoid() const = 0;
209 
210  virtual double get_caution() const = 0;
211 
212  virtual const move_map& get_dstsrc() const = 0;
213 
214  virtual const move_map& get_enemy_dstsrc() const = 0;
215 
216  virtual const moves_map& get_enemy_possible_moves() const = 0;
217 
218  virtual const move_map& get_enemy_srcdst() const = 0;
219 
220  /**
221  * get engine by cfg, creating it if it is not created yet but known
222  */
223  virtual engine_ptr get_engine_by_cfg(const config& cfg) = 0;
224 
225  virtual const std::vector<engine_ptr>& get_engines() const = 0;
226 
227  virtual std::vector<engine_ptr>& get_engines() = 0;
228 
229  virtual std::string get_grouping() const = 0;
230 
231  virtual const std::vector<goal_ptr>& get_goals() const = 0;
232 
233  virtual std::vector<goal_ptr>& get_goals() = 0;
234 
235  virtual double get_leader_aggression() const = 0;
236 
237  virtual config get_leader_goal() const = 0;
238 
239  virtual utils::variant<bool, std::vector<std::string>> get_leader_ignores_keep() const = 0;
240 
241  virtual double get_leader_value() const = 0;
242 
243  virtual utils::variant<bool, std::vector<std::string>> get_passive_leader() const = 0;
244 
245  virtual utils::variant<bool, std::vector<std::string>> get_passive_leader_shares_keep() const = 0;
246 
247  virtual const moves_map& get_possible_moves() const = 0;
248 
249  virtual double get_recruitment_diversity() const = 0;
250 
251  virtual const config get_recruitment_instructions() const = 0;
252 
253  virtual const std::vector<std::string> get_recruitment_more() const = 0;
254 
255  virtual const std::vector<std::string> get_recruitment_pattern() const = 0;
256 
257  virtual int get_recruitment_randomness() const = 0;
258 
259  virtual const config get_recruitment_save_gold() const = 0;
260 
261  virtual double get_retreat_enemy_weight() const = 0;
262 
263  virtual double get_retreat_factor() const = 0;
264 
265  virtual double get_scout_village_targeting() const = 0;
266 
267  virtual bool get_simple_targeting() const = 0;
268 
269  virtual const move_map& get_srcdst() const = 0;
270 
271  virtual bool get_support_villages() const = 0;
272 
273  virtual double get_village_value() const = 0;
274 
275  virtual int get_villages_per_scout() const = 0;
276 
277  virtual bool is_active(const std::string &time_of_day, const std::string &turns) const = 0;
278 
279  virtual bool is_keep_ignoring_leader(const std::string &id) const = 0;
280 
281  virtual bool is_passive_leader(const std::string &id) const = 0;
282 
283  virtual bool is_passive_keep_sharing_leader(const std::string &id) const = 0;
284 
285  virtual bool is_dst_src_valid_lua() const = 0;
286 
287  virtual bool is_dst_src_enemy_valid_lua() const = 0;
288 
289  virtual bool is_src_dst_valid_lua() const = 0;
290 
291  virtual bool is_src_dst_enemy_valid_lua() const = 0;
292 
293  virtual void invalidate_defensive_position_cache() const = 0;
294 
295  virtual void invalidate_move_maps() const = 0;
296 
297  virtual void invalidate_keeps_cache() const= 0;
298 
299  virtual const std::set<map_location>& keeps() const= 0;
300 
301  virtual bool leader_can_reach_keep() const = 0;
302 
303  virtual const map_location& nearest_keep(const map_location& loc) const = 0;
304 
305  /**
306  * Function which finds how much 'power' a side can attack a certain location with.
307  * This is basically the maximum hp of damage that can be inflicted upon a unit on loc
308  * by full-health units, multiplied by the defense these units will have.
309  * (if 'use_terrain' is false, then it will be multiplied by 0.5)
310  *
311  * Example: 'loc' can be reached by two units, one of whom has a 10-3 attack
312  * and has 48/48 hp, and can defend at 40% on the adjacent grassland.
313  * The other has a 8-2 attack, and has 30/40 hp, and can defend at 60% on the adjacent mountain.
314  * The rating will be 10*3*1.0*0.4 + 8*2*0.75*0.6 = 19.2
315  */
316  virtual double power_projection(const map_location& loc, const move_map& dstsrc) const = 0;
317 
318  virtual void raise_user_interact() const = 0;
319 
320  virtual void recalculate_move_maps() const = 0;
321 
322  virtual void recalculate_move_maps_enemy() const = 0;
323 
324  virtual void set_src_dst_valid_lua() = 0;
325  virtual void set_src_dst_enemy_valid_lua() = 0;
326  virtual void set_dst_src_valid_lua() = 0;
327  virtual void set_dst_src_enemy_valid_lua() = 0;
328 
329  /** get most suitable keep for leader - nearest free that can be reached in 1 turn, if none - return nearest occupied that can be reached in 1 turn, if none - return nearest keep, if none - return null_location */
330  virtual const map_location& suitable_keep( const map_location& leader_location, const pathfind::paths& leader_paths ) const = 0;
331 
332  /**
333  * serialize to config
334  */
335  virtual config to_readonly_context_config() const = 0;
336 
337  typedef std::map<std::pair<map_location,const unit_type *>,
338  std::pair<battle_context_unit_stats,battle_context_unit_stats>>
340  virtual unit_stats_cache_t & unit_stats_cache() const = 0;
341 
342 };
343 
344 class readwrite_context : public virtual readonly_context {
345 public:
347 
348  virtual ~readwrite_context(){}
349 
351 
352  virtual attack_result_ptr execute_attack_action(const map_location& attacker_loc, const map_location& defender_loc, int attacker_weapon) = 0;
353 
354  virtual move_result_ptr execute_move_action(const map_location& from, const map_location& to, bool remove_movement=true, bool unreach_is_ok=false) = 0;
355 
357 
359 
360  virtual stopunit_result_ptr execute_stopunit_action(const map_location& unit_location, bool remove_movement = true, bool remove_attacks = false) = 0;
361 
362  virtual synced_command_result_ptr execute_synced_command_action(const std::string& lua_code, const map_location& location = map_location::null_location()) = 0;
363 
364  virtual team& current_team_w() = 0;
365 
366  virtual void raise_gamestate_changed() const = 0;
367 
368  virtual game_info& get_info_w() = 0;
369 
370  /**
371  * serialize this context to config
372  */
373  virtual config to_readwrite_context_config() const = 0;
374 
375 };
376 
377 //proxies
378 
379 class side_context_proxy : public virtual side_context {
380 public:
382  : target_(nullptr)
383  {
384  }
385 
387 
389  {
390  target_= &target.get_side_context();
391  }
392 
393  virtual side_number get_side() const override
394  {
395  return target_->get_side();
396  }
397 
398  virtual void set_side(side_number side) override
399  {
400  return target_->set_side(side);
401  }
402 
403  virtual side_context& get_side_context() override
404  {
405  return target_->get_side_context();
406  }
407 
408  virtual int get_recursion_count() const override
409  {
410  return target_->get_recursion_count();
411  }
412 
413  virtual config to_side_context_config() const override
414  {
416  }
417 
418 private:
420 };
421 
422 class readonly_context_proxy : public virtual readonly_context, public virtual side_context_proxy {
423 public:
425  : target_(nullptr)
426  {
427  }
428 
430 
432  {
434  target_ = &target.get_readonly_context();
435  }
436 
438  {
439  return target_->get_readonly_context();
440  }
441 
442  virtual void on_readonly_context_create() override
443  {
445  }
446 
447  virtual const team& current_team() const override
448  {
449  return target_->current_team();
450  }
451 
452  virtual void diagnostic(const std::string& msg) override
453  {
455  }
456 
457  virtual void log_message(const std::string& msg) override
458  {
460  }
461 
462  virtual attack_result_ptr check_attack_action(const map_location &attacker_loc, const map_location &defender_loc, int attacker_weapon) override
463  {
464  return target_->check_attack_action(attacker_loc, defender_loc, attacker_weapon);
465  }
466 
467  virtual move_result_ptr check_move_action(const map_location &from, const map_location &to, bool remove_movement=true, bool unreach_is_ok=false) override
468  {
469  return target_->check_move_action(from, to, remove_movement, unreach_is_ok);
470  }
471 
472  virtual recall_result_ptr check_recall_action(const std::string &id, const map_location &where = map_location::null_location(),
473  const map_location &from = map_location::null_location()) override
474  {
475  return target_->check_recall_action(id, where, from);
476  }
477 
479  const map_location &from = map_location::null_location()) override
480  {
481  return target_->check_recruit_action(unit_name, where, from);
482  }
483 
484  virtual stopunit_result_ptr check_stopunit_action(const map_location &unit_location, bool remove_movement = true, bool remove_attacks = false) override
485  {
486  return target_->check_stopunit_action(unit_location, remove_movement, remove_attacks);
487  }
488 
489  virtual synced_command_result_ptr check_synced_command_action(const std::string& lua_code, const map_location& location = map_location::null_location()) override
490  {
491  return target_->check_synced_command_action(lua_code, location);
492  }
493 
494  virtual void calculate_possible_moves(std::map<map_location,pathfind::paths>& possible_moves,
495  move_map& srcdst, move_map& dstsrc, bool enemy,
496  bool assume_full_movement=false,
497  const terrain_filter* remove_destinations=nullptr) const override
498  {
499  target_->calculate_possible_moves(possible_moves, srcdst, dstsrc, enemy, assume_full_movement, remove_destinations);
500  }
501 
502  virtual void calculate_moves(const unit_map& units,
503  std::map<map_location,pathfind::paths>& possible_moves, move_map& srcdst,
504  move_map& dstsrc, bool enemy, bool assume_full_movement=false,
505  const terrain_filter* remove_destinations=nullptr,
506  bool see_all=false) const override
507  {
508  target_->calculate_moves(units, possible_moves, srcdst, dstsrc, enemy, assume_full_movement, remove_destinations, see_all);
509  }
510 
511  virtual const game_info& get_info() const override
512  {
513  return target_->get_info();
514  }
515 
516  virtual void raise_user_interact() const override
517  {
519  }
520 
521  virtual int get_recursion_count() const override
522  {
523  return target_->get_recursion_count();
524  }
525 
526  //@note: following part is in alphabetic order
528  const move_map& dstsrc, const move_map& srcdst, const move_map& enemy_dstsrc) const override
529  {
530  return target_->best_defensive_position(unit,dstsrc,srcdst,enemy_dstsrc);
531  }
532 
533  virtual std::map<map_location,defensive_position>& defensive_position_cache() const override
534  {
536  }
537 
538  virtual const unit_advancements_aspect& get_advancements() const override
539  {
540  return target_->get_advancements();
541  }
542 
543  virtual double get_aggression() const override
544  {
545  return target_->get_aggression();
546  }
547 
548  virtual bool get_allow_ally_villages() const override
549  {
551  }
552 
553  virtual const aspect_map& get_aspects() const override
554  {
555  return target_->get_aspects();
556  }
557 
558  virtual aspect_map& get_aspects() override
559  {
560  return target_->get_aspects();
561  }
562 
563  virtual void add_aspects(std::vector< aspect_ptr > &aspects ) override
564  {
565  return target_->add_aspects(aspects);
566  }
567 
568  virtual void add_facet(const std::string &id, const config &cfg) const override
569  {
570  target_->add_facet(id,cfg);
571  }
572 
573  virtual const attacks_vector& get_attacks() const override
574  {
575  return target_->get_attacks();
576  }
577 
578  virtual const terrain_filter& get_avoid() const override
579  {
580  return target_->get_avoid();
581  }
582 
583  virtual double get_caution() const override
584  {
585  return target_->get_caution();
586  }
587 
588  virtual const move_map& get_dstsrc() const override
589  {
590  return target_->get_dstsrc();
591  }
592 
593  virtual const move_map& get_enemy_dstsrc() const override
594  {
595  return target_->get_enemy_dstsrc();
596  }
597 
598  virtual const moves_map& get_enemy_possible_moves() const override
599  {
601  }
602 
603  virtual const move_map& get_enemy_srcdst() const override
604  {
605  return target_->get_enemy_srcdst();
606  }
607 
608  virtual engine_ptr get_engine_by_cfg(const config &cfg) override
609  {
610  return target_->get_engine_by_cfg(cfg);
611  }
612 
613  virtual const std::vector<engine_ptr>& get_engines() const override
614  {
615  return target_->get_engines();
616  }
617 
618  virtual std::vector<engine_ptr>& get_engines() override
619  {
620  return target_->get_engines();
621  }
622 
623  virtual std::string get_grouping() const override
624  {
625  return target_->get_grouping();
626  }
627 
628  virtual const std::vector<goal_ptr>& get_goals() const override
629  {
630  return target_->get_goals();
631  }
632 
633  virtual std::vector<goal_ptr>& get_goals() override
634  {
635  return target_->get_goals();
636  }
637 
638  virtual double get_leader_aggression() const override
639  {
640  return target_->get_leader_aggression();
641  }
642 
643  virtual config get_leader_goal() const override
644  {
645  return target_->get_leader_goal();
646  }
647 
648  virtual utils::variant<bool, std::vector<std::string>> get_leader_ignores_keep() const override
649  {
651  }
652 
653  virtual double get_leader_value() const override
654  {
655  return target_->get_leader_value();
656  }
657 
658  virtual utils::variant<bool, std::vector<std::string>> get_passive_leader() const override
659  {
660  return target_->get_passive_leader();
661  }
662 
663  virtual utils::variant<bool, std::vector<std::string>> get_passive_leader_shares_keep() const override
664  {
666  }
667 
668  virtual const moves_map& get_possible_moves() const override
669  {
670  return target_->get_possible_moves();
671  }
672 
673  virtual double power_projection(const map_location& loc, const move_map& dstsrc) const override
674  {
675  return target_->power_projection(loc,dstsrc);
676  }
677 
678  virtual double get_recruitment_diversity() const override
679  {
681  }
682 
683  virtual const config get_recruitment_instructions() const override
684  {
686  }
687 
688  virtual const std::vector<std::string> get_recruitment_more() const override
689  {
690  return target_->get_recruitment_more();
691  }
692 
693  virtual const std::vector<std::string> get_recruitment_pattern() const override
694  {
696  }
697 
698  virtual int get_recruitment_randomness() const override
699  {
701  }
702 
703  virtual const config get_recruitment_save_gold() const override
704  {
706  }
707 
708  virtual const move_map& get_srcdst() const override
709  {
710  return target_->get_srcdst();
711  }
712 
713  virtual double get_retreat_enemy_weight() const override
714  {
716  }
717 
718  virtual double get_retreat_factor() const override
719  {
720  return target_->get_retreat_factor();
721  }
722 
723  virtual double get_scout_village_targeting() const override
724  {
726  }
727 
728  virtual bool get_simple_targeting() const override
729  {
730  return target_->get_simple_targeting();
731  }
732 
733  virtual bool get_support_villages() const override
734  {
735  return target_->get_support_villages();
736  }
737 
738  virtual double get_village_value() const override
739  {
740  return target_->get_village_value();
741  }
742 
743  virtual int get_villages_per_scout() const override
744  {
746  }
747 
748  virtual bool is_active(const std::string &time_of_day, const std::string &turns) const override
749  {
750  return target_->is_active(time_of_day, turns);
751  }
752 
753  virtual bool is_keep_ignoring_leader(const std::string &id) const override
754  {
755  return target_->is_keep_ignoring_leader(id);
756  }
757 
758  virtual bool is_passive_leader(const std::string &id) const override
759  {
760  return target_->is_passive_leader(id);
761  }
762 
763  virtual bool is_passive_keep_sharing_leader(const std::string &id) const override
764  {
766  }
767 
768  virtual bool is_dst_src_valid_lua() const override
769  {
770  return target_->is_dst_src_valid_lua();
771  }
772 
773  virtual bool is_dst_src_enemy_valid_lua() const override
774  {
776  }
777 
778  virtual bool is_src_dst_valid_lua() const override
779  {
780  return target_->is_src_dst_valid_lua();
781  }
782 
783  virtual bool is_src_dst_enemy_valid_lua() const override
784  {
786  }
787 
788  virtual void invalidate_defensive_position_cache() const override
789  {
791  }
792 
793  virtual void invalidate_move_maps() const override
794  {
796  }
797 
798  virtual void invalidate_keeps_cache() const override
799  {
801  }
802 
803  virtual const std::set<map_location>& keeps() const override
804  {
805  return target_->keeps();
806  }
807 
808  virtual bool leader_can_reach_keep() const override
809  {
810  return target_->leader_can_reach_keep();
811  }
812 
813  virtual const map_location& nearest_keep( const map_location& loc ) const override
814  {
815  return target_->nearest_keep(loc);
816  }
817 
818  virtual void recalculate_move_maps() const override
819  {
821  }
822 
823  virtual void recalculate_move_maps_enemy() const override
824  {
826  }
827 
828  virtual void set_dst_src_valid_lua() override
829  {
831  }
832 
833  virtual void set_dst_src_enemy_valid_lua() override
834  {
836  }
837 
838  virtual void set_src_dst_valid_lua() override
839  {
841  }
842 
843  virtual void set_src_dst_enemy_valid_lua() override
844  {
846  }
847 
848  virtual const map_location& suitable_keep( const map_location& leader_location, const pathfind::paths& leader_paths ) const override
849  {
850  return target_->suitable_keep(leader_location, leader_paths);
851  }
852 
853  virtual config to_readonly_context_config() const override
854  {
856  }
857 
858  virtual unit_stats_cache_t & unit_stats_cache() const override
859  {
860  return target_->unit_stats_cache();
861  }
862 
863 private:
865 };
866 
867 class readwrite_context_proxy : public virtual readwrite_context, public virtual readonly_context_proxy {
868 public:
870  : target_(nullptr)
871  {
872  }
873 
875  {
877  target_ = &target.get_readwrite_context();
878  }
879 
881  {
882  return target_->get_readwrite_context();
883  }
884 
885  virtual attack_result_ptr execute_attack_action(const map_location& attacker_loc, const map_location& defender_loc, int attacker_weapon) override
886  {
887  return target_->execute_attack_action(attacker_loc,defender_loc,attacker_weapon);
888  }
889 
890  virtual move_result_ptr execute_move_action(const map_location& from, const map_location& to, bool remove_movement=true, bool unreach_is_ok=false) override
891  {
892  return target_->execute_move_action(from, to, remove_movement, unreach_is_ok);
893  }
894 
895  virtual recall_result_ptr execute_recall_action(const std::string& id, const map_location &where = map_location::null_location(), const map_location &from = map_location::null_location()) override
896  {
897  return target_->execute_recall_action(id,where,from);
898  }
899 
901  {
902  return target_->execute_recruit_action(unit_name,where,from);
903  }
904 
905  virtual stopunit_result_ptr execute_stopunit_action(const map_location& unit_location, bool remove_movement = true, bool remove_attacks = false) override
906  {
907  return target_->execute_stopunit_action(unit_location,remove_movement,remove_attacks);
908  }
909 
910  virtual synced_command_result_ptr execute_synced_command_action(const std::string& lua_code, const map_location& location = map_location::null_location()) override
911  {
912  return target_->execute_synced_command_action(lua_code,location);
913  }
914 
915  virtual team& current_team_w() override
916  {
917  return target_->current_team_w();
918  }
919 
920  virtual void raise_gamestate_changed() const override
921  {
923  }
924 
925  virtual game_info& get_info_w() override
926  {
927  return target_->get_info_w();
928  }
929 
930  virtual int get_recursion_count() const override
931  {
932  return target_->get_recursion_count();
933  }
934 
935  virtual config to_readwrite_context_config() const override
936  {
938  }
939 
940 private:
942 };
943 
944 //implementation
946 public:
947  side_context_impl(side_number side, const config &/*cfg*/)
948  : side_(side), recursion_counter_(0)
949  {
950  }
951 
952  virtual ~side_context_impl(){}
953 
954  virtual side_number get_side() const override
955  {
956  return side_;
957  }
958 
959  virtual void set_side(side_number side) override
960  {
961  side_ = side;
962  }
963 
964  virtual side_context& get_side_context() override
965  {
966  return *this;
967  }
968 
969  virtual int get_recursion_count() const override;
970 
971  virtual config to_side_context_config() const override;
972 
973 private:
976 };
977 
979 public:
980 
981  /**
982  * Constructor
983  */
984  readonly_context_impl(side_context &context, const config &cfg);
985 
986  /**
987  * Destructor
988  */
989  virtual ~readonly_context_impl();
990 
991  /**
992  * Unwrap - this class is not a proxy, so return *this
993 :w
994  */
996  {
997  return *this;
998  }
999 
1000  virtual void on_readonly_context_create() override;
1001 
1002  /** Handle generic event */
1003  virtual void handle_generic_event(const std::string& event_name) override;
1004 
1005  /** Return a reference to the 'team' object for the AI. */
1006  const team& current_team() const override;
1007 
1008  /** Show a diagnostic message on the screen. */
1009  void diagnostic(const std::string& msg) override;
1010 
1011  /** Display a debug message as a chat message. */
1012  void log_message(const std::string& msg) override;
1013 
1014  /**
1015  * Check if it is possible to attack enemy defender using our unit attacker from attackers current location,
1016  * @param attacker_loc location of attacker
1017  * @param defender_loc location of defender
1018  * @param attacker_weapon weapon of attacker
1019  * @retval possible results: ok, something wrong, attacker and/or defender are invalid, attacker and/or defender are invalid, or attacker doesn't have the specified weapon
1020  */
1021  attack_result_ptr check_attack_action(const map_location& attacker_loc, const map_location& defender_loc, int attacker_weapon) override;
1022 
1023  /**
1024  * Check if it is possible to move our unit from location 'from' to location 'to'
1025  * @param from location of our unit
1026  * @param to where to move
1027  * @param remove_movement set unit movement to 0 in case of successful move
1028  * @param unreach_is_ok whether it's okay for a destination to be unreachable
1029  * @retval possible results: ok, something wrong, move is interrupted, or move is impossible
1030  */
1031  move_result_ptr check_move_action(const map_location& from, const map_location& to, bool remove_movement=true, bool unreach_is_ok=false) override;
1032 
1033  /**
1034  * Check if it is possible to recall a unit for us on specified location
1035  * @param id the id of the unit to be recruited.
1036  * @param where location where the unit is to be recruited.
1037  * @param from location of the recaller.
1038  * @retval possible results: ok, something wrong, leader not on keep, no free space on keep, or not enough gold
1039  */
1040  recall_result_ptr check_recall_action(const std::string& id, const map_location &where = map_location::null_location(), const map_location &from = map_location::null_location()) override;
1041 
1042  /**
1043  * Check if it is possible to recruit a unit for us on specified location
1044  * @param unit_name the name of the unit to be recruited.
1045  * @param where location where the unit is to be recruited.
1046  * @param from location of the recruiter.
1047  * @retval possible results: ok, something wrong, leader not on keep, no free space on keep, or not enough gold
1048  */
1050 
1051  /**
1052  * Check if it is possible to remove unit movements and/or attack
1053  * @param unit_location the location of our unit
1054  * @param remove_movement set remaining movements to 0
1055  * @param remove_attacks set remaining attacks to 0
1056  * @retval possible results: ok, something wrong, or nothing to do
1057  */
1058  stopunit_result_ptr check_stopunit_action(const map_location& unit_location, bool remove_movement = true, bool remove_attacks = false) override;
1059 
1060  /**
1061  * Check if it is possible to run Lua code
1062  * @param lua_code the code to be run
1063  * @param location location to be passed to the code as x1/y1
1064  * @retval possible results: ok, something wrong, or nothing to do
1065  */
1066  synced_command_result_ptr check_synced_command_action(const std::string& lua_code, const map_location& location = map_location::null_location()) override;
1067 
1068  /**
1069  * Calculate the moves units may possibly make.
1070  *
1071  * @param possible_moves A map which will be filled with the paths
1072  * each unit can take to get to every possible
1073  * destination. You probably don't want to use
1074  * this object at all, except to pass to
1075  * 'move_unit'.
1076  * @param srcdst A map of units to all their possible
1077  * destinations.
1078  * @param dstsrc A map of destinations to all the units that
1079  * can move to that destination.
1080  * @param enemy if true, a map of possible moves for enemies
1081  * will be calculated. If false, a map of
1082  * possible moves for units on the AI's side
1083  * will be calculated. The AI's own leader will
1084  * not be included in this map.
1085  * @param assume_full_movement
1086  * If true, the function will operate on the
1087  * assumption that all units can move their full
1088  * movement allotment.
1089  * @param remove_destinations a pointer to a terrain filter for possible destinations
1090  * to omit.
1091  */
1092  void calculate_possible_moves(std::map<map_location,pathfind::paths>& possible_moves,
1093  move_map& srcdst, move_map& dstsrc, bool enemy,
1094  bool assume_full_movement=false,
1095  const terrain_filter* remove_destinations=nullptr) const override;
1096 
1097  /**
1098  * A more fundamental version of calculate_possible_moves which allows the
1099  * use of a speculative unit map.
1100  * NOTE: Support for a speculative map is broken (not used when pathfinding)
1101  * and has not been used since (probably) r38610 (September 2009).
1102  * (See the TODO in the implementation.)
1103  */
1104  void calculate_moves(const unit_map& units,
1105  std::map<map_location,pathfind::paths>& possible_moves, move_map& srcdst,
1106  move_map& dstsrc, bool enemy, bool assume_full_movement=false,
1107  const terrain_filter* remove_destinations=nullptr,
1108  bool see_all=false) const override;
1109 
1110  virtual const game_info& get_info() const override;
1111 
1112  /**
1113  * Function which should be called frequently to allow the user to interact
1114  * with the interface. This function will make sure that interaction
1115  * doesn't occur too often, so there is no problem with calling it very
1116  * regularly.
1117  */
1118  void raise_user_interact() const override;
1119 
1120  virtual int get_recursion_count() const override;
1121 
1122  //@note: following functions are in alphabetic order
1124  const move_map& dstsrc, const move_map& srcdst, const move_map& enemy_dstsrc) const override;
1125 
1126  virtual std::map<map_location,defensive_position>& defensive_position_cache() const override;
1127 
1128  virtual const unit_advancements_aspect& get_advancements() const override;
1129 
1130  virtual double get_aggression() const override;
1131 
1132  virtual bool get_allow_ally_villages() const override;
1133 
1134  virtual const aspect_map& get_aspects() const override;
1135 
1136  virtual aspect_map& get_aspects() override;
1137 
1138  virtual const attacks_vector& get_attacks() const override;
1139 
1140  virtual const terrain_filter& get_avoid() const override;
1141 
1142  virtual double get_caution() const override;
1143 
1144  virtual const move_map& get_dstsrc() const override;
1145 
1146  virtual const move_map& get_enemy_dstsrc() const override;
1147 
1148  virtual const moves_map& get_enemy_possible_moves() const override;
1149 
1150  virtual const move_map& get_enemy_srcdst() const override;
1151 
1152  virtual engine_ptr get_engine_by_cfg(const config& cfg) override;
1153 
1154  virtual const std::vector<engine_ptr>& get_engines() const override;
1155 
1156  virtual std::vector<engine_ptr>& get_engines() override;
1157 
1158  virtual std::string get_grouping() const override;
1159 
1160  virtual const std::vector<goal_ptr>& get_goals() const override;
1161 
1162  virtual std::vector<goal_ptr>& get_goals() override;
1163 
1164  virtual double get_leader_aggression() const override;
1165 
1166  virtual config get_leader_goal() const override;
1167 
1168  virtual utils::variant<bool, std::vector<std::string>> get_leader_ignores_keep() const override;
1169 
1170  virtual double get_leader_value() const override;
1171 
1172  virtual utils::variant<bool, std::vector<std::string>> get_passive_leader() const override;
1173 
1174  virtual utils::variant<bool, std::vector<std::string>> get_passive_leader_shares_keep() const override;
1175 
1176  virtual const moves_map& get_possible_moves() const override;
1177 
1178  virtual double get_recruitment_diversity() const override;
1179 
1180  virtual const config get_recruitment_instructions() const override;
1181 
1182  virtual const std::vector<std::string> get_recruitment_more() const override;
1183 
1184  virtual const std::vector<std::string> get_recruitment_pattern() const override;
1185 
1186  virtual int get_recruitment_randomness() const override;
1187 
1188  virtual const config get_recruitment_save_gold() const override;
1189 
1190  virtual double get_retreat_enemy_weight() const override;
1191 
1192  virtual double get_retreat_factor() const override;
1193 
1194  virtual double get_scout_village_targeting() const override;
1195 
1196  virtual bool get_simple_targeting() const override;
1197 
1198  virtual const move_map& get_srcdst() const override;
1199 
1200  virtual bool get_support_villages() const override;
1201 
1202  virtual double get_village_value() const override;
1203 
1204  virtual int get_villages_per_scout() const override;
1205 
1206  virtual bool is_active(const std::string &time_of_day, const std::string &turns) const override;
1207 
1208  virtual bool is_keep_ignoring_leader(const std::string &id) const override;
1209 
1210  virtual bool is_passive_leader(const std::string &id) const override;
1211 
1212  virtual bool is_passive_keep_sharing_leader(const std::string &id) const override;
1213 
1214  virtual bool is_dst_src_valid_lua() const override;
1215 
1216  virtual bool is_dst_src_enemy_valid_lua() const override;
1217 
1218  virtual bool is_src_dst_valid_lua() const override;
1219 
1220  virtual bool is_src_dst_enemy_valid_lua() const override;
1221 
1222  virtual void invalidate_defensive_position_cache() const override;
1223 
1224  virtual void invalidate_move_maps() const override;
1225 
1226  virtual void invalidate_keeps_cache() const override;
1227 
1228  virtual const std::set<map_location>& keeps() const override;
1229 
1230  virtual bool leader_can_reach_keep() const override;
1231 
1232  virtual const map_location& nearest_keep(const map_location& loc) const override;
1233 
1234  virtual double power_projection(const map_location& loc, const move_map& dstsrc) const override;
1235 
1236  virtual void recalculate_move_maps() const override;
1237 
1238  virtual void recalculate_move_maps_enemy() const override;
1239 
1240  virtual void add_aspects(std::vector< aspect_ptr > &aspects) override;
1241 
1242  virtual void add_facet(const std::string &id, const config &cfg) const override;
1243 
1244  void on_create();
1245 
1246  virtual void set_dst_src_valid_lua() override;
1247 
1248  virtual void set_dst_src_enemy_valid_lua() override;
1249 
1250  virtual void set_src_dst_valid_lua() override;
1251 
1252  virtual void set_src_dst_enemy_valid_lua() override;
1253 
1254  virtual const map_location& suitable_keep( const map_location& leader_location, const pathfind::paths& leader_paths ) const override;
1255 
1256  virtual config to_readonly_context_config() const override;
1257 
1258  virtual unit_stats_cache_t & unit_stats_cache() const override;
1259 
1260 private:
1261  template<typename T>
1262  void add_known_aspect(const std::string &name, typesafe_aspect_ptr<T>& where);
1263 
1264  bool applies_to_leader(const utils::variant<bool, std::vector<std::string>> &aspect_value, const std::string &id) const;
1265 
1266  const config cfg_;
1267 
1268  /**
1269  * AI Support Engines
1270  */
1271  std::vector< engine_ptr > engines_;
1272 
1274 
1282  mutable std::map<map_location,defensive_position> defensive_position_cache_;
1288  std::vector< goal_ptr > goals_;
1295  mutable bool move_maps_valid_;
1296  mutable bool dst_src_valid_lua_;
1298  mutable bool src_dst_valid_lua_;
1319 };
1320 
1322 public:
1323  /**
1324  * Unwrap - this class is not a proxy, so return *this
1325  */
1327  {
1328  return *this;
1329  }
1330 
1331  /**
1332  * Ask the game to attack an enemy defender using our unit attacker from attackers current location,
1333  * @param attacker_loc location of attacker
1334  * @param defender_loc location of defender
1335  * @param attacker_weapon weapon of attacker
1336  * @retval possible results: ok, something wrong, attacker and/or defender are invalid, attacker and/or defender are invalid, or attacker doesn't have the specified weapon
1337  */
1338  virtual attack_result_ptr execute_attack_action(const map_location& attacker_loc, const map_location& defender_loc, int attacker_weapon) override;
1339 
1340  /**
1341  * Ask the game to move our unit from location 'from' to location 'to', optionally - doing a partial move
1342  * @param from location of our unit
1343  * @param to where to move
1344  * @param remove_movement set unit movement to 0 in case of successful move
1345  * @param unreach_is_ok whether it's okay for a destination to be unreachable
1346  * @retval possible results: ok, something wrong, move is interrupted, or move is impossible
1347  */
1348  virtual move_result_ptr execute_move_action(const map_location& from, const map_location& to, bool remove_movement=true, bool unreach_is_ok=false) override;
1349 
1350  /**
1351  * Ask the game to recall a unit for us on specified location
1352  * @param id the id of the unit to be recalled.
1353  * @param where location where the unit is to be recalled.
1354  * @param from location of the recaller.
1355  * @retval possible results: ok, something wrong, leader not on keep, no free space on keep, or not enough gold
1356  */
1357  virtual recall_result_ptr execute_recall_action(const std::string& id, const map_location &where = map_location::null_location(), const map_location &from = map_location::null_location()) override;
1358 
1359  /**
1360  * Ask the game to recruit a unit for us on specified location
1361  * @param unit_name the name of the unit to be recruited.
1362  * @param where location where the unit is to be recruited.
1363  * @param from location of the recruiter.
1364  * @retval possible results: ok, something wrong, leader not on keep, no free space on keep, or not enough gold
1365  */
1366  virtual recruit_result_ptr execute_recruit_action(const std::string& unit_name, const map_location &where = map_location::null_location(), const map_location &from = map_location::null_location()) override;
1367 
1368  /**
1369  * Ask the game to remove unit movements and/or attack
1370  * @param unit_location the location of our unit
1371  * @param remove_movement set remaining movements to 0
1372  * @param remove_attacks set remaining attacks to 0
1373  * @retval possible results: ok, something wrong, nothing to do
1374  */
1375  virtual stopunit_result_ptr execute_stopunit_action(const map_location& unit_location, bool remove_movement = true, bool remove_attacks = false) override;
1376 
1377  /**
1378  * Ask the game to run Lua code
1379  * @param lua_code the code to be run
1380  * @param location location to be passed to the code as x1/y1
1381  * @retval possible results: ok, something wrong, nothing to do
1382  */
1383  virtual synced_command_result_ptr execute_synced_command_action(const std::string& lua_code, const map_location& location = map_location::null_location()) override;
1384 
1385  /** Return a reference to the 'team' object for the AI. */
1386  virtual team& current_team_w() override;
1387 
1388  /** Notifies all interested observers of the event respectively. */
1389  void raise_gamestate_changed() const override;
1390 
1391  /**
1392  * Constructor.
1393  */
1396  {
1397  init_readonly_context_proxy(context);
1398  }
1399 
1401  {
1402  }
1403 
1404  /**
1405  * Functions to retrieve the 'info' object.
1406  * Used by derived classes to discover all necessary game information.
1407  */
1408  virtual game_info& get_info_w() override;
1409 
1410  virtual int get_recursion_count() const override;
1411 
1412  virtual config to_readwrite_context_config() const override;
1413 
1414 private:
1416 };
1417 
1418 } //end of namespace ai
map_location loc
Definition: move.cpp:172
const gamemap * map_
Definition: contexts.hpp:112
void handle_generic_event(const std::string &event_name)
Definition: contexts.cpp:853
const std::set< map_location > & get()
Definition: contexts.cpp:899
void init(const gamemap &map)
Definition: contexts.cpp:894
std::set< map_location > keeps_
Definition: contexts.hpp:113
virtual double get_caution() const override
Definition: contexts.cpp:552
virtual ~readonly_context_impl()
Destructor.
Definition: contexts.cpp:284
virtual void recalculate_move_maps_enemy() const override
Definition: contexts.cpp:1113
std::map< map_location, defensive_position > defensive_position_cache_
Definition: contexts.hpp:1282
stopunit_result_ptr check_stopunit_action(const map_location &unit_location, bool remove_movement=true, bool remove_attacks=false) override
Check if it is possible to remove unit movements and/or attack.
Definition: contexts.cpp:142
typesafe_aspect_ptr< utils::variant< bool, std::vector< std::string > > > passive_leader_
Definition: contexts.hpp:1300
recruit_result_ptr check_recruit_action(const std::string &unit_name, const map_location &where=map_location::null_location(), const map_location &from=map_location::null_location()) override
Check if it is possible to recruit a unit for us on specified location.
Definition: contexts.cpp:134
virtual bool is_keep_ignoring_leader(const std::string &id) const override
Definition: contexts.cpp:1231
virtual const move_map & get_srcdst() const override
Definition: contexts.cpp:791
void calculate_possible_moves(std::map< map_location, pathfind::paths > &possible_moves, move_map &srcdst, move_map &dstsrc, bool enemy, bool assume_full_movement=false, const terrain_filter *remove_destinations=nullptr) const override
Calculate the moves units may possibly make.
Definition: contexts.cpp:322
typesafe_aspect_ptr< std::vector< std::string > > recruitment_more_
Definition: contexts.hpp:1305
virtual bool is_active(const std::string &time_of_day, const std::string &turns) const override
Definition: contexts.cpp:1194
virtual const move_map & get_dstsrc() const override
Definition: contexts.cpp:560
virtual const std::vector< std::string > get_recruitment_pattern() const override
Definition: contexts.cpp:735
const defensive_position & best_defensive_position(const map_location &unit, const move_map &dstsrc, const move_map &srcdst, const move_map &enemy_dstsrc) const override
Definition: contexts.cpp:446
virtual bool get_simple_targeting() const override
Definition: contexts.cpp:783
typesafe_aspect_ptr< bool > support_villages_
Definition: contexts.hpp:1315
virtual bool is_passive_keep_sharing_leader(const std::string &id) const override
Definition: contexts.cpp:1241
unit_stats_cache_t unit_stats_cache_
Definition: contexts.hpp:1316
void add_known_aspect(const std::string &name, typesafe_aspect_ptr< T > &where)
Definition: contexts.cpp:155
virtual void add_facet(const std::string &id, const config &cfg) const override
Definition: contexts.cpp:436
virtual bool get_allow_ally_villages() const override
Definition: contexts.cpp:514
virtual readonly_context & get_readonly_context() override
Definition: contexts.hpp:995
virtual std::map< map_location, defensive_position > & defensive_position_cache() const override
Definition: contexts.cpp:491
attack_result_ptr check_attack_action(const map_location &attacker_loc, const map_location &defender_loc, int attacker_weapon) override
Check if it is possible to attack enemy defender using our unit attacker from attackers current locat...
Definition: contexts.cpp:108
virtual const std::vector< goal_ptr > & get_goals() const override
Definition: contexts.cpp:645
virtual const game_info & get_info() const override
Definition: contexts.cpp:294
virtual void recalculate_move_maps() const override
Definition: contexts.cpp:1086
typesafe_aspect_ptr< terrain_filter > avoid_
Definition: contexts.hpp:1280
virtual bool is_dst_src_valid_lua() const override
Definition: contexts.cpp:823
typesafe_aspect_ptr< bool > simple_targeting_
Definition: contexts.hpp:1313
virtual const move_map & get_enemy_srcdst() const override
Definition: contexts.cpp:584
virtual double get_recruitment_diversity() const override
Definition: contexts.cpp:711
virtual bool is_src_dst_enemy_valid_lua() const override
Definition: contexts.cpp:838
void raise_user_interact() const override
Function which should be called frequently to allow the user to interact with the interface.
Definition: contexts.cpp:87
virtual double get_retreat_enemy_weight() const override
Definition: contexts.cpp:759
virtual const std::vector< engine_ptr > & get_engines() const override
Definition: contexts.cpp:627
virtual const attacks_vector & get_attacks() const override
Definition: contexts.cpp:532
typesafe_aspect_ptr< attacks_vector > attacks_
Definition: contexts.hpp:1279
virtual const map_location & suitable_keep(const map_location &leader_location, const pathfind::paths &leader_paths) const override
get most suitable keep for leader - nearest free that can be reached in 1 turn, if none - return near...
Definition: contexts.cpp:1146
virtual void invalidate_move_maps() const override
Definition: contexts.cpp:858
virtual const terrain_filter & get_avoid() const override
Definition: contexts.cpp:541
virtual int get_recursion_count() const override
Get the value of the recursion counter.
Definition: contexts.cpp:77
bool applies_to_leader(const utils::variant< bool, std::vector< std::string >> &aspect_value, const std::string &id) const
Definition: contexts.cpp:1217
virtual int get_villages_per_scout() const override
Definition: contexts.cpp:815
virtual config get_leader_goal() const override
Definition: contexts.cpp:663
virtual void invalidate_keeps_cache() const override
Definition: contexts.cpp:848
virtual double get_leader_aggression() const override
Definition: contexts.cpp:655
readonly_context_impl(side_context &context, const config &cfg)
Constructor.
Definition: contexts.cpp:160
virtual const aspect_map & get_aspects() const override
Definition: contexts.cpp:522
virtual const move_map & get_enemy_dstsrc() const override
Definition: contexts.cpp:568
virtual double get_village_value() const override
Definition: contexts.cpp:807
typesafe_aspect_ptr< int > recruitment_randomness_
Definition: contexts.hpp:1307
virtual bool is_passive_leader(const std::string &id) const override
Definition: contexts.cpp:1236
const team & current_team() const override
Return a reference to the 'team' object for the AI.
Definition: contexts.cpp:309
typesafe_aspect_ptr< int > villages_per_scout_
Definition: contexts.hpp:1318
virtual unit_stats_cache_t & unit_stats_cache() const override
Weapon choice cache, to speed simulations.
Definition: contexts.cpp:1189
virtual void set_dst_src_valid_lua() override
Definition: contexts.cpp:1126
typesafe_aspect_ptr< double > recruitment_diversity_
Definition: contexts.hpp:1303
typesafe_aspect_ptr< double > village_value_
Definition: contexts.hpp:1317
virtual void set_src_dst_enemy_valid_lua() override
Definition: contexts.cpp:1141
recursion_counter recursion_counter_
Definition: contexts.hpp:1309
virtual const moves_map & get_enemy_possible_moves() const override
Definition: contexts.cpp:576
void log_message(const std::string &msg) override
Display a debug message as a chat message.
Definition: contexts.cpp:314
virtual const map_location & nearest_keep(const map_location &loc) const override
Definition: contexts.cpp:944
typesafe_aspect_ptr< unit_advancements_aspect > advancements_
Definition: contexts.hpp:1275
typesafe_aspect_ptr< double > retreat_factor_
Definition: contexts.hpp:1311
virtual const config get_recruitment_instructions() const override
Definition: contexts.cpp:719
virtual double get_aggression() const override
Definition: contexts.cpp:506
known_aspect_map known_aspects_
Definition: contexts.hpp:1273
typesafe_aspect_ptr< double > retreat_enemy_weight_
Definition: contexts.hpp:1310
synced_command_result_ptr check_synced_command_action(const std::string &lua_code, const map_location &location=map_location::null_location()) override
Check if it is possible to run Lua code.
Definition: contexts.cpp:150
virtual double power_projection(const map_location &loc, const move_map &dstsrc) const override
Function which finds how much 'power' a side can attack a certain location with.
Definition: contexts.cpp:973
void calculate_moves(const unit_map &units, std::map< map_location, pathfind::paths > &possible_moves, move_map &srcdst, move_map &dstsrc, bool enemy, bool assume_full_movement=false, const terrain_filter *remove_destinations=nullptr, bool see_all=false) const override
A more fundamental version of calculate_possible_moves which allows the use of a speculative unit map...
Definition: contexts.cpp:329
virtual void invalidate_defensive_position_cache() const override
Definition: contexts.cpp:843
virtual utils::variant< bool, std::vector< std::string > > get_passive_leader() const override
Definition: contexts.cpp:687
typesafe_aspect_ptr< double > leader_value_
Definition: contexts.hpp:1293
typesafe_aspect_ptr< config > recruitment_instructions_
Definition: contexts.hpp:1304
std::vector< engine_ptr > engines_
AI Support Engines.
Definition: contexts.hpp:1271
typesafe_aspect_ptr< utils::variant< bool, std::vector< std::string > > > passive_leader_shares_keep_
Definition: contexts.hpp:1301
virtual bool is_src_dst_valid_lua() const override
Definition: contexts.cpp:833
virtual void add_aspects(std::vector< aspect_ptr > &aspects) override
Definition: contexts.cpp:423
virtual bool is_dst_src_enemy_valid_lua() const override
Definition: contexts.cpp:828
virtual utils::variant< bool, std::vector< std::string > > get_passive_leader_shares_keep() const override
Definition: contexts.cpp:695
virtual double get_leader_value() const override
Definition: contexts.cpp:679
typesafe_aspect_ptr< double > scout_village_targeting_
Definition: contexts.hpp:1312
virtual utils::variant< bool, std::vector< std::string > > get_leader_ignores_keep() const override
Definition: contexts.cpp:671
virtual const std::vector< std::string > get_recruitment_more() const override
Definition: contexts.cpp:727
std::vector< goal_ptr > goals_
Definition: contexts.hpp:1288
virtual void set_dst_src_enemy_valid_lua() override
Definition: contexts.cpp:1131
typesafe_aspect_ptr< utils::variant< bool, std::vector< std::string > > > leader_ignores_keep_
Definition: contexts.hpp:1292
typesafe_aspect_ptr< std::vector< std::string > > recruitment_pattern_
Definition: contexts.hpp:1306
virtual const unit_advancements_aspect & get_advancements() const override
Definition: contexts.cpp:496
recall_result_ptr check_recall_action(const std::string &id, const map_location &where=map_location::null_location(), const map_location &from=map_location::null_location()) override
Check if it is possible to recall a unit for us on specified location.
Definition: contexts.cpp:130
virtual const std::set< map_location > & keeps() const override
Definition: contexts.cpp:870
typesafe_aspect_ptr< config > leader_goal_
Definition: contexts.hpp:1291
virtual void handle_generic_event(const std::string &event_name) override
Handle generic event.
Definition: contexts.cpp:289
virtual bool leader_can_reach_keep() const override
Definition: contexts.cpp:922
virtual bool get_support_villages() const override
Definition: contexts.cpp:799
virtual std::string get_grouping() const override
Definition: contexts.cpp:637
virtual double get_retreat_factor() const override
Definition: contexts.cpp:767
typesafe_aspect_ptr< bool > allow_ally_villages_
Definition: contexts.hpp:1277
virtual const config get_recruitment_save_gold() const override
Definition: contexts.cpp:751
void diagnostic(const std::string &msg) override
Show a diagnostic message on the screen.
Definition: contexts.cpp:302
virtual void on_readonly_context_create() override
Definition: contexts.cpp:240
virtual double get_scout_village_targeting() const override
Definition: contexts.cpp:775
typesafe_aspect_ptr< double > caution_
Definition: contexts.hpp:1281
virtual const moves_map & get_possible_moves() const override
Definition: contexts.cpp:703
virtual int get_recruitment_randomness() const override
Definition: contexts.cpp:743
move_result_ptr check_move_action(const map_location &from, const map_location &to, bool remove_movement=true, bool unreach_is_ok=false) override
Check if it is possible to move our unit from location 'from' to location 'to'.
Definition: contexts.cpp:118
typesafe_aspect_ptr< std::string > grouping_
Definition: contexts.hpp:1287
virtual config to_readonly_context_config() const override
serialize to config
Definition: contexts.cpp:269
typesafe_aspect_ptr< double > aggression_
Definition: contexts.hpp:1276
typesafe_aspect_ptr< config > recruitment_save_gold_
Definition: contexts.hpp:1308
typesafe_aspect_ptr< double > leader_aggression_
Definition: contexts.hpp:1290
virtual engine_ptr get_engine_by_cfg(const config &cfg) override
get engine by cfg, creating it if it is not created yet but known
Definition: contexts.cpp:592
virtual void set_src_dst_valid_lua() override
Definition: contexts.cpp:1136
virtual double get_caution() const override
Definition: contexts.hpp:583
virtual std::map< map_location, defensive_position > & defensive_position_cache() const override
Definition: contexts.hpp:533
virtual const map_location & suitable_keep(const map_location &leader_location, const pathfind::paths &leader_paths) const override
get most suitable keep for leader - nearest free that can be reached in 1 turn, if none - return near...
Definition: contexts.hpp:848
virtual void invalidate_keeps_cache() const override
Definition: contexts.hpp:798
virtual config get_leader_goal() const override
Definition: contexts.hpp:643
virtual utils::variant< bool, std::vector< std::string > > get_passive_leader() const override
Definition: contexts.hpp:658
virtual const team & current_team() const override
Definition: contexts.hpp:447
virtual bool is_keep_ignoring_leader(const std::string &id) const override
Definition: contexts.hpp:753
virtual bool is_passive_keep_sharing_leader(const std::string &id) const override
Definition: contexts.hpp:763
virtual const move_map & get_enemy_srcdst() const override
Definition: contexts.hpp:603
virtual synced_command_result_ptr check_synced_command_action(const std::string &lua_code, const map_location &location=map_location::null_location()) override
Definition: contexts.hpp:489
virtual std::vector< goal_ptr > & get_goals() override
Definition: contexts.hpp:633
virtual void on_readonly_context_create() override
Definition: contexts.hpp:442
virtual const map_location & nearest_keep(const map_location &loc) const override
Definition: contexts.hpp:813
virtual const move_map & get_dstsrc() const override
Definition: contexts.hpp:588
virtual const config get_recruitment_save_gold() const override
Definition: contexts.hpp:703
virtual const terrain_filter & get_avoid() const override
Definition: contexts.hpp:578
virtual const aspect_map & get_aspects() const override
Definition: contexts.hpp:553
virtual void add_aspects(std::vector< aspect_ptr > &aspects) override
Definition: contexts.hpp:563
virtual const attacks_vector & get_attacks() const override
Definition: contexts.hpp:573
virtual void log_message(const std::string &msg) override
Definition: contexts.hpp:457
virtual double get_recruitment_diversity() const override
Definition: contexts.hpp:678
virtual double get_retreat_enemy_weight() const override
Definition: contexts.hpp:713
virtual bool leader_can_reach_keep() const override
Definition: contexts.hpp:808
virtual std::string get_grouping() const override
Definition: contexts.hpp:623
virtual void recalculate_move_maps() const override
Definition: contexts.hpp:818
readonly_context * target_
Definition: contexts.hpp:864
virtual int get_recursion_count() const override
Get the value of the recursion counter.
Definition: contexts.hpp:521
virtual void set_src_dst_enemy_valid_lua() override
Definition: contexts.hpp:843
virtual void raise_user_interact() const override
Definition: contexts.hpp:516
virtual void set_dst_src_enemy_valid_lua() override
Definition: contexts.hpp:833
virtual const game_info & get_info() const override
Definition: contexts.hpp:511
virtual void add_facet(const std::string &id, const config &cfg) const override
Definition: contexts.hpp:568
virtual void invalidate_move_maps() const override
Definition: contexts.hpp:793
virtual recruit_result_ptr check_recruit_action(const std::string &unit_name, const map_location &where=map_location::null_location(), const map_location &from=map_location::null_location()) override
Definition: contexts.hpp:478
virtual const std::set< map_location > & keeps() const override
Definition: contexts.hpp:803
virtual void calculate_moves(const unit_map &units, std::map< map_location, pathfind::paths > &possible_moves, move_map &srcdst, move_map &dstsrc, bool enemy, bool assume_full_movement=false, const terrain_filter *remove_destinations=nullptr, bool see_all=false) const override
Definition: contexts.hpp:502
virtual double get_retreat_factor() const override
Definition: contexts.hpp:718
virtual void recalculate_move_maps_enemy() const override
Definition: contexts.hpp:823
virtual bool get_simple_targeting() const override
Definition: contexts.hpp:728
virtual bool is_dst_src_valid_lua() const override
Definition: contexts.hpp:768
virtual void diagnostic(const std::string &msg) override
Definition: contexts.hpp:452
virtual const move_map & get_srcdst() const override
Definition: contexts.hpp:708
virtual engine_ptr get_engine_by_cfg(const config &cfg) override
get engine by cfg, creating it if it is not created yet but known
Definition: contexts.hpp:608
virtual utils::variant< bool, std::vector< std::string > > get_leader_ignores_keep() const override
Definition: contexts.hpp:648
virtual const unit_advancements_aspect & get_advancements() const override
Definition: contexts.hpp:538
virtual bool is_src_dst_valid_lua() const override
Definition: contexts.hpp:778
const defensive_position & best_defensive_position(const map_location &unit, const move_map &dstsrc, const move_map &srcdst, const move_map &enemy_dstsrc) const override
Definition: contexts.hpp:527
virtual int get_recruitment_randomness() const override
Definition: contexts.hpp:698
virtual void set_src_dst_valid_lua() override
Definition: contexts.hpp:838
virtual const config get_recruitment_instructions() const override
Definition: contexts.hpp:683
virtual recall_result_ptr check_recall_action(const std::string &id, const map_location &where=map_location::null_location(), const map_location &from=map_location::null_location()) override
Definition: contexts.hpp:472
virtual void calculate_possible_moves(std::map< map_location, pathfind::paths > &possible_moves, move_map &srcdst, move_map &dstsrc, bool enemy, bool assume_full_movement=false, const terrain_filter *remove_destinations=nullptr) const override
Definition: contexts.hpp:494
virtual const std::vector< goal_ptr > & get_goals() const override
Definition: contexts.hpp:628
virtual bool is_passive_leader(const std::string &id) const override
Definition: contexts.hpp:758
virtual void invalidate_defensive_position_cache() const override
Definition: contexts.hpp:788
virtual const std::vector< engine_ptr > & get_engines() const override
Definition: contexts.hpp:613
virtual double power_projection(const map_location &loc, const move_map &dstsrc) const override
Function which finds how much 'power' a side can attack a certain location with.
Definition: contexts.hpp:673
virtual double get_scout_village_targeting() const override
Definition: contexts.hpp:723
virtual const std::vector< std::string > get_recruitment_pattern() const override
Definition: contexts.hpp:693
virtual unit_stats_cache_t & unit_stats_cache() const override
Definition: contexts.hpp:858
virtual double get_village_value() const override
Definition: contexts.hpp:738
virtual move_result_ptr check_move_action(const map_location &from, const map_location &to, bool remove_movement=true, bool unreach_is_ok=false) override
Definition: contexts.hpp:467
virtual double get_leader_value() const override
Definition: contexts.hpp:653
virtual utils::variant< bool, std::vector< std::string > > get_passive_leader_shares_keep() const override
Definition: contexts.hpp:663
virtual double get_aggression() const override
Definition: contexts.hpp:543
virtual ~readonly_context_proxy()
Definition: contexts.hpp:429
virtual stopunit_result_ptr check_stopunit_action(const map_location &unit_location, bool remove_movement=true, bool remove_attacks=false) override
Definition: contexts.hpp:484
virtual const moves_map & get_enemy_possible_moves() const override
Definition: contexts.hpp:598
virtual const std::vector< std::string > get_recruitment_more() const override
Definition: contexts.hpp:688
virtual bool is_src_dst_enemy_valid_lua() const override
Definition: contexts.hpp:783
virtual aspect_map & get_aspects() override
Definition: contexts.hpp:558
virtual bool is_dst_src_enemy_valid_lua() const override
Definition: contexts.hpp:773
virtual int get_villages_per_scout() const override
Definition: contexts.hpp:743
virtual std::vector< engine_ptr > & get_engines() override
Definition: contexts.hpp:618
virtual readonly_context & get_readonly_context() override
Definition: contexts.hpp:437
virtual config to_readonly_context_config() const override
serialize to config
Definition: contexts.hpp:853
virtual bool is_active(const std::string &time_of_day, const std::string &turns) const override
Definition: contexts.hpp:748
virtual double get_leader_aggression() const override
Definition: contexts.hpp:638
virtual void set_dst_src_valid_lua() override
Definition: contexts.hpp:828
void init_readonly_context_proxy(readonly_context &target)
Definition: contexts.hpp:431
virtual bool get_support_villages() const override
Definition: contexts.hpp:733
virtual bool get_allow_ally_villages() const override
Definition: contexts.hpp:548
virtual const move_map & get_enemy_dstsrc() const override
Definition: contexts.hpp:593
virtual attack_result_ptr check_attack_action(const map_location &attacker_loc, const map_location &defender_loc, int attacker_weapon) override
Definition: contexts.hpp:462
virtual const moves_map & get_possible_moves() const override
Definition: contexts.hpp:668
virtual void add_facet(const std::string &id, const config &cfg) const =0
virtual int get_villages_per_scout() const =0
virtual std::string get_grouping() const =0
virtual const std::vector< engine_ptr > & get_engines() const =0
virtual const terrain_filter & get_avoid() const =0
virtual engine_ptr get_engine_by_cfg(const config &cfg)=0
get engine by cfg, creating it if it is not created yet but known
virtual bool get_simple_targeting() const =0
virtual void recalculate_move_maps() const =0
virtual const aspect_map & get_aspects() const =0
virtual void calculate_moves(const unit_map &units, std::map< map_location, pathfind::paths > &possible_moves, move_map &srcdst, move_map &dstsrc, bool enemy, bool assume_full_movement=false, const terrain_filter *remove_destinations=nullptr, bool see_all=false) const =0
virtual const std::vector< goal_ptr > & get_goals() const =0
virtual const attacks_vector & get_attacks() const =0
virtual std::vector< goal_ptr > & get_goals()=0
virtual config to_readonly_context_config() const =0
serialize to config
virtual void set_dst_src_valid_lua()=0
virtual const move_map & get_enemy_srcdst() const =0
virtual const defensive_position & best_defensive_position(const map_location &unit, const move_map &dstsrc, const move_map &srcdst, const move_map &enemy_dstsrc) const =0
virtual bool is_passive_leader(const std::string &id) const =0
virtual utils::variant< bool, std::vector< std::string > > get_leader_ignores_keep() const =0
virtual const move_map & get_enemy_dstsrc() const =0
virtual bool is_src_dst_enemy_valid_lua() const =0
virtual config get_leader_goal() const =0
virtual recruit_result_ptr check_recruit_action(const std::string &unit_name, const map_location &where=map_location::null_location(), const map_location &from=map_location::null_location())=0
virtual void invalidate_move_maps() const =0
virtual synced_command_result_ptr check_synced_command_action(const std::string &lua_code, const map_location &location=map_location::null_location())=0
virtual const map_location & nearest_keep(const map_location &loc) const =0
virtual double get_aggression() const =0
virtual int get_recruitment_randomness() const =0
virtual unit_stats_cache_t & unit_stats_cache() const =0
virtual double get_retreat_factor() const =0
virtual std::vector< engine_ptr > & get_engines()=0
virtual bool is_src_dst_valid_lua() const =0
virtual bool is_dst_src_enemy_valid_lua() const =0
virtual const team & current_team() const =0
virtual const map_location & suitable_keep(const map_location &leader_location, const pathfind::paths &leader_paths) const =0
get most suitable keep for leader - nearest free that can be reached in 1 turn, if none - return near...
virtual void calculate_possible_moves(std::map< map_location, pathfind::paths > &possible_moves, move_map &srcdst, move_map &dstsrc, bool enemy, bool assume_full_movement=false, const terrain_filter *remove_destinations=nullptr) const =0
virtual stopunit_result_ptr check_stopunit_action(const map_location &unit_location, bool remove_movement=true, bool remove_attacks=false)=0
virtual void set_src_dst_enemy_valid_lua()=0
virtual bool is_keep_ignoring_leader(const std::string &id) const =0
virtual double power_projection(const map_location &loc, const move_map &dstsrc) const =0
Function which finds how much 'power' a side can attack a certain location with.
virtual const move_map & get_srcdst() const =0
virtual void set_dst_src_enemy_valid_lua()=0
virtual void on_readonly_context_create()=0
virtual bool is_active(const std::string &time_of_day, const std::string &turns) const =0
virtual bool leader_can_reach_keep() const =0
virtual double get_caution() const =0
virtual utils::variant< bool, std::vector< std::string > > get_passive_leader() const =0
virtual void recalculate_move_maps_enemy() const =0
std::map< std::pair< map_location, const unit_type * >, std::pair< battle_context_unit_stats, battle_context_unit_stats > > unit_stats_cache_t
Definition: contexts.hpp:339
virtual bool get_allow_ally_villages() const =0
virtual void diagnostic(const std::string &msg)=0
virtual readonly_context & get_readonly_context()=0
virtual bool is_dst_src_valid_lua() const =0
virtual std::map< map_location, defensive_position > & defensive_position_cache() const =0
virtual const std::vector< std::string > get_recruitment_pattern() const =0
virtual const config get_recruitment_instructions() const =0
virtual double get_retreat_enemy_weight() const =0
virtual double get_scout_village_targeting() const =0
virtual void raise_user_interact() const =0
virtual double get_recruitment_diversity() const =0
virtual double get_leader_aggression() const =0
virtual bool get_support_villages() const =0
virtual const move_map & get_dstsrc() const =0
virtual aspect_map & get_aspects()=0
virtual bool is_passive_keep_sharing_leader(const std::string &id) const =0
virtual const std::vector< std::string > get_recruitment_more() const =0
virtual void set_src_dst_valid_lua()=0
virtual const std::set< map_location > & keeps() const =0
virtual const moves_map & get_possible_moves() const =0
virtual const config get_recruitment_save_gold() const =0
virtual void log_message(const std::string &msg)=0
virtual attack_result_ptr check_attack_action(const map_location &attacker_loc, const map_location &defender_loc, int attacker_weapon)=0
virtual void add_aspects(std::vector< aspect_ptr > &aspects)=0
virtual move_result_ptr check_move_action(const map_location &from, const map_location &to, bool remove_movement=true, bool unreach_is_ok=false)=0
virtual const game_info & get_info() const =0
virtual recall_result_ptr check_recall_action(const std::string &id, const map_location &where=map_location::null_location(), const map_location &from=map_location::null_location())=0
virtual double get_village_value() const =0
virtual ~readonly_context()
Definition: contexts.hpp:162
virtual const unit_advancements_aspect & get_advancements() const =0
virtual void invalidate_defensive_position_cache() const =0
virtual void invalidate_keeps_cache() const =0
virtual utils::variant< bool, std::vector< std::string > > get_passive_leader_shares_keep() const =0
virtual const moves_map & get_enemy_possible_moves() const =0
virtual double get_leader_value() const =0
virtual game_info & get_info_w() override
Functions to retrieve the 'info' object.
Definition: contexts.cpp:298
virtual synced_command_result_ptr execute_synced_command_action(const std::string &lua_code, const map_location &location=map_location::null_location()) override
Ask the game to run Lua code.
Definition: contexts.cpp:146
virtual recruit_result_ptr execute_recruit_action(const std::string &unit_name, const map_location &where=map_location::null_location(), const map_location &from=map_location::null_location()) override
Ask the game to recruit a unit for us on specified location.
Definition: contexts.cpp:126
virtual config to_readwrite_context_config() const override
serialize this context to config
Definition: contexts.cpp:264
void raise_gamestate_changed() const override
Notifies all interested observers of the event respectively.
Definition: contexts.cpp:92
virtual move_result_ptr execute_move_action(const map_location &from, const map_location &to, bool remove_movement=true, bool unreach_is_ok=false) override
Ask the game to move our unit from location 'from' to location 'to', optionally - doing a partial mov...
Definition: contexts.cpp:114
virtual recall_result_ptr execute_recall_action(const std::string &id, const map_location &where=map_location::null_location(), const map_location &from=map_location::null_location()) override
Ask the game to recall a unit for us on specified location.
Definition: contexts.cpp:122
virtual stopunit_result_ptr execute_stopunit_action(const map_location &unit_location, bool remove_movement=true, bool remove_attacks=false) override
Ask the game to remove unit movements and/or attack.
Definition: contexts.cpp:138
recursion_counter recursion_counter_
Definition: contexts.hpp:1415
virtual readwrite_context & get_readwrite_context() override
Unwrap - this class is not a proxy, so return *this.
Definition: contexts.hpp:1326
virtual team & current_team_w() override
Return a reference to the 'team' object for the AI.
Definition: contexts.cpp:97
virtual attack_result_ptr execute_attack_action(const map_location &attacker_loc, const map_location &defender_loc, int attacker_weapon) override
Ask the game to attack an enemy defender using our unit attacker from attackers current location,...
Definition: contexts.cpp:102
readwrite_context_impl(readonly_context &context, const config &)
Constructor.
Definition: contexts.hpp:1394
virtual int get_recursion_count() const override
Get the value of the recursion counter.
Definition: contexts.cpp:82
virtual attack_result_ptr execute_attack_action(const map_location &attacker_loc, const map_location &defender_loc, int attacker_weapon) override
Definition: contexts.hpp:885
virtual game_info & get_info_w() override
Definition: contexts.hpp:925
virtual readwrite_context & get_readwrite_context() override
Definition: contexts.hpp:880
virtual config to_readwrite_context_config() const override
serialize this context to config
Definition: contexts.hpp:935
readwrite_context * target_
Definition: contexts.hpp:941
virtual recruit_result_ptr execute_recruit_action(const std::string &unit_name, const map_location &where=map_location::null_location(), const map_location &from=map_location::null_location()) override
Definition: contexts.hpp:900
virtual stopunit_result_ptr execute_stopunit_action(const map_location &unit_location, bool remove_movement=true, bool remove_attacks=false) override
Definition: contexts.hpp:905
virtual recall_result_ptr execute_recall_action(const std::string &id, const map_location &where=map_location::null_location(), const map_location &from=map_location::null_location()) override
Definition: contexts.hpp:895
virtual int get_recursion_count() const override
Get the value of the recursion counter.
Definition: contexts.hpp:930
virtual synced_command_result_ptr execute_synced_command_action(const std::string &lua_code, const map_location &location=map_location::null_location()) override
Definition: contexts.hpp:910
virtual move_result_ptr execute_move_action(const map_location &from, const map_location &to, bool remove_movement=true, bool unreach_is_ok=false) override
Definition: contexts.hpp:890
void init_readwrite_context_proxy(readwrite_context &target)
Definition: contexts.hpp:874
virtual team & current_team_w() override
Definition: contexts.hpp:915
virtual void raise_gamestate_changed() const override
Definition: contexts.hpp:920
virtual recall_result_ptr execute_recall_action(const std::string &id, const map_location &where=map_location::null_location(), const map_location &from=map_location::null_location())=0
virtual attack_result_ptr execute_attack_action(const map_location &attacker_loc, const map_location &defender_loc, int attacker_weapon)=0
virtual ~readwrite_context()
Definition: contexts.hpp:348
virtual readwrite_context & get_readwrite_context()=0
virtual move_result_ptr execute_move_action(const map_location &from, const map_location &to, bool remove_movement=true, bool unreach_is_ok=false)=0
virtual void raise_gamestate_changed() const =0
virtual synced_command_result_ptr execute_synced_command_action(const std::string &lua_code, const map_location &location=map_location::null_location())=0
virtual game_info & get_info_w()=0
virtual config to_readwrite_context_config() const =0
serialize this context to config
virtual recruit_result_ptr execute_recruit_action(const std::string &unit_name, const map_location &where=map_location::null_location(), const map_location &from=map_location::null_location())=0
virtual team & current_team_w()=0
virtual stopunit_result_ptr execute_stopunit_action(const map_location &unit_location, bool remove_movement=true, bool remove_attacks=false)=0
recursion_counter(int counter)
Definition: contexts.hpp:54
static const int MAX_COUNTER_VALUE
Definition: contexts.hpp:71
bool is_ok() const
Check if more recursion is allowed.
Definition: contexts.hpp:76
int get_count() const
Get the current value of the recursion counter.
Definition: contexts.hpp:65
virtual ~side_context_impl()
Definition: contexts.hpp:952
virtual side_number get_side() const override
Get the side number.
Definition: contexts.hpp:954
virtual config to_side_context_config() const override
serialize this context to config
Definition: contexts.cpp:259
virtual void set_side(side_number side) override
Set the side number.
Definition: contexts.hpp:959
side_context_impl(side_number side, const config &)
Definition: contexts.hpp:947
virtual int get_recursion_count() const override
Get the value of the recursion counter.
Definition: contexts.cpp:72
virtual side_context & get_side_context() override
unwrap
Definition: contexts.hpp:964
recursion_counter recursion_counter_
Definition: contexts.hpp:975
virtual int get_recursion_count() const override
Get the value of the recursion counter.
Definition: contexts.hpp:408
virtual void set_side(side_number side) override
Set the side number.
Definition: contexts.hpp:398
virtual side_context & get_side_context() override
unwrap
Definition: contexts.hpp:403
virtual config to_side_context_config() const override
serialize this context to config
Definition: contexts.hpp:413
void init_side_context_proxy(side_context &target)
Definition: contexts.hpp:388
virtual ~side_context_proxy()
Definition: contexts.hpp:386
side_context * target_
Definition: contexts.hpp:419
virtual side_number get_side() const override
Get the side number.
Definition: contexts.hpp:393
virtual ~side_context()
empty destructor
Definition: contexts.hpp:135
virtual void set_side(side_number side)=0
Set the side number.
virtual config to_side_context_config() const =0
serialize this context to config
virtual int get_recursion_count() const =0
Get the value of the recursion counter.
virtual side_context & get_side_context()=0
unwrap
virtual side_number get_side() const =0
Get the side number.
side_context()
empty constructor
Definition: contexts.hpp:140
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:158
Encapsulates the map of the game.
Definition: map.hpp:172
This class stores all the data for a single 'side' (in game nomenclature).
Definition: team.hpp:74
Container associating units to locations.
Definition: map.hpp:98
A single unit type that the player may recruit.
Definition: types.hpp:43
This class represents a single unit of a specific type.
Definition: unit.hpp:132
Definitions for the interface to Wesnoth Markup Language (WML).
const config * cfg
Game information for the AI.
A small explanation about what's going on here: Each action has access to two game_info objects First...
Definition: actions.cpp:59
std::shared_ptr< engine > engine_ptr
Definition: game_info.hpp:99
std::vector< attack_analysis > attacks_vector
Definition: game_info.hpp:51
std::shared_ptr< recruit_result > recruit_result_ptr
Definition: game_info.hpp:84
std::shared_ptr< typesafe_aspect< T > > typesafe_aspect_ptr
Definition: game_info.hpp:58
std::map< std::string, known_aspect_ptr > known_aspect_map
Definition: game_info.hpp:105
std::shared_ptr< attack_result > attack_result_ptr
Definition: game_info.hpp:82
std::shared_ptr< stopunit_result > stopunit_result_ptr
Definition: game_info.hpp:87
std::multimap< map_location, map_location > move_map
The standard way in which a map of possible moves is recorded.
Definition: game_info.hpp:43
std::shared_ptr< synced_command_result > synced_command_result_ptr
Definition: game_info.hpp:88
std::map< map_location, pathfind::paths > moves_map
The standard way in which a map of possible movement routes to location is recorded.
Definition: game_info.hpp:46
ai_context * ai_context_ptr
Definition: contexts.hpp:49
int side_number
Definition: game_info.hpp:40
std::shared_ptr< move_result > move_result_ptr
Definition: game_info.hpp:85
std::shared_ptr< recall_result > recall_result_ptr
Definition: game_info.hpp:83
std::map< std::string, aspect_ptr > aspect_map
Definition: game_info.hpp:104
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
Definition: debugger.cpp:109
@ enemy
Belongs to a non-friendly side; normally visualised by not displaying an orb.
static config unit_name(const unit *u)
Definition: reports.cpp:163
map_location loc
Definition: contexts.hpp:96
Structure describing the statistics of a unit involved in the battle.
Definition: attack.hpp:51
Error used for any general game error, e.g.
Definition: game_errors.hpp:47
Encapsulates the map of the game.
Definition: location.hpp:45
static const map_location & null_location()
Definition: location.hpp:102
Object which contains all the possible locations a unit can move to, with associated best routes to t...
Definition: pathfind.hpp:73
Object which defines a time of day with associated bonuses, image, sounds etc.
Definition: time_of_day.hpp:57