src/waypoint.h
author KUDr
Fri, 20 Apr 2007 19:43:06 +0000
changeset 6513 454347ca3dfb
parent 6432 226650eb2ef3
child 6943 1914f26aee04
permissions -rw-r--r--
(svn r9697) -Fix [YAPF](r9694): 'unused variable' warning (glx)
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2116
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2116
diff changeset
     2
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6247
diff changeset
     3
/** @file waypoint.h */
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6247
diff changeset
     4
1542
62a03537ad0b (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff changeset
     5
#ifndef WAYPOINT_H
62a03537ad0b (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff changeset
     6
#define WAYPOINT_H
62a03537ad0b (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff changeset
     7
5216
8bd14ee39af2 (svn r7331) - Codechange: Rename all memory pool macro's and types to "old pool", so the new pool implementation can be committed alongside it.
matthijs
parents: 4984
diff changeset
     8
#include "oldpool.h"
3239
9b1030ac7d83 (svn r3913) Move declarations to rail_map.h so rail.h is dependent on rail_map.h and not the other way round
tron
parents: 2817
diff changeset
     9
#include "rail_map.h"
1542
62a03537ad0b (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff changeset
    10
62a03537ad0b (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff changeset
    11
struct Waypoint {
2670
f2d6a8424e3e (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents: 2668
diff changeset
    12
	TileIndex xy;      ///< Tile of waypoint
4389
18d6ccfb5335 (svn r6142) -Codechange: added WaypointID (sorry DV, couldn't splits it anymore)
truelight
parents: 4352
diff changeset
    13
	WaypointID index;  ///< Index of waypoint
1542
62a03537ad0b (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff changeset
    14
3346
a0d4def7d934 (svn r4130) - CodeChange: Add proper semantics for TownID for such variables instead of using the general uint16-type. We probably need to change GetTown() and IsTownIndex() as well to use TownID.
Darkvater
parents: 3239
diff changeset
    15
	TownID town_index; ///< Town associated with the waypoint
2670
f2d6a8424e3e (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents: 2668
diff changeset
    16
	byte town_cn;      ///< The Nth waypoint for this town (consecutive number)
f2d6a8424e3e (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents: 2668
diff changeset
    17
	StringID string;   ///< If this is zero (i.e. no custom name), town + town_cn is used for naming
1542
62a03537ad0b (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff changeset
    18
2670
f2d6a8424e3e (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents: 2668
diff changeset
    19
	ViewportSign sign; ///< Dimensions of sign (not saved)
4289
8981ce44336d (svn r5919) -Cleanup: use the type Date when the variable really is a date
rubidium
parents: 4044
diff changeset
    20
	Date build_date;   ///< Date of construction
2670
f2d6a8424e3e (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents: 2668
diff changeset
    21
f2d6a8424e3e (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents: 2668
diff changeset
    22
	byte stat_id;      ///< ID of waypoint within the waypoint class (not saved)
f2d6a8424e3e (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents: 2668
diff changeset
    23
	uint32 grfid;      ///< ID of GRF file
f2d6a8424e3e (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents: 2668
diff changeset
    24
	byte localidx;     ///< Index of station within GRF file
f2d6a8424e3e (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents: 2668
diff changeset
    25
f2d6a8424e3e (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents: 2668
diff changeset
    26
	byte deleted;      ///< Delete counter. If greater than 0 then it is decremented until it reaches 0; the waypoint is then is deleted.
1542
62a03537ad0b (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff changeset
    27
};
62a03537ad0b (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff changeset
    28
5216
8bd14ee39af2 (svn r7331) - Codechange: Rename all memory pool macro's and types to "old pool", so the new pool implementation can be committed alongside it.
matthijs
parents: 4984
diff changeset
    29
DECLARE_OLD_POOL(Waypoint, Waypoint, 3, 8000)
1542
62a03537ad0b (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff changeset
    30
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4289
diff changeset
    31
/**
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4289
diff changeset
    32
 * Check if a Waypoint really exists.
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6247
diff changeset
    33
 * @param wp Waypoint to query
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6247
diff changeset
    34
 * @return the validity of the waypoint
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4289
diff changeset
    35
 */
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4289
diff changeset
    36
static inline bool IsValidWaypoint(const Waypoint *wp)
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4289
diff changeset
    37
{
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4289
diff changeset
    38
	return wp->xy != 0;
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4289
diff changeset
    39
}
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4289
diff changeset
    40
4389
18d6ccfb5335 (svn r6142) -Codechange: added WaypointID (sorry DV, couldn't splits it anymore)
truelight
parents: 4352
diff changeset
    41
static inline bool IsValidWaypointID(WaypointID index)
4352
6703cd8d39e0 (svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents: 4346
diff changeset
    42
{
6703cd8d39e0 (svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents: 4346
diff changeset
    43
	return index < GetWaypointPoolSize() && IsValidWaypoint(GetWaypoint(index));
6703cd8d39e0 (svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents: 4346
diff changeset
    44
}
6703cd8d39e0 (svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents: 4346
diff changeset
    45
4390
c7adc07e4301 (svn r6143) -Codechange: DeleteWaypoint removes a waypoint from the pool
truelight
parents: 4389
diff changeset
    46
void DestroyWaypoint(Waypoint *wp);
c7adc07e4301 (svn r6143) -Codechange: DeleteWaypoint removes a waypoint from the pool
truelight
parents: 4389
diff changeset
    47
c7adc07e4301 (svn r6143) -Codechange: DeleteWaypoint removes a waypoint from the pool
truelight
parents: 4389
diff changeset
    48
static inline void DeleteWaypoint(Waypoint *wp)
c7adc07e4301 (svn r6143) -Codechange: DeleteWaypoint removes a waypoint from the pool
truelight
parents: 4389
diff changeset
    49
{
c7adc07e4301 (svn r6143) -Codechange: DeleteWaypoint removes a waypoint from the pool
truelight
parents: 4389
diff changeset
    50
	DestroyWaypoint(wp);
c7adc07e4301 (svn r6143) -Codechange: DeleteWaypoint removes a waypoint from the pool
truelight
parents: 4389
diff changeset
    51
	wp->xy = 0;
c7adc07e4301 (svn r6143) -Codechange: DeleteWaypoint removes a waypoint from the pool
truelight
parents: 4389
diff changeset
    52
}
c7adc07e4301 (svn r6143) -Codechange: DeleteWaypoint removes a waypoint from the pool
truelight
parents: 4389
diff changeset
    53
4984
f717899efa25 (svn r6987) Use the pool macros for the Waypoint pool
tron
parents: 4390
diff changeset
    54
#define FOR_ALL_WAYPOINTS_FROM(wp, start) for (wp = GetWaypoint(start); wp != NULL; wp = (wp->index + 1U < GetWaypointPoolSize()) ? GetWaypoint(wp->index + 1U) : NULL) if (IsValidWaypoint(wp))
1542
62a03537ad0b (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff changeset
    55
#define FOR_ALL_WAYPOINTS(wp) FOR_ALL_WAYPOINTS_FROM(wp, 0)
62a03537ad0b (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff changeset
    56
62a03537ad0b (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff changeset
    57
2670
f2d6a8424e3e (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents: 2668
diff changeset
    58
/**
f2d6a8424e3e (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents: 2668
diff changeset
    59
 * Fetch a waypoint by tile
f2d6a8424e3e (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents: 2668
diff changeset
    60
 * @param tile Tile of waypoint
f2d6a8424e3e (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents: 2668
diff changeset
    61
 * @return Waypoint
f2d6a8424e3e (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents: 2668
diff changeset
    62
 */
f2d6a8424e3e (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents: 2668
diff changeset
    63
static inline Waypoint *GetWaypointByTile(TileIndex tile)
f2d6a8424e3e (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents: 2668
diff changeset
    64
{
f2d6a8424e3e (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents: 2668
diff changeset
    65
	assert(IsTileType(tile, MP_RAILWAY) && IsRailWaypoint(tile));
6182
7337aca829f1 (svn r8954) -Codechange: remove direct map accesses from non-map-accessor headers.
rubidium
parents: 5475
diff changeset
    66
	return GetWaypoint(GetWaypointIndex(tile));
2670
f2d6a8424e3e (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents: 2668
diff changeset
    67
}
f2d6a8424e3e (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents: 2668
diff changeset
    68
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1718
diff changeset
    69
int32 RemoveTrainWaypoint(TileIndex tile, uint32 flags, bool justremove);
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1718
diff changeset
    70
Station *ComposeWaypointStation(TileIndex tile);
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 1977
diff changeset
    71
void ShowRenameWaypointWindow(const Waypoint *cp);
2520
8a52362c4ada (svn r3049) Replace byte/int/uint by RailType where appropriate
tron
parents: 2254
diff changeset
    72
void DrawWaypointSprite(int x, int y, int image, RailType railtype);
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6182
diff changeset
    73
void FixOldWaypoints();
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6182
diff changeset
    74
void UpdateAllWaypointSigns();
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6182
diff changeset
    75
void AfterLoadWaypoints();
1542
62a03537ad0b (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff changeset
    76
62a03537ad0b (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff changeset
    77
#endif /* WAYPOINT_H */