/*
Copyright (C) 2015  E.J.M. Martens

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/


#ifndef _SHIP
#define _SHIP


#include <allegro5/allegro.h>
#include <allegro5/allegro_image.h>
#include <allegro5/allegro_primitives.h>
#include <allegro5/allegro_font.h>
#include <allegro5/allegro_ttf.h>
#include <allegro5/allegro_audio.h>
#include <vector>
#include <string>
#include "types.h"
#include "Engine.h"


using namespace std;


class TShip:public TSprite
{
private:


protected:
    AI m_AI;

void SetSpeed(double a_dSpeed);

ID  m_PreferedBase;

double m_dSteer,
	   m_dAngleSeek,
	   m_dTargetDistance,
	   m_dViewDistance,
	   m_dPhaserX,
	   m_dPhaserY,
	   m_dSafePosX,
	   m_dSafePosY,
	   m_dMaxSpeed,
	   m_dWaypointX,
	   m_dWaypointY,
	   m_dPhaserAngle,
	   m_dAimangle;

int m_nRepairItem,
	m_nCrew,
	m_nPhaserEnergy,
	m_nPreferedTarget,
	m_nPhaserPower,
	m_nTorpedoes,
	m_nFlyheight,
	m_nEnergyTimer,
	m_nRepairTimer,
	m_nPhaserFireTimer,
	m_nPhaserTimer,
	m_nPhaserWait,
	m_nShieldTimer,
	m_nPhotonTimer,
	m_nCloakCounter,
	m_nCloakCharge,
	m_nTranslucency;


public:
bool m_blPhaserOn,
     m_blShieldOn,
	 m_blDocked,
	 m_blDocking,
	 m_blCanCloak,
	 m_blReleasing;

int m_nTask,
    m_nMaxShieldEnergy,
    m_nShieldEnergy,
    m_nEnergy,
    m_nCloakState;

ALLEGRO_COLOR m_PhaserColor;
TShip * m_pTarget;
TShip * m_pBaseTarget;
//TEngine * m_pOwner;
string m_strName;

vector<int> m_lstHealth;
int m_nMaxHealth;

// game conditions
bool m_blMustBeDestroyed,
	 m_blMustSurvive,
     m_blMustReachPosition,
     m_blDock,
     m_blNoRelease;


TShip();
~TShip();

double WayPoint(double a_dX,double a_dY);
double GetX();
double GetY();
double GetSpeed();
double GetAngle();
int GetCloackState();

virtual void DoEngineering();
virtual void CalcPhaserDamage(double a_dEnergy, int a_nTarget);
virtual void DoCollision(TSprite * a_pSprite);
virtual void DoCloak();
virtual void Draw(double a_dCamX, double a_dCamY);
virtual void Explode();
virtual void Control();


bool Dock(TShip * a_pBaseTarget);
bool TryEnterDocking();
void Release(TShip * a_pBaseTarget);
void PrecalcFireAngles(int a_nLimit);
void LooseTarget();
double CalcVolume();

friend class TEngine;
};




#endif


