summaryrefslogtreecommitdiff
path: root/roadveh_cmd.c
diff options
context:
space:
mode:
authorcelestar <celestar@openttd.org>2006-03-16 16:47:39 +0000
committercelestar <celestar@openttd.org>2006-03-16 16:47:39 +0000
commit9aab1d5711a545dd0d9b89200025369770eaad98 (patch)
treeba70b0e87d02a3fa88145a53ab4fbbb06043655f /roadveh_cmd.c
parent83ba8bdf776f8fd820e51068097567841fc4bdf4 (diff)
downloadopenttd-9aab1d5711a545dd0d9b89200025369770eaad98.tar.xz
(svn r3909) [multistop]
-Codechange: No longer hijack the VS_STOPPED flag when waiting for a slot. -Fix: Vehicles waiting for slots can still be controlled (sent to depot, orders modified, ...) -Fix: Vehicles no longer stop on crossings and during overtake operations
Diffstat (limited to 'roadveh_cmd.c')
-rw-r--r--roadveh_cmd.c32
1 files changed, 20 insertions, 12 deletions
diff --git a/roadveh_cmd.c b/roadveh_cmd.c
index 676ea0d9b..070695f6b 100644
--- a/roadveh_cmd.c
+++ b/roadveh_cmd.c
@@ -380,6 +380,8 @@ int32 CmdSendRoadVehToDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2)
if (dep == NULL) return_cmd_error(STR_9019_UNABLE_TO_FIND_LOCAL_DEPOT);
if (flags & DC_EXEC) {
+ ClearSlot(v);
+ v->vehstatus &= ~VS_WAIT_FOR_SLOT;
v->current_order.type = OT_GOTO_DEPOT;
v->current_order.flags = OF_NON_STOP | OF_HALT_IN_DEPOT;
v->current_order.station = dep->index;
@@ -405,7 +407,7 @@ int32 CmdTurnRoadVeh(int x, int y, uint32 flags, uint32 p1, uint32 p2)
if (v->type != VEH_Road || !CheckOwnership(v->owner)) return CMD_ERROR;
- if (v->vehstatus & (VS_HIDDEN | VS_STOPPED) ||
+ if (v->vehstatus & (VS_HIDDEN | VS_STOPPED | VS_WAIT_FOR_SLOT) ||
v->u.road.crashed_ctr != 0 ||
v->breakdown_ctr != 0 ||
v->u.road.overtaking != 0 ||
@@ -538,6 +540,7 @@ static void RoadVehCrash(Vehicle *v)
v->u.road.crashed_ctr++;
v->vehstatus |= VS_CRASHED;
+ ClearSlot(v);
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
@@ -629,6 +632,7 @@ static void ProcessRoadVehOrder(Vehicle *v)
v->current_order.flags = 0;
v->dest_tile = 0;
ClearSlot(v);
+ v->vehstatus &= ~VS_WAIT_FOR_SLOT;
return;
}
@@ -640,6 +644,8 @@ static void ProcessRoadVehOrder(Vehicle *v)
v->current_order = *order;
v->dest_tile = 0;
+ /* We have changed the destination STATION, so resume movement */
+ v->vehstatus &= ~VS_WAIT_FOR_SLOT;
if (order->type == OT_GOTO_STATION) {
const Station* st = GetStation(order->station);
@@ -900,7 +906,7 @@ static void RoadVehCheckOvertake(Vehicle *v, Vehicle *u)
od.u = u;
if (u->max_speed >= v->max_speed &&
- !(u->vehstatus & VS_STOPPED) &&
+ !(u->vehstatus & (VS_STOPPED | VS_WAIT_FOR_SLOT)) &&
u->cur_speed != 0) {
return;
}
@@ -922,7 +928,7 @@ static void RoadVehCheckOvertake(Vehicle *v, Vehicle *u)
od.tile = v->tile + TileOffsByDir(DirToDiagDir(v->direction));
if (FindRoadVehToOvertake(&od)) return;
- if (od.u->cur_speed == 0 || od.u->vehstatus&VS_STOPPED) {
+ if (od.u->cur_speed == 0 || od.u->vehstatus& (VS_STOPPED | VS_WAIT_FOR_SLOT)) {
v->u.road.overtaking_ctr = 0x11;
v->u.road.overtaking = 0x10;
} else {
@@ -1185,7 +1191,7 @@ static void RoadVehController(Vehicle *v)
v->breakdown_ctr--;
}
- if (v->vehstatus & VS_STOPPED) return;
+ if (v->vehstatus & (VS_STOPPED | VS_WAIT_FOR_SLOT)) return;
ProcessRoadVehOrder(v);
HandleRoadVehLoading(v);
@@ -1448,6 +1454,7 @@ again:
v->current_order.type = OT_NOTHING;
v->current_order.flags = 0;
ClearSlot(v);
+ v->vehstatus &= ~VS_WAIT_FOR_SLOT;
}
SETBIT(rs->status, 7);
@@ -1553,7 +1560,7 @@ static void CheckIfRoadVehNeedsService(Vehicle *v)
if (_patches.servint_roadveh == 0) return;
if (!VehicleNeedsService(v)) return;
- if (v->vehstatus & VS_STOPPED) return;
+ if (v->vehstatus & (VS_STOPPED | VS_WAIT_FOR_SLOT)) return;
if (_patches.gotodepot && VehicleHasDepotOrders(v)) return;
// Don't interfere with a depot visit scheduled by the user, or a
@@ -1610,11 +1617,14 @@ void OnNewDay_RoadVeh(Vehicle *v)
ClearSlot(v);
}
+ if (v->vehstatus & VS_STOPPED) return;
+
/* update destination */
if (v->current_order.type == OT_GOTO_STATION &&
v->u.road.slot == NULL &&
- !(v->vehstatus & VS_CRASHED) &&
- !((v->vehstatus & (VS_STOPPED | VS_WAIT_FOR_SLOT)) == VS_STOPPED)) {
+ !IsLevelCrossing(v->tile) &&
+ v->u.road.overtaking == 0 &&
+ !(v->vehstatus & VS_CRASHED)) {
RoadStopType type = (v->cargo_type == CT_PASSENGERS) ? RS_BUS : RS_TRUCK;
RoadStop *rs;
uint mindist = 0xFFFFFFFF;
@@ -1667,14 +1677,14 @@ void OnNewDay_RoadVeh(Vehicle *v)
v->u.road.slot_age = 14;
v->u.road.slotindex = new_slot;
- if (v->vehstatus & VS_STOPPED) {
+ if (v->vehstatus & VS_WAIT_FOR_SLOT) {
DEBUG(ms, 4) ("Multistop: ---- stopped vehicle got a slot. resuming movement");
- v->vehstatus &= ~(VS_STOPPED | VS_WAIT_FOR_SLOT);
+ v->vehstatus &= ~VS_WAIT_FOR_SLOT;
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
}
} else {
DEBUG(ms, 2) ("Multistop -- No free slot at station. Waiting");
- v->vehstatus |= (VS_STOPPED | VS_WAIT_FOR_SLOT);
+ v->vehstatus |= VS_WAIT_FOR_SLOT;
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
}
} else {
@@ -1687,8 +1697,6 @@ void OnNewDay_RoadVeh(Vehicle *v)
}
}
- if (v->vehstatus & VS_STOPPED) return;
-
cost = RoadVehInfo(v->engine_type)->running_cost * _price.roadveh_running / 364;
v->profit_this_year -= cost >> 8;