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