tron@2186: /* $Id$ */ tron@2186: belugas@6451: /** @file depot.h Header files for depots (not hangars) */ belugas@6451: truelight@1313: #ifndef DEPOT_H truelight@1313: #define DEPOT_H truelight@1313: rubidium@8596: #include "direction_type.h" rubidium@9264: #include "depot_type.h" matthijs@5216: #include "oldpool.h" rubidium@6508: #include "road_map.h" rubidium@6508: #include "rail_map.h" rubidium@6508: #include "water_map.h" rubidium@8008: #include "station_map.h" truelight@1313: matthijs@5216: DECLARE_OLD_POOL(Depot, Depot, 3, 8000) truelight@1313: rubidium@7885: struct Depot : PoolItem { rubidium@7885: TileIndex xy; rubidium@7885: TownID town_index; truelight@4346: rubidium@7885: Depot(TileIndex xy = 0) : xy(xy) {} rubidium@7885: ~Depot(); truelight@4352: rubidium@7992: inline bool IsValid() const { return this->xy != 0; } rubidium@7885: }; truelight@4388: rubidium@7885: static inline bool IsValidDepotID(DepotID index) truelight@4388: { rubidium@7885: return index < GetDepotPoolSize() && GetDepot(index)->IsValid(); truelight@4388: } truelight@4388: rubidium@7134: void ShowDepotWindow(TileIndex tile, VehicleType type); bjarni@4638: rubidium@7885: #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()) truelight@1313: #define FOR_ALL_DEPOTS(d) FOR_ALL_DEPOTS_FROM(d, 0) truelight@1313: matthijs@1330: /** smatz@10213: * Check if a tile is a depot and it is a depot of the given type. matthijs@1330: */ smatz@10213: static inline bool IsDepotTypeTile(TileIndex tile, TransportType type) matthijs@1330: { tron@4000: switch (type) { smatz@10213: default: NOT_REACHED(); matthijs@1330: case TRANSPORT_RAIL: smatz@10213: return IsRailDepotTile(tile); tron@1959: matthijs@1330: case TRANSPORT_ROAD: frosch@9059: return IsRoadDepotTile(tile); tron@1959: matthijs@1330: case TRANSPORT_WATER: smatz@10213: return IsShipDepotTile(tile); matthijs@1330: } matthijs@1330: } matthijs@1330: rubidium@8008: /** rubidium@8008: * Is the given tile a tile with a depot on it? rubidium@8008: * @param tile the tile to check rubidium@8008: * @return true if and only if there is a depot on the tile. rubidium@8008: */ rubidium@8008: static inline bool IsDepotTile(TileIndex tile) rubidium@8008: { smatz@10213: return IsRailDepotTile(tile) || IsRoadDepotTile(tile) || IsShipDepotTile(tile) || IsHangarTile(tile); rubidium@8008: } matthijs@1650: celestar@2085: /** tron@4077: * Find out if the slope of the tile is suitable to build a depot of given direction tron@6460: * @param direction The direction in which the depot's exit points 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@6460: static inline bool CanBuildDepotByTileh(DiagDirection direction, Slope tileh) celestar@2085: { KUDr@3900: return ((0x4C >> direction) & tileh) != 0; celestar@2085: } celestar@2085: tron@1977: Depot *GetDepotByTile(TileIndex tile); rubidium@6573: void InitializeDepots(); truelight@1313: bjarni@5255: void DeleteDepotHighlightOfVehicle(const Vehicle *v); bjarni@5255: truelight@1313: #endif /* DEPOT_H */