mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-05-09 03:57:51 +03:00
Use StringRefId for skills
This commit is contained in:
parent
ac9378fa08
commit
967b5d205b
9 changed files with 379 additions and 286 deletions
|
@ -7,44 +7,33 @@
|
|||
|
||||
namespace ESM
|
||||
{
|
||||
const std::string Skill::sSkillNames[Length] = {
|
||||
"Block",
|
||||
"Armorer",
|
||||
"Mediumarmor",
|
||||
"Heavyarmor",
|
||||
"Bluntweapon",
|
||||
"Longblade",
|
||||
"Axe",
|
||||
"Spear",
|
||||
"Athletics",
|
||||
"Enchant",
|
||||
"Destruction",
|
||||
"Alteration",
|
||||
"Illusion",
|
||||
"Conjuration",
|
||||
"Mysticism",
|
||||
"Restoration",
|
||||
"Alchemy",
|
||||
"Unarmored",
|
||||
"Security",
|
||||
"Sneak",
|
||||
"Acrobatics",
|
||||
"Lightarmor",
|
||||
"Shortblade",
|
||||
"Marksman",
|
||||
"Mercantile",
|
||||
"Speechcraft",
|
||||
"Handtohand",
|
||||
};
|
||||
|
||||
int Skill::stringToSkillId(std::string_view skill)
|
||||
{
|
||||
for (int id = 0; id < Skill::Length; ++id)
|
||||
if (Misc::StringUtils::ciEqual(sSkillNames[id], skill))
|
||||
return id;
|
||||
|
||||
throw std::logic_error("No such skill: " + std::string(skill));
|
||||
}
|
||||
const RefId Skill::Block = RefId::stringRefId("Block");
|
||||
const RefId Skill::Armorer = RefId::stringRefId("Armorer");
|
||||
const RefId Skill::MediumArmor = RefId::stringRefId("MediumArmor");
|
||||
const RefId Skill::HeavyArmor = RefId::stringRefId("HeavyArmor");
|
||||
const RefId Skill::BluntWeapon = RefId::stringRefId("BluntWeapon");
|
||||
const RefId Skill::LongBlade = RefId::stringRefId("LongBlade");
|
||||
const RefId Skill::Axe = RefId::stringRefId("Axe");
|
||||
const RefId Skill::Spear = RefId::stringRefId("Spear");
|
||||
const RefId Skill::Athletics = RefId::stringRefId("Athletics");
|
||||
const RefId Skill::Enchant = RefId::stringRefId("Enchant");
|
||||
const RefId Skill::Destruction = RefId::stringRefId("Destruction");
|
||||
const RefId Skill::Alteration = RefId::stringRefId("Alteration");
|
||||
const RefId Skill::Illusion = RefId::stringRefId("Illusion");
|
||||
const RefId Skill::Conjuration = RefId::stringRefId("Conjuration");
|
||||
const RefId Skill::Mysticism = RefId::stringRefId("Mysticism");
|
||||
const RefId Skill::Restoration = RefId::stringRefId("Restoration");
|
||||
const RefId Skill::Alchemy = RefId::stringRefId("Alchemy");
|
||||
const RefId Skill::Unarmored = RefId::stringRefId("Unarmored");
|
||||
const RefId Skill::Security = RefId::stringRefId("Security");
|
||||
const RefId Skill::Sneak = RefId::stringRefId("Sneak");
|
||||
const RefId Skill::Acrobatics = RefId::stringRefId("Acrobatics");
|
||||
const RefId Skill::LightArmor = RefId::stringRefId("LightArmor");
|
||||
const RefId Skill::ShortBlade = RefId::stringRefId("ShortBlade");
|
||||
const RefId Skill::Marksman = RefId::stringRefId("Marksman");
|
||||
const RefId Skill::Mercantile = RefId::stringRefId("Mercantile");
|
||||
const RefId Skill::Speechcraft = RefId::stringRefId("Speechcraft");
|
||||
const RefId Skill::HandToHand = RefId::stringRefId("HandToHand");
|
||||
|
||||
void Skill::load(ESMReader& esm, bool& isDeleted)
|
||||
{
|
||||
|
@ -102,19 +91,49 @@ namespace ESM
|
|||
mDescription.clear();
|
||||
}
|
||||
|
||||
static const RefId sSkills[] = {
|
||||
Skill::Block,
|
||||
Skill::Armorer,
|
||||
Skill::MediumArmor,
|
||||
Skill::HeavyArmor,
|
||||
Skill::BluntWeapon,
|
||||
Skill::LongBlade,
|
||||
Skill::Axe,
|
||||
Skill::Spear,
|
||||
Skill::Athletics,
|
||||
Skill::Enchant,
|
||||
Skill::Destruction,
|
||||
Skill::Alteration,
|
||||
Skill::Illusion,
|
||||
Skill::Conjuration,
|
||||
Skill::Mysticism,
|
||||
Skill::Restoration,
|
||||
Skill::Alchemy,
|
||||
Skill::Unarmored,
|
||||
Skill::Security,
|
||||
Skill::Sneak,
|
||||
Skill::Acrobatics,
|
||||
Skill::LightArmor,
|
||||
Skill::ShortBlade,
|
||||
Skill::Marksman,
|
||||
Skill::Mercantile,
|
||||
Skill::Speechcraft,
|
||||
Skill::HandToHand,
|
||||
};
|
||||
|
||||
RefId Skill::indexToRefId(int index)
|
||||
{
|
||||
if (index < 0 || index >= Length)
|
||||
return RefId();
|
||||
return RefId::index(sRecordId, static_cast<std::uint32_t>(index));
|
||||
return sSkills[index];
|
||||
}
|
||||
|
||||
int Skill::refIdToIndex(RefId id)
|
||||
{
|
||||
if (const IndexRefId* index = id.getIf<IndexRefId>())
|
||||
for (int i = 0; i < Length; ++i)
|
||||
{
|
||||
if (index->getRecordType() == sRecordId)
|
||||
return index->getValue();
|
||||
if (sSkills[i] == id)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -61,37 +61,34 @@ namespace ESM
|
|||
float mWerewolfValue{};
|
||||
std::optional<MagicSchool> mSchool;
|
||||
|
||||
static constexpr IndexRefId Block{ sRecordId, 0 };
|
||||
static constexpr IndexRefId Armorer{ sRecordId, 1 };
|
||||
static constexpr IndexRefId MediumArmor{ sRecordId, 2 };
|
||||
static constexpr IndexRefId HeavyArmor{ sRecordId, 3 };
|
||||
static constexpr IndexRefId BluntWeapon{ sRecordId, 4 };
|
||||
static constexpr IndexRefId LongBlade{ sRecordId, 5 };
|
||||
static constexpr IndexRefId Axe{ sRecordId, 6 };
|
||||
static constexpr IndexRefId Spear{ sRecordId, 7 };
|
||||
static constexpr IndexRefId Athletics{ sRecordId, 8 };
|
||||
static constexpr IndexRefId Enchant{ sRecordId, 9 };
|
||||
static constexpr IndexRefId Destruction{ sRecordId, 10 };
|
||||
static constexpr IndexRefId Alteration{ sRecordId, 11 };
|
||||
static constexpr IndexRefId Illusion{ sRecordId, 12 };
|
||||
static constexpr IndexRefId Conjuration{ sRecordId, 13 };
|
||||
static constexpr IndexRefId Mysticism{ sRecordId, 14 };
|
||||
static constexpr IndexRefId Restoration{ sRecordId, 15 };
|
||||
static constexpr IndexRefId Alchemy{ sRecordId, 16 };
|
||||
static constexpr IndexRefId Unarmored{ sRecordId, 17 };
|
||||
static constexpr IndexRefId Security{ sRecordId, 18 };
|
||||
static constexpr IndexRefId Sneak{ sRecordId, 19 };
|
||||
static constexpr IndexRefId Acrobatics{ sRecordId, 20 };
|
||||
static constexpr IndexRefId LightArmor{ sRecordId, 21 };
|
||||
static constexpr IndexRefId ShortBlade{ sRecordId, 22 };
|
||||
static constexpr IndexRefId Marksman{ sRecordId, 23 };
|
||||
static constexpr IndexRefId Mercantile{ sRecordId, 24 };
|
||||
static constexpr IndexRefId Speechcraft{ sRecordId, 25 };
|
||||
static constexpr IndexRefId HandToHand{ sRecordId, 26 };
|
||||
static const RefId Block;
|
||||
static const RefId Armorer;
|
||||
static const RefId MediumArmor;
|
||||
static const RefId HeavyArmor;
|
||||
static const RefId BluntWeapon;
|
||||
static const RefId LongBlade;
|
||||
static const RefId Axe;
|
||||
static const RefId Spear;
|
||||
static const RefId Athletics;
|
||||
static const RefId Enchant;
|
||||
static const RefId Destruction;
|
||||
static const RefId Alteration;
|
||||
static const RefId Illusion;
|
||||
static const RefId Conjuration;
|
||||
static const RefId Mysticism;
|
||||
static const RefId Restoration;
|
||||
static const RefId Alchemy;
|
||||
static const RefId Unarmored;
|
||||
static const RefId Security;
|
||||
static const RefId Sneak;
|
||||
static const RefId Acrobatics;
|
||||
static const RefId LightArmor;
|
||||
static const RefId ShortBlade;
|
||||
static const RefId Marksman;
|
||||
static const RefId Mercantile;
|
||||
static const RefId Speechcraft;
|
||||
static const RefId HandToHand;
|
||||
static constexpr int Length = 27;
|
||||
static const std::string sSkillNames[Length];
|
||||
|
||||
static int stringToSkillId(std::string_view skill);
|
||||
|
||||
void load(ESMReader& esm, bool& isDeleted);
|
||||
void save(ESMWriter& esm, bool isDeleted = false) const;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue