implemented all text defines except a few for keybindings that don't exist yet

This commit is contained in:
Tom Mason 2012-12-21 18:09:31 +00:00
parent f2c6907244
commit 8ac8fdff47
8 changed files with 254 additions and 31 deletions

View file

@ -136,6 +136,8 @@ namespace MWBase
virtual std::vector<std::string> getGlobals () const = 0; virtual std::vector<std::string> getGlobals () const = 0;
virtual std::string getCurrentCellName() const = 0;
virtual MWWorld::Ptr getPtr (const std::string& name, bool activeOnly) = 0; virtual MWWorld::Ptr getPtr (const std::string& name, bool activeOnly) = 0;
///< Return a pointer to a liveCellRef with the given name. ///< Return a pointer to a liveCellRef with the given name.
/// \param activeOnly do non search inactive cells. /// \param activeOnly do non search inactive cells.

View file

@ -11,10 +11,13 @@
#include "../mwbase/world.hpp" #include "../mwbase/world.hpp"
#include "../mwbase/scriptmanager.hpp" #include "../mwbase/scriptmanager.hpp"
#include "../mwbase/windowmanager.hpp" #include "../mwbase/windowmanager.hpp"
#include "../mwbase/inputmanager.hpp"
#include "../mwworld/class.hpp" #include "../mwworld/class.hpp"
#include "../mwworld/player.hpp" #include "../mwworld/player.hpp"
#include "../mwmechanics/npcstats.hpp"
#include "locals.hpp" #include "locals.hpp"
#include "globalscripts.hpp" #include "globalscripts.hpp"
@ -186,7 +189,133 @@ namespace MWScript
MWBase::World *world = MWBase::Environment::get().getWorld(); MWBase::World *world = MWBase::Environment::get().getWorld();
return world->getGlobalVariableType(name); return world->getGlobalVariableType(name);
} }
std::string InterpreterContext::getActionBinding(const std::string& action) const
{
std::vector<int> actions = MWBase::Environment::get().getInputManager()->getActionSorting ();
for (std::vector<int>::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<ESM::NPC>()->mBase;
return npc.mName;
}
std::string InterpreterContext::getNPCRace() const
{
ESM::NPC npc = *mReference.get<ESM::NPC>()->mBase;
return npc.mRace;
}
std::string InterpreterContext::getNPCClass() const
{
ESM::NPC npc = *mReference.get<ESM::NPC>()->mBase;
return npc.mClass;
}
std::string InterpreterContext::getNPCFaction() const
{
ESM::NPC npc = *mReference.get<ESM::NPC>()->mBase;
return npc.mFaction;
}
std::string InterpreterContext::getNPCRank() const
{
std::map<std::string, int> ranks = MWWorld::Class::get (mReference).getNpcStats (mReference).getFactionRanks();
std::map<std::string, int>::const_iterator it = ranks.begin();
MWBase::World *world = MWBase::Environment::get().getWorld();
const MWWorld::ESMStore &store = world->getStore();
const ESM::Faction *faction = store.get<ESM::Faction>().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<ESM::NPC>()->mBase;
return player.mName;
}
std::string InterpreterContext::getPCRace() const
{
MWBase::World *world = MWBase::Environment::get().getWorld();
ESM::NPC player = *world->getPlayer().getPlayer().get<ESM::NPC>()->mBase;
return player.mRace;
}
std::string InterpreterContext::getPCClass() const
{
MWBase::World *world = MWBase::Environment::get().getWorld();
ESM::NPC player = *world->getPlayer().getPlayer().get<ESM::NPC>()->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<std::string, int> ranks = MWWorld::Class::get (player).getNpcStats (player).getFactionRanks();
std::map<std::string, int>::const_iterator it = ranks.begin();
const MWWorld::ESMStore &store = world->getStore();
const ESM::Faction *faction = store.get<ESM::Faction>().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<std::string, int> ranks = MWWorld::Class::get (player).getNpcStats (player).getFactionRanks();
std::map<std::string, int>::const_iterator it = ranks.begin();
const MWWorld::ESMStore &store = world->getStore();
const ESM::Faction *faction = store.get<ESM::Faction>().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 bool InterpreterContext::isScriptRunning (const std::string& name) const
{ {

View file

@ -79,6 +79,32 @@ namespace MWScript
virtual std::vector<std::string> getGlobals () const; virtual std::vector<std::string> getGlobals () const;
virtual char getGlobalType (const std::string& name) 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; virtual bool isScriptRunning (const std::string& name) const;

View file

@ -300,6 +300,44 @@ namespace MWWorld
{ {
return mGlobalVariables->getGlobals(); 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<ESM::Region>().search(cell->mCell->mRegion);
if (region)
name = region->mName;
else
{
const ESM::GameSetting *setting =
MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().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) Ptr World::getPtr (const std::string& name, bool activeOnly)
{ {

View file

@ -155,6 +155,8 @@ namespace MWWorld
///< Return ' ', if there is no global variable with this name. ///< Return ' ', if there is no global variable with this name.
virtual std::vector<std::string> getGlobals () const; virtual std::vector<std::string> getGlobals () const;
virtual std::string getCurrentCellName () const;
virtual Ptr getPtr (const std::string& name, bool activeOnly); virtual Ptr getPtr (const std::string& name, bool activeOnly);
///< Return a pointer to a liveCellRef with the given name. ///< Return a pointer to a liveCellRef with the given name.

View file

@ -53,6 +53,32 @@ namespace Interpreter
virtual char getGlobalType (const std::string& name) const = 0; 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 bool isScriptRunning (const std::string& name) const = 0;
virtual void startScript (const std::string& name) = 0; virtual void startScript (const std::string& name) = 0;

View file

@ -35,10 +35,10 @@ namespace Interpreter{
bool found; bool found;
if( (found = Check(temp, "actionslideright", &i, &start))){ if( (found = Check(temp, "actionslideright", &i, &start))){
retval += "PLACEHOLDER_ACTION_SLIDE_RIGHT"; retval += context.getActionBinding("#{sRight}");
} }
else if((found = Check(temp, "actionreadymagic", &i, &start))){ 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))){ else if((found = Check(temp, "actionprevweapon", &i, &start))){
retval += "PLACEHOLDER_ACTION_PREV_WEAPON"; retval += "PLACEHOLDER_ACTION_PREV_WEAPON";
@ -47,13 +47,13 @@ namespace Interpreter{
retval += "PLACEHOLDER_ACTION_PREV_WEAPON"; retval += "PLACEHOLDER_ACTION_PREV_WEAPON";
} }
else if((found = Check(temp, "actiontogglerun", &i, &start))){ 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))){ 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))){ 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))){ else if((found = Check(temp, "actionprevspell", &i, &start))){
retval += "PLACEHOLDER_ACTION_PREV_SPELL"; retval += "PLACEHOLDER_ACTION_PREV_SPELL";
@ -62,31 +62,31 @@ namespace Interpreter{
retval += "PLACEHOLDER_ACTION_NEXT_SPELL"; retval += "PLACEHOLDER_ACTION_NEXT_SPELL";
} }
else if((found = Check(temp, "actionrestmenu", &i, &start))){ 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))){ 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))){ else if((found = Check(temp, "actionactivate", &i, &start))){
retval += "PLACEHOLDER_ACTION_ACTIVATE"; retval += context.getActionBinding("#{sActivate}");
} }
else if((found = Check(temp, "actionjournal", &i, &start))){ else if((found = Check(temp, "actionjournal", &i, &start))){
retval += "PLACEHOLDER_ACTION_JOURNAL"; retval += context.getActionBinding("#{sJournal}");
} }
else if((found = Check(temp, "actionforward", &i, &start))){ else if((found = Check(temp, "actionforward", &i, &start))){
retval += "PLACEHOLDER_ACTION_FORWARD"; retval += context.getActionBinding("#{sForward}");
} }
else if((found = Check(temp, "pccrimelevel", &i, &start))){ 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))){ 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))){ else if((found = Check(temp, "actionjump", &i, &start))){
retval += "PLACEHOLDER_ACTION_JUMP"; retval += context.getActionBinding("#{sJump}");
} }
else if((found = Check(temp, "actionback", &i, &start))){ else if((found = Check(temp, "actionback", &i, &start))){
retval += "PLACEHOLDER_ACTION_BACK"; retval += context.getActionBinding("#{sBack}");
} }
else if((found = Check(temp, "actionuse", &i, &start))){ else if((found = Check(temp, "actionuse", &i, &start))){
retval += "PLACEHOLDER_ACTION_USE"; retval += "PLACEHOLDER_ACTION_USE";
@ -95,43 +95,43 @@ namespace Interpreter{
retval += "PLACEHOLDER_ACTION_RUN"; retval += "PLACEHOLDER_ACTION_RUN";
} }
else if((found = Check(temp, "pcclass", &i, &start))){ else if((found = Check(temp, "pcclass", &i, &start))){
retval += "PLACEHOLDER_PC_CLASS"; retval += context.getPCClass();
} }
else if((found = Check(temp, "pcrace", &i, &start))){ else if((found = Check(temp, "pcrace", &i, &start))){
retval += "PLACEHOLDER_PC_RACE"; retval += context.getPCRace();
} }
else if((found = Check(temp, "pcname", &i, &start))){ else if((found = Check(temp, "pcname", &i, &start))){
retval += "PLACEHOLDER_PC_NAME"; retval += context.getPCName();
} }
else if((found = Check(temp, "cell", &i, &start))){ else if((found = Check(temp, "cell", &i, &start))){
retval += "PLACEHOLDER_CELL"; retval += context.getCurrentCellName();
} }
else if(eschar == '%'){ // In Dialogue, not messagebox else if(eschar == '%'){ // In Dialogue, not messagebox
if( (found = Check(temp, "faction", &i, &start))){ if( (found = Check(temp, "faction", &i, &start))){
retval += "PLACEHOLDER_FACTION"; retval += context.getNPCFaction();
} }
else if((found = Check(temp, "nextpcrank", &i, &start))){ else if((found = Check(temp, "nextpcrank", &i, &start))){
retval += "PLACEHOLDER_NEXT_PC_RANK"; retval += context.getPCNextRank();
} }
else if((found = Check(temp, "pcnextrank", &i, &start))){ else if((found = Check(temp, "pcnextrank", &i, &start))){
retval += "PLACEHOLDER_PC_NEXT_RANK"; retval += context.getPCNextRank();
} }
else if((found = Check(temp, "pcrank", &i, &start))){ else if((found = Check(temp, "pcrank", &i, &start))){
retval += "PLACEHOLDER_PC_RANK"; retval += context.getPCRank();
} }
else if((found = Check(temp, "rank", &i, &start))){ else if((found = Check(temp, "rank", &i, &start))){
retval += "PLACEHOLDER_RANK"; retval += context.getNPCRank();
} }
else if((found = Check(temp, "class", &i, &start))){ else if((found = Check(temp, "class", &i, &start))){
retval += "PLACEHOLDER_CLASS"; retval += context.getNPCClass();
} }
else if((found = Check(temp, "race", &i, &start))){ else if((found = Check(temp, "race", &i, &start))){
retval += "PLACEHOLDER_RACE"; retval += context.getNPCRace();
} }
else if((found = Check(temp, "name", &i, &start))){ else if((found = Check(temp, "name", &i, &start))){
retval += "PLACEHOLDER_NAME"; retval += context.getNPCName();
} }
} }
else if(eschar == '^') { // In messagebox, not dialogue else if(eschar == '^') { // In messagebox, not dialogue
@ -145,13 +145,13 @@ namespace Interpreter{
/* uses pc in messageboxes */ /* uses pc in messageboxes */
else if((found = Check(temp, "class", &i, &start))){ else if((found = Check(temp, "class", &i, &start))){
retval += "PLACEHOLDER_CLASS"; retval += context.getPCClass();
} }
else if((found = Check(temp, "race", &i, &start))){ else if((found = Check(temp, "race", &i, &start))){
retval += "PLACEHOLDER_RACE"; retval += context.getPCRace();
} }
else if((found = Check(temp, "name", &i, &start))){ else if((found = Check(temp, "name", &i, &start))){
retval += "PLACEHOLDER_NAME"; retval += context.getPCName();
} }
} }

View file

@ -1,5 +1,5 @@
#ifndef GAME_MWMECHANICS_DEFINES_H #ifndef INTERPRETER_DEFINES_H_INCLUDED
#define GAME_MWMECHANICS_DEFINES_H #define INTERPRETER_DEFINES_H_INCLUDED
#include <string> #include <string>
#include "context.hpp" #include "context.hpp"