1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-19 23:53:52 +00:00
This commit is contained in:
scrawl 2012-11-23 20:48:59 +01:00
parent 064cb80c0a
commit d54ed557bf
2 changed files with 37 additions and 1 deletions

View file

@ -14,6 +14,8 @@
#include "../mwworld/manualref.hpp"
#include "../mwworld/class.hpp"
#include "../mwworld/containerstore.hpp"
#include "../mwworld/actionequip.hpp"
#include "../mwworld/inventorystore.hpp"
#include "interpretercontext.hpp"
#include "ref.hpp"
@ -128,12 +130,41 @@ namespace MWScript
}
};
template <class R>
class OpEquip : public Interpreter::Opcode0
{
public:
virtual void execute(Interpreter::Runtime &runtime)
{
MWWorld::Ptr ptr = R()(runtime);
std::string item = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
MWWorld::InventoryStore& invStore = MWWorld::Class::get(ptr).getInventoryStore (ptr);
MWWorld::ContainerStoreIterator it = invStore.begin();
for (; it != invStore.end(); ++it)
{
if (toLower(it->getCellRef().mRefID) == toLower(item))
break;
}
if (it == invStore.end())
throw std::runtime_error("Item to equip not found");
MWWorld::ActionEquip action (*it);
action.execute(ptr);
}
};
const int opcodeAddItem = 0x2000076;
const int opcodeAddItemExplicit = 0x2000077;
const int opcodeGetItemCount = 0x2000078;
const int opcodeGetItemCountExplicit = 0x2000079;
const int opcodeRemoveItem = 0x200007a;
const int opcodeRemoveItemExplicit = 0x200007b;
const int opcodeEquip = 0x20001b3;
const int opcodeEquipExplicit = 0x20001b4;
void registerExtensions (Compiler::Extensions& extensions)
{
@ -142,6 +173,7 @@ namespace MWScript
opcodeGetItemCountExplicit);
extensions.registerInstruction ("removeitem", "cl", opcodeRemoveItem,
opcodeRemoveItemExplicit);
extensions.registerInstruction ("equip", "c", opcodeEquip, opcodeEquipExplicit);
}
void installOpcodes (Interpreter::Interpreter& interpreter)
@ -152,6 +184,8 @@ namespace MWScript
interpreter.installSegment5 (opcodeGetItemCountExplicit, new OpGetItemCount<ExplicitRef>);
interpreter.installSegment5 (opcodeRemoveItem, new OpRemoveItem<ImplicitRef>);
interpreter.installSegment5 (opcodeRemoveItemExplicit, new OpRemoveItem<ExplicitRef>);
interpreter.installSegment5 (opcodeEquip, new OpEquip<ImplicitRef>);
interpreter.installSegment5 (opcodeEquipExplicit, new OpEquip<ExplicitRef>);
}
}
}

View file

@ -228,5 +228,7 @@ op 0x20001af: SetReputation, explicit
op 0x20001b0: ModReputation, explicit
op 0x20001b1: GetReputation
op 0x20001b2: GetReputation, explicit
opcodes 0x20001b1-0x3ffffff unused
op 0x20001b3: Equip
op 0x20001b4: Equip, explicit
opcodes 0x20001b5-0x3ffffff unused