--- a/src/roadveh_cmd.cpp Thu Sep 06 19:42:48 2007 +0000
+++ b/src/roadveh_cmd.cpp Sat Oct 06 21:16:00 2007 +0000
@@ -179,11 +179,11 @@
if (HASBIT(GetRoadTypes(tile), ROADTYPE_TRAM) != HASBIT(EngInfo(p1)->misc_flags, EF_ROAD_TRAM)) return_cmd_error(STR_DEPOT_WRONG_DEPOT_TYPE);
- uint num_vehicles = 1 + CountArticulatedParts(p1);
+ uint num_vehicles = 1 + CountArticulatedParts(p1, false);
- /* Allow for the front and up to 10 articulated parts. */
- Vehicle *vl[11];
- memset(&vl, 0, sizeof(vl));
+ /* Allow for the front and the articulated parts, plus one to "terminate" the list. */
+ Vehicle **vl = (Vehicle**)alloca(sizeof(*vl) * (num_vehicles + 1));
+ memset(vl, 0, sizeof(*vl) * (num_vehicles + 1));
if (!Vehicle::AllocateList(vl, num_vehicles)) {
return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME);
@@ -477,6 +477,7 @@
* Now we change the setting to apply the new one and let the vehicle head for the same depot.
* Note: the if is (true for requesting service == true for ordered to stop in depot) */
if (flags & DC_EXEC) {
+ CLRBIT(v->current_order.flags, OFB_PART_OF_ORDERS);
TOGGLEBIT(v->current_order.flags, OFB_HALT_IN_DEPOT);
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
}
@@ -997,7 +998,7 @@
const Vehicle* u;
const Vehicle* v;
TileIndex tile;
- byte tilebits;
+ uint16 tilebits;
};
static void* EnumFindVehToOvertake(Vehicle* v, void* data)
@@ -1013,9 +1014,10 @@
{
uint32 bits;
- bits = GetTileTrackStatus(od->tile, TRANSPORT_ROAD, od->v->u.road.compatible_roadtypes) & 0x3F;
+ bits = GetTileTrackStatus(od->tile, TRANSPORT_ROAD, od->v->u.road.compatible_roadtypes);
+ bits |= bits >> 8;
- if (!(od->tilebits & bits) || (bits & 0x3C) || (bits & 0x3F3F0000))
+ if (!(od->tilebits & bits) || (bits & 0x3C3C) || (bits & 0x3F3F0000))
return true;
return VehicleFromPos(od->tile, od, EnumFindVehToOvertake) != NULL;
}
@@ -1023,7 +1025,7 @@
static void RoadVehCheckOvertake(Vehicle *v, Vehicle *u)
{
OvertakeData od;
- byte tt;
+ uint16 tt;
od.v = v;
od.u = u;
@@ -1037,6 +1039,9 @@
/* Trams can't overtake other trams */
if (v->u.road.roadtype == ROADTYPE_TRAM) return;
+ /* Don't overtake in stations */
+ if (IsTileType(v->tile, MP_STATION)) return;
+
/* For now, articulated road vehicles can't overtake anything. */
if (RoadVehHasArticPart(v)) return;
@@ -1045,7 +1050,10 @@
/* Check if vehicle is in a road stop, depot, tunnel or bridge or not on a straight road */
if (v->u.road.state >= RVSB_IN_ROAD_STOP || !IsStraightRoadTrackdir((Trackdir)(v->u.road.state & RVSB_TRACKDIR_MASK))) return;
- tt = GetTileTrackStatus(v->tile, TRANSPORT_ROAD, v->u.road.compatible_roadtypes) & 0x3F;
+ tt = GetTileTrackStatus(v->tile, TRANSPORT_ROAD, v->u.road.compatible_roadtypes);
+ tt |= tt >> 8;
+ tt &= 0x3F;
+
if ((tt & 3) == 0) return;
if ((tt & 0x3C) != 0) return;
@@ -1646,9 +1654,9 @@
Vehicle* u = RoadVehFindCloseTo(v, x, y, new_dir);
if (u != NULL) {
- v->cur_speed = u->cur_speed;
/* There is a vehicle in front overtake it if possible */
if (v->u.road.overtaking == 0) RoadVehCheckOvertake(v, u);
+ if (v->u.road.overtaking == 0) v->cur_speed = u->cur_speed;
return false;
}
}
@@ -2022,7 +2030,7 @@
if (v->cargo_cap == 0) continue;
- if (HASBIT(EngInfo(v->engine_type)->callbackmask, CBM_REFIT_CAPACITY)) {
+ if (HASBIT(EngInfo(v->engine_type)->callbackmask, CBM_VEHICLE_REFIT_CAPACITY)) {
/* Back up the cargo type */
CargoID temp_cid = v->cargo_type;
byte temp_subtype = v->cargo_subtype;