2016-05-18 03:57:43 +00:00
|
|
|
#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"
|
2016-05-18 03:57: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)
|
2016-05-18 03:57:43 +00:00
|
|
|
: CEntity(uid, info, active, name)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-01-15 03:07:01 +00:00
|
|
|
void CScriptRelay::Accept(IVisitor& visitor)
|
|
|
|
{
|
|
|
|
visitor.Visit(this);
|
|
|
|
}
|
|
|
|
|
2016-07-25 06:24:57 +00:00
|
|
|
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
|
|
|
}
|
2016-07-25 06:24:57 +00:00
|
|
|
}
|
|
|
|
|
2016-05-18 03:57:43 +00:00
|
|
|
}
|