From 14cf007a3f8a494f10a6f0edf9b5d5b13fb96656 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sun, 22 Aug 2010 14:49:25 +0200 Subject: [PATCH] added first batch of AI-related instructions and functions (they don't do anything at this point) --- apps/openmw/CMakeLists.txt | 2 + apps/openmw/mwscript/aiextensions.cpp | 214 +++++++++++++++++++++++++ apps/openmw/mwscript/aiextensions.hpp | 25 +++ apps/openmw/mwscript/docs/vmformat.txt | 11 +- apps/openmw/mwscript/extensions.cpp | 3 + 5 files changed, 252 insertions(+), 3 deletions(-) create mode 100644 apps/openmw/mwscript/aiextensions.cpp create mode 100644 apps/openmw/mwscript/aiextensions.hpp diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index b5948aaeac..f0aafbbbca 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -60,6 +60,7 @@ set(GAMESCRIPT mwscript/skyextensions.cpp mwscript/statsextensions.cpp mwscript/containerextensions.cpp + mwscript/aiextensions.cpp mwscript/extensions.cpp mwscript/globalscripts.cpp ) @@ -75,6 +76,7 @@ set(GAMESCRIPT_HEADER mwscript/skyextensions.hpp mwscript/statsextensions.hpp mwscript/containerextensions.hpp + mwscript/aiextensions.hpp mwscript/extensions.hpp mwscript/globalscripts.hpp ) diff --git a/apps/openmw/mwscript/aiextensions.cpp b/apps/openmw/mwscript/aiextensions.cpp new file mode 100644 index 0000000000..e1fdc1976f --- /dev/null +++ b/apps/openmw/mwscript/aiextensions.cpp @@ -0,0 +1,214 @@ + +#include "aiextensions.hpp" + +#include + +#include +#include +#include + +#include "interpretercontext.hpp" + +#include +namespace MWScript +{ + namespace Ai + { + class OpAiTravel : public Interpreter::Opcode1 + { + public: + + virtual void execute (Interpreter::Runtime& runtime, unsigned int arg0) + { + MWScript::InterpreterContext& context + = static_cast (runtime.getContext()); + + MWWorld::Ptr ptr = context.getReference(); + + Interpreter::Type_Float x = runtime[0].mInteger; + runtime.pop(); + + Interpreter::Type_Float y = runtime[0].mInteger; + runtime.pop(); + + Interpreter::Type_Float z = runtime[0].mInteger; + runtime.pop(); + + // discard additional arguments (reset), because we have no idea what they mean. + for (unsigned int i=0; i (runtime.getContext()); + + std::string id = runtime.getStringLiteral (runtime[0].mInteger); + runtime.pop(); + + MWWorld::Ptr ptr = context.getWorld().getPtr (id, false); + + Interpreter::Type_Float x = runtime[0].mInteger; + runtime.pop(); + + Interpreter::Type_Float y = runtime[0].mInteger; + runtime.pop(); + + Interpreter::Type_Float z = runtime[0].mInteger; + runtime.pop(); + + // discard additional arguments (reset), because we have no idea what they mean. + for (unsigned int i=0; i (runtime.getContext()); + + std::string id = runtime.getStringLiteral (runtime[0].mInteger); + runtime.pop(); + + MWWorld::Ptr ptr = context.getReference(); + + std::string actor = runtime.getStringLiteral (runtime[0].mInteger); + runtime.pop(); + + Interpreter::Type_Float duration = runtime[0].mInteger; + runtime.pop(); + + Interpreter::Type_Float x = runtime[0].mInteger; + runtime.pop(); + + Interpreter::Type_Float y = runtime[0].mInteger; + runtime.pop(); + + Interpreter::Type_Float z = runtime[0].mInteger; + runtime.pop(); + + // discard additional arguments (reset), because we have no idea what they mean. + for (unsigned int i=0; i (runtime.getContext()); + + std::string id = runtime.getStringLiteral (runtime[0].mInteger); + runtime.pop(); + + MWWorld::Ptr ptr = context.getWorld().getPtr (id, false); + + std::string actor = runtime.getStringLiteral (runtime[0].mInteger); + runtime.pop(); + + Interpreter::Type_Float duration = runtime[0].mInteger; + runtime.pop(); + + Interpreter::Type_Float x = runtime[0].mInteger; + runtime.pop(); + + Interpreter::Type_Float y = runtime[0].mInteger; + runtime.pop(); + + Interpreter::Type_Float z = runtime[0].mInteger; + runtime.pop(); + + // discard additional arguments (reset), because we have no idea what they mean. + for (unsigned int i=0; i (runtime.getContext()); + + MWWorld::Ptr ptr = context.getReference(); + + Interpreter::Type_Integer value = 1; + + runtime.push (value); + } + }; + + class OpGetAiPackageDoneExplicit : public Interpreter::Opcode0 + { + public: + + virtual void execute (Interpreter::Runtime& runtime) + { + MWScript::InterpreterContext& context + = static_cast (runtime.getContext()); + + std::string id = runtime.getStringLiteral (runtime[0].mInteger); + runtime.pop(); + + MWWorld::Ptr ptr = context.getWorld().getPtr (id, false); + + Interpreter::Type_Integer value = 1; + + runtime.push (value); + } + }; + + + const int opcodeAiTravel = 0x20000; + const int opcodeAiTravelExplicit = 0x20001; + const int opcodeAiEscort = 0x20002; + const int opcodeAiEscortExplicit = 0x20003; + const int opcodeGetAiPackageDone = 0x200007c; + const int opcodeGetAiPackageDoneExplicit = 0x200007d; + + void registerExtensions (Compiler::Extensions& extensions) + { + extensions.registerInstruction ("aitravel", "cllll/l", opcodeAiTravel, + opcodeAiTravelExplicit); + extensions.registerInstruction ("aiescort", "cllll/l", opcodeAiEscort, + opcodeAiEscortExplicit); + + extensions.registerFunction ("getaipackagedone", 'l', "", opcodeGetAiPackageDone, + opcodeGetAiPackageDoneExplicit); + } + + void installOpcodes (Interpreter::Interpreter& interpreter) + { + interpreter.installSegment3 (opcodeAiTravel, new OpAiTravel); + interpreter.installSegment3 (opcodeAiTravelExplicit, new OpAiTravelExplicit); + interpreter.installSegment3 (opcodeAiEscort, new OpAiEscort); + interpreter.installSegment3 (opcodeAiEscortExplicit, new OpAiEscortExplicit); + interpreter.installSegment5 (opcodeGetAiPackageDone, new OpGetAiPackageDone); + interpreter.installSegment5 (opcodeGetAiPackageDoneExplicit, new OpGetAiPackageDoneExplicit); + } + } +} diff --git a/apps/openmw/mwscript/aiextensions.hpp b/apps/openmw/mwscript/aiextensions.hpp new file mode 100644 index 0000000000..547341476e --- /dev/null +++ b/apps/openmw/mwscript/aiextensions.hpp @@ -0,0 +1,25 @@ +#ifndef GAME_SCRIPT_AIEXTENSIONS_H +#define GAME_SCRIPT_AIEXTENSIONS_H + +namespace Compiler +{ + class Extensions; +} + +namespace Interpreter +{ + class Interpreter; +} + +namespace MWScript +{ + /// \brief AI-related script functionality + namespace Ai + { + void registerExtensions (Compiler::Extensions& extensions); + + void installOpcodes (Interpreter::Interpreter& interpreter); + } +} + +#endif diff --git a/apps/openmw/mwscript/docs/vmformat.txt b/apps/openmw/mwscript/docs/vmformat.txt index 9813e2e2fd..88d3f59ac4 100644 --- a/apps/openmw/mwscript/docs/vmformat.txt +++ b/apps/openmw/mwscript/docs/vmformat.txt @@ -13,8 +13,11 @@ Segment 2: opcodes 0x200-0x3ff unused Segment 3: -(not implemented yet) -opcodes 0x20000-0x3ffff unused +op 0x20000: AiTravel +op 0x20001: AiTravel, explicit reference +op 0x20002: AiEscort +op 0x20003: AiEscort, explicit reference +opcodes 0x20004-0x3ffff unused Segment 4: (not implemented yet) @@ -83,4 +86,6 @@ op 0x2000078: GetItemCount op 0x2000079: GetItemCount, explicit reference op 0x200007a: RemoveItem op 0x200007b: RemoveItem, explicit reference -opcodes 0x200007c-0x3ffffff unused +op 0x200007c: GetAiPackageDone +op 0x200007d: GetAiPackageDone, explicit reference +opcodes 0x200007e-0x3ffffff unused diff --git a/apps/openmw/mwscript/extensions.cpp b/apps/openmw/mwscript/extensions.cpp index 1b3d3df14e..9b1e2dd45c 100644 --- a/apps/openmw/mwscript/extensions.cpp +++ b/apps/openmw/mwscript/extensions.cpp @@ -11,6 +11,7 @@ #include "skyextensions.hpp" #include "statsextensions.hpp" #include "containerextensions.hpp" +#include "aiextensions.hpp" namespace MWScript { @@ -23,6 +24,7 @@ namespace MWScript Sky::registerExtensions (extensions); Stats::registerExtensions (extensions); Container::registerExtensions (extensions); + Ai::registerExtensions (extensions); } void installOpcodes (Interpreter::Interpreter& interpreter) @@ -35,5 +37,6 @@ namespace MWScript Sky::installOpcodes (interpreter); Stats::installOpcodes (interpreter); Container::installOpcodes (interpreter); + Ai::installOpcodes (interpreter); } }