1 /* $Id$ */ |
|
2 |
|
3 /** @file depot.h Header files for depots (not hangars) */ |
|
4 |
|
5 #ifndef DEPOT_H |
|
6 #define DEPOT_H |
|
7 |
|
8 #include "direction_type.h" |
|
9 #include "depot_type.h" |
|
10 #include "oldpool.h" |
|
11 #include "road_map.h" |
|
12 #include "rail_map.h" |
|
13 #include "water_map.h" |
|
14 #include "station_map.h" |
|
15 |
|
16 DECLARE_OLD_POOL(Depot, Depot, 3, 8000) |
|
17 |
|
18 struct Depot : PoolItem<Depot, DepotID, &_Depot_pool> { |
|
19 TileIndex xy; |
|
20 TownID town_index; |
|
21 |
|
22 Depot(TileIndex xy = 0) : xy(xy) {} |
|
23 ~Depot(); |
|
24 |
|
25 inline bool IsValid() const { return this->xy != 0; } |
|
26 }; |
|
27 |
|
28 static inline bool IsValidDepotID(DepotID index) |
|
29 { |
|
30 return index < GetDepotPoolSize() && GetDepot(index)->IsValid(); |
|
31 } |
|
32 |
|
33 void ShowDepotWindow(TileIndex tile, VehicleType type); |
|
34 |
|
35 #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()) |
|
36 #define FOR_ALL_DEPOTS(d) FOR_ALL_DEPOTS_FROM(d, 0) |
|
37 |
|
38 /** |
|
39 * Check if a tile is a depot of the given type. |
|
40 */ |
|
41 static inline bool IsTileDepotType(TileIndex tile, TransportType type) |
|
42 { |
|
43 switch (type) { |
|
44 case TRANSPORT_RAIL: |
|
45 return IsTileType(tile, MP_RAILWAY) && GetRailTileType(tile) == RAIL_TILE_DEPOT; |
|
46 |
|
47 case TRANSPORT_ROAD: |
|
48 return IsRoadDepotTile(tile); |
|
49 |
|
50 case TRANSPORT_WATER: |
|
51 return IsTileType(tile, MP_WATER) && GetWaterTileType(tile) == WATER_TILE_DEPOT; |
|
52 |
|
53 default: |
|
54 NOT_REACHED(); |
|
55 return false; |
|
56 } |
|
57 } |
|
58 |
|
59 /** |
|
60 * Is the given tile a tile with a depot on it? |
|
61 * @param tile the tile to check |
|
62 * @return true if and only if there is a depot on the tile. |
|
63 */ |
|
64 static inline bool IsDepotTile(TileIndex tile) |
|
65 { |
|
66 switch (GetTileType(tile)) { |
|
67 case MP_ROAD: return IsRoadDepot(tile); |
|
68 case MP_WATER: return GetWaterTileType(tile) == WATER_TILE_DEPOT; |
|
69 case MP_RAILWAY: return GetRailTileType(tile) == RAIL_TILE_DEPOT; |
|
70 case MP_STATION: return IsHangar(tile); |
|
71 default: return false; |
|
72 } |
|
73 } |
|
74 |
|
75 /** |
|
76 * Find out if the slope of the tile is suitable to build a depot of given direction |
|
77 * @param direction The direction in which the depot's exit points |
|
78 * @param tileh The slope of the tile in question |
|
79 * @return true if the construction is possible |
|
80 |
|
81 * This is checked by the ugly 0x4C >> direction magic, which does the following: |
|
82 * 0x4C is 0100 1100 and tileh has only bits 0..3 set (steep tiles are ruled out) |
|
83 * So: for direction (only the significant bits are shown)<p> |
|
84 * 00 (exit towards NE) we need either bit 2 or 3 set in tileh: 0x4C >> 0 = 1100<p> |
|
85 * 01 (exit towards SE) we need either bit 1 or 2 set in tileh: 0x4C >> 1 = 0110<p> |
|
86 * 02 (exit towards SW) we need either bit 0 or 1 set in tileh: 0x4C >> 2 = 0011<p> |
|
87 * 03 (exit towards NW) we need either bit 0 or 4 set in tileh: 0x4C >> 3 = 1001<p> |
|
88 * So ((0x4C >> direction) & tileh) determines whether the depot can be built on the current tileh |
|
89 */ |
|
90 static inline bool CanBuildDepotByTileh(DiagDirection direction, Slope tileh) |
|
91 { |
|
92 return ((0x4C >> direction) & tileh) != 0; |
|
93 } |
|
94 |
|
95 Depot *GetDepotByTile(TileIndex tile); |
|
96 void InitializeDepots(); |
|
97 |
|
98 void DeleteDepotHighlightOfVehicle(const Vehicle *v); |
|
99 |
|
100 #endif /* DEPOT_H */ |
|