Changeset - r8838:ab02a7e7aabf
[Not reviewed]
master
0 6 0
rubidium - 17 years ago 2008-04-06 07:07:21
rubidium@openttd.org
(svn r12586) -Codechange: do not access an order's refit variables directly.
6 files changed with 55 insertions and 25 deletions:
0 comments (0 inline, 0 general)
src/autoreplace_cmd.cpp
Show inline comments
 
@@ -62,27 +62,27 @@ static void MoveVehicleCargo(Vehicle *de
 
static bool VerifyAutoreplaceRefitForOrders(const Vehicle *v, const EngineID engine_type)
 
{
 
	const Order *o;
 
	const Vehicle *u;
 

	
 
	if (v->type == VEH_TRAIN) {
 
		u = v->First();
 
	} else {
 
		u = v;
 
	}
 

	
 
	FOR_VEHICLE_ORDERS(u, o) {
 
		if (!(o->refit_cargo < NUM_CARGO)) continue;
 
		if (!CanRefitTo(v->engine_type, o->refit_cargo)) continue;
 
		if (!CanRefitTo(engine_type, o->refit_cargo)) return false;
 
		if (!o->IsRefit()) continue;
 
		if (!CanRefitTo(v->engine_type, o->GetRefitCargo())) continue;
 
		if (!CanRefitTo(engine_type, o->GetRefitCargo())) return false;
 
	}
 

	
 
	return true;
 
}
 

	
 
/**
 
 * Function to find what type of cargo to refit to when autoreplacing
 
 * @param *v Original vehicle, that is being replaced
 
 * @param engine_type The EngineID of the vehicle that is being replaced to
 
 * @return The cargo type to replace to
 
 *    CT_NO_REFIT is returned if no refit is needed
 
 *    CT_INVALID is returned when both old and new vehicle got cargo capacity and refitting the new one to the old one's cargo type isn't possible
src/openttd.cpp
Show inline comments
 
@@ -1978,31 +1978,29 @@ bool AfterLoadGame()
 
			if (GetIndustrySpec(i->type)->behaviour & INDUSTRYBEH_PLANT_ON_BUILT) {
 
				for (j = 0; j != 50; j++) PlantRandomFarmField(i);
 
			}
 
		}
 
	}
 

	
 
	/* Setting no refit flags to all orders in savegames from before refit in orders were added */
 
	if (CheckSavegameVersion(36)) {
 
		Order *order;
 
		Vehicle *v;
 

	
 
		FOR_ALL_ORDERS(order) {
 
			order->refit_cargo   = CT_NO_REFIT;
 
			order->refit_subtype = CT_NO_REFIT;
 
			order->SetRefit(CT_NO_REFIT);
 
		}
 

	
 
		FOR_ALL_VEHICLES(v) {
 
			v->current_order.refit_cargo   = CT_NO_REFIT;
 
			v->current_order.refit_subtype = CT_NO_REFIT;
 
			v->current_order.SetRefit(CT_NO_REFIT);
 
		}
 
	}
 

	
 
	/* from version 38 we have optional elrails, since we cannot know the
 
	 * preference of a user, let elrails enabled; it can be disabled manually */
 
	if (CheckSavegameVersion(38)) _patches.disable_elrails = false;
 
	/* do the same as when elrails were enabled/disabled manually just now */
 
	SettingsDisableElrail(_patches.disable_elrails);
 
	InitializeRailGUI();
 

	
 
	/* From version 53, the map array was changed for house tiles to allow
 
	 * space for newhouses grf features. A new byte, m7, was also added. */
src/order_base.h
Show inline comments
 
@@ -22,35 +22,35 @@ DECLARE_OLD_POOL(Order, Order, 6, 1000)
 
 * - REF_ORDER (all REFs are currently limited to 16 bits!!)
 
 */
 
struct Order : PoolItem<Order, OrderID, &_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.
 
	friend uint32 PackOrder(const Order *order);                         ///< 'Compressing' an order.
 
	friend Order UnpackOrder(uint32 packed);                             ///< 'Uncompressing' an order.
 
	friend Order UnpackOldOrder(uint16 packed);                          ///< 'Uncompressing' a loaded old order.
 
	friend Order UnpackVersion4Order(uint16 packed);                     ///< 'Uncompressing' a loaded ancient order.
 

	
 
	OrderTypeByte type;
 
	OrderTypeByte type;   ///< The type of order
 

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

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

	
 
	uint8  flags;
 
	DestinationID dest;   ///< The destionation of the order.
 

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

	
 
	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.
 

	
 
	Order() : refit_cargo(CT_NO_REFIT) {}
 
	~Order() { this->type = OT_NOTHING; }
 

	
 
	/**
 
	 * Check if a Order really exists.
 
	 * @return true if the order is valid.
 
	 */
 
	inline bool IsValid() const { return this->type != OT_NOTHING; }
 

	
 
@@ -74,26 +74,28 @@ public:
 
	void Free();
 

	
 
	/**
 
	 * Makes this order a Go To Station order.
 
	 * @param destsination the station to go to.
 
	 */
 
	void MakeGoToStation(StationID 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 overriden vehicle order?
 
	 * @param cargo       the cargo type to change to.
 
	 * @param subtype     the subtype to change to.
 
	 */
 
	void MakeGoToDepot(DepotID destination, bool order);
 
	void MakeGoToDepot(DepotID destination, bool order, CargoID cargo = CT_NO_REFIT, byte subtype = 0);
 

	
 
	/**
 
	 * Makes this order a Go To Waypoint order.
 
	 * @param destination the waypoint to go to.
 
	 */
 
	void MakeGoToWaypoint(WaypointID destination);
 

	
 
	/**
 
	 * Makes this order a Loading order.
 
	 */
 
	void MakeLoading();
 

	
 
@@ -104,24 +106,53 @@ public:
 

	
 
	/**
 
	 * Makes this order a Dummy order.
 
	 */
 
	void MakeDummy();
 

	
 
	/**
 
	 * Free a complete order chain.
 
	 * @note do not use on "current_order" vehicle orders!
 
	 */
 
	void FreeChain();
 

	
 
	/**
 
	 * Is this order a refit order.
 
	 * @pre IsType(OT_GOTO_DEPOT)
 
	 * @return true if a refit should happen.
 
	 */
 
	inline bool IsRefit() const { return this->refit_cargo < NUM_CARGO; }
 

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

	
 
	/**
 
	 * Make this depot 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).
 
	 */
 
	void SetRefit(CargoID cargo, byte subtype = 0);
 

	
 
	bool ShouldStopAtStation(const Vehicle *v, StationID station) const;
 

	
 
	/**
 
	 * Assign the given order to this one.
 
	 * @param other the data to copy (except next pointer).
 
	 */
 
	void AssignOrder(const Order &other);
 

	
 
	/**
 
	 * 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.
src/order_cmd.cpp
Show inline comments
 
@@ -46,31 +46,30 @@ void Order::Free()
 
	this->flags = 0;
 
	this->dest  = 0;
 
	this->next  = NULL;
 
}
 

	
 
void Order::MakeGoToStation(StationID destination)
 
{
 
	this->type = OT_GOTO_STATION;
 
	this->flags = 0;
 
	this->dest = destination;
 
}
 

	
 
void Order::MakeGoToDepot(DepotID destination, bool order)
 
void Order::MakeGoToDepot(DepotID destination, bool order, CargoID cargo, byte subtype)
 
{
 
	this->type = OT_GOTO_DEPOT;
 
	this->flags = order ? OFB_PART_OF_ORDERS : OFB_NON_STOP;
 
	this->dest = destination;
 
	this->refit_cargo = CT_NO_REFIT;
 
	this->refit_subtype = 0;
 
	this->SetRefit(cargo, subtype);
 
}
 

	
 
void Order::MakeGoToWaypoint(WaypointID destination)
 
{
 
	this->type = OT_GOTO_WAYPOINT;
 
	this->flags = 0;
 
	this->dest = destination;
 
}
 

	
 
void Order::MakeLoading()
 
{
 
	this->type = OT_LOADING;
 
@@ -79,24 +78,30 @@ void Order::MakeLoading()
 
void Order::MakeLeaveStation()
 
{
 
	this->type = OT_LEAVESTATION;
 
	this->flags = 0;
 
}
 

	
 
void Order::MakeDummy()
 
{
 
	this->type = OT_DUMMY;
 
	this->flags = 0;
 
}
 

	
 
void Order::SetRefit(CargoID cargo, byte subtype)
 
{
 
	this->refit_cargo = cargo;
 
	this->refit_subtype = subtype;
 
}
 

	
 
void Order::FreeChain()
 
{
 
	if (next != NULL) next->FreeChain();
 
	delete this;
 
}
 

	
 
bool Order::Equals(const Order &other) const
 
{
 
	return
 
			this->type  == other.type &&
 
			this->flags == other.flags &&
 
			this->dest  == other.dest;
 
@@ -993,36 +998,34 @@ CommandCost CmdOrderRefit(TileIndex tile
 
	if (!IsValidVehicleID(veh)) return CMD_ERROR;
 

	
 
	v = GetVehicle(veh);
 

	
 
	if (!CheckOwnership(v->owner)) return CMD_ERROR;
 

	
 
	order = GetVehicleOrder(v, order_number);
 
	if (order == NULL) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		Vehicle *u;
 

	
 
		order->refit_cargo = cargo;
 
		order->refit_subtype = subtype;
 
		order->SetRefit(cargo, subtype);
 

	
 
		u = GetFirstVehicleFromSharedList(v);
 
		for (; u != NULL; u = u->next_shared) {
 
			/* Update any possible open window of the vehicle */
 
			InvalidateVehicleOrder(u);
 

	
 
			/* If the vehicle already got the current depot set as current order, then update current order as well */
 
			if (u->cur_order_index == order_number && HasBit(u->current_order.flags, OF_PART_OF_ORDERS)) {
 
				u->current_order.refit_cargo = cargo;
 
				u->current_order.refit_subtype = subtype;
 
				u->current_order.SetRefit(cargo, subtype);
 
			}
 
		}
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 
/**
 
 *
 
 * Backup a vehicle order-list, so you can replace a vehicle
 
 *  without loosing the order-list
 
 *
src/order_gui.cpp
Show inline comments
 
@@ -216,27 +216,27 @@ static void DrawOrdersWindow(Window *w)
 

	
 
						switch (v->type) {
 
							case VEH_TRAIN: s = (order->flags & OFB_NON_STOP) ? STR_880F_GO_NON_STOP_TO_TRAIN_DEPOT : STR_GO_TO_TRAIN_DEPOT; break;
 
							case VEH_ROAD:  s = STR_GO_TO_ROADVEH_DEPOT; break;
 
							case VEH_SHIP:  s = STR_GO_TO_SHIP_DEPOT; break;
 
							default: break;
 
						}
 
					}
 

	
 
					if (order->flags & OFB_FULL_LOAD) s++; /* service at */
 

	
 
					SetDParam(1, s);
 
					if (order->refit_cargo < NUM_CARGO) {
 
					if (order->IsRefit()) {
 
						SetDParam(3, STR_REFIT_ORDER);
 
						SetDParam(4, GetCargo(order->refit_cargo)->name);
 
						SetDParam(4, GetCargo(order->GetRefitCargo())->name);
 
					} else {
 
						SetDParam(3, STR_EMPTY);
 
					}
 
					break;
 
				}
 

	
 
				case OT_GOTO_WAYPOINT:
 
					SetDParam(1, (order->flags & OFB_NON_STOP) ? STR_GO_NON_STOP_TO_WAYPOINT : STR_GO_TO_WAYPOINT);
 
					SetDParam(2, order->dest);
 
					break;
 

	
 
				default: break;
 
@@ -254,26 +254,24 @@ static void DrawOrdersWindow(Window *w)
 

	
 
	if (i - w->vscroll.pos < w->vscroll.cap) {
 
		str = shared_orders ? STR_END_OF_SHARED_ORDERS : STR_882A_END_OF_ORDERS;
 
		DrawString(2, y, str, (i == WP(w, order_d).sel) ? TC_WHITE : TC_BLACK);
 
	}
 
}
 

	
 
static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
 
{
 
	Order order;
 
	order.next  = NULL;
 
	order.index = 0;
 
	order.refit_cargo   = CT_INVALID;
 
	order.refit_subtype = 0;
 

	
 
	// check depot first
 
	if (_patches.gotodepot) {
 
		switch (GetTileType(tile)) {
 
		case MP_RAILWAY:
 
			if (v->type == VEH_TRAIN && IsTileOwner(tile, _local_player)) {
 
				if (IsRailDepot(tile)) {
 
					order.MakeGoToDepot(GetDepotByTile(tile)->index, true);
 
					return order;
 
				}
 
			}
 
			break;
src/vehicle.cpp
Show inline comments
 
@@ -2234,29 +2234,29 @@ void VehicleEnterDepot(Vehicle *v)
 
	VehicleServiceInDepot(v);
 

	
 
	TriggerVehicle(v, VEHICLE_TRIGGER_DEPOT);
 

	
 
	if (v->current_order.IsType(OT_GOTO_DEPOT)) {
 
		Order t;
 

	
 
		InvalidateWindow(WC_VEHICLE_VIEW, v->index);
 

	
 
		t = v->current_order;
 
		v->current_order.MakeDummy();
 

	
 
		if (t.refit_cargo < NUM_CARGO) {
 
		if (t.IsRefit()) {
 
			CommandCost cost;
 

	
 
			_current_player = v->owner;
 
			cost = DoCommand(v->tile, v->index, t.refit_cargo | t.refit_subtype << 8, DC_EXEC, GetCmdRefitVeh(v));
 
			cost = DoCommand(v->tile, v->index, t.GetRefitCargo() | t.GetRefitSubtype() << 8, DC_EXEC, GetCmdRefitVeh(v));
 

	
 
			if (CmdFailed(cost)) {
 
				v->leave_depot_instantly = false; // We ensure that the vehicle stays in the depot
 
				if (v->owner == _local_player) {
 
					/* Notify the user that we stopped the vehicle */
 
					SetDParam(0, _vehicle_type_names[v->type]);
 
					SetDParam(1, v->unitnumber);
 
					AddNewsItem(STR_ORDER_REFIT_FAILED, NM_SMALL, NF_VIEWPORT | NF_VEHICLE, NT_ADVICE, DNC_NONE, v->index, 0);
 
				}
 
			} else if (v->owner == _local_player && cost.GetCost() != 0) {
 
				ShowCostOrIncomeAnimation(v->x_pos, v->y_pos, v->z_pos, cost.GetCost());
 
			}
0 comments (0 inline, 0 general)