From 3baf4aa4a22a277406281b656d48611b46d89189 Mon Sep 17 00:00:00 2001 From: rubidium Date: Fri, 10 Aug 2007 17:53:12 +0000 Subject: [PATCH] (svn r10841) [0.5] -Backport from trunk (r10835, r10593, r10500, r10497, r10410, r10357, r10199): - Fix: [Windows] Do not try to minimise or restore the window when closing OpenTTD [FS#998] (r10835) - Fix: One could not remove locks that were build in a (very) old version of OpenTTD [FS#1038] (r10593) - Fix: One cannot navigate using arrow keys in the game name text box [FS#1038] (r10500) - Fix: Ship's maximum speed wrongly shown [FS#1013] (r10497) - Fix: [OSX] Of the resolution is changed to something that is too high for the monitor, then it is reduced to fit the monitor size, solving several crashes and graphical glitches [FS#458] (r10410) - Fix: NPF was leaking memory each time it got initialized, except for the first time (r10357) - Fix: [YAPF] 'target_seen' flag that is set prematurely in some cases (1 tile long cached segment followed by target station) which caused asserts to trigger [FS#884] (r10199) --- network_gui.c | 1 - npf.c | 8 +++++++- openttd.c | 10 ++++++++++ ship_gui.c | 2 +- video/cocoa_v.m | 7 +++++++ video/win32_v.c | 3 +++ water_cmd.c | 8 +++++--- yapf/yapf_costrail.hpp | 6 ++++-- 8 files changed, 37 insertions(+), 8 deletions(-) diff --git a/network_gui.c b/network_gui.c index 125c701320..863d08b36b 100644 --- a/network_gui.c +++ b/network_gui.c @@ -731,7 +731,6 @@ static void NetworkStartServerWindowWndProc(Window *w, WindowEvent *e) if (HandleEditBoxKey(w, &WP(w, network_ql_d).q, 3, e) == 1) break; // enter pressed ttd_strlcpy(_network_server_name, WP(w, network_ql_d).q.text.buf, sizeof(_network_server_name)); - UpdateTextBufferSize(&WP(w, network_ql_d).q.text); } break; diff --git a/npf.c b/npf.c index 7e680e30a0..03890c9f30 100644 --- a/npf.c +++ b/npf.c @@ -868,7 +868,13 @@ NPFFoundTargetData NPFRouteToDepotTrialError(TileIndex tile, Trackdir trackdir, void InitializeNPF(void) { - init_AyStar(&_npf_aystar, NPFHash, NPF_HASH_SIZE); + static bool first_init = true; + if (first_init) { + first_init = false; + init_AyStar(&_npf_aystar, NPFHash, NPF_HASH_SIZE); + } else { + AyStarMain_Clear(&_npf_aystar); + } _npf_aystar.loops_per_tick = 0; _npf_aystar.max_path_cost = 0; //_npf_aystar.max_search_nodes = 0; diff --git a/openttd.c b/openttd.c index 62069d1f8b..61d7cf5e4e 100644 --- a/openttd.c +++ b/openttd.c @@ -25,6 +25,7 @@ #include "station_map.h" #include "town_map.h" #include "tunnel_map.h" +#include "water_map.h" #include "vehicle.h" #include "viewport.h" #include "window.h" @@ -1615,10 +1616,19 @@ bool AfterLoadGame(void) /* 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)) { + TileIndex t; Station *st; FOR_ALL_STATIONS(st) { if (IsBuoy(st) && IsTileOwner(st->xy, OWNER_NONE)) SetTileOwner(st->xy, OWNER_WATER); } + + /* Locks/shiplifts in very old savegames had OWNER_WATER as owner */ + for (t = 0; t < MapSize(); t++) { + if (IsTileType(t, MP_WATER) && GetWaterTileType(t) == WATER_LOCK && + GetTileOwner(t) == OWNER_WATER) { + SetTileOwner(t, OWNER_NONE); + } + } } if (CheckSavegameVersion(7)) { diff --git a/ship_gui.c b/ship_gui.c index c0719d803e..407bb2e486 100644 --- a/ship_gui.c +++ b/ship_gui.c @@ -108,7 +108,7 @@ static void ShipDetailsWndProc(Window *w, WindowEvent *e) /* Draw max speed */ { - SetDParam(0, v->max_speed / 2); + SetDParam(0, v->max_speed * 10 / 32); DrawString(2, 25, STR_9813_MAX_SPEED, 0); } diff --git a/video/cocoa_v.m b/video/cocoa_v.m index 6e5cd54c29..86d98d8081 100644 --- a/video/cocoa_v.m +++ b/video/cocoa_v.m @@ -1154,10 +1154,17 @@ static const char* QZ_SetVideoWindowed(uint width, uint height) /* We already have a window, just change its size */ if (!isCustom) { [ _cocoa_video_data.window setContentSize:contentRect.size ]; + // Ensure frame height - title bar height >= view height + contentRect.size.height = clamp(height, 0, [ _cocoa_video_data.window frame ].size.height - 22 /* 22 is the height of title bar of window*/); + height = contentRect.size.height; [ _cocoa_video_data.qdview setFrameSize:contentRect.size ]; } } + // Update again + _cocoa_video_data.width = width; + _cocoa_video_data.height = height; + [ _cocoa_video_data.window center ]; /* Only recreate the view if it doesn't already exist */ diff --git a/video/win32_v.c b/video/win32_v.c index 0a76a7d8ed..1b2f96e696 100644 --- a/video/win32_v.c +++ b/video/win32_v.c @@ -619,6 +619,9 @@ static LRESULT CALLBACK WndProcGdi(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lP #if !defined(WINCE) case WM_ACTIVATE: { + /* Don't do anything if we are closing openttd */ + if (_exit_game) break; + bool active = (LOWORD(wParam) != WA_INACTIVE); bool minimized = (HIWORD(wParam) != 0); if (_wnd.fullscreen) { diff --git a/water_cmd.c b/water_cmd.c index 9dad847a71..4bea594e43 100644 --- a/water_cmd.c +++ b/water_cmd.c @@ -157,7 +157,7 @@ static int32 RemoveShiplift(TileIndex tile, uint32 flags) { TileIndexDiff delta = TileOffsByDiagDir(GetLockDirection(tile)); - if (!CheckTileOwnership(tile)) return CMD_ERROR; + if (!CheckTileOwnership(tile) && GetTileOwner(tile) != OWNER_NONE) return CMD_ERROR; // make sure no vehicle is on the tile. if (!EnsureNoVehicle(tile) || !EnsureNoVehicle(tile + delta) || !EnsureNoVehicle(tile - delta)) @@ -303,7 +303,7 @@ static int32 ClearTile_Water(TileIndex tile, byte flags) return_cmd_error(STR_0002_TOO_CLOSE_TO_EDGE_OF_MAP); } - if (GetTileOwner(tile) != OWNER_WATER && !CheckTileOwnership(tile)) return CMD_ERROR; + if (GetTileOwner(tile) != OWNER_WATER && GetTileOwner(tile) != OWNER_NONE && !CheckTileOwnership(tile)) return CMD_ERROR; if (flags & DC_EXEC) DoClearSquare(tile); return _price.clear_water; @@ -810,8 +810,10 @@ static void ChangeTileOwner_Water(TileIndex tile, PlayerID old_player, PlayerID if (new_player != PLAYER_SPECTATOR) { SetTileOwner(tile, new_player); - } else { + } else if (IsShipDepot(tile)) { DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); + } else { + SetTileOwner(tile, OWNER_NONE); } } diff --git a/yapf/yapf_costrail.hpp b/yapf/yapf_costrail.hpp index f5d7a8a785..bec426be62 100644 --- a/yapf/yapf_costrail.hpp +++ b/yapf/yapf_costrail.hpp @@ -193,6 +193,7 @@ public: RailType rail_type = GetTileRailType(tile, trackdir); bool target_seen = Yapf().PfDetectDestination(tile, trackdir); + bool end_by_target_seen = false; if (tf.m_is_station) { // station tiles have an extra penalty @@ -210,6 +211,7 @@ public: // finish if we have reached the destination if (target_seen) { + end_by_target_seen = true; break; } @@ -340,7 +342,7 @@ public: } // special costs for the case we have reached our target - if (target_seen) { + if (end_by_target_seen) { n.flags_u.flags_s.m_targed_seen = true; if (n.flags_u.flags_s.m_last_signal_was_red) { if (n.m_last_red_signal_type == SIGTYPE_EXIT) { @@ -356,7 +358,7 @@ public: // total node cost n.m_cost = parent_cost + first_tile_cost + segment_cost + extra_cost; - return !n.m_segment->flags_u.flags_s.m_end_of_line; + return !n.m_segment->flags_u.flags_s.m_end_of_line || end_by_target_seen; } FORCEINLINE bool CanUseGlobalCache(Node& n) const