2010-09-14 12:12:19 +00:00
|
|
|
#include "loadskil.hpp"
|
|
|
|
|
2012-09-23 18:41:41 +00:00
|
|
|
#include "esmreader.hpp"
|
|
|
|
#include "esmwriter.hpp"
|
2012-09-17 07:37:50 +00:00
|
|
|
|
2023-05-20 15:49:32 +00:00
|
|
|
#include <components/misc/strings/algorithm.hpp>
|
|
|
|
|
2011-04-08 13:58:21 +00:00
|
|
|
namespace ESM
|
2010-09-14 12:12:19 +00:00
|
|
|
{
|
2013-08-09 12:14:58 +00: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-01-05 21:18:21 +00:00
|
|
|
};
|
2011-04-08 13:58:21 +00:00
|
|
|
|
2023-05-20 15:49:32 +00:00
|
|
|
Skill::SkillEnum Skill::stringToSkillId(std::string_view skill)
|
|
|
|
{
|
2023-05-27 19:54:13 +00:00
|
|
|
for (int id = 0; id < Skill::Length; ++id)
|
2023-05-21 11:01:11 +00:00
|
|
|
if (Misc::StringUtils::ciEqual(sSkillNames[id], skill))
|
2023-05-27 19:54:13 +00:00
|
|
|
return Skill::SkillEnum(id);
|
2023-05-20 15:49:32 +00:00
|
|
|
|
|
|
|
throw std::logic_error("No such skill: " + std::string(skill));
|
|
|
|
}
|
|
|
|
|
2015-07-20 14:23:14 +00:00
|
|
|
void Skill::load(ESMReader& esm, bool& isDeleted)
|
2015-02-12 03:56:05 +00:00
|
|
|
{
|
2015-07-20 14:23:14 +00:00
|
|
|
isDeleted = false; // Skill record can't be deleted now (may be changed in the future)
|
2021-07-25 09:53:41 +00:00
|
|
|
mRecordFlags = esm.getRecordFlags();
|
2015-07-20 14:23:14 +00:00
|
|
|
|
2015-02-12 03:56:05 +00:00
|
|
|
bool hasIndex = false;
|
|
|
|
bool hasData = false;
|
|
|
|
while (esm.hasMoreSubs())
|
|
|
|
{
|
|
|
|
esm.getSubName();
|
2021-10-17 00:52:22 +00:00
|
|
|
switch (esm.retSubName().toInt())
|
2015-02-12 03:56:05 +00:00
|
|
|
{
|
2022-04-11 22:18:39 +00:00
|
|
|
case fourCC("INDX"):
|
2015-02-12 03:56:05 +00:00
|
|
|
esm.getHT(mIndex);
|
|
|
|
hasIndex = true;
|
|
|
|
break;
|
2022-04-11 22:18:39 +00:00
|
|
|
case fourCC("SKDT"):
|
2022-04-10 11:35:00 +00:00
|
|
|
esm.getHTSized<24>(mData);
|
2015-02-12 03:56:05 +00:00
|
|
|
hasData = true;
|
|
|
|
break;
|
2022-04-11 22:18:39 +00:00
|
|
|
case fourCC("DESC"):
|
2015-02-12 03:56:05 +00: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 13:30:27 +00:00
|
|
|
|
2015-02-12 03:56:05 +00:00
|
|
|
// create an ID from the index and the name (only used in the editor and likely to change in the
|
|
|
|
// future)
|
2023-02-10 23:08:59 +00:00
|
|
|
mId = indexToRefId(mIndex);
|
2015-02-12 03:56:05 +00:00
|
|
|
}
|
2013-03-26 08:43:13 +00:00
|
|
|
|
2015-07-20 14:23:14 +00:00
|
|
|
void Skill::save(ESMWriter& esm, bool /*isDeleted*/) const
|
2015-02-12 03:56:05 +00:00
|
|
|
{
|
|
|
|
esm.writeHNT("INDX", mIndex);
|
|
|
|
esm.writeHNT("SKDT", mData, 24);
|
|
|
|
esm.writeHNOString("DESC", mDescription);
|
|
|
|
}
|
2013-03-21 13:30:27 +00:00
|
|
|
|
|
|
|
void Skill::blank()
|
|
|
|
{
|
2022-05-29 20:12:30 +00:00
|
|
|
mRecordFlags = 0;
|
2013-03-21 13:30:27 +00:00
|
|
|
mData.mAttribute = 0;
|
|
|
|
mData.mSpecialization = 0;
|
|
|
|
mData.mUseValue[0] = mData.mUseValue[1] = mData.mUseValue[2] = mData.mUseValue[3] = 1.0;
|
2013-03-24 14:10:03 +00:00
|
|
|
mDescription.clear();
|
|
|
|
}
|
|
|
|
|
2023-02-10 23:08:59 +00:00
|
|
|
RefId Skill::indexToRefId(int index)
|
2013-03-24 14:10:03 +00:00
|
|
|
{
|
2023-02-10 23:08:59 +00:00
|
|
|
if (index == -1)
|
|
|
|
return RefId();
|
|
|
|
return RefId::index(sRecordId, static_cast<std::uint32_t>(index));
|
2013-03-21 13:30:27 +00:00
|
|
|
}
|
2010-09-14 12:12:19 +00:00
|
|
|
}
|