diff options
author | Nicolas Chappe <74881848+nchappe@users.noreply.github.com> | 2021-07-24 11:07:10 +0200 |
---|---|---|
committer | Michael Lutz <michi@icosahedron.de> | 2021-08-17 14:57:59 +0200 |
commit | 977604ef08212cc93653eaa8187ab64ebe72e7d2 (patch) | |
tree | 5aa86c084ebee29497147fa8008855acf572977b /src/linkgraph/refresh.cpp | |
parent | 6acf204d14343e67fdc01ae8c52044d0de20bbd2 (diff) | |
download | openttd-977604ef08212cc93653eaa8187ab64ebe72e7d2.tar.xz |
Feature: [Linkgraph] Prioritize faster routes for passengers, mail and express cargo
Passengers usually prefer fast paths to short paths.
Average travel times of links are updated in real-time for use in Dijkstra's algorithm,
and newer travel times weigh more, just like capacities.
Diffstat (limited to 'src/linkgraph/refresh.cpp')
-rw-r--r-- | src/linkgraph/refresh.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/linkgraph/refresh.cpp b/src/linkgraph/refresh.cpp index 430e29072..78fdd1643 100644 --- a/src/linkgraph/refresh.cpp +++ b/src/linkgraph/refresh.cpp @@ -218,6 +218,12 @@ void LinkRefresher::RefreshStats(const Order *cur, const Order *next) /* A link is at least partly restricted if a vehicle can't load at its source. */ EdgeUpdateMode restricted_mode = (cur->GetLoadType() & OLFB_NO_LOAD) == 0 ? EUM_UNRESTRICTED : EUM_RESTRICTED; + Station *st_to = Station::GetIfValid(next_station); + /* This estimates the travel time of the link as the time needed + * to travel between the stations at half the max speed of the consist. + * The result is in tiles/tick (= 2048 km-ish/h). */ + uint32 time_estimate = (st_to != nullptr) ? + DistanceManhattan(st->xy, st_to->xy) * 4096U / this->vehicle->GetDisplayMaxSpeed() : 0; /* If the vehicle is currently full loading, increase the capacities at the station * where it is loading by an estimate of what it would have transported if it wasn't @@ -231,15 +237,15 @@ void LinkRefresher::RefreshStats(const Order *cur, const Order *next) uint effective_capacity = cargo_quantity * this->vehicle->load_unload_ticks; if (effective_capacity > (uint)this->vehicle->orders.list->GetTotalDuration()) { IncreaseStats(st, c, next_station, effective_capacity / - this->vehicle->orders.list->GetTotalDuration(), 0, + this->vehicle->orders.list->GetTotalDuration(), 0, 0, EUM_INCREASE | restricted_mode); } else if (RandomRange(this->vehicle->orders.list->GetTotalDuration()) < effective_capacity) { - IncreaseStats(st, c, next_station, 1, 0, EUM_INCREASE | restricted_mode); + IncreaseStats(st, c, next_station, 1, 0, 0, EUM_INCREASE | restricted_mode); } else { - IncreaseStats(st, c, next_station, cargo_quantity, 0, EUM_REFRESH | restricted_mode); + IncreaseStats(st, c, next_station, cargo_quantity, 0, time_estimate, EUM_REFRESH | restricted_mode); } } else { - IncreaseStats(st, c, next_station, cargo_quantity, 0, EUM_REFRESH | restricted_mode); + IncreaseStats(st, c, next_station, cargo_quantity, 0, time_estimate, EUM_REFRESH | restricted_mode); } } } |