HoverRace  2.0
ActionPerformers.h
Go to the documentation of this file.
1 // ActionPerformers.h
2 // A collection of classes implementing the ActionPerformer template class
3 // (just has to implement operator() and a constructor). These are all
4 // actions to be performed when the user presses a control key.
5 //
6 // Copyright (c) 2010, Ryan Curtin
7 //
8 // Licensed under GrokkSoft HoverRace SourceCode License v1.0(the "License");
9 // you may not use this file except in compliance with the License.
10 //
11 // A copy of the license should have been attached to the package from which
12 // you have taken this file. If you can not find the license you can not use
13 // this file.
14 //
15 //
16 // The author makes no representations about the suitability of
17 // this software for any purpose. It is provided "as is" "AS IS",
18 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
19 // implied.
20 //
21 // See the License for the specific language governing permissions
22 // and limitations under the License.
23 //
24 
25 #pragma once
26 
27 #include "Controller.h"
28 #include "ControlAction.h"
29 
30 #if defined(_WIN32) && defined(HR_ENGINE_SHARED)
31 # ifdef MR_ENGINE
32 # define MR_DllDeclare __declspec( dllexport )
33 # else
34 # define MR_DllDeclare __declspec( dllimport )
35 # endif
36 #else
37 # define MR_DllDeclare
38 #endif
39 
40 namespace HoverRace {
41  namespace MainCharacter {
42  class MainCharacter;
43  }
44 }
45 
46 namespace HoverRace {
47 namespace Control {
48 
49 /***
50  * \class PlayerEffectAction
51  *
52  * Base class for actions that affect a player. This gives us a unified
53  * constructor so we can hang on to a shared pointer to the player. For speed
54  * concerns, most of these do not check if the pointer is NULL. Given that that
55  * condition should never happen, this should not be a problem.
56  */
58  public:
59  // C++0x should give us constructor inheritance... whenever that happens
60  PlayerEffectAction(std::string name, int listOrder, MainCharacter::MainCharacter* mc);
61 
62  void SetMainCharacter(MainCharacter::MainCharacter* mc);
63  virtual void operator()(int value) = 0;
64 
65  protected:
66  // TODO: shared_ptr
68 };
69 
70 /***
71  * \class EngineAction
72  *
73  * Turns the motor on or off.
74  */
76  public:
77  EngineAction(std::string name, int listOrder, MainCharacter::MainCharacter* mc) : PlayerEffectAction(name, listOrder, mc) { }
78 
79  /***
80  * eventValue > 0: turn engine on.
81  * eventValue == 0: turn engine off.
82  */
83  virtual void operator()(int eventValue);
84 };
85 
86 /***
87  * \class TurnLeftAction
88  *
89  * Turns the craft left.
90  */
92  public:
93  TurnLeftAction(std::string name, int listOrder, MainCharacter::MainCharacter* mc) : PlayerEffectAction(name, listOrder, mc) { }
94 
95  /***
96  * eventValue > 0: set craft to turn left
97  * eventValue == 0: stop left turn
98  */
99  virtual void operator()(int eventValue);
100 };
101 
102 /***
103  * \class TurnRightAction
104  *
105  * Turns the craft right.
106  */
108  public:
109  TurnRightAction(std::string name, int listOrder, MainCharacter::MainCharacter* mc) : PlayerEffectAction(name, listOrder, mc) { }
110 
111  /***
112  * eventValue > 0: set craft to turn right
113  * eventValue == 0: stop right turn
114  */
115  virtual void operator()(int eventValue);
116 };
117 
118 /***
119  * \class JumpAction
120  *
121  * Makes the craft jump.
122  */
124  public:
125  JumpAction(std::string name, int listOrder, MainCharacter::MainCharacter* mc) : PlayerEffectAction(name, listOrder, mc) { }
126 
127  /***
128  * The craft will be told to jump, regardless of eventValue.
129  */
130  virtual void operator()(int eventValue);
131 };
132 
133 /***
134  * \class PowerupAction
135  *
136  * Fires a missile, lays a mine, or uses a speed can, depending on the user's
137  * selected item.
138  */
140  public:
141  PowerupAction(std::string name, int listOrder, MainCharacter::MainCharacter* mc) : PlayerEffectAction(name, listOrder, mc) { }
142 
143  /***
144  * Uses the item, regardless of eventValue.
145  */
146  virtual void operator()(int eventValue);
147 };
148 
149 /***
150  * \class ChangeItemAction
151  *
152  * Changes the current item.
153  */
155  public:
156  ChangeItemAction(std::string name, int listOrder, MainCharacter::MainCharacter* mc) : PlayerEffectAction(name, listOrder, mc) { }
157 
158  /***
159  * Changes the current item, regardless of eventValue.
160  */
161  virtual void operator()(int eventValue);
162 };
163 
164 /***
165  * \class BrakeAction
166  *
167  * Brakes the craft (or turns it around so that if used in conjunction with the engine,
168  * the craft slows down).
169  */
171  public:
172  BrakeAction(std::string name, int listOrder, MainCharacter::MainCharacter* mc) : PlayerEffectAction(name, listOrder, mc) { }
173 
174  /***
175  * eventValue > 0: set brake state on
176  * eventValue == 0: set brake state off
177  */
178  virtual void operator()(int eventValue);
179 };
180 
181 /***
182  * \class LookBackAction
183  *
184  * Sets whether or not the player is looking back. This is arguably not a
185  * PlayerEffectAction but we'll leave it here for now.
186  */
188  public:
189  LookBackAction(std::string name, int listOrder, MainCharacter::MainCharacter* mc) : PlayerEffectAction(name, listOrder, mc) { }
190 
191  /***
192  * eventValue > 0: set lookback state on
193  * eventValue == 0: set lookback state off
194  */
195  virtual void operator()(int eventValue);
196 };
197 
198 } // namespace Control
199 } // namespace HoverRace
200 
201 #undef MR_DllDeclare
TurnLeftAction(std::string name, int listOrder, MainCharacter::MainCharacter *mc)
Definition: ActionPerformers.h:93
Definition: ActionPerformers.h:154
Definition: ActionPerformers.h:57
Definition: ActionPerformers.h:91
BrakeAction(std::string name, int listOrder, MainCharacter::MainCharacter *mc)
Definition: ActionPerformers.h:172
ChangeItemAction(std::string name, int listOrder, MainCharacter::MainCharacter *mc)
Definition: ActionPerformers.h:156
JumpAction(std::string name, int listOrder, MainCharacter::MainCharacter *mc)
Definition: ActionPerformers.h:125
Abstract base class which allows us a simple reference to arbitrary functors of type ControlActionImp...
Definition: ControlAction.h:50
Definition: ActionPerformers.h:123
EngineAction(std::string name, int listOrder, MainCharacter::MainCharacter *mc)
Definition: ActionPerformers.h:77
MainCharacter::MainCharacter * mc
Definition: ActionPerformers.h:67
Definition: ActionPerformers.h:187
#define MR_DllDeclare
Definition: ActionPerformers.h:37
Definition: ActionPerformers.h:75
LookBackAction(std::string name, int listOrder, MainCharacter::MainCharacter *mc)
Definition: ActionPerformers.h:189
TurnRightAction(std::string name, int listOrder, MainCharacter::MainCharacter *mc)
Definition: ActionPerformers.h:109
Definition: Announcement.h:24
Definition: ActionPerformers.h:170
Definition: ActionPerformers.h:139
PowerupAction(std::string name, int listOrder, MainCharacter::MainCharacter *mc)
Definition: ActionPerformers.h:141
Definition: ActionPerformers.h:107
Definition: MainCharacter.h:62