Disallow ordering ordinary road vehicles to tram depots and vice versa

pull/78/head
Jonathan G Rennison 5 years ago
parent 705fc18b08
commit de79d64837

@ -794,6 +794,17 @@ static inline bool OrderGoesToStation(const Vehicle *v, const Order *o)
(v->type == VEH_AIRCRAFT && o->IsType(OT_GOTO_DEPOT) && !(o->GetDepotActionType() & ODATFB_NEAREST_DEPOT));
}
/**
* Checks whether the order goes to a road depot
* @param v the vehicle to check for
* @param o the order to check
* @return true if the destination is a road depot
*/
static inline bool OrderGoesToRoadDepot(const Vehicle *v, const Order *o)
{
return (v->type == VEH_ROAD) && o->IsType(OT_GOTO_DEPOT) && !(o->GetDepotActionType() & ODATFB_NEAREST_DEPOT);
}
/**
* Delete all news items regarding defective orders about a vehicle
* This could kill still valid warnings (for example about void order when just
@ -962,6 +973,7 @@ CommandCost CmdInsertOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
case VEH_ROAD:
if (!IsRoadDepotTile(dp->xy)) return CMD_ERROR;
if ((GetRoadTypes(dp->xy) & RoadVehicle::From(v)->compatible_roadtypes) == 0) return CMD_ERROR;
break;
case VEH_SHIP:
@ -1943,14 +1955,20 @@ CommandCost CmdCloneOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
const Order *order;
FOR_VEHICLE_ORDERS(src, order) {
if (!OrderGoesToStation(dst, order)) continue;
/* Allow copying unreachable destinations if they were already unreachable for the source.
* This is basically to allow cloning / autorenewing / autoreplacing vehicles, while the stations
* are temporarily invalid due to reconstruction. */
const Station *st = Station::Get(order->GetDestination());
if (CanVehicleUseStation(src, st) && !CanVehicleUseStation(dst, st)) {
return_cmd_error(STR_ERROR_CAN_T_COPY_SHARE_ORDER);
if (OrderGoesToStation(dst, order)) {
/* Allow copying unreachable destinations if they were already unreachable for the source.
* This is basically to allow cloning / autorenewing / autoreplacing vehicles, while the stations
* are temporarily invalid due to reconstruction. */
const Station *st = Station::Get(order->GetDestination());
if (CanVehicleUseStation(src, st) && !CanVehicleUseStation(dst, st)) {
return_cmd_error(STR_ERROR_CAN_T_COPY_SHARE_ORDER);
}
}
if (OrderGoesToRoadDepot(dst, order)) {
const Depot *dp = Depot::GetIfValid(order->GetDestination());
if (!dp || (GetRoadTypes(dp->xy) & RoadVehicle::From(dst)->compatible_roadtypes) == 0) {
return_cmd_error(STR_ERROR_CAN_T_COPY_SHARE_ORDER);
}
}
}
@ -2028,6 +2046,12 @@ CommandCost CmdCloneOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
!CanVehicleUseStation(dst, Station::Get(order->GetDestination()))) {
return_cmd_error(STR_ERROR_CAN_T_COPY_SHARE_ORDER);
}
if (OrderGoesToRoadDepot(dst, order)) {
const Depot *dp = Depot::GetIfValid(order->GetDestination());
if (!dp || (GetRoadTypes(dp->xy) & RoadVehicle::From(dst)->compatible_roadtypes) == 0) {
return_cmd_error(STR_ERROR_CAN_T_COPY_SHARE_ORDER);
}
}
}
/* Check for aircraft range limits. */

@ -955,6 +955,10 @@ static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
/* check depot first */
if (IsDepotTypeTile(tile, (TransportType)(uint)v->type) && IsInfraTileUsageAllowed(v->type, v->owner, tile)) {
if (v->type == VEH_ROAD && ((GetRoadTypes(tile) & RoadVehicle::From(v)->compatible_roadtypes) == 0)) {
order.Free();
return order;
}
order.MakeGoToDepot(v->type == VEH_AIRCRAFT ? GetStationIndex(tile) : GetDepotIndex(tile),
ODTFB_PART_OF_ORDERS,
((_settings_client.gui.new_nonstop || _settings_game.order.nonstop_only) && v->IsGroundVehicle()) ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE);

@ -42,6 +42,7 @@
#include "tbtr_template_gui_main.h"
#include "zoom_func.h"
#include "tracerestrict.h"
#include "depot_base.h"
#include <vector>
@ -2120,6 +2121,7 @@ public:
if (IsDepotTile(tile) && GetDepotVehicleType(tile) == this->vli.vtype) {
if (this->vli.type != VL_DEPOT_LIST) return;
if (!IsInfraTileUsageAllowed(this->vli.vtype, this->vli.company, tile)) return;
if (this->vli.vtype == VEH_ROAD && GetRoadTypes(Depot::Get(this->vli.index)->xy) != GetRoadTypes(tile)) return;
DestinationID dest = (this->vli.vtype == VEH_AIRCRAFT) ? GetStationIndex(tile) : GetDepotIndex(tile);
DoCommandP(0, this->vli.index | (this->vli.vtype << 16) | (OT_GOTO_DEPOT << 20), dest, CMD_MASS_CHANGE_ORDER);
@ -3508,6 +3510,7 @@ public:
{
const Vehicle *v = Vehicle::Get(this->window_number);
if (IsDepotTile(tile) && GetDepotVehicleType(tile) == v->type && IsInfraTileUsageAllowed(v->type, v->owner, tile)) {
if (v->type == VEH_ROAD && (GetRoadTypes(tile) & RoadVehicle::From(v)->compatible_roadtypes) == 0) return;
DoCommandP(v->tile, v->index | (this->depot_select_ctrl_pressed ? DEPOT_SERVICE : 0U) | DEPOT_SPECIFIC, tile, GetCmdSendToDepot(v));
ResetObjectToPlace();
this->RaiseButtons();

Loading…
Cancel
Save