metaforce/Runtime/World/CScriptWaypoint.cpp

72 lines
2.5 KiB
C++
Raw Normal View History

#include "Runtime/World/CScriptWaypoint.hpp"
#include "Runtime/CStateManager.hpp"
#include "Runtime/World/CActorParameters.hpp"
#include "TCastTo.hpp" // Generated file, do not modify include path
2016-04-19 00:17:49 +00:00
2021-04-10 08:42:06 +00:00
namespace metaforce {
2016-04-19 00:17:49 +00:00
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)
2018-12-08 05:30:43 +00:00
: CActor(uid, active, name, info, xf, CModelData(), CMaterialList(), CActorParameters::None(), kInvalidUniqueId)
, 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) {
SetUseInSortedLists(false);
SetCallTouch(false);
2016-04-19 00:17:49 +00:00
}
2018-12-08 05:30:43 +00:00
void CScriptWaypoint::Accept(IVisitor& visitor) { visitor.Visit(this); }
2017-01-15 03:07:01 +00:00
2018-12-08 05:30:43 +00:00
void CScriptWaypoint::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId sender, CStateManager& mgr) {
CActor::AcceptScriptMsg(msg, sender, mgr);
2019-02-12 01:58:12 +00:00
if (GetActive() && msg == EScriptObjectMessage::Arrived)
2018-12-08 05:30:43 +00:00
SendScriptMsgs(EScriptObjectState::Arrived, mgr, EScriptObjectMessage::None);
2017-11-24 08:23:28 +00:00
}
void CScriptWaypoint::AddToRenderer(const zeus::CFrustum&, CStateManager&) {
2018-12-08 05:30:43 +00:00
// Empty
2017-11-24 08:23:28 +00:00
}
2018-12-08 05:30:43 +00:00
TUniqueId CScriptWaypoint::FollowWaypoint(CStateManager& mgr) const {
for (const SConnection& conn : x20_conns) {
if (conn.x0_state == EScriptObjectState::Arrived && conn.x4_msg == EScriptObjectMessage::Follow) {
2018-12-08 05:30:43 +00:00
return mgr.GetIdForScript(conn.x8_objId);
}
}
2018-12-08 05:30:43 +00:00
return kInvalidUniqueId;
2017-11-24 08:23:28 +00:00
}
2018-12-08 05:30:43 +00:00
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) {
const TUniqueId id = mgr.GetIdForScript(conn.x8_objId);
if (id != kInvalidUniqueId) {
if (const TCastToConstPtr<CScriptWaypoint> wp = mgr.GetObjectById(id)) {
if (wp->GetActive()) {
2018-12-08 05:30:43 +00:00
ids.push_back(wp->GetUniqueId());
}
}
}
2017-11-24 08:23:28 +00:00
}
2018-12-08 05:30:43 +00:00
}
2017-11-24 08:23:28 +00:00
if (ids.empty()) {
2018-12-08 05:30:43 +00:00
return kInvalidUniqueId;
}
2017-11-24 08:23:28 +00:00
2018-12-08 05:30:43 +00:00
return ids[int(mgr.GetActiveRandom()->Float() * ids.size() * 0.99f)];
2017-11-24 08:23:28 +00:00
}
2021-04-10 08:42:06 +00:00
} // namespace metaforce