Changeset - r243:ca7c3d233c70
[Not reviewed]
master
0 8 0
darkvater - 20 years ago 2004-09-14 14:19:53
darkvater@openttd.org
(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.
8 files changed with 215 insertions and 167 deletions:
0 comments (0 inline, 0 general)
aircraft_gui.c
Show inline comments
 
@@ -868,36 +868,41 @@ static void DrawSmallSchedule(Vehicle *v
 
static SortStruct _aircraft_sort[NUM_NORMAL_VEHICLES];
 
static uint16 _num_aircraft_sort[MAX_PLAYERS];
 

	
 
static void GlobalSortAircraftList()
 
{
 
	const Vehicle *v;
 
	uint16 *i;
 
	uint32 n = 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
 
		}
 
	}
 

	
 
	// 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);}
 

	
 
	qsort(_aircraft_sort, n, sizeof(_aircraft_sort[0]), GeneralOwnerSorter); // sort by owner
 

	
 
	// 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;
 
	Vehicle *v;
 
	uint32 n = 0;
 
	uint16 *i;
 

	
 
	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;}
 

	
 
		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);}
 

	
 
		// sort by owner, then only subsort the requested owner-vehicles
 
		qsort(_aircraft_sort, n, sizeof(_aircraft_sort[0]), GeneralOwnerSorter);
 

	
 
		_last_vehicle_idx = 0; // used for "cache" in namesorting
 
		_vehicle_sort_dirty[VEHAIRCRAFT] = false;
 
	}
 

	
 
	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 
 

	
 
	_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
 
		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;
roadveh_gui.c
Show inline comments
 
@@ -707,36 +707,41 @@ void ShowRoadDepotWindow(uint tile)
 
static SortStruct _road_sort[NUM_NORMAL_VEHICLES];
 
static uint16 _num_road_sort[MAX_PLAYERS];
 

	
 
static void MakeSortedRoadList(byte owner)
 
static void GlobalSortRoadVehList()
 
{
 
	const Vehicle *v;
 
	uint16 *i;
 
	uint32 n = 0;
 

	
 
	// reset #-of roadvehicles to 0 because ++ is used for value-assignment
 
	for (i = _num_road_sort; i != endof(_num_road_sort); i++) {*i = 0;}
 

	
 
	FOR_ALL_VEHICLES(v) {
 
		if(v->type == VEH_Road) {
 
			_road_sort[n].index = v->index;
 
			_road_sort[n++].owner = v->owner;
 
			_num_road_sort[v->owner]++; // add number of roadvehicless of player
 
		}
 
	}
 

	
 
	// create cumulative roadvehicle-ownership
 
	// roads 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_road_sort[1]; i != endof(_num_road_sort); i++) {*i += *(i-1);}
 

	
 
	qsort(_road_sort, n, sizeof(_road_sort[0]), GeneralOwnerSorter); // sort by owner
 

	
 
	// since indexes are messed up after adding/removing a station, mark all lists dirty
 
	memset(_road_sort_dirty, true, sizeof(_road_sort_dirty));
 
	_vehicle_sort_dirty[VEHROAD] = false;
 

	
 
	DEBUG(misc, 1) ("Resorting global roadvehicles list...");
 
}
 

	
 
static void MakeSortedRoadVehList(byte owner)
 
