- more code cleanup (removal of dead code that is no longer used)
- fix the icon for wartime mechanic's heal command
This commit is contained in:
parent
c58f338d1b
commit
0e9cf65e70
|
@ -48,7 +48,6 @@ PathFinder::PathFinder() {
|
||||||
for(int i = 0; i < GameConstants::maxPlayers; ++i) {
|
for(int i = 0; i < GameConstants::maxPlayers; ++i) {
|
||||||
factions.push_back(FactionState());
|
factions.push_back(FactionState());
|
||||||
}
|
}
|
||||||
//nodePool.clear();
|
|
||||||
map=NULL;
|
map=NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,8 +56,6 @@ PathFinder::PathFinder(const Map *map) {
|
||||||
factions.push_back(FactionState());
|
factions.push_back(FactionState());
|
||||||
}
|
}
|
||||||
|
|
||||||
//nodePool.clear();
|
|
||||||
|
|
||||||
map=NULL;
|
map=NULL;
|
||||||
init(map);
|
init(map);
|
||||||
}
|
}
|
||||||
|
@ -97,8 +94,6 @@ void PathFinder::removeUnitPrecache(Unit *unit) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos, bool *wasStuck, int frameIndex) {
|
TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos, bool *wasStuck, int frameIndex) {
|
||||||
//printf("PathFinder::findPath...\n");
|
|
||||||
|
|
||||||
if(map == NULL) {
|
if(map == NULL) {
|
||||||
throw runtime_error("map == NULL");
|
throw runtime_error("map == NULL");
|
||||||
}
|
}
|
||||||
|
@ -130,7 +125,6 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos, bool *wasStu
|
||||||
unit->setCurrentUnitTitle(szBuf);
|
unit->setCurrentUnitTitle(szBuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
//unit->getFaction()->addCachedPath(finalPos,unit);
|
|
||||||
return tsArrived;
|
return tsArrived;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,7 +138,6 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos, bool *wasStu
|
||||||
if(map->canMove(unit, unit->getPos(), pos)) {
|
if(map->canMove(unit, unit->getPos(), pos)) {
|
||||||
if(frameIndex < 0) {
|
if(frameIndex < 0) {
|
||||||
unit->setTargetPos(pos);
|
unit->setTargetPos(pos);
|
||||||
unit->addCurrentTargetPathTakenCell(finalPos,pos);
|
|
||||||
}
|
}
|
||||||
return tsMoving;
|
return tsMoving;
|
||||||
}
|
}
|
||||||
|
@ -168,41 +161,14 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos, bool *wasStu
|
||||||
|
|
||||||
|
|
||||||
TravelState ts = tsImpossible;
|
TravelState ts = tsImpossible;
|
||||||
//std::vector<Vec2i> cachedPath = unit->getFaction()->findCachedPath(finalPos, unit);
|
//route cache miss
|
||||||
//if(cachedPath.size() > 0) {
|
|
||||||
// path->clear();
|
|
||||||
// for(int i=0; i < cachedPath.size() && i < pathFindRefresh; ++i) {
|
|
||||||
// path->add(cachedPath[i]);
|
|
||||||
// }
|
|
||||||
// ts = tsMoving;
|
|
||||||
//}
|
|
||||||
//else {
|
|
||||||
//route cache miss
|
|
||||||
ts = aStar(unit, finalPos, false, frameIndex);
|
ts = aStar(unit, finalPos, false, frameIndex);
|
||||||
//}
|
|
||||||
|
|
||||||
//if(ts == tsBlocked) {
|
|
||||||
//std::vector<Vec2i> cachedPath = unit->getFaction()->findCachedPath(finalPos, unit);
|
|
||||||
//if(cachedPath.size() > 0) {
|
|
||||||
// path->clear();
|
|
||||||
//
|
|
||||||
// for(int i=0; i < cachedPath.size() && i < pathFindRefresh; ++i) {
|
|
||||||
// path->add(cachedPath[i]);
|
|
||||||
// }
|
|
||||||
// ts = tsMoving;
|
|
||||||
// unit->addCurrentTargetPathTakenCell(Vec2i(-1),Vec2i(-1));
|
|
||||||
//}
|
|
||||||
//}
|
|
||||||
|
|
||||||
//post actions
|
//post actions
|
||||||
switch(ts) {
|
switch(ts) {
|
||||||
case tsBlocked:
|
case tsBlocked:
|
||||||
case tsArrived:
|
case tsArrived:
|
||||||
|
|
||||||
//if(ts == tsArrived) {
|
|
||||||
//unit->getFaction()->addCachedPath(finalPos,unit);
|
|
||||||
//}
|
|
||||||
|
|
||||||
// The unit is stuck (not only blocked but unable to go anywhere for a while)
|
// The unit is stuck (not only blocked but unable to go anywhere for a while)
|
||||||
// We will try to bail out of the immediate area
|
// We will try to bail out of the immediate area
|
||||||
if( ts == tsBlocked && unit->getInBailOutAttempt() == false &&
|
if( ts == tsBlocked && unit->getInBailOutAttempt() == false &&
|
||||||
|
@ -220,48 +186,10 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos, bool *wasStu
|
||||||
}
|
}
|
||||||
unit->setInBailOutAttempt(true);
|
unit->setInBailOutAttempt(true);
|
||||||
|
|
||||||
//printf("#1 BAILOUT test unitid [%d]\n",unit->getId());
|
|
||||||
|
|
||||||
bool useBailoutRadius = Config::getInstance().getBool("EnableBailoutPathfinding","true");
|
bool useBailoutRadius = Config::getInstance().getBool("EnableBailoutPathfinding","true");
|
||||||
/*
|
|
||||||
Command *command= unit->getCurrCommand();
|
|
||||||
if(command != NULL) {
|
|
||||||
const HarvestCommandType *hct= dynamic_cast<const HarvestCommandType*>(command->getCommandType());
|
|
||||||
if(hct != NULL) {
|
|
||||||
Resource *r = map->getSurfaceCell(Map::toSurfCoords(command->getPos()))->getResource();
|
|
||||||
if(r != NULL && r->getType() != NULL) {
|
|
||||||
Vec2i newFinalPos = unit->getFaction()->getClosestResourceTypeTargetFromCache(unit, r->getType());
|
|
||||||
|
|
||||||
//printf("#2 BAILOUT test unitid [%d] newFinalPos [%s] finalPos [%s]\n",unit->getId(),newFinalPos.getString().c_str(),finalPos.getString().c_str());
|
|
||||||
|
|
||||||
if(newFinalPos != finalPos) {
|
|
||||||
bool canUnitMove = map->canMove(unit, unit->getPos(), newFinalPos);
|
|
||||||
|
|
||||||
//printf("#3 BAILOUT test unitid [%d] newFinalPos [%s] finalPos [%s] canUnitMove [%d]\n",unit->getId(),newFinalPos.getString().c_str(),finalPos.getString().c_str(),canUnitMove);
|
|
||||||
|
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true) {
|
|
||||||
char szBuf[4096]="";
|
|
||||||
sprintf(szBuf,"[attempting to BAIL OUT] finalPos [%s] newFinalPos [%s] ts [%d] canUnitMove [%d]",
|
|
||||||
finalPos.getString().c_str(),newFinalPos.getString().c_str(),ts,canUnitMove);
|
|
||||||
unit->logSynchData(__FILE__,__LINE__,szBuf);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(canUnitMove) {
|
|
||||||
useBailoutRadius = false;
|
|
||||||
ts= aStar(unit, newFinalPos, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
if(useBailoutRadius == true) {
|
if(useBailoutRadius == true) {
|
||||||
//int tryRadius = random.randRange(-PathFinder::pathFindBailoutRadius, PathFinder::pathFindBailoutRadius);
|
|
||||||
int tryRadius = factions[unit->getFactionIndex()].random.randRange(0,1);
|
int tryRadius = factions[unit->getFactionIndex()].random.randRange(0,1);
|
||||||
|
|
||||||
//printf("#4 BAILOUT test unitid [%d] useBailoutRadius [%d] tryRadius [%d]\n",unit->getId(),useBailoutRadius,tryRadius);
|
|
||||||
|
|
||||||
// Try to bail out up to PathFinder::pathFindBailoutRadius cells away
|
// Try to bail out up to PathFinder::pathFindBailoutRadius cells away
|
||||||
if(tryRadius > 0) {
|
if(tryRadius > 0) {
|
||||||
for(int bailoutX = -PathFinder::pathFindBailoutRadius; bailoutX <= PathFinder::pathFindBailoutRadius && ts == tsBlocked; ++bailoutX) {
|
for(int bailoutX = -PathFinder::pathFindBailoutRadius; bailoutX <= PathFinder::pathFindBailoutRadius && ts == tsBlocked; ++bailoutX) {
|
||||||
|
@ -322,11 +250,9 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos, bool *wasStu
|
||||||
pos = factions[unit->getFactionIndex()].precachedPath[unit->getId()][0];
|
pos = factions[unit->getFactionIndex()].precachedPath[unit->getId()][0];
|
||||||
}
|
}
|
||||||
|
|
||||||
//if(map->canMove(unit, unit->getPos(), pos, &lookupCacheCanMove)) {
|
|
||||||
if(map->canMove(unit, unit->getPos(), pos)) {
|
if(map->canMove(unit, unit->getPos(), pos)) {
|
||||||
if(frameIndex < 0) {
|
if(frameIndex < 0) {
|
||||||
unit->setTargetPos(pos);
|
unit->setTargetPos(pos);
|
||||||
unit->addCurrentTargetPathTakenCell(finalPos,pos);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -395,10 +321,9 @@ bool PathFinder::processNode(Unit *unit, Node *node,const Vec2i finalPos, int i,
|
||||||
//route a unit using A* algorithm
|
//route a unit using A* algorithm
|
||||||
TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout,
|
TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout,
|
||||||
int frameIndex) {
|
int frameIndex) {
|
||||||
//printf("PathFinder::aStar...\n");
|
|
||||||
|
|
||||||
Chrono chrono;
|
Chrono chrono;
|
||||||
chrono.start();
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled) chrono.start();
|
||||||
|
|
||||||
if(map == NULL) {
|
if(map == NULL) {
|
||||||
throw runtime_error("map == NULL");
|
throw runtime_error("map == NULL");
|
||||||
|
@ -481,22 +406,14 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
|
||||||
const Vec2i finalPos= computeNearestFreePos(unit, targetPos);
|
const Vec2i finalPos= computeNearestFreePos(unit, targetPos);
|
||||||
|
|
||||||
float dist= unitPos.dist(finalPos);
|
float dist= unitPos.dist(finalPos);
|
||||||
|
|
||||||
factions[unit->getFactionIndex()].useMaxNodeCount = PathFinder::pathFindNodesMax;
|
factions[unit->getFactionIndex()].useMaxNodeCount = PathFinder::pathFindNodesMax;
|
||||||
// if(dist <= 10) {
|
|
||||||
// useMaxNodeCount = (int)dist * 20;
|
|
||||||
// if(useMaxNodeCount <= 0) {
|
|
||||||
// useMaxNodeCount = 200;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 4) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 4) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||||
|
|
||||||
|
|
||||||
// Check the previous path find cache for the unit to see if its good to
|
// Check the previous path find cache for the unit to see if its good to
|
||||||
// use
|
// use
|
||||||
if((showConsoleDebugInfo || tryLastPathCache) && dist > 60) {
|
if(showConsoleDebugInfo || tryLastPathCache) {
|
||||||
if(showConsoleDebugInfo) printf("Distance from [%d - %s] to destination is %.2f tryLastPathCache = %d\n",unit->getId(),unit->getFullName().c_str(), dist,tryLastPathCache);
|
if(showConsoleDebugInfo && dist > 60) printf("Distance from [%d - %s] to destination is %.2f tryLastPathCache = %d\n",unit->getId(),unit->getFullName().c_str(), dist,tryLastPathCache);
|
||||||
|
|
||||||
if(tryLastPathCache == true && path != NULL) {
|
if(tryLastPathCache == true && path != NULL) {
|
||||||
UnitPathBasic *basicPathFinder = dynamic_cast<UnitPathBasic *>(path);
|
UnitPathBasic *basicPathFinder = dynamic_cast<UnitPathBasic *>(path);
|
||||||
|
@ -564,7 +481,6 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 4) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 4) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||||
|
|
||||||
return ts;
|
return ts;
|
||||||
//break;
|
|
||||||
}
|
}
|
||||||
else if(j - i > pathFindRefresh) {
|
else if(j - i > pathFindRefresh) {
|
||||||
//on the way
|
//on the way
|
||||||
|
@ -659,7 +575,7 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
|
||||||
|
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 4) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 4) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||||
|
|
||||||
// First check if unit currently blocked
|
// First check if unit currently blocked all around them, if so don't try to pathfind
|
||||||
if(inBailout == false && unitPos != finalPos) {
|
if(inBailout == false && unitPos != finalPos) {
|
||||||
int failureCount = 0;
|
int failureCount = 0;
|
||||||
int cellCount = 0;
|
int cellCount = 0;
|
||||||
|
@ -681,7 +597,6 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
|
||||||
|
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 1) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] **Check if dest blocked, distance for unit [%d - %s] from [%s] to [%s] is %.2f took msecs: %lld nodeLimitReached = %d, failureCount = %d\n",__FILE__,__FUNCTION__,__LINE__,unit->getId(),unit->getFullName().c_str(), unitPos.getString().c_str(), finalPos.getString().c_str(), dist,(long long int)chrono.getMillis(),nodeLimitReached,failureCount);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 1) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] **Check if dest blocked, distance for unit [%d - %s] from [%s] to [%s] is %.2f took msecs: %lld nodeLimitReached = %d, failureCount = %d\n",__FILE__,__FUNCTION__,__LINE__,unit->getId(),unit->getFullName().c_str(), unitPos.getString().c_str(), finalPos.getString().c_str(), dist,(long long int)chrono.getMillis(),nodeLimitReached,failureCount);
|
||||||
if(showConsoleDebugInfo && nodeLimitReached) {
|
if(showConsoleDebugInfo && nodeLimitReached) {
|
||||||
//if(showConsoleDebugInfo) {
|
|
||||||
printf("**Check if src blocked [%d - %d], unit [%d - %s] from [%s] to [%s] distance %.2f took msecs: %lld nodeLimitReached = %d, failureCount = %d [%d]\n",
|
printf("**Check if src blocked [%d - %d], unit [%d - %s] from [%s] to [%s] distance %.2f took msecs: %lld nodeLimitReached = %d, failureCount = %d [%d]\n",
|
||||||
nodeLimitReached, inBailout, unit->getId(),unit->getFullName().c_str(), unitPos.getString().c_str(), finalPos.getString().c_str(), dist,(long long int)chrono.getMillis(),nodeLimitReached,failureCount,cellCount);
|
nodeLimitReached, inBailout, unit->getId(),unit->getFullName().c_str(), unitPos.getString().c_str(), finalPos.getString().c_str(), dist,(long long int)chrono.getMillis(),nodeLimitReached,failureCount,cellCount);
|
||||||
}
|
}
|
||||||
|
@ -708,7 +623,6 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
|
||||||
|
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 1) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] **Check if dest blocked, distance for unit [%d - %s] from [%s] to [%s] is %.2f took msecs: %lld nodeLimitReached = %d, failureCount = %d\n",__FILE__,__FUNCTION__,__LINE__,unit->getId(),unit->getFullName().c_str(), unitPos.getString().c_str(), finalPos.getString().c_str(), dist,(long long int)chrono.getMillis(),nodeLimitReached,failureCount);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 1) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] **Check if dest blocked, distance for unit [%d - %s] from [%s] to [%s] is %.2f took msecs: %lld nodeLimitReached = %d, failureCount = %d\n",__FILE__,__FUNCTION__,__LINE__,unit->getId(),unit->getFullName().c_str(), unitPos.getString().c_str(), finalPos.getString().c_str(), dist,(long long int)chrono.getMillis(),nodeLimitReached,failureCount);
|
||||||
if(showConsoleDebugInfo && nodeLimitReached) {
|
if(showConsoleDebugInfo && nodeLimitReached) {
|
||||||
//if(showConsoleDebugInfo) {
|
|
||||||
printf("**Check if dest blocked [%d - %d], unit [%d - %s] from [%s] to [%s] distance %.2f took msecs: %lld nodeLimitReached = %d, failureCount = %d [%d]\n",
|
printf("**Check if dest blocked [%d - %d], unit [%d - %s] from [%s] to [%s] distance %.2f took msecs: %lld nodeLimitReached = %d, failureCount = %d [%d]\n",
|
||||||
nodeLimitReached, inBailout, unit->getId(),unit->getFullName().c_str(), unitPos.getString().c_str(), finalPos.getString().c_str(), dist,(long long int)chrono.getMillis(),nodeLimitReached,failureCount,cellCount);
|
nodeLimitReached, inBailout, unit->getId(),unit->getFullName().c_str(), unitPos.getString().c_str(), finalPos.getString().c_str(), dist,(long long int)chrono.getMillis(),nodeLimitReached,failureCount,cellCount);
|
||||||
}
|
}
|
||||||
|
@ -716,6 +630,8 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
|
|
||||||
|
// START
|
||||||
|
// Do the a-start base pathfind work if required
|
||||||
int whileLoopCount = 0;
|
int whileLoopCount = 0;
|
||||||
while(nodeLimitReached == false) {
|
while(nodeLimitReached == false) {
|
||||||
whileLoopCount++;
|
whileLoopCount++;
|
||||||
|
@ -757,9 +673,6 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
|
||||||
cellCount++;
|
cellCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// if(failureCount == cellCount && node->pos == unitPos) {
|
|
||||||
// nodeLimitReached = true;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
else if(tryDirection == 2) {
|
else if(tryDirection == 2) {
|
||||||
for(int i = -1; i <= 1 && nodeLimitReached == false; ++i) {
|
for(int i = -1; i <= 1 && nodeLimitReached == false; ++i) {
|
||||||
|
@ -770,9 +683,6 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
|
||||||
cellCount++;
|
cellCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// if(failureCount == cellCount && node->pos == unitPos) {
|
|
||||||
// nodeLimitReached = true;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
else if(tryDirection == 1) {
|
else if(tryDirection == 1) {
|
||||||
for(int i = -1; i <= 1 && nodeLimitReached == false; ++i) {
|
for(int i = -1; i <= 1 && nodeLimitReached == false; ++i) {
|
||||||
|
@ -783,9 +693,6 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
|
||||||
cellCount++;
|
cellCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// if(failureCount == cellCount && node->pos == unitPos) {
|
|
||||||
// nodeLimitReached = true;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
for(int i = 1; i >= -1 && nodeLimitReached == false; --i) {
|
for(int i = 1; i >= -1 && nodeLimitReached == false; --i) {
|
||||||
|
@ -796,9 +703,6 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
|
||||||
cellCount++;
|
cellCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// if(failureCount == cellCount && node->pos == unitPos) {
|
|
||||||
// nodeLimitReached = true;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
} //while
|
} //while
|
||||||
|
|
||||||
|
@ -823,7 +727,6 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
|
||||||
|
|
||||||
//check results of path finding
|
//check results of path finding
|
||||||
ts = tsImpossible;
|
ts = tsImpossible;
|
||||||
//UnitPathInterface *path= unit->getPath();
|
|
||||||
if(pathFound == false || lastNode == firstNode) {
|
if(pathFound == false || lastNode == firstNode) {
|
||||||
//blocked
|
//blocked
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugPathFinder).enabled == true) {
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugPathFinder).enabled == true) {
|
||||||
|
|
|
@ -1133,110 +1133,110 @@ void Faction::cleanupResourceTypeTargetCache(std::vector<Vec2i> *deleteListPtr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Vec2i> Faction::findCachedPath(const Vec2i &target, Unit *unit) {
|
//std::vector<Vec2i> Faction::findCachedPath(const Vec2i &target, Unit *unit) {
|
||||||
std::vector<Vec2i> result;
|
// std::vector<Vec2i> result;
|
||||||
if(cachingDisabled == false) {
|
// if(cachingDisabled == false) {
|
||||||
if(successfulPathFinderTargetList.find(target) == successfulPathFinderTargetList.end()) {
|
// if(successfulPathFinderTargetList.find(target) == successfulPathFinderTargetList.end()) {
|
||||||
// Lets find the shortest and most successful path already taken by a
|
// // Lets find the shortest and most successful path already taken by a
|
||||||
// similar sized unit
|
// // similar sized unit
|
||||||
|
//
|
||||||
|
// bool foundCachedPath = false;
|
||||||
|
// std::vector<FactionPathSuccessCache> &cacheList = successfulPathFinderTargetList[target];
|
||||||
|
// int unitSize = unit->getType()->getSize();
|
||||||
|
// for(int i = 0; i < cacheList.size(); ++i) {
|
||||||
|
// FactionPathSuccessCache &cache = cacheList[i];
|
||||||
|
// if(cache.unitSize <= unitSize) {
|
||||||
|
// vector<std::pair<vector<Vec2i>, int> > &pathQueue = cache.pathQueue;
|
||||||
|
//
|
||||||
|
// for(int j = 0; j < pathQueue.size(); ++j) {
|
||||||
|
// // Now start at the end of the path and see how many nodes
|
||||||
|
// // until we reach a cell near the unit's current position
|
||||||
|
// std::pair<vector<Vec2i>, int> &path = pathQueue[j];
|
||||||
|
//
|
||||||
|
// for(int k = path.first.size() - 1; k >= 0; --k) {
|
||||||
|
// if(world->getMap()->canMove(unit, unit->getPos(), path.first[k]) == true) {
|
||||||
|
// if(foundCachedPath == false) {
|
||||||
|
// for(int l = k; l < path.first.size(); ++l) {
|
||||||
|
// result.push_back(path.first[l]);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// else {
|
||||||
|
// if(result.size() > (path.first.size() - k)) {
|
||||||
|
// for(int l = k; l < path.first.size(); ++l) {
|
||||||
|
// result.push_back(path.first[l]);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// foundCachedPath = true;
|
||||||
|
//
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// return result;
|
||||||
|
//}
|
||||||
|
|
||||||
bool foundCachedPath = false;
|
//void Faction::addCachedPath(const Vec2i &target, Unit *unit) {
|
||||||
std::vector<FactionPathSuccessCache> &cacheList = successfulPathFinderTargetList[target];
|
// if(cachingDisabled == false) {
|
||||||
int unitSize = unit->getType()->getSize();
|
// if(successfulPathFinderTargetList.find(target) == successfulPathFinderTargetList.end()) {
|
||||||
for(int i = 0; i < cacheList.size(); ++i) {
|
// FactionPathSuccessCache cache;
|
||||||
FactionPathSuccessCache &cache = cacheList[i];
|
// cache.unitSize = unit->getType()->getSize();
|
||||||
if(cache.unitSize <= unitSize) {
|
// cache.pathQueue.push_back(make_pair<vector<Vec2i>, int>(unit->getCurrentTargetPathTaken().second,1));
|
||||||
vector<std::pair<vector<Vec2i>, int> > &pathQueue = cache.pathQueue;
|
// successfulPathFinderTargetList[target].push_back(cache);
|
||||||
|
// }
|
||||||
for(int j = 0; j < pathQueue.size(); ++j) {
|
// else {
|
||||||
// Now start at the end of the path and see how many nodes
|
// bool finishedAdd = false;
|
||||||
// until we reach a cell near the unit's current position
|
// std::pair<Vec2i,std::vector<Vec2i> > currentTargetPathTaken = unit->getCurrentTargetPathTaken();
|
||||||
std::pair<vector<Vec2i>, int> &path = pathQueue[j];
|
// std::vector<FactionPathSuccessCache> &cacheList = successfulPathFinderTargetList[target];
|
||||||
|
// int unitSize = unit->getType()->getSize();
|
||||||
for(int k = path.first.size() - 1; k >= 0; --k) {
|
//
|
||||||
if(world->getMap()->canMove(unit, unit->getPos(), path.first[k]) == true) {
|
// for(int i = 0; i < cacheList.size() && finishedAdd == false; ++i) {
|
||||||
if(foundCachedPath == false) {
|
// FactionPathSuccessCache &cache = cacheList[i];
|
||||||
for(int l = k; l < path.first.size(); ++l) {
|
// if(cache.unitSize <= unitSize) {
|
||||||
result.push_back(path.first[l]);
|
// vector<std::pair<vector<Vec2i>, int> > &pathQueue = cache.pathQueue;
|
||||||
}
|
//
|
||||||
}
|
// for(int j = 0; j < pathQueue.size() && finishedAdd == false; ++j) {
|
||||||
else {
|
// // Now start at the end of the path and see how many nodes are the same
|
||||||
if(result.size() > (path.first.size() - k)) {
|
// std::pair<vector<Vec2i>, int> &path = pathQueue[j];
|
||||||
for(int l = k; l < path.first.size(); ++l) {
|
// int minPathSize = std::min(path.first.size(),currentTargetPathTaken.second.size());
|
||||||
result.push_back(path.first[l]);
|
// int intersectIndex = -1;
|
||||||
}
|
//
|
||||||
}
|
// for(int k = 0; k < minPathSize; ++k) {
|
||||||
}
|
// if(path.first[path.first.size() - k - 1] != currentTargetPathTaken.second[currentTargetPathTaken.second.size() - k - 1]) {
|
||||||
foundCachedPath = true;
|
// intersectIndex = k;
|
||||||
|
// break;
|
||||||
break;
|
// }
|
||||||
}
|
// }
|
||||||
}
|
//
|
||||||
}
|
// // New path is same or longer than old path so replace
|
||||||
}
|
// // old path with new
|
||||||
}
|
// if(intersectIndex + 1 == path.first.size()) {
|
||||||
}
|
// path.first = currentTargetPathTaken.second;
|
||||||
}
|
// path.second++;
|
||||||
|
// finishedAdd = true;
|
||||||
return result;
|
// }
|
||||||
}
|
// // Old path is same or longer than new path so
|
||||||
|
// // do nothing
|
||||||
void Faction::addCachedPath(const Vec2i &target, Unit *unit) {
|
// else if(intersectIndex + 1 == currentTargetPathTaken.second.size()) {
|
||||||
if(cachingDisabled == false) {
|
// path.second++;
|
||||||
if(successfulPathFinderTargetList.find(target) == successfulPathFinderTargetList.end()) {
|
// finishedAdd = true;
|
||||||
FactionPathSuccessCache cache;
|
// }
|
||||||
cache.unitSize = unit->getType()->getSize();
|
// }
|
||||||
cache.pathQueue.push_back(make_pair<vector<Vec2i>, int>(unit->getCurrentTargetPathTaken().second,1));
|
//
|
||||||
successfulPathFinderTargetList[target].push_back(cache);
|
// // If new path is >= 10 cells add it
|
||||||
}
|
// if(finishedAdd == false && currentTargetPathTaken.second.size() >= 10) {
|
||||||
else {
|
// pathQueue.push_back(make_pair<vector<Vec2i>, int>(currentTargetPathTaken.second,1));
|
||||||
bool finishedAdd = false;
|
// }
|
||||||
std::pair<Vec2i,std::vector<Vec2i> > currentTargetPathTaken = unit->getCurrentTargetPathTaken();
|
// }
|
||||||
std::vector<FactionPathSuccessCache> &cacheList = successfulPathFinderTargetList[target];
|
// }
|
||||||
int unitSize = unit->getType()->getSize();
|
// }
|
||||||
|
// }
|
||||||
for(int i = 0; i < cacheList.size() && finishedAdd == false; ++i) {
|
//}
|
||||||
FactionPathSuccessCache &cache = cacheList[i];
|
|
||||||
if(cache.unitSize <= unitSize) {
|
|
||||||
vector<std::pair<vector<Vec2i>, int> > &pathQueue = cache.pathQueue;
|
|
||||||
|
|
||||||
for(int j = 0; j < pathQueue.size() && finishedAdd == false; ++j) {
|
|
||||||
// Now start at the end of the path and see how many nodes are the same
|
|
||||||
std::pair<vector<Vec2i>, int> &path = pathQueue[j];
|
|
||||||
int minPathSize = std::min(path.first.size(),currentTargetPathTaken.second.size());
|
|
||||||
int intersectIndex = -1;
|
|
||||||
|
|
||||||
for(int k = 0; k < minPathSize; ++k) {
|
|
||||||
if(path.first[path.first.size() - k - 1] != currentTargetPathTaken.second[currentTargetPathTaken.second.size() - k - 1]) {
|
|
||||||
intersectIndex = k;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// New path is same or longer than old path so replace
|
|
||||||
// old path with new
|
|
||||||
if(intersectIndex + 1 == path.first.size()) {
|
|
||||||
path.first = currentTargetPathTaken.second;
|
|
||||||
path.second++;
|
|
||||||
finishedAdd = true;
|
|
||||||
}
|
|
||||||
// Old path is same or longer than new path so
|
|
||||||
// do nothing
|
|
||||||
else if(intersectIndex + 1 == currentTargetPathTaken.second.size()) {
|
|
||||||
path.second++;
|
|
||||||
finishedAdd = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If new path is >= 10 cells add it
|
|
||||||
if(finishedAdd == false && currentTargetPathTaken.second.size() >= 10) {
|
|
||||||
pathQueue.push_back(make_pair<vector<Vec2i>, int>(currentTargetPathTaken.second,1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Faction::deletePixels() {
|
void Faction::deletePixels() {
|
||||||
if(factionType != NULL) {
|
if(factionType != NULL) {
|
||||||
|
|
|
@ -49,14 +49,6 @@ class Faction;
|
||||||
/// Each of the game players
|
/// Each of the game players
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
class FactionPathSuccessCache {
|
|
||||||
public:
|
|
||||||
// The unit Size for the path findings
|
|
||||||
int unitSize;
|
|
||||||
// a List of paths with their # success counts
|
|
||||||
vector<std::pair<vector<Vec2i>, int> > pathQueue;
|
|
||||||
};
|
|
||||||
|
|
||||||
class FactionThread : public BaseThread {
|
class FactionThread : public BaseThread {
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
@ -109,16 +101,8 @@ private:
|
||||||
bool factionDisconnectHandled;
|
bool factionDisconnectHandled;
|
||||||
|
|
||||||
bool cachingDisabled;
|
bool cachingDisabled;
|
||||||
std::map<Vec2i, std::vector<FactionPathSuccessCache> > successfulPathFinderTargetList;
|
|
||||||
std::map<Vec2i,int> cacheResourceTargetList;
|
std::map<Vec2i,int> cacheResourceTargetList;
|
||||||
std::map<Vec2i,bool> cachedCloseResourceTargetLookupList;
|
std::map<Vec2i,bool> cachedCloseResourceTargetLookupList;
|
||||||
//time_t lastResourceTargettListPurge;
|
|
||||||
//int lastResourceTargettListPurge;
|
|
||||||
|
|
||||||
//std::map<CommandClass,std::map<int,int> > cacheUnitCommandClassList;
|
|
||||||
// This cache stores the units free cell movement calcs during a world
|
|
||||||
// update of the faction
|
|
||||||
//std::map<int,std::map<Field, std::map<Vec2i,std::map<Vec2i, > > > localCacheForUnitCellMovement;
|
|
||||||
|
|
||||||
RandomGen random;
|
RandomGen random;
|
||||||
FactionThread *workerThread;
|
FactionThread *workerThread;
|
||||||
|
@ -176,7 +160,6 @@ public:
|
||||||
bool reqsOk(const CommandType *ct) const;
|
bool reqsOk(const CommandType *ct) const;
|
||||||
int getCountForMaxUnitCount(const UnitType *unitType) const;
|
int getCountForMaxUnitCount(const UnitType *unitType) const;
|
||||||
|
|
||||||
|
|
||||||
//diplomacy
|
//diplomacy
|
||||||
bool isAlly(const Faction *faction);
|
bool isAlly(const Faction *faction);
|
||||||
|
|
||||||
|
@ -193,9 +176,6 @@ public:
|
||||||
|
|
||||||
void setControlType(ControlType value) { control = value; }
|
void setControlType(ControlType value) { control = value; }
|
||||||
|
|
||||||
std::vector<Vec2i> findCachedPath(const Vec2i &target, Unit *unit);
|
|
||||||
void addCachedPath(const Vec2i &target, Unit *unit);
|
|
||||||
|
|
||||||
bool isResourceTargetInCache(const Vec2i &pos,bool incrementUseCounter=false);
|
bool isResourceTargetInCache(const Vec2i &pos,bool incrementUseCounter=false);
|
||||||
void addResourceTargetToCache(const Vec2i &pos,bool incrementUseCounter=true);
|
void addResourceTargetToCache(const Vec2i &pos,bool incrementUseCounter=true);
|
||||||
void removeResourceTargetFromCache(const Vec2i &pos);
|
void removeResourceTargetFromCache(const Vec2i &pos);
|
||||||
|
|
|
@ -2058,15 +2058,13 @@ void Unit::setLastHarvestResourceTarget(const Vec2i *pos) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Unit::addCurrentTargetPathTakenCell(const Vec2i &target,const Vec2i &cell) {
|
//void Unit::addCurrentTargetPathTakenCell(const Vec2i &target,const Vec2i &cell) {
|
||||||
/*
|
// if(currentTargetPathTaken.first != target) {
|
||||||
if(currentTargetPathTaken.first != target) {
|
// currentTargetPathTaken.second.clear();
|
||||||
currentTargetPathTaken.second.clear();
|
// }
|
||||||
}
|
// currentTargetPathTaken.first = target;
|
||||||
currentTargetPathTaken.first = target;
|
// currentTargetPathTaken.second.push_back(cell);
|
||||||
currentTargetPathTaken.second.push_back(cell);
|
//}
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string Unit::toString() const {
|
std::string Unit::toString() const {
|
||||||
std::string result = "";
|
std::string result = "";
|
||||||
|
|
|
@ -326,7 +326,7 @@ private:
|
||||||
//time_t lastBadHarvestListPurge;
|
//time_t lastBadHarvestListPurge;
|
||||||
std::pair<Vec2i,int> lastHarvestResourceTarget;
|
std::pair<Vec2i,int> lastHarvestResourceTarget;
|
||||||
|
|
||||||
std::pair<Vec2i,std::vector<Vec2i> > currentTargetPathTaken;
|
//std::pair<Vec2i,std::vector<Vec2i> > currentTargetPathTaken;
|
||||||
|
|
||||||
static Game *game;
|
static Game *game;
|
||||||
|
|
||||||
|
@ -489,8 +489,8 @@ public:
|
||||||
void setLastHarvestResourceTarget(const Vec2i *pos);
|
void setLastHarvestResourceTarget(const Vec2i *pos);
|
||||||
std::pair<Vec2i,int> getLastHarvestResourceTarget() const { return lastHarvestResourceTarget;}
|
std::pair<Vec2i,int> getLastHarvestResourceTarget() const { return lastHarvestResourceTarget;}
|
||||||
|
|
||||||
std::pair<Vec2i,std::vector<Vec2i> > getCurrentTargetPathTaken() const { return currentTargetPathTaken; }
|
//std::pair<Vec2i,std::vector<Vec2i> > getCurrentTargetPathTaken() const { return currentTargetPathTaken; }
|
||||||
void addCurrentTargetPathTakenCell(const Vec2i &target,const Vec2i &cell);
|
//void addCurrentTargetPathTakenCell(const Vec2i &target,const Vec2i &cell);
|
||||||
|
|
||||||
void logSynchData(string file,int line,string source="");
|
void logSynchData(string file,int line,string source="");
|
||||||
std::string toString() const;
|
std::string toString() const;
|
||||||
|
|
Loading…
Reference in New Issue