metaforce/Runtime/World/CScriptDoor.cpp

177 lines
4.6 KiB
C++
Raw Normal View History

2016-04-19 21:25:26 +00:00
#include "CScriptDoor.hpp"
2016-04-23 00:29:55 +00:00
#include "CScriptDock.hpp"
2016-04-19 21:25:26 +00:00
#include "Collision/CMaterialList.hpp"
2016-04-22 20:22:45 +00:00
#include "Character/CAnimData.hpp"
#include "Character/CAnimPlaybackParms.hpp"
#include "AutoMapper/CMapWorldInfo.hpp"
#include "CStateManager.hpp"
2016-04-23 00:29:55 +00:00
#include "CWorld.hpp"
2016-07-28 07:33:55 +00:00
#include "Camera/CCameraManager.hpp"
#include "Camera/CBallCamera.hpp"
2017-01-15 03:07:01 +00:00
#include "TCastTo.hpp"
2016-04-19 21:25:26 +00:00
namespace urde
{
2016-12-29 21:38:59 +00:00
static CMaterialList MakeDoorMaterialList(bool open)
2016-04-19 21:25:26 +00:00
{
CMaterialList ret;
2016-12-29 21:38:59 +00:00
ret.Add(EMaterialTypes::Solid);
ret.Add(EMaterialTypes::Immovable);
ret.Add(EMaterialTypes::Orbit);
if (!open)
ret.Add(EMaterialTypes::Occluder);
2016-04-22 20:22:45 +00:00
2016-04-19 21:25:26 +00:00
return ret;
}
CScriptDoor::CScriptDoor(TUniqueId uid, const std::string& name, const CEntityInfo& info,
2016-04-22 20:22:45 +00:00
const zeus::CTransform& xf, CModelData&& mData, const CActorParameters& actParms,
2016-04-19 21:25:26 +00:00
const zeus::CVector3f&, const zeus::CAABox& aabb, bool active,
2016-12-29 21:38:59 +00:00
bool open, bool b2, float, bool ballDoor)
: CPhysicsActor(uid, active, name, info, xf, std::move(mData), MakeDoorMaterialList(open),
2017-01-25 04:40:19 +00:00
aabb, SMoverData(1.f), actParms, 0.3f, 0.1f)
2016-04-19 21:25:26 +00:00
{
2017-01-25 04:40:19 +00:00
x2a8_29_ballDoor = ballDoor;
x2a8_25_ = open;
x2a8_26_ = open;
x2a8_28_ = b2;
x2a8_27_ = true;
2016-04-22 20:22:45 +00:00
x264_ = GetBoundingBox();
2016-04-23 18:04:49 +00:00
x284_modelBounds = x64_modelData->GetBounds(xf.getRotation());
2016-12-29 21:38:59 +00:00
if (open)
2016-04-23 18:04:49 +00:00
SetDoorAnimation(EDoorAnimType::Open);
SetMass(0.f);
2016-04-22 20:22:45 +00:00
}
2017-01-15 03:07:01 +00:00
void CScriptDoor::Accept(IVisitor& visitor)
{
visitor.Visit(this);
}
2016-04-23 00:29:55 +00:00
/* ORIGINAL 0-00 OFFSET: 8007F054 */
2016-04-23 18:04:49 +00:00
zeus::CVector3f CScriptDoor::GetOrbitPosition(const CStateManager& /*mgr*/) const
2016-04-23 00:29:55 +00:00
{
2016-04-29 10:08:46 +00:00
return x34_transform.origin + x29c_;
2016-04-23 00:29:55 +00:00
}
/* ORIGINAL 0-00 OFFSET: 8007E550 */
void CScriptDoor::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager &mgr)
{
2016-04-23 18:04:49 +00:00
(void)mgr;
(void)uid;
(void)msg;
2016-04-23 00:29:55 +00:00
}
2016-04-24 02:46:13 +00:00
void CScriptDoor::Think(float dt, CStateManager& mgr)
{
if (!GetActive())
return;
if (!x2a8_26_)
{
if (x25c_ < 0.5f)
x25c_ += dt;
}
}
2016-04-23 10:51:53 +00:00
void CScriptDoor::AddToRenderer(const zeus::CFrustum& /*frustum*/, CStateManager &mgr)
{
2017-08-13 07:56:35 +00:00
if (!xe4_30_outOfFrustum)
2016-04-23 10:51:53 +00:00
CPhysicsActor::Render(mgr);
}
2016-04-23 00:29:55 +00:00
/* ORIGINAL 0-00 OFFSET: 8007E0BC */
2016-04-22 20:22:45 +00:00
void CScriptDoor::ForceClosed(CStateManager & mgr)
{
if (x2a8_26_)
{
x2a8_26_ = false;
x2a8_25_ = false;
2016-07-28 07:33:55 +00:00
/* TODO: Figure out what goes here this
* mgr.GetCameraManager()->GetBallCamera()->sub_80083118(x8_uid);
* mgr.GetCameraManager()->GetBallCamera()->sub_800830F4(x8_uid);
2016-04-22 20:22:45 +00:00
*/
2016-04-23 18:04:49 +00:00
SetDoorAnimation(EDoorAnimType::Close);
2016-04-22 20:22:45 +00:00
SendScriptMsgs(EScriptObjectState::Closed, mgr, EScriptObjectMessage::None);
x25c_ = 0.f;
x2a8_27_ = false;
x2a8_30_ = false;
}
else if (x2a8_27_)
{
x2a8_27_ = false;
x2a8_30_ = false;
SendScriptMsgs(EScriptObjectState::Closed, mgr, EScriptObjectMessage::None);
}
}
2016-04-23 00:29:55 +00:00
/* ORIGINAL 0-00 OFFSET: 8007E1C4 */
bool CScriptDoor::IsConnectedToArea(const CStateManager& mgr, TAreaId area)
{
2017-01-15 03:07:01 +00:00
const CScriptDock* dock = TCastToConstPtr<CScriptDock>(mgr.GetObjectById(x282_dockId));
2016-04-23 00:29:55 +00:00
if (dock)
{
if (dock->GetDestinationAreaId() == area)
2016-04-23 00:29:55 +00:00
return true;
/*
* TODO: Determine what's going on here
* CWorld* world = mgr.GetWorld();
*/
}
return false;
}
/* ORIGINAL 0-00 OFFSET: 8007EA64 */
2016-04-22 20:22:45 +00:00
void CScriptDoor::OpenDoor(TUniqueId uid, CStateManager& mgr)
{
TEditorId eid = mgr.GetEditorIdForUniqueId(uid);
mgr.MapWorldInfo()->SetDoorVisited(eid, true);
2017-01-15 03:07:01 +00:00
const CScriptDoor* door = TCastToConstPtr<CScriptDoor>(mgr.GetObjectById(uid));
2016-04-22 20:22:45 +00:00
if (door)
2016-04-24 02:46:13 +00:00
x27c_partner = door->GetUniqueId();
2016-04-22 20:22:45 +00:00
2016-04-23 18:04:49 +00:00
SetDoorAnimation(EDoorAnimType::Open);
if (x27c_partner != kInvalidUniqueId)
2016-04-22 20:22:45 +00:00
SendScriptMsgs(EScriptObjectState::MaxReached, mgr, EScriptObjectMessage::None);
else
{
SendScriptMsgs(EScriptObjectState::Open, mgr, EScriptObjectMessage::None);
/* TODO: Finish this */
}
}
2016-04-23 00:29:55 +00:00
/* ORIGINAL 0-00 OFFSET: 8007ED4C */
u32 CScriptDoor::GetDoorOpenCondition(CStateManager& mgr)
{
2017-01-15 03:07:01 +00:00
const CScriptDock* dock = TCastToConstPtr<CScriptDock>(mgr.GetObjectById(x282_dockId));
2016-04-23 00:29:55 +00:00
if (!dock)
return 2;
if (x25c_ < 0.05f)
return 1;
/* TODO: Finish this */
return 0;
}
/* ORIGINAL 0-00 OFFSET: 8007E9D0 */
2016-04-22 20:22:45 +00:00
void CScriptDoor::SetDoorAnimation(CScriptDoor::EDoorAnimType type)
{
2016-04-23 18:04:49 +00:00
x260_doorState = type;
2016-04-22 20:22:45 +00:00
CModelData* modelData = x64_modelData.get();
2016-04-23 18:04:49 +00:00
if (modelData && modelData->AnimationData())
modelData->AnimationData()->SetAnimation(CAnimPlaybackParms(s32(type), -1, 1.f, true), false);
2016-04-19 21:25:26 +00:00
}
}