rail.h
changeset 4077 d4d440dd8925
parent 4041 72276cd8ee2b
child 4158 91ff9bb84ced
equal deleted inserted replaced
4076:a6650b616430 4077:d4d440dd8925
   162 	 * @note: Something more flexible might be desirable in the future.
   162 	 * @note: Something more flexible might be desirable in the future.
   163 	 */
   163 	 */
   164 	SpriteID total_offset;
   164 	SpriteID total_offset;
   165 
   165 
   166 	/**
   166 	/**
   167 	  * Bridge offset
   167 	 * Bridge offset
   168 	  */
   168 	 */
   169 	SpriteID bridge_offset;
   169 	SpriteID bridge_offset;
   170 
   170 
   171 	/**
   171 	/**
   172 	 * Offset to add to ground sprite when drawing custom waypoints / stations
   172 	 * Offset to add to ground sprite when drawing custom waypoints / stations
   173 	 */
   173 	 */
   261 
   261 
   262 /**
   262 /**
   263  * Returns a TrackdirBit mask that contains the two TrackdirBits that
   263  * Returns a TrackdirBit mask that contains the two TrackdirBits that
   264  * correspond with the given Track (one for each direction).
   264  * correspond with the given Track (one for each direction).
   265  */
   265  */
   266 static inline TrackdirBits TrackToTrackdirBits(Track track) { Trackdir td = TrackToTrackdir(track); return (TrackdirBits)(TrackdirToTrackdirBits(td) | TrackdirToTrackdirBits(ReverseTrackdir(td)));}
   266 static inline TrackdirBits TrackToTrackdirBits(Track track)
       
   267 {
       
   268 	Trackdir td = TrackToTrackdir(track);
       
   269 	return (TrackdirBits)(TrackdirToTrackdirBits(td) | TrackdirToTrackdirBits(ReverseTrackdir(td)));
       
   270 }
   267 
   271 
   268 /**
   272 /**
   269  * Discards all directional information from the given TrackdirBits. Any
   273  * Discards all directional information from the given TrackdirBits. Any
   270  * Track which is present in either direction will be present in the result.
   274  * Track which is present in either direction will be present in the result.
   271  */
   275  */
   272 static inline TrackBits TrackdirBitsToTrackBits(TrackdirBits bits) { return (TrackBits)(bits | (bits >> 8)); }
   276 static inline TrackBits TrackdirBitsToTrackBits(TrackdirBits bits)
       
   277 {
       
   278 	return (TrackBits)(bits | (bits >> 8));
       
   279 }
   273 
   280 
   274 /**
   281 /**
   275  * Maps a trackdir to the trackdir that you will end up on if you go straight
   282  * Maps a trackdir to the trackdir that you will end up on if you go straight
   276  * ahead. This will be the same trackdir for diagonal trackdirs, but a
   283  * ahead. This will be the same trackdir for diagonal trackdirs, but a
   277  * different (alternating) one for straight trackdirs
   284  * different (alternating) one for straight trackdirs
   278  */
   285  */
   279 static inline Trackdir NextTrackdir(Trackdir trackdir) {
   286 static inline Trackdir NextTrackdir(Trackdir trackdir)
       
   287 {
   280 	extern const Trackdir _next_trackdir[TRACKDIR_END];
   288 	extern const Trackdir _next_trackdir[TRACKDIR_END];
   281 	return _next_trackdir[trackdir];
   289 	return _next_trackdir[trackdir];
   282 }
   290 }
   283 
   291 
   284 /**
   292 /**
   285  * Maps a track to all tracks that make 90 deg turns with it.
   293  * Maps a track to all tracks that make 90 deg turns with it.
   286  */
   294  */
   287 static inline TrackBits TrackCrossesTracks(Track track) {
   295 static inline TrackBits TrackCrossesTracks(Track track)
       
   296 {
   288 	extern const TrackBits _track_crosses_tracks[TRACK_END];
   297 	extern const TrackBits _track_crosses_tracks[TRACK_END];
   289 	return _track_crosses_tracks[track];
   298 	return _track_crosses_tracks[track];
   290 }
   299 }
   291 
   300 
   292 /**
   301 /**
   293  * Maps a trackdir to the (4-way) direction the tile is exited when following
   302  * Maps a trackdir to the (4-way) direction the tile is exited when following
   294  * that trackdir.
   303  * that trackdir.
   295  */
   304  */
   296 static inline DiagDirection TrackdirToExitdir(Trackdir trackdir) {
   305 static inline DiagDirection TrackdirToExitdir(Trackdir trackdir)
       
   306 {
   297 	extern const DiagDirection _trackdir_to_exitdir[TRACKDIR_END];
   307 	extern const DiagDirection _trackdir_to_exitdir[TRACKDIR_END];
   298 	return _trackdir_to_exitdir[trackdir];
   308 	return _trackdir_to_exitdir[trackdir];
   299 }
   309 }
   300 
   310 
   301 /**
   311 /**
   302  * Maps a track and an (4-way) dir to the trackdir that represents the track
   312  * Maps a track and an (4-way) dir to the trackdir that represents the track
   303  * with the exit in the given direction.
   313  * with the exit in the given direction.
   304  */
   314  */
   305 static inline Trackdir TrackExitdirToTrackdir(Track track, DiagDirection diagdir) {
   315 static inline Trackdir TrackExitdirToTrackdir(Track track, DiagDirection diagdir)
       
   316 {
   306 	extern const Trackdir _track_exitdir_to_trackdir[TRACK_END][DIAGDIR_END];
   317 	extern const Trackdir _track_exitdir_to_trackdir[TRACK_END][DIAGDIR_END];
   307 	return _track_exitdir_to_trackdir[track][diagdir];
   318 	return _track_exitdir_to_trackdir[track][diagdir];
   308 }
   319 }
   309 
   320 
   310 /**
   321 /**
   311  * Maps a track and an (4-way) dir to the trackdir that represents the track
   322  * Maps a track and an (4-way) dir to the trackdir that represents the track
   312  * with the exit in the given direction.
   323  * with the exit in the given direction.
   313  */
   324  */
   314 static inline Trackdir TrackEnterdirToTrackdir(Track track, DiagDirection diagdir) {
   325 static inline Trackdir TrackEnterdirToTrackdir(Track track, DiagDirection diagdir)
       
   326 {
   315 	extern const Trackdir _track_enterdir_to_trackdir[TRACK_END][DIAGDIR_END];
   327 	extern const Trackdir _track_enterdir_to_trackdir[TRACK_END][DIAGDIR_END];
   316 	return _track_enterdir_to_trackdir[track][diagdir];
   328 	return _track_enterdir_to_trackdir[track][diagdir];
   317 }
   329 }
   318 
   330 
   319 /**
   331 /**
   320  * Maps a track and a full (8-way) direction to the trackdir that represents
   332  * Maps a track and a full (8-way) direction to the trackdir that represents
   321  * the track running in the given direction.
   333  * the track running in the given direction.
   322  */
   334  */
   323 static inline Trackdir TrackDirectionToTrackdir(Track track, Direction dir) {
   335 static inline Trackdir TrackDirectionToTrackdir(Track track, Direction dir)
       
   336 {
   324 	extern const Trackdir _track_direction_to_trackdir[TRACK_END][DIR_END];
   337 	extern const Trackdir _track_direction_to_trackdir[TRACK_END][DIR_END];
   325 	return _track_direction_to_trackdir[track][dir];
   338 	return _track_direction_to_trackdir[track][dir];
   326 }
   339 }
   327 
   340 
   328 /**
   341 /**
   329  * Maps a (4-way) direction to the diagonal trackdir that runs in that
   342  * Maps a (4-way) direction to the diagonal trackdir that runs in that
   330  * direction.
   343  * direction.
   331  */
   344  */
   332 static inline Trackdir DiagdirToDiagTrackdir(DiagDirection diagdir) {
   345 static inline Trackdir DiagdirToDiagTrackdir(DiagDirection diagdir)
       
   346 {
   333 	extern const Trackdir _dir_to_diag_trackdir[DIAGDIR_END];
   347 	extern const Trackdir _dir_to_diag_trackdir[DIAGDIR_END];
   334 	return _dir_to_diag_trackdir[diagdir];
   348 	return _dir_to_diag_trackdir[diagdir];
   335 }
   349 }
   336 
   350 
   337 extern const TrackdirBits _exitdir_reaches_trackdirs[DIAGDIR_END];
   351 extern const TrackdirBits _exitdir_reaches_trackdirs[DIAGDIR_END];
   409  * @param  bits The tracks present.
   423  * @param  bits The tracks present.
   410  * @return Whether the tracks present overlap in any way.
   424  * @return Whether the tracks present overlap in any way.
   411  */
   425  */
   412 static inline bool TracksOverlap(TrackBits bits)
   426 static inline bool TracksOverlap(TrackBits bits)
   413 {
   427 {
   414   /* With no, or only one track, there is no overlap */
   428 	/* With no, or only one track, there is no overlap */
   415   if (bits == 0 || KILL_FIRST_BIT(bits) == 0) return false;
   429 	if (bits == 0 || KILL_FIRST_BIT(bits) == 0) return false;
   416   /* We know that there are at least two tracks present. When there are more
   430 	/* We know that there are at least two tracks present. When there are more
   417    * than 2 tracks, they will surely overlap. When there are two, they will
   431 	 * than 2 tracks, they will surely overlap. When there are two, they will
   418    * always overlap unless they are lower & upper or right & left. */
   432 	 * always overlap unless they are lower & upper or right & left. */
   419 	return bits != TRACK_BIT_HORZ && bits != TRACK_BIT_VERT;
   433 	return bits != TRACK_BIT_HORZ && bits != TRACK_BIT_VERT;
   420 }
   434 }
   421 
   435 
   422 void DrawTrainDepotSprite(int x, int y, int image, RailType railtype);
   436 void DrawTrainDepotSprite(int x, int y, int image, RailType railtype);
   423 void DrawDefaultWaypointSprite(int x, int y, RailType railtype);
   437 void DrawDefaultWaypointSprite(int x, int y, RailType railtype);