metaforce/Runtime/Weapon/CPlayerGun.hpp

418 lines
15 KiB
C++
Raw Normal View History

#ifndef __URDE_CPLAYERGUN_HPP__
#define __URDE_CPLAYERGUN_HPP__
#include "RetroTypes.hpp"
#include "Character/CActorLights.hpp"
#include "CFidget.hpp"
#include "zeus/CTransform.hpp"
#include "zeus/CAABox.hpp"
2016-11-22 20:43:16 +00:00
#include "World/CPlayerCameraBob.hpp"
#include "CGunMotion.hpp"
#include "CGrappleArm.hpp"
#include "CAuxWeapon.hpp"
#include "CPowerBeam.hpp"
#include "CIceBeam.hpp"
#include "CWaveBeam.hpp"
#include "CPlasmaBeam.hpp"
#include "CPhazonBeam.hpp"
#include "Particle/CElementGen.hpp"
#include "Character/CModelData.hpp"
2016-11-22 20:43:16 +00:00
#include "World/CWorldShadow.hpp"
2017-06-12 04:23:34 +00:00
#include "World/ScriptObjectSupport.hpp"
#include "Graphics/CRainSplashGenerator.hpp"
2017-09-03 05:53:38 +00:00
#include "Graphics/Shaders/CTexturedQuadFilter.hpp"
#include "Graphics/Shaders/CAABoxShader.hpp"
namespace urde
{
2017-07-16 06:13:37 +00:00
class CFinalInput;
class CPlayerGun
{
2017-04-04 05:48:13 +00:00
public:
2017-10-15 05:44:07 +00:00
static float skTractorBeamFactor;
2017-04-04 05:48:13 +00:00
enum class EMissleMode
{
Inactive,
Active
};
2017-08-16 05:34:02 +00:00
enum class EBWeapon
{
Bomb,
PowerBomb
2017-08-16 05:34:02 +00:00
};
2017-09-02 04:06:05 +00:00
enum class EPhazonBeamState
2017-08-25 06:18:09 +00:00
{
2017-09-02 04:06:05 +00:00
Inactive,
Entering,
Exiting,
Active
};
enum class EChargePhase
{
NotCharging,
ChargeRequested,
AnimAndSfx,
FxGrowing,
FxGrown,
ComboXfer,
ComboXferDone,
ComboFire,
ComboFireDone,
ChargeCancelled,
ChargeDone
};
enum class ENextState
{
StatusQuo,
EnterMissile,
ExitMissile,
MissileShotDone,
MissileReload,
ChangeWeapon,
SetupBeam,
Seven,
EnterPhazonBeam,
ExitPhazonBeam
};
enum class EIdleState
{
NotIdle,
Wander,
Idle,
Three,
Four
2017-08-25 06:18:09 +00:00
};
2017-04-04 05:48:13 +00:00
private:
2017-08-16 05:34:02 +00:00
class CGunMorph
{
2017-08-25 06:18:09 +00:00
public:
enum class EGunState
{
2017-08-31 02:42:37 +00:00
InWipeDone,
OutWipeDone,
InWipe,
OutWipe
};
enum class EMorphEvent
{
None,
InWipeDone,
OutWipeDone
};
enum class EDir
{
In,
Out,
Done
2017-08-25 06:18:09 +00:00
};
private:
2017-08-31 02:42:37 +00:00
float x0_yLerp = 0.f;
float x4_gunTransformTime;
2017-08-31 02:42:37 +00:00
float x8_remTime = 0.f;
float xc_speed = 0.1f;
float x10_holoHoldTime;
2017-08-31 02:42:37 +00:00
float x14_remHoldTime = 2.f;
2017-08-16 05:34:02 +00:00
float x18_transitionFactor = 1.f;
2017-08-31 02:42:37 +00:00
EDir x1c_dir = EDir::Done;
EGunState x20_gunState = EGunState::OutWipeDone;
union
{
struct
{
2017-08-31 02:42:37 +00:00
bool x24_24_morphing : 1;
bool x24_25_weaponChanged : 1;
};
2017-08-16 05:34:02 +00:00
u32 _dummy = 0;
};
2017-08-16 05:34:02 +00:00
public:
CGunMorph(float gunTransformTime, float holoHoldTime)
: x4_gunTransformTime(gunTransformTime), x10_holoHoldTime(std::fabs(holoHoldTime)) {}
2017-08-31 02:42:37 +00:00
float GetYLerp() const { return x0_yLerp; }
2017-08-16 05:34:02 +00:00
float GetTransitionFactor() const { return x18_transitionFactor; }
2017-08-25 06:18:09 +00:00
EGunState GetGunState() const { return x20_gunState; }
2017-08-31 02:42:37 +00:00
void SetWeaponChanged() { x24_25_weaponChanged = true; }
EMorphEvent Update(float inY, float outY, float dt);
void StartWipe(EDir dir);
2017-08-16 05:34:02 +00:00
};
class CMotionState
{
2017-08-26 04:36:25 +00:00
public:
enum class EMotionState
{
Zero,
One,
2017-09-02 04:06:05 +00:00
LockOn,
CancelLockOn
};
enum class EFireState
{
NotFiring,
StartFire,
Firing
2017-08-26 04:36:25 +00:00
};
private:
static float gGunExtendDistance;
2017-09-02 04:06:05 +00:00
bool x0_24_extendParabola = true;
float x4_extendParabolaDelayTimer = 0.f;
float x8_fireTime = 0.f;
float xc_curExtendDist = 0.f;
float x10_curRotation = 0.f;
float x14_rotationT = 0.f;
float x18_startRotation = 0.f;
float x1c_endRotation = 0.f;
2017-08-26 04:36:25 +00:00
EMotionState x20_state = EMotionState::Zero;
2017-09-02 04:06:05 +00:00
EFireState x24_fireState = EFireState::NotFiring;
public:
static void SetExtendDistance(float d) { gGunExtendDistance = d; }
2017-08-26 04:36:25 +00:00
void SetState(EMotionState state) { x20_state = state; }
2017-09-02 04:06:05 +00:00
void Update(bool firing, float dt, zeus::CTransform& xf, CStateManager& mgr);
};
CActorLights x0_lights;
2017-08-26 04:36:25 +00:00
CSfxHandle x2e0_chargeSfx;
CSfxHandle x2e4_invalidSfx;
2017-08-31 02:42:37 +00:00
CSfxHandle x2e8_phazonBeamSfx;
// 0x1: FireOrBomb, 0x2: MissileOrPowerBomb
u32 x2ec_lastFireButtonStates = 0;
u32 x2f0_pressedFireButtonStates = 0;
u32 x2f4_fireButtonStates = 0;
2017-09-02 04:06:05 +00:00
// 0x1: beam mode, 0x2: missile mode, 0x4: missile ready, 0x8: morphing, 0x10: combo fire
u32 x2f8_stateFlags = 0x1;
u32 x2fc_fidgetAnimBits = 0;
2017-09-02 04:06:05 +00:00
u32 x300_remainingMissiles = 0;
u32 x304_ = 0;
2017-02-18 02:19:50 +00:00
u32 x308_bombCount = 3;
2017-09-02 04:06:05 +00:00
u32 x30c_rapidFireShots = 0;
2017-08-31 02:42:37 +00:00
CPlayerState::EBeamId x310_currentBeam = CPlayerState::EBeamId::Power;
CPlayerState::EBeamId x314_nextBeam = CPlayerState::EBeamId::Power;
2017-09-02 04:06:05 +00:00
u32 x318_comboAmmoIdx = 0;
2017-04-04 05:48:13 +00:00
EMissleMode x31c_missileMode = EMissleMode::Inactive;
2017-08-31 02:42:37 +00:00
CPlayerState::EBeamId x320_currentAuxBeam = CPlayerState::EBeamId::Power;
2017-09-02 04:06:05 +00:00
EIdleState x324_idleState = EIdleState::Four;
float x328_animSfxPitch = 0.f;
EChargePhase x32c_chargePhase = EChargePhase::NotCharging;
EChargeState x330_chargeState = EChargeState::Normal;
u32 x334_ = 0;
2017-09-02 04:06:05 +00:00
ENextState x338_nextState = ENextState::StatusQuo;
EPhazonBeamState x33c_phazonBeamState = EPhazonBeamState::Inactive;
2017-04-04 05:48:13 +00:00
float x340_chargeBeamFactor = 0.f;
2017-09-02 04:06:05 +00:00
float x344_comboXferTimer = 0.f;
float x348_chargeCancelTimer = 0.f;
2017-08-26 04:36:25 +00:00
float x34c_shakeX = 0.f;
float x350_shakeZ = 0.f;
float x354_bombFuseTime;
float x358_bombDropDelayTime;
2017-02-18 02:19:50 +00:00
float x35c_bombTime = 0.f;
float x360_ = 0.f;
2017-09-02 04:06:05 +00:00
float x364_gunStrikeCoolTimer = 0.f;
float x368_idleWanderDelayTimer = 0.f;
float x36c_ = 1.f;
2017-08-26 04:36:25 +00:00
float x370_gunMotionSpeedMult = 1.f;
float x374_ = 0.f;
2017-09-02 04:06:05 +00:00
float x378_shotSmokeStartTimer = 0.f;
float x37c_rapidFireShotsDecayTimer = 0.f;
float x380_shotSmokeTimer = 0.f;
float x384_gunStrikeDelayTimer = 0.f;
float x388_enterFreeLookDelayTimer = 0.f;
float x38c_muzzleEffectVisTimer = 0.f;
2017-08-26 04:36:25 +00:00
float x390_cooldown = 0.f;
2017-08-25 06:18:09 +00:00
float x394_damageTimer = 0.f;
float x398_damageAmt = 0.f;
2017-08-31 02:42:37 +00:00
float x39c_phazonMorphT = 0.f;
2017-09-02 04:06:05 +00:00
float x3a0_missileExitTimer = 0.f;
CFidget x3a4_fidget;
zeus::CVector3f x3dc_damageLocation;
2017-07-19 17:47:57 +00:00
zeus::CTransform x3e8_xf;
2017-08-26 04:36:25 +00:00
zeus::CTransform x418_beamLocalXf;
zeus::CTransform x448_elbowWorldXf;
2017-07-23 23:45:04 +00:00
zeus::CTransform x478_assistAimXf;
2017-08-26 04:36:25 +00:00
zeus::CTransform x4a8_gunWorldXf;
zeus::CTransform x4d8_gunLocalXf;
zeus::CTransform x508_elbowLocalXf;
2017-08-25 06:18:09 +00:00
TUniqueId x538_playerId;
TUniqueId x53a_powerBomb = kInvalidUniqueId;
2017-08-25 06:18:09 +00:00
TUniqueId x53c_lightId = kInvalidUniqueId;
std::vector<CToken> x540_handAnimTokens;
CPlayerCameraBob x550_camBob;
u32 x658_ = 1;
float x65c_ = 0.f;
float x660_ = 0.f;
float x664_ = 0.f;
float x668_aimVerticalSpeed;
float x66c_aimHorizontalSpeed;
2017-09-02 04:06:05 +00:00
std::pair<u16, CSfxHandle> x670_animSfx = {0xffff, {}};
CGunMorph x678_morph;
2017-08-26 04:36:25 +00:00
CMotionState x6a0_motionState;
2017-08-31 02:42:37 +00:00
zeus::CAABox x6c8_hologramClipCube;
CModelData x6e0_rightHandModel;
CGunWeapon* x72c_currentBeam = nullptr;
2017-08-31 02:42:37 +00:00
CGunWeapon* x730_outgoingBeam = nullptr;
CGunWeapon* x734_loadingBeam = nullptr;
CGunWeapon* x738_nextBeam = nullptr;
std::unique_ptr<CGunMotion> x73c_gunMotion;
std::unique_ptr<CGrappleArm> x740_grappleArm;
std::unique_ptr<CAuxWeapon> x744_auxWeapon;
std::unique_ptr<CRainSplashGenerator> x748_rainSplashGenerator;
std::unique_ptr<CPowerBeam> x74c_powerBeam;
std::unique_ptr<CIceBeam> x750_iceBeam;
std::unique_ptr<CWaveBeam> x754_waveBeam;
std::unique_ptr<CPlasmaBeam> x758_plasmaBeam;
std::unique_ptr<CPhazonBeam> x75c_phazonBeam;
CGunWeapon* x760_selectableBeams[4] = {}; // Used to be reserved_vector
std::unique_ptr<CElementGen> x774_holoTransitionGen;
2017-09-02 04:06:05 +00:00
std::unique_ptr<CElementGen> x77c_comboXferGen;
rstl::reserved_vector<rstl::reserved_vector<TLockedToken<CGenDescription>, 2>, 2> x784_bombEffects;
rstl::reserved_vector<TLockedToken<CGenDescription>, 5> x7c0_auxMuzzleEffects;
rstl::reserved_vector<std::unique_ptr<CElementGen>, 5> x800_auxMuzzleGenerators;
std::unique_ptr<CWorldShadow> x82c_shadow;
2017-08-26 04:36:25 +00:00
s16 x830_chargeRumbleHandle = -1;
union
{
struct
{
2017-09-02 04:06:05 +00:00
bool x832_24_cancellingCharge : 1;
bool x832_25_chargeEffectVisible : 1;
bool x832_26_comboFiring : 1;
bool x832_27_chargeAnimStarted : 1;
bool x832_28_readyForShot : 1;
bool x832_29_lockedOn : 1;
bool x832_30_requestReturnToDefault : 1;
bool x832_31_inRestPose : 1;
2017-07-20 06:04:40 +00:00
bool x833_24_isFidgeting : 1;
bool x833_25_ : 1;
bool x833_26_ : 1;
bool x833_27_ : 1;
2017-08-25 06:18:09 +00:00
bool x833_28_phazonBeamActive : 1;
2017-08-26 04:36:25 +00:00
bool x833_29_pointBlankWorldSurface : 1;
2017-09-02 04:06:05 +00:00
bool x833_30_canShowAuxMuzzleEffect : 1;
bool x833_31_inFreeLook : 1;
2017-04-04 05:48:13 +00:00
bool x834_24_charging : 1;
2017-09-02 04:06:05 +00:00
bool x834_25_gunMotionFidgeting : 1;
bool x834_26_animPlaying : 1;
2017-08-25 06:18:09 +00:00
bool x834_27_underwater : 1;
2017-09-02 04:06:05 +00:00
bool x834_28_requestImmediateRecharge : 1;
2017-08-26 04:36:25 +00:00
bool x834_29_frozen : 1;
bool x834_30_inBigStrike : 1;
2017-09-02 04:06:05 +00:00
bool x834_31_gunMotionInFidgetBasePosition : 1;
2017-08-25 06:18:09 +00:00
bool x835_24_canFirePhazon : 1;
bool x835_25_inPhazonBeam : 1;
bool x835_26_phazonBeamMorphing : 1;
bool x835_27_intoPhazonBeam : 1;
2017-04-08 20:40:36 +00:00
bool x835_28_bombReady : 1;
bool x835_29_powerBombReady : 1;
2017-08-25 06:18:09 +00:00
bool x835_30_inPhazonPool : 1;
2017-08-19 06:52:13 +00:00
bool x835_31_actorAttached : 1;
};
u32 _dummy = 0;
};
mutable CTexturedQuadFilter m_screenQuad = {EFilterType::Blend, CGraphics::g_SpareTexture.get(), true};
2017-09-03 05:53:38 +00:00
mutable CAABoxShader m_aaboxShader = {true};
void InitBeamData();
void InitBombData();
void InitMuzzleData();
void InitCTData();
void LoadHandAnimTokens();
2017-08-25 06:18:09 +00:00
void CreateGunLight(CStateManager& mgr);
void DeleteGunLight(CStateManager& mgr);
2017-09-02 04:06:05 +00:00
void UpdateGunLight(const zeus::CTransform& xf, CStateManager& mgr);
2017-08-25 06:18:09 +00:00
void SetGunLightActive(bool active, CStateManager& mgr);
void SetPhazonBeamMorph(bool intoPhazonBeam);
void Reset(CStateManager& mgr, bool b1);
void ResetBeamParams(CStateManager& mgr, const CPlayerState& playerState, bool playSelectionSfx);
2017-08-26 04:36:25 +00:00
void PlayAnim(NWeaponTypes::EGunAnimType type, bool loop);
2017-08-25 06:18:09 +00:00
void CancelCharge(CStateManager& mgr, bool withEffect);
2017-08-26 04:36:25 +00:00
bool ExitMissile();
void StopChargeSound(CStateManager& mgr);
void UnLoadFidget();
2017-09-02 04:06:05 +00:00
void ReturnArmAndGunToDefault(CStateManager& mgr, bool returnToDefault);
2017-08-26 04:36:25 +00:00
void ReturnToRestPose();
void ChangeWeapon(const CPlayerState& playerState, CStateManager& mgr);
void GetLctrWithShake(zeus::CTransform& xfOut, const CModelData& mData, const std::string& lctrName,
2017-08-31 02:42:37 +00:00
bool shake, bool dyn);
2017-08-26 04:36:25 +00:00
void UpdateLeftArmTransform(const CModelData& mData, const CStateManager& mgr);
void ProcessGunMorph(float dt, CStateManager& mgr);
2017-08-31 02:42:37 +00:00
void SetPhazonBeamFeedback(bool active);
void StartPhazonBeamTransition(bool active, CStateManager& mgr, CPlayerState& playerState);
2017-08-26 04:36:25 +00:00
void ProcessPhazonGunMorph(float dt, CStateManager& mgr);
2017-09-02 04:06:05 +00:00
void EnableChargeFx(EChargeState state, CStateManager& mgr);
2017-08-26 04:36:25 +00:00
void UpdateChargeState(float dt, CStateManager& mgr);
void UpdateAuxWeapons(float dt, const zeus::CTransform& targetXf, CStateManager& mgr);
2017-09-02 04:06:05 +00:00
void DoUserAnimEvent(float dt, CStateManager& mgr, const CInt32POINode& node, EUserEventType type);
2017-08-26 04:36:25 +00:00
void DoUserAnimEvents(float dt, CStateManager& mgr);
TUniqueId GetTargetId(CStateManager& mgr) const;
void CancelLockOn();
void FireSecondary(float dt, CStateManager& mgr);
void ResetCharged(float dt, CStateManager& mgr);
void ActivateCombo(CStateManager& mgr);
void ProcessChargeState(u32 releasedStates, u32 pressedStates, CStateManager& mgr, float dt);
void ResetNormal(CStateManager& mgr);
void UpdateNormalShotCycle(float dt, CStateManager& mgr);
void ProcessNormalState(u32 releasedStates, u32 pressedStates, CStateManager& mgr, float dt);
2017-08-26 04:36:25 +00:00
void UpdateWeaponFire(float dt, const CPlayerState& playerState, CStateManager& mgr);
void EnterFreeLook(CStateManager& mgr);
2017-09-04 02:22:46 +00:00
void SetFidgetAnimBits(int animSet, bool beamOnly);
void AsyncLoadFidget(CStateManager& mgr);
bool IsFidgetLoaded() const;
void EnterFidget(CStateManager& mgr);
2017-09-02 04:06:05 +00:00
void UpdateGunIdle(bool inStrikeCooldown, float camBobT, float dt, CStateManager& mgr);
2017-08-31 02:42:37 +00:00
void RenderEnergyDrainEffects(const CStateManager& mgr) const;
void DrawArm(const CStateManager& mgr, const zeus::CVector3f& pos, const CModelFlags& flags) const;
zeus::CVector3f ConvertToScreenSpace(const zeus::CVector3f& pos, const CGameCamera& cam) const;
2017-09-03 05:53:38 +00:00
static void CopyScreenTex();
void DrawScreenTex(float z) const;
void DrawClipCube(const zeus::CAABox& aabb) const;
public:
explicit CPlayerGun(TUniqueId playerId);
2017-08-26 04:36:25 +00:00
void TakeDamage(bool bigStrike, bool notFromMetroid, CStateManager& mgr);
2017-08-13 05:26:14 +00:00
void AcceptScriptMsg(EScriptObjectMessage, TUniqueId, CStateManager&);
void AsyncLoadSuit(CStateManager& mgr);
2017-07-31 05:19:05 +00:00
void TouchModel(const CStateManager& stateMgr);
2017-04-04 05:48:13 +00:00
EMissleMode GetMissleMode() const { return x31c_missileMode; }
2017-07-20 06:04:40 +00:00
bool IsFidgeting() const { return x833_24_isFidgeting; }
2017-04-08 20:40:36 +00:00
bool IsCharging() const { return x834_24_charging; }
float GetChargeBeamFactor() const { return x340_chargeBeamFactor; }
bool IsBombReady() const { return x835_28_bombReady; }
u32 GetBombCount() const { return x308_bombCount; }
bool IsPowerBombReady() const { return x835_29_powerBombReady; }
2017-08-31 02:42:37 +00:00
CPlayerState::EBeamId GetCurrentBeam() const { return x310_currentBeam; }
CPlayerState::EBeamId GetNextBeam() const { return x314_nextBeam; }
2017-04-09 06:14:22 +00:00
const CGunMorph& GetGunMorph() const { return x678_morph; }
2017-08-16 05:34:02 +00:00
float GetHoloTransitionFactor() const { return x678_morph.GetTransitionFactor(); }
2017-07-19 17:47:57 +00:00
void SetTransform(const zeus::CTransform& xf) { x3e8_xf = xf; }
2017-07-23 23:45:04 +00:00
void SetAssistAimTransform(const zeus::CTransform& xf) { x478_assistAimXf = xf; }
CGrappleArm& GetGrappleArm() { return *x740_grappleArm; }
void DamageRumble(const zeus::CVector3f& location, float damage, const CStateManager& mgr);
2017-08-25 06:18:09 +00:00
void ResetCharge(CStateManager& mgr, bool b1);
void HandleBeamChange(const CFinalInput& input, CStateManager& mgr);
void HandlePhazonBeamChange(CStateManager& mgr);
void HandleWeaponChange(const CFinalInput& input, CStateManager& mgr);
2017-07-16 06:13:37 +00:00
void ProcessInput(const CFinalInput& input, CStateManager& mgr);
2017-07-17 03:04:14 +00:00
void ResetIdle(CStateManager& mgr);
void CancelFiring(CStateManager& mgr);
2017-07-23 23:45:04 +00:00
float GetBeamVelocity() const;
2017-08-25 06:18:09 +00:00
void StopContinuousBeam(CStateManager& mgr, bool b1);
2017-08-16 05:34:02 +00:00
void Update(float grappleSwingT, float cameraBobT, float dt, CStateManager& mgr);
2017-07-31 05:19:05 +00:00
void PreRender(const CStateManager& mgr, const zeus::CFrustum& frustum, const zeus::CVector3f& camPos);
void Render(const CStateManager& mgr, const zeus::CVector3f& pos, const CModelFlags& flags) const;
void AddToRenderer(const zeus::CFrustum& frustum, const CStateManager& mgr) const;
u32 GetLastFireButtonStates() const { return x2ec_lastFireButtonStates; }
void DropBomb(EBWeapon weapon, CStateManager& mgr);
2017-08-16 05:34:02 +00:00
TUniqueId DropPowerBomb(CStateManager& mgr);
2017-08-19 06:52:13 +00:00
void SetActorAttached(bool b) { x835_31_actorAttached = b; }
};
}
#endif // __URDE_CPLAYERGUN_HPP__