OpenTTD Source  20240919-master-gdf0233f4c2
depot.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6  */
7 
10 #include "stdafx.h"
11 #include "depot_base.h"
12 #include "order_backup.h"
13 #include "order_func.h"
14 #include "window_func.h"
15 #include "core/pool_func.hpp"
16 #include "vehicle_gui.h"
17 #include "vehiclelist.h"
18 
19 #include "safeguards.h"
20 
22 DepotPool _depot_pool("Depot");
24 
25 
29 {
30  if (CleaningPool()) return;
31 
32  if (!IsDepotTile(this->xy) || GetDepotIndex(this->xy) != this->index) {
33  /* It can happen there is no depot here anymore (TTO/TTD savegames) */
34  return;
35  }
36 
37  /* Clear the order backup. */
38  OrderBackup::Reset(this->xy, false);
39 
40  /* Clear the depot from all order-lists */
41  RemoveOrderFromAllVehicles(OT_GOTO_DEPOT, this->index);
42 
43  /* Delete the depot-window */
45 
46  /* Delete the depot list */
47  VehicleType vt = GetDepotVehicleType(this->xy);
48  CloseWindowById(GetWindowClassForVehicleType(vt), VehicleListIdentifier(VL_DEPOT_LIST, vt, GetTileOwner(this->xy), this->index).Pack());
49 }
vehicle_gui.h
VehicleListIdentifier
The information about a vehicle list.
Definition: vehiclelist.h:28
CloseWindowById
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
Definition: window.cpp:1140
vehiclelist.h
depot_base.h
safeguards.h
GetTileOwner
Owner GetTileOwner(Tile tile)
Returns the owner of a tile.
Definition: tile_map.h:178
IsDepotTile
bool IsDepotTile(Tile tile)
Is the given tile a tile with a depot on it?
Definition: depot_map.h:41
stdafx.h
GetDepotIndex
DepotID GetDepotIndex(Tile t)
Get the index of which depot is attached to the tile.
Definition: depot_map.h:52
OrderBackup::Reset
static void Reset(TileIndex tile=INVALID_TILE, bool from_gui=true)
Reset the OrderBackups from GUI/game logic.
Definition: order_backup.cpp:187
GetDepotVehicleType
VehicleType GetDepotVehicleType(Tile t)
Get the type of vehicles that can use a depot.
Definition: depot_map.h:65
Pool
Base class for all pools.
Definition: pool_type.hpp:80
RemoveOrderFromAllVehicles
void RemoveOrderFromAllVehicles(OrderType type, DestinationID destination, bool hangar)
Removes an order from all vehicles.
Definition: order_cmd.cpp:1787
WC_VEHICLE_DEPOT
@ WC_VEHICLE_DEPOT
Depot view; Window numbers:
Definition: window_type.h:351
_depot_pool
DepotPool _depot_pool("Depot")
All our depots tucked away in a pool.
INSTANTIATE_POOL_METHODS
#define INSTANTIATE_POOL_METHODS(name)
Force instantiation of pool methods so we don't get linker errors.
Definition: pool_func.hpp:237
window_func.h
Depot
Definition: depot_base.h:20
VehicleType
VehicleType
Available vehicle types.
Definition: vehicle_type.h:21
pool_func.hpp
order_backup.h
order_func.h
GetWindowClassForVehicleType
WindowClass GetWindowClassForVehicleType(VehicleType vt)
Get WindowClass for vehicle list of given vehicle type.
Definition: vehicle_gui.h:97