Merge branch 'master' into jgrpp

# Conflicts:
#	src/vehicle.cpp
This commit is contained in:
Jonathan G Rennison
2024-03-01 23:36:16 +00:00
12 changed files with 326 additions and 296 deletions

View File

@@ -3806,11 +3806,28 @@ bool Vehicle::HasUnbunchingOrder() const
return false;
}
/**
* Check if the previous order is a depot unbunching order.
* @return true Iff the previous order is a depot order with the unbunch flag.
*/
static bool PreviousOrderIsUnbunching(const Vehicle *v)
{
/* If we are headed for the first order, we must wrap around back to the last order. */
bool is_first_order = (v->GetOrder(v->cur_real_order_index) == v->GetFirstOrder());
Order *previous_order = (is_first_order) ? v->GetLastOrder() : v->GetOrder(v->cur_real_order_index - 1);
if (previous_order == nullptr || !previous_order->IsType(OT_GOTO_DEPOT)) return false;
return (previous_order->GetDepotActionType() & ODATFB_UNBUNCH) != 0;
}
/**
* Leave an unbunching depot and calculate the next departure time for shared order vehicles.
*/
void Vehicle::LeaveUnbunchingDepot()
{
/* Don't do anything if this is not our unbunching order. */
if (!PreviousOrderIsUnbunching(this)) return;
if (this->unbunch_state == nullptr) this->unbunch_state.reset(new VehicleUnbunchState());
/* Set the start point for this round trip time. */
@@ -3865,13 +3882,8 @@ bool Vehicle::IsWaitingForUnbunching() const
/* Don't do anything if there aren't enough orders. */
if (this->GetNumOrders() <= 1) return false;
/*
* Make sure this is the correct depot for unbunching.
* If we are headed for the first order, we must wrap around back to the last order.
*/
bool is_first_order = (this->GetOrder(this->cur_real_order_index) == this->GetFirstOrder());
Order *previous_order = (is_first_order) ? this->GetLastOrder() : this->GetOrder(this->cur_real_order_index - 1);
if (previous_order == nullptr || !previous_order->IsType(OT_GOTO_DEPOT) || !(previous_order->GetDepotActionType() & ODATFB_UNBUNCH)) return false;
/* Don't do anything if this is not our unbunching order. */
if (!PreviousOrderIsUnbunching(this)) return false;
return (this->unbunch_state != nullptr) && (this->unbunch_state->depot_unbunching_next_departure > _state_ticks);
};