metaforce/Runtime/World/CScriptRelay.cpp

67 lines
1.8 KiB
C++
Raw Normal View History

#include "Runtime/World/CScriptRelay.hpp"
#include "Runtime/CStateManager.hpp"
#include "TCastTo.hpp" // Generated file, do not modify include path
2018-12-08 05:30:43 +00:00
namespace urde {
2017-11-13 06:19:18 +00:00
CScriptRelay::CScriptRelay(TUniqueId uid, std::string_view name, const CEntityInfo& info, bool active)
2018-12-08 05:30:43 +00:00
: CEntity(uid, info, active, name) {}
2018-12-08 05:30:43 +00:00
void CScriptRelay::Accept(IVisitor& visitor) { visitor.Visit(this); }
2017-01-15 03:07:01 +00:00
2018-12-08 05:30:43 +00:00
void CScriptRelay::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager& stateMgr) {
CEntity::AcceptScriptMsg(msg, objId, stateMgr);
if (msg == EScriptObjectMessage::Deleted) {
UpdateObjectRef(stateMgr);
} else if (msg == EScriptObjectMessage::SetToZero) {
if (!x30_24_active)
return;
2016-07-26 02:33:32 +00:00
2018-12-08 05:30:43 +00:00
x38_sendCount++;
TUniqueId tmp = stateMgr.GetLastRelayId();
while (tmp != GetUniqueId() && tmp != kInvalidUniqueId) {
const CScriptRelay* obj = static_cast<const CScriptRelay*>(stateMgr.GetObjectById(tmp));
if (!obj) {
tmp = kInvalidUniqueId;
break;
}
2016-07-26 02:33:32 +00:00
2018-12-08 05:30:43 +00:00
tmp = obj->x34_nextRelay;
}
2016-07-26 02:33:32 +00:00
2018-12-08 05:30:43 +00:00
if (tmp == kInvalidUniqueId) {
x34_nextRelay = stateMgr.GetLastRelayId();
stateMgr.SetLastRelayId(GetUniqueId());
2016-07-26 02:33:32 +00:00
}
2018-12-08 05:30:43 +00:00
}
2016-07-26 02:33:32 +00:00
}
2018-12-08 05:30:43 +00:00
void CScriptRelay::Think(float, CStateManager& stateMgr) {
if (x38_sendCount == 0)
return;
2016-07-26 02:33:32 +00:00
2018-12-08 05:30:43 +00:00
while (x38_sendCount != 0) {
x38_sendCount--;
SendScriptMsgs(EScriptObjectState::Zero, stateMgr, EScriptObjectMessage::None);
}
UpdateObjectRef(stateMgr);
2016-07-26 02:33:32 +00:00
}
2018-12-08 05:30:43 +00:00
void CScriptRelay::UpdateObjectRef(CStateManager& stateMgr) {
TUniqueId* tmp = stateMgr.GetLastRelayIdPtr();
while (tmp != nullptr && *tmp != kInvalidUniqueId) {
if (*tmp == GetUniqueId()) {
*tmp = x34_nextRelay;
return;
2016-07-26 02:33:32 +00:00
}
2018-12-08 05:30:43 +00:00
CScriptRelay* obj = static_cast<CScriptRelay*>(stateMgr.ObjectById(*tmp));
if (obj == nullptr)
return;
tmp = &obj->x34_nextRelay;
}
}
2018-12-08 05:30:43 +00:00
} // namespace urde