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
|
|
|
|
2024-02-27 19:47:46 +00:00
|
|
|
#include <components/misc/concepts.hpp>
|
2023-05-20 15:49:32 +00:00
|
|
|
#include <components/misc/strings/algorithm.hpp>
|
|
|
|
|
2023-07-17 17:37:28 +00:00
|
|
|
#include <cstdint>
|
|
|
|
|
2011-04-08 13:58:21 +00:00
|
|
|
namespace ESM
|
2010-09-14 12:12:19 +00:00
|
|
|
{
|
2023-07-14 15:33:32 +00:00
|
|
|
const SkillId Skill::Block("Block");
|
|
|
|
const SkillId Skill::Armorer("Armorer");
|
|
|
|
const SkillId Skill::MediumArmor("MediumArmor");
|
|
|
|
const SkillId Skill::HeavyArmor("HeavyArmor");
|
|
|
|
const SkillId Skill::BluntWeapon("BluntWeapon");
|
|
|
|
const SkillId Skill::LongBlade("LongBlade");
|
|
|
|
const SkillId Skill::Axe("Axe");
|
|
|
|
const SkillId Skill::Spear("Spear");
|
|
|
|
const SkillId Skill::Athletics("Athletics");
|
|
|
|
const SkillId Skill::Enchant("Enchant");
|
|
|
|
const SkillId Skill::Destruction("Destruction");
|
|
|
|
const SkillId Skill::Alteration("Alteration");
|
|
|
|
const SkillId Skill::Illusion("Illusion");
|
|
|
|
const SkillId Skill::Conjuration("Conjuration");
|
|
|
|
const SkillId Skill::Mysticism("Mysticism");
|
|
|
|
const SkillId Skill::Restoration("Restoration");
|
|
|
|
const SkillId Skill::Alchemy("Alchemy");
|
|
|
|
const SkillId Skill::Unarmored("Unarmored");
|
|
|
|
const SkillId Skill::Security("Security");
|
|
|
|
const SkillId Skill::Sneak("Sneak");
|
|
|
|
const SkillId Skill::Acrobatics("Acrobatics");
|
|
|
|
const SkillId Skill::LightArmor("LightArmor");
|
|
|
|
const SkillId Skill::ShortBlade("ShortBlade");
|
|
|
|
const SkillId Skill::Marksman("Marksman");
|
|
|
|
const SkillId Skill::Mercantile("Mercantile");
|
|
|
|
const SkillId Skill::Speechcraft("Speechcraft");
|
|
|
|
const SkillId Skill::HandToHand("HandToHand");
|
2023-05-20 15:49:32 +00:00
|
|
|
|
2024-02-27 19:47:46 +00:00
|
|
|
template <Misc::SameAsWithoutCvref<Skill::SKDTstruct> T>
|
|
|
|
void decompose(T&& v, const auto& f)
|
|
|
|
{
|
|
|
|
f(v.mAttribute, v.mSpecialization, v.mUseValue);
|
|
|
|
}
|
|
|
|
|
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;
|
2023-07-17 17:37:28 +00:00
|
|
|
int32_t index = -1;
|
2015-02-12 03:56:05 +00:00
|
|
|
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"):
|
2023-06-15 18:49:14 +00:00
|
|
|
esm.getHT(index);
|
2015-02-12 03:56:05 +00:00
|
|
|
hasIndex = true;
|
|
|
|
break;
|
2022-04-11 22:18:39 +00:00
|
|
|
case fourCC("SKDT"):
|
2024-02-27 19:47:46 +00:00
|
|
|
esm.getSubComposite(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");
|
2023-06-15 18:49:14 +00:00
|
|
|
else if (index < 0 || index >= Length)
|
2023-06-05 10:41:01 +00:00
|
|
|
esm.fail("Invalid INDX");
|
2015-02-12 03:56:05 +00:00
|
|
|
if (!hasData)
|
|
|
|
esm.fail("Missing SKDT");
|
2013-03-21 13:30:27 +00:00
|
|
|
|
2023-07-14 15:33:32 +00:00
|
|
|
mId = *indexToRefId(index).getIf<SkillId>();
|
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
|
|
|
{
|
2023-06-15 18:49:14 +00:00
|
|
|
esm.writeHNT("INDX", refIdToIndex(mId));
|
2024-02-27 19:47:46 +00:00
|
|
|
esm.writeNamedComposite("SKDT", mData);
|
2015-02-12 03:56:05 +00:00
|
|
|
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-07-17 17:37:28 +00:00
|
|
|
static const RefId sSkills[Skill::Length] = {
|
2023-06-15 19:38:46 +00:00
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
2023-02-10 23:08:59 +00:00
|
|
|
RefId Skill::indexToRefId(int index)
|
2013-03-24 14:10:03 +00:00
|
|
|
{
|
2023-06-05 10:41:01 +00:00
|
|
|
if (index < 0 || index >= Length)
|
2023-02-10 23:08:59 +00:00
|
|
|
return RefId();
|
2023-06-15 19:38:46 +00:00
|
|
|
return sSkills[index];
|
2013-03-21 13:30:27 +00:00
|
|
|
}
|
2023-06-26 18:42:52 +00:00
|
|
|
|
2023-06-15 18:49:14 +00:00
|
|
|
int Skill::refIdToIndex(RefId id)
|
|
|
|
{
|
2023-06-15 19:38:46 +00:00
|
|
|
for (int i = 0; i < Length; ++i)
|
2023-06-15 18:49:14 +00:00
|
|
|
{
|
2023-06-15 19:38:46 +00:00
|
|
|
if (sSkills[i] == id)
|
|
|
|
return i;
|
2023-06-15 18:49:14 +00:00
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2023-06-26 18:42:52 +00:00
|
|
|
const std::array<RefId, MagicSchool::Length> sMagicSchools = {
|
|
|
|
Skill::Alteration,
|
|
|
|
Skill::Conjuration,
|
|
|
|
Skill::Destruction,
|
|
|
|
Skill::Illusion,
|
|
|
|
Skill::Mysticism,
|
|
|
|
Skill::Restoration,
|
|
|
|
};
|
|
|
|
|
|
|
|
RefId MagicSchool::indexToSkillRefId(int index)
|
|
|
|
{
|
|
|
|
if (index < 0 || index >= Length)
|
|
|
|
return {};
|
|
|
|
return sMagicSchools[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
int MagicSchool::skillRefIdToIndex(RefId id)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < sMagicSchools.size(); ++i)
|
|
|
|
{
|
|
|
|
if (id == sMagicSchools[i])
|
|
|
|
return static_cast<int>(i);
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
2010-09-14 12:12:19 +00:00
|
|
|
}
|