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-12 18:56:43 -08:00
2021-04-10 01:42:06 -07:00
namespace metaforce {
2016-12-12 18:56:43 -08:00
2017-11-12 22:19:18 -08:00
CScriptCameraHintTrigger::CScriptCameraHintTrigger(TUniqueId uid, bool active, std::string_view name,
const CEntityInfo& info, const zeus::CVector3f& scale,
2019-06-14 17:39:20 -07:00
const zeus::CTransform& xf, bool deactivateOnEnter,
bool deactivateOnExit)
2016-12-29 13:38:59 -08: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-14 19:07:01 -08:00
2018-12-07 21:30:43 -08:00
void CScriptCameraHintTrigger::Accept(IVisitor& visitor) { visitor.Visit(this); }
2017-01-14 19:07:01 -08:00
2019-06-14 17:39:20 -07:00
void CScriptCameraHintTrigger::Think(float dt, CStateManager& mgr) {
if (!GetActive()) {
2019-06-14 17:39:20 -07:00
return;
}
2019-06-14 17:39:20 -07:00
if (x130_26_playerInside && !x130_27_playerWasInside) {
x130_27_playerWasInside = true;
SendScriptMsgs(EScriptObjectState::Entered, mgr, EScriptObjectMessage::None);
if (x130_24_deactivateOnEnter) {
2019-06-14 17:39:20 -07:00
mgr.SendScriptMsg(this, kInvalidUniqueId, EScriptObjectMessage::Deactivate);
}
2019-06-14 17:39:20 -07:00
}
if (!x130_26_playerInside && x130_27_playerWasInside) {
x130_27_playerWasInside = false;
SendScriptMsgs(EScriptObjectState::Exited, mgr, EScriptObjectMessage::None);
if (x130_25_deactivateOnExit) {
2019-06-14 17:39:20 -07:00
mgr.SendScriptMsg(this, kInvalidUniqueId, EScriptObjectMessage::Deactivate);
}
2019-06-14 17:39:20 -07:00
}
if (x130_26_playerInside) {
2019-06-14 17:39:20 -07:00
SendScriptMsgs(EScriptObjectState::Inside, mgr, EScriptObjectMessage::None);
}
2019-06-14 17:39:20 -07:00
x130_26_playerInside = false;
}
void CScriptCameraHintTrigger::Touch(CActor& other, CStateManager& mgr) {
if (TCastToConstPtr<CPlayer>(other)) {
if (const auto tb = other.GetTouchBounds()) {
2019-06-14 17:39:20 -07:00
x130_26_playerInside = xe8_obb.OBBIntersectsBox(zeus::COBBox::FromAABox(*tb, {}));
}
2019-06-14 17:39:20 -07:00
}
}
2021-06-07 12:29:18 -07:00
std::optional<zeus::CAABox> CScriptCameraHintTrigger::GetTouchBounds() const { return {xe8_obb.calculateAABox()}; }
2019-06-14 17:39:20 -07:00
2021-04-10 01:42:06 -07:00
} // namespace metaforce