Last active
March 4, 2018 13:12
-
-
Save LordAro/2ba97e450f04875f49f4186625df254b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BasedOnStyle: LLVM | |
IndentWidth: 8 | |
UseTab: ForContinuationAndIndentation | |
Cpp11BracedListStyle: false | |
ColumnLimit: 120 | |
CommentPragmas: '(part of OpenTTD|General Public License|WITHOUT ANY WARRANTY)' | |
BreakBeforeBraces: Custom | |
BraceWrapping: | |
AfterControlStatement: false | |
AfterClass: false | |
AfterEnum: false | |
AfterFunction: true | |
AfterNamespace: true | |
AfterStruct: false | |
SplitEmptyRecord: true | |
ForEachMacros: | |
- FOR_ALL_AIRCRAFT | |
- FOR_ALL_STATIONS | |
- FOR_ALL_WINDOWS_FROM_BACK | |
- FOR_EACH_SET_CARGO_ID | |
AllowShortBlocksOnASingleLine: true | |
AllowShortFunctionsOnASingleLine: Inline | |
AllowShortIfStatementsOnASingleLine: true | |
AllowShortLoopsOnASingleLine: true | |
AlwaysBreakTemplateDeclarations: true | |
AlignEscapedNewlines: Left | |
IndentCaseLabels: true | |
IncludeCategories: | |
- Regex: 'stdafx.h' | |
Priority: -1 | |
- Regex: '.*' | |
Priority: 1 | |
AccessModifierOffset: -8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/linkgraph/demands.cpp b/src/linkgraph/demands.cpp | |
index f4afbabf0..97527e656 100644 | |
--- a/src/linkgraph/demands.cpp | |
+++ b/src/linkgraph/demands.cpp | |
@@ -26,18 +26,13 @@ public: | |
* @param mod_size Size modifier to be used. Determines how much demands | |
* increase with the supply of the remote station. | |
*/ | |
- inline SymmetricScaler(uint mod_size) : mod_size(mod_size), supply_sum(0), | |
- demand_per_node(0) | |
- {} | |
+ inline SymmetricScaler(uint mod_size) : mod_size(mod_size), supply_sum(0), demand_per_node(0) {} | |
/** | |
* Count a node's supply into the sum of supplies. | |
* @param node Node. | |
*/ | |
- inline void AddNode(const Node &node) | |
- { | |
- this->supply_sum += node.Supply(); | |
- } | |
+ inline void AddNode(const Node &node) { this->supply_sum += node.Supply(); } | |
/** | |
* Calculate the mean demand per node using the sum of supplies. | |
@@ -75,8 +70,8 @@ public: | |
void SetDemands(LinkGraphJob &job, NodeID from, NodeID to, uint demand_forw); | |
private: | |
- uint mod_size; ///< Size modifier. Determines how much demands increase with the supply of the remote station. | |
- uint supply_sum; ///< Sum of all supplies in the component. | |
+ uint mod_size; ///< Size modifier. Determines how much demands increase with the supply of the remote station. | |
+ uint supply_sum; ///< Sum of all supplies in the component. | |
uint demand_per_node; ///< Mean demand associated with each node. | |
}; | |
@@ -89,27 +84,20 @@ public: | |
* Nothing to do here. | |
* @param unused. | |
*/ | |
- inline void AddNode(const Node &) | |
- { | |
- } | |
+ inline void AddNode(const Node &) {} | |
/** | |
* Nothing to do here. | |
* @param unused. | |
*/ | |
- inline void SetDemandPerNode(uint) | |
- { | |
- } | |
+ inline void SetDemandPerNode(uint) {} | |
/** | |
* Get the effective supply of one node towards another one. | |
* @param from The supplying node. | |
* @param unused. | |
*/ | |
- inline uint EffectiveSupply(const Node &from, const Node &) | |
- { | |
- return from.Supply(); | |
- } | |
+ inline uint EffectiveSupply(const Node &from, const Node &) { return from.Supply(); } | |
/** | |
* Check if there is any acceptance left for this node. In asymmetric distribution | |
@@ -161,7 +149,7 @@ inline void Scaler::SetDemands(LinkGraphJob &job, NodeID from_id, NodeID to_id, | |
* @param job Job to calculate the demands for. | |
* @tparam Tscaler Scaler to be used for scaling demands. | |
*/ | |
-template<class Tscaler> | |
+template <class Tscaler> | |
void DemandCalculator::CalcDemand(LinkGraphJob &job, Tscaler scaler) | |
{ | |
NodeList supplies; | |
@@ -209,9 +197,10 @@ void DemandCalculator::CalcDemand(LinkGraphJob &job, Tscaler scaler) | |
assert(supply > 0); | |
/* Scale the distance by mod_dist around max_distance */ | |
- int32 distance = this->max_distance - (this->max_distance - | |
- (int32)DistanceMaxPlusManhattan(job[from_id].XY(), job[to_id].XY())) * | |
- this->mod_dist / 100; | |
+ int32 distance = | |
+ this->max_distance - | |
+ (this->max_distance - (int32)DistanceMaxPlusManhattan(job[from_id].XY(), job[to_id].XY())) * | |
+ this->mod_dist / 100; | |
/* Scale the accuracy by distance around accuracy / 2 */ | |
int32 divisor = this->accuracy * (this->mod_dist - 50) / 100 + | |
@@ -256,8 +245,8 @@ void DemandCalculator::CalcDemand(LinkGraphJob &job, Tscaler scaler) | |
* Create the DemandCalculator and immediately do the calculation. | |
* @param job Job to calculate the demands for. | |
*/ | |
-DemandCalculator::DemandCalculator(LinkGraphJob &job) : | |
- max_distance(DistanceMaxPlusManhattan(TileXY(0,0), TileXY(MapMaxX(), MapMaxY()))) | |
+DemandCalculator::DemandCalculator(LinkGraphJob &job) | |
+ : max_distance(DistanceMaxPlusManhattan(TileXY(0, 0), TileXY(MapMaxX(), MapMaxY()))) | |
{ | |
const LinkGraphSettings &settings = job.Settings(); | |
CargoID cargo = job.Cargo(); | |
diff --git a/src/linkgraph/linkgraph.cpp b/src/linkgraph/linkgraph.cpp | |
index 50945d361..4d71a0e28 100644 | |
--- a/src/linkgraph/linkgraph.cpp | |
+++ b/src/linkgraph/linkgraph.cpp | |
@@ -10,8 +10,8 @@ | |
/** @file linkgraph.cpp Definition of link graph classes used for cargo distribution. */ | |
#include "../stdafx.h" | |
-#include "../core/pool_func.hpp" | |
#include "linkgraph.h" | |
+#include "../core/pool_func.hpp" | |
#include "../safeguards.h" | |
@@ -162,11 +162,9 @@ NodeID LinkGraph::AddNode(const Station *st) | |
this->nodes.Append(); | |
/* Avoid reducing the height of the matrix as that is expensive and we | |
* most likely will increase it again later which is again expensive. */ | |
- this->edges.Resize(new_node + 1U, | |
- max(new_node + 1U, this->edges.Height())); | |
+ this->edges.Resize(new_node + 1U, max(new_node + 1U, this->edges.Height())); | |
- this->nodes[new_node].Init(st->xy, st->index, | |
- HasBit(good.status, GoodsEntry::GES_ACCEPTANCE)); | |
+ this->nodes[new_node].Init(st->xy, st->index, HasBit(good.status, GoodsEntry::GES_ACCEPTANCE)); | |
BaseEdge *new_edges = this->edges[new_node]; | |
@@ -197,7 +195,7 @@ void LinkGraph::Node::AddEdge(NodeID to, uint capacity, uint usage, EdgeUpdateMo | |
edge.usage = usage; | |
edge.next_edge = first.next_edge; | |
first.next_edge = to; | |
- if (mode & EUM_UNRESTRICTED) edge.last_unrestricted_update = _date; | |
+ if (mode & EUM_UNRESTRICTED) edge.last_unrestricted_update = _date; | |
if (mode & EUM_RESTRICTED) edge.last_restricted_update = _date; | |
} | |
diff --git a/src/linkgraph/linkgraph_gui.cpp b/src/linkgraph/linkgraph_gui.cpp | |
index 1fe34fe79..c858a304d 100644 | |
--- a/src/linkgraph/linkgraph_gui.cpp | |
+++ b/src/linkgraph/linkgraph_gui.cpp | |
@@ -10,15 +10,15 @@ | |
/** @file linkgraph_gui.cpp Implementation of linkgraph overlay GUI. */ | |
#include "../stdafx.h" | |
-#include "../window_gui.h" | |
-#include "../window_func.h" | |
#include "../company_base.h" | |
#include "../company_gui.h" | |
+#include "../core/geometry_func.hpp" | |
#include "../date_func.h" | |
-#include "../viewport_func.h" | |
#include "../smallmap_gui.h" | |
-#include "../core/geometry_func.hpp" | |
+#include "../viewport_func.h" | |
#include "../widgets/link_graph_legend_widget.h" | |
+#include "../window_func.h" | |
+#include "../window_gui.h" | |
#include "table/strings.h" | |
@@ -29,9 +29,7 @@ | |
* "overloaded". | |
*/ | |
const uint8 LinkGraphOverlay::LINK_COLOURS[] = { | |
- 0x0f, 0xd1, 0xd0, 0x57, | |
- 0x55, 0x53, 0xbf, 0xbd, | |
- 0xba, 0xb9, 0xb7, 0xb5 | |
+ 0x0f, 0xd1, 0xd0, 0x57, 0x55, 0x53, 0xbf, 0xbd, 0xba, 0xb9, 0xb7, 0xb5 | |
}; | |
/** | |
@@ -59,7 +57,7 @@ void LinkGraphOverlay::RebuildCache() | |
this->GetWidgetDpi(&dpi); | |
const Station *sta; | |
- FOR_ALL_STATIONS(sta) { | |
+ FOR_ALL_STATIONS (sta) { | |
if (sta->rect.IsEmpty()) continue; | |
Point pta = this->GetStationMiddle(sta); | |
@@ -69,7 +67,7 @@ void LinkGraphOverlay::RebuildCache() | |
uint supply = 0; | |
CargoID c; | |
- FOR_EACH_SET_CARGO_ID(c, this->cargo_mask) { | |
+ FOR_EACH_SET_CARGO_ID (c, this->cargo_mask) { | |
if (!CargoSpec::Get(c)->IsValid()) continue; | |
if (!LinkGraph::IsValidID(sta->goods[c].link_graph)) continue; | |
const LinkGraph &lg = *LinkGraph::Get(sta->goods[c].link_graph); | |
@@ -86,7 +84,9 @@ void LinkGraphOverlay::RebuildCache() | |
assert(sta != stb); | |
/* Show links between stations of selected companies or "neutral" ones like oilrigs. */ | |
- if (stb->owner != OWNER_NONE && sta->owner != OWNER_NONE && !HasBit(this->company_mask, stb->owner)) continue; | |
+ if (stb->owner != OWNER_NONE && sta->owner != OWNER_NONE && | |
+ !HasBit(this->company_mask, stb->owner)) | |
+ continue; | |
if (stb->rect.IsEmpty()) continue; | |
if (!this->IsLinkVisible(pta, this->GetStationMiddle(stb), &dpi)) continue; | |
@@ -110,9 +110,8 @@ void LinkGraphOverlay::RebuildCache() | |
*/ | |
inline bool LinkGraphOverlay::IsPointVisible(Point pt, const DrawPixelInfo *dpi, int padding) const | |
{ | |
- return pt.x > dpi->left - padding && pt.y > dpi->top - padding && | |
- pt.x < dpi->left + dpi->width + padding && | |
- pt.y < dpi->top + dpi->height + padding; | |
+ return pt.x > dpi->left - padding && pt.y > dpi->top - padding && pt.x < dpi->left + dpi->width + padding && | |
+ pt.y < dpi->top + dpi->height + padding; | |
} | |
/** | |
@@ -126,11 +125,9 @@ inline bool LinkGraphOverlay::IsPointVisible(Point pt, const DrawPixelInfo *dpi, | |
inline bool LinkGraphOverlay::IsLinkVisible(Point pta, Point ptb, const DrawPixelInfo *dpi, int padding) const | |
{ | |
return !((pta.x < dpi->left - padding && ptb.x < dpi->left - padding) || | |
- (pta.y < dpi->top - padding && ptb.y < dpi->top - padding) || | |
- (pta.x > dpi->left + dpi->width + padding && | |
- ptb.x > dpi->left + dpi->width + padding) || | |
- (pta.y > dpi->top + dpi->height + padding && | |
- ptb.y > dpi->top + dpi->height + padding)); | |
+ (pta.y < dpi->top - padding && ptb.y < dpi->top - padding) || | |
+ (pta.x > dpi->left + dpi->width + padding && ptb.x > dpi->left + dpi->width + padding) || | |
+ (pta.y > dpi->top + dpi->height + padding && ptb.y > dpi->top + dpi->height + padding)); | |
} | |
/** | |
@@ -141,19 +138,19 @@ inline bool LinkGraphOverlay::IsLinkVisible(Point pta, Point ptb, const DrawPixe | |
void LinkGraphOverlay::AddLinks(const Station *from, const Station *to) | |
{ | |
CargoID c; | |
- FOR_EACH_SET_CARGO_ID(c, this->cargo_mask) { | |
+ FOR_EACH_SET_CARGO_ID (c, this->cargo_mask) { | |
if (!CargoSpec::Get(c)->IsValid()) continue; | |
const GoodsEntry &ge = from->goods[c]; | |
- if (!LinkGraph::IsValidID(ge.link_graph) || | |
- ge.link_graph != to->goods[c].link_graph) { | |
+ if (!LinkGraph::IsValidID(ge.link_graph) || ge.link_graph != to->goods[c].link_graph) { | |
continue; | |
} | |
const LinkGraph &lg = *LinkGraph::Get(ge.link_graph); | |
ConstEdge edge = lg[ge.node][to->goods[c].node]; | |
if (edge.Capacity() > 0) { | |
this->AddStats(lg.Monthly(edge.Capacity()), lg.Monthly(edge.Usage()), | |
- ge.flows.GetFlowVia(to->index), from->owner == OWNER_NONE || to->owner == OWNER_NONE, | |
- this->cached_links[from->index][to->index]); | |
+ ge.flows.GetFlowVia(to->index), | |
+ from->owner == OWNER_NONE || to->owner == OWNER_NONE, | |
+ this->cached_links[from->index][to->index]); | |
} | |
} | |
} | |
@@ -168,11 +165,12 @@ void LinkGraphOverlay::AddLinks(const Station *from, const Station *to) | |
* @param new_shared If the new link is shared. | |
* @param cargo LinkProperties to write the information to. | |
*/ | |
-/* static */ void LinkGraphOverlay::AddStats(uint new_cap, uint new_usg, uint new_plan, bool new_shared, LinkProperties &cargo) | |
+/* static */ void LinkGraphOverlay::AddStats(uint new_cap, uint new_usg, uint new_plan, bool new_shared, | |
+ LinkProperties &cargo) | |
{ | |
/* multiply the numbers by 32 in order to avoid comparing to 0 too often. */ | |
if (cargo.capacity == 0 || | |
- max(cargo.usage, cargo.planned) * 32 / (cargo.capacity + 1) < max(new_usg, new_plan) * 32 / (new_cap + 1)) { | |
+ max(cargo.usage, cargo.planned) * 32 / (cargo.capacity + 1) < max(new_usg, new_plan) * 32 / (new_cap + 1)) { | |
cargo.capacity = new_cap; | |
cargo.usage = new_usg; | |
cargo.planned = new_plan; | |
@@ -217,7 +215,8 @@ void LinkGraphOverlay::DrawLinks(const DrawPixelInfo *dpi) const | |
void LinkGraphOverlay::DrawContent(Point pta, Point ptb, const LinkProperties &cargo) const | |
{ | |
uint usage_or_plan = min(cargo.capacity * 2 + 1, max(cargo.usage, cargo.planned)); | |
- int colour = LinkGraphOverlay::LINK_COLOURS[usage_or_plan * lengthof(LinkGraphOverlay::LINK_COLOURS) / (cargo.capacity * 2 + 2)]; | |
+ int colour = LinkGraphOverlay::LINK_COLOURS[usage_or_plan * lengthof(LinkGraphOverlay::LINK_COLOURS) / | |
+ (cargo.capacity * 2 + 2)]; | |
int dash = cargo.shared ? this->scale * 4 : 0; | |
/* Move line a bit 90° against its dominant direction to prevent it from | |
@@ -240,7 +239,8 @@ void LinkGraphOverlay::DrawContent(Point pta, Point ptb, const LinkProperties &c | |
*/ | |
void LinkGraphOverlay::DrawStationDots(const DrawPixelInfo *dpi) const | |
{ | |
- for (StationSupplyList::const_iterator i(this->cached_stations.begin()); i != this->cached_stations.end(); ++i) { | |
+ for (StationSupplyList::const_iterator i(this->cached_stations.begin()); i != this->cached_stations.end(); | |
+ ++i) { | |
const Station *st = Station::GetIfValid(i->first); | |
if (st == NULL) continue; | |
Point pt = this->GetStationMiddle(st); | |
@@ -248,10 +248,11 @@ void LinkGraphOverlay::DrawStationDots(const DrawPixelInfo *dpi) const | |
uint r = this->scale * 2 + this->scale * 2 * min(200, i->second) / 200; | |
- LinkGraphOverlay::DrawVertex(pt.x, pt.y, r, | |
- _colour_gradient[st->owner != OWNER_NONE ? | |
- (Colours)Company::Get(st->owner)->colour : COLOUR_GREY][5], | |
- _colour_gradient[COLOUR_GREY][1]); | |
+ LinkGraphOverlay::DrawVertex( | |
+ pt.x, pt.y, r, | |
+ _colour_gradient[st->owner != OWNER_NONE ? (Colours)Company::Get(st->owner)->colour : COLOUR_GREY] | |
+ [5], | |
+ _colour_gradient[COLOUR_GREY][1]); | |
} | |
} | |
@@ -319,14 +320,16 @@ void LinkGraphOverlay::SetCompanyMask(uint32 company_mask) | |
/** Make a number of rows with buttons for each company for the linkgraph legend window. */ | |
NWidgetBase *MakeCompanyButtonRowsLinkGraphGUI(int *biggest_index) | |
{ | |
- return MakeCompanyButtonRows(biggest_index, WID_LGL_COMPANY_FIRST, WID_LGL_COMPANY_LAST, 3, STR_LINKGRAPH_LEGEND_SELECT_COMPANIES); | |
+ return MakeCompanyButtonRows(biggest_index, WID_LGL_COMPANY_FIRST, WID_LGL_COMPANY_LAST, 3, | |
+ STR_LINKGRAPH_LEGEND_SELECT_COMPANIES); | |
} | |
NWidgetBase *MakeSaturationLegendLinkGraphGUI(int *biggest_index) | |
{ | |
NWidgetVertical *panel = new NWidgetVertical(NC_EQUALSIZE); | |
for (uint i = 0; i < lengthof(LinkGraphOverlay::LINK_COLOURS); ++i) { | |
- NWidgetBackground * wid = new NWidgetBackground(WWT_PANEL, COLOUR_DARK_GREEN, i + WID_LGL_SATURATION_FIRST); | |
+ NWidgetBackground *wid = | |
+ new NWidgetBackground(WWT_PANEL, COLOUR_DARK_GREEN, i + WID_LGL_SATURATION_FIRST); | |
wid->SetMinimalSize(50, FONT_HEIGHT_SMALL); | |
wid->SetFill(1, 1); | |
wid->SetResize(0, 0); | |
@@ -346,7 +349,7 @@ NWidgetBase *MakeCargoesLegendLinkGraphGUI(int *biggest_index) | |
if (row) panel->Add(row); | |
row = new NWidgetHorizontal(NC_EQUALSIZE); | |
} | |
- NWidgetBackground * wid = new NWidgetBackground(WWT_PANEL, COLOUR_GREY, i + WID_LGL_CARGO_FIRST); | |
+ NWidgetBackground *wid = new NWidgetBackground(WWT_PANEL, COLOUR_GREY, i + WID_LGL_CARGO_FIRST); | |
wid->SetMinimalSize(25, FONT_HEIGHT_SMALL); | |
wid->SetFill(1, 1); | |
wid->SetResize(0, 0); | |
@@ -364,7 +367,7 @@ NWidgetBase *MakeCargoesLegendLinkGraphGUI(int *biggest_index) | |
return panel; | |
} | |
- | |
+/* clang-format off */ | |
static const NWidgetPart _nested_linkgraph_legend_widgets[] = { | |
NWidget(NWID_HORIZONTAL), | |
NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN), | |
@@ -397,16 +400,12 @@ static const NWidgetPart _nested_linkgraph_legend_widgets[] = { | |
EndContainer(), | |
EndContainer() | |
}; | |
+/* clang-format on */ | |
-assert_compile(WID_LGL_SATURATION_LAST - WID_LGL_SATURATION_FIRST == | |
- lengthof(LinkGraphOverlay::LINK_COLOURS) - 1); | |
+assert_compile(WID_LGL_SATURATION_LAST - WID_LGL_SATURATION_FIRST == lengthof(LinkGraphOverlay::LINK_COLOURS) - 1); | |
-static WindowDesc _linkgraph_legend_desc( | |
- WDP_AUTO, "toolbar_linkgraph", 0, 0, | |
- WC_LINKGRAPH_LEGEND, WC_NONE, | |
- 0, | |
- _nested_linkgraph_legend_widgets, lengthof(_nested_linkgraph_legend_widgets) | |
-); | |
+static WindowDesc _linkgraph_legend_desc(WDP_AUTO, "toolbar_linkgraph", 0, 0, WC_LINKGRAPH_LEGEND, WC_NONE, 0, | |
+ _nested_linkgraph_legend_widgets, lengthof(_nested_linkgraph_legend_widgets)); | |
/** | |
* Open a link graph legend window. | |
@@ -427,7 +426,8 @@ LinkGraphLegendWindow::LinkGraphLegendWindow(WindowDesc *desc, int window_number | |
* Set the overlay belonging to this menu and import its company/cargo settings. | |
* @params overlay New overlay for this menu. | |
*/ | |
-void LinkGraphLegendWindow::SetOverlay(LinkGraphOverlay *overlay) { | |
+void LinkGraphLegendWindow::SetOverlay(LinkGraphOverlay *overlay) | |
+{ | |
this->overlay = overlay; | |
uint32 companies = this->overlay->GetCompanyMask(); | |
for (uint c = 0; c < MAX_COMPANIES; c++) { | |
@@ -443,7 +443,8 @@ void LinkGraphLegendWindow::SetOverlay(LinkGraphOverlay *overlay) { | |
} | |
} | |
-void LinkGraphLegendWindow::UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) | |
+void LinkGraphLegendWindow::UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, | |
+ Dimension *resize) | |
{ | |
if (IsInsideMM(widget, WID_LGL_SATURATION_FIRST, WID_LGL_SATURATION_LAST + 1)) { | |
StringID str = STR_NULL; | |
@@ -478,10 +479,12 @@ void LinkGraphLegendWindow::DrawWidget(const Rect &r, int widget) const | |
if (this->IsWidgetDisabled(widget)) return; | |
CompanyID cid = (CompanyID)(widget - WID_LGL_COMPANY_FIRST); | |
Dimension sprite_size = GetSpriteSize(SPR_COMPANY_ICON); | |
- DrawCompanyIcon(cid, (r.left + r.right + 1 - sprite_size.width) / 2, (r.top + r.bottom + 1 - sprite_size.height) / 2); | |
+ DrawCompanyIcon(cid, (r.left + r.right + 1 - sprite_size.width) / 2, | |
+ (r.top + r.bottom + 1 - sprite_size.height) / 2); | |
} | |
if (IsInsideMM(widget, WID_LGL_SATURATION_FIRST, WID_LGL_SATURATION_LAST + 1)) { | |
- GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, LinkGraphOverlay::LINK_COLOURS[widget - WID_LGL_SATURATION_FIRST]); | |
+ GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, | |
+ LinkGraphOverlay::LINK_COLOURS[widget - WID_LGL_SATURATION_FIRST]); | |
StringID str = STR_NULL; | |
if (widget == WID_LGL_SATURATION_FIRST) { | |
str = STR_LINKGRAPH_LEGEND_UNUSED; | |
@@ -490,13 +493,16 @@ void LinkGraphLegendWindow::DrawWidget(const Rect &r, int widget) const | |
} else if (widget == (WID_LGL_SATURATION_LAST + WID_LGL_SATURATION_FIRST) / 2) { | |
str = STR_LINKGRAPH_LEGEND_SATURATED; | |
} | |
- if (str != STR_NULL) DrawString(r.left, r.right, (r.top + r.bottom + 1 - FONT_HEIGHT_SMALL) / 2, str, TC_FROMSTRING, SA_HOR_CENTER); | |
+ if (str != STR_NULL) | |
+ DrawString(r.left, r.right, (r.top + r.bottom + 1 - FONT_HEIGHT_SMALL) / 2, str, TC_FROMSTRING, | |
+ SA_HOR_CENTER); | |
} | |
if (IsInsideMM(widget, WID_LGL_CARGO_FIRST, WID_LGL_CARGO_LAST + 1)) { | |
if (this->IsWidgetDisabled(widget)) return; | |
CargoSpec *cargo = CargoSpec::Get(widget - WID_LGL_CARGO_FIRST); | |
GfxFillRect(r.left + 2, r.top + 2, r.right - 2, r.bottom - 2, cargo->legend_colour); | |
- DrawString(r.left, r.right, (r.top + r.bottom + 1 - FONT_HEIGHT_SMALL) / 2, cargo->abbrev, TC_BLACK, SA_HOR_CENTER); | |
+ DrawString(r.left, r.right, (r.top + r.bottom + 1 - FONT_HEIGHT_SMALL) / 2, cargo->abbrev, TC_BLACK, | |
+ SA_HOR_CENTER); | |
} | |
} | |
diff --git a/src/linkgraph/linkgraphjob.cpp b/src/linkgraph/linkgraphjob.cpp | |
index 537303cf3..ce5918998 100644 | |
--- a/src/linkgraph/linkgraphjob.cpp | |
+++ b/src/linkgraph/linkgraphjob.cpp | |
@@ -10,9 +10,9 @@ | |
/** @file linkgraphjob.cpp Definition of link graph job classes used for cargo distribution. */ | |
#include "../stdafx.h" | |
+#include "linkgraphjob.h" | |
#include "../core/pool_func.hpp" | |
#include "../window_func.h" | |
-#include "linkgraphjob.h" | |
#include "linkgraphschedule.h" | |
#include "../safeguards.h" | |
@@ -34,13 +34,11 @@ INSTANTIATE_POOL_METHODS(LinkGraphJob) | |
* original. The job is immediately started. | |
* @param orig Original LinkGraph to be copied. | |
*/ | |
-LinkGraphJob::LinkGraphJob(const LinkGraph &orig) : | |
- /* Copying the link graph here also copies its index member. | |
- * This is on purpose. */ | |
- link_graph(orig), | |
- settings(_settings_game.linkgraph), | |
- thread(NULL), | |
- join_date(_date + _settings_game.linkgraph.recalc_time) | |
+LinkGraphJob::LinkGraphJob(const LinkGraph &orig) | |
+ : /* Copying the link graph here also copies its index member. | |
+ * This is on purpose. */ | |
+ link_graph(orig), settings(_settings_game.linkgraph), thread(NULL), | |
+ join_date(_date + _settings_game.linkgraph.recalc_time) | |
{ | |
} | |
@@ -127,8 +125,8 @@ LinkGraphJob::~LinkGraphJob() | |
StationID to = (*this)[it->first].Station(); | |
Station *st2 = Station::GetIfValid(to); | |
if (st2 == NULL || st2->goods[this->Cargo()].link_graph != this->link_graph.index || | |
- st2->goods[this->Cargo()].node != it->first || | |
- (*lg)[node_id][it->first].LastUpdate() == INVALID_DATE) { | |
+ st2->goods[this->Cargo()].node != it->first || | |
+ (*lg)[node_id][it->first].LastUpdate() == INVALID_DATE) { | |
/* Edge has been removed. Delete flows. */ | |
StationIDStack erased = flows.DeleteFlows(to); | |
/* Delete old flows for source stations which have been deleted | |
@@ -156,7 +154,7 @@ LinkGraphJob::~LinkGraphJob() | |
it->second.SwapShares(shares); | |
ge.flows.erase(it++); | |
for (FlowStat::SharesMap::const_iterator shares_it(shares.GetShares()->begin()); | |
- shares_it != shares.GetShares()->end(); ++shares_it) { | |
+ shares_it != shares.GetShares()->end(); ++shares_it) { | |
RerouteCargo(st, this->Cargo(), shares_it->second, st->index); | |
} | |
} | |
@@ -269,11 +267,8 @@ uint Path::AddFlow(uint new_flow, LinkGraphJob &job, uint max_saturation) | |
* @param n Id of the link graph node this path passes. | |
* @param source If true, this is the first leg of the path. | |
*/ | |
-Path::Path(NodeID n, bool source) : | |
- distance(source ? 0 : UINT_MAX), | |
- capacity(source ? UINT_MAX : 0), | |
- free_capacity(source ? INT_MAX : INT_MIN), | |
- flow(0), node(n), origin(source ? n : INVALID_NODE), | |
- num_children(0), parent(NULL) | |
-{} | |
- | |
+Path::Path(NodeID n, bool source) | |
+ : distance(source ? 0 : UINT_MAX), capacity(source ? UINT_MAX : 0), free_capacity(source ? INT_MAX : INT_MIN), | |
+ flow(0), node(n), origin(source ? n : INVALID_NODE), num_children(0), parent(NULL) | |
+{ | |
+} | |
diff --git a/src/linkgraph/linkgraphschedule.cpp b/src/linkgraph/linkgraphschedule.cpp | |
index a65783a5e..b02e3bd72 100644 | |
--- a/src/linkgraph/linkgraphschedule.cpp | |
+++ b/src/linkgraph/linkgraphschedule.cpp | |
@@ -11,10 +11,10 @@ | |
#include "../stdafx.h" | |
#include "linkgraphschedule.h" | |
-#include "init.h" | |
#include "demands.h" | |
-#include "mcf.h" | |
#include "flowmapper.h" | |
+#include "init.h" | |
+#include "mcf.h" | |
#include "../safeguards.h" | |
@@ -154,5 +154,3 @@ void OnTick_LinkGraph() | |
LinkGraphSchedule::instance.JoinNext(); | |
} | |
} | |
- | |
- | |
diff --git a/src/linkgraph/mcf.cpp b/src/linkgraph/mcf.cpp | |
index ecdf792af..ff08e9890 100644 | |
--- a/src/linkgraph/mcf.cpp | |
+++ b/src/linkgraph/mcf.cpp | |
@@ -1,8 +1,8 @@ | |
/** @file mcf.cpp Definition of Multi-Commodity-Flow solver. */ | |
#include "../stdafx.h" | |
-#include "../core/math_func.hpp" | |
#include "mcf.h" | |
+#include "../core/math_func.hpp" | |
#include <set> | |
#include "../safeguards.h" | |
@@ -16,7 +16,6 @@ typedef std::map<NodeID, Path *> PathViaMap; | |
*/ | |
class DistanceAnnotation : public Path { | |
public: | |
- | |
/** | |
* Constructor. | |
* @param n ID of node to be annotated. | |
@@ -35,7 +34,7 @@ public: | |
/** | |
* Update the cached annotation value | |
*/ | |
- inline void UpdateAnnotation() { } | |
+ inline void UpdateAnnotation() {} | |
/** | |
* Comparator for std containers. | |
@@ -55,7 +54,6 @@ class CapacityAnnotation : public Path { | |
int cached_annotation; | |
public: | |
- | |
/** | |
* Constructor. | |
* @param n ID of node to be annotated. | |
@@ -74,10 +72,7 @@ public: | |
/** | |
* Update the cached annotation value | |
*/ | |
- inline void UpdateAnnotation() | |
- { | |
- this->cached_annotation = this->GetCapacityRatio(); | |
- } | |
+ inline void UpdateAnnotation() { this->cached_annotation = this->GetCapacityRatio(); } | |
/** | |
* Comparator for std containers. | |
@@ -98,14 +93,11 @@ private: | |
EdgeIterator end; ///< Iterator pointing beyond last edge. | |
public: | |
- | |
/** | |
* Construct a GraphEdgeIterator. | |
* @param job Job to iterate on. | |
*/ | |
- GraphEdgeIterator(LinkGraphJob &job) : job(job), | |
- i(NULL, NULL, INVALID_NODE), end(NULL, NULL, INVALID_NODE) | |
- {} | |
+ GraphEdgeIterator(LinkGraphJob &job) : job(job), i(NULL, NULL, INVALID_NODE), end(NULL, NULL, INVALID_NODE) {} | |
/** | |
* Setup the node to start iterating at. | |
@@ -122,10 +114,7 @@ public: | |
* Retrieve the ID of the node the next edge points to. | |
* @return Next edge's target node ID or INVALID_NODE. | |
*/ | |
- NodeID Next() | |
- { | |
- return this->i != this->end ? (this->i++)->first : INVALID_NODE; | |
- } | |
+ NodeID Next() { return this->i != this->end ? (this->i++)->first : INVALID_NODE; } | |
}; | |
/** | |
@@ -143,8 +132,8 @@ private: | |
/** End of the shares map. */ | |
FlowStat::SharesMap::const_iterator end; | |
-public: | |
+public: | |
/** | |
* Constructor. | |
* @param job Link graph job to work with. | |
@@ -198,8 +187,7 @@ public: | |
* @return True if base + the new edge would be better than the path associated | |
* with this annotation. | |
*/ | |
-bool DistanceAnnotation::IsBetter(const DistanceAnnotation *base, uint cap, | |
- int free_cap, uint dist) const | |
+bool DistanceAnnotation::IsBetter(const DistanceAnnotation *base, uint cap, int free_cap, uint dist) const | |
{ | |
/* If any of the paths is disconnected, the other one is better. If both | |
* are disconnected, this path is better.*/ | |
@@ -232,8 +220,7 @@ bool DistanceAnnotation::IsBetter(const DistanceAnnotation *base, uint cap, | |
* @return True if base + the new edge would be better than the path associated | |
* with this annotation. | |
*/ | |
-bool CapacityAnnotation::IsBetter(const CapacityAnnotation *base, uint cap, | |
- int free_cap, uint dist) const | |
+bool CapacityAnnotation::IsBetter(const CapacityAnnotation *base, uint cap, int free_cap, uint dist) const | |
{ | |
int min_cap = Path::GetCapacityRatio(min(base->free_capacity, free_cap), min(base->capacity, cap)); | |
int this_cap = this->GetCapacityRatio(); | |
@@ -255,7 +242,7 @@ bool CapacityAnnotation::IsBetter(const CapacityAnnotation *base, uint cap, | |
* @param source_node Node where the algorithm starts. | |
* @param paths Container for the paths to be calculated. | |
*/ | |
-template<class Tannotation, class Tedge_iterator> | |
+template <class Tannotation, class Tedge_iterator> | |
void MultiCommodityFlow::Dijkstra(NodeID source_node, PathVector &paths) | |
{ | |
typedef std::set<Tannotation *, typename Tannotation::Comparator> AnnoSet; | |
@@ -333,8 +320,7 @@ void MultiCommodityFlow::CleanupPaths(NodeID source_id, PathVector &paths) | |
* @param max_saturation If < UINT_MAX only push flow up to the given | |
* saturation, otherwise the path can be "overloaded". | |
*/ | |
-uint MultiCommodityFlow::PushFlow(Edge &edge, Path *path, uint accuracy, | |
- uint max_saturation) | |
+uint MultiCommodityFlow::PushFlow(Edge &edge, Path *path, uint accuracy, uint max_saturation) | |
{ | |
assert(edge.UnsatisfiedDemand() > 0); | |
uint flow = Clamp(edge.Demand() / accuracy, 1, edge.UnsatisfiedDemand()); | |
@@ -435,8 +421,7 @@ bool MCF1stPass::EliminateCycles(PathVector &path, NodeID origin_id, NodeID next | |
} | |
bool found = false; | |
/* Search the next hops for nodes we have already visited */ | |
- for (PathViaMap::iterator via_it = next_hops.begin(); | |
- via_it != next_hops.end(); ++via_it) { | |
+ for (PathViaMap::iterator via_it = next_hops.begin(); via_it != next_hops.end(); ++via_it) { | |
Path *child = via_it->second; | |
if (child->GetFlow() > 0) { | |
/* Push one child into the path vector and search this child's | |
@@ -509,13 +494,13 @@ MCF1stPass::MCF1stPass(LinkGraphJob &job) : MultiCommodityFlow(job) | |
/* Generally only allow paths that don't exceed the | |
* available capacity. But if no demand has been assigned | |
* yet, make an exception and allow any valid path *once*. */ | |
- if (path->GetFreeCapacity() > 0 && this->PushFlow(edge, path, | |
- accuracy, this->max_saturation) > 0) { | |
+ if (path->GetFreeCapacity() > 0 && | |
+ this->PushFlow(edge, path, accuracy, this->max_saturation) > 0) { | |
/* If a path has been found there is a chance we can | |
* find more. */ | |
more_loops = more_loops || (edge.UnsatisfiedDemand() > 0); | |
} else if (edge.UnsatisfiedDemand() == edge.Demand() && | |
- path->GetFreeCapacity() > INT_MIN) { | |
+ path->GetFreeCapacity() > INT_MIN) { | |
this->PushFlow(edge, path, accuracy, UINT_MAX); | |
} | |
} | |
@@ -579,11 +564,9 @@ bool Greater(T x_anno, T y_anno, NodeID x, NodeID y) | |
* @param y Second capacity annotation. | |
* @return If x is better than y. | |
*/ | |
-bool CapacityAnnotation::Comparator::operator()(const CapacityAnnotation *x, | |
- const CapacityAnnotation *y) const | |
+bool CapacityAnnotation::Comparator::operator()(const CapacityAnnotation *x, const CapacityAnnotation *y) const | |
{ | |
- return x != y && Greater<int>(x->GetAnnotation(), y->GetAnnotation(), | |
- x->GetNode(), y->GetNode()); | |
+ return x != y && Greater<int>(x->GetAnnotation(), y->GetAnnotation(), x->GetNode(), y->GetNode()); | |
} | |
/** | |
@@ -592,9 +575,7 @@ bool CapacityAnnotation::Comparator::operator()(const CapacityAnnotation *x, | |
* @param y Second distance annotation. | |
* @return If x is better than y. | |
*/ | |
-bool DistanceAnnotation::Comparator::operator()(const DistanceAnnotation *x, | |
- const DistanceAnnotation *y) const | |
+bool DistanceAnnotation::Comparator::operator()(const DistanceAnnotation *x, const DistanceAnnotation *y) const | |
{ | |
- return x != y && !Greater<uint>(x->GetAnnotation(), y->GetAnnotation(), | |
- x->GetNode(), y->GetNode()); | |
+ return x != y && !Greater<uint>(x->GetAnnotation(), y->GetAnnotation(), x->GetNode(), y->GetNode()); | |
} | |
diff --git a/src/linkgraph/refresh.cpp b/src/linkgraph/refresh.cpp | |
index 501f06352..32a148d54 100644 | |
--- a/src/linkgraph/refresh.cpp | |
+++ b/src/linkgraph/refresh.cpp | |
@@ -10,11 +10,11 @@ | |
/** @file refresh.h Definition of link refreshing utility. */ | |
#include "../stdafx.h" | |
+#include "refresh.h" | |
#include "../core/bitmath_func.hpp" | |
-#include "../station_func.h" | |
#include "../engine_base.h" | |
+#include "../station_func.h" | |
#include "../vehicle_func.h" | |
-#include "refresh.h" | |
#include "linkgraph.h" | |
#include "../safeguards.h" | |
@@ -68,9 +68,9 @@ bool LinkRefresher::Hop::operator<(const Hop &other) const | |
* @param allow_merge If the refresher is allowed to merge or extend link graphs. | |
* @param is_full_loading If the vehicle is full loading. | |
*/ | |
-LinkRefresher::LinkRefresher(Vehicle *vehicle, HopSet *seen_hops, bool allow_merge, bool is_full_loading) : | |
- vehicle(vehicle), seen_hops(seen_hops), cargo(CT_INVALID), allow_merge(allow_merge), | |
- is_full_loading(is_full_loading) | |
+LinkRefresher::LinkRefresher(Vehicle *vehicle, HopSet *seen_hops, bool allow_merge, bool is_full_loading) | |
+ : vehicle(vehicle), seen_hops(seen_hops), cargo(CT_INVALID), allow_merge(allow_merge), | |
+ is_full_loading(is_full_loading) | |
{ | |
memset(this->capacities, 0, sizeof(this->capacities)); | |
@@ -176,7 +176,7 @@ const Order *LinkRefresher::PredictNextOrder(const Order *cur, const Order *next | |
if (next->IsType(OT_CONDITIONAL)) { | |
const Order *skip_to = this->vehicle->orders.list->GetNextDecisionNode( | |
- this->vehicle->orders.list->GetOrderAt(next->GetConditionSkipToOrder()), num_hops); | |
+ this->vehicle->orders.list->GetOrderAt(next->GetConditionSkipToOrder()), num_hops); | |
if (skip_to != NULL && num_hops < this->vehicle->orders.list->GetNumOrders()) { | |
/* Make copies of capacity tracking lists. There is potential | |
* for optimization here: If the vehicle never refits we don't | |
@@ -189,8 +189,8 @@ const Order *LinkRefresher::PredictNextOrder(const Order *cur, const Order *next | |
/* Reassign next with the following stop. This can be a station or a | |
* depot.*/ | |
- next = this->vehicle->orders.list->GetNextDecisionNode( | |
- this->vehicle->orders.list->GetNext(next), num_hops++); | |
+ next = this->vehicle->orders.list->GetNextDecisionNode(this->vehicle->orders.list->GetNext(next), | |
+ num_hops++); | |
} | |
return next; | |
} | |
@@ -213,13 +213,14 @@ void LinkRefresher::RefreshStats(const Order *cur, const Order *next) | |
/* If not allowed to merge link graphs, make sure the stations are | |
* already in the same link graph. */ | |
- if (!this->allow_merge && st->goods[c].link_graph != Station::Get(next_station)->goods[c].link_graph) { | |
+ if (!this->allow_merge && | |
+ st->goods[c].link_graph != Station::Get(next_station)->goods[c].link_graph) { | |
continue; | |
} | |
/* 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; | |
+ EdgeUpdateMode restricted_mode = | |
+ (cur->GetLoadType() & OLFB_NO_LOAD) == 0 ? EUM_UNRESTRICTED : EUM_RESTRICTED; | |
/* 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 | |
@@ -227,18 +228,20 @@ void LinkRefresher::RefreshStats(const Order *cur, const Order *next) | |
* order list is supposed to take, though. If that is the case the total duration is | |
* probably far off and we'd greatly overestimate the capacity by increasing.*/ | |
if (this->is_full_loading && this->vehicle->orders.list != NULL && | |
- st->index == vehicle->last_station_visited && | |
- this->vehicle->orders.list->GetTotalDuration() > | |
- (Ticks)this->vehicle->current_order_time) { | |
+ st->index == vehicle->last_station_visited && | |
+ this->vehicle->orders.list->GetTotalDuration() > (Ticks)this->vehicle->current_order_time) { | |
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, | |
- EUM_INCREASE | restricted_mode); | |
- } else if (RandomRange(this->vehicle->orders.list->GetTotalDuration()) < effective_capacity) { | |
+ IncreaseStats(st, c, next_station, | |
+ effective_capacity / | |
+ this->vehicle->orders.list->GetTotalDuration(), | |
+ 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); | |
} else { | |
- IncreaseStats(st, c, next_station, cargo_quantity, 0, EUM_REFRESH | restricted_mode); | |
+ IncreaseStats(st, c, next_station, cargo_quantity, 0, | |
+ EUM_REFRESH | restricted_mode); | |
} | |
} else { | |
IncreaseStats(st, c, next_station, cargo_quantity, 0, EUM_REFRESH | restricted_mode); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment