From db03927e1d9b92a1a5396b6dd921dd8bf985131d Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Sun, 30 Jul 2017 04:00:30 -0700 Subject: [PATCH] Various imps and minor fixes --- Runtime/CGameState.cpp | 10 ++-- Runtime/CGameState.hpp | 2 +- Runtime/Collision/CCollisionSurface.cpp | 2 +- Runtime/MP1/World/CActorContraption.cpp | 2 +- Runtime/RetroTypes.hpp | 14 ++--- Runtime/World/CActorModelParticles.cpp | 66 ++++++++++++++++++++++ Runtime/World/CActorModelParticles.hpp | 11 ++-- Runtime/World/CEffect.hpp | 6 +- Runtime/World/CFluidPlane.hpp | 1 + Runtime/World/CFluidPlaneDoor.hpp | 14 +++++ Runtime/World/CFluidUVMotion.cpp | 47 ++++++++++++++- Runtime/World/CFluidUVMotion.hpp | 16 ++++-- Runtime/World/CMakeLists.txt | 2 + Runtime/World/CPathFindArea.cpp | 3 +- Runtime/World/CPathFindArea.hpp | 40 +++++++++---- Runtime/World/CPathFindAreaOctree.hpp | 23 ++++++++ Runtime/World/CPathFindOpenList.cpp | 3 +- Runtime/World/CPathFindRegion.cpp | 5 ++ Runtime/World/CPathFindRegion.hpp | 3 +- Runtime/World/CPhysicsActor.cpp | 4 -- Runtime/World/CPhysicsActor.hpp | 2 - Runtime/World/CPlayer.cpp | 2 +- Runtime/World/CScriptPlayerStateChange.cpp | 50 ++++++++++++++++ Runtime/World/CScriptPlayerStateChange.hpp | 36 ++++++++++++ Runtime/World/CScriptTrigger.cpp | 2 +- Runtime/World/CScriptWorldTeleporter.cpp | 6 +- Runtime/World/CScriptWorldTeleporter.hpp | 34 ++++++++++- Runtime/World/ScriptLoader.cpp | 15 ++++- specter | 2 +- 29 files changed, 364 insertions(+), 59 deletions(-) create mode 100644 Runtime/World/CScriptPlayerStateChange.cpp create mode 100644 Runtime/World/CScriptPlayerStateChange.hpp diff --git a/Runtime/CGameState.cpp b/Runtime/CGameState.cpp index f5559591c..45d1de161 100644 --- a/Runtime/CGameState.cpp +++ b/Runtime/CGameState.cpp @@ -129,16 +129,16 @@ CGameState::GameFileStateInfo CGameState::LoadGameFileState(const u8* data) if (origMLVL == 0x158EFE17) itemPercent = 0; else - itemPercent = std::ceil(playerState.CalculateItemCollectionRate() * 100.f / playerState.GetPickupTotal()); + itemPercent = u32(std::ceil(playerState.CalculateItemCollectionRate() * 100.f / playerState.GetPickupTotal())); ret.x18_itemPercent = itemPercent; - float somePercent; + float scanPercent; if (playerState.GetTotalLogScans() == 0) - somePercent = 0.f; + scanPercent = 0.f; else - somePercent = 100.f * playerState.GetLogScans() / float(playerState.GetTotalLogScans()); - ret.x1c_scanPercent = somePercent; + scanPercent = 100.f * playerState.GetLogScans() / float(playerState.GetTotalLogScans()); + ret.x1c_scanPercent = scanPercent; return ret; } diff --git a/Runtime/CGameState.hpp b/Runtime/CGameState.hpp index 78da7e948..e43342efb 100644 --- a/Runtime/CGameState.hpp +++ b/Runtime/CGameState.hpp @@ -71,7 +71,7 @@ class CGameState bool x0_[128] = {}; u32 x80_; - ResId x84_mlvlId = -1; + ResId x84_mlvlId = kInvalidResId; std::vector x88_worldStates; std::shared_ptr x98_playerState; std::shared_ptr x9c_transManager; diff --git a/Runtime/Collision/CCollisionSurface.cpp b/Runtime/Collision/CCollisionSurface.cpp index aee5957f4..44c516e53 100644 --- a/Runtime/Collision/CCollisionSurface.cpp +++ b/Runtime/Collision/CCollisionSurface.cpp @@ -12,7 +12,7 @@ CCollisionSurface::CCollisionSurface(const zeus::CVector3f& a, const zeus::CVect zeus::CVector3f CCollisionSurface::GetNormal() const { - zeus::CVector3f v1 = ((xc_b - x0_a) * ((x18_c - x0_a) * (xc_b - x0_a))) - (x18_c - x0_a); + zeus::CVector3f v1 = xc_b.cross(x0_a); return zeus::CUnitVector3f({v1.y, v1.z, v1.x}, true); } diff --git a/Runtime/MP1/World/CActorContraption.cpp b/Runtime/MP1/World/CActorContraption.cpp index c930a7d40..e1d9db561 100644 --- a/Runtime/MP1/World/CActorContraption.cpp +++ b/Runtime/MP1/World/CActorContraption.cpp @@ -33,7 +33,7 @@ void MP1::CActorContraption::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId else if (msg == EScriptObjectMessage::SetToZero) ResetFlameThrowers(mgr); - AcceptScriptMsg(msg, uid, mgr); + CScriptActor::AcceptScriptMsg(msg, uid, mgr); if (curActive == GetActive() || !GetActive()) return; diff --git a/Runtime/RetroTypes.hpp b/Runtime/RetroTypes.hpp index a8a490689..2a3483fd1 100644 --- a/Runtime/RetroTypes.hpp +++ b/Runtime/RetroTypes.hpp @@ -14,12 +14,13 @@ namespace urde using FourCC = hecl::FourCC; using ResId = u64; +#define kInvalidResId ResId(-1) struct SObjectTag { FourCC type; - ResId id = -1; - operator bool() const { return (id & 0xffffffff) != 0xffffffff; } + ResId id = kInvalidResId; + operator bool() const { return (id != kInvalidResId); } bool operator!=(const SObjectTag& other) const { return id != other.id; } bool operator==(const SObjectTag& other) const { return id == other.id; } bool operator<(const SObjectTag& other) const { return id < other.id; } @@ -41,10 +42,10 @@ struct TEditorId { TEditorId() = default; TEditorId(u32 idin) : id(idin) {} - u32 id = -1; - u8 LayerNum() const { return (id >> 26) & 0x3f; } - u16 AreaNum() const { return (id >> 16) & 0x3ff; } - u16 Id() const { return id & 0xffff; } + u32 id = u32(-1); + u8 LayerNum() const { return u8((id >> 26) & 0x3f); } + u16 AreaNum() const { return u16((id >> 16) & 0x3ff); } + u16 Id() const { return u16(id & 0xffff); } bool operator<(const TEditorId& other) const { return (id & 0x3ffffff) < (other.id & 0x3ffffff); } bool operator!=(const TEditorId& other) const { return (id & 0x3ffffff) != (other.id & 0x3ffffff); } @@ -57,7 +58,6 @@ using TAreaId = s32; #define kInvalidEditorId TEditorId() #define kInvalidUniqueId TUniqueId(-1) #define kInvalidAreaId TAreaId(-1) -#define kInvalidResId ResId(-1) } #if 0 diff --git a/Runtime/World/CActorModelParticles.cpp b/Runtime/World/CActorModelParticles.cpp index 5378be523..f1f983841 100644 --- a/Runtime/World/CActorModelParticles.cpp +++ b/Runtime/World/CActorModelParticles.cpp @@ -20,7 +20,73 @@ CActorModelParticles::CItem::CItem(const CEntity& ent, CActorModelParticles& par x8_.resize(8); } +u32 GetNextBestPt(s32 start, const zeus::CVector3f* vecPtr, s32 vecCount, CRandom16& rnd) +{ + const zeus::CVector3f& startVec = vecPtr[start]; + u32 ret; + float lastMag = 0.f; + for (s32 i = 0; i < 10; ++i) + { + u32 idx = u32(rnd.Range(0, vecCount - 1)); + const zeus::CVector3f& rndVec = vecPtr[idx]; + float mag = (startVec - rndVec).magSquared(); + if (mag > lastMag) + { + ret = idx; + lastMag = mag; + } + } + return ret; +} void CActorModelParticles::CItem::GeneratePoints(const zeus::CVector3f* v1, const zeus::CVector3f* v2, int w1) +{ + for (std::pair, u32>& pair: x8_) + { + if (pair.first) + { + CRandom16 rnd(pair.second); + zeus::CVector3f vec = v1[u32(rnd.Float() * (w1 - 1))]; + pair.first->SetTranslation(xec_ * vec); + } + } + + if (x84_ > 0) + { + CRandom16 rnd(x88_seed1); + u32 count = (x84_ >= 16 ? 16 : x84_); + zeus::CVector3f uVec = zeus::CVector3f::skUp; + u32 idx = x80_; + for (u32 i = 0; i < count; ++i) + { + idx = GetNextBestPt(idx, v1, w1, rnd); + x78_->SetTranslation(xec_ * v1[idx]); + zeus::CVector3f v = v2[idx]; + if (v.canBeNormalized()) + { + v.normalize(); + x78_->SetOrientation(zeus::CTransform{zeus::CVector3f::skUp.cross(v), v, zeus::CVector3f::skUp, zeus::CVector3f::skZero}); + } + x78_->ForceParticleCreation(1); + } + x84_ -= count; + x88_seed1 = rnd.GetSeed(); + } + + if (xb0_ != -1) + { + CRandom16 rnd(xb4_seed2); + + std::unique_ptr iceGen = x128_parent.MakeIceGen(); + iceGen->SetGlobalOrientAndTrans(xf8_); + + u32 next = GetNextBestPt(xb0_, v1, w1, rnd); + iceGen->SetTranslation(xec_ * v1[next]); + + iceGen->SetOrientation(zeus::CTransform::MakeRotationsBasedOnY(zeus::CUnitVector3f(v2[next]))); + } +} + +void CActorModelParticles::CItem::Update(float, CStateManager&) { } diff --git a/Runtime/World/CActorModelParticles.hpp b/Runtime/World/CActorModelParticles.hpp index 68ee81bcc..22d48b3c1 100644 --- a/Runtime/World/CActorModelParticles.hpp +++ b/Runtime/World/CActorModelParticles.hpp @@ -27,15 +27,15 @@ public: TAreaId x4_areaId; rstl::reserved_vector, u32>, 8> x8_; float x6c_ = 0.f; - CSfxHandle x74_sfx; bool x70_ = false; + CSfxHandle x74_sfx; std::unique_ptr x78_; u32 x80_ = 0; u32 x84_ = -1; - u32 x88_ = 99; + u32 x88_seed1 = 99; rstl::reserved_vector, 4> x8c_; u32 xb0_ = -1; - u32 xb4_ = 99; + u32 xb4_seed2 = 99; std::unique_ptr xb8_; std::unique_ptr xc0_; u32 xc8_ = 0; @@ -44,9 +44,7 @@ public: std::unique_ptr xd4_; TToken xdc_ashy; std::unique_ptr xe4_; - float xec_ = 1.f; - float xf0_ = 1.f; - float xf4_ = 1.f; + zeus::CVector3f xec_ = zeus::CVector3f::skOne; zeus::CTransform xf8_; CActorModelParticles& x128_parent; union @@ -63,6 +61,7 @@ public: public: CItem(const CEntity& ent, CActorModelParticles& parent); void GeneratePoints(const zeus::CVector3f* v1, const zeus::CVector3f* v2, int w1); + void Update(float, CStateManager&); }; private: diff --git a/Runtime/World/CEffect.hpp b/Runtime/World/CEffect.hpp index c061805e1..25adc5df1 100644 --- a/Runtime/World/CEffect.hpp +++ b/Runtime/World/CEffect.hpp @@ -9,7 +9,11 @@ namespace urde class CEffect : public CActor { public: - CEffect(TUniqueId uid, const CEntityInfo& info, bool active, const std::string& name, const zeus::CTransform& xf); + CEffect(TUniqueId uid, const CEntityInfo& info, bool active, const std::string& name, + const zeus::CTransform& xf); + + virtual void AddToRenderer(const zeus::CFrustum&, const CStateManager&) const {} + virtual void Render(const CStateManager&) const {} }; } diff --git a/Runtime/World/CFluidPlane.hpp b/Runtime/World/CFluidPlane.hpp index 7e39c65a1..41343a876 100644 --- a/Runtime/World/CFluidPlane.hpp +++ b/Runtime/World/CFluidPlane.hpp @@ -29,6 +29,7 @@ private: EFluidType x44_fluidType; float x48_; public: + CFluidPlane() = default; CFluidPlane(u32, u32, u32, EFluidType, float, const CFluidUVMotion&, float); virtual void Ripple(float mag, TUniqueId rippler, const zeus::CVector3f& pos, diff --git a/Runtime/World/CFluidPlaneDoor.hpp b/Runtime/World/CFluidPlaneDoor.hpp index e69de29bb..34bff1f7e 100644 --- a/Runtime/World/CFluidPlaneDoor.hpp +++ b/Runtime/World/CFluidPlaneDoor.hpp @@ -0,0 +1,14 @@ +#ifndef __URDE_CFLUIDPLANEDOOR_HPP__ +#define __URDE_CFLUIDPLANEDOOR_HPP__ + +#include "CFluidPlane.hpp + +namespace urde +{ +class CFluidPlaneDoor : public CFluidPlane +{ +}; + +} + +#endif // __URDE_CFLUIDPLANEDOOR_HPP__ \ No newline at end of file diff --git a/Runtime/World/CFluidUVMotion.cpp b/Runtime/World/CFluidUVMotion.cpp index 1962f73d1..9ee8968ff 100644 --- a/Runtime/World/CFluidUVMotion.cpp +++ b/Runtime/World/CFluidUVMotion.cpp @@ -1,16 +1,57 @@ #include "CFluidUVMotion.hpp" +#include "zeus/Math.hpp" namespace urde { -CFluidUVMotion::CFluidUVMotion(float a, float b, const urde::CFluidUVMotion::SFluidLayerMotion& c, const urde::CFluidUVMotion::SFluidLayerMotion& d, const urde::CFluidUVMotion::SFluidLayerMotion& e) +CFluidUVMotion::CFluidUVMotion(float a, float b, const CFluidUVMotion::SFluidLayerMotion& c, + const CFluidUVMotion::SFluidLayerMotion& d, const CFluidUVMotion::SFluidLayerMotion& e) +: x4c_(1.f/a) +, x50_(b) { - x4c_ = 1.f / a; - x50_ = b; x0_fluidLayers.resize(3); x0_fluidLayers[0] = c; x0_fluidLayers[1] = d; x0_fluidLayers[2] = e; } +CFluidUVMotion::CFluidUVMotion(float, float) +{} + +void CFluidUVMotion::CalculateFluidTextureOffset(float f31, float offsets[3][2]) +{ + float f29 = f31 * x4c_; + float f28 = f29 * zeus::fastCosF(x50_); + f29 = f29 / zeus::fastSinF(x50_); + + for (u32 i = 0 ; i& GetFluidLayers() const { return x0_fluidLayers; } void GetOrientation() const; void GetOOTimeToWrapTexPage() const; + void CalculateFluidTextureOffset(float, float[3][2]); }; } #endif // __URDE_CFLUIDUVMOTION_HPP__ diff --git a/Runtime/World/CMakeLists.txt b/Runtime/World/CMakeLists.txt index 1e0e7c4be..a89ca2eba 100644 --- a/Runtime/World/CMakeLists.txt +++ b/Runtime/World/CMakeLists.txt @@ -50,6 +50,7 @@ set(WORLD_SOURCES CScriptAreaAttributes.hpp CScriptAreaAttributes.cpp CFishCloud.hpp CFishCloud.cpp CScriptVisorFlare.hpp CScriptVisorFlare.cpp + CScriptWorldTeleporter.hpp CScriptWorldTeleporter.cpp CScriptCameraWaypoint.hpp CScriptCameraWaypoint.cpp CScriptCoverPoint.hpp CScriptCoverPoint.cpp CScriptSpawnPoint.hpp CScriptSpawnPoint.cpp @@ -69,6 +70,7 @@ set(WORLD_SOURCES CScriptActorRotate.hpp CScriptActorRotate.cpp CScriptSpecialFunction.hpp CScriptSpecialFunction.cpp CScriptPlayerHint.hpp CScriptPlayerHint.cpp + CScriptPlayerStateChange.hpp CScriptPlayerStateChange.cpp CScriptTargetingPoint.hpp CScriptTargetingPoint.cpp CScriptPlayerActor.hpp CScriptPlayerActor.cpp CScriptSwitch.hpp CScriptSwitch.cpp diff --git a/Runtime/World/CPathFindArea.cpp b/Runtime/World/CPathFindArea.cpp index ec83c1046..fdfc7192c 100644 --- a/Runtime/World/CPathFindArea.cpp +++ b/Runtime/World/CPathFindArea.cpp @@ -6,13 +6,12 @@ namespace urde { CPFArea::CPFArea(const std::unique_ptr&& buf, int len) { - x13c_ = buf.get(); } std::unique_ptr FPathFindAreaFactory(const SObjectTag& /*tag*/, const std::unique_ptr& buf, const CVParamTransfer &xfer) { return TToken::GetIObjObjectFor( - std::unique_ptr(new CPFArea(std::move(buf), *reinterpret_cast(xfer.GetObj())))); + std::make_unique(std::move(buf), *reinterpret_cast(xfer.GetObj()))); } } diff --git a/Runtime/World/CPathFindArea.hpp b/Runtime/World/CPathFindArea.hpp index 3162d466a..fde400ba8 100644 --- a/Runtime/World/CPathFindArea.hpp +++ b/Runtime/World/CPathFindArea.hpp @@ -20,6 +20,16 @@ public: void Rmv(s32); }; +class CPFNode +{ + zeus::CVector3f x0_position; + zeus::CVector3f xc_normal; +public: + const zeus::CVector3f& GetPos() const { return x0_position; } + const zeus::CVector3f& GetNormal() const { return xc_normal; } +}; + +class CPFAreaOctree; class CPFArea { float x0_ = FLT_MAX; @@ -49,15 +59,9 @@ class CPFArea u32 x74_ = 0; CPFOpenList x78_; u32 x138_; - u8* x13c_ = nullptr; - u32 x140_ = 0; - u8* x144_ = nullptr; - u32 x148_ = 0; - u8* x14c_ = nullptr; - u32 x150_ = 0; - u8* x154_ = nullptr; - u32 x158_ = 0; - u32 x15c_ = 0; + std::unique_ptr x13c_data = nullptr; + std::vector x140_nodes; + /*std::vector<> x150_;*/ u32 x160_ = 0; u32 x164_ = 0; u32 x168_ = 0; @@ -65,9 +69,25 @@ class CPFArea u32 x170_ = 0; u32 x174_ = 0; std::vector x178_; - zeus::CTransform x188_; + zeus::CTransform x188_transform; public: CPFArea(const std::unique_ptr&& buf, int len); + + void SetTransform(const zeus::CTransform& xf) { x188_transform = xf; } + const zeus::CTransform& GetTransform() const { return x188_transform; } + CPFRegion* GetRegion(s32) const { return nullptr; } + void GetClosestPoint() const; + void OpenList(); + void ClosedSet(); + CPFRegionData* GetRegionData() const; + CPFLink* GetLink(s32); + CPFNode* GetNode(s32) const; + CPFAreaOctree* GetOctree(s32); + void GetOctreeRegionPtrs(s32); + void GetOctreeRegionList(const zeus::CVector3f&); + void FindRegions(rstl::reserved_vector&, const zeus::CVector3f&, u32); + void FindClosestRegion(const zeus::CVector3f&, u32, float); + void FindClosestReachablePoint(rstl::reserved_vector&, const zeus::CVector3f&, u32); }; diff --git a/Runtime/World/CPathFindAreaOctree.hpp b/Runtime/World/CPathFindAreaOctree.hpp index e69de29bb..0f6655889 100644 --- a/Runtime/World/CPathFindAreaOctree.hpp +++ b/Runtime/World/CPathFindAreaOctree.hpp @@ -0,0 +1,23 @@ +#ifndef __URDE_CPATHFINDAREAOCTREE_HPP__ +#define __URDE_CPATHFINDAREAOCTREE_HPP__ + +#include "rstl.hpp" +#include "CPathFindRegion.hpp" +#include "zeus/CVector3f.hpp" + +namespace urde +{ +class CPFArea; +class CPFAreaOctree +{ +public: + void Fixup(CPFArea&); + void GetChildIndex(const zeus::CVector3f&) const; + void GetRegionList(const zeus::CVector3f&) const; + void GetRegionListList(rstl::reserved_vector, 32>, const zeus::CVector3f&, float); + bool IsPointInPaddedAABox(const zeus::CVector3f&, float); + void Render(); +}; +} + +#endif // __URDE_CPATHFINDAREAOCTREE_HPP__ \ No newline at end of file diff --git a/Runtime/World/CPathFindOpenList.cpp b/Runtime/World/CPathFindOpenList.cpp index 7e35dc976..fbdbf7dd5 100644 --- a/Runtime/World/CPathFindOpenList.cpp +++ b/Runtime/World/CPathFindOpenList.cpp @@ -1,7 +1,8 @@ #include "CPathFindOpenList.hpp" namespace urde { -CPFOpenList::CPFOpenList() {} +CPFOpenList::CPFOpenList() +{} void CPFOpenList::Clear() {} } diff --git a/Runtime/World/CPathFindRegion.cpp b/Runtime/World/CPathFindRegion.cpp index f6ab1644e..776c2d362 100644 --- a/Runtime/World/CPathFindRegion.cpp +++ b/Runtime/World/CPathFindRegion.cpp @@ -1,7 +1,12 @@ #include "CPathFindRegion.hpp" +#include "CPathFindArea.hpp" namespace urde { +void CPFRegion::Fixup(CPFArea& area, s32& r5) +{ +} + void CPFRegionData::SetOpenLess(CPFRegion* region) { x24_openLess = region; } void CPFRegionData::SetOpenMore(CPFRegion* region) { x28_openMore = region; } diff --git a/Runtime/World/CPathFindRegion.hpp b/Runtime/World/CPathFindRegion.hpp index 46bafcc43..385ecea36 100644 --- a/Runtime/World/CPathFindRegion.hpp +++ b/Runtime/World/CPathFindRegion.hpp @@ -22,7 +22,6 @@ class CPFRegion zeus::CVector3f x28_; zeus::CAABox x34_; u32 x4c_; - public: CPFRegion() = default; void SetData(CPFRegionData*) {} @@ -35,7 +34,7 @@ public: void GetLink(s32) const; void SetCentroid(const zeus::CVector3f&); zeus::CVector3f GetCentroid() const; - void Fixup(CPFArea&, s32); + void Fixup(CPFArea&, s32&); bool IsPointInside(const zeus::CVector3f&); zeus::CVector3f GetNormal(); s32 GetNumNodes() const; diff --git a/Runtime/World/CPhysicsActor.cpp b/Runtime/World/CPhysicsActor.cpp index 4b630b2d5..4005c2f17 100644 --- a/Runtime/World/CPhysicsActor.cpp +++ b/Runtime/World/CPhysicsActor.cpp @@ -51,10 +51,6 @@ float CPhysicsActor::GetStepDownHeight() const { return x240_stepDownHeight; } float CPhysicsActor::GetWeight() const { return 24.525002f * xe8_mass; } -void CPhysicsActor::sub_8011A4C(float f) { x238_maximumCollisionVelocity = f; } - -float CPhysicsActor::sub_8011A4B8() const { return x238_maximumCollisionVelocity; } - void CPhysicsActor::SetPrimitiveOffset(const zeus::CVector2f& offset) { x1e8_primitiveOffset = offset; } zeus::CVector3f CPhysicsActor::GetPrimitiveOffset() { return x1e8_primitiveOffset; } diff --git a/Runtime/World/CPhysicsActor.hpp b/Runtime/World/CPhysicsActor.hpp index 911b7fc88..4b5925c41 100644 --- a/Runtime/World/CPhysicsActor.hpp +++ b/Runtime/World/CPhysicsActor.hpp @@ -133,8 +133,6 @@ public: virtual float GetWeight() const; float GetMass() const { return xe8_mass; } - void sub_8011A4C(float f); - float sub_8011A4B8() const; void SetPrimitiveOffset(const zeus::CVector2f& offset); zeus::CVector3f GetPrimitiveOffset(); void MoveCollisionPrimitive(const zeus::CVector3f& offset); diff --git a/Runtime/World/CPlayer.cpp b/Runtime/World/CPlayer.cpp index 6e566cd2c..86618f0a5 100644 --- a/Runtime/World/CPlayer.cpp +++ b/Runtime/World/CPlayer.cpp @@ -1681,7 +1681,7 @@ void CPlayer::UpdateAimTargetPrediction(const zeus::CTransform& xf, const CState { if (TCastToConstPtr target = mgr.GetObjectById(x3f4_aimTarget)) { - x9c6_27_aimingAtProjectile = TCastToConstPtr(target); + x9c6_27_aimingAtProjectile = TCastToConstPtr(target.GetPtr()); zeus::CVector3f instantTarget = target->GetAimPosition(mgr, 0.f); zeus::CVector3f gunToTarget = instantTarget - xf.origin; float timeToTarget = gunToTarget.magnitude() / x490_gun->GetBeamVelocity(); diff --git a/Runtime/World/CScriptPlayerStateChange.cpp b/Runtime/World/CScriptPlayerStateChange.cpp new file mode 100644 index 000000000..8743ed8e1 --- /dev/null +++ b/Runtime/World/CScriptPlayerStateChange.cpp @@ -0,0 +1,50 @@ +#include "CScriptPlayerStateChange.hpp" +#include "CStateManager.hpp" +#include "CPlayerState.hpp" +#include "Input/ControlMapper.hpp" +#include "TCastTo.hpp" + +namespace urde +{ +CScriptPlayerStateChange::CScriptPlayerStateChange(TUniqueId uid, const std::string& name, const CEntityInfo& info, + bool active, u32 itemType, u32 itemCount, u32 itemCapacity, + EControl control, EControlCommandOption controlCmdOpt) +: CEntity(uid, info, active, name) +, x34_itemType(itemType) +, x38_itemCount(itemCount) +, x3c_itemCapacity(itemCapacity) +, x40_ctrl(control) +, x44_ctrlCmdOpt(controlCmdOpt) +{ +} + +void CScriptPlayerStateChange::Accept(IVisitor& visitor) +{ + visitor.Visit(this); +} + +void CScriptPlayerStateChange::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager& stateMgr) +{ + if (GetActive() && msg == EScriptObjectMessage::SetToZero) + { + stateMgr.GetPlayerState()->InitializePowerUp(CPlayerState::EItemType(x34_itemType), x3c_itemCapacity); + stateMgr.GetPlayerState()->IncrPickup(CPlayerState::EItemType(x34_itemType), x38_itemCount); + + if (x44_ctrlCmdOpt == EControlCommandOption::Filtered && x40_ctrl == EControl::Filtered) + { + bool filtered = x44_ctrlCmdOpt != EControlCommandOption::Unfiltered; + ControlMapper::SetCommandFiltered(ControlMapper::ECommands::OrbitClose, filtered); + ControlMapper::SetCommandFiltered(ControlMapper::ECommands::OrbitConfirm, filtered); + ControlMapper::SetCommandFiltered(ControlMapper::ECommands::OrbitDown, filtered); + ControlMapper::SetCommandFiltered(ControlMapper::ECommands::OrbitFar, filtered); + ControlMapper::SetCommandFiltered(ControlMapper::ECommands::OrbitLeft, filtered); + ControlMapper::SetCommandFiltered(ControlMapper::ECommands::OrbitObject, filtered); + ControlMapper::SetCommandFiltered(ControlMapper::ECommands::OrbitRight, filtered); + ControlMapper::SetCommandFiltered(ControlMapper::ECommands::OrbitSelect, filtered); + ControlMapper::SetCommandFiltered(ControlMapper::ECommands::OrbitUp, filtered); + } + } + + CEntity::AcceptScriptMsg(msg, objId, stateMgr); +} +} \ No newline at end of file diff --git a/Runtime/World/CScriptPlayerStateChange.hpp b/Runtime/World/CScriptPlayerStateChange.hpp new file mode 100644 index 000000000..cf2f7f96c --- /dev/null +++ b/Runtime/World/CScriptPlayerStateChange.hpp @@ -0,0 +1,36 @@ +#ifndef __URDE_CSCRIPTPLAYERSTATECHANGE_HPP__ +#define __URDE_CSCRIPTPLAYERSTATECHANGE_HPP__ + +#include "World/CEntity.hpp" + +namespace urde +{ +class CScriptPlayerStateChange : public CEntity +{ +public: + enum class EControl + { + Unfiltered, + Filtered + }; + enum class EControlCommandOption + { + Unfiltered, + Filtered + }; +private: + u32 x34_itemType; + u32 x38_itemCount; + u32 x3c_itemCapacity; + EControl x40_ctrl; + EControlCommandOption x44_ctrlCmdOpt; +public: + CScriptPlayerStateChange(TUniqueId, const std::string&, const CEntityInfo&, bool, u32, u32, u32, EControl, + EControlCommandOption); + void Accept(IVisitor& visit); + void AcceptScriptMsg(EScriptObjectMessage, TUniqueId, CStateManager&); +}; +} + + +#endif // __URDE_CSCRIPTPLAYERSTATECHANGE_HPP__ diff --git a/Runtime/World/CScriptTrigger.cpp b/Runtime/World/CScriptTrigger.cpp index 4883c1429..67af517c6 100644 --- a/Runtime/World/CScriptTrigger.cpp +++ b/Runtime/World/CScriptTrigger.cpp @@ -266,7 +266,7 @@ void CScriptTrigger::Touch(CActor& act, CStateManager& mgr) if (pl) { - if (x148_28_ == false) + if (!x148_28_) { x148_28_ = true; if (x148_29_didPhazonDamage) diff --git a/Runtime/World/CScriptWorldTeleporter.cpp b/Runtime/World/CScriptWorldTeleporter.cpp index 5ac2b0077..dfeaa9d24 100644 --- a/Runtime/World/CScriptWorldTeleporter.cpp +++ b/Runtime/World/CScriptWorldTeleporter.cpp @@ -2,5 +2,9 @@ namespace urde { - +CScriptWorldTeleporter::CScriptWorldTeleporter(TUniqueId uid, const std::string& name, const CEntityInfo& info, + bool active, u32, u32) +: CEntity(uid, info, active, name) +{ +} } diff --git a/Runtime/World/CScriptWorldTeleporter.hpp b/Runtime/World/CScriptWorldTeleporter.hpp index 5e9fbed44..43e91b774 100644 --- a/Runtime/World/CScriptWorldTeleporter.hpp +++ b/Runtime/World/CScriptWorldTeleporter.hpp @@ -2,16 +2,44 @@ #define __CSCRIPTWORLDTELEPORTER_HPP__ #include "CEntity.hpp" +#include "zeus/CVector3f.hpp" namespace urde { -class CScriptWorldTeleporter +class CScriptWorldTeleporter : public CEntity { + u32 x34_; + u32 x38_; + u32 x3c_ = 0; + union + { + struct + { + bool x40_24_ : 1; + bool x40_25_ : 1; + bool x40_26_ : 1; + bool x40_27_ : 1; + }; + u8 _dummy = 0; + }; + + float x44_ = 0.1f; + float x48_ = 8.0f; + float x4c_ = 0.0f; + u32 x50_ = -1; + u32 x54_ = -1; + u32 x58_ = 0; + zeus::CVector3f x5c_; + u32 x68_ = -1; + zeus::CVector3f x6c_; + u32 x78_ = -1; + zeus::CVector3f x7c_; + u32 x88_ = -1; + public: - + CScriptWorldTeleporter(TUniqueId, const std::string&, const CEntityInfo&, bool, u32, u32); }; - } #endif // __CSCRIPTWORLDTELEPORTER_HPP__ diff --git a/Runtime/World/ScriptLoader.cpp b/Runtime/World/ScriptLoader.cpp index 83ca22bc0..a02b01834 100644 --- a/Runtime/World/ScriptLoader.cpp +++ b/Runtime/World/ScriptLoader.cpp @@ -50,6 +50,7 @@ #include "CScriptActorRotate.hpp" #include "CScriptSpecialFunction.hpp" #include "CScriptSwitch.hpp" +#include "CScriptPlayerStateChange.hpp" #include "CWallCrawlerSwarm.hpp" #include "CScriptAiJumpPoint.hpp" #include "CScriptColorModulate.hpp" @@ -1896,7 +1897,19 @@ CEntity* ScriptLoader::LoadSwitch(CStateManager& mgr, CInputStream& in, int prop CEntity* ScriptLoader::LoadPlayerStateChange(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info) { - return nullptr; + if (!EnsurePropertyCount(propCount, 7, "PlayerStateChange")) + return nullptr; + + std::string name = mgr.HashInstanceName(in); + bool active = in.readBool(); + s32 itemType = in.readUint32Big(); + s32 itemCount = in.readInt32Big(); + s32 itemCapacity = in.readInt32Big(); + CScriptPlayerStateChange::EControl ctrl = CScriptPlayerStateChange::EControl(in.readUint32Big()); + CScriptPlayerStateChange::EControlCommandOption ctrlCmdOpt = + CScriptPlayerStateChange::EControlCommandOption(in.readUint32Big()); + return new CScriptPlayerStateChange(mgr.AllocateUniqueId(), name, info, active, itemType, itemCount, itemCapacity, + ctrl, ctrlCmdOpt); } CEntity* ScriptLoader::LoadThardus(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info) diff --git a/specter b/specter index cd448ae32..855551039 160000 --- a/specter +++ b/specter @@ -1 +1 @@ -Subproject commit cd448ae32819248448d04fa3ff050c2a82e1d190 +Subproject commit 855551039ca6aeefefe282e39965c3d79d932926