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