2010-09-14 14:12:19 +02:00
|
|
|
#include "loadskil.hpp"
|
|
|
|
|
2012-09-23 22:41:41 +04:00
|
|
|
#include "esmreader.hpp"
|
|
|
|
#include "esmwriter.hpp"
|
2012-09-17 11:37:50 +04:00
|
|
|
|
2023-05-20 17:49:32 +02:00
|
|
|
#include <components/misc/strings/algorithm.hpp>
|
|
|
|
|
2011-04-08 17:58:21 +04:00
|
|
|
namespace ESM
|
2010-09-14 14:12:19 +02:00
|
|
|
{
|
2013-08-09 05:14:58 -07:00
|
|
|
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",
|
|
|
|
};
|
2011-04-08 17:58:21 +04:00
|
|
|
const std::string Skill::sSkillNameIds[Length] = {
|
|
|
|
"sSkillBlock",
|
|
|
|
"sSkillArmorer",
|
|
|
|
"sSkillMediumarmor",
|
|
|
|
"sSkillHeavyarmor",
|
|
|
|
"sSkillBluntweapon",
|
|
|
|
"sSkillLongblade",
|
|
|
|
"sSkillAxe",
|
|
|
|
"sSkillSpear",
|
|
|
|
"sSkillAthletics",
|
|
|
|
"sSkillEnchant",
|
|
|
|
"sSkillDestruction",
|
|
|
|
"sSkillAlteration",
|
|
|
|
"sSkillIllusion",
|
|
|
|
"sSkillConjuration",
|
|
|
|
"sSkillMysticism",
|
|
|
|
"sSkillRestoration",
|
|
|
|
"sSkillAlchemy",
|
|
|
|
"sSkillUnarmored",
|
|
|
|
"sSkillSecurity",
|
|
|
|
"sSkillSneak",
|
|
|
|
"sSkillAcrobatics",
|
|
|
|
"sSkillLightarmor",
|
|
|
|
"sSkillShortblade",
|
|
|
|
"sSkillMarksman",
|
|
|
|
"sSkillMercantile",
|
|
|
|
"sSkillSpeechcraft",
|
|
|
|
"sSkillHandtohand",
|
2011-01-05 22:18:21 +01:00
|
|
|
};
|
2012-05-21 01:58:11 +02:00
|
|
|
const std::string Skill::sIconNames[Length] = {
|
|
|
|
"combat_block.dds",
|
|
|
|
"combat_armor.dds",
|
|
|
|
"combat_mediumarmor.dds",
|
|
|
|
"combat_heavyarmor.dds",
|
|
|
|
"combat_blunt.dds",
|
|
|
|
"combat_longblade.dds",
|
|
|
|
"combat_axe.dds",
|
|
|
|
"combat_spear.dds",
|
|
|
|
"combat_athletics.dds",
|
|
|
|
"magic_enchant.dds",
|
|
|
|
"magic_destruction.dds",
|
|
|
|
"magic_alteration.dds",
|
|
|
|
"magic_illusion.dds",
|
|
|
|
"magic_conjuration.dds",
|
|
|
|
"magic_mysticism.dds",
|
|
|
|
"magic_restoration.dds",
|
|
|
|
"magic_alchemy.dds",
|
|
|
|
"magic_unarmored.dds",
|
|
|
|
"stealth_security.dds",
|
|
|
|
"stealth_sneak.dds",
|
|
|
|
"stealth_acrobatics.dds",
|
|
|
|
"stealth_lightarmor.dds",
|
|
|
|
"stealth_shortblade.dds",
|
|
|
|
"stealth_marksman.dds",
|
|
|
|
"stealth_mercantile.dds",
|
|
|
|
"stealth_speechcraft.dds",
|
|
|
|
"stealth_handtohand.dds",
|
|
|
|
};
|
2011-04-08 17:58:21 +04:00
|
|
|
|
2023-05-20 17:49:32 +02:00
|
|
|
Skill::SkillEnum Skill::stringToSkillId(std::string_view skill)
|
|
|
|
{
|
2023-05-27 21:54:13 +02:00
|
|
|
for (int id = 0; id < Skill::Length; ++id)
|
2023-05-21 13:01:11 +02:00
|
|
|
if (Misc::StringUtils::ciEqual(sSkillNames[id], skill))
|
2023-05-27 21:54:13 +02:00
|
|
|
return Skill::SkillEnum(id);
|
2023-05-20 17:49:32 +02:00
|
|
|
|
|
|
|
throw std::logic_error("No such skill: " + std::string(skill));
|
|
|
|
}
|
|
|
|
|
2015-07-20 17:23:14 +03:00
|
|
|
void Skill::load(ESMReader& esm, bool& isDeleted)
|
2015-02-12 04:56:05 +01:00
|
|
|
{
|
2015-07-20 17:23:14 +03:00
|
|
|
isDeleted = false; // Skill record can't be deleted now (may be changed in the future)
|
2021-07-25 19:53:41 +10:00
|
|
|
mRecordFlags = esm.getRecordFlags();
|
2015-07-20 17:23:14 +03:00
|
|
|
|
2015-02-12 04:56:05 +01:00
|
|
|
bool hasIndex = false;
|
|
|
|
bool hasData = false;
|
|
|
|
while (esm.hasMoreSubs())
|
|
|
|
{
|
|
|
|
esm.getSubName();
|
2021-10-17 02:52:22 +02:00
|
|
|
switch (esm.retSubName().toInt())
|
2015-02-12 04:56:05 +01:00
|
|
|
{
|
2022-04-12 00:18:39 +02:00
|
|
|
case fourCC("INDX"):
|
2015-02-12 04:56:05 +01:00
|
|
|
esm.getHT(mIndex);
|
|
|
|
hasIndex = true;
|
|
|
|
break;
|
2022-04-12 00:18:39 +02:00
|
|
|
case fourCC("SKDT"):
|
2022-04-10 13:35:00 +02:00
|
|
|
esm.getHTSized<24>(mData);
|
2015-02-12 04:56:05 +01:00
|
|
|
hasData = true;
|
|
|
|
break;
|
2022-04-12 00:18:39 +02:00
|
|
|
case fourCC("DESC"):
|
2015-02-12 04:56:05 +01:00
|
|
|
mDescription = esm.getHString();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
esm.fail("Unknown subrecord");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!hasIndex)
|
|
|
|
esm.fail("Missing INDX");
|
|
|
|
if (!hasData)
|
|
|
|
esm.fail("Missing SKDT");
|
2013-03-21 14:30:27 +01:00
|
|
|
|
2015-02-12 04:56:05 +01:00
|
|
|
// create an ID from the index and the name (only used in the editor and likely to change in the
|
|
|
|
// future)
|
2023-02-11 00:08:59 +01:00
|
|
|
mId = indexToRefId(mIndex);
|
2015-02-12 04:56:05 +01:00
|
|
|
}
|
2013-03-26 09:43:13 +01:00
|
|
|
|
2015-07-20 17:23:14 +03:00
|
|
|
void Skill::save(ESMWriter& esm, bool /*isDeleted*/) const
|
2015-02-12 04:56:05 +01:00
|
|
|
{
|
|
|
|
esm.writeHNT("INDX", mIndex);
|
|
|
|
esm.writeHNT("SKDT", mData, 24);
|
|
|
|
esm.writeHNOString("DESC", mDescription);
|
|
|
|
}
|
2013-03-21 14:30:27 +01:00
|
|
|
|
|
|
|
void Skill::blank()
|
|
|
|
{
|
2022-05-29 22:12:30 +02:00
|
|
|
mRecordFlags = 0;
|
2013-03-21 14:30:27 +01:00
|
|
|
mData.mAttribute = 0;
|
|
|
|
mData.mSpecialization = 0;
|
|
|
|
mData.mUseValue[0] = mData.mUseValue[1] = mData.mUseValue[2] = mData.mUseValue[3] = 1.0;
|
2013-03-24 15:10:03 +01:00
|
|
|
mDescription.clear();
|
|
|
|
}
|
|
|
|
|
2023-02-11 00:08:59 +01:00
|
|
|
RefId Skill::indexToRefId(int index)
|
2013-03-24 15:10:03 +01:00
|
|
|
{
|
2023-02-11 00:08:59 +01:00
|
|
|
if (index == -1)
|
|
|
|
return RefId();
|
|
|
|
return RefId::index(sRecordId, static_cast<std::uint32_t>(index));
|
2013-03-21 14:30:27 +01:00
|
|
|
}
|
2010-09-14 14:12:19 +02:00
|
|
|
}
|