#ifndef _AI_H
#define _AI_H

#include <vector>
#include <vamos/body/Gl_Car.h>
#include "bezier.h"
#include "track.h"

struct AI_Car
{
	AI_Car (Vamos_Body::Gl_Car* new_car) : car (new_car), shift_time(0.0),
		longitude_mu(0.9), lateral_mu(0.9),last_patch(NULL) {}
	Vamos_Body::Car* car;
	float shift_time;
	float longitude_mu; //friction coefficient of the tire - longitude direction
	float lateral_mu; //friction coefficient of the tire - lateral direction
	BEZIER* last_patch; //last patch the car was on, used in case car is off track
};
 
class AI
{
private:
	std::vector <AI_Car> AI_Cars;
	void updateGasBrake(AI_Car *c, float timefactor, float fps, TRACK* track_p);
	void calcMu(AI_Car *c, TRACK* track_p);
	float calcSpeedLimit(AI_Car *c, BEZIER* patch, float friction);
	float calcBrakeDist(AI_Car *c, float current_speed, float allowed_speed, float friction);
	void updateGear(AI_Car *c, float timefactor, float fps);
	float DownshiftPoint(AI_Car *c, int gear);
	void updateClutch(AI_Car *c, float timefactor, float fps);
	void updateSteer(AI_Car *c, float timefactor, float fps);


public:
	void add_car(Vamos_Body::Gl_Car* car) { AI_Cars.push_back(AI_Car(car)); };
	void clear_cars() { AI_Cars.clear(); } 
	void update(float timefactor, float fps, TRACK* track_p);
};

#endif //_AI_H
