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)
|
|
|
|
* @see depot.c */
|
|
|
|
|
2006-03-05 12:34:55 +00:00
|
|
|
#include "direction.h"
|
2005-02-06 10:18:47 +00:00
|
|
|
#include "pool.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;
|
|
|
|
uint16 town_index;
|
|
|
|
uint16 index;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern MemoryPool _depot_pool;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the pointer to the depot with index 'index'
|
|
|
|
*/
|
|
|
|
static inline Depot *GetDepot(uint index)
|
|
|
|
{
|
|
|
|
return (Depot*)GetItemFromPool(&_depot_pool, index);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the current size of the DepotPool
|
|
|
|
*/
|
|
|
|
static inline uint16 GetDepotPoolSize(void)
|
|
|
|
{
|
|
|
|
return _depot_pool.total_items;
|
|
|
|
}
|
|
|
|
|
2005-04-22 05:41:09 +00:00
|
|
|
static inline bool IsDepotIndex(uint index)
|
|
|
|
{
|
|
|
|
return index < GetDepotPoolSize();
|
|
|
|
}
|
|
|
|
|
2005-02-06 10:18:47 +00:00
|
|
|
#define FOR_ALL_DEPOTS_FROM(d, start) for (d = GetDepot(start); d != NULL; d = (d->index + 1 < GetDepotPoolSize()) ? GetDepot(d->index + 1) : NULL)
|
|
|
|
#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
|
|
|
|
|
2005-05-11 16:17:03 +00:00
|
|
|
/** Get the service interval domain.
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
static inline uint16 GetServiceIntervalClamped(uint index)
|
|
|
|
{
|
|
|
|
return (_patches.servint_ispercent) ? clamp(index, MIN_SERVINT_PERCENT, MAX_SERVINT_PERCENT) : clamp(index, MIN_SERVINT_DAYS, MAX_SERVINT_DAYS);
|
|
|
|
}
|
|
|
|
|
2005-02-06 10:18:47 +00:00
|
|
|
VARDEF TileIndex _last_built_train_depot_tile;
|
|
|
|
VARDEF TileIndex _last_built_road_depot_tile;
|
|
|
|
VARDEF TileIndex _last_built_aircraft_depot_tile;
|
|
|
|
VARDEF TileIndex _last_built_ship_depot_tile;
|
|
|
|
|
2005-02-06 22:36:08 +00:00
|
|
|
/**
|
|
|
|
* Check if a depot really exists.
|
|
|
|
*/
|
2005-04-22 05:41:09 +00:00
|
|
|
static inline bool IsValidDepot(const Depot* depot)
|
2005-02-06 22:36:08 +00:00
|
|
|
{
|
|
|
|
return depot->xy != 0; /* XXX: Replace by INVALID_TILE someday */
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a tile is a depot of the given type.
|
|
|
|
*/
|
|
|
|
static inline bool IsTileDepotType(TileIndex tile, TransportType type)
|
|
|
|
{
|
2006-02-01 07:36:15 +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
|
|
|
/**
|
|
|
|
* Returns the direction the exit of the depot on the given tile is facing.
|
|
|
|
*/
|
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
|
|
|
static inline DiagDirection GetDepotDirection(TileIndex tile, TransportType type)
|
2005-04-05 22:06:02 +00:00
|
|
|
{
|
|
|
|
assert(IsTileDepotType(tile, type));
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case TRANSPORT_RAIL:
|
|
|
|
case TRANSPORT_ROAD:
|
|
|
|
/* Rail and road store a diagonal direction in bits 0 and 1 */
|
2005-10-05 07:20:26 +00:00
|
|
|
return (DiagDirection)GB(_m[tile].m5, 0, 2);
|
2005-04-05 22:06:02 +00:00
|
|
|
case TRANSPORT_WATER:
|
|
|
|
/* Water is stubborn, it stores the directions in a different order. */
|
2005-10-05 07:20:26 +00:00
|
|
|
switch (GB(_m[tile].m5, 0, 2)) {
|
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
|
|
|
case 0: return DIAGDIR_NE;
|
|
|
|
case 1: return DIAGDIR_SW;
|
|
|
|
case 2: return DIAGDIR_NW;
|
|
|
|
case 3: return DIAGDIR_SE;
|
2005-04-05 22:06:02 +00:00
|
|
|
}
|
|
|
|
default:
|
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
|
|
|
return INVALID_DIAGDIR; /* Not reached */
|
2005-04-05 22:06:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-07-16 23:47:37 +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 >> p2) & tileh) determines whether the depot can be built on the current tileh
|
|
|
|
*/
|
|
|
|
static inline bool CanBuildDepotByTileh(uint32 direction, uint tileh)
|
|
|
|
{
|
|
|
|
return (0x4C >> direction) & tileh;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
Depot *GetDepotByTile(TileIndex tile);
|
2005-02-06 10:18:47 +00:00
|
|
|
void InitializeDepot(void);
|
|
|
|
Depot *AllocateDepot(void);
|
2005-06-24 12:38:35 +00:00
|
|
|
void DoDeleteDepot(TileIndex tile);
|
2005-02-06 10:18:47 +00:00
|
|
|
|
|
|
|
#endif /* DEPOT_H */
|