Add average travel time to the link graph overlay tooltip
This commit is contained in:
@@ -171,7 +171,9 @@ void LinkGraphOverlay::RebuildCache(bool incremental)
|
||||
item->to_pt = to_pt;
|
||||
}
|
||||
this->AddStats(c, lg.Monthly(edge.Capacity()), lg.Monthly(edge.Usage()),
|
||||
ge.flows.GetFlowVia(to->index), from->owner == OWNER_NONE || to->owner == OWNER_NONE,
|
||||
ge.flows.GetFlowVia(to->index),
|
||||
edge.TravelTime(),
|
||||
from->owner == OWNER_NONE || to->owner == OWNER_NONE,
|
||||
item->prop);
|
||||
}
|
||||
}
|
||||
@@ -345,7 +347,7 @@ inline bool LinkGraphOverlay::IsLinkVisible(Point pta, Point ptb, const DrawPixe
|
||||
* @param new_shared If the new link is shared.
|
||||
* @param cargo LinkProperties to write the information to.
|
||||
*/
|
||||
/* static */ void LinkGraphOverlay::AddStats(CargoID new_cargo, uint new_cap, uint new_usg, uint new_plan, bool new_shared, LinkProperties &cargo)
|
||||
/* static */ void LinkGraphOverlay::AddStats(CargoID new_cargo, uint new_cap, uint new_usg, uint new_plan, uint32 time, bool new_shared, LinkProperties &cargo)
|
||||
{
|
||||
/* multiply the numbers by 32 in order to avoid comparing to 0 too often. */
|
||||
if (cargo.capacity == 0 ||
|
||||
@@ -354,6 +356,7 @@ inline bool LinkGraphOverlay::IsLinkVisible(Point pta, Point ptb, const DrawPixe
|
||||
cargo.capacity = new_cap;
|
||||
cargo.usage = new_usg;
|
||||
cargo.planned = new_plan;
|
||||
cargo.time = time;
|
||||
}
|
||||
if (new_shared) cargo.shared = true;
|
||||
}
|
||||
@@ -505,20 +508,35 @@ bool LinkGraphOverlay::ShowTooltip(Point pt, TooltipCloseCondition close_cond)
|
||||
check_distance()) {
|
||||
|
||||
static char buf[1024];
|
||||
char *buf_end = buf;
|
||||
buf[0] = 0;
|
||||
|
||||
/* Fill buf with more information if this is a bidirectional link. */
|
||||
uint32 back_time = 0;
|
||||
for (LinkList::const_reverse_iterator j = std::next(i); j != this->cached_links.rend(); ++j) {
|
||||
if (j->from_id == i->to_id && j->to_id == i->from_id) {
|
||||
back_time = j->prop.time;
|
||||
if (j->prop.Usage() > 0) {
|
||||
SetDParam(0, j->prop.cargo);
|
||||
SetDParam(1, j->prop.Usage());
|
||||
SetDParam(2, j->prop.Usage() * 100 / (j->prop.capacity + 1));
|
||||
GetString(buf, STR_LINKGRAPH_STATS_TOOLTIP_RETURN_EXTENSION, lastof(buf));
|
||||
buf_end = GetString(buf, STR_LINKGRAPH_STATS_TOOLTIP_RETURN_EXTENSION, lastof(buf));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* Add information about the travel time if known. */
|
||||
const uint32 time = link.time ? (back_time ? ((link.time + back_time) / 2) : link.time) : back_time;
|
||||
if (time > 0) {
|
||||
if (_settings_time.time_in_minutes) {
|
||||
SetDParam(0, STR_TIMETABLE_MINUTES);
|
||||
SetDParam(1, time / _settings_time.ticks_per_minute);
|
||||
buf_end = GetString(buf_end, STR_LINKGRAPH_STATS_TOOLTIP_TIME_EXTENSION_GENERAL, lastof(buf));
|
||||
} else {
|
||||
SetDParam(0, time / (DAY_TICKS * _settings_game.economy.day_length_factor));
|
||||
buf_end = GetString(buf_end, STR_LINKGRAPH_STATS_TOOLTIP_TIME_EXTENSION, lastof(buf));
|
||||
}
|
||||
}
|
||||
|
||||
SetDParam(0, link.cargo);
|
||||
SetDParam(1, link.Usage());
|
||||
|
@@ -23,7 +23,7 @@
|
||||
* Only the cargo type of the most saturated linkgraph is taken into account.
|
||||
*/
|
||||
struct LinkProperties {
|
||||
LinkProperties() : capacity(0), usage(0), planned(0), cargo(CT_INVALID), shared(false) {}
|
||||
LinkProperties() : capacity(0), usage(0), planned(0), cargo(CT_INVALID), time(0), shared(false) {}
|
||||
|
||||
/** Return the usage of the link to display. */
|
||||
uint Usage() const { return std::max(this->usage, this->planned); }
|
||||
@@ -32,6 +32,7 @@ struct LinkProperties {
|
||||
uint usage; ///< Actual usage of the link.
|
||||
uint planned; ///< Planned usage of the link.
|
||||
CargoID cargo; ///< Cargo type of the link.
|
||||
uint32 time; ///< Travel time of the link.
|
||||
bool shared; ///< If this is a shared link to be drawn dashed.
|
||||
};
|
||||
|
||||
@@ -112,7 +113,7 @@ protected:
|
||||
bool IsPointVisible(Point pt, const DrawPixelInfo *dpi, int padding = 0) const;
|
||||
void GetWidgetDpi(DrawPixelInfo *dpi, uint margin = 0) const;
|
||||
|
||||
static void AddStats(CargoID new_cargo, uint new_cap, uint new_usg, uint new_flow, bool new_shared, LinkProperties &cargo);
|
||||
static void AddStats(CargoID new_cargo, uint new_cap, uint new_usg, uint new_plan, uint32 time, bool new_shared, LinkProperties &cargo);
|
||||
static void DrawVertex(int x, int y, int size, int colour, int border_colour);
|
||||
};
|
||||
|
||||
|
@@ -313,9 +313,7 @@ void MultiCommodityFlow::Dijkstra(NodeID source_node, PathVector &paths)
|
||||
/* Prioritize the fastest route for passengers, mail and express cargo,
|
||||
* and the shortest route for other classes of cargo.
|
||||
* In-between stops are punished with a 1 tile or 1 day penalty. */
|
||||
bool express = IsCargoInClass(this->job.Cargo(), CC_PASSENGERS) ||
|
||||
IsCargoInClass(this->job.Cargo(), CC_MAIL) ||
|
||||
IsCargoInClass(this->job.Cargo(), CC_EXPRESS);
|
||||
bool express = IsLinkGraphCargoExpress(this->job.Cargo());
|
||||
|
||||
auto calculate_distance = [&]() {
|
||||
return DistanceMaxPlusManhattan(this->job[from].XY(), this->job[to].XY()) + 1;
|
||||
|
@@ -89,4 +89,11 @@ public:
|
||||
virtual ~MCFHandler() {}
|
||||
};
|
||||
|
||||
inline bool IsLinkGraphCargoExpress(CargoID cargo)
|
||||
{
|
||||
return IsCargoInClass(cargo, CC_PASSENGERS) ||
|
||||
IsCargoInClass(cargo, CC_MAIL) ||
|
||||
IsCargoInClass(cargo, CC_EXPRESS);
|
||||
}
|
||||
|
||||
#endif /* MCF_H */
|
||||
|
Reference in New Issue
Block a user