2005-02-06 10:18:47 +00:00
|
|
|
#ifndef DEPOT_H
|
|
|
|
#define DEPOT_H
|
|
|
|
|
|
|
|
#include "pool.h"
|
2005-02-06 22:36:08 +00:00
|
|
|
#include "tile.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)
|
|
|
|
{
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
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-07-13 18:04:01 +00:00
|
|
|
return (DiagDirection)(_m[tile].m5 & 3);
|
2005-04-05 22:06:02 +00:00
|
|
|
case TRANSPORT_WATER:
|
|
|
|
/* Water is stubborn, it stores the directions in a different order. */
|
2005-07-13 18:04:01 +00:00
|
|
|
switch (_m[tile].m5 & 3) {
|
(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-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 */
|