From 847f3f660d665aedff737eece86c5967f5dc4a98 Mon Sep 17 00:00:00 2001 From: SamuXarick <43006711+SamuXarick@users.noreply.github.com> Date: Fri, 5 Jan 2024 21:23:01 +0000 Subject: [PATCH 1/3] Fix #10511: Delay 'go to nearest depot' orders (#11548) Delay the nearest depot order search for a day if the vehicle can't find its destination, which happens when it has already attempted to do so and failed to find a valid destination. --- src/order_cmd.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp index 2650843c1f..b64275314f 100644 --- a/src/order_cmd.cpp +++ b/src/order_cmd.cpp @@ -1961,6 +1961,10 @@ bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth, bool } if (v->current_order.GetDepotActionType() & ODATFB_NEAREST_DEPOT) { + /* If the vehicle can't find its destination, delay its next search. + * In case many vehicles are in this state, use the vehicle index to spread out pathfinder calls. */ + if (v->dest_tile == 0 && TimerGameCalendar::date_fract != (v->index % Ticks::DAY_TICKS)) break; + /* We need to search for the nearest depot (hangar). */ ClosestDepot closestDepot = v->FindClosestDepot(); From 6828b6014a0c4f510351a6c6828c7702549dcdb1 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Fri, 5 Jan 2024 21:38:56 +0000 Subject: [PATCH 2/3] Codechange: Use company group statistics to test for vehicles for drop down list state. This avoids iterating full the vehicle pool to find out if a company has any vehicles of a particular type. --- src/toolbar_gui.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp index 0ff9cfe7eb..7a187103cd 100644 --- a/src/toolbar_gui.cpp +++ b/src/toolbar_gui.cpp @@ -728,10 +728,10 @@ static CallBackFunction MenuClickIndustry(int index) static void ToolbarVehicleClick(Window *w, VehicleType veh) { - int dis = ~0; + int dis = 0; - for (const Vehicle *v : Vehicle::Iterate()) { - if (v->type == veh && v->IsPrimaryVehicle()) ClrBit(dis, v->owner); + for (const Company *c : Company::Iterate()) { + if (c->group_all[veh].num_vehicle == 0) SetBit(dis, c->index); } PopupMainCompanyToolbMenu(w, WID_TN_VEHICLE_START + veh, dis); } From 06a5fa6239a116f1fd616048b9e0d69493f2a1c8 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Fri, 5 Jan 2024 21:50:37 +0000 Subject: [PATCH 3/3] Codechange: Use CompanyMask to pass Companies to PopupMainCompanyToolbMenu(). It's like the type was designed for it. --- src/toolbar_gui.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp index 7a187103cd..2931774962 100644 --- a/src/toolbar_gui.cpp +++ b/src/toolbar_gui.cpp @@ -145,9 +145,9 @@ static const int CTMN_SPECTATOR = -3; ///< Show a company window as spectator * Pop up a generic company list menu. * @param w The toolbar window. * @param widget The button widget id. - * @param grey A bitbask of which items to mark as disabled. + * @param grey A bitmask of which companies to mark as disabled. */ -static void PopupMainCompanyToolbMenu(Window *w, WidgetID widget, int grey = 0) +static void PopupMainCompanyToolbMenu(Window *w, WidgetID widget, CompanyMask grey = 0) { DropDownList list; @@ -728,7 +728,7 @@ static CallBackFunction MenuClickIndustry(int index) static void ToolbarVehicleClick(Window *w, VehicleType veh) { - int dis = 0; + CompanyMask dis = 0; for (const Company *c : Company::Iterate()) { if (c->group_all[veh].num_vehicle == 0) SetBit(dis, c->index);