Mercurial > hg > openttd
changeset 11866:1e159ef634d5 draft
(svn r16260) -Codechange: Add Vehicle::IncrementOrderIndex() to deduplicate some code.
author | frosch <frosch@openttd.org> |
---|---|
date | Sat, 09 May 2009 13:37:18 +0000 |
parents | a8d788b2bbd2 |
children | 8bf4312f1a12 |
files | src/order_cmd.cpp src/roadveh_cmd.cpp src/ship_cmd.cpp src/train_cmd.cpp src/vehicle.cpp src/vehicle_base.h |
diffstat | 6 files changed, 27 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/src/order_cmd.cpp +++ b/src/order_cmd.cpp @@ -798,9 +798,9 @@ /* 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 @@ } } 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 @@ v->current_order_time += GetVehicleOrder(v, next_order)->travel_time; } else { UpdateVehicleTimetable(v, true); - v->cur_order_index++; + v->IncrementOrderIndex(); } + assert(v->cur_order_index < v->GetNumOrders()); + /* Get the current order */ - if (v->cur_order_index >= v->GetNumOrders()) v->cur_order_index = 0; - const Order *order = GetVehicleOrder(v, v->cur_order_index); v->current_order = *order; return UpdateOrderDest(v, order, conditional_depth + 1); @@ -1709,7 +1709,7 @@ if ((v->current_order.GetDepotOrderType() & ODTFB_SERVICE) && !v->NeedsServicing()) { UpdateVehicleTimetable(v, true); - v->cur_order_index++; + v->IncrementOrderIndex(); } break; @@ -1735,7 +1735,7 @@ /* 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 @@ 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 */
--- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -692,7 +692,7 @@ 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; } }
--- a/src/ship_cmd.cpp +++ b/src/ship_cmd.cpp @@ -235,7 +235,7 @@ 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 @@ /* 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 @@ v->BeginLoading(); } else { // leave stations without docks right aways v->current_order.MakeLeaveStation(); - v->cur_order_index++; - InvalidateVehicleOrder(v, 0); + v->IncrementOrderIndex(); } } }
--- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -3284,7 +3284,7 @@ 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; }
--- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -1067,7 +1067,7 @@ 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 @@ default: return; } - this->cur_order_index++; - InvalidateVehicleOrder(this, 0); + this->IncrementOrderIndex(); } CommandCost Vehicle::SendToDepot(DoCommandFlag flags, DepotCommand command) @@ -1605,7 +1604,7 @@ 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);
--- a/src/vehicle_base.h +++ b/src/vehicle_base.h @@ -598,6 +598,16 @@ * @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); + } }; /**