
#include "ActionWait.h"
#include "Unit.h"
#include "MemoryManager/debugNew.h"

ActionWait::ActionWait(Unit * u,unitEnumeration::UnitState state) : UnitAction(u,state)
{
	unit = u;
	nbTop = -1;
}

ActionWait::ActionWait(Unit * u,unitEnumeration::UnitState state, int nbWait) : UnitAction(u,state)
{
	unit = u;
	nbTop = nbWait;
}

ActionWait::~ActionWait(void)
{
}

void ActionWait::execute()
{
	/**
	 * on restaure l'etat de l'unité
	 */
	unit->setState(this->unitState);
	unit->allowDust(false);
	if (unit->getCurrentAnimation() != RenderSystem::RenderableEntity::WAIT){
		unit->setAnimation(RenderSystem::RenderableEntity::WAIT,unit->isMounted());
	}
	if(nbTop > 0) {
		--nbTop;
		unit->pushAction(this);
	}else if (nbTop < 0){
		unit->pushAction(this);
	}else{
		// on a fini d'attendre, on supprime l'action
		dispose();		
	}
}
