#include "Command.h"
#include "Person.h"
#include "List.h"
#include "Level.h"
#include "Player.h"

#include <iostream>

using namespace std;

const std::string FollowPlayerCommand::_id = "followPlayer";

FollowPlayerCommand::FollowPlayerCommand(Person *person)
:_person(person)
{
}

FollowPlayerCommand::FollowPlayerCommand(List *command)
{
	command = command->rest();
	_person = (Person *)Level::instance()->getObject(command->firstString());
}
void FollowPlayerCommand::execute()
{
	Player* player = Level::instance()->getPlayer();
	int dist = player->getBox().x-_person->getBox().x;
	xDirection dir;
	if (dist > 0)
		dir = RIGHT;
	else
		dir = LEFT;
	MoveCommand(_person,dir).execute();
}
std::string FollowPlayerCommand::getString()
{
	List *command = new List();
	command->snoc(new Atom(_id));
	command->snoc(new Atom(_person->id()));

	string commandString = command->getString();
	delete command;

	return commandString;
}