metaforce/Runtime/World/CScriptRelay.cpp

83 lines
1.9 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
{
CScriptRelay::CScriptRelay(TUniqueId uid, const std::string& 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)
{
if (x30_24_active)
return;
2017-01-18 22:30:02 +00:00
x38_refCount++;
TUniqueId tmp = stateMgr.GetLastRelayId();
2016-07-26 02:33:32 +00:00
while (tmp != kInvalidUniqueId)
{
const CEntity* obj = stateMgr.GetObjectById(tmp);
if (!obj)
{
2017-01-18 22:30:02 +00:00
tmp = x34_nextRelay;
2016-07-26 02:33:32 +00:00
continue;
}
if (obj->GetUniqueId() == tmp)
break;
}
if (tmp == kInvalidUniqueId)
return;
2017-01-18 22:30:02 +00:00
x34_nextRelay = stateMgr.GetLastRelayId();
stateMgr.SetLastRelayId(GetUniqueId());
2016-07-26 02:33:32 +00:00
}
}
void CScriptRelay::Think(float, CStateManager& stateMgr)
{
2017-01-18 22:30:02 +00:00
if (x38_refCount == 0)
2016-07-26 02:33:32 +00:00
return;
2017-01-18 22:30:02 +00:00
while (x38_refCount != 0)
2016-07-26 02:33:32 +00:00
{
2017-01-18 22:30:02 +00:00
x38_refCount--;
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();
2016-07-26 02:33:32 +00:00
while (*tmp != kInvalidUniqueId && tmp != nullptr)
{
if (*tmp == GetUniqueId())
{
2017-01-18 22:30:02 +00:00
*tmp = x34_nextRelay;
2016-07-26 02:33:32 +00:00
return;
}
2017-01-18 22:30:02 +00:00
CScriptRelay* obj = dynamic_cast<CScriptRelay*>(stateMgr.ObjectById(*tmp));
if (obj == nullptr)
return;
tmp = &obj->x34_nextRelay;
2016-07-26 02:33:32 +00:00
}
}
}