metaforce/Runtime/World/CEntity.cpp

57 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
2017-11-13 06:19:18 +00:00
CEntity::CEntity(TUniqueId uniqueId, const CEntityInfo& info, bool active, std::string_view name)
2016-04-22 20:22:45 +00:00
: x4_areaId(info.GetAreaId()), x8_uid(uniqueId), xc_editorId(info.GetEditorId()), x10_name(name),
2017-01-25 04:40:19 +00:00
x20_conns(info.GetConnectionList())
{
x30_24_active = active;
2018-11-17 05:05:57 +00:00
x30_27_inUse = x4_areaId != kInvalidAreaId;
2017-01-25 04:40:19 +00:00
}
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
}
}