metaforce/Runtime/Weapon/CGunWeapon.hpp

160 lines
6.7 KiB
C++
Raw Normal View History

2018-10-07 03:42:33 +00:00
#pragma once
#include "RetroTypes.hpp"
#include "CWeaponMgr.hpp"
#include "Collision/CMaterialList.hpp"
#include "zeus/CVector3f.hpp"
#include "CPlayerState.hpp"
#include "Character/CAnimCharacterSet.hpp"
#include "Particle/CElementGen.hpp"
#include "CToken.hpp"
2017-08-25 06:18:09 +00:00
#include "CStateManager.hpp"
2017-08-26 04:36:25 +00:00
#include "CGunController.hpp"
#include "WeaponCommon.hpp"
#include "CGunMotion.hpp"
2017-09-05 03:00:19 +00:00
#include "World/CDamageInfo.hpp"
2018-12-08 05:30:43 +00:00
namespace urde {
class CActorLights;
2016-12-11 01:54:08 +00:00
struct CModelFlags;
2017-07-23 23:45:04 +00:00
class CWeaponDescription;
2018-12-08 05:30:43 +00:00
enum class EChargeState { Normal, Charged };
2017-08-26 04:36:25 +00:00
using SWeaponInfo = DataSpec::SWeaponInfo;
2017-09-05 03:00:19 +00:00
using SShotParam = DataSpec::SShotParam;
using SChargedShotParam = DataSpec::SChargedShotParam;
2017-08-26 04:36:25 +00:00
2018-12-08 05:30:43 +00:00
class CVelocityInfo {
friend class CGunWeapon;
rstl::reserved_vector<zeus::CVector3f, 2> x0_vel;
rstl::reserved_vector<bool, 2> x1c_targetHoming;
rstl::reserved_vector<float, 2> x24_trat;
2017-07-23 23:45:04 +00:00
public:
2018-12-08 05:30:43 +00:00
const zeus::CVector3f& GetVelocity(int i) const { return x0_vel[i]; }
bool GetTargetHoming(int i) const { return x1c_targetHoming[i]; }
void Clear() {
x0_vel.clear();
x1c_targetHoming.clear();
x24_trat.clear();
}
2017-07-23 23:45:04 +00:00
};
2018-12-08 05:30:43 +00:00
class CGunWeapon {
public:
2018-12-08 05:30:43 +00:00
enum class ESecondaryFxType { None, Charge, ToCombo, CancelCharge };
enum class EFrozenFxType { None, Frozen, Thawed };
protected:
2018-12-08 05:30:43 +00:00
static const s32 skShootAnim[2];
zeus::CVector3f x4_scale;
std::experimental::optional<CModelData> x10_solidModelData;
std::experimental::optional<CModelData> x60_holoModelData;
std::experimental::optional<CModelData> xb0_suitArmModelData;
std::unique_ptr<CGunController> x100_gunController;
TToken<CAnimCharacterSet> x104_gunCharacter;
std::vector<CToken> x10c_anims;
std::vector<CToken> x12c_deps;
TToken<CAnimCharacterSet> x13c_armCharacter;
rstl::reserved_vector<TCachedToken<CWeaponDescription>, 2> x144_weapons;
TCachedToken<CGenDescription> x160_xferEffect;
rstl::reserved_vector<TCachedToken<CGenDescription>, 2> x16c_muzzleEffects;
rstl::reserved_vector<TCachedToken<CGenDescription>, 2> x188_frozenEffects;
rstl::reserved_vector<std::unique_ptr<CElementGen>, 2> x1a4_muzzleGenerators;
std::unique_ptr<CElementGen> x1b8_frozenGenerator;
CRainSplashGenerator* x1bc_rainSplashGenerator = nullptr;
EWeaponType x1c0_weaponType;
TUniqueId x1c4_playerId;
EMaterialTypes x1c8_playerMaterial;
ESecondaryFxType x1cc_enabledSecondaryEffect = ESecondaryFxType::None;
CVelocityInfo x1d0_velInfo;
CPlayerState::EBeamId x200_beamId;
EFrozenFxType x204_frozenEffect = EFrozenFxType::None;
u32 x208_muzzleEffectIdx = 0;
u32 x20c_shaderIdx;
// 0x1: load request, 0x2: muzzle fx, 0x4: projectile data, 0x8: anims, 0x10: everything else
u32 x210_loadFlags = 0;
CAssetId x214_ancsId;
union {
struct {
bool x218_24 : 1;
bool x218_25_enableCharge : 1;
bool x218_26_loaded : 1;
// Initialize in selected beam's pose, rather than power beam's pose
bool x218_27_subtypeBasePose : 1;
bool x218_28_suitArmLocked : 1;
bool x218_29_drawHologram : 1;
2017-08-26 04:36:25 +00:00
};
2018-12-08 05:30:43 +00:00
u32 _dummy = 0;
};
2017-08-26 04:36:25 +00:00
2018-12-08 05:30:43 +00:00
void AllocResPools(CPlayerState::EBeamId beam);
void FreeResPools();
void FillTokenVector(const std::vector<SObjectTag>& tags, std::vector<CToken>& objects);
void BuildDependencyList(CPlayerState::EBeamId beam);
void LoadSuitArm(CStateManager& mgr);
void LoadGunModels(CStateManager& mgr);
void LoadAnimations();
bool IsAnimsLoaded() const;
void LoadMuzzleFx(float dt);
void LoadProjectileData(CStateManager& mgr);
void LoadFxIdle(float dt, CStateManager& mgr);
void LockTokens(CStateManager& mgr);
void UnlockTokens();
2017-09-05 03:00:19 +00:00
2018-12-08 05:30:43 +00:00
static void PointGenerator(void* ctx, const std::vector<std::pair<zeus::CVector3f, zeus::CVector3f>>& vn);
2017-09-05 03:00:19 +00:00
public:
2018-12-08 05:30:43 +00:00
CGunWeapon(CAssetId ancsId, EWeaponType type, TUniqueId playerId, EMaterialTypes playerMaterial,
const zeus::CVector3f& scale);
void AsyncLoadSuitArm(CStateManager& mgr);
virtual void Reset(CStateManager& mgr);
virtual void PlayAnim(NWeaponTypes::EGunAnimType type, bool loop);
virtual void PreRenderGunFx(const CStateManager& mgr, const zeus::CTransform& xf);
virtual void PostRenderGunFx(const CStateManager& mgr, const zeus::CTransform& xf);
virtual void UpdateGunFx(bool shotSmoke, float dt, const CStateManager& mgr, const zeus::CTransform& xf);
virtual void Fire(bool underwater, float dt, EChargeState chargeState, const zeus::CTransform& xf, CStateManager& mgr,
TUniqueId homingTarget, float chargeFactor1, float chargeFactor2);
virtual void EnableFx(bool enable);
virtual void EnableSecondaryFx(ESecondaryFxType type);
void EnableFrozenEffect(EFrozenFxType type);
void ActivateCharge(bool enable, bool resetEffect);
void Touch(const CStateManager& mgr);
void TouchHolo(const CStateManager& mgr);
virtual void Draw(bool drawSuitArm, const CStateManager& mgr, const zeus::CTransform& xf, const CModelFlags& flags,
const CActorLights* lights) const;
virtual void DrawMuzzleFx(const CStateManager& mgr) const;
virtual void Update(float dt, CStateManager& mgr);
virtual void Load(CStateManager& mgr, bool subtypeBasePose);
virtual void Unload(CStateManager& mgr);
virtual bool IsLoaded() const;
void DrawHologram(const CStateManager& mgr, const zeus::CTransform& xf, const CModelFlags& flags) const;
void UpdateMuzzleFx(float dt, const zeus::CVector3f& scale, const zeus::CVector3f& pos, bool emitting);
const CVelocityInfo& GetVelocityInfo() const { return x1d0_velInfo; }
void SetRainSplashGenerator(CRainSplashGenerator* g) { x1bc_rainSplashGenerator = g; }
CElementGen* GetChargeMuzzleFx() const { return x1a4_muzzleGenerators[1].get(); }
const TToken<CGenDescription>& GetComboXferDescr() const { return x160_xferEffect; }
void ReturnToDefault(CStateManager& mgr);
bool PlayPasAnim(SamusGun::EAnimationState state, CStateManager& mgr, float angle);
void UnLoadFidget();
bool IsFidgetLoaded() const;
void AsyncLoadFidget(CStateManager& mgr, SamusGun::EFidgetType type, s32 animSet);
void EnterFidget(CStateManager& mgr, SamusGun::EFidgetType type, s32 parm2);
bool HasSolidModelData() const { return x10_solidModelData.operator bool(); }
CModelData& GetSolidModelData() { return *x10_solidModelData; }
const SWeaponInfo& GetWeaponInfo() const;
CDamageInfo GetDamageInfo(CStateManager& mgr, EChargeState chargeState, float chargeFactor) const;
EWeaponType GetWeaponType() const { return x1c0_weaponType; }
zeus::CAABox GetBounds() const;
zeus::CAABox GetBounds(const zeus::CTransform& xf) const;
bool ComboFireOver() const { return x100_gunController->IsComboOver(); }
bool IsChargeAnimOver() const;
void SetDrawHologram(bool d) { x218_29_drawHologram = d; }
void EnableCharge(bool c) { x218_25_enableCharge = c; }
2017-09-10 00:36:21 +00:00
2018-12-08 05:30:43 +00:00
static CDamageInfo GetShotDamageInfo(const SShotParam& shotParam, CStateManager& mgr);
};
2018-12-08 05:30:43 +00:00
} // namespace urde