metaforce/Runtime/CPlayerState.hpp

197 lines
6.1 KiB
C++
Raw Normal View History

2016-04-12 23:07:23 -07:00
#ifndef __URDE_CPLAYERSTATE_HPP__
#define __URDE_CPLAYERSTATE_HPP__
2015-08-16 22:26:58 -07:00
2015-08-18 22:48:57 -07:00
#include "RetroTypes.hpp"
2015-08-19 19:52:07 -07:00
#include "CBasics.hpp"
2015-08-17 13:33:58 -07:00
#include "CStaticInterference.hpp"
2015-08-23 16:58:07 -07:00
#include "IOStreams.hpp"
2016-03-19 12:19:43 -07:00
#include "rstl.hpp"
2016-06-30 12:33:38 -07:00
#include "World/CHealthInfo.hpp"
#include <unordered_map>
2015-08-17 13:33:58 -07:00
2016-03-04 15:04:53 -08:00
namespace urde
{
2015-08-17 22:54:43 -07:00
class CPlayerState
2015-08-16 22:26:58 -07:00
{
2016-08-16 15:49:19 -07:00
friend class CWorldTransManager;
2016-03-23 13:38:01 -07:00
public:
2017-09-01 21:06:05 -07:00
enum class EItemType : s32
2016-03-23 13:38:01 -07:00
{
2017-09-01 21:06:05 -07:00
Invalid = -1,
PowerBeam = 0,
IceBeam = 1,
WaveBeam = 2,
PlasmaBeam = 3,
Missiles = 4,
ScanVisor = 5,
MorphBallBombs = 6,
PowerBombs = 7,
Flamethrower = 8,
ThermalVisor = 9,
ChargeBeam = 10,
SuperMissile = 11,
GrappleBeam = 12,
XRayVisor = 13,
IceSpreader = 14,
SpaceJumpBoots = 15,
MorphBall = 16,
CombatVisor = 17,
BoostBall = 18,
SpiderBall = 19,
PowerSuit = 20,
GravitySuit = 21,
VariaSuit = 22,
PhazonSuit = 23,
EnergyTanks = 24,
UnknownItem1 = 25,
HealthRefill = 26,
UnknownItem2 = 27,
Wavebuster = 28,
Truth = 29,
Strength = 30,
Elder = 31,
Wild = 32,
Lifegiver = 33,
Warrior = 34,
Chozo = 35,
Nature = 36,
Sun = 37,
World = 38,
Spirit = 39,
Newborn = 40,
2016-03-23 13:38:01 -07:00
/* This must remain at the end of the list */
Max
};
enum class EPlayerVisor : u32
2015-08-17 13:33:58 -07:00
{
2016-03-23 13:38:01 -07:00
Combat,
XRay,
Scan,
Thermal,
/* This must remain at the end of the list */
Max
};
2017-09-03 19:22:46 -07:00
enum class EPlayerSuit : s32
2016-03-23 13:38:01 -07:00
{
2017-09-03 19:22:46 -07:00
Invalid = -1,
2016-03-23 13:38:01 -07:00
Power,
Gravity,
Varia,
Phazon,
FusionPower,
FusionGravity,
FusionVaria,
FusionPhazon
};
2017-08-30 19:42:37 -07:00
enum class EBeamId : s32
2016-03-28 01:54:02 -07:00
{
2017-08-30 19:42:37 -07:00
Invalid = -1,
2016-03-28 01:54:02 -07:00
Power,
Ice,
Wave,
2017-08-30 19:42:37 -07:00
Plasma,
2017-09-04 20:00:19 -07:00
Phazon,
Phazon2 = 27
2016-03-28 01:54:02 -07:00
};
2016-03-23 13:38:01 -07:00
private:
static const std::unordered_map<std::string_view, EItemType> g_TypeNameMap;
2016-03-23 13:38:01 -07:00
static const u32 PowerUpMaxValues[41];
static const char* PowerUpNames[41];
2016-03-23 13:38:01 -07:00
struct CPowerUp
{
u32 x0_amount = 0;
u32 x4_capacity = 0;
2015-08-19 19:52:07 -07:00
CPowerUp() {}
CPowerUp(u32 amount, u32 capacity) : x0_amount(amount), x4_capacity(capacity) {}
2016-03-19 12:19:43 -07:00
};
union
{
2017-09-09 17:36:21 -07:00
struct { bool x0_24_alive : 1; bool x0_25_firingComboBeam : 1; bool x0_26_fusion : 1; };
2016-03-19 12:19:43 -07:00
u32 dummy = 0;
2015-08-17 13:33:58 -07:00
};
2015-08-19 19:52:07 -07:00
2017-08-12 22:26:14 -07:00
u32 x4_enabledItems = 0;
2016-03-28 01:54:02 -07:00
EBeamId x8_currentBeam = EBeamId::Power;
2016-06-30 12:33:38 -07:00
CHealthInfo xc_health = {99.f, 50.f};
2016-03-23 13:38:01 -07:00
EPlayerVisor x14_currentVisor = EPlayerVisor::Combat;
EPlayerVisor x18_transitioningVisor = x14_currentVisor;
float x1c_visorTransitionFactor = 0.2f;
EPlayerSuit x20_currentSuit = EPlayerSuit::Power;
rstl::reserved_vector<CPowerUp, 41> x24_powerups;
2018-04-04 23:58:11 -07:00
std::vector<std::pair<CAssetId, float>> x170_scanTimes;
2017-07-30 22:19:05 -07:00
std::pair<u32, u32> x180_scanCompletionRate = {};
2016-03-19 12:19:43 -07:00
CStaticInterference x188_staticIntf;
2018-06-13 12:36:11 -07:00
bool m_canTakeDamage = true;
2015-08-19 19:52:07 -07:00
public:
2016-03-23 13:38:01 -07:00
2016-03-28 01:54:02 -07:00
u32 GetMissileCostForAltAttack() const;
2017-09-09 17:36:21 -07:00
float GetComboFireAmmoPeriod() const;
2017-09-01 21:06:05 -07:00
static constexpr float GetMissileComboChargeFactor() { return 1.8f; }
2016-03-23 13:38:01 -07:00
u32 CalculateItemCollectionRate() const;
2016-06-30 12:33:38 -07:00
CHealthInfo& HealthInfo();
2017-01-14 19:59:37 -08:00
const CHealthInfo &GetHealthInfo() const;
2016-03-28 01:54:02 -07:00
u32 GetPickupTotal() { return 99; }
2016-12-29 13:38:59 -08:00
void SetIsFusionEnabled(bool val) { x0_26_fusion = val; }
bool IsFusionEnabled() const { return x0_26_fusion; }
2016-03-23 13:38:01 -07:00
EPlayerSuit GetCurrentSuit() const;
2017-02-17 18:19:50 -08:00
EPlayerSuit GetCurrentSuitRaw() const { return x20_currentSuit; }
2016-08-16 15:49:19 -07:00
EBeamId GetCurrentBeam() const { return x8_currentBeam; }
2017-08-30 19:42:37 -07:00
void SetCurrentBeam(EBeamId beam) { x8_currentBeam = beam; }
2016-03-23 13:38:01 -07:00
bool CanVisorSeeFog(const CStateManager& stateMgr) const;
EPlayerVisor GetCurrentVisor() const { return x14_currentVisor; }
2017-04-01 20:03:37 -07:00
EPlayerVisor GetTransitioningVisor() const { return x18_transitioningVisor; }
2016-03-23 13:38:01 -07:00
EPlayerVisor GetActiveVisor(const CStateManager& stateMgr) const;
2017-08-15 22:34:02 -07:00
void UpdateStaticInterference(CStateManager& stateMgr, float dt);
2016-03-23 13:38:01 -07:00
void IncreaseScanTime(u32 time, float val);
2017-08-12 22:26:14 -07:00
void SetScanTime(CAssetId res, float time);
float GetScanTime(CAssetId time) const;
2016-03-23 13:38:01 -07:00
bool GetIsVisorTransitioning() const;
float GetVisorTransitionFactor() const;
void UpdateVisorTransition(float dt);
bool StartVisorTransition(EPlayerVisor visor);
void ResetVisor();
2017-08-24 23:18:09 -07:00
bool ItemEnabled(EItemType type) const;
2016-03-23 13:38:01 -07:00
void DisableItem(EItemType type);
void EnableItem(EItemType type);
2017-08-24 23:18:09 -07:00
bool HasPowerUp(EItemType type) const;
2016-03-23 13:38:01 -07:00
u32 GetItemCapacity(EItemType type) const;
u32 GetItemAmount(EItemType type) const;
void DecrPickup(EItemType type, u32 amount);
void IncrPickup(EItemType type, u32 amount);
void ResetAndIncrPickUp(EItemType type, u32 amount);
2017-04-02 22:37:54 -07:00
static float GetEnergyTankCapacity() { return 100.f; }
static float GetBaseHealthCapacity() { return 99.f; }
float CalculateHealth();
2016-03-23 13:38:01 -07:00
void ReInitalizePowerUp(EItemType type, u32 capacity);
void InitializePowerUp(EItemType type, u32 capacity);
2017-07-30 22:19:05 -07:00
u32 GetLogScans() const { return x180_scanCompletionRate.first; }
u32 GetTotalLogScans() const { return x180_scanCompletionRate.second; }
void SetScanCompletionRate(const std::pair<u32, u32>& p) { x180_scanCompletionRate = p; }
2017-02-17 18:19:50 -08:00
bool IsPlayerAlive() const { return x0_24_alive; }
2017-03-25 22:53:04 -07:00
void SetPlayerAlive(bool alive) { x0_24_alive = alive; }
2017-09-09 17:36:21 -07:00
bool IsFiringComboBeam() const { return x0_25_firingComboBeam; }
void SetFiringComboBeam(bool f) { x0_25_firingComboBeam = f; }
2017-02-05 19:21:58 -08:00
void InitializeScanTimes();
2017-06-11 21:23:34 -07:00
CStaticInterference& GetStaticInterference() { return x188_staticIntf; }
2018-04-04 23:58:11 -07:00
const std::vector<std::pair<CAssetId, float>>& GetScanTimes() const { return x170_scanTimes; }
2017-02-05 19:21:58 -08:00
CPlayerState();
2016-03-19 12:19:43 -07:00
CPlayerState(CBitStreamReader& stream);
2016-03-28 01:54:02 -07:00
void PutTo(CBitStreamWriter& stream);
static u32 GetPowerUpMaxValue(EItemType type) { return PowerUpMaxValues[u32(type)]; }
static EItemType ItemNameToType(std::string_view name);
2018-06-13 12:36:11 -07:00
bool CanTakeDamage() const { return m_canTakeDamage; }
void SetCanTakeDamage(bool c) { m_canTakeDamage = c; }
2015-08-16 22:26:58 -07:00
};
}
2016-04-12 23:07:23 -07:00
#endif // __URDE_CPLAYERSTATE_HPP__