The Battle for Wesnoth  1.17.23+dev
contexts.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2023
3  by Yurii Chernyi <terraninfo@terraninfo.net>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 /**
17  * @file
18  * Composite AI contexts
19  */
20 
21 #pragma once
22 
23 #include "ai/default/contexts.hpp"
24 
25 //============================================================================
26 namespace ai {
27 
28 class ai_context : public virtual default_ai_context {
29 public:
30 
31  /**
32  * Unwrap
33  */
34  virtual ai_context& get_ai_context() = 0;
35 
36 };
37 
38 class rca_context;
39 class rca_context : public virtual ai_context {
40 public:
41 
42  /**
43  * Constructor
44  */
45  rca_context();
46 
47  /**
48  * Destructor
49  */
50  virtual ~rca_context();
51 
52  /**
53  * Unwrap
54  */
55  virtual rca_context& get_rca_context() = 0;
56  bool is_offense(){ return is_offense_; }
57  void set_offense(){ is_offense_ = true; is_defense_ = false; strategy_set_ = true; }
58  bool is_defense(){ return is_defense_; }
59  void set_defense(){ is_defense_ = true; is_offense_ = false; strategy_set_ = true; }
60  void clear_strategy(){ strategy_set_ = false; }
61  bool has_strategy(){ return strategy_set_; }
62 
63 private:
64  static bool is_offense_;
65  static bool is_defense_;
66  static bool strategy_set_;
67 };
68 
70 class candidate_action_context : public virtual rca_context {
71 public:
72 
73  /**
74  * Constructor
75  */
77 
78  /**
79  * Destructor
80  */
82 
83  /**
84  * Unwrap
85  */
87 };
88 
89 // proxies
90 class ai_context_proxy : public virtual ai_context, public virtual default_ai_context_proxy {
91 public:
93 
95  {
97  target_ = &target;
98  }
99 
100  virtual ~ai_context_proxy();
101 
103  {
104  return target_->get_ai_context();
105  }
106 
107 private:
109 };
110 
111 class rca_context_proxy : public virtual rca_context, public virtual ai_context_proxy {
112 public:
114 
115  virtual ~rca_context_proxy();
116 
118  {
120  target_ = &target;
121  }
122 
124  {
125  return target_->get_rca_context();
126  }
127 
128 private:
130 };
131 
132 } //end of namespace ai
ai_context & get_ai_context()
Unwrap.
Definition: contexts.hpp:102
ai_context * target_
Definition: contexts.hpp:108
virtual ~ai_context_proxy()
Definition: contexts.cpp:32
void init_ai_context_proxy(ai_context &target)
Definition: contexts.hpp:94
virtual ai_context & get_ai_context()=0
Unwrap.
virtual ~candidate_action_context()
Destructor.
Definition: contexts.hpp:81
virtual candidate_action_context & get_candidate_action_context()=0
Unwrap.
candidate_action_context()
Constructor.
Definition: contexts.hpp:76
void init_default_ai_context_proxy(default_ai_context &target)
Definition: contexts.cpp:57
void init_rca_context_proxy(rca_context &target)
Definition: contexts.hpp:117
rca_context * target_
Definition: contexts.hpp:129
rca_context & get_rca_context()
Unwrap.
Definition: contexts.hpp:123
virtual ~rca_context_proxy()
Definition: contexts.cpp:52
rca_context()
Constructor.
Definition: contexts.cpp:39
virtual rca_context & get_rca_context()=0
Unwrap.
void set_defense()
Definition: contexts.hpp:59
bool is_offense()
Definition: contexts.hpp:56
static bool strategy_set_
Definition: contexts.hpp:66
virtual ~rca_context()
Destructor.
Definition: contexts.cpp:43
bool has_strategy()
Definition: contexts.hpp:61
bool is_defense()
Definition: contexts.hpp:58
static bool is_offense_
Definition: contexts.hpp:64
static bool is_defense_
Definition: contexts.hpp:65
void set_offense()
Definition: contexts.hpp:57
void clear_strategy()
Definition: contexts.hpp:60
Default AI contexts.
A small explanation about what's going on here: Each action has access to two game_info objects First...
Definition: actions.cpp:61