{
 
	SortStruct *firstelement;
 
	Vehicle *v;
 
	uint32 n = 0;
 
	uint16 *i;
 

	
 
	if (_vehicle_sort_dirty[VEHROAD]) { // only resort the whole array if vehicles have been added/removed
 
		// reset to 0 just to be sure
 
		for (i = _num_road_sort; i != endof(_num_road_sort); i++) {*i = 0;}
 

	
 
		FOR_ALL_VEHICLES(v) {
 
			if(v->type == VEH_Road) {
 
				_road_sort[n].index = v->index;
 
				_road_sort[n++].owner = v->owner;
 
				_num_road_sort[v->owner]++; // add number of roads of player
 
			}
 
		}
 

	
 
		// create cumulative road-ownage
 
		// roads 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_road_sort[1]; i != endof(_num_road_sort); i++) {*i += *(i-1);}
 

	
 
		// sort by owner, then only subsort the requested owner-vehicles
 
		qsort(_road_sort, n, sizeof(_road_sort[0]), GeneralOwnerSorter);
 

	
 
		_last_vehicle_idx = 0; // used for "cache" in namesorting
 
		_vehicle_sort_dirty[VEHROAD] = false;
 
	}
 

	
 
	if (owner == 0) { // first element starts at 0th element and has n elements as described above
 
		firstelement =	&_road_sort[0];
 
@@ -748,8 +753,11 @@ static void MakeSortedRoadList(byte owne
 

	
 
	_internal_sort_order			= _road_sort_order[owner];
 
	_internal_name_sorter_id	= STR_SV_ROADVEH_NAME;
 
	_last_vehicle_idx = 0; // used for "cache" in namesorting
 
	qsort(firstelement, n, sizeof(_road_sort[0]), _vehicle_sorter[_road_sort_type[owner]]);
 

	
 
	_road_sort_dirty[owner] = false;
 

	
 
	DEBUG(misc, 1) ("Resorting Roadvehicles list player %d...", owner+1);
 
}
 

	
 
@@ -763,9 +771,12 @@ static void PlayerRoadVehWndProc(Window 
 
		if (_road_sort_type[window_number] == SORT_BY_UNSORTED) // disable 'Sort By' tooltip on Unsorted sorting criteria
 
			w->disabled_state |= (1 << 2);
 

	
 
		if (_road_sort_dirty[window_number] || _vehicle_sort_dirty[VEHROAD]) {
 
			_road_sort_dirty[window_number] = false;
 
			MakeSortedRoadList(window_number);
 
		// resort roadvehicles window if roadvehicles have been added/removed
 
		if (_vehicle_sort_dirty[VEHROAD])
 
			GlobalSortRoadVehList();
 

	
 
		if (_road_sort_dirty[window_number]) {
 
			MakeSortedRoadVehList(window_number);
 
			/* reset sorting timeout */
 
			w->custom[0] = DAY_TICKS;
 
			w->custom[1] = PERIODIC_RESORT_DAYS;
ship_gui.c
Show inline comments
 
@@ -871,36 +871,41 @@ static void DrawSmallShipSchedule(Vehicl
 
static SortStruct _ship_sort[NUM_NORMAL_VEHICLES];
 
static uint16 _num_ship_sort[MAX_PLAYERS];
 

	
 
static void MakeSortedShiptList(byte owner)
 
static void GlobalSortShipList()
 
{
 
	const Vehicle *v;
 
	uint16 *i;
 
	uint32 n = 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 ships of player
 
		}
 
	}
 

	
 
	// 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);}
 

	
 
	qsort(_ship_sort, n, sizeof(_ship_sort[0]), GeneralOwnerSorter); // sort by owner
 

	
 
	// 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;
 
	Vehicle *v;
 
	uint32 n = 0;
 
	uint16 *i;
 

	
 
	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;}
 

	
 
		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
 
			}
 
		}
 

	
 
		// 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);}
 

	
 
		// sort by owner, then only subsort the requested owner-vehicles
 
		qsort(_ship_sort, n, sizeof(_ship_sort[0]), GeneralOwnerSorter);
 

	
 
		_last_vehicle_idx = 0; // used for "cache" in namesorting
 
		_vehicle_sort_dirty[VEHSHIP] = false;
 
	}
 

	
 
	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 own
 

	
 
	_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
 
		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;
station.h
Show inline comments
 
@@ -79,7 +79,8 @@ void ShowStationViewWindow(int station);
 
void UpdateAllStationVirtCoord();
 

	
 
VARDEF Station _stations[250];
 
VARDEF bool _station_sort_dirty;
 
VARDEF bool _station_sort_dirty[MAX_PLAYERS];
 
VARDEF bool _global_station_sort_dirty;
 

	
 
#define DEREF_STATION(i) (&_stations[i])
 
#define FOR_ALL_STATIONS(st) for(st=_stations; st != endof(_stations); st++)
station_cmd.c
Show inline comments
 
@@ -313,7 +313,8 @@ static void StationInitialize(Station *s
 
		ge->last_speed = 0;
 
		ge->last_age = 0xFF;
 
	}
 
	_station_sort_dirty = true;
 

	
 
	_global_station_sort_dirty = true; // build a new station
 
}
 

	
 
