2015-08-19 05:48:57 +00:00
|
|
|
#include "CEntity.hpp"
|
2015-08-22 01:58:41 +00:00
|
|
|
#include "CStateManager.hpp"
|
2015-08-19 05:48:57 +00:00
|
|
|
|
2016-02-13 09:02:47 +00:00
|
|
|
namespace pshag
|
2015-08-19 05:48:57 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
CEntity::CEntity(TUniqueId uniqueId, const CEntityInfo& info, bool active)
|
|
|
|
: m_uid(uniqueId), m_info(info), m_active(active) {}
|
|
|
|
|
|
|
|
void CEntity::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager& stateMgr)
|
|
|
|
{
|
|
|
|
switch (msg)
|
|
|
|
{
|
2015-11-21 01:16:07 +00:00
|
|
|
case EScriptObjectMessage::Activate:
|
2015-08-19 05:48:57 +00:00
|
|
|
if (!GetActive())
|
|
|
|
{
|
|
|
|
SetActive(true);
|
2015-11-21 01:16:07 +00:00
|
|
|
SendScriptMsgs(EScriptObjectState::Active, stateMgr, EScriptObjectMessage::None);
|
2015-08-19 05:48:57 +00:00
|
|
|
}
|
|
|
|
break;
|
2015-11-21 01:16:07 +00:00
|
|
|
case EScriptObjectMessage::Deactivate:
|
2015-08-19 05:48:57 +00:00
|
|
|
if (GetActive())
|
|
|
|
{
|
|
|
|
SetActive(false);
|
2015-11-21 01:16:07 +00:00
|
|
|
SendScriptMsgs(EScriptObjectState::Inactive, stateMgr, EScriptObjectMessage::None);
|
2015-08-19 05:48:57 +00:00
|
|
|
}
|
|
|
|
break;
|
2015-11-21 01:16:07 +00:00
|
|
|
case EScriptObjectMessage::ToggleActive:
|
2015-08-19 05:48:57 +00:00
|
|
|
if (GetActive())
|
|
|
|
{
|
|
|
|
SetActive(false);
|
2015-11-21 01:16:07 +00:00
|
|
|
SendScriptMsgs(EScriptObjectState::Inactive, stateMgr, EScriptObjectMessage::None);
|
2015-08-19 05:48:57 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetActive(true);
|
2015-11-21 01:16:07 +00:00
|
|
|
SendScriptMsgs(EScriptObjectState::Active, stateMgr, EScriptObjectMessage::None);
|
2015-08-19 05:48:57 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CEntity::SendScriptMsgs(EScriptObjectState state, CStateManager& stateMgr, EScriptObjectMessage skipMsg)
|
|
|
|
{
|
|
|
|
for (const SConnection& conn : m_info.m_conns)
|
|
|
|
if (conn.state == state && conn.msg != skipMsg)
|
|
|
|
stateMgr.SendScriptMsg(m_uid, conn.objId, conn.msg, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|