2282 } |
2282 } |
2283 } |
2283 } |
2284 } |
2284 } |
2285 } |
2285 } |
2286 } else if (v->type == VEH_Road) { |
2286 } else if (v->type == VEH_Road) { |
2287 if (v->u.road.state < 16 && (v->u.road.state&4)==0 && v->u.road.frame==0) { |
2287 if (v->u.road.state < 16 && !HASBIT(v->u.road.state, 2) && v->u.road.frame == 0) { |
2288 byte m5 = _m[tile].m5; |
2288 if (IS_BYTE_INSIDE(_m[tile].m5, 0x43, 0x4B)) { |
2289 byte *b, bb,state; |
2289 /* Attempt to allocate a parking bay in a road stop */ |
2290 |
|
2291 if (IS_BYTE_INSIDE(m5, 0x43, 0x4B)) { |
|
2292 RoadStop *rs = GetRoadStopByTile(tile, GetRoadStopType(tile)); |
2290 RoadStop *rs = GetRoadStopByTile(tile, GetRoadStopType(tile)); |
2293 b = &rs->status; |
2291 |
2294 |
2292 /* rs->status bits 0 and 1 describe current the two parking spots. |
2295 bb = *b; |
2293 * 0 means occupied, 1 means free. */ |
2296 |
2294 |
2297 /* bb bits 1..0 describe current the two parking spots. |
2295 // Check if station is busy or if there are no free bays. |
2298 0 means occupied, 1 means free. */ |
2296 if (HASBIT(rs->status, 7) || GB(rs->status, 0, 2) == 0) |
2299 |
|
2300 // Station busy? |
|
2301 if (bb & 0x80 || (bb&3) == 0) |
|
2302 return 8; |
2297 return 8; |
2303 |
2298 |
2304 state = v->u.road.state + 32; |
2299 v->u.road.state += 32; |
2305 if (bb & 1) { |
2300 |
2306 bb &= ~1; |
2301 // if the first bay is free, allocate that, else the second bay must be free. |
|
2302 if (HASBIT(rs->status, 0)) { |
|
2303 CLRBIT(rs->status, 0); |
2307 } else { |
2304 } else { |
2308 bb &= ~2; |
2305 CLRBIT(rs->status, 1); |
2309 state += 2; |
2306 v->u.road.state += 2; |
2310 } |
2307 } |
2311 |
2308 |
2312 bb |= 0x80; |
2309 // mark the station as busy |
2313 *b = bb; |
2310 SETBIT(rs->status, 7); |
2314 v->u.road.state = state; |
|
2315 } |
2311 } |
2316 } |
2312 } |
2317 } |
2313 } |
2318 |
2314 |
2319 return 0; |
2315 return 0; |