170 * @param end_tile end tile |
170 * @param end_tile end tile |
171 * @param flags type of operation |
171 * @param flags type of operation |
172 * @param p1 packed start tile coords (~ dx) |
172 * @param p1 packed start tile coords (~ dx) |
173 * @param p2 various bitstuffed elements |
173 * @param p2 various bitstuffed elements |
174 * - p2 = (bit 0- 7) - bridge type (hi bh) |
174 * - p2 = (bit 0- 7) - bridge type (hi bh) |
175 * - p2 = (bit 8-..) - rail type. bit15 ((x>>8)&0x80) means road bridge. |
175 * - p2 = (bit 8-..) - rail type or road types. |
|
176 * - p2 = (bit 15 ) - set means road bridge. |
176 */ |
177 */ |
177 int32 CmdBuildBridge(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2) |
178 int32 CmdBuildBridge(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2) |
178 { |
179 { |
179 uint bridge_type; |
180 uint bridge_type; |
180 RailType railtype; |
181 RailType railtype; |
|
182 RoadTypes roadtypes; |
181 uint x; |
183 uint x; |
182 uint y; |
184 uint y; |
183 uint sx; |
185 uint sx; |
184 uint sy; |
186 uint sy; |
185 TileIndex tile_start; |
187 TileIndex tile_start; |
205 if (p1 >= MapSize()) return CMD_ERROR; |
207 if (p1 >= MapSize()) return CMD_ERROR; |
206 |
208 |
207 /* type of bridge */ |
209 /* type of bridge */ |
208 if (HASBIT(p2, 15)) { |
210 if (HASBIT(p2, 15)) { |
209 railtype = INVALID_RAILTYPE; // road bridge |
211 railtype = INVALID_RAILTYPE; // road bridge |
|
212 roadtypes = (RoadTypes)GB(p2, 8, 3); |
|
213 if (!AreValidRoadTypes(roadtypes)) return CMD_ERROR; |
210 } else { |
214 } else { |
211 if (!ValParamRailtype(GB(p2, 8, 8))) return CMD_ERROR; |
215 if (!ValParamRailtype(GB(p2, 8, 8))) return CMD_ERROR; |
212 railtype = (RailType)GB(p2, 8, 8); |
216 railtype = (RailType)GB(p2, 8, 8); |
|
217 roadtypes = ROADTYPES_NONE; |
213 } |
218 } |
214 |
219 |
215 x = TileX(end_tile); |
220 x = TileX(end_tile); |
216 y = TileY(end_tile); |
221 y = TileY(end_tile); |
217 sx = TileX(p1); |
222 sx = TileX(p1); |
350 |
355 |
351 if (railtype != INVALID_RAILTYPE) { |
356 if (railtype != INVALID_RAILTYPE) { |
352 MakeRailBridgeRamp(tile_start, owner, bridge_type, dir, railtype); |
357 MakeRailBridgeRamp(tile_start, owner, bridge_type, dir, railtype); |
353 MakeRailBridgeRamp(tile_end, owner, bridge_type, ReverseDiagDir(dir), railtype); |
358 MakeRailBridgeRamp(tile_end, owner, bridge_type, ReverseDiagDir(dir), railtype); |
354 } else { |
359 } else { |
355 MakeRoadBridgeRamp(tile_start, owner, bridge_type, dir); |
360 MakeRoadBridgeRamp(tile_start, owner, bridge_type, dir, roadtypes); |
356 MakeRoadBridgeRamp(tile_end, owner, bridge_type, ReverseDiagDir(dir)); |
361 MakeRoadBridgeRamp(tile_end, owner, bridge_type, ReverseDiagDir(dir), roadtypes); |
357 } |
362 } |
358 MarkTileDirtyByTile(tile_start); |
363 MarkTileDirtyByTile(tile_start); |
359 MarkTileDirtyByTile(tile_end); |
364 MarkTileDirtyByTile(tile_end); |
360 } |
365 } |
361 |
366 |
440 |
445 |
441 |
446 |
442 /** Build Tunnel. |
447 /** Build Tunnel. |
443 * @param start_tile start tile of tunnel |
448 * @param start_tile start tile of tunnel |
444 * @param flags type of operation |
449 * @param flags type of operation |
445 * @param p1 railtype, 0x200 for road tunnel |
450 * @param p1 railtype or roadtypes. bit 9 set means road tunnel |
446 * @param p2 unused |
451 * @param p2 unused |
447 */ |
452 */ |
448 int32 CmdBuildTunnel(TileIndex start_tile, uint32 flags, uint32 p1, uint32 p2) |
453 int32 CmdBuildTunnel(TileIndex start_tile, uint32 flags, uint32 p1, uint32 p2) |
449 { |
454 { |
450 TileIndexDiff delta; |
455 TileIndexDiff delta; |
456 uint end_z; |
461 uint end_z; |
457 int32 cost; |
462 int32 cost; |
458 int32 ret; |
463 int32 ret; |
459 |
464 |
460 _build_tunnel_endtile = 0; |
465 _build_tunnel_endtile = 0; |
461 |
466 if (!HASBIT(p1, 9)) { |
462 if (p1 != 0x200 && !ValParamRailtype(p1)) return CMD_ERROR; |
467 if (!ValParamRailtype(p1)) return CMD_ERROR; |
|
468 } else if (!AreValidRoadTypes((RoadTypes)GB(p1, 0, 3))) { |
|
469 return CMD_ERROR; |
|
470 } |
463 |
471 |
464 start_tileh = GetTileSlope(start_tile, &start_z); |
472 start_tileh = GetTileSlope(start_tile, &start_z); |
465 |
473 |
466 switch (start_tileh) { |
474 switch (start_tileh) { |
467 case SLOPE_SW: direction = DIAGDIR_SW; break; |
475 case SLOPE_SW: direction = DIAGDIR_SW; break; |
517 MakeRailTunnel(start_tile, _current_player, direction, (RailType)GB(p1, 0, 4)); |
525 MakeRailTunnel(start_tile, _current_player, direction, (RailType)GB(p1, 0, 4)); |
518 MakeRailTunnel(end_tile, _current_player, ReverseDiagDir(direction), (RailType)GB(p1, 0, 4)); |
526 MakeRailTunnel(end_tile, _current_player, ReverseDiagDir(direction), (RailType)GB(p1, 0, 4)); |
519 UpdateSignalsOnSegment(start_tile, direction); |
527 UpdateSignalsOnSegment(start_tile, direction); |
520 YapfNotifyTrackLayoutChange(start_tile, AxisToTrack(DiagDirToAxis(direction))); |
528 YapfNotifyTrackLayoutChange(start_tile, AxisToTrack(DiagDirToAxis(direction))); |
521 } else { |
529 } else { |
522 MakeRoadTunnel(start_tile, _current_player, direction); |
530 MakeRoadTunnel(start_tile, _current_player, direction, (RoadTypes)GB(p1, 0, 3)); |
523 MakeRoadTunnel(end_tile, _current_player, ReverseDiagDir(direction)); |
531 MakeRoadTunnel(end_tile, _current_player, ReverseDiagDir(direction), (RoadTypes)GB(p1, 0, 3)); |
524 } |
532 } |
525 } |
533 } |
526 |
534 |
527 return cost; |
535 return cost; |
528 } |
536 } |
637 SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
645 SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
638 |
646 |
639 if (!CheckAllowRemoveTunnelBridge(tile)) return CMD_ERROR; |
647 if (!CheckAllowRemoveTunnelBridge(tile)) return CMD_ERROR; |
640 |
648 |
641 endtile = GetOtherBridgeEnd(tile); |
649 endtile = GetOtherBridgeEnd(tile); |
642 |
650 byte bridge_height = GetBridgeHeight(tile); |
643 if (!EnsureNoVehicleOnGround(tile) || |
651 |
644 !EnsureNoVehicleOnGround(endtile) || |
652 if (FindVehicleOnTileZ(tile, bridge_height) != NULL || |
645 IsVehicleOnBridge(tile, endtile, GetBridgeHeight(tile))) { |
653 FindVehicleOnTileZ(endtile, bridge_height) != NULL || |
|
654 IsVehicleOnBridge(tile, endtile, bridge_height)) { |
646 return CMD_ERROR; |
655 return CMD_ERROR; |
647 } |
656 } |
648 |
657 |
649 direction = GetBridgeRampDirection(tile); |
658 direction = GetBridgeRampDirection(tile); |
650 delta = TileOffsByDiagDir(direction); |
659 delta = TileOffsByDiagDir(direction); |
741 } else if (IsBridge(tile) && GetBridgeTransportType(tile) == TRANSPORT_RAIL) { |
750 } else if (IsBridge(tile) && GetBridgeTransportType(tile) == TRANSPORT_RAIL) { |
742 |
751 |
743 if (!CheckTileOwnership(tile)) return CMD_ERROR; |
752 if (!CheckTileOwnership(tile)) return CMD_ERROR; |
744 |
753 |
745 endtile = GetOtherBridgeEnd(tile); |
754 endtile = GetOtherBridgeEnd(tile); |
746 |
755 byte bridge_height = GetBridgeHeight(tile); |
747 if (!EnsureNoVehicleOnGround(tile) || |
756 |
748 !EnsureNoVehicleOnGround(endtile) || |
757 if (FindVehicleOnTileZ(tile, bridge_height) != NULL || |
749 IsVehicleOnBridge(tile, endtile, GetBridgeHeight(tile))) { |
758 FindVehicleOnTileZ(endtile, bridge_height) != NULL || |
|
759 IsVehicleOnBridge(tile, endtile, bridge_height)) { |
750 return CMD_ERROR; |
760 return CMD_ERROR; |
751 } |
761 } |
752 |
762 |
753 if (GetRailType(tile) == totype) return CMD_ERROR; |
763 if (GetRailType(tile) == totype) return CMD_ERROR; |
754 |
764 |
875 |
885 |
876 if (HasTunnelSnowOrDesert(ti->tile)) image += 32; |
886 if (HasTunnelSnowOrDesert(ti->tile)) image += 32; |
877 |
887 |
878 image += GetTunnelDirection(ti->tile) * 2; |
888 image += GetTunnelDirection(ti->tile) * 2; |
879 DrawGroundSprite(image, PAL_NONE); |
889 DrawGroundSprite(image, PAL_NONE); |
880 if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC) DrawCatenary(ti); |
890 if (GetTunnelTransportType(ti->tile) == TRANSPORT_RAIL && GetRailType(ti->tile) == RAILTYPE_ELECTRIC) { |
881 |
891 DrawCatenary(ti); |
882 AddSortableSpriteToDraw(image+1, PAL_NONE, ti->x + TILE_SIZE - 1, ti->y + TILE_SIZE - 1, 1, 1, 8, (byte)ti->z); |
892 } |
|
893 |
|
894 AddSortableSpriteToDraw(image + 1, PAL_NONE, ti->x + TILE_SIZE - 1, ti->y + TILE_SIZE - 1, 1, 1, 8, (byte)ti->z); |
883 DrawBridgeMiddle(ti); |
895 DrawBridgeMiddle(ti); |
884 } else if (IsBridge(ti->tile)) { // XXX is this necessary? |
896 } else if (IsBridge(ti->tile)) { // XXX is this necessary? |
885 const PalSpriteID *psid; |
897 const PalSpriteID *psid; |
886 int base_offset; |
898 int base_offset; |
887 bool ice = HasBridgeSnowOrDesert(ti->tile); |
899 bool ice = HasBridgeSnowOrDesert(ti->tile); |
913 DrawClearLandTile(ti, 3); |
925 DrawClearLandTile(ti, 3); |
914 } else { |
926 } else { |
915 DrawGroundSprite(SPR_FLAT_SNOWY_TILE + _tileh_to_sprite[ti->tileh], PAL_NONE); |
927 DrawGroundSprite(SPR_FLAT_SNOWY_TILE + _tileh_to_sprite[ti->tileh], PAL_NONE); |
916 } |
928 } |
917 |
929 |
918 if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC) DrawCatenary(ti); |
930 if (GetBridgeTransportType(ti->tile) == TRANSPORT_RAIL && GetRailType(ti->tile) == RAILTYPE_ELECTRIC) { |
|
931 DrawCatenary(ti); |
|
932 } |
919 |
933 |
920 image = psid->sprite; |
934 image = psid->sprite; |
921 |
935 |
922 /* draw ramp */ |
936 /* draw ramp */ |
923 if (HASBIT(_transparent_opt, TO_BRIDGES)) { |
937 if (HASBIT(_transparent_opt, TO_BRIDGES)) { |