diff options
author | Andrew Kurushin | 2005-01-06 22:22:20 +0000 |
---|---|---|
committer | Andrew Kurushin | 2005-01-06 22:22:20 +0000 |
commit | 198d85eecd972483dc4a9bf2b792e31ef3dc6f71 (patch) | |
tree | f26f51332cdd7eb1b739e682e294dea1bbac9681 /saga | |
parent | 59a93737dbd9b0f60f8545b0a0a23ceb75c03ab7 (diff) | |
download | scummvm-rg350-198d85eecd972483dc4a9bf2b792e31ef3dc6f71.tar.gz scummvm-rg350-198d85eecd972483dc4a9bf2b792e31ef3dc6f71.tar.bz2 scummvm-rg350-198d85eecd972483dc4a9bf2b792e31ef3dc6f71.zip |
small fixes to previous
svn-id: r16465
Diffstat (limited to 'saga')
-rw-r--r-- | saga/actor.cpp | 83 | ||||
-rw-r--r-- | saga/actor.h | 9 |
2 files changed, 37 insertions, 55 deletions
diff --git a/saga/actor.cpp b/saga/actor.cpp index 7a519fd1b5..b2b8d211e8 100644 --- a/saga/actor.cpp +++ b/saga/actor.cpp @@ -153,7 +153,7 @@ Actor::Actor(SagaEngine *vm) : _vm(vm) { _yCellCount = _vm->getStatusYOffset() + 1; _xCellCount = _vm->getDisplayWidth(); - _pathCell = (int*) malloc(_yCellCount * _xCellCount * sizeof(*_pathCell)); + _pathCell = (int8*) malloc(_yCellCount * _xCellCount * sizeof(*_pathCell)); _pathRect.left = 0; @@ -1353,7 +1353,6 @@ void Actor::findActorPath(ActorData *actor, const Point &fromPoint, const Point Point iteratorPoint; Point bestPoint; int maskType; - int cellValue; int i; Rect intersect; @@ -1368,8 +1367,7 @@ void Actor::findActorPath(ActorData *actor, const Point &fromPoint, const Point for (iteratorPoint.y = 0; iteratorPoint.y < _yCellCount; iteratorPoint.y++) { for (iteratorPoint.x = 0; iteratorPoint.x < _xCellCount; iteratorPoint.x++) { maskType = _vm->_scene->getBGMaskType(iteratorPoint); - cellValue = maskType ? kPathCellBarrier : kPathCellEmpty; - setPathCell(iteratorPoint, cellValue); + setPathCell(iteratorPoint, maskType ? kPathCellBarrier : kPathCellEmpty); } } @@ -1407,29 +1405,6 @@ void Actor::findActorPath(ActorData *actor, const Point &fromPoint, const Point i = fillPathArray(fromPoint, toPoint, bestPoint); -#if 0 - { - Point iteratorPoint; - int cellValue; - FILE *fp = fopen("d:\\FINDPATH.DAT", "w"); - char c; - - fprintf(fp, "from = (%d,%d)\n", fromPoint.x, fromPoint.y); - fprintf(fp, "to = (%d,%d)\n", toPoint.x, toPoint.y); - fprintf(fp, "bestPoint = (%d,%d)\n", bestPoint.x, bestPoint.y); - - for (iteratorPoint.y = 0; iteratorPoint.y < _yCellCount; iteratorPoint.y++) { - for (iteratorPoint.x = 0; iteratorPoint.x < _xCellCount; iteratorPoint.x++) { - cellValue = getPathCell(iteratorPoint); - c = (cellValue < 0) ? ' ' : (cellValue == kPathCellBarrier) ? kPathCellBarrier : (cellValue < 8) ? "^>v<?jLP"[cellValue] : '.'; - putc(c, fp); - } - putc('\n', fp); - } - fclose(fp); - } -#endif - if (fromPoint == bestPoint) { actor->addWalkStepPoint(bestPoint); return; @@ -1506,6 +1481,7 @@ int Actor::fillPathArray(const Point &fromPoint, const Point &toPoint, Point &be PathDirectionData *samplePathDirection; PathDirectionList::iterator pathDirectionIterator; PathDirectionList::iterator newPathDirectionIterator; + Point nextPoint; int directionCount; pointCounter = 0; @@ -1521,7 +1497,7 @@ int Actor::fillPathArray(const Point &fromPoint, const Point &toPoint, Point &be } if (validPathCellPoint(fromPoint)) { - setPathCell(fromPoint, 0); + setPathCell(fromPoint, kDirUp); addDebugPoint(fromPoint, 24+36); } @@ -1532,29 +1508,34 @@ int Actor::fillPathArray(const Point &fromPoint, const Point &toPoint, Point &be pathDirection = pathDirectionIterator.operator->(); for (directionCount = 0; directionCount < 3; directionCount++) { samplePathDirection = &pathDirectionLUT[pathDirection->direction][directionCount]; - Point nextPoint; nextPoint.x = samplePathDirection->x + pathDirection->x; nextPoint.y = samplePathDirection->y + pathDirection->y; - if (validPathCellPoint(nextPoint) && - (getPathCell(nextPoint) == kPathCellEmpty)) { - setPathCell(nextPoint, samplePathDirection->direction); - - addDebugPoint(nextPoint, samplePathDirection->direction + 96); - newPathDirectionIterator = pathDirectionList.pushBack(); - pathDirection = newPathDirectionIterator.operator->(); - pathDirection->x = nextPoint.x; - pathDirection->y = nextPoint.y; - pathDirection->direction = samplePathDirection->direction; - ++pointCounter; - if (nextPoint == toPoint) { - bestPoint = toPoint; - return pointCounter; - } - currentRating = quickDistance(nextPoint, toPoint); - if (currentRating < bestRating) { - bestRating = currentRating; - bestPath = nextPoint; - } + + if (!validPathCellPoint(nextPoint)) { + continue; + } + + if (getPathCell(nextPoint) != kPathCellEmpty) { + continue; + } + + setPathCell(nextPoint, samplePathDirection->direction); + + addDebugPoint(nextPoint, samplePathDirection->direction + 96); + newPathDirectionIterator = pathDirectionList.pushBack(); + pathDirection = newPathDirectionIterator.operator->(); + pathDirection->x = nextPoint.x; + pathDirection->y = nextPoint.y; + pathDirection->direction = samplePathDirection->direction; + ++pointCounter; + if (nextPoint == toPoint) { + bestPoint = toPoint; + return pointCounter; + } + currentRating = quickDistance(nextPoint, toPoint); + if (currentRating < bestRating) { + bestRating = currentRating; + bestPath = nextPoint; } } ++pathDirectionIterator; @@ -1566,7 +1547,7 @@ int Actor::fillPathArray(const Point &fromPoint, const Point &toPoint, Point &be void Actor::setActorPath(ActorData *actor, const Point &fromPoint, const Point &toPoint) { Point nextPoint; - int direction; + int8 direction; int i; _pathListIndex = -1; @@ -1575,7 +1556,7 @@ void Actor::setActorPath(ActorData *actor, const Point &fromPoint, const Point & while ( !(nextPoint == fromPoint)) { direction = getPathCell(nextPoint); - if ((direction < 0) || (direction > 8)) { + if ((direction < 0) || (direction >= 8)) { error("Actor::setActorPath error direction 0x%X", direction); } nextPoint.x -= pathDirectionLUT2[direction][0]; diff --git a/saga/actor.h b/saga/actor.h index 8c5fff49e6..97b1625100 100644 --- a/saga/actor.h +++ b/saga/actor.h @@ -115,11 +115,12 @@ enum ActorFlagsEx { enum PathCellType { kPathCellEmpty = -1, + //kDirUp = 0 .... kDirUpLeft = 7 kPathCellBarrier = 0x57 }; struct PathDirectionData { - int direction; + int8 direction; int x; int y; }; @@ -319,13 +320,13 @@ private: return !((testPoint.x < 0) || (testPoint.x >= _xCellCount) || (testPoint.y < 0) || (testPoint.y >= _yCellCount)); } - void setPathCell(const Point &testPoint, int value) { + void setPathCell(const Point &testPoint, int8 value) { if (!validPathCellPoint(testPoint)) { error("Actor::setPathCell wrong point"); } _pathCell[testPoint.x + testPoint.y * _xCellCount] = value; } - int getPathCell(const Point &testPoint) { + int8 getPathCell(const Point &testPoint) { if (!validPathCellPoint(testPoint)) { error("Actor::getPathCell wrong point"); } @@ -351,7 +352,7 @@ private: //path stuff Rect _barrierList[ACTOR_BARRIERS_MAX]; int _barrierCount; - int *_pathCell; + int8 *_pathCell; int _xCellCount; int _yCellCount; |