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