From aa8418634f8f776a09e19bf141e322505b26ad1f Mon Sep 17 00:00:00 2001 From: gugus Date: Mon, 9 Apr 2012 14:26:53 +0200 Subject: [PATCH] add PCLowerRank script instruction --- apps/openmw/mwscript/docs/vmformat.txt | 3 +- apps/openmw/mwscript/statsextensions.cpp | 43 +++++++++++++++++++++--- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/apps/openmw/mwscript/docs/vmformat.txt b/apps/openmw/mwscript/docs/vmformat.txt index 2b20b973c..9a5cf8525 100644 --- a/apps/openmw/mwscript/docs/vmformat.txt +++ b/apps/openmw/mwscript/docs/vmformat.txt @@ -25,7 +25,8 @@ op 0x20008: LoopAnim op 0x20009: LoopAnim, explicit reference op 0x2000a: Choice op 0x2000b: PCRaiseRank -opcodes 0x2000c-0x3ffff unused +op 0x2000c: PCLowerRank +opcodes 0x2000d-0x3ffff unused Segment 4: (not implemented yet) diff --git a/apps/openmw/mwscript/statsextensions.cpp b/apps/openmw/mwscript/statsextensions.cpp index 05db10301..176f139aa 100644 --- a/apps/openmw/mwscript/statsextensions.cpp +++ b/apps/openmw/mwscript/statsextensions.cpp @@ -305,14 +305,11 @@ namespace MWScript virtual void execute (Interpreter::Runtime& runtime, unsigned int arg0) { - std::cout << "arg0:" << arg0<< std::endl; - std::cout << "try to rais rank..."; std::string factionID = ""; MWScript::InterpreterContext& context = static_cast (runtime.getContext()); if(arg0==0) { - std::cout << "slurpppp"; factionID = context.getEnvironment().mDialogueManager->getFaction(); } else @@ -322,7 +319,6 @@ namespace MWScript } if(factionID != "") { - std::cout << "raiserank!!!!!"; MWWorld::Ptr player = context.getEnvironment().mWorld->getPlayer().getPlayer(); if(MWWorld::Class::get(player).getNpcStats(player).mFactionRank.find(factionID) == MWWorld::Class::get(player).getNpcStats(player).mFactionRank.end()) { @@ -336,7 +332,41 @@ namespace MWScript std::cout << std::endl; } }; - + + class OpPCLowerRank : public Interpreter::Opcode1 + { + public: + + virtual void execute (Interpreter::Runtime& runtime, unsigned int arg0) + { + std::string factionID = ""; + MWScript::InterpreterContext& context + = static_cast (runtime.getContext()); + if(arg0==0) + { + factionID = context.getEnvironment().mDialogueManager->getFaction(); + } + else + { + factionID = runtime.getStringLiteral (runtime[0].mInteger); + runtime.pop(); + } + if(factionID != "") + { + MWWorld::Ptr player = context.getEnvironment().mWorld->getPlayer().getPlayer(); + if(MWWorld::Class::get(player).getNpcStats(player).mFactionRank.find(factionID) == MWWorld::Class::get(player).getNpcStats(player).mFactionRank.end()) + { + //do nothing, the player is not in the faction... Throw an exeption? + } + else + { + MWWorld::Class::get(player).getNpcStats(player).mFactionRank[factionID] = MWWorld::Class::get(player).getNpcStats(player).mFactionRank[factionID] -1; + } + } + std::cout << std::endl; + } + }; + class OpModDisposition : public Interpreter::Opcode0 { public: @@ -379,6 +409,7 @@ namespace MWScript const int opcodeModSkillExplicit = 0x2000115; //const int opcodePCJoinFaction = 0x2000141; const int opcodePCRaiseRank = 0x2000b; + const int opcodePCLowerRank = 0x2000c; const int opcodeModDisposition = 0x2000145; void registerExtensions (Compiler::Extensions& extensions) @@ -453,6 +484,7 @@ namespace MWScript } //extensions.registerInstruction("PCJoinFaction","S",opcodePCJoinFaction); extensions.registerInstruction("pcraiserank","/S",opcodePCRaiseRank); + extensions.registerInstruction("pclowerrank","/S",opcodePCLowerRank); extensions.registerInstruction("moddisposition","l",opcodeModDisposition); } @@ -512,6 +544,7 @@ namespace MWScript //interpreter.installSegment5(opcodePCJoinFaction,new OpPCJoinFaction); interpreter.installSegment3(opcodePCRaiseRank,new OpPCRaiseRank); + interpreter.installSegment3(opcodePCLowerRank,new OpPCLowerRank); interpreter.installSegment5(opcodeModDisposition,new OpModDisposition); } }