metaforce/Runtime/World/CScriptCameraHintTrigger.cpp

62 lines
2.2 KiB
C++
Raw Normal View History

#include "Runtime/World/CScriptCameraHintTrigger.hpp"
#include "Runtime/CStateManager.hpp"
#include "Runtime/World/CActorParameters.hpp"
#include "TCastTo.hpp" // Generated file, do not modify include path
2016-12-13 02:56:43 +00:00
2021-04-10 08:42:06 +00:00
namespace metaforce {
2016-12-13 02:56:43 +00:00
2017-11-13 06:19:18 +00:00
CScriptCameraHintTrigger::CScriptCameraHintTrigger(TUniqueId uid, bool active, std::string_view name,
const CEntityInfo& info, const zeus::CVector3f& scale,
2019-06-15 00:39:20 +00:00
const zeus::CTransform& xf, bool deactivateOnEnter,
bool deactivateOnExit)
2016-12-29 21:38:59 +00:00
: CActor(uid, active, name, info, xf, CModelData::CModelDataNull(), CMaterialList(EMaterialTypes::Trigger),
CActorParameters::None(), kInvalidUniqueId)
, xe8_obb(xf, scale)
, x124_scale(scale)
, x130_24_deactivateOnEnter(deactivateOnEnter)
, x130_25_deactivateOnExit(deactivateOnExit) {}
2017-01-15 03:07:01 +00:00
2018-12-08 05:30:43 +00:00
void CScriptCameraHintTrigger::Accept(IVisitor& visitor) { visitor.Visit(this); }
2017-01-15 03:07:01 +00:00
2019-06-15 00:39:20 +00:00
void CScriptCameraHintTrigger::Think(float dt, CStateManager& mgr) {
if (!GetActive()) {
2019-06-15 00:39:20 +00:00
return;
}
2019-06-15 00:39:20 +00:00
if (x130_26_playerInside && !x130_27_playerWasInside) {
x130_27_playerWasInside = true;
SendScriptMsgs(EScriptObjectState::Entered, mgr, EScriptObjectMessage::None);
if (x130_24_deactivateOnEnter) {
2019-06-15 00:39:20 +00:00
mgr.SendScriptMsg(this, kInvalidUniqueId, EScriptObjectMessage::Deactivate);
}
2019-06-15 00:39:20 +00:00
}
if (!x130_26_playerInside && x130_27_playerWasInside) {
x130_27_playerWasInside = false;
SendScriptMsgs(EScriptObjectState::Exited, mgr, EScriptObjectMessage::None);
if (x130_25_deactivateOnExit) {
2019-06-15 00:39:20 +00:00
mgr.SendScriptMsg(this, kInvalidUniqueId, EScriptObjectMessage::Deactivate);
}
2019-06-15 00:39:20 +00:00
}
if (x130_26_playerInside) {
2019-06-15 00:39:20 +00:00
SendScriptMsgs(EScriptObjectState::Inside, mgr, EScriptObjectMessage::None);
}
2019-06-15 00:39:20 +00:00
x130_26_playerInside = false;
}
void CScriptCameraHintTrigger::Touch(CActor& other, CStateManager& mgr) {
if (TCastToConstPtr<CPlayer>(other)) {
if (const auto tb = other.GetTouchBounds()) {
2019-06-15 00:39:20 +00:00
x130_26_playerInside = xe8_obb.OBBIntersectsBox(zeus::COBBox::FromAABox(*tb, {}));
}
2019-06-15 00:39:20 +00:00
}
}
2021-06-07 19:29:18 +00:00
std::optional<zeus::CAABox> CScriptCameraHintTrigger::GetTouchBounds() const { return {xe8_obb.calculateAABox()}; }
2019-06-15 00:39:20 +00:00
2021-04-10 08:42:06 +00:00
} // namespace metaforce