diff --git a/source/glest_game/game/script_manager.cpp b/source/glest_game/game/script_manager.cpp index e6dd2dc6c..a45bb94d2 100644 --- a/source/glest_game/game/script_manager.cpp +++ b/source/glest_game/game/script_manager.cpp @@ -175,6 +175,8 @@ void ScriptManager::init(World* world, GameCamera *gameCamera){ luaScript.registerFunction(getGameWon, "gameWon"); + luaScript.registerFunction(getSystemMacroValue, "getSystemMacroValue"); + luaScript.registerFunction(loadScenario, "loadScenario"); //load code @@ -1024,6 +1026,12 @@ int ScriptManager::getUnitCountOfType(int factionIndex, const string &typeName) return world->getUnitCountOfType(factionIndex, typeName); } +const string ScriptManager::getSystemMacroValue(const string &key) { + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + ScriptManager_STREFLOP_Wrapper streflopWrapper; + return world->getSystemMacroValue(key); +} + void ScriptManager::loadScenario(const string &name, bool keepFactions) { //printf("[%s:%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); @@ -1470,6 +1478,12 @@ int ScriptManager::getLastAttackingUnitId(LuaHandle* luaHandle) { return luaArguments.getReturnCount(); } +int ScriptManager::getSystemMacroValue(LuaHandle* luaHandle) { + LuaArguments luaArguments(luaHandle); + luaArguments.returnString(thisScriptManager->getSystemMacroValue(luaArguments.getString(-1))); + return luaArguments.getReturnCount(); +} + int ScriptManager::getUnitCount(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); luaArguments.returnInt(thisScriptManager->getUnitCount(luaArguments.getInt(-1))); diff --git a/source/glest_game/game/script_manager.h b/source/glest_game/game/script_manager.h index 0e68c3821..7bd8cc4db 100644 --- a/source/glest_game/game/script_manager.h +++ b/source/glest_game/game/script_manager.h @@ -271,6 +271,8 @@ private: bool getGameWon(); + const string getSystemMacroValue(const string &key); + void loadScenario(const string &name, bool keepFactions); //callbacks, commands @@ -356,6 +358,8 @@ private: static int getGameWon(LuaHandle* luaHandle); + static int getSystemMacroValue(LuaHandle* luaHandle); + static int loadScenario(LuaHandle* luaHandle); }; diff --git a/source/glest_game/world/world.cpp b/source/glest_game/world/world.cpp index db230e286..39fbfc872 100644 --- a/source/glest_game/world/world.cpp +++ b/source/glest_game/world/world.cpp @@ -1082,6 +1082,24 @@ void World::addConsoleTextWoLang(const string &text) { game->getConsole()->addLine(text); } +const string World::getSystemMacroValue(const string key) { + string result = ""; + + result = key; + bool tagApplied = Properties::applyTagsToValue(result); + if(tagApplied == false) { + result = ""; + + if(key == "$SCENARIO_PATH") { + result = extractDirectoryPathFromFile(game->getGameSettings()->getScenarioDir()); + } + } + + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("system macro key [%s] returning [%s]\n",key.c_str(),result.c_str()); + + return result; +} + void World::giveUpgradeCommand(int unitId, const string &upgradeName) { Unit *unit= findUnitById(unitId); if(unit != NULL) { diff --git a/source/glest_game/world/world.h b/source/glest_game/world/world.h index 47138b40b..bd409f673 100644 --- a/source/glest_game/world/world.h +++ b/source/glest_game/world/world.h @@ -239,6 +239,8 @@ public: int getUnitCount(int factionIndex); int getUnitCountOfType(int factionIndex, const string &typeName); + const string getSystemMacroValue(const string key); + Game * getGame() { return game; } const GameSettings * getGameSettings() const;