depot.h
changeset 4388 c8a66d26e146
parent 4352 6703cd8d39e0
child 4549 106ed18a7675
equal deleted inserted replaced
4387:3d8fe06fb594 4388:c8a66d26e146
    12 #include "variables.h"
    12 #include "variables.h"
    13 
    13 
    14 struct Depot {
    14 struct Depot {
    15 	TileIndex xy;
    15 	TileIndex xy;
    16 	TownID town_index;
    16 	TownID town_index;
    17 	StationID index;
    17 	DepotID index;
    18 };
    18 };
    19 
    19 
    20 extern MemoryPool _depot_pool;
    20 extern MemoryPool _depot_pool;
    21 
    21 
    22 /**
    22 /**
    23  * Get the pointer to the depot with index 'index'
    23  * Get the pointer to the depot with index 'index'
    24  */
    24  */
    25 static inline Depot *GetDepot(uint index)
    25 static inline Depot *GetDepot(DepotID index)
    26 {
    26 {
    27 	return (Depot*)GetItemFromPool(&_depot_pool, index);
    27 	return (Depot*)GetItemFromPool(&_depot_pool, index);
    28 }
    28 }
    29 
    29 
    30 /**
    30 /**
    36 }
    36 }
    37 
    37 
    38 /**
    38 /**
    39  * Check if a depot really exists.
    39  * Check if a depot really exists.
    40  */
    40  */
    41 static inline bool IsValidDepot(const Depot* depot)
    41 static inline bool IsValidDepot(const Depot *depot)
    42 {
    42 {
    43 	return depot->xy != 0;
    43 	return depot != NULL && depot->xy != 0;
    44 }
    44 }
    45 
    45 
    46 static inline bool IsValidDepotID(uint index)
    46 static inline bool IsValidDepotID(uint index)
    47 {
    47 {
    48 	return index < GetDepotPoolSize() && IsValidDepot(GetDepot(index));
    48 	return index < GetDepotPoolSize() && IsValidDepot(GetDepot(index));
       
    49 }
       
    50 
       
    51 void DestroyDepot(Depot *depot);
       
    52 
       
    53 static inline void DeleteDepot(Depot *depot)
       
    54 {
       
    55 	DestroyDepot(depot);
       
    56 	depot->xy = 0;
    49 }
    57 }
    50 
    58 
    51 #define FOR_ALL_DEPOTS_FROM(d, start) for (d = GetDepot(start); d != NULL; d = (d->index + 1 < GetDepotPoolSize()) ? GetDepot(d->index + 1) : NULL) if (IsValidDepot(d))
    59 #define FOR_ALL_DEPOTS_FROM(d, start) for (d = GetDepot(start); d != NULL; d = (d->index + 1 < GetDepotPoolSize()) ? GetDepot(d->index + 1) : NULL) if (IsValidDepot(d))
    52 #define FOR_ALL_DEPOTS(d) FOR_ALL_DEPOTS_FROM(d, 0)
    60 #define FOR_ALL_DEPOTS(d) FOR_ALL_DEPOTS_FROM(d, 0)
    53 
    61 
    54 #define MIN_SERVINT_PERCENT  5
    62 #define MIN_SERVINT_PERCENT  5
    55 #define MAX_SERVINT_PERCENT 90
    63 #define MAX_SERVINT_PERCENT 90
    56 #define MIN_SERVINT_DAYS    30
    64 #define MIN_SERVINT_DAYS    30
    57 #define MAX_SERVINT_DAYS   800
    65 #define MAX_SERVINT_DAYS   800
    58 
    66 
    59 /** Get the service interval domain.
    67 /**
       
    68  * Get the service interval domain.
    60  * Get the new proposed service interval for the vehicle is indeed, clamped
    69  * Get the new proposed service interval for the vehicle is indeed, clamped
    61  * within the given bounds. @see MIN_SERVINT_PERCENT ,etc.
    70  * within the given bounds. @see MIN_SERVINT_PERCENT ,etc.
    62  * @param index proposed service interval
    71  * @param index proposed service interval
    63  */
    72  */
    64 static inline Date GetServiceIntervalClamped(uint index)
    73 static inline Date GetServiceIntervalClamped(uint index)
   106 static inline bool CanBuildDepotByTileh(uint32 direction, Slope tileh)
   115 static inline bool CanBuildDepotByTileh(uint32 direction, Slope tileh)
   107 {
   116 {
   108 	return ((0x4C >> direction) & tileh) != 0;
   117 	return ((0x4C >> direction) & tileh) != 0;
   109 }
   118 }
   110 
   119 
   111 
       
   112 Depot *GetDepotByTile(TileIndex tile);
   120 Depot *GetDepotByTile(TileIndex tile);
   113 void InitializeDepots(void);
   121 void InitializeDepots(void);
   114 Depot *AllocateDepot(void);
   122 Depot *AllocateDepot(void);
   115 void DoDeleteDepot(TileIndex tile);
       
   116 
   123 
   117 #endif /* DEPOT_H */
   124 #endif /* DEPOT_H */