- 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) {
|
||||
factions.push_back(FactionState());
|
||||
}
|
||||
//nodePool.clear();
|
||||
map=NULL;
|
||||
}
|
||||
|
||||
|
@ -57,8 +56,6 @@ PathFinder::PathFinder(const Map *map) {
|
|||
factions.push_back(FactionState());
|
||||
}
|
||||
|
||||
//nodePool.clear();
|
||||
|
||||
map=NULL;
|
||||
init(map);
|
||||
}
|
||||
|
@ -97,8 +94,6 @@ void PathFinder::removeUnitPrecache(Unit *unit) {
|
|||
}
|
||||
|
||||
TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos, bool *wasStuck, int frameIndex) {
|
||||
//printf("PathFinder::findPath...\n");
|
||||
|
||||
if(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->getFaction()->addCachedPath(finalPos,unit);
|
||||
return tsArrived;
|
||||
}
|
||||
|
||||
|
@ -144,7 +138,6 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos, bool *wasStu
|
|||
if(map->canMove(unit, unit->getPos(), pos)) {
|
||||
if(frameIndex < 0) {
|
||||
unit->setTargetPos(pos);
|
||||
unit->addCurrentTargetPathTakenCell(finalPos,pos);
|
||||
}
|
||||
return tsMoving;
|
||||
}
|
||||
|
@ -168,41 +161,14 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos, bool *wasStu
|
|||
|
||||
|
||||
TravelState ts = tsImpossible;
|
||||
//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;
|
||||
//}
|
||||
//else {
|
||||
//route cache miss
|
||||
//route cache miss
|
||||
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
|
||||
switch(ts) {
|
||||
case tsBlocked:
|
||||
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)
|
||||
// We will try to bail out of the immediate area
|
||||
if( ts == tsBlocked && unit->getInBailOutAttempt() == false &&
|
||||
|
@ -220,48 +186,10 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos, bool *wasStu
|
|||
}
|
||||
unit->setInBailOutAttempt(true);
|
||||
|
||||
//printf("#1 BAILOUT test unitid [%d]\n",unit->getId());
|
||||
|
||||
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) {
|
||||
//int tryRadius = random.randRange(-PathFinder::pathFindBailoutRadius, PathFinder::pathFindBailoutRadius);
|
||||
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
|
||||
if(tryRadius > 0) {
|
||||
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];
|
||||
}
|
||||
|
||||
//if(map->canMove(unit, unit->getPos(), pos, &lookupCacheCanMove)) {
|
||||
if(map->canMove(unit, unit->getPos(), pos)) {
|
||||
if(frameIndex < 0) {
|
||||
unit->setTargetPos(pos);
|
||||
unit->addCurrentTargetPathTakenCell(finalPos,pos);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -395,10 +321,9 @@ bool PathFinder::processNode(Unit *unit, Node *node,const Vec2i finalPos, int i,
|
|||
//route a unit using A* algorithm
|
||||
TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout,
|
||||
int frameIndex) {
|
||||
//printf("PathFinder::aStar...\n");
|
||||
|
||||
Chrono chrono;
|
||||
chrono.start();
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled) chrono.start();
|
||||
|
||||
if(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);
|
||||
|
||||
float dist= unitPos.dist(finalPos);
|
||||
|
||||
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());
|
||||
|
||||
|
||||
// Check the previous path find cache for the unit to see if its good to
|
||||
// use
|
||||
if((showConsoleDebugInfo || tryLastPathCache) && dist > 60) {
|
||||
if(showConsoleDebugInfo) printf("Distance from [%d - %s] to destination is %.2f tryLastPathCache = %d\n",unit->getId(),unit->getFullName().c_str(), dist,tryLastPathCache);
|
||||
if(showConsoleDebugInfo || 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) {
|
||||
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());
|
||||
|
||||
return ts;
|
||||
//break;
|
||||
}
|
||||
else if(j - i > pathFindRefresh) {
|
||||
//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());
|
||||
|
||||
// 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) {
|
||||
int failureCount = 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(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",
|
||||
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(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",
|
||||
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;
|
||||
while(nodeLimitReached == false) {
|
||||
whileLoopCount++;
|
||||
|
@ -757,9 +673,6 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
|
|||
cellCount++;
|
||||
}
|
||||
}
|
||||
// if(failureCount == cellCount && node->pos == unitPos) {
|
||||
// nodeLimitReached = true;
|
||||
// }
|
||||
}
|
||||
else if(tryDirection == 2) {
|
||||
for(int i = -1; i <= 1 && nodeLimitReached == false; ++i) {
|
||||
|
@ -770,9 +683,6 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
|
|||
cellCount++;
|
||||
}
|
||||
}
|
||||
// if(failureCount == cellCount && node->pos == unitPos) {
|
||||
// nodeLimitReached = true;
|
||||
// }
|
||||
}
|
||||
else if(tryDirection == 1) {
|
||||
for(int i = -1; i <= 1 && nodeLimitReached == false; ++i) {
|
||||
|
@ -783,9 +693,6 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
|
|||
cellCount++;
|
||||
}
|
||||
}
|
||||
// if(failureCount == cellCount && node->pos == unitPos) {
|
||||
// nodeLimitReached = true;
|
||||
// }
|
||||
}
|
||||
else {
|
||||
for(int i = 1; i >= -1 && nodeLimitReached == false; --i) {
|
||||
|
@ -796,9 +703,6 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
|
|||
cellCount++;
|
||||
}
|
||||
}
|
||||
// if(failureCount == cellCount && node->pos == unitPos) {
|
||||
// nodeLimitReached = true;
|
||||
// }
|
||||
}
|
||||
} //while
|
||||
|
||||
|
@ -823,7 +727,6 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
|
|||
|
||||
//check results of path finding
|
||||
ts = tsImpossible;
|
||||
//UnitPathInterface *path= unit->getPath();
|
||||
if(pathFound == false || lastNode == firstNode) {
|
||||
//blocked
|
||||
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> result;
|
||||
if(cachingDisabled == false) {
|
||||
if(successfulPathFinderTargetList.find(target) == successfulPathFinderTargetList.end()) {
|
||||
// Lets find the shortest and most successful path already taken by a
|
||||
// similar sized unit
|
||||
//std::vector<Vec2i> Faction::findCachedPath(const Vec2i &target, Unit *unit) {
|
||||
// std::vector<Vec2i> result;
|
||||
// if(cachingDisabled == false) {
|
||||
// if(successfulPathFinderTargetList.find(target) == successfulPathFinderTargetList.end()) {
|
||||
// // Lets find the shortest and most successful path already taken by a
|
||||
// // 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;
|
||||
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;
|
||||
}
|
||||
|
||||
void Faction::addCachedPath(const Vec2i &target, Unit *unit) {
|
||||
if(cachingDisabled == false) {
|
||||
if(successfulPathFinderTargetList.find(target) == successfulPathFinderTargetList.end()) {
|
||||
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);
|
||||
}
|
||||
else {
|
||||
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::addCachedPath(const Vec2i &target, Unit *unit) {
|
||||
// if(cachingDisabled == false) {
|
||||
// if(successfulPathFinderTargetList.find(target) == successfulPathFinderTargetList.end()) {
|
||||
// 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);
|
||||
// }
|
||||
// else {
|
||||
// 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() {
|
||||
if(factionType != NULL) {
|
||||
|
|
|
@ -49,14 +49,6 @@ class Faction;
|
|||
/// 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 {
|
||||
protected:
|
||||
|
||||
|
@ -109,16 +101,8 @@ private:
|
|||
bool factionDisconnectHandled;
|
||||
|
||||
bool cachingDisabled;
|
||||
std::map<Vec2i, std::vector<FactionPathSuccessCache> > successfulPathFinderTargetList;
|
||||
std::map<Vec2i,int> cacheResourceTargetList;
|
||||
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;
|
||||
FactionThread *workerThread;
|
||||
|
@ -176,7 +160,6 @@ public:
|
|||
bool reqsOk(const CommandType *ct) const;
|
||||
int getCountForMaxUnitCount(const UnitType *unitType) const;
|
||||
|
||||
|
||||
//diplomacy
|
||||
bool isAlly(const Faction *faction);
|
||||
|
||||
|
@ -193,9 +176,6 @@ public:
|
|||
|
||||
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);
|
||||
void addResourceTargetToCache(const Vec2i &pos,bool incrementUseCounter=true);
|
||||
void removeResourceTargetFromCache(const Vec2i &pos);
|
||||
|
|
|
@ -2058,15 +2058,13 @@ void Unit::setLastHarvestResourceTarget(const Vec2i *pos) {
|
|||
}
|
||||
}
|
||||
|
||||
void Unit::addCurrentTargetPathTakenCell(const Vec2i &target,const Vec2i &cell) {
|
||||
/*
|
||||
if(currentTargetPathTaken.first != target) {
|
||||
currentTargetPathTaken.second.clear();
|
||||
}
|
||||
currentTargetPathTaken.first = target;
|
||||
currentTargetPathTaken.second.push_back(cell);
|
||||
*/
|
||||
}
|
||||
//void Unit::addCurrentTargetPathTakenCell(const Vec2i &target,const Vec2i &cell) {
|
||||
// if(currentTargetPathTaken.first != target) {
|
||||
// currentTargetPathTaken.second.clear();
|
||||
// }
|
||||
// currentTargetPathTaken.first = target;
|
||||
// currentTargetPathTaken.second.push_back(cell);
|
||||
//}
|
||||
|
||||
std::string Unit::toString() const {
|
||||
std::string result = "";
|
||||
|
|
|
@ -326,7 +326,7 @@ private:
|
|||
//time_t lastBadHarvestListPurge;
|
||||
std::pair<Vec2i,int> lastHarvestResourceTarget;
|
||||
|
||||
std::pair<Vec2i,std::vector<Vec2i> > currentTargetPathTaken;
|
||||
//std::pair<Vec2i,std::vector<Vec2i> > currentTargetPathTaken;
|
||||
|
||||
static Game *game;
|
||||
|
||||
|
@ -489,8 +489,8 @@ public:
|
|||
void setLastHarvestResourceTarget(const Vec2i *pos);
|
||||
std::pair<Vec2i,int> getLastHarvestResourceTarget() const { return lastHarvestResourceTarget;}
|
||||
|
||||
std::pair<Vec2i,std::vector<Vec2i> > getCurrentTargetPathTaken() const { return currentTargetPathTaken; }
|
||||
void addCurrentTargetPathTakenCell(const Vec2i &target,const Vec2i &cell);
|
||||
//std::pair<Vec2i,std::vector<Vec2i> > getCurrentTargetPathTaken() const { return currentTargetPathTaken; }
|
||||
//void addCurrentTargetPathTakenCell(const Vec2i &target,const Vec2i &cell);
|
||||
|
||||
void logSynchData(string file,int line,string source="");
|
||||
std::string toString() const;
|
||||
|
|
Loading…
Reference in New Issue