... another try to submit useful Lua methods:
Index: source/glest_game/game/script_manager.cpp
===================================================================
--- source/glest_game/game/script_manager.cpp (revision 3330)
+++ source/glest_game/game/script_manager.cpp (working copy)
@@ -309,6 +309,7 @@
luaScript.registerFunction(setUnitPosition, "setUnitPosition");
luaScript.registerFunction(getUnitFaction, "unitFaction");
+ luaScript.registerFunction(getUnitName, "unitName");
luaScript.registerFunction(getResourceAmount, "resourceAmount");
luaScript.registerFunction(getLastCreatedUnitName, "lastCreatedUnitName");
@@ -1258,6 +1259,11 @@
ScriptManager_STREFLOP_Wrapper streflopWrapper;
return world->getUnitFactionIndex(unitId);
}
+const string ScriptManager::getUnitName(int unitId) {
+ 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->getUnitName(unitId);
+}
int ScriptManager::getResourceAmount(const string &resourceName, int factionIndex) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
@@ -1781,6 +1787,12 @@
luaArguments.returnInt(factionIndex);
return luaArguments.getReturnCount();
}
+int ScriptManager::getUnitName(LuaHandle* luaHandle){
+ LuaArguments luaArguments(luaHandle);
+ const string unitname = thisScriptManager->getUnitName(luaArguments.getInt(-1));
+ luaArguments.returnString(unitname);
+ return luaArguments.getReturnCount();
+}
int ScriptManager::getResourceAmount(LuaHandle* luaHandle){
LuaArguments luaArguments(luaHandle);
Index: source/glest_game/game/script_manager.h
===================================================================
--- source/glest_game/game/script_manager.h (revision 3330)
+++ source/glest_game/game/script_manager.h (working copy)
@@ -304,6 +304,7 @@
Vec2i getStartLocation(int factionIndex);
Vec2i getUnitPosition(int unitId);
int getUnitFaction(int unitId);
+ const string getUnitName(int unitId);
int getResourceAmount(const string &resourceName, int factionIndex);
const string &getLastCreatedUnitName();
int getLastCreatedUnitId();
@@ -410,6 +411,7 @@
static int getStartLocation(LuaHandle* luaHandle);
static int getUnitPosition(LuaHandle* luaHandle);
static int getUnitFaction(LuaHandle* luaHandle);
+ static int getUnitName(LuaHandle* luaHandle);
static int getResourceAmount(LuaHandle* luaHandle);
static int getLastCreatedUnitName(LuaHandle* luaHandle);
static int getLastCreatedUnitId(LuaHandle* luaHandle);
Index: source/glest_game/world/world.cpp
===================================================================
--- source/glest_game/world/world.cpp (revision 3330)
+++ source/glest_game/world/world.cpp (working copy)
@@ -1285,6 +1285,13 @@
}
return unit->getFactionIndex();
}
+const string World::getUnitName(int unitId) {
+ Unit* unit= findUnitById(unitId);
+ if(unit == NULL) {
+ throw megaglest_runtime_error("Can not find Faction unit to get position unitId = " + intToStr(unitId));
+ }
+ return unit->getFullName();
+}
int World::getUnitCount(int factionIndex) {
if(factionIndex < factions.size()) {
Index: source/glest_game/world/world.h
===================================================================
--- source/glest_game/world/world.h (revision 3330)
+++ source/glest_game/world/world.h (working copy)
@@ -248,6 +248,7 @@
void setUnitPosition(int unitId, Vec2i pos);
int getUnitFactionIndex(int unitId);
+ const string getUnitName(int unitId);
int getUnitCount(int factionIndex);
int getUnitCountOfType(int factionIndex, const string &typeName);