metaforce/Runtime/World/CScriptPlayerHint.cpp

94 lines
2.8 KiB
C++
Raw Permalink Normal View History

#include "Runtime/World/CScriptPlayerHint.hpp"
#include <algorithm>
#include "Runtime/CStateManager.hpp"
#include "Runtime/MP1/World/CMetroidPrimeRelay.hpp"
#include "Runtime/World/CActorParameters.hpp"
#include "Runtime/World/CPlayer.hpp"
#include "TCastTo.hpp" // Generated file, do not modify include path
2017-08-18 01:30:15 +00:00
2021-04-10 08:42:06 +00:00
namespace metaforce {
2017-08-18 01:30:15 +00:00
2017-11-13 06:19:18 +00:00
CScriptPlayerHint::CScriptPlayerHint(TUniqueId uid, std::string_view name, const CEntityInfo& info,
2017-08-18 01:30:15 +00:00
const zeus::CTransform& xf, bool active, u32 priority, u32 overrideFlags)
2017-12-19 03:05:50 +00:00
: CActor(uid, active, name, info, xf, CModelData::CModelDataNull(), {EMaterialTypes::NoStepLogic},
2018-12-08 05:30:43 +00:00
CActorParameters::None(), kInvalidUniqueId)
, x100_priority(priority)
, x104_overrideFlags(overrideFlags) {}
2017-08-18 01:30:15 +00:00
2018-12-08 05:30:43 +00:00
void CScriptPlayerHint::Accept(IVisitor& visit) { visit.Visit(this); }
2017-08-18 01:30:15 +00:00
2018-12-08 05:30:43 +00:00
void CScriptPlayerHint::AddToObjectList(TUniqueId uid) {
const bool inList =
std::any_of(xe8_objectList.cbegin(), xe8_objectList.cend(), [uid](const auto id) { return id == uid; });
if (inList) {
return;
}
if (xe8_objectList.size() == xe8_objectList.capacity()) {
return;
}
xe8_objectList.push_back(uid);
2017-08-20 05:23:22 +00:00
}
2018-12-08 05:30:43 +00:00
void CScriptPlayerHint::RemoveFromObjectList(TUniqueId uid) {
const auto iter =
std::find_if(xe8_objectList.cbegin(), xe8_objectList.cend(), [uid](const auto id) { return id == uid; });
if (iter == xe8_objectList.cend()) {
return;
2018-12-08 05:30:43 +00:00
}
xe8_objectList.erase(iter);
2017-08-20 05:23:22 +00:00
}
2018-12-08 05:30:43 +00:00
void CScriptPlayerHint::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId sender, CStateManager& mgr) {
switch (msg) {
case EScriptObjectMessage::Deactivate:
case EScriptObjectMessage::Deleted:
RemoveFromObjectList(sender);
mgr.GetPlayer().AddToPlayerHintRemoveList(GetUniqueId(), mgr);
xfc_deactivated = true;
break;
case EScriptObjectMessage::Increment:
x108_mpId = kInvalidUniqueId;
if ((x104_overrideFlags & 0x4000) != 0) {
for (const SConnection& conn : x20_conns) {
if (conn.x0_state != EScriptObjectState::Play) {
2018-12-08 05:30:43 +00:00
continue;
}
2018-12-08 05:30:43 +00:00
x108_mpId = mgr.GetIdForScript(conn.x8_objId);
if (TCastToConstPtr<MP1::CMetroidPrimeRelay> mpRelay = mgr.GetObjectById(x108_mpId)) {
x108_mpId = mpRelay->GetMetroidPrimeExoId();
break;
2017-08-20 05:23:22 +00:00
}
2018-12-08 05:30:43 +00:00
}
2017-08-20 05:23:22 +00:00
}
2018-12-08 05:30:43 +00:00
break;
default:
break;
}
2017-08-20 05:23:22 +00:00
2018-12-08 05:30:43 +00:00
if (x30_24_active) {
switch (msg) {
case EScriptObjectMessage::Increment:
AddToObjectList(sender);
mgr.GetPlayer().AddToPlayerHintAddList(GetUniqueId(), mgr);
xfc_deactivated = false;
break;
case EScriptObjectMessage::Decrement:
RemoveFromObjectList(sender);
mgr.GetPlayer().AddToPlayerHintRemoveList(GetUniqueId(), mgr);
break;
default:
break;
2017-08-20 05:23:22 +00:00
}
2018-12-08 05:30:43 +00:00
}
2017-08-20 05:23:22 +00:00
2018-12-08 05:30:43 +00:00
CActor::AcceptScriptMsg(msg, sender, mgr);
2017-08-20 05:23:22 +00:00
}
2021-04-10 08:42:06 +00:00
} // namespace metaforce