/*                                                  *\
** CrimsonRoks    2003 (c) Tero Alatalo / 10tons    **
** An Asteroids Game                                ***
**                                                  ****
** General Notes:                                   ***
**                                                  **
**  I don't take any responsibility what this code  **
**  does or does not do. This code is provided to   **
**  you as is, with no further technical support or **
**  support what so ever provided. Feel free to use **
**  this how ever you see fit.                      **
**                                                  **
** The Code..                                       **
**                                                  **
**  Ok. The game is programmed in a hurry and the   **
**  code may look exactly like that. It's by no     **
**  means the way a game should be built.           **
**  Code is by no means optimized. You could easily **
**  pick better data structures and use some nicer  **
**  iteration methods to go through the game        **
**  entities etc. However, the structures are       **
**  chosen to make the code as simple as possible   **
**  (however I think I already missed that goal     **
**  when I started to add some extra features.      **
**                                                  **
**  The game is not complete and you can't really   **
**  "win" it or anything. I hope some of you has    **
**  the time and energy to develop this into        **
**  something bigger :)                             **
**                                                  **
\*                                                  */


#ifndef R_ROKS_H
#define R_ROKS_H

#include "clMod.h"


enum rConstants
{
	R_MAX_ROCKS				= 256,
	R_MAX_PROJS				= 256,
	R_MAX_PARTS				= 256,
	R_MAX_TEXS				= 64,
	R_MAX_CRAFTS			= 4,

	R_BIGPARTBIT			= (1<<31)	// set on if the part subtexture is 64x64 size (hacky hacky)
};



struct rTexs_t						// texture handles
{
	int		projsParts;
	int		rockTiny;
	int		rockSmall;
	int		rockMedium;
	int		craftBase;
	int		craftShield;
	int		craftWep[5];
	int		stars;
	int		earth;
	int		logo;
};

struct rSounds_t
{
	int		shoot;
	int		hit;
	int		expl;
	int		bonus;
};


// craft control structure
struct rActions_t
{
	int				time;			// frame time
	float			angleTo;		// angle the craft is facing this frame
	union
	{
		struct	// FIXME: anonymous struct..
		{
			bool	thrust		: 1;
			bool	turnLeft	: 1;// unused
			bool	turnRight	: 1;// unused
			bool	fire		: 1;
		};

		BYTE		flags;			// oh no, 4 bits go waste =)
	};

	// compiler probably pads this with 3 extra bytes..
};



struct rEntity_t
{
	bool			alive;			// is alive?
	float			time;

//	vec2_t			drawPos;		// lerped position for drawing the entity

	vec2_t			origin;			// position, where on screen the ent is on logic frame
	float			angle;			// angle ent is facing to
	vec2_t			vel;			// velocity, where's the ent's moving

	float			radius;			// half size of the sprite
	color_t			color;
};

struct rRock_t : rEntity_t
{
	float			health;			// how much damage rock takes.. how can a rock have health anyway? :)
	float			animFrame;		// animation frame
};


enum rProjType_e
{
	R_PROJ_BASIC
};


struct rProj_t : rEntity_t			// projectile (eg. bullet)
{
	float			angle;
	float			damage;
	int				frame;
};


struct rPart_t : rEntity_t			// particle (eg. smoke or explosion)
{
	int				frame;
	float			timeToLive;
};

struct rCraft_t : rEntity_t
{
	float			angle;
	float			health;			// ships physical condition :) Kinda unused, any rock will destroy your puny ship..
	int				livesLeft;		// lives left
	float			invulCount;		// after spawn you're invulnerable for a while, when this is <= you're not
	float			spawnCount;		// countdown to spawn
	float			damage;
	float			canFire;		// countdown to weapon fire (reload)
	float			canThrust;		// countdown to acceleration
	int				weaponLevel;	// weapon level
};


extern modExport_t*	clMod;			// defined in DllMain
extern clAPI_t*		cl;				// defined in DllMain


void		rInitMod ();
void		rShutdownMod ();

void		rInitGame ();

void		rDrawRocks ();
void		rDrawProjs ();

rProj_t*	rSpawnProj (vec2_t &from, vec2_t &vel, int frame);
rRock_t*	rSpawnRock (vec2_t &to, vec2_t &vel, float radius, int frame);

void		rFrame (float time);



#endif // ROKS_H
