From 36134a7285970e57c0e0a125f921a5f055f73ce2 Mon Sep 17 00:00:00 2001 From: Darkvater Date: Sat, 24 Feb 2007 01:14:54 +0000 Subject: [PATCH] (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 | 9 +++++++++ order_cmd.c | 44 +++++++++++++++++++++++++++++++++----------- station_cmd.c | 14 ++++---------- viewport.c | 2 +- 4 files changed, 47 insertions(+), 22 deletions(-) diff --git a/openttd.c b/openttd.c index 4e9b3f9536..c9a2edf990 100644 --- a/openttd.c +++ b/openttd.c @@ -1585,6 +1585,15 @@ bool AfterLoadGame(void) 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; } diff --git a/order_cmd.c b/order_cmd.c index 4c318cb32c..a69ad443a5 100644 --- a/order_cmd.c +++ b/order_cmd.c @@ -167,6 +167,16 @@ static void DeleteOrderWarnings(const Vehicle* v) } +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 @@ int32 CmdInsertOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) * 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) { diff --git a/station_cmd.c b/station_cmd.c index c70f426752..d5fef7f978 100644 --- a/station_cmd.c +++ b/station_cmd.c @@ -231,12 +231,6 @@ static Station* GetStationAround(TileIndex tile, int w, int h, StationID closest 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 @@ int32 CmdBuildRailroadStation(TileIndex tile_org, uint32 flags, uint32 p1, uint3 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 @@ int32 CmdBuildRoadStop(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) } 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 @@ int32 CmdBuildAirport(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) } 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 @@ int32 CmdBuildDock(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) } 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; diff --git a/viewport.c b/viewport.c index 5902fef150..75cf3e3ae2 100644 --- a/viewport.c +++ b/viewport.c @@ -1617,7 +1617,7 @@ static bool CheckClickOnSign(const ViewPort *vp, int x, int y) { 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: