From e5b1e27fa6fae0b8f10dbff3e757342acefdbd5c Mon Sep 17 00:00:00 2001 From: gugus Date: Mon, 9 Apr 2012 13:24:19 +0200 Subject: [PATCH] pcRaiseRank works. Player can now join factions. --- apps/openmw/mwdialogue/dialoguemanager.cpp | 22 ++++++---- apps/openmw/mwscript/docs/vmformat.txt | 5 ++- apps/openmw/mwscript/statsextensions.cpp | 47 +++++++++++++++++----- 3 files changed, 55 insertions(+), 19 deletions(-) diff --git a/apps/openmw/mwdialogue/dialoguemanager.cpp b/apps/openmw/mwdialogue/dialoguemanager.cpp index cd7be5031..b36c9d998 100644 --- a/apps/openmw/mwdialogue/dialoguemanager.cpp +++ b/apps/openmw/mwdialogue/dialoguemanager.cpp @@ -181,7 +181,17 @@ namespace MWDialogue break; case 46://Same faction - if(!selectCompare(comp,0,select.i)) return false; + { + MWMechanics::NpcStats PCstats = MWWorld::Class::get(mEnvironment.mWorld->getPlayer().getPlayer()).getNpcStats(mEnvironment.mWorld->getPlayer().getPlayer()); + MWMechanics::NpcStats NPCstats = MWWorld::Class::get(actor).getNpcStats(actor); + int sameFaction = 0; + if(!NPCstats.mFactionRank.empty()) + { + std::string NPCFaction = NPCstats.mFactionRank.begin()->first; + if(PCstats.mFactionRank.find(NPCFaction) != PCstats.mFactionRank.end()) sameFaction = 1; + } + if(!selectCompare(comp,sameFaction,select.i)) return false; + } break; case 48://Detected @@ -193,7 +203,6 @@ namespace MWDialogue break; case 50://choice - if(choice) { if(!selectCompare(comp,mChoice,select.i)) return false; @@ -447,9 +456,6 @@ namespace MWDialogue if (toLower (info.actor)!=MWWorld::Class::get (actor).getId (actor)) return false; - //PC Faction - if(!info.pcFaction.empty()) return false; - //NPC race if (!info.race.empty()) { @@ -495,8 +501,8 @@ namespace MWDialogue // TODO check player faction if(!info.pcFaction.empty()) { - MWMechanics::NpcStats stats = MWWorld::Class::get(actor).getNpcStats(mEnvironment.mWorld->getPlayer().getPlayer()); - std::map::iterator it = stats.mFactionRank.find(info.npcFaction); + MWMechanics::NpcStats stats = MWWorld::Class::get(mEnvironment.mWorld->getPlayer().getPlayer()).getNpcStats(mEnvironment.mWorld->getPlayer().getPlayer()); + std::map::iterator it = stats.mFactionRank.find(info.pcFaction); if(it!=stats.mFactionRank.end()) { //check rank @@ -816,7 +822,7 @@ namespace MWDialogue std::string DialogueManager::getFaction() { std::string factionID(""); - MWMechanics::NpcStats stats = MWWorld::Class::get(mActor).getNpcStats(mEnvironment.mWorld->getPlayer().getPlayer()); + MWMechanics::NpcStats stats = MWWorld::Class::get(mActor).getNpcStats(mActor); if(stats.mFactionRank.empty()) { std::cout << "No faction for this actor!"; diff --git a/apps/openmw/mwscript/docs/vmformat.txt b/apps/openmw/mwscript/docs/vmformat.txt index 27b426d0e..2b20b973c 100644 --- a/apps/openmw/mwscript/docs/vmformat.txt +++ b/apps/openmw/mwscript/docs/vmformat.txt @@ -24,7 +24,8 @@ op 0x20007: PlayAnim, explicit reference op 0x20008: LoopAnim op 0x20009: LoopAnim, explicit reference op 0x2000a: Choice -opcodes 0x2000b-0x3ffff unused +op 0x2000b: PCRaiseRank +opcodes 0x2000c-0x3ffff unused Segment 4: (not implemented yet) @@ -127,5 +128,5 @@ op 0x2000141: GetWaterLevel op 0x2000142: SetWaterLevel op 0x2000143: ModWaterLevel op 0x2000144: ToggleWater, twa -op 0x2000145: PCRaiseRank +op 0x2000145: ModDisposition opcodes 0x2000146-0x3ffffff unused diff --git a/apps/openmw/mwscript/statsextensions.cpp b/apps/openmw/mwscript/statsextensions.cpp index be31321e9..05db10301 100644 --- a/apps/openmw/mwscript/statsextensions.cpp +++ b/apps/openmw/mwscript/statsextensions.cpp @@ -299,27 +299,54 @@ namespace MWScript } }; - class OpPCRaiseRank : public Interpreter::Opcode0 + class OpPCRaiseRank : public Interpreter::Opcode1 { public: - virtual void execute (Interpreter::Runtime& runtime) + 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()); - - std::string factionID = context.getEnvironment().mDialogueManager->getFaction(); + if(arg0==0) + { + std::cout << "slurpppp"; + factionID = context.getEnvironment().mDialogueManager->getFaction(); + } + else + { + factionID = runtime.getStringLiteral (runtime[0].mInteger); + runtime.pop(); + } if(factionID != "") { std::cout << "raiserank!!!!!"; MWWorld::Ptr player = context.getEnvironment().mWorld->getPlayer().getPlayer(); - MWWorld::Class::get(player).getNpcStats(player).mFactionRank[factionID] = 1; + if(MWWorld::Class::get(player).getNpcStats(player).mFactionRank.find(factionID) == MWWorld::Class::get(player).getNpcStats(player).mFactionRank.end()) + { + MWWorld::Class::get(player).getNpcStats(player).mFactionRank[factionID] = 1; + } + 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: + + virtual void execute (Interpreter::Runtime& runtime) + { + + } + }; + const int numberOfAttributes = 8; const int opcodeGetAttribute = 0x2000027; @@ -351,7 +378,8 @@ namespace MWScript const int opcodeModSkill = 0x20000fa; const int opcodeModSkillExplicit = 0x2000115; //const int opcodePCJoinFaction = 0x2000141; - const int opcodePCRaiseRank = 0x2000145; + const int opcodePCRaiseRank = 0x2000b; + const int opcodeModDisposition = 0x2000145; void registerExtensions (Compiler::Extensions& extensions) { @@ -424,8 +452,8 @@ namespace MWScript opcodeModSkill+i, opcodeModSkillExplicit+i); } //extensions.registerInstruction("PCJoinFaction","S",opcodePCJoinFaction); - std::cout << "rgister raiserank"; - extensions.registerInstruction("pcraiserank","",opcodePCRaiseRank); + extensions.registerInstruction("pcraiserank","/S",opcodePCRaiseRank); + extensions.registerInstruction("moddisposition","l",opcodeModDisposition); } void installOpcodes (Interpreter::Interpreter& interpreter) @@ -483,7 +511,8 @@ namespace MWScript } //interpreter.installSegment5(opcodePCJoinFaction,new OpPCJoinFaction); - interpreter.installSegment5(opcodePCRaiseRank,new OpPCRaiseRank); + interpreter.installSegment3(opcodePCRaiseRank,new OpPCRaiseRank); + interpreter.installSegment5(opcodeModDisposition,new OpModDisposition); } } }