2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2005-02-06 10:18:47 +00:00
|
|
|
#ifndef DEPOT_H
|
|
|
|
#define DEPOT_H
|
|
|
|
|
2005-07-16 23:47:37 +00:00
|
|
|
/** @file depot.h Header files for depots (not hangars)
|
2006-09-04 20:40:33 +00:00
|
|
|
* @see depot.c */
|
2005-07-16 23:47:37 +00:00
|
|
|
|
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"
|
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
|
|
|
|
*/
|
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:
|
2005-07-13 18:04:01 +00:00
|
|
|
return IsTileType(tile, MP_RAILWAY) && (_m[tile].m5 & 0xFC) == 0xC0;
|
2005-06-20 20:09:46 +00:00
|
|
|
|
2005-02-06 22:36:08 +00:00
|
|
|
case TRANSPORT_ROAD:
|
2005-07-13 18:04:01 +00:00
|
|
|
return IsTileType(tile, MP_STREET) && (_m[tile].m5 & 0xF0) == 0x20;
|
2005-06-20 20:09:46 +00:00
|
|
|
|
2005-02-06 22:36:08 +00:00
|
|
|
case TRANSPORT_WATER:
|
2005-07-13 18:04:01 +00:00
|
|
|
return IsTileType(tile, MP_WATER) && (_m[tile].m5 & ~3) == 0x80;
|
2005-06-20 20:09:46 +00:00
|
|
|
|
2005-02-06 22:36:08 +00:00
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
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
|
|
|
|
* @param direction The direction in which the depot's exit points. Starts with 0 as NE and goes Clockwise
|
|
|
|
* @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
|
|
|
|
*/
|
2006-04-23 13:48:16 +00:00
|
|
|
static inline bool CanBuildDepotByTileh(uint32 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);
|
2006-08-22 15:39:22 +00:00
|
|
|
void InitializeDepots(void);
|
2005-02-06 10:18:47 +00:00
|
|
|
Depot *AllocateDepot(void);
|
|
|
|
|
2006-12-05 22:40:42 +00:00
|
|
|
void DeleteDepotHighlightOfVehicle(const Vehicle *v);
|
|
|
|
|
2005-02-06 10:18:47 +00:00
|
|
|
#endif /* DEPOT_H */
|