Changeset - r20078:a7a34cf316df
[Not reviewed]
master
0 7 0
frosch - 12 years ago 2013-02-24 16:41:51
frosch@openttd.org
(svn r25041) -Remove [FS#3764-ish]: ordered refit with subtypes, since the cases where it worked were corner cases rather than the general case.
7 files changed with 21 insertions and 35 deletions:
0 comments (0 inline, 0 general)
src/economy.cpp
Show inline comments
 
@@ -1438,13 +1438,12 @@ static void LoadUnloadVehicle(Vehicle *f
 

	
 
		/* This order has a refit, if this is the first vehicle part carrying cargo and the whole vehicle is empty, try refitting. */
 
		if (front->current_order.IsRefit() && artic_part == 1 && IsArticulatedVehicleEmpty(v) &&
 
				(v->type != VEH_AIRCRAFT || (Aircraft::From(v)->IsNormalAircraft() && v->Next()->cargo.Count() == 0))) {
 
			Vehicle *v_start = v->GetFirstEnginePart();
 
			CargoID new_cid = front->current_order.GetRefitCargo();
 
			byte new_subtype = front->current_order.GetRefitSubtype();
 

	
 
			/* Remove old capacity from consist capacity */
 
			consist_capleft[v_start->cargo_type] -= v_start->cargo_cap;
 
			for (Vehicle *w = v_start; w->HasArticulatedPart(); ) {
 
				w = w->GetNextArticulatedPart();
 
				consist_capleft[w->cargo_type] -= w->cargo_cap;
 
@@ -1468,25 +1467,24 @@ static void LoadUnloadVehicle(Vehicle *f
 
				FOR_EACH_SET_CARGO_ID(cid, refit_mask) {
 
					/* Consider refitting to this cargo, if other vehicles of the consist cannot
 
					 * already take the cargo without refitting */
 
					if ((int)st->goods[cid].cargo.Count() > (int)consist_capleft[cid] + amount) {
 
						/* Try to find out if auto-refitting would succeed. In case the refit is allowed,
 
						 * the returned refit capacity will be greater than zero. */
 
						new_subtype = GetBestFittingSubType(v, v, cid);
 
						DoCommand(v_start->tile, v_start->index, cid | 1U << 6 | new_subtype << 8 | 1U << 16, DC_QUERY_COST, GetCmdRefitVeh(v_start)); // Auto-refit and only this vehicle including artic parts.
 
						DoCommand(v_start->tile, v_start->index, cid | 1U << 6 | 0xFF << 8 | 1U << 16, DC_QUERY_COST, GetCmdRefitVeh(v_start)); // Auto-refit and only this vehicle including artic parts.
 
						if (_returned_refit_capacity > 0) {
 
							amount = st->goods[cid].cargo.Count() - consist_capleft[cid];
 
							new_cid = cid;
 
						}
 
					}
 
				}
 
			}
 

	
 
			/* Refit if given a valid cargo. */
 
			if (new_cid < NUM_CARGO) {
 
				CommandCost cost = DoCommand(v_start->tile, v_start->index, new_cid | 1U << 6 | new_subtype << 8 | 1U << 16, DC_EXEC, GetCmdRefitVeh(v_start)); // Auto-refit and only this vehicle including artic parts.
 
				CommandCost cost = DoCommand(v_start->tile, v_start->index, new_cid | 1U << 6 | 0xFF << 8 | 1U << 16, DC_EXEC, GetCmdRefitVeh(v_start)); // Auto-refit and only this vehicle including artic parts.
 
				if (cost.Succeeded()) front->profit_this_year -= cost.GetCost() << 8;
 
				ge = &st->goods[v->cargo_type];
 
			}
 

	
 
			/* Add new capacity to consist capacity and reserve cargo */
 
			w = v_start;
src/order_base.h
Show inline comments
 
@@ -39,13 +39,12 @@ private:
 

	
 
	uint8 type;           ///< The type of order + non-stop flags
 
	uint8 flags;          ///< Load/unload types, depot order/action types.
 
	DestinationID dest;   ///< The destination of the order.
 

	
 
	CargoID refit_cargo;  ///< Refit CargoID
 
	byte refit_subtype;   ///< Refit subtype
 

	
 
public:
 
	Order *next;          ///< Pointer to next order. If NULL, end of list
 

	
 
	uint16 wait_time;    ///< How long in ticks to wait at the destination.
 
	uint16 travel_time;  ///< How long in ticks the journey to this destination should take.
 
@@ -69,13 +68,13 @@ public:
 
	 */
 
	inline OrderType GetType() const { return (OrderType)GB(this->type, 0, 4); }
 

	
 
	void Free();
 

	
 
	void MakeGoToStation(StationID destination);
 
	void MakeGoToDepot(DepotID destination, OrderDepotTypeFlags order, OrderNonStopFlags non_stop_type = ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS, OrderDepotActionFlags action = ODATF_SERVICE_ONLY, CargoID cargo = CT_NO_REFIT, byte subtype = 0);
 
	void MakeGoToDepot(DepotID destination, OrderDepotTypeFlags order, OrderNonStopFlags non_stop_type = ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS, OrderDepotActionFlags action = ODATF_SERVICE_ONLY, CargoID cargo = CT_NO_REFIT);
 
	void MakeGoToWaypoint(StationID destination);
 
	void MakeLoading(bool ordered);
 
	void MakeLeaveStation();
 
	void MakeDummy();
 
	void MakeConditional(VehicleOrderID order);
 
	void MakeImplicit(StationID destination);
 
@@ -121,20 +120,13 @@ public:
 
	 * Get the cargo to to refit to.
 
	 * @pre IsType(OT_GOTO_DEPOT) || IsType(OT_GOTO_STATION)
 
	 * @return the cargo type.
 
	 */
 
	inline CargoID GetRefitCargo() const { return this->refit_cargo; }
 

	
 
	/**
 
	 * Get the cargo subtype to to refit to.
 
	 * @pre IsType(OT_GOTO_DEPOT) || IsType(OT_GOTO_STATION)
 
	 * @return the cargo subtype.
 
	 */
 
	inline byte GetRefitSubtype() const { return this->refit_subtype; }
 

	
 
	void SetRefit(CargoID cargo, byte subtype = 0);
 
	void SetRefit(CargoID cargo);
 

	
 
	/** How must the consist be loaded? */
 
	inline OrderLoadFlags GetLoadType() const { return (OrderLoadFlags)GB(this->flags, 4, 4); }
 
	/** How must the consist be unloaded? */
 
	inline OrderUnloadFlags GetUnloadType() const { return (OrderUnloadFlags)GB(this->flags, 0, 4); }
 
	/** At which stations must we stop? */
src/order_cmd.cpp
Show inline comments
 
@@ -80,22 +80,21 @@ void Order::MakeGoToStation(StationID de
 
 * Makes this order a Go To Depot order.
 
 * @param destination   the depot to go to.
 
 * @param order         is this order a 'default' order, or an overridden vehicle order?
 
 * @param non_stop_type how to get to the depot?
 
 * @param action        what to do in the depot?
 
 * @param cargo         the cargo type to change to.
 
 * @param subtype       the subtype to change to.
 
 */
 
void Order::MakeGoToDepot(DepotID destination, OrderDepotTypeFlags order, OrderNonStopFlags non_stop_type, OrderDepotActionFlags action, CargoID cargo, byte subtype)
 
void Order::MakeGoToDepot(DepotID destination, OrderDepotTypeFlags order, OrderNonStopFlags non_stop_type, OrderDepotActionFlags action, CargoID cargo)
 
{
 
	this->type = OT_GOTO_DEPOT;
 
	this->SetDepotOrderType(order);
 
	this->SetDepotActionType(action);
 
	this->SetNonStopType(non_stop_type);
 
	this->dest = destination;
 
	this->SetRefit(cargo, subtype);
 
	this->SetRefit(cargo);
 
}
 

	
 
/**
 
 * Makes this order a Go To Waypoint order.
 
 * @param destination the waypoint to go to.
 
 */
 
@@ -155,19 +154,17 @@ void Order::MakeImplicit(StationID desti
 
	this->dest = destination;
 
}
 

	
 
/**
 
 * Make this depot/station order also a refit order.
 
 * @param cargo   the cargo type to change to.
 
 * @param subtype the subtype to change to.
 
 * @pre IsType(OT_GOTO_DEPOT) || IsType(OT_GOTO_STATION).
 
 */
 
void Order::SetRefit(CargoID cargo, byte subtype)
 
void Order::SetRefit(CargoID cargo)
 
{
 
	this->refit_cargo = cargo;
 
	this->refit_subtype = subtype;
 
}
 

	
 
/**
 
 * Does this order have the same type, flags and destination?
 
 * @param other the second order to compare to.
 
 * @return true if the type, flags and destination match.
 
@@ -235,13 +232,12 @@ Order::Order(uint32 packed)
 
{
 
	this->type    = (OrderType)GB(packed,  0,  8);
 
	this->flags   = GB(packed,  8,  8);
 
	this->dest    = GB(packed, 16, 16);
 
	this->next    = NULL;
 
	this->refit_cargo   = CT_NO_REFIT;
 
	this->refit_subtype = 0;
 
	this->wait_time     = 0;
 
	this->travel_time   = 0;
 
	this->max_speed     = UINT16_MAX;
 
}
 

	
 
/**
 
@@ -275,13 +271,12 @@ void Order::AssignOrder(const Order &oth
 
{
 
	this->type  = other.type;
 
	this->flags = other.flags;
 
	this->dest  = other.dest;
 

	
 
	this->refit_cargo   = other.refit_cargo;
 
	this->refit_subtype = other.refit_subtype;
 

	
 
	this->wait_time   = other.wait_time;
 
	this->travel_time = other.travel_time;
 
	this->max_speed   = other.max_speed;
 
}
 

	
 
@@ -1584,23 +1579,21 @@ CommandCost CmdCloneOrder(TileIndex tile
 
 * Add/remove refit orders from an order
 
 * @param tile Not used
 
 * @param flags operation to perform
 
 * @param p1 VehicleIndex of the vehicle having the order
 
 * @param p2 bitmask
 
 *   - bit 0-7 CargoID
 
 *   - bit 8-15 Cargo subtype
 
 *   - bit 16-23 number of order to modify
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdOrderRefit(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	VehicleID veh = GB(p1, 0, 20);
 
	VehicleOrderID order_number  = GB(p2, 16, 8);
 
	CargoID cargo = GB(p2, 0, 8);
 
	byte subtype  = GB(p2, 8, 8);
 

	
 
	if (cargo >= NUM_CARGO && cargo != CT_NO_REFIT && cargo != CT_AUTO_REFIT) return CMD_ERROR;
 

	
 
	const Vehicle *v = Vehicle::GetIfValid(veh);
 
	if (v == NULL || !v->IsPrimaryVehicle()) return CMD_ERROR;
 

	
 
@@ -1613,13 +1606,13 @@ CommandCost CmdOrderRefit(TileIndex tile
 
	/* Automatic refit cargo is only supported for goto station orders. */
 
	if (cargo == CT_AUTO_REFIT && !order->IsType(OT_GOTO_STATION)) return CMD_ERROR;
 

	
 
	if (order->GetLoadType() & OLFB_NO_LOAD) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		order->SetRefit(cargo, subtype);
 
		order->SetRefit(cargo);
 

	
 
		/* Make the depot order an 'always go' order. */
 
		if (cargo != CT_NO_REFIT && order->IsType(OT_GOTO_DEPOT)) {
 
			order->SetDepotOrderType((OrderDepotTypeFlags)(order->GetDepotOrderType() & ~ODTFB_SERVICE));
 
			order->SetDepotActionType((OrderDepotActionFlags)(order->GetDepotActionType() & ~ODATFB_HALT));
 
		}
 
@@ -1627,13 +1620,13 @@ CommandCost CmdOrderRefit(TileIndex tile
 
		for (Vehicle *u = v->FirstShared(); u != NULL; u = u->NextShared()) {
 
			/* Update any possible open window of the vehicle */
 
			InvalidateVehicleOrder(u, VIWD_MODIFY_ORDERS);
 

	
 
			/* If the vehicle already got the current depot set as current order, then update current order as well */
 
			if (u->cur_real_order_index == order_number && (u->current_order.GetDepotOrderType() & ODTFB_PART_OF_ORDERS)) {
 
				u->current_order.SetRefit(cargo, subtype);
 
				u->current_order.SetRefit(cargo);
 
			}
 
		}
 
	}
 

	
 
	return CommandCost();
 
}
 
@@ -1929,13 +1922,13 @@ bool UpdateOrderDest(Vehicle *v, const O
 

	
 
				if (v->FindClosestDepot(&location, &destination, &reverse)) {
 
					/* PBS reservations cannot reverse */
 
					if (pbs_look_ahead && reverse) return false;
 

	
 
					v->dest_tile = location;
 
					v->current_order.MakeGoToDepot(destination, v->current_order.GetDepotOrderType(), v->current_order.GetNonStopType(), (OrderDepotActionFlags)(v->current_order.GetDepotActionType() & ~ODATFB_NEAREST_DEPOT), v->current_order.GetRefitCargo(), v->current_order.GetRefitSubtype());
 
					v->current_order.MakeGoToDepot(destination, v->current_order.GetDepotOrderType(), v->current_order.GetNonStopType(), (OrderDepotActionFlags)(v->current_order.GetDepotActionType() & ~ODATFB_NEAREST_DEPOT), v->current_order.GetRefitCargo());
 

	
 
					/* If there is no depot in front, reverse automatically (trains only) */
 
					if (v->type == VEH_TRAIN && reverse) DoCommand(v->tile, v->index, 0, DC_EXEC, CMD_REVERSE_TRAIN_DIRECTION);
 

	
 
					if (v->type == VEH_AIRCRAFT) {
 
						Aircraft *a = Aircraft::From(v);
src/saveload/order_sl.cpp
Show inline comments
 
@@ -104,13 +104,13 @@ const SaveLoad *GetOrderDescription()
 
	static const SaveLoad _order_desc[] = {
 
		     SLE_VAR(Order, type,           SLE_UINT8),
 
		     SLE_VAR(Order, flags,          SLE_UINT8),
 
		     SLE_VAR(Order, dest,           SLE_UINT16),
 
		     SLE_REF(Order, next,           REF_ORDER),
 
		 SLE_CONDVAR(Order, refit_cargo,    SLE_UINT8,   36, SL_MAX_VERSION),
 
		 SLE_CONDVAR(Order, refit_subtype,  SLE_UINT8,   36, SL_MAX_VERSION),
 
		SLE_CONDNULL(1,                                  36, 181), // refit_subtype
 
		 SLE_CONDVAR(Order, wait_time,      SLE_UINT16,  67, SL_MAX_VERSION),
 
		 SLE_CONDVAR(Order, travel_time,    SLE_UINT16,  67, SL_MAX_VERSION),
 
		 SLE_CONDVAR(Order, max_speed,      SLE_UINT16, 172, SL_MAX_VERSION),
 

	
 
		/* Leftover from the minor savegame version stuff
 
		 * We will never use those free bytes, but we have to keep this line to allow loading of old savegames */
src/saveload/vehicle_sl.cpp
Show inline comments
 
@@ -636,13 +636,13 @@ const SaveLoad *GetVehicleDescription(Ve
 
		 SLE_CONDVAR(Vehicle, current_order.type,    SLE_UINT8,                    5, SL_MAX_VERSION),
 
		 SLE_CONDVAR(Vehicle, current_order.flags,   SLE_UINT8,                    5, SL_MAX_VERSION),
 
		 SLE_CONDVAR(Vehicle, current_order.dest,    SLE_UINT16,                   5, SL_MAX_VERSION),
 

	
 
		/* Refit in current order */
 
		 SLE_CONDVAR(Vehicle, current_order.refit_cargo,   SLE_UINT8,             36, SL_MAX_VERSION),
 
		 SLE_CONDVAR(Vehicle, current_order.refit_subtype, SLE_UINT8,             36, SL_MAX_VERSION),
 
		SLE_CONDNULL(1,                                                           36, 181), // refit_subtype
 

	
 
		/* Timetable in current order */
 
		 SLE_CONDVAR(Vehicle, current_order.wait_time,     SLE_UINT16,            67, SL_MAX_VERSION),
 
		 SLE_CONDVAR(Vehicle, current_order.travel_time,   SLE_UINT16,            67, SL_MAX_VERSION),
 
		 SLE_CONDVAR(Vehicle, current_order.max_speed,     SLE_UINT16,           174, SL_MAX_VERSION),
 
		 SLE_CONDVAR(Vehicle, timetable_start,       SLE_INT32,                  129, SL_MAX_VERSION),
src/vehicle.cpp
Show inline comments
 
@@ -1364,13 +1364,13 @@ void VehicleEnterDepot(Vehicle *v)
 
			/* We are heading for another depot, keep driving. */
 
			return;
 
		}
 

	
 
		if (t.IsRefit()) {
 
			Backup<CompanyByte> cur_company(_current_company, v->owner, FILE_LINE);
 
			CommandCost cost = DoCommand(v->tile, v->index, t.GetRefitCargo() | t.GetRefitSubtype() << 8, DC_EXEC, GetCmdRefitVeh(v));
 
			CommandCost cost = DoCommand(v->tile, v->index, t.GetRefitCargo() | 0xFF << 8, DC_EXEC, GetCmdRefitVeh(v));
 
			cur_company.Restore();
 

	
 
			if (cost.Failed()) {
 
				_vehicles_to_autoreplace[v] = false;
 
				if (v->owner == _local_company) {
 
					/* Notify the user that we stopped the vehicle */
src/vehicle_gui.cpp
Show inline comments
 
@@ -402,14 +402,17 @@ struct RefitWindow : public Window {
 
				/* Skip cargo type if it's not listed */
 
				if (!HasBit(cmask, cid)) {
 
					current_index++;
 
					continue;
 
				}
 

	
 
				/* Check the vehicle's callback mask for cargo suffixes */
 
				if (HasBit(callback_mask, CBM_VEHICLE_CARGO_SUFFIX)) {
 
				/* Check the vehicle's callback mask for cargo suffixes.
 
				 * This is not supported for ordered refits, since subtypes only have a meaning
 
				 * for a specific vehicle at a specific point in time, which conflicts with shared orders,
 
				 * autoreplace, autorenew, clone, order restoration, ... */
 
				if (this->order == INVALID_VEH_ORDER_ID && HasBit(callback_mask, CBM_VEHICLE_CARGO_SUFFIX)) {
 
					/* Make a note of the original cargo type. It has to be
 
					 * changed to test the cargo & subtype... */
 
					CargoID temp_cargo = v->cargo_type;
 
					byte temp_subtype  = v->cargo_subtype;
 

	
 
					v->cargo_type = cid;
 
@@ -484,12 +487,13 @@ struct RefitWindow : public Window {
 
	}
 

	
 
	RefitWindow(const WindowDesc *desc, const Vehicle *v, VehicleOrderID order, bool auto_refit) : Window()
 
	{
 
		this->sel = -1;
 
		this->auto_refit = auto_refit;
 
		this->order = order;
 
		this->CreateNestedTree(desc);
 

	
 
		this->vscroll = this->GetScrollbar(WID_VR_SCROLLBAR);
 
		this->hscroll = (v->IsGroundVehicle() ? this->GetScrollbar(WID_VR_HSCROLLBAR) : NULL);
 
		this->GetWidget<NWidgetCore>(WID_VR_SELECT_HEADER)->tool_tip = STR_REFIT_TRAIN_LIST_TOOLTIP + v->type;
 
		this->GetWidget<NWidgetCore>(WID_VR_MATRIX)->tool_tip        = STR_REFIT_TRAIN_LIST_TOOLTIP + v->type;
 
@@ -499,13 +503,12 @@ struct RefitWindow : public Window {
 
		this->GetWidget<NWidgetStacked>(WID_VR_SHOW_HSCROLLBAR)->SetDisplayedPlane(v->IsGroundVehicle() ? 0 : SZSP_HORIZONTAL);
 
		this->GetWidget<NWidgetCore>(WID_VR_VEHICLE_PANEL_DISPLAY)->tool_tip = (v->type == VEH_TRAIN) ? STR_REFIT_SELECT_VEHICLES_TOOLTIP : STR_NULL;
 

	
 
		this->FinishInitNested(desc, v->index);
 
		this->owner = v->owner;
 

	
 
		this->order = order;
 
		this->SetWidgetDisabledState(WID_VR_REFIT, this->sel == -1);
 
	}
 

	
 
	virtual void OnInit()
 
	{
 
		if (this->cargo != NULL) {
 
@@ -844,13 +847,13 @@ struct RefitWindow : public Window {
 
					const Vehicle *v = Vehicle::Get(this->window_number);
 

	
 
					if (this->order == INVALID_VEH_ORDER_ID) {
 
						bool delete_window = this->selected_vehicle == v->index && this->num_vehicles == UINT8_MAX;
 
						if (DoCommandP(v->tile, this->selected_vehicle, this->cargo->cargo | this->cargo->subtype << 8 | this->num_vehicles << 16, GetCmdRefitVeh(v)) && delete_window) delete this;
 
					} else {
 
						if (DoCommandP(v->tile, v->index, this->cargo->cargo | this->cargo->subtype << 8 | this->order << 16, CMD_ORDER_REFIT)) delete this;
 
						if (DoCommandP(v->tile, v->index, this->cargo->cargo | this->order << 16, CMD_ORDER_REFIT)) delete this;
 
					}
 
				}
 
				break;
 
		}
 
	}
 

	
 
@@ -921,13 +924,13 @@ static const WindowDesc _vehicle_refit_d
 
	_nested_vehicle_refit_widgets, lengthof(_nested_vehicle_refit_widgets)
 
);
 

	
 
/**
 
 * Show the refit window for a vehicle
 
 * @param *v The vehicle to show the refit window for
 
 * @param order of the vehicle ( ? )
 
 * @param order of the vehicle to assign refit to, or INVALID_VEH_ORDER_ID to refit the vehicle now
 
 * @param parent the parent window of the refit window
 
 * @param auto_refit Choose cargo for auto-refitting
 
 */
 
void ShowVehicleRefitWindow(const Vehicle *v, VehicleOrderID order, Window *parent, bool auto_refit)
 
{
 
	DeleteWindowById(WC_VEHICLE_REFIT, v->index);
0 comments (0 inline, 0 general)