- added new lua method to get system macro values:

dofile(getSystemMacroValue("$SCENARIO_PATH") .. "unit.ai.class.lua")
This commit is contained in:
Mark Vejvoda
2012-01-05 00:04:55 +00:00
parent 2e6fcb2d4a
commit 6f924b310d
4 changed files with 38 additions and 0 deletions

View File

@@ -175,6 +175,8 @@ void ScriptManager::init(World* world, GameCamera *gameCamera){
luaScript.registerFunction(getGameWon, "gameWon"); luaScript.registerFunction(getGameWon, "gameWon");
luaScript.registerFunction(getSystemMacroValue, "getSystemMacroValue");
luaScript.registerFunction(loadScenario, "loadScenario"); luaScript.registerFunction(loadScenario, "loadScenario");
//load code //load code
@@ -1024,6 +1026,12 @@ int ScriptManager::getUnitCountOfType(int factionIndex, const string &typeName)
return world->getUnitCountOfType(factionIndex, 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) { void ScriptManager::loadScenario(const string &name, bool keepFactions) {
//printf("[%s:%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); //printf("[%s:%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
@@ -1470,6 +1478,12 @@ int ScriptManager::getLastAttackingUnitId(LuaHandle* luaHandle) {
return luaArguments.getReturnCount(); 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){ int ScriptManager::getUnitCount(LuaHandle* luaHandle){
LuaArguments luaArguments(luaHandle); LuaArguments luaArguments(luaHandle);
luaArguments.returnInt(thisScriptManager->getUnitCount(luaArguments.getInt(-1))); luaArguments.returnInt(thisScriptManager->getUnitCount(luaArguments.getInt(-1)));

View File

@@ -271,6 +271,8 @@ private:
bool getGameWon(); bool getGameWon();
const string getSystemMacroValue(const string &key);
void loadScenario(const string &name, bool keepFactions); void loadScenario(const string &name, bool keepFactions);
//callbacks, commands //callbacks, commands
@@ -356,6 +358,8 @@ private:
static int getGameWon(LuaHandle* luaHandle); static int getGameWon(LuaHandle* luaHandle);
static int getSystemMacroValue(LuaHandle* luaHandle);
static int loadScenario(LuaHandle* luaHandle); static int loadScenario(LuaHandle* luaHandle);
}; };

View File

@@ -1082,6 +1082,24 @@ void World::addConsoleTextWoLang(const string &text) {
game->getConsole()->addLine(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) { void World::giveUpgradeCommand(int unitId, const string &upgradeName) {
Unit *unit= findUnitById(unitId); Unit *unit= findUnitById(unitId);
if(unit != NULL) { if(unit != NULL) {

View File

@@ -239,6 +239,8 @@ public:
int getUnitCount(int factionIndex); int getUnitCount(int factionIndex);
int getUnitCountOfType(int factionIndex, const string &typeName); int getUnitCountOfType(int factionIndex, const string &typeName);
const string getSystemMacroValue(const string key);
Game * getGame() { return game; } Game * getGame() { return game; }
const GameSettings * getGameSettings() const; const GameSettings * getGameSettings() const;