metaforce/Runtime/World/CScriptRelay.cpp

70 lines
1.9 KiB
C++
Raw Permalink Normal View History

#include "Runtime/World/CScriptRelay.hpp"
#include "Runtime/CStateManager.hpp"
#include "TCastTo.hpp" // Generated file, do not modify include path
2021-04-10 01:42:06 -07:00
namespace metaforce {
2017-11-12 22:19:18 -08:00
CScriptRelay::CScriptRelay(TUniqueId uid, std::string_view name, const CEntityInfo& info, bool active)
2018-12-07 21:30:43 -08:00
: CEntity(uid, info, active, name) {}
2018-12-07 21:30:43 -08:00
void CScriptRelay::Accept(IVisitor& visitor) { visitor.Visit(this); }
2017-01-14 19:07:01 -08:00
2018-12-07 21:30:43 -08: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) {
2018-12-07 21:30:43 -08:00
return;
}
2016-07-25 19:33:32 -07:00
2018-12-07 21:30:43 -08: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-25 19:33:32 -07:00
2018-12-07 21:30:43 -08:00
tmp = obj->x34_nextRelay;
}
2016-07-25 19:33:32 -07:00
2018-12-07 21:30:43 -08:00
if (tmp == kInvalidUniqueId) {
x34_nextRelay = stateMgr.GetLastRelayId();
stateMgr.SetLastRelayId(GetUniqueId());
2016-07-25 19:33:32 -07:00
}
2018-12-07 21:30:43 -08:00
}
2016-07-25 19:33:32 -07:00
}
2018-12-07 21:30:43 -08:00
void CScriptRelay::Think(float, CStateManager& stateMgr) {
if (x38_sendCount == 0) {
2018-12-07 21:30:43 -08:00
return;
}
2016-07-25 19:33:32 -07:00
2018-12-07 21:30:43 -08:00
while (x38_sendCount != 0) {
x38_sendCount--;
SendScriptMsgs(EScriptObjectState::Zero, stateMgr, EScriptObjectMessage::None);
}
UpdateObjectRef(stateMgr);
2016-07-25 19:33:32 -07:00
}
2018-12-07 21:30:43 -08:00
void CScriptRelay::UpdateObjectRef(CStateManager& stateMgr) {
TUniqueId* tmp = stateMgr.GetLastRelayIdPtr();
while (tmp != nullptr && *tmp != kInvalidUniqueId) {
if (*tmp == GetUniqueId()) {
*tmp = x34_nextRelay;
return;
2016-07-25 19:33:32 -07:00
}
auto* obj = static_cast<CScriptRelay*>(stateMgr.ObjectById(*tmp));
if (obj == nullptr) {
2018-12-07 21:30:43 -08:00
return;
}
2018-12-07 21:30:43 -08:00
tmp = &obj->x34_nextRelay;
}
}
2021-04-10 01:42:06 -07:00
} // namespace metaforce