Kelsidavis-WoWee/include/game/protocol_constants.hpp
Pavel Okhlopkov 97106bd6ae fix(render): code quality cleanup
Magic number elimination:
- Create protocol_constants.hpp, warden_constants.hpp,
  render_constants.hpp, ui_constants.hpp
- Replace ~55 magic numbers across game_handler, warden_handler,
  m2_renderer_render

Reduce nesting depth:
- Extract 5 parseEffect* methods from handleSpellLogExecute
  (max indent 52 → 16 cols)
- Extract resolveSpellSchool/playSpellCastSound/playSpellImpactSound
  from 3× duplicate audio blocks in handleSpellGo
- Flatten SMSG_INVENTORY_CHANGE_FAILURE with early-return guards
- Extract drawScreenEdgeVignette() for 3 duplicate vignette blocks

DRY extract patterns:
- Replace 12 compound expansion checks with isPreWotlk() across
  movement_handler (9), chat_handler (1), social_handler (1)

const to constexpr:
- Promote 23+ static const arrays/scalars to static constexpr across
  12 source files

Error handling:
- Convert PIN auth from exceptions to std::optional<PinProof>
- Add [[nodiscard]] to 15+ initialize/parse methods
- Wrap ~20 unchecked initialize() calls with LOG_WARNING/LOG_ERROR

Signed-off-by: Pavel Okhlopkov <pavel.okhlopkov@flant.com>
2026-04-06 22:43:13 +03:00

126 lines
5.4 KiB
C++

#pragma once
#include <cstdint>
// WoW 3.3.5a (12340) protocol constants.
// Centralised so every handler references a single source of truth.
namespace wowee {
namespace game {
// ---------------------------------------------------------------------------
// Currency
// ---------------------------------------------------------------------------
constexpr uint32_t COPPER_PER_GOLD = 10000;
constexpr uint32_t COPPER_PER_SILVER = 100;
// ---------------------------------------------------------------------------
// Unit flags (UNIT_FIELD_FLAGS — offset 46 in UnitFields)
// ---------------------------------------------------------------------------
constexpr uint32_t UNIT_FLAG_TAXI_FLIGHT = 0x00000100;
// ---------------------------------------------------------------------------
// NPC flags (UNIT_NPC_FLAGS — offset 147 in UnitFields, 3.3.5a)
// ---------------------------------------------------------------------------
constexpr uint32_t NPC_FLAG_SPIRIT_GUIDE = 0x00004000;
constexpr uint32_t NPC_FLAG_SPIRIT_HEALER = 0x00008000;
// ---------------------------------------------------------------------------
// Default action-bar spell IDs
// ---------------------------------------------------------------------------
constexpr uint32_t SPELL_ID_ATTACK = 6603;
constexpr uint32_t SPELL_ID_HEARTHSTONE = 8690;
// ---------------------------------------------------------------------------
// Class IDs
// ---------------------------------------------------------------------------
constexpr uint32_t CLASS_WARRIOR = 1;
constexpr uint32_t CLASS_PALADIN = 2;
constexpr uint32_t CLASS_HUNTER = 3;
constexpr uint32_t CLASS_ROGUE = 4;
constexpr uint32_t CLASS_PRIEST = 5;
constexpr uint32_t CLASS_DK = 6;
constexpr uint32_t CLASS_SHAMAN = 7;
constexpr uint32_t CLASS_MAGE = 8;
constexpr uint32_t CLASS_WARLOCK = 9;
constexpr uint32_t CLASS_DRUID = 11;
// ---------------------------------------------------------------------------
// Class-specific stance / form / presence spell IDs
// ---------------------------------------------------------------------------
// Warrior stances
constexpr uint32_t SPELL_BATTLE_STANCE = 2457;
constexpr uint32_t SPELL_DEFENSIVE_STANCE = 71;
constexpr uint32_t SPELL_BERSERKER_STANCE = 2458;
// Death Knight presences
constexpr uint32_t SPELL_BLOOD_PRESENCE = 48266;
constexpr uint32_t SPELL_FROST_PRESENCE = 48263;
constexpr uint32_t SPELL_UNHOLY_PRESENCE = 48265;
// Druid forms
constexpr uint32_t SPELL_BEAR_FORM = 5487;
constexpr uint32_t SPELL_DIRE_BEAR_FORM = 9634;
constexpr uint32_t SPELL_CAT_FORM = 768;
constexpr uint32_t SPELL_AQUATIC_FORM = 1066;
constexpr uint32_t SPELL_TRAVEL_FORM = 783;
constexpr uint32_t SPELL_MOONKIN_FORM = 24858;
constexpr uint32_t SPELL_FLIGHT_FORM = 33943;
constexpr uint32_t SPELL_SWIFT_FLIGHT = 40120;
constexpr uint32_t SPELL_TREE_OF_LIFE = 33891;
// Rogue
constexpr uint32_t SPELL_STEALTH = 1784;
// Priest
constexpr uint32_t SPELL_SHADOWFORM = 15473;
// ---------------------------------------------------------------------------
// Session / network timing
// ---------------------------------------------------------------------------
constexpr uint32_t SESSION_KEY_HEX_LENGTH = 40;
constexpr uint32_t RX_SILENCE_WARNING_MS = 10000; // 10 s
constexpr uint32_t RX_SILENCE_CRITICAL_MS = 15000; // 15 s
constexpr float WARDEN_GATE_LOG_INTERVAL_SEC = 30.0f;
constexpr float CLASSIC_PING_INTERVAL_SEC = 10.0f;
// ---------------------------------------------------------------------------
// Heartbeat / area-trigger intervals (seconds)
// ---------------------------------------------------------------------------
constexpr float HEARTBEAT_INTERVAL_TAXI = 0.25f;
constexpr float HEARTBEAT_INTERVAL_STATIONARY_COMBAT = 0.75f;
constexpr float HEARTBEAT_INTERVAL_MOVING_COMBAT = 0.20f;
constexpr float AREA_TRIGGER_CHECK_INTERVAL = 0.25f;
// ---------------------------------------------------------------------------
// Gameplay distance thresholds
// ---------------------------------------------------------------------------
constexpr float ENTITY_UPDATE_RADIUS = 150.0f;
constexpr float NPC_INTERACT_MAX_DISTANCE = 15.0f;
// ---------------------------------------------------------------------------
// Skill categories (from SkillLine DBC)
// ---------------------------------------------------------------------------
constexpr uint32_t SKILL_CATEGORY_PROFESSION = 11;
constexpr uint32_t SKILL_CATEGORY_SECONDARY = 9;
// ---------------------------------------------------------------------------
// DBC field-index sentinel (field lookup failure)
// ---------------------------------------------------------------------------
constexpr uint32_t DBC_FIELD_INVALID = 0xFFFFFFFF;
// ---------------------------------------------------------------------------
// Appearance byte packing
// ---------------------------------------------------------------------------
constexpr uint32_t APPEARANCE_SKIN_MASK = 0xFF;
constexpr uint32_t APPEARANCE_FACE_SHIFT = 8;
constexpr uint32_t APPEARANCE_HAIRSTYLE_SHIFT = 16;
constexpr uint32_t APPEARANCE_HAIRCOLOR_SHIFT = 24;
// ---------------------------------------------------------------------------
// Critter detection
// ---------------------------------------------------------------------------
constexpr uint32_t CRITTER_MAX_HEALTH_THRESHOLD = 100;
} // namespace game
} // namespace wowee