- some bugfixes for new LUA features
This commit is contained in:
parent
5ae0430928
commit
f16bb3f28b
|
@ -105,6 +105,7 @@ void ScriptManager::init(World* world, GameCamera *gameCamera){
|
||||||
luaScript.registerFunction(getCellTriggerEventCount, "getCellTriggerEventCount");
|
luaScript.registerFunction(getCellTriggerEventCount, "getCellTriggerEventCount");
|
||||||
luaScript.registerFunction(unregisterCellTriggerEvent, "unregisterCellTriggerEvent");
|
luaScript.registerFunction(unregisterCellTriggerEvent, "unregisterCellTriggerEvent");
|
||||||
luaScript.registerFunction(startTimerEvent, "startTimerEvent");
|
luaScript.registerFunction(startTimerEvent, "startTimerEvent");
|
||||||
|
luaScript.registerFunction(resetTimerEvent, "resetTimerEvent");
|
||||||
luaScript.registerFunction(stopTimerEvent, "stopTimerEvent");
|
luaScript.registerFunction(stopTimerEvent, "stopTimerEvent");
|
||||||
luaScript.registerFunction(getTimerEventSecondsElapsed, "timerEventSecondsElapsed");
|
luaScript.registerFunction(getTimerEventSecondsElapsed, "timerEventSecondsElapsed");
|
||||||
luaScript.registerFunction(getCellTriggeredEventId, "triggeredCellEventId");
|
luaScript.registerFunction(getCellTriggeredEventId, "triggeredCellEventId");
|
||||||
|
@ -203,6 +204,7 @@ void ScriptManager::onTimerTriggerEvent() {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
currentTimerTriggeredEventId = iterMap->first;
|
currentTimerTriggeredEventId = iterMap->first;
|
||||||
|
|
||||||
luaScript.beginCall("timerTriggerEvent");
|
luaScript.beginCall("timerTriggerEvent");
|
||||||
luaScript.endCall();
|
luaScript.endCall();
|
||||||
}
|
}
|
||||||
|
@ -214,17 +216,22 @@ void ScriptManager::onCellTriggerEvent(Unit *movingUnit) {
|
||||||
if(CellTriggerEventList.size() <= 0) {
|
if(CellTriggerEventList.size() <= 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
// remove any delayed removals
|
||||||
|
unregisterCellTriggerEvent(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
inCellTriggerEvent = true;
|
||||||
if(movingUnit != NULL) {
|
if(movingUnit != NULL) {
|
||||||
for(std::map<int,CellTriggerEvent>::iterator iterMap = CellTriggerEventList.begin();
|
for(std::map<int,CellTriggerEvent>::iterator iterMap = CellTriggerEventList.begin();
|
||||||
iterMap != CellTriggerEventList.end(); iterMap++) {
|
iterMap != CellTriggerEventList.end(); iterMap++) {
|
||||||
|
|
||||||
bool triggerEvent = false;
|
|
||||||
CellTriggerEvent &event = iterMap->second;
|
CellTriggerEvent &event = iterMap->second;
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] movingUnit = %d, event.type = %d, movingUnit->getPos() = %s, event.sourceId = %d, event.destId = %d, event.destPos = %s\n",
|
SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] movingUnit = %d, event.type = %d, movingUnit->getPos() = %s, event.sourceId = %d, event.destId = %d, event.destPos = %s\n",
|
||||||
__FILE__,__FUNCTION__,__LINE__,movingUnit->getId(),event.type,movingUnit->getPos().getString().c_str(), event.sourceId,event.destId,event.destPos.getString().c_str());
|
__FILE__,__FUNCTION__,__LINE__,movingUnit->getId(),event.type,movingUnit->getPos().getString().c_str(), event.sourceId,event.destId,event.destPos.getString().c_str());
|
||||||
|
|
||||||
|
bool triggerEvent = false;
|
||||||
|
|
||||||
switch(event.type) {
|
switch(event.type) {
|
||||||
case ctet_Unit:
|
case ctet_Unit:
|
||||||
{
|
{
|
||||||
|
@ -233,13 +240,17 @@ void ScriptManager::onCellTriggerEvent(Unit *movingUnit) {
|
||||||
if(movingUnit->getId() == event.sourceId) {
|
if(movingUnit->getId() == event.sourceId) {
|
||||||
bool srcInDst = world->getMap()->isInUnitTypeCells(destUnit->getType(), destUnit->getPos(),movingUnit->getPos());
|
bool srcInDst = world->getMap()->isInUnitTypeCells(destUnit->getType(), destUnit->getPos(),movingUnit->getPos());
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] movingUnit = %d, event.type = %d, movingUnit->getPos() = %s, event.sourceId = %d, event.destId = %d, event.destPos = %s, destUnit->getPos() = %s, srcInDst = %d\n",
|
SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] movingUnit = %d, event.type = %d, movingUnit->getPos() = %s, event.sourceId = %d, event.destId = %d, event.destPos = %s, destUnit->getPos() = %s, srcInDst = %d\n",
|
||||||
__FILE__,__FUNCTION__,__LINE__,movingUnit->getId(),event.type,movingUnit->getPos().getString().c_str(),event.sourceId,event.destId,event.destPos.getString().c_str(),destUnit->getPos().getString().c_str(),srcInDst);
|
__FILE__,__FUNCTION__,__LINE__,movingUnit->getId(), event.type,movingUnit->getPos().getString().c_str(),event.sourceId,event.destId, event.destPos.getString().c_str(), destUnit->getPos().getString().c_str(),srcInDst);
|
||||||
|
|
||||||
if(srcInDst == true) {
|
if(srcInDst == true) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
triggerEvent = true;
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
srcInDst = world->getMap()->isNextToUnitTypeCells(destUnit->getType(), destUnit->getPos(),movingUnit->getPos());
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] movingUnit = %d, event.type = %d, movingUnit->getPos() = %s, event.sourceId = %d, event.destId = %d, event.destPos = %s, destUnit->getPos() = %s, srcInDst = %d\n",
|
||||||
|
__FILE__,__FUNCTION__,__LINE__,movingUnit->getId(), event.type,movingUnit->getPos().getString().c_str(),event.sourceId,event.destId, event.destPos.getString().c_str(), destUnit->getPos().getString().c_str(),srcInDst);
|
||||||
|
}
|
||||||
|
triggerEvent = srcInDst;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -253,9 +264,8 @@ void ScriptManager::onCellTriggerEvent(Unit *movingUnit) {
|
||||||
|
|
||||||
if(srcInDst == true) {
|
if(srcInDst == true) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
triggerEvent = true;
|
|
||||||
}
|
}
|
||||||
|
triggerEvent = srcInDst;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -271,20 +281,25 @@ void ScriptManager::onCellTriggerEvent(Unit *movingUnit) {
|
||||||
|
|
||||||
if(srcInDst == true) {
|
if(srcInDst == true) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
triggerEvent = true;
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
srcInDst = world->getMap()->isNextToUnitTypeCells(destUnit->getType(), destUnit->getPos(),movingUnit->getPos());
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] movingUnit = %d, event.type = %d, movingUnit->getPos() = %s, event.sourceId = %d, event.destId = %d, event.destPos = %s, destUnit->getPos() = %s, srcInDst = %d\n",
|
||||||
|
__FILE__,__FUNCTION__,__LINE__,movingUnit->getId(),event.type,movingUnit->getPos().getString().c_str(),event.sourceId,event.destId,event.destPos.getString().c_str(),destUnit->getPos().getString().c_str(),srcInDst);
|
||||||
|
}
|
||||||
|
triggerEvent = srcInDst;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ctet_FactionPos:
|
case ctet_FactionPos:
|
||||||
{
|
{
|
||||||
if(movingUnit->getFactionIndex() == event.sourceId &&
|
if(movingUnit->getFactionIndex() == event.sourceId) {
|
||||||
world->getMap()->isInUnitTypeCells(0, event.destPos,movingUnit->getPos())) {
|
bool srcInDst = world->getMap()->isInUnitTypeCells(0, event.destPos,movingUnit->getPos());
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
if(srcInDst == true) {
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
triggerEvent = true;
|
}
|
||||||
|
triggerEvent = srcInDst;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -296,11 +311,14 @@ void ScriptManager::onCellTriggerEvent(Unit *movingUnit) {
|
||||||
|
|
||||||
currentCellTriggeredEventId = iterMap->first;
|
currentCellTriggeredEventId = iterMap->first;
|
||||||
event.triggerCount++;
|
event.triggerCount++;
|
||||||
|
|
||||||
luaScript.beginCall("cellTriggerEvent");
|
luaScript.beginCall("cellTriggerEvent");
|
||||||
luaScript.endCall();
|
luaScript.endCall();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inCellTriggerEvent = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ========================== lua wrappers ===============================================
|
// ========================== lua wrappers ===============================================
|
||||||
|
@ -507,7 +525,24 @@ int ScriptManager::getCellTriggerEventCount(int eventId) {
|
||||||
|
|
||||||
void ScriptManager::unregisterCellTriggerEvent(int eventId) {
|
void ScriptManager::unregisterCellTriggerEvent(int eventId) {
|
||||||
if(CellTriggerEventList.find(eventId) != CellTriggerEventList.end()) {
|
if(CellTriggerEventList.find(eventId) != CellTriggerEventList.end()) {
|
||||||
CellTriggerEventList.erase(eventId);
|
if(inCellTriggerEvent == false) {
|
||||||
|
CellTriggerEventList.erase(eventId);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
unRegisterCellTriggerEventList.push_back(eventId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(inCellTriggerEvent == false) {
|
||||||
|
if(unRegisterCellTriggerEventList.size() > 0) {
|
||||||
|
for(int i = 0; i < unRegisterCellTriggerEventList.size(); ++i) {
|
||||||
|
int delayedEventId = unRegisterCellTriggerEventList[i];
|
||||||
|
if(CellTriggerEventList.find(delayedEventId) != CellTriggerEventList.end()) {
|
||||||
|
CellTriggerEventList.erase(delayedEventId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unRegisterCellTriggerEventList.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -525,6 +560,21 @@ int ScriptManager::startTimerEvent() {
|
||||||
return eventId;
|
return eventId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ScriptManager::resetTimerEvent(int eventId) {
|
||||||
|
int result = 0;
|
||||||
|
if(TimerTriggerEventList.find(eventId) != TimerTriggerEventList.end()) {
|
||||||
|
TimerTriggerEvent &trigger = TimerTriggerEventList[eventId];
|
||||||
|
result = getTimerEventSecondsElapsed(eventId);
|
||||||
|
|
||||||
|
trigger.startTime = time(NULL);
|
||||||
|
trigger.endTime = 0;
|
||||||
|
trigger.running = true;
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] TimerTriggerEventList.size() = %d, eventId = %d, trigger.startTime = %lld, trigger.endTime = %lld, result = %d\n",__FILE__,__FUNCTION__,__LINE__,TimerTriggerEventList.size(),eventId,(long long int)trigger.startTime,(long long int)trigger.endTime,result);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
int ScriptManager::stopTimerEvent(int eventId) {
|
int ScriptManager::stopTimerEvent(int eventId) {
|
||||||
int result = 0;
|
int result = 0;
|
||||||
if(TimerTriggerEventList.find(eventId) != TimerTriggerEventList.end()) {
|
if(TimerTriggerEventList.find(eventId) != TimerTriggerEventList.end()) {
|
||||||
|
@ -828,6 +878,13 @@ int ScriptManager::stopTimerEvent(LuaHandle* luaHandle) {
|
||||||
return luaArguments.getReturnCount();
|
return luaArguments.getReturnCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ScriptManager::resetTimerEvent(LuaHandle* luaHandle) {
|
||||||
|
LuaArguments luaArguments(luaHandle);
|
||||||
|
int result = thisScriptManager->resetTimerEvent(luaArguments.getInt(-1));
|
||||||
|
luaArguments.returnInt(result);
|
||||||
|
return luaArguments.getReturnCount();
|
||||||
|
}
|
||||||
|
|
||||||
int ScriptManager::getTimerEventSecondsElapsed(LuaHandle* luaHandle) {
|
int ScriptManager::getTimerEventSecondsElapsed(LuaHandle* luaHandle) {
|
||||||
LuaArguments luaArguments(luaHandle);
|
LuaArguments luaArguments(luaHandle);
|
||||||
int result = thisScriptManager->getTimerEventSecondsElapsed(luaArguments.getInt(-1));
|
int result = thisScriptManager->getTimerEventSecondsElapsed(luaArguments.getInt(-1));
|
||||||
|
|
|
@ -136,6 +136,8 @@ private:
|
||||||
int currentEventId;
|
int currentEventId;
|
||||||
std::map<int,CellTriggerEvent> CellTriggerEventList;
|
std::map<int,CellTriggerEvent> CellTriggerEventList;
|
||||||
std::map<int,TimerTriggerEvent> TimerTriggerEventList;
|
std::map<int,TimerTriggerEvent> TimerTriggerEventList;
|
||||||
|
bool inCellTriggerEvent;
|
||||||
|
std::vector<int> unRegisterCellTriggerEventList;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static ScriptManager* thisScriptManager;
|
static ScriptManager* thisScriptManager;
|
||||||
|
@ -191,6 +193,7 @@ private:
|
||||||
int getCellTriggerEventCount(int eventId);
|
int getCellTriggerEventCount(int eventId);
|
||||||
void unregisterCellTriggerEvent(int eventId);
|
void unregisterCellTriggerEvent(int eventId);
|
||||||
int startTimerEvent();
|
int startTimerEvent();
|
||||||
|
int resetTimerEvent(int eventId);
|
||||||
int stopTimerEvent(int eventId);
|
int stopTimerEvent(int eventId);
|
||||||
int getTimerEventSecondsElapsed(int eventId);
|
int getTimerEventSecondsElapsed(int eventId);
|
||||||
int getCellTriggeredEventId();
|
int getCellTriggeredEventId();
|
||||||
|
@ -249,6 +252,7 @@ private:
|
||||||
static int getCellTriggerEventCount(LuaHandle* luaHandle);
|
static int getCellTriggerEventCount(LuaHandle* luaHandle);
|
||||||
static int unregisterCellTriggerEvent(LuaHandle* luaHandle);
|
static int unregisterCellTriggerEvent(LuaHandle* luaHandle);
|
||||||
static int startTimerEvent(LuaHandle* luaHandle);
|
static int startTimerEvent(LuaHandle* luaHandle);
|
||||||
|
static int resetTimerEvent(LuaHandle* luaHandle);
|
||||||
static int stopTimerEvent(LuaHandle* luaHandle);
|
static int stopTimerEvent(LuaHandle* luaHandle);
|
||||||
static int getTimerEventSecondsElapsed(LuaHandle* luaHandle);
|
static int getTimerEventSecondsElapsed(LuaHandle* luaHandle);
|
||||||
|
|
||||||
|
|
|
@ -439,9 +439,56 @@ bool Map::aproxCanMove(const Unit *unit, const Vec2i &pos1, const Vec2i &pos2) c
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// is testPos in the cells of unitType where unitType's position is pos
|
Vec2i Map::findBestBuildApproach(Vec2i unitBuilderPos, Vec2i originalBuildPos,
|
||||||
bool Map::isInUnitTypeCells(const UnitType *ut, const Vec2i &pos,const Vec2i &testPos) {
|
const UnitType *ut) {
|
||||||
|
Vec2i pos = originalBuildPos;
|
||||||
|
|
||||||
|
float bestRange = -1;
|
||||||
|
|
||||||
|
Vec2i start = pos - Vec2i(1);
|
||||||
|
Vec2i end = pos + Vec2i(ut->getSize());
|
||||||
|
|
||||||
|
for(int i = start.x; i <= end.x; ++i) {
|
||||||
|
for(int j = start.y; j <= end.y; ++j){
|
||||||
|
Vec2i testPos(i,j);
|
||||||
|
if(isInUnitTypeCells(ut, originalBuildPos,testPos) == false) {
|
||||||
|
float distance = unitBuilderPos.dist(testPos);
|
||||||
|
if(bestRange < 0 || bestRange > distance) {
|
||||||
|
bestRange = distance;
|
||||||
|
pos = testPos;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Map::isNextToUnitTypeCells(const UnitType *ut, const Vec2i &pos,
|
||||||
|
const Vec2i &testPos) {
|
||||||
|
bool isInsideDestUnitCells = isInUnitTypeCells(ut, pos,testPos);
|
||||||
|
if(isInsideDestUnitCells == false) {
|
||||||
|
Cell *testCell = getCell(testPos);
|
||||||
|
for(int i=-1; i <= ut->getSize(); ++i){
|
||||||
|
for(int j = -1; j <= ut->getSize(); ++j) {
|
||||||
|
Vec2i currPos = pos + Vec2i(i, j);
|
||||||
|
if(isInside(currPos) == true) {
|
||||||
|
//Cell *unitCell = getCell(currPos);
|
||||||
|
//if(unitCell == testCell) {
|
||||||
|
if(isNextTo(testPos,currPos) == true) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// is testPos in the cells of unitType where unitType's position is pos
|
||||||
|
bool Map::isInUnitTypeCells(const UnitType *ut, const Vec2i &pos,
|
||||||
|
const Vec2i &testPos) {
|
||||||
assert(ut!=NULL);
|
assert(ut!=NULL);
|
||||||
|
|
||||||
Cell *testCell = getCell(testPos);
|
Cell *testCell = getCell(testPos);
|
||||||
|
@ -449,9 +496,7 @@ bool Map::isInUnitTypeCells(const UnitType *ut, const Vec2i &pos,const Vec2i &te
|
||||||
for(int j = 0; j < ut->getSize(); ++j) {
|
for(int j = 0; j < ut->getSize(); ++j) {
|
||||||
Vec2i currPos = pos + Vec2i(i, j);
|
Vec2i currPos = pos + Vec2i(i, j);
|
||||||
if(isInside(currPos) == true) {
|
if(isInside(currPos) == true) {
|
||||||
//if(ut->hasCellMap() == false || ut->getCellMapCell(i, j, facing)) {
|
|
||||||
Cell *unitCell = getCell(currPos);
|
Cell *unitCell = getCell(currPos);
|
||||||
|
|
||||||
if(unitCell == testCell) {
|
if(unitCell == testCell) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -215,6 +215,11 @@ public:
|
||||||
void putUnitCells(Unit *unit, const Vec2i &pos);
|
void putUnitCells(Unit *unit, const Vec2i &pos);
|
||||||
void clearUnitCells(Unit *unit, const Vec2i &pos);
|
void clearUnitCells(Unit *unit, const Vec2i &pos);
|
||||||
bool isInUnitTypeCells(const UnitType *ut, const Vec2i &pos,const Vec2i &testPos);
|
bool isInUnitTypeCells(const UnitType *ut, const Vec2i &pos,const Vec2i &testPos);
|
||||||
|
bool isNextToUnitTypeCells(const UnitType *ut, const Vec2i &pos,const Vec2i &testPos);
|
||||||
|
|
||||||
|
Vec2i findBestBuildApproach(Vec2i unitBuilderPos, Vec2i originalBuildPos,
|
||||||
|
const UnitType *ut);
|
||||||
|
|
||||||
|
|
||||||
//misc
|
//misc
|
||||||
bool isNextTo(const Vec2i &pos, const Unit *unit) const;
|
bool isNextTo(const Vec2i &pos, const Unit *unit) const;
|
||||||
|
|
|
@ -385,30 +385,6 @@ void UnitUpdater::updateAttackStopped(Unit *unit){
|
||||||
|
|
||||||
// ==================== updateBuild ====================
|
// ==================== updateBuild ====================
|
||||||
|
|
||||||
Vec2i UnitUpdater::findBestBuildApproach(Vec2i unitBuilderPos, Vec2i originalBuildPos, const UnitType *ut) {
|
|
||||||
Vec2i pos = originalBuildPos;
|
|
||||||
|
|
||||||
float bestRange = -1;
|
|
||||||
|
|
||||||
Vec2i start = pos - Vec2i(1);
|
|
||||||
Vec2i end = pos + Vec2i(ut->getSize());
|
|
||||||
|
|
||||||
for(int i = start.x; i <= end.x; ++i) {
|
|
||||||
for(int j = start.y; j <= end.y; ++j){
|
|
||||||
Vec2i testPos(i,j);
|
|
||||||
if(map->isInUnitTypeCells(ut, originalBuildPos,testPos) == false) {
|
|
||||||
float distance = unitBuilderPos.dist(testPos);
|
|
||||||
if(bestRange < 0 || bestRange > distance) {
|
|
||||||
bestRange = distance;
|
|
||||||
pos = testPos;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
void UnitUpdater::updateBuild(Unit *unit){
|
void UnitUpdater::updateBuild(Unit *unit){
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
@ -429,7 +405,7 @@ void UnitUpdater::updateBuild(Unit *unit){
|
||||||
case pfBasic:
|
case pfBasic:
|
||||||
{
|
{
|
||||||
//Vec2i buildPos = (command->getPos()-Vec2i(1));
|
//Vec2i buildPos = (command->getPos()-Vec2i(1));
|
||||||
Vec2i buildPos = findBestBuildApproach(unit->getPos(), command->getPos(), ut);
|
Vec2i buildPos = map->findBestBuildApproach(unit->getPos(), command->getPos(), ut);
|
||||||
//Vec2i buildPos = (command->getPos() + Vec2i(ut->getSize() / 2));
|
//Vec2i buildPos = (command->getPos() + Vec2i(ut->getSize() / 2));
|
||||||
tsValue = pathFinder->findPath(unit, buildPos);
|
tsValue = pathFinder->findPath(unit, buildPos);
|
||||||
}
|
}
|
||||||
|
|
|
@ -118,7 +118,7 @@ private:
|
||||||
|
|
||||||
Unit * findPeerUnitBuilder(Unit *unit);
|
Unit * findPeerUnitBuilder(Unit *unit);
|
||||||
void SwapActiveCommand(Unit *unitSrc, Unit *unitDest);
|
void SwapActiveCommand(Unit *unitSrc, Unit *unitDest);
|
||||||
Vec2i findBestBuildApproach(Vec2i unitBuilderPos, Vec2i originalBuildPos, const UnitType *ut);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
Loading…
Reference in New Issue
Block a user