Add order occupancy average.

Show overall average instead of % char in toggle button.
Add a sort mode.
This commit is contained in:
Jonathan G Rennison
2016-01-24 02:51:40 +00:00
parent 0cf7428f85
commit 2955610575
5 changed files with 62 additions and 5 deletions

View File

@@ -2130,6 +2130,7 @@ void Vehicle::LeaveStation()
new_occupancy /= 100;
}
if (new_occupancy + 1 != old_occupancy) {
this->order_occupancy_average = 0;
real_current_order->SetOccupancy(static_cast<uint8>(new_occupancy + 1));
for (const Vehicle *v = this->FirstShared(); v != NULL; v = v->NextShared()) {
SetWindowDirty(WC_VEHICLE_ORDERS, v->index);
@@ -2140,6 +2141,25 @@ void Vehicle::LeaveStation()
this->MarkDirty();
}
void Vehicle::RecalculateOrderOccupancyAverage()
{
uint num_valid = 0;
uint total = 0;
uint order_count = this->GetNumOrders();
for (uint i = 0; i < order_count; i++) {
uint occupancy = this->GetOrder(i)->GetOccupancy();
if (occupancy > 0) {
num_valid++;
total += (occupancy - 1);
}
}
if (num_valid > 0) {
this->order_occupancy_average = 16 + ((total + (num_valid / 2)) / num_valid);
} else {
this->order_occupancy_average = 1;
}
}
/**
* Reset all refit_cap in the consist to cargo_cap.
*/