diff options
author | peter1138 <peter1138@openttd.org> | 2007-07-30 08:49:41 +0000 |
---|---|---|
committer | peter1138 <peter1138@openttd.org> | 2007-07-30 08:49:41 +0000 |
commit | 9b9bca40b94fe7e44887004d28efc6b175005e1d (patch) | |
tree | 3a919447e032e1fc18a1e2e780c0d9f53dec26d5 | |
parent | 2800a49f0361b586573e8d3c78a1ecb13e414b18 (diff) | |
download | openttd-9b9bca40b94fe7e44887004d28efc6b175005e1d.tar.xz |
(svn r10734) -Fix [FS#1030]: Revert r10513) and add special cases for collision detection on bridges/tunnels.
-rw-r--r-- | src/rail_cmd.cpp | 9 | ||||
-rw-r--r-- | src/train_cmd.cpp | 11 | ||||
-rw-r--r-- | src/vehicle.cpp | 4 |
3 files changed, 15 insertions, 9 deletions
diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp index 4c6a01563..ac22758fa 100644 --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -1669,13 +1669,10 @@ static bool SignalVehicleCheck(TileIndex tile, uint track) /* check for a vehicle with that trackdir on the end tile of the tunnel */ if (VehicleFromPos(end, &dest, SignalVehicleCheckProc) != NULL) return true; - /* now check all tiles from start to end for a warping vehicle - * NOTE: the hashes for tiles may overlap, so this could maybe be optimised a bit by not checking every tile? */ + /* now check all tiles from start to end for a warping vehicle */ dest.track = 0x40; //Vehicle inside a tunnel or on a bridge - for (; tile != end; tile += TileOffsByDiagDir(direction)) { - if (VehicleFromPos(tile, &dest, SignalVehicleCheckProc) != NULL) - return true; - } + if (VehicleFromPos(tile, &dest, SignalVehicleCheckProc) != NULL) return true; + if (VehicleFromPos(end, &dest, SignalVehicleCheckProc) != NULL) return true; /* no vehicle found */ return false; diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 69ed022e8..047725269 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -2760,7 +2760,16 @@ static void CheckTrainCollision(Vehicle *v) tcc.num = 0; /* find colliding vehicles */ - VehicleFromPosXY(v->x_pos, v->y_pos, &tcc, FindTrainCollideEnum); + if (v->u.rail.track == TRACK_BIT_WORMHOLE) { + VehicleFromPos(v->tile, &tcc, FindTrainCollideEnum); + if (IsBridgeTile(v->tile)) { + VehicleFromPos(GetOtherBridgeEnd(v->tile), &tcc, FindTrainCollideEnum); + } else { + VehicleFromPos(GetOtherTunnelEnd(v->tile), &tcc, FindTrainCollideEnum); + } + } else { + VehicleFromPosXY(v->x_pos, v->y_pos, &tcc, FindTrainCollideEnum); + } /* any dead -> no crash */ if (tcc.num == 0) return; diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 2d2b865fa..7c3c5a4db 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -471,8 +471,8 @@ static void UpdateNewVehiclePosHash(Vehicle *v, bool remove) if (remove) { new_hash = NULL; } else { - int x = GB(v->x_pos / TILE_SIZE, HASH_RES, HASH_BITS); - int y = GB(v->y_pos / TILE_SIZE, HASH_RES, HASH_BITS) << HASH_BITS; + int x = GB(TileX(v->tile), HASH_RES, HASH_BITS); + int y = GB(TileY(v->tile), HASH_RES, HASH_BITS) << HASH_BITS; new_hash = &_new_vehicle_position_hash[(x + y) & TOTAL_HASH_MASK]; } |