The Battle for Wesnoth  1.15.0-dev
contexts.hpp
Go to the documentation of this file.
1 
2 /*
3  Copyright (C) 2009 - 2018 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 //============================================================================
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 
39 
40 class rca_context;
41 class rca_context : public virtual ai_context {
42 public:
43 
44 
45  /**
46  * Constructor
47  */
48  rca_context();
49 
50 
51  /**
52  * Destructor
53  */
54  virtual ~rca_context();
55 
56 
57  /**
58  * Unwrap
59  */
60  virtual rca_context& get_rca_context() = 0;
61  bool is_offense(){ return is_offense_; }
62  void set_offense(){ is_offense_ = true; is_defense_ = false; strategy_set_ = true; }
63  bool is_defense(){ return is_defense_; }
64  void set_defense(){ is_defense_ = true; is_offense_ = false; strategy_set_ = true; }
65  void clear_strategy(){ strategy_set_ = false; }
66  bool has_strategy(){ return strategy_set_; }
67 
68 private:
69  static bool is_offense_;
70  static bool is_defense_;
71  static bool strategy_set_;
72 };
73 
74 
76 class candidate_action_context : public virtual rca_context {
77 public:
78 
79 
80  /**
81  * Constructor
82  */
84 
85 
86  /**
87  * Destructor
88  */
90 
91 
92  /**
93  * Unwrap
94  */
95  virtual candidate_action_context& get_candidate_action_context() = 0;
96 };
97 
98 // proxies
99 class ai_context_proxy : public virtual ai_context, public virtual default_ai_context_proxy {
100 public:
102 
103 
105  {
106  init_default_ai_context_proxy(target);
107  target_ = &target;
108  }
109 
110 
111  virtual ~ai_context_proxy();
112 
113 
115  {
116  return target_->get_ai_context();
117  }
118 
119 
120 private:
122 };
123 
124 
125 class rca_context_proxy : public virtual rca_context, public virtual ai_context_proxy {
126 public:
128 
129 
130  virtual ~rca_context_proxy();
131 
132 
134  {
135  init_ai_context_proxy(target);
136  target_ = &target;
137  }
138 
139 
141  {
142  return target_->get_rca_context();
143  }
144 
145 
146 private:
148 };
149 
150 
151 } //end of namespace ai
rca_context & get_rca_context()
Unwrap.
Definition: contexts.hpp:140
void clear_strategy()
Definition: contexts.hpp:65
bool is_defense()
Definition: contexts.hpp:63
virtual ai_context & get_ai_context()=0
Unwrap.
static bool strategy_set_
Definition: contexts.hpp:71
static bool is_defense_
Definition: contexts.hpp:70
bool is_offense()
Definition: contexts.hpp:61
A small explanation about what&#39;s going on here: Each action has access to two game_info objects First...
Definition: actions.cpp:58
virtual ~candidate_action_context()
Destructor.
Definition: contexts.hpp:89
void init_rca_context_proxy(rca_context &target)
Definition: contexts.hpp:133
static bool is_offense_
Definition: contexts.hpp:69
rca_context * target_
Definition: contexts.hpp:147
void init_ai_context_proxy(ai_context &target)
Definition: contexts.hpp:104
Default AI contexts.
candidate_action_context()
Constructor.
Definition: contexts.hpp:83
void set_offense()
Definition: contexts.hpp:62
ai_context * target_
Definition: contexts.hpp:121
virtual rca_context & get_rca_context()=0
Unwrap.
void set_defense()
Definition: contexts.hpp:64
bool has_strategy()
Definition: contexts.hpp:66
ai_context & get_ai_context()
Unwrap.
Definition: contexts.hpp:114