feat(editor): add WSPC (Spell Power Cost) — completes spell-bucket five-pack

Open replacement for the per-spell power-cost fields in Spell.dbc
plus SpellPowerCost-related side tables. Defines categorical
power-cost buckets that spells reference (LowMana 5% / MediumMana
15% / HighMana 30% of caster max mana; fixed Rage-30 /
Energy-40 / Runic-30 / etc), so spells share cost metadata across
ranks instead of embedding per-rank cost numbers.

Completes the small lookup-bucket five-pack:
  WSRG — range bucket
  WSCT — cast time bucket
  WSDR — duration bucket
  WSCD — cooldown bucket
  WSPC — power cost bucket   (this catalog)

Five small integer ids per spell (range / cast / dur / cd / cost)
replace the dozens of duplicate per-rank fields that Blizzard's
Spell.dbc carries. Editing one bucket here retunes every spell
that references it — change LowMana from 5% to 4% and every
rank-1 bolt across every caster class becomes cheaper.

Cost can be flat (baseCost), per-level scaled (perLevelCost), or
percentage-of-max-power (percentOfBase) — the engine sums
whichever fields are non-zero. resolveCost(id, level, maxPower)
does the math. Twelve power types covering every WoW resource
(Mana / Rage / Focus / Energy / Happiness / Runic Power / Runes /
Soul Shards / Holy Power / Eclipse / Health / NoCost).

Three preset emitters: --gen-spc (4 baseline mana tiers),
--gen-spc-rage (4 fixed warrior rage costs including stance-locked
Whirlwind), --gen-spc-mixed (5 cross-class costs covering every
non-mana power type with refund-on-miss flag for energy).

Validation enforces id+name presence, powerType 0..11, no
duplicate ids; warns on percentOfBase outside [0,1] (would
overflow), NoCost type with non-zero cost fields, and non-NoCost
types with no cost set (would cast for free — easy bug to ship).

Wired through the cross-format table; WSPC appears automatically
in all 11 cross-format utilities. Format count 72 -> 73; CLI flag
count 922 -> 927.
This commit is contained in:
Kelsi 2026-05-09 22:00:55 -07:00
parent 74be3f6135
commit 88effe39cd
10 changed files with 695 additions and 0 deletions

View file

