//Copyright (C) 2007 SiegeLord
//See ReadMe.txt and License.txt for copying information

#pragma once

#include "neonz.h"
#include "objectex.h"
#include "quadtree.h"

struct SOrder;
struct SQuadNode;
struct SThrusterParticleHolder;
struct SWeaponSlot;

struct SShip : SCollidableObject
{
	SShip()
	{
		type = genericship_type;
		selected = false;
		dead = false;
		flashy_timer = 0;
	}
	//our new coordinate system
	//radius, theta
	vector2d polar_pos;
	vector2d polar_vel;
	vector2d polar_accel;
	vector2d polar_max_vel;

	//the player who owns this ship
	int player;

	float hitpoints;
	float max_hitpoints;
	
	float armour;

	SBitmap* image;

	//range where we seek enemies to attack
	float sense_range;

	void UpdatePolarPosition();
	void UpdatePolarRotation();
	void DeActivateAllThrusters();
	//right, top, left, bottom
	void ActivateThrusters(int bank, float goal_vel);
	void TargetAllWeapons(vector2d& target_loc, SShip* target_ship);
	void CeaseFire();
	float GetSmallestWeaponRange();

	bool selected;
	int ID;//the id of the ship in the registry

	float flashy_timer;//used when we attack it

	void SetPolarPosition(float r, float theta);
	
	void Damage(float min_damage, float max_damage, float fraction = 1.0f);

	list<SOrder*> order_list;//ah geez!

	vector<SThrusterParticleHolder*> top_thrusters;
	vector<SThrusterParticleHolder*> left_thrusters;
	vector<SThrusterParticleHolder*> right_thrusters;
	vector<SThrusterParticleHolder*> bottom_thrusters;

	vector<SWeaponSlot*> weapon_slots;

	virtual ~SShip();
	virtual int Handle();
	virtual void Draw();
};

SShip* CreateShip(SObject* parent);
SShip* CreateMotherShip(SObject* parent);
