summaryrefslogtreecommitdiff
path: root/aircraft_gui.c
diff options
context:
space:
mode:
authordarkvater <darkvater@openttd.org>2004-09-14 14:19:53 +0000
committerdarkvater <darkvater@openttd.org>2004-09-14 14:19:53 +0000
commitc79e8ad626acbc9b8d6dd3fdc4fa40e100f2167e (patch)
tree7df8b49dd0e2fa59e7cd1963b5fdb40849630535 /aircraft_gui.c
parent5e699ca65d58722d0e0daebdfc61fbc8913b56bc (diff)
downloadopenttd-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 'aircraft_gui.c')
-rw-r--r--aircraft_gui.c59
1 files changed, 35 insertions, 24 deletions
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;