Let's assume I have a CEntity
class that describes every entity within the game.
Each entity class has it's own std::vector
of CAction
s. Each CAction
is just an action that the entities can perform, for example CActionFight
would have the logic for fighting.
To command my player (or any other entity) to fight all I do is:
CActionFight *pActionFight = new CActionFight();
pActionFight->SetTarget(pTargetEntity);
pPlayer->AddAction(pActionFight);
Before this action is started, all other actions queued earlier have to be finished. Imagine player starting to execute the CActionFight
over pTargetEntity
and suddenly, pTargetEntity
disconnects. pTargetEntity
is invalid and here's my question.
How do you normally handle that in actions?
If a disconnection event of an entity is received on the server side, do you iterate through the actions of all entity in the map and remove these which are related to an entity that has just dropped connection?
EDIT Liked Josh's approach and implemented the solution, sounds very sensible and worked like a charm.
// Example of an action, checking wether Entity is still valid.
void CActionFight::Execute()
{
m_iCycles--;
if(m_iCycles>0)
{
if(m_pTarget->IsValid() == false)
{
m_pTarget = NULL;
m_bValid = false;
}
else
{
printf("Attacking.%s\n", m_pTarget->GetName().data());
}
}
else m_bValid = false;
}