metaforce/Runtime/World/CEntity.cpp

53 lines
1.7 KiB
C++
Raw Normal View History

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-03-04 23:04:53 +00:00
namespace urde
2015-08-19 05:48:57 +00:00
{
2016-04-22 20:22:45 +00:00
const std::vector<SConnection> CEntity::NullConnectionList;
2015-08-19 05:48:57 +00:00
2016-04-20 21:44:18 +00:00
CEntity::CEntity(TUniqueId uniqueId, const CEntityInfo& info, bool active, const std::string& name)
2016-04-22 20:22:45 +00:00
: x4_areaId(info.GetAreaId()), x8_uid(uniqueId), xc_editorId(info.GetEditorId()), x10_name(name),
x20_conns(info.GetConnectionList()), x30_24_active(active) {}
2015-08-19 05:48:57 +00:00
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)
{
2016-04-20 21:44:18 +00:00
for (const SConnection& conn : x20_conns)
if (conn.x0_state == state && conn.x4_msg != skipMsg)
stateMgr.SendScriptMsg(x8_uid, conn.x8_objId, conn.x4_msg, state);
2015-08-19 05:48:57 +00:00
}
}