metaforce/Runtime/World/CScriptCameraHintTrigger.cpp

58 lines
2.1 KiB
C++
Raw Normal View History

2016-12-13 02:56:43 +00:00
#include "CScriptCameraHintTrigger.hpp"
#include "CActorParameters.hpp"
2019-06-15 00:39:20 +00:00
#include "CStateManager.hpp"
2017-01-15 03:07:01 +00:00
#include "TCastTo.hpp"
2016-12-13 02:56:43 +00:00
2018-12-08 05:30:43 +00:00
namespace urde {
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)
2018-12-08 05:30:43 +00:00
, x124_scale(scale) {
2019-06-15 00:39:20 +00:00
x130_24_deactivateOnEnter = deactivateOnEnter;
x130_25_deactivateOnExit = deactivateOnExit;
2016-12-13 02:56:43 +00:00
}
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())
return;
if (x130_26_playerInside && !x130_27_playerWasInside) {
x130_27_playerWasInside = true;
SendScriptMsgs(EScriptObjectState::Entered, mgr, EScriptObjectMessage::None);
if (x130_24_deactivateOnEnter)
mgr.SendScriptMsg(this, kInvalidUniqueId, EScriptObjectMessage::Deactivate);
}
if (!x130_26_playerInside && x130_27_playerWasInside) {
x130_27_playerWasInside = false;
SendScriptMsgs(EScriptObjectState::Exited, mgr, EScriptObjectMessage::None);
if (x130_25_deactivateOnExit)
mgr.SendScriptMsg(this, kInvalidUniqueId, EScriptObjectMessage::Deactivate);
}
if (x130_26_playerInside)
SendScriptMsgs(EScriptObjectState::Inside, mgr, EScriptObjectMessage::None);
x130_26_playerInside = false;
}
void CScriptCameraHintTrigger::Touch(CActor& other, CStateManager& mgr) {
if (TCastToPtr<CPlayer>(other)) {
if (auto tb = other.GetTouchBounds())
x130_26_playerInside = xe8_obb.OBBIntersectsBox(zeus::COBBox::FromAABox(*tb, {}));
}
}
std::optional<zeus::CAABox> CScriptCameraHintTrigger::GetTouchBounds() const {
return {xe8_obb.calculateAABox()};
}
2018-12-08 05:30:43 +00:00
} // namespace urde