rail.h
changeset 2951 2de6d3a59743
parent 2916 b687477adcba
child 2989 916f9443345f
equal deleted inserted replaced
2950:30eee9c93028 2951:2de6d3a59743
   495  * given rail tile.
   495  * given rail tile.
   496  */
   496  */
   497 static inline bool HasSignalOnTrack(TileIndex tile, Track track)
   497 static inline bool HasSignalOnTrack(TileIndex tile, Track track)
   498 {
   498 {
   499 	assert(IsValidTrack(track));
   499 	assert(IsValidTrack(track));
   500 	return ((GetRailTileType(tile) == RAIL_TYPE_SIGNALS) && ((_m[tile].m3 & SignalOnTrack(track)) != 0));
   500 	return
       
   501 		GetRailTileType(tile) == RAIL_TYPE_SIGNALS &&
       
   502 		(_m[tile].m3 & SignalOnTrack(track)) != 0;
   501 }
   503 }
   502 
   504 
   503 /**
   505 /**
   504  * Checks for the presence of signals along the given trackdir on the given
   506  * Checks for the presence of signals along the given trackdir on the given
   505  * rail tile.
   507  * rail tile.
   508  * the signal that is facing us (for which we stop when it's red).
   510  * the signal that is facing us (for which we stop when it's red).
   509  */
   511  */
   510 static inline bool HasSignalOnTrackdir(TileIndex tile, Trackdir trackdir)
   512 static inline bool HasSignalOnTrackdir(TileIndex tile, Trackdir trackdir)
   511 {
   513 {
   512 	assert (IsValidTrackdir(trackdir));
   514 	assert (IsValidTrackdir(trackdir));
   513 	return (GetRailTileType(tile) == RAIL_TYPE_SIGNALS) && (_m[tile].m3 & SignalAlongTrackdir(trackdir));
   515 	return
       
   516 		GetRailTileType(tile) == RAIL_TYPE_SIGNALS &&
       
   517 		_m[tile].m3 & SignalAlongTrackdir(trackdir);
   514 }
   518 }
   515 
   519 
   516 /**
   520 /**
   517  * Gets the state of the signal along the given trackdir.
   521  * Gets the state of the signal along the given trackdir.
   518  *
   522  *
   521  */
   525  */
   522 static inline SignalState GetSignalState(TileIndex tile, Trackdir trackdir)
   526 static inline SignalState GetSignalState(TileIndex tile, Trackdir trackdir)
   523 {
   527 {
   524 	assert(IsValidTrackdir(trackdir));
   528 	assert(IsValidTrackdir(trackdir));
   525 	assert(HasSignalOnTrack(tile, TrackdirToTrack(trackdir)));
   529 	assert(HasSignalOnTrack(tile, TrackdirToTrack(trackdir)));
   526 	return ((_m[tile].m2 & SignalAlongTrackdir(trackdir))?SIGNAL_STATE_GREEN:SIGNAL_STATE_RED);
   530 	return _m[tile].m2 & SignalAlongTrackdir(trackdir) ?
       
   531 		SIGNAL_STATE_GREEN : SIGNAL_STATE_RED;
   527 }
   532 }
   528 
   533 
   529 /**
   534 /**
   530  * Gets the type of signal on a given track on a given rail tile with signals.
   535  * Gets the type of signal on a given track on a given rail tile with signals.
   531  *
   536  *
   550  * future-compatible, though.
   555  * future-compatible, though.
   551  */
   556  */
   552 static inline bool HasSemaphores(TileIndex tile, Track track)
   557 static inline bool HasSemaphores(TileIndex tile, Track track)
   553 {
   558 {
   554 	assert(IsValidTrack(track));
   559 	assert(IsValidTrack(track));
   555 	return (_m[tile].m4 & SIG_SEMAPHORE_MASK);
   560 	return _m[tile].m4 & SIG_SEMAPHORE_MASK;
   556 }
   561 }
   557 
   562 
   558 /**
   563 /**
   559  * Return the rail type of tile, or INVALID_RAILTYPE if this is no rail tile.
   564  * Return the rail type of tile, or INVALID_RAILTYPE if this is no rail tile.
   560  * Note that there is no check if the given trackdir is actually present on
   565  * Note that there is no check if the given trackdir is actually present on
   578  * TRANSPORT_RAIL.
   583  * TRANSPORT_RAIL.
   579  */
   584  */
   580 static inline TransportType GetCrossingTransportType(TileIndex tile, Track track)
   585 static inline TransportType GetCrossingTransportType(TileIndex tile, Track track)
   581 {
   586 {
   582 	/* XXX: Nicer way to write this? */
   587 	/* XXX: Nicer way to write this? */
   583 	switch(track)
   588 	switch (track) {
   584 	{
       
   585 		/* When map5 bit 3 is set, the road runs in the y direction (DIAG2) */
   589 		/* When map5 bit 3 is set, the road runs in the y direction (DIAG2) */
   586 		case TRACK_DIAG1:
   590 		case TRACK_DIAG1:
   587 			return (HASBIT(_m[tile].m5, 3) ? TRANSPORT_RAIL : TRANSPORT_ROAD);
   591 			return (HASBIT(_m[tile].m5, 3) ? TRANSPORT_RAIL : TRANSPORT_ROAD);
   588 		case TRACK_DIAG2:
   592 		case TRACK_DIAG2:
   589 			return (HASBIT(_m[tile].m5, 3) ? TRANSPORT_ROAD : TRANSPORT_RAIL);
   593 			return (HASBIT(_m[tile].m5, 3) ? TRANSPORT_ROAD : TRANSPORT_RAIL);
   625  * @return Whether the tracks present overlap in any way.
   629  * @return Whether the tracks present overlap in any way.
   626  */
   630  */
   627 static inline bool TracksOverlap(TrackBits bits)
   631 static inline bool TracksOverlap(TrackBits bits)
   628 {
   632 {
   629   /* With no, or only one track, there is no overlap */
   633   /* With no, or only one track, there is no overlap */
   630   if (bits == 0 || KILL_FIRST_BIT(bits) == 0)
   634   if (bits == 0 || KILL_FIRST_BIT(bits) == 0) return false;
   631     return false;
       
   632   /* We know that there are at least two tracks present. When there are more
   635   /* We know that there are at least two tracks present. When there are more
   633    * than 2 tracks, they will surely overlap. When there are two, they will
   636    * than 2 tracks, they will surely overlap. When there are two, they will
   634    * always overlap unless they are lower & upper or right & left. */
   637    * always overlap unless they are lower & upper or right & left. */
   635   if ((bits == (TRACK_BIT_UPPER|TRACK_BIT_LOWER)) || (bits == (TRACK_BIT_LEFT | TRACK_BIT_RIGHT)))
   638   if ((bits == (TRACK_BIT_UPPER|TRACK_BIT_LOWER)) || (bits == (TRACK_BIT_LEFT | TRACK_BIT_RIGHT)))
   636     return false;
   639     return false;