The Battle for Wesnoth  1.13.10+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 - 2017 by Yurii Chernyi <terraninfo@terraninfo.net>
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 #pragma once
22 
23 #include "ai/default/contexts.hpp"
24 
25 #ifdef _MSC_VER
26 #pragma warning(push)
27 //silence "inherits via dominance" warnings
28 #pragma warning(disable:4250)
29 #endif
30 
31 
32 //============================================================================
33 namespace ai {
34 
35 class ai_context : public virtual default_ai_context {
36 public:
37 
38  /**
39  * Unwrap
40  */
41  virtual ai_context& get_ai_context() = 0;
42 
43 
44 };
45 
46 
47 class rca_context;
48 class rca_context : public virtual ai_context {
49 public:
50 
51 
52  /**
53  * Constructor
54  */
55  rca_context();
56 
57 
58  /**
59  * Destructor
60  */
61  virtual ~rca_context();
62 
63 
64  /**
65  * Unwrap
66  */
67  virtual rca_context& get_rca_context() = 0;
68  bool is_offense(){ return is_offense_; }
69  void set_offense(){ is_offense_ = true; is_defense_ = false; strategy_set_ = true; }
70  bool is_defense(){ return is_defense_; }
71  void set_defense(){ is_defense_ = true; is_offense_ = false; strategy_set_ = true; }
72  void clear_strategy(){ strategy_set_ = false; }
73  bool has_strategy(){ return strategy_set_; }
74 
75 private:
76  static bool is_offense_;
77  static bool is_defense_;
78  static bool strategy_set_;
79 };
80 
81 
83 class candidate_action_context : public virtual rca_context {
84 public:
85 
86 
87  /**
88  * Constructor
89  */
91 
92 
93  /**
94  * Destructor
95  */
97 
98 
99  /**
100  * Unwrap
101  */
103 };
104 
105 // proxies
106 class ai_context_proxy : public virtual ai_context, public virtual default_ai_context_proxy {
107 public:
109 
110 
112  {
114  target_ = &target;
115  }
116 
117 
118  virtual ~ai_context_proxy();
119 
120 
122  {
123  return target_->get_ai_context();
124  }
125 
126 
127 private:
129 };
130 
131 
132 class rca_context_proxy : public virtual rca_context, public virtual ai_context_proxy {
133 public:
135 
136 
137  virtual ~rca_context_proxy();
138 
139 
141  {
142  init_ai_context_proxy(target);
143  target_ = &target;
144  }
145 
146 
148  {
149  return target_->get_rca_context();
150  }
151 
152 
153 private:
155 };
156 
157 
158 } //end of namespace ai
159 
160 #ifdef _MSC_VER
161 #pragma warning(pop)
162 #endif
rca_context & get_rca_context()
Unwrap.
Definition: contexts.hpp:147
void clear_strategy()
Definition: contexts.hpp:72
virtual ~ai_context_proxy()
Definition: contexts.cpp:32
bool is_defense()
Definition: contexts.hpp:70
virtual ai_context & get_ai_context()=0
Unwrap.
static bool strategy_set_
Definition: contexts.hpp:78
static bool is_defense_
Definition: contexts.hpp:77
bool is_offense()
Definition: contexts.hpp:68
A small explanation about what's going on here: Each action has access to two game_info objects First...
Definition: actions.cpp:58
virtual candidate_action_context & get_candidate_action_context()=0
Unwrap.
virtual ~candidate_action_context()
Destructor.
Definition: contexts.hpp:96
void init_rca_context_proxy(rca_context &target)
Definition: contexts.hpp:140
static bool is_offense_
Definition: contexts.hpp:76
void init_default_ai_context_proxy(default_ai_context &target)
Definition: contexts.cpp:58
rca_context * target_
Definition: contexts.hpp:154
void init_ai_context_proxy(ai_context &target)
Definition: contexts.hpp:111
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:90
void set_offense()
Definition: contexts.hpp:69
ai_context * target_
Definition: contexts.hpp:128
virtual rca_context & get_rca_context()=0
Unwrap.
void set_defense()
Definition: contexts.hpp:71
bool has_strategy()
Definition: contexts.hpp:73
ai_context & get_ai_context()
Unwrap.
Definition: contexts.hpp:121
rca_context()
Constructor.
Definition: contexts.cpp:40