diff --git a/source/glest_game/game/script_manager.cpp b/source/glest_game/game/script_manager.cpp index a30695b3..1b091b1e 100644 --- a/source/glest_game/game/script_manager.cpp +++ b/source/glest_game/game/script_manager.cpp @@ -295,6 +295,8 @@ void ScriptManager::init(World* world, GameCamera *gameCamera, const XmlNode *ro luaScript.registerFunction(getStartLocation, "startLocation"); luaScript.registerFunction(getIsUnitAlive, "isUnitAlive"); luaScript.registerFunction(getUnitPosition, "unitPosition"); + luaScript.registerFunction(setUnitPosition, "setUnitPosition"); + luaScript.registerFunction(getUnitFaction, "unitFaction"); luaScript.registerFunction(getResourceAmount, "resourceAmount"); @@ -1154,6 +1156,12 @@ Vec2i ScriptManager::getUnitPosition(int unitId) { return world->getUnitPosition(unitId); } +void ScriptManager::setUnitPosition(int unitId, Vec2i pos) { + 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->setUnitPosition(unitId,pos); +} + int ScriptManager::getIsUnitAlive(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; @@ -1662,6 +1670,12 @@ int ScriptManager::getUnitPosition(LuaHandle* luaHandle){ return luaArguments.getReturnCount(); } +int ScriptManager::setUnitPosition(LuaHandle* luaHandle){ + LuaArguments luaArguments(luaHandle); + thisScriptManager->setUnitPosition(luaArguments.getInt(-2),luaArguments.getVec2i(-1)); + return luaArguments.getReturnCount(); +} + int ScriptManager::getUnitFaction(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); int factionIndex= thisScriptManager->getUnitFaction(luaArguments.getInt(-1)); diff --git a/source/glest_game/game/script_manager.h b/source/glest_game/game/script_manager.h index 53894f6a..52d19a72 100644 --- a/source/glest_game/game/script_manager.h +++ b/source/glest_game/game/script_manager.h @@ -298,6 +298,8 @@ private: const string &getLastCreatedUnitName(); int getLastCreatedUnitId(); + void setUnitPosition(int unitId, Vec2i pos); + const string &getLastDeadUnitName(); int getLastDeadUnitId(); @@ -398,6 +400,8 @@ private: static int getLastCreatedUnitName(LuaHandle* luaHandle); static int getLastCreatedUnitId(LuaHandle* luaHandle); + static int setUnitPosition(LuaHandle* luaHandle); + static int getLastDeadUnitName(LuaHandle* luaHandle); static int getLastDeadUnitId(LuaHandle* luaHandle); static int getLastDeadUnitCauseOfDeath(LuaHandle* luaHandle); diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index c1847d5b..430c0e18 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -1015,11 +1015,14 @@ void Unit::setTarget(const Unit *unit){ targetRef= unit; } -void Unit::setPos(const Vec2i &pos) { +void Unit::setPos(const Vec2i &pos, bool clearPathFinder) { if(map->isInside(pos) == false || map->isInsideSurface(map->toSurfCoords(pos)) == false) { throw runtime_error("#3 Invalid path position = " + pos.getString()); } + if(clearPathFinder == true && this->unitPath != NULL) { + this->unitPath->clear(); + } this->lastPos= this->pos; this->pos= pos; map->clampPos(this->pos); diff --git a/source/glest_game/type_instances/unit.h b/source/glest_game/type_instances/unit.h index 11a41d38..6df7988d 100644 --- a/source/glest_game/type_instances/unit.h +++ b/source/glest_game/type_instances/unit.h @@ -522,7 +522,7 @@ public: void setLoadCount(int loadCount) {this->loadCount= loadCount;} void setLoadType(const ResourceType *loadType) {this->loadType= loadType;} void setProgress2(int progress2) {this->progress2= progress2;} - void setPos(const Vec2i &pos); + void setPos(const Vec2i &pos,bool clearPathFinder=false); void setTargetPos(const Vec2i &targetPos); void setTarget(const Unit *unit); void setTargetVec(const Vec3f &targetVec); diff --git a/source/glest_game/world/world.cpp b/source/glest_game/world/world.cpp index 2085e1b4..8b6c1450 100644 --- a/source/glest_game/world/world.cpp +++ b/source/glest_game/world/world.cpp @@ -1275,6 +1275,14 @@ Vec2i World::getUnitPosition(int unitId) { return unit->getPos(); } +void World::setUnitPosition(int unitId, Vec2i pos) { + Unit* unit= findUnitById(unitId); + if(unit == NULL) { + throw runtime_error("Can not find unit to set position unitId = " + intToStr(unitId)); + } + unit->setPos(pos,true); +} + int World::getUnitFactionIndex(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 ba06c793..06a13001 100644 --- a/source/glest_game/world/world.h +++ b/source/glest_game/world/world.h @@ -240,6 +240,8 @@ public: int getResourceAmount(const string &resourceName, int factionIndex); Vec2i getStartLocation(int factionIndex); Vec2i getUnitPosition(int unitId); + void setUnitPosition(int unitId, Vec2i pos); + int getUnitFactionIndex(int unitId); int getUnitCount(int factionIndex); int getUnitCountOfType(int factionIndex, const string &typeName);