2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2007-02-23 18:55:07 +00:00
|
|
|
/** @file depot.h Header files for depots (not hangars) */
|
|
|
|
|
2005-02-06 10:18:47 +00:00
|
|
|
#ifndef DEPOT_H
|
|
|
|
#define DEPOT_H
|
|
|
|
|
2007-12-18 19:52:14 +00:00
|
|
|
#include "direction_type.h"
|
2006-12-03 17:27:43 +00:00
|
|
|
#include "oldpool.h"
|
2007-03-01 13:35:40 +00:00
|
|
|
#include "road_map.h"
|
|
|
|
#include "rail_map.h"
|
|
|
|
#include "water_map.h"
|
2007-08-31 20:52:38 +00:00
|
|
|
#include "station_map.h"
|
2005-02-06 10:18:47 +00:00
|
|
|
|
2007-08-02 22:33:53 +00:00
|
|
|
struct Depot;
|
2006-12-03 17:27:43 +00:00
|
|
|
DECLARE_OLD_POOL(Depot, Depot, 3, 8000)
|
2005-02-06 10:18:47 +00:00
|
|
|
|
2007-08-02 22:33:53 +00:00
|
|
|
struct Depot : PoolItem<Depot, DepotID, &_Depot_pool> {
|
|
|
|
TileIndex xy;
|
|
|
|
TownID town_index;
|
2006-08-22 15:33:35 +00:00
|
|
|
|
2007-08-02 22:33:53 +00:00
|
|
|
Depot(TileIndex xy = 0) : xy(xy) {}
|
|
|
|
~Depot();
|
2006-08-22 18:15:17 +00:00
|
|
|
|
2007-08-30 20:40:33 +00:00
|
|
|
inline bool IsValid() const { return this->xy != 0; }
|
2007-08-02 22:33:53 +00:00
|
|
|
};
|
2006-08-26 14:44:55 +00:00
|
|
|
|
2007-08-02 22:33:53 +00:00
|
|
|
static inline bool IsValidDepotID(DepotID index)
|
2006-08-26 14:44:55 +00:00
|
|
|
{
|
2007-08-02 22:33:53 +00:00
|
|
|
return index < GetDepotPoolSize() && GetDepot(index)->IsValid();
|
2006-08-26 14:44:55 +00:00
|
|
|
}
|
|
|
|
|
2007-05-18 17:31:41 +00:00
|
|
|
void ShowDepotWindow(TileIndex tile, VehicleType type);
|
2006-09-26 16:47:51 +00:00
|
|
|
|
2007-08-02 22:33:53 +00:00
|
|
|
#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())
|
2005-02-06 10:18:47 +00:00
|
|
|
#define FOR_ALL_DEPOTS(d) FOR_ALL_DEPOTS_FROM(d, 0)
|
|
|
|
|
2005-02-06 22:36:08 +00:00
|
|
|
/**
|
|
|
|
* Check if a tile is a depot of the given type.
|
|
|
|
*/
|
|
|
|
static inline bool IsTileDepotType(TileIndex tile, TransportType type)
|
|
|
|
{
|
2006-06-10 08:37:41 +00:00
|
|
|
switch (type) {
|
2005-02-06 22:36:08 +00:00
|
|
|
case TRANSPORT_RAIL:
|
2007-03-01 13:35:40 +00:00
|
|
|
return IsTileType(tile, MP_RAILWAY) && GetRailTileType(tile) == RAIL_TILE_DEPOT;
|
2005-06-20 20:09:46 +00:00
|
|
|
|
2005-02-06 22:36:08 +00:00
|
|
|
case TRANSPORT_ROAD:
|
2007-08-31 20:52:38 +00:00
|
|
|
return IsTileType(tile, MP_ROAD) && GetRoadTileType(tile) == ROAD_TILE_DEPOT;
|
2005-06-20 20:09:46 +00:00
|
|
|
|
2005-02-06 22:36:08 +00:00
|
|
|
case TRANSPORT_WATER:
|
2007-03-01 13:35:40 +00:00
|
|
|
return IsTileType(tile, MP_WATER) && GetWaterTileType(tile) == WATER_TILE_DEPOT;
|
2005-06-20 20:09:46 +00:00
|
|
|
|
2005-02-06 22:36:08 +00:00
|
|
|
default:
|
2007-03-01 13:35:40 +00:00
|
|
|
NOT_REACHED();
|
2005-02-06 22:36:08 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-31 20:52:38 +00:00
|
|
|
/**
|
|
|
|
* Is the given tile a tile with a depot on it?
|
|
|
|
* @param tile the tile to check
|
|
|
|
* @return true if and only if there is a depot on the tile.
|
|
|
|
*/
|
|
|
|
static inline bool IsDepotTile(TileIndex tile)
|
|
|
|
{
|
|
|
|
switch (GetTileType(tile)) {
|
|
|
|
case MP_ROAD: return GetRoadTileType(tile) == ROAD_TILE_DEPOT;
|
|
|
|
case MP_WATER: return GetWaterTileType(tile) == WATER_TILE_DEPOT;
|
|
|
|
case MP_RAILWAY: return GetRailTileType(tile) == RAIL_TILE_DEPOT;
|
|
|
|
case MP_STATION: return IsHangar(tile);
|
|
|
|
default: return false;
|
|
|
|
}
|
|
|
|
}
|
2005-04-05 22:06:02 +00:00
|
|
|
|
2005-07-16 23:47:37 +00:00
|
|
|
/**
|
2006-06-27 21:25:53 +00:00
|
|
|
* Find out if the slope of the tile is suitable to build a depot of given direction
|
2007-02-24 09:42:39 +00:00
|
|
|
* @param direction The direction in which the depot's exit points
|
2006-06-27 21:25:53 +00:00
|
|
|
* @param tileh The slope of the tile in question
|
|
|
|
* @return true if the construction is possible
|
|
|
|
|
|
|
|
* This is checked by the ugly 0x4C >> direction magic, which does the following:
|
|
|
|
* 0x4C is 0100 1100 and tileh has only bits 0..3 set (steep tiles are ruled out)
|
|
|
|
* So: for direction (only the significant bits are shown)<p>
|
|
|
|
* 00 (exit towards NE) we need either bit 2 or 3 set in tileh: 0x4C >> 0 = 1100<p>
|
|
|
|
* 01 (exit towards SE) we need either bit 1 or 2 set in tileh: 0x4C >> 1 = 0110<p>
|
|
|
|
* 02 (exit towards SW) we need either bit 0 or 1 set in tileh: 0x4C >> 2 = 0011<p>
|
|
|
|
* 03 (exit towards NW) we need either bit 0 or 4 set in tileh: 0x4C >> 3 = 1001<p>
|
|
|
|
* So ((0x4C >> direction) & tileh) determines whether the depot can be built on the current tileh
|
|
|
|
*/
|
2007-02-24 09:42:39 +00:00
|
|
|
static inline bool CanBuildDepotByTileh(DiagDirection direction, Slope tileh)
|
2005-07-16 23:47:37 +00:00
|
|
|
{
|
2006-05-27 16:12:16 +00:00
|
|
|
return ((0x4C >> direction) & tileh) != 0;
|
2005-07-16 23:47:37 +00:00
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
Depot *GetDepotByTile(TileIndex tile);
|
2007-03-07 11:47:46 +00:00
|
|
|
void InitializeDepots();
|
2005-02-06 10:18:47 +00:00
|
|
|
|
2006-12-05 22:40:42 +00:00
|
|
|
void DeleteDepotHighlightOfVehicle(const Vehicle *v);
|
|
|
|
|
2005-02-06 10:18:47 +00:00
|
|
|
#endif /* DEPOT_H */
|