Fixed pathfinder post processing in HoF, this should smooth walk paths a lot.

svn-id: r31179
This commit is contained in:
Johannes Schickel 2008-03-18 13:29:12 +00:00
parent caf1cc60de
commit 4c880c77a4
2 changed files with 40 additions and 37 deletions

View File

@ -530,14 +530,14 @@ protected:
bool lineIsPassable(int x, int y);
bool directLinePassable(int x, int y, int toX, int toY);
int pathfinderUnk1(int *moveTable);
int pathfinderUnk2(int index, int v1, int v2);
int pathfinderUnk3(int tableLen, int x, int y);
int pathfinderUnk4(int index, int v);
void pathfinderUnk5(int *moveTable, int unk1, int x, int y, int moveTableSize);
int pathfinderInitPositionTable(int *moveTable);
int pathfinderAddToPositionTable(int index, int v1, int v2);
int pathfinderInitPositionIndexTable(int tableLen, int x, int y);
int pathfinderAddToPositionIndexTable(int index, int v);
void pathfinderFinializePath(int *moveTable, int unk1, int x, int y, int moveTableSize);
int _pathfinderUnkTable1[400];
int _pathfinderUnkTable2[200];
int _pathfinderPositionTable[400];
int _pathfinderPositionIndexTable[200];
// item
uint8 _itemHtDat[176];

View File

@ -736,12 +736,15 @@ int KyraEngine_v2::findWay(int x, int y, int toX, int toY, int *moveTable, int m
x &= ~3; toX &= ~3;
y &= ~1; toY &= ~1;
int size = KyraEngine::findWay(x, y, toX, toY, moveTable, moveTableSize);
if (size) {
//int temp = pathfinderUnk1(moveTable);
//temp = pathfinderUnk3(temp, x, y);
//pathfinderUnk5(moveTable, temp, x, y, moveTableSize);
}
return getMoveTableSize(moveTable);
static bool usePostProcess = false;
if (size && !usePostProcess) {
usePostProcess = true;
int temp = pathfinderInitPositionTable(moveTable);
temp = pathfinderInitPositionIndexTable(temp, x, y);
pathfinderFinializePath(moveTable, temp, x, y, moveTableSize);
usePostProcess = false;
}
return usePostProcess ? size : getMoveTableSize(moveTable);
}
bool KyraEngine_v2::lineIsPassable(int x, int y) {
@ -795,13 +798,13 @@ bool KyraEngine_v2::directLinePassable(int x, int y, int toX, int toY) {
return true;
}
int KyraEngine_v2::pathfinderUnk1(int *moveTable) {
int KyraEngine_v2::pathfinderInitPositionTable(int *moveTable) {
bool breakLoop = false;
int *moveTableCur = moveTable;
int oldEntry = *moveTableCur, curEntry = *moveTableCur;
int oldX = 0, newX = 0, oldY = 0, newY = 0;
int lastEntry = 0;
lastEntry = pathfinderUnk2(lastEntry, 0, 0);
lastEntry = pathfinderAddToPositionTable(lastEntry, 0, 0);
while (*moveTableCur != 8) {
oldEntry = curEntry;
@ -834,45 +837,45 @@ int KyraEngine_v2::pathfinderUnk1(int *moveTable) {
}
if (temp > 1 || oldEntry != curEntry)
lastEntry = pathfinderUnk2(lastEntry, oldX, oldY);
lastEntry = pathfinderAddToPositionTable(lastEntry, oldX, oldY);
++moveTableCur;
}
lastEntry = pathfinderUnk2(lastEntry, newX, newY);
_pathfinderUnkTable1[lastEntry*2+0] = -1;
_pathfinderUnkTable1[lastEntry*2+1] = -1;
lastEntry = pathfinderAddToPositionTable(lastEntry, newX, newY);
_pathfinderPositionTable[lastEntry*2+0] = -1;
_pathfinderPositionTable[lastEntry*2+1] = -1;
return lastEntry;
}
int KyraEngine_v2::pathfinderUnk2(int index, int v1, int v2) {
_pathfinderUnkTable1[index<<1] = v1;
_pathfinderUnkTable1[(index<<1)+1] = v2;
int KyraEngine_v2::pathfinderAddToPositionTable(int index, int v1, int v2) {
_pathfinderPositionTable[index<<1] = v1;
_pathfinderPositionTable[(index<<1)+1] = v2;
++index;
if (index >= 199)
--index;
return index;
}
int KyraEngine_v2::pathfinderUnk3(int tableLen, int x, int y) {
int KyraEngine_v2::pathfinderInitPositionIndexTable(int tableLen, int x, int y) {
int x1 = 0, y1 = 0;
int x2 = 0, y2 = 0;
int lastEntry = 0;
int index2 = tableLen-1, index1 = 0;
while (index2 > index1) {
x1 = _pathfinderUnkTable1[index1*2+0] + x;
y1 = _pathfinderUnkTable1[index1*2+1] + y;
x2 = _pathfinderUnkTable1[index2*2+0] + x;
y2 = _pathfinderUnkTable1[index2*2+0] + x;
x1 = _pathfinderPositionTable[index1*2+0] + x;
y1 = _pathfinderPositionTable[index1*2+1] + y;
x2 = _pathfinderPositionTable[index2*2+0] + x;
y2 = _pathfinderPositionTable[index2*2+1] + y;
if (directLinePassable(x1, y1, x2, y2)) {
lastEntry = pathfinderUnk4(lastEntry, index2);
lastEntry = pathfinderAddToPositionIndexTable(lastEntry, index2);
if (tableLen-1 == index2)
break;
index1 = index2;
index2 = tableLen-1;
} else if (index1+1 == index2) {
lastEntry = pathfinderUnk4(lastEntry, index2);
lastEntry = pathfinderAddToPositionIndexTable(lastEntry, index2);
index1 = index2;
index2 = tableLen-1;
} else {
@ -882,25 +885,25 @@ int KyraEngine_v2::pathfinderUnk3(int tableLen, int x, int y) {
return lastEntry;
}
int KyraEngine_v2::pathfinderUnk4(int index, int v) {
_pathfinderUnkTable2[index] = v;
int KyraEngine_v2::pathfinderAddToPositionIndexTable(int index, int v) {
_pathfinderPositionIndexTable[index] = v;
++index;
if (index >= 199)
--index;
return index;
}
void KyraEngine_v2::pathfinderUnk5(int *moveTable, int tableLen, int x, int y, int moveTableSize) {
void KyraEngine_v2::pathfinderFinializePath(int *moveTable, int tableLen, int x, int y, int moveTableSize) {
int x1 = 0, y1 = 0;
int x2 = 0, y2 = 0;
int index1 = 0, index2 = 0;
int sizeLeft = moveTableSize;
for (int i = 0; i < tableLen; ++i) {
index2 = _pathfinderUnkTable2[i];
x1 = _pathfinderUnkTable1[index1*2+0] + x;
y1 = _pathfinderUnkTable1[index1*2+1] + y;
x2 = _pathfinderUnkTable1[index2*2+0] + x;
y2 = _pathfinderUnkTable1[index2*2+0] + x;
index2 = _pathfinderPositionIndexTable[i];
x1 = _pathfinderPositionTable[index1*2+0] + x;
y1 = _pathfinderPositionTable[index1*2+1] + y;
x2 = _pathfinderPositionTable[index2*2+0] + x;
y2 = _pathfinderPositionTable[index2*2+1] + y;
int wayLen = findWay(x1, y1, x2, y2, moveTable, sizeLeft);
moveTable += wayLen;