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