diff --git a/pathfind.c b/pathfind.c index 038b5b9498..7a78cea830 100644 --- a/pathfind.c +++ b/pathfind.c @@ -251,31 +251,13 @@ const byte _ffb_64[128] = { 48, 56, 56, 58, 56, 60, 60, 62, }; -static void TPFMode1(TrackPathFinder* tpf, TileIndex tile, DiagDirection direction) +static void TPFMode1(TrackPathFinder* tpf, TileIndex tile, DiagDirection direction); + +/** Most code of the "Normal" case of TPF Mode 1; for signals special tricks + * have to be done, but those happen in TPFMode1; this is just to prevent + * gotos ;). */ +static inline void TPFMode1_NormalCase(TrackPathFinder* tpf, TileIndex tile, TileIndex tile_org, DiagDirection direction) { - uint bits; - int i; - RememberData rd; - TileIndex tile_org = tile; - - // check if the old tile can be left at that direction - if (tpf->tracktype == TRANSPORT_ROAD) { - // road stops and depots now have a track (r4419) - // don't enter road stop from the back - if (IsRoadStopTile(tile) && GetRoadStopDir(tile) != direction) return; - // don't enter road depot from the back - if (IsTileDepotType(tile, TRANSPORT_ROAD) && GetRoadDepotDirection(tile) != direction) return; - } - - if (IsTunnelTile(tile)) { - if (GetTunnelDirection(tile) != direction || - GetTunnelTransportType(tile) != tpf->tracktype) { - return; - } - tile = SkipToEndOfTunnel(tpf, tile, direction); - } - tile += TileOffsByDiagDir(direction); - /* Check in case of rail if the owner is the same */ if (tpf->tracktype == TRANSPORT_RAIL) { // don't enter train depot from the back @@ -302,11 +284,46 @@ static void TPFMode1(TrackPathFinder* tpf, TileIndex tile, DiagDirection directi /* Check if the new tile is a tunnel or bridge head and that the direction * and transport type match */ if (IsTileType(tile, MP_TUNNELBRIDGE) && IsTunnel(tile)) { + if (GetTunnelTransportType(tile) != tpf->tracktype) { + return; + } + /* Only skip through the tunnel if heading inwards. We can + * be headed outwards if our starting position was in a + * tunnel and we're pathfinding backwards */ + if (GetTunnelDirection(tile) == direction) { + tile = SkipToEndOfTunnel(tpf, tile, direction); + } else if (GetTunnelDirection(tile) != ReverseDiagDir(direction)) { + /* We don't support moving through the sides of a tunnel + * entrance :-) */ + return; + } + } +} + +static void TPFMode1(TrackPathFinder* tpf, TileIndex tile, DiagDirection direction) +{ + uint bits; + int i; + RememberData rd; + TileIndex tile_org = tile; + + // check if the old tile can be left at that direction + if (tpf->tracktype == TRANSPORT_ROAD) { + // road stops and depots now have a track (r4419) + // don't enter road stop from the back + if (IsRoadStopTile(tile) && GetRoadStopDir(tile) != direction) return; + // don't enter road depot from the back + if (IsTileDepotType(tile, TRANSPORT_ROAD) && GetRoadDepotDirection(tile) != direction) return; + } + + if (IsTunnelTile(tile)) { if (GetTunnelDirection(tile) != direction || GetTunnelTransportType(tile) != tpf->tracktype) { return; } + tile = SkipToEndOfTunnel(tpf, tile, direction); } + tile += TileOffsByDiagDir(direction); tpf->rd.cur_length++; @@ -336,6 +353,8 @@ static void TPFMode1(TrackPathFinder* tpf, TileIndex tile, DiagDirection directi } } + TPFMode1_NormalCase(tpf, tile, tile_org, direction); + /* the next is only used when signals are checked. * seems to go in 2 directions simultaneously */ diff --git a/roadveh_cmd.c b/roadveh_cmd.c index 8084ed4cc5..4fc57e0411 100644 --- a/roadveh_cmd.c +++ b/roadveh_cmd.c @@ -332,7 +332,7 @@ static const Depot* FindClosestRoadDepot(const Vehicle* v) /* See where we are now */ Trackdir trackdir = GetVehicleTrackdir(v); - ftd = NPFRouteToDepotBreadthFirst(v->tile, trackdir, TRANSPORT_ROAD, v->owner, INVALID_RAILTYPE); + ftd = NPFRouteToDepotBreadthFirstTwoWay(v->tile, trackdir, v->tile, ReverseTrackdir(trackdir), TRANSPORT_ROAD, v->owner, INVALID_RAILTYPE, 0); if (ftd.best_bird_dist == 0) { return GetDepotByTile(ftd.node.tile); /* Target found */ } else { diff --git a/vehicle_gui.c b/vehicle_gui.c index 2ad87d5574..df9ed859b9 100644 --- a/vehicle_gui.c +++ b/vehicle_gui.c @@ -1769,7 +1769,7 @@ void PlayerVehWndProc(Window *w, WindowEvent *e) /* XXX - Substite string since the dropdown cannot handle dynamic strings */ action_str[2] = depot_name[vl->vehicle_type - VEH_Train]; - ShowDropDownMenu(w, action_str, 0, VLW_WIDGET_MANAGE_VEHICLES_DROPDOWN, 0, 0); + ShowDropDownMenu(w, action_str, 0, VLW_WIDGET_MANAGE_VEHICLES_DROPDOWN, 0, (w->window_number & VLW_MASK) == VLW_STANDARD ? 0 : 1); break; } diff --git a/waypoint.c b/waypoint.c index eaf9275045..7c05a9bd3a 100644 --- a/waypoint.c +++ b/waypoint.c @@ -316,13 +316,15 @@ int32 CmdRenameWaypoint(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) if (!IsValidWaypointID(p1)) return CMD_ERROR; + wp = GetWaypoint(p1); + if (!CheckTileOwnership(wp->xy)) return CMD_ERROR; + if (_cmd_text[0] != '\0') { StringID str = AllocateNameUnique(_cmd_text, 0); if (str == 0) return CMD_ERROR; if (flags & DC_EXEC) { - wp = GetWaypoint(p1); if (wp->string != STR_NULL) DeleteName(wp->string); wp->string = str; @@ -335,7 +337,6 @@ int32 CmdRenameWaypoint(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) } } else { if (flags & DC_EXEC) { - wp = GetWaypoint(p1); if (wp->string != STR_NULL) DeleteName(wp->string); MakeDefaultWaypointName(wp); diff --git a/window.c b/window.c index d8fe2c3120..87e28c0584 100644 --- a/window.c +++ b/window.c @@ -596,7 +596,7 @@ static Window *LocalAllocateWindow( * XXX - Yes, ugly, probably needs something like w->always_on_top flag * to implement correctly, but even then you need some kind of distinction * between on-top of chat/news and status windows, because these conflict */ - if (wz != _z_windows && w->window_class != WC_SEND_NETWORK_MSG) { + if (wz != _z_windows && w->window_class != WC_SEND_NETWORK_MSG && w->window_class != WC_HIGHSCORE && w->window_class != WC_ENDSCREEN) { if (FindWindowById(WC_MAIN_TOOLBAR, 0) != NULL) wz--; if (FindWindowById(WC_STATUS_BAR, 0) != NULL) wz--; if (FindWindowById(WC_NEWS_WINDOW, 0) != NULL) wz--;