1260 |
1260 |
1261 static uint32 VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y) |
1261 static uint32 VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y) |
1262 { |
1262 { |
1263 int z = GetSlopeZ(x, y) - v->z_pos; |
1263 int z = GetSlopeZ(x, y) - v->z_pos; |
1264 |
1264 |
1265 if (myabs(z) > 2) return 8; |
1265 if (myabs(z) > 2) return VETSB_CANNOT_ENTER; |
1266 |
1266 |
1267 if (IsTunnel(tile)) { |
1267 if (IsTunnel(tile)) { |
1268 byte fc; |
1268 byte fc; |
1269 DiagDirection dir; |
1269 DiagDirection dir; |
1270 DiagDirection vdir; |
1270 DiagDirection vdir; |
1278 if (v->u.rail.track != 0x40 && dir == vdir) { |
1278 if (v->u.rail.track != 0x40 && dir == vdir) { |
1279 if (IsFrontEngine(v) && fc == _tunnel_fractcoord_1[dir]) { |
1279 if (IsFrontEngine(v) && fc == _tunnel_fractcoord_1[dir]) { |
1280 if (!PlayVehicleSound(v, VSE_TUNNEL) && v->spritenum < 4) { |
1280 if (!PlayVehicleSound(v, VSE_TUNNEL) && v->spritenum < 4) { |
1281 SndPlayVehicleFx(SND_05_TRAIN_THROUGH_TUNNEL, v); |
1281 SndPlayVehicleFx(SND_05_TRAIN_THROUGH_TUNNEL, v); |
1282 } |
1282 } |
1283 return 0; |
1283 return VETSB_CONTINUE; |
1284 } |
1284 } |
1285 if (fc == _tunnel_fractcoord_2[dir]) { |
1285 if (fc == _tunnel_fractcoord_2[dir]) { |
1286 v->tile = tile; |
1286 v->tile = tile; |
1287 v->u.rail.track = TRACK_BIT_WORMHOLE; |
1287 v->u.rail.track = TRACK_BIT_WORMHOLE; |
1288 v->vehstatus |= VS_HIDDEN; |
1288 v->vehstatus |= VS_HIDDEN; |
1289 return 4; |
1289 return VETSB_ENTERED_WORMHOLE; |
1290 } |
1290 } |
1291 } |
1291 } |
1292 |
1292 |
1293 if (dir == ReverseDiagDir(vdir) && fc == _tunnel_fractcoord_3[dir] && z == 0) { |
1293 if (dir == ReverseDiagDir(vdir) && fc == _tunnel_fractcoord_3[dir] && z == 0) { |
1294 /* We're at the tunnel exit ?? */ |
1294 /* We're at the tunnel exit ?? */ |
1295 v->tile = tile; |
1295 v->tile = tile; |
1296 v->u.rail.track = (TrackBits)_exit_tunnel_track[dir]; |
1296 v->u.rail.track = (TrackBits)_exit_tunnel_track[dir]; |
1297 assert(v->u.rail.track); |
1297 assert(v->u.rail.track); |
1298 v->vehstatus &= ~VS_HIDDEN; |
1298 v->vehstatus &= ~VS_HIDDEN; |
1299 return 4; |
1299 return VETSB_ENTERED_WORMHOLE; |
1300 } |
1300 } |
1301 } else if (v->type == VEH_Road) { |
1301 } else if (v->type == VEH_Road) { |
1302 fc = (x & 0xF) + (y << 4); |
1302 fc = (x & 0xF) + (y << 4); |
1303 dir = GetTunnelDirection(tile); |
1303 dir = GetTunnelDirection(tile); |
1304 vdir = DirToDiagDir(v->direction); |
1304 vdir = DirToDiagDir(v->direction); |
1308 if (fc == _tunnel_fractcoord_4[dir] || |
1308 if (fc == _tunnel_fractcoord_4[dir] || |
1309 fc == _tunnel_fractcoord_5[dir]) { |
1309 fc == _tunnel_fractcoord_5[dir]) { |
1310 v->tile = tile; |
1310 v->tile = tile; |
1311 v->u.road.state = 0xFF; |
1311 v->u.road.state = 0xFF; |
1312 v->vehstatus |= VS_HIDDEN; |
1312 v->vehstatus |= VS_HIDDEN; |
1313 return 4; |
1313 return VETSB_ENTERED_WORMHOLE; |
1314 } else { |
1314 } else { |
1315 return 0; |
1315 return VETSB_CONTINUE; |
1316 } |
1316 } |
1317 } |
1317 } |
1318 |
1318 |
1319 if (dir == ReverseDiagDir(vdir) && ( |
1319 if (dir == ReverseDiagDir(vdir) && ( |
1320 /* We're at the tunnel exit ?? */ |
1320 /* We're at the tunnel exit ?? */ |
1342 |
1342 |
1343 dir = GetBridgeRampDirection(tile); |
1343 dir = GetBridgeRampDirection(tile); |
1344 if (DirToDiagDir(v->direction) == dir) { |
1344 if (DirToDiagDir(v->direction) == dir) { |
1345 switch (dir) { |
1345 switch (dir) { |
1346 default: NOT_REACHED(); |
1346 default: NOT_REACHED(); |
1347 case DIAGDIR_NE: if ((x & 0xF) != 0) return 0; break; |
1347 case DIAGDIR_NE: if ((x & 0xF) != 0) return VETSB_CONTINUE; break; |
1348 case DIAGDIR_SE: if ((y & 0xF) != TILE_SIZE - 1) return 0; break; |
1348 case DIAGDIR_SE: if ((y & 0xF) != TILE_SIZE - 1) return VETSB_CONTINUE; break; |
1349 case DIAGDIR_SW: if ((x & 0xF) != TILE_SIZE - 1) return 0; break; |
1349 case DIAGDIR_SW: if ((x & 0xF) != TILE_SIZE - 1) return VETSB_CONTINUE; break; |
1350 case DIAGDIR_NW: if ((y & 0xF) != 0) return 0; break; |
1350 case DIAGDIR_NW: if ((y & 0xF) != 0) return VETSB_CONTINUE; break; |
1351 } |
1351 } |
1352 if (v->type == VEH_Train) { |
1352 if (v->type == VEH_Train) { |
1353 v->u.rail.track = TRACK_BIT_WORMHOLE; |
1353 v->u.rail.track = TRACK_BIT_WORMHOLE; |
1354 CLRBIT(v->u.rail.flags, VRF_GOINGUP); |
1354 CLRBIT(v->u.rail.flags, VRF_GOINGUP); |
1355 CLRBIT(v->u.rail.flags, VRF_GOINGDOWN); |
1355 CLRBIT(v->u.rail.flags, VRF_GOINGDOWN); |
1356 } else { |
1356 } else { |
1357 v->u.road.state = 0xFF; |
1357 v->u.road.state = 0xFF; |
1358 } |
1358 } |
1359 return 4; |
1359 return VETSB_ENTERED_WORMHOLE; |
1360 } else if (DirToDiagDir(v->direction) == ReverseDiagDir(dir)) { |
1360 } else if (DirToDiagDir(v->direction) == ReverseDiagDir(dir)) { |
1361 v->tile = tile; |
1361 v->tile = tile; |
1362 if (v->type == VEH_Train) { |
1362 if (v->type == VEH_Train) { |
1363 if (v->u.rail.track == 0x40) { |
1363 if (v->u.rail.track == 0x40) { |
1364 v->u.rail.track = (DiagDirToAxis(dir) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y); |
1364 v->u.rail.track = (DiagDirToAxis(dir) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y); |
1365 return 4; |
1365 return VETSB_ENTERED_WORMHOLE; |
1366 } |
1366 } |
1367 } else { |
1367 } else { |
1368 if (v->u.road.state == 0xFF) { |
1368 if (v->u.road.state == 0xFF) { |
1369 v->u.road.state = _road_exit_tunnel_state[dir]; |
1369 v->u.road.state = _road_exit_tunnel_state[dir]; |
1370 v->u.road.frame = 0; |
1370 v->u.road.frame = 0; |
1371 return 4; |
1371 return VETSB_ENTERED_WORMHOLE; |
1372 } |
1372 } |
1373 } |
1373 } |
1374 return 0; |
1374 return VETSB_CONTINUE; |
1375 } |
1375 } |
1376 } |
1376 } |
1377 return 0; |
1377 return VETSB_CONTINUE; |
1378 } |
1378 } |
1379 |
1379 |
1380 extern const TileTypeProcs _tile_type_tunnelbridge_procs = { |
1380 extern const TileTypeProcs _tile_type_tunnelbridge_procs = { |
1381 DrawTile_TunnelBridge, /* draw_tile_proc */ |
1381 DrawTile_TunnelBridge, /* draw_tile_proc */ |
1382 GetSlopeZ_TunnelBridge, /* get_slope_z_proc */ |
1382 GetSlopeZ_TunnelBridge, /* get_slope_z_proc */ |