From 6f9113fe882c183d572bcffe846af1a63becd071 Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 9 Jan 2014 01:49:58 +0100 Subject: [PATCH] Add preliminary implementation of PayFine, PayFineThief and GoToJail instructions --- apps/openmw/mwbase/world.hpp | 5 ++- apps/openmw/mwgui/messagebox.cpp | 1 + apps/openmw/mwmechanics/spellcasting.cpp | 8 ++--- apps/openmw/mwrender/camera.cpp | 1 + apps/openmw/mwscript/docs/vmformat.txt | 5 ++- apps/openmw/mwscript/miscextensions.cpp | 40 ++++++++++++++++++++++++ apps/openmw/mwworld/worldimp.cpp | 8 ++++- apps/openmw/mwworld/worldimp.hpp | 5 ++- components/compiler/extensions0.cpp | 3 ++ components/compiler/opcodes.hpp | 3 ++ 10 files changed, 65 insertions(+), 14 deletions(-) diff --git a/apps/openmw/mwbase/world.hpp b/apps/openmw/mwbase/world.hpp index b719ce4d6..43e526ecb 100644 --- a/apps/openmw/mwbase/world.hpp +++ b/apps/openmw/mwbase/world.hpp @@ -431,11 +431,10 @@ namespace MWBase virtual bool findInteriorPositionInWorldSpace(MWWorld::CellStore* cell, Ogre::Vector3& result) = 0; - /// Teleports \a ptr to the reference of \a id (e.g. DivineMarker, PrisonMarker, TempleMarker) - /// closest to \a worldPos. + /// Teleports \a ptr to the closest reference of \a id (e.g. DivineMarker, PrisonMarker, TempleMarker) /// @note id must be lower case virtual void teleportToClosestMarker (const MWWorld::Ptr& ptr, - const std::string& id, Ogre::Vector3 worldPos) = 0; + const std::string& id) = 0; enum DetectionType { diff --git a/apps/openmw/mwgui/messagebox.cpp b/apps/openmw/mwgui/messagebox.cpp index 378e76e46..8e518668b 100644 --- a/apps/openmw/mwgui/messagebox.cpp +++ b/apps/openmw/mwgui/messagebox.cpp @@ -10,6 +10,7 @@ namespace MWGui MessageBoxManager::MessageBoxManager () { + // TODO: fMessageTimePerChar mMessageBoxSpeed = 0.1; mInterMessageBoxe = NULL; mStaticMessageBox = NULL; diff --git a/apps/openmw/mwmechanics/spellcasting.cpp b/apps/openmw/mwmechanics/spellcasting.cpp index 21b6d0d77..a1cdb8b61 100644 --- a/apps/openmw/mwmechanics/spellcasting.cpp +++ b/apps/openmw/mwmechanics/spellcasting.cpp @@ -287,17 +287,13 @@ namespace MWMechanics if (!MWBase::Environment::get().getWorld()->isTeleportingEnabled()) return; - Ogre::Vector3 worldPos; - if (!MWBase::Environment::get().getWorld()->findInteriorPositionInWorldSpace(target.getCell(), worldPos)) - worldPos = MWBase::Environment::get().getWorld()->getPlayer().getLastKnownExteriorPosition(); - if (effectId == ESM::MagicEffect::DivineIntervention) { - MWBase::Environment::get().getWorld()->teleportToClosestMarker(target, "divinemarker", worldPos); + MWBase::Environment::get().getWorld()->teleportToClosestMarker(target, "divinemarker"); } else if (effectId == ESM::MagicEffect::AlmsiviIntervention) { - MWBase::Environment::get().getWorld()->teleportToClosestMarker(target, "templemarker", worldPos); + MWBase::Environment::get().getWorld()->teleportToClosestMarker(target, "templemarker"); } else if (effectId == ESM::MagicEffect::Mark) diff --git a/apps/openmw/mwrender/camera.cpp b/apps/openmw/mwrender/camera.cpp index 9a35725ee..dda9797ef 100644 --- a/apps/openmw/mwrender/camera.cpp +++ b/apps/openmw/mwrender/camera.cpp @@ -228,6 +228,7 @@ namespace MWRender void Camera::setSneakOffset() { + // TODO: iFirstPersonSneakDelta if(mAnimation) mAnimation->addFirstPersonOffset(Ogre::Vector3(0.f, 0.f, -9.8f)); } diff --git a/apps/openmw/mwscript/docs/vmformat.txt b/apps/openmw/mwscript/docs/vmformat.txt index a6349c4da..64a9d427a 100644 --- a/apps/openmw/mwscript/docs/vmformat.txt +++ b/apps/openmw/mwscript/docs/vmformat.txt @@ -372,5 +372,8 @@ op 0x2000231: GetSpellReadied op 0x2000232: GetSpellReadied, explicit op 0x2000233: GetPcJumping op 0x2000234: ShowRestMenu, explicit -opcodes 0x2000235-0x3ffffff unused +op 0x2000235: GoToJail +op 0x2000236: PayFine +op 0x2000237: PayFineThief +opcodes 0x2000238-0x3ffffff unused diff --git a/apps/openmw/mwscript/miscextensions.cpp b/apps/openmw/mwscript/miscextensions.cpp index 61d286ae3..03dc5c14c 100644 --- a/apps/openmw/mwscript/miscextensions.cpp +++ b/apps/openmw/mwscript/miscextensions.cpp @@ -762,6 +762,43 @@ namespace MWScript } }; + class OpGoToJail : public Interpreter::Opcode0 + { + public: + virtual void execute (Interpreter::Runtime& runtime) + { + MWBase::World* world = MWBase::Environment::get().getWorld(); + MWWorld::Ptr player = world->getPlayerPtr(); + world->teleportToClosestMarker(player, "prisonmarker"); + player.getClass().getNpcStats(player).setBounty(0); + // TODO: pass time, change skills, show messagebox + // TODO: move stolen items to closest evidence chest + // iDaysinPrisonMod + } + }; + + class OpPayFine : public Interpreter::Opcode0 + { + public: + virtual void execute(Interpreter::Runtime &runtime) + { + MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); + player.getClass().getNpcStats(player).setBounty(0); + + // TODO: move stolen items to closest evidence chest + } + }; + + class OpPayFineThief : public Interpreter::Opcode0 + { + public: + virtual void execute(Interpreter::Runtime &runtime) + { + MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); + player.getClass().getNpcStats(player).setBounty(0); + } + }; + void installOpcodes (Interpreter::Interpreter& interpreter) { interpreter.installSegment5 (Compiler::Misc::opcodeXBox, new OpXBox); @@ -785,6 +822,9 @@ namespace MWScript interpreter.installSegment5 (Compiler::Misc::opcodeGetPcJumping, new OpGetPcJumping); interpreter.installSegment5 (Compiler::Misc::opcodeWakeUpPc, new OpWakeUpPc); interpreter.installSegment5 (Compiler::Misc::opcodePlayBink, new OpPlayBink); + interpreter.installSegment5 (Compiler::Misc::opcodePayFine, new OpPayFine); + interpreter.installSegment5 (Compiler::Misc::opcodePayFineThief, new OpPayFineThief); + interpreter.installSegment5 (Compiler::Misc::opcodeGoToJail, new OpGoToJail); interpreter.installSegment5 (Compiler::Misc::opcodeGetLocked, new OpGetLocked); interpreter.installSegment5 (Compiler::Misc::opcodeGetLockedExplicit, new OpGetLocked); interpreter.installSegment5 (Compiler::Misc::opcodeGetEffect, new OpGetEffect); diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 46511f5bc..f61938f92 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -2273,6 +2273,8 @@ namespace MWWorld bool World::findInteriorPositionInWorldSpace(MWWorld::CellStore* cell, Ogre::Vector3& result) { + if (cell->isExterior()) + return false; MWWorld::CellRefList& doors = cell->mDoors; CellRefList::List& refList = doors.mList; @@ -2293,8 +2295,12 @@ namespace MWWorld } void World::teleportToClosestMarker (const MWWorld::Ptr& ptr, - const std::string& id, Ogre::Vector3 worldPos) + const std::string& id) { + Ogre::Vector3 worldPos; + if (!findInteriorPositionInWorldSpace(ptr.getCell(), worldPos)) + worldPos = mPlayer->getLastKnownExteriorPosition(); + MWWorld::Ptr closestMarker; float closestDistance = FLT_MAX; diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index ba7dc66b6..cc087a89f 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -522,11 +522,10 @@ namespace MWWorld virtual bool findInteriorPositionInWorldSpace(MWWorld::CellStore* cell, Ogre::Vector3& result); - /// Teleports \a ptr to the reference of \a id (e.g. DivineMarker, PrisonMarker, TempleMarker) - /// closest to \a worldPos. + /// Teleports \a ptr to the closest reference of \a id (e.g. DivineMarker, PrisonMarker, TempleMarker) /// @note id must be lower case virtual void teleportToClosestMarker (const MWWorld::Ptr& ptr, - const std::string& id, Ogre::Vector3 worldPos); + const std::string& id); /// List all references (filtered by \a type) detected by \a ptr. The range /// is determined by the current magnitude of the "Detect X" magic effect belonging to \a type. diff --git a/components/compiler/extensions0.cpp b/components/compiler/extensions0.cpp index e35a32ffa..03510d833 100644 --- a/components/compiler/extensions0.cpp +++ b/components/compiler/extensions0.cpp @@ -244,6 +244,9 @@ namespace Compiler extensions.registerFunction ("getpcjumping", 'l', "", opcodeGetPcJumping); extensions.registerInstruction ("wakeuppc", "", opcodeWakeUpPc); extensions.registerInstruction ("playbink", "Sl", opcodePlayBink); + extensions.registerInstruction ("payfine", "", opcodePayFine); + extensions.registerInstruction ("payfinethief", "", opcodePayFineThief); + extensions.registerInstruction ("gotojail", "", opcodeGoToJail); extensions.registerFunction ("getlocked", 'l', "", opcodeGetLocked, opcodeGetLockedExplicit); extensions.registerFunction ("geteffect", 'l', "S", opcodeGetEffect, opcodeGetEffectExplicit); extensions.registerInstruction ("addsoulgem", "cc", opcodeAddSoulGem, opcodeAddSoulGemExplicit); diff --git a/components/compiler/opcodes.hpp b/components/compiler/opcodes.hpp index eb2240964..3a4c8135d 100644 --- a/components/compiler/opcodes.hpp +++ b/components/compiler/opcodes.hpp @@ -223,6 +223,9 @@ namespace Compiler const int opcodeGetStandingActorExplicit = 0x200020f; const int opcodeGetWindSpeed = 0x2000212; const int opcodePlayBink = 0x20001f7; + const int opcodeGoToJail = 0x2000235; + const int opcodePayFine = 0x2000236; + const int opcodePayFineThief = 0x2000237; const int opcodeHitOnMe = 0x2000213; const int opcodeHitOnMeExplicit = 0x2000214; const int opcodeDisableTeleporting = 0x2000215;