src/ai/trolly/pathfinder.cpp
branchgamebalance
changeset 9913 e79cd19772dd
parent 9912 1ac8aac92385
child 6743 cabfaa4a0295
equal deleted inserted replaced
9912:1ac8aac92385 9913:e79cd19772dd
    21 static bool TestCanBuildStationHere(TileIndex tile, byte dir)
    21 static bool TestCanBuildStationHere(TileIndex tile, byte dir)
    22 {
    22 {
    23 	Player *p = GetPlayer(_current_player);
    23 	Player *p = GetPlayer(_current_player);
    24 
    24 
    25 	if (dir == TEST_STATION_NO_DIR) {
    25 	if (dir == TEST_STATION_NO_DIR) {
    26 		int32 ret;
    26 		CommandCost ret;
    27 		// TODO: currently we only allow spots that can be access from al 4 directions...
    27 		// TODO: currently we only allow spots that can be access from al 4 directions...
    28 		//  should be fixed!!!
    28 		//  should be fixed!!!
    29 		for (dir = 0; dir < 4; dir++) {
    29 		for (dir = 0; dir < 4; dir++) {
    30 			ret = AiNew_Build_Station(p, p->ainew.tbt, tile, 1, 1, dir, DC_QUERY_COST);
    30 			ret = AiNew_Build_Station(p, p->ainew.tbt, tile, 1, 1, dir, DC_QUERY_COST);
    31 			if (!CmdFailed(ret)) return true;
    31 			if (CmdSucceeded(ret)) return true;
    32 		}
    32 		}
    33 		return false;
    33 		return false;
    34 	}
    34 	}
    35 
    35 
    36 	// return true if command succeeded, so the inverse of CmdFailed()
    36 	// return true if command succeeded, so the inverse of CmdFailed()
    37 	return !CmdFailed(AiNew_Build_Station(p, p->ainew.tbt, tile, 1, 1, dir, DC_QUERY_COST));
    37 	return CmdSucceeded(AiNew_Build_Station(p, p->ainew.tbt, tile, 1, 1, dir, DC_QUERY_COST));
    38 }
    38 }
    39 
    39 
    40 
    40 
    41 static bool IsRoad(TileIndex tile)
    41 static bool IsRoad(TileIndex tile)
    42 {
    42 {
   212 
   212 
   213 
   213 
   214 // What tiles are around us.
   214 // What tiles are around us.
   215 static void AyStar_AiPathFinder_GetNeighbours(AyStar *aystar, OpenListNode *current)
   215 static void AyStar_AiPathFinder_GetNeighbours(AyStar *aystar, OpenListNode *current)
   216 {
   216 {
   217 	int ret;
   217 	CommandCost ret;
   218 	int dir;
   218 	int dir;
   219 
   219 
   220 	Ai_PathFinderInfo *PathFinderInfo = (Ai_PathFinderInfo*)aystar->user_target;
   220 	Ai_PathFinderInfo *PathFinderInfo = (Ai_PathFinderInfo*)aystar->user_target;
   221 
   221 
   222 	aystar->num_neighbours = 0;
   222 	aystar->num_neighbours = 0;
   350 				(dir == DIAGDIR_SW && tileh == SLOPE_SW) ||
   350 				(dir == DIAGDIR_SW && tileh == SLOPE_SW) ||
   351 				(dir == DIAGDIR_NW && tileh == SLOPE_NW)) {
   351 				(dir == DIAGDIR_NW && tileh == SLOPE_NW)) {
   352 			// Now simply check if a tunnel can be build
   352 			// Now simply check if a tunnel can be build
   353 			ret = AI_DoCommand(tile, (PathFinderInfo->rail_or_road?0:0x200), 0, DC_AUTO, CMD_BUILD_TUNNEL);
   353 			ret = AI_DoCommand(tile, (PathFinderInfo->rail_or_road?0:0x200), 0, DC_AUTO, CMD_BUILD_TUNNEL);
   354 			tileh = GetTileSlope(_build_tunnel_endtile, NULL);
   354 			tileh = GetTileSlope(_build_tunnel_endtile, NULL);
   355 			if (!CmdFailed(ret) && (tileh == SLOPE_SW || tileh == SLOPE_SE || tileh == SLOPE_NW || tileh == SLOPE_NE)) {
   355 			if (CmdSucceeded(ret) && (tileh == SLOPE_SW || tileh == SLOPE_SE || tileh == SLOPE_NW || tileh == SLOPE_NE)) {
   356 				aystar->neighbours[aystar->num_neighbours].tile = _build_tunnel_endtile;
   356 				aystar->neighbours[aystar->num_neighbours].tile = _build_tunnel_endtile;
   357 				aystar->neighbours[aystar->num_neighbours].user_data[0] = AI_PATHFINDER_FLAG_TUNNEL + (dir << 8);
   357 				aystar->neighbours[aystar->num_neighbours].user_data[0] = AI_PATHFINDER_FLAG_TUNNEL + (dir << 8);
   358 				aystar->neighbours[aystar->num_neighbours++].direction = 0;
   358 				aystar->neighbours[aystar->num_neighbours++].direction = 0;
   359 			}
   359 			}
   360 		}
   360 		}