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, 2); |
|
213 if (roadtypes > ROADTYPES_ALL || roadtypes == ROADTYPES_NONE) 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); |
213 } |
217 } |
214 |
218 |
350 |
354 |
351 if (railtype != INVALID_RAILTYPE) { |
355 if (railtype != INVALID_RAILTYPE) { |
352 MakeRailBridgeRamp(tile_start, owner, bridge_type, dir, railtype); |
356 MakeRailBridgeRamp(tile_start, owner, bridge_type, dir, railtype); |
353 MakeRailBridgeRamp(tile_end, owner, bridge_type, ReverseDiagDir(dir), railtype); |
357 MakeRailBridgeRamp(tile_end, owner, bridge_type, ReverseDiagDir(dir), railtype); |
354 } else { |
358 } else { |
355 MakeRoadBridgeRamp(tile_start, owner, bridge_type, dir); |
359 MakeRoadBridgeRamp(tile_start, owner, bridge_type, dir, roadtypes); |
356 MakeRoadBridgeRamp(tile_end, owner, bridge_type, ReverseDiagDir(dir)); |
360 MakeRoadBridgeRamp(tile_end, owner, bridge_type, ReverseDiagDir(dir), roadtypes); |
357 } |
361 } |
358 MarkTileDirtyByTile(tile_start); |
362 MarkTileDirtyByTile(tile_start); |
359 MarkTileDirtyByTile(tile_end); |
363 MarkTileDirtyByTile(tile_end); |
360 } |
364 } |
361 |
365 |
440 |
444 |
441 |
445 |
442 /** Build Tunnel. |
446 /** Build Tunnel. |
443 * @param start_tile start tile of tunnel |
447 * @param start_tile start tile of tunnel |
444 * @param flags type of operation |
448 * @param flags type of operation |
445 * @param p1 railtype, 0x200 for road tunnel |
449 * @param p1 railtype or roadtypes. bit 9 set means road tunnel |
446 * @param p2 unused |
450 * @param p2 unused |
447 */ |
451 */ |
448 int32 CmdBuildTunnel(TileIndex start_tile, uint32 flags, uint32 p1, uint32 p2) |
452 int32 CmdBuildTunnel(TileIndex start_tile, uint32 flags, uint32 p1, uint32 p2) |
449 { |
453 { |
450 TileIndexDiff delta; |
454 TileIndexDiff delta; |
457 int32 cost; |
461 int32 cost; |
458 int32 ret; |
462 int32 ret; |
459 |
463 |
460 _build_tunnel_endtile = 0; |
464 _build_tunnel_endtile = 0; |
461 |
465 |
462 if (p1 != 0x200 && !ValParamRailtype(p1)) return CMD_ERROR; |
466 if (HASBIT(p1, 9)) { |
|
467 if (!ValParamRailtype(p1)) return CMD_ERROR; |
|
468 } else if (GB(p1, 0, 4) > ROADTYPES_ALL || GB(p1, 0, 4) == ROADTYPES_NONE) { |
|
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, 4)); |
523 MakeRoadTunnel(end_tile, _current_player, ReverseDiagDir(direction)); |
531 MakeRoadTunnel(end_tile, _current_player, ReverseDiagDir(direction), (RoadTypes)GB(p1, 0, 4)); |
524 } |
532 } |
525 } |
533 } |
526 |
534 |
527 return cost; |
535 return cost; |
528 } |
536 } |