From f321e549a4bb4af4bae0bf6a37e4b5a558156681 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Mon, 4 Apr 2011 15:10:37 +0200 Subject: [PATCH] added instruction GetPCCell --- apps/openmw/mwscript/cellextensions.cpp | 34 +++++++++++++++++++++++++ apps/openmw/mwscript/docs/vmformat.txt | 3 ++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwscript/cellextensions.cpp b/apps/openmw/mwscript/cellextensions.cpp index 9c756e11f..bb5263203 100644 --- a/apps/openmw/mwscript/cellextensions.cpp +++ b/apps/openmw/mwscript/cellextensions.cpp @@ -102,10 +102,42 @@ namespace MWScript } }; + class OpGetPCCell : public Interpreter::Opcode0 + { + public: + + virtual void execute (Interpreter::Runtime& runtime) + { + InterpreterContext& context + = static_cast (runtime.getContext()); + + std::string name = runtime.getStringLiteral (runtime[0].mInteger); + runtime.pop(); + + const ESM::Cell *cell = context.getWorld().getPlayer().getPlayer().getCell()->cell; + + std::string current = cell->name; + + if (!(cell->data.flags & ESM::Cell::Interior) && current.empty()) + { + const ESM::Region *region = + context.getWorld().getStore().regions.find (cell->region); + + current = region->name; + } + + bool match = current.length()>=name.length() && + current.substr (0, name.length())==name; + + runtime.push (match ? 1 : 0); + } + }; + const int opcodeCellChanged = 0x2000000; const int opcodeCOC = 0x2000026; const int opcodeCOE = 0x200008e; const int opcodeGetInterior = 0x2000131; + const int opcodeGetPCCell = 0x2000136; void registerExtensions (Compiler::Extensions& extensions) { @@ -115,6 +147,7 @@ namespace MWScript extensions.registerInstruction ("coe", "ll", opcodeCOE); extensions.registerInstruction ("centeronexterior", "ll", opcodeCOE); extensions.registerFunction ("getinterior", 'l', "", opcodeGetInterior); + extensions.registerFunction ("getpccell", 'l', "c", opcodeGetPCCell); } void installOpcodes (Interpreter::Interpreter& interpreter) @@ -123,6 +156,7 @@ namespace MWScript interpreter.installSegment5 (opcodeCOC, new OpCOC); interpreter.installSegment5 (opcodeCOE, new OpCOE); interpreter.installSegment5 (opcodeGetInterior, new OpGetInterior); + interpreter.installSegment5 (opcodeGetPCCell, new OpGetPCCell); } } } diff --git a/apps/openmw/mwscript/docs/vmformat.txt b/apps/openmw/mwscript/docs/vmformat.txt index 90962f56b..fcebaae2b 100644 --- a/apps/openmw/mwscript/docs/vmformat.txt +++ b/apps/openmw/mwscript/docs/vmformat.txt @@ -107,4 +107,5 @@ op 0x2000132: ToggleCollsionDebug op 0x2000133: Journal op 0x2000134: SetJournalIndex op 0x2000135: GetJournalIndex -opcodes 0x2000136-0x3ffffff unused +op 0x2000136: GetPCCell +opcodes 0x2000137-0x3ffffff unused