#include "world.h"
#include <cstdio>
#include <cstring>
#include <cmath>

extern World *world;

void BotThink() {
	static float alpha = 0.0;

	//Send our turn and receive the update of the game world
	world->makeMove();

	//Print some information
	printf("frame : %d, HP: %.2lf x: %.2lf y:%.2lf\n",
			world->player.Time, world->player.HitPoints,
			world->player.PositionX, world->player.PositionY);

	alpha += 0.02;
	//Run in circles (set direction)
	world->run(cos(alpha), sin(alpha));

	//Choose the first monster that is still alive
	for ( int j = 0; j < world->MAXMONSTERS; j++)
		if (world->monsters[j].ClassName >= 0) {
			//Shoot the bastard! (Shoot in the direction of the monster)
			world->shoot(world->monsters[j].PositionX - world->player.PositionX,
					   world->monsters[j].PositionY - world->player.PositionY);
			break;
		}
}

#ifndef BOTWITHGLUT
World *world;
int main(int argc, char** argv) {
	if (argc < 3) {
		fprintf(stderr, "Parameters: IP port\n");
		return 666;
	}
	world = new World(argv[1], atoi(argv[2]));
	world->makeMove();
	while (1) {
		BotThink();
		world->makeMove();
	}
	printf("Game over!\n");
	delete world;
	return 0;
}
#endif
