Revert "Fix unneeded runtime errors"

This reverts commit d207c2251ffe4693f73e275c8df95bc7127c0010.
This commit is contained in:
Aussiemon 2025-07-06 20:51:53 -06:00
parent 555721141d
commit 67795543a2
2 changed files with 36 additions and 60 deletions

View File

@ -4,7 +4,6 @@
#include <sstream> #include <sstream>
#include <components/compiler/locals.hpp> #include <components/compiler/locals.hpp>
#include <components/debug/debuglog.hpp>
#include <components/esm/records.hpp> #include <components/esm/records.hpp>
#include "../mwworld/esmstore.hpp" #include "../mwworld/esmstore.hpp"
@ -301,15 +300,7 @@ namespace MWScript
std::string_view InterpreterContext::getNPCFaction() const std::string_view InterpreterContext::getNPCFaction() const
{ {
const MWWorld::Ptr& ptr = getReferenceImp(); const ESM::NPC* npc = getReferenceImp().get<ESM::NPC>()->mBase;
const ESM::RefId& factionId = ptr.getClass().getPrimaryFaction(ptr);
if (factionId.empty())
{
Log(Debug::Warning) << "getNPCFaction(): NPC is not in a faction";
return "%";
}
const ESM::NPC* npc = ptr.get<ESM::NPC>()->mBase;
const ESM::Faction* faction = MWBase::Environment::get().getESMStore()->get<ESM::Faction>().find(npc->mFaction); const ESM::Faction* faction = MWBase::Environment::get().getESMStore()->get<ESM::Faction>().find(npc->mFaction);
return faction->mName; return faction->mName;
} }
@ -319,10 +310,7 @@ namespace MWScript
const MWWorld::Ptr& ptr = getReferenceImp(); const MWWorld::Ptr& ptr = getReferenceImp();
const ESM::RefId& faction = ptr.getClass().getPrimaryFaction(ptr); const ESM::RefId& faction = ptr.getClass().getPrimaryFaction(ptr);
if (faction.empty()) if (faction.empty())
{ throw std::runtime_error("getNPCRank(): NPC is not in a faction");
Log(Debug::Warning) << "getNPCRank(): NPC is not in a faction";
return "%";
}
int rank = ptr.getClass().getPrimaryFactionRank(ptr); int rank = ptr.getClass().getPrimaryFactionRank(ptr);
if (rank < 0 || rank > 9) if (rank < 0 || rank > 9)
@ -361,10 +349,7 @@ namespace MWScript
const ESM::RefId& factionId = getReferenceImp().getClass().getPrimaryFaction(getReferenceImp()); const ESM::RefId& factionId = getReferenceImp().getClass().getPrimaryFaction(getReferenceImp());
if (factionId.empty()) if (factionId.empty())
{ throw std::runtime_error("getPCRank(): NPC is not in a faction");
Log(Debug::Warning) << "getPCRank(): NPC is not in a faction";
return "%";
}
const auto& ranks = player.getClass().getNpcStats(player).getFactionRanks(); const auto& ranks = player.getClass().getNpcStats(player).getFactionRanks();
auto it = ranks.find(factionId); auto it = ranks.find(factionId);
@ -393,10 +378,7 @@ namespace MWScript
const ESM::RefId& factionId = getReferenceImp().getClass().getPrimaryFaction(getReferenceImp()); const ESM::RefId& factionId = getReferenceImp().getClass().getPrimaryFaction(getReferenceImp());
if (factionId.empty()) if (factionId.empty())
{ throw std::runtime_error("getPCNextRank(): NPC is not in a faction");
Log(Debug::Warning) << "getPCNextRank(): NPC is not in a faction";
return "%";
}
const auto& ranks = player.getClass().getNpcStats(player).getFactionRanks(); const auto& ranks = player.getClass().getNpcStats(player).getFactionRanks();
auto it = ranks.find(factionId); auto it = ranks.find(factionId);

View File

