summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/order_cmd.cpp18
-rw-r--r--src/roadveh_cmd.cpp2
-rw-r--r--src/ship_cmd.cpp8
-rw-r--r--src/train_cmd.cpp2
-rw-r--r--src/vehicle.cpp7
-rw-r--r--src/vehicle_base.h10
6 files changed, 27 insertions, 20 deletions
diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp
index 18a8ef73f..8abb51901 100644
--- a/src/order_cmd.cpp
+++ b/src/order_cmd.cpp
@@ -798,9 +798,9 @@ CommandCost CmdMoveOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
/* Update the current order */
if (u->cur_order_index == moving_order) {
u->cur_order_index = target_order;
- } else if(u->cur_order_index > moving_order && u->cur_order_index <= target_order) {
+ } else if (u->cur_order_index > moving_order && u->cur_order_index <= target_order) {
u->cur_order_index--;
- } else if(u->cur_order_index < moving_order && u->cur_order_index >= target_order) {
+ } else if (u->cur_order_index < moving_order && u->cur_order_index >= target_order) {
u->cur_order_index++;
}
@@ -1654,7 +1654,7 @@ bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth)
}
} else {
UpdateVehicleTimetable(v, true);
- v->cur_order_index++;
+ v->IncrementOrderIndex();
}
} else if (v->type != VEH_AIRCRAFT) {
v->dest_tile = GetDepot(order->GetDestination())->xy;
@@ -1675,12 +1675,12 @@ bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth)
v->current_order_time += GetVehicleOrder(v, next_order)->travel_time;
} else {
UpdateVehicleTimetable(v, true);
- v->cur_order_index++;
+ v->IncrementOrderIndex();
}
- /* Get the current order */
- if (v->cur_order_index >= v->GetNumOrders()) v->cur_order_index = 0;
+ assert(v->cur_order_index < v->GetNumOrders());
+ /* Get the current order */
const Order *order = GetVehicleOrder(v, v->cur_order_index);
v->current_order = *order;
return UpdateOrderDest(v, order, conditional_depth + 1);
@@ -1709,7 +1709,7 @@ bool ProcessOrders(Vehicle *v)
if ((v->current_order.GetDepotOrderType() & ODTFB_SERVICE) && !v->NeedsServicing()) {
UpdateVehicleTimetable(v, true);
- v->cur_order_index++;
+ v->IncrementOrderIndex();
}
break;
@@ -1735,7 +1735,7 @@ bool ProcessOrders(Vehicle *v)
/* Check if we've reached the waypoint? */
if (v->current_order.IsType(OT_GOTO_WAYPOINT) && v->tile == v->dest_tile) {
UpdateVehicleTimetable(v, true);
- v->cur_order_index++;
+ v->IncrementOrderIndex();
}
/* Check if we've reached a non-stop station.. */
@@ -1744,7 +1744,7 @@ bool ProcessOrders(Vehicle *v)
v->current_order.GetDestination() == GetStationIndex(v->tile)) {
v->last_station_visited = v->current_order.GetDestination();
UpdateVehicleTimetable(v, true);
- v->cur_order_index++;
+ v->IncrementOrderIndex();
}
/* Get the current order */
diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp
index 70fb90571..563d0679a 100644
--- a/src/roadveh_cmd.cpp
+++ b/src/roadveh_cmd.cpp
@@ -692,7 +692,7 @@ TileIndex RoadVehicle::GetOrderStationLocation(StationID station)
return dest;
} else {
/* There is no stop left at the station, so don't even TRY to go there */
- this->cur_order_index++;
+ this->IncrementOrderIndex();
return 0;
}
}
diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp
index 6f1af330c..4abf9e0da 100644
--- a/src/ship_cmd.cpp
+++ b/src/ship_cmd.cpp
@@ -235,7 +235,7 @@ TileIndex Ship::GetOrderStationLocation(StationID station)
if (st->dock_tile != INVALID_TILE) {
return TILE_ADD(st->dock_tile, ToTileIndexDiff(GetDockOffset(st->dock_tile)));
} else {
- this->cur_order_index++;
+ this->IncrementOrderIndex();
return 0;
}
}
@@ -614,9 +614,8 @@ static void ShipController(Vehicle *v)
/* We got within 3 tiles of our target buoy, so let's skip to our
* next order */
UpdateVehicleTimetable(v, true);
- v->cur_order_index++;
+ v->IncrementOrderIndex();
v->current_order.MakeDummy();
- InvalidateVehicleOrder(v, 0);
} else {
/* Non-buoy orders really need to reach the tile */
if (v->dest_tile == gp.new_tile) {
@@ -635,8 +634,7 @@ static void ShipController(Vehicle *v)
v->BeginLoading();
} else { // leave stations without docks right aways
v->current_order.MakeLeaveStation();
- v->cur_order_index++;
- InvalidateVehicleOrder(v, 0);
+ v->IncrementOrderIndex();
}
}
}
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index ba9ece7d7..f95aabc38 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -3284,7 +3284,7 @@ TileIndex Train::GetOrderStationLocation(StationID station)
const Station *st = GetStation(station);
if (!(st->facilities & FACIL_TRAIN)) {
/* The destination station has no trainstation tiles. */
- this->cur_order_index++;
+ this->IncrementOrderIndex();
return 0;
}
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index 1c8de34fb..5dda6a93d 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -1067,7 +1067,7 @@ void VehicleEnterDepot(Vehicle *v)
if (t.GetDepotOrderType() & ODTFB_PART_OF_ORDERS) {
/* Part of orders */
UpdateVehicleTimetable(v, true);
- v->cur_order_index++;
+ v->IncrementOrderIndex();
}
if (t.GetDepotActionType() & ODATFB_HALT) {
/* Vehicles are always stopped on entering depots. Do not restart this one. */
@@ -1577,8 +1577,7 @@ void Vehicle::HandleLoading(bool mode)
default: return;
}
- this->cur_order_index++;
- InvalidateVehicleOrder(this, 0);
+ this->IncrementOrderIndex();
}
CommandCost Vehicle::SendToDepot(DoCommandFlag flags, DepotCommand command)
@@ -1605,7 +1604,7 @@ CommandCost Vehicle::SendToDepot(DoCommandFlag flags, DepotCommand command)
if (flags & DC_EXEC) {
/* If the orders to 'goto depot' are in the orders list (forced servicing),
* then skip to the next order; effectively cancelling this forced service */
- if (this->current_order.GetDepotOrderType() & ODTFB_PART_OF_ORDERS) this->cur_order_index++;
+ if (this->current_order.GetDepotOrderType() & ODTFB_PART_OF_ORDERS) this->IncrementOrderIndex();
this->current_order.MakeDummy();
InvalidateWindowWidget(WC_VEHICLE_VIEW, this->index, VVW_WIDGET_START_STOP_VEH);
diff --git a/src/vehicle_base.h b/src/vehicle_base.h
index 9a224d2de..ca6666118 100644
--- a/src/vehicle_base.h
+++ b/src/vehicle_base.h
@@ -598,6 +598,16 @@ public:
* @return the cost of the depot action.
*/
CommandCost SendToDepot(DoCommandFlag flags, DepotCommand command);
+
+ /**
+ * Increments cur_order_index, keeps care of the wrap-around and invalidates the GUI.
+ * Note: current_order is not invalidated.
+ */
+ void IncrementOrderIndex() {
+ this->cur_order_index++;
+ if (this->cur_order_index >= this->GetNumOrders()) this->cur_order_index = 0;
+ InvalidateVehicleOrder(this, 0);
+ }
};
/**