////////////////////////////////////////////////////////////////////////////////
// CombatVehicle.h
// Copyright Bjoern Ganster
// Developed since 2021
////////////////////////////////////////////////////////////////////////////////

#ifndef CombatVehicle__h
#define CombatVehicle__h

#include "Vehicles.h"

////////////////////////////////////////////////////////////////////////////////
// Since the majority of the code for vehicles will be shared among the vehicle 
// types, there will be only one class to cover them. CombatVehicleTypes 
// describes the exact vehicle subclass.

class CombatVehicle: public Vehicle {
public:
	// Constructor
	CombatVehicle(CombatVehicleTypes subType);

	// Destructor
	~CombatVehicle() OVERRIDE;

	// Load vehicle from XML
	void readSpecialAttributes(XMLTreeConstIterator& iter, const std::vector<RenderableObject*>& geometries, const PathChar* mechDir) OVERRIDE;
	void readSpecialAttributesFromRoot(XMLTreeConstIterator& iter) OVERRIDE;

	// Show or hide the vehicle's windshiled (cockpit view may require it to be hidden)
	void windshieldVisible(bool newVal) OVERRIDE;

	// Set direction where the vehicle is aiming, by moving the turret (vehicles) or twisting and tilting the torso (mechs)
	void setAim(double turn, double tilt) OVERRIDE;

	// Set current animation matrices
	void setMatrices(double speed, DWORD missionTime) OVERRIDE;

	// Get tilt and turn for current aim direction
	double getAimTilt() const OVERRIDE;
	double getAimTurn() const OVERRIDE;

	// Move aim towards given angles by at most delta
	void adjustAim(double desiredTorsoTwist, double desiredTorsoTilt, double delta) OVERRIDE;

	// Get mesh used for the cockpit
	Mesh* getCockpitMesh() OVERRIDE;

	// Check for a collision with a polygon and handle it
	void checkCollision(const MeshPolygon* poly, Point3D& movement) OVERRIDE;

	// Based on the vehicle type, connect the vehicle to a suitable AI
	AbstractVehicleAI* createAI(bool isPlayer, int environment) OVERRIDE;

	bool reticleMovesVertically() const OVERRIDE;

	// Calculate heat for next frame
	void calcNextFrameHeat(DWORD now, double deltaT) OVERRIDE;

	// Get current heat value for vehicle
	double getHeat() const NOEXCEPT OVERRIDE;

	// Calculate movement for next frame
	void calcNextFrameMovement(double deltaT, RenderableObject* scene, DWORD now, double gravity) OVERRIDE;

	// Query damage to armor
	double getArmorDamage(int section, int type) const OVERRIDE;

	// Query armor
	DWORD getArmor(int section, int ArmorType) const OVERRIDE;

private:
	ENUM_CLASS CombatVehicleSections {
		body,
		cockpit,
		turret,
		windshield,
		rotor
	};

	CombatVehicleTypes mSubType;
	double mTurretTurn, mTurretTilt, mTurretTurnLimit, mTurretTiltLimit;

	// Help function for parsing that translates a section name to a number
	int getSectionByName(const BGCPString& str) OVERRIDE;
};

#endif

