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