diff --git a/src/game/game.cpp b/src/game/game.cpp index e0d2c65b..7e96bfb8 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -724,6 +724,11 @@ int Game::getGlobalNumber(const string &name) const { return maybeValue != _globalNumbers.end() ? maybeValue->second : 0; } +string Game::getGlobalString(const string &name) const { + auto maybeValue = _globalStrings.find(name); + return maybeValue != _globalStrings.end() ? maybeValue->second : ""; +} + bool Game::getLocalBoolean(uint32_t objectId, int index) const { auto maybeObject = _localBooleans.find(objectId); if (maybeObject == _localBooleans.end()) return false; @@ -752,6 +757,10 @@ void Game::setGlobalNumber(const string &name, int value) { _globalNumbers[name] = value; } +void Game::setGlobalString(const string &name, const string &value) { + _globalStrings[name] = value; +} + void Game::setLocalBoolean(uint32_t objectId, int index, bool value) { _localBooleans[objectId][index] = value; } diff --git a/src/game/game.h b/src/game/game.h index 1aeeb7a0..5f7b6242 100644 --- a/src/game/game.h +++ b/src/game/game.h @@ -112,11 +112,13 @@ public: bool getGlobalBoolean(const std::string &name) const; int getGlobalNumber(const std::string &name) const; + std::string getGlobalString(const std::string &name) const; bool getLocalBoolean(uint32_t objectId, int idx) const; int getLocalNumber(uint32_t objectId, int idx) const; void setGlobalBoolean(const std::string &name, bool value); void setGlobalNumber(const std::string &name, int value); + void setGlobalString(const std::string &name, const std::string &value); void setLocalBoolean(uint32_t objectId, int idx, bool value); void setLocalNumber(uint32_t objectId, int idx, int value); @@ -204,6 +206,7 @@ private: // Globals/locals + std::map _globalStrings; std::map _globalBooleans; std::map _globalNumbers; std::map> _localBooleans; diff --git a/src/game/gui/selectoverlay.cpp b/src/game/gui/selectoverlay.cpp index bf24303c..a58c4f1e 100644 --- a/src/game/gui/selectoverlay.cpp +++ b/src/game/gui/selectoverlay.cpp @@ -101,7 +101,7 @@ bool SelectionOverlay::handleMouseMotion(const SDL_MouseMotionEvent &event) { bool SelectionOverlay::handleMouseButtonDown(const SDL_MouseButtonEvent &event) { if (event.clicks > 1 || - _selectedActionIdx == -1 | + _selectedActionIdx == -1 || _selectedActionIdx >= _actions.size()) return false; shared_ptr area(_game->module()->area()); diff --git a/src/game/script/routines.h b/src/game/script/routines.h index d407d0a8..b117731f 100644 --- a/src/game/script/routines.h +++ b/src/game/script/routines.h @@ -125,14 +125,16 @@ private: // Globals/locals - script::Variable setLocalNumber(const std::vector &args, script::ExecutionContext &ctx); - script::Variable setLocalBoolean(const std::vector &args, script::ExecutionContext &ctx); - script::Variable setGlobalNumber(const std::vector &args, script::ExecutionContext &ctx); - script::Variable setGlobalBoolean(const std::vector &args, script::ExecutionContext &ctx); - script::Variable getLocalNumber(const std::vector &args, script::ExecutionContext &ctx); - script::Variable getLocalBoolean(const std::vector &args, script::ExecutionContext &ctx); - script::Variable getGlobalNumber(const std::vector &args, script::ExecutionContext &ctx); script::Variable getGlobalBoolean(const std::vector &args, script::ExecutionContext &ctx); + script::Variable getGlobalNumber(const std::vector &args, script::ExecutionContext &ctx); + script::Variable getGlobalString(const std::vector &args, script::ExecutionContext &ctx); + script::Variable getLocalBoolean(const std::vector &args, script::ExecutionContext &ctx); + script::Variable getLocalNumber(const std::vector &args, script::ExecutionContext &ctx); + script::Variable setGlobalBoolean(const std::vector &args, script::ExecutionContext &ctx); + script::Variable setGlobalNumber(const std::vector &args, script::ExecutionContext &ctx); + script::Variable setGlobalString(const std::vector &args, script::ExecutionContext &ctx); + script::Variable setLocalBoolean(const std::vector &args, script::ExecutionContext &ctx); + script::Variable setLocalNumber(const std::vector &args, script::ExecutionContext &ctx); // END Globals/locals diff --git a/src/game/script/routines_kotor.cpp b/src/game/script/routines_kotor.cpp index 53c40a24..6caf2f77 100644 --- a/src/game/script/routines_kotor.cpp +++ b/src/game/script/routines_kotor.cpp @@ -199,7 +199,7 @@ void Routines::addKotorRoutines() { add("EffectConfused", Effect, { }); add("EffectFrightened", Effect, { }); add("EffectChoke", Effect, { }); - add("SetGlobalString", Void, { String, String }); + add("SetGlobalString", Void, { String, String }, bind(&Routines::setGlobalString, this, _1, _2)); add("EffectStunned", Effect, { }); add("SetCommandable", Void, { Int, Object }); add("GetCommandable", Int, { Object }); @@ -233,7 +233,7 @@ void Routines::addKotorRoutines() { add("GetFactionMostFrequentClass", Int, { Object }); add("GetFactionWorstAC", Object, { Object, Int }); add("GetFactionBestAC", Object, { Object, Int }); - add("GetGlobalString", String, { String }); + add("GetGlobalString", String, { String }, bind(&Routines::getGlobalString, this, _1, _2)); add("GetListenPatternNumber", Int, { }); add("ActionJumpToObject", Void, { Object, Int }); add("GetWaypointByTag", Object, { String }, bind(&Routines::getWaypointByTag, this, _1, _2)); diff --git a/src/game/script/routines_tsl.cpp b/src/game/script/routines_tsl.cpp index 75c220a9..71cd2f1b 100644 --- a/src/game/script/routines_tsl.cpp +++ b/src/game/script/routines_tsl.cpp @@ -199,7 +199,7 @@ void Routines::addTslRoutines() { add("EffectConfused", Effect, { }); add("EffectFrightened", Effect, { }); add("EffectChoke", Effect, { }); - add("SetGlobalString", Void, { String, String }); + add("SetGlobalString", Void, { String, String }, bind(&Routines::setGlobalString, this, _1, _2)); add("EffectStunned", Effect, { }); add("SetCommandable", Void, { Int, Object }); add("GetCommandable", Int, { Object }); @@ -233,7 +233,7 @@ void Routines::addTslRoutines() { add("GetFactionMostFrequentClass", Int, { Object }); add("GetFactionWorstAC", Object, { Object, Int }); add("GetFactionBestAC", Object, { Object, Int }); - add("GetGlobalString", String, { String }); + add("GetGlobalString", String, { String }, bind(&Routines::getGlobalString, this, _1, _2)); add("GetListenPatternNumber", Int, { }); add("ActionJumpToObject", Void, { Object, Int }); add("GetWaypointByTag", Object, { String }, bind(&Routines::getWaypointByTag, this, _1, _2)); diff --git a/src/game/script/routines_vars.cpp b/src/game/script/routines_vars.cpp index dc939d5f..706e6143 100644 --- a/src/game/script/routines_vars.cpp +++ b/src/game/script/routines_vars.cpp @@ -35,6 +35,10 @@ Variable Routines::getGlobalNumber(const vector &args, ExecutionContex return _game->getGlobalNumber(args[0].strValue); } +Variable Routines::getGlobalString(const vector &args, ExecutionContext &ctx) { + return _game->getGlobalString(args[0].strValue); +} + Variable Routines::getLocalBoolean(const vector &args, ExecutionContext &ctx) { shared_ptr object(getObjectById(args[0].objectId, ctx)); return object ? _game->getLocalBoolean(object->id(), args[1].intValue) : false; @@ -55,6 +59,11 @@ Variable Routines::setGlobalNumber(const vector &args, ExecutionContex return Variable(); } +Variable Routines::setGlobalString(const vector &args, ExecutionContext &ctx) { + _game->setGlobalString(args[0].strValue, args[1].strValue); + return Variable(); +} + Variable Routines::setLocalBoolean(const vector &args, ExecutionContext &ctx) { shared_ptr object(getObjectById(args[0].objectId, ctx)); if (object) {