@ -0,0 +1,258 @@
#include "pipeline/wowee_spell_power_costs.hpp"
#include <cstdio>
#include <cstring>
#include <fstream>
namespace wowee {
namespace pipeline {
namespace {
constexpr char kMagic[4] = {'W', 'S', 'P', 'C'};
constexpr uint32_t kVersion = 1;
template <typename T>
void writePOD(std::ofstream& os, const T& v) {
os.write(reinterpret_cast<const char*>(&v), sizeof(T));
}
template <typename T>
bool readPOD(std::ifstream& is, T& v) {
is.read(reinterpret_cast<char*>(&v), sizeof(T));
return is.gcount() == static_cast<std::streamsize>(sizeof(T));
}
void writeStr(std::ofstream& os, const std::string& s) {
uint32_t n = static_cast<uint32_t>(s.size());
writePOD(os, n);
if (n > 0) os.write(s.data(), n);
}
bool readStr(std::ifstream& is, std::string& s) {
uint32_t n = 0;
if (!readPOD(is, n)) return false;
if (n > (1u << 20)) return false;
s.resize(n);
if (n > 0) {
is.read(s.data(), n);
if (is.gcount() != static_cast<std::streamsize>(n)) {
s.clear();
return false;
}
}
return true;
}
std::string normalizePath(std::string base) {
if (base.size() < 5 || base.substr(base.size() - 5) != ".wspc") {
base += ".wspc";
}
return base;
}
uint32_t packRgba(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 0xFF) {
return (static_cast<uint32_t>(a) << 24) |
(static_cast<uint32_t>(b) << 16) |
(static_cast<uint32_t>(g) << 8) |
static_cast<uint32_t>(r);
}
} // namespace
const WoweeSpellPowerCost::Entry*
WoweeSpellPowerCost::findById(uint32_t powerCostId) const {
for (const auto& e : entries)
if (e.powerCostId == powerCostId) return &e;
return nullptr;
}
int32_t WoweeSpellPowerCost::resolveCost(uint32_t powerCostId,
uint32_t casterLevel,
int32_t maxPower) const {
const Entry* e = findById(powerCostId);
if (!e) return 0;
if (e->powerType == NoCost) return 0;
int64_t cost = static_cast<int64_t>(e->baseCost) +
static_cast<int64_t>(e->perLevelCost) *
static_cast<int64_t>(casterLevel);
if (e->percentOfBase != 0.0f) {
cost += static_cast<int64_t>(
static_cast<float>(maxPower) * e->percentOfBase);
}
if (cost < 0) cost = 0;
return static_cast<int32_t>(cost);
}
const char* WoweeSpellPowerCost::powerTypeName(uint8_t k) {
switch (k) {
case Mana: return "mana";
case Rage: return "rage";
case Focus: return "focus";
case Energy: return "energy";
case Happiness: return "happiness";
case RunicPower: return "runic-power";
case Runes: return "runes";
case SoulShards: return "soul-shards";
case HolyPower: return "holy-power";
case Eclipse: return "eclipse";
case Health: return "health";
case NoCost: return "no-cost";
default: return "unknown";
}
}
bool WoweeSpellPowerCostLoader::save(const WoweeSpellPowerCost& cat,
const std::string& basePath) {
std::ofstream os(normalizePath(basePath), std::ios::binary);
if (!os) return false;
os.write(kMagic, 4);
writePOD(os, kVersion);
writeStr(os, cat.name);
uint32_t entryCount = static_cast<uint32_t>(cat.entries.size());
writePOD(os, entryCount);
for (const auto& e : cat.entries) {
writePOD(os, e.powerCostId);
writeStr(os, e.name);
writeStr(os, e.description);
writePOD(os, e.powerType);
uint8_t pad3[3] = {0, 0, 0};
os.write(reinterpret_cast<const char*>(pad3), 3);
writePOD(os, e.baseCost);
writePOD(os, e.perLevelCost);
writePOD(os, e.percentOfBase);
writePOD(os, e.costFlags);
writePOD(os, e.iconColorRGBA);
}
return os.good();
}
WoweeSpellPowerCost WoweeSpellPowerCostLoader::load(
const std::string& basePath) {
WoweeSpellPowerCost out;
std::ifstream is(normalizePath(basePath), std::ios::binary);
if (!is) return out;
char magic[4];
is.read(magic, 4);
if (std::memcmp(magic, kMagic, 4) != 0) return out;
uint32_t version = 0;
if (!readPOD(is, version) || version != kVersion) return out;
if (!readStr(is, out.name)) return out;
uint32_t entryCount = 0;
if (!readPOD(is, entryCount)) return out;
if (entryCount > (1u << 20)) return out;
out.entries.resize(entryCount);
for (auto& e : out.entries) {
if (!readPOD(is, e.powerCostId)) {
out.entries.clear(); return out;
}
if (!readStr(is, e.name) || !readStr(is, e.description)) {
out.entries.clear(); return out;
}
if (!readPOD(is, e.powerType)) {
out.entries.clear(); return out;
}
uint8_t pad3[3];
is.read(reinterpret_cast<char*>(pad3), 3);
if (is.gcount() != 3) { out.entries.clear(); return out; }
if (!readPOD(is, e.baseCost) ||
!readPOD(is, e.perLevelCost) ||
!readPOD(is, e.percentOfBase) ||
!readPOD(is, e.costFlags) ||
!readPOD(is, e.iconColorRGBA)) {
out.entries.clear(); return out;
}
}
return out;
}
bool WoweeSpellPowerCostLoader::exists(const std::string& basePath) {
std::ifstream is(normalizePath(basePath), std::ios::binary);
return is.good();
}
WoweeSpellPowerCost WoweeSpellPowerCostLoader::makeStarter(
const std::string& catalogName) {
using P = WoweeSpellPowerCost;
WoweeSpellPowerCost c;
c.name = catalogName;
auto add = [&](uint32_t id, const char* name, uint8_t type,
float pct, int32_t base, const char* desc) {
P::Entry e;
e.powerCostId = id; e.name = name; e.description = desc;
e.powerType = type;
e.baseCost = base;
e.percentOfBase = pct;
e.iconColorRGBA = packRgba(80, 140, 240); // mana blue
c.entries.push_back(e);
};
add(1, "NoCost", P::NoCost, 0.0f, 0,
"Free spell — no resource cost (Auto Attack).");
add(2, "LowMana", P::Mana, 0.05f, 0,
"Low-cost spell — 5% of max mana (Frostbolt).");
add(3, "MediumMana", P::Mana, 0.15f, 0,
"Medium-cost spell — 15% of max mana (Fireball).");
add(4, "HighMana", P::Mana, 0.30f, 0,
"High-cost spell — 30% of max mana (Pyroblast).");
return c;
}
WoweeSpellPowerCost WoweeSpellPowerCostLoader::makeRage(
const std::string& catalogName) {
using P = WoweeSpellPowerCost;
WoweeSpellPowerCost c;
c.name = catalogName;
auto add = [&](uint32_t id, const char* name, int32_t rage,
uint32_t flags, const char* desc) {
P::Entry e;
e.powerCostId = id; e.name = name; e.description = desc;
e.powerType = P::Rage;
e.baseCost = rage;
e.costFlags = flags;
e.iconColorRGBA = packRgba(220, 60, 60); // rage red
c.entries.push_back(e);
};
// Warrior abilities, fixed rage cost (no level scaling).
add(100, "HeroicStrikeRage", 15, 0,
"Heroic Strike — 15 rage on next melee.");
add(101, "SlamRage", 20, 0,
"Slam — 20 rage, channeled.");
add(102, "WhirlwindRage", 25, P::RequiresCombatStance,
"Whirlwind — 25 rage, requires Berserker stance.");
add(103, "MortalStrikeRage", 30, 0,
"Mortal Strike — 30 rage instant strike.");
return c;
}
WoweeSpellPowerCost WoweeSpellPowerCostLoader::makeMixed(
const std::string& catalogName) {
using P = WoweeSpellPowerCost;
WoweeSpellPowerCost c;
c.name = catalogName;
auto add = [&](uint32_t id, const char* name, uint8_t type,
int32_t cost, uint32_t flags, const char* desc) {
P::Entry e;
e.powerCostId = id; e.name = name; e.description = desc;
e.powerType = type;
e.baseCost = cost;
e.costFlags = flags;
e.iconColorRGBA = packRgba(180, 180, 180); // neutral
c.entries.push_back(e);
};
add(200, "HunterFocus30", P::Focus, 30, 0,
"Hunter Focus — 30 focus (Cobra Shot).");
add(201, "RogueEnergy40", P::Energy, 40, P::RefundOnMiss,
"Rogue Energy — 40 energy (Sinister Strike), refunds "
"on miss/dodge/parry.");
add(202, "DKRunic30", P::RunicPower, 30, 0,
"Death Knight Runic Power — 30 RP (Death Coil).");
add(203, "PaladinHoly1", P::HolyPower, 1, 0,
"Paladin Holy Power — 1 HP per finisher (Templar's "
"Verdict, Word of Glory).");
add(204, "WarlockShard1", P::SoulShards, 1, 0,
"Warlock Soul Shard — 1 shard (Soulburn finishers).");
return c;
}
} // namespace pipeline
} // namespace wowee