summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2005-11-17 10:12:21 +0000
committerpeter1138 <peter1138@openttd.org>2005-11-17 10:12:21 +0000
commit3e702afc08bd8118f5b01e6493fcdea1aea4c0d4 (patch)
treecdeb753e43ef3784d9c21d6f5d98a687fac9040d
parent754d26407e8cda101f04c93a94c60bc0625f540c (diff)
downloadopenttd-3e702afc08bd8118f5b01e6493fcdea1aea4c0d4.tar.xz
(svn r3213) - Codechange: Clean up handling of road stops, avoiding unnecessary use of pointers and using the *BIT() macros.
-rw-r--r--roadveh_cmd.c14
-rw-r--r--station_cmd.c36
2 files changed, 19 insertions, 31 deletions
diff --git a/roadveh_cmd.c b/roadveh_cmd.c
index c1d4dd4b0..87b52cfa5 100644
--- a/roadveh_cmd.c
+++ b/roadveh_cmd.c
@@ -463,21 +463,13 @@ static void UpdateRoadVehDeltaXY(Vehicle *v)
static void ClearCrashedStation(Vehicle *v)
{
- TileIndex tile = v->tile;
- byte *b, bb;
-
- RoadStop *rs = GetRoadStopByTile(tile, GetRoadStopType(tile));
- b = &rs->status;
-
- bb = *b;
+ RoadStop *rs = GetRoadStopByTile(v->tile, GetRoadStopType(v->tile));
// mark station as not busy
- bb &= ~0x80;
+ CLRBIT(rs->status, 7);
// free parking bay
- bb |= (v->u.road.state&0x02)?2:1;
-
- *b = bb;
+ SETBIT(rs->status, HASBIT(v->u.road.state, 1) ? 1 : 0);
}
static void RoadVehDelete(Vehicle *v)
diff --git a/station_cmd.c b/station_cmd.c
index 4e18b1eef..66e8c2415 100644
--- a/station_cmd.c
+++ b/station_cmd.c
@@ -2284,34 +2284,30 @@ static uint32 VehicleEnter_Station(Vehicle *v, TileIndex tile, int x, int y)
}
}
} else if (v->type == VEH_Road) {
- if (v->u.road.state < 16 && (v->u.road.state&4)==0 && v->u.road.frame==0) {
- byte m5 = _m[tile].m5;
- byte *b, bb,state;
-
- if (IS_BYTE_INSIDE(m5, 0x43, 0x4B)) {
+ if (v->u.road.state < 16 && !HASBIT(v->u.road.state, 2) && v->u.road.frame == 0) {
+ if (IS_BYTE_INSIDE(_m[tile].m5, 0x43, 0x4B)) {
+ /* Attempt to allocate a parking bay in a road stop */
RoadStop *rs = GetRoadStopByTile(tile, GetRoadStopType(tile));
- b = &rs->status;
-
- bb = *b;
- /* bb bits 1..0 describe current the two parking spots.
- 0 means occupied, 1 means free. */
+ /* rs->status bits 0 and 1 describe current the two parking spots.
+ * 0 means occupied, 1 means free. */
- // Station busy?
- if (bb & 0x80 || (bb&3) == 0)
+ // Check if station is busy or if there are no free bays.
+ if (HASBIT(rs->status, 7) || GB(rs->status, 0, 2) == 0)
return 8;
- state = v->u.road.state + 32;
- if (bb & 1) {
- bb &= ~1;
+ v->u.road.state += 32;
+
+ // 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 {
- bb &= ~2;
- state += 2;
+ CLRBIT(rs->status, 1);
+ v->u.road.state += 2;
}
- bb |= 0x80;
- *b = bb;
- v->u.road.state = state;
+ // mark the station as busy
+ SETBIT(rs->status, 7);
}
}
}