/* Calcs the heuristic to the target station or tile. For train stations, it * takes into account the direction of approach. */ static int32 NPFCalcStationOrTileHeuristic(AyStar *as, AyStarNode *current, OpenListNode *parent) { NPFFindStationOrTileData *fstd = (NPFFindStationOrTileData*)as->user_target; NPFFoundTargetData *ftd = (NPFFoundTargetData*)as->user_path; TileIndex from = current->tile; TileIndex to = fstd->dest_coords; uint dist; /* for train-stations, we are going to aim for the closest station tile */ if (as->user_data[NPF_TYPE] != TRANSPORT_WATER && fstd->station_index != INVALID_STATION) to = CalcClosestStationTile(fstd->station_index, from, fstd->station_type); if (as->user_data[NPF_TYPE] == TRANSPORT_ROAD) { /* Since roads only have diagonal pieces, we use manhattan distance here */ dist = DistanceManhattan(from, to) * NPF_TILE_LENGTH; } else { /* Ships and trains can also go diagonal, so the minimum distance is shorter */ dist = NPFDistanceTrack(from, to); } DEBUG(npf, 4, "Calculating H for: (%d, %d). Result: %d", TileX(current->tile), TileY(current->tile), dist); if (dist < ftd->best_bird_dist) { ftd->best_bird_dist = dist; ftd->best_trackdir = (Trackdir)current->user_data[NPF_TRACKDIR_CHOICE]; } return dist; }
void SetDestination(const Train *v) { switch (v->current_order.GetType()) { case OT_GOTO_WAYPOINT: if (!Waypoint::Get(v->current_order.GetDestination())->IsSingleTile()) { /* In case of 'complex' waypoints we need to do a look * ahead. This look ahead messes a bit about, which * means that it 'corrupts' the cache. To prevent this * we disable caching when we're looking for a complex * waypoint. */ Yapf().DisableCache(true); } /* FALL THROUGH */ case OT_GOTO_STATION: m_destTile = CalcClosestStationTile(v->current_order.GetDestination(), v->tile, v->current_order.IsType(OT_GOTO_STATION) ? STATION_RAIL : STATION_WAYPOINT); m_dest_station_id = v->current_order.GetDestination(); m_destTrackdirs = INVALID_TRACKDIR_BIT; break; default: m_destTile = v->dest_tile; m_dest_station_id = INVALID_STATION; m_destTrackdirs = TrackStatusToTrackdirBits(GetTileTrackStatus(v->dest_tile, TRANSPORT_RAIL, 0)); break; } CYapfDestinationRailBase::SetDestination(v); }
void SetDestination(const RoadVehicle *v) { if (v->current_order.IsType(OT_GOTO_STATION)) { m_dest_station = v->current_order.GetDestination(); m_bus = v->IsBus(); m_destTile = CalcClosestStationTile(m_dest_station, v->tile, m_bus ? STATION_BUS : STATION_TRUCK); m_non_artic = !v->HasArticulatedPart(); m_destTrackdirs = INVALID_TRACKDIR_BIT; } else { m_dest_station = INVALID_STATION; m_destTile = v->dest_tile; m_destTrackdirs = TrackStatusToTrackdirBits(GetTileTrackStatus(v->dest_tile, TRANSPORT_ROAD, v->compatible_roadtypes)); } }