Show EntityController.cpp syntax highlighted
#include "StdAfx.h"
#include "EntityController.h"
#include "EntityEvents.h"
#include "EntityManager.h"
#include "IEntity.h"
#include "../kernel.h"
extern Kernel* g_kernel;
#define TIME g_kernel->GetTime()
/**
=============================
Construct a controller object
registering the listener
=============================
*/
EntityController::EntityController(void) : IEventListener()
{
m_entity = NULL;
EventManager::GetInstance()->AddListener(this);
}
/**
=============================
Deconstructor - destroy
=============================
*/
EntityController::~EntityController(void)
{
EventManager::GetInstance()->RemoveListener(this);
IEventListener::~IEventListener();
}
/**
* Handle a giving event, switch the entities state
* based off the FSM
*/
bool EntityController::HandleEvent( IEvent* e )
{
switch( e->GetType() )
{
/*--- entity event ----*/
case EVT_ENTITY:
EntityEvents* evt = e->GetData<EntityEvents>();
if ( m_entity->GetID() != evt->ent_id ) return false;
int actions = evt->buttons;
m_entity->m_actions = actions;
//// The entity is attempting to attack
//if ( actions & BUTTON_ATTACK1 )
//{
// if ( m_entity->CarryingEntity() )
// {
// m_entity->Throw();
// }
// else
// {
// m_entity->m_nextUpdate = TIME + 450; // TEMP
// m_entity->SetState( ENT_STATES[ATTACKING1] );
// return true;
// }
//}
//// The entity is attempting to 'use'
//if ( actions & BUTTON_USE )
//{
// if ( m_entity->CarryingEntity() )
// {
// m_entity->Throw();
// }
// else
// {
// // search for an entity in a region -- TODO THIS IS HORRIBLY SLOW!!!
// IEntity* ent = EntityManager::GetInstance()->FindInRegion( m_entity->GetReachRectangle(), m_entity );
//
// if ( ent )
// {
// if ( ent->m_attributes.Has( "dialog" ) )
// {
// ent->SetFace( (m_entity->GetFace() + 2) % 4);
// ent->SetState( ENT_STATES[TALKING] );
// }
// else if ( ent->m_attributes.Has( "liftable" ) )
// {
// if ( !m_entity->CarryingEntity() )
// {
// m_entity->Carry( ent );
// }
// }
// }
// }
// return true;
//}
//// Check for movement
//if ( m_entity->m_velocity.Length() )
//{
// // switch the state to walking
// if ( m_entity->CarryingEntity() )
// {
// m_entity->SetState( ENT_STATES[CARRYING_WALKING] );
// }
// else
// {
// m_entity->SetState( ENT_STATES[WALKING] );
// }
//}
//else
//{
// // switch the state to idle
// if ( m_entity->CarryingEntity() )
// {
// m_entity->SetState( ENT_STATES[CARRYING] );
// }
// else
// {
// m_entity->SetState( ENT_STATES[IDLE] );
// }
//}
//break;
///*--- entity is moving ----*/
//case EVT_MOVE:
// m_entity->m_velocity.Set( e->GetData<EntityMovement>()->m_velocity );
// // switch the state to walking
// if ( m_entity->CarryingEntity() )
// {
// m_entity->SetState( ENT_STATES[CARRYING_WALKING] );
// }
// else
// {
// m_entity->SetState( ENT_STATES[WALKING] );
// }
// break;
///*--- entity is attacking ----*/
//case EVT_ATTACK:
// if ( m_entity->CarryingEntity() )
// {
// m_entity->Throw();
// }
// else
// {
// m_entity->SetState( ENT_STATES[ATTACKING1] );
// }
// break;
///*--- entity is using ----*/
//case EVT_USE:
// if ( m_entity->CarryingEntity() )
// {
// m_entity->Throw();
// }
// else
// {
// // TODO - search around for lifting/talking ?
// }
// break;
};
return true;
}
See more files for this project here