From bb34f6e7fc057b3838fcf46db4783ca10a33f4b4 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sun, 9 Jan 2011 20:38:58 +0100 Subject: [PATCH] added Enable/DisableCollision instructions --- apps/openmw/mwscript/controlextensions.cpp | 30 ++++++++++++++++++++++ apps/openmw/mwscript/docs/vmformat.txt | 2 ++ apps/openmw/mwworld/player.cpp | 4 +-- apps/openmw/mwworld/player.hpp | 6 +++++ 4 files changed, 40 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwscript/controlextensions.cpp b/apps/openmw/mwscript/controlextensions.cpp index e38ee7c2d..a560a28c6 100644 --- a/apps/openmw/mwscript/controlextensions.cpp +++ b/apps/openmw/mwscript/controlextensions.cpp @@ -7,6 +7,8 @@ #include #include +#include "../mwworld/player.hpp" + #include "interpretercontext.hpp" #include @@ -35,10 +37,32 @@ namespace MWScript } }; + class OpSetCollision : public Interpreter::Opcode0 + { + bool mEnable; + + public: + + OpSetCollision (bool enable) + : mEnable (enable) + {} + + virtual void execute (Interpreter::Runtime& runtime) + { + InterpreterContext& context + = static_cast (runtime.getContext()); + + context.getWorld().getPlayer().setCollisionMode (mEnable); + } + + }; + const int numberOfControls = 7; const int opcodeEnable = 0x200007e; const int opcodeDisable = 0x2000085; + const int opcodeEnableCollision = 0x2000130; + const int opcodeDisableCollision = 0x2000131; const char *controls[numberOfControls] = { @@ -56,6 +80,9 @@ namespace MWScript extensions.registerInstruction (enable + controls[i], "", opcodeEnable+i); extensions.registerInstruction (disable + controls[i], "", opcodeDisable+i); } + + extensions.registerInstruction ("enablecollision", "", opcodeEnableCollision); + extensions.registerInstruction ("disablecollision", "", opcodeDisableCollision); } void installOpcodes (Interpreter::Interpreter& interpreter) @@ -65,6 +92,9 @@ namespace MWScript interpreter.installSegment5 (opcodeEnable+i, new OpSetControl (controls[i], true)); interpreter.installSegment5 (opcodeDisable+i, new OpSetControl (controls[i], false)); } + + interpreter.installSegment5 (opcodeEnableCollision, new OpSetCollision (true)); + interpreter.installSegment5 (opcodeDisableCollision, new OpSetCollision (false)); } } } diff --git a/apps/openmw/mwscript/docs/vmformat.txt b/apps/openmw/mwscript/docs/vmformat.txt index 2a859c57f..b77f53221 100644 --- a/apps/openmw/mwscript/docs/vmformat.txt +++ b/apps/openmw/mwscript/docs/vmformat.txt @@ -101,4 +101,6 @@ op 0x20000c4-0x20000de: SetSkill op 0x20000df-0x20000f9: SetSkill, explicit reference op 0x20000fa-0x2000114: ModSkill op 0x2000115-0x200012f: ModSKill, explicit reference +op 0x2000130: EnableCollision +op 0x2000131: DisableCollision opcodes 0x2000130-0x3ffffff unused diff --git a/apps/openmw/mwworld/player.cpp b/apps/openmw/mwworld/player.cpp index 1c27dbe77..cc7abccac 100644 --- a/apps/openmw/mwworld/player.cpp +++ b/apps/openmw/mwworld/player.cpp @@ -8,7 +8,7 @@ namespace MWWorld { Player::Player (MWRender::Player *renderer, const ESM::NPC *player, MWWorld::World& world) : - mCellStore (0), mRenderer (renderer), mWorld (world), mClass (0) + mCellStore (0), mRenderer (renderer), mWorld (world), mClass (0), mCollisionMode (true) { mPlayer.base = player; mName = player->name; @@ -49,7 +49,7 @@ namespace MWWorld relZ = pos[1]; // TODO: Collision detection must be used to find the REAL new - // position. + // position, if mCollisionMode==true // Set the position setPos(relX, relY, relZ); diff --git a/apps/openmw/mwworld/player.hpp b/apps/openmw/mwworld/player.hpp index 27bc3138b..b54afad56 100644 --- a/apps/openmw/mwworld/player.hpp +++ b/apps/openmw/mwworld/player.hpp @@ -29,6 +29,7 @@ namespace MWWorld std::string mRace; std::string mBirthsign; ESM::Class *mClass; + bool mCollisionMode; public: @@ -102,6 +103,11 @@ namespace MWWorld { return *mClass; } + + void setCollisionMode (bool enable) + { + mCollisionMode = enable; + } }; } #endif