1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-04-16 10:36:44 +00:00

Revert use of string_view to std::string for effectIdTo* methods.

This commit is contained in:
Mads Buvik Sandvei 2023-05-22 19:37:00 +02:00
parent 6cfc06d7d8
commit 4bf23f152b
7 changed files with 340 additions and 321 deletions

View file

@ -196,8 +196,7 @@ namespace MWGui
mEffectImage->setImageTexture(Misc::ResourceHelpers::correctIconPath( mEffectImage->setImageTexture(Misc::ResourceHelpers::correctIconPath(
effect->mIcon, MWBase::Environment::get().getResourceSystem()->getVFS())); effect->mIcon, MWBase::Environment::get().getResourceSystem()->getVFS()));
mEffectName->setCaptionWithReplacing( mEffectName->setCaptionWithReplacing("#{" + ESM::MagicEffect::effectIdToGmstString(effect->mIndex) + "}");
"#{" + std::string(ESM::MagicEffect::effectIdToGmstString(effect->mIndex)) + "}");
mEffect.mEffectID = effect->mIndex; mEffect.mEffectID = effect->mIndex;

View file

@ -162,10 +162,10 @@ namespace MWGui
image->setImageTexture(Misc::ResourceHelpers::correctIconPath( image->setImageTexture(Misc::ResourceHelpers::correctIconPath(
effect->mIcon, MWBase::Environment::get().getResourceSystem()->getVFS())); effect->mIcon, MWBase::Environment::get().getResourceSystem()->getVFS()));
std::string_view name = ESM::MagicEffect::effectIdToGmstString(effectId); const std::string& name = ESM::MagicEffect::effectIdToGmstString(effectId);
ToolTipInfo tooltipInfo; ToolTipInfo tooltipInfo;
tooltipInfo.caption = "#{" + std::string(name) + "}"; tooltipInfo.caption = "#{" + name + "}";
tooltipInfo.icon = effect->mIcon; tooltipInfo.icon = effect->mIcon;
tooltipInfo.imageSize = 16; tooltipInfo.imageSize = 16;
tooltipInfo.wordWrap = false; tooltipInfo.wordWrap = false;

View file

