#include "SoccerField.h"

SoccerPlayer::SoccerPlayer() {
	position.X = 50;
	position.Y = 30;
	velocity.X = velocity.Y = 0;
	radius = PLAYER_RADIUS;
}
SoccerBall::SoccerBall() {
	position.X = 50;
	position.Y = 30;
	velocity.X = velocity.Y = 0;
	radius = BALL_RADIUS;
}

void SoccerField::FillDatagram(DATAGRAM *d)
{
	d->team = ntohl(CURRENT_TEAM);
	if (CURRENT_TEAM) {
		for (int i=0; i<NUM_PLAYERS; i++) {
			d->team1[i].vx = htonf(team1[i].velocity.X);
			d->team1[i].vy = htonf(team1[i].velocity.Y);
			d->team1[i].kick = htonf(team1[i].kick);
			if (team1[i].kick>0) team1[i].kick = 0.0;
		}
	} else {
		for (int i=0; i<NUM_PLAYERS; i++) {
			d->team0[i].vx = htonf(team0[i].velocity.X);
			d->team0[i].vy = htonf(team0[i].velocity.Y);
			d->team0[i].kick = htonf(team0[i].kick);
			if (team0[i].kick>0) team0[i].kick = 0.0;
		}
	}
}

void SoccerField::ReadDatagram(DATAGRAM *d)
{
	for (int i=0; i<NUM_PLAYERS; i++) {
		team0[i].position.X = ntohf(d->team0[i].x);
		team0[i].position.Y = ntohf(d->team0[i].y);
		team1[i].position.X = ntohf(d->team1[i].x);
		team1[i].position.Y = ntohf(d->team1[i].y);
	}
	ball.position.X = ntohf(d->ball.x);		ball.position.Y = ntohf(d->ball.y);
	ball.velocity.X = ntohf(d->ball.vx);	ball.velocity.Y = ntohf(d->ball.vy);
	paused = ntohl(d->paused);
	score[0] = ntohl(d->score[0]);		score[1] = ntohl(d->score[1]);
}

