2016-04-19 00:17:49 +00:00
|
|
|
#include "CScriptWaypoint.hpp"
|
|
|
|
#include "CActorParameters.hpp"
|
2017-01-15 03:07:01 +00:00
|
|
|
#include "TCastTo.hpp"
|
2017-11-24 08:23:28 +00:00
|
|
|
#include "CStateManager.hpp"
|
2016-04-19 00:17:49 +00:00
|
|
|
|
|
|
|
namespace urde
|
|
|
|
{
|
|
|
|
|
2017-11-13 06:19:18 +00:00
|
|
|
CScriptWaypoint::CScriptWaypoint(TUniqueId uid, std::string_view name, const CEntityInfo& info,
|
2018-11-11 03:27:54 +00:00
|
|
|
const zeus::CTransform& xf, bool active, float speed, float pause,
|
|
|
|
u32 patternTranslate, u32 patternOrient, u32 patternFit, u32 behaviour,
|
|
|
|
u32 behaviourOrient, u32 behaviourModifiers, u32 animation)
|
2016-04-22 20:22:45 +00:00
|
|
|
: CActor(uid, active, name, info, xf, CModelData(), CMaterialList(),
|
2017-11-24 08:23:28 +00:00
|
|
|
CActorParameters::None(), kInvalidUniqueId),
|
2018-11-11 03:27:54 +00:00
|
|
|
xe8_speed(speed), xec_animation(animation), xf0_pause(pause),
|
|
|
|
xf4_patternTranslate(patternTranslate), xf5_patternOrient(patternOrient),
|
|
|
|
xf6_patternFit(patternFit), xf7_behaviour(behaviour),
|
|
|
|
xf8_behaviourOrient(behaviourOrient), xfa_behaviourModifiers(behaviourModifiers)
|
2016-04-19 00:17:49 +00:00
|
|
|
{
|
2017-11-24 08:23:28 +00:00
|
|
|
SetUseInSortedLists(false);
|
|
|
|
SetCallTouch(false);
|
2016-04-19 00:17:49 +00:00
|
|
|
}
|
|
|
|
|
2017-01-15 03:07:01 +00:00
|
|
|
void CScriptWaypoint::Accept(IVisitor& visitor)
|
|
|
|
{
|
|
|
|
visitor.Visit(this);
|
|
|
|
}
|
|
|
|
|
2017-11-24 08:23:28 +00:00
|
|
|
void CScriptWaypoint::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId sender, CStateManager& mgr)
|
|
|
|
{
|
|
|
|
CActor::AcceptScriptMsg(msg, sender, mgr);
|
|
|
|
if (GetActive())
|
|
|
|
if (msg == EScriptObjectMessage::Arrived)
|
|
|
|
SendScriptMsgs(EScriptObjectState::Arrived, mgr, EScriptObjectMessage::None);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CScriptWaypoint::AddToRenderer(const zeus::CFrustum&, const CStateManager&) const
|
|
|
|
{
|
|
|
|
// Empty
|
|
|
|
}
|
|
|
|
|
|
|
|
TUniqueId CScriptWaypoint::FollowWaypoint(CStateManager& mgr) const
|
|
|
|
{
|
|
|
|
for (const SConnection& conn : x20_conns)
|
|
|
|
if (conn.x0_state == EScriptObjectState::Arrived && conn.x4_msg == EScriptObjectMessage::Follow)
|
|
|
|
return mgr.GetIdForScript(conn.x8_objId);
|
|
|
|
return kInvalidUniqueId;
|
|
|
|
}
|
|
|
|
|
|
|
|
TUniqueId CScriptWaypoint::NextWaypoint(CStateManager& mgr) const
|
|
|
|
{
|
|
|
|
rstl::reserved_vector<TUniqueId, 10> ids;
|
|
|
|
for (const SConnection& conn : x20_conns)
|
|
|
|
{
|
|
|
|
if (conn.x0_state == EScriptObjectState::Arrived && conn.x4_msg == EScriptObjectMessage::Next)
|
|
|
|
{
|
|
|
|
TUniqueId id = mgr.GetIdForScript(conn.x8_objId);
|
|
|
|
if (id != kInvalidUniqueId)
|
|
|
|
if (TCastToConstPtr<CScriptWaypoint> wp = mgr.GetObjectById(id))
|
|
|
|
if (wp->GetActive())
|
|
|
|
ids.push_back(wp->GetUniqueId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ids.size() == 0)
|
|
|
|
return kInvalidUniqueId;
|
|
|
|
|
|
|
|
return ids[int(mgr.GetActiveRandom()->Float() * ids.size() * 0.99f)];
|
|
|
|
}
|
|
|
|
|
2016-04-19 00:17:49 +00:00
|
|
|
}
|