src/waypoint.h
branchnoai
changeset 9694 e72987579514
parent 9629 66dde6412125
child 6800 6c09e1e86fcb
child 9701 d1ac22c62f64
equal deleted inserted replaced
9693:31fcaa5375a1 9694:e72987579514
     6 #define WAYPOINT_H
     6 #define WAYPOINT_H
     7 
     7 
     8 #include "oldpool.h"
     8 #include "oldpool.h"
     9 #include "rail_map.h"
     9 #include "rail_map.h"
    10 
    10 
    11 struct Waypoint {
    11 struct Waypoint;
       
    12 DECLARE_OLD_POOL(Waypoint, Waypoint, 3, 8000)
       
    13 
       
    14 struct Waypoint : PoolItem<Waypoint, WaypointID, &_Waypoint_pool> {
    12 	TileIndex xy;      ///< Tile of waypoint
    15 	TileIndex xy;      ///< Tile of waypoint
    13 	WaypointID index;  ///< Index of waypoint
       
    14 
    16 
    15 	TownID town_index; ///< Town associated with the waypoint
    17 	TownID town_index; ///< Town associated with the waypoint
    16 	byte town_cn;      ///< The Nth waypoint for this town (consecutive number)
    18 	byte town_cn;      ///< The Nth waypoint for this town (consecutive number)
    17 	StringID string;   ///< If this is zero (i.e. no custom name), town + town_cn is used for naming
    19 	StringID string;   ///< If this is zero (i.e. no custom name), town + town_cn is used for naming
    18 
    20 
    22 	byte stat_id;      ///< ID of waypoint within the waypoint class (not saved)
    24 	byte stat_id;      ///< ID of waypoint within the waypoint class (not saved)
    23 	uint32 grfid;      ///< ID of GRF file
    25 	uint32 grfid;      ///< ID of GRF file
    24 	byte localidx;     ///< Index of station within GRF file
    26 	byte localidx;     ///< Index of station within GRF file
    25 
    27 
    26 	byte deleted;      ///< Delete counter. If greater than 0 then it is decremented until it reaches 0; the waypoint is then is deleted.
    28 	byte deleted;      ///< Delete counter. If greater than 0 then it is decremented until it reaches 0; the waypoint is then is deleted.
       
    29 
       
    30 	Waypoint(TileIndex tile = 0);
       
    31 	~Waypoint();
       
    32 
       
    33 	void QuickFree();
       
    34 
       
    35 	bool IsValid() const;
    27 };
    36 };
    28 
       
    29 DECLARE_OLD_POOL(Waypoint, Waypoint, 3, 8000)
       
    30 
       
    31 /**
       
    32  * Check if a Waypoint really exists.
       
    33  * @param wp Waypoint to query
       
    34  * @return the validity of the waypoint
       
    35  */
       
    36 static inline bool IsValidWaypoint(const Waypoint *wp)
       
    37 {
       
    38 	return wp->xy != 0;
       
    39 }
       
    40 
    37 
    41 static inline bool IsValidWaypointID(WaypointID index)
    38 static inline bool IsValidWaypointID(WaypointID index)
    42 {
    39 {
    43 	return index < GetWaypointPoolSize() && IsValidWaypoint(GetWaypoint(index));
    40 	return index < GetWaypointPoolSize() && GetWaypoint(index)->IsValid();
    44 }
    41 }
    45 
       
    46 void DestroyWaypoint(Waypoint *wp);
       
    47 
    42 
    48 static inline void DeleteWaypoint(Waypoint *wp)
    43 static inline void DeleteWaypoint(Waypoint *wp)
    49 {
    44 {
    50 	DestroyWaypoint(wp);
    45 	wp->~Waypoint();
    51 	wp->xy = 0;
       
    52 }
    46 }
    53 
    47 
    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))
    48 #define FOR_ALL_WAYPOINTS_FROM(wp, start) for (wp = GetWaypoint(start); wp != NULL; wp = (wp->index + 1U < GetWaypointPoolSize()) ? GetWaypoint(wp->index + 1U) : NULL) if (wp->IsValid())
    55 #define FOR_ALL_WAYPOINTS(wp) FOR_ALL_WAYPOINTS_FROM(wp, 0)
    49 #define FOR_ALL_WAYPOINTS(wp) FOR_ALL_WAYPOINTS_FROM(wp, 0)
    56 
    50 
    57 
    51 
    58 /**
    52 /**
    59  * Fetch a waypoint by tile
    53  * Fetch a waypoint by tile
    67 }
    61 }
    68 
    62 
    69 CommandCost RemoveTrainWaypoint(TileIndex tile, uint32 flags, bool justremove);
    63 CommandCost RemoveTrainWaypoint(TileIndex tile, uint32 flags, bool justremove);
    70 Station *ComposeWaypointStation(TileIndex tile);
    64 Station *ComposeWaypointStation(TileIndex tile);
    71 void ShowRenameWaypointWindow(const Waypoint *cp);
    65 void ShowRenameWaypointWindow(const Waypoint *cp);
    72 void DrawWaypointSprite(int x, int y, int image, RailType railtype);
    66 void DrawWaypointSprite(int x, int y, int stat_id, RailType railtype);
    73 void FixOldWaypoints();
    67 void FixOldWaypoints();
    74 void UpdateAllWaypointSigns();
    68 void UpdateAllWaypointSigns();
    75 void AfterLoadWaypoints();
    69 void AfterLoadWaypoints();
    76 
    70 
    77 #endif /* WAYPOINT_H */
    71 #endif /* WAYPOINT_H */