metaforce/Runtime/World/CScriptRelay.cpp

83 lines
2.0 KiB
C++
Raw Normal View History

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