diff --git a/src/lang/english.txt b/src/lang/english.txt index e9bdf02439..f72cf1dbbb 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -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}' diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp index 1e3b0af420..3c2ee6f088 100644 --- a/src/order_cmd.cpp +++ b/src/order_cmd.cpp @@ -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 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; } diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 2c0752fe0a..efa6074272 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -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)); diff --git a/src/settings_type.h b/src/settings_type.h index 45e8fa4b1f..a2a518d965 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -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. */ diff --git a/src/table/company_settings.ini b/src/table/company_settings.ini index 6bbe098cac..f811c5dc58 100644 --- a/src/table/company_settings.ini +++ b/src/table/company_settings.ini @@ -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]