truelight@1313: #ifndef DEPOT_H truelight@1313: #define DEPOT_H truelight@1313: truelight@1313: #include "pool.h" matthijs@1330: #include "tile.h" truelight@1313: truelight@1313: struct Depot { truelight@1313: TileIndex xy; truelight@1313: uint16 town_index; truelight@1313: uint16 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@1313: static inline Depot *GetDepot(uint 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: tron@1718: static inline bool IsDepotIndex(uint index) tron@1718: { tron@1718: return index < GetDepotPoolSize(); tron@1718: } tron@1718: truelight@1313: #define FOR_ALL_DEPOTS_FROM(d, start) for (d = GetDepot(start); d != NULL; d = (d->index + 1 < GetDepotPoolSize()) ? GetDepot(d->index + 1) : NULL) 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: Darkvater@1790: /** 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: */ Darkvater@1790: static inline uint16 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: truelight@1313: VARDEF TileIndex _last_built_train_depot_tile; truelight@1313: VARDEF TileIndex _last_built_road_depot_tile; truelight@1313: VARDEF TileIndex _last_built_aircraft_depot_tile; truelight@1313: VARDEF TileIndex _last_built_ship_depot_tile; truelight@1313: matthijs@1330: /** matthijs@1330: * Check if a depot really exists. matthijs@1330: */ tron@1718: static inline bool IsValidDepot(const Depot* depot) matthijs@1330: { matthijs@1330: return depot->xy != 0; /* XXX: Replace by INVALID_TILE someday */ matthijs@1330: } matthijs@1330: 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: { matthijs@1330: switch(type) matthijs@1330: { matthijs@1330: case TRANSPORT_RAIL: matthijs@1330: return IsTileType(tile, MP_RAILWAY) && (_map5[tile] & 0xFC) == 0xC0; matthijs@1330: break; matthijs@1330: case TRANSPORT_ROAD: matthijs@1330: return IsTileType(tile, MP_STREET) && (_map5[tile] & 0xF0) == 0x20; matthijs@1330: break; matthijs@1330: case TRANSPORT_WATER: matthijs@1330: return IsTileType(tile, MP_WATER) && (_map5[tile] & ~3) == 0x80; matthijs@1330: break; matthijs@1330: default: matthijs@1330: assert(0); matthijs@1330: return false; matthijs@1330: } matthijs@1330: } matthijs@1330: matthijs@1650: /** matthijs@1650: * Returns the direction the exit of the depot on the given tile is facing. matthijs@1650: */ matthijs@1942: static inline DiagDirection GetDepotDirection(TileIndex tile, TransportType type) matthijs@1650: { matthijs@1650: assert(IsTileDepotType(tile, type)); matthijs@1650: matthijs@1650: switch (type) matthijs@1650: { matthijs@1650: case TRANSPORT_RAIL: matthijs@1650: case TRANSPORT_ROAD: matthijs@1650: /* Rail and road store a diagonal direction in bits 0 and 1 */ matthijs@1650: return _map5[tile] & 3; matthijs@1650: case TRANSPORT_WATER: matthijs@1650: /* Water is stubborn, it stores the directions in a different order. */ matthijs@1650: switch (_map5[tile] & 3) { matthijs@1942: case 0: return DIAGDIR_NE; matthijs@1942: case 1: return DIAGDIR_SW; matthijs@1942: case 2: return DIAGDIR_NW; matthijs@1942: case 3: return DIAGDIR_SE; matthijs@1650: } matthijs@1650: default: matthijs@1942: return INVALID_DIAGDIR; /* Not reached */ matthijs@1650: } matthijs@1650: } matthijs@1650: truelight@1313: Depot *GetDepotByTile(uint tile); truelight@1313: void InitializeDepot(void); truelight@1313: Depot *AllocateDepot(void); truelight@1313: void DoDeleteDepot(uint tile); truelight@1313: truelight@1313: #endif /* DEPOT_H */