DOOM-3-BFG

DOOM 3 BFG Edition
Log | Files | Refs

GameSSDWindow.h (15234B)


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