ai_pathfinder.c
changeset 1095 b59632d9df1b
parent 1047 df93a1386892
child 1209 2e00193652b2
equal deleted inserted replaced
1094:9a01482df45a 1095:b59632d9df1b
     6 
     6 
     7 #define TEST_STATION_NO_DIR 0xFF
     7 #define TEST_STATION_NO_DIR 0xFF
     8 
     8 
     9 // Tests if a station can be build on the given spot
     9 // Tests if a station can be build on the given spot
    10 // TODO: make it train compatible
    10 // TODO: make it train compatible
    11 bool TestCanBuildStationHere(uint tile, byte dir) {
    11 static bool TestCanBuildStationHere(uint tile, byte dir)
       
    12 {
    12     Player *p = DEREF_PLAYER(_current_player);
    13     Player *p = DEREF_PLAYER(_current_player);
    13     if (dir == TEST_STATION_NO_DIR) {
    14     if (dir == TEST_STATION_NO_DIR) {
    14         // TODO: currently we only allow spots that can be access from al 4 directions...
    15         // TODO: currently we only allow spots that can be access from al 4 directions...
    15         //  should be fixed!!!
    16         //  should be fixed!!!
    16         for (dir=0;dir<4;dir++) {
    17         for (dir=0;dir<4;dir++) {
    44 
    45 
    45 // Checks if a tile 'a' is between the tiles 'b' and 'c'
    46 // Checks if a tile 'a' is between the tiles 'b' and 'c'
    46 #define TILES_BETWEEN(a, b, c) (TileX(a) >= TileX(b) && TileX(a) <= TileX(c) && TileY(a) >= TileY(b) && TileY(a) <= TileY(c))
    47 #define TILES_BETWEEN(a, b, c) (TileX(a) >= TileX(b) && TileX(a) <= TileX(c) && TileY(a) >= TileY(b) && TileY(a) <= TileY(c))
    47 
    48 
    48 // Check if the current tile is in our end-area
    49 // Check if the current tile is in our end-area
    49 int32 AyStar_AiPathFinder_EndNodeCheck(AyStar *aystar, OpenListNode *current) {
    50 static int32 AyStar_AiPathFinder_EndNodeCheck(AyStar *aystar, OpenListNode *current)
       
    51 {
    50 	Ai_PathFinderInfo *PathFinderInfo = (Ai_PathFinderInfo*)aystar->user_target;
    52 	Ai_PathFinderInfo *PathFinderInfo = (Ai_PathFinderInfo*)aystar->user_target;
    51 	// It is not allowed to have a station on the end of a bridge or tunnel ;)
    53 	// It is not allowed to have a station on the end of a bridge or tunnel ;)
    52 	if (current->path.node.user_data[0] != 0) return AYSTAR_DONE;
    54 	if (current->path.node.user_data[0] != 0) return AYSTAR_DONE;
    53 	if (TILES_BETWEEN(current->path.node.tile, PathFinderInfo->end_tile_tl, PathFinderInfo->end_tile_br))
    55 	if (TILES_BETWEEN(current->path.node.tile, PathFinderInfo->end_tile_tl, PathFinderInfo->end_tile_br))
    54 		if (IsTileType(current->path.node.tile, MP_CLEAR) || IsTileType(current->path.node.tile, MP_TREES))
    56 		if (IsTileType(current->path.node.tile, MP_CLEAR) || IsTileType(current->path.node.tile, MP_TREES))
    58 	return AYSTAR_DONE;
    60 	return AYSTAR_DONE;
    59 }
    61 }
    60 
    62 
    61 // Calculates the hash
    63 // Calculates the hash
    62 //   Currently it is a 10 bit hash, so the hash array has a max depth of 6 bits (so 64)
    64 //   Currently it is a 10 bit hash, so the hash array has a max depth of 6 bits (so 64)
    63 uint AiPathFinder_Hash(uint key1, uint key2) {
    65 static uint AiPathFinder_Hash(uint key1, uint key2)
       
    66 {
    64 	return (TileX(key1) & 0x1F) + ((TileY(key1) & 0x1F) << 5);
    67 	return (TileX(key1) & 0x1F) + ((TileY(key1) & 0x1F) << 5);
    65 }
    68 }
    66 
    69 
    67 // Clear the memory of all the things
    70 // Clear the memory of all the things
    68 void AyStar_AiPathFinder_Free(AyStar *aystar) {
    71 static void AyStar_AiPathFinder_Free(AyStar *aystar)
       
    72 {
    69 	AyStarMain_Free(aystar);
    73 	AyStarMain_Free(aystar);
    70 	free(aystar);
    74 	free(aystar);
    71 }
    75 }
    72 
    76 
    73 static int32 AyStar_AiPathFinder_CalculateG(AyStar *aystar, AyStarNode *current, OpenListNode *parent);
    77 static int32 AyStar_AiPathFinder_CalculateG(AyStar *aystar, AyStarNode *current, OpenListNode *parent);