HoverRace  2.0
MainCharacter.h
Go to the documentation of this file.
1 
2 // MainCharacter.h
3 //
4 // Copyright (c) 1995-1998 - Richard Langlois and Grokksoft Inc.
5 // Copyright (c) 2013-2015 Michael Imamura.
6 //
7 // Licensed under GrokkSoft HoverRace SourceCode License v1.0(the "License");
8 // you may not use this file except in compliance with the License.
9 //
10 // A copy of the license should have been attached to the package from which
11 // you have taken this file. If you can not find the license you can not use
12 // this file.
13 //
14 //
15 // The author makes no representations about the suitability of
16 // this software for any purpose. It is provided "as is" "AS IS",
17 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
18 // implied.
19 //
20 // See the License for the specific language governing permissions
21 // and limitations under the License.
22 //
23 
24 #pragma once
25 
26 #include "../Display/Color.h"
27 #include "../Model/MazeElement.h"
28 #include "../Model/PhysicalCollision.h"
29 #include "../Util/FastFifo.h"
30 
31 #if defined(_WIN32) && defined(HR_ENGINE_SHARED)
32 # ifdef MR_ENGINE
33 # define MR_DllDeclare __declspec( dllexport )
34 # else
35 # define MR_DllDeclare __declspec( dllimport )
36 # endif
37 #else
38 # define MR_DllDeclare
39 #endif
40 
41 namespace HoverRace {
42  namespace MainCharacter {
43  class MainCharacterRenderer;
44  }
45  namespace VideoServices {
46  class ShortSound;
47  }
48 }
49 
50 namespace HoverRace {
51 namespace MainCharacter {
52 
53 // for game options (also found in TrackSelect.h)
54 #define OPT_ALLOW_WEAPONS 0x40
55 #define OPT_ALLOW_MINES 0x20
56 #define OPT_ALLOW_CANS 0x10
57 #define OPT_ALLOW_BASIC 0x08
58 #define OPT_ALLOW_BI 0x02
59 #define OPT_ALLOW_CX 0x04
60 #define OPT_ALLOW_EON 0x01
61 
63 {
64 public:
65  enum : unsigned int {
66  eMotorOn = 1,
67  eRight = 2,
68  eLeft = 4,
69  eStraffleRight = 8,
70  eLookBack = 8, // Control added 12/1/2006; eStraffleRight seems unused
71  eStraffleLeft = 16,
72  eBreakDirection = 32,
73  eJump = 64,
74  eFire = 128,
75  eSlowRotation = 1024, // Used internally
76  eSelectWeapon = 2048
77  };
78 
79  enum eWeapon
80  {
84  eNotAWeapon
85  };
86 
87 private:
89  {
90  public:
93 
94  MR_Int32 ZMin() const override;
95  MR_Int32 ZMax() const override;
96  MR_Int32 AxisX() const override;
97  MR_Int32 AxisY() const override;
98  MR_Int32 RayLen() const override;
99  };
100 
101 public:
102  // Position complement
103  int mRoom;
104 
105  // Network helper
106  BOOL mNetPriority; // Indicate that the hover position must
107  // be resent as soon as possible due to a collision
108  // with a moving object (used only in server mode)
109 
110  MR_SimulationTime mLastCollisionTime; // Time of the last collision with a moving object
111  // Used to ignore out-of date refresh messages
112  // This time is only used in slave mode
113 
114 private:
116  unsigned mHoverModel; // HoverRace model
117  std::shared_ptr<MainCharacterRenderer> mRenderer;
118  unsigned int mControlState;
122  char mGameOpts;
123 
124  double mXSpeed;
125  double mYSpeed;
126  double mZSpeed;
129 
130  BOOL mOnFloor;
133 
134  BOOL mFireDone;
135 
141 
142  double mFuelLevel;
143 
148 
149  int mHoverId;
150 
151  // Race stats
155 
158 
160 
161  // Sound events list
164 
165  MainCharacter();
166 
167  int InternalSimulate(MR_SimulationTime pDuration, Model::Track &track,
168  int pRoom);
169 
170 public:
171  // Construction
172  static MainCharacter *New(int idx, char pGameOpts);
173 
174  virtual ~MainCharacter();
175 
176  void SetAsMaster();
177  void SetAsSlave();
178 
179  void SetHoverId(int pId);
180  int GetHoverId() const;
181 
182  void SetHoverModel(unsigned int pModel);
183  unsigned int GetHoverModel() const;
184 
185  void SetOrientation(MR_Angle pOrientation);
186 
187  void AddRenderer() override;
188  void Render(VideoServices::Viewport3D *pDest,
189  MR_SimulationTime pTime) override;
190 
191  Model::ElementNetState GetNetState() const override;
192  void SetNetState(int pDataLen, const MR_UInt8 * pData) override;
193 
194  // Movement inputs
195  void SetSimulationTime(MR_SimulationTime pTime);
196  void SetEngineState(bool engineState); // TODO: analog
197  void SetTurnLeftState(bool leftState); // TODO: analog
198  void SetTurnRightState(bool rightState); // TODO: analog
199  void SetJump();
200  void SetPowerup();
201  void SetChangeItem();
202  void SetBrakeState(bool brakeState); // TODO: analog? maybe not
203  void SetLookBackState(bool lookBackState);
204 
205  // State interogation functions
206  MR_Angle GetCabinOrientation() const;
207 
208  double GetFuelLevel() const;
209  double GetAbsoluteSpeed() const;
210  double GetDirectionalSpeed() const;
211 
212  eWeapon GetCurrentWeapon() const;
213  int GetMissileRefillLevel(int pNbLevel) const;
214  int GetMineCount() const;
215  int GetPowerUpCount() const;
216  int GetPowerUpFraction(int pNbLevel) const;
217 
218  int GetPlayerIndex() const { return playerIdx; }
219 
220  MR_SimulationTime GetTotalTime() const;
221  MR_SimulationTime GetLastLapDuration() const;
222  MR_SimulationTime GetLastLapCompletion() const;
223  bool HasStarted() const;
224  void Finish();
225  bool HasFinish() const;
226 
227  int HitQueueCount() const;
228  int GetHitQueue();
229 
230 protected:
231  // Logic interface
232  int Simulate(MR_SimulationTime pDuration, Model::Track &track, int pRoom)
233  override;
234 
235  const Model::ShapeInterface *GetObstacleShape() override;
236 
237  // ContactEffectShapeInterface
238  void ApplyEffect(const Model::ContactEffect *pEffect,
239  MR_SimulationTime pTime, MR_SimulationTime pDuration,
240  BOOL pValidDirection, MR_Angle pHorizontalDirection,
241  MR_Int32 pZMin, MR_Int32 pZMax, Model::Track &track) override;
242 
243  const Model::ContactEffectList *GetEffectList() override;
244 
245  const Model::ShapeInterface *GetReceivingContactEffectShape() override;
246  const Model::ShapeInterface *GetGivingContactEffectShape() override;
247 
248 public:
249  // Sounds
250  void PlayInternalSounds() override;
251  void PlayExternalSounds(int pDB, int pPan) override;
252 
253 public:
254  using startedSignal_t = boost::signals2::signal<void(MainCharacter*)>;
255  startedSignal_t &GetStartedSignal() { return startedSignal; }
256 
257  using finishedSignal_t = boost::signals2::signal<void(MainCharacter*)>;
258  finishedSignal_t &GetFinishedSignal() { return finishedSignal; }
259 
260  using checkpointSignal_t = boost::signals2::signal<void(MainCharacter*, int)>;
261  checkpointSignal_t &GetCheckpointSignal() { return checkpointSignal; }
262 
263  using finishLineSignal_t = boost::signals2::signal<void(MainCharacter*)>;
264  finishLineSignal_t &GetFinishLineSignal() { return finishLineSignal; }
265 
266 private:
267  bool started;
268  bool finished;
273 };
274 
275 } // namespace MainCharacter
276 } // namespace HoverRace
277 
278 #undef MR_DllDeclare
int playerIdx
Definition: MainCharacter.h:121
std::vector< ContactEffect * > ContactEffectList
Definition: ContactEffect.h:56
MR_Int32 mRay
Definition: MainCharacter.h:91
MR_SimulationTime mLastCollisionTime
Definition: MainCharacter.h:110
boost::signals2::signal< void(MainCharacter *)> startedSignal_t
Definition: MainCharacter.h:254
MR_SimulationTime mLastLapCompletion
Definition: MainCharacter.h:152
std::shared_ptr< MainCharacterRenderer > mRenderer
Definition: MainCharacter.h:117
double mXSpeed
Definition: MainCharacter.h:124
Cylinder mCollisionShape
Definition: MainCharacter.h:146
MR_SimulationTime mOutOfControlDuration
Definition: MainCharacter.h:132
MR_SimulationTime mCurrentTime
Definition: MainCharacter.h:154
int GetPlayerIndex() const
Definition: MainCharacter.h:218
MR_FixedFastFifo< int, 4 > mPowerUpList
Definition: MainCharacter.h:139
Definition: Viewport3D.h:53
Definition: Shapes.h:50
Definition: WorldCoordinates.h:75
double mFuelLevel
Definition: MainCharacter.h:142
MR_Int16 MR_Angle
Definition: WorldCoordinates.h:96
MR_SimulationTime mMissileRefillDuration
Definition: MainCharacter.h:137
double mYSpeed
Definition: MainCharacter.h:125
boost::signals2::signal< void(MainCharacter *)> finishLineSignal_t
Definition: MainCharacter.h:263
MR_SimulationTime mPowerUpLeft
Definition: MainCharacter.h:140
MR_3DCoordinate mPosition
Definition: MainCharacter.h:92
#define MR_DllDeclare
Definition: MainCharacter.h:38
boost::signals2::signal< void(MainCharacter *, int)> checkpointSignal_t
Definition: MainCharacter.h:260
BOOL mOnFloor
Definition: MainCharacter.h:130
BOOL mCheckPoint2
Definition: MainCharacter.h:157
bool finished
Definition: MainCharacter.h:268
int mRoom
Definition: MainCharacter.h:103
MR_Int32 MR_SimulationTime
Definition: WorldCoordinates.h:106
Definition: MazeElement.h:151
Base class for all contact effects.
Definition: ContactEffect.h:44
finishLineSignal_t finishLineSignal
Definition: MainCharacter.h:272
finishedSignal_t & GetFinishedSignal()
Definition: MainCharacter.h:258
BOOL mFireDone
Definition: MainCharacter.h:134
startedSignal_t startedSignal
Definition: MainCharacter.h:269
A track level.
Definition: Track.h:57
checkpointSignal_t checkpointSignal
Definition: MainCharacter.h:271
Definition: Shapes.h:75
int32_t MR_Int32
Definition: MR_Types.h:43
bool started
Definition: MainCharacter.h:267
unsigned mHoverModel
Definition: MainCharacter.h:116
startedSignal_t & GetStartedSignal()
Definition: MainCharacter.h:255
BOOL mNetPriority
Definition: MainCharacter.h:106
MR_FixedFastFifo< int, 6 > mLastHits
Definition: MainCharacter.h:159
double mZSpeed
Definition: MainCharacter.h:126
MR_Angle mCabinOrientation
Definition: MainCharacter.h:131
int idx
Definition: SdlDisplay.cpp:254
char mGameOpts
Definition: MainCharacter.h:122
Definition: PhysicalCollision.h:58
double mYSpeedBeforeCollision
Definition: MainCharacter.h:128
BOOL mMotorOnState
Definition: MainCharacter.h:119
Model::PhysicalCollision mContactEffect
Definition: MainCharacter.h:144
MR_FixedFastFifo< int, 2 > mMineList
Definition: MainCharacter.h:138
Cylinder mContactShape
Definition: MainCharacter.h:147
finishedSignal_t finishedSignal
Definition: MainCharacter.h:270
unsigned int mControlState
Definition: MainCharacter.h:118
Definition: Announcement.h:24
boost::signals2::signal< void(MainCharacter *)> finishedSignal_t
Definition: MainCharacter.h:257
checkpointSignal_t & GetCheckpointSignal()
Definition: MainCharacter.h:261
finishLineSignal_t & GetFinishLineSignal()
Definition: MainCharacter.h:264
eWeapon
Definition: MainCharacter.h:79
BOOL mCheckPoint1
Definition: MainCharacter.h:156
uint8_t MR_UInt8
Definition: MR_Types.h:40
Model::ContactEffectList mContactEffectList
Definition: MainCharacter.h:145
double mXSpeedBeforeCollision
Definition: MainCharacter.h:127
int mMotorDisplay
Definition: MainCharacter.h:120
Definition: MainCharacter.h:62
MR_FixedFastFifo< VideoServices::ShortSound *, 6 > mExternalSoundList
Definition: MainCharacter.h:163
MR_FixedFastFifo< VideoServices::ShortSound *, 6 > mInternalSoundList
Definition: MainCharacter.h:162
BOOL mMasterMode
Definition: MainCharacter.h:115
MR_SimulationTime mLastLapDuration
Definition: MainCharacter.h:153
eWeapon mCurrentWeapon
Definition: MainCharacter.h:136
int mHoverId
Definition: MainCharacter.h:149
Definition: MazeElement.h:56