409 // Skip if the tile was from a bridge or tunnel |
409 // Skip if the tile was from a bridge or tunnel |
410 if (parent->path.node.user_data[0] == 0 && current->user_data[0] == 0) { |
410 if (parent->path.node.user_data[0] == 0 && current->user_data[0] == 0) { |
411 if (PathFinderInfo->rail_or_road) { |
411 if (PathFinderInfo->rail_or_road) { |
412 Foundation f = GetRailFoundation(parent_tileh, (TrackBits)(1 << AiNew_GetRailDirection(parent->path.parent->node.tile, parent->path.node.tile, current->tile))); |
412 Foundation f = GetRailFoundation(parent_tileh, (TrackBits)(1 << AiNew_GetRailDirection(parent->path.parent->node.tile, parent->path.node.tile, current->tile))); |
413 // Maybe is BRIDGE_NO_FOUNDATION a bit strange here, but it contains just the right information.. |
413 // Maybe is BRIDGE_NO_FOUNDATION a bit strange here, but it contains just the right information.. |
414 if (IsInclinedFoundation(f) || (!IsFoundation(f) && HASBIT(BRIDGE_NO_FOUNDATION, parent_tileh))) { |
414 if (IsInclinedFoundation(f) || (!IsFoundation(f) && HasBit(BRIDGE_NO_FOUNDATION, parent_tileh))) { |
415 res += AI_PATHFINDER_TILE_GOES_UP_PENALTY; |
415 res += AI_PATHFINDER_TILE_GOES_UP_PENALTY; |
416 } else { |
416 } else { |
417 res += AI_PATHFINDER_FOUNDATION_PENALTY; |
417 res += AI_PATHFINDER_FOUNDATION_PENALTY; |
418 } |
418 } |
419 } else { |
419 } else { |
420 if (!IsRoad(parent->path.node.tile) || !IsTileType(parent->path.node.tile, MP_TUNNELBRIDGE)) { |
420 if (!IsRoad(parent->path.node.tile) || !IsTileType(parent->path.node.tile, MP_TUNNELBRIDGE)) { |
421 Foundation f = GetRoadFoundation(parent_tileh, (RoadBits)AiNew_GetRoadDirection(parent->path.parent->node.tile, parent->path.node.tile, current->tile)); |
421 Foundation f = GetRoadFoundation(parent_tileh, (RoadBits)AiNew_GetRoadDirection(parent->path.parent->node.tile, parent->path.node.tile, current->tile)); |
422 if (IsInclinedFoundation(f) || (!IsFoundation(f) && HASBIT(BRIDGE_NO_FOUNDATION, parent_tileh))) { |
422 if (IsInclinedFoundation(f) || (!IsFoundation(f) && HasBit(BRIDGE_NO_FOUNDATION, parent_tileh))) { |
423 res += AI_PATHFINDER_TILE_GOES_UP_PENALTY; |
423 res += AI_PATHFINDER_TILE_GOES_UP_PENALTY; |
424 } else { |
424 } else { |
425 res += AI_PATHFINDER_FOUNDATION_PENALTY; |
425 res += AI_PATHFINDER_FOUNDATION_PENALTY; |
426 } |
426 } |
427 } |
427 } |
442 if ((AI_PATHFINDER_FLAG_BRIDGE & current->user_data[0]) != 0) { |
442 if ((AI_PATHFINDER_FLAG_BRIDGE & current->user_data[0]) != 0) { |
443 // That means for every length a penalty |
443 // That means for every length a penalty |
444 res += AI_PATHFINDER_BRIDGE_PENALTY * GetBridgeLength(current->tile, parent->path.node.tile); |
444 res += AI_PATHFINDER_BRIDGE_PENALTY * GetBridgeLength(current->tile, parent->path.node.tile); |
445 // Check if we are going up or down, first for the starting point |
445 // Check if we are going up or down, first for the starting point |
446 // In user_data[0] is at the 8th bit the direction |
446 // In user_data[0] is at the 8th bit the direction |
447 if (!HASBIT(BRIDGE_NO_FOUNDATION, parent_tileh)) { |
447 if (!HasBit(BRIDGE_NO_FOUNDATION, parent_tileh)) { |
448 if (IsLeveledFoundation(GetBridgeFoundation(parent_tileh, (Axis)((current->user_data[0] >> 8) & 1)))) { |
448 if (IsLeveledFoundation(GetBridgeFoundation(parent_tileh, (Axis)((current->user_data[0] >> 8) & 1)))) { |
449 res += AI_PATHFINDER_BRIDGE_GOES_UP_PENALTY; |
449 res += AI_PATHFINDER_BRIDGE_GOES_UP_PENALTY; |
450 } |
450 } |
451 } |
451 } |
452 // Second for the end point |
452 // Second for the end point |
453 if (!HASBIT(BRIDGE_NO_FOUNDATION, tileh)) { |
453 if (!HasBit(BRIDGE_NO_FOUNDATION, tileh)) { |
454 if (IsLeveledFoundation(GetBridgeFoundation(tileh, (Axis)((current->user_data[0] >> 8) & 1)))) { |
454 if (IsLeveledFoundation(GetBridgeFoundation(tileh, (Axis)((current->user_data[0] >> 8) & 1)))) { |
455 res += AI_PATHFINDER_BRIDGE_GOES_UP_PENALTY; |
455 res += AI_PATHFINDER_BRIDGE_GOES_UP_PENALTY; |
456 } |
456 } |
457 } |
457 } |
458 if (parent_tileh == SLOPE_FLAT) res += AI_PATHFINDER_BRIDGE_GOES_UP_PENALTY; |
458 if (parent_tileh == SLOPE_FLAT) res += AI_PATHFINDER_BRIDGE_GOES_UP_PENALTY; |