Files
cdemeyer-teachx aff99a507c code refactor
2025-08-20 13:02:04 +09:00

107 lines
4.4 KiB
C++

#ifndef CONFIG_H
#define CONFIG_H
#include <cstdint>
namespace PokEng {
// Generation support
enum class Generation : uint8_t {
I = 1,
II = 2,
III = 3,
IV = 4,
V = 5,
VI = 6,
VII = 7,
VIII = 8,
IX = 9
};
// Stat indices for nature calculations
enum class StatIndex : uint8_t {
HP = 0,
ATTACK = 1,
DEFENSE = 2,
SP_ATTACK = 3,
SP_DEFENSE = 4,
SPEED = 5
};
// Pokemon Nature - encoded as 8 bits: upper 4 bits = positive stat, lower 4 bits = negative stat
// Stat encoding: 0=HP/None, 1=Attack, 2=Defense, 3=SpAttack, 4=SpDefense, 5=Speed
struct Nature {
private:
uint8_t m_encoded; // Upper 4 bits: positive stat, Lower 4 bits: negative stat
public:
// Constructor from encoded value
constexpr explicit Nature(uint8_t encoded = 0) : m_encoded(encoded) {}
// Constructor from positive and negative stats
constexpr Nature(StatIndex positive, StatIndex negative)
: m_encoded((static_cast<uint8_t>(positive) << 4) | static_cast<uint8_t>(negative)) {}
// Get the stat that is increased by this nature
constexpr StatIndex getPositiveStat() const {
return static_cast<StatIndex>((m_encoded >> 4) & 0xF);
}
// Get the stat that is decreased by this nature
constexpr StatIndex getNegativeStat() const {
return static_cast<StatIndex>(m_encoded & 0xF);
}
// Check if nature is neutral (same positive and negative stat)
constexpr bool isNeutral() const {
return getPositiveStat() == getNegativeStat();
}
constexpr uint8_t getMultiplier10(StatIndex stat) const {
return static_cast<uint8_t>(10u + (getPositiveStat() == stat) - (getNegativeStat() == stat));
}
// Get encoded value
constexpr uint8_t getEncoded() const { return m_encoded; }
// Comparison operators
constexpr bool operator==(const Nature& other) const { return m_encoded == other.m_encoded; }
constexpr bool operator!=(const Nature& other) const { return m_encoded != other.m_encoded; }
// Predefined nature constants
static constexpr Nature HARDY() { return Nature(StatIndex::ATTACK, StatIndex::ATTACK); }
static constexpr Nature DOCILE() { return Nature(StatIndex::DEFENSE, StatIndex::DEFENSE); }
static constexpr Nature BASHFUL() { return Nature(StatIndex::SP_ATTACK, StatIndex::SP_ATTACK); }
static constexpr Nature QUIRKY() { return Nature(StatIndex::SP_DEFENSE, StatIndex::SP_DEFENSE); }
static constexpr Nature SERIOUS() { return Nature(StatIndex::SPEED, StatIndex::SPEED); }
static constexpr Nature LONELY() { return Nature(StatIndex::ATTACK, StatIndex::DEFENSE); }
static constexpr Nature ADAMANT() { return Nature(StatIndex::ATTACK, StatIndex::SP_ATTACK); }
static constexpr Nature NAUGHTY() { return Nature(StatIndex::ATTACK, StatIndex::SP_DEFENSE); }
static constexpr Nature BRAVE() { return Nature(StatIndex::ATTACK, StatIndex::SPEED); }
static constexpr Nature BOLD() { return Nature(StatIndex::DEFENSE, StatIndex::ATTACK); }
static constexpr Nature IMPISH() { return Nature(StatIndex::DEFENSE, StatIndex::SP_ATTACK); }
static constexpr Nature LAX() { return Nature(StatIndex::DEFENSE, StatIndex::SP_DEFENSE); }
static constexpr Nature RELAXED() { return Nature(StatIndex::DEFENSE, StatIndex::SPEED); }
static constexpr Nature MODEST() { return Nature(StatIndex::SP_ATTACK, StatIndex::ATTACK); }
static constexpr Nature MILD() { return Nature(StatIndex::SP_ATTACK, StatIndex::DEFENSE); }
static constexpr Nature RASH() { return Nature(StatIndex::SP_ATTACK, StatIndex::SP_DEFENSE); }
static constexpr Nature QUIET() { return Nature(StatIndex::SP_ATTACK, StatIndex::SPEED); }
static constexpr Nature CALM() { return Nature(StatIndex::SP_DEFENSE, StatIndex::ATTACK); }
static constexpr Nature GENTLE() { return Nature(StatIndex::SP_DEFENSE, StatIndex::DEFENSE); }
static constexpr Nature CAREFUL() { return Nature(StatIndex::SP_DEFENSE, StatIndex::SP_ATTACK); }
static constexpr Nature SASSY() { return Nature(StatIndex::SP_DEFENSE, StatIndex::SPEED); }
static constexpr Nature TIMID() { return Nature(StatIndex::SPEED, StatIndex::ATTACK); }
static constexpr Nature HASTY() { return Nature(StatIndex::SPEED, StatIndex::DEFENSE); }
static constexpr Nature JOLLY() { return Nature(StatIndex::SPEED, StatIndex::SP_ATTACK); }
static constexpr Nature NAIVE() { return Nature(StatIndex::SPEED, StatIndex::SP_DEFENSE); }
};
} // namespace PokEng
#endif