Mercurial > hg > openttd
changeset 2823:df4532dcfccd draft
(svn r3371) -Fix: don't allow road-vehicles to perform an out-of-bound operation while overtaking in a curve (tnx to guru3, Tron and peter1138)
-Codechange: while at that, removed a local variable (more pretty :))
author | truelight <truelight@openttd.org> |
---|---|
date | Fri, 06 Jan 2006 17:25:39 +0000 |
parents | 66d51cdabe48 |
children | af06f6ef243b |
files | roadveh_cmd.c |
diffstat | 1 files changed, 11 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/roadveh_cmd.c +++ b/roadveh_cmd.c @@ -1243,7 +1243,14 @@ if (v->u.road.overtaking != 0) { if (++v->u.road.overtaking_ctr >= 35) - v->u.road.overtaking = 0; + /* If overtaking just aborts at a random moment, we can have a out-of-bound problem, + * if the vehicle started a corner. To protect that, only allow an abort of + * overtake if we are on straight road, which are the 8 states below */ + if (v->u.road.state == 0 || v->u.road.state == 1 || + v->u.road.state == 8 || v->u.road.state == 9 || + v->u.road.state == 16 || v->u.road.state == 17 || + v->u.road.state == 24 || v->u.road.state == 25) + v->u.road.overtaking = 0; } BeginVehicleMove(v); @@ -1279,7 +1286,6 @@ if (rd.x & 0x80) { TileIndex tile = v->tile + TileOffsByDir(rd.x & 3); int dir = RoadFindPathToDest(v, tile, rd.x&3); - int tmp; uint32 r; byte newdir; const RoadDriveEntry *rdp; @@ -1295,10 +1301,7 @@ tile = v->tile; } - tmp = (dir+(_opt.road_side<<4))^v->u.road.overtaking; - rdp = _road_drive_data[tmp]; - - tmp &= ~0x10; + rdp = _road_drive_data[(dir + (_opt.road_side << 4)) ^ v->u.road.overtaking]; x = TileX(tile) * 16 + rdp[0].x; y = TileY(tile) * 16 + rdp[0].y; @@ -1317,7 +1320,7 @@ } if (IS_BYTE_INSIDE(v->u.road.state, 0x20, 0x30) && IsTileType(v->tile, MP_STATION)) { - if ((tmp&7) >= 6) { v->cur_speed = 0; return; } + if ((dir & 7) >= 6) { v->cur_speed = 0; return; } if (IS_BYTE_INSIDE(_m[v->tile].m5, 0x43, 0x4B)) { RoadStop *rs = GetRoadStopByTile(v->tile, GetRoadStopType(v->tile)); byte *b = &rs->status; @@ -1330,7 +1333,7 @@ if (!(r & 4)) { v->tile = tile; - v->u.road.state = (byte)tmp; + v->u.road.state = (byte)dir; v->u.road.frame = 0; } if (newdir != v->direction) {