StarTrekV3_Linux  Version3
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros Pages
Engine.h
Go to the documentation of this file.
1 //
2 // ___.--------._____________,------' -----.`----._
3 // \ ` - . _ /\
4 // `.__________ ` - | | __,---"-._
5 // `-----------.______ ,'_/ ________,------'___________`----.___________
6 // `-----.____,' \===========================================/
7 // | :| >--------------.----------.---------------'
8 // / :| _,--' ,--' `--.__.--'
9 // / : |--'______________/_
10 // ,---,' : \__________________`--.
11 // `__________ |/|
12 // `------._ |\|
13 // `--._________,-'
14 //
15 //
16 //
17 // Credits go to Paramount pictures for the star - trek concept and universe.
18 
19 
20 // Copyright (C) 2015 - 2016 E.J.M. Martens
21 //
22 // This program is free software; you can redistribute it and/or
23 // modify it under the terms of the GNU General Public License
24 // as published by the Free Software Foundation; either version 2
25 // of the License, or (at your option) any later version.
26 //
27 // This program is distributed in the hope that it will be useful,
28 // but WITHOUT ANY WARRANTY; without even the implied warranty of
29 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 // GNU General Public License for more details.
31 //
32 // You should have received a copy of the GNU General Public License
33 // along with this program; if not, write to the Free Software
34 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
35 
36 
37 
38 
39 
40 #ifndef _Engine
41 #define _Engine
42 
43 #include <allegro5/allegro.h>
44 #include <allegro5/allegro_image.h>
45 #include <allegro5/allegro_primitives.h>
46 #include <allegro5/allegro_font.h>
47 #include <allegro5/allegro_ttf.h>
48 #include <exception>
49 #include <stdio.h>
50 #include <iostream>
51 #include <fstream>
52 #include <list>
53 #include <math.h>
54 #include "types.h"
55 #include "CoolMath.h"
56 #include "KeyMapper.h"
57 
58 
59 
60 using namespace std;
61 
63 typedef struct
64 {
67 
68  char m_szName [10];
70  int m_nHealth [20];
72  int m_nProbes;
74  int m_nZ;
75  int m_AI;
77  int m_nCrew;
78  int m_nEnergy;
84  int m_nTarget;
85  int m_nLife;
86  int m_nCount;
92  int m_nTask;
96 
97  double m_dX;
98  double m_dY;
99  double m_dSpeed;
100  double m_dWaypointX;
101  double m_dWaypointY;
102  double m_dAngle;
103  double m_dAngleSeek;
104 
111  bool m_blDock;
116 
117 } sGameObject;
118 
119 
120 class TEngine;
121 class TShip;
122 
123 
124 
125 
131 class TSprite
132 {
133 private:
134 
135 protected:
139  ALLEGRO_BITMAP * m_pImage;
141  int m_nZ;
142 
143  double m_dAngle,
144  m_dX,
145  m_dY,
146  m_dSpeed;
151 
152 public:
154  m_blCanCollide,
155  m_blCanFind;
156 
159 
162 
173 virtual void Draw(double a_dCamX,double a_dCamY);
174 
182 virtual void Move(double a_dLagCount);
183 
189 virtual void Do_ai();
190 
198 virtual void DoCollision(TSprite * const a_pSprite);
199 
209 void SetPosition(double a_dX, double a_dY, double a_dAngle);
210 
218 void SetPosition(double a_dX, double a_dY);
219 
225 void SetHeight(int a_nHeight);
226 
232 void SetSpeed(double a_dSpeed);
233 
239 void SetImage(ALLEGRO_BITMAP * a_pImage);
240 
246 double GetX();
247 
253 double GetY();
254 
258 TSprite();
259 virtual ~TSprite();
260 
261 friend class TEngine;
262 friend bool Comp(const TSprite * a_pV1, const TSprite * a_p_V2);
263 };
264 
265 
266 
274 class TEngine
275 {
276 friend class TShip;
277 
278 private:
279 // a list of sprites
280 std::list <TSprite *> m_lstItems;
281 
282 int m_nCount;
283 int m_nGameOver;
284 double m_dPosx,
285  m_dPosy,
286  m_dX,
287  m_dY;
288 
290 int CountSaveObjects();
291 
292 public:
293 
294 
300 
301 
302 // standard colors
303 ALLEGRO_COLOR m_clBLACK;
304 ALLEGRO_COLOR m_clWHITE;
305 ALLEGRO_COLOR m_clGREEN;
306 ALLEGRO_COLOR m_clYELLOW;
307 ALLEGRO_COLOR m_clBROWN;
308 ALLEGRO_COLOR m_clBLUE;
309 ALLEGRO_COLOR m_clRED;
310 ALLEGRO_COLOR m_clMAGENTA;
311 ALLEGRO_COLOR m_clAQUA;
312 ALLEGRO_COLOR m_clATHM;
313 
314 // key toggle list
315 bool m_blKeys[KEY_MAX];
316 
317 
323 void Move(double a_dLagCount);
324 
328 void Do_ai();
329 
336 void Add(TSprite * const a_pSprite);
337 
338 
348 void Draw_sensor(int a_nX,int a_nY, TShip * const a_pPlayer);
349 
355 void DrawHud(TShip * const a_pPlayer);
356 
364 void SetOrigin(double a_dX, double a_dY);
365 
371 void Folow(TSprite * const a_pSprite);
372 
376 void Draw();
377 
381 void Kill();
382 
386 void Sort();
387 
393 void Clear(bool a_blKeepPlayer);
394 
398 double GetDx();
399 
403 double GetDy();
404 
405 
419 TSprite * Seek(int a_nID, double a_dViewDistance, double a_dX, double a_dY);
420 
436 TSprite * Seek(int a_nMember, bool a_blEnemy,double a_dViewDistance, double a_dX, double a_dY);
437 
453 TSprite * Seekstarbase(int a_nMember, bool a_blEnemy,double a_dViewDistance, double a_dX, double a_dY);
454 
455 
466 bool Detect_collision(TSprite * a_pSprite1, TSprite * a_pSprite2);
467 
475 TEngine(int a_nWidth,int a_nHeight);
476 
480 ~TEngine();
481 
490 bool Save(ofstream & a_SaveStream);
491 
499 bool Load(ifstream & a_LoadStream);
500 
501 friend class Sector;
502 
503 };
504 
505 
510 class A5Exception: public exception
511 {
512  private:
513  string m_strError;
514 
515  public:
516 
522  A5Exception(string a_strError)
523  {
524  m_strError = a_strError;
525  }
526 
532  virtual const char* what() const throw()
533  {
534  return m_strError.c_str();
535  }
536 
537  virtual ~A5Exception() throw() { }
538 };
539 
540 
552 bool Comp(const TSprite * a_pV1, const TSprite * a_p_V2);
553 
554 
555 
556 
557 #endif
Definition: Ship.h:62
virtual ~A5Exception()
Definition: Engine.h:537
ALLEGRO_COLOR m_clMAGENTA
Definition: Engine.h:310
bool m_blReleasing
Definition: Engine.h:107
int m_nProbes
Definition: Engine.h:72
int m_nScreenMidY
Definition: Engine.h:299
A5Exception(string a_strError)
Exception Constructor.
Definition: Engine.h:522
int m_nCrew
Definition: Engine.h:77
int m_nLife
Definition: Engine.h:85
int m_nPopulation
Definition: Engine.h:83
bool m_blDocked
Definition: Engine.h:105
TEngine * m_pEngine
Pointer to the engine.
Definition: Engine.h:137
int m_nCount
Definition: Engine.h:86
ALLEGRO_COLOR m_clRED
Definition: Engine.h:309
Definition: Engine.h:510
int m_nBitmapMidY
Definition: Engine.h:150
int m_nBitmapHeight
Definition: Engine.h:148
int m_nCloakState
Definition: Engine.h:93
bool m_blMustSurvive
Definition: Engine.h:109
int m_nZ
Definition: Engine.h:74
int m_nTorpedoes
Definition: Engine.h:71
virtual const char * what() const
Exception descriptor.
Definition: Engine.h:532
virtual void Do_ai()
** VIRTUAL ** Enter AI routine Called by Engine
Definition: Engine.cpp:86
bool m_blCanFind
Definition: Engine.h:113
double m_dX
Definition: Engine.h:143
int m_nWarpFactor
Definition: Engine.h:73
int m_nZ
Z drawing order ( Depth)
Definition: Engine.h:141
ALLEGRO_COLOR m_clYELLOW
Definition: Engine.h:306
double m_dAngle
Definition: Engine.h:102
int m_nScreenHeight
Definition: Engine.h:297
Definition: KeyMapper.h:77
bool m_blDestroyed
Definition: Engine.h:153
bool m_blDocking
Definition: Engine.h:106
Definition: Engine.h:131
int m_nEnergy
Definition: Engine.h:78
int m_AI
Definition: Engine.h:75
Definition: Engine.h:274
int m_nBitmapWidth
Definition: Engine.h:147
bool m_blMustBeDestroyed
Definition: Engine.h:108
double m_dX
Definition: Engine.h:97
bool m_blCanCloak
Definition: Engine.h:115
int m_nPhotonTimer
Definition: Engine.h:88
ALLEGRO_COLOR m_clGREEN
Definition: Engine.h:305
int m_nBitmapMidX
Definition: Engine.h:149
int m_nCloakCharge
Definition: Engine.h:90
int m_nScreenMidX
Definition: Engine.h:298
ID m_ID
Definition: Engine.h:65
int m_nPhaserPower
Definition: Engine.h:82
Definition: Universe.h:95
MEMBER
Definition: types.h:133
ALLEGRO_COLOR m_clBROWN
Definition: Engine.h:307
double m_dWaypointY
Definition: Engine.h:101
MEMBER m_Member
Definition: Engine.h:66
bool m_blPhaserOn
Definition: Engine.h:114
Definition: Engine.h:63
bool m_blNoRelease
Definition: Engine.h:112
int m_nTask
Definition: Engine.h:92
virtual void Draw(double a_dCamX, double a_dCamY)
VIRTUAL Draw the ship and some effects (phaser) relative to camera position
Definition: Ship.cpp:579
virtual void Move(double a_dLagCount)
** VIRTUAL ** Move the sprite according to its speed. Called by Engine
Definition: Engine.cpp:58
friend class TEngine
Definition: Ship.h:331
int m_nShieldTimer
Definition: Engine.h:87
double m_dWaypointX
Definition: Engine.h:100
double m_dY
Definition: Engine.h:98
int m_nTranslucency
Definition: Engine.h:91
bool Comp(const TSprite *a_pV1, const TSprite *a_p_V2)
Compare function for Z sorting. Compares the Z value of the sprites passed through the pointers...
Definition: Engine.cpp:991
double m_dY
Definition: Engine.h:143
int m_nCloakCounter
Definition: Engine.h:89
int m_nRepairItem
Definition: Engine.h:76
int m_nSectorPositionX
Definition: Engine.h:94
ALLEGRO_COLOR m_clATHM
Definition: Engine.h:312
bool m_blMustReachPosition
Definition: Engine.h:110
ID m_ID
an ID providig some runtime type information
Definition: Engine.h:161
bool m_blSensorStatic
Definition: Engine.h:295
MEMBER m_Member
A sprite can be associated with a certain group (Federation, Klingon etc.)
Definition: Engine.h:158
ALLEGRO_COLOR m_clBLUE
Definition: Engine.h:308
int m_nShieldEnergy
Definition: Engine.h:79
int m_nPlanetType
Definition: Engine.h:69
int m_nTarget
Definition: Engine.h:84
ALLEGRO_COLOR m_clWHITE
Definition: Engine.h:304
ALLEGRO_COLOR m_clBLACK
Definition: Engine.h:303
int m_nScreenWidth
Definition: Engine.h:296
bool m_blDock
Definition: Engine.h:111
ALLEGRO_COLOR m_clAQUA
Definition: Engine.h:311
int m_nPhaserEnergy
Definition: Engine.h:80
double m_dAngleSeek
Definition: Engine.h:103
ALLEGRO_BITMAP * m_pImage
pointer to a bitmap representing this sprite
Definition: Engine.h:139
int m_nSectorPositionY
Definition: Engine.h:95
ID
Definition: types.h:170
double m_dSpeed
Definition: Engine.h:99
int m_nPreferedTarget
Definition: Engine.h:81