tron@2186: /* $Id$ */ tron@2186: truelight@1313: #ifndef DEPOT_H truelight@1313: #define DEPOT_H truelight@1313: celestar@2085: /** @file depot.h Header files for depots (not hangars) rubidium@4549: * @see depot.c */ celestar@2085: tron@3147: #include "direction.h" truelight@1313: #include "pool.h" matthijs@1330: #include "tile.h" tron@2153: #include "variables.h" truelight@1313: truelight@1313: struct Depot { truelight@1313: TileIndex xy; Darkvater@3346: TownID town_index; truelight@4388: DepotID index; truelight@1313: }; truelight@1313: truelight@1313: extern MemoryPool _depot_pool; truelight@1313: truelight@1313: /** truelight@1313: * Get the pointer to the depot with index 'index' truelight@1313: */ truelight@4388: static inline Depot *GetDepot(DepotID index) truelight@1313: { truelight@1313: return (Depot*)GetItemFromPool(&_depot_pool, index); truelight@1313: } truelight@1313: truelight@1313: /** truelight@1313: * Get the current size of the DepotPool truelight@1313: */ truelight@1313: static inline uint16 GetDepotPoolSize(void) truelight@1313: { truelight@1313: return _depot_pool.total_items; truelight@1313: } truelight@1313: truelight@4346: /** truelight@4346: * Check if a depot really exists. truelight@4346: */ truelight@4388: static inline bool IsValidDepot(const Depot *depot) truelight@4346: { truelight@4388: return depot != NULL && depot->xy != 0; truelight@4346: } truelight@4346: truelight@4352: static inline bool IsValidDepotID(uint index) truelight@4352: { truelight@4352: return index < GetDepotPoolSize() && IsValidDepot(GetDepot(index)); truelight@4352: } truelight@4352: truelight@4388: void DestroyDepot(Depot *depot); truelight@4388: truelight@4388: static inline void DeleteDepot(Depot *depot) truelight@4388: { truelight@4388: DestroyDepot(depot); truelight@4388: depot->xy = 0; truelight@4388: } truelight@4388: bjarni@4638: void ShowDepotWindow(TileIndex tile, byte type); bjarni@4638: truelight@4346: #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)) truelight@1313: #define FOR_ALL_DEPOTS(d) FOR_ALL_DEPOTS_FROM(d, 0) truelight@1313: truelight@1313: #define MIN_SERVINT_PERCENT 5 truelight@1313: #define MAX_SERVINT_PERCENT 90 truelight@1313: #define MIN_SERVINT_DAYS 30 truelight@1313: #define MAX_SERVINT_DAYS 800 truelight@1313: truelight@4388: /** truelight@4388: * Get the service interval domain. Darkvater@1790: * Get the new proposed service interval for the vehicle is indeed, clamped Darkvater@1790: * within the given bounds. @see MIN_SERVINT_PERCENT ,etc. Darkvater@1790: * @param index proposed service interval Darkvater@1790: */ rubidium@4297: static inline Date GetServiceIntervalClamped(uint index) Darkvater@1790: { Darkvater@1790: return (_patches.servint_ispercent) ? clamp(index, MIN_SERVINT_PERCENT, MAX_SERVINT_PERCENT) : clamp(index, MIN_SERVINT_DAYS, MAX_SERVINT_DAYS); Darkvater@1790: } Darkvater@1790: matthijs@1330: /** matthijs@1330: * Check if a tile is a depot of the given type. matthijs@1330: */ matthijs@1330: static inline bool IsTileDepotType(TileIndex tile, TransportType type) matthijs@1330: { tron@4000: switch (type) { matthijs@1330: case TRANSPORT_RAIL: tron@2049: return IsTileType(tile, MP_RAILWAY) && (_m[tile].m5 & 0xFC) == 0xC0; tron@1959: matthijs@1330: case TRANSPORT_ROAD: tron@2049: return IsTileType(tile, MP_STREET) && (_m[tile].m5 & 0xF0) == 0x20; tron@1959: matthijs@1330: case TRANSPORT_WATER: tron@2049: return IsTileType(tile, MP_WATER) && (_m[tile].m5 & ~3) == 0x80; tron@1959: matthijs@1330: default: matthijs@1330: assert(0); matthijs@1330: return false; matthijs@1330: } matthijs@1330: } matthijs@1330: matthijs@1650: celestar@2085: /** tron@4077: * Find out if the slope of the tile is suitable to build a depot of given direction tron@4077: * @param direction The direction in which the depot's exit points. Starts with 0 as NE and goes Clockwise tron@4077: * @param tileh The slope of the tile in question tron@4077: * @return true if the construction is possible celestar@2085: tron@4077: * This is checked by the ugly 0x4C >> direction magic, which does the following: tron@4077: * 0x4C is 0100 1100 and tileh has only bits 0..3 set (steep tiles are ruled out) tron@4077: * So: for direction (only the significant bits are shown)
tron@4077: * 00 (exit towards NE) we need either bit 2 or 3 set in tileh: 0x4C >> 0 = 1100
tron@4077: * 01 (exit towards SE) we need either bit 1 or 2 set in tileh: 0x4C >> 1 = 0110
tron@4077: * 02 (exit towards SW) we need either bit 0 or 1 set in tileh: 0x4C >> 2 = 0011
tron@4077: * 03 (exit towards NW) we need either bit 0 or 4 set in tileh: 0x4C >> 3 = 1001
tron@4077: * So ((0x4C >> direction) & tileh) determines whether the depot can be built on the current tileh tron@4077: */ tron@3636: static inline bool CanBuildDepotByTileh(uint32 direction, Slope tileh) celestar@2085: { KUDr@3900: return ((0x4C >> direction) & tileh) != 0; celestar@2085: } celestar@2085: tron@1977: Depot *GetDepotByTile(TileIndex tile); truelight@4347: void InitializeDepots(void); truelight@1313: Depot *AllocateDepot(void); truelight@1313: truelight@1313: #endif /* DEPOT_H */