Changeset - r20078:a7a34cf316df
[Not reviewed]
master
0 7 0
frosch - 11 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
 
@@ -1432,25 +1432,24 @@ static void LoadUnloadVehicle(Vehicle *f
 

	
 
			continue;
 
		}
 

	
 
		/* Do not pick up goods when we have no-load set or loading is stopped. */
 
		if (front->current_order.GetLoadType() & OLFB_NO_LOAD || HasBit(front->vehicle_flags, VF_STOP_LOADING)) continue;
 

	
 
		/* 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;
 
			}
 

	
 
			Backup<CompanyByte> cur_company(_current_company, front->owner, FILE_LINE);
 

	
 
			/* Check if all articulated parts are empty and collect refit mask. */
 
			uint32 refit_mask = v->GetEngine()->info.refit_mask;
 
@@ -1462,37 +1461,36 @@ static void LoadUnloadVehicle(Vehicle *f
 
			}
 

	
 
			if (new_cid == CT_AUTO_REFIT) {
 
				/* Get refittable cargo type with the most waiting cargo. */
 
				int amount = 0;
 
				CargoID cid;
 
				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;
 
			do {
 
				st->goods[w->cargo_type].cargo.Reserve(w->cargo_cap, &w->cargo, st->xy);
 
				consist_capleft[w->cargo_type] += w->cargo_cap - w->cargo.Count();
 
				w = w->HasArticulatedPart() ? w->GetNextArticulatedPart() : NULL;
 
			} while (w != NULL);
 

	
src/order_base.h
Show inline comments
 
@@ -33,25 +33,24 @@ extern OrderListPool _orderlist_pool;
 
 */
 
struct Order : OrderPool::PoolItem<&_order_pool> {
 
private:
 
	friend const struct SaveLoad *GetVehicleDescription(VehicleType vt); ///< Saving and loading the current order of vehicles.
 
	friend void Load_VEHS();                                             ///< Loading of ancient vehicles.
 
	friend const struct SaveLoad *GetOrderDescription();                 ///< Saving and loading of orders.
 

	
 
	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.
 
	uint16 max_speed;    ///< How fast the vehicle may go on the way to the destination.
 

	
 
	Order() : refit_cargo(CT_NO_REFIT), max_speed(UINT16_MAX) {}
 
	~Order();
 

	
 
	Order(uint32 packed);
 
@@ -63,25 +62,25 @@ public:
 
	 */
 
	inline bool IsType(OrderType type) const { return this->GetType() == type; }
 

	
 
	/**
 
	 * Get the type of order of this order.
 
	 * @return the order type.
 
	 */
 
	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);
 

	
 
	/**
 
	 * Is this a 'goto' order with a real destination?
 
	 * @return True if the type is either #OT_GOTO_WAYPOINT, #OT_GOTO_DEPOT or #OT_GOTO_STATION.
 
	 */
 
	inline bool IsGotoOrder() const
 
@@ -115,32 +114,25 @@ public:
 
	 * @pre IsType(OT_GOTO_DEPOT) || IsType(OT_GOTO_STATION)
 
	 * @return true if a auto-refit should happen.
 
	 */
 
	inline bool IsAutoRefit() const { return this->refit_cargo == CT_AUTO_REFIT; }
 

	
 
	/**
 
	 * 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? */
 
	inline OrderNonStopFlags GetNonStopType() const { return (OrderNonStopFlags)GB(this->type, 6, 2); }
 
	/** Where must we stop at the platform? */
 
	inline OrderStopLocation GetStopLocation() const { return (OrderStopLocation)GB(this->type, 4, 2); }
 
	/** What caused us going to the depot? */
 
	inline OrderDepotTypeFlags GetDepotOrderType() const { return (OrderDepotTypeFlags)GB(this->flags, 0, 4); }
 
	/** What are we going to do when in the depot. */
src/order_cmd.cpp
Show inline comments
 
@@ -74,34 +74,33 @@ void Order::MakeGoToStation(StationID de
 
	this->type = OT_GOTO_STATION;
 
	this->flags = 0;
 
	this->dest = destination;
 
}
 

	
 
/**
 
 * 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.
 
 */
 
void Order::MakeGoToWaypoint(StationID destination)
 
{
 
	this->type = OT_GOTO_WAYPOINT;
 
	this->flags = 0;
 
	this->dest = destination;
 
}
 
@@ -149,31 +148,29 @@ void Order::MakeConditional(VehicleOrder
 
 * Makes this order an implicit order.
 
 * @param destination the station to go to.
 
 */
 
void Order::MakeImplicit(StationID destination)
 
{
 
	this->type = OT_IMPLICIT;
 
	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.
 
 */
 
bool Order::Equals(const Order &other) const
 
{
 
	/* In case of go to nearest depot orders we need "only" compare the flags
 
	 * with the other and not the nearest depot order bit or the actual
 
	 * destination because those get clear/filled in during the order
 
@@ -229,25 +226,24 @@ uint16 Order::MapOldOrder() const
 

	
 
/**
 
 * Create an order based on a packed representation of that order.
 
 * @param packed the packed representation.
 
 */
 
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;
 
}
 

	
 
/**
 
 *
 
 * Updates the widgets of a vehicle which contains the order-data
 
 *
 
 */
 
void InvalidateVehicleOrder(const Vehicle *v, int data)
 
{
 
@@ -269,25 +265,24 @@ void InvalidateVehicleOrder(const Vehicl
 
 * Assign data to an order (from another order)
 
 *   This function makes sure that the index is maintained correctly
 
 * @param other the data to copy (except next pointer).
 
 *
 
 */
 
void Order::AssignOrder(const Order &other)
 
{
 
	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;
 
}
 

	
 
/**
 
 * Recomputes everything.
 
 * @param chain first order in the chain
 
 * @param v one of vehicle that is using this orderlist
 
 */
 
void OrderList::Initialize(Order *chain, Vehicle *v)
 
@@ -1578,68 +1573,66 @@ CommandCost CmdCloneOrder(TileIndex tile
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 
/**
 
 * 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;
 

	
 
	CommandCost ret = CheckOwnership(v->owner);
 
	if (ret.Failed()) return ret;
 

	
 
	Order *order = v->GetOrder(order_number);
 
	if (order == NULL) return CMD_ERROR;
 

	
 
	/* 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));
 
		}
 

	
 
		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();
 
}
 

	
 

	
 
/**
 
 *
 
 * Check the orders of a vehicle, to see if there are invalid orders and stuff
 
 *
 
@@ -1923,25 +1916,25 @@ bool UpdateOrderDest(Vehicle *v, const O
 

	
 
			if (v->current_order.GetDepotActionType() & ODATFB_NEAREST_DEPOT) {
 
				/* We need to search for the nearest depot (hangar). */
 
				TileIndex location;
 
				DestinationID destination;
 
				bool reverse;
 

	
 
				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);
 
						if (a->state == FLYING && a->targetairport != destination) {
 
							/* The aircraft is now heading for a different hangar than the next in the orders */
 
							extern void AircraftNextAirportPos_and_Order(Aircraft *a);
 
							AircraftNextAirportPos_and_Order(a);
 
						}
 
					}
src/saveload/order_sl.cpp
Show inline comments
 
@@ -98,25 +98,25 @@ Order UnpackOldOrder(uint16 packed)
 

	
 
	return order;
 
}
 

	
 
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 */
 
		SLE_CONDNULL(10,                                  5,  35),
 
		     SLE_END()
 
	};
 

	
 
	return _order_desc;
 
}
src/saveload/vehicle_sl.cpp
Show inline comments
 
@@ -630,25 +630,25 @@ const SaveLoad *GetVehicleDescription(Ve
 
		 type and flags (which were both 4 bits) into type. Later on this is
 
		 converted correctly */
 
		 SLE_CONDVAR(Vehicle, current_order.type,    SLE_UINT8,                    0,   4),
 
		 SLE_CONDVAR(Vehicle, current_order.dest,    SLE_FILE_U8  | SLE_VAR_U16,   0,   4),
 

	
 
		/* Orders for version 5 and on */
 
		 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),
 

	
 
		 SLE_CONDREF(Vehicle, orders,                REF_ORDER,                    0, 104),
 
		 SLE_CONDREF(Vehicle, orders,                REF_ORDERLIST,              105, SL_MAX_VERSION),
 

	
 
		 SLE_CONDVAR(Vehicle, age,                   SLE_FILE_U16 | SLE_VAR_I32,   0,  30),
 
		 SLE_CONDVAR(Vehicle, age,                   SLE_INT32,                   31, SL_MAX_VERSION),
src/vehicle.cpp
Show inline comments
 
@@ -1358,25 +1358,25 @@ void VehicleEnterDepot(Vehicle *v)
 

	
 
		/* Test whether we are heading for this depot. If not, do nothing.
 
		 * Note: The target depot for nearest-/manual-depot-orders is only updated on junctions, but we want to accept every depot. */
 
		if ((t.GetDepotOrderType() & ODTFB_PART_OF_ORDERS) &&
 
				real_order != NULL && !(real_order->GetDepotActionType() & ODATFB_NEAREST_DEPOT) &&
 
				(v->type == VEH_AIRCRAFT ? t.GetDestination() != GetStationIndex(v->tile) : v->dest_tile != v->tile)) {
 
			/* 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 */
 
					SetDParam(0, v->index);
 
					AddVehicleAdviceNewsItem(STR_NEWS_ORDER_REFIT_FAILED, v->index);
 
				}
 
			} else if (cost.GetCost() != 0) {
 
				v->profit_this_year -= cost.GetCost() << 8;
 
				if (v->owner == _local_company) {
src/vehicle_gui.cpp
Show inline comments
 
@@ -396,26 +396,29 @@ struct RefitWindow : public Window {
 

	
 
			/* Loop through all cargoes in the refit mask */
 
			int current_index = 0;
 
			const CargoSpec *cs;
 
			FOR_ALL_SORTED_CARGOSPECS(cs) {
 
				CargoID cid = cs->Index();
 
				/* 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;
 

	
 
					for (uint refit_cyc = 0; refit_cyc < MAX_REFIT_CYCLE; refit_cyc++) {
 
						v->cargo_subtype = refit_cyc;
 

	
 
						/* Make sure we don't pick up anything cached. */
 
						v->First()->InvalidateNewGRFCache();
 
@@ -478,40 +481,40 @@ struct RefitWindow : public Window {
 
				}
 
				subtype++;
 
			}
 
		}
 

	
 
		return NULL;
 
	}
 

	
 
	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;
 
		NWidgetCore *nwi = this->GetWidget<NWidgetCore>(WID_VR_REFIT);
 
		nwi->widget_data = STR_REFIT_TRAIN_REFIT_BUTTON + v->type;
 
		nwi->tool_tip    = STR_REFIT_TRAIN_REFIT_TOOLTIP + v->type;
 
		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) {
 
			/* Store the RefitOption currently in use. */
 
			RefitOption current_refit_option = *(this->cargo);
 

	
 
			/* Rebuild the refit list */
 
			this->BuildRefitList();
 
			this->sel = -1;
 
@@ -838,25 +841,25 @@ struct RefitWindow : public Window {
 
				if (click_count == 1) break;
 
				/* FALL THROUGH */
 
			}
 

	
 
			case WID_VR_REFIT: // refit button
 
				if (this->cargo != NULL) {
 
					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;
 
		}
 
	}
 

	
 
	virtual void OnMouseDrag(Point pt, int widget)
 
	{
 
		switch (widget) {
 
			case WID_VR_VEHICLE_PANEL_DISPLAY: { // Vehicle image.
 
				if (this->order != INVALID_VEH_ORDER_ID) break;
 
				NWidgetBase *nwi = this->GetWidget<NWidgetBase>(WID_VR_VEHICLE_PANEL_DISPLAY);
 
@@ -915,25 +918,25 @@ static const NWidgetPart _nested_vehicle
 
};
 

	
 
static const WindowDesc _vehicle_refit_desc(
 
	WDP_AUTO, 240, 174,
 
	WC_VEHICLE_REFIT, WC_VEHICLE_VIEW,
 
	WDF_CONSTRUCTION,
 
	_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);
 
	RefitWindow *w = new RefitWindow(&_vehicle_refit_desc, v, order, auto_refit);
 
	w->parent = parent;
 
}
 

	
 
/** Display list of cargo types of the engine, for the purchase information window */
 
uint ShowRefitOptionsList(int left, int right, int y, EngineID engine)
0 comments (0 inline, 0 general)