feat: Implement global string script routines

This commit is contained in:
Vsevolod Kremianskii 2020-11-16 00:33:26 +07:00
parent cbdbed6d6d
commit 339cf04703
7 changed files with 35 additions and 12 deletions

View file

@ -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;
}

View file

@ -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<std::string, std::string> _globalStrings;
std::map<std::string, bool> _globalBooleans;
std::map<std::string, int> _globalNumbers;
std::map<uint32_t, std::map<int, bool>> _localBooleans;

View file

@ -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> area(_game->module()->area());

View file

@ -125,14 +125,16 @@ private:
// Globals/locals
script::Variable setLocalNumber(const std::vector<script::Variable> &args, script::ExecutionContext &ctx);
script::Variable setLocalBoolean(const std::vector<script::Variable> &args, script::ExecutionContext &ctx);
script::Variable setGlobalNumber(const std::vector<script::Variable> &args, script::ExecutionContext &ctx);
script::Variable setGlobalBoolean(const std::vector<script::Variable> &args, script::ExecutionContext &ctx);
script::Variable getLocalNumber(const std::vector<script::Variable> &args, script::ExecutionContext &ctx);
script::Variable getLocalBoolean(const std::vector<script::Variable> &args, script::ExecutionContext &ctx);
script::Variable getGlobalNumber(const std::vector<script::Variable> &args, script::ExecutionContext &ctx);
script::Variable getGlobalBoolean(const std::vector<script::Variable> &args, script::ExecutionContext &ctx);
script::Variable getGlobalNumber(const std::vector<script::Variable> &args, script::ExecutionContext &ctx);
script::Variable getGlobalString(const std::vector<script::Variable> &args, script::ExecutionContext &ctx);
script::Variable getLocalBoolean(const std::vector<script::Variable> &args, script::ExecutionContext &ctx);
script::Variable getLocalNumber(const std::vector<script::Variable> &args, script::ExecutionContext &ctx);
script::Variable setGlobalBoolean(const std::vector<script::Variable> &args, script::ExecutionContext &ctx);
script::Variable setGlobalNumber(const std::vector<script::Variable> &args, script::ExecutionContext &ctx);
script::Variable setGlobalString(const std::vector<script::Variable> &args, script::ExecutionContext &ctx);
script::Variable setLocalBoolean(const std::vector<script::Variable> &args, script::ExecutionContext &ctx);
script::Variable setLocalNumber(const std::vector<script::Variable> &args, script::ExecutionContext &ctx);
// END Globals/locals

View file

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

View file

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

View file

@ -35,6 +35,10 @@ Variable Routines::getGlobalNumber(const vector<Variable> &args, ExecutionContex
return _game->getGlobalNumber(args[0].strValue);
}
Variable Routines::getGlobalString(const vector<Variable> &args, ExecutionContext &ctx) {
return _game->getGlobalString(args[0].strValue);
}
Variable Routines::getLocalBoolean(const vector<Variable> &args, ExecutionContext &ctx) {
shared_ptr<Object> 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<Variable> &args, ExecutionContex
return Variable();
}
Variable Routines::setGlobalString(const vector<Variable> &args, ExecutionContext &ctx) {
_game->setGlobalString(args[0].strValue, args[1].strValue);
return Variable();
}
Variable Routines::setLocalBoolean(const vector<Variable> &args, ExecutionContext &ctx) {
shared_ptr<Object> object(getObjectById(args[0].objectId, ctx));
if (object) {