From 0db48b29c755490b7614f7197249b11b9c9e5eff Mon Sep 17 00:00:00 2001 From: scrawl Date: Sun, 25 Nov 2012 01:26:29 +0100 Subject: [PATCH] GetSpellEffects, GetRace --- apps/openmw/mwmechanics/activespells.cpp | 16 ++++++++++++++ apps/openmw/mwmechanics/activespells.hpp | 3 +++ apps/openmw/mwscript/docs/vmformat.txt | 6 ++++- apps/openmw/mwscript/miscextensions.cpp | 22 ++++++++++++++++++- apps/openmw/mwscript/statsextensions.cpp | 28 ++++++++++++++++++++++++ 5 files changed, 73 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwmechanics/activespells.cpp b/apps/openmw/mwmechanics/activespells.cpp index 989bdedd7..f53ccdce3 100644 --- a/apps/openmw/mwmechanics/activespells.cpp +++ b/apps/openmw/mwmechanics/activespells.cpp @@ -3,6 +3,8 @@ #include +#include + #include #include #include @@ -258,4 +260,18 @@ namespace MWMechanics return scaledDuration-usedUp; } + + bool ActiveSpells::isSpellActive(std::string id) const + { + boost::algorithm::to_lower(id); + for (TContainer::iterator iter = mSpells.begin(); iter != mSpells.end(); ++iter) + { + std::string left = iter->first; + boost::algorithm::to_lower(left); + + if (iter->first == id) + return true; + } + return false; + } } diff --git a/apps/openmw/mwmechanics/activespells.hpp b/apps/openmw/mwmechanics/activespells.hpp index e7a239854..6b832f4cd 100644 --- a/apps/openmw/mwmechanics/activespells.hpp +++ b/apps/openmw/mwmechanics/activespells.hpp @@ -58,6 +58,9 @@ namespace MWMechanics void removeSpell (const std::string& id); + bool isSpellActive (std::string id) const; + ///< case insensitive + const MagicEffects& getMagicEffects() const; TIterator begin() const; diff --git a/apps/openmw/mwscript/docs/vmformat.txt b/apps/openmw/mwscript/docs/vmformat.txt index 498e1572f..73d6b5239 100644 --- a/apps/openmw/mwscript/docs/vmformat.txt +++ b/apps/openmw/mwscript/docs/vmformat.txt @@ -266,5 +266,9 @@ op 0x20001d5: HasItemEquipped op 0x20001d6: HasItemEquipped, explicit op 0x20001d7: GetWeaponDrawn op 0x20001d8: GetWeaponDrawn, explicit -opcodes 0x20001d9-0x3ffffff unused +op 0x20001d9: GetRace +op 0x20001da: GetRace, explicit +op 0x20001db: GetSpellEffects +op 0x20001dc: GetSpellEffects, explicit +opcodes 0x20001dd-0x3ffffff unused diff --git a/apps/openmw/mwscript/miscextensions.cpp b/apps/openmw/mwscript/miscextensions.cpp index 505dbdf7d..81a315456 100644 --- a/apps/openmw/mwscript/miscextensions.cpp +++ b/apps/openmw/mwscript/miscextensions.cpp @@ -332,6 +332,21 @@ namespace MWScript } }; + template + class OpGetSpellEffects : public Interpreter::Opcode0 + { + public: + + virtual void execute (Interpreter::Runtime& runtime) + { + MWWorld::Ptr ptr = R()(runtime); + std::string id = runtime.getStringLiteral(runtime[0].mInteger); + runtime.pop(); + + runtime.push(MWWorld::Class::get(ptr).getCreatureStats(ptr).getActiveSpells().isSpellActive(id)); + } + }; + const int opcodeXBox = 0x200000c; const int opcodeOnActivate = 0x200000d; const int opcodeActivate = 0x2000075; @@ -359,6 +374,8 @@ namespace MWScript const int opcodeGetAttackedExplicit = 0x20001d4; const int opcodeGetWeaponDrawn = 0x20001d7; const int opcodeGetWeaponDrawnExplicit = 0x20001d8; + const int opcodeGetSpellEffects = 0x20001db; + const int opcodeGetSpellEffectsExplicit = 0x20001dc; void registerExtensions (Compiler::Extensions& extensions) { @@ -389,6 +406,7 @@ namespace MWScript extensions.registerFunction ("geteffect", 'l', "l", opcodeGetEffect, opcodeGetEffectExplicit); extensions.registerFunction ("getattacked", 'l', "", opcodeGetAttacked, opcodeGetAttackedExplicit); extensions.registerFunction ("getweapondrawn", 'l', "", opcodeGetWeaponDrawn, opcodeGetWeaponDrawnExplicit); + extensions.registerFunction ("getspelleffects", 'l', "c", opcodeGetSpellEffects, opcodeGetSpellEffectsExplicit); } void installOpcodes (Interpreter::Interpreter& interpreter) @@ -418,8 +436,10 @@ namespace MWScript interpreter.installSegment5 (opcodeGetEffectExplicit, new OpGetEffect); interpreter.installSegment5 (opcodeGetAttacked, new OpGetAttacked); interpreter.installSegment5 (opcodeGetAttackedExplicit, new OpGetAttacked); + interpreter.installSegment5 (opcodeGetWeaponDrawn, new OpGetWeaponDrawn); interpreter.installSegment5 (opcodeGetWeaponDrawnExplicit, new OpGetWeaponDrawn); - interpreter.installSegment5 (opcodeGetWeaponDrawnExplicit, new OpGetWeaponDrawn); + interpreter.installSegment5 (opcodeGetSpellEffects, new OpGetSpellEffects); + interpreter.installSegment5 (opcodeGetSpellEffectsExplicit, new OpGetSpellEffects); } } } diff --git a/apps/openmw/mwscript/statsextensions.cpp b/apps/openmw/mwscript/statsextensions.cpp index f6a31dd7f..bea41df1d 100644 --- a/apps/openmw/mwscript/statsextensions.cpp +++ b/apps/openmw/mwscript/statsextensions.cpp @@ -780,6 +780,25 @@ namespace MWScript } }; + template + class OpGetRace : public Interpreter::Opcode0 + { + public: + + virtual void execute (Interpreter::Runtime& runtime) + { + MWWorld::Ptr ptr = R()(runtime); + + std::string race = runtime.getStringLiteral(runtime[0].mInteger); + boost::algorithm::to_lower(race); + runtime.pop(); + + std::string npcRace = ptr.get()->mBase->mRace; + boost::algorithm::to_lower(npcRace); + + runtime.push (npcRace == race); + } + }; const int numberOfAttributes = 8; @@ -850,6 +869,9 @@ namespace MWScript const int opcodeGetBlightDisease = 0x20001aa; const int opcodeGetBlightDiseaseExplicit = 0x20001ab; + const int opcodeGetRace = 0x20001d9; + const int opcodeGetRaceExplicit = 0x20001da; + void registerExtensions (Compiler::Extensions& extensions) { static const char *attributes[numberOfAttributes] = @@ -950,6 +972,9 @@ namespace MWScript opcodeGetCommonDiseaseExplicit); extensions.registerFunction ("getblightdisease", 'l', "", opcodeGetBlightDisease, opcodeGetBlightDiseaseExplicit); + + extensions.registerFunction ("getrace", 'l', "c", opcodeGetRace, + opcodeGetRaceExplicit); } void installOpcodes (Interpreter::Interpreter& interpreter) @@ -1045,6 +1070,9 @@ namespace MWScript interpreter.installSegment5 (opcodeGetCommonDiseaseExplicit, new OpGetCommonDisease); interpreter.installSegment5 (opcodeGetBlightDisease, new OpGetBlightDisease); interpreter.installSegment5 (opcodeGetBlightDiseaseExplicit, new OpGetBlightDisease); + + interpreter.installSegment5 (opcodeGetRace, new OpGetRace); + interpreter.installSegment5 (opcodeGetRaceExplicit, new OpGetRace); } } }