GameSSDWindow.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 Source Code 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 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #ifndef __GAME_SSD_WINDOW_H__
  21. #define __GAME_SSD_WINDOW_H__
  22. class idGameSSDWindow;
  23. class SSDCrossHair {
  24. public:
  25. enum {
  26. CROSSHAIR_STANDARD = 0,
  27. CROSSHAIR_SUPER,
  28. CROSSHAIR_COUNT
  29. };
  30. const idMaterial* crosshairMaterial[CROSSHAIR_COUNT];
  31. int currentCrosshair;
  32. float crosshairWidth, crosshairHeight;
  33. public:
  34. SSDCrossHair();
  35. ~SSDCrossHair();
  36. virtual void WriteToSaveGame( idFile *savefile );
  37. virtual void ReadFromSaveGame( idFile *savefile );
  38. void InitCrosshairs();
  39. void Draw(idDeviceContext *dc, const idVec2& cursor);
  40. };
  41. enum {
  42. SSD_ENTITY_BASE = 0,
  43. SSD_ENTITY_ASTEROID,
  44. SSD_ENTITY_ASTRONAUT,
  45. SSD_ENTITY_EXPLOSION,
  46. SSD_ENTITY_POINTS,
  47. SSD_ENTITY_PROJECTILE,
  48. SSD_ENTITY_POWERUP
  49. };
  50. class SSDEntity {
  51. public:
  52. //SSDEntity Information
  53. int type;
  54. int id;
  55. idStr materialName;
  56. const idMaterial* material;
  57. idVec3 position;
  58. idVec2 size;
  59. float radius;
  60. float hitRadius;
  61. float rotation;
  62. idVec4 matColor;
  63. idStr text;
  64. float textScale;
  65. idVec4 foreColor;
  66. idGameSSDWindow* game;
  67. int currentTime;
  68. int lastUpdate;
  69. int elapsed;
  70. bool destroyed;
  71. bool noHit;
  72. bool noPlayerDamage;
  73. bool inUse;
  74. public:
  75. SSDEntity();
  76. virtual ~SSDEntity();
  77. virtual void WriteToSaveGame( idFile *savefile );
  78. virtual void ReadFromSaveGame( idFile *savefile, idGameSSDWindow* _game );
  79. void EntityInit();
  80. void SetGame(idGameSSDWindow* _game);
  81. void SetMaterial(const char* _name);
  82. void SetPosition(const idVec3& _position);
  83. void SetSize(const idVec2& _size);
  84. void SetRadius(float _radius, float _hitFactor = 1.0f);
  85. void SetRotation(float _rotation);
  86. void Update();
  87. bool HitTest(const idVec2& pt);
  88. virtual void EntityUpdate() {};
  89. virtual void Draw(idDeviceContext *dc);
  90. virtual void DestroyEntity();
  91. virtual void OnHit(int key) {};
  92. virtual void OnStrikePlayer() {};
  93. idBounds WorldToScreen(const idBounds worldBounds);
  94. idVec3 WorldToScreen(const idVec3& worldPos);
  95. idVec3 ScreenToWorld(const idVec3& screenPos);
  96. };
  97. /*
  98. *****************************************************************************
  99. * SSDMover
  100. ****************************************************************************
  101. */
  102. class SSDMover : public SSDEntity {
  103. public:
  104. idVec3 speed;
  105. float rotationSpeed;
  106. public:
  107. SSDMover();
  108. virtual ~SSDMover();
  109. virtual void WriteToSaveGame( idFile *savefile );
  110. virtual void ReadFromSaveGame( idFile *savefile, idGameSSDWindow* _game );
  111. void MoverInit(const idVec3& _speed, float _rotationSpeed);
  112. virtual void EntityUpdate();
  113. };
  114. /*
  115. *****************************************************************************
  116. * SSDAsteroid
  117. ****************************************************************************
  118. */
  119. #define MAX_ASTEROIDS 64
  120. class SSDAsteroid : public SSDMover {
  121. public:
  122. int health;
  123. public:
  124. SSDAsteroid();
  125. ~SSDAsteroid();
  126. virtual void WriteToSaveGame( idFile *savefile );
  127. virtual void ReadFromSaveGame( idFile *savefile, idGameSSDWindow* _game );
  128. void Init(idGameSSDWindow* _game, const idVec3& startPosition, const idVec2& _size, float _speed, float rotate, int _health);
  129. virtual void EntityUpdate();
  130. static SSDAsteroid* GetNewAsteroid(idGameSSDWindow* _game, const idVec3& startPosition, const idVec2& _size, float _speed, float rotate, int _health);
  131. static SSDAsteroid* GetSpecificAsteroid(int id);
  132. static void WriteAsteroids(idFile* savefile);
  133. static void ReadAsteroids(idFile* savefile, idGameSSDWindow* _game);
  134. protected:
  135. static SSDAsteroid asteroidPool[MAX_ASTEROIDS];
  136. };
  137. /*
  138. *****************************************************************************
  139. * SSDAstronaut
  140. ****************************************************************************
  141. */
  142. #define MAX_ASTRONAUT 8
  143. class SSDAstronaut : public SSDMover {
  144. public:
  145. int health;
  146. public:
  147. SSDAstronaut();
  148. ~SSDAstronaut();
  149. virtual void WriteToSaveGame( idFile *savefile );
  150. virtual void ReadFromSaveGame( idFile *savefile, idGameSSDWindow* _game );
  151. void Init(idGameSSDWindow* _game, const idVec3& startPosition, float _speed, float rotate, int _health);
  152. static SSDAstronaut* GetNewAstronaut(idGameSSDWindow* _game, const idVec3& startPosition, float _speed, float rotate, int _health);
  153. static SSDAstronaut* GetSpecificAstronaut(int id);
  154. static void WriteAstronauts(idFile* savefile);
  155. static void ReadAstronauts(idFile* savefile, idGameSSDWindow* _game);
  156. protected:
  157. static SSDAstronaut astronautPool[MAX_ASTRONAUT];
  158. };
  159. /*
  160. *****************************************************************************
  161. * SSDExplosion
  162. ****************************************************************************
  163. */
  164. #define MAX_EXPLOSIONS 64
  165. class SSDExplosion : public SSDEntity {
  166. public:
  167. idVec2 finalSize;
  168. int length;
  169. int beginTime;
  170. int endTime;
  171. int explosionType;
  172. //The entity that is exploding
  173. SSDEntity* buddy;
  174. bool killBuddy;
  175. bool followBuddy;
  176. enum {
  177. EXPLOSION_NORMAL = 0,
  178. EXPLOSION_TELEPORT = 1
  179. };
  180. public:
  181. SSDExplosion();
  182. ~SSDExplosion();
  183. virtual void WriteToSaveGame( idFile *savefile );
  184. virtual void ReadFromSaveGame( idFile *savefile, idGameSSDWindow* _game );
  185. void Init(idGameSSDWindow* _game, const idVec3& _position, const idVec2& _size, int _length, int _type, SSDEntity* _buddy, bool _killBuddy = true, bool _followBuddy = true);
  186. virtual void EntityUpdate();
  187. static SSDExplosion* GetNewExplosion(idGameSSDWindow* _game, const idVec3& _position, const idVec2& _size, int _length, int _type, SSDEntity* _buddy, bool _killBuddy = true, bool _followBuddy = true);
  188. static SSDExplosion* GetSpecificExplosion(int id);
  189. static void WriteExplosions(idFile* savefile);
  190. static void ReadExplosions(idFile* savefile, idGameSSDWindow* _game);
  191. protected:
  192. static SSDExplosion explosionPool[MAX_EXPLOSIONS];
  193. };
  194. #define MAX_POINTS 16
  195. class SSDPoints : public SSDEntity {
  196. int length;
  197. int distance;
  198. int beginTime;
  199. int endTime;
  200. idVec3 beginPosition;
  201. idVec3 endPosition;
  202. idVec4 beginColor;
  203. idVec4 endColor;
  204. public:
  205. SSDPoints();
  206. ~SSDPoints();
  207. virtual void WriteToSaveGame( idFile *savefile );
  208. virtual void ReadFromSaveGame( idFile *savefile, idGameSSDWindow* _game );
  209. void Init(idGameSSDWindow* _game, SSDEntity* _ent, int _points, int _length, int _distance, const idVec4& color);
  210. virtual void EntityUpdate();
  211. static SSDPoints* GetNewPoints(idGameSSDWindow* _game, SSDEntity* _ent, int _points, int _length, int _distance, const idVec4& color);
  212. static SSDPoints* GetSpecificPoints(int id);
  213. static void WritePoints(idFile* savefile);
  214. static void ReadPoints(idFile* savefile, idGameSSDWindow* _game);
  215. protected:
  216. static SSDPoints pointsPool[MAX_POINTS];
  217. };
  218. #define MAX_PROJECTILES 64
  219. class SSDProjectile : public SSDEntity {
  220. idVec3 dir;
  221. idVec3 speed;
  222. int beginTime;
  223. int endTime;
  224. idVec3 endPosition;
  225. public:
  226. SSDProjectile();
  227. ~SSDProjectile();
  228. virtual void WriteToSaveGame( idFile *savefile );
  229. virtual void ReadFromSaveGame( idFile *savefile, idGameSSDWindow* _game );
  230. void Init(idGameSSDWindow* _game, const idVec3& _beginPosition, const idVec3& _endPosition, float _speed, float _size);
  231. virtual void EntityUpdate();
  232. static SSDProjectile* GetNewProjectile(idGameSSDWindow* _game, const idVec3& _beginPosition, const idVec3& _endPosition, float _speed, float _size);
  233. static SSDProjectile* GetSpecificProjectile(int id);
  234. static void WriteProjectiles(idFile* savefile);
  235. static void ReadProjectiles(idFile* savefile, idGameSSDWindow* _game);
  236. protected:
  237. static SSDProjectile projectilePool[MAX_PROJECTILES];
  238. };
  239. #define MAX_POWERUPS 64
  240. /**
  241. * Powerups work in two phases:
  242. * 1.) Closed container hurls at you
  243. * If you shoot the container it open
  244. * 3.) If an opened powerup hits the player he aquires the powerup
  245. * Powerup Types:
  246. * Health - Give a specific amount of health
  247. * Super Blaster - Increases the power of the blaster (lasts a specific amount of time)
  248. * Asteroid Nuke - Destroys all asteroids on screen as soon as it is aquired
  249. * Rescue Powerup - Rescues all astronauts as soon as it is acquited
  250. * Bonus Points - Gives some bonus points when acquired
  251. */
  252. class SSDPowerup : public SSDMover {
  253. enum {
  254. POWERUP_STATE_CLOSED = 0,
  255. POWERUP_STATE_OPEN
  256. };
  257. enum {
  258. POWERUP_TYPE_HEALTH = 0,
  259. POWERUP_TYPE_SUPER_BLASTER,
  260. POWERUP_TYPE_ASTEROID_NUKE,
  261. POWERUP_TYPE_RESCUE_ALL,
  262. POWERUP_TYPE_BONUS_POINTS,
  263. POWERUP_TYPE_DAMAGE,
  264. POWERUP_TYPE_MAX
  265. };
  266. int powerupState;
  267. int powerupType;
  268. public:
  269. public:
  270. SSDPowerup();
  271. virtual ~SSDPowerup();
  272. virtual void WriteToSaveGame( idFile *savefile );
  273. virtual void ReadFromSaveGame( idFile *savefile, idGameSSDWindow* _game );
  274. virtual void OnHit(int key);
  275. virtual void OnStrikePlayer();
  276. void OnOpenPowerup();
  277. void OnActivatePowerup();
  278. void Init(idGameSSDWindow* _game, float _speed, float _rotation);
  279. static SSDPowerup* GetNewPowerup(idGameSSDWindow* _game, float _speed, float _rotation);
  280. static SSDPowerup* GetSpecificPowerup(int id);
  281. static void WritePowerups(idFile* savefile);
  282. static void ReadPowerups(idFile* savefile, idGameSSDWindow* _game);
  283. protected:
  284. static SSDPowerup powerupPool[MAX_POWERUPS];
  285. };
  286. typedef struct {
  287. float spawnBuffer;
  288. int needToWin;
  289. } SSDLevelData_t;
  290. typedef struct {
  291. float speedMin, speedMax;
  292. float sizeMin, sizeMax;
  293. float rotateMin, rotateMax;
  294. int spawnMin, spawnMax;
  295. int asteroidHealth;
  296. int asteroidPoints;
  297. int asteroidDamage;
  298. } SSDAsteroidData_t;
  299. typedef struct {
  300. float speedMin, speedMax;
  301. float rotateMin, rotateMax;
  302. int spawnMin, spawnMax;
  303. int health;
  304. int points;
  305. int penalty;
  306. } SSDAstronautData_t;
  307. typedef struct {
  308. float speedMin, speedMax;
  309. float rotateMin, rotateMax;
  310. int spawnMin, spawnMax;
  311. } SSDPowerupData_t;
  312. typedef struct {
  313. float speed;
  314. int damage;
  315. int size;
  316. } SSDWeaponData_t;
  317. /**
  318. * SSDLevelStats_t
  319. * Data that is used for each level. This data is reset
  320. * each new level.
  321. */
  322. typedef struct {
  323. int shotCount;
  324. int hitCount;
  325. int destroyedAsteroids;
  326. int nextAsteroidSpawnTime;
  327. int killedAstronauts;
  328. int savedAstronauts;
  329. //Astronaut Level Data
  330. int nextAstronautSpawnTime;
  331. //Powerup Level Data
  332. int nextPowerupSpawnTime;
  333. SSDEntity* targetEnt;
  334. } SSDLevelStats_t;
  335. /**
  336. * SSDGameStats_t
  337. * Data that is used for the game that is currently running. Memset this
  338. * to completely reset the game
  339. */
  340. typedef struct {
  341. bool gameRunning;
  342. int score;
  343. int prebonusscore;
  344. int health;
  345. int currentWeapon;
  346. int currentLevel;
  347. int nextLevel;
  348. SSDLevelStats_t levelStats;
  349. } SSDGameStats_t;
  350. class idGameSSDWindow : public idWindow {
  351. public:
  352. idGameSSDWindow(idUserInterfaceLocal *gui);
  353. idGameSSDWindow(idDeviceContext *d, idUserInterfaceLocal *gui);
  354. ~idGameSSDWindow();
  355. virtual void WriteToSaveGame( idFile *savefile );
  356. virtual void ReadFromSaveGame( idFile *savefile );
  357. virtual const char* HandleEvent(const sysEvent_t *event, bool *updateVisuals);
  358. virtual idWinVar* GetWinVarByName (const char *_name, bool winLookup = false, drawWin_t** owner = NULL);
  359. virtual void Draw(int time, float x, float y);
  360. void AddHealth(int health);
  361. void AddScore(SSDEntity* ent, int points);
  362. void AddDamage(int damage);
  363. void OnNuke();
  364. void OnRescueAll();
  365. void OnSuperBlaster();
  366. SSDEntity* GetSpecificEntity(int type, int id);
  367. void PlaySound(const char* sound);
  368. static idRandom random;
  369. int ssdTime;
  370. private:
  371. //Initialization
  372. virtual bool ParseInternalVar(const char *name, idParser *src);
  373. void ParseLevelData(int level, const idStr& levelDataString);
  374. void ParseAsteroidData(int level, const idStr& asteroidDataString);
  375. void ParseWeaponData(int weapon, const idStr& weaponDataString);
  376. void ParseAstronautData(int level, const idStr& astronautDataString);
  377. void ParsePowerupData(int level, const idStr& powerupDataString);
  378. void CommonInit();
  379. void ResetGameStats();
  380. void ResetLevelStats();
  381. void ResetEntities();
  382. //Game Running Methods
  383. void StartGame();
  384. void StopGame();
  385. void GameOver();
  386. //Starting the Game
  387. void BeginLevel(int level);
  388. void ContinueGame();
  389. //Stopping the Game
  390. void LevelComplete();
  391. void GameComplete();
  392. void UpdateGame();
  393. void CheckForHits();
  394. void ZOrderEntities();
  395. void SpawnAsteroid();
  396. void FireWeapon(int key);
  397. SSDEntity* EntityHitTest(const idVec2& pt);
  398. void HitAsteroid(SSDAsteroid* asteroid, int key);
  399. void AsteroidStruckPlayer(SSDAsteroid* asteroid);
  400. void RefreshGuiData();
  401. idVec2 GetCursorWorld();
  402. //Astronaut Methods
  403. void SpawnAstronaut();
  404. void HitAstronaut(SSDAstronaut* astronaut, int key);
  405. void AstronautStruckPlayer(SSDAstronaut* astronaut);
  406. //Powerup Methods
  407. void SpawnPowerup();
  408. void StartSuperBlaster();
  409. void StopSuperBlaster();
  410. //void FreeSoundEmitter( bool immediate );
  411. public:
  412. //WinVars used to call functions from the guis
  413. idWinBool beginLevel;
  414. idWinBool resetGame;
  415. idWinBool continueGame;
  416. idWinBool refreshGuiData;
  417. SSDCrossHair crosshair;
  418. idBounds screenBounds;
  419. //Level Data
  420. int levelCount;
  421. idList<SSDLevelData_t> levelData;
  422. idList<SSDAsteroidData_t> asteroidData;
  423. idList<SSDAstronautData_t> astronautData;
  424. idList<SSDPowerupData_t> powerupData;
  425. //Weapon Data
  426. int weaponCount;
  427. idList<SSDWeaponData_t> weaponData;
  428. int superBlasterTimeout;
  429. //All current game data is stored in this structure (except the entity list)
  430. SSDGameStats_t gameStats;
  431. idList<SSDEntity*> entities;
  432. int currentSound;
  433. };
  434. #endif //__GAME_SSD_WINDOW_H__