mirror of
https://github.com/glest/glest-source.git
synced 2025-08-23 16:32:53 +02:00
- added new lua method to get system macro values:
dofile(getSystemMacroValue("$SCENARIO_PATH") .. "unit.ai.class.lua")
This commit is contained in:
@@ -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)));
|
||||
|
@@ -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);
|
||||
};
|
||||
|
||||
|
@@ -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) {
|
||||
|
@@ -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;
|
||||
|
||||
|
Reference in New Issue
Block a user