diff options
author | darkvater <darkvater@openttd.org> | 2004-09-14 14:19:53 +0000 |
---|---|---|
committer | darkvater <darkvater@openttd.org> | 2004-09-14 14:19:53 +0000 |
commit | c79e8ad626acbc9b8d6dd3fdc4fa40e100f2167e (patch) | |
tree | 7df8b49dd0e2fa59e7cd1963b5fdb40849630535 /ship_gui.c | |
parent | 5e699ca65d58722d0e0daebdfc61fbc8913b56bc (diff) | |
download | openttd-c79e8ad626acbc9b8d6dd3fdc4fa40e100f2167e.tar.xz |
(svn r244) -Fix: Stations were not sorted for non-player-0 players
-Fix: Correctly resorting vehicle list of player when the list of another player is open.
Diffstat (limited to 'ship_gui.c')
-rw-r--r-- | ship_gui.c | 61 |
1 files changed, 36 insertions, 25 deletions
diff --git a/ship_gui.c b/ship_gui.c index 6862f3024..23a796d0d 100644 --- a/ship_gui.c +++ b/ship_gui.c @@ -871,36 +871,41 @@ static void DrawSmallShipSchedule(Vehicle *v, int x, int y) { static SortStruct _ship_sort[NUM_NORMAL_VEHICLES]; static uint16 _num_ship_sort[MAX_PLAYERS]; -static void MakeSortedShiptList(byte owner) +static void GlobalSortShipList() { - SortStruct *firstelement; - Vehicle *v; - uint32 n = 0; + const Vehicle *v; uint16 *i; + uint32 n = 0; - if (_vehicle_sort_dirty[VEHSHIP]) { // only resort the whole array if vehicles have been added/removed - // reset to 0 just to be sure - for (i = _num_ship_sort; i != endof(_num_ship_sort); i++) {*i = 0;} + // reset #-of ships to 0 because ++ is used for value-assignment + for (i = _num_ship_sort; i != endof(_num_ship_sort); i++) {*i = 0;} - FOR_ALL_VEHICLES(v) { - if(v->type == VEH_Ship) { - _ship_sort[n].index = v->index; - _ship_sort[n++].owner = v->owner; - _num_ship_sort[v->owner]++; // add number of trains of player - } + FOR_ALL_VEHICLES(v) { + if(v->type == VEH_Ship) { + _ship_sort[n].index = v->index; + _ship_sort[n++].owner = v->owner; + _num_ship_sort[v->owner]++; // add number of ships of player } + } - // create cumulative ship-ownage - // ships are stored as a cummulative index, eg 25, 41, 43. This means - // Player0: 25; Player1: (41-25) 16; Player2: (43-41) 2 - for (i = &_num_ship_sort[1]; i != endof(_num_ship_sort); i++) {*i += *(i-1);} + // create cumulative ship-ownership + // ships are stored as a cummulative index, eg 25, 41, 43. This means + // Player0: 25; Player1: (41-25) 16; Player2: (43-41) 2 + for (i = &_num_ship_sort[1]; i != endof(_num_ship_sort); i++) {*i += *(i-1);} - // sort by owner, then only subsort the requested owner-vehicles - qsort(_ship_sort, n, sizeof(_ship_sort[0]), GeneralOwnerSorter); + qsort(_ship_sort, n, sizeof(_ship_sort[0]), GeneralOwnerSorter); // sort by owner - _last_vehicle_idx = 0; // used for "cache" in namesorting - _vehicle_sort_dirty[VEHSHIP] = false; - } + // since indexes are messed up after adding/removing a station, mark all lists dirty + memset(_ship_sort_dirty, true, sizeof(_ship_sort_dirty)); + _vehicle_sort_dirty[VEHSHIP] = false; + + DEBUG(misc, 1) ("Resorting global ships list..."); +} + +static void MakeSortedShipList(byte owner) +{ + SortStruct *firstelement; + uint32 n = 0; if (owner == 0) { // first element starts at 0th element and has n elements as described above firstelement = &_ship_sort[0]; @@ -912,8 +917,11 @@ static void MakeSortedShiptList(byte owner) _internal_sort_order = _ship_sort_order[owner]; _internal_name_sorter_id = STR_SV_SHIP_NAME; + _last_vehicle_idx = 0; // used for "cache" in namesorting qsort(firstelement, n, sizeof(_ship_sort[0]), _vehicle_sorter[_ship_sort_type[owner]]); + _ship_sort_dirty[owner] = false; + DEBUG(misc, 1) ("Resorting Ships list player %d...", owner+1); } @@ -927,9 +935,12 @@ static void PlayerShipsWndProc(Window *w, WindowEvent *e) if (_ship_sort_type[window_number] == SORT_BY_UNSORTED) // disable 'Sort By' tooltip on Unsorted sorting criteria w->disabled_state |= (1 << 2); - if (_ship_sort_dirty[window_number] || _vehicle_sort_dirty[VEHSHIP]) { - _ship_sort_dirty[window_number] = false; - MakeSortedShiptList(window_number); + // resort shipps window if roadvehicles have been added/removed + if (_vehicle_sort_dirty[VEHSHIP]) + GlobalSortShipList(); + + if (_ship_sort_dirty[window_number]) { + MakeSortedShipList(window_number); /* reset sorting timeout */ w->custom[0] = DAY_TICKS; w->custom[1] = PERIODIC_RESORT_DAYS; |