diff --git a/apps/openmw/mwbase/world.hpp b/apps/openmw/mwbase/world.hpp index 0be732790..cc625b306 100644 --- a/apps/openmw/mwbase/world.hpp +++ b/apps/openmw/mwbase/world.hpp @@ -136,6 +136,8 @@ namespace MWBase virtual std::vector getGlobals () const = 0; + virtual std::string getCurrentCellName() const = 0; + virtual MWWorld::Ptr getPtr (const std::string& name, bool activeOnly) = 0; ///< Return a pointer to a liveCellRef with the given name. /// \param activeOnly do non search inactive cells. diff --git a/apps/openmw/mwscript/interpretercontext.cpp b/apps/openmw/mwscript/interpretercontext.cpp index 4ea984f9c..cb0e4a7f9 100644 --- a/apps/openmw/mwscript/interpretercontext.cpp +++ b/apps/openmw/mwscript/interpretercontext.cpp @@ -11,10 +11,13 @@ #include "../mwbase/world.hpp" #include "../mwbase/scriptmanager.hpp" #include "../mwbase/windowmanager.hpp" +#include "../mwbase/inputmanager.hpp" #include "../mwworld/class.hpp" #include "../mwworld/player.hpp" +#include "../mwmechanics/npcstats.hpp" + #include "locals.hpp" #include "globalscripts.hpp" @@ -186,7 +189,133 @@ namespace MWScript MWBase::World *world = MWBase::Environment::get().getWorld(); return world->getGlobalVariableType(name); } + + std::string InterpreterContext::getActionBinding(const std::string& action) const + { + std::vector actions = MWBase::Environment::get().getInputManager()->getActionSorting (); + for (std::vector::const_iterator it = actions.begin(); it != actions.end(); ++it) + { + std::string desc = MWBase::Environment::get().getInputManager()->getActionDescription (*it); + if(desc == "") + continue; + if(desc == action) + return MWBase::Environment::get().getInputManager()->getActionBindingName (*it); + } + + return "None"; + } + + std::string InterpreterContext::getNPCName() const + { + ESM::NPC npc = *mReference.get()->mBase; + return npc.mName; + } + + std::string InterpreterContext::getNPCRace() const + { + ESM::NPC npc = *mReference.get()->mBase; + return npc.mRace; + } + + std::string InterpreterContext::getNPCClass() const + { + ESM::NPC npc = *mReference.get()->mBase; + return npc.mClass; + } + + std::string InterpreterContext::getNPCFaction() const + { + ESM::NPC npc = *mReference.get()->mBase; + return npc.mFaction; + } + + std::string InterpreterContext::getNPCRank() const + { + std::map ranks = MWWorld::Class::get (mReference).getNpcStats (mReference).getFactionRanks(); + std::map::const_iterator it = ranks.begin(); + + MWBase::World *world = MWBase::Environment::get().getWorld(); + const MWWorld::ESMStore &store = world->getStore(); + const ESM::Faction *faction = store.get().find(it->first); + + return faction->mRanks[it->second]; + } + + std::string InterpreterContext::getPCName() const + { + MWBase::World *world = MWBase::Environment::get().getWorld(); + ESM::NPC player = *world->getPlayer().getPlayer().get()->mBase; + return player.mName; + } + + std::string InterpreterContext::getPCRace() const + { + MWBase::World *world = MWBase::Environment::get().getWorld(); + ESM::NPC player = *world->getPlayer().getPlayer().get()->mBase; + return player.mRace; + } + + std::string InterpreterContext::getPCClass() const + { + MWBase::World *world = MWBase::Environment::get().getWorld(); + ESM::NPC player = *world->getPlayer().getPlayer().get()->mBase; + return player.mClass; + } + + std::string InterpreterContext::getPCRank() const + { + MWBase::World *world = MWBase::Environment::get().getWorld(); + MWWorld::Ptr player = world->getPlayer().getPlayer(); + + std::string factionId = MWWorld::Class::get (mReference).getNpcStats (mReference).getFactionRanks().begin()->first; + + std::map ranks = MWWorld::Class::get (player).getNpcStats (player).getFactionRanks(); + std::map::const_iterator it = ranks.begin(); + + const MWWorld::ESMStore &store = world->getStore(); + const ESM::Faction *faction = store.get().find(factionId); + + if(it->second < 0 || it->second > 9) // there are only 10 ranks + return ""; + + return faction->mRanks[it->second]; + } + + std::string InterpreterContext::getPCNextRank() const + { + MWBase::World *world = MWBase::Environment::get().getWorld(); + MWWorld::Ptr player = world->getPlayer().getPlayer(); + + std::string factionId = MWWorld::Class::get (mReference).getNpcStats (mReference).getFactionRanks().begin()->first; + + std::map ranks = MWWorld::Class::get (player).getNpcStats (player).getFactionRanks(); + std::map::const_iterator it = ranks.begin(); + + const MWWorld::ESMStore &store = world->getStore(); + const ESM::Faction *faction = store.get().find(factionId); + + if(it->second < 0 || it->second > 9) + return ""; + + if(it->second <= 8) // If player is at max rank, there is no next rank + return faction->mRanks[it->second + 1]; + else + return faction->mRanks[it->second]; + } + + int InterpreterContext::getPCBounty() const + { + MWBase::World *world = MWBase::Environment::get().getWorld(); + MWWorld::Ptr player = world->getPlayer().getPlayer(); + return MWWorld::Class::get (player).getNpcStats (player).getBounty(); + } + + std::string InterpreterContext::getCurrentCellName() const + { + MWBase::World *world = MWBase::Environment::get().getWorld(); + return world->getCurrentCellName(); + } bool InterpreterContext::isScriptRunning (const std::string& name) const { diff --git a/apps/openmw/mwscript/interpretercontext.hpp b/apps/openmw/mwscript/interpretercontext.hpp index 15578aa24..f0b2758d9 100644 --- a/apps/openmw/mwscript/interpretercontext.hpp +++ b/apps/openmw/mwscript/interpretercontext.hpp @@ -79,6 +79,32 @@ namespace MWScript virtual std::vector getGlobals () const; virtual char getGlobalType (const std::string& name) const; + + virtual std::string getActionBinding(const std::string& action) const; + + virtual std::string getNPCName() const; + + virtual std::string getNPCRace() const; + + virtual std::string getNPCClass() const; + + virtual std::string getNPCFaction() const; + + virtual std::string getNPCRank() const; + + virtual std::string getPCName() const; + + virtual std::string getPCRace() const; + + virtual std::string getPCClass() const; + + virtual std::string getPCRank() const; + + virtual std::string getPCNextRank() const; + + virtual int getPCBounty() const; + + virtual std::string getCurrentCellName() const; virtual bool isScriptRunning (const std::string& name) const; diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 88ad917c3..343b5dcfc 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -300,6 +300,44 @@ namespace MWWorld { return mGlobalVariables->getGlobals(); } + + std::string World::getCurrentCellName () const + { + std::string name; + + Ptr::CellStore *cell = mWorldScene->getCurrentCell(); + if (cell->mCell->isExterior()) + { + if (cell->mCell->mName != "") + { + name = cell->mCell->mName; + } + else + { + const ESM::Region* region = + MWBase::Environment::get().getWorld()->getStore().get().search(cell->mCell->mRegion); + if (region) + name = region->mName; + else + { + const ESM::GameSetting *setting = + MWBase::Environment::get().getWorld()->getStore().get().search("sDefaultCellname"); + + if (setting && setting->mType == ESM::VT_String) + name = setting->getString(); + else + name = "Wilderness"; + } + + } + } + else + { + name = cell->mCell->mName; + } + + return name; + } Ptr World::getPtr (const std::string& name, bool activeOnly) { diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index 15b13256a..ba90dd403 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -155,6 +155,8 @@ namespace MWWorld ///< Return ' ', if there is no global variable with this name. virtual std::vector getGlobals () const; + + virtual std::string getCurrentCellName () const; virtual Ptr getPtr (const std::string& name, bool activeOnly); ///< Return a pointer to a liveCellRef with the given name. diff --git a/components/interpreter/context.hpp b/components/interpreter/context.hpp index 2cfc1c03d..bdba7b6af 100644 --- a/components/interpreter/context.hpp +++ b/components/interpreter/context.hpp @@ -53,6 +53,32 @@ namespace Interpreter virtual char getGlobalType (const std::string& name) const = 0; + virtual std::string getActionBinding(const std::string& action) const = 0; + + virtual std::string getNPCName() const = 0; + + virtual std::string getNPCRace() const = 0; + + virtual std::string getNPCClass() const = 0; + + virtual std::string getNPCFaction() const = 0; + + virtual std::string getNPCRank() const = 0; + + virtual std::string getPCName() const = 0; + + virtual std::string getPCRace() const = 0; + + virtual std::string getPCClass() const = 0; + + virtual std::string getPCRank() const = 0; + + virtual std::string getPCNextRank() const = 0; + + virtual int getPCBounty() const = 0; + + virtual std::string getCurrentCellName() const = 0; + virtual bool isScriptRunning (const std::string& name) const = 0; virtual void startScript (const std::string& name) = 0; diff --git a/components/interpreter/defines.cpp b/components/interpreter/defines.cpp index d5e3e3d0d..bd355fd7c 100644 --- a/components/interpreter/defines.cpp +++ b/components/interpreter/defines.cpp @@ -35,10 +35,10 @@ namespace Interpreter{ bool found; if( (found = Check(temp, "actionslideright", &i, &start))){ - retval += "PLACEHOLDER_ACTION_SLIDE_RIGHT"; + retval += context.getActionBinding("#{sRight}"); } else if((found = Check(temp, "actionreadymagic", &i, &start))){ - retval += "PLACEHOLDER_ACTION_READY_MAGIC"; + retval += context.getActionBinding("#{sReady_Magic}"); } else if((found = Check(temp, "actionprevweapon", &i, &start))){ retval += "PLACEHOLDER_ACTION_PREV_WEAPON"; @@ -47,13 +47,13 @@ namespace Interpreter{ retval += "PLACEHOLDER_ACTION_PREV_WEAPON"; } else if((found = Check(temp, "actiontogglerun", &i, &start))){ - retval += "PLACEHOLDER_ACTION_TOGGLE_RUN"; + retval += context.getActionBinding("#{sAuto_Run}"); } else if((found = Check(temp, "actionslideleft", &i, &start))){ - retval += "PLACEHOLDER_ACTION_TOGGLE_RUN"; + retval += context.getActionBinding("#{sLeft}"); } else if((found = Check(temp, "actionreadyitem", &i, &start))){ - retval += "PLACEHOLDER_ACTION_READY_ITEM"; + retval += context.getActionBinding("#{sReady_Weapon}"); } else if((found = Check(temp, "actionprevspell", &i, &start))){ retval += "PLACEHOLDER_ACTION_PREV_SPELL"; @@ -62,31 +62,31 @@ namespace Interpreter{ retval += "PLACEHOLDER_ACTION_NEXT_SPELL"; } else if((found = Check(temp, "actionrestmenu", &i, &start))){ - retval += "PLACEHOLDER_ACTION_REST_MENU"; + retval += context.getActionBinding("#{sRestKey}"); } else if((found = Check(temp, "actionmenumode", &i, &start))){ - retval += "PLACEHOLDER_ACTION_MENU_MODE"; + retval += context.getActionBinding("#{sJournal}"); } else if((found = Check(temp, "actionactivate", &i, &start))){ - retval += "PLACEHOLDER_ACTION_ACTIVATE"; + retval += context.getActionBinding("#{sActivate}"); } else if((found = Check(temp, "actionjournal", &i, &start))){ - retval += "PLACEHOLDER_ACTION_JOURNAL"; + retval += context.getActionBinding("#{sJournal}"); } else if((found = Check(temp, "actionforward", &i, &start))){ - retval += "PLACEHOLDER_ACTION_FORWARD"; + retval += context.getActionBinding("#{sForward}"); } else if((found = Check(temp, "pccrimelevel", &i, &start))){ - retval += "PLACEHOLDER_PC_CRIME_LEVEL"; + retval += std::to_string(context.getPCBounty()); } else if((found = Check(temp, "actioncrouch", &i, &start))){ - retval += "PLACEHOLDER_ACTION_CROUCH"; + retval += context.getActionBinding("#{sCrouch_Sneak}"); } else if((found = Check(temp, "actionjump", &i, &start))){ - retval += "PLACEHOLDER_ACTION_JUMP"; + retval += context.getActionBinding("#{sJump}"); } else if((found = Check(temp, "actionback", &i, &start))){ - retval += "PLACEHOLDER_ACTION_BACK"; + retval += context.getActionBinding("#{sBack}"); } else if((found = Check(temp, "actionuse", &i, &start))){ retval += "PLACEHOLDER_ACTION_USE"; @@ -95,43 +95,43 @@ namespace Interpreter{ retval += "PLACEHOLDER_ACTION_RUN"; } else if((found = Check(temp, "pcclass", &i, &start))){ - retval += "PLACEHOLDER_PC_CLASS"; + retval += context.getPCClass(); } else if((found = Check(temp, "pcrace", &i, &start))){ - retval += "PLACEHOLDER_PC_RACE"; + retval += context.getPCRace(); } else if((found = Check(temp, "pcname", &i, &start))){ - retval += "PLACEHOLDER_PC_NAME"; + retval += context.getPCName(); } else if((found = Check(temp, "cell", &i, &start))){ - retval += "PLACEHOLDER_CELL"; + retval += context.getCurrentCellName(); } else if(eschar == '%'){ // In Dialogue, not messagebox if( (found = Check(temp, "faction", &i, &start))){ - retval += "PLACEHOLDER_FACTION"; + retval += context.getNPCFaction(); } else if((found = Check(temp, "nextpcrank", &i, &start))){ - retval += "PLACEHOLDER_NEXT_PC_RANK"; + retval += context.getPCNextRank(); } else if((found = Check(temp, "pcnextrank", &i, &start))){ - retval += "PLACEHOLDER_PC_NEXT_RANK"; + retval += context.getPCNextRank(); } else if((found = Check(temp, "pcrank", &i, &start))){ - retval += "PLACEHOLDER_PC_RANK"; + retval += context.getPCRank(); } else if((found = Check(temp, "rank", &i, &start))){ - retval += "PLACEHOLDER_RANK"; + retval += context.getNPCRank(); } else if((found = Check(temp, "class", &i, &start))){ - retval += "PLACEHOLDER_CLASS"; + retval += context.getNPCClass(); } else if((found = Check(temp, "race", &i, &start))){ - retval += "PLACEHOLDER_RACE"; + retval += context.getNPCRace(); } else if((found = Check(temp, "name", &i, &start))){ - retval += "PLACEHOLDER_NAME"; + retval += context.getNPCName(); } } else if(eschar == '^') { // In messagebox, not dialogue @@ -145,13 +145,13 @@ namespace Interpreter{ /* uses pc in messageboxes */ else if((found = Check(temp, "class", &i, &start))){ - retval += "PLACEHOLDER_CLASS"; + retval += context.getPCClass(); } else if((found = Check(temp, "race", &i, &start))){ - retval += "PLACEHOLDER_RACE"; + retval += context.getPCRace(); } else if((found = Check(temp, "name", &i, &start))){ - retval += "PLACEHOLDER_NAME"; + retval += context.getPCName(); } } diff --git a/components/interpreter/defines.hpp b/components/interpreter/defines.hpp index 731284661..4cfba21ea 100644 --- a/components/interpreter/defines.hpp +++ b/components/interpreter/defines.hpp @@ -1,5 +1,5 @@ -#ifndef GAME_MWMECHANICS_DEFINES_H -#define GAME_MWMECHANICS_DEFINES_H +#ifndef INTERPRETER_DEFINES_H_INCLUDED +#define INTERPRETER_DEFINES_H_INCLUDED #include #include "context.hpp"