- added new lua method for setting the direct position of a unit (can be used for teleporting):
setUnitPosition(int unitId, Vec2i pos)
This commit is contained in:
parent
7328875160
commit
22f43f4267
|
@ -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));
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue