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

using namespace std;

const std::string SetPositionCommand::_id = "setPosition";

SetPositionCommand::SetPositionCommand(Object *object, int xPos, int yPos)
:_object(object->id()),_xPos(xPos),_yPos(yPos)
{
	
}

SetPositionCommand::SetPositionCommand(List *command)
{
	command = command->rest();
	_object = command->firstString();
	command = command->rest();
	_xPos = command->firstInt();
	command = command->rest();
	_yPos = command->firstInt();
}

void SetPositionCommand::execute()
{
	Object *object = Level::instance()->getObject(_object);
	if(object == NULL)
		return;
	object->setPos(_xPos,_yPos);
}

std::string SetPositionCommand::getString()
{
	List *command = new List();
	command->snoc(new Atom(_id));
	command->snoc(new Atom(_object));
	command->snoc(new Atom(_xPos));
	command->snoc(new Atom(_yPos));
	string commandString = command->getString();
	delete command;

	return commandString;
}