1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-16 20:29:57 +00:00

Add record presence early-outs for various script instructions (feature #7625)

AddItem, RemoveItem, StartScript, StopScript, AddTopic
This commit is contained in:
Alexei Kotov 2023-10-16 02:34:07 +03:00
parent 3b6211ec4f
commit e6c02efbb7
4 changed files with 39 additions and 0 deletions

View file

@ -109,6 +109,7 @@
Feature #7546: Start the game on Fredas Feature #7546: Start the game on Fredas
Feature #7568: Uninterruptable scripted music Feature #7568: Uninterruptable scripted music
Feature #7618: Show the player character's health in the save details Feature #7618: Show the player character's health in the save details
Feature #7625: Add some missing console error outputs
Feature #7634: Support NiParticleBomb Feature #7634: Support NiParticleBomb
Task #5896: Do not use deprecated MyGUI properties Task #5896: Do not use deprecated MyGUI properties
Task #7113: Move from std::atoi to std::from_char Task #7113: Move from std::atoi to std::from_char

View file

@ -31,6 +31,7 @@
#include "../mwmechanics/actorutil.hpp" #include "../mwmechanics/actorutil.hpp"
#include "../mwmechanics/levelledlist.hpp" #include "../mwmechanics/levelledlist.hpp"
#include "interpretercontext.hpp"
#include "ref.hpp" #include "ref.hpp"
namespace namespace
@ -94,6 +95,12 @@ namespace MWScript
Interpreter::Type_Integer count = runtime[0].mInteger; Interpreter::Type_Integer count = runtime[0].mInteger;
runtime.pop(); runtime.pop();
if (!MWBase::Environment::get().getESMStore()->find(item))
{
runtime.getContext().report("Failed to add item '" + item.getRefIdString() + "': unknown ID");
return;
}
if (count < 0) if (count < 0)
count = static_cast<uint16_t>(count); count = static_cast<uint16_t>(count);
@ -210,6 +217,12 @@ namespace MWScript
Interpreter::Type_Integer count = runtime[0].mInteger; Interpreter::Type_Integer count = runtime[0].mInteger;
runtime.pop(); runtime.pop();
if (!MWBase::Environment::get().getESMStore()->find(item))
{
runtime.getContext().report("Failed to remove item '" + item.getRefIdString() + "': unknown ID");
return;
}
if (count < 0) if (count < 0)
count = static_cast<uint16_t>(count); count = static_cast<uint16_t>(count);

View file

@ -16,6 +16,7 @@
#include "../mwmechanics/npcstats.hpp" #include "../mwmechanics/npcstats.hpp"
#include "../mwworld/class.hpp" #include "../mwworld/class.hpp"
#include "../mwworld/esmstore.hpp"
#include "ref.hpp" #include "ref.hpp"
@ -89,6 +90,13 @@ namespace MWScript
ESM::RefId topic = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); ESM::RefId topic = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger));
runtime.pop(); runtime.pop();
if (!MWBase::Environment::get().getESMStore()->get<ESM::Dialogue>().search(topic))
{
runtime.getContext().report(
"Failed to add topic '" + topic.getRefIdString() + "': topic record not found");
return;
}
MWBase::Environment::get().getDialogueManager()->addTopic(topic); MWBase::Environment::get().getDialogueManager()->addTopic(topic);
} }
}; };

View file

@ -41,6 +41,7 @@
#include <components/esm3/loadmisc.hpp> #include <components/esm3/loadmisc.hpp>
#include <components/esm3/loadprob.hpp> #include <components/esm3/loadprob.hpp>
#include <components/esm3/loadrepa.hpp> #include <components/esm3/loadrepa.hpp>
#include <components/esm3/loadscpt.hpp>
#include <components/esm3/loadstat.hpp> #include <components/esm3/loadstat.hpp>
#include <components/esm3/loadweap.hpp> #include <components/esm3/loadweap.hpp>
@ -184,6 +185,14 @@ namespace MWScript
MWWorld::Ptr target = R()(runtime, false); MWWorld::Ptr target = R()(runtime, false);
ESM::RefId name = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); ESM::RefId name = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger));
runtime.pop(); runtime.pop();
if (!MWBase::Environment::get().getESMStore()->get<ESM::Script>().search(name))
{
runtime.getContext().report(
"Failed to start global script '" + name.getRefIdString() + "': script record not found");
return;
}
MWBase::Environment::get().getScriptManager()->getGlobalScripts().addScript(name, target); MWBase::Environment::get().getScriptManager()->getGlobalScripts().addScript(name, target);
} }
}; };
@ -206,6 +215,14 @@ namespace MWScript
{ {
const ESM::RefId& name = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); const ESM::RefId& name = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger));
runtime.pop(); runtime.pop();
if (!MWBase::Environment::get().getESMStore()->get<ESM::Script>().search(name))
{
runtime.getContext().report(
"Failed to stop global script '" + name.getRefIdString() + "': script record not found");
return;
}
MWBase::Environment::get().getScriptManager()->getGlobalScripts().removeScript(name); MWBase::Environment::get().getScriptManager()->getGlobalScripts().removeScript(name);
} }
}; };