2019-09-19 19:24:26 +00:00
|
|
|
#include "Runtime/CPlayerState.hpp"
|
|
|
|
|
2019-09-19 19:40:54 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include <array>
|
2020-03-21 04:37:06 +00:00
|
|
|
#include <cstring>
|
2019-09-19 19:40:54 +00:00
|
|
|
|
2019-09-19 19:24:26 +00:00
|
|
|
#include "Runtime/CMemoryCardSys.hpp"
|
|
|
|
#include "Runtime/CStateManager.hpp"
|
|
|
|
#include "Runtime/GameGlobalObjects.hpp"
|
|
|
|
#include "Runtime/IOStreams.hpp"
|
|
|
|
#include "Runtime/Camera/CCameraManager.hpp"
|
|
|
|
#include "Runtime/Camera/CFirstPersonCamera.hpp"
|
2019-09-21 13:10:54 +00:00
|
|
|
#include "TCastTo.hpp" // Generated file, do not modify include path
|
2019-09-19 19:24:26 +00:00
|
|
|
|
|
|
|
#include <zeus/Math.hpp>
|
2015-08-17 22:05:00 +00:00
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
namespace metaforce {
|
2019-09-19 19:33:38 +00:00
|
|
|
namespace {
|
2019-09-19 19:40:54 +00:00
|
|
|
constexpr std::array<u32, 41> PowerUpMaxValues{
|
2019-09-19 19:33:38 +00:00
|
|
|
1, 1, 1, 1, 250, 1, 1, 8, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
|
1, 1, 1, 14, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
|
};
|
2016-03-19 19:19:43 +00:00
|
|
|
|
2019-09-19 19:40:54 +00:00
|
|
|
[[maybe_unused]] constexpr std::array<const char*, 41> PowerUpNames{
|
2016-03-23 20:38:01 +00:00
|
|
|
"Power Beam",
|
|
|
|
"Ice Beam",
|
|
|
|
"Wave Beam",
|
|
|
|
"Plasma Beam",
|
2016-03-19 19:19:43 +00:00
|
|
|
"Missiles",
|
2016-03-23 20:38:01 +00:00
|
|
|
"Scan Visor",
|
|
|
|
"Morph Ball Bombs",
|
2016-03-19 19:19:43 +00:00
|
|
|
"Power Bombs",
|
2016-03-23 20:38:01 +00:00
|
|
|
"Flamethrower",
|
|
|
|
"Thermal Visor",
|
|
|
|
"Charge Beam",
|
|
|
|
"Super Missile",
|
|
|
|
"GrappleBeam",
|
|
|
|
"X-Ray Visor",
|
|
|
|
"Ice Spreader",
|
|
|
|
"Space Jump Boots",
|
|
|
|
"Morph Ball",
|
|
|
|
"Combat Visor",
|
|
|
|
"Boost Ball",
|
|
|
|
"Spider Ball",
|
|
|
|
"Power Suit",
|
|
|
|
"Gravity Suit",
|
|
|
|
"Varia Suit",
|
|
|
|
"Phazon Suit",
|
2016-03-19 19:19:43 +00:00
|
|
|
"Energy Tanks",
|
2016-03-23 20:38:01 +00:00
|
|
|
"Unknown Item 1",
|
|
|
|
"Health Refill",
|
|
|
|
"Unknown Item 2",
|
|
|
|
"Wavebuster",
|
|
|
|
"Artifact of Truth",
|
|
|
|
"Artifact of Strength",
|
|
|
|
"Artifact of Elder",
|
|
|
|
"Artifact of Wild",
|
|
|
|
"Artifact of Lifegiver",
|
|
|
|
"Artifact of Warrior",
|
|
|
|
"Artifact of Chozo",
|
|
|
|
"Artifact of Nature",
|
|
|
|
"Artifact of Sun",
|
|
|
|
"Artifact of World",
|
|
|
|
"Artifact of Spirit",
|
|
|
|
"Artifact of Newborn",
|
2016-03-19 19:19:43 +00:00
|
|
|
};
|
|
|
|
|
2019-09-19 19:40:54 +00:00
|
|
|
constexpr std::array<u32, 5> costs{
|
2019-09-19 19:33:38 +00:00
|
|
|
5, 10, 10, 10, 1,
|
|
|
|
};
|
|
|
|
|
2019-09-19 19:40:54 +00:00
|
|
|
constexpr std::array<float, 5> ComboAmmoPeriods{
|
2019-09-19 19:33:38 +00:00
|
|
|
0.2f, 0.1f, 0.2f, 0.2f, 1.f,
|
|
|
|
};
|
|
|
|
} // Anonymous namespace
|
|
|
|
|
2020-04-20 04:57:50 +00:00
|
|
|
CPlayerState::CPlayerState() {
|
2018-12-08 05:30:43 +00:00
|
|
|
x24_powerups.resize(41);
|
|
|
|
}
|
|
|
|
|
2020-04-20 04:57:50 +00:00
|
|
|
CPlayerState::CPlayerState(CBitStreamReader& stream) {
|
2018-12-08 05:30:43 +00:00
|
|
|
x4_enabledItems = u32(stream.ReadEncoded(32));
|
2020-03-21 04:37:06 +00:00
|
|
|
|
|
|
|
const u32 integralHP = u32(stream.ReadEncoded(32));
|
|
|
|
float realHP;
|
|
|
|
std::memcpy(&realHP, &integralHP, sizeof(float));
|
|
|
|
|
|
|
|
xc_health.SetHP(realHP);
|
2018-12-08 05:30:43 +00:00
|
|
|
x8_currentBeam = EBeamId(stream.ReadEncoded(CBitStreamReader::GetBitCount(5)));
|
|
|
|
x20_currentSuit = EPlayerSuit(stream.ReadEncoded(CBitStreamReader::GetBitCount(4)));
|
|
|
|
x24_powerups.resize(41);
|
2019-09-19 19:40:54 +00:00
|
|
|
for (size_t i = 0; i < x24_powerups.size(); ++i) {
|
|
|
|
if (PowerUpMaxValues[i] == 0) {
|
2018-12-08 05:30:43 +00:00
|
|
|
continue;
|
2019-09-19 19:40:54 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
2019-09-19 19:40:54 +00:00
|
|
|
const u32 a = u32(stream.ReadEncoded(CBitStreamReader::GetBitCount(PowerUpMaxValues[i])));
|
|
|
|
const u32 b = u32(stream.ReadEncoded(CBitStreamReader::GetBitCount(PowerUpMaxValues[i])));
|
2018-12-08 05:30:43 +00:00
|
|
|
x24_powerups[i] = CPowerUp(a, b);
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto& scanStates = g_MemoryCardSys->GetScanStates();
|
|
|
|
x170_scanTimes.reserve(scanStates.size());
|
|
|
|
for (const auto& state : scanStates) {
|
2020-04-16 06:58:00 +00:00
|
|
|
float time = stream.ReadEncoded(1) ? 1.f : 0.f;
|
2018-12-08 05:30:43 +00:00
|
|
|
x170_scanTimes.emplace_back(state.first, time);
|
|
|
|
}
|
|
|
|
|
|
|
|
x180_scanCompletionRate.first = u32(stream.ReadEncoded(CBitStreamReader::GetBitCount(0x100u)));
|
|
|
|
x180_scanCompletionRate.second = u32(stream.ReadEncoded(CBitStreamReader::GetBitCount(0x100u)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPlayerState::PutTo(CBitStreamWriter& stream) {
|
|
|
|
stream.WriteEncoded(x4_enabledItems, 32);
|
2020-03-21 04:37:06 +00:00
|
|
|
|
|
|
|
const float realHP = xc_health.GetHP();
|
|
|
|
u32 integralHP;
|
|
|
|
std::memcpy(&integralHP, &realHP, sizeof(u32));
|
|
|
|
|
|
|
|
stream.WriteEncoded(integralHP, 32);
|
2018-12-08 05:30:43 +00:00
|
|
|
stream.WriteEncoded(u32(x8_currentBeam), CBitStreamWriter::GetBitCount(5));
|
|
|
|
stream.WriteEncoded(u32(x20_currentSuit), CBitStreamWriter::GetBitCount(4));
|
2019-09-19 19:40:54 +00:00
|
|
|
for (size_t i = 0; i < x24_powerups.size(); ++i) {
|
2018-12-08 05:30:43 +00:00
|
|
|
const CPowerUp& pup = x24_powerups[i];
|
|
|
|
stream.WriteEncoded(pup.x0_amount, CBitStreamWriter::GetBitCount(PowerUpMaxValues[i]));
|
|
|
|
stream.WriteEncoded(pup.x4_capacity, CBitStreamWriter::GetBitCount(PowerUpMaxValues[i]));
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const auto& scanTime : x170_scanTimes) {
|
|
|
|
if (scanTime.second >= 1.f)
|
|
|
|
stream.WriteEncoded(true, 1);
|
|
|
|
else
|
|
|
|
stream.WriteEncoded(false, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
stream.WriteEncoded(x180_scanCompletionRate.first, CBitStreamWriter::GetBitCount(0x100));
|
|
|
|
stream.WriteEncoded(x180_scanCompletionRate.second, CBitStreamWriter::GetBitCount(0x100));
|
|
|
|
}
|
|
|
|
|
2019-09-19 19:40:54 +00:00
|
|
|
u32 CPlayerState::GetMissileCostForAltAttack() const { return costs[size_t(x8_currentBeam)]; }
|
2018-12-08 05:30:43 +00:00
|
|
|
|
2019-09-19 19:40:54 +00:00
|
|
|
float CPlayerState::GetComboFireAmmoPeriod() const { return ComboAmmoPeriods[size_t(x8_currentBeam)]; }
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
u32 CPlayerState::CalculateItemCollectionRate() const {
|
|
|
|
u32 total = GetItemCapacity(EItemType::PowerBombs);
|
|
|
|
|
|
|
|
if (total >= 4)
|
|
|
|
total -= 3;
|
|
|
|
total += GetItemCapacity(EItemType::WaveBeam);
|
|
|
|
total += GetItemCapacity(EItemType::IceBeam);
|
|
|
|
total += GetItemCapacity(EItemType::PlasmaBeam);
|
|
|
|
total += GetItemCapacity(EItemType::Missiles) / 5;
|
|
|
|
total += GetItemCapacity(EItemType::MorphBallBombs);
|
|
|
|
total += GetItemCapacity(EItemType::Flamethrower);
|
|
|
|
total += GetItemCapacity(EItemType::ThermalVisor);
|
|
|
|
total += GetItemCapacity(EItemType::ChargeBeam);
|
|
|
|
total += GetItemCapacity(EItemType::SuperMissile);
|
|
|
|
total += GetItemCapacity(EItemType::GrappleBeam);
|
|
|
|
total += GetItemCapacity(EItemType::XRayVisor);
|
|
|
|
total += GetItemCapacity(EItemType::IceSpreader);
|
|
|
|
total += GetItemCapacity(EItemType::SpaceJumpBoots);
|
|
|
|
total += GetItemCapacity(EItemType::MorphBall);
|
|
|
|
total += GetItemCapacity(EItemType::BoostBall);
|
|
|
|
total += GetItemCapacity(EItemType::SpiderBall);
|
|
|
|
total += GetItemCapacity(EItemType::GravitySuit);
|
|
|
|
total += GetItemCapacity(EItemType::VariaSuit);
|
|
|
|
total += GetItemCapacity(EItemType::EnergyTanks);
|
|
|
|
total += GetItemCapacity(EItemType::Truth);
|
|
|
|
total += GetItemCapacity(EItemType::Strength);
|
|
|
|
total += GetItemCapacity(EItemType::Elder);
|
|
|
|
total += GetItemCapacity(EItemType::Wild);
|
|
|
|
total += GetItemCapacity(EItemType::Lifegiver);
|
|
|
|
total += GetItemCapacity(EItemType::Warrior);
|
|
|
|
total += GetItemCapacity(EItemType::Chozo);
|
|
|
|
total += GetItemCapacity(EItemType::Nature);
|
|
|
|
total += GetItemCapacity(EItemType::Sun);
|
|
|
|
total += GetItemCapacity(EItemType::World);
|
|
|
|
total += GetItemCapacity(EItemType::Spirit);
|
|
|
|
total += GetItemCapacity(EItemType::Newborn);
|
|
|
|
return total + GetItemCapacity(EItemType::Wavebuster);
|
|
|
|
}
|
|
|
|
|
2020-03-24 10:20:33 +00:00
|
|
|
CHealthInfo& CPlayerState::GetHealthInfo() { return xc_health; }
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
const CHealthInfo& CPlayerState::GetHealthInfo() const { return xc_health; }
|
|
|
|
|
|
|
|
CPlayerState::EPlayerSuit CPlayerState::GetCurrentSuit() const {
|
|
|
|
if (IsFusionEnabled())
|
|
|
|
return EPlayerSuit::FusionPower;
|
|
|
|
|
|
|
|
return x20_currentSuit;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CPlayerState::CanVisorSeeFog(const CStateManager& stateMgr) const {
|
|
|
|
EPlayerVisor activeVisor = GetActiveVisor(stateMgr);
|
|
|
|
if (activeVisor == EPlayerVisor::Combat || activeVisor == EPlayerVisor::Scan)
|
2016-03-23 20:38:01 +00:00
|
|
|
return true;
|
2018-12-08 05:30:43 +00:00
|
|
|
return true;
|
2016-03-23 20:38:01 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CPlayerState::EPlayerVisor CPlayerState::GetActiveVisor(const CStateManager& stateMgr) const {
|
|
|
|
const CFirstPersonCamera* cam =
|
2019-02-24 07:15:54 +00:00
|
|
|
TCastToConstPtr<CFirstPersonCamera>(stateMgr.GetCameraManager()->GetCurrentCamera(stateMgr)).GetPtr();
|
2018-12-08 05:30:43 +00:00
|
|
|
return (cam ? x14_currentVisor : EPlayerVisor::Combat);
|
2016-03-23 20:38:01 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CPlayerState::UpdateStaticInterference(CStateManager& stateMgr, float dt) { x188_staticIntf.Update(stateMgr, dt); }
|
2016-03-23 20:38:01 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CPlayerState::SetScanTime(CAssetId res, float time) {
|
|
|
|
auto it = std::find_if(x170_scanTimes.begin(), x170_scanTimes.end(),
|
|
|
|
[&](const auto& test) -> bool { return test.first == res; });
|
2016-03-28 08:54:02 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (it != x170_scanTimes.end())
|
|
|
|
it->second = time;
|
2017-02-09 07:37:00 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
float CPlayerState::GetScanTime(CAssetId res) const {
|
|
|
|
const auto it = std::find_if(x170_scanTimes.cbegin(), x170_scanTimes.cend(),
|
|
|
|
[&](const auto& test) -> bool { return test.first == res; });
|
2017-02-09 07:37:00 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (it == x170_scanTimes.end())
|
|
|
|
return 0.f;
|
2017-02-09 07:37:00 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
return it->second;
|
2016-03-23 20:38:01 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CPlayerState::GetIsVisorTransitioning() const {
|
|
|
|
return x14_currentVisor != x18_transitioningVisor || x1c_visorTransitionFactor < 0.2f;
|
2016-03-23 20:38:01 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
float CPlayerState::GetVisorTransitionFactor() const { return x1c_visorTransitionFactor / 0.2f; }
|
2016-03-23 20:38:01 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CPlayerState::UpdateVisorTransition(float dt) {
|
|
|
|
if (!GetIsVisorTransitioning())
|
|
|
|
return;
|
2016-03-23 20:38:01 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (x14_currentVisor == x18_transitioningVisor) {
|
|
|
|
x1c_visorTransitionFactor += dt;
|
|
|
|
if (x1c_visorTransitionFactor > 0.2f)
|
|
|
|
x1c_visorTransitionFactor = 0.2f;
|
|
|
|
} else {
|
|
|
|
x1c_visorTransitionFactor -= dt;
|
|
|
|
if (x1c_visorTransitionFactor < 0.f) {
|
|
|
|
x14_currentVisor = x18_transitioningVisor;
|
|
|
|
x1c_visorTransitionFactor = std::fabs(x1c_visorTransitionFactor);
|
|
|
|
if (x1c_visorTransitionFactor > 0.19999f)
|
|
|
|
x1c_visorTransitionFactor = 0.19999f;
|
2016-03-23 20:38:01 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2016-03-23 20:38:01 +00:00
|
|
|
}
|
|
|
|
|
2019-02-24 07:15:54 +00:00
|
|
|
void CPlayerState::StartTransitionToVisor(CPlayerState::EPlayerVisor visor) {
|
|
|
|
if (x18_transitioningVisor == visor)
|
|
|
|
return;
|
2018-12-08 05:30:43 +00:00
|
|
|
x18_transitioningVisor = visor;
|
2016-03-23 20:38:01 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CPlayerState::ResetVisor() {
|
|
|
|
x18_transitioningVisor = x14_currentVisor = EPlayerVisor::Combat;
|
|
|
|
x1c_visorTransitionFactor = 0.0f;
|
2016-03-23 20:38:01 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CPlayerState::ItemEnabled(CPlayerState::EItemType type) const {
|
|
|
|
if (HasPowerUp(type))
|
|
|
|
return (x4_enabledItems & (1 << u32(type)));
|
|
|
|
return false;
|
2016-03-23 20:38:01 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CPlayerState::EnableItem(CPlayerState::EItemType type) {
|
|
|
|
if (HasPowerUp(type))
|
|
|
|
x4_enabledItems |= (1 << u32(type));
|
2017-08-13 05:26:14 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CPlayerState::DisableItem(CPlayerState::EItemType type) {
|
|
|
|
if (HasPowerUp(type))
|
|
|
|
x4_enabledItems &= ~(1 << u32(type));
|
2017-08-13 05:26:14 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CPlayerState::HasPowerUp(CPlayerState::EItemType type) const {
|
|
|
|
if (type < EItemType::Max)
|
|
|
|
return x24_powerups[u32(type)].x4_capacity != 0;
|
|
|
|
return false;
|
2016-03-23 20:38:01 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
u32 CPlayerState::GetItemCapacity(CPlayerState::EItemType type) const {
|
|
|
|
if (type < EItemType::Max)
|
|
|
|
return x24_powerups[u32(type)].x4_capacity;
|
|
|
|
return 0;
|
2016-03-23 20:38:01 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
u32 CPlayerState::GetItemAmount(CPlayerState::EItemType type) const {
|
|
|
|
if (type == EItemType::SpaceJumpBoots || type == EItemType::PowerBombs || type == EItemType::Flamethrower ||
|
|
|
|
type == EItemType::EnergyTanks || type == EItemType::Missiles ||
|
|
|
|
(type >= EItemType::Truth && type <= EItemType::Newborn)) {
|
|
|
|
return x24_powerups[u32(type)].x0_amount;
|
|
|
|
}
|
2016-03-23 20:38:01 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
return 0;
|
2016-03-23 20:38:01 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CPlayerState::DecrPickup(CPlayerState::EItemType type, u32 amount) {
|
|
|
|
if (type >= EItemType::Max)
|
|
|
|
return;
|
2016-03-23 20:38:01 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if ((type == EItemType::Missiles || type >= EItemType::PowerBombs) && type < EItemType::ThermalVisor)
|
|
|
|
x24_powerups[u32(type)].x0_amount -= amount;
|
2016-03-23 20:38:01 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CPlayerState::IncrPickup(EItemType type, u32 amount) {
|
|
|
|
if (type >= EItemType::Max)
|
|
|
|
return;
|
2016-03-23 20:38:01 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
switch (type) {
|
|
|
|
case EItemType::Missiles:
|
|
|
|
case EItemType::PowerBombs:
|
|
|
|
case EItemType::ChargeBeam:
|
|
|
|
case EItemType::SpaceJumpBoots:
|
|
|
|
case EItemType::EnergyTanks:
|
|
|
|
case EItemType::Truth:
|
|
|
|
case EItemType::Strength:
|
|
|
|
case EItemType::Elder:
|
|
|
|
case EItemType::Wild:
|
|
|
|
case EItemType::Lifegiver:
|
|
|
|
case EItemType::Warrior:
|
|
|
|
case EItemType::Chozo:
|
|
|
|
case EItemType::Nature:
|
|
|
|
case EItemType::Sun:
|
|
|
|
case EItemType::World:
|
|
|
|
case EItemType::Spirit:
|
|
|
|
case EItemType::Newborn: {
|
2018-04-26 21:12:20 +00:00
|
|
|
CPowerUp& pup = x24_powerups[u32(type)];
|
2018-12-08 05:30:43 +00:00
|
|
|
pup.x0_amount = std::min(pup.x0_amount + u32(amount), pup.x4_capacity);
|
|
|
|
|
|
|
|
if (type == EItemType::EnergyTanks)
|
|
|
|
IncrPickup(EItemType::HealthRefill, 9999);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EItemType::HealthRefill:
|
|
|
|
xc_health.SetHP(std::min(amount + xc_health.GetHP(), CalculateHealth()));
|
2019-02-18 05:47:46 +00:00
|
|
|
break;
|
2018-12-08 05:30:43 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPlayerState::ResetAndIncrPickUp(CPlayerState::EItemType type, u32 amount) {
|
|
|
|
x24_powerups[u32(type)].x0_amount = 0;
|
|
|
|
IncrPickup(type, amount);
|
|
|
|
}
|
|
|
|
|
|
|
|
float CPlayerState::CalculateHealth() {
|
|
|
|
return (GetEnergyTankCapacity() * x24_powerups[u32(EItemType::EnergyTanks)].x0_amount) + GetBaseHealthCapacity();
|
|
|
|
}
|
|
|
|
|
2019-05-08 03:50:21 +00:00
|
|
|
void CPlayerState::AddPowerUp(CPlayerState::EItemType type, u32 capacity) {
|
2018-12-08 05:30:43 +00:00
|
|
|
if (type >= EItemType::Max)
|
|
|
|
return;
|
|
|
|
|
|
|
|
CPowerUp& pup = x24_powerups[u32(type)];
|
|
|
|
pup.x4_capacity = zeus::clamp(0u, pup.x4_capacity + capacity, PowerUpMaxValues[u32(type)]);
|
|
|
|
pup.x0_amount = std::min(pup.x0_amount, pup.x4_capacity);
|
|
|
|
if (type >= EItemType::PowerSuit && type <= EItemType::PhazonSuit) {
|
|
|
|
if (HasPowerUp(EItemType::PhazonSuit))
|
|
|
|
x20_currentSuit = EPlayerSuit::Phazon;
|
|
|
|
else if (HasPowerUp(EItemType::GravitySuit))
|
|
|
|
x20_currentSuit = EPlayerSuit::Gravity;
|
|
|
|
else if (HasPowerUp(EItemType::VariaSuit))
|
|
|
|
x20_currentSuit = EPlayerSuit::Varia;
|
|
|
|
else
|
|
|
|
x20_currentSuit = EPlayerSuit::Power;
|
|
|
|
}
|
2016-03-23 20:38:01 +00:00
|
|
|
}
|
|
|
|
|
2021-03-15 22:43:28 +00:00
|
|
|
void CPlayerState::ReInitializePowerUp(CPlayerState::EItemType type, u32 capacity) {
|
2018-12-08 05:30:43 +00:00
|
|
|
x24_powerups[u32(type)].x4_capacity = 0;
|
2019-05-08 03:50:21 +00:00
|
|
|
AddPowerUp(type, capacity);
|
2015-08-20 02:52:07 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CPlayerState::InitializeScanTimes() {
|
|
|
|
if (x170_scanTimes.size())
|
|
|
|
return;
|
2017-02-06 03:21:58 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
const auto& scanStates = g_MemoryCardSys->GetScanStates();
|
|
|
|
x170_scanTimes.reserve(scanStates.size());
|
|
|
|
for (const auto& state : scanStates)
|
|
|
|
x170_scanTimes.emplace_back(state.first, 0.f);
|
2017-02-06 03:21:58 +00:00
|
|
|
}
|
|
|
|
|
2019-09-19 19:40:54 +00:00
|
|
|
u32 CPlayerState::GetPowerUpMaxValue(EItemType type) { return PowerUpMaxValues[size_t(type)]; }
|
2019-09-19 19:33:38 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CPlayerState::EItemType CPlayerState::ItemNameToType(std::string_view name) {
|
2020-03-21 04:57:03 +00:00
|
|
|
static constexpr std::array<std::pair<std::string_view, EItemType>, 46> typeNameMap{{
|
|
|
|
{"powerbeam"sv, EItemType::PowerBeam},
|
|
|
|
{"icebeam"sv, EItemType::IceBeam},
|
|
|
|
{"wavebeam"sv, EItemType::WaveBeam},
|
|
|
|
{"plasmabeam"sv, EItemType::PlasmaBeam},
|
|
|
|
{"missiles"sv, EItemType::Missiles},
|
|
|
|
{"scanvisor"sv, EItemType::ScanVisor},
|
|
|
|
{"bombs"sv, EItemType::MorphBallBombs},
|
|
|
|
{"ballbombs"sv, EItemType::MorphBallBombs},
|
|
|
|
{"morphballbombs"sv, EItemType::MorphBallBombs},
|
|
|
|
{"powerbombs"sv, EItemType::PowerBombs},
|
|
|
|
{"flamethrower"sv, EItemType::Flamethrower},
|
|
|
|
{"thermalvisor"sv, EItemType::ThermalVisor},
|
|
|
|
{"chargebeam"sv, EItemType::ChargeBeam},
|
|
|
|
{"supermissile"sv, EItemType::SuperMissile},
|
|
|
|
{"grapple"sv, EItemType::GrappleBeam},
|
|
|
|
{"grapplebeam"sv, EItemType::GrappleBeam},
|
|
|
|
{"xrayvisor"sv, EItemType::XRayVisor},
|
|
|
|
{"icespreader"sv, EItemType::IceSpreader},
|
|
|
|
{"spacejump"sv, EItemType::SpaceJumpBoots},
|
|
|
|
{"spacejumpboots"sv, EItemType::SpaceJumpBoots},
|
|
|
|
{"morphball"sv, EItemType::MorphBall},
|
|
|
|
{"combatvisor"sv, EItemType::CombatVisor},
|
|
|
|
{"boostball"sv, EItemType::BoostBall},
|
|
|
|
{"spiderball"sv, EItemType::SpiderBall},
|
|
|
|
{"powersuit"sv, EItemType::PowerSuit},
|
|
|
|
{"gravitysuit"sv, EItemType::GravitySuit},
|
|
|
|
{"variasuit"sv, EItemType::VariaSuit},
|
|
|
|
{"phazonsuit"sv, EItemType::PhazonSuit},
|
|
|
|
{"energytanks"sv, EItemType::EnergyTanks},
|
|
|
|
{"unknownitem1"sv, EItemType::UnknownItem1},
|
|
|
|
{"healthrefill"sv, EItemType::HealthRefill},
|
|
|
|
{"health"sv, EItemType::HealthRefill},
|
|
|
|
{"unknownitem2"sv, EItemType::UnknownItem2},
|
|
|
|
{"wavebuster"sv, EItemType::Wavebuster},
|
|
|
|
{"truth"sv, EItemType::Truth},
|
|
|
|
{"strength"sv, EItemType::Strength},
|
|
|
|
{"elder"sv, EItemType::Elder},
|
|
|
|
{"wild"sv, EItemType::Wild},
|
|
|
|
{"lifegiver"sv, EItemType::Lifegiver},
|
|
|
|
{"warrior"sv, EItemType::Warrior},
|
|
|
|
{"chozo"sv, EItemType::Chozo},
|
|
|
|
{"nature"sv, EItemType::Nature},
|
|
|
|
{"sun"sv, EItemType::Sun},
|
|
|
|
{"world"sv, EItemType::World},
|
|
|
|
{"spirit"sv, EItemType::Spirit},
|
|
|
|
{"newborn"sv, EItemType::Newborn},
|
|
|
|
}};
|
|
|
|
|
|
|
|
std::string lowName{name};
|
2018-12-08 05:30:43 +00:00
|
|
|
athena::utility::tolower(lowName);
|
2020-03-21 04:57:03 +00:00
|
|
|
|
|
|
|
const auto iter = std::find_if(typeNameMap.cbegin(), typeNameMap.cend(),
|
|
|
|
[&lowName](const auto& entry) { return entry.first == lowName; });
|
|
|
|
if (iter == typeNameMap.cend()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return EItemType::Invalid;
|
2020-03-21 04:57:03 +00:00
|
|
|
}
|
2018-06-04 19:15:35 +00:00
|
|
|
|
2020-03-21 04:57:03 +00:00
|
|
|
return iter->second;
|
2018-06-04 19:15:35 +00:00
|
|
|
}
|
|
|
|
|
2021-05-27 14:26:13 +00:00
|
|
|
std::string_view CPlayerState::ItemTypeToName(CPlayerState::EItemType type) {
|
|
|
|
switch (type) {
|
|
|
|
case EItemType::PowerBeam:
|
|
|
|
return "Power Beam"sv;
|
|
|
|
case EItemType::IceBeam:
|
|
|
|
return "Ice Beam"sv;
|
|
|
|
case EItemType::WaveBeam:
|
|
|
|
return "Wave Beam"sv;
|
|
|
|
case EItemType::PlasmaBeam:
|
|
|
|
return "Plasma Beam"sv;
|
|
|
|
case EItemType::Missiles:
|
|
|
|
return "Missiles"sv;
|
|
|
|
case EItemType::ScanVisor:
|
|
|
|
return "Scan Visor"sv;
|
|
|
|
case EItemType::MorphBallBombs:
|
|
|
|
return "Morph Ball Bombs"sv;
|
|
|
|
case EItemType::PowerBombs:
|
|
|
|
return "Power Bombs"sv;
|
|
|
|
case EItemType::Flamethrower:
|
|
|
|
return "Flamethrower"sv;
|
|
|
|
case EItemType::ThermalVisor:
|
|
|
|
return "Thermal Visor"sv;
|
|
|
|
case EItemType::ChargeBeam:
|
|
|
|
return "Charge Beam"sv;
|
|
|
|
case EItemType::SuperMissile:
|
|
|
|
return "Super Missile"sv;
|
|
|
|
case EItemType::GrappleBeam:
|
|
|
|
return "Grapple Beam"sv;
|
|
|
|
case EItemType::XRayVisor:
|
|
|
|
return "XRay Visor"sv;
|
|
|
|
case EItemType::IceSpreader:
|
|
|
|
return "Ice Spreader"sv;
|
|
|
|
case EItemType::SpaceJumpBoots:
|
|
|
|
return "Space Jump Boots"sv;
|
|
|
|
case EItemType::MorphBall:
|
|
|
|
return "Morph Ball"sv;
|
|
|
|
case EItemType::CombatVisor:
|
|
|
|
return "Combat Visor"sv;
|
|
|
|
case EItemType::BoostBall:
|
|
|
|
return "Boost Ball"sv;
|
|
|
|
case EItemType::SpiderBall:
|
|
|
|
return "Spider Ball"sv;
|
|
|
|
case EItemType::PowerSuit:
|
|
|
|
return "Power Suit"sv;
|
|
|
|
case EItemType::GravitySuit:
|
|
|
|
return "Gravity Suit"sv;
|
|
|
|
case EItemType::VariaSuit:
|
|
|
|
return "Varia Suit"sv;
|
|
|
|
case EItemType::PhazonSuit:
|
|
|
|
return "Phazon Suit"sv;
|
|
|
|
case EItemType::EnergyTanks:
|
|
|
|
return "Energy Tanks"sv;
|
|
|
|
case EItemType::HealthRefill:
|
|
|
|
return "Health Refill"sv;
|
|
|
|
case EItemType::Wavebuster:
|
|
|
|
return "Wavebuster"sv;
|
|
|
|
case EItemType::Truth:
|
|
|
|
return "Artifact of Truth"sv;
|
|
|
|
case EItemType::Strength:
|
|
|
|
return "Artifact of Strength"sv;
|
|
|
|
case EItemType::Elder:
|
|
|
|
return "Artifact of Elder"sv;
|
|
|
|
case EItemType::Wild:
|
|
|
|
return "Artifact of Wild"sv;
|
|
|
|
case EItemType::Lifegiver:
|
|
|
|
return "Artifact of Lifegiver"sv;
|
|
|
|
case EItemType::Warrior:
|
|
|
|
return "Artifact of Warrior"sv;
|
|
|
|
case EItemType::Chozo:
|
|
|
|
return "Artifact of Chozo"sv;
|
|
|
|
case EItemType::Nature:
|
|
|
|
return "Artifact of Nature"sv;
|
|
|
|
case EItemType::Sun:
|
|
|
|
return "Artifact of Sun"sv;
|
|
|
|
case EItemType::World:
|
|
|
|
return "Artifact of World"sv;
|
|
|
|
case EItemType::Spirit:
|
|
|
|
return "Artifact of Spirit"sv;
|
|
|
|
case EItemType::Newborn:
|
|
|
|
return "Artifact of Newborn"sv;
|
|
|
|
default:
|
|
|
|
return "[unknown]"sv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
} // namespace metaforce
|