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