From 53f52656488663c7ea516c158edc410451694740 Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Mon, 4 Jun 2018 12:30:04 -0700 Subject: [PATCH] Sometimes I hate git --- Runtime/Weapon/CBurstFire.cpp | 18 ++++ Runtime/Weapon/CBurstFire.hpp | 57 ++++++++++ Runtime/Weapon/CProjectileInfo.cpp | 21 ++++ Runtime/Weapon/CProjectileInfo.hpp | 25 +++++ Runtime/World/CAmbientAI.cpp | 163 +++++++++++++++++++++++++++++ Runtime/World/CAmbientAI.hpp | 49 +++++++++ 6 files changed, 333 insertions(+) create mode 100644 Runtime/Weapon/CBurstFire.cpp create mode 100644 Runtime/Weapon/CBurstFire.hpp create mode 100644 Runtime/Weapon/CProjectileInfo.cpp create mode 100644 Runtime/Weapon/CProjectileInfo.hpp create mode 100644 Runtime/World/CAmbientAI.cpp create mode 100644 Runtime/World/CAmbientAI.hpp diff --git a/Runtime/Weapon/CBurstFire.cpp b/Runtime/Weapon/CBurstFire.cpp new file mode 100644 index 000000000..8fe789a6c --- /dev/null +++ b/Runtime/Weapon/CBurstFire.cpp @@ -0,0 +1,18 @@ +#include "CBurstFire.hpp" + +namespace urde +{ +CBurstFire::CBurstFire(SBurst** bursts, s32 firstIndex) + : x10_(firstIndex) +{ + SBurst** burst = bursts; + while (1) + { + if (!*burst) + break; + + x18_bursts.push_back(*burst); + ++burst; + } +} +} diff --git a/Runtime/Weapon/CBurstFire.hpp b/Runtime/Weapon/CBurstFire.hpp new file mode 100644 index 000000000..646077e44 --- /dev/null +++ b/Runtime/Weapon/CBurstFire.hpp @@ -0,0 +1,57 @@ +#ifndef __URDE_CBURSTFIRE_HPP__ +#define __URDE_CBURSTFIRE_HPP__ + +#include "CStateManager.hpp" + +namespace urde +{ +struct SBurst +{ + u32 x0_; + u32 x4_; + u32 x8_; + s32 xc_; + s32 x10_; + u32 x14_; + u32 x18_; + u32 x1c_; + u32 x20_; + float x24_; + float x28_; +}; + +class CBurstFire +{ + s32 x0_ = -1; + s32 x4_ = -1; + float x8_ = 0.f; + u32 xc_ = 0; + s32 x10_; + union + { + struct { bool x14_24_ : 1; bool x14_25_ : 1; }; + u32 _dummy = 0; + }; + + rstl::reserved_vector x18_bursts; +public: + CBurstFire(SBurst**, s32); + + void SetFirstBurst(bool); + void SetBurstType(s32); + bool IsBurstSet() const; + void SetTimeToNextShot(float); + bool ShouldFire() const; + s32 GetBurstType() const; + void Start(CStateManager&); + void Update(CStateManager&, float); + void Update(); + void GetError(float, float) const; + void GetDistanceCompensatedError(float, float) const; + float GetMaxXError() const; + float GetMaxZError() const; + void GetError() const; + void SetFirstBurstIndex(s32); +}; +} +#endif // __URDE_CBURSTFIRE_HPP__ diff --git a/Runtime/Weapon/CProjectileInfo.cpp b/Runtime/Weapon/CProjectileInfo.cpp new file mode 100644 index 000000000..b89378db2 --- /dev/null +++ b/Runtime/Weapon/CProjectileInfo.cpp @@ -0,0 +1,21 @@ +#include "CProjectileInfo.hpp" +#include "World/CDamageInfo.hpp" +#include "GameGlobalObjects.hpp" +#include "CSimplePool.hpp" + +namespace urde +{ + +CProjectileInfo::CProjectileInfo(CAssetId proj, const CDamageInfo & dInfo) +: x0_weaponDescription(g_SimplePool->GetObj({SBIG('WPSC'), proj})) +, xc_damageInfo(dInfo) +{ + +} + +zeus::CVector3f CProjectileInfo::PredictInterceptPos(const zeus::CVector3f &, const zeus::CVector3f &, const CPlayer &, bool) +{ + return {}; +} + +} diff --git a/Runtime/Weapon/CProjectileInfo.hpp b/Runtime/Weapon/CProjectileInfo.hpp new file mode 100644 index 000000000..02361ebda --- /dev/null +++ b/Runtime/Weapon/CProjectileInfo.hpp @@ -0,0 +1,25 @@ +#ifndef __URDE_CPROJECTILEINFO_HPP__ +#define __URDE_CPROJECTILEINFO_HPP__ + +#include "RetroTypes.hpp" +#include "zeus/CVector3f.hpp" +#include "World/CDamageInfo.hpp" +#include "Particle/CWeaponDescription.hpp" + +namespace urde +{ +class CPlayer; +class CProjectileInfo +{ + TToken x0_weaponDescription; + CDamageInfo xc_damageInfo; +public: + CProjectileInfo(CAssetId, const CDamageInfo&); + + zeus::CVector3f PredictInterceptPos(const zeus::CVector3f&, const zeus::CVector3f&, const CPlayer&, bool); + + CDamageInfo GetDamage() const { return xc_damageInfo; } + const TToken& Token() { return x0_weaponDescription; } +}; +} +#endif // __URDE_CPROJECTILEINFO_HPP__ diff --git a/Runtime/World/CAmbientAI.cpp b/Runtime/World/CAmbientAI.cpp new file mode 100644 index 000000000..5a9bdec2f --- /dev/null +++ b/Runtime/World/CAmbientAI.cpp @@ -0,0 +1,163 @@ +#include "CAmbientAI.hpp" +#include "CStateManager.hpp" +#include "CPlayer.hpp" +#include "TCastTo.hpp" + +namespace urde +{ + +CAmbientAI::CAmbientAI(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf, + CModelData&& mData, const zeus::CAABox& aabox, const CMaterialList& matList, float mass, + const CHealthInfo& hInfo, const CDamageVulnerability& dVuln, + const CActorParameters& aParms, float alertRange, float impactRange, s32 alertAnim, s32 impactAnim, bool active) +: CPhysicsActor(uid, active, name, info, xf, std::move(mData), matList, aabox, SMoverData(mass), aParms, 0.3f, 0.1f) +, x258_initialHealthInfo(hInfo) +, x260_healthInfo(hInfo) +, x268_dVuln(dVuln) +, x2d4_alertRange(alertRange) +, x2d8_impactRange(impactRange) +, x2dc_defaultAnim(GetModelData()->GetAnimationData()->GetDefaultAnimation()) +, x2e0_alertAnim(alertAnim) +, x2e4_impactAnim(impactAnim) +{ + ModelData()->AnimationData()->EnableLooping(true); +} + + +void CAmbientAI::Accept(IVisitor& visitor) +{ + visitor.Visit(this); +} + +void CAmbientAI::Think(float dt, CStateManager& mgr) +{ + if (!GetActive()) + return; + + if (GetModelData() && GetModelData()->GetAnimationData()) + { + bool hasAnimTime = GetModelData()->GetAnimationData()->IsAnimTimeRemaining(dt - FLT_EPSILON, "Whole Body"sv); + bool isLooping = GetModelData()->GetIsLoop(); + + if (hasAnimTime || isLooping) + { + x2e8_25_animating = true; + SAdvancementDeltas deltas = UpdateAnimation(dt, mgr, x2e8_25_animating); + MoveToOR(deltas.x0_posDelta, dt); + RotateToOR(deltas.xc_rotDelta, dt); + } + + if (!hasAnimTime || (x2e8_25_animating && !isLooping)) + { + SendScriptMsgs(EScriptObjectState::MaxReached, mgr, EScriptObjectMessage::None); + x2e8_25_animating = false; + } + } + + bool inAlertRange = (mgr.GetPlayer().GetTranslation() - GetTranslation()).magnitude() < x2d4_alertRange; + bool inImpactRange = (mgr.GetPlayer().GetTranslation() - GetTranslation()).magnitude() < x2d8_impactRange; + + switch(x2d0_animState) + { + case EAnimationState::Ready: + { + if (inAlertRange) + { + x2d0_animState = EAnimationState::Alert; + ModelData()->AnimationData()->SetAnimation(CAnimPlaybackParms(x2e0_alertAnim, -1, 1.f, true), false); + ModelData()->EnableLooping(true); + RandomizePlaybackRate(mgr); + } + break; + } + case EAnimationState::Alert: + { + if (!inAlertRange) + { + x2d0_animState = EAnimationState::Ready; + ModelData()->AnimationData()->SetAnimation(CAnimPlaybackParms(x2dc_defaultAnim, -1, 1.f, true), false); + ModelData()->EnableLooping(true); + RandomizePlaybackRate(mgr); + } + else if (inImpactRange) + { + SendScriptMsgs(EScriptObjectState::Dead, mgr, EScriptObjectMessage::None); + SetActive(false); + } + break; + } + case EAnimationState::Impact: + { + if (!x2e8_25_animating) + { + x2d0_animState = EAnimationState::Ready; + ModelData()->AnimationData()->SetAnimation(CAnimPlaybackParms(x2dc_defaultAnim, -1, 1.f, true), false); + ModelData()->EnableLooping(true); + RandomizePlaybackRate(mgr); + } + break; + } + } + + if (!x2e8_24_dead) + { + CHealthInfo* hInfo = HealthInfo(mgr); + if (hInfo->GetHP() <= 0.f) + { + x2e8_24_dead = true; + SendScriptMsgs(EScriptObjectState::Dead, mgr, EScriptObjectMessage::None); + RemoveEmitter(); + SetActive(false); + } + } +} + +void CAmbientAI::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr) +{ + switch(msg) + { + case EScriptObjectMessage::Reset: + { + if (!GetActive()) + SetActive(true); + x2d0_animState = EAnimationState::Ready; + ModelData()->AnimationData()->SetAnimation(CAnimPlaybackParms(x2dc_defaultAnim, -1, 1.f, true), false); + ModelData()->AnimationData()->EnableLooping(true); + RandomizePlaybackRate(mgr); + x2e8_24_dead = false; + x260_healthInfo = x258_initialHealthInfo; + break; + } + case EScriptObjectMessage::Damage: + { + if (GetActive()) + { + x2d0_animState = EAnimationState::Impact; + ModelData()->AnimationData()->SetAnimation(CAnimPlaybackParms(x2e4_impactAnim, -1, 1.f, true), false); + ModelData()->AnimationData()->EnableLooping(false); + RandomizePlaybackRate(mgr); + } + break; + } + case EScriptObjectMessage::InitializedInArea: + RandomizePlaybackRate(mgr); + break; + default: + break; + } + CPhysicsActor::AcceptScriptMsg(msg, uid, mgr); +} + +std::experimental::optional CAmbientAI::GetTouchBounds() const +{ + if (GetActive()) + return {GetBoundingBox()}; + return {}; +} + +void CAmbientAI::RandomizePlaybackRate(CStateManager& mgr) +{ + ModelData()->AnimationData()->MultiplyPlaybackRate(0.4f * mgr.GetActiveRandom()->Float() + 0.8f); +} + +} diff --git a/Runtime/World/CAmbientAI.hpp b/Runtime/World/CAmbientAI.hpp new file mode 100644 index 000000000..f3b39208f --- /dev/null +++ b/Runtime/World/CAmbientAI.hpp @@ -0,0 +1,49 @@ +#ifndef __URDE_CAMBIENTAI_HPP__ +#define __URDE_CAMBIENTAI_HPP__ +#include "CPhysicsActor.hpp" +#include "CDamageVulnerability.hpp" + +namespace urde +{ +class CAmbientAI : public CPhysicsActor +{ + enum class EAnimationState + { + Ready, + Alert, + Impact + }; + + CHealthInfo x258_initialHealthInfo; + CHealthInfo x260_healthInfo; + CDamageVulnerability x268_dVuln; + EAnimationState x2d0_animState= EAnimationState::Ready; + float x2d4_alertRange; + float x2d8_impactRange; + s32 x2dc_defaultAnim; + s32 x2e0_alertAnim; + s32 x2e4_impactAnim; + + union + { + struct { bool x2e8_24_dead : 1; bool x2e8_25_animating : 1; }; + u32 _dummy = 0; + }; + +public: + CAmbientAI(TUniqueId, std::string_view, const CEntityInfo&, const zeus::CTransform&, + CModelData&&, const zeus::CAABox&, const CMaterialList&, float, const CHealthInfo&, const CDamageVulnerability&, + const CActorParameters&, float, float, s32, s32, bool); + + void Accept(IVisitor&); + void Think(float, CStateManager&); + void AcceptScriptMsg(EScriptObjectMessage, TUniqueId, CStateManager&); + CHealthInfo* HealthInfo(CStateManager&) { return &x260_healthInfo; } + const CDamageVulnerability* GetDamageVulnerability() const { return &x268_dVuln; } + std::experimental::optional GetTouchBounds() const; + void Touch(CActor&, CStateManager&) {} + void RandomizePlaybackRate(CStateManager&); +}; + +} +#endif // __URDE_CAMBIENTAI_HPP