The Battle for Wesnoth  1.17.0-dev
contexts.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2021
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 const aspect_map& get_aspects() const = 0;
204 
205  virtual aspect_map& get_aspects() = 0;
206 
207  virtual void add_facet(const std::string &id, const config &cfg) const = 0;
208 
209  virtual void add_aspects(std::vector< aspect_ptr > &aspects ) = 0;
210 
211  virtual const attacks_vector& get_attacks() const = 0;
212 
213  virtual const wfl::variant& get_attacks_as_variant() const = 0;
214 
215  virtual const terrain_filter& get_avoid() const = 0;
216 
217  virtual double get_caution() const = 0;
218 
219  virtual const move_map& get_dstsrc() const = 0;
220 
221  virtual const move_map& get_enemy_dstsrc() const = 0;
222 
223  virtual const moves_map& get_enemy_possible_moves() const = 0;
224 
225  virtual const move_map& get_enemy_srcdst() const = 0;
226 
227  /**
228  * get engine by cfg, creating it if it is not created yet but known
229  */
230  virtual engine_ptr get_engine_by_cfg(const config& cfg) = 0;
231 
232  virtual const std::vector<engine_ptr>& get_engines() const = 0;
233 
234  virtual std::vector<engine_ptr>& get_engines() = 0;
235 
236  virtual std::string get_grouping() const = 0;
237 
238  virtual const std::vector<goal_ptr>& get_goals() const = 0;
239 
240  virtual std::vector<goal_ptr>& get_goals() = 0;
241 
242  virtual double get_leader_aggression() const = 0;
243 
244  virtual config get_leader_goal() const = 0;
245 
246  virtual utils::variant<bool, std::vector<std::string>> get_leader_ignores_keep() const = 0;
247 
248  virtual double get_leader_value() const = 0;
249 
250  virtual utils::variant<bool, std::vector<std::string>> get_passive_leader() const = 0;
251 
252  virtual utils::variant<bool, std::vector<std::string>> get_passive_leader_shares_keep() const = 0;
253 
254  virtual const moves_map& get_possible_moves() const = 0;
255 
256  virtual double get_recruitment_diversity() const = 0;
257 
258  virtual const config get_recruitment_instructions() const = 0;
259 
260  virtual const std::vector<std::string> get_recruitment_more() const = 0;
261 
262  virtual const std::vector<std::string> get_recruitment_pattern() const = 0;
263 
264  virtual int get_recruitment_randomness() const = 0;
265 
266  virtual const config get_recruitment_save_gold() const = 0;
267 
268  virtual double get_retreat_enemy_weight() const = 0;
269 
270  virtual double get_retreat_factor() const = 0;
271 
272  virtual double get_scout_village_targeting() const = 0;
273 
274  virtual bool get_simple_targeting() const = 0;
275 
276  virtual const move_map& get_srcdst() const = 0;
277 
278  virtual bool get_support_villages() const = 0;
279 
280  virtual double get_village_value() const = 0;
281 
282  virtual int get_villages_per_scout() const = 0;
283 
284  virtual bool is_active(const std::string &time_of_day, const std::string &turns) const = 0;
285 
286  virtual bool is_keep_ignoring_leader(const std::string &id) const = 0;
287 
288  virtual bool is_passive_leader(const std::string &id) const = 0;
289 
290  virtual bool is_passive_keep_sharing_leader(const std::string &id) const = 0;
291 
292  virtual bool is_dst_src_valid_lua() const = 0;
293 
294  virtual bool is_dst_src_enemy_valid_lua() const = 0;
295 
296  virtual bool is_src_dst_valid_lua() const = 0;
297 
298  virtual bool is_src_dst_enemy_valid_lua() const = 0;
299 
300  virtual void invalidate_defensive_position_cache() const = 0;
301 
302  virtual void invalidate_move_maps() const = 0;
303 
304  virtual void invalidate_keeps_cache() const= 0;
305 
306  virtual const std::set<map_location>& keeps() const= 0;
307 
308  virtual bool leader_can_reach_keep() const = 0;
309 
310  virtual const map_location& nearest_keep(const map_location& loc) const = 0;
311 
312  /**
313  * Function which finds how much 'power' a side can attack a certain location with.
314  * This is basically the maximum hp of damage that can be inflicted upon a unit on loc
315  * by full-health units, multiplied by the defense these units will have.
316  * (if 'use_terrain' is false, then it will be multiplied by 0.5)
317  *
318  * Example: 'loc' can be reached by two units, one of whom has a 10-3 attack
319  * and has 48/48 hp, and can defend at 40% on the adjacent grassland.
320  * The other has a 8-2 attack, and has 30/40 hp, and can defend at 60% on the adjacent mountain.
321  * The rating will be 10*3*1.0*0.4 + 8*2*0.75*0.6 = 19.2
322  */
323  virtual double power_projection(const map_location& loc, const move_map& dstsrc) const = 0;
324 
325  virtual void raise_user_interact() const = 0;
326 
327  virtual void recalculate_move_maps() const = 0;
328 
329  virtual void recalculate_move_maps_enemy() const = 0;
330 
331  virtual void set_src_dst_valid_lua() = 0;
332  virtual void set_src_dst_enemy_valid_lua() = 0;
333  virtual void set_dst_src_valid_lua() = 0;
334  virtual void set_dst_src_enemy_valid_lua() = 0;
335 
336  /** 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 */
337  virtual const map_location& suitable_keep( const map_location& leader_location, const pathfind::paths& leader_paths ) const = 0;
338 
339  /**
340  * serialize to config
341  */
342  virtual config to_readonly_context_config() const = 0;
343 
344  typedef std::map<std::pair<map_location,const unit_type *>,
345  std::pair<battle_context_unit_stats,battle_context_unit_stats>>
347  virtual unit_stats_cache_t & unit_stats_cache() const = 0;
348 
349 };
350 
351 class readwrite_context;
352 class readwrite_context : public virtual readonly_context {
353 public:
355 
356  virtual ~readwrite_context(){}
357 
358  virtual readwrite_context& get_readwrite_context() = 0;
359 
360  virtual attack_result_ptr execute_attack_action(const map_location& attacker_loc, const map_location& defender_loc, int attacker_weapon) = 0;
361 
362  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;
363 
364  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;
365 
366  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;
367 
368  virtual stopunit_result_ptr execute_stopunit_action(const map_location& unit_location, bool remove_movement = true, bool remove_attacks = false) = 0;
369 
370  virtual synced_command_result_ptr execute_synced_command_action(const std::string& lua_code, const map_location& location = map_location::null_location()) = 0;
371 
372  virtual team& current_team_w() = 0;
373 
374  virtual void raise_gamestate_changed() const = 0;
375 
376  virtual game_info& get_info_w() = 0;
377 
378  /**
379  * serialize this context to config
380  */
381  virtual config to_readwrite_context_config() const = 0;
382 
383 };
384 
385 //proxies
386 
387 class side_context_proxy : public virtual side_context {
388 public:
390  : target_(nullptr)
391  {
392  }
393 
395 
397  {
398  target_= &target.get_side_context();
399  }
400 
401  virtual side_number get_side() const override
402  {
403  return target_->get_side();
404  }
405 
406  virtual void set_side(side_number side) override
407  {
408  return target_->set_side(side);
409  }
410 
411  virtual side_context& get_side_context() override
412  {
413  return target_->get_side_context();
414  }
415 
416  virtual int get_recursion_count() const override
417  {
418  return target_->get_recursion_count();
419  }
420 
421  virtual config to_side_context_config() const override
422  {
423  return target_->to_side_context_config();
424  }
425 
426 private:
428 };
429 
430 class readonly_context_proxy : public virtual readonly_context, public virtual side_context_proxy {
431 public:
433  : target_(nullptr)
434  {
435  }
436 
438 
440  {
441  init_side_context_proxy(target);
442  target_ = &target.get_readonly_context();
443  }
444 
446  {
447  return target_->get_readonly_context();
448  }
449 
450  virtual void on_readonly_context_create() override
451  {
452  return target_->on_readonly_context_create();
453  }
454 
455  virtual const team& current_team() const override
456  {
457  return target_->current_team();
458  }
459 
460  virtual void diagnostic(const std::string& msg) override
461  {
462  target_->diagnostic(msg);
463  }
464 
465  virtual void log_message(const std::string& msg) override
466  {
467  target_->log_message(msg);
468  }
469 
470  virtual attack_result_ptr check_attack_action(const map_location &attacker_loc, const map_location &defender_loc, int attacker_weapon) override
471  {
472  return target_->check_attack_action(attacker_loc, defender_loc, attacker_weapon);
473  }
474 
475  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
476  {
477  return target_->check_move_action(from, to, remove_movement, unreach_is_ok);
478  }
479 
480  virtual recall_result_ptr check_recall_action(const std::string &id, const map_location &where = map_location::null_location(),
481  const map_location &from = map_location::null_location()) override
482  {
483  return target_->check_recall_action(id, where, from);
484  }
485 
487  const map_location &from = map_location::null_location()) override
488  {
489  return target_->check_recruit_action(unit_name, where, from);
490  }
491 
492  virtual stopunit_result_ptr check_stopunit_action(const map_location &unit_location, bool remove_movement = true, bool remove_attacks = false) override
493  {
494  return target_->check_stopunit_action(unit_location, remove_movement, remove_attacks);
495  }
496 
497  virtual synced_command_result_ptr check_synced_command_action(const std::string& lua_code, const map_location& location = map_location::null_location()) override
498  {
499  return target_->check_synced_command_action(lua_code, location);
500  }
501 
502  virtual void calculate_possible_moves(std::map<map_location,pathfind::paths>& possible_moves,
503  move_map& srcdst, move_map& dstsrc, bool enemy,
504  bool assume_full_movement=false,
505  const terrain_filter* remove_destinations=nullptr) const override
506  {
507  target_->calculate_possible_moves(possible_moves, srcdst, dstsrc, enemy, assume_full_movement, remove_destinations);
508  }
509 
510  virtual void calculate_moves(const unit_map& units,
511  std::map<map_location,pathfind::paths>& possible_moves, move_map& srcdst,
512  move_map& dstsrc, bool enemy, bool assume_full_movement=false,
513  const terrain_filter* remove_destinations=nullptr,
514  bool see_all=false) const override
515  {
516  target_->calculate_moves(units, possible_moves, srcdst, dstsrc, enemy, assume_full_movement, remove_destinations, see_all);
517  }
518 
519  virtual const game_info& get_info() const override
520  {
521  return target_->get_info();
522  }
523 
524  virtual void raise_user_interact() const override
525  {
526  target_->raise_user_interact();
527  }
528 
529  virtual int get_recursion_count() const override
530  {
531  return target_->get_recursion_count();
532  }
533 
534  //@note: following part is in alphabetic order
536  const move_map& dstsrc, const move_map& srcdst, const move_map& enemy_dstsrc) const override
537  {
538  return target_->best_defensive_position(unit,dstsrc,srcdst,enemy_dstsrc);
539  }
540 
541  virtual std::map<map_location,defensive_position>& defensive_position_cache() const override
542  {
543  return target_->defensive_position_cache();
544  }
545 
546  virtual const unit_advancements_aspect& get_advancements() const override
547  {
548  return target_->get_advancements();
549  }
550 
551  virtual double get_aggression() const override
552  {
553  return target_->get_aggression();
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  {
583  return target_->get_attacks_as_variant();
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  {
608  return target_->get_enemy_possible_moves();
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  {
658  return target_->get_leader_ignores_keep();
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  {
673  return target_->get_passive_leader_shares_keep();
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  {
688  return target_->get_recruitment_diversity();
689  }
690 
691  virtual const config get_recruitment_instructions() const override
692  {
693  return target_->get_recruitment_instructions();
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  {
703  return target_->get_recruitment_pattern();
704  }
705 
706  virtual int get_recruitment_randomness() const override
707  {
708  return target_->get_recruitment_randomness();
709  }
710 
711  virtual const config get_recruitment_save_gold() const override
712  {
713  return target_->get_recruitment_save_gold();
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  {
723  return target_->get_retreat_enemy_weight();
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  {
733  return target_->get_scout_village_targeting();
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  {
753  return target_->get_villages_per_scout();
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  {
773  return target_->is_passive_keep_sharing_leader(id);
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  {
783  return target_->is_dst_src_enemy_valid_lua();
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  {
793  return target_->is_src_dst_enemy_valid_lua();
794  }
795 
796  virtual void invalidate_defensive_position_cache() const override
797  {
798  return target_->invalidate_defensive_position_cache();
799  }
800 
801  virtual void invalidate_move_maps() const override
802  {
803  target_->invalidate_move_maps();
804  }
805 
806  virtual void invalidate_keeps_cache() const override
807  {
808  return target_->invalidate_keeps_cache();
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  {
828  target_->recalculate_move_maps();
829  }
830 
831  virtual void recalculate_move_maps_enemy() const override
832  {
833  target_->recalculate_move_maps_enemy();
834  }
835 
836  virtual void set_dst_src_valid_lua() override
837  {
838  target_->set_dst_src_valid_lua();
839  }
840 
841  virtual void set_dst_src_enemy_valid_lua() override
842  {
843  target_->set_dst_src_enemy_valid_lua();
844  }
845 
846  virtual void set_src_dst_valid_lua() override
847  {
848  target_->set_src_dst_valid_lua();
849  }
850 
851  virtual void set_src_dst_enemy_valid_lua() override
852  {
853  target_->set_src_dst_enemy_valid_lua();
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  {
863  return target_->to_readonly_context_config();
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  {
884  init_readonly_context_proxy(target);
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 
908  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
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  {
930  target_->raise_gamestate_changed();
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  {
945  return target_->to_readwrite_context_config();
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  */
1057  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;
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
1131  const defensive_position& best_defensive_position(const map_location& unit,
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 const aspect_map& get_aspects() const override;
1141 
1142  virtual aspect_map& get_aspects() override;
1143 
1144  virtual const attacks_vector& get_attacks() const override;
1145 
1146  virtual const wfl::variant& get_attacks_as_variant() const override;
1147 
1148  virtual const terrain_filter& get_avoid() const override;
1149 
1150  virtual double get_caution() const override;
1151 
1152  virtual const move_map& get_dstsrc() const override;
1153 
1154  virtual const move_map& get_enemy_dstsrc() const override;
1155 
1156  virtual const moves_map& get_enemy_possible_moves() const override;
1157 
1158  virtual const move_map& get_enemy_srcdst() const override;
1159 
1160  virtual engine_ptr get_engine_by_cfg(const config& cfg) override;
1161 
1162  virtual const std::vector<engine_ptr>& get_engines() const override;
1163 
1164  virtual std::vector<engine_ptr>& get_engines() override;
1165 
1166  virtual std::string get_grouping() const override;
1167 
1168  virtual const std::vector<goal_ptr>& get_goals() const override;
1169 
1170  virtual std::vector<goal_ptr>& get_goals() override;
1171 
1172  virtual double get_leader_aggression() const override;
1173 
1174  virtual config get_leader_goal() const override;
1175 
1176  virtual utils::variant<bool, std::vector<std::string>> get_leader_ignores_keep() const override;
1177 
1178  virtual double get_leader_value() const override;
1179 
1180  virtual utils::variant<bool, std::vector<std::string>> get_passive_leader() const override;
1181 
1182  virtual utils::variant<bool, std::vector<std::string>> get_passive_leader_shares_keep() const override;
1183 
1184  virtual const moves_map& get_possible_moves() const override;
1185 
1186  virtual double get_recruitment_diversity() const override;
1187 
1188  virtual const config get_recruitment_instructions() const override;
1189 
1190  virtual const std::vector<std::string> get_recruitment_more() const override;
1191 
1192  virtual const std::vector<std::string> get_recruitment_pattern() const override;
1193 
1194  virtual int get_recruitment_randomness() const override;
1195 
1196  virtual const config get_recruitment_save_gold() const override;
1197 
1198  virtual double get_retreat_enemy_weight() const override;
1199 
1200  virtual double get_retreat_factor() const override;
1201 
1202  virtual double get_scout_village_targeting() const override;
1203 
1204  virtual bool get_simple_targeting() const override;
1205 
1206  virtual const move_map& get_srcdst() const override;
1207 
1208  virtual bool get_support_villages() const override;
1209 
1210  virtual double get_village_value() const override;
1211 
1212  virtual int get_villages_per_scout() const override;
1213 
1214  virtual bool is_active(const std::string &time_of_day, const std::string &turns) const override;
1215 
1216  virtual bool is_keep_ignoring_leader(const std::string &id) const override;
1217 
1218  virtual bool is_passive_leader(const std::string &id) const override;
1219 
1220  virtual bool is_passive_keep_sharing_leader(const std::string &id) const override;
1221 
1222  virtual bool is_dst_src_valid_lua() const override;
1223 
1224  virtual bool is_dst_src_enemy_valid_lua() const override;
1225 
1226  virtual bool is_src_dst_valid_lua() const override;
1227 
1228  virtual bool is_src_dst_enemy_valid_lua() const override;
1229 
1230  virtual void invalidate_defensive_position_cache() const override;
1231 
1232  virtual void invalidate_move_maps() const override;
1233 
1234  virtual void invalidate_keeps_cache() const override;
1235 
1236  virtual const std::set<map_location>& keeps() const override;
1237 
1238  virtual bool leader_can_reach_keep() const override;
1239 
1240  virtual const map_location& nearest_keep(const map_location& loc) const override;
1241 
1242  virtual double power_projection(const map_location& loc, const move_map& dstsrc) const override;
1243 
1244  virtual void recalculate_move_maps() const override;
1245 
1246  virtual void recalculate_move_maps_enemy() const override;
1247 
1248  virtual void add_aspects(std::vector< aspect_ptr > &aspects) override;
1249 
1250  virtual void add_facet(const std::string &id, const config &cfg) const override;
1251 
1252  void on_create();
1253 
1254  virtual void set_dst_src_valid_lua() override;
1255 
1256  virtual void set_dst_src_enemy_valid_lua() override;
1257 
1258  virtual void set_src_dst_valid_lua() override;
1259 
1260  virtual void set_src_dst_enemy_valid_lua() override;
1261 
1262  virtual const map_location& suitable_keep( const map_location& leader_location, const pathfind::paths& leader_paths ) const override;
1263 
1264  virtual config to_readonly_context_config() const override;
1265 
1266  virtual unit_stats_cache_t & unit_stats_cache() const override;
1267 
1268 private:
1269  template<typename T>
1270  void add_known_aspect(const std::string &name, typesafe_aspect_ptr<T>& where);
1271 
1272  bool applies_to_leader(const utils::variant<bool, std::vector<std::string>> &aspect_value, const std::string &id) const;
1273 
1274  const config cfg_;
1275 
1276  /**
1277  * AI Support Engines
1278  */
1279  std::vector< engine_ptr > engines_;
1280 
1282 
1289  mutable std::map<map_location,defensive_position> defensive_position_cache_;
1295  std::vector< goal_ptr > goals_;
1302  mutable bool move_maps_valid_;
1303  mutable bool dst_src_valid_lua_;
1305  mutable bool src_dst_valid_lua_;
1326 };
1327 
1329 public:
1330  /**
1331  * Unwrap - this class is not a proxy, so return *this
1332  */
1334  {
1335  return *this;
1336  }
1337 
1338  /**
1339  * Ask the game to attack an enemy defender using our unit attacker from attackers current location,
1340  * @param attacker_loc location of attacker
1341  * @param defender_loc location of defender
1342  * @param attacker_weapon weapon of attacker
1343  * @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
1344  */
1345  virtual attack_result_ptr execute_attack_action(const map_location& attacker_loc, const map_location& defender_loc, int attacker_weapon) override;
1346 
1347  /**
1348  * Ask the game to move our unit from location 'from' to location 'to', optionally - doing a partial move
1349  * @param from location of our unit
1350  * @param to where to move
1351  * @param remove_movement set unit movement to 0 in case of successful move
1352  * @param unreach_is_ok whether it's okay for a destination to be unreachable
1353  * @retval possible results: ok, something wrong, move is interrupted, or move is impossible
1354  */
1355  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;
1356 
1357  /**
1358  * Ask the game to recall a unit for us on specified location
1359  * @param id the id of the unit to be recalled.
1360  * @param where location where the unit is to be recalled.
1361  * @param from location of the recaller.
1362  * @retval possible results: ok, something wrong, leader not on keep, no free space on keep, or not enough gold
1363  */
1364  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;
1365 
1366  /**
1367  * Ask the game to recruit a unit for us on specified location
1368  * @param unit_name the name of the unit to be recruited.
1369  * @param where location where the unit is to be recruited.
1370  * @param from location of the recruiter.
1371  * @retval possible results: ok, something wrong, leader not on keep, no free space on keep, or not enough gold
1372  */
1373  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;
1374 
1375  /**
1376  * Ask the game to remove unit movements and/or attack
1377  * @param unit_location the location of our unit
1378  * @param remove_movement set remaining movements to 0
1379  * @param remove_attacks set remaining attacks to 0
1380  * @retval possible results: ok, something wrong, nothing to do
1381  */
1382  virtual stopunit_result_ptr execute_stopunit_action(const map_location& unit_location, bool remove_movement = true, bool remove_attacks = false) override;
1383 
1384  /**
1385  * Ask the game to run Lua code
1386  * @param lua_code the code to be run
1387  * @param location location to be passed to the code as x1/y1
1388  * @retval possible results: ok, something wrong, nothing to do
1389  */
1390  virtual synced_command_result_ptr execute_synced_command_action(const std::string& lua_code, const map_location& location = map_location::null_location()) override;
1391 
1392  /** Return a reference to the 'team' object for the AI. */
1393  virtual team& current_team_w() override;
1394 
1395  /** Notifies all interested observers of the event respectively. */
1396  void raise_gamestate_changed() const override;
1397 
1398  /**
1399  * Constructor.
1400  */
1402  : recursion_counter_(context.get_recursion_count())
1403  {
1404  init_readonly_context_proxy(context);
1405  }
1406 
1408  {
1409  }
1410 
1411  /**
1412  * Functions to retrieve the 'info' object.
1413  * Used by derived classes to discover all necessary game information.
1414  */
1415  virtual game_info& get_info_w() override;
1416 
1417  virtual int get_recursion_count() const override;
1418 
1419  virtual config to_readwrite_context_config() const override;
1420 
1421 private:
1423 };
1424 
1425 } //end of namespace ai
virtual void invalidate_move_maps() const override
Definition: contexts.hpp:801
typesafe_aspect_ptr< terrain_filter > avoid_
Definition: contexts.hpp:1287
virtual void set_src_dst_valid_lua() override
Definition: contexts.hpp:846
virtual side_number get_side() const override
Get the side number.
Definition: contexts.hpp:962
side_context_impl(side_number side, const config &)
Definition: contexts.hpp:955
virtual void raise_user_interact() const override
Definition: contexts.hpp:524
virtual std::string get_grouping() const override
Definition: contexts.hpp:631
virtual attack_result_ptr check_attack_action(const map_location &attacker_loc, const map_location &defender_loc, int attacker_weapon) override
Definition: contexts.hpp:470
static ai::readonly_context & get_readonly_context(lua_State *L)
Definition: core.cpp:127
virtual const move_map & get_enemy_srcdst() const override
Definition: contexts.hpp:611
virtual int get_villages_per_scout() const override
Definition: contexts.hpp:751
virtual int get_recursion_count() const override
Get the value of the recursion counter.
Definition: contexts.hpp:938
virtual side_context & get_side_context() override
unwrap
Definition: contexts.hpp:972
typesafe_aspect_ptr< bool > simple_targeting_
Definition: contexts.hpp:1320
virtual void log_message(const std::string &msg) override
Definition: contexts.hpp:465
virtual const attacks_vector & get_attacks() const override
Definition: contexts.hpp:576
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:821
This class represents a single unit of a specific type.
Definition: unit.hpp:121
virtual bool is_active(const std::string &time_of_day, const std::string &turns) const override
Definition: contexts.hpp:756
virtual ~readwrite_context()
Definition: contexts.hpp:356
typesafe_aspect_ptr< config > leader_goal_
Definition: contexts.hpp:1298
virtual const std::set< map_location > & keeps() const override
Definition: contexts.hpp:811
virtual const config get_recruitment_save_gold() const override
Definition: contexts.hpp:711
virtual stopunit_result_ptr check_stopunit_action(const map_location &unit_location, bool remove_movement=true, bool remove_attacks=false) override
Definition: contexts.hpp:492
virtual game_info & get_info_w() override
Definition: contexts.hpp:933
virtual config to_readwrite_context_config() const override
serialize this context to config
Definition: contexts.hpp:943
typesafe_aspect_ptr< double > caution_
Definition: contexts.hpp:1288
virtual double get_leader_value() const override
Definition: contexts.hpp:661
virtual int get_recruitment_randomness() const override
Definition: contexts.hpp:706
virtual void recalculate_move_maps_enemy() const override
Definition: contexts.hpp:831
virtual double get_village_value() const override
Definition: contexts.hpp:746
unit_stats_cache_t unit_stats_cache_
Definition: contexts.hpp:1323
virtual const move_map & get_srcdst() const override
Definition: contexts.hpp:716
std::shared_ptr< move_result > move_result_ptr
Definition: game_info.hpp:85
void clear(const std::string &key)
Definition: general.cpp:186
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
readwrite_context_impl(readonly_context &context, const config &)
Constructor.
Definition: contexts.hpp:1401
typesafe_aspect_ptr< double > retreat_factor_
Definition: contexts.hpp:1318
virtual const game_info & get_info() const override
Definition: contexts.hpp:519
std::vector< goal_ptr > goals_
Definition: contexts.hpp:1295
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:561
virtual ~side_context_proxy()
Definition: contexts.hpp:394
std::shared_ptr< recruit_result > recruit_result_ptr
Definition: game_info.hpp:84
void init_side_context_proxy(side_context &target)
Definition: contexts.hpp:396
virtual team & current_team_w() override
Definition: contexts.hpp:923
virtual double get_retreat_factor() const override
Definition: contexts.hpp:726
virtual void raise_gamestate_changed() const override
Definition: contexts.hpp:928
virtual bool leader_can_reach_keep() const override
Definition: contexts.hpp:816
readwrite_context * target_
Definition: contexts.hpp:949
virtual readonly_context & get_readonly_context() override
Unwrap - this class is not a proxy, so return *this :w
Definition: contexts.hpp:1003
static config unit_name(const unit *u)
Definition: reports.cpp:160
bool is_ok() const
Check if more recursion is allowed.
Definition: contexts.hpp:81
side_context * target_
Definition: contexts.hpp:427
virtual void add_facet(const std::string &id, const config &cfg) const override
Definition: contexts.hpp:571
std::shared_ptr< attack_result > attack_result_ptr
Definition: game_info.hpp:82
typesafe_aspect_ptr< double > leader_value_
Definition: contexts.hpp:1300
Definitions for the interface to Wesnoth Markup Language (WML).
virtual void on_readonly_context_create() override
Definition: contexts.hpp:450
std::map< map_location, defensive_position > defensive_position_cache_
Definition: contexts.hpp:1289
virtual readwrite_context & get_readwrite_context() override
Definition: contexts.hpp:888
A single unit type that the player may recruit.
Definition: types.hpp:45
typesafe_aspect_ptr< int > villages_per_scout_
Definition: contexts.hpp:1325
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 const std::vector< std::string > get_recruitment_more() const override
Definition: contexts.hpp:696
virtual config to_side_context_config() const override
serialize this context to config
Definition: contexts.hpp:421
virtual unit_stats_cache_t & unit_stats_cache() const override
Definition: contexts.hpp:866
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:1317
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:546
virtual ~readonly_context()
Definition: contexts.hpp:169
static bool is_active(const widget *wgt)
Definition: window.cpp:1336
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:626
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:437
virtual utils::variant< bool, std::vector< std::string > > get_passive_leader() const override
Definition: contexts.hpp:666
virtual const moves_map & get_enemy_possible_moves() const override
Definition: contexts.hpp:606
This class stores all the data for a single &#39;side&#39; (in game nomenclature).
Definition: team.hpp:72
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:851
virtual const aspect_map & get_aspects() const override
Definition: contexts.hpp:556
virtual readwrite_context & get_readwrite_context()=0
virtual void set_side(side_number side) override
Set the side number.
Definition: contexts.hpp:967
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:480
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:535
virtual double get_leader_aggression() const override
Definition: contexts.hpp:646
virtual const std::vector< goal_ptr > & get_goals() const override
Definition: contexts.hpp:636
virtual void recalculate_move_maps() const override
Definition: contexts.hpp:826
virtual utils::variant< bool, std::vector< std::string > > get_leader_ignores_keep() const override
Definition: contexts.hpp:656
virtual double get_recruitment_diversity() const override
Definition: contexts.hpp:686
typesafe_aspect_ptr< std::vector< std::string > > recruitment_pattern_
Definition: contexts.hpp:1313
Encapsulates the map of the game.
Definition: map.hpp:171
readonly_context * target_
Definition: contexts.hpp:872
virtual bool is_passive_leader(const std::string &id) const override
Definition: contexts.hpp:766
virtual const move_map & get_enemy_dstsrc() const override
Definition: contexts.hpp:601
virtual std::vector< goal_ptr > & get_goals() override
Definition: contexts.hpp:641
virtual const std::vector< std::string > get_recruitment_pattern() const override
Definition: contexts.hpp:701
typesafe_aspect_ptr< double > scout_village_targeting_
Definition: contexts.hpp:1319
Structure describing the statistics of a unit involved in the battle.
Definition: attack.hpp:51
typesafe_aspect_ptr< config > recruitment_instructions_
Definition: contexts.hpp:1311
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:486
std::set< map_location > keeps_
Definition: contexts.hpp:118
virtual side_context & get_side_context()=0
unwrap
recursion_counter recursion_counter_
Definition: contexts.hpp:983
virtual double get_retreat_enemy_weight() const override
Definition: contexts.hpp:721
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:893
virtual void add_aspects(std::vector< aspect_ptr > &aspects) override
Definition: contexts.hpp:566
virtual side_context & get_side_context() override
unwrap
Definition: contexts.hpp:411
virtual void set_side(side_number side) override
Set the side number.
Definition: contexts.hpp:406
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
std::vector< engine_ptr > engines_
AI Support Engines.
Definition: contexts.hpp:1279
virtual const team & current_team() const override
Definition: contexts.hpp:455
typesafe_aspect_ptr< bool > support_villages_
Definition: contexts.hpp:1322
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:616
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:918
recursion_counter recursion_counter_
Definition: contexts.hpp:1316
typesafe_aspect_ptr< double > leader_aggression_
Definition: contexts.hpp:1297
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 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:681
virtual bool is_src_dst_enemy_valid_lua() const override
Definition: contexts.hpp:791
typesafe_aspect_ptr< utils::variant< bool, std::vector< std::string > > > passive_leader_
Definition: contexts.hpp:1307
virtual double get_scout_village_targeting() const override
Definition: contexts.hpp:731
virtual side_number get_side() const override
Get the side number.
Definition: contexts.hpp:401
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:475
typesafe_aspect_ptr< attacks_vector > attacks_
Definition: contexts.hpp:1286
virtual void set_dst_src_valid_lua() override
Definition: contexts.hpp:836
virtual bool is_passive_keep_sharing_leader(const std::string &id) const override
Definition: contexts.hpp:771
typesafe_aspect_ptr< unit_advancements_aspect > advancements_
Definition: contexts.hpp:1283
virtual readwrite_context & get_readwrite_context() override
Unwrap - this class is not a proxy, so return *this.
Definition: contexts.hpp:1333
typesafe_aspect_ptr< std::vector< std::string > > recruitment_more_
Definition: contexts.hpp:1312
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:346
virtual config to_readonly_context_config() const override
serialize to config
Definition: contexts.hpp:861
typesafe_aspect_ptr< std::string > grouping_
Definition: contexts.hpp:1294
virtual ~side_context_impl()
Definition: contexts.hpp:960
virtual const move_map & get_dstsrc() const override
Definition: contexts.hpp:596
int turns()
Definition: game.cpp:559
virtual bool is_dst_src_enemy_valid_lua() const override
Definition: contexts.hpp:781
virtual double get_aggression() const override
Definition: contexts.hpp:551
virtual const wfl::variant & get_attacks_as_variant() const override
Definition: contexts.hpp:581
std::map< std::string, aspect_ptr > aspect_map
Definition: game_info.hpp:104
recursion_counter recursion_counter_
Definition: contexts.hpp:1422
virtual readonly_context & get_readonly_context() override
Definition: contexts.hpp:445
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:502
virtual int get_recursion_count() const override
Get the value of the recursion counter.
Definition: contexts.hpp:416
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:497
typesafe_aspect_ptr< utils::variant< bool, std::vector< std::string > > > leader_ignores_keep_
Definition: contexts.hpp:1299
virtual readonly_context & get_readonly_context()=0
virtual int get_recursion_count() const override
Get the value of the recursion counter.
Definition: contexts.hpp:529
virtual std::map< map_location, defensive_position > & defensive_position_cache() const override
Definition: contexts.hpp:541
known_aspect_map known_aspects_
Definition: contexts.hpp:1281
virtual void set_dst_src_enemy_valid_lua() override
Definition: contexts.hpp:841
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:786
virtual const config get_recruitment_instructions() const override
Definition: contexts.hpp:691
Container associating units to locations.
Definition: map.hpp:98
virtual bool is_keep_ignoring_leader(const std::string &id) const override
Definition: contexts.hpp:761
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:1314
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:510
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:882
typesafe_aspect_ptr< double > recruitment_diversity_
Definition: contexts.hpp:1310
virtual bool get_support_villages() const override
Definition: contexts.hpp:741
virtual void invalidate_keeps_cache() const override
Definition: contexts.hpp:806
int side_number
Definition: game_info.hpp:40
virtual const terrain_filter & get_avoid() const override
Definition: contexts.hpp:586
virtual void invalidate_defensive_position_cache() const override
Definition: contexts.hpp:796
typesafe_aspect_ptr< double > aggression_
Definition: contexts.hpp:1284
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:61
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
typesafe_aspect_ptr< utils::variant< bool, std::vector< std::string > > > passive_leader_shares_keep_
Definition: contexts.hpp:1308
virtual bool is_dst_src_valid_lua() const override
Definition: contexts.hpp:776
virtual double get_caution() const override
Definition: contexts.hpp:591
virtual utils::variant< bool, std::vector< std::string > > get_passive_leader_shares_keep() const override
Definition: contexts.hpp:671
virtual const std::vector< engine_ptr > & get_engines() const override
Definition: contexts.hpp:621
typesafe_aspect_ptr< config > recruitment_save_gold_
Definition: contexts.hpp:1315
virtual const moves_map & get_possible_moves() const override
Definition: contexts.hpp:676
typesafe_aspect_ptr< double > village_value_
Definition: contexts.hpp:1324
virtual bool get_simple_targeting() const override
Definition: contexts.hpp:736
virtual config get_leader_goal() const override
Definition: contexts.hpp:651
virtual void diagnostic(const std::string &msg) override
Definition: contexts.hpp:460
void init_readonly_context_proxy(readonly_context &target)
Definition: contexts.hpp:439