@ -954,7 +954,7 @@ namespace MWGui
void ToolTips::createMagicEffectToolTip(MyGUI::Widget* widget, short id) void ToolTips::createMagicEffectToolTip(MyGUI::Widget* widget, short id)
{ {
const ESM::MagicEffect* effect = MWBase::Environment::get().getESMStore()->get<ESM::MagicEffect>().find(id); const ESM::MagicEffect* effect = MWBase::Environment::get().getESMStore()->get<ESM::MagicEffect>().find(id);
std::string_view name = ESM::MagicEffect::effectIdToGmstString(id); const std::string& name = ESM::MagicEffect::effectIdToGmstString(id);
std::string icon = effect->mIcon; std::string icon = effect->mIcon;
int slashPos = icon.rfind('\\'); int slashPos = icon.rfind('\\');
@ -963,7 +963,7 @@ namespace MWGui
widget->setUserString("ToolTipType", "Layout"); widget->setUserString("ToolTipType", "Layout");
widget->setUserString("ToolTipLayout", "MagicEffectToolTip"); widget->setUserString("ToolTipLayout", "MagicEffectToolTip");
widget->setUserString("Caption_MagicEffectName", "#{" + std::string(name) + "}"); widget->setUserString("Caption_MagicEffectName", "#{" + name + "}");
widget->setUserString("Caption_MagicEffectDescription", effect->mDescription); widget->setUserString("Caption_MagicEffectDescription", effect->mDescription);
widget->setUserString("Caption_MagicEffectSchool", "#{sSchool}: " + sSchoolNames[effect->mData.mSchool]); widget->setUserString("Caption_MagicEffectSchool", "#{sSchool}: " + sSchoolNames[effect->mData.mSchool]);
widget->setUserString("ImageTexture_MagicEffectImage", icon); widget->setUserString("ImageTexture_MagicEffectImage", icon);

View file

@ -191,9 +191,9 @@ namespace MWLua
sol::table effect(context.mLua->sol(), sol::create); sol::table effect(context.mLua->sol(), sol::create);
magicApi["EFFECT_TYPE"] = LuaUtil::makeStrictReadOnly(effect); magicApi["EFFECT_TYPE"] = LuaUtil::makeStrictReadOnly(effect);
for (const auto& it : ESM::MagicEffect::sEffectNames) for (const auto& name : ESM::MagicEffect::sEffectNames)
{ {
effect[it.second] = Misc::StringUtils::lowerCase(it.second); effect[name] = Misc::StringUtils::lowerCase(name);
} }
// Spell store // Spell store
@ -263,7 +263,7 @@ namespace MWLua
auto effectParamsT = lua.new_usertype<ESM::ENAMstruct>("ESM3_EffectParams"); auto effectParamsT = lua.new_usertype<ESM::ENAMstruct>("ESM3_EffectParams");
effectParamsT[sol::meta_function::to_string] = [magicEffectStore](const ESM::ENAMstruct& params) { effectParamsT[sol::meta_function::to_string] = [magicEffectStore](const ESM::ENAMstruct& params) {
const ESM::MagicEffect* const rec = magicEffectStore->find(params.mEffectID); const ESM::MagicEffect* const rec = magicEffectStore->find(params.mEffectID);
return "ESM3_EffectParams[" + std::string(ESM::MagicEffect::effectIdToGmstString(rec->mIndex)) + "]"; return "ESM3_EffectParams[" + ESM::MagicEffect::effectIdToGmstString(rec->mIndex) + "]";
}; };
effectParamsT["effect"] effectParamsT["effect"]
= sol::readonly_property([magicEffectStore](const ESM::ENAMstruct& params) -> const ESM::MagicEffect* { = sol::readonly_property([magicEffectStore](const ESM::ENAMstruct& params) -> const ESM::MagicEffect* {
@ -296,7 +296,7 @@ namespace MWLua
auto magicEffectT = context.mLua->sol().new_usertype<ESM::MagicEffect>("ESM3_MagicEffect"); auto magicEffectT = context.mLua->sol().new_usertype<ESM::MagicEffect>("ESM3_MagicEffect");
magicEffectT[sol::meta_function::to_string] = [](const ESM::MagicEffect& rec) { magicEffectT[sol::meta_function::to_string] = [](const ESM::MagicEffect& rec) {
return "ESM3_MagicEffect[" + std::string(ESM::MagicEffect::effectIdToGmstString(rec.mIndex)) + "]"; return "ESM3_MagicEffect[" + ESM::MagicEffect::effectIdToGmstString(rec.mIndex) + "]";
}; };
magicEffectT["id"] = sol::readonly_property([](const ESM::MagicEffect& rec) -> std::string { magicEffectT["id"] = sol::readonly_property([](const ESM::MagicEffect& rec) -> std::string {
auto name = ESM::MagicEffect::effectIdToName(rec.mIndex); auto name = ESM::MagicEffect::effectIdToName(rec.mIndex);
@ -327,7 +327,7 @@ namespace MWLua
auto activeEffectT = context.mLua->sol().new_usertype<ActiveEffect>("ActiveEffect"); auto activeEffectT = context.mLua->sol().new_usertype<ActiveEffect>("ActiveEffect");
activeEffectT[sol::meta_function::to_string] = [](const ActiveEffect& effect) { activeEffectT[sol::meta_function::to_string] = [](const ActiveEffect& effect) {
return "ActiveEffect[" + std::string(ESM::MagicEffect::effectIdToGmstString(effect.key.mId)) + "]"; return "ActiveEffect[" + ESM::MagicEffect::effectIdToGmstString(effect.key.mId) + "]";
}; };
activeEffectT["id"] = sol::readonly_property([](const ActiveEffect& effect) -> std::string { activeEffectT["id"] = sol::readonly_property([](const ActiveEffect& effect) -> std::string {
auto name = ESM::MagicEffect::effectIdToName(effect.key.mId); auto name = ESM::MagicEffect::effectIdToName(effect.key.mId);

View file

@ -268,7 +268,7 @@ namespace MWMechanics
if (spellLine.empty()) if (spellLine.empty())
{ {
std::string_view effectIDStr = ESM::MagicEffect::effectIdToGmstString(effect.mIndex); auto& effectIDStr = ESM::MagicEffect::effectIdToGmstString(effect.mIndex);
spellLine = windowManager->getGameSettingString(effectIDStr, {}); spellLine = windowManager->getGameSettingString(effectIDStr, {});
} }

View file

@ -352,307 +352,324 @@ namespace ESM
} }
// Map effect ID to GMST name // Map effect ID to GMST name
const std::map<int, std::string> MagicEffect::sGmstEffectIds = { const std::array<std::string, MagicEffect::Length> MagicEffect::sGmstEffectIds = {
{ MagicEffect::AbsorbAttribute, "sEffectAbsorbAttribute" },
{ MagicEffect::AbsorbFatigue, "sEffectAbsorbFatigue" },
{ MagicEffect::AbsorbHealth, "sEffectAbsorbHealth" },
{ MagicEffect::AbsorbMagicka, "sEffectAbsorbSpellPoints" },
{ MagicEffect::AbsorbSkill, "sEffectAbsorbSkill" },
{ MagicEffect::AlmsiviIntervention, "sEffectAlmsiviIntervention" },
{ MagicEffect::Blind, "sEffectBlind" },
{ MagicEffect::BoundBattleAxe, "sEffectBoundBattleAxe" },
{ MagicEffect::BoundBoots, "sEffectBoundBoots" },
{ MagicEffect::BoundCuirass, "sEffectBoundCuirass" },
{ MagicEffect::BoundDagger, "sEffectBoundDagger" },
{ MagicEffect::BoundGloves, "sEffectBoundGloves" },
{ MagicEffect::BoundHelm, "sEffectBoundHelm" },
{ MagicEffect::BoundLongbow, "sEffectBoundLongbow" },
{ MagicEffect::ExtraSpell, "sEffectExtraSpell" },
{ MagicEffect::BoundLongsword, "sEffectBoundLongsword" },
{ MagicEffect::BoundMace, "sEffectBoundMace" },
{ MagicEffect::BoundShield, "sEffectBoundShield" },
{ MagicEffect::BoundSpear, "sEffectBoundSpear" },
{ MagicEffect::Burden, "sEffectBurden" },
{ MagicEffect::CalmCreature, "sEffectCalmCreature" },
{ MagicEffect::CalmHumanoid, "sEffectCalmHumanoid" },
{ MagicEffect::Chameleon, "sEffectChameleon" },
{ MagicEffect::Charm, "sEffectCharm" },
{ MagicEffect::CommandCreature, "sEffectCommandCreatures" },
{ MagicEffect::CommandHumanoid, "sEffectCommandHumanoids" },
{ MagicEffect::Corprus, "sEffectCorpus" }, // NB this typo. (bethesda made it)
{ MagicEffect::CureBlightDisease, "sEffectCureBlightDisease" },
{ MagicEffect::CureCommonDisease, "sEffectCureCommonDisease" },
{ MagicEffect::CureCorprusDisease, "sEffectCureCorprusDisease" },
{ MagicEffect::CureParalyzation, "sEffectCureParalyzation" },
{ MagicEffect::CurePoison, "sEffectCurePoison" },
{ MagicEffect::DamageAttribute, "sEffectDamageAttribute" },
{ MagicEffect::DamageFatigue, "sEffectDamageFatigue" },
{ MagicEffect::DamageHealth, "sEffectDamageHealth" },
{ MagicEffect::DamageMagicka, "sEffectDamageMagicka" },
{ MagicEffect::DamageSkill, "sEffectDamageSkill" },
{ MagicEffect::DemoralizeCreature, "sEffectDemoralizeCreature" },
{ MagicEffect::DemoralizeHumanoid, "sEffectDemoralizeHumanoid" },
{ MagicEffect::DetectAnimal, "sEffectDetectAnimal" },
{ MagicEffect::DetectEnchantment, "sEffectDetectEnchantment" },
{ MagicEffect::DetectKey, "sEffectDetectKey" },
{ MagicEffect::DisintegrateArmor, "sEffectDisintegrateArmor" },
{ MagicEffect::DisintegrateWeapon, "sEffectDisintegrateWeapon" },
{ MagicEffect::Dispel, "sEffectDispel" },
{ MagicEffect::DivineIntervention, "sEffectDivineIntervention" },
{ MagicEffect::DrainAttribute, "sEffectDrainAttribute" },
{ MagicEffect::DrainFatigue, "sEffectDrainFatigue" },
{ MagicEffect::DrainHealth, "sEffectDrainHealth" },
{ MagicEffect::DrainMagicka, "sEffectDrainSpellpoints" },
{ MagicEffect::DrainSkill, "sEffectDrainSkill" },
{ MagicEffect::Feather, "sEffectFeather" },
{ MagicEffect::FireDamage, "sEffectFireDamage" },
{ MagicEffect::FireShield, "sEffectFireShield" },
{ MagicEffect::FortifyAttack, "sEffectFortifyAttackBonus" },
{ MagicEffect::FortifyAttribute, "sEffectFortifyAttribute" },
{ MagicEffect::FortifyFatigue, "sEffectFortifyFatigue" },
{ MagicEffect::FortifyHealth, "sEffectFortifyHealth" },
{ MagicEffect::FortifyMagicka, "sEffectFortifySpellpoints" },
{ MagicEffect::FortifyMaximumMagicka, "sEffectFortifyMagickaMultiplier" },
{ MagicEffect::FortifySkill, "sEffectFortifySkill" },
{ MagicEffect::FrenzyCreature, "sEffectFrenzyCreature" },
{ MagicEffect::FrenzyHumanoid, "sEffectFrenzyHumanoid" },
{ MagicEffect::FrostDamage, "sEffectFrostDamage" },
{ MagicEffect::FrostShield, "sEffectFrostShield" },
{ MagicEffect::Invisibility, "sEffectInvisibility" },
{ MagicEffect::Jump, "sEffectJump" },
{ MagicEffect::Levitate, "sEffectLevitate" },
{ MagicEffect::Light, "sEffectLight" },
{ MagicEffect::LightningShield, "sEffectLightningShield" },
{ MagicEffect::Lock, "sEffectLock" },
{ MagicEffect::Mark, "sEffectMark" },
{ MagicEffect::NightEye, "sEffectNightEye" },
{ MagicEffect::Open, "sEffectOpen" },
{ MagicEffect::Paralyze, "sEffectParalyze" },
{ MagicEffect::Poison, "sEffectPoison" },
{ MagicEffect::RallyCreature, "sEffectRallyCreature" },
{ MagicEffect::RallyHumanoid, "sEffectRallyHumanoid" },
{ MagicEffect::Recall, "sEffectRecall" },
{ MagicEffect::Reflect, "sEffectReflect" },
{ MagicEffect::RemoveCurse, "sEffectRemoveCurse" },
{ MagicEffect::ResistBlightDisease, "sEffectResistBlightDisease" },
{ MagicEffect::ResistCommonDisease, "sEffectResistCommonDisease" },
{ MagicEffect::ResistCorprusDisease, "sEffectResistCorprusDisease" },
{ MagicEffect::ResistFire, "sEffectResistFire" },
{ MagicEffect::ResistFrost, "sEffectResistFrost" },
{ MagicEffect::ResistMagicka, "sEffectResistMagicka" },
{ MagicEffect::ResistNormalWeapons, "sEffectResistNormalWeapons" },
{ MagicEffect::ResistParalysis, "sEffectResistParalysis" },
{ MagicEffect::ResistPoison, "sEffectResistPoison" },
{ MagicEffect::ResistShock, "sEffectResistShock" },
{ MagicEffect::RestoreAttribute, "sEffectRestoreAttribute" },
{ MagicEffect::RestoreFatigue, "sEffectRestoreFatigue" },
{ MagicEffect::RestoreHealth, "sEffectRestoreHealth" },
{ MagicEffect::RestoreMagicka, "sEffectRestoreSpellPoints" },
{ MagicEffect::RestoreSkill, "sEffectRestoreSkill" },
{ MagicEffect::Sanctuary, "sEffectSanctuary" },
{ MagicEffect::Shield, "sEffectShield" },
{ MagicEffect::ShockDamage, "sEffectShockDamage" },
{ MagicEffect::Silence, "sEffectSilence" },
{ MagicEffect::SlowFall, "sEffectSlowFall" },
{ MagicEffect::Soultrap, "sEffectSoultrap" },
{ MagicEffect::Sound, "sEffectSound" },
{ MagicEffect::SpellAbsorption, "sEffectSpellAbsorption" },
{ MagicEffect::StuntedMagicka, "sEffectStuntedMagicka" },
{ MagicEffect::SummonAncestralGhost, "sEffectSummonAncestralGhost" },
{ MagicEffect::SummonBonelord, "sEffectSummonBonelord" },
{ MagicEffect::SummonBonewalker, "sEffectSummonLeastBonewalker" },
{ MagicEffect::SummonCenturionSphere, "sEffectSummonCenturionSphere" },
{ MagicEffect::SummonClannfear, "sEffectSummonClannfear" },
{ MagicEffect::SummonDaedroth, "sEffectSummonDaedroth" },
{ MagicEffect::SummonDremora, "sEffectSummonDremora" },
{ MagicEffect::SummonFlameAtronach, "sEffectSummonFlameAtronach" },
{ MagicEffect::SummonFrostAtronach, "sEffectSummonFrostAtronach" },
{ MagicEffect::SummonGoldenSaint, "sEffectSummonGoldenSaint" },
{ MagicEffect::SummonGreaterBonewalker, "sEffectSummonGreaterBonewalker" },
{ MagicEffect::SummonHunger, "sEffectSummonHunger" },
{ MagicEffect::SummonScamp, "sEffectSummonScamp" },
{ MagicEffect::SummonSkeletalMinion, "sEffectSummonSkeletalMinion" },
{ MagicEffect::SummonStormAtronach, "sEffectSummonStormAtronach" },
{ MagicEffect::SummonWingedTwilight, "sEffectSummonWingedTwilight" },
{ MagicEffect::SunDamage, "sEffectSunDamage" },
{ MagicEffect::SwiftSwim, "sEffectSwiftSwim" },
{ MagicEffect::Telekinesis, "sEffectTelekinesis" },
{ MagicEffect::TurnUndead, "sEffectTurnUndead" },
{ MagicEffect::Vampirism, "sEffectVampirism" },
{ MagicEffect::WaterBreathing, "sEffectWaterBreathing" },
{ MagicEffect::WaterWalking, "sEffectWaterWalking" },
{ MagicEffect::WeaknessToBlightDisease, "sEffectWeaknesstoBlightDisease" },
{ MagicEffect::WeaknessToCommonDisease, "sEffectWeaknesstoCommonDisease" },
{ MagicEffect::WeaknessToCorprusDisease, "sEffectWeaknesstoCorprusDisease" },
{ MagicEffect::WeaknessToFire, "sEffectWeaknesstoFire" },
{ MagicEffect::WeaknessToFrost, "sEffectWeaknesstoFrost" },
{ MagicEffect::WeaknessToMagicka, "sEffectWeaknesstoMagicka" },
{ MagicEffect::WeaknessToNormalWeapons, "sEffectWeaknesstoNormalWeapons" },
{ MagicEffect::WeaknessToPoison, "sEffectWeaknesstoPoison" },
{ MagicEffect::WeaknessToShock, "sEffectWeaknesstoShock" },
// bloodmoon "sEffectWaterBreathing",
{ MagicEffect::SummonWolf, "sEffectSummonCreature01" }, "sEffectSwiftSwim",
{ MagicEffect::SummonBear, "sEffectSummonCreature02" }, "sEffectWaterWalking",
{ MagicEffect::SummonBonewolf, "sEffectSummonCreature03" }, "sEffectShield",
{ MagicEffect::SummonCreature04, "sEffectSummonCreature04" }, "sEffectFireShield",
{ MagicEffect::SummonCreature05, "sEffectSummonCreature05" }, "sEffectLightningShield",
"sEffectFrostShield",
"sEffectBurden",
"sEffectFeather",
"sEffectJump",
"sEffectLevitate",
"sEffectSlowFall",
"sEffectLock",
"sEffectOpen",
"sEffectFireDamage",
"sEffectShockDamage",
"sEffectFrostDamage",
"sEffectDrainAttribute",
"sEffectDrainHealth",
"sEffectDrainSpellpoints",
"sEffectDrainFatigue",
"sEffectDrainSkill",
"sEffectDamageAttribute",
"sEffectDamageHealth",
"sEffectDamageMagicka",
"sEffectDamageFatigue",
"sEffectDamageSkill",
"sEffectPoison",
"sEffectWeaknesstoFire",
"sEffectWeaknesstoFrost",
"sEffectWeaknesstoShock",
"sEffectWeaknesstoMagicka",
"sEffectWeaknesstoCommonDisease",
"sEffectWeaknesstoBlightDisease",
"sEffectWeaknesstoCorprusDisease",
"sEffectWeaknesstoPoison",
"sEffectWeaknesstoNormalWeapons",
"sEffectDisintegrateWeapon",
"sEffectDisintegrateArmor",
"sEffectInvisibility",
"sEffectChameleon",
"sEffectLight",
"sEffectSanctuary",
"sEffectNightEye",
"sEffectCharm",
"sEffectParalyze",
"sEffectSilence",
"sEffectBlind",
"sEffectSound",
"sEffectCalmHumanoid",
"sEffectCalmCreature",
"sEffectFrenzyHumanoid",
"sEffectFrenzyCreature",
"sEffectDemoralizeHumanoid",
"sEffectDemoralizeCreature",
"sEffectRallyHumanoid",
"sEffectRallyCreature",
"sEffectDispel",
"sEffectSoultrap",
"sEffectTelekinesis",
"sEffectMark",
"sEffectRecall",
"sEffectDivineIntervention",
"sEffectAlmsiviIntervention",
"sEffectDetectAnimal",
"sEffectDetectEnchantment",
"sEffectDetectKey",
"sEffectSpellAbsorption",
"sEffectReflect",
"sEffectCureCommonDisease",
"sEffectCureBlightDisease",
"sEffectCureCorprusDisease",
"sEffectCurePoison",
"sEffectCureParalyzation",
"sEffectRestoreAttribute",
"sEffectRestoreHealth",
"sEffectRestoreSpellPoints",
"sEffectRestoreFatigue",
"sEffectRestoreSkill",
"sEffectFortifyAttribute",
"sEffectFortifyHealth",
"sEffectFortifySpellpoints",
"sEffectFortifyFatigue",
"sEffectFortifySkill",
"sEffectFortifyMagickaMultiplier",
"sEffectAbsorbAttribute",
"sEffectAbsorbHealth",
"sEffectAbsorbSpellPoints",
"sEffectAbsorbFatigue",
"sEffectAbsorbSkill",
"sEffectResistFire",
"sEffectResistFrost",
"sEffectResistShock",
"sEffectResistMagicka",
"sEffectResistCommonDisease",
"sEffectResistBlightDisease",
"sEffectResistCorprusDisease",
"sEffectResistPoison",
"sEffectResistNormalWeapons",
"sEffectResistParalysis",
"sEffectRemoveCurse",
"sEffectTurnUndead",
"sEffectSummonScamp",
"sEffectSummonClannfear",
"sEffectSummonDaedroth",
"sEffectSummonDremora",
"sEffectSummonAncestralGhost",
"sEffectSummonSkeletalMinion",
"sEffectSummonLeastBonewalker",
"sEffectSummonGreaterBonewalker",
"sEffectSummonBonelord",
"sEffectSummonWingedTwilight",
"sEffectSummonHunger",
"sEffectSummonGoldenSaint",
"sEffectSummonFlameAtronach",
"sEffectSummonFrostAtronach",
"sEffectSummonStormAtronach",
"sEffectFortifyAttackBonus",
"sEffectCommandCreatures",
"sEffectCommandHumanoids",
"sEffectBoundDagger",
"sEffectBoundLongsword",
"sEffectBoundMace",
"sEffectBoundBattleAxe",
"sEffectBoundSpear",
"sEffectBoundLongbow",
"sEffectExtraSpell",
"sEffectBoundCuirass",
"sEffectBoundHelm",
"sEffectBoundBoots",
"sEffectBoundShield",
"sEffectBoundGloves",
"sEffectCorpus", // NB this typo. (bethesda made it)
"sEffectVampirism",
"sEffectSummonCenturionSphere",
"sEffectSunDamage",
"sEffectStuntedMagicka",
// tribunal // tribunal
{ MagicEffect::SummonFabricant, "sEffectSummonFabricant" }, "sEffectSummonFabricant",
// bloodmoon
"sEffectSummonCreature01",
"sEffectSummonCreature02",
"sEffectSummonCreature03",
"sEffectSummonCreature04",
"sEffectSummonCreature05",
}; };
// Map effect ID to identifying name // Map effect ID to identifying name
const std::map<int, std::string> MagicEffect::sEffectNames = { const std::array<std::string, MagicEffect::Length> MagicEffect::sEffectNames = {
{ MagicEffect::AbsorbAttribute, "AbsorbAttribute" }, "WaterBreathing",
{ MagicEffect::AbsorbFatigue, "AbsorbFatigue" }, "SwiftSwim",
{ MagicEffect::AbsorbHealth, "AbsorbHealth" }, "WaterWalking",
{ MagicEffect::AbsorbMagicka, "AbsorbMagicka" }, "Shield",
{ MagicEffect::AbsorbSkill, "AbsorbSkill" }, "FireShield",
{ MagicEffect::AlmsiviIntervention, "AlmsiviIntervention" }, "LightningShield",
{ MagicEffect::Blind, "Blind" }, "FrostShield",
{ MagicEffect::BoundBattleAxe, "BoundBattleAxe" }, "Burden",
{ MagicEffect::BoundBoots, "BoundBoots" }, "Feather",
{ MagicEffect::BoundCuirass, "BoundCuirass" }, "Jump",
{ MagicEffect::BoundDagger, "BoundDagger" }, "Levitate",
{ MagicEffect::BoundGloves, "BoundGloves" }, "SlowFall",
{ MagicEffect::BoundHelm, "BoundHelm" }, "Lock",
{ MagicEffect::BoundLongbow, "BoundLongbow" }, "Open",
{ MagicEffect::ExtraSpell, "ExtraSpell" }, "FireDamage",
{ MagicEffect::BoundLongsword, "BoundLongsword" }, "ShockDamage",
{ MagicEffect::BoundMace, "BoundMace" }, "FrostDamage",
{ MagicEffect::BoundShield, "BoundShield" }, "DrainAttribute",
{ MagicEffect::BoundSpear, "BoundSpear" }, "DrainHealth",
{ MagicEffect::Burden, "Burden" }, "DrainMagicka",
{ MagicEffect::CalmCreature, "CalmCreature" }, "DrainFatigue",
{ MagicEffect::CalmHumanoid, "CalmHumanoid" }, "DrainSkill",
{ MagicEffect::Chameleon, "Chameleon" }, "DamageAttribute",
{ MagicEffect::Charm, "Charm" }, "DamageHealth",
{ MagicEffect::CommandCreature, "CommandCreature" }, "DamageMagicka",
{ MagicEffect::CommandHumanoid, "CommandHumanoid" }, "DamageFatigue",
{ MagicEffect::Corprus, "Corprus" }, "DamageSkill",
{ MagicEffect::CureBlightDisease, "CureBlightDisease" }, "Poison",
{ MagicEffect::CureCommonDisease, "CureCommonDisease" }, "WeaknessToFire",
{ MagicEffect::CureCorprusDisease, "CureCorprusDisease" }, "WeaknessToFrost",
{ MagicEffect::CureParalyzation, "CureParalyzation" }, "WeaknessToShock",
{ MagicEffect::CurePoison, "CurePoison" }, "WeaknessToMagicka",
{ MagicEffect::DamageAttribute, "DamageAttribute" }, "WeaknessToCommonDisease",
{ MagicEffect::DamageFatigue, "DamageFatigue" }, "WeaknessToBlightDisease",
{ MagicEffect::DamageHealth, "DamageHealth" }, "WeaknessToCorprusDisease",
{ MagicEffect::DamageMagicka, "DamageMagicka" }, "WeaknessToPoison",
{ MagicEffect::DamageSkill, "DamageSkill" }, "WeaknessToNormalWeapons",
{ MagicEffect::DemoralizeCreature, "DemoralizeCreature" }, "DisintegrateWeapon",
{ MagicEffect::DemoralizeHumanoid, "DemoralizeHumanoid" }, "DisintegrateArmor",
{ MagicEffect::DetectAnimal, "DetectAnimal" }, "Invisibility",
{ MagicEffect::DetectEnchantment, "DetectEnchantment" }, "Chameleon",
{ MagicEffect::DetectKey, "DetectKey" }, "Light",
{ MagicEffect::DisintegrateArmor, "DisintegrateArmor" }, "Sanctuary",
{ MagicEffect::DisintegrateWeapon, "DisintegrateWeapon" }, "NightEye",
{ MagicEffect::Dispel, "Dispel" }, "Charm",
{ MagicEffect::DivineIntervention, "DivineIntervention" }, "Paralyze",
{ MagicEffect::DrainAttribute, "DrainAttribute" }, "Silence",
{ MagicEffect::DrainFatigue, "DrainFatigue" }, "Blind",
{ MagicEffect::DrainHealth, "DrainHealth" }, "Sound",
{ MagicEffect::DrainMagicka, "DrainMagicka" }, "CalmHumanoid",
{ MagicEffect::DrainSkill, "DrainSkill" }, "CalmCreature",
{ MagicEffect::Feather, "Feather" }, "FrenzyHumanoid",
{ MagicEffect::FireDamage, "FireDamage" }, "FrenzyCreature",
{ MagicEffect::FireShield, "FireShield" }, "DemoralizeHumanoid",
{ MagicEffect::FortifyAttack, "FortifyAttack" }, "DemoralizeCreature",
{ MagicEffect::FortifyAttribute, "FortifyAttribute" }, "RallyHumanoid",
{ MagicEffect::FortifyFatigue, "FortifyFatigue" }, "RallyCreature",
{ MagicEffect::FortifyHealth, "FortifyHealth" }, "Dispel",
{ MagicEffect::FortifyMagicka, "FortifyMagicka" }, "Soultrap",
{ MagicEffect::FortifyMaximumMagicka, "FortifyMaximumMagicka" }, "Telekinesis",
{ MagicEffect::FortifySkill, "FortifySkill" }, "Mark",
{ MagicEffect::FrenzyCreature, "FrenzyCreature" }, "Recall",
{ MagicEffect::FrenzyHumanoid, "FrenzyHumanoid" }, "DivineIntervention",
{ MagicEffect::FrostDamage, "FrostDamage" }, "AlmsiviIntervention",
{ MagicEffect::FrostShield, "FrostShield" }, "DetectAnimal",
{ MagicEffect::Invisibility, "Invisibility" }, "DetectEnchantment",
{ MagicEffect::Jump, "Jump" }, "DetectKey",
{ MagicEffect::Levitate, "Levitate" }, "SpellAbsorption",
{ MagicEffect::Light, "Light" }, "Reflect",
{ MagicEffect::LightningShield, "LightningShield" }, "CureCommonDisease",
{ MagicEffect::Lock, "Lock" }, "CureBlightDisease",
{ MagicEffect::Mark, "Mark" }, "CureCorprusDisease",
{ MagicEffect::NightEye, "NightEye" }, "CurePoison",
{ MagicEffect::Open, "Open" }, "CureParalyzation",
{ MagicEffect::Paralyze, "Paralyze" }, "RestoreAttribute",
{ MagicEffect::Poison, "Poison" }, "RestoreHealth",
{ MagicEffect::RallyCreature, "RallyCreature" }, "RestoreMagicka",
{ MagicEffect::RallyHumanoid, "RallyHumanoid" }, "RestoreFatigue",
{ MagicEffect::Recall, "Recall" }, "RestoreSkill",
{ MagicEffect::Reflect, "Reflect" }, "FortifyAttribute",
{ MagicEffect::RemoveCurse, "RemoveCurse" }, "FortifyHealth",
{ MagicEffect::ResistBlightDisease, "ResistBlightDisease" }, "FortifyMagicka",
{ MagicEffect::ResistCommonDisease, "ResistCommonDisease" }, "FortifyFatigue",
{ MagicEffect::ResistCorprusDisease, "ResistCorprusDisease" }, "FortifySkill",
{ MagicEffect::ResistFire, "ResistFire" }, "FortifyMaximumMagicka",
{ MagicEffect::ResistFrost, "ResistFrost" }, "AbsorbAttribute",
{ MagicEffect::ResistMagicka, "ResistMagicka" }, "AbsorbHealth",
{ MagicEffect::ResistNormalWeapons, "ResistNormalWeapons" }, "AbsorbMagicka",
{ MagicEffect::ResistParalysis, "ResistParalysis" }, "AbsorbFatigue",
{ MagicEffect::ResistPoison, "ResistPoison" }, "AbsorbSkill",
{ MagicEffect::ResistShock, "ResistShock" }, "ResistFire",
{ MagicEffect::RestoreAttribute, "RestoreAttribute" }, "ResistFrost",
{ MagicEffect::RestoreFatigue, "RestoreFatigue" }, "ResistShock",
{ MagicEffect::RestoreHealth, "RestoreHealth" }, "ResistMagicka",
{ MagicEffect::RestoreMagicka, "RestoreMagicka" }, "ResistCommonDisease",
{ MagicEffect::RestoreSkill, "RestoreSkill" }, "ResistBlightDisease",
{ MagicEffect::Sanctuary, "Sanctuary" }, "ResistCorprusDisease",
{ MagicEffect::Shield, "Shield" }, "ResistPoison",
{ MagicEffect::ShockDamage, "ShockDamage" }, "ResistNormalWeapons",
{ MagicEffect::Silence, "Silence" }, "ResistParalysis",
{ MagicEffect::SlowFall, "SlowFall" }, "RemoveCurse",
{ MagicEffect::Soultrap, "Soultrap" }, "TurnUndead",
{ MagicEffect::Sound, "Sound" }, "SummonScamp",
{ MagicEffect::SpellAbsorption, "SpellAbsorption" }, "SummonClannfear",
{ MagicEffect::StuntedMagicka, "StuntedMagicka" }, "SummonDaedroth",
{ MagicEffect::SummonAncestralGhost, "SummonAncestralGhost" }, "SummonDremora",
{ MagicEffect::SummonBonelord, "SummonBonelord" }, "SummonAncestralGhost",
{ MagicEffect::SummonBonewalker, "SummonBonewalker" }, "SummonSkeletalMinion",
{ MagicEffect::SummonCenturionSphere, "SummonCenturionSphere" }, "SummonBonewalker",
{ MagicEffect::SummonClannfear, "SummonClannfear" }, "SummonGreaterBonewalker",
{ MagicEffect::SummonDaedroth, "SummonDaedroth" }, "SummonBonelord",
{ MagicEffect::SummonDremora, "SummonDremora" }, "SummonWingedTwilight",
{ MagicEffect::SummonFlameAtronach, "SummonFlameAtronach" }, "SummonHunger",
{ MagicEffect::SummonFrostAtronach, "SummonFrostAtronach" }, "SummonGoldenSaint",
{ MagicEffect::SummonGoldenSaint, "SummonGoldenSaint" }, "SummonFlameAtronach",
{ MagicEffect::SummonGreaterBonewalker, "SummonGreaterBonewalker" }, "SummonFrostAtronach",
{ MagicEffect::SummonHunger, "SummonHunger" }, "SummonStormAtronach",
{ MagicEffect::SummonScamp, "SummonScamp" }, "FortifyAttack",
{ MagicEffect::SummonSkeletalMinion, "SummonSkeletalMinion" }, "CommandCreature",
{ MagicEffect::SummonStormAtronach, "SummonStormAtronach" }, "CommandHumanoid",
{ MagicEffect::SummonWingedTwilight, "SummonWingedTwilight" }, "BoundDagger",
{ MagicEffect::SunDamage, "SunDamage" }, "BoundLongsword",
{ MagicEffect::SwiftSwim, "SwiftSwim" }, "BoundMace",
{ MagicEffect::Telekinesis, "Telekinesis" }, "BoundBattleAxe",
{ MagicEffect::TurnUndead, "TurnUndead" }, "BoundSpear",
{ MagicEffect::Vampirism, "Vampirism" }, "BoundLongbow",
{ MagicEffect::WaterBreathing, "WaterBreathing" }, "ExtraSpell",
{ MagicEffect::WaterWalking, "WaterWalking" }, "BoundCuirass",
{ MagicEffect::WeaknessToBlightDisease, "WeaknessToBlightDisease" }, "BoundHelm",
{ MagicEffect::WeaknessToCommonDisease, "WeaknessToCommonDisease" }, "BoundBoots",
{ MagicEffect::WeaknessToCorprusDisease, "WeaknessToCorprusDisease" }, "BoundShield",
{ MagicEffect::WeaknessToFire, "WeaknessToFire" }, "BoundGloves",
{ MagicEffect::WeaknessToFrost, "WeaknessToFrost" }, "Corprus",
{ MagicEffect::WeaknessToMagicka, "WeaknessToMagicka" }, "Vampirism",
{ MagicEffect::WeaknessToNormalWeapons, "WeaknessToNormalWeapons" }, "SummonCenturionSphere",
{ MagicEffect::WeaknessToPoison, "WeaknessToPoison" }, "SunDamage",
{ MagicEffect::WeaknessToShock, "WeaknessToShock" }, "StuntedMagicka",
// bloodmoon
{ MagicEffect::SummonWolf, "SummonWolf" },
{ MagicEffect::SummonBear, "SummonBear" },
{ MagicEffect::SummonBonewolf, "SummonBonewolf" },
{ MagicEffect::SummonCreature04, "SummonCreature04" },
{ MagicEffect::SummonCreature05, "SummonCreature05" },
// tribunal // tribunal
{ MagicEffect::SummonFabricant, "SummonFabricant" }, "SummonFabricant",
// bloodmoon
"SummonWolf",
"SummonBear",
"SummonBonewolf",
"SummonCreature04",
"SummonCreature05",
}; };
static std::map<std::string_view, int, Misc::StringUtils::CiComp> initStringToIntMap(
const std::array<std::string, MagicEffect::Length>& strings)
{
std::map<std::string_view, int, Misc::StringUtils::CiComp> map;
for (int i = 0; i < strings.size(); i++)
map[strings[i]] = i;
return map;
}
const std::map<std::string_view, int, Misc::StringUtils::CiComp> MagicEffect::sGmstEffectIdToEffectIdMap
= initStringToIntMap(MagicEffect::sGmstEffectIds);
const std::map<std::string_view, int, Misc::StringUtils::CiComp> MagicEffect::sEffectNameToEffectIdMap
= initStringToIntMap(MagicEffect::sEffectNames);
class FindSecond class FindSecond
{ {
std::string_view mName; std::string_view mName;
@ -712,40 +729,38 @@ namespace ESM
mDescription.clear(); mDescription.clear();
} }
std::string_view MagicEffect::effectIdToGmstString(int effectID) const std::string& MagicEffect::effectIdToGmstString(int effectID)
{ {
auto name = sGmstEffectIds.find(effectID); if (effectID >= sGmstEffectIds.size() || effectID < 0)
if (name == sGmstEffectIds.end())
throw std::runtime_error(std::string("Unimplemented effect ID ") + std::to_string(effectID)); throw std::runtime_error(std::string("Unimplemented effect ID ") + std::to_string(effectID));
return name->second; return sGmstEffectIds[effectID];
} }
std::string_view MagicEffect::effectIdToName(int effectID) const std::string& MagicEffect::effectIdToName(int effectID)
{ {
auto name = sEffectNames.find(effectID); if (effectID >= sEffectNames.size() || effectID < 0)
if (name == sEffectNames.end())
throw std::runtime_error(std::string("Unimplemented effect ID ") + std::to_string(effectID)); throw std::runtime_error(std::string("Unimplemented effect ID ") + std::to_string(effectID));
return name->second; return sEffectNames[effectID];
} }
int MagicEffect::effectNameToId(std::string_view effect) int MagicEffect::effectNameToId(std::string_view effect)
{ {
auto name = std::find_if(sEffectNames.begin(), sEffectNames.end(), FindSecond(effect)); auto name = sEffectNameToEffectIdMap.find(effect);
if (name == sEffectNames.end()) if (name == sEffectNameToEffectIdMap.end())
throw std::runtime_error("Unimplemented effect " + std::string(effect)); throw std::runtime_error("Unimplemented effect " + std::string(effect));
return name->first; return name->second;
} }
int MagicEffect::effectGmstIdToId(std::string_view gmstId) int MagicEffect::effectGmstIdToId(std::string_view gmstId)
{ {
auto name = std::find_if(sGmstEffectIds.begin(), sGmstEffectIds.end(), FindSecond(gmstId)); auto name = sGmstEffectIdToEffectIdMap.find(gmstId);
if (name == sGmstEffectIds.end()) if (name == sGmstEffectIdToEffectIdMap.end())
throw std::runtime_error("Unimplemented effect " + std::string(gmstId)); throw std::runtime_error("Unimplemented effect " + std::string(gmstId));
return name->first; return name->second;
} }
RefId MagicEffect::indexToRefId(int index) RefId MagicEffect::indexToRefId(int index)

View file

@ -2,11 +2,13 @@
#define OPENMW_ESM_MGEF_H #define OPENMW_ESM_MGEF_H
#include <map> #include <map>
#include <array>
#include <string> #include <string>
#include <string_view> #include <string_view>
#include "components/esm/defs.hpp" #include "components/esm/defs.hpp"
#include "components/esm/refid.hpp" #include "components/esm/refid.hpp"
#include "components/misc/strings/algorithm.hpp"
namespace ESM namespace ESM
{ {
@ -264,10 +266,13 @@ namespace ESM
Length Length
}; };
static const std::map<int, std::string> sGmstEffectIds; static const std::array<std::string, Length> sGmstEffectIds;
static const std::map<int, std::string> sEffectNames; static const std::array<std::string, Length> sEffectNames;
static std::string_view effectIdToGmstString(int effectID); static const std::map<std::string_view, int, Misc::StringUtils::CiComp> sGmstEffectIdToEffectIdMap;
static std::string_view effectIdToName(int effectID); static const std::map<std::string_view, int, Misc::StringUtils::CiComp> sEffectNameToEffectIdMap;
static const std::string& effectIdToGmstString(int effectID);
static const std::string& effectIdToName(int effectID);
static int effectNameToId(std::string_view effect); static int effectNameToId(std::string_view effect);
static int effectGmstIdToId(std::string_view gmstId); static int effectGmstIdToId(std::string_view gmstId);