////////////////////////////////////////////////////////////////////////////////
// FighterAISpace.h
// AI class that controls a conventional or aerospace fighter
// Written by Björn Ganster since 2021
////////////////////////////////////////////////////////////////////////////////

#ifndef FighterAISpace__H
#define FighterAISpace__H

#include "AeroTech.h"
#include "VehicleAI.h"

#include <vector>

class FighterAISpace: public AbstractVehicleAI {
public:
	// Construct fighter AI
	FighterAISpace(AeroTech* aerotech);

	void setAim(double dx, double dy) OVERRIDE;

	bool weaponActive(int i, bool groupFire) const OVERRIDE;

	void planMovement(DWORD now) OVERRIDE;

	// Notify AI of an event, like a destroyed object
	void updateObjectStatus(const BGCPString& id, SubObjectiveType newStatus) OVERRIDE;

	// Set range where AI triggers
	void setTriggerRange(double newVal) OVERRIDE;

	// Add single goal to attack (possibly after sleep goal)
	void addAttackGoal(const BGCPString& target) OVERRIDE;

	// Add goals for AI
	void addGoals(const std::vector<AIGoal>& goals, bool clearExisting) OVERRIDE;

	// AI modes
	void fight(DWORD now);
	void checkWakeUp();
	void doAttack();
	void doDefend();
	void doInspect();
	void doVisit();

	// Set skills (will be reflected by other variables));
	void setPiloting(int newVal) OVERRIDE;
	//void setGunnery(int newVal) OVERRIDE; // Gunnery and piloting are the same for aerospace pilots?
protected:
	// Cast copy of mVehicle
	AeroTech* mAeroTech;

	// When an enemy enters this range, this vehicle will attack it
	double mTriggerRange;

	// When an obstacle enters this range, this vehicle will evade it
	double mEvadeRange;

	// When evading, this is the distance that needs to be reached before returning to attack mode
	double mSaveRange;

	// The GameObject the AI is currently evading
	GameObject* mEvadedObject;

	// When was the last weapon fired?
	DWORD mLastFired;

	// The position where this vehicle will fly around at low velocity
	Point3D mWaitPosition;

	// Number of milliseconds between AI frames used to move
	DWORD mMsBetweenMoveFrames;

	// How far the AI aim is off
	double mAimError;

	// Time stamp for the last frame where the AI aimed or moved
	DWORD mLastMoveFrame;

	// Goals for the AI
	size_t mCurrentGoal;
	std::vector<AIGoal> mGoals;

	// Piloting skill used by the AI - skill value 7 would normally be illegal, here it indicates a pilot
	// who will follow his flight plan blindly
	int mPiloting;

	// Fly towards given position
	double flyTowards(const Point3D& desiredPos, int env);
};

#endif
