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


using namespace std;

const std::string CrouchCommand::_id = "crouch";

CrouchCommand::CrouchCommand(Person *person, bool crouch)
:_person(person),
 _crouch( crouch )
{
}

CrouchCommand::CrouchCommand(List *command)
{
	command = command->rest();
	_person = (Person *)Level::instance()->getObject(command->firstString());
	command = command->rest();
	string crouch = command->firstString();
	if(crouch == "true")
		_crouch = true;
	else
		_crouch = false;
}

void CrouchCommand::execute()
{
	if( _crouch )
		_person->crouch();
	else
		_person->uncrouch();
}

std::string CrouchCommand::getString()
{
	List *command = new List();
	command->snoc(new Atom(_id));
	command->snoc(new Atom(_person->id()));
	if(_crouch)
		command->snoc(new Atom("true"));
	else
		command->snoc(new Atom("false"));
	string commandString = command->getString();
	delete command;

	return commandString;
}