1
0
Fork 0

Change: BuildDepotVehicleList through a DepotId instead of a TileIndex.

pull/8480/head
J0anJosep 2023-04-22 13:01:37 +02:00
parent c405a59bbc
commit cec541ac2c
4 changed files with 18 additions and 11 deletions

View File

@ -714,7 +714,7 @@ struct DepotWindow : Window {
if (this->generate_list) {
/* Generate the vehicle list
* It's ok to use the wagon pointers for non-trains as they will be ignored */
BuildDepotVehicleList(this->type, Depot::Get(this->window_number)->xy, &this->vehicle_list, &this->wagon_list);
BuildDepotVehicleList(this->type, this->window_number, &this->vehicle_list, &this->wagon_list);
this->generate_list = false;
DepotSortList(&this->vehicle_list);

View File

@ -668,7 +668,7 @@ CommandCost CmdMassStartStopVehicle(DoCommandFlag flags, TileIndex tile, bool do
} else {
if (!IsDepotTile(tile) || !IsTileOwner(tile, _current_company)) return CMD_ERROR;
/* Get the list of vehicles in the depot */
BuildDepotVehicleList(vli.vtype, tile, &list, nullptr);
BuildDepotVehicleList(vli.vtype, GetDepotIndex(tile), &list, nullptr);
}
for (const Vehicle *v : list) {
@ -700,7 +700,7 @@ CommandCost CmdDepotSellAllVehicles(DoCommandFlag flags, TileIndex tile, Vehicle
if (!IsDepotTile(tile) || !IsTileOwner(tile, _current_company)) return CMD_ERROR;
/* Get the list of vehicles in the depot */
BuildDepotVehicleList(vehicle_type, tile, &list, &list);
BuildDepotVehicleList(vehicle_type, GetDepotIndex(tile), &list, &list);
CommandCost last_error = CMD_ERROR;
bool had_success = false;
@ -733,7 +733,7 @@ CommandCost CmdDepotMassAutoReplace(DoCommandFlag flags, TileIndex tile, Vehicle
if (!IsDepotTile(tile) || !IsTileOwner(tile, _current_company)) return CMD_ERROR;
/* Get the list of vehicles in the depot */
BuildDepotVehicleList(vehicle_type, tile, &list, &list, true);
BuildDepotVehicleList(vehicle_type, GetDepotIndex(tile), &list, &list, true);
for (const Vehicle *v : list) {
/* Ensure that the vehicle completely in the depot */

View File

@ -13,6 +13,7 @@
#include "vehiclelist.h"
#include "vehiclelist_func.h"
#include "group.h"
#include "depot_base.h"
#include "safeguards.h"
@ -96,18 +97,23 @@ static Vehicle *BuildDepotVehicleListProc(Vehicle *v, void *data)
/**
* Generate a list of vehicles inside a depot.
* @param type Type of vehicle
* @param tile The tile the depot is located on
* @param depot_id The id of the depot
* @param engines Pointer to list to add vehicles to
* @param wagons Pointer to list to add wagons to (can be nullptr)
* @param individual_wagons If true add every wagon to \a wagons which is not attached to an engine. If false only add the first wagon of every row.
*/
void BuildDepotVehicleList(VehicleType type, TileIndex tile, VehicleList *engines, VehicleList *wagons, bool individual_wagons)
void BuildDepotVehicleList(VehicleType type, DepotID depot_id, VehicleList *engines, VehicleList *wagons, bool individual_wagons)
{
assert(Depot::IsValidID(depot_id));
Depot *dep = Depot::Get(depot_id);
engines->clear();
if (wagons != nullptr && wagons != engines) wagons->clear();
BuildDepotVehicleListData bdvld{engines, wagons, type, individual_wagons};
for (TileIndex tile : dep->depot_tiles) {
FindVehicleOnPos(tile, &bdvld, BuildDepotVehicleListProc);
}
}
/**

View File

@ -12,6 +12,7 @@
#include "vehicle_type.h"
#include "company_type.h"
#include "depot_type.h"
#include "tile_type.h"
/** Vehicle List type flags */
@ -54,7 +55,7 @@ struct VehicleListIdentifier {
typedef std::vector<const Vehicle *> VehicleList;
bool GenerateVehicleSortList(VehicleList *list, const VehicleListIdentifier &identifier);
void BuildDepotVehicleList(VehicleType type, TileIndex tile, VehicleList *engine_list, VehicleList *wagon_list, bool individual_wagons = false);
void BuildDepotVehicleList(VehicleType type, DepotID depot_id, VehicleList *engine_list, VehicleList *wagon_list, bool individual_wagons = false);
uint GetUnitNumberDigits(VehicleList &vehicles);
#endif /* VEHICLELIST_H */