@ -26,40 +26,40 @@ namespace
std::vector<std::string> globals; std::vector<std::string> globals;
const std::initializer_list<std::tuple<std::string_view, std::string_view>> sActionBindings{ const std::initializer_list<std::tuple<std::string_view, std::string_view>> sActionBindings{
{ "ActionSlideRight", "#{sRight}" }, { "actionslideright", "#{sRight}" },
{ "ActionReadyMagic", "#{sReady_Magic}" }, { "actionreadymagic", "#{sReady_Magic}" },
{ "ActionPrevWeapon", "#{sPrevWeapon}" }, { "actionprevweapon", "#{sPrevWeapon}" },
{ "ActionNextWeapon", "#{sNextWeapon}" }, { "actionnextweapon", "#{sNextWeapon}" },
{ "ActionToggleRun", "#{sAuto_Run}" }, { "actiontogglerun", "#{sAuto_Run}" },
{ "ActionSlideLeft", "#{sLeft}" }, { "actionslideleft", "#{sLeft}" },
{ "ActionReadyItem", "#{sReady_Weapon}" }, { "actionreadyitem", "#{sReady_Weapon}" },
{ "ActionPrevSpell", "#{sPrevSpell}" }, { "actionprevspell", "#{sPrevSpell}" },
{ "ActionNextSpell", "#{sNextSpell}" }, { "actionnextspell", "#{sNextSpell}" },
{ "ActionRestMenu", "#{sRestKey}" }, { "actionrestmenu", "#{sRestKey}" },
{ "ActionMenuMode", "#{sInventory}" }, { "actionmenumode", "#{sInventory}" },
{ "ActionActivate", "#{sActivate}" }, { "actionactivate", "#{sActivate}" },
{ "ActionJournal", "#{sJournal}" }, { "actionjournal", "#{sJournal}" },
{ "ActionForward", "#{sForward}" }, { "actionforward", "#{sForward}" },
{ "ActionCrouch", "#{sCrouch_Sneak}" }, { "actioncrouch", "#{sCrouch_Sneak}" },
{ "ActionJump", "#{sJump}" }, { "actionjump", "#{sJump}" },
{ "ActionBack", "#{sBack}" }, { "actionback", "#{sBack}" },
{ "ActionUse", "#{sUse}" }, { "actionuse", "#{sUse}" },
{ "ActionRun", "#{sRun}" }, { "actionrun", "#{sRun}" },
}; };
using ContextMethod = std::string_view (Interpreter::Context::*)() const; using ContextMethod = std::string_view (Interpreter::Context::*)() const;
const std::initializer_list<std::tuple<std::string_view, std::pair<ContextMethod, ContextMethod>>> sContextMethods{ const std::initializer_list<std::tuple<std::string_view, std::pair<ContextMethod, ContextMethod>>> sContextMethods{
{ "NextPCRank", { &Interpreter::Context::getPCNextRank, nullptr } }, { "nextpcrank", { &Interpreter::Context::getPCNextRank, nullptr } },
{ "PCNextRank", { &Interpreter::Context::getPCNextRank, nullptr } }, { "pcnextrank", { &Interpreter::Context::getPCNextRank, nullptr } },
{ "Faction", { &Interpreter::Context::getNPCFaction, nullptr } }, { "faction", { &Interpreter::Context::getNPCFaction, nullptr } },
{ "PCClass", { &Interpreter::Context::getPCClass, &Interpreter::Context::getPCClass } }, { "pcclass", { &Interpreter::Context::getPCClass, &Interpreter::Context::getPCClass } },
{ "PCName", { &Interpreter::Context::getPCName, &Interpreter::Context::getPCName } }, { "pcname", { &Interpreter::Context::getPCName, &Interpreter::Context::getPCName } },
{ "PCRace", { &Interpreter::Context::getPCRace, &Interpreter::Context::getPCRace } }, { "pcrace", { &Interpreter::Context::getPCRace, &Interpreter::Context::getPCRace } },
{ "PCRank", { &Interpreter::Context::getPCRank, nullptr } }, { "pcrank", { &Interpreter::Context::getPCRank, nullptr } },
{ "Class", { &Interpreter::Context::getNPCClass, &Interpreter::Context::getPCClass } }, { "class", { &Interpreter::Context::getNPCClass, &Interpreter::Context::getPCClass } },
{ "Cell", { &Interpreter::Context::getCurrentCellName, &Interpreter::Context::getCurrentCellName } }, { "cell", { &Interpreter::Context::getCurrentCellName, &Interpreter::Context::getCurrentCellName } },
{ "Race", { &Interpreter::Context::getNPCRace, &Interpreter::Context::getPCRace } }, { "race", { &Interpreter::Context::getNPCRace, &Interpreter::Context::getPCRace } },
{ "Rank", { &Interpreter::Context::getNPCRank, nullptr } }, { "rank", { &Interpreter::Context::getNPCRank, nullptr } },
{ "Name", { &Interpreter::Context::getActorName, &Interpreter::Context::getPCName } }, { "name", { &Interpreter::Context::getActorName, &Interpreter::Context::getPCName } },
}; };
bool longerStr(std::string_view a, std::string_view b) bool longerStr(std::string_view a, std::string_view b)
@ -78,7 +78,7 @@ namespace
return true; return true;
} }
} }
if (check(temp, "PCCrimeLevel", i, start)) if (check(temp, "pccrimelevel", i, start))
{ {
retval << context.getPCBounty(); retval << context.getPCBounty();
return true; return true;
@ -89,13 +89,7 @@ namespace
if (check(temp, name, i, start)) if (check(temp, name, i, start))
{ {
if (method) // Not all variables are available outside of dialogue if (method) // Not all variables are available outside of dialogue
{
retval << (context.*method)(); retval << (context.*method)();
// Re-add the token if replacement failed without an error
if ((context.*method)() == "%")
retval << name;
}
return true; return true;
} }
} }