metaforce/Runtime/World/CEntity.cpp

53 lines
1.6 KiB
C++
Raw Normal View History

#include "Runtime/World/CEntity.hpp"
#include "Runtime/CStateManager.hpp"
2015-08-19 05:48:57 +00:00
2021-04-10 08:42:06 +00:00
namespace metaforce {
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)
2018-12-08 05:30:43 +00:00
: x4_areaId(info.GetAreaId())
, x8_uid(uniqueId)
, xc_editorId(info.GetEditorId())
, x10_name(name)
, x20_conns(info.GetConnectionList())
, x30_24_active(active)
, x30_27_inUse(x4_areaId != kInvalidAreaId) {}
2015-08-19 05:48:57 +00:00
2018-12-08 05:30:43 +00:00
void CEntity::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager& stateMgr) {
switch (msg) {
case EScriptObjectMessage::Activate:
if (!GetActive()) {
SetActive(true);
SendScriptMsgs(EScriptObjectState::Active, stateMgr, EScriptObjectMessage::None);
2015-08-19 05:48:57 +00:00
}
2018-12-08 05:30:43 +00:00
break;
case EScriptObjectMessage::Deactivate:
if (GetActive()) {
SetActive(false);
SendScriptMsgs(EScriptObjectState::Inactive, stateMgr, EScriptObjectMessage::None);
}
break;
case EScriptObjectMessage::ToggleActive:
if (GetActive()) {
SetActive(false);
SendScriptMsgs(EScriptObjectState::Inactive, stateMgr, EScriptObjectMessage::None);
} else {
SetActive(true);
SendScriptMsgs(EScriptObjectState::Active, stateMgr, EScriptObjectMessage::None);
}
break;
default:
break;
}
2015-08-19 05:48:57 +00:00
}
2018-12-08 05:30:43 +00:00
void CEntity::SendScriptMsgs(EScriptObjectState state, CStateManager& stateMgr, EScriptObjectMessage skipMsg) {
2020-04-15 11:27:06 +00:00
for (const SConnection& conn : x20_conns) {
if (conn.x0_state == state && conn.x4_msg != skipMsg) {
2018-12-08 05:30:43 +00:00
stateMgr.SendScriptMsg(x8_uid, conn.x8_objId, conn.x4_msg, state);
2020-04-15 11:27:06 +00:00
}
}
2015-08-19 05:48:57 +00:00
}
2021-04-10 08:42:06 +00:00
} // namespace metaforce