(svn r10374) [0.5] -Backport from trunk (r10333, r10336, r10337, r10345, 10346, 10368): 0.5
authorrubidium
Thu, 28 Jun 2007 14:31:46 +0000
branch0.5
changeset 5520 82988aae1562
parent 5519 f666f6b62978
child 5521 3fe5c80f0778
(svn r10374) [0.5] -Backport from trunk (r10333, r10336, r10337, r10345, 10346, 10368):
- Fix: Waypoints could be renamed when you are not the owner (r10368)
- Fix: The 'old' pathfinders (OPF and NPF) for road vehicles could not find a path when in a tunnel [FS#290] (r10345, r10346)
- Fix: Only add the autoreplace menu when autoreplace actually knows about the group [FS#880] (r10337)
- Fix: Signal state sometimes not properly set when the signal "pathfinder" reached the end of a line [FS#910] (r10336)
- Fix: News messages were shown over the endgame/highscore windows [FS#943] (r10333)
pathfind.c
roadveh_cmd.c
vehicle_gui.c
waypoint.c
window.c
--- a/pathfind.c	Thu Jun 28 14:11:00 2007 +0000
+++ b/pathfind.c	Thu Jun 28 14:31:46 2007 +0000
@@ -251,31 +251,13 @@
 48, 56, 56, 58, 56, 60, 60, 62,
 };
 
-static void TPFMode1(TrackPathFinder* tpf, TileIndex tile, DiagDirection direction)
-{
-	uint bits;
-	int i;
-	RememberData rd;
-	TileIndex tile_org = tile;
+static void TPFMode1(TrackPathFinder* tpf, TileIndex tile, DiagDirection direction);
 
-	// 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);
-
+/** 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)
+{
 	/* 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 @@
 	/* 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 @@
 		}
 	}
 
+	TPFMode1_NormalCase(tpf, tile, tile_org, direction);
+
 	/* the next is only used when signals are checked.
 	 * seems to go in 2 directions simultaneously */
 
--- a/roadveh_cmd.c	Thu Jun 28 14:11:00 2007 +0000
+++ b/roadveh_cmd.c	Thu Jun 28 14:31:46 2007 +0000
@@ -332,7 +332,7 @@
 		/* 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 {
--- a/vehicle_gui.c	Thu Jun 28 14:11:00 2007 +0000
+++ b/vehicle_gui.c	Thu Jun 28 14:31:46 2007 +0000
@@ -1769,7 +1769,7 @@
 
 					/* 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;
 				}
 
--- a/waypoint.c	Thu Jun 28 14:11:00 2007 +0000
+++ b/waypoint.c	Thu Jun 28 14:31:46 2007 +0000
@@ -316,13 +316,15 @@
 
 	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 @@
 		}
 	} else {
 		if (flags & DC_EXEC) {
-			wp = GetWaypoint(p1);
 			if (wp->string != STR_NULL) DeleteName(wp->string);
 
 			MakeDefaultWaypointName(wp);
--- a/window.c	Thu Jun 28 14:11:00 2007 +0000
+++ b/window.c	Thu Jun 28 14:31:46 2007 +0000
@@ -596,7 +596,7 @@
 		 * 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--;