diff --git a/source/glest_game/game/script_manager.cpp b/source/glest_game/game/script_manager.cpp index 09ddc2c49..7970007bf 100644 --- a/source/glest_game/game/script_manager.cpp +++ b/source/glest_game/game/script_manager.cpp @@ -504,6 +504,7 @@ namespace luaScript.registerFunction(unhighlightUnit, "unhighlightUnit"); luaScript.registerFunction(giveStopCommand, "giveStopCommand"); + luaScript.registerFunction(isBuilding, "isBuilding"); luaScript.registerFunction(selectUnit, "selectUnit"); luaScript.registerFunction(unselectUnit, "unselectUnit"); luaScript.registerFunction(addUnitToGroupSelection, @@ -534,6 +535,7 @@ namespace luaScript.registerFunction(getLastUnitTriggerEventType, "lastUnitTriggerEventType"); luaScript.registerFunction(getUnitProperty, "getUnitProperty"); + luaScript.registerFunction(setUnitProperty, "setUnitProperty"); luaScript.registerFunction(getUnitPropertyName, "getUnitPropertyName"); luaScript.registerFunction(disableSpeedChange, "disableSpeedChange"); luaScript.registerFunction(enableSpeedChange, "enableSpeedChange"); @@ -2954,6 +2956,17 @@ namespace return world->selectUnit(unitId); } + bool + ScriptManager::isBuilding(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->isBuilding(unitId); + } + void ScriptManager::unselectUnit(int unitId) { if (SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) @@ -3080,6 +3093,37 @@ namespace //printf("File: %s line: %d result: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,result); return result; } + + int + ScriptManager::setUnitProperty(int unitId, UnitTriggerEventType type, int value) { + bool result = false; + + //printf("File: %s line: %d type: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,type); + + Unit * + unit = world->findUnitById(unitId); + if (unit != NULL) { + switch (type) { + case utet_None: + break; + case utet_HPChanged: + unit->setHp(value); + result = true; + break; + case utet_EPChanged: + unit->setEp(value); + result = true; + break; + case utet_FieldChanged: + unit->setCurrField(value == 1 ? Field::fAir : Field::fLand); + result = true; + break; + } + } + //printf("File: %s line: %d result: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,result); + return result ? 1 : 0; + } + const string ScriptManager::getUnitPropertyName(int unitId, UnitTriggerEventType type) { string @@ -5576,6 +5620,20 @@ namespace return luaArguments.getReturnCount(); } + int + ScriptManager::isBuilding(LuaHandle * luaHandle) { + LuaArguments + luaArguments(luaHandle); + try { + luaArguments.returnInt(thisScriptManager-> + isBuilding(luaArguments.getInt(-1))); + } catch (const megaglest_runtime_error & ex) { + error(luaHandle, &ex, __FILE__, __FUNCTION__, __LINE__); + } + + return luaArguments.getReturnCount(); + } + int ScriptManager::selectUnit(LuaHandle * luaHandle) { LuaArguments @@ -5808,6 +5866,26 @@ namespace return luaArguments.getReturnCount(); } + + int + ScriptManager::setUnitProperty(LuaHandle * luaHandle) { + LuaArguments + luaArguments(luaHandle); + try { + bool + value = + thisScriptManager->setUnitProperty(luaArguments.getInt(-3), + static_cast < + UnitTriggerEventType> + (luaArguments.getInt(-2)), luaArguments.getInt(-1)); + luaArguments.returnInt(value); + } catch (const megaglest_runtime_error & ex) { + error(luaHandle, &ex, __FILE__, __FUNCTION__, __LINE__); + } + + return luaArguments.getReturnCount(); + } + int ScriptManager::getUnitPropertyName(LuaHandle * luaHandle) { LuaArguments diff --git a/source/glest_game/game/script_manager.h b/source/glest_game/game/script_manager.h index 4929a78c7..696d24e73 100644 --- a/source/glest_game/game/script_manager.h +++ b/source/glest_game/game/script_manager.h @@ -716,6 +716,8 @@ namespace bool selectUnit(int unitId); + bool + isBuilding(int unitId); void unselectUnit(int unitId); void @@ -750,6 +752,8 @@ namespace getLastUnitTriggerEventType(); int getUnitProperty(int unitId, UnitTriggerEventType type); + int + setUnitProperty(int unitId, UnitTriggerEventType type, int value); const string getUnitPropertyName(int unitId, UnitTriggerEventType type); @@ -1025,6 +1029,8 @@ namespace giveStopCommand(LuaHandle * luaHandle); static int selectUnit(LuaHandle * luaHandle); + static int + isBuilding(LuaHandle * luaHandle); static int unselectUnit(LuaHandle * luaHandle); static int @@ -1059,6 +1065,8 @@ namespace getLastUnitTriggerEventType(LuaHandle * luaHandle); static int getUnitProperty(LuaHandle * luaHandle); + static int + setUnitProperty(LuaHandle * luaHandle); static int getUnitPropertyName(LuaHandle * luaHandle); diff --git a/source/glest_game/type_instances/unit.h b/source/glest_game/type_instances/unit.h index da2846fbd..c5de30b11 100644 --- a/source/glest_game/type_instances/unit.h +++ b/source/glest_game/type_instances/unit.h @@ -635,6 +635,9 @@ namespace Glest { inline Field getCurrField() const { return currField; } + inline void setCurrField(Field value) { + currField = value; + } inline int getLoadCount() const { return loadCount; } @@ -668,6 +671,12 @@ namespace Glest { inline int getEp() const { return ep; } + inline void setHp(int32 value) { + hp = value; + } + inline void setEp(int32 value) { + ep = value; + } int getProductionPercent() const; float getProgressRatio() const; float getHpRatio() const; diff --git a/source/glest_game/world/world.cpp b/source/glest_game/world/world.cpp index f3493c28c..a7e103f52 100644 --- a/source/glest_game/world/world.cpp +++ b/source/glest_game/world/world.cpp @@ -1498,6 +1498,16 @@ namespace Glest { return result; } + bool World::isBuilding(int unitId) { + bool result = false; + Unit* unit = findUnitById(unitId); + if (unit != NULL) { + result = unit->getType()->hasSkillClass(scBeBuilt); + } + + return result; + } + void World::unselectUnit(int unitId) { Unit* unit = findUnitById(unitId); if (unit != NULL) { diff --git a/source/glest_game/world/world.h b/source/glest_game/world/world.h index 07a5aa596..7033510da 100644 --- a/source/glest_game/world/world.h +++ b/source/glest_game/world/world.h @@ -334,7 +334,7 @@ namespace Glest { void unhighlightUnit(int unitId); void giveStopCommand(int unitId); - + bool isBuilding(int unitId); bool selectUnit(int unitId); void unselectUnit(int unitId); void addUnitToGroupSelection(int unitId, int groupIndex);