Browse Source

Clean up path_solid_pieces

pull/25/head
Anders Jenbo 8 years ago committed by Dennis Duda
parent
commit
3c0358f34f
  1. 61
      Source/path.cpp
  2. 2
      Source/path.h

61
Source/path.cpp

@ -182,53 +182,24 @@ PATHNODE *__cdecl GetNextPath()
*
* return true if step is allowed
*/
bool __fastcall path_solid_pieces(PATHNODE *pPath, int dx, int dy)
BOOL __fastcall path_solid_pieces(PATHNODE *pPath, int dx, int dy)
{
bool result; // eax
int dir; // ecx
int tile1; // ecx
int tile2; // edx
result = 1;
// this maps the four corner directions to 0,1,2,3
dir = path_directions[3 * (dy - pPath->y) - pPath->x + 4 + dx] - 5;
// and this is basically a switch
if ( !dir ) // (-1,-1)->0
{
result = 0;
if ( nSolidTable[dPiece[dx][dy + 1]] )
return result;
tile1 = dPiece[dx + 1][dy];
goto LABEL_13;
}
if ( !--dir ) // (1,-1)->1
{
tile2 = dPiece[dx][dy + 1];
goto LABEL_9;
}
if ( !--dir ) // (1,1)->2
{
tile2 = dPiece[dx][dy-1]; /* check */
LABEL_9:
result = 0;
if ( nSolidTable[tile2] )
return result;
tile1 = dPiece[dx-1][dy]; /* check */
goto LABEL_13;
}
if ( dir == 1 ) // (-1,1)->3
{
result = 0;
if ( !nSolidTable[dPiece[dx + 1][dy]] )
{
tile1 = dPiece[dx][dy-1]; /* check */
LABEL_13:
if ( !nSolidTable[tile1] )
result = 1;
return result;
}
BOOL rv = TRUE;
switch ( path_directions[3 * (dy - pPath->y) + 3 - pPath->x + 1 + dx] ) {
case 5:
rv = !nSolidTable[dPiece[dx][dy + 1]] && !nSolidTable[dPiece[dx + 1][dy]];
break;
case 6:
rv = !nSolidTable[dPiece[dx][dy + 1]] && !nSolidTable[dPiece[dx - 1][dy]];
break;
case 7:
rv = !nSolidTable[dPiece[dx][dy - 1]] && !nSolidTable[dPiece[dx - 1][dy]];
break;
case 8:
rv = !nSolidTable[dPiece[dx + 1][dy]] && !nSolidTable[dPiece[dx][dy - 1]];
break;
}
return result;
return rv;
}
/* perform a single step of A* bread-first search by trying to step in every

2
Source/path.h

@ -14,7 +14,7 @@ int __fastcall FindPath(BOOL (__fastcall *PosOk)(int, int, int), int PosOkArg, i
int __fastcall path_get_h_cost(int sx, int sy, int dx, int dy);
int __fastcall path_check_equal(PATHNODE *pPath, int dx, int dy);
PATHNODE *__cdecl GetNextPath();
bool __fastcall path_solid_pieces(PATHNODE *pPath, int dx, int dy);
BOOL __fastcall path_solid_pieces(PATHNODE *pPath, int dx, int dy);
int __fastcall path_get_path(BOOL (__fastcall *PosOk)(int, int, int), int PosOkArg, PATHNODE *pPath, int x, int y);
int __fastcall path_parent_path(PATHNODE *pPath, int dx, int dy, int sx, int sy);
PATHNODE *__fastcall path_get_node1(int dx, int dy);

Loading…
Cancel
Save