diff --git a/BUGS b/BUGS new file mode 100644 index 0000000000..bcdcee6f2a --- /dev/null +++ b/BUGS @@ -0,0 +1,7 @@ +/* $Id */ + +KNOWN BUGS / PROBLEMS: + +Normal and elrail depots look the same. Use 'X' (transparent buildings) + to distinguish between them +Missing curors / icons for construction (currently using the conventional ones) diff --git a/Makefile b/Makefile index 5fb9a1eb73..4de699a2ac 100644 --- a/Makefile +++ b/Makefile @@ -630,6 +630,7 @@ SRCS += dock_gui.c SRCS += driver.c SRCS += dummy_land.c SRCS += economy.c +SRCS += elrail.c SRCS += engine.c SRCS += engine_gui.c SRCS += fileio.c diff --git a/ai/default/default.c b/ai/default/default.c index 2a638e3e90..8c4d2569e4 100644 --- a/ai/default/default.c +++ b/ai/default/default.c @@ -126,7 +126,7 @@ static void AiStateVehLoop(Player *p) p->ai.state_counter = 0; } -static EngineID AiChooseTrainToBuild(byte railtype, int32 money, byte flag, TileIndex tile) +static EngineID AiChooseTrainToBuild(RailType railtype, int32 money, byte flag, TileIndex tile) { EngineID best_veh_index = INVALID_ENGINE; byte best_veh_score = 0; @@ -137,7 +137,7 @@ static EngineID AiChooseTrainToBuild(byte railtype, int32 money, byte flag, Tile const RailVehicleInfo *rvi = RailVehInfo(i); const Engine* e = GetEngine(i); - if (e->railtype != railtype || + if (!IsCompatibleRail(e->railtype, railtype) || rvi->flags & RVI_WAGON || (rvi->flags & RVI_MULTIHEAD && flag & 1) || !HASBIT(e->player_avail, _current_player) || @@ -2321,6 +2321,41 @@ static StationID AiGetStationIdByDef(TileIndex tile, int id) return GetStationIndex(TILE_ADD(tile, ToTileIndexDiff(p->tileoffs))); } +static EngineID AiFindBestWagon(CargoID cargo, RailType railtype) +{ + EngineID best_veh_index = INVALID_ENGINE; + EngineID i; + uint16 best_capacity = 0; + uint16 best_speed = 0; + uint speed; + + for (i = 0; i < NUM_TRAIN_ENGINES; i++) { + const RailVehicleInfo *rvi = RailVehInfo(i); + const Engine* e = GetEngine(i); + + if (!IsCompatibleRail(e->railtype, railtype) || + !(rvi->flags & RVI_WAGON) || + !HASBIT(e->player_avail, _current_player)) { + continue; + } + + if (rvi->cargo_type != cargo) { + continue; + } + + /* max_speed of 0 indicates no speed limit */ + speed = rvi->max_speed == 0 ? 0xFFFF : rvi->max_speed; + + if (rvi->capacity >= best_capacity && speed >= best_speed) { + best_capacity = rvi->capacity; + best_speed = best_speed; + best_veh_index = i; + } + } + + return best_veh_index; +} + static void AiStateBuildRailVeh(Player *p) { const AiDefaultBlockData *ptr; @@ -2337,10 +2372,14 @@ static void AiStateBuildRailVeh(Player *p) tile = TILE_ADD(p->ai.src.use_tile, ToTileIndexDiff(ptr->tileoffs)); + cargo = p->ai.cargo_type; for (i = 0;;) { if (p->ai.wagon_list[i] == INVALID_VEHICLE) { - veh = _cargoc.ai_railwagon[p->ai.railtype_to_use][cargo]; + veh = AiFindBestWagon(cargo, p->ai.railtype_to_use); + /* veh will return INVALID_ENGINE if no suitable wagon is available. + * We shall treat this in the same way as having no money */ + if (veh == INVALID_ENGINE) goto handle_nocash; cost = DoCommandByTile(tile, veh, 0, DC_EXEC, CMD_BUILD_RAIL_VEHICLE); if (CmdFailed(cost)) goto handle_nocash; p->ai.wagon_list[i] = _new_wagon_id; diff --git a/bridge.h b/bridge.h index 79ea4fbde3..18fcf81de8 100644 --- a/bridge.h +++ b/bridge.h @@ -22,4 +22,6 @@ typedef struct Bridge { extern const Bridge orig_bridge[MAX_BRIDGES]; extern Bridge _bridge[MAX_BRIDGES]; +uint GetBridgeFoundation(uint tileh, Axis axis); + #endif /* BRIDGE_H */ diff --git a/bridge_map.h b/bridge_map.h index f799077b3c..014a3671c8 100644 --- a/bridge_map.h +++ b/bridge_map.h @@ -127,6 +127,7 @@ TileIndex GetSouthernBridgeEnd(TileIndex t); */ TileIndex GetOtherBridgeEnd(TileIndex); +uint GetBridgeHeight(TileIndex t); static inline void SetClearUnderBridge(TileIndex t) { diff --git a/data/elrailsw.grf b/data/elrailsw.grf new file mode 100644 index 0000000000..f722d1e3a7 Binary files /dev/null and b/data/elrailsw.grf differ diff --git a/docs/elrail.svg b/docs/elrail.svg new file mode 100644 index 0000000000..39098a388b --- /dev/null +++ b/docs/elrail.svg @@ -0,0 +1,1091 @@ + + + diff --git a/docs/elrail_tile.png b/docs/elrail_tile.png new file mode 100644 index 0000000000..82407de486 Binary files /dev/null and b/docs/elrail_tile.png differ diff --git a/docs/elrail_track.png b/docs/elrail_track.png new file mode 100644 index 0000000000..af88bd3317 Binary files /dev/null and b/docs/elrail_track.png differ diff --git a/docs/landscape.html b/docs/landscape.html index 92fed219e4..b28a8932fc 100644 --- a/docs/landscape.html +++ b/docs/landscape.html @@ -129,7 +129,7 @@ m5 bit 7 clear: railway track
+ +Now on each edge there are two PCPs: One from each adjacent tile. Both PCPs are merged +using an OR matrix (i. e. if one tile needs a PCP at the postion in question, both +tiles get it). + +
@@ -478,6 +480,11 @@ static inline bool IsCompatibleRail(RailType enginetype, RailType tiletype)
return HASBIT(GetRailTypeInfo(enginetype)->compatible_railtypes, tiletype);
}
+static inline bool HasPowerOnRail(RailType enginetype, RailType tiletype)
+{
+ return HASBIT(GetRailTypeInfo(enginetype)->powered_railtypes, tiletype);
+}
+
/**
* Checks if the given tracks overlap, ie form a crossing. Basically this
* means when there is more than one track on the tile, exept when there are
@@ -497,4 +504,13 @@ static inline bool TracksOverlap(TrackBits bits)
void DrawTrainDepotSprite(int x, int y, int image, RailType railtype);
void DrawDefaultWaypointSprite(int x, int y, RailType railtype);
+
+/**
+ * Draws overhead wires and pylons for electric railways.
+ * @param ti The TileInfo struct of the tile being drawn
+ * @see DrawCatenaryRailway
+ */
+void DrawCatenary(const TileInfo *ti);
+
+uint GetRailFoundation(uint tileh, uint bits);
#endif /* RAIL_H */
diff --git a/rail_cmd.c b/rail_cmd.c
index 039acf9bd5..75e0263f17 100644
--- a/rail_cmd.c
+++ b/rail_cmd.c
@@ -896,11 +896,13 @@ int32 CmdRemoveSignalTrack(int x, int y, uint32 flags, uint32 p1, uint32 p2)
return CmdSignalTrackHelper(x, y, flags, p1, SETBIT(p2, 0));
}
-typedef int32 DoConvertRailProc(TileIndex tile, uint totype, bool exec);
+typedef int32 DoConvertRailProc(TileIndex tile, RailType totype, bool exec);
-static int32 DoConvertRail(TileIndex tile, uint totype, bool exec)
+static int32 DoConvertRail(TileIndex tile, RailType totype, bool exec)
{
- if (!CheckTileOwnership(tile) || !EnsureNoVehicle(tile)) return CMD_ERROR;
+ if (!CheckTileOwnership(tile)) return CMD_ERROR;
+
+ if (!EnsureNoVehicle(tile) && (!IsCompatibleRail(GetRailType(tile), totype) || IsPlainRailTile(tile))) return CMD_ERROR;
// tile is already of requested type?
if (GetRailType(tile) == totype) return CMD_ERROR;
@@ -1297,6 +1299,9 @@ static void DrawTrackBits(TileInfo* ti, TrackBits track, bool earth, bool snow,
if (track & TRACK_BIT_LEFT) DrawGroundSprite(rti->base_sprites.single_w);
if (track & TRACK_BIT_RIGHT) DrawGroundSprite(rti->base_sprites.single_e);
}
+
+ if (GB(_m[ti->tile].m3, 0, 4) == RAILTYPE_ELECTRIC) DrawCatenary(ti);
+
}
static void DrawTile_Track(TileInfo *ti)
@@ -1388,6 +1393,8 @@ static void DrawTile_Track(TileInfo *ti)
DrawGroundSprite(image);
+ if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC) DrawCatenary(ti);
+
foreach_draw_tile_seq(seq, cust->seq) {
DrawSpecialBuilding(
seq->image + relocation, 0, ti,
@@ -1420,6 +1427,8 @@ static void DrawTile_Track(TileInfo *ti)
DrawGroundSprite(image);
+ if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC) DrawCatenary(ti);
+
for (; drss->image != 0; drss++) {
DrawSpecialBuilding(
drss->image, type < 4 ? rti->total_offset : 0, ti,
diff --git a/rail_map.h b/rail_map.h
index 5a3828282f..a74982cf11 100644
--- a/rail_map.h
+++ b/rail_map.h
@@ -32,13 +32,16 @@ typedef enum RailTileSubtypes {
typedef enum RailTypes {
- RAILTYPE_RAIL = 0,
- RAILTYPE_MONO = 1,
- RAILTYPE_MAGLEV = 2,
+ RAILTYPE_RAIL = 0,
+ RAILTYPE_ELECTRIC = 1,
+ RAILTYPE_MONO = 2,
+ RAILTYPE_MAGLEV = 3,
RAILTYPE_END,
INVALID_RAILTYPE = 0xFF
} RailType;
+typedef byte RailTypeMask;
+
static inline RailType GetRailType(TileIndex t)
{
return (RailType)GB(_m[t].m3, 0, 4);
diff --git a/railtypes.h b/railtypes.h
index 12180c352a..1b9b665c49 100644
--- a/railtypes.h
+++ b/railtypes.h
@@ -40,8 +40,11 @@ const RailtypeInfo _railtypes[] = {
/* Offset of snow tiles */
SPR_RAIL_SNOW_OFFSET,
+ /* Powered railtypes */
+ 1 << RAILTYPE_RAIL | 1 << RAILTYPE_ELECTRIC,
+
/* Compatible railtypes */
- (1 << RAILTYPE_RAIL),
+ 1 << RAILTYPE_RAIL | 1 << RAILTYPE_ELECTRIC,
/* main offset */
0,
@@ -50,6 +53,56 @@ const RailtypeInfo _railtypes[] = {
0,
},
+ /** Electrified railway */
+ { /* Main Sprites */
+ { SPR_RAIL_TRACK_Y, SPR_RAIL_TRACK_N_S, SPR_RAIL_TRACK_BASE, SPR_RAIL_SINGLE_Y, SPR_RAIL_SINGLE_X,
+ SPR_RAIL_SINGLE_NORTH, SPR_RAIL_SINGLE_SOUTH, SPR_RAIL_SINGLE_EAST, SPR_RAIL_SINGLE_WEST,
+ SPR_CROSSING_OFF_X_RAIL,
+ SPR_TUNNEL_ENTRY_REAR_RAIL
+ },
+
+ /* GUI sprites */
+ {
+ SPR_BUILD_NS_ELRAIL,
+ SPR_BUILD_X_ELRAIL,
+ SPR_BUILD_EW_ELRAIL,
+ SPR_BUILD_Y_ELRAIL,
+ SPR_OPENTTD_BASE + 0,
+ 0x50E,
+ SPR_BUILD_TUNNEL_ELRAIL,
+ SPR_IMG_CONVERT_RAIL
+ },
+
+ {
+ SPR_CURSOR_NS_ELRAIL,
+ SPR_CURSOR_SWNE_ELRAIL,
+ SPR_CURSOR_EW_ELRAIL,
+ SPR_CURSOR_NWSE_ELRAIL,
+ SPR_CURSOR_AUTORAIL,
+ SPR_CURSOR_RAIL_DEPOT,
+ SPR_CURSOR_TUNNEL_ELRAIL,
+ SPR_CURSOR_CONVERT_RAIL
+ },
+
+ /* strings */
+ { STR_TITLE_ELRAIL_CONSTRUCTION },
+
+ /* Offset of snow tiles */
+ SPR_RAIL_SNOW_OFFSET,
+
+ /* Powered railtypes */
+ 1 << RAILTYPE_ELECTRIC,
+
+ /* Compatible railtypes */
+ 1 << RAILTYPE_ELECTRIC | 1 << RAILTYPE_RAIL,
+
+ /* main offset */
+ 0,
+
+ /* bridge offset */
+ 0
+ },
+
/** Monorail */
{ /* Main Sprites */
{ SPR_MONO_TRACK_Y, SPR_MONO_TRACK_N_S, SPR_MONO_TRACK_BASE, SPR_MONO_SINGLE_Y, SPR_MONO_SINGLE_X,
@@ -83,8 +136,11 @@ const RailtypeInfo _railtypes[] = {
/* Offset of snow tiles */
SPR_MONO_SNOW_OFFSET,
+ /* Powered railtypes */
+ 1 << RAILTYPE_MONO,
+
/* Compatible Railtypes */
- (1 << RAILTYPE_MONO),
+ 1 << RAILTYPE_MONO,
/* main offset */
82,
@@ -126,8 +182,11 @@ const RailtypeInfo _railtypes[] = {
/* Offset of snow tiles */
SPR_MGLV_SNOW_OFFSET,
+ /* Powered railtypes */
+ 1 << RAILTYPE_MAGLEV,
+
/* Compatible Railtypes */
- (1 << RAILTYPE_MAGLEV),
+ 1 << RAILTYPE_MAGLEV,
/* main offset */
164,
diff --git a/road_cmd.c b/road_cmd.c
index 854c59cff9..20505c9591 100644
--- a/road_cmd.c
+++ b/road_cmd.c
@@ -787,6 +787,7 @@ static void DrawTile_Road(TileInfo *ti)
}
DrawGroundSprite(image);
+ if (GB(_m[ti->tile].m4, 0, 4) == RAILTYPE_ELECTRIC) DrawCatenary(ti);
break;
}
diff --git a/saveload.c b/saveload.c
index 3b304f445e..75f75c6d06 100644
--- a/saveload.c
+++ b/saveload.c
@@ -30,7 +30,7 @@
#include "variables.h"
#include
+ * Identifiers for Pylons:
+ *
+ */
+typedef enum {
+ WIRE_X_FLAT_SW,
+ WIRE_X_FLAT_NE,
+ WIRE_X_FLAT_BOTH,
+
+ WIRE_X_UP_SW,
+ WIRE_X_UP_NE,
+ WIRE_X_UP_BOTH,
+
+ WIRE_X_DOWN_SW,
+ WIRE_X_DOWN_NE,
+ WIRE_X_DOWN_BOTH,
+
+ WIRE_Y_FLAT_SE,
+ WIRE_Y_FLAT_NW,
+ WIRE_Y_FLAT_BOTH,
+
+ WIRE_Y_UP_SE,
+ WIRE_Y_UP_NW,
+ WIRE_Y_UP_BOTH,
+
+ WIRE_Y_DOWN_SE,
+ WIRE_Y_DOWN_NW,
+ WIRE_Y_DOWN_BOTH,
+
+ WIRE_NS_W_BOTH,
+ WIRE_NS_E_BOTH,
+
+ WIRE_NS_W_N,
+ WIRE_NS_E_N,
+
+ WIRE_NS_W_S,
+ WIRE_NS_E_S,
+
+ WIRE_EW_N_BOTH,
+ WIRE_EW_S_BOTH,
+
+ WIRE_EW_N_W,
+ WIRE_EW_S_W,
+
+ WIRE_EW_N_E,
+ WIRE_EW_S_E,
+
+ WIRE_DEPOT_SW,
+ WIRE_DEPOT_NW,
+ WIRE_DEPOT_NE,
+ WIRE_DEPOT_SE,
+
+ INVALID_CATENARY = 0xFF
+} CatenarySprite;
+
+/* This array stores which track bits can meet at a tile edge */
+static const Track PPPtracks[DIAGDIR_END][TRACKS_AT_PCP] = {
+ {TRACK_X, TRACK_X, TRACK_UPPER, TRACK_LOWER, TRACK_LEFT, TRACK_RIGHT},
+ {TRACK_Y, TRACK_Y, TRACK_UPPER, TRACK_LOWER, TRACK_LEFT, TRACK_RIGHT},
+ {TRACK_X, TRACK_X, TRACK_UPPER, TRACK_LOWER, TRACK_LEFT, TRACK_RIGHT},
+ {TRACK_Y, TRACK_Y, TRACK_UPPER, TRACK_LOWER, TRACK_LEFT, TRACK_RIGHT},
+};
+
+/* takes each of the 8 track bits from the array above and
+ assigns it to the home tile or neighbour tile */
+static const TileSource trackorigin[DIAGDIR_END][TRACKS_AT_PCP] = {
+ {TS_HOME, TS_NEIGHBOUR, TS_HOME , TS_NEIGHBOUR, TS_NEIGHBOUR, TS_HOME },
+ {TS_HOME, TS_NEIGHBOUR, TS_NEIGHBOUR, TS_HOME , TS_NEIGHBOUR, TS_HOME },
+ {TS_HOME, TS_NEIGHBOUR, TS_NEIGHBOUR, TS_HOME , TS_HOME , TS_NEIGHBOUR},
+ {TS_HOME, TS_NEIGHBOUR, TS_HOME , TS_NEIGHBOUR, TS_HOME , TS_NEIGHBOUR},
+};
+
+/* Several PPPs maybe exist, here they are sorted in order of preference. */
+static const Direction PPPorder[DIAGDIR_END][TLG_END][DIR_END] = { /* X - Y */
+ { /* PCP 0 */
+ {DIR_NE, DIR_NW, DIR_SE, DIR_SW, DIR_N, DIR_E, DIR_S, DIR_W}, /* evn - evn */
+ {DIR_NE, DIR_SE, DIR_SW, DIR_NW, DIR_S, DIR_W, DIR_N, DIR_E}, /* evn - odd */
+ {DIR_SW, DIR_NW, DIR_NE, DIR_SE, DIR_S, DIR_W, DIR_N, DIR_E}, /* odd - evn */
+ {DIR_SW, DIR_SE, DIR_NE, DIR_NW, DIR_N, DIR_E, DIR_S, DIR_W}, /* odd - odd */
+ }, {/* PCP 1 */
+ {DIR_NE, DIR_NW, DIR_SE, DIR_SW, DIR_S, DIR_E, DIR_N, DIR_W}, /* evn - evn */
+ {DIR_NE, DIR_SE, DIR_SW, DIR_NW, DIR_N, DIR_W, DIR_S, DIR_E}, /* evn - odd */
+ {DIR_SW, DIR_NW, DIR_NE, DIR_SE, DIR_N, DIR_W, DIR_S, DIR_E}, /* odd - evn */
+ {DIR_SW, DIR_SE, DIR_NE, DIR_NW, DIR_S, DIR_E, DIR_N, DIR_W}, /* odd - odd */
+ }, {/* PCP 2 */
+ {DIR_NE, DIR_NW, DIR_SE, DIR_SW, DIR_S, DIR_W, DIR_N, DIR_E}, /* evn - evn */
+ {DIR_NE, DIR_SE, DIR_SW, DIR_NW, DIR_N, DIR_E, DIR_S, DIR_W}, /* evn - odd */
+ {DIR_SW, DIR_NW, DIR_NE, DIR_SE, DIR_N, DIR_E, DIR_S, DIR_W}, /* odd - evn */
+ {DIR_SW, DIR_SE, DIR_NE, DIR_NW, DIR_S, DIR_W, DIR_N, DIR_E}, /* odd - odd */
+ }, {/* PCP 3 */
+ {DIR_NE, DIR_NW, DIR_SE, DIR_SW, DIR_N, DIR_W, DIR_S, DIR_E}, /* evn - evn */
+ {DIR_NE, DIR_SE, DIR_SW, DIR_NW, DIR_S, DIR_E, DIR_N, DIR_W}, /* evn - odd */
+ {DIR_SW, DIR_NW, DIR_NE, DIR_SE, DIR_S, DIR_E, DIR_N, DIR_W}, /* odd - evn */
+ {DIR_SW, DIR_SE, DIR_NE, DIR_NW, DIR_N, DIR_W, DIR_S, DIR_E}, /* odd - odd */
+ }
+};
+/* Geometric placement of the PCP relative to the tile origin */
+static const char x_pcp_offsets[DIAGDIR_END] = {0, 8, 15, 8};
+static const char y_pcp_offsets[DIAGDIR_END] = {8, 15, 8, 0};
+/* Geometric placement of the PPP relative to the PCP*/
+static const char x_ppp_offsets[DIR_END] = {-3, -4, -3, 0, +3, +4, +3, 0};
+static const char y_ppp_offsets[DIR_END] = {-3, 0, +3, +4, +3, 0, -3, -4};
+/* The type of pylon to draw at each PPP */
+static const SpriteID pylons_normal[] = {
+ SPR_PYLON_EW_N,
+ SPR_PYLON_Y_NE,
+ SPR_PYLON_NS_E,
+ SPR_PYLON_X_SE,
+ SPR_PYLON_EW_S,
+ SPR_PYLON_Y_SW,
+ SPR_PYLON_NS_W,
+ SPR_PYLON_X_NW
+};
+
+static const SpriteID pylons_bridge[] = {
+ SPR_PYLON_X_NW,
+ SPR_PYLON_X_SE,
+ SPR_PYLON_Y_NE,
+ SPR_PYLON_Y_SW
+};
+
+/* Maps a track bit onto two PCP positions */
+static const byte PCPpositions[TRACK_END][2] = {
+ {0, 2}, /* X */
+ {1, 3}, /* Y */
+ {3, 0}, /* UPPER */
+ {1, 2}, /* LOWER */
+ {2, 3}, /* LEFT */
+ {0, 1}, /* RIGHT */
+};
+
+/* Selects a Wire (with white and grey ends) depending on whether:
+ a) none (should never happen)
+ b) the first
+ c) the second
+ d) both
+ PCP exists.*/
+static const CatenarySprite Wires[5][TRACK_END][4] = {
+ { /* Tileh == 0 */
+ {INVALID_CATENARY, WIRE_X_FLAT_NE, WIRE_X_FLAT_SW, WIRE_X_FLAT_BOTH},
+ {INVALID_CATENARY, WIRE_Y_FLAT_SE, WIRE_Y_FLAT_NW, WIRE_Y_FLAT_BOTH},
+ {INVALID_CATENARY, WIRE_EW_N_W, WIRE_EW_N_E, WIRE_EW_N_BOTH},
+ {INVALID_CATENARY, WIRE_EW_S_E, WIRE_EW_S_W, WIRE_EW_S_BOTH},
+ {INVALID_CATENARY, WIRE_NS_W_S, WIRE_NS_W_N, WIRE_NS_W_BOTH},
+ {INVALID_CATENARY, WIRE_NS_E_N, WIRE_NS_E_S, WIRE_NS_E_BOTH},
+ }, { /* Tileh == 3 */
+ {INVALID_CATENARY, WIRE_X_UP_NE, WIRE_X_UP_SW, WIRE_X_UP_BOTH},
+ {INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY},
+ {INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY},
+ {INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY},
+ {INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY},
+ {INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY},
+ }, { /* Tileh == 6 */
+ {INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY},
+ {INVALID_CATENARY, WIRE_Y_UP_SE, WIRE_Y_UP_NW, WIRE_Y_UP_BOTH},
+ {INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY},
+ {INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY},
+ {INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY},
+ {INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY},
+ }, { /* Tileh == 9 */
+ {INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY},
+ {INVALID_CATENARY, WIRE_Y_DOWN_SE, WIRE_Y_DOWN_NW, WIRE_Y_DOWN_BOTH},
+ {INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY},
+ {INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY},
+ {INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY},
+ {INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY},
+ }, { /* Tileh == 12 */
+ {INVALID_CATENARY, WIRE_X_DOWN_NE, WIRE_X_DOWN_SW, WIRE_X_DOWN_BOTH},
+ {INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY},
+ {INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY},
+ {INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY},
+ {INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY},
+ {INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY, INVALID_CATENARY},
+ }
+};
+
+#endif /* ELRAIL_DATA_H */
+
diff --git a/table/engines.h b/table/engines.h
index b8fe401907..dc33ebafab 100644
--- a/table/engines.h
+++ b/table/engines.h
@@ -27,11 +27,13 @@
// Rail types
// R = Conventional railway
+// E = Electrified railway
// M = Monorail
// L = MagLev
#define R 0
-#define M 1
-#define L 2
+#define E 1
+#define M 2
+#define L 3
// Climates
// T = Temperate
// A = Arctic
@@ -65,10 +67,10 @@ const EngineInfo orig_engine_info[] = {
MK( 20454, 20, 22, 30, R, A|S ), /* 20 Turner Turbo (Diesel) */
MK( 16071, 20, 22, 30, R, A|S ), /* 21 MJS 1000 (Diesel) */
MK( 20820, 20, 20, 25, R, T ), /* 22 SH '125' (Diesel) */
- MK( 16437, 20, 23, 30, R, T ), /* 23 SH '30' (Electric) */
- MK( 19359, 20, 23, 80, R, T ), /* 24 SH '40' (Electric) */
- MK( 23376, 20, 25, 30, R, T ), /* 25 'T.I.M.' (Electric) */
- MK( 26298, 20, 25, 50, R, T ), /* 26 'AsiaStar' (Electric) */
+ MK( 16437, 20, 23, 30, E, T ), /* 23 SH '30' (Electric) */
+ MK( 19359, 20, 23, 80, E, T ), /* 24 SH '40' (Electric) */
+ MK( 23376, 20, 25, 30, E, T ), /* 25 'T.I.M.' (Electric) */
+ MK( 26298, 20, 25, 50, E, T ), /* 26 'AsiaStar' (Electric) */
MW( 1827, 20, 20, 50, R, T|A|S|Y), /* 27 Passenger Carriage */
MW( 1827, 20, 20, 50, R, T|A|S|Y), /* 28 Mail Van */
MW( 1827, 20, 20, 50, R, T|A ), /* 29 Coal Truck */
@@ -306,6 +308,7 @@ const EngineInfo orig_engine_info[] = {
#undef L
#undef M
#undef R
+#undef E
/** Writes the properties of a rail vehicle into the RailVehicleInfo struct.
* @see RailVehicleInfo
diff --git a/table/landscape_const.h b/table/landscape_const.h
index d7c3179e77..8cf1083c0a 100644
--- a/table/landscape_const.h
+++ b/table/landscape_const.h
@@ -42,13 +42,6 @@ static const LandscapePredefVar _landscape_predef_var[4] = {
24, 255, 90, 255, 18, 28, 40, 255, 255, 255, 32, 30,
},
- /* normal railveh by cargo */
- {
- {27, 29, 28, 30, 31, 32, 33, 34, 35, 36, 37, 38},
- {57, 59, 58, 60, 61, 62, 63, 64, 65, 66, 67, 68},
- {89, 91, 90, 92, 93, 94, 95, 96, 97, 98, 99, 100}
- },
-
/* normal road veh by cargo start & count */
{116, 123, 126, 132, 135, 138, 141, 144, 147, 150, 153, 156},
{7, 3, 6, 3, 3, 3, 3, 3, 3, 3, 3, 3}
@@ -95,14 +88,6 @@ static const LandscapePredefVar _landscape_predef_var[4] = {
24, 255, 90, 255, 18, 28, 40, 255, 255, 60, 40, 30
},
- /* hilly railveh by cargo */
- {
- {27, 29, 28, 30, 31, 32, 33, 34, 35, 39, 37, 38},
- {57, 59, 58, 60, 61, 62, 63, 64, 65, 69, 67, 68},
- {89, 91, 90, 92, 93, 94, 95, 96, 97, 101, 99, 100}
- },
-
-
/* hilly road veh by cargo start & count */
{116, 123, 126, 132, 135, 138, 141, 144, 147, 159, 153, 156},
{7, 3, 6, 3, 3, 3, 3, 3, 3, 3, 3, 3},
@@ -150,13 +135,6 @@ static const LandscapePredefVar _landscape_predef_var[4] = {
24, 20, 90, 255, 15, 28, 40, 255, 255, 80, 255, 30
},
- /* desert railveh by cargo */
- {
- {27, 43, 28, 30, 42, 32, 33, 34, 40, 41, 37, 38},
- {57, 73, 58, 60, 72, 62, 63, 64, 70, 71, 67, 68},
- {89, 105, 90, 92, 104, 94, 95, 96, 102, 103, 99, 100}
- },
-
/* desert road veh by cargo start & count */
{116, 171, 126, 132, 168, 138, 141, 144, 162, 165, 153, 156},
{7, 3, 6, 3, 3, 3, 3, 3, 3, 3, 3, 3}
@@ -203,13 +181,6 @@ static const LandscapePredefVar _landscape_predef_var[4] = {
24, 255, 90, 255, 30, 40, 60, 75, 25, 80, 255, 50
},
- /* candy railveh by cargo */
- {
- {27, 44, 28, 50, 51, 49, 46, 48, 45, 47, 53, 52},
- {57, 74, 58, 80, 81, 79, 76, 78, 75, 77, 83, 82},
- {89, 106, 90, 112, 113, 111, 108, 110, 107, 109, 115, 114}
- },
-
/* candy road veh by cargo start & count */
{116, 174, 126, 186, 192, 189, 183, 177, 180, 201, 198, 195},
{7, 3, 6, 3, 3, 3, 3, 3, 3, 3, 3, 3}
diff --git a/table/sprites.h b/table/sprites.h
index 34fda3f647..f7e0817c29 100644
--- a/table/sprites.h
+++ b/table/sprites.h
@@ -51,7 +51,8 @@ enum Sprites {
SPR_CANALS_BASE = 5382,
SPR_SLOPES_BASE = SPR_CANALS_BASE + 70,
SPR_AUTORAIL_BASE = SPR_SLOPES_BASE + 78,
- SPR_2CCMAP_BASE = SPR_AUTORAIL_BASE + 55,
+ SPR_ELRAIL_BASE = SPR_AUTORAIL_BASE + 55,
+ SPR_2CCMAP_BASE = SPR_ELRAIL_BASE + 53,
SPR_OPENTTD_BASE = SPR_2CCMAP_BASE + 256,
SPR_BLOT = SPR_OPENTTD_BASE + 29, // colored circle (mainly used as vehicle profit marker and for sever compatibility)
@@ -206,6 +207,54 @@ enum Sprites {
OFFSET_TILEH_13 = 19,
OFFSET_TILEH_14 = 16,
+ /* Elrail stuff */
+ /* Wires. First identifier is the direction of the track, second is the required placement of the pylon.
+ "short" denotes a wire that requires a pylon on each end. Third identifier is the direction of the slope
+ (in positive coordinate direction) */
+ SPR_WIRE_X_SHORT = SPR_ELRAIL_BASE + 3,
+ SPR_WIRE_Y_SHORT = SPR_ELRAIL_BASE + 4,
+ SPR_WIRE_EW_SHORT = SPR_ELRAIL_BASE + 5,
+ SPR_WIRE_NS_SHORT = SPR_ELRAIL_BASE + 6,
+ SPR_WIRE_X_SHORT_DOWN = SPR_ELRAIL_BASE + 7,
+ SPR_WIRE_Y_SHORT_UP = SPR_ELRAIL_BASE + 8,
+ SPR_WIRE_X_SHORT_UP = SPR_ELRAIL_BASE + 9,
+ SPR_WIRE_Y_SHORT_DOWN = SPR_ELRAIL_BASE + 10,
+
+ SPR_WIRE_X_SW = SPR_ELRAIL_BASE + 11,
+ SPR_WIRE_Y_SE = SPR_ELRAIL_BASE + 12,
+ SPR_WIRE_EW_E = SPR_ELRAIL_BASE + 13,
+ SPR_WIRE_NS_S = SPR_ELRAIL_BASE + 14,
+ SPR_WIRE_X_SW_DOWN = SPR_ELRAIL_BASE + 15,
+ SPR_WIRE_Y_SE_UP = SPR_ELRAIL_BASE + 16,
+ SPR_WIRE_X_SW_UP = SPR_ELRAIL_BASE + 17,
+ SPR_WIRE_Y_SE_DOWN = SPR_ELRAIL_BASE + 18,
+
+ SPR_WIRE_X_NE = SPR_ELRAIL_BASE + 19,
+ SPR_WIRE_Y_NW = SPR_ELRAIL_BASE + 20,
+ SPR_WIRE_EW_W = SPR_ELRAIL_BASE + 21,
+ SPR_WIRE_NS_N = SPR_ELRAIL_BASE + 22,
+ SPR_WIRE_X_NE_DOWN = SPR_ELRAIL_BASE + 23,
+ SPR_WIRE_Y_NW_UP = SPR_ELRAIL_BASE + 24,
+ SPR_WIRE_X_NE_UP = SPR_ELRAIL_BASE + 25,
+ SPR_WIRE_Y_NW_DOWN = SPR_ELRAIL_BASE + 26,
+
+ /* Tunnel entries */
+ SPR_WIRE_DEPOT_SW = SPR_ELRAIL_BASE + 27,
+ SPR_WIRE_DEPOT_NW = SPR_ELRAIL_BASE + 28,
+ SPR_WIRE_DEPOT_NE = SPR_ELRAIL_BASE + 29,
+ SPR_WIRE_DEPOT_SE = SPR_ELRAIL_BASE + 30,
+
+
+ /* Pylons, first identifier is the direction of the track, second the placement relative to the track */
+ SPR_PYLON_Y_NE = SPR_ELRAIL_BASE + 31,
+ SPR_PYLON_Y_SW = SPR_ELRAIL_BASE + 32,
+ SPR_PYLON_X_NW = SPR_ELRAIL_BASE + 33,
+ SPR_PYLON_X_SE = SPR_ELRAIL_BASE + 34,
+ SPR_PYLON_EW_N = SPR_ELRAIL_BASE + 35,
+ SPR_PYLON_EW_S = SPR_ELRAIL_BASE + 36,
+ SPR_PYLON_NS_W = SPR_ELRAIL_BASE + 37,
+ SPR_PYLON_NS_E = SPR_ELRAIL_BASE + 38,
+
/* sprites for airports and airfields*/
/* Small airports are AIRFIELD, everything else is AIRPORT */
SPR_HELIPORT = 2633,
@@ -955,6 +1004,13 @@ enum Sprites {
SPR_BUBBLE_ABSORB_3 = 4761,
SPR_BUBBLE_ABSORB_4 = 4762,
+ /* Electrified rail build menu */
+ SPR_BUILD_NS_ELRAIL = SPR_ELRAIL_BASE + 39,
+ SPR_BUILD_X_ELRAIL = SPR_ELRAIL_BASE + 40,
+ SPR_BUILD_EW_ELRAIL = SPR_ELRAIL_BASE + 41,
+ SPR_BUILD_Y_ELRAIL = SPR_ELRAIL_BASE + 42,
+ SPR_BUILD_TUNNEL_ELRAIL = SPR_ELRAIL_BASE + 47,
+
/* road_gui.c */
SPR_IMG_ROAD_NW = 1309,
SPR_IMG_ROAD_NE = 1310,
@@ -1034,9 +1090,15 @@ typedef enum CursorSprites {
SPR_CURSOR_EW_MAGLEV = 1273,
SPR_CURSOR_NWSE_MAGLEV = 1274,
+ SPR_CURSOR_NS_ELRAIL = SPR_ELRAIL_BASE + 43,
+ SPR_CURSOR_SWNE_ELRAIL = SPR_ELRAIL_BASE + 44,
+ SPR_CURSOR_EW_ELRAIL = SPR_ELRAIL_BASE + 45,
+ SPR_CURSOR_NWSE_ELRAIL = SPR_ELRAIL_BASE + 46,
+
SPR_CURSOR_RAIL_STATION = 1300,
SPR_CURSOR_TUNNEL_RAIL = 2434,
+ SPR_CURSOR_TUNNEL_ELRAIL = SPR_ELRAIL_BASE + 48,
SPR_CURSOR_TUNNEL_MONO = 2435,
SPR_CURSOR_TUNNEL_MAGLEV = 2436,
diff --git a/train_cmd.c b/train_cmd.c
index e5fd267724..4e433eef05 100644
--- a/train_cmd.c
+++ b/train_cmd.c
@@ -71,6 +71,46 @@ static void TrainCargoChanged(Vehicle* v)
v->u.rail.cached_weight = weight;
}
+/**
+ * Recalculates the cached total power of a train. Should be called when the consist is changed
+ * @param v First vehicle of the consist.
+ */
+void TrainPowerChanged(Vehicle* v)
+{
+ const RailVehicleInfo *rvi_v = RailVehInfo(v->engine_type);
+ Vehicle* u;
+ uint32 power = 0;
+
+ for (u = v; u != NULL; u = u->next) {
+ const RailVehicleInfo *rvi_u;
+ bool engine_has_power = true;
+ bool wagon_has_power = true;
+
+ /* Power is not added for articulated parts */
+ if (IsArticulatedPart(u)) continue;
+
+ if (IsBridgeTile(u->tile) && IsBridgeMiddle(u->tile) && DiagDirToAxis(DirToDiagDir(u->direction)) == GetBridgeAxis(u->tile)) {
+ if (!HasPowerOnRail(u->u.rail.railtype, GetRailTypeOnBridge(u->tile))) engine_has_power = false;
+ if (!HasPowerOnRail(v->u.rail.railtype, GetRailTypeOnBridge(u->tile))) wagon_has_power = false;
+ } else {
+ if (!HasPowerOnRail(u->u.rail.railtype, GetRailType(u->tile))) engine_has_power = false;
+ if (!HasPowerOnRail(v->u.rail.railtype, GetRailType(u->tile))) wagon_has_power = false;
+ }
+
+ rvi_u = RailVehInfo(u->engine_type);
+
+ if (engine_has_power) power += rvi_u->power;
+ if (HASBIT(u->u.rail.flags, VRF_POWEREDWAGON) && (wagon_has_power)) {
+ power += rvi_v->pow_wag_power;
+ }
+ }
+
+ if (v->u.rail.cached_power != power) {
+ v->u.rail.cached_power = power;
+ InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
+ }
+}
+
/**
* Recalculates the cached stuff of a train. Should be called each time a vehicle is added
* to/removed from the chain, and when the game is loaded.
@@ -82,7 +122,6 @@ void TrainConsistChanged(Vehicle* v)
const RailVehicleInfo *rvi_v;
Vehicle *u;
uint16 max_speed = 0xFFFF;
- uint32 power = 0;
EngineID first_engine;
assert(v->type == VEH_Train);
@@ -92,6 +131,7 @@ void TrainConsistChanged(Vehicle* v)
rvi_v = RailVehInfo(v->engine_type);
first_engine = IsFrontEngine(v) ? v->engine_type : INVALID_ENGINE;
v->u.rail.cached_total_length = 0;
+ v->u.rail.compatible_railtypes = 0;
for (u = v; u != NULL; u = u->next) {
const RailVehicleInfo *rvi_u = RailVehInfo(u->engine_type);
@@ -102,6 +142,7 @@ void TrainConsistChanged(Vehicle* v)
// update the 'first engine'
u->u.rail.first_engine = (v == u) ? INVALID_ENGINE : first_engine;
+ u->u.rail.railtype = GetEngine(u->engine_type)->railtype;
if (rvi_u->visual_effect != 0) {
u->u.rail.cached_vis_effect = rvi_u->visual_effect;
@@ -119,9 +160,6 @@ void TrainConsistChanged(Vehicle* v)
}
if (!IsArticulatedPart(u)) {
- // power is the sum of the powers of all engines and powered wagons in the consist
- power += rvi_u->power;
-
// check if its a powered wagon
CLRBIT(u->u.rail.flags, VRF_POWEREDWAGON);
if ((rvi_v->pow_wag_power != 0) && (rvi_u->flags & RVI_WAGON) && UsesWagonOverride(u)) {
@@ -135,10 +173,15 @@ void TrainConsistChanged(Vehicle* v)
if (u->u.rail.cached_vis_effect < 0x40) {
/* wagon is powered */
SETBIT(u->u.rail.flags, VRF_POWEREDWAGON); // cache 'powered' status
- power += rvi_v->pow_wag_power;
}
}
+ /* Do not count powered wagons for the compatible railtypes, as wagons always
+ have railtype normal */
+ if (rvi_u->power > 0) {
+ v->u.rail.compatible_railtypes |= GetRailTypeInfo(u->u.rail.railtype)->powered_railtypes;
+ }
+
// max speed is the minimum of the speed limits of all vehicles in the consist
if (!(rvi_u->flags & RVI_WAGON) || _patches.wagon_speed_limits)
if (rvi_u->max_speed != 0 && !UsesWagonOverride(u))
@@ -159,7 +202,8 @@ void TrainConsistChanged(Vehicle* v)
// store consist weight/max speed in cache
v->u.rail.cached_max_speed = max_speed;
- v->u.rail.cached_power = power;
+
+ TrainPowerChanged(v);
// recalculate cached weights too (we do this *after* the rest, so it is known which wagons are powered and need extra weight added)
TrainCargoChanged(v);
@@ -333,6 +377,7 @@ static int GetTrainAcceleration(Vehicle *v, bool mode)
if (speed > 0) {
switch (v->u.rail.railtype) {
case RAILTYPE_RAIL:
+ case RAILTYPE_ELECTRIC:
case RAILTYPE_MONO:
force = power / speed; //[N]
force *= 22;
@@ -1468,6 +1513,9 @@ static void ReverseTrainSwapVeh(Vehicle *v, int l, int r)
VehicleEnterTile(a, a->tile, a->x_pos, a->y_pos);
}
+
+ /* Update train's power incase tiles were different rail type */
+ TrainPowerChanged(v);
}
/* Check if the vehicle is a train and is on the tile we are testing */
@@ -1786,7 +1834,7 @@ static TrainFindDepotData FindClosestTrainDepot(Vehicle *v)
Trackdir trackdir_rev = ReverseTrackdir(GetVehicleTrackdir(last));
assert (trackdir != INVALID_TRACKDIR);
- ftd = NPFRouteToDepotBreadthFirstTwoWay(v->tile, trackdir, last->tile, trackdir_rev, TRANSPORT_RAIL, v->owner, v->u.rail.railtype, NPF_INFINITE_PENALTY);
+ ftd = NPFRouteToDepotBreadthFirstTwoWay(v->tile, trackdir, last->tile, trackdir_rev, TRANSPORT_RAIL, v->owner, v->u.rail.compatible_railtypes, NPF_INFINITE_PENALTY);
if (ftd.best_bird_dist == 0) {
/* Found target */
tfdd.tile = ftd.node.tile;
@@ -1805,7 +1853,7 @@ static TrainFindDepotData FindClosestTrainDepot(Vehicle *v)
if (!(v->direction & 1) && v->u.rail.track != _state_dir_table[i]) {
i = ChangeDiagDir(i, DIAGDIRDIFF_90LEFT);
}
- NewTrainPathfind(tile, 0, i, (NTPEnumProc*)NtpCallbFindDepot, &tfdd);
+ NewTrainPathfind(tile, 0, v->u.rail.compatible_railtypes, i, (NTPEnumProc*)NtpCallbFindDepot, &tfdd);
if (tfdd.best_length == (uint)-1){
tfdd.reverse = true;
// search in backwards direction
@@ -1813,7 +1861,7 @@ static TrainFindDepotData FindClosestTrainDepot(Vehicle *v)
if (!(v->direction & 1) && v->u.rail.track != _state_dir_table[i]) {
i = ChangeDiagDir(i, DIAGDIRDIFF_90LEFT);
}
- NewTrainPathfind(tile, 0, i, (NTPEnumProc*)NtpCallbFindDepot, &tfdd);
+ NewTrainPathfind(tile, 0, v->u.rail.compatible_railtypes, i, (NTPEnumProc*)NtpCallbFindDepot, &tfdd);
}
}
@@ -1899,7 +1947,7 @@ static void HandleLocomotiveSmokeCloud(const Vehicle* v)
// no smoke?
if ((RailVehInfo(engtype)->flags & RVI_WAGON && effect_type == 0) ||
disable_effect ||
- GetEngine(engtype)->railtype > RAILTYPE_RAIL ||
+ GetEngine(engtype)->railtype > RAILTYPE_ELECTRIC ||
v->vehstatus & VS_HIDDEN ||
v->u.rail.track & 0xC0) {
continue;
@@ -1961,6 +2009,7 @@ static void TrainPlayLeaveStationSound(const Vehicle* v)
switch (GetEngine(engtype)->railtype) {
case RAILTYPE_RAIL:
+ case RAILTYPE_ELECTRIC:
SndPlayVehicleFx(sfx[RailVehInfo(engtype)->engclass], v);
break;
@@ -2112,7 +2161,7 @@ static byte ChooseTrainTrack(Vehicle* v, TileIndex tile, DiagDirection enterdir,
trackdir = GetVehicleTrackdir(v);
assert(trackdir != 0xff);
- ftd = NPFRouteToStationOrTile(tile - TileOffsByDir(enterdir), trackdir, &fstd, TRANSPORT_RAIL, v->owner, v->u.rail.railtype);
+ ftd = NPFRouteToStationOrTile(tile - TileOffsByDir(enterdir), trackdir, &fstd, TRANSPORT_RAIL, v->owner, v->u.rail.compatible_railtypes);
if (ftd.best_trackdir == 0xff) {
/* We are already at our target. Just do something */
@@ -2136,7 +2185,7 @@ static byte ChooseTrainTrack(Vehicle* v, TileIndex tile, DiagDirection enterdir,
fd.best_track = 0xFF;
NewTrainPathfind(tile - TileOffsByDir(enterdir), v->dest_tile,
- enterdir, (NTPEnumProc*)NtpCallbFindStation, &fd);
+ v->u.rail.compatible_railtypes, enterdir, (NTPEnumProc*)NtpCallbFindStation, &fd);
if (fd.best_track == 0xff) {
// blaha
@@ -2190,7 +2239,7 @@ static bool CheckReverseTrain(Vehicle *v)
assert(trackdir != 0xff);
assert(trackdir_rev != 0xff);
- ftd = NPFRouteToStationOrTileTwoWay(v->tile, trackdir, last->tile, trackdir_rev, &fstd, TRANSPORT_RAIL, v->owner, v->u.rail.railtype);
+ ftd = NPFRouteToStationOrTileTwoWay(v->tile, trackdir, last->tile, trackdir_rev, &fstd, TRANSPORT_RAIL, v->owner, v->u.rail.compatible_railtypes);
if (ftd.best_bird_dist != 0) {
/* We didn't find anything, just keep on going straight ahead */
reverse_best = false;
@@ -2206,7 +2255,7 @@ static bool CheckReverseTrain(Vehicle *v)
fd.best_bird_dist = (uint)-1;
fd.best_track_dist = (uint)-1;
- NewTrainPathfind(v->tile, v->dest_tile, reverse ^ i, (NTPEnumProc*)NtpCallbFindStation, &fd);
+ NewTrainPathfind(v->tile, v->dest_tile, v->u.rail.compatible_railtypes, reverse ^ i, (NTPEnumProc*)NtpCallbFindStation, &fd);
if (best_track != -1) {
if (best_bird_dist != 0) {
@@ -2575,7 +2624,7 @@ static bool CheckCompatibleRail(const Vehicle *v, TileIndex tile)
return
IsTileOwner(tile, v->owner) && (
!IsFrontEngine(v) ||
- IsCompatibleRail(v->u.rail.railtype, GetRailType(tile))
+ HASBIT(v->u.rail.compatible_railtypes, GetRailType(tile))
);
}
@@ -2585,9 +2634,10 @@ typedef struct {
byte z_down; // fraction to remove when moving down
} RailtypeSlowdownParams;
-static const RailtypeSlowdownParams _railtype_slowdown[3] = {
+static const RailtypeSlowdownParams _railtype_slowdown[] = {
// normal accel
{256/4, 256/2, 256/4, 2}, // normal
+ {256/4, 256/2, 256/4, 2}, // electrified
{256/4, 256/2, 256/4, 2}, // monorail
{0, 256/2, 256/4, 2}, // maglev
};
@@ -2873,6 +2923,11 @@ static void TrainController(Vehicle *v)
if (!(r&0x4)) {
v->tile = gp.new_tile;
+
+ if (GetTileRailType(gp.new_tile, chosen_track) != GetTileRailType(gp.old_tile, v->u.rail.track)) {
+ TrainPowerChanged(GetFirstVehicleInChain(v));
+ }
+
v->u.rail.track = chosen_track;
assert(v->u.rail.track);
}
diff --git a/train_gui.c b/train_gui.c
index 51565980b1..160e8fe7d5 100644
--- a/train_gui.c
+++ b/train_gui.c
@@ -177,7 +177,7 @@ static void engine_drawing_loop(int *x, int *y, int *pos, int *sel,
const Engine *e = GetEngine(i);
const RailVehicleInfo *rvi = RailVehInfo(i);
- if (!IsCompatibleRail(e->railtype, railtype) || !(rvi->flags & RVI_WAGON) != is_engine ||
+ if (!HasPowerOnRail(e->railtype, railtype) || !(rvi->flags & RVI_WAGON) != is_engine ||
!HASBIT(e->player_avail, _local_player))
continue;
@@ -208,7 +208,7 @@ static void NewRailVehicleWndProc(Window *w, WindowEvent *e)
for (i = 0; i < NUM_TRAIN_ENGINES; i++) {
const Engine *e = GetEngine(i);
- if (IsCompatibleRail(e->railtype, railtype)
+ if (HasPowerOnRail(e->railtype, railtype)
&& HASBIT(e->player_avail, _local_player))
count++;
}
diff --git a/tunnelbridge_cmd.c b/tunnelbridge_cmd.c
index b7d8466dd1..7445db1673 100644
--- a/tunnelbridge_cmd.c
+++ b/tunnelbridge_cmd.c
@@ -799,9 +799,9 @@ int32 DoConvertTunnelBridgeRail(TileIndex tile, uint totype, bool exec)
// fast routine for getting the height of a middle bridge tile. 'tile' MUST be a middle bridge tile.
-static uint GetBridgeHeight(const TileInfo *ti)
+uint GetBridgeHeight(TileIndex t)
{
- TileIndex tile = GetSouthernBridgeEnd(ti->tile);
+ TileIndex tile = GetSouthernBridgeEnd(t);
/* Return the height there (the height of the NORTH CORNER)
* If the end of the bridge is on a tileh 7 (all raised, except north corner),
@@ -930,6 +930,7 @@ static void DrawTile_TunnelBridge(TileInfo *ti)
image += GetTunnelDirection(ti->tile) * 2;
DrawGroundSprite(image);
+ if (GB(_m[ti->tile].m3, 0, 3) == RAILTYPE_ELECTRIC) DrawCatenary(ti);
AddSortableSpriteToDraw(image+1, ti->x + 15, ti->y + 15, 1, 1, 8, (byte)ti->z);
} else if (IsBridge(ti->tile)) { // XXX is this necessary?
@@ -973,6 +974,8 @@ static void DrawTile_TunnelBridge(TileInfo *ti)
DrawGroundSprite(SPR_FLAT_SNOWY_TILE + _tileh_to_sprite[ti->tileh]);
}
+ if (GB(_m[ti->tile].m3, 0, 3) == RAILTYPE_ELECTRIC) DrawCatenary(ti);
+
// draw ramp
if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image);
AddSortableSpriteToDraw(image, ti->x, ti->y, 16, 16, 7, ti->z);
@@ -1029,7 +1032,7 @@ static void DrawTile_TunnelBridge(TileInfo *ti)
// get bridge sprites
b = GetBridgeSpriteTable(GetBridgeType(ti->tile), GetBridgePiece(ti->tile)) + base_offset;
- z = GetBridgeHeight(ti) + 5;
+ z = GetBridgeHeight(ti->tile) + 5;
// draw rail or road component
image = b[0];
@@ -1054,6 +1057,8 @@ static void DrawTile_TunnelBridge(TileInfo *ti)
if (image & SPRITE_MASK) AddSortableSpriteToDraw(image, x, y, 1, 16, 0x28, z);
}
+ if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC || GetRailTypeOnBridge(ti->tile) == RAILTYPE_ELECTRIC) DrawCatenary(ti);
+
if (ti->z + 5 == z) {
// draw poles below for small bridges
image = b[2];
@@ -1107,7 +1112,7 @@ static uint GetSlopeZ_TunnelBridge(const TileInfo* ti)
if (_get_z_hint >= z + 8) return _get_z_hint;
// actually on the bridge, but not yet in the shared area.
- if (!IS_INT_INSIDE(x, 5, 10 + 1)) return GetBridgeHeight(ti) + 8;
+ if (!IS_INT_INSIDE(x, 5, 10 + 1)) return GetBridgeHeight(ti->tile) + 8;
// in the shared area, assume that we're below the bridge, cause otherwise the hint would've caught it.
// if rail or road below then it means it's possibly build on slope below the bridge.
diff --git a/variables.h b/variables.h
index c7c051ad34..b63a0cee7e 100644
--- a/variables.h
+++ b/variables.h
@@ -345,7 +345,6 @@ typedef struct {
SpriteID sprites[NUM_CARGO];
byte transit_days_1[NUM_CARGO];
byte transit_days_2[NUM_CARGO];
- byte ai_railwagon[3][NUM_CARGO];
byte ai_roadveh_start[NUM_CARGO];
byte ai_roadveh_count[NUM_CARGO];
} CargoConst;
diff --git a/vehicle.c b/vehicle.c
index 6f85588237..0183d04c77 100644
--- a/vehicle.c
+++ b/vehicle.c
@@ -218,6 +218,10 @@ void AfterLoadVehicles(void)
FOR_ALL_VEHICLES(v) {
v->first = NULL;
+ if (v->type == VEH_Train) v->u.rail.first_engine = INVALID_ENGINE;
+ }
+
+ FOR_ALL_VEHICLES(v) {
if (v->type == VEH_Train && (IsFrontEngine(v) || IsFreeWagon(v)))
TrainConsistChanged(v);
}
diff --git a/vehicle.h b/vehicle.h
index d63e6b5f51..87d279449d 100644
--- a/vehicle.h
+++ b/vehicle.h
@@ -72,6 +72,7 @@ typedef struct VehicleRail {
byte track;
byte force_proceed;
byte railtype;
+ RailTypeMask compatible_railtypes;
byte flags;
@@ -307,6 +308,7 @@ UnitID GetFreeUnitNumber(byte type);
int LoadUnloadVehicle(Vehicle *v);
void TrainConsistChanged(Vehicle *v);
+void TrainPowerChanged(Vehicle *v);
int32 GetTrainRunningCost(const Vehicle *v);
int CheckTrainStoppedInDepot(const Vehicle *v);
diff --git a/vehicle_gui.c b/vehicle_gui.c
index 25b0f65772..31b8e9bf05 100644
--- a/vehicle_gui.c
+++ b/vehicle_gui.c
@@ -76,6 +76,7 @@ const StringID _vehicle_sort_listing[] = {
static const StringID _rail_types_list[] = {
STR_RAIL_VEHICLES,
+ STR_ELRAIL_VEHICLES,
STR_MONORAIL_VEHICLES,
STR_MAGLEV_VEHICLES,
INVALID_STRING_ID
@@ -450,7 +451,7 @@ static int CDECL VehicleValueSorter(const void *a, const void *b)
* if used compined with show_cars set to false, it will work as intended. Replace window do it like that
* this was a big hack even before show_outdated was added. Stupid newgrf :p */
static void train_engine_drawing_loop(int *x, int *y, int *pos, int *sel, EngineID *selected_id, RailType railtype,
- uint8 lines_drawn, bool is_engine, bool show_cars, bool show_outdated)
+ uint8 lines_drawn, bool is_engine, bool show_cars, bool show_outdated, bool show_compatible)
{
EngineID j;
byte colour;
@@ -472,7 +473,9 @@ static void train_engine_drawing_loop(int *x, int *y, int *pos, int *sel, Engine
colour = *sel == 0 ? 0xC : 0x10;
if (!(ENGINE_AVAILABLE && show_outdated && RailVehInfo(i)->power && e->railtype == railtype)) {
- if (e->railtype != railtype || !(rvi->flags & RVI_WAGON) != is_engine ||
+ if ((!HasPowerOnRail(e->railtype, railtype) && show_compatible)
+ || (e->railtype != railtype && !show_compatible)
+ || !(rvi->flags & RVI_WAGON) != is_engine ||
!HASBIT(e->player_avail, _local_player))
continue;
} /*else {
@@ -522,16 +525,15 @@ static void SetupScrollStuffForReplaceWindow(Window *w)
const Engine* e = GetEngine(eid);
const EngineInfo* info = &_engine_info[eid];
+ // left window contains compatible engines while right window only contains engines of the selected type
if (ENGINE_AVAILABLE && (
(RailVehInfo(eid)->power != 0 && WP(w, replaceveh_d).wagon_btnstate) ||
- (RailVehInfo(eid)->power == 0 && !WP(w, replaceveh_d).wagon_btnstate)
- ) &&
- e->railtype == railtype) {
- if (_player_num_engines[eid] > 0 || EngineHasReplacementForPlayer(p, eid)) {
+ (RailVehInfo(eid)->power == 0 && !WP(w, replaceveh_d).wagon_btnstate))) {
+ if (HasPowerOnRail(e->railtype, railtype) && (_player_num_engines[eid] > 0 || EngineHasReplacementForPlayer(p, eid))) {
if (sel[0] == count) selected_id[0] = eid;
count++;
}
- if (HASBIT(e->player_avail, _local_player)) {
+ if (e->railtype == railtype && HASBIT(e->player_avail, _local_player)) {
if (sel[1] == count2) selected_id[1] = eid;
count2++;
}
@@ -647,12 +649,12 @@ static void DrawEngineArrayInReplaceWindow(Window *w, int x, int y, int x2, int
* engines to get more types.. Stays here until we have our own format
* then it is exit!!! */
if (WP(w,replaceveh_d).wagon_btnstate) {
- train_engine_drawing_loop(&x, &y, &pos, &sel[0], &selected_id[0], railtype, w->vscroll.cap, true, false, true); // True engines
- train_engine_drawing_loop(&x2, &y2, &pos2, &sel[1], &selected_id[1], railtype, w->vscroll.cap, true, false, false); // True engines
- train_engine_drawing_loop(&x2, &y2, &pos2, &sel[1], &selected_id[1], railtype, w->vscroll.cap, false, false, false); // Feeble wagons
+ train_engine_drawing_loop(&x, &y, &pos, &sel[0], &selected_id[0], railtype, w->vscroll.cap, true, false, true, true); // True engines
+ train_engine_drawing_loop(&x2, &y2, &pos2, &sel[1], &selected_id[1], railtype, w->vscroll.cap, true, false, false, false); // True engines
+ train_engine_drawing_loop(&x2, &y2, &pos2, &sel[1], &selected_id[1], railtype, w->vscroll.cap, false, false, false, false); // Feeble wagons
} else {
- train_engine_drawing_loop(&x, &y, &pos, &sel[0], &selected_id[0], railtype, w->vscroll.cap, false, true, true);
- train_engine_drawing_loop(&x2, &y2, &pos2, &sel[1], &selected_id[1], railtype, w->vscroll.cap, false, true, false);
+ train_engine_drawing_loop(&x, &y, &pos, &sel[0], &selected_id[0], railtype, w->vscroll.cap, false, true, true, true);
+ train_engine_drawing_loop(&x2, &y2, &pos2, &sel[1], &selected_id[1], railtype, w->vscroll.cap, false, true, false, true);
}
break;
}