Add company setting to advance order when cloning/copying/sharing

Advance order if current depot is in order list
pull/78/head
Jonathan G Rennison 5 years ago
parent 7b8db50fd5
commit 705fc18b08

@ -1936,6 +1936,9 @@ STR_CONFIG_SETTING_REPAIR_COST_HELPTEXT :Cost of repairi
STR_CONFIG_OCCUPANCY_SMOOTHNESS :Smoothness of order occupancy measurement: {STRING2}
STR_CONFIG_OCCUPANCY_SMOOTHNESS_HELPTEXT :0% sets the measurement to the most recent value, 100% leaves it unchanged
STR_CONFIG_SETTING_ADVANCE_ORDER_ON_CLONE :Advance order after cloning/copying/sharing: {STRING2}
STR_CONFIG_SETTING_ADVANCE_ORDER_ON_CLONE_HELPTEXT :After cloning a vehicle or copying/sharing orders from an existing vehicle.{}For trains, road vehicles and ships: if the vehicle is in a depot which is in the order list, skip to the order which follows one of the orders for that depot.{}For aircraft: if the aircraft is in a hangar and the associated airport is in the order list, skip to one of the orders for that airport.
# Config errors
STR_CONFIG_ERROR :{WHITE}Error with the configuration file...
STR_CONFIG_ERROR_ARRAY :{WHITE}... error in array '{RAW_STRING}'

@ -1871,6 +1871,35 @@ static bool CheckAircraftOrderDistance(const Aircraft *v_new, const Vehicle *v_o
return true;
}
static void CheckAdvanceVehicleOrdersAfterClone(Vehicle *v, DoCommandFlag flags)
{
const Company *owner = Company::GetIfValid(v->owner);
if (!owner || !owner->settings.advance_order_on_clone || !v->IsInDepot() || !IsDepotTile(v->tile)) return;
std::vector<VehicleOrderID> target_orders;
const int order_count = v->GetNumOrders();
if (v->type == VEH_AIRCRAFT) {
for (VehicleOrderID idx = 0; idx < order_count; idx++) {
const Order *o = v->GetOrder(idx);
if (o->IsType(OT_GOTO_STATION) && o->GetDestination() == GetStationIndex(v->tile)) {
target_orders.push_back(idx);
}
}
} else if (GetDepotVehicleType(v->tile) == v->type) {
for (VehicleOrderID idx = 0; idx < order_count; idx++) {
const Order *o = v->GetOrder(idx);
if (o->IsType(OT_GOTO_DEPOT) && o->GetDestination() == GetDepotIndex(v->tile)) {
target_orders.push_back(idx + 1 < order_count ? idx + 1 : 0);
}
}
}
if (target_orders.empty()) return;
VehicleOrderID skip_to = target_orders[v->unitnumber % target_orders.size()];
DoCommand(v->tile, v->index, skip_to, flags, CMD_SKIP_TO_ORDER);
}
/**
* Clone/share/copy an order-list of another vehicle.
* @param tile unused
@ -1976,6 +2005,8 @@ CommandCost CmdCloneOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
InvalidateWindowClassesData(GetWindowClassForVehicleType(dst->type), 0);
CheckMarkDirtyFocusedRoutePaths(dst);
CheckAdvanceVehicleOrdersAfterClone(dst, flags);
}
break;
}
@ -2078,6 +2109,8 @@ CommandCost CmdCloneOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
InvalidateWindowClassesData(GetWindowClassForVehicleType(dst->type), 0);
CheckMarkDirtyFocusedRoutePaths(dst);
CheckAdvanceVehicleOrdersAfterClone(dst, flags);
}
break;
}

@ -1673,6 +1673,7 @@ static SettingsContainer &GetSettingsTree()
company->Add(new SettingEntry("company.infra_others_buy_in_depot[1]"));
company->Add(new SettingEntry("company.infra_others_buy_in_depot[2]"));
company->Add(new SettingEntry("company.infra_others_buy_in_depot[3]"));
company->Add(new SettingEntry("company.advance_order_on_clone"));
}
SettingsPage *accounting = main->Add(new SettingsPage(STR_CONFIG_SETTING_ACCOUNTING));

@ -643,6 +643,7 @@ struct CompanySettings {
uint8 auto_timetable_separation_rate; ///< percentage of auto timetable separation change to apply
bool infra_others_buy_in_depot[4]; ///< other companies can buy/autorenew in this companies depots (where infra sharing enabled)
uint16 timetable_autofill_rounding; ///< round up timetable times to be a multiple of this number of ticks
bool advance_order_on_clone; ///< when cloning a vehicle or copying/sharing an order list, advance the current order to a suitable point
};
/** All settings together for the game. */

@ -237,6 +237,16 @@ def = false
str = STR_CONFIG_SETTING_INFRA_OTHERS_BUY_IN_DEPOT_AIR
patxname = ""infra_sharing.infra_others_buy_in_depot.air""
[SDT_BOOL]
base = CompanySettings
var = advance_order_on_clone
guiflags = SGF_PER_COMPANY
def = false
str = STR_CONFIG_SETTING_ADVANCE_ORDER_ON_CLONE
strhelp = STR_CONFIG_SETTING_ADVANCE_ORDER_ON_CLONE_HELPTEXT
patxname = ""advance_order_on_clone""
[SDT_END]

Loading…
Cancel
Save