#ifndef __UNITS_H__
#define __UNITS_H__

#define PI 3.1415926535897932384626433832795
#define UNITS_NUM_FRAMES  72

#include <string>
#include "SDL_mixer.h"
#include "graphics.h"
#include "fftfile.h"
#include "log.h"
#include "math.h"

#define AI_STATE_STOP     1000
#define AI_STATE_RUN      1001
#define AI_STATE_ATTACK   1002
#define AI_STATE_LOOK     1003
#define AI_STATE_IGNORE   1004
#define AI_STATE_WAITLOOK 1005

extern Mix_Chunk *explode;
extern Mix_Chunk *shot;
extern int SMOOTH;

typedef struct{
	std::string type;
	unsigned int priceBought;
}__cargo;

class Unit
{
public:
	Unit();
	~Unit();
	void Reset();
	void CleanUp();
	void Init(int sx, int sy, std::string img, std::string fpk, float zzoom);
	void Init(int sx, int sy, std::string img, SDL_Surface *img2, std::string fpk, float zzoom);
	void Display(int sx, int sy);
	void StatusDisplay(int sx, int sy, int sw, int sh, TTF_Font *font);
	void SetSpeed(int sSpeed);
	void SetAngle(int sAngle);
	void SetX(int sx);
	void SetY(int sy);
	void SetAI(std::string ai);
	void SetAIState(int state);
	void Move(int sx, int sy);
	void SetMMR(Uint8 sr);
	void SetMMG(Uint8 sg);
	void SetMMB(Uint8 sb);
	void SetWarp(bool sw);
	void SetName(std::string sname);
	void SetZoom(float szoom);
	void SetMaxSpeed(int ms);
	void SetMaxWarp(int mw);
	void SetMaxSafeWarp(int msw);
	void SetTurnDelay(int td);
	void SetWarpTurnDelay(int tdw);
	void SetHullHitMax(int hhm);
	void SetShieldHitMax(int shm);
	void SetOverHeatMax(int ohm);
	void SetShootPoint(int sx, int sy);
	void SetCredits(unsigned int cred);
	void SetPriceBought(unsigned int spricebought);
	void AdjustShootPoint();
	void ResetHits();
	void SetHullHits(int hh);
	void SetShieldHits(int sh);
	void PrevWeapon();
	void NextWeapon();
	void Rotate(int rotation);
	void EnableWarp();
	void DisableWarp();
	void AddShield(std::string shieldpic);
	void AddWeaponToSlot(int slotid, std::string fpk, std::string fn, int amount=0);
	void RemoveWeaponFromSlot(int slotid);
	void ReduceAmmo(int slotid);
	void AddWeaponBayToSlot(int slotid, std::string holdweapon, int holdamount);
	void RemoveWeaponBayFromSlot(int slotid);
	void AddCargoBayToSlot(int slotid, int units);
	void RemoveCargoBayFromSlot(int slotid);
	void AddToCargo(__cargo newcargo);
	void SortCargo();
	void RemoveFromCargo(int cargoindex);
	void RemoveAmountFromCargo(std::string type, int quantity);
	__ship_slot GetCurWeaponSlot();
	int GetWidth();
	int GetHeight();
	int GetImageWidth();
	int GetImageHeight();
	int GetDispImageW();
	int GetDispImageH();
	Uint8 GetMMR();
	Uint8 GetMMG();
	Uint8 GetMMB();
	int GetSpeed();
	int GetAngle();
	int GetX();
	int GetY();
	double GetDX();
	double GetDY();
	int GetNegX();
	int GetNegY();
	int GetSectorX();
	int GetSectorY();
	int GetMaxSpeed();
	int GetMaxWarp();
	int GetMaxSafeWarp();
	int GetTurnDelay();
	int GetWarpTurnDelay();
	int GetMaxHullHits();
	int GetHullHits();
	int GetMaxShieldHits();
	int GetShieldHits();
	int GetShootX();
	int GetShootY();
	unsigned int GetCredits();
	unsigned int GetPriceBought();
	int GetCargoUnits();
	int GetCargoFill();
	float GetZoom();
	std::string GetCurWeaponFN();
	std::string GetCurWeaponFPK();
	std::string GetName();
	bool AtWarp();
	bool WarpEnabled();
	bool HasShield();
	void Hit();
	bool IsAIFiring();
	bool IsOverHeated();
	void Orbit();
	void Orbit(int sx, int sy, int rad);
	void SetOrbit(bool orbit);
	bool IsOrbiter();
	void FreeImages();
	void FPK_NewImages(std::string fpk, std::string imagename);
	void ReloadImages();
	void LoadImages(int start, int end);
	bool IsLoaded(int pic);
	bool ShieldIsLoaded(int pic);
	SDL_Surface *GetCurImage();
	void DisplayDispImage(int x, int y);
	void ZeroSlots();
	void FillSlots(__ship_slot *sls, int max);
	__ship_slot *GetSlots();
	__cargo *GetCargo();
	int GetNumSlots();
	int GetHeatSeekingBay();
	int GetHeatSeekingAmmoFill();
	int GetHeatSeekingAmmoSpace();
	void Colorize(Uint8 r, Uint8 g, Uint8 b);
	bitmask *mask[UNITS_NUM_FRAMES];
	bitmask *smask[UNITS_NUM_FRAMES];
	int radius, orbitx, orbity;
private:
	int angleinc;
	int angle;
	double angle2;
	int speed;
	std::string imgload;
	std::string usingfpk;
	SDL_Surface *image[UNITS_NUM_FRAMES];
	SDL_Surface *dispimg;
	int x;
	int y;
	double dx;
	double dy;
	std::string aiscript;
	Uint32 aiwait;
	int aistate;
	int aiwaitfor;
	Uint8 mmr;
	Uint8 mmg;
	Uint8 mmb;
	Uint8 cr;
	Uint8 cg;
	Uint8 cb;
	bool warp;
	bool warpenabled;
	bool orbiter;
	std::string name;
	float zoom;
	SDL_Surface *shield[UNITS_NUM_FRAMES];
	std::string shieldload;
	bool hasShield;
	bool hadShield;
	int maxspeed;
	int maxwarp;
	int maxsafewarp;
	int turndelay;
	int warpturndelay;
	int curweapon;
	int overheatcount, overheatmax;
	Uint32 overheatwait;
	int hullhitmax, shieldhitmax, numshieldhits, numhullhits;
	int shootx, shooty, origshootx, origshooty;
	bool aifire;
	std::string curweaponfn;
	std::string curweaponfpk;
	__ship_slot slots[__MAXSHIPSLOTS];
	int numslots;
	unsigned int credits;
	unsigned int pricebought;
	int cargounits;
	int cargofill;
	__cargo cargo[1000];
};

#endif /* __UNITS_H__ */

