The Battle for Wesnoth  1.19.5+dev
contexts.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2024
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 : public virtual ai_context {
39 public:
40 
41  /**
42  * Constructor
43  */
44  rca_context();
45 
46  /**
47  * Destructor
48  */
49  virtual ~rca_context();
50 
51  /**
52  * Unwrap
53  */
54  virtual rca_context& get_rca_context() = 0;
55  bool is_offense(){ return is_offense_; }
56  void set_offense(){ is_offense_ = true; is_defense_ = false; strategy_set_ = true; }
57  bool is_defense(){ return is_defense_; }
58  void set_defense(){ is_defense_ = true; is_offense_ = false; strategy_set_ = true; }
59  void clear_strategy(){ strategy_set_ = false; }
60  bool has_strategy(){ return strategy_set_; }
61 
62 private:
63  static bool is_offense_;
64  static bool is_defense_;
65  static bool strategy_set_;
66 };
67 
68 class candidate_action_context : public virtual rca_context {
69 public:
70 
71  /**
72  * Constructor
73  */
75 
76  /**
77  * Destructor
78  */
80 
81  /**
82  * Unwrap
83  */
85 };
86 
87 // proxies
88 class ai_context_proxy : public virtual ai_context, public virtual default_ai_context_proxy {
89 public:
91 
93  {
95  target_ = &target;
96  }
97 
98  virtual ~ai_context_proxy();
99 
101  {
102  return target_->get_ai_context();
103  }
104 
105 private:
107 };
108 
109 class rca_context_proxy : public virtual rca_context, public virtual ai_context_proxy {
110 public:
112 
113  virtual ~rca_context_proxy();
114 
116  {
118  target_ = &target;
119  }
120 
122  {
123  return target_->get_rca_context();
124  }
125 
126 private:
128 };
129 
130 } //end of namespace ai
ai_context & get_ai_context()
Unwrap.
Definition: contexts.hpp:100
ai_context * target_
Definition: contexts.hpp:106
virtual ~ai_context_proxy()
Definition: contexts.cpp:32
void init_ai_context_proxy(ai_context &target)
Definition: contexts.hpp:92
virtual ai_context & get_ai_context()=0
Unwrap.
virtual ~candidate_action_context()
Destructor.
Definition: contexts.hpp:79
virtual candidate_action_context & get_candidate_action_context()=0
Unwrap.
candidate_action_context()
Constructor.
Definition: contexts.hpp:74
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:115
rca_context * target_
Definition: contexts.hpp:127
rca_context & get_rca_context()
Unwrap.
Definition: contexts.hpp:121
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:58
bool is_offense()
Definition: contexts.hpp:55
static bool strategy_set_
Definition: contexts.hpp:65
virtual ~rca_context()
Destructor.
Definition: contexts.cpp:43
bool has_strategy()
Definition: contexts.hpp:60
bool is_defense()
Definition: contexts.hpp:57
static bool is_offense_
Definition: contexts.hpp:63
static bool is_defense_
Definition: contexts.hpp:64
void set_offense()
Definition: contexts.hpp:56
void clear_strategy()
Definition: contexts.hpp:59
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:59