fixed lua function getUnitName; added new lua function getUnitDisplayName

This commit is contained in:
titiger 2014-08-09 00:48:04 +02:00
parent e5d2bbbf9e
commit cf5da4d2b3
2 changed files with 31 additions and 0 deletions

View File

@ -1531,6 +1531,12 @@ int ScriptManager::getUnitFaction(int unitId) {
const string ScriptManager::getUnitName(int unitId) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
return world->findUnitById(unitId)->getType()->getName(false);
}
const string ScriptManager::getUnitDisplayName(int unitId) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
return world->getUnitName(unitId);
}
@ -3414,6 +3420,7 @@ int ScriptManager::getUnitFaction(LuaHandle* luaHandle){
return luaArguments.getReturnCount();
}
int ScriptManager::getUnitName(LuaHandle* luaHandle){
LuaArguments luaArguments(luaHandle);
try {
@ -3435,6 +3442,28 @@ int ScriptManager::getUnitName(LuaHandle* luaHandle){
return luaArguments.getReturnCount();
}
int ScriptManager::getUnitDisplayName(LuaHandle* luaHandle){
LuaArguments luaArguments(luaHandle);
try {
const string unitname = thisScriptManager->getUnitDisplayName(luaArguments.getInt(-1));
luaArguments.returnString(unitname);
}
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();
}
int ScriptManager::getResourceAmount(LuaHandle* luaHandle){
LuaArguments luaArguments(luaHandle);
try {

View File

@ -356,6 +356,7 @@ private:
Vec2i getUnitPosition(int unitId);
int getUnitFaction(int unitId);
const string getUnitName(int unitId);
const string getUnitDisplayName(int unitId);
int getResourceAmount(const string &resourceName, int factionIndex);
const string &getLastCreatedUnitName();
int getLastCreatedUnitId();
@ -521,6 +522,7 @@ private:
static int getUnitPosition(LuaHandle* luaHandle);
static int getUnitFaction(LuaHandle* luaHandle);
static int getUnitName(LuaHandle* luaHandle);
static int getUnitDisplayName(LuaHandle* luaHandle);
static int getResourceAmount(LuaHandle* luaHandle);
static int getLastCreatedUnitName(LuaHandle* luaHandle);
static int getLastCreatedUnitId(LuaHandle* luaHandle);