From f9bb19fcdc8111ab405cbc8673dbf9c5800b1986 Mon Sep 17 00:00:00 2001 From: gugus Date: Fri, 23 Mar 2012 15:18:09 +0100 Subject: [PATCH 01/13] begining factions --- apps/openmw/mwworld/player.cpp | 53 ++++++++++++++++++++++++++++++++++ apps/openmw/mwworld/player.hpp | 21 ++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/apps/openmw/mwworld/player.cpp b/apps/openmw/mwworld/player.cpp index 5bfb82138c..270ffa55ca 100644 --- a/apps/openmw/mwworld/player.cpp +++ b/apps/openmw/mwworld/player.cpp @@ -89,4 +89,57 @@ namespace MWWorld MWWorld::Class::get (ptr).setStance (ptr, MWWorld::Class::Run, !running); } + + Player::Faction Player::getFaction(std::string faction) + { + for(std::list::iterator it = mFactions.begin(); it != mFactions.end();it++) + { + if(it->name == faction) return *it; + } + //faction was not found->dummy faction + Player::Faction fact; + fact.id = "not found"; + fact.name = "not found"; + fact.rank = -10; + fact.expelled = false; + return fact; + } + + void Player::addFaction(std::string faction) + { + if(getFaction(faction).name == "not found") + { + Player::Faction fact; + const ESM::Faction* eFact = mWorld.getStore().factions.find(faction); + fact.expelled = false; + fact.rank = 0; + fact.name = faction; + fact.id = eFact->id; + mFactions.push_back(fact); + } + } + + int Player::getRank(std::string faction) + { + Player::Faction fact = getFaction(faction); + return fact.rank; + } + + void Player::setRank(std::string faction,int rank) + { + Player::Faction fact = getFaction(faction); + fact.rank = rank; + } + + bool Player::isExpelled(std::string faction) + { + Player::Faction fact = getFaction(faction); + return fact.expelled; + } + + void Player::setExpelled(std::string faction,bool expelled) + { + Player::Faction fact = getFaction(faction); + fact.expelled = expelled; + } } diff --git a/apps/openmw/mwworld/player.hpp b/apps/openmw/mwworld/player.hpp index 01c71da437..8129c4d8ea 100644 --- a/apps/openmw/mwworld/player.hpp +++ b/apps/openmw/mwworld/player.hpp @@ -4,6 +4,7 @@ #include "OgreCamera.h" #include +#include #include "../mwworld/refdata.hpp" #include "../mwworld/ptr.hpp" @@ -20,6 +21,13 @@ namespace MWWorld /// \brief NPC object representing the player and additional player data class Player { + struct Faction + { + std::string id,name; + int rank; + bool expelled; + }; + ESMS::LiveCellRef mPlayer; MWWorld::Ptr::CellStore *mCellStore; MWRender::Player *mRenderer; @@ -29,9 +37,12 @@ namespace MWWorld std::string mRace; std::string mBirthsign; ESM::Class *mClass; + std::list mFactions; bool mAutoMove; int mForwardBackward; + Faction getFaction(std::string faction); + public: Player(MWRender::Player *renderer, const ESM::NPC *player, MWWorld::World& world); @@ -108,6 +119,16 @@ namespace MWWorld void setAutoMove (bool enable); + void addFaction(std::string faction); + + int getRank(std::string faction); + + void setRank(std::string faction,int rank); + + bool isExpelled(std::string faction); + + void setExpelled(std::string faction,bool expelled); + void setLeftRight (int value); void setForwardBackward (int value); From 0c61f0d2942036d52a5703f9c17c968484d08dca Mon Sep 17 00:00:00 2001 From: gugus Date: Wed, 28 Mar 2012 11:45:46 +0200 Subject: [PATCH 02/13] test stuff --- apps/openmw/mwscript/docs/vmformat.txt | 3 +- apps/openmw/mwscript/statsextensions.cpp | 39 +++++++++++++++++ apps/openmw/mwworld/player.cpp | 53 +++++++++++++++++------- apps/openmw/mwworld/player.hpp | 14 ++++--- 4 files changed, 89 insertions(+), 20 deletions(-) diff --git a/apps/openmw/mwscript/docs/vmformat.txt b/apps/openmw/mwscript/docs/vmformat.txt index eab5bf846f..713ac43b06 100644 --- a/apps/openmw/mwscript/docs/vmformat.txt +++ b/apps/openmw/mwscript/docs/vmformat.txt @@ -123,4 +123,5 @@ op 0x200013d: FadeOut op 0x200013e: FadeTo op 0x200013f: GetCurrentWeather op 0x2000140: ChangeWeather -opcodes 0x2000141-0x3ffffff unused +op 0x2000141: OpPCJoinFaction +opcodes 0x2000142-0x3ffffff unused diff --git a/apps/openmw/mwscript/statsextensions.cpp b/apps/openmw/mwscript/statsextensions.cpp index 0e97a39cf4..85ac54348a 100644 --- a/apps/openmw/mwscript/statsextensions.cpp +++ b/apps/openmw/mwscript/statsextensions.cpp @@ -8,6 +8,8 @@ #include #include "../mwworld/class.hpp" +#include "../mwworld/environment.hpp" +#include "../mwworld/player.hpp" #include "../mwmechanics/creaturestats.hpp" #include "../mwmechanics/npcstats.hpp" @@ -280,6 +282,36 @@ namespace MWScript } }; + class OpPCJoinFaction : public Interpreter::Opcode0 + { + public: + + virtual void execute (Interpreter::Runtime& runtime) + { + MWScript::InterpreterContext& context + = static_cast (runtime.getContext()); + + std::string factionID = runtime.getStringLiteral (runtime[0].mInteger); + runtime.pop(); + context.getEnvironment().mWorld->getPlayer().addFaction(factionID); + } + }; + + class OpPCRaiseRank : public Interpreter::Opcode0 + { + public: + + virtual void execute (Interpreter::Runtime& runtime) + { + MWScript::InterpreterContext& context + = static_cast (runtime.getContext()); + + std::string factionID = runtime.getStringLiteral (runtime[0].mInteger); + runtime.pop(); + context.getEnvironment().mWorld->getPlayer().raiseRank(factionID); + } + }; + const int numberOfAttributes = 8; const int opcodeGetAttribute = 0x2000027; @@ -310,6 +342,8 @@ namespace MWScript const int opcodeSetSkillExplicit = 0x20000df; const int opcodeModSkill = 0x20000fa; const int opcodeModSkillExplicit = 0x2000115; + const int opcodePCJoinFaction = 0x2000141; + const int opcodePCRaiseRank = 0x2000142; void registerExtensions (Compiler::Extensions& extensions) { @@ -381,6 +415,8 @@ namespace MWScript extensions.registerInstruction (mod + skills[i], "l", opcodeModSkill+i, opcodeModSkillExplicit+i); } + extensions.registerInstruction("PCJoinFaction","S",opcodePCJoinFaction); + extensions.registerInstruction("PCRaiseRank","S",opcodePCRaiseRank); } void installOpcodes (Interpreter::Interpreter& interpreter) @@ -436,6 +472,9 @@ namespace MWScript interpreter.installSegment5 (opcodeModSkill+i, new OpModSkill (i)); interpreter.installSegment5 (opcodeModSkillExplicit+i, new OpModSkill (i)); } + + interpreter.installSegment5(opcodePCJoinFaction,new OpPCJoinFaction); + interpreter.installSegment5(opcodePCRaiseRank,new OpPCRaiseRank); } } } diff --git a/apps/openmw/mwworld/player.cpp b/apps/openmw/mwworld/player.cpp index 270ffa55ca..518b1d5198 100644 --- a/apps/openmw/mwworld/player.cpp +++ b/apps/openmw/mwworld/player.cpp @@ -90,11 +90,11 @@ namespace MWWorld MWWorld::Class::get (ptr).setStance (ptr, MWWorld::Class::Run, !running); } - Player::Faction Player::getFaction(std::string faction) + Player::Faction Player::getFaction(std::string factionID) { for(std::list::iterator it = mFactions.begin(); it != mFactions.end();it++) { - if(it->name == faction) return *it; + if(it->name == factionID) return *it; } //faction was not found->dummy faction Player::Faction fact; @@ -105,41 +105,66 @@ namespace MWWorld return fact; } - void Player::addFaction(std::string faction) + void Player::addFaction(std::string factionID) { - if(getFaction(faction).name == "not found") + if(getFaction(factionID).name == "not found") { Player::Faction fact; - const ESM::Faction* eFact = mWorld.getStore().factions.find(faction); + const ESM::Faction* eFact = mWorld.getStore().factions.find(factionID); fact.expelled = false; fact.rank = 0; - fact.name = faction; + fact.name = eFact->name; fact.id = eFact->id; mFactions.push_back(fact); } } - int Player::getRank(std::string faction) + int Player::getRank(std::string factionID) { - Player::Faction fact = getFaction(faction); + Player::Faction fact = getFaction(factionID); return fact.rank; } - void Player::setRank(std::string faction,int rank) + void Player::setRank(std::string factionID,int rank) { - Player::Faction fact = getFaction(faction); + Player::Faction fact = getFaction(factionID); fact.rank = rank; } - bool Player::isExpelled(std::string faction) + void Player::raiseRank(std::string factionID) { - Player::Faction fact = getFaction(faction); + if(getFaction(factionID).name == "not found") + { + addFaction(factionID); + setRank(factionID,1); + } + else + { + setRank(factionID,getRank(factionID) + 1); + } + } + + void Player::lowerRank(std::string factionID) + { + if(getFaction(factionID).name == "not found") + { + std::cout << "cannot lower the rank of the player: faction no found. Faction: "<< factionID << std::endl; + } + else + { + setRank(factionID,getRank(factionID) - 1); + } + } + + bool Player::isExpelled(std::string factionID) + { + Player::Faction fact = getFaction(factionID); return fact.expelled; } - void Player::setExpelled(std::string faction,bool expelled) + void Player::setExpelled(std::string factionID,bool expelled) { - Player::Faction fact = getFaction(faction); + Player::Faction fact = getFaction(factionID); fact.expelled = expelled; } } diff --git a/apps/openmw/mwworld/player.hpp b/apps/openmw/mwworld/player.hpp index 8129c4d8ea..628a238266 100644 --- a/apps/openmw/mwworld/player.hpp +++ b/apps/openmw/mwworld/player.hpp @@ -119,15 +119,19 @@ namespace MWWorld void setAutoMove (bool enable); - void addFaction(std::string faction); + void addFaction(std::string factionID); - int getRank(std::string faction); + int getRank(std::string factionID); - void setRank(std::string faction,int rank); + void setRank(std::string factionID,int rank); - bool isExpelled(std::string faction); + void raiseRank(std::string factionID); - void setExpelled(std::string faction,bool expelled); + void lowerRank(std::string factionID); + + bool isExpelled(std::string factionID); + + void setExpelled(std::string factionID,bool expelled); void setLeftRight (int value); From be4af711af3ee7668110b7d838c275432b969bfb Mon Sep 17 00:00:00 2001 From: gugus Date: Tue, 3 Apr 2012 17:30:19 +0200 Subject: [PATCH 03/13] NPC rank was not loaded. Not sure if it's the right way, but it seems to work. --- apps/openmw/mwclass/npc.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index 83a94d27d1..b98df79ef1 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -53,9 +53,14 @@ namespace MWClass // NPC stats if (!ref->base->faction.empty()) { - // TODO research how initial rank is stored. The information in loadnpc.hpp are at - // best very unclear. - data->mNpcStats.mFactionRank[ref->base->faction] = 0; + if(ref->base->npdt52.gold != -10) + { + data->mNpcStats.mFactionRank[ref->base->faction] = ref->base->npdt52.rank; + } + else + { + data->mNpcStats.mFactionRank[ref->base->faction] = ref->base->npdt52.rank; + } } for (int i=0; i<27; ++i) @@ -281,7 +286,7 @@ namespace MWClass void Npc::registerSelf() { boost::shared_ptr instance (new Npc); - + std::cout << "class npc:" << typeid (ESM::NPC).name(); registerClass (typeid (ESM::NPC).name(), instance); } } From a268b89239742ce05f164f0706c8c765aa01ab6e Mon Sep 17 00:00:00 2001 From: gugus Date: Tue, 3 Apr 2012 17:31:41 +0200 Subject: [PATCH 04/13] changed the way NPC faction is checked. Should be the same way for the player. --- apps/openmw/mwdialogue/dialoguemanager.cpp | 23 +++++++++++----------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/apps/openmw/mwdialogue/dialoguemanager.cpp b/apps/openmw/mwdialogue/dialoguemanager.cpp index 50549f4a55..1e6faf2924 100644 --- a/apps/openmw/mwdialogue/dialoguemanager.cpp +++ b/apps/openmw/mwdialogue/dialoguemanager.cpp @@ -39,6 +39,9 @@ #include "../mwscript/interpretercontext.hpp" #include +#include "../mwclass/npc.hpp" +#include "../mwmechanics/npcstats.hpp" + namespace { std::string toLower (const std::string& name) @@ -474,22 +477,18 @@ namespace MWDialogue //NPC faction if (!info.npcFaction.empty()) { - ESMS::LiveCellRef *cellRef = actor.get(); - - if (!cellRef) - return false; - - if (toLower (info.npcFaction)!=toLower (cellRef->base->faction)) - return false; - - //check NPC rank - if(cellRef->base->npdt52.gold != -10) + //MWWorld::Class npcClass = MWWorld::Class::get(actor); + MWMechanics::NpcStats stats = MWWorld::Class::get(actor).getNpcStats(actor); + std::map::iterator it = stats.mFactionRank.find(info.npcFaction); + if(it!=stats.mFactionRank.end()) { - if(cellRef->base->npdt52.rank < info.data.rank) return false; + //check rank + if(it->second < info.data.rank) return false; } else { - if(cellRef->base->npdt12.rank < info.data.rank) return false; + //not in the faction + return false; } } From 2c7c945208789b2ea29a8755608fc212721f3462 Mon Sep 17 00:00:00 2001 From: gugus Date: Wed, 4 Apr 2012 22:13:57 +0200 Subject: [PATCH 05/13] check playerfaction during dialogue --- apps/openmw/mwdialogue/dialoguemanager.cpp | 31 ++++++++++++++++++++++ apps/openmw/mwdialogue/dialoguemanager.hpp | 3 +++ 2 files changed, 34 insertions(+) diff --git a/apps/openmw/mwdialogue/dialoguemanager.cpp b/apps/openmw/mwdialogue/dialoguemanager.cpp index 1e6faf2924..cd7be50316 100644 --- a/apps/openmw/mwdialogue/dialoguemanager.cpp +++ b/apps/openmw/mwdialogue/dialoguemanager.cpp @@ -493,6 +493,21 @@ 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); + if(it!=stats.mFactionRank.end()) + { + //check rank + if(it->second < info.data.rank) return false; + } + else + { + //not in the faction + return false; + } + } //check gender ESMS::LiveCellRef* npc = actor.get(); @@ -655,6 +670,7 @@ namespace MWDialogue void DialogueManager::executeScript(std::string script) { + std::cout << script; std::vector code; if(compile(script,code)) { @@ -796,4 +812,19 @@ namespace MWDialogue mChoiceMap[question] = choice; mIsInChoice = true; } + + std::string DialogueManager::getFaction() + { + std::string factionID(""); + MWMechanics::NpcStats stats = MWWorld::Class::get(mActor).getNpcStats(mEnvironment.mWorld->getPlayer().getPlayer()); + if(stats.mFactionRank.empty()) + { + std::cout << "No faction for this actor!"; + } + else + { + factionID = stats.mFactionRank.begin()->first; + } + return factionID; + } } diff --git a/apps/openmw/mwdialogue/dialoguemanager.hpp b/apps/openmw/mwdialogue/dialoguemanager.hpp index 260d8e3394..d0380fa717 100644 --- a/apps/openmw/mwdialogue/dialoguemanager.hpp +++ b/apps/openmw/mwdialogue/dialoguemanager.hpp @@ -63,6 +63,9 @@ namespace MWDialogue void askQuestion(std::string question,int choice); + ///get the faction of the actor you are talking with + std::string getFaction(); + //calbacks for the GUI void keywordSelected(std::string keyword); void goodbyeSelected(); From aaa5368fe927b093b239862bb7d069c83099f140 Mon Sep 17 00:00:00 2001 From: gugus Date: Wed, 4 Apr 2012 22:14:38 +0200 Subject: [PATCH 06/13] added script instruction pcraiserank. Does not work yet. --- apps/openmw/mwscript/docs/vmformat.txt | 3 ++- apps/openmw/mwscript/statsextensions.cpp | 27 ++++++++++++++++-------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/apps/openmw/mwscript/docs/vmformat.txt b/apps/openmw/mwscript/docs/vmformat.txt index 7ff60a2035..27b426d0e0 100644 --- a/apps/openmw/mwscript/docs/vmformat.txt +++ b/apps/openmw/mwscript/docs/vmformat.txt @@ -127,4 +127,5 @@ op 0x2000141: GetWaterLevel op 0x2000142: SetWaterLevel op 0x2000143: ModWaterLevel op 0x2000144: ToggleWater, twa -opcodes 0x2000145-0x3ffffff unused +op 0x2000145: PCRaiseRank +opcodes 0x2000146-0x3ffffff unused diff --git a/apps/openmw/mwscript/statsextensions.cpp b/apps/openmw/mwscript/statsextensions.cpp index 85ac54348a..be31321e98 100644 --- a/apps/openmw/mwscript/statsextensions.cpp +++ b/apps/openmw/mwscript/statsextensions.cpp @@ -17,6 +17,8 @@ #include "interpretercontext.hpp" #include "ref.hpp" +#include "../mwdialogue/dialoguemanager.hpp" + namespace MWScript { namespace Stats @@ -303,12 +305,18 @@ namespace MWScript virtual void execute (Interpreter::Runtime& runtime) { + std::cout << "try to rais rank..."; MWScript::InterpreterContext& context = static_cast (runtime.getContext()); - - std::string factionID = runtime.getStringLiteral (runtime[0].mInteger); - runtime.pop(); - context.getEnvironment().mWorld->getPlayer().raiseRank(factionID); + + std::string factionID = context.getEnvironment().mDialogueManager->getFaction(); + if(factionID != "") + { + std::cout << "raiserank!!!!!"; + MWWorld::Ptr player = context.getEnvironment().mWorld->getPlayer().getPlayer(); + MWWorld::Class::get(player).getNpcStats(player).mFactionRank[factionID] = 1; + } + std::cout << std::endl; } }; @@ -342,8 +350,8 @@ namespace MWScript const int opcodeSetSkillExplicit = 0x20000df; const int opcodeModSkill = 0x20000fa; const int opcodeModSkillExplicit = 0x2000115; - const int opcodePCJoinFaction = 0x2000141; - const int opcodePCRaiseRank = 0x2000142; + //const int opcodePCJoinFaction = 0x2000141; + const int opcodePCRaiseRank = 0x2000145; void registerExtensions (Compiler::Extensions& extensions) { @@ -415,8 +423,9 @@ namespace MWScript extensions.registerInstruction (mod + skills[i], "l", opcodeModSkill+i, opcodeModSkillExplicit+i); } - extensions.registerInstruction("PCJoinFaction","S",opcodePCJoinFaction); - extensions.registerInstruction("PCRaiseRank","S",opcodePCRaiseRank); + //extensions.registerInstruction("PCJoinFaction","S",opcodePCJoinFaction); + std::cout << "rgister raiserank"; + extensions.registerInstruction("pcraiserank","",opcodePCRaiseRank); } void installOpcodes (Interpreter::Interpreter& interpreter) @@ -473,7 +482,7 @@ namespace MWScript interpreter.installSegment5 (opcodeModSkillExplicit+i, new OpModSkill (i)); } - interpreter.installSegment5(opcodePCJoinFaction,new OpPCJoinFaction); + //interpreter.installSegment5(opcodePCJoinFaction,new OpPCJoinFaction); interpreter.installSegment5(opcodePCRaiseRank,new OpPCRaiseRank); } } From e5b1e27fa6fae0b8f10dbff3e757342acefdbd5c Mon Sep 17 00:00:00 2001 From: gugus Date: Mon, 9 Apr 2012 13:24:19 +0200 Subject: [PATCH 07/13] 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 cd7be50316..b36c9d998e 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 27b426d0e0..2b20b973c4 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 be31321e98..05db103018 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); } } } From 45d11eaf144a160d8a3b3a2fb83e0a1b491a2324 Mon Sep 17 00:00:00 2001 From: gugus Date: Mon, 9 Apr 2012 14:23:12 +0200 Subject: [PATCH 08/13] fixed a bug in the dialogue manager. --- apps/openmw/mwdialogue/dialoguemanager.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwdialogue/dialoguemanager.cpp b/apps/openmw/mwdialogue/dialoguemanager.cpp index b36c9d998e..5dded07b08 100644 --- a/apps/openmw/mwdialogue/dialoguemanager.cpp +++ b/apps/openmw/mwdialogue/dialoguemanager.cpp @@ -112,16 +112,15 @@ namespace switch (world.getGlobalVariableType (name)) { case 's': - - return selectCompare (comp, value, world.getGlobalVariable (name).mShort); + return selectCompare (comp, world.getGlobalVariable (name).mShort, value); case 'l': - return selectCompare (comp, value, world.getGlobalVariable (name).mLong); + return selectCompare (comp, world.getGlobalVariable (name).mLong, value); case 'f': - return selectCompare (comp, value, world.getGlobalVariable (name).mFloat); + return selectCompare (comp, world.getGlobalVariable (name).mFloat, value); case ' ': @@ -282,7 +281,7 @@ namespace MWDialogue { case '1': // function - return true; // TODO implement functions + return true; // Done elsewhere. case '2': // global From aa8418634f8f776a09e19bf141e322505b26ad1f Mon Sep 17 00:00:00 2001 From: gugus Date: Mon, 9 Apr 2012 14:26:53 +0200 Subject: [PATCH 09/13] 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 2b20b973c4..9a5cf8525d 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 05db103018..176f139aa1 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); } } From 6ca212b9e96280cbb671d22b44795ecdc64a6198 Mon Sep 17 00:00:00 2001 From: gugus Date: Mon, 9 Apr 2012 14:30:42 +0200 Subject: [PATCH 10/13] script instruction: PCJoinFaction --- apps/openmw/mwscript/docs/vmformat.txt | 3 +- apps/openmw/mwscript/statsextensions.cpp | 35 ++++++++++++++++++------ 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/apps/openmw/mwscript/docs/vmformat.txt b/apps/openmw/mwscript/docs/vmformat.txt index 9a5cf8525d..30b9f97e79 100644 --- a/apps/openmw/mwscript/docs/vmformat.txt +++ b/apps/openmw/mwscript/docs/vmformat.txt @@ -26,7 +26,8 @@ op 0x20009: LoopAnim, explicit reference op 0x2000a: Choice op 0x2000b: PCRaiseRank op 0x2000c: PCLowerRank -opcodes 0x2000d-0x3ffff unused +op x20000d: PCJoinFaction +opcodes 0x2000e-0x3ffff unused Segment 4: (not implemented yet) diff --git a/apps/openmw/mwscript/statsextensions.cpp b/apps/openmw/mwscript/statsextensions.cpp index 176f139aa1..5b64ee239e 100644 --- a/apps/openmw/mwscript/statsextensions.cpp +++ b/apps/openmw/mwscript/statsextensions.cpp @@ -284,18 +284,36 @@ namespace MWScript } }; - class OpPCJoinFaction : public Interpreter::Opcode0 + class OpPCJoinFaction : public Interpreter::Opcode1 { public: - virtual void execute (Interpreter::Runtime& runtime) + virtual void execute (Interpreter::Runtime& runtime, unsigned int arg0) { + std::string factionID = ""; MWScript::InterpreterContext& context = static_cast (runtime.getContext()); - - std::string factionID = runtime.getStringLiteral (runtime[0].mInteger); - runtime.pop(); - context.getEnvironment().mWorld->getPlayer().addFaction(factionID); + 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()) + { + MWWorld::Class::get(player).getNpcStats(player).mFactionRank[factionID] = 1; + } + else + { + //the player is already in the faction... Throw an exeption? + } + } } }; @@ -329,7 +347,6 @@ namespace MWScript MWWorld::Class::get(player).getNpcStats(player).mFactionRank[factionID] = MWWorld::Class::get(player).getNpcStats(player).mFactionRank[factionID] +1; } } - std::cout << std::endl; } }; @@ -363,7 +380,6 @@ namespace MWScript MWWorld::Class::get(player).getNpcStats(player).mFactionRank[factionID] = MWWorld::Class::get(player).getNpcStats(player).mFactionRank[factionID] -1; } } - std::cout << std::endl; } }; @@ -410,6 +426,7 @@ namespace MWScript //const int opcodePCJoinFaction = 0x2000141; const int opcodePCRaiseRank = 0x2000b; const int opcodePCLowerRank = 0x2000c; + const int opcodePCJoinFaction = 0x2000d; const int opcodeModDisposition = 0x2000145; void registerExtensions (Compiler::Extensions& extensions) @@ -485,6 +502,7 @@ namespace MWScript //extensions.registerInstruction("PCJoinFaction","S",opcodePCJoinFaction); extensions.registerInstruction("pcraiserank","/S",opcodePCRaiseRank); extensions.registerInstruction("pclowerrank","/S",opcodePCLowerRank); + extensions.registerInstruction("pcjoinfaction","/S",opcodePCJoinFaction); extensions.registerInstruction("moddisposition","l",opcodeModDisposition); } @@ -545,6 +563,7 @@ namespace MWScript //interpreter.installSegment5(opcodePCJoinFaction,new OpPCJoinFaction); interpreter.installSegment3(opcodePCRaiseRank,new OpPCRaiseRank); interpreter.installSegment3(opcodePCLowerRank,new OpPCLowerRank); + interpreter.installSegment3(opcodePCJoinFaction,new OpPCJoinFaction); interpreter.installSegment5(opcodeModDisposition,new OpModDisposition); } } From dd9a88cee266f4e91bd77312b3b083c9c9a47ad7 Mon Sep 17 00:00:00 2001 From: gugus Date: Mon, 9 Apr 2012 14:32:07 +0200 Subject: [PATCH 11/13] clean up --- apps/openmw/mwscript/statsextensions.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/apps/openmw/mwscript/statsextensions.cpp b/apps/openmw/mwscript/statsextensions.cpp index 5b64ee239e..27983eca8a 100644 --- a/apps/openmw/mwscript/statsextensions.cpp +++ b/apps/openmw/mwscript/statsextensions.cpp @@ -423,7 +423,7 @@ namespace MWScript const int opcodeSetSkillExplicit = 0x20000df; const int opcodeModSkill = 0x20000fa; const int opcodeModSkillExplicit = 0x2000115; - //const int opcodePCJoinFaction = 0x2000141; + const int opcodePCRaiseRank = 0x2000b; const int opcodePCLowerRank = 0x2000c; const int opcodePCJoinFaction = 0x2000d; @@ -499,7 +499,6 @@ namespace MWScript extensions.registerInstruction (mod + skills[i], "l", opcodeModSkill+i, opcodeModSkillExplicit+i); } - //extensions.registerInstruction("PCJoinFaction","S",opcodePCJoinFaction); extensions.registerInstruction("pcraiserank","/S",opcodePCRaiseRank); extensions.registerInstruction("pclowerrank","/S",opcodePCLowerRank); extensions.registerInstruction("pcjoinfaction","/S",opcodePCJoinFaction); @@ -560,7 +559,6 @@ namespace MWScript interpreter.installSegment5 (opcodeModSkillExplicit+i, new OpModSkill (i)); } - //interpreter.installSegment5(opcodePCJoinFaction,new OpPCJoinFaction); interpreter.installSegment3(opcodePCRaiseRank,new OpPCRaiseRank); interpreter.installSegment3(opcodePCLowerRank,new OpPCLowerRank); interpreter.installSegment3(opcodePCJoinFaction,new OpPCJoinFaction); From 03d6d1fb82faf7dcdd808facfcefb7e2716b8cfc Mon Sep 17 00:00:00 2001 From: gugus Date: Thu, 12 Apr 2012 17:08:57 +0200 Subject: [PATCH 12/13] NPC rank is correctly loaded now. Also corrected a potential bug (i think). --- apps/openmw/mwclass/npc.cpp | 41 ++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index b98df79ef1..43e04ab521 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -55,31 +55,38 @@ namespace MWClass { if(ref->base->npdt52.gold != -10) { - data->mNpcStats.mFactionRank[ref->base->faction] = ref->base->npdt52.rank; + data->mNpcStats.mFactionRank[ref->base->faction] = (int)ref->base->npdt52.rank; } else { - data->mNpcStats.mFactionRank[ref->base->faction] = ref->base->npdt52.rank; + data->mNpcStats.mFactionRank[ref->base->faction] = (int)ref->base->npdt12.rank; } } - for (int i=0; i<27; ++i) - data->mNpcStats.mSkill[i].setBase (ref->base->npdt52.skills[i]); + if(ref->base->npdt52.gold != -10) + { + for (int i=0; i<27; ++i) + data->mNpcStats.mSkill[i].setBase (ref->base->npdt52.skills[i]); - // creature stats - data->mCreatureStats.mAttributes[0].set (ref->base->npdt52.strength); - data->mCreatureStats.mAttributes[1].set (ref->base->npdt52.intelligence); - data->mCreatureStats.mAttributes[2].set (ref->base->npdt52.willpower); - data->mCreatureStats.mAttributes[3].set (ref->base->npdt52.agility); - data->mCreatureStats.mAttributes[4].set (ref->base->npdt52.speed); - data->mCreatureStats.mAttributes[5].set (ref->base->npdt52.endurance); - data->mCreatureStats.mAttributes[6].set (ref->base->npdt52.personality); - data->mCreatureStats.mAttributes[7].set (ref->base->npdt52.luck); - data->mCreatureStats.mDynamic[0].set (ref->base->npdt52.health); - data->mCreatureStats.mDynamic[1].set (ref->base->npdt52.mana); - data->mCreatureStats.mDynamic[2].set (ref->base->npdt52.fatigue); + // creature stats + data->mCreatureStats.mAttributes[0].set (ref->base->npdt52.strength); + data->mCreatureStats.mAttributes[1].set (ref->base->npdt52.intelligence); + data->mCreatureStats.mAttributes[2].set (ref->base->npdt52.willpower); + data->mCreatureStats.mAttributes[3].set (ref->base->npdt52.agility); + data->mCreatureStats.mAttributes[4].set (ref->base->npdt52.speed); + data->mCreatureStats.mAttributes[5].set (ref->base->npdt52.endurance); + data->mCreatureStats.mAttributes[6].set (ref->base->npdt52.personality); + data->mCreatureStats.mAttributes[7].set (ref->base->npdt52.luck); + data->mCreatureStats.mDynamic[0].set (ref->base->npdt52.health); + data->mCreatureStats.mDynamic[1].set (ref->base->npdt52.mana); + data->mCreatureStats.mDynamic[2].set (ref->base->npdt52.fatigue); - data->mCreatureStats.mLevel = ref->base->npdt52.level; + data->mCreatureStats.mLevel = ref->base->npdt52.level; + } + else + { + //TODO: do something with npdt12 maybe:p + } // \todo add initial container content From 7edc5c733ca0f52bcba0025a5dc5244c8e1dff09 Mon Sep 17 00:00:00 2001 From: gugus Date: Thu, 12 Apr 2012 17:29:05 +0200 Subject: [PATCH 13/13] corrected a bug about rank. --- apps/openmw/mwdialogue/dialoguemanager.cpp | 4 ++-- apps/openmw/mwscript/statsextensions.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/openmw/mwdialogue/dialoguemanager.cpp b/apps/openmw/mwdialogue/dialoguemanager.cpp index 1405224991..90f0c0231f 100644 --- a/apps/openmw/mwdialogue/dialoguemanager.cpp +++ b/apps/openmw/mwdialogue/dialoguemanager.cpp @@ -488,7 +488,7 @@ namespace MWDialogue if(it!=stats.mFactionRank.end()) { //check rank - if(it->second < info.data.rank) return false; + if(it->second < (int)info.data.rank) return false; } else { @@ -505,7 +505,7 @@ namespace MWDialogue if(it!=stats.mFactionRank.end()) { //check rank - if(it->second < info.data.rank) return false; + if(it->second < (int)info.data.PCrank) return false; } else { diff --git a/apps/openmw/mwscript/statsextensions.cpp b/apps/openmw/mwscript/statsextensions.cpp index a3c517f8cb..47ae9d13d5 100644 --- a/apps/openmw/mwscript/statsextensions.cpp +++ b/apps/openmw/mwscript/statsextensions.cpp @@ -307,7 +307,7 @@ namespace MWScript 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()) { - MWWorld::Class::get(player).getNpcStats(player).mFactionRank[factionID] = 1; + MWWorld::Class::get(player).getNpcStats(player).mFactionRank[factionID] = 0; } else { @@ -340,7 +340,7 @@ namespace MWScript 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()) { - MWWorld::Class::get(player).getNpcStats(player).mFactionRank[factionID] = 1; + MWWorld::Class::get(player).getNpcStats(player).mFactionRank[factionID] = 0; } else {