2016-04-20 21:07:18 +00:00
|
|
|
#include "CScriptDock.hpp"
|
|
|
|
#include "CActorParameters.hpp"
|
|
|
|
#include "Character/CModelData.hpp"
|
|
|
|
#include "Collision/CMaterialList.hpp"
|
2016-12-22 02:48:22 +00:00
|
|
|
#include "CWorld.hpp"
|
|
|
|
#include "CStateManager.hpp"
|
2017-01-04 04:08:30 +00:00
|
|
|
#include "CScriptDoor.hpp"
|
|
|
|
#include "CPlayer.hpp"
|
2017-02-12 04:43:33 +00:00
|
|
|
#include "Particle/CGenDescription.hpp"
|
2017-01-15 03:07:01 +00:00
|
|
|
#include "TCastTo.hpp"
|
2016-04-20 21:07:18 +00:00
|
|
|
|
|
|
|
namespace urde
|
|
|
|
{
|
|
|
|
CMaterialList MakeDockMaterialList()
|
|
|
|
{
|
|
|
|
CMaterialList list;
|
2016-12-29 21:38:59 +00:00
|
|
|
list.Add(EMaterialTypes::Trigger);
|
|
|
|
list.Add(EMaterialTypes::Immovable);
|
|
|
|
list.Add(EMaterialTypes::AIBlock);
|
2016-04-20 21:07:18 +00:00
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2018-05-14 03:38:36 +00:00
|
|
|
CScriptDock::CScriptDock(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CVector3f position,
|
|
|
|
const zeus::CVector3f& extents, s32 dock, TAreaId area, bool active, s32 dockReferenceCount,
|
|
|
|
bool loadConnected)
|
2018-05-07 00:47:40 +00:00
|
|
|
: CPhysicsActor(uid, active, name, info, zeus::CTransform(zeus::CMatrix3f::skIdentityMatrix3f, position),
|
2017-01-04 04:08:30 +00:00
|
|
|
CModelData::CModelDataNull(), MakeDockMaterialList(), zeus::CAABox(-extents * 0.5f, extents * 0.5f),
|
|
|
|
SMoverData(1.f), CActorParameters::None(), 0.3f, 0.1f)
|
2017-01-04 06:39:56 +00:00
|
|
|
, x258_dockReferenceCount(dockReferenceCount)
|
2017-01-04 04:08:30 +00:00
|
|
|
, x25c_dock(dock)
|
|
|
|
, x260_area(area)
|
2016-04-20 21:07:18 +00:00
|
|
|
{
|
2017-01-25 04:40:19 +00:00
|
|
|
x268_25_loadConnected = loadConnected;
|
2016-04-20 21:07:18 +00:00
|
|
|
}
|
2016-12-22 02:48:22 +00:00
|
|
|
|
2018-05-14 03:38:36 +00:00
|
|
|
void CScriptDock::Accept(IVisitor& visitor) { visitor.Visit(this); }
|
2017-01-15 03:07:01 +00:00
|
|
|
|
2017-01-04 04:08:30 +00:00
|
|
|
void CScriptDock::Think(float dt, CStateManager& mgr)
|
2016-12-22 02:48:22 +00:00
|
|
|
{
|
2017-01-04 04:08:30 +00:00
|
|
|
if (!GetActive())
|
|
|
|
{
|
|
|
|
UpdateAreaActivateFlags(mgr);
|
|
|
|
x268_24_dockReferenced = false;
|
|
|
|
}
|
|
|
|
|
2018-10-27 06:16:12 +00:00
|
|
|
const IGameArea::Dock* gameDock = mgr.WorldNC()->GetArea(x260_area)->GetDock(x25c_dock);
|
|
|
|
TAreaId connArea = gameDock->GetConnectedAreaId(gameDock->GetReferenceCount());
|
|
|
|
if (connArea != kInvalidAreaId)
|
2017-01-04 04:08:30 +00:00
|
|
|
{
|
2018-10-27 06:16:12 +00:00
|
|
|
bool connPostConstructed = mgr.WorldNC()->GetArea(connArea)->IsPostConstructed();
|
|
|
|
if (x268_26_areaPostConstructed != connPostConstructed)
|
|
|
|
{
|
|
|
|
x268_26_areaPostConstructed = connPostConstructed;
|
|
|
|
if (connPostConstructed)
|
|
|
|
CEntity::SendScriptMsgs(EScriptObjectState::MaxReached, mgr, EScriptObjectMessage::None);
|
|
|
|
else
|
|
|
|
CEntity::SendScriptMsgs(EScriptObjectState::Zero, mgr, EScriptObjectMessage::None);
|
|
|
|
}
|
2017-01-04 06:39:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mgr.GetNextAreaId() != x260_area)
|
|
|
|
x264_dockState = EDockState::Three;
|
|
|
|
else if (x264_dockState == EDockState::Three)
|
|
|
|
x264_dockState = EDockState::Idle;
|
|
|
|
else if (x264_dockState == EDockState::PlayerTouched)
|
|
|
|
x264_dockState = EDockState::EnterNextArea;
|
|
|
|
else if (x264_dockState == EDockState::EnterNextArea)
|
|
|
|
{
|
|
|
|
CPlayer& player = mgr.GetPlayer();
|
2018-05-20 06:14:57 +00:00
|
|
|
if (HasPointCrossedDock(mgr, player.GetTranslation()))
|
2017-01-04 06:39:56 +00:00
|
|
|
{
|
|
|
|
IGameArea::Dock* dock = mgr.WorldNC()->GetArea(mgr.GetNextAreaId())->DockNC(x25c_dock);
|
|
|
|
TAreaId aid = dock->GetConnectedAreaId(dock->GetReferenceCount());
|
|
|
|
if (aid != kInvalidAreaId && mgr.WorldNC()->GetArea(aid)->GetActive())
|
|
|
|
{
|
|
|
|
mgr.SetCurrentAreaId(aid);
|
|
|
|
s32 otherDock = dock->GetOtherDockNumber(dock->GetReferenceCount());
|
|
|
|
|
2018-10-27 06:16:12 +00:00
|
|
|
if (CObjectList* objs = mgr.WorldNC()->GetArea(aid)->GetAreaObjects())
|
2017-01-04 06:39:56 +00:00
|
|
|
{
|
2017-12-04 02:26:17 +00:00
|
|
|
for (CEntity* ent : *objs)
|
|
|
|
{
|
|
|
|
TCastToPtr<CScriptDock> dock(ent);
|
|
|
|
if (dock && dock->GetDockId() == otherDock)
|
|
|
|
dock->SetLoadConnected(mgr, true);
|
|
|
|
}
|
2017-01-04 06:39:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
x264_dockState = EDockState::Idle;
|
2017-01-04 04:08:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CScriptDock::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr)
|
|
|
|
{
|
|
|
|
switch (msg)
|
|
|
|
{
|
2017-03-24 05:30:16 +00:00
|
|
|
case EScriptObjectMessage::Registered:
|
2017-01-04 04:08:30 +00:00
|
|
|
{
|
|
|
|
CGameArea* area = mgr.WorldNC()->GetArea(x260_area);
|
2018-05-02 00:43:31 +00:00
|
|
|
if (area->GetDockCount() < x25c_dock)
|
2017-01-04 04:08:30 +00:00
|
|
|
return;
|
|
|
|
IGameArea::Dock* dock = area->DockNC(x25c_dock);
|
|
|
|
if (!dock->IsReferenced())
|
|
|
|
dock->SetReferenceCount(x258_dockReferenceCount);
|
|
|
|
}
|
|
|
|
break;
|
2017-02-14 04:27:20 +00:00
|
|
|
case EScriptObjectMessage::Deleted:
|
2017-01-04 04:08:30 +00:00
|
|
|
CleanUp();
|
|
|
|
break;
|
2017-03-24 05:30:16 +00:00
|
|
|
case EScriptObjectMessage::InitializedInArea:
|
2017-01-04 04:08:30 +00:00
|
|
|
AreaLoaded(mgr);
|
|
|
|
break;
|
2017-11-27 05:06:53 +00:00
|
|
|
case EScriptObjectMessage::WorldInitialized:
|
2017-01-04 04:08:30 +00:00
|
|
|
{
|
|
|
|
UpdateAreaActivateFlags(mgr);
|
|
|
|
CMaterialList exclude = GetMaterialFilter().GetExcludeList();
|
|
|
|
CMaterialList include = GetMaterialFilter().GetIncludeList();
|
|
|
|
include.Add(EMaterialTypes::AIBlock);
|
2017-01-07 01:58:05 +00:00
|
|
|
SetMaterialFilter(CMaterialFilter::MakeIncludeExclude(include, exclude));
|
2017-01-04 04:08:30 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EScriptObjectMessage::SetToZero:
|
|
|
|
{
|
|
|
|
if (mgr.GetNextAreaId() != x260_area)
|
|
|
|
return;
|
|
|
|
|
|
|
|
SetLoadConnected(mgr, false);
|
|
|
|
|
|
|
|
CGameArea* area = mgr.WorldNC()->GetArea(x260_area);
|
|
|
|
IGameArea::Dock* dock = area->DockNC(x25c_dock);
|
|
|
|
|
|
|
|
TAreaId aid = dock->GetConnectedAreaId(dock->GetReferenceCount());
|
|
|
|
|
|
|
|
CPlatformAndDoorList& lst = mgr.GetPlatformAndDoorObjectList();
|
|
|
|
for (CEntity* ent : lst)
|
|
|
|
{
|
2017-01-15 03:59:37 +00:00
|
|
|
TCastToPtr<CScriptDoor> door(ent);
|
2018-05-07 00:47:40 +00:00
|
|
|
if (door && door->IsConnectedToArea(mgr, aid))
|
2017-01-04 04:08:30 +00:00
|
|
|
door->ForceClosed(mgr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EScriptObjectMessage::SetToMax:
|
|
|
|
if (mgr.GetNextAreaId() != x260_area)
|
|
|
|
return;
|
|
|
|
|
|
|
|
SetLoadConnected(mgr, true);
|
|
|
|
break;
|
|
|
|
case EScriptObjectMessage::Increment:
|
|
|
|
SetLoadConnected(mgr, true);
|
2018-05-02 00:43:31 +00:00
|
|
|
[[fallthrough]];
|
2017-01-04 04:08:30 +00:00
|
|
|
case EScriptObjectMessage::Decrement:
|
|
|
|
{
|
|
|
|
TAreaId aid = x260_area;
|
|
|
|
if (mgr.GetNextAreaId() == x260_area)
|
|
|
|
{
|
|
|
|
IGameArea::Dock* dock = mgr.WorldNC()->GetArea(x260_area)->DockNC(x25c_dock);
|
|
|
|
aid = dock->GetConnectedAreaId(dock->GetReferenceCount());
|
|
|
|
}
|
2018-05-07 00:47:40 +00:00
|
|
|
|
|
|
|
if (aid >= 0 && aid < mgr.GetWorld()->GetNumAreas() && mgr.WorldNC()->GetArea(aid)->GetActive())
|
|
|
|
CWorld::PropogateAreaChain(CGameArea::EOcclusionState(msg == EScriptObjectMessage::Increment),
|
|
|
|
mgr.WorldNC()->GetArea(aid), mgr.WorldNC());
|
2017-01-04 04:08:30 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
CPhysicsActor::AcceptScriptMsg(msg, uid, mgr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-30 03:12:41 +00:00
|
|
|
std::experimental::optional<zeus::CAABox> CScriptDock::GetTouchBounds() const
|
2017-01-04 04:08:30 +00:00
|
|
|
{
|
|
|
|
if (x264_dockState == EDockState::Three)
|
|
|
|
return {};
|
|
|
|
|
|
|
|
return GetBoundingBox();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CScriptDock::Touch(CActor& act, CStateManager&)
|
|
|
|
{
|
|
|
|
if (x264_dockState == EDockState::Three)
|
|
|
|
return;
|
|
|
|
|
2017-01-15 03:59:37 +00:00
|
|
|
if (TCastToPtr<CPlayer>(act))
|
2017-01-04 04:08:30 +00:00
|
|
|
x264_dockState = EDockState::PlayerTouched;
|
|
|
|
}
|
|
|
|
|
|
|
|
zeus::CPlane CScriptDock::GetPlane(const CStateManager& mgr) const
|
|
|
|
{
|
|
|
|
const IGameArea::Dock* dock = mgr.GetWorld()->GetAreaAlways(x260_area)->GetDock(x25c_dock);
|
|
|
|
return zeus::CPlane(dock->GetPoint(0), dock->GetPoint(1), dock->GetPoint(2));
|
|
|
|
}
|
|
|
|
|
|
|
|
void CScriptDock::SetDockReference(CStateManager& mgr, s32 ref)
|
|
|
|
{
|
|
|
|
mgr.WorldNC()->GetArea(x260_area)->DockNC(x25c_dock)->SetReferenceCount(ref);
|
|
|
|
x268_24_dockReferenced = true;
|
|
|
|
}
|
|
|
|
|
2018-04-30 03:12:41 +00:00
|
|
|
s32 CScriptDock::GetDockReference(const CStateManager& mgr) const
|
2017-01-04 04:08:30 +00:00
|
|
|
{
|
|
|
|
return mgr.GetWorld()->GetAreaAlways(x260_area)->GetDock(x25c_dock)->GetReferenceCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
TAreaId CScriptDock::GetCurrentConnectedAreaId(const CStateManager& mgr) const
|
|
|
|
{
|
2018-05-02 00:43:31 +00:00
|
|
|
if (x260_area >= mgr.GetWorld()->GetNumAreas())
|
2017-01-04 04:08:30 +00:00
|
|
|
return kInvalidAreaId;
|
|
|
|
const CGameArea* area = mgr.GetWorld()->GetAreaAlways(x260_area);
|
2018-05-02 00:43:31 +00:00
|
|
|
if (x25c_dock >= area->GetDockCount())
|
2017-01-04 04:08:30 +00:00
|
|
|
return kInvalidAreaId;
|
|
|
|
|
|
|
|
const IGameArea::Dock* dock = area->GetDock(x25c_dock);
|
|
|
|
return dock->GetConnectedAreaId(dock->GetReferenceCount());
|
|
|
|
}
|
|
|
|
|
|
|
|
void CScriptDock::UpdateAreaActivateFlags(CStateManager& mgr)
|
|
|
|
{
|
|
|
|
CWorld* world = mgr.WorldNC();
|
|
|
|
if (x260_area >= world->GetNumAreas())
|
|
|
|
return;
|
|
|
|
|
|
|
|
CGameArea* area = world->GetArea(x260_area);
|
|
|
|
|
|
|
|
if (x25c_dock >= area->GetDockCount())
|
|
|
|
return;
|
|
|
|
|
|
|
|
IGameArea::Dock* dock = area->DockNC(x25c_dock);
|
|
|
|
|
|
|
|
for (s32 i = 0; i < dock->GetDockRefs().size(); ++i)
|
|
|
|
{
|
|
|
|
s32 dockRefCount = dock->GetReferenceCount();
|
|
|
|
TAreaId aid = dock->GetConnectedAreaId(i);
|
|
|
|
if (aid != kInvalidAreaId)
|
|
|
|
world->GetArea(aid)->SetActive(i == dockRefCount);
|
|
|
|
}
|
|
|
|
mgr.SetCurrentAreaId(mgr.GetNextAreaId());
|
|
|
|
}
|
|
|
|
|
2017-01-04 06:39:56 +00:00
|
|
|
bool CScriptDock::HasPointCrossedDock(const CStateManager& mgr, const zeus::CVector3f& point) const
|
2017-01-04 04:08:30 +00:00
|
|
|
{
|
2017-01-04 06:39:56 +00:00
|
|
|
const zeus::CPlane plane = GetPlane(mgr);
|
2018-05-20 06:14:57 +00:00
|
|
|
return (point.dot(plane.vec) >= plane.d);
|
2016-12-22 02:48:22 +00:00
|
|
|
}
|
|
|
|
|
2017-01-04 06:39:56 +00:00
|
|
|
void CScriptDock::AreaLoaded(CStateManager& mgr) { SetLoadConnected(mgr, x268_25_loadConnected); }
|
|
|
|
|
2016-12-22 02:48:22 +00:00
|
|
|
void CScriptDock::SetLoadConnected(CStateManager& mgr, bool loadOther)
|
|
|
|
{
|
2017-01-04 04:08:30 +00:00
|
|
|
IGameArea::Dock* dock = mgr.WorldNC()->GetArea(x260_area)->DockNC(x25c_dock);
|
|
|
|
bool cur = dock->GetShouldLoadOther(dock->GetReferenceCount());
|
|
|
|
if (cur == loadOther)
|
|
|
|
return;
|
|
|
|
|
|
|
|
dock->SetShouldLoadOther(dock->GetReferenceCount(), loadOther);
|
2016-12-22 02:48:22 +00:00
|
|
|
}
|
2018-05-14 03:38:36 +00:00
|
|
|
} // namespace urde
|