src/depot.h
branchnoai
changeset 9694 e72987579514
parent 9624 b71483f2330f
child 6868 7eb395287b3d
equal deleted inserted replaced
9693:31fcaa5375a1 9694:e72987579514
    11 #include "variables.h"
    11 #include "variables.h"
    12 #include "road_map.h"
    12 #include "road_map.h"
    13 #include "rail_map.h"
    13 #include "rail_map.h"
    14 #include "water_map.h"
    14 #include "water_map.h"
    15 
    15 
    16 struct Depot {
    16 struct Depot;
       
    17 DECLARE_OLD_POOL(Depot, Depot, 3, 8000)
       
    18 
       
    19 struct Depot : PoolItem<Depot, DepotID, &_Depot_pool> {
    17 	TileIndex xy;
    20 	TileIndex xy;
    18 	TownID town_index;
    21 	TownID town_index;
    19 	DepotID index;
    22 
       
    23 	Depot(TileIndex xy = 0) : xy(xy) {}
       
    24 	~Depot();
       
    25 
       
    26 	bool IsValid() const { return this->xy != 0; }
    20 };
    27 };
    21 
    28 
    22 DECLARE_OLD_POOL(Depot, Depot, 3, 8000)
    29 static inline bool IsValidDepotID(DepotID index)
    23 
       
    24 /**
       
    25  * Check if a depot really exists.
       
    26  */
       
    27 static inline bool IsValidDepot(const Depot *depot)
       
    28 {
    30 {
    29 	return depot != NULL && depot->xy != 0;
    31 	return index < GetDepotPoolSize() && GetDepot(index)->IsValid();
    30 }
       
    31 
       
    32 static inline bool IsValidDepotID(uint index)
       
    33 {
       
    34 	return index < GetDepotPoolSize() && IsValidDepot(GetDepot(index));
       
    35 }
       
    36 
       
    37 void DestroyDepot(Depot *depot);
       
    38 
       
    39 static inline void DeleteDepot(Depot *depot)
       
    40 {
       
    41 	DestroyDepot(depot);
       
    42 	depot->xy = 0;
       
    43 }
    32 }
    44 
    33 
    45 void ShowDepotWindow(TileIndex tile, VehicleType type);
    34 void ShowDepotWindow(TileIndex tile, VehicleType type);
    46 
    35 
    47 #define FOR_ALL_DEPOTS_FROM(d, start) for (d = GetDepot(start); d != NULL; d = (d->index + 1U < GetDepotPoolSize()) ? GetDepot(d->index + 1U) : NULL) if (IsValidDepot(d))
    36 #define FOR_ALL_DEPOTS_FROM(d, start) for (d = GetDepot(start); d != NULL; d = (d->index + 1U < GetDepotPoolSize()) ? GetDepot(d->index + 1U) : NULL) if (d->IsValid())
    48 #define FOR_ALL_DEPOTS(d) FOR_ALL_DEPOTS_FROM(d, 0)
    37 #define FOR_ALL_DEPOTS(d) FOR_ALL_DEPOTS_FROM(d, 0)
    49 
    38 
    50 #define MIN_SERVINT_PERCENT  5
    39 #define MIN_SERVINT_PERCENT  5
    51 #define MAX_SERVINT_PERCENT 90
    40 #define MAX_SERVINT_PERCENT 90
    52 #define MIN_SERVINT_DAYS    30
    41 #define MIN_SERVINT_DAYS    30
    72 	switch (type) {
    61 	switch (type) {
    73 		case TRANSPORT_RAIL:
    62 		case TRANSPORT_RAIL:
    74 			return IsTileType(tile, MP_RAILWAY) && GetRailTileType(tile)  == RAIL_TILE_DEPOT;
    63 			return IsTileType(tile, MP_RAILWAY) && GetRailTileType(tile)  == RAIL_TILE_DEPOT;
    75 
    64 
    76 		case TRANSPORT_ROAD:
    65 		case TRANSPORT_ROAD:
    77 			return IsTileType(tile, MP_STREET)  && GetRoadTileType(tile)  == ROAD_TILE_DEPOT;
    66 			return IsTileType(tile, MP_ROAD)  && GetRoadTileType(tile)  == ROAD_TILE_DEPOT;
    78 
    67 
    79 		case TRANSPORT_WATER:
    68 		case TRANSPORT_WATER:
    80 			return IsTileType(tile, MP_WATER)   && GetWaterTileType(tile) == WATER_TILE_DEPOT;
    69 			return IsTileType(tile, MP_WATER)   && GetWaterTileType(tile) == WATER_TILE_DEPOT;
    81 
    70 
    82 		default:
    71 		default:
   106 	return ((0x4C >> direction) & tileh) != 0;
    95 	return ((0x4C >> direction) & tileh) != 0;
   107 }
    96 }
   108 
    97 
   109 Depot *GetDepotByTile(TileIndex tile);
    98 Depot *GetDepotByTile(TileIndex tile);
   110 void InitializeDepots();
    99 void InitializeDepots();
   111 Depot *AllocateDepot();
       
   112 
   100 
   113 void DeleteDepotHighlightOfVehicle(const Vehicle *v);
   101 void DeleteDepotHighlightOfVehicle(const Vehicle *v);
   114 
   102 
   115 #endif /* DEPOT_H */
   103 #endif /* DEPOT_H */