2016-05-18 03:57:43 +00:00
|
|
|
#include "CScriptRandomRelay.hpp"
|
2016-07-25 06:24:57 +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
|
|
|
CScriptRandomRelay::CScriptRandomRelay(TUniqueId uid, std::string_view name, const CEntityInfo& info, s32 connCount, s32 variance,
|
2016-05-18 03:57:43 +00:00
|
|
|
bool clamp, bool active)
|
|
|
|
: CEntity(uid, info, active, name),
|
|
|
|
x34_connectionCount((clamp && connCount > 100) ? 100 : connCount),
|
|
|
|
x38_variance(variance),
|
|
|
|
x3c_clamp(clamp)
|
|
|
|
{
|
|
|
|
}
|
2016-07-25 06:24:57 +00:00
|
|
|
|
2017-01-15 03:07:01 +00:00
|
|
|
void CScriptRandomRelay::Accept(IVisitor& visitor)
|
|
|
|
{
|
|
|
|
visitor.Visit(this);
|
|
|
|
}
|
|
|
|
|
2016-07-25 06:24:57 +00:00
|
|
|
void CScriptRandomRelay::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager& stateMgr)
|
|
|
|
{
|
|
|
|
CEntity::AcceptScriptMsg(msg, objId, stateMgr);
|
|
|
|
if (msg == EScriptObjectMessage::SetToZero)
|
|
|
|
{
|
|
|
|
if (!x30_24_active)
|
|
|
|
return;
|
|
|
|
SendLocalScriptMsgs(EScriptObjectState::Zero, stateMgr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CScriptRandomRelay::SendLocalScriptMsgs(EScriptObjectState state, CStateManager &stateMgr)
|
|
|
|
{
|
|
|
|
if (state != EScriptObjectState::Zero)
|
|
|
|
{
|
|
|
|
SendScriptMsgs(state, stateMgr, EScriptObjectMessage::None);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
std::vector<std::pair<CEntity*, EScriptObjectMessage>> objs;
|
|
|
|
objs.reserve(10);
|
2016-09-02 20:57:45 +00:00
|
|
|
for (const SConnection& conn : x20_conns)
|
2016-07-25 06:24:57 +00:00
|
|
|
{
|
2016-09-02 20:57:45 +00:00
|
|
|
auto list = stateMgr.GetIdListForScript(conn.x8_objId);
|
|
|
|
auto it = list.first;
|
|
|
|
for (; it != list.second; ++it)
|
|
|
|
{
|
|
|
|
CEntity* ent = stateMgr.ObjectById(it->second);
|
|
|
|
if (ent && ent->GetActive())
|
|
|
|
objs.emplace_back(ent, conn.x4_msg);
|
|
|
|
}
|
2016-07-25 06:24:57 +00:00
|
|
|
}
|
2016-09-02 20:57:45 +00:00
|
|
|
|
|
|
|
u32 r0 = x34_connectionCount;
|
|
|
|
if (x3c_clamp)
|
|
|
|
r0 = u32(0.5 + (float(x34_connectionCount) / 100.f));
|
|
|
|
|
|
|
|
float fVariance = float(x38_variance) * (2.f * stateMgr.GetActiveRandom()->Float());
|
|
|
|
|
2016-07-25 06:24:57 +00:00
|
|
|
#endif
|
|
|
|
}
|
2016-05-18 03:57:43 +00:00
|
|
|
}
|