From c79e8ad626acbc9b8d6dd3fdc4fa40e100f2167e Mon Sep 17 00:00:00 2001 From: darkvater Date: Tue, 14 Sep 2004 14:19:53 +0000 Subject: (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. --- aircraft_gui.c | 59 ++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 24 deletions(-) (limited to 'aircraft_gui.c') diff --git a/aircraft_gui.c b/aircraft_gui.c index ce438ab5a..371ef4f10 100644 --- a/aircraft_gui.c +++ b/aircraft_gui.c @@ -868,36 +868,41 @@ static void DrawSmallSchedule(Vehicle *v, int x, int y) { static SortStruct _aircraft_sort[NUM_NORMAL_VEHICLES]; static uint16 _num_aircraft_sort[MAX_PLAYERS]; -static void MakeSortedAircraftList(byte owner) +static void GlobalSortAircraftList() { - SortStruct *firstelement; - Vehicle *v; - uint32 n = 0; + const Vehicle *v; uint16 *i; + uint32 n = 0; - if (_vehicle_sort_dirty[VEHAIRCRAFT]) { // only resort the whole array if vehicles have been added/removed - // reset to 0 just to be sure - for (i = _num_aircraft_sort; i != endof(_num_aircraft_sort); i++) {*i = 0;} + // reset #-of aircraft to 0 because ++ is used for value-assignment + for (i = _num_aircraft_sort; i != endof(_num_aircraft_sort); i++) {*i = 0;} - FOR_ALL_VEHICLES(v) { - if(v->type == VEH_Aircraft && v->subtype <= 2) { - _aircraft_sort[n].index = v->index; - _aircraft_sort[n++].owner = v->owner; - _num_aircraft_sort[v->owner]++; // add number of aircraft of player - } + FOR_ALL_VEHICLES(v) { + if(v->type == VEH_Aircraft && v->subtype <= 2) { + _aircraft_sort[n].index = v->index; + _aircraft_sort[n++].owner = v->owner; + _num_aircraft_sort[v->owner]++; // add number of aircraft of player } + } - // create cumulative aircraft-ownage - // aircraft 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_aircraft_sort[1]; i != endof(_num_aircraft_sort); i++) {*i += *(i-1);} + // create cumulative aircraft-ownership + // aircraft 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_aircraft_sort[1]; i != endof(_num_aircraft_sort); i++) {*i += *(i-1);} - // sort by owner, then only subsort the requested owner-vehicles - qsort(_aircraft_sort, n, sizeof(_aircraft_sort[0]), GeneralOwnerSorter); + qsort(_aircraft_sort, n, sizeof(_aircraft_sort[0]), GeneralOwnerSorter); // sort by owner - _last_vehicle_idx = 0; // used for "cache" in namesorting - _vehicle_sort_dirty[VEHAIRCRAFT] = false; - } + // since indexes are messed up after adding/removing a station, mark all lists dirty + memset(_aircraft_sort_dirty, true, sizeof(_aircraft_sort_dirty)); + _vehicle_sort_dirty[VEHAIRCRAFT] = false; + + DEBUG(misc, 1) ("Resorting global aircraft list..."); +} + +static void MakeSortedAircraftList(byte owner) +{ + SortStruct *firstelement; + uint32 n = 0; if (owner == 0) { // first element starts at 0th element and has n elements as described above firstelement = &_aircraft_sort[0]; @@ -909,8 +914,11 @@ static void MakeSortedAircraftList(byte owner) _internal_sort_order = _aircraft_sort_order[owner]; _internal_name_sorter_id = STR_SV_AIRCRAFT_NAME; + _last_vehicle_idx = 0; // used for "cache" in namesorting qsort(firstelement, n, sizeof(_aircraft_sort[0]), _vehicle_sorter[_aircraft_sort_type[owner]]); + _aircraft_sort_dirty[owner] = false; + DEBUG(misc, 1) ("Resorting Aircraft list player %d...", owner+1); } @@ -924,8 +932,11 @@ static void PlayerAircraftWndProc(Window *w, WindowEvent *e) if (_aircraft_sort_type[window_number] == SORT_BY_UNSORTED) // disable 'Sort By' tooltip on Unsorted sorting criteria w->disabled_state |= (1 << 2); - if (_aircraft_sort_dirty[window_number] || _vehicle_sort_dirty[VEHAIRCRAFT]) { - _aircraft_sort_dirty[window_number] = false; + // resort shipps window if roadvehicles have been added/removed + if (_vehicle_sort_dirty[VEHAIRCRAFT]) + GlobalSortAircraftList(); + + if (_aircraft_sort_dirty[window_number]) { MakeSortedAircraftList(window_number); /* reset sorting timeout */ w->custom[0] = DAY_TICKS; -- cgit v1.2.3-54-g00ecf