src/pbs.h
author peter1138
Sun, 03 Aug 2008 17:35:08 +0000
changeset 9834 7474149531c1
parent 9831 b233da1b1723
child 10027 c2e1b560b17c
permissions -rw-r--r--
(svn r13977) -Codechange: Let ResizeWindowForWidget() handle hidden (zero height or zero width) widgets.
9786
0169b327f3d2 (svn r13928) -Add [YAPP]: Function for getting the path reservation state of any tile. (michi_cc)
rubidium
parents:
diff changeset
     1
/* $Id$ */
0169b327f3d2 (svn r13928) -Add [YAPP]: Function for getting the path reservation state of any tile. (michi_cc)
rubidium
parents:
diff changeset
     2
0169b327f3d2 (svn r13928) -Add [YAPP]: Function for getting the path reservation state of any tile. (michi_cc)
rubidium
parents:
diff changeset
     3
/** @file pbs.h PBS support routines */
0169b327f3d2 (svn r13928) -Add [YAPP]: Function for getting the path reservation state of any tile. (michi_cc)
rubidium
parents:
diff changeset
     4
0169b327f3d2 (svn r13928) -Add [YAPP]: Function for getting the path reservation state of any tile. (michi_cc)
rubidium
parents:
diff changeset
     5
#ifndef PBS_H
0169b327f3d2 (svn r13928) -Add [YAPP]: Function for getting the path reservation state of any tile. (michi_cc)
rubidium
parents:
diff changeset
     6
#define PBS_H
0169b327f3d2 (svn r13928) -Add [YAPP]: Function for getting the path reservation state of any tile. (michi_cc)
rubidium
parents:
diff changeset
     7
0169b327f3d2 (svn r13928) -Add [YAPP]: Function for getting the path reservation state of any tile. (michi_cc)
rubidium
parents:
diff changeset
     8
#include "tile_type.h"
9787
cedb26977f52 (svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium
parents: 9786
diff changeset
     9
#include "direction_type.h"
9786
0169b327f3d2 (svn r13928) -Add [YAPP]: Function for getting the path reservation state of any tile. (michi_cc)
rubidium
parents:
diff changeset
    10
#include "track_type.h"
9798
4b8cdc1adf4b (svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium
parents: 9787
diff changeset
    11
#include "vehicle_type.h"
9786
0169b327f3d2 (svn r13928) -Add [YAPP]: Function for getting the path reservation state of any tile. (michi_cc)
rubidium
parents:
diff changeset
    12
0169b327f3d2 (svn r13928) -Add [YAPP]: Function for getting the path reservation state of any tile. (michi_cc)
rubidium
parents:
diff changeset
    13
TrackBits GetReservedTrackbits(TileIndex t);
0169b327f3d2 (svn r13928) -Add [YAPP]: Function for getting the path reservation state of any tile. (michi_cc)
rubidium
parents:
diff changeset
    14
9787
cedb26977f52 (svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium
parents: 9786
diff changeset
    15
void SetRailwayStationPlatformReservation(TileIndex start, DiagDirection dir, bool b);
cedb26977f52 (svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium
parents: 9786
diff changeset
    16
cedb26977f52 (svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium
parents: 9786
diff changeset
    17
bool TryReserveRailTrack(TileIndex tile, Track t);
cedb26977f52 (svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium
parents: 9786
diff changeset
    18
void UnreserveRailTrack(TileIndex tile, Track t);
cedb26977f52 (svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium
parents: 9786
diff changeset
    19
9798
4b8cdc1adf4b (svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium
parents: 9787
diff changeset
    20
/** This struct contains information about the end of a reserved path. */
4b8cdc1adf4b (svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium
parents: 9787
diff changeset
    21
struct PBSTileInfo {
4b8cdc1adf4b (svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium
parents: 9787
diff changeset
    22
	TileIndex tile;      ///< Tile the path ends, INVALID_TILE if no valid path was found.
4b8cdc1adf4b (svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium
parents: 9787
diff changeset
    23
	Trackdir  trackdir;  ///< The reserved trackdir on the tile.
4b8cdc1adf4b (svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium
parents: 9787
diff changeset
    24
	bool      okay;      ///< True if tile is a safe wairing position, false otherwise.
4b8cdc1adf4b (svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium
parents: 9787
diff changeset
    25
4b8cdc1adf4b (svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium
parents: 9787
diff changeset
    26
	PBSTileInfo() : tile(INVALID_TILE), trackdir(INVALID_TRACKDIR), okay(false) {}
4b8cdc1adf4b (svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium
parents: 9787
diff changeset
    27
	PBSTileInfo(TileIndex _t, Trackdir _td, bool _okay) : tile(_t), trackdir(_td), okay(_okay) {}
4b8cdc1adf4b (svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium
parents: 9787
diff changeset
    28
};
4b8cdc1adf4b (svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium
parents: 9787
diff changeset
    29
9831
b233da1b1723 (svn r13974) -Fix [YAPP]: A train crash could lead to stale reservations. (michi_cc)
frosch
parents: 9814
diff changeset
    30
PBSTileInfo FollowTrainReservation(const Vehicle *v, Vehicle **train_on_res = NULL);
9798
4b8cdc1adf4b (svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium
parents: 9787
diff changeset
    31
bool IsSafeWaitingPosition(const Vehicle *v, TileIndex tile, Trackdir trackdir, bool include_line_end, bool forbid_90deg = false);
4b8cdc1adf4b (svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium
parents: 9787
diff changeset
    32
bool IsWaitingPositionFree(const Vehicle *v, TileIndex tile, Trackdir trackdir, bool forbid_90deg = false);
4b8cdc1adf4b (svn r13940) -Add [YAPP]: YAPF is now able to reserve the found path. (michi_cc)
rubidium
parents: 9787
diff changeset
    33
9814
19720a320565 (svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium
parents: 9798
diff changeset
    34
Vehicle *GetTrainForReservation(TileIndex tile, Track track);
19720a320565 (svn r13956) -Add [YAPP]: Function for getting the train holding a reserved path. (michi_cc)
rubidium
parents: 9798
diff changeset
    35
9787
cedb26977f52 (svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium
parents: 9786
diff changeset
    36
/**
cedb26977f52 (svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium
parents: 9786
diff changeset
    37
 * Check whether some of tracks is reserved on a tile.
cedb26977f52 (svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium
parents: 9786
diff changeset
    38
 *
cedb26977f52 (svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium
parents: 9786
diff changeset
    39
 * @param tile the tile
cedb26977f52 (svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium
parents: 9786
diff changeset
    40
 * @param tracks the tracks to test
cedb26977f52 (svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium
parents: 9786
diff changeset
    41
 * @return true if at least on of tracks is reserved
cedb26977f52 (svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium
parents: 9786
diff changeset
    42
 */
cedb26977f52 (svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium
parents: 9786
diff changeset
    43
static inline bool HasReservedTracks(TileIndex tile, TrackBits tracks)
cedb26977f52 (svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium
parents: 9786
diff changeset
    44
{
cedb26977f52 (svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium
parents: 9786
diff changeset
    45
	return (GetReservedTrackbits(tile) & tracks) != TRACK_BIT_NONE;
cedb26977f52 (svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium
parents: 9786
diff changeset
    46
}
cedb26977f52 (svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
rubidium
parents: 9786
diff changeset
    47
9786
0169b327f3d2 (svn r13928) -Add [YAPP]: Function for getting the path reservation state of any tile. (michi_cc)
rubidium
parents:
diff changeset
    48
#endif /* PBS_H */