2005-07-24 14:12:37 +00:00
/* $Id$ */
2004-08-09 17:04:08 +00:00
# include "stdafx.h"
2005-06-02 19:30:21 +00:00
# include "openttd.h"
2005-06-06 22:44:11 +00:00
# include "debug.h"
2005-07-22 07:02:20 +00:00
# include "functions.h"
2005-02-13 11:18:02 +00:00
# include "table/sprites.h"
2004-11-25 10:47:30 +00:00
# include "table/strings.h"
2004-12-15 22:18:54 +00:00
# include "map.h"
2005-01-29 12:19:05 +00:00
# include "tile.h"
2004-08-09 17:04:08 +00:00
# include "vehicle.h"
# include "viewport.h"
# include "command.h"
# include "pathfind.h"
2005-06-06 22:44:11 +00:00
# include "engine.h"
2004-08-09 17:04:08 +00:00
# include "town.h"
2004-11-05 23:12:33 +00:00
# include "sound.h"
2004-11-14 09:07:15 +00:00
# include "station.h"
2004-11-14 16:42:08 +00:00
# include "sprite.h"
2005-02-06 10:18:47 +00:00
# include "depot.h"
2005-07-04 14:58:55 +00:00
# include "pbs.h"
2005-03-24 17:03:37 +00:00
# include "waypoint.h"
2005-07-04 14:58:55 +00:00
# include "npf.h"
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
# include "rail.h"
2005-07-29 22:13:04 +00:00
# include "railtypes.h" // include table for railtypes
2004-08-09 17:04:08 +00:00
2004-11-14 22:10:08 +00:00
extern uint16 _custom_sprites_base ;
2005-08-01 16:31:19 +00:00
const byte _track_sloped_sprites [ 14 ] = {
14 , 15 , 22 , 13 ,
0 , 21 , 17 , 12 ,
23 , 0 , 18 , 20 ,
19 , 16
} ;
2005-06-24 12:38:35 +00:00
void ShowTrainDepotWindow ( TileIndex tile ) ;
2004-08-09 17:04:08 +00:00
/* Format of rail map5 byte.
* 00 abcdef = > Normal rail
* 01 abcdef = > Rail with signals
* 10 ? ? ? ? ? ? = > Unused
* 11 ? ? ? ? dd = > Depot
2004-08-11 22:07:08 +00:00
*
* abcdef is a bitmask , which contains ones for all present tracks . Below the
2004-09-11 09:55:19 +00:00
* value for each track is given .
2004-08-09 17:04:08 +00:00
*/
/* 4
* - - - - - - - - -
* | \ / |
* | \ 1 / |
* | \ / |
* | \ / |
* 16 | \ | 32
2004-09-11 09:55:19 +00:00
* | / \ 2 |
2004-08-09 17:04:08 +00:00
* | / \ |
* | / \ |
* | / \ |
* - - - - - - - - -
* 8
*/
// Constants for lower part of Map2 byte.
2004-09-11 09:55:19 +00:00
enum RailMap2Lower4 {
2004-08-09 17:04:08 +00:00
RAIL_MAP2LO_GROUND_MASK = 0xF ,
RAIL_GROUND_BROWN = 0 ,
RAIL_GROUND_GREEN = 1 ,
RAIL_GROUND_FENCE_NW = 2 ,
RAIL_GROUND_FENCE_SE = 3 ,
RAIL_GROUND_FENCE_SENW = 4 ,
RAIL_GROUND_FENCE_NE = 5 ,
RAIL_GROUND_FENCE_SW = 6 ,
RAIL_GROUND_FENCE_NESW = 7 ,
RAIL_GROUND_FENCE_VERT1 = 8 ,
RAIL_GROUND_FENCE_VERT2 = 9 ,
RAIL_GROUND_FENCE_HORIZ1 = 10 ,
RAIL_GROUND_FENCE_HORIZ2 = 11 ,
RAIL_GROUND_ICE_DESERT = 12 ,
} ;
2004-08-11 22:07:08 +00:00
/* MAP2 byte: abcd???? => Signal On? Same coding as map3lo
2004-09-11 09:55:19 +00:00
* MAP3LO byte : abcd ? ? ? ? = > Signal Exists ?
2004-08-11 22:07:08 +00:00
* a and b are for diagonals , upper and left ,
* one for each direction . ( ie a = = NE - > SW , b = =
* SW - > NE , or v . v . , I don ' t know . b and c are
* similar for lower and right .
2004-08-09 17:04:08 +00:00
* MAP2 byte : ? ? ? ? abcd = > Type of ground .
* MAP3LO byte : ? ? ? ? abcd = > Type of rail .
* MAP5 : 00 abcdef = > rail
* 01 abcdef = > rail w / signals
* 10uuuuuu = > unused
2004-09-11 09:55:19 +00:00
* 11uuuu dd = > rail depot
2004-08-09 17:04:08 +00:00
*/
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
static bool CheckTrackCombination ( TileIndex tile , TrackBits to_build , uint flags )
2004-08-09 17:04:08 +00:00
{
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
RailTileType type = GetRailTileType ( tile ) ;
TrackBits current ; /* The current track layout */
TrackBits future ; /* The track layout we want to build */
2004-08-09 17:04:08 +00:00
_error_message = STR_1001_IMPOSSIBLE_TRACK_COMBINATION ;
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
if ( type ! = RAIL_TYPE_NORMAL & & type ! = RAIL_TYPE_SIGNALS )
return false ; /* Cannot build anything on depots and checkpoints */
2005-03-28 07:25:36 +00:00
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
/* So, we have a tile with tracks on it (and possibly signals). Let's see
* what tracks first */
current = GetTrackBits ( tile ) ;
2005-06-17 07:35:10 +00:00
future = current | to_build ;
2005-03-28 07:25:36 +00:00
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
/* Are we really building something new? */
if ( current = = future ) {
/* Nothing new is being built */
_error_message = STR_1007_ALREADY_BUILT ;
return false ;
}
2005-03-28 07:25:36 +00:00
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
/* Let's see if we may build this */
if ( ( flags & DC_NO_RAIL_OVERLAP ) | | type = = RAIL_TYPE_SIGNALS ) {
/* If we are not allowed to overlap (flag is on for ai players or we have
* signals on the tile ) , check that */
return
future = = ( TRACK_BIT_UPPER | TRACK_BIT_LOWER ) | |
future = = ( TRACK_BIT_LEFT | TRACK_BIT_RIGHT ) ;
} else {
/* Normally, we may overlap and any combination is valid */
return true ;
2004-08-09 17:04:08 +00:00
}
}
2004-08-10 18:35:43 +00:00
static const byte _valid_tileh_slopes [ 4 ] [ 15 ] = {
2004-08-09 17:04:08 +00:00
// set of normal ones
{
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
TRACK_BIT_DIAG1 | TRACK_BIT_DIAG2 | TRACK_BIT_UPPER | TRACK_BIT_LOWER | TRACK_BIT_LEFT | TRACK_BIT_RIGHT ,
TRACK_BIT_RIGHT ,
TRACK_BIT_UPPER ,
TRACK_BIT_DIAG1 ,
2004-08-09 17:04:08 +00:00
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
TRACK_BIT_LEFT ,
2004-08-09 17:04:08 +00:00
0 ,
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
TRACK_BIT_DIAG2 ,
TRACK_BIT_LOWER ,
2004-09-11 09:55:19 +00:00
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
TRACK_BIT_LOWER ,
TRACK_BIT_DIAG2 ,
2004-08-09 17:04:08 +00:00
0 ,
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
TRACK_BIT_LEFT ,
2004-09-11 09:55:19 +00:00
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
TRACK_BIT_DIAG1 ,
TRACK_BIT_UPPER ,
TRACK_BIT_RIGHT ,
2004-08-09 17:04:08 +00:00
} ,
// allowed rail for an evenly raised platform
{
0 ,
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
TRACK_BIT_LEFT ,
TRACK_BIT_LOWER ,
TRACK_BIT_DIAG2 | TRACK_BIT_LOWER | TRACK_BIT_LEFT ,
TRACK_BIT_RIGHT ,
TRACK_BIT_DIAG1 | TRACK_BIT_DIAG2 | TRACK_BIT_UPPER | TRACK_BIT_LOWER | TRACK_BIT_LEFT | TRACK_BIT_RIGHT ,
TRACK_BIT_DIAG1 | TRACK_BIT_LOWER | TRACK_BIT_RIGHT ,
TRACK_BIT_DIAG1 | TRACK_BIT_DIAG2 | TRACK_BIT_UPPER | TRACK_BIT_LOWER | TRACK_BIT_LEFT | TRACK_BIT_RIGHT ,
TRACK_BIT_UPPER ,
TRACK_BIT_DIAG1 | TRACK_BIT_UPPER | TRACK_BIT_LEFT ,
TRACK_BIT_DIAG1 | TRACK_BIT_DIAG2 | TRACK_BIT_UPPER | TRACK_BIT_LOWER | TRACK_BIT_LEFT | TRACK_BIT_RIGHT ,
TRACK_BIT_DIAG1 | TRACK_BIT_DIAG2 | TRACK_BIT_UPPER | TRACK_BIT_LOWER | TRACK_BIT_LEFT | TRACK_BIT_RIGHT ,
TRACK_BIT_DIAG2 | TRACK_BIT_UPPER | TRACK_BIT_RIGHT ,
TRACK_BIT_DIAG1 | TRACK_BIT_DIAG2 | TRACK_BIT_UPPER | TRACK_BIT_LOWER | TRACK_BIT_LEFT | TRACK_BIT_RIGHT ,
TRACK_BIT_DIAG1 | TRACK_BIT_DIAG2 | TRACK_BIT_UPPER | TRACK_BIT_LOWER | TRACK_BIT_LEFT | TRACK_BIT_RIGHT ,
2004-08-09 17:04:08 +00:00
} ,
// allowed rail on coast tile
{
0 ,
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
TRACK_BIT_LEFT ,
TRACK_BIT_LOWER ,
TRACK_BIT_DIAG2 | TRACK_BIT_LEFT | TRACK_BIT_LOWER ,
TRACK_BIT_RIGHT ,
TRACK_BIT_DIAG1 | TRACK_BIT_DIAG2 | TRACK_BIT_UPPER | TRACK_BIT_LOWER | TRACK_BIT_LEFT | TRACK_BIT_RIGHT ,
TRACK_BIT_DIAG1 | TRACK_BIT_RIGHT | TRACK_BIT_LOWER ,
TRACK_BIT_DIAG1 | TRACK_BIT_DIAG2 | TRACK_BIT_UPPER | TRACK_BIT_LOWER | TRACK_BIT_LEFT | TRACK_BIT_RIGHT ,
TRACK_BIT_UPPER ,
TRACK_BIT_DIAG1 | TRACK_BIT_LEFT | TRACK_BIT_UPPER ,
TRACK_BIT_DIAG1 | TRACK_BIT_DIAG2 | TRACK_BIT_UPPER | TRACK_BIT_LOWER | TRACK_BIT_LEFT | TRACK_BIT_RIGHT ,
TRACK_BIT_DIAG1 | TRACK_BIT_DIAG2 | TRACK_BIT_UPPER | TRACK_BIT_LOWER | TRACK_BIT_LEFT | TRACK_BIT_RIGHT ,
TRACK_BIT_DIAG2 | TRACK_BIT_RIGHT | TRACK_BIT_UPPER ,
TRACK_BIT_DIAG1 | TRACK_BIT_DIAG2 | TRACK_BIT_UPPER | TRACK_BIT_LOWER | TRACK_BIT_LEFT | TRACK_BIT_RIGHT ,
TRACK_BIT_DIAG1 | TRACK_BIT_DIAG2 | TRACK_BIT_UPPER | TRACK_BIT_LOWER | TRACK_BIT_LEFT | TRACK_BIT_RIGHT ,
2004-08-10 18:35:43 +00:00
} ,
// valid railway crossings on slopes
{
1 , 0 , 0 , // 0, 1, 2
0 , 0 , 1 , // 3, 4, 5
0 , 1 , 0 , // 6, 7, 8
0 , 1 , 1 , // 9, 10, 11
0 , 1 , 1 , // 12, 13, 14
2004-08-09 17:04:08 +00:00
}
} ;
2004-08-20 09:32:32 +00:00
uint GetRailFoundation ( uint tileh , uint bits )
2004-08-09 17:04:08 +00:00
{
int i ;
if ( ( ~ _valid_tileh_slopes [ 0 ] [ tileh ] & bits ) = = 0 )
return 0 ;
if ( ( ~ _valid_tileh_slopes [ 1 ] [ tileh ] & bits ) = = 0 )
return tileh ;
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
if ( ( ( i = 0 , tileh = = 1 ) | | ( i + = 2 , tileh = = 2 ) | | ( i + = 2 , tileh = = 4 ) | | ( i + = 2 , tileh = = 8 ) ) & & ( bits = = TRACK_BIT_DIAG1 | | ( i + + , bits = = TRACK_BIT_DIAG2 ) ) )
2004-08-09 17:04:08 +00:00
return i + 15 ;
return 0 ;
}
//
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
static uint32 CheckRailSlope ( uint tileh , TrackBits rail_bits , TrackBits existing , TileIndex tile )
2004-08-09 17:04:08 +00:00
{
// never allow building on top of steep tiles
2005-07-16 23:47:37 +00:00
if ( ! IsSteepTileh ( tileh ) ) {
2004-08-09 17:04:08 +00:00
rail_bits | = existing ;
// don't allow building on the lower side of a coast
2005-04-02 18:33:53 +00:00
if ( IsTileType ( tile , MP_WATER ) & &
~ _valid_tileh_slopes [ 2 ] [ tileh ] & rail_bits ) {
2004-08-09 17:04:08 +00:00
return_cmd_error ( STR_3807_CAN_T_BUILD_ON_WATER ) ;
}
// no special foundation
if ( ( ~ _valid_tileh_slopes [ 0 ] [ tileh ] & rail_bits ) = = 0 )
return 0 ;
2004-09-11 09:55:19 +00:00
2005-04-02 18:33:53 +00:00
if ( ( ~ _valid_tileh_slopes [ 1 ] [ tileh ] & rail_bits ) = = 0 | | ( // whole tile is leveled up
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
( rail_bits = = TRACK_BIT_DIAG1 | | rail_bits = = TRACK_BIT_DIAG2 ) & &
2005-04-02 18:33:53 +00:00
( tileh = = 1 | | tileh = = 2 | | tileh = = 4 | | tileh = = 8 )
) ) { // partly up
if ( existing ! = 0 ) {
return 0 ;
2005-09-13 12:19:27 +00:00
} else if ( ! _patches . build_on_slopes | | _is_old_ai_player ) {
2005-04-02 18:33:53 +00:00
return_cmd_error ( STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION ) ;
} else {
return _price . terraform ;
}
2004-08-09 17:04:08 +00:00
}
}
return_cmd_error ( STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION ) ;
}
2005-05-07 10:26:12 +00:00
/* Validate functions for rail building */
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
static inline bool ValParamTrackOrientation ( Track track ) { return IsValidTrack ( track ) ; }
2005-05-07 10:26:12 +00:00
/** Build a single piece of rail
* @ param x , y coordinates on where to build
* @ param p1 railtype of being built piece ( normal , mono , maglev )
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
* @ param p2 rail track to build
2005-05-07 10:26:12 +00:00
*/
int32 CmdBuildSingleRail ( int x , int y , uint32 flags , uint32 p1 , uint32 p2 )
2004-08-09 17:04:08 +00:00
{
2005-04-02 18:33:53 +00:00
TileIndex tile ;
uint tileh ;
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
uint m5 ; /* XXX: Used only as a cache, should probably be removed? */
Track track = ( Track ) p2 ;
TrackBits trackbit ;
2005-04-02 18:33:53 +00:00
int32 cost = 0 ;
int32 ret ;
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
if ( ! ValParamRailtype ( p1 ) | | ! ValParamTrackOrientation ( track ) ) return CMD_ERROR ;
2004-08-09 17:04:08 +00:00
2005-06-25 06:15:43 +00:00
tile = TileVirtXY ( x , y ) ;
2005-04-02 18:33:53 +00:00
tileh = GetTileSlope ( tile , NULL ) ;
2005-07-13 18:04:01 +00:00
m5 = _m [ tile ] . m5 ;
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
trackbit = TrackToTrackBits ( track ) ;
2004-08-09 17:04:08 +00:00
2005-04-02 18:33:53 +00:00
SET_EXPENSES_TYPE ( EXPENSES_CONSTRUCTION ) ;
2004-08-09 17:04:08 +00:00
2005-04-02 18:33:53 +00:00
switch ( GetTileType ( tile ) ) {
case MP_TUNNELBRIDGE :
if ( ( m5 & 0xC0 ) ! = 0xC0 | | // not bridge middle part?
2005-08-25 16:53:51 +00:00
( m5 & 0x01 ? TRACK_BIT_DIAG1 : TRACK_BIT_DIAG2 ) ! = trackbit ) { // wrong direction?
2005-04-02 18:33:53 +00:00
// Get detailed error message
return DoCommandByTile ( tile , 0 , 0 , flags , CMD_LANDSCAPE_CLEAR ) ;
}
2004-08-09 17:04:08 +00:00
2005-04-02 22:04:43 +00:00
switch ( m5 & 0x38 ) { // what's under the bridge?
case 0x00 : // clear land
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
ret = CheckRailSlope ( tileh , trackbit , 0 , tile ) ;
2005-04-14 11:17:36 +00:00
if ( CmdFailed ( ret ) ) return ret ;
2005-04-02 22:04:43 +00:00
cost + = ret ;
if ( flags & DC_EXEC ) {
2005-06-04 12:13:24 +00:00
SetTileOwner ( tile , _current_player ) ;
2005-07-13 18:04:01 +00:00
_m [ tile ] . m3 & = ~ 0x0F ;
_m [ tile ] . m3 | = p1 ;
_m [ tile ] . m5 = ( m5 & 0xC7 ) | 0x20 ; // railroad under bridge
2005-04-02 22:04:43 +00:00
}
break ;
case 0x20 : // rail already there
return_cmd_error ( STR_1007_ALREADY_BUILT ) ;
default :
// Get detailed error message
return DoCommandByTile ( tile , 0 , 0 , flags , CMD_LANDSCAPE_CLEAR ) ;
2005-04-02 18:33:53 +00:00
}
break ;
2004-08-10 18:35:43 +00:00
2005-04-02 18:33:53 +00:00
case MP_RAILWAY :
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
if ( ! CheckTrackCombination ( tile , trackbit , flags ) | |
2005-04-02 18:33:53 +00:00
! EnsureNoVehicle ( tile ) ) {
return CMD_ERROR ;
}
if ( m5 & RAIL_TYPE_SPECIAL | |
2005-06-04 12:14:51 +00:00
! IsTileOwner ( tile , _current_player ) | |
2005-07-13 18:04:01 +00:00
( _m [ tile ] . m3 & 0xFU ) ! = p1 ) {
2005-04-02 18:33:53 +00:00
// Get detailed error message
return DoCommandByTile ( tile , 0 , 0 , flags , CMD_LANDSCAPE_CLEAR ) ;
}
2004-08-10 18:35:43 +00:00
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
ret = CheckRailSlope ( tileh , trackbit , GetTrackBits ( tile ) , tile ) ;
2005-04-14 11:17:36 +00:00
if ( CmdFailed ( ret ) ) return ret ;
2004-08-09 17:04:08 +00:00
cost + = ret ;
2005-04-24 07:56:18 +00:00
if ( flags & DC_EXEC ) {
2005-07-13 18:04:01 +00:00
_m [ tile ] . m2 & = ~ RAIL_MAP2LO_GROUND_MASK ; // Bare land
_m [ tile ] . m5 = m5 | trackbit ;
2005-04-24 07:56:18 +00:00
}
2005-04-02 18:33:53 +00:00
break ;
2004-08-09 17:04:08 +00:00
2005-04-02 18:33:53 +00:00
case MP_STREET :
if ( ! _valid_tileh_slopes [ 3 ] [ tileh ] ) // prevent certain slopes
return_cmd_error ( STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION ) ;
if ( ! EnsureNoVehicle ( tile ) ) return CMD_ERROR ;
if ( ( m5 & 0xF0 ) = = 0 & & ( // normal road?
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
( track = = TRACK_DIAG1 & & m5 = = 0x05 ) | |
( track = = TRACK_DIAG2 & & m5 = = 0x0A ) // correct direction?
2005-04-02 18:33:53 +00:00
) ) {
if ( flags & DC_EXEC ) {
2005-07-13 18:04:01 +00:00
_m [ tile ] . m3 = GetTileOwner ( tile ) ;
2005-06-04 12:13:24 +00:00
SetTileOwner ( tile , _current_player ) ;
2005-07-13 18:04:01 +00:00
_m [ tile ] . m4 = p1 ;
_m [ tile ] . m5 = 0x10 | ( track = = TRACK_DIAG1 ? 0x08 : 0x00 ) ; // level crossing
2005-04-02 18:33:53 +00:00
}
break ;
}
2004-08-09 17:04:08 +00:00
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
if ( IsLevelCrossing ( tile ) & & ( m5 & 0x08 ? TRACK_DIAG1 : TRACK_DIAG2 ) = = track )
2005-04-02 18:33:53 +00:00
return_cmd_error ( STR_1007_ALREADY_BUILT ) ;
/* FALLTHROUGH */
2004-08-09 17:04:08 +00:00
2005-04-02 18:33:53 +00:00
default :
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
ret = CheckRailSlope ( tileh , trackbit , 0 , tile ) ;
2005-04-14 11:17:36 +00:00
if ( CmdFailed ( ret ) ) return ret ;
2005-04-02 18:33:53 +00:00
cost + = ret ;
2004-08-09 17:04:08 +00:00
2005-04-02 18:33:53 +00:00
ret = DoCommandByTile ( tile , 0 , 0 , flags , CMD_LANDSCAPE_CLEAR ) ;
2005-04-14 11:17:36 +00:00
if ( CmdFailed ( ret ) ) return ret ;
2005-04-02 18:33:53 +00:00
cost + = ret ;
2004-08-09 17:04:08 +00:00
2005-04-02 18:33:53 +00:00
if ( flags & DC_EXEC ) {
SetTileType ( tile , MP_RAILWAY ) ;
2005-06-04 12:13:24 +00:00
SetTileOwner ( tile , _current_player ) ;
2005-07-13 18:04:01 +00:00
_m [ tile ] . m2 = 0 ; // Bare land
_m [ tile ] . m3 = p1 ; // No signals, rail type
_m [ tile ] . m5 = trackbit ;
2005-04-02 18:33:53 +00:00
}
break ;
}
2004-08-09 17:04:08 +00:00
2005-04-02 18:33:53 +00:00
if ( flags & DC_EXEC ) {
2004-08-09 17:04:08 +00:00
MarkTileDirtyByTile ( tile ) ;
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
SetSignalsOnBothDir ( tile , track ) ;
2004-08-09 17:04:08 +00:00
}
return cost + _price . build_rail ;
}
static const byte _signals_table [ ] = {
0x40 , 0x40 , 0x40 , 0x10 , 0x80 , 0x20 , 0 , 0 , // direction 1
0x80 , 0x80 , 0x80 , 0x20 , 0x40 , 0x10 , 0 , 0 // direction 2
} ;
static const byte _signals_table_other [ ] = {
0x80 , 0x80 , 0x80 , 0x20 , 0x40 , 0x10 , 0 , 0 , // direction 1
0x40 , 0x40 , 0x40 , 0x10 , 0x80 , 0x20 , 0 , 0 // direction 2
} ;
static const byte _signals_table_both [ ] = {
2004-09-11 09:55:19 +00:00
0xC0 , 0xC0 , 0xC0 , 0x30 , 0xC0 , 0x30 , 0 , 0 , // both directions combined
2004-08-09 17:04:08 +00:00
0xC0 , 0xC0 , 0xC0 , 0x30 , 0xC0 , 0x30 , 0 , 0
} ;
2005-05-07 10:26:12 +00:00
/** Remove a single piece of track
* @ param x , y coordinates for removal of track
* @ param p1 unused
* @ param p2 rail orientation
2004-08-09 17:04:08 +00:00
*/
int32 CmdRemoveSingleRail ( int x , int y , uint32 flags , uint32 p1 , uint32 p2 )
{
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
Track track = ( Track ) p2 ;
TrackBits trackbit ;
uint tileh ;
2005-05-07 10:26:12 +00:00
TileIndex tile ;
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
byte m5 ;
2005-06-21 19:45:05 +00:00
int32 cost = _price . remove_rail ;
2005-05-07 10:26:12 +00:00
if ( ! ValParamTrackOrientation ( p2 ) ) return CMD_ERROR ;
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
trackbit = TrackToTrackBits ( track ) ;
2004-08-09 17:04:08 +00:00
SET_EXPENSES_TYPE ( EXPENSES_CONSTRUCTION ) ;
2005-06-25 06:15:43 +00:00
tile = TileVirtXY ( x , y ) ;
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
tileh = GetTileSlope ( tile , NULL ) ;
2004-08-09 17:04:08 +00:00
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
if ( ! IsTileType ( tile , MP_TUNNELBRIDGE ) & & ! IsTileType ( tile , MP_STREET ) & & ! IsTileType ( tile , MP_RAILWAY ) )
2004-08-09 17:04:08 +00:00
return CMD_ERROR ;
if ( _current_player ! = OWNER_WATER & & ! CheckTileOwnership ( tile ) )
return CMD_ERROR ;
// allow building rail under bridge
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
if ( ! IsTileType ( tile , MP_TUNNELBRIDGE ) & & ! EnsureNoVehicle ( tile ) )
2004-08-09 17:04:08 +00:00
return CMD_ERROR ;
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
switch ( GetTileType ( tile ) )
{
case MP_TUNNELBRIDGE :
if ( ! EnsureNoVehicleZ ( tile , TilePixelHeight ( tile ) ) )
return CMD_ERROR ;
2004-08-09 17:04:08 +00:00
2005-07-13 18:04:01 +00:00
if ( ( _m [ tile ] . m5 & 0xF8 ) ! = 0xE0 )
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
return CMD_ERROR ;
2004-08-09 17:04:08 +00:00
2005-08-25 16:53:51 +00:00
if ( ( _m [ tile ] . m5 & 1 ? TRACK_BIT_DIAG1 : TRACK_BIT_DIAG2 ) ! = trackbit )
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
return CMD_ERROR ;
2004-08-09 17:04:08 +00:00
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
if ( ! ( flags & DC_EXEC ) )
return _price . remove_rail ;
2004-09-11 09:55:19 +00:00
2005-06-04 12:13:24 +00:00
SetTileOwner ( tile , OWNER_NONE ) ;
2005-07-13 18:04:01 +00:00
_m [ tile ] . m5 = _m [ tile ] . m5 & 0xC7 ;
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
break ;
case MP_STREET :
2005-07-13 18:04:01 +00:00
if ( ! ( _m [ tile ] . m5 & 0xF0 ) )
2004-08-09 17:04:08 +00:00
return CMD_ERROR ;
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
2005-07-13 18:04:01 +00:00
if ( _m [ tile ] . m5 & 0xE0 )
2004-08-09 17:04:08 +00:00
return CMD_ERROR ;
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
/* This is a crossing, let's check if the direction is correct */
2005-07-13 18:04:01 +00:00
if ( _m [ tile ] . m5 & 8 ) {
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
m5 = 5 ;
if ( track ! = TRACK_DIAG1 )
return CMD_ERROR ;
} else {
m5 = 10 ;
if ( track ! = TRACK_DIAG2 )
return CMD_ERROR ;
}
2004-08-09 17:04:08 +00:00
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
if ( ! ( flags & DC_EXEC ) )
return _price . remove_rail ;
2004-08-09 17:04:08 +00:00
2005-07-13 18:04:01 +00:00
_m [ tile ] . m5 = m5 ;
SetTileOwner ( tile , _m [ tile ] . m3 ) ;
_m [ tile ] . m2 = 0 ;
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
break ;
case MP_RAILWAY :
2004-08-09 17:04:08 +00:00
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
if ( ! IsPlainRailTile ( tile ) )
return CMD_ERROR ;
2004-08-09 17:04:08 +00:00
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
/* See if the track to remove is actually there */
if ( ! ( GetTrackBits ( tile ) & trackbit ) )
2004-08-09 17:04:08 +00:00
return CMD_ERROR ;
2005-06-21 19:45:05 +00:00
/* Charge extra to remove signals on the track, if they are there */
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
if ( HasSignalOnTrack ( tile , track ) )
2005-06-21 19:45:05 +00:00
cost + = DoCommand ( x , y , track , 0 , flags , CMD_REMOVE_SIGNALS ) ;
2004-08-09 17:04:08 +00:00
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
if ( ! ( flags & DC_EXEC ) )
2005-06-21 19:45:05 +00:00
return cost ;
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
/* We remove the trackbit here. */
2005-07-13 18:04:01 +00:00
_m [ tile ] . m5 & = ~ trackbit ;
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
2005-07-17 18:48:45 +00:00
/* Unreserve track for PBS */
if ( PBSTileReserved ( tile ) & trackbit )
PBSClearTrack ( tile , track ) ;
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
if ( GetTrackBits ( tile ) = = 0 ) {
/* The tile has no tracks left, it is no longer a rail tile */
DoClearSquare ( tile ) ;
/* XXX: This is an optimisation, right? Is it really worth the ugly goto? */
goto skip_mark_dirty ;
}
break ;
default :
assert ( 0 ) ;
2004-08-09 17:04:08 +00:00
}
/* mark_dirty */
MarkTileDirtyByTile ( tile ) ;
skip_mark_dirty : ;
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
SetSignalsOnBothDir ( tile , track ) ;
2004-09-11 09:55:19 +00:00
2005-06-21 19:45:05 +00:00
return cost ;
2004-08-09 17:04:08 +00:00
}
static const struct {
int8 xinc [ 16 ] ;
int8 yinc [ 16 ] ;
} _railbit = { {
2005-01-30 15:57:38 +00:00
// 0 1 2 3 4 5
- 16 , 0 , - 16 , 0 , 16 , 0 , 0 , 0 ,
16 , 0 , 0 , 16 , 0 , - 16 , 0 , 0 ,
2004-08-09 17:04:08 +00:00
} , {
2005-01-30 15:57:38 +00:00
0 , 16 , 0 , 16 , 0 , 16 , 0 , 0 ,
0 , - 16 , - 16 , 0 , - 16 , 0 , 0 , 0 ,
2004-08-09 17:04:08 +00:00
} } ;
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
static int32 ValidateAutoDrag ( Trackdir * trackdir , int x , int y , int ex , int ey )
2005-01-30 15:57:38 +00:00
{
int dx , dy , trdx , trdy ;
2004-08-09 17:04:08 +00:00
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
if ( ! ValParamTrackOrientation ( * trackdir ) ) return CMD_ERROR ;
2004-08-09 17:04:08 +00:00
2005-01-30 15:57:38 +00:00
// calculate delta x,y from start to end tile
dx = ex - x ;
dy = ey - y ;
2004-08-09 17:04:08 +00:00
2005-01-30 15:57:38 +00:00
// calculate delta x,y for the first direction
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
trdx = _railbit . xinc [ * trackdir ] ;
trdy = _railbit . yinc [ * trackdir ] ;
2005-01-30 15:57:38 +00:00
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
if ( ! IsDiagonalTrackdir ( * trackdir ) ) {
trdx + = _railbit . xinc [ * trackdir ^ 1 ] ;
trdy + = _railbit . yinc [ * trackdir ^ 1 ] ;
2005-01-30 15:57:38 +00:00
}
// validate the direction
while ( ( ( trdx < = 0 ) & & ( dx > 0 ) ) | | ( ( trdx > = 0 ) & & ( dx < 0 ) ) | |
( ( trdy < = 0 ) & & ( dy > 0 ) ) | | ( ( trdy > = 0 ) & & ( dy < 0 ) ) ) {
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
if ( ! HASBIT ( * trackdir , 3 ) ) { // first direction is invalid, try the other
SETBIT ( * trackdir , 3 ) ; // reverse the direction
2005-01-30 15:57:38 +00:00
trdx = - trdx ;
trdy = - trdy ;
} else // other direction is invalid too, invalid drag
return CMD_ERROR ;
}
// (for diagonal tracks, this is already made sure of by above test), but:
// for non-diagonal tracks, check if the start and end tile are on 1 line
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
if ( ! IsDiagonalTrackdir ( * trackdir ) ) {
trdx = _railbit . xinc [ * trackdir ] ;
trdy = _railbit . yinc [ * trackdir ] ;
2005-01-30 15:57:38 +00:00
if ( ( abs ( dx ) ! = abs ( dy ) ) & & ( abs ( dx ) + abs ( trdy ) ! = abs ( dy ) + abs ( trdx ) ) )
return CMD_ERROR ;
}
return 0 ;
}
2005-05-07 10:26:12 +00:00
/** Build a stretch of railroad tracks.
* @ param x , y start tile of drag
* @ param p1 end tile of drag
* @ param p2 various bitstuffed elements
* - p2 = ( bit 0 - 3 ) - railroad type normal / maglev ( 0 = normal , 1 = mono , 2 = maglev )
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
* - p2 = ( bit 4 - 6 ) - track - orientation , valid values : 0 - 5 ( Track enum )
2005-05-07 10:26:12 +00:00
* - p2 = ( bit 7 ) - 0 = build , 1 = remove tracks
2005-01-30 15:57:38 +00:00
*/
static int32 CmdRailTrackHelper ( int x , int y , uint32 flags , uint32 p1 , uint32 p2 )
2004-08-09 17:04:08 +00:00
{
2005-01-30 15:57:38 +00:00
int ex , ey ;
2004-08-09 17:04:08 +00:00
int32 ret , total_cost = 0 ;
2005-07-20 15:29:28 +00:00
Track track = ( Track ) GB ( p2 , 4 , 3 ) ;
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
Trackdir trackdir ;
2005-01-30 15:57:38 +00:00
byte mode = HASBIT ( p2 , 7 ) ;
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
if ( ! ValParamRailtype ( p2 & 0x3 ) | | ! ValParamTrackOrientation ( track ) ) return CMD_ERROR ;
2005-05-09 13:26:15 +00:00
if ( p1 > MapSize ( ) ) return CMD_ERROR ;
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
trackdir = TrackToTrackdir ( track ) ;
2005-05-07 10:26:12 +00:00
2005-01-30 15:57:38 +00:00
/* unpack end point */
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
ex = TileX ( p1 ) * TILE_SIZE ;
ey = TileY ( p1 ) * TILE_SIZE ;
2004-08-09 17:04:08 +00:00
2005-01-04 17:11:03 +00:00
SET_EXPENSES_TYPE ( EXPENSES_CONSTRUCTION ) ;
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
if ( CmdFailed ( ValidateAutoDrag ( & trackdir , x , y , ex , ey ) ) ) return CMD_ERROR ;
2004-09-11 09:55:19 +00:00
2005-06-25 06:15:43 +00:00
if ( flags & DC_EXEC ) SndPlayTileFx ( SND_20_SPLAT_2 , TileVirtXY ( x , y ) ) ;
2004-08-09 17:04:08 +00:00
for ( ; ; ) {
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
ret = DoCommand ( x , y , p2 & 0x3 , TrackdirToTrack ( trackdir ) , flags , ( mode = = 0 ) ? CMD_BUILD_SINGLE_RAIL : CMD_REMOVE_SINGLE_RAIL ) ;
2004-08-09 17:04:08 +00:00
2005-05-07 10:26:12 +00:00
if ( CmdFailed ( ret ) ) {
2005-01-30 15:57:38 +00:00
if ( ( _error_message ! = STR_1007_ALREADY_BUILT ) & & ( mode = = 0 ) )
2004-08-09 17:04:08 +00:00
break ;
} else
total_cost + = ret ;
2005-01-30 15:57:38 +00:00
if ( x = = ex & & y = = ey )
2004-08-09 17:04:08 +00:00
break ;
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
x + = _railbit . xinc [ trackdir ] ;
y + = _railbit . yinc [ trackdir ] ;
2004-09-11 09:55:19 +00:00
2005-01-30 15:57:38 +00:00
// toggle railbit for the non-diagonal tracks
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
if ( ! IsDiagonalTrackdir ( trackdir ) ) trackdir ^ = 1 ;
2004-09-11 09:55:19 +00:00
}
2004-08-09 17:04:08 +00:00
2005-05-07 10:26:12 +00:00
return ( total_cost = = 0 ) ? CMD_ERROR : total_cost ;
2004-08-09 17:04:08 +00:00
}
2005-05-12 23:46:01 +00:00
/** Build rail on a stretch of track.
* Stub for the unified rail builder / remover
* @ see CmdRailTrackHelper
*/
2005-01-30 15:57:38 +00:00
int32 CmdBuildRailroadTrack ( int x , int y , uint32 flags , uint32 p1 , uint32 p2 )
{
2005-05-07 10:26:12 +00:00
return CmdRailTrackHelper ( x , y , flags , p1 , CLRBIT ( p2 , 7 ) ) ;
2005-01-30 15:57:38 +00:00
}
2004-08-09 17:04:08 +00:00
2005-05-12 23:46:01 +00:00
/** Build rail on a stretch of track.
* Stub for the unified rail builder / remover
* @ see CmdRailTrackHelper
*/
2004-08-09 17:04:08 +00:00
int32 CmdRemoveRailroadTrack ( int x , int y , uint32 flags , uint32 p1 , uint32 p2 )
{
2005-01-30 15:57:38 +00:00
return CmdRailTrackHelper ( x , y , flags , p1 , SETBIT ( p2 , 7 ) ) ;
2004-08-09 17:04:08 +00:00
}
2005-05-07 10:26:12 +00:00
/** Build a train depot
* @ param x , y position of the train depot
* @ param p1 rail type
2005-07-16 23:47:37 +00:00
* @ param p2 depot direction ( 0 through 3 ) , where 0 is NE , 1 is SE , 2 is SW , 3 is NW
*
* @ todo When checking for the tile slope ,
* distingush between " Flat land required " and " land sloped in wrong direction "
2004-08-09 17:04:08 +00:00
*/
int32 CmdBuildTrainDepot ( int x , int y , uint32 flags , uint32 p1 , uint32 p2 )
{
2005-05-07 10:26:12 +00:00
Depot * d ;
2005-06-25 06:15:43 +00:00
TileIndex tile = TileVirtXY ( x , y ) ;
2004-08-09 17:04:08 +00:00
int32 cost , ret ;
uint tileh ;
SET_EXPENSES_TYPE ( EXPENSES_CONSTRUCTION ) ;
if ( ! EnsureNoVehicle ( tile ) ) return CMD_ERROR ;
2005-05-07 10:26:12 +00:00
/* check railtype and valid direction for depot (0 through 3), 4 in total */
if ( ! ValParamRailtype ( p1 ) | | p2 > 3 ) return CMD_ERROR ;
2004-08-09 17:04:08 +00:00
tileh = GetTileSlope ( tile , NULL ) ;
2005-07-16 23:47:37 +00:00
/* Prohibit construction if
The tile is non - flat AND
1 ) The AI is " old-school "
2 ) build - on - slopes is disabled
3 ) the tile is steep i . e . spans two height levels
4 ) the exit points in the wrong direction
*/
if ( tileh ! = 0 & & (
2005-09-13 12:19:27 +00:00
_is_old_ai_player | |
2005-07-16 23:47:37 +00:00
! _patches . build_on_slopes | |
IsSteepTileh ( tileh ) | |
! CanBuildDepotByTileh ( p2 , tileh )
)
) {
2004-08-09 17:04:08 +00:00
return_cmd_error ( STR_0007_FLAT_LAND_REQUIRED ) ;
}
ret = DoCommandByTile ( tile , 0 , 0 , flags , CMD_LANDSCAPE_CLEAR ) ;
2005-05-07 10:26:12 +00:00
if ( CmdFailed ( ret ) ) return CMD_ERROR ;
2004-08-09 17:04:08 +00:00
cost = ret ;
2005-05-07 10:26:12 +00:00
d = AllocateDepot ( ) ;
if ( d = = NULL )
2004-08-09 17:04:08 +00:00
return CMD_ERROR ;
if ( flags & DC_EXEC ) {
2005-09-14 18:03:38 +00:00
if ( IsLocalPlayer ( ) ) _last_built_train_depot_tile = tile ;
2004-09-11 09:55:19 +00:00
ModifyTile ( tile ,
2004-08-09 17:04:08 +00:00
MP_SETTYPE ( MP_RAILWAY ) |
MP_MAP3LO | MP_MAPOWNER_CURRENT | MP_MAP5 ,
p1 , /* map3_lo */
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
p2 | RAIL_TYPE_DEPOT_WAYPOINT /* map5 */
2004-08-09 17:04:08 +00:00
) ;
2004-09-11 09:55:19 +00:00
2005-05-07 10:26:12 +00:00
d - > xy = tile ;
d - > town_index = ClosestTownFromTile ( tile , ( uint ) - 1 ) - > index ;
2004-08-09 17:04:08 +00:00
SetSignalsOnBothDir ( tile , ( p2 & 1 ) ? 2 : 1 ) ;
}
return cost + _price . build_train_depot ;
}
2005-05-07 10:26:12 +00:00
/** Build signals, alternate between double/single, signal/semaphore,
* pre / exit / combo - signals , and what - else not
* @ param x , y coordinates where signals is being built
* @ param p1 various bitstuffed elements
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
* - p1 = ( bit 0 - 2 ) - track - orientation , valid values : 0 - 5 ( Track enum )
2005-05-07 10:26:12 +00:00
* - p1 = ( bit 3 ) - choose semaphores / signals or cycle normal / pre / exit / combo depending on context
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
* @ param p2 used for CmdBuildManySignals ( ) to copy direction of first signal
* TODO : p2 should be replaced by two bits for " along " and " against " the track .
2004-08-15 20:23:42 +00:00
*/
2005-01-30 15:57:38 +00:00
int32 CmdBuildSingleSignal ( int x , int y , uint32 flags , uint32 p1 , uint32 p2 )
2004-08-09 17:04:08 +00:00
{
2005-06-25 06:15:43 +00:00
TileIndex tile = TileVirtXY ( x , y ) ;
2005-01-22 14:52:20 +00:00
bool semaphore ;
bool pre_signal ;
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
Track track = ( Track ) ( p1 & 0x7 ) ;
2004-08-09 17:04:08 +00:00
byte m5 ;
int32 cost ;
2004-09-11 09:55:19 +00:00
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
// Same bit, used in different contexts
semaphore = pre_signal = HASBIT ( p1 , 3 ) ;
2005-05-07 10:26:12 +00:00
if ( ! ValParamTrackOrientation ( track ) | | ! IsTileType ( tile , MP_RAILWAY ) | | ! EnsureNoVehicle ( tile ) )
2005-01-22 14:52:20 +00:00
return CMD_ERROR ;
2004-09-11 09:55:19 +00:00
2005-05-07 10:26:12 +00:00
/* Protect against invalid signal copying */
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
if ( p2 ! = 0 & & ( p2 & SignalOnTrack ( track ) ) = = 0 ) return CMD_ERROR ;
2004-08-09 17:04:08 +00:00
2005-07-13 18:04:01 +00:00
m5 = _m [ tile ] . m5 ;
2004-09-11 09:55:19 +00:00
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
/* You can only build signals on plain rail tiles, and the selected track must exist */
if ( ! IsPlainRailTile ( tile ) | | ! HasTrack ( tile , track ) ) return CMD_ERROR ;
2004-08-09 17:04:08 +00:00
2005-01-22 14:52:20 +00:00
if ( ! CheckTileOwnership ( tile ) ) return CMD_ERROR ;
2004-08-09 17:04:08 +00:00
2004-08-15 20:23:42 +00:00
_error_message = STR_1005_NO_SUITABLE_RAILROAD_TRACK ;
2004-08-09 17:04:08 +00:00
{
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
/* See if this is a valid track combination for signals, (ie, no overlap) */
TrackBits trackbits = GetTrackBits ( tile ) ;
if ( KILL_FIRST_BIT ( trackbits ) ! = 0 & & /* More than one track present */
trackbits ! = ( TRACK_BIT_UPPER | TRACK_BIT_LOWER ) & & /* Horizontal parallel, non-intersecting tracks */
trackbits ! = ( TRACK_BIT_LEFT | TRACK_BIT_RIGHT ) /* Vertical parallel, non-intersecting tracks */
)
2004-08-09 17:04:08 +00:00
return CMD_ERROR ;
}
2005-01-22 14:52:20 +00:00
SET_EXPENSES_TYPE ( EXPENSES_CONSTRUCTION ) ;
2004-08-09 17:04:08 +00:00
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
if ( ! HasSignalOnTrack ( tile , track ) ) {
2005-01-22 14:52:20 +00:00
// build new signals
2004-08-09 17:04:08 +00:00
cost = _price . build_signals ;
2005-01-19 13:31:46 +00:00
} else {
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
if ( p2 ! = 0 & & semaphore ! = HasSemaphores ( tile , track ) ) {
2005-01-22 14:52:20 +00:00
// convert signals <-> semaphores
cost = _price . build_signals + _price . remove_signals ;
} else {
// it is free to change orientation/pre-exit-combo signals
cost = 0 ;
}
2004-08-09 17:04:08 +00:00
}
if ( flags & DC_EXEC ) {
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
if ( GetRailTileType ( tile ) ! = RAIL_TYPE_SIGNALS ) {
2005-01-22 14:52:20 +00:00
// there are no signals at all on this tile yet
2005-07-13 18:04:01 +00:00
_m [ tile ] . m5 | = RAIL_TYPE_SIGNALS ; // change into signals
_m [ tile ] . m2 | = 0xF0 ; // all signals are on
_m [ tile ] . m3 & = ~ 0xF0 ; // no signals built by default
_m [ tile ] . m4 = semaphore ? 0x08 : 0 ;
2004-08-09 17:04:08 +00:00
}
2005-01-22 14:52:20 +00:00
if ( p2 = = 0 ) {
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
if ( ! HasSignalOnTrack ( tile , track ) ) {
2005-01-22 14:52:20 +00:00
// build new signals
2005-07-13 18:04:01 +00:00
_m [ tile ] . m3 | = SignalOnTrack ( track ) ;
2005-01-22 14:52:20 +00:00
} else {
if ( pre_signal ) {
2005-07-04 14:58:55 +00:00
// cycle between normal -> pre -> exit -> combo -> pbs ->...
byte type = ( ( GetSignalType ( tile , track ) + 1 ) % 5 ) ;
2005-07-13 18:04:01 +00:00
_m [ tile ] . m4 & = ~ 0x07 ;
_m [ tile ] . m4 | = type ;
2005-01-22 14:52:20 +00:00
} else {
// cycle between two-way -> one-way -> one-way -> ...
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
/* TODO: Rewrite switch into something more general */
2005-01-22 14:52:20 +00:00
switch ( track ) {
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
case TRACK_LOWER :
case TRACK_RIGHT : {
2005-07-13 18:04:01 +00:00
byte signal = ( _m [ tile ] . m3 - 0x10 ) & 0x30 ;
2005-01-22 14:52:20 +00:00
if ( signal = = 0 ) signal = 0x30 ;
2005-07-13 18:04:01 +00:00
_m [ tile ] . m3 & = ~ 0x30 ;
_m [ tile ] . m3 | = signal ;
2005-01-22 14:52:20 +00:00
break ;
}
default : {
2005-07-13 18:04:01 +00:00
byte signal = ( _m [ tile ] . m3 - 0x40 ) & 0xC0 ;
2005-01-22 14:52:20 +00:00
if ( signal = = 0 ) signal = 0xC0 ;
2005-07-13 18:04:01 +00:00
_m [ tile ] . m3 & = ~ 0xC0 ;
_m [ tile ] . m3 | = signal ;
2005-01-22 14:52:20 +00:00
break ;
}
}
}
2004-08-15 20:23:42 +00:00
}
2005-01-22 14:52:20 +00:00
} else {
/* If CmdBuildManySignals is called with copying signals, just copy the
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
* direction of the first signal given as parameter by CmdBuildManySignals */
2005-07-13 18:04:01 +00:00
_m [ tile ] . m3 & = ~ SignalOnTrack ( track ) ;
_m [ tile ] . m3 | = p2 & SignalOnTrack ( track ) ;
2004-08-15 20:23:42 +00:00
// convert between signal<->semaphores when dragging
2005-01-22 14:52:20 +00:00
if ( semaphore )
2005-07-13 18:04:01 +00:00
SETBIT ( _m [ tile ] . m4 , 3 ) ;
2005-01-22 14:52:20 +00:00
else
2005-07-13 18:04:01 +00:00
CLRBIT ( _m [ tile ] . m4 , 3 ) ;
2004-08-09 17:04:08 +00:00
}
2004-09-11 09:55:19 +00:00
2004-08-09 17:04:08 +00:00
MarkTileDirtyByTile ( tile ) ;
SetSignalsOnBothDir ( tile , track ) ;
}
return cost ;
}
2005-05-12 23:46:01 +00:00
/** Build many signals by dragging; AutoSignals
* @ param x , y start tile of drag
* @ param p1 end tile of drag
* @ param p2 various bitstuffed elements
* - p2 = ( bit 0 ) - 0 = build , 1 = remove signals
* - p2 = ( bit 3 ) - 0 = signals , 1 = semaphores
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
* - p2 = ( bit 4 - 6 ) - track - orientation , valid values : 0 - 5 ( Track enum )
2005-05-12 23:46:01 +00:00
* - p2 = ( bit 24 - 31 ) - user defined signals_density
2004-08-15 20:23:42 +00:00
*/
2005-01-30 15:57:38 +00:00
static int32 CmdSignalTrackHelper ( int x , int y , uint32 flags , uint32 p1 , uint32 p2 )
2004-08-15 20:23:42 +00:00
{
2005-01-30 15:57:38 +00:00
int ex , ey ;
2004-08-15 20:23:42 +00:00
int32 ret , total_cost , signal_ctr ;
2005-06-19 11:56:07 +00:00
byte signals ;
2005-06-25 06:15:43 +00:00
TileIndex tile = TileVirtXY ( x , y ) ;
2005-05-12 23:46:01 +00:00
bool error = true ;
2005-01-30 15:57:38 +00:00
int mode = p2 & 0x1 ;
2005-07-20 15:29:28 +00:00
Track track = GB ( p2 , 4 , 3 ) ;
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
Trackdir trackdir = TrackToTrackdir ( track ) ;
2005-05-12 23:46:01 +00:00
byte semaphores = ( HASBIT ( p2 , 3 ) ) ? 8 : 0 ;
byte signal_density = ( p2 > > 24 ) ;
if ( p1 > MapSize ( ) ) return CMD_ERROR ;
if ( signal_density = = 0 | | signal_density > 20 ) return CMD_ERROR ;
2004-08-15 20:23:42 +00:00
2005-06-19 11:56:07 +00:00
if ( ! IsTileType ( tile , MP_RAILWAY ) )
return CMD_ERROR ;
2005-01-04 17:11:03 +00:00
SET_EXPENSES_TYPE ( EXPENSES_CONSTRUCTION ) ;
2005-05-12 23:46:01 +00:00
/* for vertical/horizontal tracks, double the given signals density
* since the original amount will be too dense ( shorter tracks ) */
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
if ( ! IsDiagonalTrack ( track ) )
signal_density * = 2 ;
2005-05-12 23:46:01 +00:00
2005-01-30 15:57:38 +00:00
// unpack end tile
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
ex = TileX ( p1 ) * TILE_SIZE ;
ey = TileY ( p1 ) * TILE_SIZE ;
if ( CmdFailed ( ValidateAutoDrag ( & trackdir , x , y , ex , ey ) ) ) return CMD_ERROR ;
2004-08-15 20:23:42 +00:00
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
track = TrackdirToTrack ( trackdir ) ; /* trackdir might have changed, keep track in sync */
2004-08-15 20:23:42 +00:00
// copy the signal-style of the first rail-piece if existing
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
if ( GetRailTileType ( tile ) = = RAIL_TYPE_SIGNALS & & GetTrackBits ( tile ) ! = 0 ) { /* XXX: GetTrackBits check useless? */
2005-07-13 18:04:01 +00:00
signals = _m [ tile ] . m3 & SignalOnTrack ( track ) ;
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
if ( signals = = 0 ) signals = SignalOnTrack ( track ) ; /* Can this actually occur? */
2004-08-15 20:23:42 +00:00
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
semaphores = ( HasSemaphores ( tile , track ) ? 8 : 0 ) ; // copy signal/semaphores style (independent of CTRL)
2005-05-12 23:46:01 +00:00
} else // no signals exist, drag a two-way signal stretch
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
signals = SignalOnTrack ( track ) ;
2004-08-15 20:23:42 +00:00
2005-06-19 11:56:07 +00:00
/* signal_ctr - amount of tiles already processed
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
* signals_density - patch setting to put signal on every Nth tile ( double space on | , - - tracks )
2004-08-15 20:23:42 +00:00
* * * * * * * * * *
2005-06-19 11:56:07 +00:00
* trackdir - trackdir to build with autorail
* semaphores - semaphores or signals
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
* signals - is there a signal / semaphore on the first tile , copy its style ( two - way / single - way )
and convert all others to semaphore / signal
2005-06-19 11:56:07 +00:00
* mode - 1 remove signals , 0 build signals */
2004-08-15 20:23:42 +00:00
signal_ctr = total_cost = 0 ;
2005-05-12 23:46:01 +00:00
for ( ; ; ) {
2004-08-15 20:23:42 +00:00
// only build/remove signals with the specified density
2005-06-19 11:56:07 +00:00
if ( ( signal_ctr % signal_density ) = = 0 ) {
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
ret = DoCommand ( x , y , TrackdirToTrack ( trackdir ) | semaphores , signals , flags , ( mode = = 1 ) ? CMD_REMOVE_SIGNALS : CMD_BUILD_SIGNALS ) ;
2004-08-15 20:23:42 +00:00
2004-12-29 13:13:29 +00:00
/* Abort placement for any other error than NOT_SUITABLE_TRACK
2004-08-15 20:23:42 +00:00
* This includes vehicles on track , competitor ' s tracks , etc . */
2005-05-12 23:46:01 +00:00
if ( CmdFailed ( ret ) ) {
if ( _error_message ! = STR_1005_NO_SUITABLE_RAILROAD_TRACK & & mode ! = 1 ) return CMD_ERROR ;
2004-08-15 20:23:42 +00:00
} else {
error = false ;
total_cost + = ret ;
}
}
2005-05-12 23:46:01 +00:00
if ( ex = = x & & ey = = y ) break ; // reached end of drag
2004-08-15 20:23:42 +00:00
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
x + = _railbit . xinc [ trackdir ] ;
y + = _railbit . yinc [ trackdir ] ;
2004-08-15 20:23:42 +00:00
signal_ctr + + ;
2004-09-11 09:55:19 +00:00
2005-01-30 15:57:38 +00:00
// toggle railbit for the non-diagonal tracks (|, -- tracks)
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
if ( ! IsDiagonalTrackdir ( trackdir ) ) trackdir ^ = 1 ;
2004-08-15 20:23:42 +00:00
}
return ( error ) ? CMD_ERROR : total_cost ;
}
2005-05-12 23:46:01 +00:00
/** Build signals on a stretch of track.
* Stub for the unified signal builder / remover
* @ see CmdSignalTrackHelper
*/
2005-01-30 15:57:38 +00:00
int32 CmdBuildSignalTrack ( int x , int y , uint32 flags , uint32 p1 , uint32 p2 )
{
return CmdSignalTrackHelper ( x , y , flags , p1 , p2 ) ;
}
2005-05-07 10:26:12 +00:00
/** Remove signals
* @ param x , y coordinates where signal is being deleted from
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
* @ param p1 track to remove signal from ( Track enum )
2004-08-09 17:04:08 +00:00
*/
2005-01-30 15:57:38 +00:00
int32 CmdRemoveSingleSignal ( int x , int y , uint32 flags , uint32 p1 , uint32 p2 )
2004-08-09 17:04:08 +00:00
{
2005-06-25 06:15:43 +00:00
TileIndex tile = TileVirtXY ( x , y ) ;
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
Track track = ( Track ) ( p1 & 0x7 ) ;
2004-08-09 17:04:08 +00:00
2005-05-07 10:26:12 +00:00
if ( ! ValParamTrackOrientation ( track ) | | ! IsTileType ( tile , MP_RAILWAY ) | | ! EnsureNoVehicle ( tile ) )
2004-08-09 17:04:08 +00:00
return CMD_ERROR ;
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
if ( ! HasSignalOnTrack ( tile , track ) ) // no signals on track?
2004-08-09 17:04:08 +00:00
return CMD_ERROR ;
2005-05-07 10:26:12 +00:00
/* Only water can remove signals from anyone */
if ( _current_player ! = OWNER_WATER & & ! CheckTileOwnership ( tile ) ) return CMD_ERROR ;
2005-01-19 13:31:46 +00:00
2005-03-18 07:37:32 +00:00
SET_EXPENSES_TYPE ( EXPENSES_CONSTRUCTION ) ;
2005-01-19 13:31:46 +00:00
2004-08-09 17:04:08 +00:00
/* Do it? */
if ( flags & DC_EXEC ) {
2005-07-13 18:04:01 +00:00
_m [ tile ] . m3 & = ~ SignalOnTrack ( track ) ;
2004-09-11 09:55:19 +00:00
2005-01-19 13:31:46 +00:00
/* removed last signal from tile? */
2005-07-13 18:04:01 +00:00
if ( ( _m [ tile ] . m3 & 0xF0 ) = = 0 ) {
_m [ tile ] . m5 & = ~ RAIL_TYPE_SIGNALS ;
_m [ tile ] . m2 & = ~ 0xF0 ;
CLRBIT ( _m [ tile ] . m4 , 3 ) ; // remove any possible semaphores
2005-01-19 13:31:46 +00:00
}
2005-01-23 13:09:35 +00:00
2005-01-19 13:31:46 +00:00
SetSignalsOnBothDir ( tile , track ) ;
2004-08-09 17:04:08 +00:00
MarkTileDirtyByTile ( tile ) ;
}
2004-09-11 09:55:19 +00:00
2004-08-09 17:04:08 +00:00
return _price . remove_signals ;
}
2005-05-12 23:46:01 +00:00
/** Remove signals on a stretch of track.
* Stub for the unified signal builder / remover
* @ see CmdSignalTrackHelper
*/
2005-01-30 15:57:38 +00:00
int32 CmdRemoveSignalTrack ( int x , int y , uint32 flags , uint32 p1 , uint32 p2 )
{
2005-01-30 16:08:19 +00:00
return CmdSignalTrackHelper ( x , y , flags , p1 , SETBIT ( p2 , 0 ) ) ;
2005-01-30 15:57:38 +00:00
}
2005-06-24 12:38:35 +00:00
typedef int32 DoConvertRailProc ( TileIndex tile , uint totype , bool exec ) ;
2004-08-09 17:04:08 +00:00
2005-06-24 12:38:35 +00:00
static int32 DoConvertRail ( TileIndex tile , uint totype , bool exec )
2004-08-09 17:04:08 +00:00
{
if ( ! CheckTileOwnership ( tile ) | | ! EnsureNoVehicle ( tile ) )
return CMD_ERROR ;
// tile is already of requested type?
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
if ( GetRailType ( tile ) = = totype )
2004-08-09 17:04:08 +00:00
return CMD_ERROR ;
// change type.
if ( exec ) {
2005-07-13 18:04:01 +00:00
_m [ tile ] . m3 = ( _m [ tile ] . m3 & 0xF0 ) + totype ;
2004-08-09 17:04:08 +00:00
MarkTileDirtyByTile ( tile ) ;
}
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
return _price . build_rail / 2 ;
2004-08-09 17:04:08 +00:00
}
2005-06-24 12:38:35 +00:00
extern int32 DoConvertStationRail ( TileIndex tile , uint totype , bool exec ) ;
extern int32 DoConvertStreetRail ( TileIndex tile , uint totype , bool exec ) ;
extern int32 DoConvertTunnelBridgeRail ( TileIndex tile , uint totype , bool exec ) ;
2004-08-09 17:04:08 +00:00
2005-05-09 16:37:40 +00:00
/** Convert one rail type to the other. You can convert normal rail to
* monorail / maglev easily or vice - versa .
* @ param ex , ey end tile of rail conversion drag
* @ param p1 start tile of drag
* @ param p2 new railtype to convert to
*/
2004-08-09 17:04:08 +00:00
int32 CmdConvertRail ( int ex , int ey , uint32 flags , uint32 p1 , uint32 p2 )
{
int32 ret , cost , money ;
2005-05-09 16:37:40 +00:00
int sx , sy , x , y ;
2004-08-09 17:04:08 +00:00
2005-01-04 17:11:03 +00:00
SET_EXPENSES_TYPE ( EXPENSES_CONSTRUCTION ) ;
2005-05-09 16:37:40 +00:00
if ( ! ValParamRailtype ( p2 ) ) return CMD_ERROR ;
if ( p1 > MapSize ( ) ) return CMD_ERROR ;
2004-08-09 17:04:08 +00:00
// make sure sx,sy are smaller than ex,ey
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
sx = TileX ( p1 ) * TILE_SIZE ;
sy = TileY ( p1 ) * TILE_SIZE ;
2004-08-09 17:04:08 +00:00
if ( ex < sx ) intswap ( ex , sx ) ;
if ( ey < sy ) intswap ( ey , sy ) ;
2004-09-11 09:55:19 +00:00
2004-08-09 17:04:08 +00:00
money = GetAvailableMoneyForCommand ( ) ;
cost = 0 ;
2005-05-09 16:37:40 +00:00
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
for ( x = sx ; x < = ex ; x + = TILE_SIZE ) {
for ( y = sy ; y < = ey ; y + = TILE_SIZE ) {
2005-06-25 06:15:43 +00:00
TileIndex tile = TileVirtXY ( x , y ) ;
2005-05-09 16:37:40 +00:00
DoConvertRailProc * proc ;
if ( IsTileType ( tile , MP_RAILWAY ) ) proc = DoConvertRail ;
else if ( IsTileType ( tile , MP_STATION ) ) proc = DoConvertStationRail ;
else if ( IsTileType ( tile , MP_STREET ) ) proc = DoConvertStreetRail ;
else if ( IsTileType ( tile , MP_TUNNELBRIDGE ) ) proc = DoConvertTunnelBridgeRail ;
2004-08-09 17:04:08 +00:00
else continue ;
2004-09-11 09:55:19 +00:00
2005-05-09 16:37:40 +00:00
ret = proc ( tile , p2 , false ) ;
if ( CmdFailed ( ret ) ) continue ;
2004-08-09 17:04:08 +00:00
cost + = ret ;
if ( flags & DC_EXEC ) {
if ( ( money - = ret ) < 0 ) { _additional_cash_required = ret ; return cost - ret ; }
2005-05-09 16:37:40 +00:00
proc ( tile , p2 , true ) ;
2004-08-09 17:04:08 +00:00
}
}
}
2005-05-09 16:37:40 +00:00
return ( cost = = 0 ) ? CMD_ERROR : cost ;
2004-08-09 17:04:08 +00:00
}
2005-06-24 12:38:35 +00:00
static int32 RemoveTrainDepot ( TileIndex tile , uint32 flags )
2004-08-09 17:04:08 +00:00
{
2004-09-03 17:57:27 +00:00
if ( ! CheckTileOwnership ( tile ) & & _current_player ! = OWNER_WATER )
2004-08-09 17:04:08 +00:00
return CMD_ERROR ;
if ( ! EnsureNoVehicle ( tile ) )
return CMD_ERROR ;
if ( flags & DC_EXEC ) {
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
int track = TrackdirToTrack ( DiagdirToDiagTrackdir ( GetDepotDirection ( tile , TRANSPORT_RAIL ) ) ) ;
2004-08-09 17:04:08 +00:00
DoDeleteDepot ( tile ) ;
SetSignalsOnBothDir ( tile , track ) ;
}
return _price . remove_train_depot ;
}
2005-03-23 20:02:28 +00:00
static int32 ClearTile_Track ( TileIndex tile , byte flags )
{
int32 cost ;
int32 ret ;
2004-08-09 17:04:08 +00:00
byte m5 ;
2005-07-13 18:04:01 +00:00
m5 = _m [ tile ] . m5 ;
2004-08-09 17:04:08 +00:00
if ( flags & DC_AUTO ) {
if ( m5 & RAIL_TYPE_SPECIAL )
return_cmd_error ( STR_2004_BUILDING_MUST_BE_DEMOLISHED ) ;
2005-06-04 11:56:32 +00:00
if ( ! IsTileOwner ( tile , _current_player ) )
2004-08-09 17:04:08 +00:00
return_cmd_error ( STR_1024_AREA_IS_OWNED_BY_ANOTHER ) ;
return_cmd_error ( STR_1008_MUST_REMOVE_RAILROAD_TRACK ) ;
}
cost = 0 ;
2004-09-11 09:55:19 +00:00
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
switch ( GetRailTileType ( tile ) ) {
2005-03-23 20:02:28 +00:00
case RAIL_TYPE_SIGNALS :
2005-07-13 18:04:01 +00:00
if ( _m [ tile ] . m3 & _signals_table_both [ 0 ] ) {
2005-03-23 20:02:28 +00:00
ret = DoCommandByTile ( tile , 0 , 0 , flags , CMD_REMOVE_SIGNALS ) ;
if ( ret = = CMD_ERROR ) return CMD_ERROR ;
2004-08-09 17:04:08 +00:00
cost + = ret ;
}
2005-07-13 18:04:01 +00:00
if ( _m [ tile ] . m3 & _signals_table_both [ 3 ] ) {
2005-03-23 20:02:28 +00:00
ret = DoCommandByTile ( tile , 3 , 0 , flags , CMD_REMOVE_SIGNALS ) ;
if ( ret = = CMD_ERROR ) return CMD_ERROR ;
cost + = ret ;
}
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
m5 & = TRACK_BIT_MASK ;
2005-03-28 18:59:33 +00:00
if ( ! ( flags & DC_EXEC ) ) {
for ( ; m5 ! = 0 ; m5 > > = 1 ) if ( m5 & 1 ) cost + = _price . remove_rail ;
return cost ;
}
2005-03-23 20:02:28 +00:00
/* FALLTHROUGH */
case RAIL_TYPE_NORMAL : {
uint i ;
for ( i = 0 ; m5 ! = 0 ; i + + , m5 > > = 1 ) {
if ( m5 & 1 ) {
2005-03-28 18:59:33 +00:00
ret = DoCommandByTile ( tile , 0 , i , flags , CMD_REMOVE_SINGLE_RAIL ) ;
if ( ret = = CMD_ERROR ) return CMD_ERROR ;
2005-03-23 20:02:28 +00:00
cost + = ret ;
}
}
return cost ;
2004-08-09 17:04:08 +00:00
}
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
case RAIL_TYPE_DEPOT_WAYPOINT :
2005-03-23 20:02:28 +00:00
switch ( m5 & RAIL_SUBTYPE_MASK ) {
case RAIL_SUBTYPE_DEPOT :
return RemoveTrainDepot ( tile , flags ) ;
case RAIL_SUBTYPE_WAYPOINT :
return RemoveTrainWaypoint ( tile , flags , false ) ;
default :
return CMD_ERROR ;
}
default :
return CMD_ERROR ;
}
2004-08-09 17:04:08 +00:00
}
# include "table/track_land.h"
// used for presignals
2005-06-30 13:24:17 +00:00
static const SpriteID _signal_base_sprites [ 32 ] = {
2004-08-09 17:04:08 +00:00
0x4FB ,
0x1323 ,
0x1333 ,
0x1343 ,
2005-07-04 14:58:55 +00:00
// pbs signals
0x1393 ,
0x13A3 , // not used (yet?)
0x13B3 , // not used (yet?)
0x13C3 , // not used (yet?)
2005-06-30 13:24:17 +00:00
2005-07-04 14:58:55 +00:00
// semaphores
2004-08-09 17:04:08 +00:00
0x1353 ,
0x1363 ,
0x1373 ,
0x1383 ,
2005-07-04 14:58:55 +00:00
// pbs semaphores
0x13D3 ,
0x13E3 , // not used (yet?)
0x13F3 , // not used (yet?)
0x1403 , // not used (yet?)
2005-06-30 13:24:17 +00:00
2004-08-09 17:04:08 +00:00
// mirrored versions
0x4FB ,
0x1323 ,
0x1333 ,
0x1343 ,
2004-09-11 09:55:19 +00:00
2005-07-04 14:58:55 +00:00
// pbs signals
0x1393 ,
0x13A3 , // not used (yet?)
0x13B3 , // not used (yet?)
0x13C3 , // not used (yet?)
// semaphores
0x1446 ,
0x1456 ,
0x1466 ,
0x1476 ,
// pbs semaphores
0x14C6 ,
0x14D6 , // not used (yet?)
0x14E6 , // not used (yet?)
0x14F6 , // not used (yet?)
2004-08-09 17:04:08 +00:00
} ;
// used to determine the side of the road for the signal
static const byte _signal_position [ 24 ] = {
/* original: left side position */
0x58 , 0x1E , 0xE1 , 0xB9 , 0x01 , 0xA3 , 0x4B , 0xEE , 0x3B , 0xD4 , 0x43 , 0xBD ,
/* patch: ride side position */
0x1E , 0xAC , 0x64 , 0xE1 , 0x4A , 0x10 , 0xEE , 0xC5 , 0xDB , 0x34 , 0x4D , 0xB3
} ;
2005-09-18 20:56:44 +00:00
static void DrawSignalHelper ( const TileInfo * ti , byte condition , uint32 image_and_pos )
2004-08-09 17:04:08 +00:00
{
bool otherside = _opt . road_side & _patches . signal_side ;
uint v = _signal_position [ ( image_and_pos & 0xF ) + ( otherside ? 12 : 0 ) ] ;
uint x = ti - > x | ( v & 0xF ) ;
uint y = ti - > y | ( v > > 4 ) ;
2005-07-13 18:04:01 +00:00
uint sprite = _signal_base_sprites [ ( _m [ ti - > tile ] . m4 & 0xF ) + ( otherside ? 0x10 : 0 ) ] + ( image_and_pos > > 4 ) + ( ( condition ! = 0 ) ? 1 : 0 ) ;
2004-08-09 17:04:08 +00:00
AddSortableSpriteToDraw ( sprite , x , y , 1 , 1 , 10 , GetSlopeZ ( x , y ) ) ;
}
static uint32 _drawtile_track_palette ;
2005-09-18 20:56:44 +00:00
static void DrawTrackFence_NW ( const TileInfo * ti )
2004-08-09 17:04:08 +00:00
{
uint32 image = 0x515 ;
if ( ti - > tileh ! = 0 ) {
image = 0x519 ;
if ( ! ( ti - > tileh & 2 ) ) {
image = 0x51B ;
}
}
2004-09-11 09:55:19 +00:00
AddSortableSpriteToDraw ( image | _drawtile_track_palette ,
2004-08-09 17:04:08 +00:00
ti - > x , ti - > y + 1 , 16 , 1 , 4 , ti - > z ) ;
}
2005-09-18 20:56:44 +00:00
static void DrawTrackFence_SE ( const TileInfo * ti )
2004-08-09 17:04:08 +00:00
{
uint32 image = 0x515 ;
if ( ti - > tileh ! = 0 ) {
image = 0x519 ;
if ( ! ( ti - > tileh & 2 ) ) {
image = 0x51B ;
}
}
2004-09-11 09:55:19 +00:00
AddSortableSpriteToDraw ( image | _drawtile_track_palette ,
2004-08-09 17:04:08 +00:00
ti - > x , ti - > y + 15 , 16 , 1 , 4 , ti - > z ) ;
}
2005-09-18 20:56:44 +00:00
static void DrawTrackFence_NW_SE ( const TileInfo * ti )
2004-08-09 17:04:08 +00:00
{
DrawTrackFence_NW ( ti ) ;
DrawTrackFence_SE ( ti ) ;
}
2005-09-18 20:56:44 +00:00
static void DrawTrackFence_NE ( const TileInfo * ti )
2004-08-09 17:04:08 +00:00
{
uint32 image = 0x516 ;
if ( ti - > tileh ! = 0 ) {
image = 0x51A ;
if ( ! ( ti - > tileh & 2 ) ) {
image = 0x51C ;
}
}
2004-09-11 09:55:19 +00:00
AddSortableSpriteToDraw ( image | _drawtile_track_palette ,
2004-08-09 17:04:08 +00:00
ti - > x + 1 , ti - > y , 1 , 16 , 4 , ti - > z ) ;
}
2005-09-18 20:56:44 +00:00
static void DrawTrackFence_SW ( const TileInfo * ti )
2004-08-09 17:04:08 +00:00
{
uint32 image = 0x516 ;
if ( ti - > tileh ! = 0 ) {
image = 0x51A ;
if ( ! ( ti - > tileh & 2 ) ) {
image = 0x51C ;
}
}
2004-09-11 09:55:19 +00:00
AddSortableSpriteToDraw ( image | _drawtile_track_palette ,
2004-08-09 17:04:08 +00:00
ti - > x + 15 , ti - > y , 1 , 16 , 4 , ti - > z ) ;
}
2005-09-18 20:56:44 +00:00
static void DrawTrackFence_NE_SW ( const TileInfo * ti )
2004-08-09 17:04:08 +00:00
{
DrawTrackFence_NE ( ti ) ;
DrawTrackFence_SW ( ti ) ;
}
2005-09-18 20:56:44 +00:00
static void DrawTrackFence_NS_1 ( const TileInfo * ti )
2004-08-09 17:04:08 +00:00
{
int z = ti - > z ;
if ( ti - > tileh & 1 )
z + = 8 ;
AddSortableSpriteToDraw ( 0x517 | _drawtile_track_palette ,
ti - > x + 8 , ti - > y + 8 , 1 , 1 , 4 , z ) ;
}
2005-09-18 20:56:44 +00:00
static void DrawTrackFence_NS_2 ( const TileInfo * ti )
2004-08-09 17:04:08 +00:00
{
int z = ti - > z ;
if ( ti - > tileh & 4 )
z + = 8 ;
AddSortableSpriteToDraw ( 0x517 | _drawtile_track_palette ,
ti - > x + 8 , ti - > y + 8 , 1 , 1 , 4 , z ) ;
}
2005-09-18 20:56:44 +00:00
static void DrawTrackFence_WE_1 ( const TileInfo * ti )
2004-08-09 17:04:08 +00:00
{
int z = ti - > z ;
if ( ti - > tileh & 8 )
z + = 8 ;
AddSortableSpriteToDraw ( 0x518 | _drawtile_track_palette ,
ti - > x + 8 , ti - > y + 8 , 1 , 1 , 4 , z ) ;
}
2005-09-18 20:56:44 +00:00
static void DrawTrackFence_WE_2 ( const TileInfo * ti )
2004-08-09 17:04:08 +00:00
{
int z = ti - > z ;
if ( ti - > tileh & 2 )
z + = 8 ;
AddSortableSpriteToDraw ( 0x518 | _drawtile_track_palette ,
ti - > x + 8 , ti - > y + 8 , 1 , 1 , 4 , z ) ;
}
2005-09-18 20:56:44 +00:00
static void DetTrackDrawProc_Null ( const TileInfo * ti )
2004-08-09 17:04:08 +00:00
{
/* nothing should be here */
}
2005-09-18 20:56:44 +00:00
typedef void DetailedTrackProc ( const TileInfo * ti ) ;
2004-08-09 17:04:08 +00:00
DetailedTrackProc * const _detailed_track_proc [ 16 ] = {
DetTrackDrawProc_Null ,
DetTrackDrawProc_Null ,
2004-09-11 09:55:19 +00:00
2004-08-09 17:04:08 +00:00
DrawTrackFence_NW ,
DrawTrackFence_SE ,
DrawTrackFence_NW_SE ,
2004-09-11 09:55:19 +00:00
2004-08-09 17:04:08 +00:00
DrawTrackFence_NE ,
DrawTrackFence_SW ,
DrawTrackFence_NE_SW ,
2004-09-11 09:55:19 +00:00
2004-08-09 17:04:08 +00:00
DrawTrackFence_NS_1 ,
DrawTrackFence_NS_2 ,
2004-09-11 09:55:19 +00:00
2004-08-09 17:04:08 +00:00
DrawTrackFence_WE_1 ,
DrawTrackFence_WE_2 ,
2004-09-11 09:55:19 +00:00
2004-08-09 17:04:08 +00:00
DetTrackDrawProc_Null ,
DetTrackDrawProc_Null ,
DetTrackDrawProc_Null ,
DetTrackDrawProc_Null ,
} ;
2005-07-31 22:53:57 +00:00
static void DrawSpecialBuilding ( uint32 image , uint32 offset ,
2004-11-14 09:07:15 +00:00
TileInfo * ti ,
byte x , byte y , byte z ,
byte xsize , byte ysize , byte zsize )
{
2005-07-24 15:56:31 +00:00
if ( image & PALETTE_MODIFIER_COLOR )
2004-11-14 09:07:15 +00:00
image | = _drawtile_track_palette ;
2005-07-31 22:53:57 +00:00
image + = offset ;
2004-11-23 22:36:11 +00:00
if ( _display_opt & DO_TRANS_BUILDINGS ) // show transparent depots
2005-07-20 22:05:13 +00:00
MAKE_TRANSPARENT ( image ) ;
2004-11-14 09:07:15 +00:00
AddSortableSpriteToDraw ( image , ti - > x + x , ti - > y + y , xsize , ysize , zsize , ti - > z + z ) ;
}
2005-09-29 20:20:34 +00:00
/**
* Draw ground sprite and track bits
* @ param ti TileInfo
* @ param track TrackBits to draw
* @ param earth Draw as earth
* @ param snow Draw as snow
* @ param flat Always draw foundation
*/
void DrawTrackBits ( TileInfo * ti , TrackBits track , bool earth , bool snow , bool flat )
2004-08-09 17:04:08 +00:00
{
2005-07-29 21:36:02 +00:00
const RailtypeInfo * rti = GetRailTypeInfo ( GetRailType ( ti - > tile ) ) ;
2005-09-29 20:20:34 +00:00
PalSpriteID image ;
bool junction = false ;
// Select the sprite to use.
( image = rti - > base_sprites . track_y , track = = TRACK_BIT_DIAG2 ) | |
( image + + , track = = TRACK_BIT_DIAG1 ) | |
( image + + , track = = TRACK_BIT_UPPER ) | |
( image + + , track = = TRACK_BIT_LOWER ) | |
( image + + , track = = TRACK_BIT_RIGHT ) | |
( image + + , track = = TRACK_BIT_LEFT ) | |
( image + + , track = = ( TRACK_BIT_DIAG1 | TRACK_BIT_DIAG2 ) ) | |
( image = rti - > base_sprites . track_ns , track = = ( TRACK_BIT_UPPER | TRACK_BIT_LOWER ) ) | |
( image + + , track = = ( TRACK_BIT_LEFT | TRACK_BIT_RIGHT ) ) | |
( junction = true , false ) | |
( image = rti - > base_sprites . ground , ! ( track & ( TRACK_BIT_RIGHT | TRACK_BIT_UPPER | TRACK_BIT_DIAG1 ) ) ) | |
( image + + , ! ( track & ( TRACK_BIT_LEFT | TRACK_BIT_LOWER | TRACK_BIT_DIAG1 ) ) ) | |
( image + + , ! ( track & ( TRACK_BIT_LEFT | TRACK_BIT_UPPER | TRACK_BIT_DIAG2 ) ) ) | |
( image + + , ! ( track & ( TRACK_BIT_RIGHT | TRACK_BIT_LOWER | TRACK_BIT_DIAG2 ) ) ) | |
( image + + , true ) ;
2004-08-09 17:04:08 +00:00
2005-09-29 20:20:34 +00:00
if ( ti - > tileh ! = 0 ) {
int foundation ;
2004-09-11 09:55:19 +00:00
2005-09-29 20:20:34 +00:00
if ( flat ) {
foundation = ti - > tileh ;
} else {
foundation = GetRailFoundation ( ti - > tileh , track ) ;
}
2004-08-09 17:04:08 +00:00
2005-09-29 20:20:34 +00:00
if ( foundation ! = 0 )
DrawFoundation ( ti , foundation ) ;
2004-09-11 09:55:19 +00:00
2005-09-29 20:20:34 +00:00
// DrawFoundation() modifies ti.
// Default sloped sprites..
if ( ti - > tileh ! = 0 )
image = _track_sloped_sprites [ ti - > tileh - 1 ] + rti - > base_sprites . track_y ;
}
2004-09-11 09:55:19 +00:00
2005-09-29 20:20:34 +00:00
if ( earth ) {
image = ( image & SPRITE_MASK ) | PALETTE_TO_BARE_LAND ; // Use brown palette
} else if ( snow ) {
image + = rti - > snow_offset ;
}
2004-08-09 17:04:08 +00:00
2005-09-29 20:20:34 +00:00
DrawGroundSprite ( image ) ;
2004-08-09 17:04:08 +00:00
2005-09-29 20:20:34 +00:00
// Draw track pieces individually for junction tiles
if ( junction ) {
if ( track & TRACK_BIT_DIAG1 ) DrawGroundSprite ( rti - > base_sprites . single_y ) ;
if ( track & TRACK_BIT_DIAG2 ) DrawGroundSprite ( rti - > base_sprites . single_x ) ;
if ( track & TRACK_BIT_UPPER ) DrawGroundSprite ( rti - > base_sprites . single_n ) ;
if ( track & TRACK_BIT_LOWER ) DrawGroundSprite ( rti - > base_sprites . single_s ) ;
if ( track & TRACK_BIT_LEFT ) DrawGroundSprite ( rti - > base_sprites . single_w ) ;
if ( track & TRACK_BIT_RIGHT ) DrawGroundSprite ( rti - > base_sprites . single_e ) ;
}
2004-09-11 09:55:19 +00:00
2005-09-29 20:20:34 +00:00
if ( _debug_pbs_level > = 1 ) {
byte pbs = PBSTileReserved ( ti - > tile ) & track ;
if ( pbs & TRACK_BIT_DIAG1 ) DrawGroundSprite ( rti - > base_sprites . single_y | PALETTE_CRASH ) ;
if ( pbs & TRACK_BIT_DIAG2 ) DrawGroundSprite ( rti - > base_sprites . single_x | PALETTE_CRASH ) ;
if ( pbs & TRACK_BIT_UPPER ) DrawGroundSprite ( rti - > base_sprites . single_n | PALETTE_CRASH ) ;
if ( pbs & TRACK_BIT_LOWER ) DrawGroundSprite ( rti - > base_sprites . single_s | PALETTE_CRASH ) ;
if ( pbs & TRACK_BIT_LEFT ) DrawGroundSprite ( rti - > base_sprites . single_w | PALETTE_CRASH ) ;
if ( pbs & TRACK_BIT_RIGHT ) DrawGroundSprite ( rti - > base_sprites . single_e | PALETTE_CRASH ) ;
}
}
2004-08-09 17:04:08 +00:00
2005-09-29 20:20:34 +00:00
static void DrawTile_Track ( TileInfo * ti )
{
byte m5 ;
const RailtypeInfo * rti = GetRailTypeInfo ( GetRailType ( ti - > tile ) ) ;
PalSpriteID image ;
2004-08-09 17:04:08 +00:00
2005-09-29 20:20:34 +00:00
_drawtile_track_palette = SPRITE_PALETTE ( PLAYER_SPRITE_COLOR ( GetTileOwner ( ti - > tile ) ) ) ;
2004-08-09 17:04:08 +00:00
2005-09-29 20:20:34 +00:00
m5 = ( byte ) ti - > map5 ;
if ( ! ( m5 & RAIL_TYPE_SPECIAL ) ) {
bool earth = ( _m [ ti - > tile ] . m2 & RAIL_MAP2LO_GROUND_MASK ) = = RAIL_GROUND_BROWN ;
bool snow = ( _m [ ti - > tile ] . m2 & RAIL_MAP2LO_GROUND_MASK ) = = RAIL_GROUND_ICE_DESERT ;
2004-08-09 17:04:08 +00:00
2005-09-29 20:20:34 +00:00
DrawTrackBits ( ti , m5 & TRACK_BIT_MASK , earth , snow , false ) ;
2005-07-04 14:58:55 +00:00
2004-08-09 17:04:08 +00:00
if ( _display_opt & DO_FULL_DETAIL ) {
2005-07-13 18:04:01 +00:00
_detailed_track_proc [ _m [ ti - > tile ] . m2 & RAIL_MAP2LO_GROUND_MASK ] ( ti ) ;
2004-08-09 17:04:08 +00:00
}
/* draw signals also? */
if ( ! ( ti - > map5 & RAIL_TYPE_SIGNALS ) )
return ;
{
byte m23 ;
2005-07-13 18:04:01 +00:00
m23 = ( _m [ ti - > tile ] . m3 > > 4 ) | ( _m [ ti - > tile ] . m2 & 0xF0 ) ;
2004-08-09 17:04:08 +00:00
# define HAS_SIGNAL(x) (m23 & (byte)(0x1 << (x)))
# define ISON_SIGNAL(x) (m23 & (byte)(0x10 << (x)))
# define MAYBE_DRAW_SIGNAL(x,y,z) if (HAS_SIGNAL(x)) DrawSignalHelper(ti, ISON_SIGNAL(x), ((y-0x4FB) << 4)|(z))
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
if ( ! ( m5 & TRACK_BIT_DIAG2 ) ) {
if ( ! ( m5 & TRACK_BIT_DIAG1 ) ) {
if ( m5 & TRACK_BIT_LEFT ) {
2004-08-09 17:04:08 +00:00
MAYBE_DRAW_SIGNAL ( 2 , 0x509 , 0 ) ;
MAYBE_DRAW_SIGNAL ( 3 , 0x507 , 1 ) ;
}
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
if ( m5 & TRACK_BIT_RIGHT ) {
2004-08-09 17:04:08 +00:00
MAYBE_DRAW_SIGNAL ( 0 , 0x509 , 2 ) ;
MAYBE_DRAW_SIGNAL ( 1 , 0x507 , 3 ) ;
}
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
if ( m5 & TRACK_BIT_UPPER ) {
2004-08-09 17:04:08 +00:00
MAYBE_DRAW_SIGNAL ( 3 , 0x505 , 4 ) ;
MAYBE_DRAW_SIGNAL ( 2 , 0x503 , 5 ) ;
}
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
if ( m5 & TRACK_BIT_LOWER ) {
2004-08-09 17:04:08 +00:00
MAYBE_DRAW_SIGNAL ( 1 , 0x505 , 6 ) ;
MAYBE_DRAW_SIGNAL ( 0 , 0x503 , 7 ) ;
}
} else {
MAYBE_DRAW_SIGNAL ( 3 , 0x4FB , 8 ) ;
MAYBE_DRAW_SIGNAL ( 2 , 0x4FD , 9 ) ;
}
} else {
MAYBE_DRAW_SIGNAL ( 3 , 0x4FF , 10 ) ;
MAYBE_DRAW_SIGNAL ( 2 , 0x501 , 11 ) ;
}
}
} else {
2004-11-14 13:07:07 +00:00
/* draw depots / waypoints */
2004-08-09 17:04:08 +00:00
const DrawTrackSeqStruct * drss ;
2004-11-14 13:07:07 +00:00
byte type = m5 & 0x3F ; // 0-3: depots, 4-5: waypoints
2004-08-09 17:04:08 +00:00
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
if ( ! ( m5 & ( RAIL_TILE_TYPE_MASK & ~ RAIL_TYPE_SPECIAL ) ) )
/* XXX: There used to be "return;" here, but since I could not find out
* why this would ever occur , I put assert ( 0 ) here . Let ' s see if someone
* complains about it . If not , we ' ll remove this check . ( Matthijs ) . */
assert ( 0 ) ;
2004-09-11 09:55:19 +00:00
2004-08-09 17:04:08 +00:00
if ( ti - > tileh ! = 0 ) { DrawFoundation ( ti , ti - > tileh ) ; }
2005-07-31 22:53:57 +00:00
if ( IsRailWaypoint ( m5 ) & & HASBIT ( _m [ ti - > tile ] . m3 , 4 ) ) {
2004-11-14 09:07:15 +00:00
// look for customization
2005-07-13 18:04:01 +00:00
StationSpec * stat = GetCustomStation ( STAT_CLASS_WAYP , _m [ ti - > tile ] . m4 ) ;
2004-11-14 09:07:15 +00:00
2004-11-14 16:11:48 +00:00
if ( stat ) {
2004-11-14 09:07:15 +00:00
DrawTileSeqStruct const * seq ;
2004-11-14 16:11:48 +00:00
// emulate station tile - open with building
DrawTileSprites * cust = & stat - > renderdata [ 2 + ( m5 & 0x1 ) ] ;
2004-11-14 20:50:38 +00:00
uint32 relocation = GetCustomStationRelocation ( stat , ComposeWaypointStation ( ti - > tile ) , 0 ) ;
2004-11-14 22:10:08 +00:00
2004-11-17 15:14:18 +00:00
/* We don't touch the 0x8000 bit. In all this
* waypoint code , it is used to indicate that
* we should offset by railtype , but we always
* do that for custom ground sprites and never
* for station sprites . And in the drawing
* code , it is used to indicate that the sprite
* should be drawn in company colors , and it ' s
* up to the GRF file to decide that . */
2004-11-14 22:30:46 +00:00
image = cust - > ground_sprite ;
2005-07-31 22:53:57 +00:00
image + = ( image < _custom_sprites_base ) ? rti - > total_offset : GetRailType ( ti - > tile ) ;
2004-11-14 09:07:15 +00:00
DrawGroundSprite ( image ) ;
foreach_draw_tile_seq ( seq , cust - > seq ) {
2004-11-14 16:11:48 +00:00
uint32 image = seq - > image + relocation ;
2004-11-17 15:14:18 +00:00
DrawSpecialBuilding ( image , 0 , ti ,
2004-11-14 09:07:15 +00:00
seq - > delta_x , seq - > delta_y , seq - > delta_z ,
seq - > width , seq - > height , seq - > unk ) ;
}
return ;
}
}
2005-02-22 18:27:57 +00:00
drss = _track_depot_layout_table [ type ] ;
2004-08-09 17:04:08 +00:00
2005-02-22 18:27:57 +00:00
image = drss + + - > image ;
2005-07-31 22:53:57 +00:00
/* @note This is kind of an ugly hack, as the PALETTE_MODIFIER_COLOR indicates
* whether the sprite is railtype dependent . Rewrite this asap */
if ( image & PALETTE_MODIFIER_COLOR ) image = ( image & SPRITE_MASK ) + rti - > total_offset ;
2004-08-09 17:04:08 +00:00
// adjust ground tile for desert
2004-09-17 20:56:28 +00:00
// (don't adjust for arctic depots, because snow in depots looks weird)
2005-07-31 22:53:57 +00:00
// type >= 4 means waypoints
if ( ( _m [ ti - > tile ] . m2 & RAIL_MAP2LO_GROUND_MASK ) = = RAIL_GROUND_ICE_DESERT & & ( _opt . landscape = = LT_DESERT | | type > = 4 ) ) {
if ( image ! = SPR_FLAT_GRASS_TILE )
image + = rti - > snow_offset ; // tile with tracks
2004-08-09 17:04:08 +00:00
else
2005-07-31 22:53:57 +00:00
image = SPR_FLAT_SNOWY_TILE ; // flat ground
2004-08-09 17:04:08 +00:00
}
DrawGroundSprite ( image ) ;
2005-07-04 14:58:55 +00:00
if ( _debug_pbs_level > = 1 ) {
byte pbs = PBSTileReserved ( ti - > tile ) ;
2005-07-31 22:53:57 +00:00
if ( pbs & TRACK_BIT_DIAG1 ) DrawGroundSprite ( rti - > base_sprites . single_y | PALETTE_CRASH ) ;
if ( pbs & TRACK_BIT_DIAG2 ) DrawGroundSprite ( rti - > base_sprites . single_x | PALETTE_CRASH ) ;
if ( pbs & TRACK_BIT_UPPER ) DrawGroundSprite ( rti - > base_sprites . single_n | PALETTE_CRASH ) ;
if ( pbs & TRACK_BIT_LOWER ) DrawGroundSprite ( rti - > base_sprites . single_s | PALETTE_CRASH ) ;
if ( pbs & TRACK_BIT_LEFT ) DrawGroundSprite ( rti - > base_sprites . single_w | PALETTE_CRASH ) ;
if ( pbs & TRACK_BIT_RIGHT ) DrawGroundSprite ( rti - > base_sprites . single_e | PALETTE_CRASH ) ;
2005-07-04 14:58:55 +00:00
}
2005-07-31 22:53:57 +00:00
while ( ( image = drss - > image ) ! = 0 ) {
DrawSpecialBuilding ( image , type < 4 ? rti - > total_offset : 0 , ti ,
2004-11-14 09:07:15 +00:00
drss - > subcoord_x , drss - > subcoord_y , 0 ,
drss - > width , drss - > height , 0x17 ) ;
2004-08-09 17:04:08 +00:00
drss + + ;
}
}
}
void DrawTrainDepotSprite ( int x , int y , int image , int railtype )
{
uint32 ormod , img ;
2005-07-31 22:53:57 +00:00
const RailtypeInfo * rti = GetRailTypeInfo ( railtype ) ;
2004-08-09 17:04:08 +00:00
const DrawTrackSeqStruct * dtss ;
ormod = PLAYER_SPRITE_COLOR ( _local_player ) ;
2005-02-22 18:27:57 +00:00
dtss = _track_depot_layout_table [ image ] ;
2004-08-09 17:04:08 +00:00
x + = 33 ;
y + = 17 ;
2005-02-22 18:27:57 +00:00
img = dtss + + - > image ;
2005-07-31 22:53:57 +00:00
/* @note This is kind of an ugly hack, as the PALETTE_MODIFIER_COLOR indicates
* whether the sprite is railtype dependent . Rewrite this asap */
if ( img & PALETTE_MODIFIER_COLOR ) img = ( img & SPRITE_MASK ) + rti - > total_offset ;
2004-08-09 17:04:08 +00:00
DrawSprite ( img , x , y ) ;
2005-02-22 18:27:57 +00:00
for ( ; dtss - > image ! = 0 ; dtss + + ) {
2004-08-09 17:04:08 +00:00
Point pt = RemapCoords ( dtss - > subcoord_x , dtss - > subcoord_y , 0 ) ;
image = dtss - > image ;
2005-07-24 15:56:31 +00:00
if ( image & PALETTE_MODIFIER_COLOR ) image | = ormod ;
2005-07-31 22:53:57 +00:00
DrawSprite ( image + rti - > total_offset , x + pt . x , y + pt . y ) ;
2004-08-09 17:04:08 +00:00
}
}
2005-08-01 16:31:19 +00:00
void DrawDefaultWaypointSprite ( int x , int y , int railtype )
{
const DrawTrackSeqStruct * dtss = _track_depot_layout_table [ 4 ] ;
const RailtypeInfo * rti = GetRailTypeInfo ( railtype ) ;
uint32 img ;
img = dtss + + - > image ;
if ( img & PALETTE_MODIFIER_COLOR ) img = ( img & SPRITE_MASK ) + rti - > total_offset ;
DrawSprite ( img , x , y ) ;
for ( ; dtss - > image ! = 0 ; dtss + + ) {
Point pt = RemapCoords ( dtss - > subcoord_x , dtss - > subcoord_y , 0 ) ;
img = dtss - > image ;
if ( img & PALETTE_MODIFIER_COLOR ) img | = PLAYER_SPRITE_COLOR ( _local_player ) ;
DrawSprite ( img , x + pt . x , y + pt . y ) ;
}
}
2004-08-09 17:04:08 +00:00
typedef struct SetSignalsData {
int cur ;
int cur_stack ;
bool stop ;
bool has_presignal ;
2004-09-11 09:55:19 +00:00
2005-07-04 14:58:55 +00:00
bool has_pbssignal ;
// lowest 2 bits = amount of pbs signals in the block, clamped at 2
// bit 2 = there is a pbs entry signal in this block
// bit 3 = there is a pbs exit signal in this block
2004-08-09 17:04:08 +00:00
// presignal info
int presignal_exits ;
int presignal_exits_free ;
// these are used to keep track of the signals that change.
byte bit [ NUM_SSD_ENTRY ] ;
TileIndex tile [ NUM_SSD_ENTRY ] ;
2005-07-04 14:58:55 +00:00
int pbs_cur ;
// these are used to keep track of all signals in the block
TileIndex pbs_tile [ NUM_SSD_ENTRY ] ;
2004-08-09 17:04:08 +00:00
// these are used to keep track of the stack that modifies presignals recursively
TileIndex next_tile [ NUM_SSD_STACK ] ;
byte next_dir [ NUM_SSD_STACK ] ;
} SetSignalsData ;
2005-06-24 12:38:35 +00:00
static bool SetSignalsEnumProc ( TileIndex tile , SetSignalsData * ssd , int track , uint length , byte * state )
2004-08-09 17:04:08 +00:00
{
// the tile has signals?
2005-01-16 11:24:58 +00:00
if ( IsTileType ( tile , MP_RAILWAY ) ) {
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
if ( HasSignalOnTrack ( tile , TrackdirToTrack ( track ) ) ) {
2005-07-13 18:04:01 +00:00
if ( ( _m [ tile ] . m3 & _signals_table [ track ] ) ! = 0 ) {
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
// yes, add the signal to the list of signals
if ( ssd - > cur ! = NUM_SSD_ENTRY ) {
ssd - > tile [ ssd - > cur ] = tile ; // remember the tile index
ssd - > bit [ ssd - > cur ] = track ; // and the controlling bit number
ssd - > cur + + ;
2004-08-09 17:04:08 +00:00
}
2004-09-11 09:55:19 +00:00
2005-07-04 14:58:55 +00:00
if ( PBSIsPbsSignal ( tile , ReverseTrackdir ( track ) ) )
SETBIT ( ssd - > has_pbssignal , 2 ) ;
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
// remember if this block has a presignal.
2005-07-13 18:04:01 +00:00
ssd - > has_presignal | = ( _m [ tile ] . m4 & 1 ) ;
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
}
2004-08-09 17:04:08 +00:00
2005-07-04 14:58:55 +00:00
if ( PBSIsPbsSignal ( tile , ReverseTrackdir ( track ) ) | | PBSIsPbsSignal ( tile , track ) ) {
byte num = ssd - > has_pbssignal & 3 ;
num = clamp ( num + 1 , 0 , 2 ) ;
ssd - > has_pbssignal & = ~ 3 ;
ssd - > has_pbssignal | = num ;
}
2005-07-13 18:04:01 +00:00
if ( ( _m [ tile ] . m3 & _signals_table_both [ track ] ) ! = 0 ) {
2005-07-04 14:58:55 +00:00
ssd - > pbs_tile [ ssd - > pbs_cur ] = tile ; // remember the tile index
ssd - > pbs_cur + + ;
}
2005-07-13 18:04:01 +00:00
if ( _m [ tile ] . m3 & _signals_table_other [ track ] ) {
if ( _m [ tile ] . m4 & 2 ) {
2005-07-04 14:58:55 +00:00
// this is an exit signal that points out from the segment
ssd - > presignal_exits + + ;
2005-07-13 18:04:01 +00:00
if ( ( _m [ tile ] . m2 & _signals_table_other [ track ] ) ! = 0 )
2005-07-04 14:58:55 +00:00
ssd - > presignal_exits_free + + ;
}
if ( PBSIsPbsSignal ( tile , track ) )
SETBIT ( ssd - > has_pbssignal , 3 ) ;
2004-08-09 17:04:08 +00:00
}
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
return true ;
} else if ( IsTileDepotType ( tile , TRANSPORT_RAIL ) )
2004-08-09 17:04:08 +00:00
return true ; // don't look further if the tile is a depot
}
return false ;
}
2005-03-25 13:37:37 +00:00
/* Struct to parse data from VehicleFromPos to SignalVehicleCheckProc */
typedef struct SignalVehicleCheckStruct {
TileIndex tile ;
uint track ;
} SignalVehicleCheckStruct ;
static void * SignalVehicleCheckProc ( Vehicle * v , void * data )
{
SignalVehicleCheckStruct * dest = data ;
TileIndex tile ;
2005-03-31 12:39:18 +00:00
if ( v - > type ! = VEH_Train )
return NULL ;
2005-03-25 13:37:37 +00:00
/* Find the tile outside the tunnel, for signalling */
2005-03-31 12:39:18 +00:00
if ( v - > u . rail . track = = 0x40 )
2005-03-25 13:37:37 +00:00
tile = GetVehicleOutOfTunnelTile ( v ) ;
2005-03-31 12:39:18 +00:00
else
2005-03-25 13:37:37 +00:00
tile = v - > tile ;
/* Wrong tile, or no train? Not a match */
2005-03-31 12:39:18 +00:00
if ( tile ! = dest - > tile )
2005-03-25 13:37:37 +00:00
return NULL ;
/* Are we on the same piece of track? */
if ( dest - > track & ( v - > u . rail . track + ( v - > u . rail . track < < 8 ) ) )
return v ;
return NULL ;
}
/* Special check for SetSignalsAfterProc, to see if there is a vehicle on this tile */
bool SignalVehicleCheck ( TileIndex tile , uint track )
{
SignalVehicleCheckStruct dest ;
dest . tile = tile ;
dest . track = track ;
2005-05-15 16:30:02 +00:00
/** @todo "Hackish" fix for the tunnel problems. This is needed because a tunnel
* is some kind of invisible black hole , and there is some special magic going
* on in there . This ' workaround ' can be removed once the maprewrite is done .
*/
2005-07-13 18:04:01 +00:00
if ( GetTileType ( tile ) = = MP_TUNNELBRIDGE & & ( ( _m [ tile ] . m5 & 0xF0 ) = = 0 ) ) {
2005-05-15 13:48:23 +00:00
// It is a tunnel we're checking, we need to do some special stuff
// because VehicleFromPos will not find the vihicle otherwise
2005-07-13 18:04:01 +00:00
byte direction = _m [ tile ] . m5 & 3 ;
2005-05-15 13:48:23 +00:00
FindLengthOfTunnelResult flotr ;
flotr = FindLengthOfTunnel ( tile , direction ) ;
dest . track = 1 < < ( direction & 1 ) ; // get the trackbit the vehicle would have if it has not entered the tunnel yet (ie is still visible)
// check for a vehicle with that trackdir on the start tile of the tunnel
2005-05-15 16:30:02 +00:00
if ( VehicleFromPos ( tile , & dest , SignalVehicleCheckProc ) ! = NULL ) return true ;
2005-05-15 13:48:23 +00:00
// check for a vehicle with that trackdir on the end tile of the tunnel
2005-05-15 16:30:02 +00:00
if ( VehicleFromPos ( flotr . tile , & dest , SignalVehicleCheckProc ) ! = NULL ) return true ;
2005-05-15 13:48:23 +00:00
// now check all tiles from start to end for a "hidden" vehicle
// NOTE: the hashes for tiles may overlap, so this could maybe be optimised a bit by not checking every tile?
dest . track = 0x40 ; // trackbit for vehicles "hidden" inside a tunnel
for ( ; tile ! = flotr . tile ; tile + = TileOffsByDir ( direction ) ) {
if ( VehicleFromPos ( tile , & dest , SignalVehicleCheckProc ) ! = NULL )
return true ;
}
// no vehicle found
return false ;
2005-05-15 16:30:02 +00:00
}
return VehicleFromPos ( tile , & dest , SignalVehicleCheckProc ) ! = NULL ;
2005-03-25 13:37:37 +00:00
}
2004-08-09 17:04:08 +00:00
static void SetSignalsAfterProc ( TrackPathFinder * tpf )
{
SetSignalsData * ssd = tpf - > userdata ;
TrackPathFinderLink * link ;
2005-03-25 13:37:37 +00:00
uint offs ;
uint i ;
2004-08-09 17:04:08 +00:00
ssd - > stop = false ;
2004-09-11 09:55:19 +00:00
2005-03-25 13:37:37 +00:00
/* Go through all the PF tiles */
for ( i = 0 ; i < lengthof ( tpf - > hash_head ) ; i + + ) {
/* Empty hash item */
if ( tpf - > hash_head [ i ] = = 0 )
2004-08-09 17:04:08 +00:00
continue ;
2005-03-25 13:37:37 +00:00
/* If 0x8000 is not set, there is only 1 item */
if ( ! ( tpf - > hash_head [ i ] & 0x8000 ) ) {
/* Check if there is a vehicle on this tile */
if ( SignalVehicleCheck ( tpf - > hash_tile [ i ] , tpf - > hash_head [ i ] ) ) {
ssd - > stop = true ;
return ;
}
2004-08-09 17:04:08 +00:00
} else {
2005-03-25 13:37:37 +00:00
/* There are multiple items, where hash_tile points to the first item in the list */
offs = tpf - > hash_tile [ i ] ;
2004-08-09 17:04:08 +00:00
do {
2005-03-25 13:37:37 +00:00
/* Find the next item */
2004-08-09 17:04:08 +00:00
link = PATHFIND_GET_LINK_PTR ( tpf , offs ) ;
2005-03-25 13:37:37 +00:00
/* Check if there is a vehicle on this tile */
if ( SignalVehicleCheck ( link - > tile , link - > flags ) ) {
ssd - > stop = true ;
return ;
2004-08-09 17:04:08 +00:00
}
2005-03-25 13:37:37 +00:00
/* Goto the next item */
2004-08-09 17:04:08 +00:00
} while ( ( offs = link - > next ) ! = 0xFFFF ) ;
}
}
}
static const byte _dir_from_track [ 14 ] = {
0 , 1 , 0 , 1 , 2 , 1 , 0 , 0 ,
2 , 3 , 3 , 2 , 3 , 0 ,
} ;
static void ChangeSignalStates ( SetSignalsData * ssd )
{
int i ;
// thinking about presignals...
// the presignal is green if,
// if no train is in the segment AND
// there is at least one green exit signal OR
// there are no exit signals in the segment
2005-07-04 14:58:55 +00:00
// convert the block to pbs, if needed
if ( _patches . auto_pbs_placement & & ! ( ssd - > stop ) & & ( ssd - > has_pbssignal = = 0xE ) & & ! ssd - > has_presignal & & ( ssd - > presignal_exits = = 0 ) ) // 0xE means at least 2 pbs signals, and at least 1 entry and 1 exit, see comments ssd->has_pbssignal
for ( i = 0 ; i ! = ssd - > pbs_cur ; i + + ) {
TileIndex tile = ssd - > pbs_tile [ i ] ;
2005-07-13 18:04:01 +00:00
_m [ tile ] . m4 & = ~ 0x07 ;
_m [ tile ] . m4 | = 0x04 ;
2005-07-04 14:58:55 +00:00
MarkTileDirtyByTile ( tile ) ;
} ;
2004-08-09 17:04:08 +00:00
// then mark the signals in the segment accordingly
for ( i = 0 ; i ! = ssd - > cur ; i + + ) {
2005-06-24 12:38:35 +00:00
TileIndex tile = ssd - > tile [ i ] ;
2004-08-09 17:04:08 +00:00
byte bit = _signals_table [ ssd - > bit [ i ] ] ;
2005-07-13 18:04:01 +00:00
uint16 m2 = _m [ tile ] . m2 ;
2004-08-09 17:04:08 +00:00
// presignals don't turn green if there is at least one presignal exit and none are free
2005-07-13 18:04:01 +00:00
if ( _m [ tile ] . m4 & 1 ) {
2004-08-09 17:04:08 +00:00
int ex = ssd - > presignal_exits , exfree = ssd - > presignal_exits_free ;
// subtract for dual combo signals so they don't count themselves
2005-07-13 18:04:01 +00:00
if ( _m [ tile ] . m4 & 2 & & _m [ tile ] . m3 & _signals_table_other [ ssd - > bit [ i ] ] ) {
2004-08-09 17:04:08 +00:00
ex - - ;
2005-07-13 18:04:01 +00:00
if ( ( _m [ tile ] . m2 & _signals_table_other [ ssd - > bit [ i ] ] ) ! = 0 ) exfree - - ;
2004-08-09 17:04:08 +00:00
}
// if we have exits and none are free, make red.
if ( ex & & ! exfree ) goto make_red ;
}
// check if the signal is unaffected.
if ( ssd - > stop ) {
make_red :
// turn red
if ( ( bit & m2 ) = = 0 )
2004-09-11 09:55:19 +00:00
continue ;
2004-08-09 17:04:08 +00:00
} else {
// turn green
if ( ( bit & m2 ) ! = 0 )
continue ;
}
2005-05-15 10:23:42 +00:00
/* Update signals on the other side of this exit-combo signal; it changed. */
2005-07-13 18:04:01 +00:00
if ( _m [ tile ] . m4 & 2 ) {
2004-08-09 17:04:08 +00:00
if ( ssd - > cur_stack ! = NUM_SSD_STACK ) {
ssd - > next_tile [ ssd - > cur_stack ] = tile ;
ssd - > next_dir [ ssd - > cur_stack ] = _dir_from_track [ ssd - > bit [ i ] ] ;
ssd - > cur_stack + + ;
} else {
2005-05-15 10:23:42 +00:00
printf ( " NUM_SSD_STACK too small \n " ) ; /// @todo WTF is this???
2004-08-09 17:04:08 +00:00
}
}
2004-09-11 09:55:19 +00:00
2004-08-09 17:04:08 +00:00
// it changed, so toggle it
2005-07-13 18:04:01 +00:00
_m [ tile ] . m2 = m2 ^ bit ;
2004-08-09 17:04:08 +00:00
MarkTileDirtyByTile ( tile ) ;
}
}
2005-06-24 12:38:35 +00:00
bool UpdateSignalsOnSegment ( TileIndex tile , byte direction )
2004-08-09 17:04:08 +00:00
{
SetSignalsData ssd ;
int result = - 1 ;
ssd . cur_stack = 0 ;
direction > > = 1 ;
for ( ; ; ) {
// go through one segment and update all signals pointing into that segment.
2005-07-04 14:58:55 +00:00
ssd . cur = ssd . pbs_cur = ssd . presignal_exits = ssd . presignal_exits_free = 0 ;
2004-08-09 17:04:08 +00:00
ssd . has_presignal = false ;
2005-07-04 14:58:55 +00:00
ssd . has_pbssignal = false ;
2004-08-09 17:04:08 +00:00
2004-09-05 16:15:22 +00:00
FollowTrack ( tile , 0xC000 | TRANSPORT_RAIL , direction , ( TPFEnumProc * ) SetSignalsEnumProc , SetSignalsAfterProc , & ssd ) ;
2004-08-09 17:04:08 +00:00
ChangeSignalStates ( & ssd ) ;
// remember the result only for the first iteration.
if ( result < 0 ) result = ssd . stop ;
2004-09-11 09:55:19 +00:00
2004-08-09 17:04:08 +00:00
// if any exit signals were changed, we need to keep going to modify the stuff behind those.
if ( ! ssd . cur_stack )
break ;
// one or more exit signals were changed, so we need to update another segment too.
tile = ssd . next_tile [ - - ssd . cur_stack ] ;
direction = ssd . next_dir [ ssd . cur_stack ] ;
}
2004-09-11 09:55:19 +00:00
2004-08-09 17:04:08 +00:00
return ( bool ) result ;
}
2005-06-24 12:38:35 +00:00
void SetSignalsOnBothDir ( TileIndex tile , byte track )
2004-08-09 17:04:08 +00:00
{
static const byte _search_dir_1 [ 6 ] = { 1 , 3 , 1 , 3 , 5 , 3 } ;
static const byte _search_dir_2 [ 6 ] = { 5 , 7 , 7 , 5 , 7 , 1 } ;
UpdateSignalsOnSegment ( tile , _search_dir_1 [ track ] ) ;
UpdateSignalsOnSegment ( tile , _search_dir_2 [ track ] ) ;
}
2004-11-14 19:44:06 +00:00
static uint GetSlopeZ_Track ( TileInfo * ti )
2004-08-09 17:04:08 +00:00
{
uint z = ti - > z ;
int th = ti - > tileh ;
2004-08-10 18:35:43 +00:00
2004-08-09 17:04:08 +00:00
// check if it's a foundation
if ( ti - > tileh ! = 0 ) {
if ( ( ti - > map5 & 0x80 ) = = 0 ) {
uint f = GetRailFoundation ( ti - > tileh , ti - > map5 & 0x3F ) ;
if ( f ! = 0 ) {
if ( f < 15 ) {
// leveled foundation
return z + 8 ;
}
// inclined foundation
th = _inclined_tileh [ f - 15 ] ;
}
} else if ( ( ti - > map5 & 0xC0 ) = = 0xC0 ) {
2004-11-14 13:07:07 +00:00
// depot or waypoint
2004-08-09 17:04:08 +00:00
return z + 8 ;
}
return GetPartialZ ( ti - > x & 0xF , ti - > y & 0xF , th ) + z ;
}
return z ;
}
2005-09-18 20:56:44 +00:00
static uint GetSlopeTileh_Track ( const TileInfo * ti )
2004-08-13 18:27:33 +00:00
{
// check if it's a foundation
if ( ti - > tileh ! = 0 ) {
if ( ( ti - > map5 & 0x80 ) = = 0 ) {
uint f = GetRailFoundation ( ti - > tileh , ti - > map5 & 0x3F ) ;
if ( f ! = 0 ) {
if ( f < 15 ) {
// leveled foundation
return 0 ;
}
// inclined foundation
return _inclined_tileh [ f - 15 ] ;
}
} else if ( ( ti - > map5 & 0xC0 ) = = 0xC0 ) {
2004-11-14 13:07:07 +00:00
// depot or waypoint
2004-08-13 18:27:33 +00:00
return 0 ;
}
}
return ti - > tileh ;
}
2005-06-24 12:38:35 +00:00
static void GetAcceptedCargo_Track ( TileIndex tile , AcceptedCargo ac )
2004-08-09 17:04:08 +00:00
{
/* not used */
}
2005-06-24 12:38:35 +00:00
static void AnimateTile_Track ( TileIndex tile )
2004-08-09 17:04:08 +00:00
{
/* not used */
}
2005-06-24 12:38:35 +00:00
static void TileLoop_Track ( TileIndex tile )
2004-08-09 17:04:08 +00:00
{
byte a2 ;
byte rail ;
2004-12-28 11:51:31 +00:00
uint16 m2 ;
2004-08-09 17:04:08 +00:00
byte owner ;
2005-07-13 18:04:01 +00:00
m2 = _m [ tile ] . m2 & 0xF ;
2004-08-09 17:04:08 +00:00
/* special code for alps landscape */
if ( _opt . landscape = = LT_HILLY ) {
/* convert into snow? */
if ( GetTileZ ( tile ) > _opt . snow_line ) {
a2 = RAIL_GROUND_ICE_DESERT ;
goto modify_me ;
}
/* special code for desert landscape */
} else if ( _opt . landscape = = LT_DESERT ) {
/* convert into desert? */
if ( GetMapExtraBits ( tile ) = = 1 ) {
a2 = RAIL_GROUND_ICE_DESERT ;
goto modify_me ;
}
}
// Don't continue tile loop for depots
2005-07-13 18:04:01 +00:00
if ( _m [ tile ] . m5 & RAIL_TYPE_SPECIAL )
2004-08-09 17:04:08 +00:00
return ;
a2 = RAIL_GROUND_GREEN ;
if ( m2 ! = RAIL_GROUND_BROWN ) { /* wait until bottom is green */
/* determine direction of fence */
2005-07-13 18:04:01 +00:00
rail = _m [ tile ] . m5 & TRACK_BIT_MASK ;
2004-09-11 09:55:19 +00:00
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
if ( rail = = TRACK_BIT_UPPER ) {
2004-08-09 17:04:08 +00:00
a2 = RAIL_GROUND_FENCE_HORIZ1 ;
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
} else if ( rail = = TRACK_BIT_LOWER ) {
2004-08-09 17:04:08 +00:00
a2 = RAIL_GROUND_FENCE_HORIZ2 ;
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
} else if ( rail = = TRACK_BIT_LEFT ) {
2004-08-09 17:04:08 +00:00
a2 = RAIL_GROUND_FENCE_VERT1 ;
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
} else if ( rail = = TRACK_BIT_RIGHT ) {
2004-08-09 17:04:08 +00:00
a2 = RAIL_GROUND_FENCE_VERT2 ;
} else {
2005-06-04 11:56:32 +00:00
owner = GetTileOwner ( tile ) ;
2004-08-09 17:04:08 +00:00
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
if ( ( ! ( rail & ( TRACK_BIT_DIAG2 | TRACK_BIT_UPPER | TRACK_BIT_LEFT ) ) & & ( rail & TRACK_BIT_DIAG1 ) ) | | rail = = ( TRACK_BIT_LOWER | TRACK_BIT_RIGHT ) ) {
2005-06-25 16:44:57 +00:00
if ( ! IsTileType ( tile + TileDiffXY ( 0 , - 1 ) , MP_RAILWAY ) | |
! IsTileOwner ( tile + TileDiffXY ( 0 , - 1 ) , owner ) | |
2005-07-13 18:04:01 +00:00
( _m [ tile + TileDiffXY ( 0 , - 1 ) ] . m5 = = TRACK_BIT_UPPER | | _m [ tile + TileDiffXY ( 0 , - 1 ) ] . m5 = = TRACK_BIT_LEFT ) )
2004-09-11 09:55:19 +00:00
a2 = RAIL_GROUND_FENCE_NW ;
2004-08-09 17:04:08 +00:00
}
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
if ( ( ! ( rail & ( TRACK_BIT_DIAG2 | TRACK_BIT_LOWER | TRACK_BIT_RIGHT ) ) & & ( rail & TRACK_BIT_DIAG1 ) ) | | rail = = ( TRACK_BIT_UPPER | TRACK_BIT_LEFT ) ) {
2005-06-25 16:44:57 +00:00
if ( ! IsTileType ( tile + TileDiffXY ( 0 , 1 ) , MP_RAILWAY ) | |
! IsTileOwner ( tile + TileDiffXY ( 0 , 1 ) , owner ) | |
2005-07-13 18:04:01 +00:00
( _m [ tile + TileDiffXY ( 0 , 1 ) ] . m5 = = TRACK_BIT_LOWER | | _m [ tile + TileDiffXY ( 0 , 1 ) ] . m5 = = TRACK_BIT_RIGHT ) )
2004-08-09 17:04:08 +00:00
a2 = ( a2 = = RAIL_GROUND_FENCE_NW ) ? RAIL_GROUND_FENCE_SENW : RAIL_GROUND_FENCE_SE ;
}
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
if ( ( ! ( rail & ( TRACK_BIT_DIAG1 | TRACK_BIT_UPPER | TRACK_BIT_RIGHT ) ) & & ( rail & TRACK_BIT_DIAG2 ) ) | | rail = = ( TRACK_BIT_LOWER | TRACK_BIT_LEFT ) ) {
2005-06-25 16:44:57 +00:00
if ( ! IsTileType ( tile + TileDiffXY ( - 1 , 0 ) , MP_RAILWAY ) | |
! IsTileOwner ( tile + TileDiffXY ( - 1 , 0 ) , owner ) | |
2005-07-13 18:04:01 +00:00
( _m [ tile + TileDiffXY ( - 1 , 0 ) ] . m5 = = TRACK_BIT_UPPER | | _m [ tile + TileDiffXY ( - 1 , 0 ) ] . m5 = = TRACK_BIT_RIGHT ) )
2004-08-09 17:04:08 +00:00
a2 = RAIL_GROUND_FENCE_NE ;
}
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
if ( ( ! ( rail & ( TRACK_BIT_DIAG1 | TRACK_BIT_LOWER | TRACK_BIT_LEFT ) ) & & ( rail & TRACK_BIT_DIAG2 ) ) | | rail = = ( TRACK_BIT_UPPER | TRACK_BIT_RIGHT ) ) {
2005-06-25 16:44:57 +00:00
if ( ! IsTileType ( tile + TileDiffXY ( 1 , 0 ) , MP_RAILWAY ) | |
! IsTileOwner ( tile + TileDiffXY ( 1 , 0 ) , owner ) | |
2005-07-13 18:04:01 +00:00
( _m [ tile + TileDiffXY ( 1 , 0 ) ] . m5 = = TRACK_BIT_LOWER | | _m [ tile + TileDiffXY ( 1 , 0 ) ] . m5 = = TRACK_BIT_LEFT ) )
2004-08-09 17:04:08 +00:00
a2 = ( a2 = = RAIL_GROUND_FENCE_NE ) ? RAIL_GROUND_FENCE_NESW : RAIL_GROUND_FENCE_SW ;
}
}
}
modify_me : ;
/* tile changed? */
if ( m2 ! = a2 ) {
2005-07-13 18:04:01 +00:00
_m [ tile ] . m2 = ( _m [ tile ] . m2 & ~ RAIL_MAP2LO_GROUND_MASK ) | a2 ;
2004-08-09 17:04:08 +00:00
MarkTileDirtyByTile ( tile ) ;
}
}
2005-06-24 12:38:35 +00:00
static uint32 GetTileTrackStatus_Track ( TileIndex tile , TransportType mode )
{
2004-12-28 11:51:31 +00:00
byte m5 , a ;
uint16 b ;
2004-08-09 17:04:08 +00:00
uint32 ret ;
2004-09-05 16:15:22 +00:00
if ( mode ! = TRANSPORT_RAIL )
2004-08-09 17:04:08 +00:00
return 0 ;
2005-07-13 18:04:01 +00:00
m5 = _m [ tile ] . m5 ;
2004-08-09 17:04:08 +00:00
if ( ! ( m5 & RAIL_TYPE_SPECIAL ) ) {
ret = ( m5 | ( m5 < < 8 ) ) & 0x3F3F ;
if ( ! ( m5 & RAIL_TYPE_SIGNALS ) ) {
if ( ( ret & 0xFF ) = = 3 )
2004-08-11 22:07:08 +00:00
/* Diagonal crossing? */
2004-08-09 17:04:08 +00:00
ret | = 0x40 ;
} else {
/* has_signals */
2005-07-13 18:04:01 +00:00
a = _m [ tile ] . m3 ;
b = _m [ tile ] . m2 ;
2004-08-09 17:04:08 +00:00
b & = a ;
2004-08-11 22:07:08 +00:00
/* When signals are not present (in neither
* direction ) , we pretend them to be green . ( So if
* signals are only one way , the other way will
* implicitely become ` red ' */
2004-08-09 17:04:08 +00:00
if ( ( a & 0xC0 ) = = 0 ) { b | = 0xC0 ; }
if ( ( a & 0x30 ) = = 0 ) { b | = 0x30 ; }
if ( ( b & 0x80 ) = = 0 ) ret | = 0x10070000 ;
if ( ( b & 0x40 ) = = 0 ) ret | = 0x7100000 ;
if ( ( b & 0x20 ) = = 0 ) ret | = 0x20080000 ;
if ( ( b & 0x10 ) = = 0 ) ret | = 0x8200000 ;
}
} else if ( m5 & 0x40 ) {
static const byte _train_spec_tracks [ 6 ] = { 1 , 2 , 1 , 2 , 1 , 2 } ;
m5 = _train_spec_tracks [ m5 & 0x3F ] ;
ret = ( m5 < < 8 ) + m5 ;
} else
return 0 ;
return ret ;
}
2005-06-24 12:38:35 +00:00
static void ClickTile_Track ( TileIndex tile )
2004-08-09 17:04:08 +00:00
{
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
if ( IsTileDepotType ( tile , TRANSPORT_RAIL ) )
2004-08-09 17:04:08 +00:00
ShowTrainDepotWindow ( tile ) ;
2005-07-13 18:04:01 +00:00
else if ( IsRailWaypoint ( _m [ tile ] . m5 ) )
2005-03-24 17:03:37 +00:00
ShowRenameWaypointWindow ( GetWaypointByTile ( tile ) ) ;
2004-09-11 09:55:19 +00:00
2004-08-09 17:04:08 +00:00
}
2005-03-28 07:02:51 +00:00
static void GetTileDesc_Track ( TileIndex tile , TileDesc * td )
2004-08-09 17:04:08 +00:00
{
2005-06-04 11:56:32 +00:00
td - > owner = GetTileOwner ( tile ) ;
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
switch ( GetRailTileType ( tile ) ) {
2005-03-28 07:02:51 +00:00
case RAIL_TYPE_NORMAL :
2004-08-09 17:04:08 +00:00
td - > str = STR_1021_RAILROAD_TRACK ;
2005-03-28 07:02:51 +00:00
break ;
case RAIL_TYPE_SIGNALS : {
2005-07-07 22:15:34 +00:00
const StringID signal_type [ 7 ] = {
2005-03-28 07:02:51 +00:00
STR_RAILROAD_TRACK_WITH_NORMAL_SIGNALS ,
STR_RAILROAD_TRACK_WITH_PRESIGNALS ,
STR_RAILROAD_TRACK_WITH_EXITSIGNALS ,
2005-07-07 22:15:34 +00:00
STR_RAILROAD_TRACK_WITH_COMBOSIGNALS ,
STR_RAILROAD_TRACK_WITH_PBSSIGNALS ,
STR_NULL , STR_NULL
2005-03-28 07:02:51 +00:00
} ;
2005-07-13 18:04:01 +00:00
td - > str = signal_type [ _m [ tile ] . m4 & 0x7 ] ;
2005-03-28 07:02:51 +00:00
break ;
2004-08-09 17:04:08 +00:00
}
2005-03-28 07:02:51 +00:00
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
case RAIL_TYPE_DEPOT_WAYPOINT :
2005-03-28 07:02:51 +00:00
default :
2005-07-13 18:04:01 +00:00
td - > str = ( ( _m [ tile ] . m5 & RAIL_SUBTYPE_MASK ) = = RAIL_SUBTYPE_DEPOT ) ?
2005-03-28 07:02:51 +00:00
STR_1023_RAILROAD_TRAIN_DEPOT : STR_LANDINFO_WAYPOINT ;
break ;
2004-08-09 17:04:08 +00:00
}
}
2005-09-18 20:56:44 +00:00
static void ChangeTileOwner_Track ( TileIndex tile , PlayerID old_player , PlayerID new_player )
2004-08-09 17:04:08 +00:00
{
2005-06-04 11:56:32 +00:00
if ( ! IsTileOwner ( tile , old_player ) ) return ;
2004-09-11 09:55:19 +00:00
2004-08-09 17:04:08 +00:00
if ( new_player ! = 255 ) {
2005-06-04 12:13:24 +00:00
SetTileOwner ( tile , new_player ) ;
2004-08-09 17:04:08 +00:00
} else {
DoCommandByTile ( tile , 0 , 0 , DC_EXEC , CMD_LANDSCAPE_CLEAR ) ;
}
}
static const byte _fractcoords_behind [ 4 ] = { 0x8F , 0x8 , 0x80 , 0xF8 } ;
static const byte _fractcoords_enter [ 4 ] = { 0x8A , 0x48 , 0x84 , 0xA8 } ;
2005-06-06 22:44:11 +00:00
static const byte _deltacoord_leaveoffset [ 8 ] = {
- 1 , 0 , 1 , 0 , /* x */
0 , 1 , 0 , - 1 /* y */
} ;
2004-08-09 17:04:08 +00:00
static const byte _enter_directions [ 4 ] = { 5 , 7 , 1 , 3 } ;
static const byte _leave_directions [ 4 ] = { 1 , 3 , 5 , 7 } ;
static const byte _depot_track_mask [ 4 ] = { 1 , 2 , 1 , 2 } ;
2005-06-24 12:38:35 +00:00
static uint32 VehicleEnter_Track ( Vehicle * v , TileIndex tile , int x , int y )
2004-08-09 17:04:08 +00:00
{
byte fract_coord ;
2005-06-06 22:44:11 +00:00
byte fract_coord_leave ;
2004-08-09 17:04:08 +00:00
int dir ;
2005-06-06 22:44:11 +00:00
int length ;
2004-09-11 09:55:19 +00:00
2004-08-09 17:04:08 +00:00
// this routine applies only to trains in depot tiles
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
if ( v - > type ! = VEH_Train | | ! IsTileDepotType ( tile , TRANSPORT_RAIL ) )
2004-08-09 17:04:08 +00:00
return 0 ;
/* depot direction */
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
dir = GetDepotDirection ( tile , TRANSPORT_RAIL ) ;
2004-09-11 09:55:19 +00:00
2005-06-06 22:44:11 +00:00
/* calculate the point where the following wagon should be activated */
/* this depends on the length of the current vehicle */
length = v - > u . rail . cached_veh_length ;
fract_coord_leave =
( ( _fractcoords_enter [ dir ] & 0x0F ) + // x
( length + 1 ) * _deltacoord_leaveoffset [ dir ] ) +
( ( ( _fractcoords_enter [ dir ] > > 4 ) + // y
( ( length + 1 ) * _deltacoord_leaveoffset [ dir + 4 ] ) ) < < 4 ) ;
2004-08-09 17:04:08 +00:00
fract_coord = ( x & 0xF ) + ( ( y & 0xF ) < < 4 ) ;
2005-06-06 22:44:11 +00:00
2004-08-09 17:04:08 +00:00
if ( _fractcoords_behind [ dir ] = = fract_coord ) {
/* make sure a train is not entering the tile from behind */
return 8 ;
} else if ( _fractcoords_enter [ dir ] = = fract_coord ) {
if ( _enter_directions [ dir ] = = v - > direction ) {
/* enter the depot */
2005-07-04 14:58:55 +00:00
if ( v - > next = = NULL )
PBSClearTrack ( v - > tile , FIND_FIRST_BIT ( v - > u . rail . track ) ) ;
2004-08-09 17:04:08 +00:00
v - > u . rail . track = 0x80 ,
v - > vehstatus | = VS_HIDDEN ; /* hide it */
v - > direction ^ = 4 ;
if ( v - > next = = NULL )
TrainEnterDepot ( v , tile ) ;
v - > tile = tile ;
InvalidateWindow ( WC_VEHICLE_DEPOT , tile ) ;
return 4 ;
}
2005-06-06 22:44:11 +00:00
} else if ( fract_coord_leave = = fract_coord ) {
2004-08-09 17:04:08 +00:00
if ( _leave_directions [ dir ] = = v - > direction ) {
/* leave the depot? */
if ( ( v = v - > next ) ! = NULL ) {
v - > vehstatus & = ~ VS_HIDDEN ;
v - > u . rail . track = _depot_track_mask [ dir ] ;
2005-02-06 22:36:08 +00:00
assert ( v - > u . rail . track ) ;
2004-08-09 17:04:08 +00:00
}
}
}
return 0 ;
}
2005-01-22 20:23:18 +00:00
void InitializeRail ( void )
2004-08-09 17:04:08 +00:00
{
_last_built_train_depot_tile = 0 ;
}
const TileTypeProcs _tile_type_rail_procs = {
DrawTile_Track , /* draw_tile_proc */
GetSlopeZ_Track , /* get_slope_z_proc */
ClearTile_Track , /* clear_tile_proc */
GetAcceptedCargo_Track , /* get_accepted_cargo_proc */
GetTileDesc_Track , /* get_tile_desc_proc */
GetTileTrackStatus_Track , /* get_tile_track_status_proc */
ClickTile_Track , /* click_tile_proc */
AnimateTile_Track , /* animate_tile_proc */
TileLoop_Track , /* tile_loop_clear */
ChangeTileOwner_Track , /* change_tile_owner_clear */
NULL , /* get_produced_cargo_proc */
VehicleEnter_Track , /* vehicle_enter_tile_proc */
NULL , /* vehicle_leave_tile_proc */
2004-08-13 18:27:33 +00:00
GetSlopeTileh_Track , /* get_slope_tileh_proc */
2004-08-09 17:04:08 +00:00
} ;