- units now use a random # from 10-20 cells to determine how often they refresh their path

This commit is contained in:
Mark Vejvoda 2012-05-12 01:06:55 +00:00
parent dc270fbbaa
commit 5458f7abb4
3 changed files with 46 additions and 14 deletions

View File

@ -477,7 +477,8 @@ TravelState PathFinder::aStarFast(Unit *unit, Vec2i finalPos, bool inBailout, in
throw megaglest_runtime_error("Pathfinder invalid node path position = " + nodePos.getString() + " i = " + intToStr(i));
}
if(i < pathFindRefresh ||
//if(i < pathFindRefresh ||
if(i < unit->getPathFindRefreshCellCount() ||
(factions[unitFactionIndex].precachedPath[unit->getId()].size() >= pathFindExtendRefreshForNodeCount &&
i < getPathFindExtendRefreshNodeCount(unitFactionIndex))) {
//!!! Test MV
@ -502,7 +503,8 @@ TravelState PathFinder::aStarFast(Unit *unit, Vec2i finalPos, bool inBailout, in
throw megaglest_runtime_error("Pathfinder invalid node path position = " + nodePos.getString() + " i = " + intToStr(i));
}
if(i < pathFindRefresh ||
//if(i < pathFindRefresh ||
if(i < unit->getPathFindRefreshCellCount() ||
(factions[unitFactionIndex].precachedPath[unit->getId()].size() >= pathFindExtendRefreshForNodeCount &&
i < getPathFindExtendRefreshNodeCount(unitFactionIndex))) {
path->add(nodePos);
@ -584,7 +586,8 @@ TravelState PathFinder::aStarFast(Unit *unit, Vec2i finalPos, bool inBailout, in
factions[unitFactionIndex].precachedPath[unit->getId()].push_back(cachedPath[k]);
}
else {
if(pathCount < pathFindRefresh) {
//if(pathCount < pathFindRefresh) {
if(pathCount < unit->getPathFindRefreshCellCount()) {
basicPathFinder->add(cachedPath[k]);
}
basicPathFinder->addToLastPathCache(cachedPath[k]);
@ -618,7 +621,8 @@ TravelState PathFinder::aStarFast(Unit *unit, Vec2i finalPos, bool inBailout, in
unit->setUsePathfinderExtendedMaxNodes(false);
return ts;
}
else if(j - i > pathFindRefresh) {
//else if(j - i > pathFindRefresh) {
else if(j - i > unit->getPathFindRefreshCellCount()) {
//on the way
ts= tsMoving;
@ -639,7 +643,8 @@ TravelState PathFinder::aStarFast(Unit *unit, Vec2i finalPos, bool inBailout, in
factions[unitFactionIndex].precachedPath[unit->getId()].push_back(cachedPath[k]);
}
else {
if(pathCount < pathFindRefresh) {
//if(pathCount < pathFindRefresh) {
if(pathCount < unit->getPathFindRefreshCellCount()) {
basicPathFinder->add(cachedPath[k]);
}
basicPathFinder->addToLastPathCache(cachedPath[k]);
@ -862,8 +867,8 @@ TravelState PathFinder::aStarFast(Unit *unit, Vec2i finalPos, bool inBailout, in
factions[unitFactionIndex].precachedPath[unit->getId()].push_back(nodePos);
}
else {
//if(i < pathFindRefresh) {
if(i < pathFindRefresh ||
//if(i < pathFindRefresh ||
if(i < unit->getPathFindRefreshCellCount() ||
(nodeSearchCount >= pathFindExtendRefreshForNodeCount &&
i < getPathFindExtendRefreshNodeCount(unitFactionIndex))) {
path->add(nodePos);
@ -1322,7 +1327,8 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
throw megaglest_runtime_error("Pathfinder invalid node path position = " + nodePos.getString() + " i = " + intToStr(i));
}
if(i < pathFindRefresh ||
//if(i < pathFindRefresh ||
if(i < unit->getPathFindRefreshCellCount() ||
(factions[unitFactionIndex].precachedPath[unit->getId()].size() >= pathFindExtendRefreshForNodeCount &&
i < getPathFindExtendRefreshNodeCount(unitFactionIndex))) {
//!!! Test MV
@ -1347,7 +1353,8 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
throw megaglest_runtime_error("Pathfinder invalid node path position = " + nodePos.getString() + " i = " + intToStr(i));
}
if(i < pathFindRefresh ||
//if(i < pathFindRefresh ||
if(i < unit->getPathFindRefreshCellCount() ||
(factions[unitFactionIndex].precachedPath[unit->getId()].size() >= pathFindExtendRefreshForNodeCount &&
i < getPathFindExtendRefreshNodeCount(unitFactionIndex))) {
path->add(nodePos);
@ -1426,7 +1433,8 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
factions[unitFactionIndex].precachedPath[unit->getId()].push_back(cachedPath[k]);
}
else {
if(pathCount < pathFindRefresh) {
//if(pathCount < pathFindRefresh) {
if(pathCount < unit->getPathFindRefreshCellCount()) {
basicPathFinder->add(cachedPath[k]);
}
basicPathFinder->addToLastPathCache(cachedPath[k]);
@ -1460,7 +1468,8 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
unit->setUsePathfinderExtendedMaxNodes(false);
return ts;
}
else if(j - i > pathFindRefresh) {
//else if(j - i > pathFindRefresh) {
else if(j - i > unit->getPathFindRefreshCellCount()) {
//on the way
ts= tsMoving;
@ -1481,7 +1490,8 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
factions[unitFactionIndex].precachedPath[unit->getId()].push_back(cachedPath[k]);
}
else {
if(pathCount < pathFindRefresh) {
//if(pathCount < pathFindRefresh) {
if(pathCount < unit->getPathFindRefreshCellCount()) {
basicPathFinder->add(cachedPath[k]);
}
basicPathFinder->addToLastPathCache(cachedPath[k]);
@ -1765,7 +1775,8 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
factions[unitFactionIndex].precachedPath[unit->getId()].push_back(nodePos);
}
else {
if(i < pathFindRefresh ||
//if(i < pathFindRefresh ||
if(i < unit->getPathFindRefreshCellCount() ||
(whileLoopCount >= pathFindExtendRefreshForNodeCount &&
i < getPathFindExtendRefreshNodeCount(unitFactionIndex))) {
path->add(nodePos);

View File

@ -401,7 +401,9 @@ Unit::Unit(int id, UnitPathInterface *unitpath, const Vec2i &pos,
this->unitPath = unitpath;
this->unitPath->setMap(map);
RandomGen random;
//RandomGen random;
random.init(id);
pathFindRefreshCellCount = random.randRange(10,20);
if(map->isInside(pos) == false || map->isInsideSurface(map->toSurfCoords(pos)) == false) {
throw megaglest_runtime_error("#2 Invalid path position = " + pos.getString());
@ -3487,6 +3489,9 @@ std::string Unit::toString() const {
result += "inBailOutAttempt = " + intToStr(inBailOutAttempt) + "\n";
result += "random = " + intToStr(random.getLastNumber()) + "\n";
result += "pathFindRefreshCellCount = " + intToStr(pathFindRefreshCellCount) + "\n";
return result;
}
@ -3774,6 +3779,9 @@ void Unit::saveGame(XmlNode *rootNode) {
unitNode->addAttribute("pathfindFailedConsecutiveFrameCount",intToStr(pathfindFailedConsecutiveFrameCount), mapTagReplacements);
unitNode->addAttribute("currentPathFinderDesiredFinalPos",currentPathFinderDesiredFinalPos.getString(), mapTagReplacements);
unitNode->addAttribute("random",intToStr(random.getLastNumber()), mapTagReplacements);
unitNode->addAttribute("pathFindRefreshCellCount",intToStr(pathFindRefreshCellCount), mapTagReplacements);
}
Unit * Unit::loadGame(const XmlNode *rootNode, GameSettings *settings, Faction *faction, World *world) {
@ -4191,6 +4199,14 @@ Unit * Unit::loadGame(const XmlNode *rootNode, GameSettings *settings, Faction *
if(unitNode->hasAttribute("currentPathFinderDesiredFinalPos")) {
result->currentPathFinderDesiredFinalPos = Vec2i::strToVec2(unitNode->getAttribute("currentPathFinderDesiredFinalPos")->getValue());
}
if(unitNode->hasAttribute("random")) {
result->random.setLastNumber(unitNode->getAttribute("random")->getIntValue());
}
if(unitNode->hasAttribute("pathFindRefreshCellCount")) {
result->pathFindRefreshCellCount = unitNode->getAttribute("pathFindRefreshCellCount")->getIntValue();
}
return result;
}

View File

@ -439,6 +439,9 @@ private:
uint32 pathfindFailedConsecutiveFrameCount;
Vec2i currentPathFinderDesiredFinalPos;
RandomGen random;
int pathFindRefreshCellCount;
public:
Unit(int id, UnitPathInterface *path, const Vec2i &pos, const UnitType *type, Faction *faction, Map *map, CardinalDir placeFacing);
~Unit();
@ -447,6 +450,8 @@ public:
static void setGame(Game *value) { game=value;}
inline int getPathFindRefreshCellCount() const { return pathFindRefreshCellCount; }
void setCurrentPathFinderDesiredFinalPos(const Vec2i &finalPos) { currentPathFinderDesiredFinalPos = finalPos; }
Vec2i getCurrentPathFinderDesiredFinalPos() const { return currentPathFinderDesiredFinalPos; }