From 8dd881eab1d3af71a6d4281caff3383f5b863bb5 Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Tue, 4 Oct 2022 23:46:30 -0700 Subject: [PATCH] CPlayerState fixes --- Makefile | 2 +- include/MetroidPrime/Player/CPlayerState.hpp | 15 ++++++++ src/MetroidPrime/Player/CPlayerState.cpp | 39 +++++++++----------- 3 files changed, 34 insertions(+), 22 deletions(-) diff --git a/Makefile b/Makefile index a015b662..70953a06 100644 --- a/Makefile +++ b/Makefile @@ -119,7 +119,7 @@ DEFINES = -DPRIME1 -DVERSION=$(VERSION_NUM) -DNONMATCHING=$(NONMATCHING) CFLAGS_BASE = -proc gekko -nodefaults -Cpp_exceptions off -RTTI off -fp hard -fp_contract on -O4,p -maxerrors 1 -enum int -inline auto -str reuse -nosyspath -MMD $(DEFINES) $(INCLUDES) CFLAGS = $(CFLAGS_BASE) -use_lmw_stmw on -str reuse,pool,readonly -gccinc -inline deferred,noauto -common on CFLAGS_RUNTIME = $(CFLAGS_BASE) -use_lmw_stmw on -str reuse,pool,readonly -gccinc -inline deferred,auto -CFLAGS_MUSYX = $(CFLAGS_BASE) -str reuse,pool,readonly +CFLAGS_MUSYX = $(CFLAGS_BASE) -fp hard -fp_contract off -str reuse,pool,readonly ifeq ($(VERBOSE),0) # this set of ASFLAGS generates no warnings. diff --git a/include/MetroidPrime/Player/CPlayerState.hpp b/include/MetroidPrime/Player/CPlayerState.hpp index a8e43143..4a5fa2b5 100644 --- a/include/MetroidPrime/Player/CPlayerState.hpp +++ b/include/MetroidPrime/Player/CPlayerState.hpp @@ -158,6 +158,21 @@ private: int x4_capacity; CPowerUp() : x0_amount(0), x4_capacity(0) {} CPowerUp(int amount, int capacity); + + void Add(int amount) { + int capacity = x4_capacity; + x0_amount += amount; + if (x0_amount > capacity) { + x0_amount = capacity; + } + } + + void Dec(int amount) { + x0_amount -= amount; + if (x0_amount < 0) { + x0_amount = 0; + } + } }; bool x0_24_alive : 1; diff --git a/src/MetroidPrime/Player/CPlayerState.cpp b/src/MetroidPrime/Player/CPlayerState.cpp index 9c102418..c1bc3304 100644 --- a/src/MetroidPrime/Player/CPlayerState.cpp +++ b/src/MetroidPrime/Player/CPlayerState.cpp @@ -27,6 +27,13 @@ static const float kComboAmmoPeriods[] = { 0.2f, 0.1f, 0.2f, 0.2f, 1.f, }; +static const char* kVisorNames[] = { + "CombatVisor", + "XRayVisor", + "ScanVisor", + "ThermalVisor", +}; + static const float kEnergyTankCapacity = 100.f; static const float kBaseHealthCapacity = 99.f; @@ -151,11 +158,11 @@ void CPlayerState::ReInitializePowerUp(CPlayerState::EItemType type, int capacit } void CPlayerState::InitializePowerUp(CPlayerState::EItemType type, int capacity) { - if (type >= kIT_Max) + if (type < kIT_PowerBeam || type > kIT_Max - 1) return; CPowerUp& pup = x24_powerups[u32(type)]; - pup.x4_capacity = CMath::Clamp(0, pup.x4_capacity + capacity, kPowerUpMax[u32(type)]); + pup.x4_capacity = CMath::Clamp(0, capacity + pup.x4_capacity, kPowerUpMax[u32(type)]); pup.x0_amount = rstl::min_val(pup.x0_amount, pup.x4_capacity); if (type >= kIT_PowerSuit && type <= kIT_PhazonSuit) { if (HasPowerUp(kIT_PhazonSuit)) @@ -202,11 +209,7 @@ void CPlayerState::IncrPickUp(EItemType type, int amount) { case kIT_World: case kIT_Spirit: case kIT_Newborn: { - int oldCapacity = x24_powerups[type].x4_capacity; - x24_powerups[type].x0_amount += amount; - if (oldCapacity < x24_powerups[type].x0_amount) { - x24_powerups[type].x0_amount = oldCapacity; - } + x24_powerups[type].Add(amount); break; } case kIT_HealthRefill: { @@ -214,10 +217,10 @@ void CPlayerState::IncrPickUp(EItemType type, int amount) { if (info != NULL) { float newHealth = float(amount) + info->GetHP(); float maxHealth = CalculateHealth(); - if (newHealth <= newHealth) { - info->SetHP(newHealth); - } else { + if (newHealth > maxHealth) { info->SetHP(maxHealth); + } else { + info->SetHP(newHealth); } } } @@ -236,10 +239,7 @@ void CPlayerState::DecrPickUp(CPlayerState::EItemType type, int amount) { case kIT_Missiles: case kIT_PowerBombs: case kIT_Flamethrower: - x24_powerups[type].x0_amount -= amount; - if (x24_powerups[type].x0_amount < 0) { - x24_powerups[type].x0_amount = 0; - } + x24_powerups[type].Dec(amount); default: return; } @@ -285,7 +285,7 @@ bool CPlayerState::HasPowerUp(CPlayerState::EItemType type) const { if (type < 0 || kIT_Max - 1 < type) { return false; } - return x24_powerups[u32(type)].x4_capacity != 0; + return x24_powerups[u32(type)].x4_capacity > 0; } uint CPlayerState::GetPowerUp(CPlayerState::EItemType type) { @@ -312,7 +312,7 @@ bool CPlayerState::ItemEnabled(CPlayerState::EItemType type) const { } void CPlayerState::ResetVisor() { - x18_transitioningVisor = x14_currentVisor = kPV_Combat; + x14_currentVisor = x18_transitioningVisor = kPV_Combat; x1c_visorTransitionFactor = 0.0f; } @@ -327,16 +327,13 @@ void CPlayerState::UpdateVisorTransition(float dt) { return; if (x14_currentVisor == x18_transitioningVisor) { - x1c_visorTransitionFactor += dt; - if (x1c_visorTransitionFactor > 0.2f) - x1c_visorTransitionFactor = 0.2f; + x1c_visorTransitionFactor = rstl::min_val(0.2f, x1c_visorTransitionFactor + dt); } else { x1c_visorTransitionFactor -= dt; if (x1c_visorTransitionFactor < 0.f) { x14_currentVisor = x18_transitioningVisor; x1c_visorTransitionFactor = fabs(x1c_visorTransitionFactor); - if (x1c_visorTransitionFactor > 0.19999f) - x1c_visorTransitionFactor = 0.19999f; + x1c_visorTransitionFactor = rstl::min_val(x1c_visorTransitionFactor, 0.19999f); } } }