/*
 * (C) Copyright Chris B. Kaynor 2006
 * All Rights Reserved.
 *
 * CONTACT: chris@kaynor.net
*/

#ifndef CBK_AI_H
#define CBK_AI_H

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <assert.h>
#include <ctime> 
#include <string.h>

#ifdef __linux__
	#include <GL/glut.h>
	#include <GL/glext.h>
	#include <png.h>
	#include <pngconf.h>
	#include <zlib.h>
	#include <zconf.h>
#else
	#include "glut.h"
	#include "glext.h"
	#include "png.h"
	#include "pngconf.h"
	#include "zlib.h"
	#include "zconf.h"
#endif

#include "vector.h"
#include "data.h"

int FireProjectile(unsigned int TankID) {
	Number_Projectiles++;

	if (Number_Projectiles >= Maximum_Projectiles) {
		Number_Projectiles--;
		return 1;
	}

	if (Tanks[TankID].CoolDownTime > 0) {
		Number_Projectiles--;
		return 2;
	}

	Tanks[TankID].CoolDownTime = RefireRate;

	Projectiles[Number_Projectiles].Firer = TankID;
	Projectiles[Number_Projectiles].move(Tanks[TankID].get_position());
	Projectiles[Number_Projectiles].rotate(Tanks[TankID].get_rotation());
	Projectiles[Number_Projectiles].change_movement_speed(1);
	Projectiles[Number_Projectiles].update(1);
	Projectiles[Number_Projectiles].change_movement_speed(Tanks[TankID].get_movement_speed() + BaseProjectileSpeed);
	Projectiles[Number_Projectiles].SetLifeTime(ProjectileLife);
	Projectiles[Number_Projectiles].SetCollsionSize(0.1);

	Tanks[TankID].ShotsFired++;
	Tanks[TankID].Score -= BulletPointCost;

	return 0;
}

void RunAI(cbk_object_data_tank TankData[], long AITankID, GLfloat Dt) { 
	if (GetRandom(0, 100) <= (40 * Dt)) {
		FireProjectile(AITankID);
	}
	if (GetRandom(0, 100) <= (90 * Dt)) {
		TankData[AITankID].change_rotation_speed(TankData[AITankID].get_rotation_speed() + 5);
		if (TankData[AITankID].get_rotation_speed() > MaxRotationSpeed) {
			TankData[AITankID].change_rotation_speed(MaxRotationSpeed);
		}
	}
}

#endif //CBK_AI_H