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