|
@@ -157,13 +157,13 @@ Order UnpackOldOrder(uint16 packed)
|
|
|
Order order = UnpackVersion4Order(packed);
|
|
|
|
|
|
/*
|
|
|
* Sanity check
|
|
|
* TTD stores invalid orders as OT_NOTHING with non-zero flags/station
|
|
|
*/
|
|
|
if (!order.IsValid() && (order.flags != 0 || order.dest != 0)) {
|
|
|
if (!order.IsValid() && (order.flags != 0 || order.GetDestination() != 0)) {
|
|
|
order.MakeDummy();
|
|
|
}
|
|
|
|
|
|
return order;
|
|
|
}
|
|
|
|
|
@@ -231,14 +231,14 @@ static void DeleteOrderWarnings(const Ve
|
|
|
|
|
|
|
|
|
static TileIndex GetOrderLocation(const Order& o)
|
|
|
{
|
|
|
switch (o.GetType()) {
|
|
|
default: NOT_REACHED();
|
|
|
case OT_GOTO_STATION: return GetStation(o.dest)->xy;
|
|
|
case OT_GOTO_DEPOT: return GetDepot(o.dest)->xy;
|
|
|
case OT_GOTO_STATION: return GetStation(o.GetDestination())->xy;
|
|
|
case OT_GOTO_DEPOT: return GetDepot(o.GetDestination())->xy;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/** Add an order to the orderlist of a vehicle.
|
|
|
* @param tile unused
|
|
@@ -264,16 +264,15 @@ CommandCost CmdInsertOrder(TileIndex til
|
|
|
if (!CheckOwnership(v->owner)) return CMD_ERROR;
|
|
|
|
|
|
/* Check if the inserted order is to the correct destination (owner, type),
|
|
|
* and has the correct flags if any */
|
|
|
switch (new_order.GetType()) {
|
|
|
case OT_GOTO_STATION: {
|
|
|
const Station *st;
|
|
|
if (!IsValidStationID(new_order.GetDestination())) return CMD_ERROR;
|
|
|
|
|
|
if (!IsValidStationID(new_order.dest)) return CMD_ERROR;
|
|
|
st = GetStation(new_order.dest);
|
|
|
const Station *st = GetStation(new_order.GetDestination());
|
|
|
|
|
|
if (st->owner != OWNER_NONE && !CheckOwnership(st->owner)) {
|
|
|
return CMD_ERROR;
|
|
|
}
|
|
|
|
|
|
switch (v->type) {
|
|
@@ -327,28 +326,26 @@ CommandCost CmdInsertOrder(TileIndex til
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case OT_GOTO_DEPOT: {
|
|
|
if (v->type == VEH_AIRCRAFT) {
|
|
|
const Station* st;
|
|
|
if (!IsValidStationID(new_order.GetDestination())) return CMD_ERROR;
|
|
|
|
|
|
if (!IsValidStationID(new_order.dest)) return CMD_ERROR;
|
|
|
st = GetStation(new_order.dest);
|
|
|
const Station *st = GetStation(new_order.GetDestination());
|
|
|
|
|
|
if (!CheckOwnership(st->owner) ||
|
|
|
!(st->facilities & FACIL_AIRPORT) ||
|
|
|
st->Airport()->nof_depots == 0 ||
|
|
|
!CanAircraftUseStation(v->engine_type, st)) {
|
|
|
return CMD_ERROR;
|
|
|
}
|
|
|
} else {
|
|
|
const Depot* dp;
|
|
|
if (!IsValidDepotID(new_order.GetDestination())) return CMD_ERROR;
|
|
|
|
|
|
if (!IsValidDepotID(new_order.dest)) return CMD_ERROR;
|
|
|
dp = GetDepot(new_order.dest);
|
|
|
const Depot *dp = GetDepot(new_order.GetDestination());
|
|
|
|
|
|
if (!CheckOwnership(GetTileOwner(dp->xy))) return CMD_ERROR;
|
|
|
|
|
|
switch (v->type) {
|
|
|
case VEH_TRAIN:
|
|
|
if (!IsTileDepotType(dp->xy, TRANSPORT_RAIL)) return CMD_ERROR;
|
|
@@ -382,18 +379,17 @@ CommandCost CmdInsertOrder(TileIndex til
|
|
|
default: return CMD_ERROR;
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case OT_GOTO_WAYPOINT: {
|
|
|
const Waypoint* wp;
|
|
|
|
|
|
if (v->type != VEH_TRAIN) return CMD_ERROR;
|
|
|
|
|
|
if (!IsValidWaypointID(new_order.dest)) return CMD_ERROR;
|
|
|
wp = GetWaypoint(new_order.dest);
|
|
|
if (!IsValidWaypointID(new_order.GetDestination())) return CMD_ERROR;
|
|
|
const Waypoint *wp = GetWaypoint(new_order.GetDestination());
|
|
|
|
|
|
if (!CheckOwnership(GetTileOwner(wp->xy))) return CMD_ERROR;
|
|
|
|
|
|
/* Order flags can be any of the following for waypoints:
|
|
|
* [non-stop]
|
|
|
* non-stop orders (if any) are only valid for trains */
|
|
@@ -766,13 +762,13 @@ CommandCost CmdModifyOrder(TileIndex til
|
|
|
if (!CheckOwnership(v->owner)) return CMD_ERROR;
|
|
|
|
|
|
/* Is it a valid order? */
|
|
|
if (sel_ord >= v->num_orders) return CMD_ERROR;
|
|
|
|
|
|
order = GetVehicleOrder(v, sel_ord);
|
|
|
if ((!order->IsType(OT_GOTO_STATION) || GetStation(order->dest)->IsBuoy()) &&
|
|
|
if ((!order->IsType(OT_GOTO_STATION) || GetStation(order->GetDestination())->IsBuoy()) &&
|
|
|
(!order->IsType(OT_GOTO_DEPOT) || p2 == OF_UNLOAD) &&
|
|
|
(!order->IsType(OT_GOTO_WAYPOINT) || p2 != OF_NON_STOP)) {
|
|
|
return CMD_ERROR;
|
|
|
}
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
|
@@ -906,13 +902,13 @@ CommandCost CmdCloneOrder(TileIndex tile
|
|
|
if (src->type == VEH_ROAD) {
|
|
|
const Order *order;
|
|
|
TileIndex required_dst = INVALID_TILE;
|
|
|
|
|
|
FOR_VEHICLE_ORDERS(src, order) {
|
|
|
if (order->IsType(OT_GOTO_STATION)) {
|
|
|
const Station *st = GetStation(order->dest);
|
|
|
const Station *st = GetStation(order->GetDestination());
|
|
|
if (IsCargoInClass(dst->cargo_type, CC_PASSENGERS)) {
|
|
|
if (st->bus_stops != NULL) required_dst = st->bus_stops->xy;
|
|
|
} else {
|
|
|
if (st->truck_stops != NULL) required_dst = st->truck_stops->xy;
|
|
|
}
|
|
|
/* This station has not the correct road-bay, so we can't copy! */
|
|
@@ -1187,13 +1183,13 @@ void CheckOrders(const Vehicle* v)
|
|
|
if (order->IsType(OT_DUMMY)) {
|
|
|
problem_type = 1;
|
|
|
break;
|
|
|
}
|
|
|
/* Does station have a load-bay for this vehicle? */
|
|
|
if (order->IsType(OT_GOTO_STATION)) {
|
|
|
const Station* st = GetStation(order->dest);
|
|
|
const Station* st = GetStation(order->GetDestination());
|
|
|
TileIndex required_tile = GetStationTileForVehicle(v, st);
|
|
|
|
|
|
n_st++;
|
|
|
if (required_tile == 0) problem_type = 3;
|
|
|
}
|
|
|
}
|
|
@@ -1248,22 +1244,22 @@ void RemoveOrderFromAllVehicles(OrderTyp
|
|
|
if (v->last_station_visited == destination && type == OT_GOTO_STATION) {
|
|
|
v->last_station_visited = INVALID_STATION;
|
|
|
}
|
|
|
|
|
|
order = &v->current_order;
|
|
|
if ((v->type == VEH_AIRCRAFT && order->IsType(OT_GOTO_DEPOT) ? OT_GOTO_STATION : order->GetType()) == type &&
|
|
|
v->current_order.dest == destination) {
|
|
|
v->current_order.GetDestination() == destination) {
|
|
|
order->MakeDummy();
|
|
|
InvalidateWindow(WC_VEHICLE_VIEW, v->index);
|
|
|
}
|
|
|
|
|
|
/* Clear the order from the order-list */
|
|
|
invalidate = false;
|
|
|
FOR_VEHICLE_ORDERS(v, order) {
|
|
|
if ((v->type == VEH_AIRCRAFT && order->IsType(OT_GOTO_DEPOT) ? OT_GOTO_STATION : order->GetType()) == type &&
|
|
|
order->dest == destination) {
|
|
|
order->GetDestination() == destination) {
|
|
|
order->MakeDummy();
|
|
|
invalidate = true;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/* Only invalidate once, and if needed */
|
|
@@ -1411,14 +1407,14 @@ bool ProcessOrders(Vehicle *v)
|
|
|
}
|
|
|
|
|
|
/* Check if we've reached a non-stop station while TTDPatch nonstop is enabled.. */
|
|
|
if (_patches.new_nonstop &&
|
|
|
v->current_order.flags & OFB_NON_STOP &&
|
|
|
IsTileType(v->tile, MP_STATION) &&
|
|
|
v->current_order.dest == GetStationIndex(v->tile)) {
|
|
|
v->last_station_visited = v->current_order.dest;
|
|
|
v->current_order.GetDestination() == GetStationIndex(v->tile)) {
|
|
|
v->last_station_visited = v->current_order.GetDestination();
|
|
|
UpdateVehicleTimetable(v, true);
|
|
|
v->cur_order_index++;
|
|
|
}
|
|
|
|
|
|
/* Get the current order */
|
|
|
if (v->cur_order_index >= v->num_orders) v->cur_order_index = 0;
|
|
@@ -1439,13 +1435,13 @@ bool ProcessOrders(Vehicle *v)
|
|
|
if (v->type == VEH_ROAD) ClearSlot(v);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
/* If it is unchanged, keep it. */
|
|
|
if (order->Equals(v->current_order) &&
|
|
|
(v->type != VEH_SHIP || !order->IsType(OT_GOTO_STATION) || GetStation(order->dest)->dock_tile != 0)) {
|
|
|
(v->type != VEH_SHIP || !order->IsType(OT_GOTO_STATION) || GetStation(order->GetDestination())->dock_tile != 0)) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
/* Otherwise set it, and determine the destination tile. */
|
|
|
v->current_order = *order;
|
|
|
|
|
@@ -1463,21 +1459,21 @@ bool ProcessOrders(Vehicle *v)
|
|
|
InvalidateWindowClasses(v->GetVehicleListWindowClass());
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
switch (order->GetType()) {
|
|
|
case OT_GOTO_STATION:
|
|
|
v->dest_tile = v->GetOrderStationLocation(order->dest);
|
|
|
v->dest_tile = v->GetOrderStationLocation(order->GetDestination());
|
|
|
break;
|
|
|
|
|
|
case OT_GOTO_DEPOT:
|
|
|
if (v->type != VEH_AIRCRAFT) v->dest_tile = GetDepot(order->dest)->xy;
|
|
|
if (v->type != VEH_AIRCRAFT) v->dest_tile = GetDepot(order->GetDestination())->xy;
|
|
|
break;
|
|
|
|
|
|
case OT_GOTO_WAYPOINT:
|
|
|
v->dest_tile = GetWaypoint(order->dest)->xy;
|
|
|
v->dest_tile = GetWaypoint(order->GetDestination())->xy;
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
v->dest_tile = 0;
|
|
|
return false;
|
|
|
}
|