The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
contexts.hpp
Go to the documentation of this file.
1 
2 /*
3  Copyright (C) 2009 - 2016 by Yurii Chernyi <[email protected]>
4  Part of the Battle for Wesnoth Project http://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 #ifndef AI_COMPOSITE_CONTEXTS_HPP_INCLUDED
22 #define AI_COMPOSITE_CONTEXTS_HPP_INCLUDED
23 
24 #include "ai/default/contexts.hpp"
25 
26 #ifdef _MSC_VER
27 #pragma warning(push)
28 //silence "inherits via dominance" warnings
29 #pragma warning(disable:4250)
30 #endif
31 
32 
33 //============================================================================
34 namespace ai {
35 
36 class ai_context : public virtual default_ai_context {
37 public:
38 
39  /**
40  * Unwrap
41  */
42  virtual ai_context& get_ai_context() = 0;
43 
44 
45 };
46 
47 
48 class rca_context;
49 class rca_context : public virtual ai_context {
50 public:
51 
52 
53  /**
54  * Constructor
55  */
56  rca_context();
57 
58 
59  /**
60  * Destructor
61  */
62  virtual ~rca_context();
63 
64 
65  /**
66  * Unwrap
67  */
68  virtual rca_context& get_rca_context() = 0;
69  bool is_offense(){ return is_offense_; }
70  void set_offense(){ is_offense_ = true; is_defense_ = false; strategy_set_ = true; }
71  bool is_defense(){ return is_defense_; }
72  void set_defense(){ is_defense_ = true; is_offense_ = false; strategy_set_ = true; }
73  void clear_strategy(){ strategy_set_ = false; }
74  bool has_strategy(){ return strategy_set_; }
75 
76 private:
77  static bool is_offense_;
78  static bool is_defense_;
79  static bool strategy_set_;
80 };
81 
82 
84 class candidate_action_context : public virtual rca_context {
85 public:
86 
87 
88  /**
89  * Constructor
90  */
92 
93 
94  /**
95  * Destructor
96  */
98 
99 
100  /**
101  * Unwrap
102  */
104 };
105 
106 // proxies
107 class ai_context_proxy : public virtual ai_context, public virtual default_ai_context_proxy {
108 public:
110 
111 
113  {
115  target_ = &target;
116  }
117 
118 
119  virtual ~ai_context_proxy();
120 
121 
123  {
124  return target_->get_ai_context();
125  }
126 
127 
128 private:
130 };
131 
132 
133 class rca_context_proxy : public virtual rca_context, public virtual ai_context_proxy {
134 public:
136 
137 
138  virtual ~rca_context_proxy();
139 
140 
142  {
143  init_ai_context_proxy(target);
144  target_ = &target;
145  }
146 
147 
149  {
150  return target_->get_rca_context();
151  }
152 
153 
154 private:
156 };
157 
158 
159 } //end of namespace ai
160 
161 #ifdef _MSC_VER
162 #pragma warning(pop)
163 #endif
164 
165 
166 #endif
rca_context & get_rca_context()
Unwrap.
Definition: contexts.hpp:148
void clear_strategy()
Definition: contexts.hpp:73
virtual ~ai_context_proxy()
Definition: contexts.cpp:32
bool is_defense()
Definition: contexts.hpp:71
virtual ai_context & get_ai_context()=0
Unwrap.
static bool strategy_set_
Definition: contexts.hpp:79
static bool is_defense_
Definition: contexts.hpp:78
bool is_offense()
Definition: contexts.hpp:69
A small explanation about what's going on here: Each action has access to two game_info objects First...
Definition: actions.cpp:57
virtual candidate_action_context & get_candidate_action_context()=0
Unwrap.
virtual ~candidate_action_context()
Destructor.
Definition: contexts.hpp:97
void init_rca_context_proxy(rca_context &target)
Definition: contexts.hpp:141
static bool is_offense_
Definition: contexts.hpp:77
void init_default_ai_context_proxy(default_ai_context &target)
Definition: contexts.cpp:58
rca_context * target_
Definition: contexts.hpp:155
void init_ai_context_proxy(ai_context &target)
Definition: contexts.hpp:112
virtual ~rca_context()
Destructor.
Definition: contexts.cpp:45
Default AI contexts.
virtual ~rca_context_proxy()
Definition: contexts.cpp:56
candidate_action_context()
Constructor.
Definition: contexts.hpp:91
void set_offense()
Definition: contexts.hpp:70
ai_context * target_
Definition: contexts.hpp:129
virtual rca_context & get_rca_context()=0
Unwrap.
void set_defense()
Definition: contexts.hpp:72
bool has_strategy()
Definition: contexts.hpp:74
ai_context & get_ai_context()
Unwrap.
Definition: contexts.hpp:122
rca_context()
Constructor.
Definition: contexts.cpp:40
GLenum target
Definition: glew.h:5190