/
contexts.hpp
1542 lines (1184 loc) · 42.6 KB
/
contexts.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright (C) 2009 - 2018 by Yurii Chernyi <terraninfo@terraninfo.net>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
/**
* @file
* Helper functions for the object which operates in the context of AI for specific side
* this is part of AI interface
*/
#pragma once
#include "ai/game_info.hpp" // for move_map, typesafe_aspect_ptr, etc
#include "config.hpp" // for config
#include "game_errors.hpp"
#include "generic_event.hpp" // for observer
#include "map/location.hpp" // for map_location
#include "units/ptr.hpp" // for unit_ptr
#include <map> // for map, map<>::value_compare
#include <set> // for set
#include <string> // for string
#include <utility> // for pair
#include <vector> // for vector
class gamemap;
class team;
class terrain_filter;
class unit_map;
class unit_type;
namespace wfl { class variant; }
namespace ai { class ai_context; }
namespace ai { class unit_advancements_aspect; }
namespace ai { template <typename T> class typesafe_aspect; }
namespace boost { template <class T> class shared_ptr; }
namespace pathfind { struct paths; }
struct battle_context_unit_stats;
namespace ai
{
typedef ai_context* ai_context_ptr;
// recursion counter
class recursion_counter
{
public:
recursion_counter(int counter)
: counter_(++counter)
{
if(counter > MAX_COUNTER_VALUE) {
throw game::game_error("maximum recursion depth reached!");
}
}
/**
* Get the current value of the recursion counter
*/
int get_count() const
{
return counter_;
}
// max recursion depth
static const int MAX_COUNTER_VALUE = 100;
/**
* Check if more recursion is allowed
*/
bool is_ok() const
{
return counter_ < MAX_COUNTER_VALUE;
}
private:
// recursion counter value
int counter_;
};
// defensive position
struct defensive_position
{
defensive_position()
: loc()
, chance_to_hit(0)
, vulnerability(0.0)
, support(0.0)
{
}
map_location loc;
int chance_to_hit;
double vulnerability, support;
};
// keeps cache
class keeps_cache : public events::observer
{
public:
keeps_cache();
~keeps_cache();
void handle_generic_event(const std::string& event_name);
void clear();
const std::set<map_location>& get();
void init(const gamemap& map);
private:
const gamemap* map_;
std::set<map_location> keeps_;
};
// side context
class side_context;
class side_context
{
public:
/**
* Get the side number
*/
virtual side_number get_side() const = 0;
/**
* Set the side number
*/
virtual void set_side(side_number side) = 0;
/**
* empty destructor
*/
virtual ~side_context()
{
}
/**
* empty constructor
*/
side_context()
{
}
/**
* unwrap
*/
virtual side_context& get_side_context() = 0;
/**
* serialize this context to config
*/
virtual config to_side_context_config() const = 0;
/**
* Get the value of the recursion counter
*/
virtual int get_recursion_count() const = 0;
};
class readonly_context;
class readonly_context : public virtual side_context
{
public:
readonly_context()
{
}
virtual ~readonly_context()
{
}
virtual readonly_context& get_readonly_context() = 0;
virtual void on_readonly_context_create() = 0;
virtual const team& current_team() const = 0;
virtual void diagnostic(const std::string& msg) = 0;
virtual void log_message(const std::string& msg) = 0;
virtual attack_result_ptr check_attack_action(
const map_location& attacker_loc, const map_location& defender_loc, int attacker_weapon)
= 0;
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;
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;
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;
virtual stopunit_result_ptr check_stopunit_action(
const map_location& unit_location, bool remove_movement = true, bool remove_attacks = false)
= 0;
virtual synced_command_result_ptr check_synced_command_action(
const std::string& lua_code, const map_location& location = map_location::null_location())
= 0;
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 = 0;
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 = 0;
virtual const game_info& get_info() const = 0;
//@note: following part is in alphabetic order
virtual const defensive_position& best_defensive_position(const map_location& unit,
const move_map& dstsrc,
const move_map& srcdst,
const move_map& enemy_dstsrc) const = 0;
virtual std::map<map_location, defensive_position>& defensive_position_cache() const = 0;
virtual const unit_advancements_aspect& get_advancements() const = 0;
virtual double get_aggression() const = 0;
virtual int get_attack_depth() const = 0;
virtual const aspect_map& get_aspects() const = 0;
virtual aspect_map& get_aspects() = 0;
virtual void add_facet(const std::string& id, const config& cfg) const = 0;
virtual void add_aspects(std::vector<aspect_ptr>& aspects) = 0;
virtual const attacks_vector& get_attacks() const = 0;
virtual const wfl::variant& get_attacks_as_variant() const = 0;
virtual const terrain_filter& get_avoid() const = 0;
virtual double get_caution() const = 0;
virtual const move_map& get_dstsrc() const = 0;
virtual const move_map& get_enemy_dstsrc() const = 0;
virtual const moves_map& get_enemy_possible_moves() const = 0;
virtual const move_map& get_enemy_srcdst() const = 0;
/**
* get engine by cfg, creating it if it is not created yet but known
*/
virtual engine_ptr get_engine_by_cfg(const config& cfg) = 0;
virtual const std::vector<engine_ptr>& get_engines() const = 0;
virtual std::vector<engine_ptr>& get_engines() = 0;
virtual std::string get_grouping() const = 0;
virtual const std::vector<goal_ptr>& get_goals() const = 0;
virtual std::vector<goal_ptr>& get_goals() = 0;
virtual double get_leader_aggression() const = 0;
virtual config get_leader_goal() const = 0;
virtual bool get_leader_ignores_keep() const = 0;
virtual double get_leader_value() const = 0;
virtual bool get_passive_leader() const = 0;
virtual bool get_passive_leader_shares_keep() const = 0;
virtual const moves_map& get_possible_moves() const = 0;
virtual const std::vector<unit_ptr>& get_recall_list() const = 0;
virtual double get_recruitment_diversity() const = 0;
virtual const config get_recruitment_instructions() const = 0;
virtual const std::vector<std::string> get_recruitment_more() const = 0;
virtual const std::vector<std::string> get_recruitment_pattern() const = 0;
virtual int get_recruitment_randomness() const = 0;
virtual const config get_recruitment_save_gold() const = 0;
virtual double get_scout_village_targeting() const = 0;
virtual bool get_simple_targeting() const = 0;
virtual const move_map& get_srcdst() const = 0;
virtual bool get_support_villages() const = 0;
virtual double get_village_value() const = 0;
virtual int get_villages_per_scout() const = 0;
virtual bool is_active(const std::string& time_of_day, const std::string& turns) const = 0;
virtual bool is_dst_src_valid_lua() const = 0;
virtual bool is_dst_src_enemy_valid_lua() const = 0;
virtual bool is_src_dst_valid_lua() const = 0;
virtual bool is_src_dst_enemy_valid_lua() const = 0;
virtual void invalidate_defensive_position_cache() const = 0;
virtual void invalidate_move_maps() const = 0;
virtual void invalidate_keeps_cache() const = 0;
virtual const std::set<map_location>& keeps() const = 0;
virtual bool leader_can_reach_keep() const = 0;
virtual const map_location& nearest_keep(const map_location& loc) const = 0;
/**
* Function which finds how much 'power' a side can attack a certain location with.
* This is basically the maximum hp of damage that can be inflicted upon a unit on loc
* by full-health units, multiplied by the defense these units will have.
* (if 'use_terrain' is false, then it will be multiplied by 0.5)
*
* Example: 'loc' can be reached by two units, one of whom has a 10-3 attack
* and has 48/48 hp, and can defend at 40% on the adjacent grassland.
* The other has a 8-2 attack, and has 30/40 hp, and can defend at 60% on the adjacent mountain.
* The rating will be 10*3*1.0*0.4 + 8*2*0.75*0.6 = 19.2
*/
virtual double power_projection(const map_location& loc, const move_map& dstsrc) const = 0;
virtual void raise_user_interact() const = 0;
virtual void recalculate_move_maps() const = 0;
virtual void recalculate_move_maps_enemy() const = 0;
virtual void set_src_dst_valid_lua() = 0;
virtual void set_src_dst_enemy_valid_lua() = 0;
virtual void set_dst_src_valid_lua() = 0;
virtual void set_dst_src_enemy_valid_lua() = 0;
/**
* 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
* */
virtual const map_location& suitable_keep(
const map_location& leader_location, const pathfind::paths& leader_paths) const = 0;
/**
* serialize to config
*/
virtual config to_readonly_context_config() const = 0;
using unit_stats_cache_t = std::map<
std::pair<map_location, const unit_type*>,
std::pair<battle_context_unit_stats, battle_context_unit_stats>
>;
virtual unit_stats_cache_t& unit_stats_cache() const = 0;
};
class readwrite_context;
class readwrite_context : public virtual readonly_context
{
public:
readwrite_context()
{
}
virtual ~readwrite_context()
{
}
virtual readwrite_context& get_readwrite_context() = 0;
virtual attack_result_ptr execute_attack_action(
const map_location& attacker_loc, const map_location& defender_loc, int attacker_weapon)
= 0;
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;
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;
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;
virtual stopunit_result_ptr execute_stopunit_action(
const map_location& unit_location, bool remove_movement = true, bool remove_attacks = false)
= 0;
virtual synced_command_result_ptr execute_synced_command_action(
const std::string& lua_code, const map_location& location = map_location::null_location())
= 0;
virtual team& current_team_w() = 0;
virtual void raise_gamestate_changed() const = 0;
virtual game_info& get_info_w() = 0;
/**
* serialize this context to config
*/
virtual config to_readwrite_context_config() const = 0;
};
// proxies
class side_context_proxy : public virtual side_context
{
public:
side_context_proxy()
: target_(nullptr)
{
}
virtual ~side_context_proxy()
{
}
void init_side_context_proxy(side_context& target)
{
target_ = &target.get_side_context();
}
virtual side_number get_side() const override
{
return target_->get_side();
}
virtual void set_side(side_number side) override
{
return target_->set_side(side);
}
virtual side_context& get_side_context() override
{
return target_->get_side_context();
}
virtual int get_recursion_count() const override
{
return target_->get_recursion_count();
}
virtual config to_side_context_config() const override
{
return target_->to_side_context_config();
}
private:
side_context* target_;
};
class readonly_context_proxy : public virtual readonly_context, public virtual side_context_proxy
{
public:
readonly_context_proxy()
: target_(nullptr)
{
}
virtual ~readonly_context_proxy()
{
}
void init_readonly_context_proxy(readonly_context& target)
{
init_side_context_proxy(target);
target_ = &target.get_readonly_context();
}
virtual readonly_context& get_readonly_context() override
{
return target_->get_readonly_context();
}
virtual void on_readonly_context_create() override
{
return target_->on_readonly_context_create();
}
virtual const team& current_team() const override
{
return target_->current_team();
}
virtual void diagnostic(const std::string& msg) override
{
target_->diagnostic(msg);
}
virtual void log_message(const std::string& msg) override
{
target_->log_message(msg);
}
virtual attack_result_ptr check_attack_action(
const map_location& attacker_loc, const map_location& defender_loc, int attacker_weapon) override;
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;
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;
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;
virtual stopunit_result_ptr check_stopunit_action(
const map_location& unit_location, bool remove_movement = true, bool remove_attacks = false) override;
virtual synced_command_result_ptr check_synced_command_action(
const std::string& lua_code, const map_location& location = map_location::null_location()) override;
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
{
target_->calculate_possible_moves(
possible_moves, srcdst, dstsrc, enemy, assume_full_movement, remove_destinations);
}
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
{
target_->calculate_moves(
units, possible_moves, srcdst, dstsrc, enemy, assume_full_movement, remove_destinations, see_all);
}
virtual const game_info& get_info() const override
{
return target_->get_info();
}
virtual void raise_user_interact() const override
{
target_->raise_user_interact();
}
virtual int get_recursion_count() const override
{
return target_->get_recursion_count();
}
//@note: following part is in alphabetic order
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
{
return target_->best_defensive_position(unit, dstsrc, srcdst, enemy_dstsrc);
}
virtual std::map<map_location, defensive_position>& defensive_position_cache() const override
{
return target_->defensive_position_cache();
}
virtual const unit_advancements_aspect& get_advancements() const override
{
return target_->get_advancements();
}
virtual double get_aggression() const override
{
return target_->get_aggression();
}
virtual int get_attack_depth() const override
{
return target_->get_attack_depth();
}
virtual const aspect_map& get_aspects() const override
{
return target_->get_aspects();
}
virtual aspect_map& get_aspects() override
{
return target_->get_aspects();
}
virtual void add_aspects(std::vector<aspect_ptr>& aspects) override
{
return target_->add_aspects(aspects);
}
virtual void add_facet(const std::string& id, const config& cfg) const override
{
target_->add_facet(id, cfg);
}
virtual const attacks_vector& get_attacks() const override
{
return target_->get_attacks();
}
virtual const wfl::variant& get_attacks_as_variant() const override
{
return target_->get_attacks_as_variant();
}
virtual const terrain_filter& get_avoid() const override
{
return target_->get_avoid();
}
virtual double get_caution() const override
{
return target_->get_caution();
}
virtual const move_map& get_dstsrc() const override
{
return target_->get_dstsrc();
}
virtual const move_map& get_enemy_dstsrc() const override
{
return target_->get_enemy_dstsrc();
}
virtual const moves_map& get_enemy_possible_moves() const override
{
return target_->get_enemy_possible_moves();
}
virtual const move_map& get_enemy_srcdst() const override
{
return target_->get_enemy_srcdst();
}
virtual engine_ptr get_engine_by_cfg(const config& cfg) override
{
return target_->get_engine_by_cfg(cfg);
}
virtual const std::vector<engine_ptr>& get_engines() const override
{
return target_->get_engines();
}
virtual std::vector<engine_ptr>& get_engines() override
{
return target_->get_engines();
}
virtual std::string get_grouping() const override
{
return target_->get_grouping();
}
virtual const std::vector<goal_ptr>& get_goals() const override
{
return target_->get_goals();
}
virtual std::vector<goal_ptr>& get_goals() override
{
return target_->get_goals();
}
virtual double get_leader_aggression() const override
{
return target_->get_leader_aggression();
}
virtual config get_leader_goal() const override
{
return target_->get_leader_goal();
}
virtual bool get_leader_ignores_keep() const override
{
return target_->get_leader_ignores_keep();
}
virtual double get_leader_value() const override
{
return target_->get_leader_value();
}
virtual bool get_passive_leader() const override
{
return target_->get_passive_leader();
}
virtual bool get_passive_leader_shares_keep() const override
{
return target_->get_passive_leader_shares_keep();
}
virtual const moves_map& get_possible_moves() const override
{
return target_->get_possible_moves();
}
virtual double power_projection(const map_location& loc, const move_map& dstsrc) const override
{
return target_->power_projection(loc, dstsrc);
}
virtual const std::vector<unit_ptr>& get_recall_list() const override
{
return target_->get_recall_list();
}
virtual double get_recruitment_diversity() const override
{
return target_->get_recruitment_diversity();
}
virtual const config get_recruitment_instructions() const override
{
return target_->get_recruitment_instructions();
}
virtual const std::vector<std::string> get_recruitment_more() const override
{
return target_->get_recruitment_more();
}
virtual const std::vector<std::string> get_recruitment_pattern() const override
{
return target_->get_recruitment_pattern();
}
virtual int get_recruitment_randomness() const override
{
return target_->get_recruitment_randomness();
}
virtual const config get_recruitment_save_gold() const override
{
return target_->get_recruitment_save_gold();
}
virtual const move_map& get_srcdst() const override
{
return target_->get_srcdst();
}
virtual double get_scout_village_targeting() const override
{
return target_->get_scout_village_targeting();
}
virtual bool get_simple_targeting() const override
{
return target_->get_simple_targeting();
}
virtual bool get_support_villages() const override
{
return target_->get_support_villages();
}
virtual double get_village_value() const override
{
return target_->get_village_value();
}
virtual int get_villages_per_scout() const override
{
return target_->get_villages_per_scout();
}
virtual bool is_active(const std::string& time_of_day, const std::string& turns) const override
{
return target_->is_active(time_of_day, turns);
}
virtual bool is_dst_src_valid_lua() const override
{
return target_->is_dst_src_valid_lua();
}
virtual bool is_dst_src_enemy_valid_lua() const override
{
return target_->is_dst_src_enemy_valid_lua();
}
virtual bool is_src_dst_valid_lua() const override
{
return target_->is_src_dst_valid_lua();
}
virtual bool is_src_dst_enemy_valid_lua() const override
{
return target_->is_src_dst_enemy_valid_lua();
}
virtual void invalidate_defensive_position_cache() const override
{
return target_->invalidate_defensive_position_cache();
}
virtual void invalidate_move_maps() const override
{
target_->invalidate_move_maps();
}
virtual void invalidate_keeps_cache() const override
{
return target_->invalidate_keeps_cache();
}
virtual const std::set<map_location>& keeps() const override
{
return target_->keeps();
}
virtual bool leader_can_reach_keep() const override
{
return target_->leader_can_reach_keep();
}
virtual const map_location& nearest_keep(const map_location& loc) const override
{
return target_->nearest_keep(loc);
}
virtual void recalculate_move_maps() const override
{
target_->recalculate_move_maps();
}
virtual void recalculate_move_maps_enemy() const override
{
target_->recalculate_move_maps_enemy();
}
virtual void set_dst_src_valid_lua() override
{
target_->set_dst_src_valid_lua();
}
virtual void set_dst_src_enemy_valid_lua() override
{
target_->set_dst_src_enemy_valid_lua();
}
virtual void set_src_dst_valid_lua() override
{
target_->set_src_dst_valid_lua();
}
virtual void set_src_dst_enemy_valid_lua() override
{
target_->set_src_dst_enemy_valid_lua();
}
virtual const map_location& suitable_keep(
const map_location& leader_location, const pathfind::paths& leader_paths) const override
{
return target_->suitable_keep(leader_location, leader_paths);
}
virtual config to_readonly_context_config() const override
{
return target_->to_readonly_context_config();
}
virtual unit_stats_cache_t& unit_stats_cache() const override
{
return target_->unit_stats_cache();
}
private:
readonly_context* target_;
};
class readwrite_context_proxy : public virtual readwrite_context, public virtual readonly_context_proxy
{
public:
readwrite_context_proxy()
: target_(nullptr)
{
}
void init_readwrite_context_proxy(readwrite_context& target)
{
init_readonly_context_proxy(target);
target_ = &target.get_readwrite_context();
}
virtual readwrite_context& get_readwrite_context() override
{
return target_->get_readwrite_context();
}
virtual attack_result_ptr execute_attack_action(
const map_location& attacker_loc, const map_location& defender_loc, int attacker_weapon) override;
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;
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;
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;
virtual stopunit_result_ptr execute_stopunit_action(
const map_location& unit_location, bool remove_movement = true, bool remove_attacks = false) override;
virtual synced_command_result_ptr execute_synced_command_action(
const std::string& lua_code, const map_location& location = map_location::null_location()) override;
virtual team& current_team_w() override
{
return target_->current_team_w();
}
virtual void raise_gamestate_changed() const override
{
target_->raise_gamestate_changed();
}
virtual game_info& get_info_w() override
{
return target_->get_info_w();
}
virtual int get_recursion_count() const override
{
return target_->get_recursion_count();
}
virtual config to_readwrite_context_config() const override
{
return target_->to_readwrite_context_config();
}
private:
readwrite_context* target_;
};
// implementation
class side_context_impl : public side_context
{
public:
side_context_impl(side_number side, const config& /*cfg*/)