mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-07-15 08:35:11 +01:00
(svn r3213) - Codechange: Clean up handling of road stops, avoiding unnecessary use of pointers and using the *BIT() macros.
This commit is contained in:
parent
754d26407e
commit
3e702afc08
@ -463,21 +463,13 @@ static void UpdateRoadVehDeltaXY(Vehicle *v)
|
|||||||
|
|
||||||
static void ClearCrashedStation(Vehicle *v)
|
static void ClearCrashedStation(Vehicle *v)
|
||||||
{
|
{
|
||||||
TileIndex tile = v->tile;
|
RoadStop *rs = GetRoadStopByTile(v->tile, GetRoadStopType(v->tile));
|
||||||
byte *b, bb;
|
|
||||||
|
|
||||||
RoadStop *rs = GetRoadStopByTile(tile, GetRoadStopType(tile));
|
|
||||||
b = &rs->status;
|
|
||||||
|
|
||||||
bb = *b;
|
|
||||||
|
|
||||||
// mark station as not busy
|
// mark station as not busy
|
||||||
bb &= ~0x80;
|
CLRBIT(rs->status, 7);
|
||||||
|
|
||||||
// free parking bay
|
// free parking bay
|
||||||
bb |= (v->u.road.state&0x02)?2:1;
|
SETBIT(rs->status, HASBIT(v->u.road.state, 1) ? 1 : 0);
|
||||||
|
|
||||||
*b = bb;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void RoadVehDelete(Vehicle *v)
|
static void RoadVehDelete(Vehicle *v)
|
||||||
|
@ -2284,34 +2284,30 @@ static uint32 VehicleEnter_Station(Vehicle *v, TileIndex tile, int x, int y)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (v->type == VEH_Road) {
|
} else if (v->type == VEH_Road) {
|
||||||
if (v->u.road.state < 16 && (v->u.road.state&4)==0 && v->u.road.frame==0) {
|
if (v->u.road.state < 16 && !HASBIT(v->u.road.state, 2) && v->u.road.frame == 0) {
|
||||||
byte m5 = _m[tile].m5;
|
if (IS_BYTE_INSIDE(_m[tile].m5, 0x43, 0x4B)) {
|
||||||
byte *b, bb,state;
|
/* Attempt to allocate a parking bay in a road stop */
|
||||||
|
|
||||||
if (IS_BYTE_INSIDE(m5, 0x43, 0x4B)) {
|
|
||||||
RoadStop *rs = GetRoadStopByTile(tile, GetRoadStopType(tile));
|
RoadStop *rs = GetRoadStopByTile(tile, GetRoadStopType(tile));
|
||||||
b = &rs->status;
|
|
||||||
|
|
||||||
bb = *b;
|
/* rs->status bits 0 and 1 describe current the two parking spots.
|
||||||
|
* 0 means occupied, 1 means free. */
|
||||||
|
|
||||||
/* bb bits 1..0 describe current the two parking spots.
|
// Check if station is busy or if there are no free bays.
|
||||||
0 means occupied, 1 means free. */
|
if (HASBIT(rs->status, 7) || GB(rs->status, 0, 2) == 0)
|
||||||
|
|
||||||
// Station busy?
|
|
||||||
if (bb & 0x80 || (bb&3) == 0)
|
|
||||||
return 8;
|
return 8;
|
||||||
|
|
||||||
state = v->u.road.state + 32;
|
v->u.road.state += 32;
|
||||||
if (bb & 1) {
|
|
||||||
bb &= ~1;
|
// if the first bay is free, allocate that, else the second bay must be free.
|
||||||
|
if (HASBIT(rs->status, 0)) {
|
||||||
|
CLRBIT(rs->status, 0);
|
||||||
} else {
|
} else {
|
||||||
bb &= ~2;
|
CLRBIT(rs->status, 1);
|
||||||
state += 2;
|
v->u.road.state += 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
bb |= 0x80;
|
// mark the station as busy
|
||||||
*b = bb;
|
SETBIT(rs->status, 7);
|
||||||
v->u.road.state = state;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user