Changeset - r11861:e9322118cf50
[Not reviewed]
master
0 6 0
frosch - 15 years ago 2009-05-09 13:37:18
frosch@openttd.org
(svn r16260) -Codechange: Add Vehicle::IncrementOrderIndex() to deduplicate some code.
6 files changed with 27 insertions and 20 deletions:
0 comments (0 inline, 0 general)
src/order_cmd.cpp
Show inline comments
 
@@ -798,9 +798,9 @@ CommandCost CmdMoveOrder(TileIndex tile,
 
			/* 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 O
 
					}
 
				} 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 O
 
				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 @@ 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 */
src/roadveh_cmd.cpp
Show inline comments
 
@@ -692,7 +692,7 @@ TileIndex RoadVehicle::GetOrderStationLo
 
		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;
 
	}
 
}
src/ship_cmd.cpp
Show inline comments
 
@@ -235,7 +235,7 @@ TileIndex Ship::GetOrderStationLocation(
 
	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();
 
								}
 
							}
 
						}
src/train_cmd.cpp
Show inline comments
 
@@ -3284,7 +3284,7 @@ TileIndex Train::GetOrderStationLocation
 
	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;
 
	}
 

	
src/vehicle.cpp
Show inline comments
 
@@ -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(DoComma
 
		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);
src/vehicle_base.h
Show inline comments
 
@@ -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);
 
	}
 
};
 

	
 
/**
0 comments (0 inline, 0 general)