mirror of https://github.com/OpenTTD/OpenTTD
Codechange: BuildDepotVehicleList through a DepotId instead of a TileIndex.
parent
8610a80721
commit
11fc7f2710
|
@ -714,7 +714,7 @@ struct DepotWindow : Window {
|
||||||
if (this->generate_list) {
|
if (this->generate_list) {
|
||||||
/* Generate the vehicle list
|
/* Generate the vehicle list
|
||||||
* It's ok to use the wagon pointers for non-trains as they will be ignored */
|
* 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;
|
this->generate_list = false;
|
||||||
DepotSortList(&this->vehicle_list);
|
DepotSortList(&this->vehicle_list);
|
||||||
|
|
||||||
|
|
|
@ -668,7 +668,7 @@ CommandCost CmdMassStartStopVehicle(DoCommandFlag flags, TileIndex tile, bool do
|
||||||
} else {
|
} else {
|
||||||
if (!IsDepotTile(tile) || !IsTileOwner(tile, _current_company)) return CMD_ERROR;
|
if (!IsDepotTile(tile) || !IsTileOwner(tile, _current_company)) return CMD_ERROR;
|
||||||
/* Get the list of vehicles in the depot */
|
/* 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) {
|
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;
|
if (!IsDepotTile(tile) || !IsTileOwner(tile, _current_company)) return CMD_ERROR;
|
||||||
|
|
||||||
/* Get the list of vehicles in the depot */
|
/* 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;
|
CommandCost last_error = CMD_ERROR;
|
||||||
bool had_success = false;
|
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;
|
if (!IsDepotTile(tile) || !IsTileOwner(tile, _current_company)) return CMD_ERROR;
|
||||||
|
|
||||||
/* Get the list of vehicles in the depot */
|
/* 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) {
|
for (const Vehicle *v : list) {
|
||||||
/* Ensure that the vehicle completely in the depot */
|
/* Ensure that the vehicle completely in the depot */
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include "vehiclelist.h"
|
#include "vehiclelist.h"
|
||||||
#include "vehiclelist_func.h"
|
#include "vehiclelist_func.h"
|
||||||
#include "group.h"
|
#include "group.h"
|
||||||
|
#include "depot_base.h"
|
||||||
|
|
||||||
#include "safeguards.h"
|
#include "safeguards.h"
|
||||||
|
|
||||||
|
@ -96,19 +97,24 @@ static Vehicle *BuildDepotVehicleListProc(Vehicle *v, void *data)
|
||||||
/**
|
/**
|
||||||
* Generate a list of vehicles inside a depot.
|
* Generate a list of vehicles inside a depot.
|
||||||
* @param type Type of vehicle
|
* @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 engines Pointer to list to add vehicles to
|
||||||
* @param wagons Pointer to list to add wagons to (can be nullptr)
|
* @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.
|
* @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();
|
engines->clear();
|
||||||
if (wagons != nullptr && wagons != engines) wagons->clear();
|
if (wagons != nullptr && wagons != engines) wagons->clear();
|
||||||
|
|
||||||
BuildDepotVehicleListData bdvld{engines, wagons, type, individual_wagons};
|
BuildDepotVehicleListData bdvld{engines, wagons, type, individual_wagons};
|
||||||
|
|
||||||
|
for (TileIndex tile : dep->depot_tiles) {
|
||||||
FindVehicleOnPos(tile, &bdvld, BuildDepotVehicleListProc);
|
FindVehicleOnPos(tile, &bdvld, BuildDepotVehicleListProc);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate a list of vehicles based on window type.
|
* Generate a list of vehicles based on window type.
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
#include "vehicle_type.h"
|
#include "vehicle_type.h"
|
||||||
#include "company_type.h"
|
#include "company_type.h"
|
||||||
|
#include "depot_type.h"
|
||||||
#include "tile_type.h"
|
#include "tile_type.h"
|
||||||
|
|
||||||
/** Vehicle List type flags */
|
/** Vehicle List type flags */
|
||||||
|
@ -54,7 +55,7 @@ struct VehicleListIdentifier {
|
||||||
typedef std::vector<const Vehicle *> VehicleList;
|
typedef std::vector<const Vehicle *> VehicleList;
|
||||||
|
|
||||||
bool GenerateVehicleSortList(VehicleList *list, const VehicleListIdentifier &identifier);
|
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);
|
uint GetUnitNumberDigits(VehicleList &vehicles);
|
||||||
|
|
||||||
#endif /* VEHICLELIST_H */
|
#endif /* VEHICLELIST_H */
|
||||||
|
|
Loading…
Reference in New Issue