From e68dc19256a413229779d3e0eec47e61c8a955b2 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sun, 25 Nov 2012 01:54:37 +0100 Subject: [PATCH] GetCurrentTime, HasSoulGem --- apps/openmw/mwscript/containerextensions.cpp | 35 ++++++++++++++++++-- apps/openmw/mwscript/docs/vmformat.txt | 5 ++- apps/openmw/mwscript/miscextensions.cpp | 13 ++++++++ 3 files changed, 50 insertions(+), 3 deletions(-) diff --git a/apps/openmw/mwscript/containerextensions.cpp b/apps/openmw/mwscript/containerextensions.cpp index 66cf21c5b..5dba79d3f 100644 --- a/apps/openmw/mwscript/containerextensions.cpp +++ b/apps/openmw/mwscript/containerextensions.cpp @@ -256,6 +256,33 @@ namespace MWScript } }; + template + class OpHasSoulGem : public Interpreter::Opcode0 + { + public: + + virtual void execute(Interpreter::Runtime &runtime) + { + MWWorld::Ptr ptr = R()(runtime); + + std::string creatureName = toLower (runtime.getStringLiteral (runtime[0].mInteger)); + runtime.pop(); + + MWWorld::InventoryStore& invStore = MWWorld::Class::get(ptr).getInventoryStore (ptr); + for (MWWorld::ContainerStoreIterator it = invStore.begin(MWWorld::ContainerStore::Type_Miscellaneous); + it != invStore.end(); ++it) + { + + if (toLower(it->getCellRef().mSoul) == toLower(creatureName)) + { + runtime.push(1); + return; + } + } + runtime.push(0); + } + }; + const int opcodeAddItem = 0x2000076; const int opcodeAddItemExplicit = 0x2000077; const int opcodeGetItemCount = 0x2000078; @@ -268,6 +295,8 @@ namespace MWScript const int opcodeGetArmorTypeExplicit = 0x20001d2; const int opcodeHasItemEquipped = 0x20001d5; const int opcodeHasItemEquippedExplicit = 0x20001d6; + const int opcodeHasSoulGem = 0x20001de; + const int opcodeHasSoulGemExplicit = 0x20001df; void registerExtensions (Compiler::Extensions& extensions) { @@ -279,6 +308,7 @@ namespace MWScript extensions.registerInstruction ("equip", "c", opcodeEquip, opcodeEquipExplicit); extensions.registerFunction ("getarmortype", 'l', "l", opcodeGetArmorType, opcodeGetArmorTypeExplicit); extensions.registerFunction ("hasitemequipped", 'l', "c", opcodeHasItemEquipped, opcodeHasItemEquippedExplicit); + extensions.registerFunction ("hassoulgem", 'l', "c", opcodeHasSoulGem, opcodeHasSoulGemExplicit); } void installOpcodes (Interpreter::Interpreter& interpreter) @@ -293,9 +323,10 @@ namespace MWScript interpreter.installSegment5 (opcodeEquipExplicit, new OpEquip); interpreter.installSegment5 (opcodeGetArmorType, new OpGetArmorType); interpreter.installSegment5 (opcodeGetArmorTypeExplicit, new OpGetArmorType); - interpreter.installSegment5 (opcodeHasItemEquipped, new OpHasItemEquipped); + interpreter.installSegment5 (opcodeHasItemEquipped, new OpHasItemEquipped); interpreter.installSegment5 (opcodeHasItemEquippedExplicit, new OpHasItemEquipped); - + interpreter.installSegment5 (opcodeHasSoulGem, new OpHasSoulGem); + interpreter.installSegment5 (opcodeHasSoulGemExplicit, new OpHasSoulGem); } } } diff --git a/apps/openmw/mwscript/docs/vmformat.txt b/apps/openmw/mwscript/docs/vmformat.txt index 73d6b5239..3e8542335 100644 --- a/apps/openmw/mwscript/docs/vmformat.txt +++ b/apps/openmw/mwscript/docs/vmformat.txt @@ -270,5 +270,8 @@ op 0x20001d9: GetRace op 0x20001da: GetRace, explicit op 0x20001db: GetSpellEffects op 0x20001dc: GetSpellEffects, explicit -opcodes 0x20001dd-0x3ffffff unused +op 0x20001dd: GetCurrentTime +op 0x20001de: HasSoulGem +op 0x20001df: HasSoulGem, explicit +opcodes 0x20001e0-0x3ffffff unused diff --git a/apps/openmw/mwscript/miscextensions.cpp b/apps/openmw/mwscript/miscextensions.cpp index 81a315456..1cd5ed35e 100644 --- a/apps/openmw/mwscript/miscextensions.cpp +++ b/apps/openmw/mwscript/miscextensions.cpp @@ -347,6 +347,16 @@ namespace MWScript } }; + class OpGetCurrentTime : public Interpreter::Opcode0 + { + public: + + virtual void execute (Interpreter::Runtime& runtime) + { + runtime.push(MWBase::Environment::get().getWorld()->getTimeStamp().getHour()); + } + }; + const int opcodeXBox = 0x200000c; const int opcodeOnActivate = 0x200000d; const int opcodeActivate = 0x2000075; @@ -376,6 +386,7 @@ namespace MWScript const int opcodeGetWeaponDrawnExplicit = 0x20001d8; const int opcodeGetSpellEffects = 0x20001db; const int opcodeGetSpellEffectsExplicit = 0x20001dc; + const int opcodeGetCurrentTime = 0x20001dd; void registerExtensions (Compiler::Extensions& extensions) { @@ -407,6 +418,7 @@ namespace MWScript extensions.registerFunction ("getattacked", 'l', "", opcodeGetAttacked, opcodeGetAttackedExplicit); extensions.registerFunction ("getweapondrawn", 'l', "", opcodeGetWeaponDrawn, opcodeGetWeaponDrawnExplicit); extensions.registerFunction ("getspelleffects", 'l', "c", opcodeGetSpellEffects, opcodeGetSpellEffectsExplicit); + extensions.registerFunction ("getcurrenttime", 'f', "", opcodeGetCurrentTime); } void installOpcodes (Interpreter::Interpreter& interpreter) @@ -440,6 +452,7 @@ namespace MWScript interpreter.installSegment5 (opcodeGetWeaponDrawnExplicit, new OpGetWeaponDrawn); interpreter.installSegment5 (opcodeGetSpellEffects, new OpGetSpellEffects); interpreter.installSegment5 (opcodeGetSpellEffectsExplicit, new OpGetSpellEffects); + interpreter.installSegment5 (opcodeGetCurrentTime, new OpGetCurrentTime); } } }