2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2007-03-28 20:41:35 +00:00
|
|
|
/** @file rail_cmd.cpp */
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
2005-06-02 19:30:21 +00:00
|
|
|
#include "openttd.h"
|
2006-03-13 12:55:20 +00:00
|
|
|
#include "bridge_map.h"
|
2007-02-26 18:25:03 +00:00
|
|
|
#include "bridge.h"
|
2007-02-24 09:42:39 +00:00
|
|
|
#include "cmd_helper.h"
|
2005-06-06 22:44:11 +00:00
|
|
|
#include "debug.h"
|
2005-07-22 07:02:20 +00:00
|
|
|
#include "functions.h"
|
2006-03-01 08:56:38 +00:00
|
|
|
#include "rail_map.h"
|
2006-03-05 10:19:33 +00:00
|
|
|
#include "road_map.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"
|
2007-03-20 13:47:00 +00:00
|
|
|
#include "landscape.h"
|
2005-01-29 12:19:05 +00:00
|
|
|
#include "tile.h"
|
2006-03-24 12:00:24 +00:00
|
|
|
#include "town_map.h"
|
2006-03-06 20:55:24 +00:00
|
|
|
#include "tunnel_map.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-03-24 17:03:37 +00:00
|
|
|
#include "waypoint.h"
|
2006-08-29 06:50:47 +00:00
|
|
|
#include "window.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
|
2006-04-23 15:57:34 +00:00
|
|
|
#include "newgrf.h"
|
2006-05-27 16:12:16 +00:00
|
|
|
#include "yapf/yapf.h"
|
2006-05-06 09:40:12 +00:00
|
|
|
#include "newgrf_callbacks.h"
|
|
|
|
#include "newgrf_station.h"
|
2006-09-05 16:40:23 +00:00
|
|
|
#include "train.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
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
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
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?
|
2006-08-28 18:53:03 +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: 00abcdef => rail
|
|
|
|
* 01abcdef => rail w/ signals
|
|
|
|
* 10uuuuuu => unused
|
2004-09-11 09:55:19 +00:00
|
|
|
* 11uuuudd => 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
|
|
|
{
|
2007-04-04 01:35:16 +00:00
|
|
|
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;
|
|
|
|
|
2006-07-27 05:30:53 +00:00
|
|
|
if (!IsPlainRailTile(tile)) 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
|
|
|
/* 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 */
|
2006-07-27 05:30:53 +00:00
|
|
|
if (flags & DC_NO_RAIL_OVERLAP || HasSignals(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
|
|
|
/* If we are not allowed to overlap (flag is on for ai players or we have
|
|
|
|
* signals on the tile), check that */
|
2006-03-18 13:20:50 +00:00
|
|
|
return future == TRACK_BIT_HORZ || future == TRACK_BIT_VERT;
|
(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 {
|
|
|
|
/* Normally, we may overlap and any combination is valid */
|
|
|
|
return true;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-25 17:39:19 +00:00
|
|
|
static const TrackBits _valid_tileh_slopes[][15] = {
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-04-04 01:35:16 +00:00
|
|
|
/* set of normal ones */
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-03-18 13:20:50 +00:00
|
|
|
TRACK_BIT_ALL,
|
(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_RIGHT,
|
|
|
|
TRACK_BIT_UPPER,
|
2006-03-01 09:40:34 +00:00
|
|
|
TRACK_BIT_X,
|
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,
|
2007-01-10 18:56:51 +00:00
|
|
|
TRACK_BIT_NONE,
|
2006-03-01 09:40:34 +00:00
|
|
|
TRACK_BIT_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_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,
|
2006-03-01 09:40:34 +00:00
|
|
|
TRACK_BIT_Y,
|
2007-01-10 18:56:51 +00:00
|
|
|
TRACK_BIT_NONE,
|
(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
|
|
|
|
2006-03-01 09:40:34 +00:00
|
|
|
TRACK_BIT_X,
|
(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_UPPER,
|
|
|
|
TRACK_BIT_RIGHT,
|
2004-08-09 17:04:08 +00:00
|
|
|
},
|
|
|
|
|
2007-04-04 01:35:16 +00:00
|
|
|
/* allowed rail for an evenly raised platform */
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-01-10 18:56:51 +00:00
|
|
|
TRACK_BIT_NONE,
|
(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,
|
2006-03-01 09:40:34 +00:00
|
|
|
TRACK_BIT_Y | TRACK_BIT_LOWER | TRACK_BIT_LEFT,
|
(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_RIGHT,
|
2006-03-18 13:20:50 +00:00
|
|
|
TRACK_BIT_ALL,
|
2006-03-01 09:40:34 +00:00
|
|
|
TRACK_BIT_X | TRACK_BIT_LOWER | TRACK_BIT_RIGHT,
|
2006-03-18 13:20:50 +00:00
|
|
|
TRACK_BIT_ALL,
|
(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_UPPER,
|
2006-03-01 09:40:34 +00:00
|
|
|
TRACK_BIT_X | TRACK_BIT_UPPER | TRACK_BIT_LEFT,
|
2006-03-18 13:20:50 +00:00
|
|
|
TRACK_BIT_ALL,
|
|
|
|
TRACK_BIT_ALL,
|
(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
|
|
|
|
2006-03-01 09:40:34 +00:00
|
|
|
TRACK_BIT_Y | TRACK_BIT_UPPER | TRACK_BIT_RIGHT,
|
2006-03-18 13:20:50 +00:00
|
|
|
TRACK_BIT_ALL,
|
|
|
|
TRACK_BIT_ALL
|
2006-03-19 19:56:57 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2006-04-23 13:48:16 +00:00
|
|
|
uint GetRailFoundation(Slope tileh, TrackBits bits)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-05-20 18:03:22 +00:00
|
|
|
uint i;
|
|
|
|
|
2006-08-10 14:44:32 +00:00
|
|
|
if (!IsSteepSlope(tileh)) {
|
|
|
|
if ((~_valid_tileh_slopes[0][tileh] & bits) == 0) return 0;
|
|
|
|
if ((~_valid_tileh_slopes[1][tileh] & bits) == 0) return tileh;
|
|
|
|
}
|
2006-05-20 18:03:22 +00:00
|
|
|
|
|
|
|
switch (bits) {
|
2006-08-12 12:56:45 +00:00
|
|
|
default: NOT_REACHED();
|
2006-05-20 18:03:22 +00:00
|
|
|
case TRACK_BIT_X: i = 0; break;
|
|
|
|
case TRACK_BIT_Y: i = 1; break;
|
2006-08-12 12:56:45 +00:00
|
|
|
case TRACK_BIT_LEFT: return 15 + 8 + (tileh == SLOPE_STEEP_W ? 4 : 0);
|
|
|
|
case TRACK_BIT_LOWER: return 15 + 8 + (tileh == SLOPE_STEEP_S ? 5 : 1);
|
|
|
|
case TRACK_BIT_RIGHT: return 15 + 8 + (tileh == SLOPE_STEEP_E ? 6 : 2);
|
|
|
|
case TRACK_BIT_UPPER: return 15 + 8 + (tileh == SLOPE_STEEP_N ? 7 : 3);
|
2006-05-20 18:03:22 +00:00
|
|
|
}
|
|
|
|
switch (tileh) {
|
2006-08-10 14:44:32 +00:00
|
|
|
case SLOPE_W:
|
|
|
|
case SLOPE_STEEP_W: i += 0; break;
|
|
|
|
case SLOPE_S:
|
|
|
|
case SLOPE_STEEP_S: i += 2; break;
|
|
|
|
case SLOPE_E:
|
|
|
|
case SLOPE_STEEP_E: i += 4; break;
|
|
|
|
case SLOPE_N:
|
|
|
|
case SLOPE_STEEP_N: i += 6; break;
|
|
|
|
default: return 0;
|
2006-02-01 06:32:03 +00:00
|
|
|
}
|
2006-05-20 18:03:22 +00:00
|
|
|
return i + 15;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
|
2007-06-18 10:48:15 +00:00
|
|
|
static CommandCost CheckRailSlope(Slope tileh, TrackBits rail_bits, TrackBits existing, TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-08-10 14:44:32 +00:00
|
|
|
if (IsSteepSlope(tileh)) {
|
2007-04-12 06:16:46 +00:00
|
|
|
if (_patches.build_on_slopes && existing == 0) {
|
2006-08-12 12:56:45 +00:00
|
|
|
TrackBits valid = TRACK_BIT_CROSS | (HASBIT(1 << SLOPE_STEEP_W | 1 << SLOPE_STEEP_E, tileh) ? TRACK_BIT_VERT : TRACK_BIT_HORZ);
|
|
|
|
if (valid & rail_bits) return _price.terraform;
|
2006-08-10 14:44:32 +00:00
|
|
|
}
|
|
|
|
} else {
|
2004-08-09 17:04:08 +00:00
|
|
|
rail_bits |= existing;
|
|
|
|
|
2007-04-04 01:35:16 +00:00
|
|
|
/* don't allow building on the lower side of a coast */
|
2005-04-02 18:33:53 +00:00
|
|
|
if (IsTileType(tile, MP_WATER) &&
|
2006-03-19 19:56:57 +00:00
|
|
|
~_valid_tileh_slopes[1][tileh] & rail_bits) {
|
2004-08-09 17:04:08 +00:00
|
|
|
return_cmd_error(STR_3807_CAN_T_BUILD_ON_WATER);
|
|
|
|
}
|
|
|
|
|
2007-04-04 01:35:16 +00:00
|
|
|
/* no special foundation */
|
2007-06-03 19:22:23 +00:00
|
|
|
if ((~_valid_tileh_slopes[0][tileh] & rail_bits) == 0) {
|
2007-06-18 19:53:50 +00:00
|
|
|
return CommandCost();
|
2007-06-03 19:22:23 +00:00
|
|
|
} else if (!_patches.build_on_slopes || _is_old_ai_player) {
|
|
|
|
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
|
|
|
|
}
|
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
|
2006-03-01 09:40:34 +00:00
|
|
|
(rail_bits == TRACK_BIT_X || rail_bits == TRACK_BIT_Y) &&
|
2006-04-23 13:48:16 +00:00
|
|
|
(tileh == SLOPE_W || tileh == SLOPE_S || tileh == SLOPE_E || tileh == SLOPE_N)
|
2005-04-02 18:33:53 +00:00
|
|
|
)) { // partly up
|
2007-06-18 19:53:50 +00:00
|
|
|
return CommandCost((existing != 0) ? 0 : _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
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param tile tile to build on
|
2007-04-17 21:09:38 +00:00
|
|
|
* @param flags operation to perform
|
2005-05-07 10:26:12 +00:00
|
|
|
* @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
|
|
|
*/
|
2007-06-18 10:48:15 +00:00
|
|
|
CommandCost CmdBuildSingleRail(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-04-23 13:48:16 +00:00
|
|
|
Slope tileh;
|
2006-11-08 09:18:27 +00:00
|
|
|
RailType railtype;
|
|
|
|
Track 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
|
|
|
TrackBits trackbit;
|
2007-06-18 19:53:50 +00:00
|
|
|
CommandCost cost;
|
2007-06-18 10:48:15 +00:00
|
|
|
CommandCost ret;
|
2005-04-02 18:33:53 +00:00
|
|
|
|
2007-01-10 18:56:51 +00:00
|
|
|
if (!ValParamRailtype(p1) || !ValParamTrackOrientation((Track)p2)) return CMD_ERROR;
|
2006-11-08 09:18:27 +00:00
|
|
|
railtype = (RailType)p1;
|
|
|
|
track = (Track)p2;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-04-02 18:33:53 +00:00
|
|
|
tileh = GetTileSlope(tile, NULL);
|
(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_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) ||
|
2007-04-01 11:11:49 +00:00
|
|
|
!EnsureNoVehicleOnGround(tile)) {
|
2005-04-02 18:33:53 +00:00
|
|
|
return CMD_ERROR;
|
|
|
|
}
|
2006-07-26 12:11:52 +00:00
|
|
|
if (!IsTileOwner(tile, _current_player) ||
|
2006-12-27 18:29:34 +00:00
|
|
|
!IsCompatibleRail(GetRailType(tile), railtype)) {
|
2007-04-04 01:35:16 +00:00
|
|
|
/* Get detailed error message */
|
2006-04-10 07:15:58 +00:00
|
|
|
return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
2005-04-02 18:33:53 +00:00
|
|
|
}
|
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;
|
2007-06-18 19:53:50 +00:00
|
|
|
cost.AddCost(ret);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-11-08 10:09:46 +00:00
|
|
|
/* If the rail types don't match, try to convert only if engines of
|
|
|
|
* the present rail type are powered on the new rail type. */
|
|
|
|
if (GetRailType(tile) != railtype && HasPowerOnRail(GetRailType(tile), railtype)) {
|
2006-11-08 09:18:27 +00:00
|
|
|
ret = DoCommand(tile, tile, railtype, flags, CMD_CONVERT_RAIL);
|
2006-11-07 22:34:59 +00:00
|
|
|
if (CmdFailed(ret)) return ret;
|
2007-06-18 19:53:50 +00:00
|
|
|
cost.AddCost(ret);
|
2006-11-07 22:34:59 +00:00
|
|
|
}
|
|
|
|
|
2005-04-24 07:56:18 +00:00
|
|
|
if (flags & DC_EXEC) {
|
2006-04-12 11:58:07 +00:00
|
|
|
SetRailGroundType(tile, RAIL_GROUND_BARREN);
|
2006-12-29 10:16:36 +00:00
|
|
|
SetTrackBits(tile, GetTrackBits(tile) | 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:
|
2006-03-04 13:52:52 +00:00
|
|
|
#define M(x) (1 << (x))
|
|
|
|
/* Level crossings may only be built on these slopes */
|
2006-04-23 13:48:16 +00:00
|
|
|
if (!HASBIT(M(SLOPE_SEN) | M(SLOPE_ENW) | M(SLOPE_NWS) | M(SLOPE_NS) | M(SLOPE_WSE) | M(SLOPE_EW) | M(SLOPE_FLAT), tileh)) {
|
2005-04-02 18:33:53 +00:00
|
|
|
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
|
2006-03-04 13:52:52 +00:00
|
|
|
}
|
|
|
|
#undef M
|
|
|
|
|
2007-04-01 11:11:49 +00:00
|
|
|
if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
|
2005-04-02 18:33:53 +00:00
|
|
|
|
2006-07-15 09:29:39 +00:00
|
|
|
if (GetRoadTileType(tile) == ROAD_TILE_NORMAL) {
|
|
|
|
if (HasRoadWorks(tile)) return_cmd_error(STR_ROAD_WORKS_IN_PROGRESS);
|
|
|
|
|
2007-05-20 19:14:08 +00:00
|
|
|
RoadTypes roadtypes = GetRoadTypes(tile);
|
|
|
|
RoadBits road = GetRoadBits(tile, ROADTYPE_ROAD);
|
|
|
|
RoadBits tram = GetRoadBits(tile, ROADTYPE_TRAM);
|
|
|
|
switch (roadtypes) {
|
|
|
|
default: break;
|
2007-05-28 03:41:18 +00:00
|
|
|
case ROADTYPES_TRAM:
|
|
|
|
/* Tram crossings must always have road. */
|
|
|
|
SetRoadOwner(tile, ROADTYPE_ROAD, _current_player);
|
|
|
|
roadtypes |= ROADTYPES_ROAD;
|
|
|
|
break;
|
|
|
|
|
2007-05-20 19:14:08 +00:00
|
|
|
case ROADTYPES_ROADTRAM: if (road == tram) break;
|
|
|
|
/* FALL THROUGH */
|
|
|
|
case ROADTYPES_ROADHWAY: // Road and highway are incompatible in this case
|
|
|
|
case ROADTYPES_TRAMHWAY: // Tram and highway are incompatible in this case
|
|
|
|
case ROADTYPES_ALL: // Also incompatible
|
|
|
|
return CMD_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
road |= tram | GetRoadBits(tile, ROADTYPE_HWAY);
|
|
|
|
|
|
|
|
if ((track == TRACK_X && road == ROAD_Y) ||
|
|
|
|
(track == TRACK_Y && road == ROAD_X)) {
|
2006-07-15 09:29:39 +00:00
|
|
|
if (flags & DC_EXEC) {
|
2007-05-20 19:14:08 +00:00
|
|
|
MakeRoadCrossing(tile, GetRoadOwner(tile, ROADTYPE_ROAD), GetRoadOwner(tile, ROADTYPE_TRAM), GetRoadOwner(tile, ROADTYPE_HWAY), _current_player, (track == TRACK_X ? AXIS_Y : AXIS_X), railtype, roadtypes, GetTownIndex(tile));
|
2006-07-15 09:29:39 +00:00
|
|
|
}
|
|
|
|
break;
|
2005-04-02 18:33:53 +00:00
|
|
|
}
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-03-19 12:06:12 +00:00
|
|
|
if (IsLevelCrossing(tile) && GetCrossingRailBits(tile) == trackbit) {
|
2005-04-02 18:33:53 +00:00
|
|
|
return_cmd_error(STR_1007_ALREADY_BUILT);
|
2006-03-19 12:06:12 +00:00
|
|
|
}
|
2005-04-02 18:33:53 +00:00
|
|
|
/* FALLTHROUGH */
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-04-02 18:33:53 +00:00
|
|
|
default:
|
2007-01-10 18:56:51 +00:00
|
|
|
ret = CheckRailSlope(tileh, trackbit, TRACK_BIT_NONE, tile);
|
2005-04-14 11:17:36 +00:00
|
|
|
if (CmdFailed(ret)) return ret;
|
2007-06-18 19:53:50 +00:00
|
|
|
cost.AddCost(ret);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-10 07:15:58 +00:00
|
|
|
ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
2005-04-14 11:17:36 +00:00
|
|
|
if (CmdFailed(ret)) return ret;
|
2007-06-18 19:53:50 +00:00
|
|
|
cost.AddCost(ret);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-11-08 09:18:27 +00:00
|
|
|
if (flags & DC_EXEC) MakeRailNormal(tile, _current_player, trackbit, railtype);
|
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);
|
2006-05-27 16:12:16 +00:00
|
|
|
YapfNotifyTrackLayoutChange(tile, track);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-06-18 19:53:50 +00:00
|
|
|
return cost.AddCost(_price.build_rail);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-05-07 10:26:12 +00:00
|
|
|
/** Remove a single piece of track
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param tile tile to remove track from
|
2007-04-17 21:09:38 +00:00
|
|
|
* @param flags operation to perform
|
2005-05-07 10:26:12 +00:00
|
|
|
* @param p1 unused
|
|
|
|
* @param p2 rail orientation
|
2004-08-09 17:04:08 +00:00
|
|
|
*/
|
2007-06-18 10:48:15 +00:00
|
|
|
CommandCost CmdRemoveSingleRail(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
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 track = (Track)p2;
|
|
|
|
TrackBits trackbit;
|
2007-06-18 19:53:50 +00:00
|
|
|
CommandCost cost(_price.remove_rail);
|
2006-03-21 21:11:41 +00:00
|
|
|
bool crossing = false;
|
2005-05-07 10:26:12 +00:00
|
|
|
|
2007-01-10 18:56:51 +00:00
|
|
|
if (!ValParamTrackOrientation((Track)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);
|
|
|
|
|
2006-03-19 17:52:02 +00:00
|
|
|
switch (GetTileType(tile)) {
|
2006-02-23 12:24:19 +00:00
|
|
|
case MP_STREET: {
|
2006-03-19 17:52:02 +00:00
|
|
|
if (!IsLevelCrossing(tile) ||
|
|
|
|
GetCrossingRailBits(tile) != trackbit ||
|
|
|
|
(_current_player != OWNER_WATER && !CheckTileOwnership(tile)) ||
|
2007-04-01 11:11:49 +00:00
|
|
|
!EnsureNoVehicleOnGround(tile)) {
|
2006-03-19 17:52:02 +00:00
|
|
|
return CMD_ERROR;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-03-19 17:52:02 +00:00
|
|
|
if (flags & DC_EXEC) {
|
2007-05-20 19:14:08 +00:00
|
|
|
MakeRoadNormal(tile, GetCrossingRoadBits(tile), GetRoadTypes(tile), GetTownIndex(tile), GetRoadOwner(tile, ROADTYPE_ROAD), GetRoadOwner(tile, ROADTYPE_TRAM), GetRoadOwner(tile, ROADTYPE_HWAY));
|
2006-03-19 17:52:02 +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
|
|
|
break;
|
2006-02-23 12:24:19 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-03-19 17:52:02 +00:00
|
|
|
case MP_RAILWAY: {
|
|
|
|
TrackBits present;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-03-19 17:52:02 +00:00
|
|
|
if (!IsPlainRailTile(tile) ||
|
|
|
|
(_current_player != OWNER_WATER && !CheckTileOwnership(tile)) ||
|
2007-04-01 11:11:49 +00:00
|
|
|
!EnsureNoVehicleOnGround(tile)) {
|
2004-08-09 17:04:08 +00:00
|
|
|
return CMD_ERROR;
|
2006-03-19 17:52:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
present = GetTrackBits(tile);
|
|
|
|
if ((present & trackbit) == 0) return CMD_ERROR;
|
2006-03-21 21:11:41 +00:00
|
|
|
if (present == (TRACK_BIT_X | TRACK_BIT_Y)) crossing = true;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
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))
|
2007-06-18 19:53:50 +00:00
|
|
|
cost.AddCost(DoCommand(tile, track, 0, flags, CMD_REMOVE_SIGNALS));
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-03-19 17:52:02 +00:00
|
|
|
if (flags & DC_EXEC) {
|
|
|
|
present ^= trackbit;
|
|
|
|
if (present == 0) {
|
|
|
|
DoClearSquare(tile);
|
|
|
|
} else {
|
|
|
|
SetTrackBits(tile, present);
|
|
|
|
}
|
(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;
|
2006-03-19 17:52:02 +00:00
|
|
|
}
|
2005-10-22 06:39:32 +00:00
|
|
|
|
2006-03-19 17:52:02 +00:00
|
|
|
default: return CMD_ERROR;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-03-19 17:52:02 +00:00
|
|
|
if (flags & DC_EXEC) {
|
|
|
|
MarkTileDirtyByTile(tile);
|
2006-03-21 21:11:41 +00:00
|
|
|
if (crossing) {
|
|
|
|
/* crossing is set when only TRACK_BIT_X and TRACK_BIT_Y are set. As we
|
|
|
|
* are removing one of these pieces, we'll need to update signals for
|
|
|
|
* both directions explicitly, as after the track is removed it won't
|
|
|
|
* 'connect' with the other piece. */
|
|
|
|
SetSignalsOnBothDir(tile, TRACK_X);
|
|
|
|
SetSignalsOnBothDir(tile, TRACK_Y);
|
2006-05-27 16:12:16 +00:00
|
|
|
YapfNotifyTrackLayoutChange(tile, TRACK_X);
|
|
|
|
YapfNotifyTrackLayoutChange(tile, TRACK_Y);
|
2006-03-21 21:11:41 +00:00
|
|
|
} else {
|
|
|
|
SetSignalsOnBothDir(tile, track);
|
2006-05-27 16:12:16 +00:00
|
|
|
YapfNotifyTrackLayoutChange(tile, track);
|
2006-03-21 21:11:41 +00:00
|
|
|
}
|
2006-03-19 17:52:02 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2006-04-10 12:36:04 +00:00
|
|
|
|
|
|
|
static const TileIndexDiffC _trackdelta[] = {
|
|
|
|
{ -1, 0 }, { 0, 1 }, { -1, 0 }, { 0, 1 }, { 1, 0 }, { 0, 1 },
|
|
|
|
{ 0, 0 },
|
|
|
|
{ 0, 0 },
|
|
|
|
{ 1, 0 }, { 0, -1 }, { 0, -1 }, { 1, 0 }, { 0, -1 }, { -1, 0 },
|
|
|
|
{ 0, 0 },
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-06-18 10:48:15 +00:00
|
|
|
static CommandCost ValidateAutoDrag(Trackdir *trackdir, TileIndex start, TileIndex end)
|
2005-01-30 15:57:38 +00:00
|
|
|
{
|
2006-04-10 12:36:04 +00:00
|
|
|
int x = TileX(start);
|
|
|
|
int y = TileY(start);
|
|
|
|
int ex = TileX(end);
|
|
|
|
int ey = TileY(end);
|
2005-01-30 15:57:38 +00:00
|
|
|
int dx, dy, trdx, trdy;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-01-10 18:56:51 +00:00
|
|
|
if (!ValParamTrackOrientation(TrackdirToTrack(*trackdir))) return CMD_ERROR;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-04-04 01:35:16 +00:00
|
|
|
/* calculate delta x,y from start to end tile */
|
2005-01-30 15:57:38 +00:00
|
|
|
dx = ex - x;
|
|
|
|
dy = ey - y;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-04-04 01:35:16 +00:00
|
|
|
/* calculate delta x,y for the first direction */
|
2006-04-10 12:36:04 +00:00
|
|
|
trdx = _trackdelta[*trackdir].x;
|
|
|
|
trdy = _trackdelta[*trackdir].y;
|
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)) {
|
2006-04-10 12:36:04 +00:00
|
|
|
trdx += _trackdelta[*trackdir ^ 1].x;
|
|
|
|
trdy += _trackdelta[*trackdir ^ 1].y;
|
2005-01-30 15:57:38 +00:00
|
|
|
}
|
|
|
|
|
2007-04-04 01:35:16 +00:00
|
|
|
/* validate the direction */
|
2006-02-01 06:32:03 +00:00
|
|
|
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
|
2007-02-23 20:51:10 +00:00
|
|
|
SetBitT(*trackdir, 3); // reverse the direction
|
2005-01-30 15:57:38 +00:00
|
|
|
trdx = -trdx;
|
|
|
|
trdy = -trdy;
|
2006-06-27 21:25:53 +00:00
|
|
|
} else { // other direction is invalid too, invalid drag
|
2005-01-30 15:57:38 +00:00
|
|
|
return CMD_ERROR;
|
2006-06-27 21:25:53 +00:00
|
|
|
}
|
2005-01-30 15:57:38 +00:00
|
|
|
}
|
|
|
|
|
2007-04-04 01:35:16 +00:00
|
|
|
/* (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)) {
|
2006-04-10 12:36:04 +00:00
|
|
|
trdx = _trackdelta[*trackdir].x;
|
|
|
|
trdy = _trackdelta[*trackdir].y;
|
2006-02-01 06:32:03 +00:00
|
|
|
if (abs(dx) != abs(dy) && abs(dx) + abs(trdy) != abs(dy) + abs(trdx))
|
2005-01-30 15:57:38 +00:00
|
|
|
return CMD_ERROR;
|
|
|
|
}
|
|
|
|
|
2007-06-18 19:53:50 +00:00
|
|
|
return CommandCost();
|
2005-01-30 15:57:38 +00:00
|
|
|
}
|
|
|
|
|
2005-05-07 10:26:12 +00:00
|
|
|
/** Build a stretch of railroad tracks.
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param tile start tile of drag
|
2007-04-17 21:09:38 +00:00
|
|
|
* @param flags operation to perform
|
2005-05-07 10:26:12 +00:00
|
|
|
* @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
|
|
|
*/
|
2007-06-18 10:48:15 +00:00
|
|
|
static CommandCost CmdRailTrackHelper(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-06-18 19:53:50 +00:00
|
|
|
CommandCost ret, total_cost;
|
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);
|
2005-11-05 18:21:28 +00:00
|
|
|
RailType railtype = (RailType)GB(p2, 0, 4);
|
2006-04-10 12:36:04 +00:00
|
|
|
TileIndex end_tile;
|
2005-01-30 15:57:38 +00:00
|
|
|
|
2005-11-05 18:21:28 +00:00
|
|
|
if (!ValParamRailtype(railtype) || !ValParamTrackOrientation(track)) return CMD_ERROR;
|
2006-01-30 17:18:45 +00:00
|
|
|
if (p1 >= MapSize()) return CMD_ERROR;
|
2006-04-10 12:36:04 +00:00
|
|
|
end_tile = p1;
|
(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-04 17:11:03 +00:00
|
|
|
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
|
|
|
|
|
2006-04-10 12:36:04 +00:00
|
|
|
if (CmdFailed(ValidateAutoDrag(&trackdir, tile, end_tile))) return CMD_ERROR;
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2006-04-10 12:36:04 +00:00
|
|
|
if (flags & DC_EXEC) SndPlayTileFx(SND_20_SPLAT_2, tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-02-01 07:36:15 +00:00
|
|
|
for (;;) {
|
2006-04-10 12:36:04 +00:00
|
|
|
ret = DoCommand(tile, railtype, 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)) {
|
2006-04-26 21:48:22 +00:00
|
|
|
if ((_error_message != STR_1007_ALREADY_BUILT) && (mode == 0)) break;
|
|
|
|
_error_message = INVALID_STRING_ID;
|
2006-06-27 21:25:53 +00:00
|
|
|
} else {
|
2007-06-18 19:53:50 +00:00
|
|
|
total_cost.AddCost(ret);
|
2006-06-27 21:25:53 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-10 12:36:04 +00:00
|
|
|
if (tile == end_tile) break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-10 12:36:04 +00:00
|
|
|
tile += ToTileIndexDiff(_trackdelta[trackdir]);
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2007-04-04 01:35:16 +00:00
|
|
|
/* toggle railbit for the non-diagonal tracks */
|
2007-02-23 20:51:10 +00:00
|
|
|
if (!IsDiagonalTrackdir(trackdir)) ToggleBitT(trackdir, 0);
|
2004-09-11 09:55:19 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-06-18 19:53:50 +00:00
|
|
|
return (total_cost.GetCost() == 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
|
2007-04-17 21:09:38 +00:00
|
|
|
* @param tile start tile of drag
|
|
|
|
* @param flags operation to perform
|
|
|
|
* @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)
|
|
|
|
* - p2 = (bit 4-6) - track-orientation, valid values: 0-5 (Track enum)
|
|
|
|
* - p2 = (bit 7) - 0 = build, 1 = remove tracks
|
2005-05-12 23:46:01 +00:00
|
|
|
* @see CmdRailTrackHelper
|
|
|
|
*/
|
2007-06-18 10:48:15 +00:00
|
|
|
CommandCost CmdBuildRailroadTrack(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
2005-01-30 15:57:38 +00:00
|
|
|
{
|
2006-04-10 07:15:58 +00:00
|
|
|
return CmdRailTrackHelper(tile, 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
|
2007-04-17 21:09:38 +00:00
|
|
|
* @param tile start tile of drag
|
|
|
|
* @param flags operation to perform
|
|
|
|
* @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)
|
|
|
|
* - p2 = (bit 4-6) - track-orientation, valid values: 0-5 (Track enum)
|
|
|
|
* - p2 = (bit 7) - 0 = build, 1 = remove tracks
|
2005-05-12 23:46:01 +00:00
|
|
|
* @see CmdRailTrackHelper
|
|
|
|
*/
|
2007-06-18 10:48:15 +00:00
|
|
|
CommandCost CmdRemoveRailroadTrack(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-04-10 07:15:58 +00:00
|
|
|
return CmdRailTrackHelper(tile, 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
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param tile position of the train depot
|
2007-04-17 21:09:38 +00:00
|
|
|
* @param flags operation to perform
|
2005-05-07 10:26:12 +00:00
|
|
|
* @param p1 rail type
|
2007-02-24 09:42:39 +00:00
|
|
|
* @param p2 bit 0..1 entrance direction (DiagDirection)
|
2005-07-16 23:47:37 +00:00
|
|
|
*
|
|
|
|
* @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
|
|
|
*/
|
2007-06-18 10:48:15 +00:00
|
|
|
CommandCost CmdBuildTrainDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-05-07 10:26:12 +00:00
|
|
|
Depot *d;
|
2007-06-18 19:53:50 +00:00
|
|
|
CommandCost cost;
|
2006-04-23 13:48:16 +00:00
|
|
|
Slope tileh;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
|
|
|
|
|
2005-05-07 10:26:12 +00:00
|
|
|
/* check railtype and valid direction for depot (0 through 3), 4 in total */
|
2007-02-24 09:42:39 +00:00
|
|
|
if (!ValParamRailtype(p1)) return CMD_ERROR;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
tileh = GetTileSlope(tile, NULL);
|
2005-07-16 23:47:37 +00:00
|
|
|
|
2007-02-24 09:42:39 +00:00
|
|
|
DiagDirection dir = Extract<DiagDirection, 0>(p2);
|
|
|
|
|
2005-07-16 23:47:37 +00:00
|
|
|
/* Prohibit construction if
|
2006-09-04 20:40:33 +00:00
|
|
|
* 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
|
|
|
|
*/
|
2005-07-16 23:47:37 +00:00
|
|
|
|
2006-04-23 13:48:16 +00:00
|
|
|
if (tileh != SLOPE_FLAT && (
|
2005-10-22 06:39:32 +00:00
|
|
|
_is_old_ai_player ||
|
|
|
|
!_patches.build_on_slopes ||
|
2006-04-23 13:48:16 +00:00
|
|
|
IsSteepSlope(tileh) ||
|
2007-02-24 09:42:39 +00:00
|
|
|
!CanBuildDepotByTileh(dir, tileh)
|
2005-10-22 06:39:32 +00:00
|
|
|
)) {
|
|
|
|
return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-06-18 19:53:50 +00:00
|
|
|
cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
|
|
|
if (CmdFailed(cost)) return CMD_ERROR;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-12-27 12:38:02 +00:00
|
|
|
if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
|
|
|
|
|
2005-05-07 10:26:12 +00:00
|
|
|
d = AllocateDepot();
|
2005-11-14 19:48:04 +00:00
|
|
|
if (d == NULL) return CMD_ERROR;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
2007-01-10 18:56:51 +00:00
|
|
|
MakeRailDepot(tile, _current_player, dir, (RailType)p1);
|
2006-03-01 08:56:38 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
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
|
|
|
|
2007-01-10 18:56:51 +00:00
|
|
|
UpdateSignalsOnSegment(tile, dir);
|
|
|
|
YapfNotifyTrackLayoutChange(tile, TrackdirToTrack(DiagdirToDiagTrackdir(dir)));
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-06-18 19:53:50 +00:00
|
|
|
return cost.AddCost(_price.build_train_depot);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-05-07 10:26:12 +00:00
|
|
|
/** Build signals, alternate between double/single, signal/semaphore,
|
2007-01-19 00:01:52 +00:00
|
|
|
* pre/exit/combo-signals, and what-else not. If the rail piece does not
|
|
|
|
* have any signals, bit 4 (cycle signal-type) is ignored
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param tile tile where to build the signals
|
2007-04-17 21:09:38 +00:00
|
|
|
* @param flags operation to perform
|
2005-05-07 10:26:12 +00:00
|
|
|
* @param p1 various bitstuffed elements
|
2007-01-19 17:44:11 +00:00
|
|
|
* - p1 = (bit 0-2) - track-orientation, valid values: 0-5 (Track enum)
|
|
|
|
* - p1 = (bit 3) - 1 = override signal/semaphore, or pre/exit/combo signal (CTRL-toggle)
|
|
|
|
* - p1 = (bit 4) - 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
|
|
|
* @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
|
|
|
*/
|
2007-06-18 10:48:15 +00:00
|
|
|
CommandCost CmdBuildSingleSignal(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-01-19 17:44:11 +00:00
|
|
|
Track track = (Track)GB(p1, 0, 3);
|
|
|
|
bool pre_signal = HASBIT(p1, 3);
|
|
|
|
SignalVariant sigvar = (pre_signal ^ HASBIT(p1, 4)) ? SIG_SEMAPHORE : SIG_ELECTRIC;
|
2007-06-18 10:48:15 +00:00
|
|
|
CommandCost cost;
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2007-04-01 11:11:49 +00:00
|
|
|
if (!ValParamTrackOrientation(track) || !IsTileType(tile, MP_RAILWAY) || !EnsureNoVehicleOnGround(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
|
|
|
|
(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
|
|
|
{
|
2006-06-27 21:25:53 +00:00
|
|
|
/* See if this is a valid track combination for signals, (ie, no overlap) */
|
|
|
|
TrackBits trackbits = GetTrackBits(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
|
|
|
if (KILL_FIRST_BIT(trackbits) != 0 && /* More than one track present */
|
2006-03-18 13:20:50 +00:00
|
|
|
trackbits != TRACK_BIT_HORZ &&
|
2006-06-27 21:25:53 +00:00
|
|
|
trackbits != TRACK_BIT_VERT) {
|
2004-08-09 17:04:08 +00:00
|
|
|
return CMD_ERROR;
|
2006-06-27 21:25:53 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
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)) {
|
2007-04-04 01:35:16 +00:00
|
|
|
/* build new signals */
|
2007-06-18 19:53:50 +00:00
|
|
|
cost = CommandCost(_price.build_signals);
|
2005-01-19 13:31:46 +00:00
|
|
|
} else {
|
2007-05-31 21:21:04 +00:00
|
|
|
if (p2 != 0 && sigvar != GetSignalVariant(tile, track)) {
|
2007-04-04 01:35:16 +00:00
|
|
|
/* convert signals <-> semaphores */
|
2007-06-18 19:53:50 +00:00
|
|
|
cost = CommandCost(_price.build_signals + _price.remove_signals);
|
2005-01-22 14:52:20 +00:00
|
|
|
} else {
|
2007-04-06 04:10:19 +00:00
|
|
|
/* it is free to change orientation/pre-exit-combo signals */
|
2007-06-18 19:53:50 +00:00
|
|
|
cost = CommandCost();
|
2005-01-22 14:52:20 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
2006-07-27 05:30:53 +00:00
|
|
|
if (!HasSignals(tile)) {
|
2007-04-04 01:35:16 +00:00
|
|
|
/* there are no signals at all on this tile yet */
|
2007-02-27 23:36:28 +00:00
|
|
|
SetHasSignals(tile, true);
|
2007-05-30 13:33:19 +00:00
|
|
|
SetSignalStates(tile, 0xF); // all signals are on
|
|
|
|
SetPresentSignals(tile, 0); // no signals built by default
|
2007-05-31 21:21:04 +00:00
|
|
|
SetSignalType(tile, track, SIGTYPE_NORMAL);
|
|
|
|
SetSignalVariant(tile, track, sigvar);
|
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)) {
|
2007-04-04 01:35:16 +00:00
|
|
|
/* build new signals */
|
2007-05-30 13:33:19 +00:00
|
|
|
SetPresentSignals(tile, GetPresentSignals(tile) | SignalOnTrack(track));
|
2007-05-31 21:21:04 +00:00
|
|
|
SetSignalType(tile, track, SIGTYPE_NORMAL);
|
|
|
|
SetSignalVariant(tile, track, sigvar);
|
2005-01-22 14:52:20 +00:00
|
|
|
} else {
|
|
|
|
if (pre_signal) {
|
2007-04-04 01:35:16 +00:00
|
|
|
/* cycle between normal -> pre -> exit -> combo -> ... */
|
2007-05-31 21:21:04 +00:00
|
|
|
SignalType type = GetSignalType(tile, track);
|
2006-03-17 06:26:37 +00:00
|
|
|
|
2007-05-31 21:21:04 +00:00
|
|
|
SetSignalType(tile, track, type == SIGTYPE_COMBO ? SIGTYPE_NORMAL : (SignalType)(type + 1));
|
2005-01-22 14:52:20 +00:00
|
|
|
} else {
|
2006-04-12 09:36:27 +00:00
|
|
|
CycleSignalSide(tile, track);
|
2005-01-22 14:52:20 +00:00
|
|
|
}
|
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 */
|
2007-05-30 13:33:19 +00:00
|
|
|
SetPresentSignals(tile, (GetPresentSignals(tile) & ~SignalOnTrack(track)) | (p2 & SignalOnTrack(track)));
|
2007-05-31 21:21:04 +00:00
|
|
|
SetSignalVariant(tile, track, sigvar);
|
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);
|
2006-05-27 16:12:16 +00:00
|
|
|
YapfNotifyTrackLayoutChange(tile, track);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return cost;
|
|
|
|
}
|
|
|
|
|
2007-07-04 17:21:28 +00:00
|
|
|
static bool CheckSignalAutoFill(TileIndex &tile, Trackdir &trackdir, int &signal_ctr, bool remove)
|
|
|
|
{
|
|
|
|
tile = AddTileIndexDiffCWrap(tile, _trackdelta[trackdir]);
|
|
|
|
if (tile == INVALID_TILE) return false;
|
|
|
|
|
|
|
|
/* Check for track bits on the new tile */
|
|
|
|
uint32 ts = GetTileTrackStatus(tile, TRANSPORT_RAIL, 0);
|
|
|
|
TrackdirBits trackdirbits = (TrackdirBits)(ts & TRACKDIR_BIT_MASK);
|
|
|
|
|
|
|
|
if (TracksOverlap(TrackdirBitsToTrackBits(trackdirbits))) return false;
|
|
|
|
trackdirbits &= TrackdirReachesTrackdirs(trackdir);
|
|
|
|
|
|
|
|
/* No track bits, must stop */
|
|
|
|
if (trackdirbits == TRACKDIR_BIT_NONE) return false;
|
|
|
|
|
|
|
|
/* Get the first track dir */
|
|
|
|
trackdir = RemoveFirstTrackdir(&trackdirbits);
|
|
|
|
|
|
|
|
/* Any left? It's a junction so we stop */
|
|
|
|
if (trackdirbits != TRACKDIR_BIT_NONE) return false;
|
|
|
|
|
|
|
|
switch (GetTileType(tile)) {
|
|
|
|
case MP_RAILWAY:
|
|
|
|
if (IsRailDepot(tile)) return false;
|
|
|
|
if (!remove && HasSignalOnTrack(tile, TrackdirToTrack(trackdir))) return false;
|
|
|
|
signal_ctr++;
|
|
|
|
if (IsDiagonalTrackdir(trackdir)) {
|
|
|
|
signal_ctr++;
|
|
|
|
/* Ensure signal_ctr even so X and Y pieces get signals */
|
|
|
|
CLRBIT(signal_ctr, 0);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case MP_STREET:
|
|
|
|
if (!IsLevelCrossing(tile)) return false;
|
|
|
|
signal_ctr += 2;
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case MP_TUNNELBRIDGE: {
|
|
|
|
TileIndex orig_tile = tile;
|
|
|
|
/* Skip to end of tunnel or bridge */
|
|
|
|
if (IsBridge(tile)) {
|
|
|
|
if (GetBridgeTransportType(tile) != TRANSPORT_RAIL) return false;
|
|
|
|
if (GetBridgeRampDirection(tile) != TrackdirToExitdir(trackdir)) return false;
|
|
|
|
tile = GetOtherBridgeEnd(tile);
|
|
|
|
} else {
|
|
|
|
if (GetTunnelTransportType(tile) != TRANSPORT_RAIL) return false;
|
|
|
|
if (GetTunnelDirection(tile) != TrackdirToExitdir(trackdir)) return false;
|
|
|
|
tile = GetOtherTunnelEnd(tile);
|
|
|
|
}
|
|
|
|
signal_ctr += 2 + DistanceMax(orig_tile, tile) * 2;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
default: return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-28 18:53:03 +00:00
|
|
|
/** Build many signals by dragging; AutoSignals
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param tile start tile of drag
|
2007-04-17 21:09:38 +00:00
|
|
|
* @param flags operation to perform
|
2005-05-12 23:46:01 +00:00
|
|
|
* @param p1 end tile of drag
|
|
|
|
* @param p2 various bitstuffed elements
|
2007-01-19 17:44:11 +00:00
|
|
|
* - p2 = (bit 0- 2) - track-orientation, valid values: 0-5 (Track enum)
|
|
|
|
* - p2 = (bit 3) - 1 = override signal/semaphore, or pre/exit/combo signal (CTRL-toggle)
|
|
|
|
* - p2 = (bit 4) - 0 = signals, 1 = semaphores
|
2007-01-19 00:01:52 +00:00
|
|
|
* - p2 = (bit 5) - 0 = build, 1 = remove signals
|
2007-07-04 17:21:28 +00:00
|
|
|
* - p2 = (bit 6) - 0 = selected stretch, 1 = auto fill
|
2005-05-12 23:46:01 +00:00
|
|
|
* - p2 = (bit 24-31) - user defined signals_density
|
2004-08-15 20:23:42 +00:00
|
|
|
*/
|
2007-06-18 10:48:15 +00:00
|
|
|
static CommandCost CmdSignalTrackHelper(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
2004-08-15 20:23:42 +00:00
|
|
|
{
|
2007-06-18 10:48:15 +00:00
|
|
|
CommandCost ret, total_cost;
|
|
|
|
int signal_ctr;
|
2005-06-19 11:56:07 +00:00
|
|
|
byte signals;
|
2005-05-12 23:46:01 +00:00
|
|
|
bool error = true;
|
2006-04-10 12:36:04 +00:00
|
|
|
TileIndex end_tile;
|
2007-07-04 17:21:28 +00:00
|
|
|
TileIndex start_tile = tile;
|
2005-05-12 23:46:01 +00:00
|
|
|
|
2007-01-19 17:44:11 +00:00
|
|
|
Track track = (Track)GB(p2, 0, 3);
|
|
|
|
bool mode = HASBIT(p2, 3);
|
|
|
|
bool semaphores = HASBIT(p2, 4);
|
2007-01-19 00:01:52 +00:00
|
|
|
bool remove = HASBIT(p2, 5);
|
2007-07-04 17:21:28 +00:00
|
|
|
bool autofill = HASBIT(p2, 6);
|
(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);
|
2007-01-19 00:01:52 +00:00
|
|
|
byte signal_density = GB(p2, 24, 8);
|
2005-05-12 23:46:01 +00:00
|
|
|
|
2006-01-30 17:18:45 +00:00
|
|
|
if (p1 >= MapSize()) return CMD_ERROR;
|
2006-04-10 12:36:04 +00:00
|
|
|
end_tile = p1;
|
2005-05-12 23:46:01 +00:00
|
|
|
if (signal_density == 0 || signal_density > 20) return CMD_ERROR;
|
2004-08-15 20:23:42 +00:00
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
if (!IsTileType(tile, MP_RAILWAY)) return CMD_ERROR;
|
2005-06-19 11:56:07 +00:00
|
|
|
|
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
|
2006-09-04 20:40:33 +00:00
|
|
|
* since the original amount will be too dense (shorter tracks) */
|
2007-07-04 17:21:28 +00:00
|
|
|
signal_density *= 2;
|
2005-05-12 23:46:01 +00:00
|
|
|
|
2006-04-10 12:36:04 +00:00
|
|
|
if (CmdFailed(ValidateAutoDrag(&trackdir, tile, end_tile))) 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 */
|
2007-07-04 17:21:28 +00:00
|
|
|
Trackdir start_trackdir = trackdir;
|
|
|
|
|
|
|
|
/* Autofill must start on a valid track to be able to avoid loops */
|
|
|
|
if (autofill && !HasTrack(tile, track)) return CMD_ERROR;
|
2004-08-15 20:23:42 +00:00
|
|
|
|
2007-04-06 04:10:19 +00:00
|
|
|
/* copy the signal-style of the first rail-piece if existing */
|
2006-07-27 05:30:53 +00:00
|
|
|
if (HasSignals(tile)) {
|
2007-05-30 13:33:19 +00:00
|
|
|
signals = GetPresentSignals(tile) & 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
|
|
|
|
2007-04-04 01:35:16 +00:00
|
|
|
/* copy signal/semaphores style (independent of CTRL) */
|
2007-05-31 21:21:04 +00:00
|
|
|
semaphores = GetSignalVariant(tile, track) != SIG_ELECTRIC;
|
2006-06-27 21:25:53 +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);
|
2006-06-27 21:25:53 +00:00
|
|
|
}
|
2004-08-15 20:23:42 +00:00
|
|
|
|
2007-07-04 17:21:28 +00:00
|
|
|
byte signal_dir = 0;
|
|
|
|
if (signals & SignalAlongTrackdir(trackdir)) SETBIT(signal_dir, 0);
|
|
|
|
if (signals & SignalAgainstTrackdir(trackdir)) SETBIT(signal_dir, 1);
|
|
|
|
|
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)
|
2006-09-04 20:40:33 +00:00
|
|
|
* and convert all others to semaphore/signal
|
2007-01-19 00:01:52 +00:00
|
|
|
* remove - 1 remove signals, 0 build signals */
|
2007-06-18 19:53:50 +00:00
|
|
|
signal_ctr = 0;
|
2005-05-12 23:46:01 +00:00
|
|
|
for (;;) {
|
2007-04-04 01:35:16 +00:00
|
|
|
/* only build/remove signals with the specified density */
|
2007-07-04 17:21:28 +00:00
|
|
|
if ((remove && autofill) || signal_ctr % signal_density == 0) {
|
2007-01-19 17:44:11 +00:00
|
|
|
uint32 p1 = GB(TrackdirToTrack(trackdir), 0, 3);
|
|
|
|
SB(p1, 3, 1, mode);
|
|
|
|
SB(p1, 4, 1, semaphores);
|
2007-07-04 17:21:28 +00:00
|
|
|
|
|
|
|
/* Pick the correct orientation for the track direction */
|
|
|
|
signals = 0;
|
|
|
|
if (HASBIT(signal_dir, 0)) signals |= SignalAlongTrackdir(trackdir);
|
|
|
|
if (HASBIT(signal_dir, 1)) signals |= SignalAgainstTrackdir(trackdir);
|
|
|
|
|
2007-01-19 00:01:52 +00:00
|
|
|
ret = DoCommand(tile, p1, signals, flags, remove ? CMD_REMOVE_SIGNALS : CMD_BUILD_SIGNALS);
|
2004-08-15 20:23:42 +00:00
|
|
|
|
2006-11-10 19:04:27 +00:00
|
|
|
/* Be user-friendly and try placing signals as much as possible */
|
2007-06-18 16:42:40 +00:00
|
|
|
if (CmdSucceeded(ret)) {
|
2004-08-15 20:23:42 +00:00
|
|
|
error = false;
|
2007-06-18 19:53:50 +00:00
|
|
|
total_cost.AddCost(ret);
|
2004-08-15 20:23:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-04 17:21:28 +00:00
|
|
|
if (autofill) {
|
|
|
|
if (!CheckSignalAutoFill(tile, trackdir, signal_ctr, remove)) break;
|
2004-08-15 20:23:42 +00:00
|
|
|
|
2007-07-04 17:21:28 +00:00
|
|
|
/* Prevent possible loops */
|
|
|
|
if (tile == start_tile && trackdir == start_trackdir) break;
|
|
|
|
} else {
|
|
|
|
if (tile == end_tile) break;
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2007-07-04 17:21:28 +00:00
|
|
|
tile += ToTileIndexDiff(_trackdelta[trackdir]);
|
|
|
|
signal_ctr++;
|
|
|
|
|
|
|
|
/* toggle railbit for the non-diagonal tracks (|, -- tracks) */
|
|
|
|
if (IsDiagonalTrackdir(trackdir)) {
|
|
|
|
signal_ctr++;
|
|
|
|
} else {
|
|
|
|
ToggleBitT(trackdir, 0);
|
|
|
|
}
|
|
|
|
}
|
2004-08-15 20:23:42 +00:00
|
|
|
}
|
|
|
|
|
2006-02-01 06:32:03 +00:00
|
|
|
return error ? CMD_ERROR : total_cost;
|
2004-08-15 20:23:42 +00:00
|
|
|
}
|
|
|
|
|
2005-05-12 23:46:01 +00:00
|
|
|
/** Build signals on a stretch of track.
|
|
|
|
* Stub for the unified signal builder/remover
|
2007-04-17 21:09:38 +00:00
|
|
|
* @param tile start tile of drag
|
|
|
|
* @param flags operation to perform
|
|
|
|
* @param p1 end tile of drag
|
|
|
|
* @param p2 various bitstuffed elements
|
|
|
|
* - p2 = (bit 0- 2) - track-orientation, valid values: 0-5 (Track enum)
|
|
|
|
* - p2 = (bit 3) - 1 = override signal/semaphore, or pre/exit/combo signal (CTRL-toggle)
|
|
|
|
* - p2 = (bit 4) - 0 = signals, 1 = semaphores
|
|
|
|
* - p2 = (bit 5) - 0 = build, 1 = remove signals
|
2007-07-04 17:21:28 +00:00
|
|
|
* - p2 = (bit 6) - 0 = selected stretch, 1 = auto fill
|
2007-04-17 21:09:38 +00:00
|
|
|
* - p2 = (bit 24-31) - user defined signals_density
|
2005-05-12 23:46:01 +00:00
|
|
|
* @see CmdSignalTrackHelper
|
|
|
|
*/
|
2007-06-18 10:48:15 +00:00
|
|
|
CommandCost CmdBuildSignalTrack(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
2005-01-30 15:57:38 +00:00
|
|
|
{
|
2006-04-10 07:15:58 +00:00
|
|
|
return CmdSignalTrackHelper(tile, flags, p1, p2);
|
2005-01-30 15:57:38 +00:00
|
|
|
}
|
|
|
|
|
2005-05-07 10:26:12 +00:00
|
|
|
/** Remove signals
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param tile coordinates where signal is being deleted from
|
2007-04-17 21:09:38 +00:00
|
|
|
* @param flags operation to perform
|
2007-04-18 18:00:33 +00:00
|
|
|
* @param p1 various bitstuffed elements, only track information is used
|
|
|
|
* - (bit 0- 2) - track-orientation, valid values: 0-5 (Track enum)
|
|
|
|
* - (bit 3) - override signal/semaphore, or pre/exit/combo signal (CTRL-toggle)
|
|
|
|
* - (bit 4) - 0 = signals, 1 = semaphores
|
|
|
|
* @param p2 unused
|
2004-08-09 17:04:08 +00:00
|
|
|
*/
|
2007-06-18 10:48:15 +00:00
|
|
|
CommandCost CmdRemoveSingleSignal(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-01-19 17:44:11 +00:00
|
|
|
Track track = (Track)GB(p1, 0, 3);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-06-27 21:25:53 +00:00
|
|
|
if (!ValParamTrackOrientation(track) ||
|
|
|
|
!IsTileType(tile, MP_RAILWAY) ||
|
2007-04-01 11:11:49 +00:00
|
|
|
!EnsureNoVehicleOnGround(tile) ||
|
2006-06-27 21:25:53 +00:00
|
|
|
!HasSignalOnTrack(tile, track)) {
|
2004-08-09 17:04:08 +00:00
|
|
|
return CMD_ERROR;
|
2006-06-27 21:25:53 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
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) {
|
2007-05-30 13:33:19 +00:00
|
|
|
SetPresentSignals(tile, GetPresentSignals(tile) & ~SignalOnTrack(track));
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2005-01-19 13:31:46 +00:00
|
|
|
/* removed last signal from tile? */
|
2007-05-30 13:33:19 +00:00
|
|
|
if (GetPresentSignals(tile) == 0) {
|
|
|
|
SetSignalStates(tile, 0);
|
2007-02-27 23:36:28 +00:00
|
|
|
SetHasSignals(tile, false);
|
2007-05-31 21:21:04 +00:00
|
|
|
SetSignalVariant(tile, INVALID_TRACK, SIG_ELECTRIC); // 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);
|
2006-05-27 16:12:16 +00:00
|
|
|
YapfNotifyTrackLayoutChange(tile, track);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
}
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2007-06-18 19:53:50 +00:00
|
|
|
return CommandCost(_price.remove_signals);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-05-12 23:46:01 +00:00
|
|
|
/** Remove signals on a stretch of track.
|
|
|
|
* Stub for the unified signal builder/remover
|
2007-04-17 21:09:38 +00:00
|
|
|
* @param tile start tile of drag
|
|
|
|
* @param flags operation to perform
|
|
|
|
* @param p1 end tile of drag
|
|
|
|
* @param p2 various bitstuffed elements
|
|
|
|
* - p2 = (bit 0- 2) - track-orientation, valid values: 0-5 (Track enum)
|
|
|
|
* - p2 = (bit 3) - 1 = override signal/semaphore, or pre/exit/combo signal (CTRL-toggle)
|
|
|
|
* - p2 = (bit 4) - 0 = signals, 1 = semaphores
|
|
|
|
* - p2 = (bit 5) - 0 = build, 1 = remove signals
|
2007-07-04 17:21:28 +00:00
|
|
|
* - p2 = (bit 6) - 0 = selected stretch, 1 = auto fill
|
2007-04-17 21:09:38 +00:00
|
|
|
* - p2 = (bit 24-31) - user defined signals_density
|
2005-05-12 23:46:01 +00:00
|
|
|
* @see CmdSignalTrackHelper
|
|
|
|
*/
|
2007-06-18 10:48:15 +00:00
|
|
|
CommandCost CmdRemoveSignalTrack(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
2005-01-30 15:57:38 +00:00
|
|
|
{
|
2007-01-19 00:01:52 +00:00
|
|
|
return CmdSignalTrackHelper(tile, flags, p1, SETBIT(p2, 5)); // bit 5 is remove bit
|
2005-01-30 15:57:38 +00:00
|
|
|
}
|
|
|
|
|
2007-06-18 10:48:15 +00:00
|
|
|
typedef CommandCost DoConvertRailProc(TileIndex tile, RailType totype, bool exec);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-24 09:12:03 +00:00
|
|
|
/**
|
|
|
|
* Switches the rail type.
|
|
|
|
* Railtypes are stored on a per-tile basis, not on a per-track basis, so
|
|
|
|
* all the tracks in the given tile will be converted.
|
|
|
|
* @param tile The tile on which the railtype is to be convert.
|
|
|
|
* @param totype The railtype we want to convert to
|
|
|
|
* @param exec Switches between test and execute mode
|
|
|
|
* @return The cost and state of the operation
|
|
|
|
* @retval CMD_ERROR An error occured during the operation.
|
|
|
|
*/
|
2007-06-18 10:48:15 +00:00
|
|
|
static CommandCost DoConvertRail(TileIndex tile, RailType totype, bool exec)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-03-29 16:30:26 +00:00
|
|
|
if (!CheckTileOwnership(tile)) return CMD_ERROR;
|
|
|
|
|
2005-10-23 13:04:44 +00:00
|
|
|
if (GetRailType(tile) == totype) return CMD_ERROR;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-04-01 11:11:49 +00:00
|
|
|
if (!EnsureNoVehicleOnGround(tile) && (!IsCompatibleRail(GetRailType(tile), totype) || IsPlainRailTile(tile))) return CMD_ERROR;
|
2007-03-24 09:12:03 +00:00
|
|
|
|
2007-04-04 01:35:16 +00:00
|
|
|
/* 'hidden' elrails can't be downgraded to normal rail when elrails are disabled */
|
2006-11-17 19:31:44 +00:00
|
|
|
if (_patches.disable_elrails && totype == RAILTYPE_RAIL && GetRailType(tile) == RAILTYPE_ELECTRIC) return CMD_ERROR;
|
|
|
|
|
2007-04-04 01:35:16 +00:00
|
|
|
/* change type. */
|
2004-08-09 17:04:08 +00:00
|
|
|
if (exec) {
|
2006-03-17 10:10:31 +00:00
|
|
|
SetRailType(tile, totype);
|
2004-08-09 17:04:08 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
2006-05-18 16:51:42 +00:00
|
|
|
|
2007-04-04 01:35:16 +00:00
|
|
|
/* notify YAPF about the track layout change */
|
2007-01-10 18:56:51 +00:00
|
|
|
TrackBits tracks = GetTrackBits(tile);
|
|
|
|
while (tracks != TRACK_BIT_NONE) {
|
2007-01-11 10:34:42 +00:00
|
|
|
YapfNotifyTrackLayoutChange(tile, RemoveFirstTrack(&tracks));
|
2007-01-10 18:56:51 +00:00
|
|
|
}
|
2006-05-27 16:12:16 +00:00
|
|
|
|
2006-05-18 16:51:42 +00:00
|
|
|
if (IsTileDepotType(tile, TRANSPORT_RAIL)) {
|
2006-09-05 16:40:23 +00:00
|
|
|
Vehicle *v;
|
|
|
|
|
|
|
|
/* Update build vehicle window related to this depot */
|
2006-10-10 08:14:30 +00:00
|
|
|
InvalidateWindowData(WC_BUILD_VEHICLE, tile);
|
2006-09-05 16:40:23 +00:00
|
|
|
|
|
|
|
/* update power of trains in this depot */
|
|
|
|
FOR_ALL_VEHICLES(v) {
|
2007-03-08 16:27:54 +00:00
|
|
|
if (v->type == VEH_TRAIN && IsFrontEngine(v) && v->tile == tile && v->u.rail.track == 0x80) {
|
2006-09-05 16:40:23 +00:00
|
|
|
TrainPowerChanged(v);
|
|
|
|
}
|
|
|
|
}
|
2006-05-18 16:51:42 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-06-18 19:53:50 +00:00
|
|
|
return CommandCost(_price.build_rail / 2);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-06-18 10:48:15 +00:00
|
|
|
extern CommandCost DoConvertStationRail(TileIndex tile, RailType totype, bool exec);
|
|
|
|
extern CommandCost DoConvertStreetRail(TileIndex tile, RailType totype, bool exec);
|
|
|
|
extern CommandCost DoConvertTunnelBridgeRail(TileIndex tile, RailType 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.
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param tile end tile of rail conversion drag
|
2007-04-17 21:09:38 +00:00
|
|
|
* @param flags operation to perform
|
2005-05-09 16:37:40 +00:00
|
|
|
* @param p1 start tile of drag
|
|
|
|
* @param p2 new railtype to convert to
|
|
|
|
*/
|
2007-06-18 10:48:15 +00:00
|
|
|
CommandCost CmdConvertRail(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-06-18 10:48:15 +00:00
|
|
|
CommandCost ret, cost;
|
2007-06-21 14:32:27 +00:00
|
|
|
Money money;
|
2006-04-10 07:15:58 +00:00
|
|
|
int ex;
|
|
|
|
int ey;
|
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;
|
2006-01-30 17:18:45 +00:00
|
|
|
if (p1 >= MapSize()) return CMD_ERROR;
|
2005-05-09 16:37:40 +00:00
|
|
|
|
2007-04-04 01:35:16 +00:00
|
|
|
/* make sure sx,sy are smaller than ex,ey */
|
2006-04-10 12:36:04 +00:00
|
|
|
ex = TileX(tile);
|
|
|
|
ey = TileY(tile);
|
|
|
|
sx = TileX(p1);
|
|
|
|
sy = TileY(p1);
|
2007-02-22 08:43:02 +00:00
|
|
|
if (ex < sx) Swap(ex, sx);
|
|
|
|
if (ey < sy) Swap(ey, sy);
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
money = GetAvailableMoneyForCommand();
|
2005-05-09 16:37:40 +00:00
|
|
|
|
2006-04-10 12:36:04 +00:00
|
|
|
for (x = sx; x <= ex; ++x) {
|
|
|
|
for (y = sy; y <= ey; ++y) {
|
|
|
|
TileIndex tile = TileXY(x, y);
|
2005-10-23 13:04:44 +00:00
|
|
|
DoConvertRailProc* proc;
|
|
|
|
|
|
|
|
switch (GetTileType(tile)) {
|
|
|
|
case MP_RAILWAY: proc = DoConvertRail; break;
|
|
|
|
case MP_STATION: proc = DoConvertStationRail; break;
|
|
|
|
case MP_STREET: proc = DoConvertStreetRail; break;
|
|
|
|
case MP_TUNNELBRIDGE: proc = DoConvertTunnelBridgeRail; break;
|
|
|
|
default: continue;
|
|
|
|
}
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2007-01-10 18:56:51 +00:00
|
|
|
ret = proc(tile, (RailType)p2, false);
|
2005-05-09 16:37:40 +00:00
|
|
|
if (CmdFailed(ret)) continue;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
2007-06-18 19:53:50 +00:00
|
|
|
money -= ret.GetCost();
|
2005-10-23 13:04:44 +00:00
|
|
|
if (money < 0) {
|
2007-06-18 19:53:50 +00:00
|
|
|
_additional_cash_required = ret.GetCost();
|
|
|
|
return cost;
|
2005-10-23 13:04:44 +00:00
|
|
|
}
|
2007-01-10 18:56:51 +00:00
|
|
|
proc(tile, (RailType)p2, true);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2007-06-18 19:53:50 +00:00
|
|
|
cost.AddCost(ret);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
2005-05-09 16:37:40 +00:00
|
|
|
|
2007-06-18 19:53:50 +00:00
|
|
|
return (cost.GetCost() == 0) ? ret : cost;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-06-18 10:48:15 +00:00
|
|
|
static CommandCost 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;
|
|
|
|
|
2007-04-01 11:11:49 +00:00
|
|
|
if (!EnsureNoVehicleOnGround(tile))
|
2004-08-09 17:04:08 +00:00
|
|
|
return CMD_ERROR;
|
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
2006-03-13 20:12:35 +00:00
|
|
|
DiagDirection dir = GetRailDepotDirection(tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-08-26 14:44:55 +00:00
|
|
|
DeleteDepot(GetDepotByTile(tile));
|
2006-03-13 20:12:35 +00:00
|
|
|
UpdateSignalsOnSegment(tile, dir);
|
2006-05-27 16:12:16 +00:00
|
|
|
YapfNotifyTrackLayoutChange(tile, TrackdirToTrack(DiagdirToDiagTrackdir(dir)));
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-06-18 19:53:50 +00:00
|
|
|
return CommandCost(_price.remove_train_depot);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-06-18 10:48:15 +00:00
|
|
|
static CommandCost ClearTile_Track(TileIndex tile, byte flags)
|
2005-03-23 20:02:28 +00:00
|
|
|
{
|
2007-06-18 10:48:15 +00:00
|
|
|
CommandCost cost;
|
|
|
|
CommandCost ret;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (flags & DC_AUTO) {
|
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);
|
|
|
|
|
2006-07-27 05:30:53 +00:00
|
|
|
if (IsPlainRailTile(tile)) {
|
|
|
|
return_cmd_error(STR_1008_MUST_REMOVE_RAILROAD_TRACK);
|
|
|
|
} else {
|
|
|
|
return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED);
|
|
|
|
}
|
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
|
|
|
switch (GetRailTileType(tile)) {
|
2006-05-09 08:17:33 +00:00
|
|
|
case RAIL_TILE_SIGNALS:
|
|
|
|
case RAIL_TILE_NORMAL: {
|
2006-12-29 16:40:22 +00:00
|
|
|
TrackBits tracks = GetTrackBits(tile);
|
2007-01-10 18:56:51 +00:00
|
|
|
while (tracks != TRACK_BIT_NONE) {
|
2007-01-11 10:34:42 +00:00
|
|
|
Track track = RemoveFirstTrack(&tracks);
|
2007-01-10 18:56:51 +00:00
|
|
|
ret = DoCommand(tile, 0, track, flags, CMD_REMOVE_SINGLE_RAIL);
|
2006-12-29 10:16:36 +00:00
|
|
|
if (CmdFailed(ret)) return CMD_ERROR;
|
2007-06-18 19:53:50 +00:00
|
|
|
cost.AddCost(ret);
|
2005-03-23 20:02:28 +00:00
|
|
|
}
|
|
|
|
return cost;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-02-27 23:36:28 +00:00
|
|
|
case RAIL_TILE_DEPOT:
|
|
|
|
return RemoveTrainDepot(tile, flags);
|
|
|
|
|
|
|
|
case RAIL_TILE_WAYPOINT:
|
|
|
|
return RemoveTrainWaypoint(tile, flags, false);
|
2005-03-23 20:02:28 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
return CMD_ERROR;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#include "table/track_land.h"
|
|
|
|
|
2007-05-31 21:21:04 +00:00
|
|
|
static void DrawSingleSignal(TileIndex tile, Track track, byte condition, uint image, uint pos)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-01-10 18:56:51 +00:00
|
|
|
bool side = (_opt.road_side != 0) && _patches.signal_side;
|
2006-04-11 10:19:50 +00:00
|
|
|
static const Point SignalPositions[2][12] = {
|
|
|
|
{ /* Signals on the left side */
|
|
|
|
/* LEFT LEFT RIGHT RIGHT UPPER UPPER */
|
|
|
|
{ 8, 5}, {14, 1}, { 1, 14}, { 9, 11}, { 1, 0}, { 3, 10},
|
|
|
|
/* LOWER LOWER X X Y Y */
|
|
|
|
{11, 4}, {14, 14}, {11, 3}, { 4, 13}, { 3, 4}, {11, 13}
|
|
|
|
}, { /* Signals on the right side */
|
|
|
|
/* LEFT LEFT RIGHT RIGHT UPPER UPPER */
|
|
|
|
{14, 1}, {12, 10}, { 4, 6}, { 1, 14}, {10, 4}, { 0, 1},
|
|
|
|
/* LOWER LOWER X X Y Y */
|
|
|
|
{14, 14}, { 5, 12}, {11, 13}, { 4, 3}, {13, 4}, { 3, 11}
|
|
|
|
}
|
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-11 13:10:16 +00:00
|
|
|
static const SpriteID SignalBase[2][2][4] = {
|
|
|
|
{ /* Signals on left side */
|
|
|
|
{ 0x4FB, 0x1323, 0x1333, 0x1343}, /* light signals */
|
|
|
|
{ 0x1353, 0x1363, 0x1373, 0x1383} /* semaphores */
|
|
|
|
}, { /* Signals on right side */
|
|
|
|
{ 0x4FB, 0x1323, 0x1333, 0x1343}, /* light signals */
|
|
|
|
{ 0x1446, 0x1456, 0x1466, 0x1476} /* semaphores */
|
|
|
|
/* | | | | */
|
|
|
|
/* normal, entry, exit, combo */
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2006-04-17 19:09:30 +00:00
|
|
|
uint x = TileX(tile) * TILE_SIZE + SignalPositions[side][pos].x;
|
|
|
|
uint y = TileY(tile) * TILE_SIZE + SignalPositions[side][pos].y;
|
|
|
|
|
2006-04-23 15:57:34 +00:00
|
|
|
SpriteID sprite;
|
|
|
|
|
|
|
|
/* _signal_base is set by our NewGRF Action 5 loader. If it is 0 then we
|
|
|
|
* just draw the standard signals, else we get the offset from _signal_base
|
|
|
|
* and draw that sprite. All the signal sprites are loaded sequentially. */
|
2007-05-31 21:21:04 +00:00
|
|
|
if (_signal_base == 0 || (GetSignalType(tile, track) == SIGTYPE_NORMAL && GetSignalVariant(tile, track) == SIG_ELECTRIC)) {
|
|
|
|
sprite = SignalBase[side][GetSignalVariant(tile, track)][GetSignalType(tile, track)] + image + condition;
|
2006-04-23 15:57:34 +00:00
|
|
|
} else {
|
2007-05-31 21:21:04 +00:00
|
|
|
sprite = _signal_base + (GetSignalType(tile, track) - 1) * 16 + GetSignalVariant(tile, track) * 64 + image + condition;
|
2006-04-23 15:57:34 +00:00
|
|
|
}
|
2006-04-17 19:09:30 +00:00
|
|
|
|
2007-01-14 19:57:49 +00:00
|
|
|
AddSortableSpriteToDraw(sprite, PAL_NONE, x, y, 1, 1, 10, GetSlopeZ(x,y));
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2007-07-23 16:08:58 +00:00
|
|
|
SpriteID image = SPR_TRACK_FENCE_FLAT_X;
|
|
|
|
if (ti->tileh != SLOPE_FLAT) image = (ti->tileh & SLOPE_S) ? SPR_TRACK_FENCE_SLOPE_SW : SPR_TRACK_FENCE_SLOPE_NE;
|
2007-01-14 19:57:49 +00:00
|
|
|
AddSortableSpriteToDraw(image, _drawtile_track_palette,
|
2006-02-01 06:32:03 +00:00
|
|
|
ti->x, ti->y + 1, 16, 1, 4, ti->z);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-09-18 20:56:44 +00:00
|
|
|
static void DrawTrackFence_SE(const TileInfo *ti)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-07-23 16:08:58 +00:00
|
|
|
SpriteID image = SPR_TRACK_FENCE_FLAT_X;
|
|
|
|
if (ti->tileh != SLOPE_FLAT) image = (ti->tileh & SLOPE_S) ? SPR_TRACK_FENCE_SLOPE_SW : SPR_TRACK_FENCE_SLOPE_NE;
|
2007-01-14 19:57:49 +00:00
|
|
|
AddSortableSpriteToDraw(image, _drawtile_track_palette,
|
2006-04-23 19:35:36 +00:00
|
|
|
ti->x, ti->y + TILE_SIZE - 1, 16, 1, 4, ti->z);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2007-07-23 16:08:58 +00:00
|
|
|
SpriteID image = SPR_TRACK_FENCE_FLAT_Y;
|
|
|
|
if (ti->tileh != SLOPE_FLAT) image = (ti->tileh & SLOPE_S) ? SPR_TRACK_FENCE_SLOPE_SE : SPR_TRACK_FENCE_SLOPE_NW;
|
2007-01-14 19:57:49 +00:00
|
|
|
AddSortableSpriteToDraw(image, _drawtile_track_palette,
|
2006-02-01 06:32:03 +00:00
|
|
|
ti->x + 1, ti->y, 1, 16, 4, ti->z);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-09-18 20:56:44 +00:00
|
|
|
static void DrawTrackFence_SW(const TileInfo *ti)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-07-23 16:08:58 +00:00
|
|
|
SpriteID image = SPR_TRACK_FENCE_FLAT_Y;
|
|
|
|
if (ti->tileh != SLOPE_FLAT) image = (ti->tileh & SLOPE_S) ? SPR_TRACK_FENCE_SLOPE_SE : SPR_TRACK_FENCE_SLOPE_NW;
|
2007-01-14 19:57:49 +00:00
|
|
|
AddSortableSpriteToDraw(image, _drawtile_track_palette,
|
2006-04-23 19:35:36 +00:00
|
|
|
ti->x + TILE_SIZE - 1, ti->y, 1, 16, 4, ti->z);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2007-07-23 16:08:58 +00:00
|
|
|
/**
|
|
|
|
* Draw fence at eastern side of track.
|
|
|
|
*/
|
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;
|
2006-04-23 19:35:36 +00:00
|
|
|
if (ti->tileh & SLOPE_W) z += TILE_HEIGHT;
|
2007-07-23 16:08:58 +00:00
|
|
|
AddSortableSpriteToDraw(SPR_TRACK_FENCE_FLAT_VERT, _drawtile_track_palette,
|
2006-04-23 19:35:36 +00:00
|
|
|
ti->x + TILE_SIZE / 2, ti->y + TILE_SIZE / 2, 1, 1, 4, z);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-07-23 16:08:58 +00:00
|
|
|
/**
|
|
|
|
* Draw fence at western side of track.
|
|
|
|
*/
|
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;
|
2006-04-23 19:35:36 +00:00
|
|
|
if (ti->tileh & SLOPE_E) z += TILE_HEIGHT;
|
2007-07-23 16:08:58 +00:00
|
|
|
AddSortableSpriteToDraw(SPR_TRACK_FENCE_FLAT_VERT, _drawtile_track_palette,
|
2006-04-23 19:35:36 +00:00
|
|
|
ti->x + TILE_SIZE / 2, ti->y + TILE_SIZE / 2, 1, 1, 4, z);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-07-23 16:08:58 +00:00
|
|
|
/**
|
|
|
|
* Draw fence at southern side of track.
|
|
|
|
*/
|
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;
|
2006-04-23 19:35:36 +00:00
|
|
|
if (ti->tileh & SLOPE_N) z += TILE_HEIGHT;
|
2007-07-23 16:08:58 +00:00
|
|
|
AddSortableSpriteToDraw(SPR_TRACK_FENCE_FLAT_HORZ, _drawtile_track_palette,
|
2006-04-23 19:35:36 +00:00
|
|
|
ti->x + TILE_SIZE / 2, ti->y + TILE_SIZE / 2, 1, 1, 4, z);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-07-23 16:08:58 +00:00
|
|
|
/**
|
|
|
|
* Draw fence at northern side of track.
|
|
|
|
*/
|
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;
|
2006-04-23 19:35:36 +00:00
|
|
|
if (ti->tileh & SLOPE_S) z += TILE_HEIGHT;
|
2007-07-23 16:08:58 +00:00
|
|
|
AddSortableSpriteToDraw(SPR_TRACK_FENCE_FLAT_HORZ, _drawtile_track_palette,
|
2006-04-23 19:35:36 +00:00
|
|
|
ti->x + TILE_SIZE / 2, ti->y + TILE_SIZE / 2, 1, 1, 4, z);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-06-18 09:37:08 +00:00
|
|
|
|
|
|
|
static void DrawTrackDetails(const TileInfo* ti)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-06-18 09:37:08 +00:00
|
|
|
switch (GetRailGroundType(ti->tile)) {
|
|
|
|
case RAIL_GROUND_FENCE_NW: DrawTrackFence_NW(ti); break;
|
|
|
|
case RAIL_GROUND_FENCE_SE: DrawTrackFence_SE(ti); break;
|
|
|
|
case RAIL_GROUND_FENCE_SENW: DrawTrackFence_NW_SE(ti); break;
|
|
|
|
case RAIL_GROUND_FENCE_NE: DrawTrackFence_NE(ti); break;
|
|
|
|
case RAIL_GROUND_FENCE_SW: DrawTrackFence_SW(ti); break;
|
|
|
|
case RAIL_GROUND_FENCE_NESW: DrawTrackFence_NE_SW(ti); break;
|
|
|
|
case RAIL_GROUND_FENCE_VERT1: DrawTrackFence_NS_1(ti); break;
|
|
|
|
case RAIL_GROUND_FENCE_VERT2: DrawTrackFence_NS_2(ti); break;
|
|
|
|
case RAIL_GROUND_FENCE_HORIZ1: DrawTrackFence_WE_1(ti); break;
|
|
|
|
case RAIL_GROUND_FENCE_HORIZ2: DrawTrackFence_WE_2(ti); break;
|
|
|
|
default: break;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-29 20:20:34 +00:00
|
|
|
/**
|
|
|
|
* Draw ground sprite and track bits
|
|
|
|
* @param ti TileInfo
|
|
|
|
* @param track TrackBits to draw
|
|
|
|
*/
|
2006-06-28 06:10:20 +00:00
|
|
|
static void DrawTrackBits(TileInfo* ti, TrackBits track)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-07-29 21:36:02 +00:00
|
|
|
const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(ti->tile));
|
2007-01-14 19:57:49 +00:00
|
|
|
SpriteID image;
|
|
|
|
SpriteID pal = PAL_NONE;
|
2005-09-29 20:20:34 +00:00
|
|
|
bool junction = false;
|
|
|
|
|
2007-04-04 01:35:16 +00:00
|
|
|
/* Select the sprite to use. */
|
2006-03-01 09:40:34 +00:00
|
|
|
(image = rti->base_sprites.track_y, track == TRACK_BIT_Y) ||
|
|
|
|
(image++, track == TRACK_BIT_X) ||
|
2005-09-29 20:20:34 +00:00
|
|
|
(image++, track == TRACK_BIT_UPPER) ||
|
|
|
|
(image++, track == TRACK_BIT_LOWER) ||
|
|
|
|
(image++, track == TRACK_BIT_RIGHT) ||
|
|
|
|
(image++, track == TRACK_BIT_LEFT) ||
|
2006-03-18 13:20:50 +00:00
|
|
|
(image++, track == TRACK_BIT_CROSS) ||
|
2005-09-29 20:20:34 +00:00
|
|
|
|
2006-03-18 13:20:50 +00:00
|
|
|
(image = rti->base_sprites.track_ns, track == TRACK_BIT_HORZ) ||
|
|
|
|
(image++, track == TRACK_BIT_VERT) ||
|
2005-09-29 20:20:34 +00:00
|
|
|
|
|
|
|
(junction = true, false) ||
|
2006-03-18 13:20:50 +00:00
|
|
|
(image = rti->base_sprites.ground, (track & TRACK_BIT_3WAY_NE) == 0) ||
|
|
|
|
(image++, (track & TRACK_BIT_3WAY_SW) == 0) ||
|
|
|
|
(image++, (track & TRACK_BIT_3WAY_NW) == 0) ||
|
|
|
|
(image++, (track & TRACK_BIT_3WAY_SE) == 0) ||
|
2005-09-29 20:20:34 +00:00
|
|
|
(image++, true);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-23 13:48:16 +00:00
|
|
|
if (ti->tileh != SLOPE_FLAT) {
|
2006-06-28 06:10:20 +00:00
|
|
|
uint foundation = GetRailFoundation(ti->tileh, track);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-06-27 21:25:53 +00:00
|
|
|
if (foundation != 0) DrawFoundation(ti, foundation);
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2007-04-04 01:35:16 +00:00
|
|
|
/* DrawFoundation() modifies it.
|
|
|
|
* Default sloped sprites.. */
|
2006-04-23 13:48:16 +00:00
|
|
|
if (ti->tileh != SLOPE_FLAT)
|
2005-09-29 20:20:34 +00:00
|
|
|
image = _track_sloped_sprites[ti->tileh - 1] + rti->base_sprites.track_y;
|
|
|
|
}
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2006-08-31 06:46:52 +00:00
|
|
|
switch (GetRailGroundType(ti->tile)) {
|
2007-01-14 19:57:49 +00:00
|
|
|
case RAIL_GROUND_BARREN: pal = PALETTE_TO_BARE_LAND; break;
|
2006-08-31 06:46:52 +00:00
|
|
|
case RAIL_GROUND_ICE_DESERT: image += rti->snow_offset; break;
|
|
|
|
default: break;
|
2005-09-29 20:20:34 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-01-14 19:57:49 +00:00
|
|
|
DrawGroundSprite(image, pal);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-04-04 01:35:16 +00:00
|
|
|
/* Draw track pieces individually for junction tiles */
|
2005-09-29 20:20:34 +00:00
|
|
|
if (junction) {
|
2007-01-14 19:57:49 +00:00
|
|
|
if (track & TRACK_BIT_X) DrawGroundSprite(rti->base_sprites.single_y, PAL_NONE);
|
|
|
|
if (track & TRACK_BIT_Y) DrawGroundSprite(rti->base_sprites.single_x, PAL_NONE);
|
|
|
|
if (track & TRACK_BIT_UPPER) DrawGroundSprite(rti->base_sprites.single_n, PAL_NONE);
|
|
|
|
if (track & TRACK_BIT_LOWER) DrawGroundSprite(rti->base_sprites.single_s, PAL_NONE);
|
|
|
|
if (track & TRACK_BIT_LEFT) DrawGroundSprite(rti->base_sprites.single_w, PAL_NONE);
|
|
|
|
if (track & TRACK_BIT_RIGHT) DrawGroundSprite(rti->base_sprites.single_e, PAL_NONE);
|
2005-09-29 20:20:34 +00:00
|
|
|
}
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-12 08:06:08 +00:00
|
|
|
static void DrawSignals(TileIndex tile, TrackBits rails)
|
|
|
|
{
|
2007-05-31 21:21:04 +00:00
|
|
|
#define MAYBE_DRAW_SIGNAL(x,y,z,t) if (IsSignalPresent(tile, x)) DrawSingleSignal(tile, t, GetSingleSignalState(tile, x), y - 0x4FB, z)
|
2006-04-12 08:06:08 +00:00
|
|
|
|
|
|
|
if (!(rails & TRACK_BIT_Y)) {
|
|
|
|
if (!(rails & TRACK_BIT_X)) {
|
|
|
|
if (rails & TRACK_BIT_LEFT) {
|
2007-05-31 21:21:04 +00:00
|
|
|
MAYBE_DRAW_SIGNAL(2, 0x509, 0, TRACK_LEFT);
|
|
|
|
MAYBE_DRAW_SIGNAL(3, 0x507, 1, TRACK_LEFT);
|
2006-04-12 08:06:08 +00:00
|
|
|
}
|
|
|
|
if (rails & TRACK_BIT_RIGHT) {
|
2007-05-31 21:21:04 +00:00
|
|
|
MAYBE_DRAW_SIGNAL(0, 0x509, 2, TRACK_RIGHT);
|
|
|
|
MAYBE_DRAW_SIGNAL(1, 0x507, 3, TRACK_RIGHT);
|
2006-04-12 08:06:08 +00:00
|
|
|
}
|
|
|
|
if (rails & TRACK_BIT_UPPER) {
|
2007-05-31 21:21:04 +00:00
|
|
|
MAYBE_DRAW_SIGNAL(3, 0x505, 4, TRACK_UPPER);
|
|
|
|
MAYBE_DRAW_SIGNAL(2, 0x503, 5, TRACK_UPPER);
|
2006-04-12 08:06:08 +00:00
|
|
|
}
|
|
|
|
if (rails & TRACK_BIT_LOWER) {
|
2007-05-31 21:21:04 +00:00
|
|
|
MAYBE_DRAW_SIGNAL(1, 0x505, 6, TRACK_LOWER);
|
|
|
|
MAYBE_DRAW_SIGNAL(0, 0x503, 7, TRACK_LOWER);
|
2006-04-12 08:06:08 +00:00
|
|
|
}
|
|
|
|
} else {
|
2007-05-31 21:21:04 +00:00
|
|
|
MAYBE_DRAW_SIGNAL(3, 0x4FB, 8, TRACK_X);
|
|
|
|
MAYBE_DRAW_SIGNAL(2, 0x4FD, 9, TRACK_X);
|
2006-04-12 08:06:08 +00:00
|
|
|
}
|
|
|
|
} else {
|
2007-05-31 21:21:04 +00:00
|
|
|
MAYBE_DRAW_SIGNAL(3, 0x4FF, 10, TRACK_Y);
|
|
|
|
MAYBE_DRAW_SIGNAL(2, 0x501, 11, TRACK_Y);
|
2006-04-12 08:06:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-29 20:20:34 +00:00
|
|
|
static void DrawTile_Track(TileInfo *ti)
|
|
|
|
{
|
|
|
|
const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(ti->tile));
|
2007-01-14 19:57:49 +00:00
|
|
|
SpriteID image;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-01-14 19:57:49 +00:00
|
|
|
_drawtile_track_palette = PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile));
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-07-27 05:30:53 +00:00
|
|
|
if (IsPlainRailTile(ti->tile)) {
|
2006-03-19 12:06:12 +00:00
|
|
|
TrackBits rails = GetTrackBits(ti->tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-06-28 06:10:20 +00:00
|
|
|
DrawTrackBits(ti, rails);
|
2005-07-04 14:58:55 +00:00
|
|
|
|
2007-05-07 11:24:23 +00:00
|
|
|
if (HASBIT(_display_opt, DO_FULL_DETAIL)) DrawTrackDetails(ti);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-06-24 20:06:10 +00:00
|
|
|
if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC) DrawCatenary(ti);
|
|
|
|
|
2006-07-27 05:30:53 +00:00
|
|
|
if (HasSignals(ti->tile)) DrawSignals(ti->tile, rails);
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2007-04-04 01:35:16 +00:00
|
|
|
/* draw depot/waypoint */
|
2006-08-05 16:54:55 +00:00
|
|
|
const DrawTileSprites* dts;
|
|
|
|
const DrawTileSeqStruct* dtss;
|
|
|
|
uint32 relocation;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-23 13:48:16 +00:00
|
|
|
if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, ti->tileh);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-02-27 23:36:28 +00:00
|
|
|
if (IsRailDepot(ti->tile)) {
|
2006-08-05 16:54:55 +00:00
|
|
|
dts = &_depot_gfx_table[GetRailDepotDirection(ti->tile)];
|
|
|
|
|
|
|
|
relocation = rti->total_offset;
|
|
|
|
|
|
|
|
image = dts->ground_sprite;
|
|
|
|
if (image != SPR_FLAT_GRASS_TILE) image += rti->total_offset;
|
|
|
|
|
2007-04-04 01:35:16 +00:00
|
|
|
/* adjust ground tile for desert
|
|
|
|
* don't adjust for snow, because snow in depots looks weird */
|
2007-03-22 03:42:43 +00:00
|
|
|
if (IsSnowRailGround(ti->tile) && _opt.landscape == LT_TROPIC) {
|
2006-08-05 16:54:55 +00:00
|
|
|
if (image != SPR_FLAT_GRASS_TILE) {
|
|
|
|
image += rti->snow_offset; // tile with tracks
|
|
|
|
} else {
|
|
|
|
image = SPR_FLAT_SNOWY_TILE; // flat ground
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2007-04-04 01:35:16 +00:00
|
|
|
/* look for customization */
|
2005-11-16 22:20:15 +00:00
|
|
|
byte stat_id = GetWaypointByTile(ti->tile)->stat_id;
|
2006-04-27 18:28:56 +00:00
|
|
|
const StationSpec *statspec = GetCustomStationSpec(STAT_CLASS_WAYP, stat_id);
|
2004-11-14 09:07:15 +00:00
|
|
|
|
2006-04-27 18:28:56 +00:00
|
|
|
if (statspec != NULL) {
|
2007-04-04 01:35:16 +00:00
|
|
|
/* emulate station tile - open with building */
|
2006-08-05 16:54:55 +00:00
|
|
|
const Station* st = ComposeWaypointStation(ti->tile);
|
|
|
|
uint gfx = 2;
|
2006-05-06 09:40:12 +00:00
|
|
|
|
|
|
|
if (HASBIT(statspec->callbackmask, CBM_CUSTOM_LAYOUT)) {
|
|
|
|
uint16 callback = GetStationCallback(CBID_STATION_SPRITE_LAYOUT, 0, 0, statspec, st, ti->tile);
|
2006-08-05 16:54:55 +00:00
|
|
|
if (callback != CALLBACK_FAILED) gfx = callback;
|
2006-05-06 09:40:12 +00:00
|
|
|
}
|
|
|
|
|
2006-05-06 20:33:22 +00:00
|
|
|
if (statspec->renderdata == NULL) {
|
2007-07-16 23:55:22 +00:00
|
|
|
dts = GetStationTileLayout(STATION_RAIL, gfx);
|
2006-05-06 20:33:22 +00:00
|
|
|
} else {
|
2006-08-05 16:54:55 +00:00
|
|
|
dts = &statspec->renderdata[(gfx < statspec->tiles ? gfx : 0) + GetWaypointAxis(ti->tile)];
|
2006-05-06 20:33:22 +00:00
|
|
|
}
|
2004-11-17 15:14:18 +00:00
|
|
|
|
2006-08-05 16:54:55 +00:00
|
|
|
if (dts != NULL && dts->seq != NULL) {
|
|
|
|
relocation = GetCustomStationRelocation(statspec, st, ti->tile);
|
|
|
|
|
|
|
|
image = dts->ground_sprite;
|
2007-01-19 21:40:10 +00:00
|
|
|
if (HASBIT(image, SPRITE_MODIFIER_USE_OFFSET)) {
|
2006-05-07 10:58:53 +00:00
|
|
|
image += GetCustomStationGroundRelocation(statspec, st, ti->tile);
|
|
|
|
image += rti->custom_ground_offset;
|
|
|
|
} else {
|
|
|
|
image += rti->total_offset;
|
|
|
|
}
|
2006-08-05 16:54:55 +00:00
|
|
|
} else {
|
|
|
|
goto default_waypoint;
|
2004-11-14 09:07:15 +00:00
|
|
|
}
|
2005-10-23 13:04:44 +00:00
|
|
|
} else {
|
2006-08-05 16:54:55 +00:00
|
|
|
default_waypoint:
|
2007-04-04 01:35:16 +00:00
|
|
|
/* There is no custom layout, fall back to the default graphics */
|
2006-08-05 16:54:55 +00:00
|
|
|
dts = &_waypoint_gfx_table[GetWaypointAxis(ti->tile)];
|
|
|
|
relocation = 0;
|
|
|
|
image = dts->ground_sprite + rti->total_offset;
|
|
|
|
if (IsSnowRailGround(ti->tile)) image += rti->snow_offset;
|
2005-10-23 13:04:44 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-01-14 19:57:49 +00:00
|
|
|
DrawGroundSprite(image, PAL_NONE);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-03-29 16:30:26 +00:00
|
|
|
if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC) DrawCatenary(ti);
|
|
|
|
|
2006-08-05 16:54:55 +00:00
|
|
|
foreach_draw_tile_seq(dtss, dts->seq) {
|
2007-01-19 21:40:10 +00:00
|
|
|
SpriteID image = dtss->image;
|
2007-01-14 19:57:49 +00:00
|
|
|
SpriteID pal;
|
2006-08-05 16:54:55 +00:00
|
|
|
|
2007-01-19 21:40:10 +00:00
|
|
|
/* Unlike stations, our default waypoint has no variation for
|
|
|
|
* different railtype, so don't use the railtype offset if
|
|
|
|
* no relocation is set */
|
|
|
|
if (HASBIT(image, SPRITE_MODIFIER_USE_OFFSET)) {
|
|
|
|
image += rti->total_offset;
|
|
|
|
} else {
|
|
|
|
image += relocation;
|
|
|
|
}
|
|
|
|
|
2007-04-05 07:49:04 +00:00
|
|
|
if (HASBIT(_transparent_opt, TO_BUILDINGS)) {
|
2007-01-14 19:57:49 +00:00
|
|
|
SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
|
|
|
|
pal = PALETTE_TO_TRANSPARENT;
|
|
|
|
} else if (HASBIT(image, PALETTE_MODIFIER_COLOR)) {
|
|
|
|
pal = _drawtile_track_palette;
|
|
|
|
} else {
|
|
|
|
pal = dtss->pal;
|
2006-08-05 16:54:55 +00:00
|
|
|
}
|
2007-01-14 19:57:49 +00:00
|
|
|
|
2007-01-19 21:40:10 +00:00
|
|
|
if ((byte)dtss->delta_z != 0x80) {
|
|
|
|
AddSortableSpriteToDraw(
|
|
|
|
image, pal,
|
|
|
|
ti->x + dtss->delta_x, ti->y + dtss->delta_y,
|
|
|
|
dtss->size_x, dtss->size_y,
|
|
|
|
dtss->size_z, ti->z + dtss->delta_z
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
AddChildSpriteScreen(image, pal, dtss->delta_x, dtss->delta_y);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
2006-12-27 12:38:02 +00:00
|
|
|
DrawBridgeMiddle(ti);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-14 19:57:49 +00:00
|
|
|
static void DrawTileSequence(int x, int y, SpriteID ground, const DrawTileSeqStruct* dtss, uint32 offset)
|
2006-08-05 16:54:55 +00:00
|
|
|
{
|
2007-01-14 19:57:49 +00:00
|
|
|
SpriteID palette = PLAYER_SPRITE_COLOR(_local_player);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-01-14 19:57:49 +00:00
|
|
|
DrawSprite(ground, PAL_NONE, x, y);
|
2006-08-05 16:54:55 +00:00
|
|
|
for (; dtss->image != 0; dtss++) {
|
|
|
|
Point pt = RemapCoords(dtss->delta_x, dtss->delta_y, dtss->delta_z);
|
2007-01-14 19:57:49 +00:00
|
|
|
SpriteID image = dtss->image + offset;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-01-14 19:57:49 +00:00
|
|
|
DrawSprite(image, HASBIT(image, PALETTE_MODIFIER_COLOR) ? palette : PAL_NONE, x + pt.x, y + pt.y);
|
2006-08-05 16:54:55 +00:00
|
|
|
}
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-08-05 16:54:55 +00:00
|
|
|
void DrawTrainDepotSprite(int x, int y, int dir, RailType railtype)
|
|
|
|
{
|
|
|
|
const DrawTileSprites* dts = &_depot_gfx_table[dir];
|
2007-01-14 19:57:49 +00:00
|
|
|
SpriteID image = dts->ground_sprite;
|
2006-08-05 16:54:55 +00:00
|
|
|
uint32 offset = GetRailTypeInfo(railtype)->total_offset;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-08-05 16:54:55 +00:00
|
|
|
if (image != SPR_FLAT_GRASS_TILE) image += offset;
|
|
|
|
DrawTileSequence(x + 33, y + 17, image, dts->seq, offset);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-10-16 09:13:04 +00:00
|
|
|
void DrawDefaultWaypointSprite(int x, int y, RailType railtype)
|
2005-08-01 16:31:19 +00:00
|
|
|
{
|
2006-08-05 16:54:55 +00:00
|
|
|
uint32 offset = GetRailTypeInfo(railtype)->total_offset;
|
|
|
|
const DrawTileSprites* dts = &_waypoint_gfx_table[AXIS_X];
|
2005-08-01 16:31:19 +00:00
|
|
|
|
2006-08-05 16:54:55 +00:00
|
|
|
DrawTileSequence(x, y, dts->ground_sprite + offset, dts->seq, 0);
|
2005-08-01 16:31:19 +00:00
|
|
|
}
|
|
|
|
|
2007-03-07 12:11:48 +00:00
|
|
|
struct SetSignalsData {
|
2004-08-09 17:04:08 +00:00
|
|
|
int cur;
|
|
|
|
int cur_stack;
|
|
|
|
bool stop;
|
|
|
|
bool has_presignal;
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2007-04-04 01:35:16 +00:00
|
|
|
/* presignal info */
|
2004-08-09 17:04:08 +00:00
|
|
|
int presignal_exits;
|
|
|
|
int presignal_exits_free;
|
|
|
|
|
2007-04-04 01:35:16 +00:00
|
|
|
/* these are used to keep track of the signals that change. */
|
2007-01-10 18:56:51 +00:00
|
|
|
TrackdirByte bit[NUM_SSD_ENTRY];
|
2004-08-09 17:04:08 +00:00
|
|
|
TileIndex tile[NUM_SSD_ENTRY];
|
|
|
|
|
2007-04-04 01:35:16 +00:00
|
|
|
/* these are used to keep track of the stack that modifies presignals recursively */
|
2004-08-09 17:04:08 +00:00
|
|
|
TileIndex next_tile[NUM_SSD_STACK];
|
2007-01-10 18:56:51 +00:00
|
|
|
DiagDirectionByte next_dir[NUM_SSD_STACK];
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-01-10 18:56:51 +00:00
|
|
|
static bool SetSignalsEnumProc(TileIndex tile, void* data, Trackdir trackdir, uint length, byte* state)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-01-10 18:56:51 +00:00
|
|
|
SetSignalsData* ssd = (SetSignalsData*)data;
|
2007-05-31 21:21:04 +00:00
|
|
|
Track track = TrackdirToTrack(trackdir);
|
2006-08-31 10:36:59 +00:00
|
|
|
|
2006-02-13 21:15:00 +00:00
|
|
|
if (!IsTileType(tile, MP_RAILWAY)) return false;
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2007-04-04 01:35:16 +00:00
|
|
|
/* the tile has signals? */
|
2007-05-31 21:21:04 +00:00
|
|
|
if (HasSignalOnTrack(tile, track)) {
|
2007-01-10 18:56:51 +00:00
|
|
|
if (HasSignalOnTrackdir(tile, ReverseTrackdir(trackdir))) {
|
2007-04-04 01:35:16 +00:00
|
|
|
/* yes, add the signal to the list of signals */
|
2006-02-13 21:15:00 +00:00
|
|
|
if (ssd->cur != NUM_SSD_ENTRY) {
|
|
|
|
ssd->tile[ssd->cur] = tile; // remember the tile index
|
2007-01-10 18:56:51 +00:00
|
|
|
ssd->bit[ssd->cur] = trackdir; // and the controlling bit number
|
2006-02-13 21:15:00 +00:00
|
|
|
ssd->cur++;
|
(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
|
|
|
|
2007-04-04 01:35:16 +00:00
|
|
|
/* remember if this block has a presignal. */
|
2007-05-31 21:21:04 +00:00
|
|
|
ssd->has_presignal |= IsPresignalEntry(tile, track);
|
2006-02-13 21:15:00 +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
|
|
|
|
2007-05-31 21:21:04 +00:00
|
|
|
if (HasSignalOnTrackdir(tile, trackdir) && IsPresignalExit(tile, track)) {
|
2007-04-04 01:35:16 +00:00
|
|
|
/* this is an exit signal that points out from the segment */
|
2006-02-13 21:15:00 +00:00
|
|
|
ssd->presignal_exits++;
|
2007-01-10 18:56:51 +00:00
|
|
|
if (GetSignalStateByTrackdir(tile, trackdir) != SIGNAL_STATE_RED)
|
2006-02-13 21:15:00 +00:00
|
|
|
ssd->presignal_exits_free++;
|
2005-10-23 13:04:44 +00:00
|
|
|
}
|
2006-02-13 21:15:00 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
} else if (IsTileDepotType(tile, TRANSPORT_RAIL)) {
|
|
|
|
return true; // don't look further if the tile is a depot
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2006-02-13 21:15:00 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2005-03-25 13:37:37 +00:00
|
|
|
/* Struct to parse data from VehicleFromPos to SignalVehicleCheckProc */
|
2007-03-07 12:11:48 +00:00
|
|
|
struct SignalVehicleCheckStruct {
|
2005-03-25 13:37:37 +00:00
|
|
|
TileIndex tile;
|
|
|
|
uint track;
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2005-03-25 13:37:37 +00:00
|
|
|
|
|
|
|
static void *SignalVehicleCheckProc(Vehicle *v, void *data)
|
|
|
|
{
|
2007-01-10 18:56:51 +00:00
|
|
|
const SignalVehicleCheckStruct* dest = (SignalVehicleCheckStruct*)data;
|
2005-03-25 13:37:37 +00:00
|
|
|
|
2007-03-08 16:27:54 +00:00
|
|
|
if (v->type != VEH_TRAIN) return NULL;
|
2005-03-31 12:39:18 +00:00
|
|
|
|
2005-03-25 13:37:37 +00:00
|
|
|
/* Wrong tile, or no train? Not a match */
|
2006-12-27 12:38:02 +00:00
|
|
|
if (v->tile != dest->tile) return NULL;
|
2005-03-25 13:37:37 +00:00
|
|
|
|
|
|
|
/* Are we on the same piece of track? */
|
2006-06-27 21:25:53 +00:00
|
|
|
if (dest->track & v->u.rail.track * 0x101) return v;
|
2005-03-25 13:37:37 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Special check for SetSignalsAfterProc, to see if there is a vehicle on this tile */
|
2005-12-14 06:20:23 +00:00
|
|
|
static bool SignalVehicleCheck(TileIndex tile, uint track)
|
2005-03-25 13:37:37 +00:00
|
|
|
{
|
|
|
|
SignalVehicleCheckStruct dest;
|
|
|
|
|
|
|
|
dest.tile = tile;
|
|
|
|
dest.track = track;
|
|
|
|
|
2006-12-27 12:38:02 +00:00
|
|
|
/* Locate vehicles in tunnels or on bridges */
|
|
|
|
if (IsTunnelTile(tile) || IsBridgeTile(tile)) {
|
|
|
|
TileIndex end;
|
|
|
|
DiagDirection direction;
|
|
|
|
|
|
|
|
if (IsTunnelTile(tile)) {
|
|
|
|
end = GetOtherTunnelEnd(tile);
|
|
|
|
direction = GetTunnelDirection(tile);
|
|
|
|
} else {
|
|
|
|
end = GetOtherBridgeEnd(tile);
|
|
|
|
direction = GetBridgeRampDirection(tile);
|
|
|
|
}
|
2006-03-06 20:55:24 +00:00
|
|
|
|
2005-05-15 13:48:23 +00:00
|
|
|
dest.track = 1 << (direction & 1); // get the trackbit the vehicle would have if it has not entered the tunnel yet (ie is still visible)
|
|
|
|
|
2007-04-04 01:35:16 +00:00
|
|
|
/* 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
|
|
|
|
2007-04-04 01:35:16 +00:00
|
|
|
/* check for a vehicle with that trackdir on the end tile of the tunnel */
|
2006-03-06 20:55:24 +00:00
|
|
|
if (VehicleFromPos(end, &dest, SignalVehicleCheckProc) != NULL) return true;
|
2005-05-15 13:48:23 +00:00
|
|
|
|
2007-04-04 01:35:16 +00:00
|
|
|
/* now check all tiles from start to end for a warping vehicle
|
|
|
|
* NOTE: the hashes for tiles may overlap, so this could maybe be optimised a bit by not checking every tile? */
|
2006-12-27 12:38:02 +00:00
|
|
|
dest.track = 0x40; //Vehicle inside a tunnel or on a bridge
|
2006-09-05 23:21:41 +00:00
|
|
|
for (; tile != end; tile += TileOffsByDiagDir(direction)) {
|
2005-05-15 13:48:23 +00:00
|
|
|
if (VehicleFromPos(tile, &dest, SignalVehicleCheckProc) != NULL)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-04-04 01:35:16 +00:00
|
|
|
/* no vehicle found */
|
2005-05-15 13:48:23 +00:00
|
|
|
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)
|
|
|
|
{
|
2007-01-10 18:56:51 +00:00
|
|
|
SetSignalsData *ssd = (SetSignalsData*)tpf->userdata;
|
2005-10-22 06:39:32 +00:00
|
|
|
const 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 */
|
2005-11-14 19:48:04 +00:00
|
|
|
if (tpf->hash_head[i] == 0) continue;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
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 */
|
2006-02-01 06:32:03 +00:00
|
|
|
} while ((offs = link->next) != 0xFFFF);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ChangeSignalStates(SetSignalsData *ssd)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2007-04-04 01:35:16 +00:00
|
|
|
/* 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 */
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-04-04 01:35:16 +00:00
|
|
|
/* then mark the signals in the segment accordingly */
|
2005-10-23 13:04:44 +00:00
|
|
|
for (i = 0; i != ssd->cur; i++) {
|
2005-06-24 12:38:35 +00:00
|
|
|
TileIndex tile = ssd->tile[i];
|
2006-01-06 00:08:00 +00:00
|
|
|
byte bit = SignalAgainstTrackdir(ssd->bit[i]);
|
2007-05-30 13:33:19 +00:00
|
|
|
uint signals = GetSignalStates(tile);
|
2007-05-31 21:21:04 +00:00
|
|
|
Track track = TrackdirToTrack(ssd->bit[i]);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-04-04 01:35:16 +00:00
|
|
|
/* presignals don't turn green if there is at least one presignal exit and none are free */
|
2007-05-31 21:21:04 +00:00
|
|
|
if (IsPresignalEntry(tile, track)) {
|
2004-08-09 17:04:08 +00:00
|
|
|
int ex = ssd->presignal_exits, exfree = ssd->presignal_exits_free;
|
|
|
|
|
2007-04-04 01:35:16 +00:00
|
|
|
/* subtract for dual combo signals so they don't count themselves */
|
2007-05-31 21:21:04 +00:00
|
|
|
if (IsPresignalExit(tile, track) && HasSignalOnTrackdir(tile, ssd->bit[i])) {
|
2004-08-09 17:04:08 +00:00
|
|
|
ex--;
|
2006-04-12 08:28:03 +00:00
|
|
|
if (GetSignalStateByTrackdir(tile, ssd->bit[i]) != SIGNAL_STATE_RED) exfree--;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-04-04 01:35:16 +00:00
|
|
|
/* if we have exits and none are free, make red. */
|
2004-08-09 17:04:08 +00:00
|
|
|
if (ex && !exfree) goto make_red;
|
|
|
|
}
|
|
|
|
|
2007-04-04 01:35:16 +00:00
|
|
|
/* check if the signal is unaffected. */
|
2004-08-09 17:04:08 +00:00
|
|
|
if (ssd->stop) {
|
|
|
|
make_red:
|
2007-04-04 01:35:16 +00:00
|
|
|
/* turn red */
|
2007-05-30 13:33:19 +00:00
|
|
|
if ((bit & signals) == 0) continue;
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2007-04-04 01:35:16 +00:00
|
|
|
/* turn green */
|
2007-05-30 13:33:19 +00:00
|
|
|
if ((bit & signals) != 0) continue;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-05-15 10:23:42 +00:00
|
|
|
/* Update signals on the other side of this exit-combo signal; it changed. */
|
2007-05-31 21:21:04 +00:00
|
|
|
if (IsPresignalExit(tile, track)) {
|
2004-08-09 17:04:08 +00:00
|
|
|
if (ssd->cur_stack != NUM_SSD_STACK) {
|
|
|
|
ssd->next_tile[ssd->cur_stack] = tile;
|
2007-07-04 09:42:47 +00:00
|
|
|
ssd->next_dir[ssd->cur_stack] = TrackdirToExitdir(ssd->bit[i]);
|
2004-08-09 17:04:08 +00:00
|
|
|
ssd->cur_stack++;
|
|
|
|
} else {
|
2006-12-26 17:36:18 +00:00
|
|
|
DEBUG(misc, 0, "NUM_SSD_STACK too small"); /// @todo WTF is this???
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2007-04-04 01:35:16 +00:00
|
|
|
/* it changed, so toggle it */
|
2007-05-30 13:33:19 +00:00
|
|
|
SetSignalStates(tile, signals ^ bit);
|
2004-08-09 17:04:08 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-09 12:32:25 +00:00
|
|
|
bool UpdateSignalsOnSegment(TileIndex tile, DiagDirection direction)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
SetSignalsData ssd;
|
|
|
|
int result = -1;
|
|
|
|
|
|
|
|
ssd.cur_stack = 0;
|
|
|
|
|
2006-02-01 06:32:03 +00:00
|
|
|
for (;;) {
|
2007-04-04 01:35:16 +00:00
|
|
|
/* go through one segment and update all signals pointing into that segment. */
|
(svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
- The only change is that the nsignalsw.grf file is kept and that existing nightlies with PBS signals get those signals converted to combo-signals.
2006-01-29 18:57:26 +00:00
|
|
|
ssd.cur = ssd.presignal_exits = ssd.presignal_exits_free = 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
ssd.has_presignal = false;
|
|
|
|
|
2007-05-24 22:41:50 +00:00
|
|
|
FollowTrack(tile, 0xC000 | TRANSPORT_RAIL, 0, direction, SetSignalsEnumProc, SetSignalsAfterProc, &ssd);
|
2004-08-09 17:04:08 +00:00
|
|
|
ChangeSignalStates(&ssd);
|
|
|
|
|
2007-04-04 01:35:16 +00:00
|
|
|
/* remember the result only for the first iteration. */
|
2006-05-27 16:12:16 +00:00
|
|
|
if (result < 0) {
|
2007-04-04 01:35:16 +00:00
|
|
|
/* stay in depot while segment is occupied or while all presignal exits are blocked */
|
2006-05-27 16:12:16 +00:00
|
|
|
result = ssd.stop || (ssd.presignal_exits > 0 && ssd.presignal_exits_free == 0);
|
|
|
|
}
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2007-04-04 01:35:16 +00:00
|
|
|
/* if any exit signals were changed, we need to keep going to modify the stuff behind those. */
|
2005-11-14 19:48:04 +00:00
|
|
|
if (ssd.cur_stack == 0) break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-04-04 01:35:16 +00:00
|
|
|
/* one or more exit signals were changed, so we need to update another segment too. */
|
2004-08-09 17:04:08 +00:00
|
|
|
tile = ssd.next_tile[--ssd.cur_stack];
|
|
|
|
direction = ssd.next_dir[ssd.cur_stack];
|
|
|
|
}
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2006-02-13 21:15:00 +00:00
|
|
|
return result != 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
void SetSignalsOnBothDir(TileIndex tile, byte track)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-03-09 12:32:25 +00:00
|
|
|
static const DiagDirection _search_dir_1[] = {
|
|
|
|
DIAGDIR_NE, DIAGDIR_SE, DIAGDIR_NE, DIAGDIR_SE, DIAGDIR_SW, DIAGDIR_SE
|
|
|
|
};
|
|
|
|
static const DiagDirection _search_dir_2[] = {
|
|
|
|
DIAGDIR_SW, DIAGDIR_NW, DIAGDIR_NW, DIAGDIR_SW, DIAGDIR_NW, DIAGDIR_NE
|
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
UpdateSignalsOnSegment(tile, _search_dir_1[track]);
|
|
|
|
UpdateSignalsOnSegment(tile, _search_dir_2[track]);
|
|
|
|
}
|
|
|
|
|
2006-08-06 16:32:49 +00:00
|
|
|
static uint GetSlopeZ_Track(TileIndex tile, uint x, uint y)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-08-06 16:32:49 +00:00
|
|
|
uint z;
|
|
|
|
Slope tileh = GetTileSlope(tile, &z);
|
2004-08-10 18:35:43 +00:00
|
|
|
|
2006-04-23 13:48:16 +00:00
|
|
|
if (tileh == SLOPE_FLAT) return z;
|
2006-08-06 16:32:49 +00:00
|
|
|
if (IsPlainRailTile(tile)) {
|
|
|
|
uint f = GetRailFoundation(tileh, GetTrackBits(tile));
|
2006-02-01 06:32:03 +00:00
|
|
|
|
2006-03-21 22:06:32 +00:00
|
|
|
if (f != 0) {
|
2006-08-10 14:44:32 +00:00
|
|
|
if (IsSteepSlope(tileh)) {
|
|
|
|
z += TILE_HEIGHT;
|
|
|
|
} else if (f < 15) {
|
|
|
|
return z + TILE_HEIGHT; // leveled foundation
|
|
|
|
}
|
2006-03-21 22:06:32 +00:00
|
|
|
tileh = _inclined_tileh[f - 15]; // inclined foundation
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2006-08-06 16:32:49 +00:00
|
|
|
return z + GetPartialZ(x & 0xF, y & 0xF, tileh);
|
2006-07-27 05:30:53 +00:00
|
|
|
} else {
|
|
|
|
return z + TILE_HEIGHT;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-23 13:48:16 +00:00
|
|
|
static Slope GetSlopeTileh_Track(TileIndex tile, Slope tileh)
|
2004-08-13 18:27:33 +00:00
|
|
|
{
|
2006-04-23 13:48:16 +00:00
|
|
|
if (tileh == SLOPE_FLAT) return SLOPE_FLAT;
|
2006-07-27 05:30:53 +00:00
|
|
|
if (IsPlainRailTile(tile)) {
|
2006-04-02 12:49:18 +00:00
|
|
|
uint f = GetRailFoundation(tileh, GetTrackBits(tile));
|
2006-03-21 22:06:32 +00:00
|
|
|
|
2006-04-02 12:49:18 +00:00
|
|
|
if (f == 0) return tileh;
|
2006-04-23 13:48:16 +00:00
|
|
|
if (f < 15) return SLOPE_FLAT; // leveled foundation
|
2006-03-21 22:06:32 +00:00
|
|
|
return _inclined_tileh[f - 15]; // inclined foundation
|
2006-07-27 05:30:53 +00:00
|
|
|
} else {
|
|
|
|
return SLOPE_FLAT;
|
2004-08-13 18:27:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2006-04-12 11:58:07 +00:00
|
|
|
RailGroundType old_ground = GetRailGroundType(tile);
|
2006-08-31 12:19:32 +00:00
|
|
|
RailGroundType new_ground;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-11-13 14:54:09 +00:00
|
|
|
switch (_opt.landscape) {
|
2007-03-22 03:42:43 +00:00
|
|
|
case LT_ARCTIC:
|
2007-03-20 13:47:00 +00:00
|
|
|
if (GetTileZ(tile) > GetSnowLine()) {
|
2006-04-15 22:16:47 +00:00
|
|
|
new_ground = RAIL_GROUND_ICE_DESERT;
|
2006-08-31 11:42:16 +00:00
|
|
|
goto set_ground;
|
2006-04-15 22:16:47 +00:00
|
|
|
}
|
2005-11-13 14:54:09 +00:00
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-22 03:42:43 +00:00
|
|
|
case LT_TROPIC:
|
2006-04-15 22:16:47 +00:00
|
|
|
if (GetTropicZone(tile) == TROPICZONE_DESERT) {
|
|
|
|
new_ground = RAIL_GROUND_ICE_DESERT;
|
2006-08-31 11:42:16 +00:00
|
|
|
goto set_ground;
|
2006-04-15 22:16:47 +00:00
|
|
|
}
|
2005-11-13 14:54:09 +00:00
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-07-27 05:30:53 +00:00
|
|
|
if (!IsPlainRailTile(tile)) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-12 11:58:07 +00:00
|
|
|
new_ground = RAIL_GROUND_GRASS;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-04-04 01:35:16 +00:00
|
|
|
if (old_ground != RAIL_GROUND_BARREN) { // wait until bottom is green
|
2004-08-09 17:04:08 +00:00
|
|
|
/* determine direction of fence */
|
2006-03-19 12:06:12 +00:00
|
|
|
TrackBits rail = GetTrackBits(tile);
|
2006-01-07 16:30:49 +00:00
|
|
|
|
|
|
|
switch (rail) {
|
|
|
|
case TRACK_BIT_UPPER: new_ground = RAIL_GROUND_FENCE_HORIZ1; break;
|
|
|
|
case TRACK_BIT_LOWER: new_ground = RAIL_GROUND_FENCE_HORIZ2; break;
|
|
|
|
case TRACK_BIT_LEFT: new_ground = RAIL_GROUND_FENCE_VERT1; break;
|
|
|
|
case TRACK_BIT_RIGHT: new_ground = RAIL_GROUND_FENCE_VERT2; break;
|
|
|
|
|
|
|
|
default: {
|
|
|
|
PlayerID owner = GetTileOwner(tile);
|
|
|
|
|
|
|
|
if (rail == (TRACK_BIT_LOWER | TRACK_BIT_RIGHT) || (
|
2006-03-18 13:20:50 +00:00
|
|
|
(rail & TRACK_BIT_3WAY_NW) == 0 &&
|
2006-03-01 09:40:34 +00:00
|
|
|
(rail & TRACK_BIT_X)
|
2006-01-07 16:30:49 +00:00
|
|
|
)) {
|
|
|
|
TileIndex n = tile + TileDiffXY(0, -1);
|
2006-04-12 12:12:51 +00:00
|
|
|
TrackBits nrail = GetTrackBits(n);
|
2006-01-07 16:30:49 +00:00
|
|
|
|
|
|
|
if (!IsTileType(n, MP_RAILWAY) ||
|
|
|
|
!IsTileOwner(n, owner) ||
|
2006-04-12 12:12:51 +00:00
|
|
|
nrail == TRACK_BIT_UPPER ||
|
|
|
|
nrail == TRACK_BIT_LEFT) {
|
2006-01-07 16:30:49 +00:00
|
|
|
new_ground = RAIL_GROUND_FENCE_NW;
|
|
|
|
}
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-01-07 16:30:49 +00:00
|
|
|
if (rail == (TRACK_BIT_UPPER | TRACK_BIT_LEFT) || (
|
2006-03-18 13:20:50 +00:00
|
|
|
(rail & TRACK_BIT_3WAY_SE) == 0 &&
|
2006-03-01 09:40:34 +00:00
|
|
|
(rail & TRACK_BIT_X)
|
2006-01-07 16:30:49 +00:00
|
|
|
)) {
|
|
|
|
TileIndex n = tile + TileDiffXY(0, 1);
|
2006-04-12 12:12:51 +00:00
|
|
|
TrackBits nrail = GetTrackBits(n);
|
2006-01-07 16:30:49 +00:00
|
|
|
|
|
|
|
if (!IsTileType(n, MP_RAILWAY) ||
|
|
|
|
!IsTileOwner(n, owner) ||
|
2006-04-12 12:12:51 +00:00
|
|
|
nrail == TRACK_BIT_LOWER ||
|
|
|
|
nrail == TRACK_BIT_RIGHT) {
|
2006-01-07 16:30:49 +00:00
|
|
|
new_ground = (new_ground == RAIL_GROUND_FENCE_NW) ?
|
|
|
|
RAIL_GROUND_FENCE_SENW : RAIL_GROUND_FENCE_SE;
|
|
|
|
}
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-01-07 16:30:49 +00:00
|
|
|
if (rail == (TRACK_BIT_LOWER | TRACK_BIT_LEFT) || (
|
2006-03-18 13:20:50 +00:00
|
|
|
(rail & TRACK_BIT_3WAY_NE) == 0 &&
|
2006-03-01 09:40:34 +00:00
|
|
|
(rail & TRACK_BIT_Y)
|
2006-01-07 16:30:49 +00:00
|
|
|
)) {
|
|
|
|
TileIndex n = tile + TileDiffXY(-1, 0);
|
2006-04-12 12:12:51 +00:00
|
|
|
TrackBits nrail = GetTrackBits(n);
|
2006-01-07 16:30:49 +00:00
|
|
|
|
|
|
|
if (!IsTileType(n, MP_RAILWAY) ||
|
|
|
|
!IsTileOwner(n, owner) ||
|
2006-04-12 12:12:51 +00:00
|
|
|
nrail == TRACK_BIT_UPPER ||
|
|
|
|
nrail == TRACK_BIT_RIGHT) {
|
2006-01-07 16:30:49 +00:00
|
|
|
new_ground = RAIL_GROUND_FENCE_NE;
|
|
|
|
}
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-01-07 16:30:49 +00:00
|
|
|
if (rail == (TRACK_BIT_UPPER | TRACK_BIT_RIGHT) || (
|
2006-03-19 06:50:19 +00:00
|
|
|
(rail & TRACK_BIT_3WAY_SW) == 0 &&
|
2006-03-01 09:40:34 +00:00
|
|
|
(rail & TRACK_BIT_Y)
|
2006-01-07 16:30:49 +00:00
|
|
|
)) {
|
|
|
|
TileIndex n = tile + TileDiffXY(1, 0);
|
2006-04-12 12:12:51 +00:00
|
|
|
TrackBits nrail = GetTrackBits(n);
|
2006-01-07 16:30:49 +00:00
|
|
|
|
|
|
|
if (!IsTileType(n, MP_RAILWAY) ||
|
|
|
|
!IsTileOwner(n, owner) ||
|
2006-04-12 12:12:51 +00:00
|
|
|
nrail == TRACK_BIT_LOWER ||
|
|
|
|
nrail == TRACK_BIT_LEFT) {
|
2006-01-07 16:30:49 +00:00
|
|
|
new_ground = (new_ground == RAIL_GROUND_FENCE_NE) ?
|
|
|
|
RAIL_GROUND_FENCE_NESW : RAIL_GROUND_FENCE_SW;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-31 11:42:16 +00:00
|
|
|
set_ground:
|
2005-11-16 14:30:24 +00:00
|
|
|
if (old_ground != new_ground) {
|
2006-04-12 11:58:07 +00:00
|
|
|
SetRailGroundType(tile, new_ground);
|
2004-08-09 17:04:08 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-05-24 22:41:50 +00:00
|
|
|
static uint32 GetTileTrackStatus_Track(TileIndex tile, TransportType mode, uint sub_mode)
|
2005-06-24 12:38:35 +00:00
|
|
|
{
|
2005-11-14 19:48:04 +00:00
|
|
|
if (mode != TRANSPORT_RAIL) return 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-02 00:17:35 +00:00
|
|
|
switch (GetRailTileType(tile)) {
|
|
|
|
default: NOT_REACHED();
|
|
|
|
case RAIL_TILE_NORMAL: {
|
|
|
|
TrackBits rails = GetTrackBits(tile);
|
|
|
|
uint32 ret = rails * 0x101;
|
|
|
|
return (rails == TRACK_BIT_CROSS) ? ret | 0x40 : ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
case RAIL_TILE_SIGNALS: {
|
|
|
|
uint32 ret = GetTrackBits(tile) * 0x101;
|
2007-05-30 13:33:19 +00:00
|
|
|
byte a = GetPresentSignals(tile);
|
|
|
|
uint b = GetSignalStates(tile);
|
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' */
|
2007-05-30 13:33:19 +00:00
|
|
|
if ((a & 0xC) == 0) b |= 0xC;
|
|
|
|
if ((a & 0x3) == 0) b |= 0x3;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-05-30 13:33:19 +00:00
|
|
|
if ((b & 0x8) == 0) ret |= 0x10070000;
|
|
|
|
if ((b & 0x4) == 0) ret |= 0x07100000;
|
|
|
|
if ((b & 0x2) == 0) ret |= 0x20080000;
|
|
|
|
if ((b & 0x1) == 0) ret |= 0x08200000;
|
2007-03-02 00:17:35 +00:00
|
|
|
|
|
|
|
return ret;
|
2006-03-19 12:06:12 +00:00
|
|
|
}
|
2007-03-02 00:17:35 +00:00
|
|
|
|
|
|
|
case RAIL_TILE_DEPOT: return AxisToTrackBits(DiagDirToAxis(GetRailDepotDirection(tile))) * 0x101;
|
|
|
|
case RAIL_TILE_WAYPOINT: return GetRailWaypointBits(tile) * 0x101;
|
2006-03-19 12:06:12 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static void ClickTile_Track(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-03-02 00:17:35 +00:00
|
|
|
switch (GetRailTileType(tile)) {
|
2007-03-08 16:27:54 +00:00
|
|
|
case RAIL_TILE_DEPOT: ShowDepotWindow(tile, VEH_TRAIN); break;
|
2007-03-02 00:17:35 +00:00
|
|
|
case RAIL_TILE_WAYPOINT: ShowRenameWaypointWindow(GetWaypointByTile(tile)); break;
|
|
|
|
default: break;
|
2005-10-22 06:39:32 +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)) {
|
2006-05-09 08:17:33 +00:00
|
|
|
case RAIL_TILE_NORMAL:
|
2004-08-09 17:04:08 +00:00
|
|
|
td->str = STR_1021_RAILROAD_TRACK;
|
2005-03-28 07:02:51 +00:00
|
|
|
break;
|
|
|
|
|
2006-05-09 08:17:33 +00:00
|
|
|
case RAIL_TILE_SIGNALS: {
|
2007-05-31 21:21:04 +00:00
|
|
|
const StringID signal_type[4][4] = {
|
|
|
|
{
|
|
|
|
STR_RAILROAD_TRACK_WITH_NORMAL_SIGNALS,
|
|
|
|
STR_RAILROAD_TRACK_WITH_NORMAL_PRESIGNALS,
|
|
|
|
STR_RAILROAD_TRACK_WITH_NORMAL_EXITSIGNALS,
|
|
|
|
STR_RAILROAD_TRACK_WITH_NORMAL_COMBOSIGNALS
|
|
|
|
},
|
|
|
|
{
|
|
|
|
STR_RAILROAD_TRACK_WITH_NORMAL_PRESIGNALS,
|
|
|
|
STR_RAILROAD_TRACK_WITH_PRESIGNALS,
|
|
|
|
STR_RAILROAD_TRACK_WITH_PRE_EXITSIGNALS,
|
|
|
|
STR_RAILROAD_TRACK_WITH_PRE_COMBOSIGNALS
|
|
|
|
},
|
|
|
|
{
|
|
|
|
STR_RAILROAD_TRACK_WITH_NORMAL_EXITSIGNALS,
|
|
|
|
STR_RAILROAD_TRACK_WITH_PRE_EXITSIGNALS,
|
|
|
|
STR_RAILROAD_TRACK_WITH_EXITSIGNALS,
|
|
|
|
STR_RAILROAD_TRACK_WITH_EXIT_COMBOSIGNALS
|
|
|
|
},
|
|
|
|
{
|
|
|
|
STR_RAILROAD_TRACK_WITH_NORMAL_COMBOSIGNALS,
|
|
|
|
STR_RAILROAD_TRACK_WITH_PRE_COMBOSIGNALS,
|
|
|
|
STR_RAILROAD_TRACK_WITH_EXIT_COMBOSIGNALS,
|
|
|
|
STR_RAILROAD_TRACK_WITH_COMBOSIGNALS
|
|
|
|
}
|
2005-03-28 07:02:51 +00:00
|
|
|
};
|
|
|
|
|
2007-05-31 21:21:04 +00:00
|
|
|
td->str = signal_type[GetSignalType(tile, TRACK_UPPER)][GetSignalType(tile, TRACK_LOWER)];
|
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
|
|
|
|
2007-02-27 23:36:28 +00:00
|
|
|
case RAIL_TILE_DEPOT:
|
|
|
|
td->str = STR_1023_RAILROAD_TRAIN_DEPOT;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RAIL_TILE_WAYPOINT:
|
2005-03-28 07:02:51 +00:00
|
|
|
default:
|
2007-02-27 23:36:28 +00:00
|
|
|
td->str = STR_LANDINFO_WAYPOINT;
|
2005-03-28 07:02:51 +00:00
|
|
|
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
|
|
|
|
2006-10-14 15:49:43 +00:00
|
|
|
if (new_player != PLAYER_SPECTATOR) {
|
2005-06-04 12:13:24 +00:00
|
|
|
SetTileOwner(tile, new_player);
|
2006-08-28 18:53:03 +00:00
|
|
|
} else {
|
2006-04-10 07:15:58 +00:00
|
|
|
DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const byte _fractcoords_behind[4] = { 0x8F, 0x8, 0x80, 0xF8 };
|
|
|
|
static const byte _fractcoords_enter[4] = { 0x8A, 0x48, 0x84, 0xA8 };
|
2007-01-10 18:56:51 +00:00
|
|
|
static const signed char _deltacoord_leaveoffset[8] = {
|
2005-06-06 22:44:11 +00:00
|
|
|
-1, 0, 1, 0, /* x */
|
|
|
|
0, 1, 0, -1 /* y */
|
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
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;
|
2006-03-08 06:55:33 +00:00
|
|
|
DiagDirection dir;
|
2005-06-06 22:44:11 +00:00
|
|
|
int length;
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2007-04-04 01:35:16 +00:00
|
|
|
/* this routine applies only to trains in depot tiles */
|
2007-03-08 16:27:54 +00:00
|
|
|
if (v->type != VEH_TRAIN || !IsTileDepotType(tile, TRANSPORT_RAIL)) return VETSB_CONTINUE;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
/* depot direction */
|
2006-03-12 16:13:16 +00:00
|
|
|
dir = GetRailDepotDirection(tile);
|
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 =
|
2006-08-28 18:53:03 +00:00
|
|
|
((_fractcoords_enter[dir] & 0x0F) + // x
|
2005-06-06 22:44:11 +00:00
|
|
|
(length + 1) * _deltacoord_leaveoffset[dir]) +
|
2006-08-28 18:53:03 +00:00
|
|
|
(((_fractcoords_enter[dir] >> 4) + // y
|
2005-06-06 22:44:11 +00:00
|
|
|
((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 */
|
2007-02-13 10:26:53 +00:00
|
|
|
return VETSB_CANNOT_ENTER;
|
2004-08-09 17:04:08 +00:00
|
|
|
} else if (_fractcoords_enter[dir] == fract_coord) {
|
2006-03-08 06:55:33 +00:00
|
|
|
if (DiagDirToDir(ReverseDiagDir(dir)) == v->direction) {
|
2004-08-09 17:04:08 +00:00
|
|
|
/* enter the depot */
|
2007-02-13 10:46:45 +00:00
|
|
|
v->u.rail.track = TRACK_BIT_DEPOT,
|
2004-08-09 17:04:08 +00:00
|
|
|
v->vehstatus |= VS_HIDDEN; /* hide it */
|
2006-03-08 06:55:33 +00:00
|
|
|
v->direction = ReverseDir(v->direction);
|
2006-12-01 00:09:13 +00:00
|
|
|
if (v->next == NULL) VehicleEnterDepot(v);
|
2004-08-09 17:04:08 +00:00
|
|
|
v->tile = tile;
|
2006-12-01 00:09:13 +00:00
|
|
|
|
|
|
|
InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
|
2007-02-13 10:26:53 +00:00
|
|
|
return VETSB_ENTERED_WORMHOLE;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2005-06-06 22:44:11 +00:00
|
|
|
} else if (fract_coord_leave == fract_coord) {
|
2006-03-08 06:55:33 +00:00
|
|
|
if (DiagDirToDir(dir) == v->direction) {
|
2004-08-09 17:04:08 +00:00
|
|
|
/* leave the depot? */
|
2006-02-01 06:32:03 +00:00
|
|
|
if ((v = v->next) != NULL) {
|
2004-08-09 17:04:08 +00:00
|
|
|
v->vehstatus &= ~VS_HIDDEN;
|
2007-01-10 18:56:51 +00:00
|
|
|
v->u.rail.track = (DiagDirToAxis(dir) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-13 10:26:53 +00:00
|
|
|
return VETSB_CONTINUE;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-10 18:56:51 +00:00
|
|
|
extern const TileTypeProcs _tile_type_rail_procs = {
|
2006-08-22 14:38:37 +00:00
|
|
|
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 */
|
|
|
|
GetSlopeTileh_Track, /* get_slope_tileh_proc */
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|