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
|
|
|
|
|
2006-03-05 12:34:55 +00:00
|
|
|
#include "direction.h"
|
2006-12-03 17:27:43 +00:00
|
|
|
#include "oldpool.h"
|
2005-02-06 22:36:08 +00:00
|
|
|
#include "tile.h"
|
2005-07-21 18:44:27 +00:00
|
|
|
#include "variables.h"
|
2007-03-01 13:35:40 +00:00
|
|
|
#include "road_map.h"
|
|
|
|
#include "rail_map.h"
|
|
|
|
#include "water_map.h"
|
2005-02-06 10:18:47 +00:00
|
|
|
|
|
|
|
struct Depot {
|
|
|
|
TileIndex xy;
|
2006-03-26 22:41:56 +00:00
|
|
|
TownID town_index;
|
2006-08-26 14:44:55 +00:00
|
|
|
DepotID index;
|
2005-02-06 10:18:47 +00:00
|
|
|
};
|
|
|
|
|
2006-12-03 17:27:43 +00:00
|
|
|
DECLARE_OLD_POOL(Depot, Depot, 3, 8000)
|
2005-02-06 10:18:47 +00:00
|
|
|
|
2006-08-22 15:33:35 +00:00
|
|
|
/**
|
|
|
|
* Check if a depot really exists.
|
|
|
|
*/
|
2006-08-26 14:44:55 +00:00
|
|
|
static inline bool IsValidDepot(const Depot *depot)
|
2006-08-22 15:33:35 +00:00
|
|
|
{
|
2006-08-26 14:44:55 +00:00
|
|
|
return depot != NULL && depot->xy != 0;
|
2006-08-22 15:33:35 +00:00
|
|
|
}
|
|
|
|
|
2006-08-22 18:15:17 +00:00
|
|
|
static inline bool IsValidDepotID(uint index)
|
|
|
|
{
|
|
|
|
return index < GetDepotPoolSize() && IsValidDepot(GetDepot(index));
|
|
|
|
}
|
|
|
|
|
2006-08-26 14:44:55 +00:00
|
|
|
void DestroyDepot(Depot *depot);
|
|
|
|
|
|
|
|
static inline void DeleteDepot(Depot *depot)
|
|
|
|
{
|
|
|
|
DestroyDepot(depot);
|
|
|
|
depot->xy = 0;
|
|
|
|
}
|
|
|
|
|
2006-09-26 16:47:51 +00:00
|
|
|
void ShowDepotWindow(TileIndex tile, byte type);
|
|
|
|
|
2006-10-28 11:02:37 +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 (IsValidDepot(d))
|
2005-02-06 10:18:47 +00:00
|
|
|
#define FOR_ALL_DEPOTS(d) FOR_ALL_DEPOTS_FROM(d, 0)
|
|
|
|
|
|
|
|
#define MIN_SERVINT_PERCENT 5
|
|
|
|
#define MAX_SERVINT_PERCENT 90
|
|
|
|
#define MIN_SERVINT_DAYS 30
|
|
|
|
#define MAX_SERVINT_DAYS 800
|
|
|
|
|
2006-08-26 14:44:55 +00:00
|
|
|
/**
|
|
|
|
* Get the service interval domain.
|
2005-05-11 16:17:03 +00:00
|
|
|
* Get the new proposed service interval for the vehicle is indeed, clamped
|
|
|
|
* within the given bounds. @see MIN_SERVINT_PERCENT ,etc.
|
|
|
|
* @param index proposed service interval
|
2007-02-23 18:55:07 +00:00
|
|
|
* @return service interval
|
2005-05-11 16:17:03 +00:00
|
|
|
*/
|
2006-08-17 20:22:35 +00:00
|
|
|
static inline Date GetServiceIntervalClamped(uint index)
|
2005-05-11 16:17:03 +00:00
|
|
|
{
|
|
|
|
return (_patches.servint_ispercent) ? clamp(index, MIN_SERVINT_PERCENT, MAX_SERVINT_PERCENT) : clamp(index, MIN_SERVINT_DAYS, MAX_SERVINT_DAYS);
|
|
|
|
}
|
|
|
|
|
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-03-01 13:35:40 +00:00
|
|
|
return IsTileType(tile, MP_STREET) && 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
Depot *AllocateDepot();
|
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 */
|