1
0
Fork 0

(svn r1198) -Fix: [ 1087701 ] It is no longer possible to crash trains of other

companies by building a depot close to a station. (even more: trains do 
no longer enter tiles that do not belong to his owner)
release/0.4.5
truelight 2004-12-21 16:00:14 +00:00
parent c136432978
commit 24853eb42c
1 changed files with 23 additions and 8 deletions

View File

@ -18,6 +18,7 @@
? is_custom_firsthead_sprite(spritenum) \ ? is_custom_firsthead_sprite(spritenum) \
: _engine_sprite_add[spritenum] == 0) : _engine_sprite_add[spritenum] == 0)
static bool TrainCheckIfLineEnds(Vehicle *v);
static const byte _vehicle_initial_x_fract[4] = {10,8,4,8}; static const byte _vehicle_initial_x_fract[4] = {10,8,4,8};
static const byte _vehicle_initial_y_fract[4] = {8,4,8,10}; static const byte _vehicle_initial_y_fract[4] = {8,4,8,10};
@ -1274,7 +1275,7 @@ static bool CheckTrainStayInDepot(Vehicle *v)
Vehicle *u; Vehicle *u;
// bail out if not all wagons are in the same depot or not in a depot at all // bail out if not all wagons are in the same depot or not in a depot at all
for (u = v; u != NULL; u = u->next) for (u = v; u != NULL; u = u->next)
if (u->u.rail.track != 0x80 || u->tile != v->tile) if (u->u.rail.track != 0x80 || u->tile != v->tile)
return false; return false;
@ -2067,6 +2068,10 @@ static void TrainController(Vehicle *v)
gp.y = v->y_pos; gp.y = v->y_pos;
} else { } else {
/* is not inside depot */ /* is not inside depot */
if (!TrainCheckIfLineEnds(v))
return;
r = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y); r = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y);
if (r & 0x8) if (r & 0x8)
goto invalid_rail; goto invalid_rail;
@ -2363,7 +2368,7 @@ static const byte _breakdown_speeds[16] = {
225, 210, 195, 180, 165, 150, 135, 120, 105, 90, 75, 60, 45, 30, 15, 15 225, 210, 195, 180, 165, 150, 135, 120, 105, 90, 75, 60, 45, 30, 15, 15
}; };
static void TrainCheckIfLineEnds(Vehicle *v) static bool TrainCheckIfLineEnds(Vehicle *v)
{ {
uint tile; uint tile;
uint x,y; uint x,y;
@ -2382,18 +2387,20 @@ static void TrainCheckIfLineEnds(Vehicle *v)
// exit if inside a tunnel // exit if inside a tunnel
if (v->u.rail.track & 0x40) if (v->u.rail.track & 0x40)
return; return true;
tile = v->tile; tile = v->tile;
// tunnel entrance? // tunnel entrance?
if (IS_TILETYPE(tile, MP_TUNNELBRIDGE) && if (IS_TILETYPE(tile, MP_TUNNELBRIDGE) &&
(_map5[tile] & 0xF0) == 0 && (byte)((_map5[tile] & 3)*2+1) == v->direction) (_map5[tile] & 0xF0) == 0 && (byte)((_map5[tile] & 3)*2+1) == v->direction)
return; return true;
// depot? // depot?
if (IS_TILETYPE(tile, MP_RAILWAY) && (_map5[tile] & 0xFC) == 0xC0) /* XXX -- When enabled, this makes it possible to crash trains of others
return; (by building a depot right against a station) */
/* if (IS_TILETYPE(tile, MP_RAILWAY) && (_map5[tile] & 0xFC) == 0xC0)
return true;*/
/* Determine the non-diagonal direction in which we will exit this tile */ /* Determine the non-diagonal direction in which we will exit this tile */
t = v->direction >> 1; t = v->direction >> 1;
@ -2434,6 +2441,12 @@ static void TrainCheckIfLineEnds(Vehicle *v)
} }
if ( (uint16)ts != 0) { if ( (uint16)ts != 0) {
/* If we approach a rail-piece which we can't enter, don't enter it! */
if (x + 4 > 15 && !CheckCompatibleRail(v, tile)) {
v->cur_speed = 0;
ReverseTrainDirection(v);
return false;
}
if ((ts &= (ts >> 16)) == 0) { if ((ts &= (ts >> 16)) == 0) {
// make a rail/road crossing red // make a rail/road crossing red
if (IS_TILETYPE(tile, MP_STREET) && (_map5[tile] & 0xF0)==0x10) { if (IS_TILETYPE(tile, MP_STREET) && (_map5[tile] & 0xF0)==0x10) {
@ -2443,12 +2456,12 @@ static void TrainCheckIfLineEnds(Vehicle *v)
MarkTileDirtyByTile(tile); MarkTileDirtyByTile(tile);
} }
} }
return; return true;
} }
} else if (x + 4 > 15) { } else if (x + 4 > 15) {
v->cur_speed = 0; v->cur_speed = 0;
ReverseTrainDirection(v); ReverseTrainDirection(v);
return; return false;
} }
// slow down // slow down
@ -2457,6 +2470,8 @@ static void TrainCheckIfLineEnds(Vehicle *v)
if (!(v->direction&1)) t>>=1; if (!(v->direction&1)) t>>=1;
if ((uint16)t < v->cur_speed) if ((uint16)t < v->cur_speed)
v->cur_speed = t; v->cur_speed = t;
return true;
} }
static void TrainLocoHandler(Vehicle *v, bool mode) static void TrainLocoHandler(Vehicle *v, bool mode)