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);