(svn r8295) -Cleanup: merged arguments station, order and depot_airport_index for GenerateVehicleSortList() and BuildVehicleList() into one uint16 argument

It turned out that all 3 arguments were the same at all the places those functions are called, so there was no point in having more than one
This commit is contained in:
bjarni 2007-01-21 01:07:15 +00:00
parent 7871ce1879
commit 518c4cdfce
3 changed files with 21 additions and 20 deletions

View File

@ -1624,7 +1624,7 @@ int32 CmdMassStartStopVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2
uint16 id = GB(p1, 0, 16);
uint16 window_type = p2 & VLW_MASK;
engine_count = GenerateVehicleSortList((const Vehicle***)&vl, &engine_list_length, vehicle_type, _current_player, id, id, id, window_type);
engine_count = GenerateVehicleSortList((const Vehicle***)&vl, &engine_list_length, vehicle_type, _current_player, id, window_type);
} else {
/* Get the list of vehicles in the depot */
BuildDepotVehicleList(vehicle_type, tile, &vl, &engine_list_length, &engine_count, NULL, NULL, NULL);
@ -2361,12 +2361,15 @@ void BuildDepotVehicleList(byte type, TileIndex tile, Vehicle ***engine_list, ui
* @param length_of_array informs the length allocated for sort_list. This is not the same as the number of vehicles in the list. Needs to be 0 when sort_list is NULL
* @param type type of vehicle
* @param owner PlayerID of owner to generate a list for
* @param station index of station to generate a list for. INVALID_STATION when not used
* @param order index of oder to generate a list for. INVALID_ORDER when not used
* @param index This parameter got different meanings depending on window_type
VLW_STATION_LIST: index of station to generate a list for
VLW_SHARED_ORDERS: index of order to generate a list for
VLW_STANDARD: not used
VLW_DEPOT_LIST: TileIndex of the depot/hangar to make the list for
* @param window_type tells what kind of window the list is for. Use the VLW flags in vehicle_gui.h
* @return the number of vehicles added to the list
*/
uint GenerateVehicleSortList(const Vehicle ***sort_list, uint16 *length_of_array, byte type, PlayerID owner, StationID station, OrderID order, uint16 depot_airport_index, uint16 window_type)
uint GenerateVehicleSortList(const Vehicle ***sort_list, uint16 *length_of_array, byte type, PlayerID owner, uint16 index, uint16 window_type)
{
const uint subtype = (type != VEH_Aircraft) ? Train_Front : 2;
uint n = 0;
@ -2381,7 +2384,7 @@ uint GenerateVehicleSortList(const Vehicle ***sort_list, uint16 *length_of_array
const Order *order;
FOR_VEHICLE_ORDERS(v, order) {
if (order->type == OT_GOTO_STATION && order->dest == station) {
if (order->type == OT_GOTO_STATION && order->dest == index) {
if (n == *length_of_array) ExtendVehicleListSize(sort_list, length_of_array, 50);
(*sort_list)[n++] = v;
break;
@ -2395,10 +2398,10 @@ uint GenerateVehicleSortList(const Vehicle ***sort_list, uint16 *length_of_array
case VLW_SHARED_ORDERS: {
FOR_ALL_VEHICLES(v) {
/* Find a vehicle with the order in question */
if (v->orders != NULL && v->orders->index == order) break;
if (v->orders != NULL && v->orders->index == index) break;
}
if (v != NULL && v->orders != NULL && v->orders->index == order) {
if (v != NULL && v->orders != NULL && v->orders->index == index) {
/* Only try to make the list if we found a vehicle using the order in question */
for (v = GetFirstVehicleFromSharedList(v); v != NULL; v = v->next_shared) {
if (n == *length_of_array) ExtendVehicleListSize(sort_list, length_of_array, 25);
@ -2429,7 +2432,7 @@ uint GenerateVehicleSortList(const Vehicle ***sort_list, uint16 *length_of_array
const Order *order;
FOR_VEHICLE_ORDERS(v, order) {
if (order->type == OT_GOTO_DEPOT && order->dest == depot_airport_index) {
if (order->type == OT_GOTO_DEPOT && order->dest == index) {
if (n == *length_of_array) ExtendVehicleListSize(sort_list, length_of_array, 25);
(*sort_list)[n++] = v;
break;
@ -2469,7 +2472,7 @@ int32 SendAllVehiclesToDepot(byte type, uint32 flags, bool service, PlayerID own
uint n, i;
uint16 array_length = 0;
n = GenerateVehicleSortList(&sort_list, &array_length, type, owner, id, id, id, vlw_flag);
n = GenerateVehicleSortList(&sort_list, &array_length, type, owner, id, vlw_flag);
/* Send all the vehicles to a depot */
for (i = 0; i < n; i++) {

View File

@ -333,7 +333,7 @@ int CheckTrainStoppedInDepot(const Vehicle *v);
bool VehicleNeedsService(const Vehicle *v);
uint GenerateVehicleSortList(const Vehicle*** sort_list, uint16 *length_of_array, byte type, PlayerID owner, StationID station, OrderID order, uint16 depot_airport_index, uint16 window_type);
uint GenerateVehicleSortList(const Vehicle*** sort_list, uint16 *length_of_array, byte type, PlayerID owner, uint16 index, uint16 window_type);
void BuildDepotVehicleList(byte type, TileIndex tile, Vehicle ***engine_list, uint16 *engine_list_length, uint16 *engine_count, Vehicle ***wagon_list, uint16 *wagon_list_length, uint16 *wagon_count);
int32 SendAllVehiclesToDepot(byte type, uint32 flags, bool service, PlayerID owner, uint16 vlw_flag, uint32 id);
bool IsVehicleInDepot(const Vehicle *v);

View File

@ -138,13 +138,13 @@ void ResortVehicleLists(void)
}
}
static void BuildVehicleList(vehiclelist_d* vl, PlayerID owner, StationID station, OrderID order, uint16 depot_airport_index, uint16 window_type)
static void BuildVehicleList(vehiclelist_d* vl, PlayerID owner, uint16 index, uint16 window_type)
{
if (!(vl->l.flags & VL_REBUILD)) return;
DEBUG(misc, 3, "Building vehicle list for player %d at station %d", owner, station);
DEBUG(misc, 3, "Building vehicle list for player %d at station %d", owner, index);
vl->l.list_length = GenerateVehicleSortList(&vl->sort_list, &vl->length_of_sort_list, vl->vehicle_type, owner, station, order, depot_airport_index, window_type);
vl->l.list_length = GenerateVehicleSortList(&vl->sort_list, &vl->length_of_sort_list, vl->vehicle_type, owner, index, window_type);
vl->l.flags &= ~VL_REBUILD;
vl->l.flags |= VL_RESORT;
@ -1590,11 +1590,9 @@ static void DrawVehicleListWindow(Window *w)
const PlayerID owner = (PlayerID)w->caption_color;
const Player *p = GetPlayer(owner);
const uint16 window_type = w->window_number & VLW_MASK;
const StationID station = (window_type == VLW_STATION_LIST) ? GB(w->window_number, 16, 16) : INVALID_STATION;
const OrderID order = (window_type == VLW_SHARED_ORDERS) ? GB(w->window_number, 16, 16) : INVALID_ORDER;
const uint16 depot_airport_index = (window_type == VLW_DEPOT_LIST) ? GB(w->window_number, 16, 16) : INVALID_STATION;
const uint16 index = GB(w->window_number, 16, 16);
BuildVehicleList(vl, owner, station, order, depot_airport_index, window_type);
BuildVehicleList(vl, owner, index, window_type);
SortVehicleList(vl);
SetVScrollCount(w, vl->l.list_length);
@ -1616,7 +1614,7 @@ static void DrawVehicleListWindow(Window *w)
break;
case VLW_STATION_LIST: /* Station Name */
SetDParam(0, station);
SetDParam(0, index);
SetDParam(1, w->vscroll.count);
break;
@ -1629,9 +1627,9 @@ static void DrawVehicleListWindow(Window *w)
default: NOT_REACHED(); break;
}
if (vl->vehicle_type == VEH_Aircraft) {
SetDParam(1, depot_airport_index); // Airport name
SetDParam(1, index); // Airport name
} else {
SetDParam(1, GetDepot(depot_airport_index)->town_index);
SetDParam(1, GetDepot(index)->town_index);
}
SetDParam(2, w->vscroll.count);
break;