mirror of https://github.com/AxioDL/metaforce.git
Merge pull request #77 from lioncash/state
CPlayerState: Make use of std::array where applicable
This commit is contained in:
commit
110f07256d
|
@ -1,18 +1,26 @@
|
||||||
#include "CPlayerState.hpp"
|
#include "Runtime/CPlayerState.hpp"
|
||||||
#include "IOStreams.hpp"
|
|
||||||
#include "zeus/Math.hpp"
|
#include <algorithm>
|
||||||
#include "CStateManager.hpp"
|
#include <array>
|
||||||
#include "Camera/CCameraManager.hpp"
|
|
||||||
#include "Camera/CFirstPersonCamera.hpp"
|
#include "Runtime/CMemoryCardSys.hpp"
|
||||||
#include "CMemoryCardSys.hpp"
|
#include "Runtime/CStateManager.hpp"
|
||||||
#include "GameGlobalObjects.hpp"
|
#include "Runtime/GameGlobalObjects.hpp"
|
||||||
#include "TCastTo.hpp"
|
#include "Runtime/IOStreams.hpp"
|
||||||
|
#include "Runtime/TCastTo.hpp"
|
||||||
|
#include "Runtime/Camera/CCameraManager.hpp"
|
||||||
|
#include "Runtime/Camera/CFirstPersonCamera.hpp"
|
||||||
|
|
||||||
|
#include <zeus/Math.hpp>
|
||||||
|
|
||||||
namespace urde {
|
namespace urde {
|
||||||
const u32 CPlayerState::PowerUpMaxValues[41] = {1, 1, 1, 1, 250, 1, 1, 8, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
namespace {
|
||||||
1, 1, 1, 14, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
|
constexpr std::array<u32, 41> PowerUpMaxValues{
|
||||||
|
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,
|
||||||
|
};
|
||||||
|
|
||||||
const char* CPlayerState::PowerUpNames[41] = {
|
[[maybe_unused]] constexpr std::array<const char*, 41> PowerUpNames{
|
||||||
"Power Beam",
|
"Power Beam",
|
||||||
"Ice Beam",
|
"Ice Beam",
|
||||||
"Wave Beam",
|
"Wave Beam",
|
||||||
|
@ -56,6 +64,15 @@ const char* CPlayerState::PowerUpNames[41] = {
|
||||||
"Artifact of Newborn",
|
"Artifact of Newborn",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
constexpr std::array<u32, 5> costs{
|
||||||
|
5, 10, 10, 10, 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
constexpr std::array<float, 5> ComboAmmoPeriods{
|
||||||
|
0.2f, 0.1f, 0.2f, 0.2f, 1.f,
|
||||||
|
};
|
||||||
|
} // Anonymous namespace
|
||||||
|
|
||||||
CPlayerState::CPlayerState() : x188_staticIntf(5) {
|
CPlayerState::CPlayerState() : x188_staticIntf(5) {
|
||||||
x0_24_alive = true;
|
x0_24_alive = true;
|
||||||
x24_powerups.resize(41);
|
x24_powerups.resize(41);
|
||||||
|
@ -73,12 +90,13 @@ CPlayerState::CPlayerState(CBitStreamReader& stream) : x188_staticIntf(5) {
|
||||||
x8_currentBeam = EBeamId(stream.ReadEncoded(CBitStreamReader::GetBitCount(5)));
|
x8_currentBeam = EBeamId(stream.ReadEncoded(CBitStreamReader::GetBitCount(5)));
|
||||||
x20_currentSuit = EPlayerSuit(stream.ReadEncoded(CBitStreamReader::GetBitCount(4)));
|
x20_currentSuit = EPlayerSuit(stream.ReadEncoded(CBitStreamReader::GetBitCount(4)));
|
||||||
x24_powerups.resize(41);
|
x24_powerups.resize(41);
|
||||||
for (u32 i = 0; i < x24_powerups.size(); ++i) {
|
for (size_t i = 0; i < x24_powerups.size(); ++i) {
|
||||||
if (PowerUpMaxValues[i] == 0)
|
if (PowerUpMaxValues[i] == 0) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
u32 a = u32(stream.ReadEncoded(CBitStreamReader::GetBitCount(PowerUpMaxValues[i])));
|
const u32 a = u32(stream.ReadEncoded(CBitStreamReader::GetBitCount(PowerUpMaxValues[i])));
|
||||||
u32 b = u32(stream.ReadEncoded(CBitStreamReader::GetBitCount(PowerUpMaxValues[i])));
|
const u32 b = u32(stream.ReadEncoded(CBitStreamReader::GetBitCount(PowerUpMaxValues[i])));
|
||||||
x24_powerups[i] = CPowerUp(a, b);
|
x24_powerups[i] = CPowerUp(a, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,7 +121,7 @@ void CPlayerState::PutTo(CBitStreamWriter& stream) {
|
||||||
stream.WriteEncoded(hp.iHP, 32);
|
stream.WriteEncoded(hp.iHP, 32);
|
||||||
stream.WriteEncoded(u32(x8_currentBeam), CBitStreamWriter::GetBitCount(5));
|
stream.WriteEncoded(u32(x8_currentBeam), CBitStreamWriter::GetBitCount(5));
|
||||||
stream.WriteEncoded(u32(x20_currentSuit), CBitStreamWriter::GetBitCount(4));
|
stream.WriteEncoded(u32(x20_currentSuit), CBitStreamWriter::GetBitCount(4));
|
||||||
for (u32 i = 0; i < x24_powerups.size(); ++i) {
|
for (size_t i = 0; i < x24_powerups.size(); ++i) {
|
||||||
const CPowerUp& pup = x24_powerups[i];
|
const CPowerUp& pup = x24_powerups[i];
|
||||||
stream.WriteEncoded(pup.x0_amount, CBitStreamWriter::GetBitCount(PowerUpMaxValues[i]));
|
stream.WriteEncoded(pup.x0_amount, CBitStreamWriter::GetBitCount(PowerUpMaxValues[i]));
|
||||||
stream.WriteEncoded(pup.x4_capacity, CBitStreamWriter::GetBitCount(PowerUpMaxValues[i]));
|
stream.WriteEncoded(pup.x4_capacity, CBitStreamWriter::GetBitCount(PowerUpMaxValues[i]));
|
||||||
|
@ -120,13 +138,9 @@ void CPlayerState::PutTo(CBitStreamWriter& stream) {
|
||||||
stream.WriteEncoded(x180_scanCompletionRate.second, CBitStreamWriter::GetBitCount(0x100));
|
stream.WriteEncoded(x180_scanCompletionRate.second, CBitStreamWriter::GetBitCount(0x100));
|
||||||
}
|
}
|
||||||
|
|
||||||
static const u32 costs[] = {5, 10, 10, 10, 1};
|
u32 CPlayerState::GetMissileCostForAltAttack() const { return costs[size_t(x8_currentBeam)]; }
|
||||||
|
|
||||||
u32 CPlayerState::GetMissileCostForAltAttack() const { return costs[u32(x8_currentBeam)]; }
|
float CPlayerState::GetComboFireAmmoPeriod() const { return ComboAmmoPeriods[size_t(x8_currentBeam)]; }
|
||||||
|
|
||||||
static const float ComboAmmoPeriods[] = {0.2f, 0.1f, 0.2f, 0.2f, 1.f};
|
|
||||||
|
|
||||||
float CPlayerState::GetComboFireAmmoPeriod() const { return ComboAmmoPeriods[u32(x8_currentBeam)]; }
|
|
||||||
|
|
||||||
u32 CPlayerState::CalculateItemCollectionRate() const {
|
u32 CPlayerState::CalculateItemCollectionRate() const {
|
||||||
u32 total = GetItemCapacity(EItemType::PowerBombs);
|
u32 total = GetItemCapacity(EItemType::PowerBombs);
|
||||||
|
@ -373,6 +387,8 @@ void CPlayerState::InitializeScanTimes() {
|
||||||
x170_scanTimes.emplace_back(state.first, 0.f);
|
x170_scanTimes.emplace_back(state.first, 0.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u32 CPlayerState::GetPowerUpMaxValue(EItemType type) { return PowerUpMaxValues[size_t(type)]; }
|
||||||
|
|
||||||
const std::unordered_map<std::string_view, CPlayerState::EItemType> CPlayerState::g_TypeNameMap = {
|
const std::unordered_map<std::string_view, CPlayerState::EItemType> CPlayerState::g_TypeNameMap = {
|
||||||
{"powerbeam"sv, EItemType::PowerBeam},
|
{"powerbeam"sv, EItemType::PowerBeam},
|
||||||
{"icebeam"sv, EItemType::IceBeam},
|
{"icebeam"sv, EItemType::IceBeam},
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "RetroTypes.hpp"
|
#include <string_view>
|
||||||
#include "CBasics.hpp"
|
|
||||||
#include "CStaticInterference.hpp"
|
|
||||||
#include "IOStreams.hpp"
|
|
||||||
#include "rstl.hpp"
|
|
||||||
#include "World/CHealthInfo.hpp"
|
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "Runtime/CStaticInterference.hpp"
|
||||||
|
#include "Runtime/IOStreams.hpp"
|
||||||
|
#include "Runtime/RetroTypes.hpp"
|
||||||
|
#include "Runtime/rstl.hpp"
|
||||||
|
#include "Runtime/World/CHealthInfo.hpp"
|
||||||
|
|
||||||
namespace urde {
|
namespace urde {
|
||||||
|
|
||||||
|
@ -88,8 +90,6 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static const std::unordered_map<std::string_view, EItemType> g_TypeNameMap;
|
static const std::unordered_map<std::string_view, EItemType> g_TypeNameMap;
|
||||||
static const u32 PowerUpMaxValues[41];
|
|
||||||
static const char* PowerUpNames[41];
|
|
||||||
struct CPowerUp {
|
struct CPowerUp {
|
||||||
u32 x0_amount = 0;
|
u32 x0_amount = 0;
|
||||||
u32 x4_capacity = 0;
|
u32 x4_capacity = 0;
|
||||||
|
@ -174,7 +174,7 @@ public:
|
||||||
CPlayerState();
|
CPlayerState();
|
||||||
CPlayerState(CBitStreamReader& stream);
|
CPlayerState(CBitStreamReader& stream);
|
||||||
void PutTo(CBitStreamWriter& stream);
|
void PutTo(CBitStreamWriter& stream);
|
||||||
static u32 GetPowerUpMaxValue(EItemType type) { return PowerUpMaxValues[u32(type)]; }
|
static u32 GetPowerUpMaxValue(EItemType type);
|
||||||
static EItemType ItemNameToType(std::string_view name);
|
static EItemType ItemNameToType(std::string_view name);
|
||||||
bool CanTakeDamage() const { return m_canTakeDamage; }
|
bool CanTakeDamage() const { return m_canTakeDamage; }
|
||||||
void SetCanTakeDamage(bool c) { m_canTakeDamage = c; }
|
void SetCanTakeDamage(bool c) { m_canTakeDamage = c; }
|
||||||
|
|
Loading…
Reference in New Issue