(svn r8871) [0.5] -Backport from trunk (r8689, r8794, r8802, r8808): 0.5
authorDarkvater
Sat, 24 Feb 2007 01:14:54 +0000
branch0.5
changeset 5443 4ef33c0ddab7
parent 5442 427c81cfd6f6
child 5444 3209bb62403e
(svn r8871) [0.5] -Backport from trunk (r8689, r8794, r8802, r8808):
- Crash when an old savegame had buoys on the northern edge of the map (r8689)
- It was possible to take over buoys by building a station next to them (r8794)
- Adhere order types for ship order insertion to determine destination type (r8802)
- Do not show the 'edit sign' window for spectators (r8808)
openttd.c
order_cmd.c
station_cmd.c
viewport.c
--- a/openttd.c	Sat Feb 24 01:02:15 2007 +0000
+++ b/openttd.c	Sat Feb 24 01:14:54 2007 +0000
@@ -1585,6 +1585,15 @@
 		SettingsDisableElrail(_patches.disable_elrails);
 	}
 
+	/* Buoys do now store the owner of the previous water tile, which can never
+	 * be OWNER_NONE. So replace OWNER_NONE with OWNER_WATER. */
+	if (CheckSavegameVersion(46)) {
+		Station *st;
+		FOR_ALL_STATIONS(st) {
+			if (IsBuoy(st) && IsTileOwner(st->xy, OWNER_NONE)) SetTileOwner(st->xy, OWNER_WATER);
+		}
+	}
+
 	return true;
 }
 
--- a/order_cmd.c	Sat Feb 24 01:02:15 2007 +0000
+++ b/order_cmd.c	Sat Feb 24 01:14:54 2007 +0000
@@ -167,6 +167,16 @@
 }
 
 
+static TileIndex GetOrderLocation(const Order *o)
+{
+	switch (o->type) {
+		default: NOT_REACHED();
+		case OT_GOTO_STATION: return GetStation(o->dest)->xy;
+		case OT_GOTO_DEPOT:   return GetDepot(o->dest)->xy;
+	}
+}
+
+
 /** Add an order to the orderlist of a vehicle.
  * @param tile unused
  * @param p1 various bitstuffed elements
@@ -343,18 +353,30 @@
 	 * handle any more then this.. */
 	if (v->num_orders >= MAX_BACKUP_ORDER_COUNT) return_cmd_error(STR_8832_TOO_MANY_ORDERS);
 
-	/* For ships, make sure that the station is not too far away from the
-	 * previous destination, for human players with new pathfinding disabled */
-	if (v->type == VEH_Ship && IsHumanPlayer(v->owner) &&
-		sel_ord != 0 && GetVehicleOrder(v, sel_ord - 1)->type == OT_GOTO_STATION
-		&& !_patches.new_pathfinding_all) {
+	if (v->type == VEH_Ship &&
+			IsHumanPlayer(v->owner) &&
+			!_patches.new_pathfinding_all) {
+		// Make sure the new destination is not too far away from the previous
+		const Order *prev = NULL;
+		const Order *o;
+		uint n = 0;
 
-		int dist = DistanceManhattan(
-			GetStation(GetVehicleOrder(v, sel_ord - 1)->dest)->xy,
-			GetStation(new_order.dest)->xy // XXX type != OT_GOTO_STATION?
-		);
-		if (dist >= 130)
-			return_cmd_error(STR_0210_TOO_FAR_FROM_PREVIOUS_DESTINATIO);
+		/* Find the last goto station or depot order before the insert location.
+		 * If the order is to be inserted at the beginning of the order list this
+		 * finds the last order in the list. */
+		for (o = v->orders; o != NULL; o = o->next) {
+			if (o->type == OT_GOTO_STATION || o->type == OT_GOTO_DEPOT) prev = o;
+			if (++n == sel_ord && prev != NULL) break;
+		}
+		if (prev != NULL) {
+			uint dist = DistanceManhattan(
+				GetOrderLocation(prev),
+				GetOrderLocation(&new_order)
+			);
+			if (dist >= 130) {
+				return_cmd_error(STR_0210_TOO_FAR_FROM_PREVIOUS_DESTINATIO);
+			}
+		}
 	}
 
 	if (flags & DC_EXEC) {
--- a/station_cmd.c	Sat Feb 24 01:02:15 2007 +0000
+++ b/station_cmd.c	Sat Feb 24 01:14:54 2007 +0000
@@ -231,12 +231,6 @@
 	BEGIN_TILE_LOOP(tile_cur, w + 2, h + 2, tile - TileDiffXY(1, 1))
 		if (IsTileType(tile_cur, MP_STATION)) {
 			StationID t = GetStationIndex(tile_cur);
-			{
-				Station *st = GetStation(t);
-				// you cannot take control of an oilrig!!
-				if (st->airport_type == AT_OILRIG && st->facilities == (FACIL_AIRPORT|FACIL_DOCK))
-					continue;
-			}
 
 			if (closest_station == INVALID_STATION) {
 				closest_station = t;
@@ -1016,7 +1010,7 @@
 
 	if (st != NULL) {
 		// Reuse an existing station.
-		if (st->owner != OWNER_NONE && st->owner != _current_player)
+		if (st->owner != _current_player)
 			return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION);
 
 		if (st->train_tile != 0) {
@@ -1451,7 +1445,7 @@
 	}
 
 	if (st != NULL) {
-		if (st->owner != OWNER_NONE && st->owner != _current_player) {
+		if (st->owner != _current_player) {
 			return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION);
 		}
 
@@ -1706,7 +1700,7 @@
 	}
 
 	if (st != NULL) {
-		if (st->owner != OWNER_NONE && st->owner != _current_player)
+		if (st->owner != _current_player)
 			return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION);
 
 		if (!StationRect_BeforeAddRect(st, tile, w, h, RECT_MODE_TEST)) return CMD_ERROR;
@@ -1987,7 +1981,7 @@
 	}
 
 	if (st != NULL) {
-		if (st->owner != OWNER_NONE && st->owner != _current_player)
+		if (st->owner != _current_player)
 			return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION);
 
 		if (!StationRect_BeforeAddRect(st, tile, _dock_w_chk[direction], _dock_h_chk[direction], RECT_MODE_TEST)) return CMD_ERROR;
--- a/viewport.c	Sat Feb 24 01:02:15 2007 +0000
+++ b/viewport.c	Sat Feb 24 01:14:54 2007 +0000
@@ -1617,7 +1617,7 @@
 {
 	const Sign *si;
 
-	if (!(_display_opt & DO_SHOW_SIGNS)) return false;
+	if (!(_display_opt & DO_SHOW_SIGNS) || _current_player == PLAYER_SPECTATOR) return false;
 
 	switch (vp->zoom) {
 		case 0: