File diff r20077:1122c5c64e88 → r20078:a7a34cf316df
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);
 
						}
 
					}