// Update the virtual coords needed to draw the station sign.
 
@@ -2026,7 +2027,7 @@ static void DeleteStation(Station *st)
 

	
 
	DeleteName(st->string_id);
 
	MarkStationDirty(st);
 
	_station_sort_dirty = true;
 
	_global_station_sort_dirty = true; // delete station, remove sign
 
	InvalidateWindowClasses(WC_STATION_LIST);
 

	
 
	index = st->index;
 
@@ -2247,7 +2248,7 @@ int32 CmdRenameStation(int x, int y, uin
 
		st->string_id = str;
 
		UpdateStationVirtCoord(st);
 
		DeleteName(old_str);
 
		_station_sort_dirty = true;
 
		_station_sort_dirty[st->owner] = true; // rename a station
 
		MarkWholeScreenDirty();
 
	} else {
 
		DeleteName(str);
 
@@ -2426,7 +2427,7 @@ static void ChangeTileOwner_Station(uint
 
		Station *st = DEREF_STATION(_map2[tile]);
 
		_map_owner[tile] = new_player;
 
		st->owner = new_player;
 
		_station_sort_dirty = true;
 
		_global_station_sort_dirty = true; // transfer ownership of station to another player
 
		InvalidateWindowClasses(WC_STATION_LIST);
 
	} else {
 
		DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
 
@@ -2476,11 +2477,16 @@ static int32 ClearTile_Station(uint tile
 
void InitializeStations()
 
{
 
	int i;
 
	
 
	memset(_stations, 0, sizeof(_stations));
 
	for(i=0;i!=lengthof(_stations); i++)
 
	for(i = 0; i != lengthof(_stations); i++)
 
		_stations[i].index=i;
 

	
 
	_station_tick_ctr = 0;
 
	_station_sort_dirty = true;	// set stations to be sorted on first load
 

	
 
	// set stations to be sorted on load of savegame
 
	memset(_station_sort_dirty, true, sizeof(_station_sort_dirty));
 
	_global_station_sort_dirty = true; // load of savegame
 
}
 

	
 

	
station_gui.c
Show inline comments
 
@@ -73,13 +73,13 @@ static int CDECL StationNameSorter(const
 
	return strcmp(buf1, _bufcache);	// sort by name
 
}
 

	
 
static void MakeSortedStationList(byte owner)
 
static void GlobalSortStationList()
 
{
 
	SortStruct *firstelement;
 
	Station *st;
 
	const Station *st;
 
	uint32 n = 0;
 
	uint16 *i;
 
	// reset to 0 just to be sure
 

	
 
	// reset #-of stations to 0 because ++ is used for value-assignment
 
	for (i = _num_station_sort; i != endof(_num_station_sort); i++) {*i = 0;}
 

	
 
	FOR_ALL_STATIONS(st) {
 
@@ -90,15 +90,24 @@ static void MakeSortedStationList(byte o
 
		}
 
	}
 

	
 
	// create cumulative station-ownage
 
	// create cumulative station-ownership
 
	// stations 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_station_sort[1]; i != endof(_num_station_sort); i++) {*i += *(i-1);}
 

	
 
	_last_station_idx = 0; // used for "cache"
 
	qsort(_station_sort, n, sizeof(_station_sort[0]), GeneralOwnerSorter); // sort by owner
 

	
 
	// since indexes are messed up after adding/removing a station, mark all lists dirty
 
	memset(_station_sort_dirty, true, sizeof(_station_sort_dirty));
 
	_global_station_sort_dirty = false;
 

	
 
	// sort by owner, then only subsort the requested owner-vehicles
 
	qsort(_station_sort, n, sizeof(_station_sort[0]), GeneralOwnerSorter);
 
	DEBUG(misc, 1) ("Resorting global station list...");
 
}
 

	
 
static void MakeSortedStationList(byte owner)
 
{
 
	SortStruct *firstelement;
 
	uint32 n = 0;
 

	
 
	if (owner == 0) { // first element starts at 0th element and has n elements as described above
 
		firstelement =	&_station_sort[0];
 
@@ -108,9 +117,12 @@ static void MakeSortedStationList(byte o
 
		n =							_num_station_sort[owner] - _num_station_sort[owner-1];
 
	}
 

	
 
	qsort(firstelement, n, sizeof(_station_sort[0]), StationNameSorter);
 
	_last_station_idx = 0; // used for "cache" in namesorting
 
	qsort(firstelement, n, sizeof(_station_sort[0]), StationNameSorter); // sort by name
 

	
 
	DEBUG(misc, 1) ("Resorting Stations list...");
 
	_station_sort_dirty[owner] = false;
 

	
 
	DEBUG(misc, 1) ("Resorting Stations list player %d...", owner+1);
 
}
 

	
 
static void PlayerStationsWndProc(Window *w, WindowEvent *e)
 
@@ -120,8 +132,11 @@ static void PlayerStationsWndProc(Window
 
		uint32 i;
 
		const byte window_number = (byte)w->window_number;
 

	
 
		if (_station_sort_dirty) {
 
			_station_sort_dirty = false;
 
		// resort station window if stations have been added/removed
 
		if (_global_station_sort_dirty)
 
			GlobalSortStationList();
 

	
 
		if (_station_sort_dirty[window_number]) { // resort in case of a station rename.
 
			MakeSortedStationList(window_number);
 
		}
 

	
train_gui.c
Show inline comments
 
@@ -1140,36 +1140,41 @@ void ShowTrainDetailsWindow(Vehicle *v)
 
static SortStruct _train_sort[NUM_NORMAL_VEHICLES];
 
static uint16 _num_train_sort[MAX_PLAYERS];
 

	
 
static void GlobalSortTrainList()
 
{
 
	const Vehicle *v;
 
	uint16 *i;
 
	uint32 n = 0;
 

	
 
	// reset #-of trains to 0 because ++ is used for value-assignment
 
	for (i = _num_train_sort; i != endof(_num_train_sort); i++) {*i = 0;}
 

	
 
	FOR_ALL_VEHICLES(v) {
 
		if(v->type == VEH_Train && v->subtype == 0) {
 
			_train_sort[n].index = v->index;
 
			_train_sort[n++].owner = v->owner;
 
			_num_train_sort[v->owner]++; // add number of trains of player
 
		}
 
	}
 

	
 
	// create cumulative train-ownership
 
	// trains 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_train_sort[1]; i != endof(_num_train_sort); i++) {*i += *(i-1);}
 

	
 
	qsort(_train_sort, n, sizeof(_train_sort[0]), GeneralOwnerSorter); // sort by owner
 

	
 
	// since indexes are messed up after adding/removing a station, mark all lists dirty
 
	memset(_train_sort_dirty, true, sizeof(_train_sort_dirty));
 
	_vehicle_sort_dirty[VEHTRAIN] = false;
 

	
 
	DEBUG(misc, 1) ("Resorting global trains list...");	
 
}
 

	
 
static void MakeSortedTrainList(byte owner)
 
{
 
	SortStruct *firstelement;
 
	Vehicle *v;
 
	uint32 n = 0;
 
	uint16 *i;
 

	
 
	if (_vehicle_sort_dirty[VEHTRAIN]) { // only resort the whole array if vehicles have been added/removed
 
		// reset to 0 just to be sure
 
		for (i = _num_train_sort; i != endof(_num_train_sort); i++) {*i = 0;}
 

	
 
		FOR_ALL_VEHICLES(v) {
 
			if(v->type == VEH_Train && v->subtype == 0) {
 
				_train_sort[n].index = v->index;
 
				_train_sort[n++].owner = v->owner;
 
				_num_train_sort[v->owner]++; // add number of trains of player
 
			}
 
		}
 

	
 
		// create cumulative train-ownage
 
		// trains 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_train_sort[1]; i != endof(_num_train_sort); i++) {*i += *(i-1);}
 

	
 
		// sort by owner, then only subsort the requested owner-vehicles
 
		qsort(_train_sort, n, sizeof(_train_sort[0]), GeneralOwnerSorter);
 

	
 
		_last_vehicle_idx = 0; // used for "cache" in namesorting
 
		_vehicle_sort_dirty[VEHTRAIN] = false;
 
	}
 

	
 
	if (owner == 0) { // first element starts at 0th element and has n elements as described above
 
		firstelement =	&_train_sort[0];
 
@@ -1181,8 +1186,11 @@ static void MakeSortedTrainList(byte own
 

	
 
	_internal_sort_order			= _train_sort_order[owner];
 
	_internal_name_sorter_id	= STR_SV_TRAIN_NAME;
 
	_last_vehicle_idx = 0; // used for "cache" in namesorting
 
	qsort(firstelement, n, sizeof(_train_sort[0]), _vehicle_sorter[_train_sort_type[owner]]);
 

	
 
	_train_sort_dirty[owner] = false;
 

	
 
	DEBUG(misc, 1) ("Resorting Trains list player %d...", owner+1);
 
}
 

	
 
@@ -1196,8 +1204,11 @@ static void PlayerTrainsWndProc(Window *
 
		if (_train_sort_type[window_number] == SORT_BY_UNSORTED) // disable 'Sort By' tooltip on Unsorted sorting criteria
 
			w->disabled_state |= (1 << 2);
 

	
 
		if (_train_sort_dirty[window_number] || _vehicle_sort_dirty[VEHTRAIN]) {
 
			_train_sort_dirty[window_number] = false;
 
		// resort trains window if roadvehicles have been added/removed
 
		if (_vehicle_sort_dirty[VEHTRAIN])
 
			GlobalSortTrainList();
 

	
 
		if (_train_sort_dirty[window_number]) {
 
			MakeSortedTrainList(window_number);
 
			/* reset sorting timeout */
 
			w->custom[0] = DAY_TICKS;
vehicle_gui.c
Show inline comments
 
@@ -6,23 +6,11 @@
 
/* General Vehicle GUI based procedures that are independent of vehicle types */
 
void InitializeVehiclesGuiList()
 
{
 
	bool *i;
 
	for (i = _train_sort_dirty; i != endof(_train_sort_dirty); i++)
 
		*i = true;
 

	
 
	for (i = _aircraft_sort_dirty; i != endof(_aircraft_sort_dirty); i++)
 
		*i = true;
 

	
 
	for (i = _ship_sort_dirty; i != endof(_ship_sort_dirty); i++)
 
		*i = true;
 

	
 
	for (i = _road_sort_dirty; i != endof(_road_sort_dirty); i++)
 
		*i = true;
 

	
 
	for (i = _vehicle_sort_dirty; i != endof(_vehicle_sort_dirty); i++)
 
		*i = true;
 

	
 
	//memset(_train_sort_dirty, true, sizeof(_train_sort_dirty));
 
	memset(_train_sort_dirty, true, sizeof(_train_sort_dirty));
 
	memset(_aircraft_sort_dirty, true, sizeof(_aircraft_sort_dirty));
 
	memset(_ship_sort_dirty, true, sizeof(_ship_sort_dirty));
 
	memset(_road_sort_dirty, true, sizeof(_road_sort_dirty));
 
	memset(_vehicle_sort_dirty, true, sizeof(_vehicle_sort_dirty));
 
}
 

	
 
// draw the vehicle profit button in the vehicle list window.
 
@@ -59,15 +47,15 @@ int CDECL VehicleUnsortedSorter(const vo
 
	return DEREF_VEHICLE((*(const SortStruct*)a).index)->index - DEREF_VEHICLE((*(const SortStruct*)b).index)->index;
 
}
 

	
 
// if the sorting criteria had the same value, sort vehicle by unitnumber
 
#define VEHICLEUNITNUMBERSORTER(r, a, b) {if (r == 0) {r = a->unitnumber - b->unitnumber;}}
 

	
 
int CDECL VehicleNumberSorter(const void *a, const void *b)
 
{
 
	const Vehicle *va = DEREF_VEHICLE((*(const SortStruct*)a).index);
 
	const Vehicle *vb = DEREF_VEHICLE((*(const SortStruct*)b).index);
 
	int r = va->unitnumber - vb->unitnumber;
 

	
 
	if (r == 0) // if the sorting criteria had the same value, sort by unitnumber
 
		r = va->unitnumber - vb->unitnumber;
 

	
 
	return (_internal_sort_order & 1) ? -r : r;
 
}
 

	
 
@@ -97,8 +85,7 @@ int CDECL VehicleNameSorter(const void *
 

	
 
	r =  strcmp(buf1, _bufcache);	// sort by name
 

	
 
	if (r == 0) // if the sorting criteria had the same value, sort by unitnumber
 
		r = va->unitnumber - vb->unitnumber;
 
	VEHICLEUNITNUMBERSORTER(r, va, vb);
 

	
 
	return (_internal_sort_order & 1) ? -r : r;
 
}
 
@@ -109,8 +96,7 @@ int CDECL VehicleAgeSorter(const void *a
 
	const Vehicle *vb = DEREF_VEHICLE((*(const SortStruct*)b).index);
 
	int r = va->age - vb->age;
 

	
 
	if (r == 0) // if the sorting criteria had the same value, sort by unitnumber
 
		r = va->unitnumber - vb->unitnumber;
 
	VEHICLEUNITNUMBERSORTER(r, va, vb);
 

	
 
	return (_internal_sort_order & 1) ? -r : r;
 
}
 
@@ -121,8 +107,7 @@ int CDECL VehicleProfitThisYearSorter(co
 
	const Vehicle *vb = DEREF_VEHICLE((*(const SortStruct*)b).index);
 
	int r = va->profit_this_year - vb->profit_this_year;
 

	
 
	if (r == 0) // if the sorting criteria had the same value, sort by unitnumber
 
		r = va->unitnumber - vb->unitnumber;
 
	VEHICLEUNITNUMBERSORTER(r, va, vb);
 

	
 
	return (_internal_sort_order & 1) ? -r : r;
 
}
 
@@ -133,8 +118,7 @@ int CDECL VehicleProfitLastYearSorter(co
 
	const Vehicle *vb = DEREF_VEHICLE((*(const SortStruct*)b).index);
 
	int r = va->profit_last_year - vb->profit_last_year;
 

	
 
	if (r == 0) // if the sorting criteria had the same value, sort by unitnumber
 
		r = va->unitnumber - vb->unitnumber;
 
	VEHICLEUNITNUMBERSORTER(r, va, vb);
 

	
 
	return (_internal_sort_order & 1) ? -r : r;
 
}
 
@@ -175,8 +159,7 @@ int CDECL VehicleReliabilitySorter(const
 
	const Vehicle *vb = DEREF_VEHICLE((*(const SortStruct*)b).index);
 
	int r = va->reliability - vb->reliability;
 

	
 
	if (r == 0) // if the sorting criteria had the same value, sort by unitnumber
 
		r = va->unitnumber - vb->unitnumber;
 
	VEHICLEUNITNUMBERSORTER(r, va, vb);
 

	
 
	return (_internal_sort_order & 1) ? -r : r;
 
}
 
@@ -187,8 +170,7 @@ int CDECL VehicleMaxSpeedSorter(const vo
 
	const Vehicle *vb = DEREF_VEHICLE((*(const SortStruct*)b).index);
 
	int r = va->max_speed - vb->max_speed;
 

	
 
	if (r == 0) // if the sorting criteria had the same value, sort by unitnumber
 
		r = va->unitnumber - vb->unitnumber;
 
	VEHICLEUNITNUMBERSORTER(r, va, vb);
 

	
 
	return (_internal_sort_order & 1) ? -r : r;
 
}
0 comments (0 inline, 0 general)