From dd61d27d98a07faf07efc4f1b0220b5110df6125 Mon Sep 17 00:00:00 2001 From: Connor De Meyer Date: Sat, 16 Aug 2025 14:14:53 +0900 Subject: [PATCH] compilable for windows --- cmake/modules/CompilerWarnings.cmake | 4 +++ include/core/pokemon_stats.h | 44 ++++++++++++---------------- include/core/types.h | 1 + src/core/pokemon_stats.cpp | 12 +++----- src/core/types.cpp | 2 +- 5 files changed, 29 insertions(+), 34 deletions(-) diff --git a/cmake/modules/CompilerWarnings.cmake b/cmake/modules/CompilerWarnings.cmake index 143c7a8..90d9654 100644 --- a/cmake/modules/CompilerWarnings.cmake +++ b/cmake/modules/CompilerWarnings.cmake @@ -6,7 +6,11 @@ function(set_project_warnings) add_compile_options( /W4 /permissive- + /std:c++20 # Explicitly enable C++17 standard $<$:/WX> + # Disable specific warnings that are too strict + /wd4244 # conversion from 'int' to 'char', possible loss of data + /wd4996 # 'fopen': This function or variable may be unsafe ) else() add_compile_options( diff --git a/include/core/pokemon_stats.h b/include/core/pokemon_stats.h index decd4df..fd136d2 100644 --- a/include/core/pokemon_stats.h +++ b/include/core/pokemon_stats.h @@ -12,15 +12,15 @@ class PokemonInfo; // Base stats structure for a Pokemon species struct BaseStats { - uint16_t hp; - uint16_t attack; - uint16_t defense; - uint16_t sp_attack; - uint16_t sp_defense; - uint16_t speed; + uint8_t hp; + uint8_t attack; + uint8_t defense; + uint8_t sp_attack; + uint8_t sp_defense; + uint8_t speed; BaseStats() : hp(0), attack(0), defense(0), sp_attack(0), sp_defense(0), speed(0) {} - BaseStats(uint16_t hp_, uint16_t atk, uint16_t def, uint16_t spa, uint16_t spd, uint16_t spe) + BaseStats(uint8_t hp_, uint8_t atk, uint8_t def, uint8_t spa, uint8_t spd, uint8_t spe) : hp(hp_), attack(atk), defense(def), sp_attack(spa), sp_defense(spd), speed(spe) {} }; @@ -68,14 +68,14 @@ struct IndividualValues { } }; -// Computed battle stats +// Computed battle stat struct BattleStats { - uint16_t hp; // Max 20,000 - uint16_t attack; // Max 20,000 - uint16_t defense; // Max 20,000 - uint16_t sp_attack; // Max 20,000 - uint16_t sp_defense; // Max 20,000 - uint16_t speed; // Max 20,000 + uint16_t hp; + uint16_t attack; + uint16_t defense; + uint16_t sp_attack; + uint16_t sp_defense; + uint16_t speed; BattleStats() : hp(0), attack(0), defense(0), sp_attack(0), sp_defense(0), speed(0) {} BattleStats(uint16_t hp_, uint16_t atk, uint16_t def, uint16_t spa, uint16_t spd, uint16_t spe) @@ -111,11 +111,11 @@ public: BattleStats calculateBattleStats() const; private: - BaseStats m_baseStats; - uint8_t m_level = 1; - Nature m_nature = Nature::HARDY; - IndividualValues m_ivs; - EffortValues m_evs; + BaseStats m_baseStats; // size 6, align 1 + IndividualValues m_ivs; // size 6, align 1 + EffortValues m_evs; // size 6, align 1 + uint8_t m_level = 1; // size 1, align 1 + Nature m_nature = Nature::HARDY; // size 1, align 1 }; // Nature utility functions @@ -154,12 +154,6 @@ public: template static typename std::enable_if= Generation::III, uint16_t>::type calculateStat(uint16_t base, uint8_t iv, uint8_t ev, uint8_t level, Nature nature, StatIndex statIndex); - -private: - // Helper functions - static uint16_t clampStat(uint32_t value) { - return (value > 20000) ? 20000 : static_cast(value); - } }; } // namespace PokEng diff --git a/include/core/types.h b/include/core/types.h index c348ad2..251c4c5 100644 --- a/include/core/types.h +++ b/include/core/types.h @@ -3,6 +3,7 @@ #include #include +#include #include #include #include diff --git a/src/core/pokemon_stats.cpp b/src/core/pokemon_stats.cpp index fcb2648..be2318f 100644 --- a/src/core/pokemon_stats.cpp +++ b/src/core/pokemon_stats.cpp @@ -113,18 +113,16 @@ template typename std::enable_if::type StatCalculator::calculateHP(uint16_t base, uint8_t dv, uint16_t statExp, uint8_t level) { // HP=⌊((Base+DV)×2+⌊⌈STATEXP⌉/4⌋)×Level/100⌋+Level+10 - uint32_t result = ((static_cast(base) + dv) * 2 + + return ((static_cast(base) + dv) * 2 + static_cast(std::ceil(statExp) / 4)) * level / 100 + level + 10; - return clampStat(result); } template typename std::enable_if::type StatCalculator::calculateStat(uint16_t base, uint8_t dv, uint16_t statExp, uint8_t level) { // OtherStat=⌊((Base+DV)×2+⌊⌈STATEXP⌉/4⌋)×Level/100⌋+5 - uint32_t result = ((static_cast(base) + dv) * 2 + + return ((static_cast(base) + dv) * 2 + static_cast(std::ceil(statExp) / 4)) * level / 100 + 5; - return clampStat(result); } // Generation III+ stat calculation implementations @@ -132,8 +130,7 @@ template typename std::enable_if= Generation::III, uint16_t>::type StatCalculator::calculateHP(uint16_t base, uint8_t iv, uint8_t ev, uint8_t level) { // HP=⌊(2×Base+IV+⌊EV/4⌋)×Level/100⌋+Level+10 - uint32_t result = (2 * static_cast(base) + iv + ev / 4) * level / 100 + level + 10; - return clampStat(result); + return (2 * static_cast(base) + iv + ev / 4) * level / 100 + level + 10; } template @@ -142,8 +139,7 @@ StatCalculator::calculateStat(uint16_t base, uint8_t iv, uint8_t ev, uint8_t lev // OtherStat=⌊(⌊(2×Base+IV+⌊EV/4⌋)×Level/100⌋+5)×Nature⌋ uint32_t baseStat = (2 * static_cast(base) + iv + ev / 4) * level / 100 + 5; float natureMultiplier = NatureUtils::getStatMultiplier(nature, statIndex); - uint32_t result = static_cast(std::floor(static_cast(baseStat) * natureMultiplier)); - return clampStat(result); + return static_cast(std::floor(static_cast(baseStat) * natureMultiplier)); } // Explicit template instantiations for Generation I & II diff --git a/src/core/types.cpp b/src/core/types.cpp index 3fe1217..55be3df 100644 --- a/src/core/types.cpp +++ b/src/core/types.cpp @@ -255,7 +255,7 @@ bool TypeUtils::loadTypeChartFromFile(const std::string& filename) { } else if constexpr (Gen == Generation::II) { TypeUtils::s_gen2Chart[index] = multiplier; } else if constexpr (Gen == Generation::III) { - TypeUtils::s_gen3Chart[index] = multiplier; + TypeUtils::s_gen3Chart[index] = multiplier; } else if constexpr (Gen == Generation::IV) { TypeUtils::s_gen4Chart[index] = multiplier; } else if constexpr (Gen == Generation::V) {