branch | NewGRF_ports |
changeset 6877 | 889301acc299 |
parent 6872 | 1c4a4a609f85 |
child 6878 | 7d1ff2f621c7 |
6876:2c40faeef7a5 | 6877:889301acc299 |
---|---|
62 #include "rail_gui.h" |
62 #include "rail_gui.h" |
63 #include "transparency.h" |
63 #include "transparency.h" |
64 #include "tunnelbridge_map.h" |
64 #include "tunnelbridge_map.h" |
65 #include "vehicle_func.h" |
65 #include "vehicle_func.h" |
66 #include "player_base.h" |
66 #include "player_base.h" |
67 #include "tunnelbridge.h" |
|
67 |
68 |
68 #include "table/sprites.h" |
69 #include "table/sprites.h" |
69 #include "table/elrail_data.h" |
70 #include "table/elrail_data.h" |
70 |
71 |
71 static inline TLG GetTLG(TileIndex t) |
72 static inline TLG GetTLG(TileIndex t) |
72 { |
73 { |
73 return (TLG)((HasBit(TileX(t), 0) << 1) + HasBit(TileY(t), 0)); |
74 return (TLG)((HasBit(TileX(t), 0) << 1) + HasBit(TileY(t), 0)); |
74 } |
75 } |
75 |
76 |
76 /** Finds which Rail Bits are present on a given tile. For bridge tiles, |
77 /** |
77 * returns track bits under the bridge |
78 * Finds which Electrified Rail Bits are present on a given tile. |
79 * @param t tile to check |
|
80 * @param override pointer to PCP override, can be NULL |
|
81 * @return trackbits of tile if it is electrified |
|
78 */ |
82 */ |
79 static TrackBits GetRailTrackBitsUniversal(TileIndex t, byte *override) |
83 static TrackBits GetRailTrackBitsUniversal(TileIndex t, byte *override) |
80 { |
84 { |
81 switch (GetTileType(t)) { |
85 switch (GetTileType(t)) { |
82 case MP_RAILWAY: |
86 case MP_RAILWAY: |
91 } |
95 } |
92 break; |
96 break; |
93 |
97 |
94 case MP_TUNNELBRIDGE: |
98 case MP_TUNNELBRIDGE: |
95 if (GetRailType(t) != RAILTYPE_ELECTRIC) return TRACK_BIT_NONE; |
99 if (GetRailType(t) != RAILTYPE_ELECTRIC) return TRACK_BIT_NONE; |
96 if (override != NULL && (IsTunnel(t) || DistanceMax(t, GetOtherBridgeEnd(t)) > 1)) { |
100 if (override != NULL && (IsTunnel(t) || GetTunnelBridgeLength(t, GetOtherBridgeEnd(t)) > 0)) { |
97 *override = 1 << GetTunnelBridgeDirection(t); |
101 *override = 1 << GetTunnelBridgeDirection(t); |
98 } |
102 } |
99 return AxisToTrackBits(DiagDirToAxis(GetTunnelBridgeDirection(t))); |
103 return AxisToTrackBits(DiagDirToAxis(GetTunnelBridgeDirection(t))); |
100 |
104 |
101 case MP_ROAD: |
105 case MP_ROAD: |
124 if (IsTunnel(tile)) { |
128 if (IsTunnel(tile)) { |
125 *tileh = SLOPE_STEEP; // XXX - Hack to make tunnel entrances to always have a pylon |
129 *tileh = SLOPE_STEEP; // XXX - Hack to make tunnel entrances to always have a pylon |
126 } else if (*tileh != SLOPE_FLAT) { |
130 } else if (*tileh != SLOPE_FLAT) { |
127 *tileh = SLOPE_FLAT; |
131 *tileh = SLOPE_FLAT; |
128 } else { |
132 } else { |
129 switch (GetTunnelBridgeDirection(tile)) { |
133 *tileh = InclinedSlope(GetTunnelBridgeDirection(tile)); |
130 case DIAGDIR_NE: *tileh = SLOPE_NE; break; |
|
131 case DIAGDIR_SE: *tileh = SLOPE_SE; break; |
|
132 case DIAGDIR_SW: *tileh = SLOPE_SW; break; |
|
133 case DIAGDIR_NW: *tileh = SLOPE_NW; break; |
|
134 default: NOT_REACHED(); |
|
135 } |
|
136 } |
134 } |
137 } |
135 } |
138 } |
136 } |
139 |
137 |
140 /** |
138 /** |
381 static void DrawCatenaryOnBridge(const TileInfo *ti) |
379 static void DrawCatenaryOnBridge(const TileInfo *ti) |
382 { |
380 { |
383 TileIndex end = GetSouthernBridgeEnd(ti->tile); |
381 TileIndex end = GetSouthernBridgeEnd(ti->tile); |
384 TileIndex start = GetOtherBridgeEnd(end); |
382 TileIndex start = GetOtherBridgeEnd(end); |
385 |
383 |
386 uint length = GetBridgeLength(start, end); |
384 uint length = GetTunnelBridgeLength(start, end); |
387 uint num = DistanceMax(ti->tile, start); |
385 uint num = GetTunnelBridgeLength(ti->tile, start) + 1; |
388 uint height; |
386 uint height; |
389 |
387 |
390 const SortableSpriteStruct *sss; |
388 const SortableSpriteStruct *sss; |
391 Axis axis = GetBridgeAxis(ti->tile); |
389 Axis axis = GetBridgeAxis(ti->tile); |
392 TLG tlg = GetTLG(ti->tile); |
390 TLG tlg = GetTLG(ti->tile); |
419 uint y = ti->y + y_pcp_offsets[PCPpos] + y_ppp_offsets[PPPpos]; |
417 uint y = ti->y + y_pcp_offsets[PCPpos] + y_ppp_offsets[PPPpos]; |
420 AddSortableSpriteToDraw(pylon_sprites[PPPpos], PAL_NONE, x, y, 1, 1, BB_HEIGHT_UNDER_BRIDGE, height, IsTransparencySet(TO_BUILDINGS), -1, -1); |
418 AddSortableSpriteToDraw(pylon_sprites[PPPpos], PAL_NONE, x, y, 1, 1, BB_HEIGHT_UNDER_BRIDGE, height, IsTransparencySet(TO_BUILDINGS), -1, -1); |
421 } |
419 } |
422 |
420 |
423 /* need a pylon on the southern end of the bridge */ |
421 /* need a pylon on the southern end of the bridge */ |
424 if (DistanceMax(ti->tile, start) == length) { |
422 if (GetTunnelBridgeLength(ti->tile, start) + 1 == length) { |
425 DiagDirection PCPpos = (axis == AXIS_X ? DIAGDIR_SW : DIAGDIR_SE); |
423 DiagDirection PCPpos = (axis == AXIS_X ? DIAGDIR_SW : DIAGDIR_SE); |
426 Direction PPPpos = (axis == AXIS_X ? DIR_NW : DIR_NE); |
424 Direction PPPpos = (axis == AXIS_X ? DIR_NW : DIR_NE); |
427 if (HasBit(tlg, (axis == AXIS_X ? 0 : 1))) PPPpos = ReverseDir(PPPpos); |
425 if (HasBit(tlg, (axis == AXIS_X ? 0 : 1))) PPPpos = ReverseDir(PPPpos); |
428 uint x = ti->x + x_pcp_offsets[PCPpos] + x_ppp_offsets[PPPpos]; |
426 uint x = ti->x + x_pcp_offsets[PCPpos] + x_ppp_offsets[PPPpos]; |
429 uint y = ti->y + y_pcp_offsets[PCPpos] + y_ppp_offsets[PPPpos]; |
427 uint y = ti->y + y_pcp_offsets[PCPpos] + y_ppp_offsets[PPPpos]; |
469 DrawCatenaryRailway(ti); |
467 DrawCatenaryRailway(ti); |
470 } |
468 } |
471 |
469 |
472 int32 SettingsDisableElrail(int32 p1) |
470 int32 SettingsDisableElrail(int32 p1) |
473 { |
471 { |
474 EngineID e_id; |
|
475 Vehicle *v; |
472 Vehicle *v; |
476 Player *p; |
473 Player *p; |
477 bool disable = (p1 != 0); |
474 bool disable = (p1 != 0); |
478 |
475 |
479 /* we will now walk through all electric train engines and change their railtypes if it is the wrong one*/ |
476 /* we will now walk through all electric train engines and change their railtypes if it is the wrong one*/ |
480 const RailType old_railtype = disable ? RAILTYPE_ELECTRIC : RAILTYPE_RAIL; |
477 const RailType old_railtype = disable ? RAILTYPE_ELECTRIC : RAILTYPE_RAIL; |
481 const RailType new_railtype = disable ? RAILTYPE_RAIL : RAILTYPE_ELECTRIC; |
478 const RailType new_railtype = disable ? RAILTYPE_RAIL : RAILTYPE_ELECTRIC; |
482 |
479 |
483 /* walk through all train engines */ |
480 /* walk through all train engines */ |
484 for (e_id = 0; e_id < NUM_TRAIN_ENGINES; e_id++) { |
481 EngineID eid; |
485 RailVehicleInfo *rv_info = &_rail_vehicle_info[e_id]; |
482 FOR_ALL_ENGINEIDS_OF_TYPE(eid, VEH_TRAIN) { |
483 RailVehicleInfo *rv_info = &_rail_vehicle_info[eid]; |
|
486 /* if it is an electric rail engine and its railtype is the wrong one */ |
484 /* if it is an electric rail engine and its railtype is the wrong one */ |
487 if (rv_info->engclass == 2 && rv_info->railtype == old_railtype) { |
485 if (rv_info->engclass == 2 && rv_info->railtype == old_railtype) { |
488 /* change it to the proper one */ |
486 /* change it to the proper one */ |
489 rv_info->railtype = new_railtype; |
487 rv_info->railtype = new_railtype; |
490 } |
488 } |