From 37494a9c3770225f453dbc6d9b16569daee7fbcd Mon Sep 17 00:00:00 2001 From: SoftCoder Date: Sat, 4 Jan 2014 09:34:49 -0800 Subject: [PATCH] - added new LUA method getFactionPlayerType --- source/glest_game/game/script_manager.cpp | 29 +++++++++++++++++++++++ source/glest_game/game/script_manager.h | 3 +++ 2 files changed, 32 insertions(+) diff --git a/source/glest_game/game/script_manager.cpp b/source/glest_game/game/script_manager.cpp index 578eba7a..6e929042 100644 --- a/source/glest_game/game/script_manager.cpp +++ b/source/glest_game/game/script_manager.cpp @@ -393,6 +393,8 @@ void ScriptManager::init(World* world, GameCamera *gameCamera, const XmlNode *ro luaScript.registerFunction(storeSaveGameData, "storeSaveGameData"); luaScript.registerFunction(loadSaveGameData, "loadSaveGameData"); + luaScript.registerFunction(getFactionPlayerType, "getFactionPlayerType"); + //load code for(int i= 0; igetScriptCount(); ++i){ const Script* script= scenario->getScript(i); @@ -1999,6 +2001,13 @@ string ScriptManager::loadSaveGameData(string name) { return value; } +ControlType ScriptManager::getFactionPlayerType(int factionIndex) { + Faction *faction = world->getFaction(factionIndex); + if(faction != NULL) { + return faction->getControlType(); + } + return ctClosed; +} // ========================== lua callbacks =============================================== int ScriptManager::showMessage(LuaHandle* luaHandle){ @@ -4892,6 +4901,26 @@ int ScriptManager::loadSaveGameData(LuaHandle* luaHandle) { return luaArguments.getReturnCount(); } +int ScriptManager::getFactionPlayerType(LuaHandle* luaHandle) { + LuaArguments luaArguments(luaHandle); + try { + luaArguments.returnInt(thisScriptManager->getFactionPlayerType(luaArguments.getInt(-1))); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nThe game may no longer be stable!\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error",-1,-1,true)); + thisScriptManager->onMessageBoxOk(false); + } + + return luaArguments.getReturnCount(); + +} void ScriptManager::saveGame(XmlNode *rootNode) { std::map mapTagReplacements; diff --git a/source/glest_game/game/script_manager.h b/source/glest_game/game/script_manager.h index 7a5ba8a3..c5b42fa3 100644 --- a/source/glest_game/game/script_manager.h +++ b/source/glest_game/game/script_manager.h @@ -423,6 +423,7 @@ private: void storeSaveGameData(string name, string value); string loadSaveGameData(string name); + ControlType getFactionPlayerType(int factionIndex); // ----------------------------------------------------------------------- //callbacks, commands @@ -591,6 +592,8 @@ private: static int storeSaveGameData(LuaHandle* luaHandle); static int loadSaveGameData(LuaHandle* luaHandle); + + static int getFactionPlayerType(LuaHandle* luaHandle); }; }}//end namespace