summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/saveload/station_sl.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/saveload/station_sl.cpp b/src/saveload/station_sl.cpp
index 8b31cf3a4..6f1a864a2 100644
--- a/src/saveload/station_sl.cpp
+++ b/src/saveload/station_sl.cpp
@@ -224,6 +224,7 @@ static const SaveLoad _old_station_desc[] = {
};
static uint16 _waiting_acceptance;
+static uint32 _num_flows;
static uint16 _cargo_source;
static uint32 _cargo_source_xy;
static uint8 _cargo_days;
@@ -236,6 +237,20 @@ static const SaveLoad _station_speclist_desc[] = {
SLE_END()
};
+struct FlowSaveLoad {
+ FlowSaveLoad() : via(0), share(0) {}
+ StationID source;
+ StationID via;
+ uint32 share;
+};
+
+static const SaveLoad _flow_desc[] = {
+ SLE_VAR(FlowSaveLoad, source, SLE_UINT16),
+ SLE_VAR(FlowSaveLoad, via, SLE_UINT16),
+ SLE_VAR(FlowSaveLoad, share, SLE_UINT32),
+ SLE_END()
+};
+
/**
* Wrapper function to get the GoodsEntry's internal structure while
* some of the variables itself are private.
@@ -260,6 +275,9 @@ const SaveLoad *GetGoodsDesc()
SLE_CONDVAR(GoodsEntry, amount_fract, SLE_UINT8, 150, SL_MAX_VERSION),
SLE_CONDLST(GoodsEntry, cargo.packets, REF_CARGO_PACKET, 68, SL_MAX_VERSION),
SLE_CONDVAR(GoodsEntry, cargo.reserved_count, SLE_UINT, 181, SL_MAX_VERSION),
+ SLE_CONDVAR(GoodsEntry, link_graph, SLE_UINT16, 183, SL_MAX_VERSION),
+ SLE_CONDVAR(GoodsEntry, node, SLE_UINT16, 183, SL_MAX_VERSION),
+ SLEG_CONDVAR( _num_flows, SLE_UINT32, 183, SL_MAX_VERSION),
SLE_END()
};
@@ -409,7 +427,24 @@ static void RealSave_STNN(BaseStation *bst)
if (!waypoint) {
Station *st = Station::From(bst);
for (CargoID i = 0; i < NUM_CARGO; i++) {
+ _num_flows = 0;
+ for (FlowStatMap::const_iterator it(st->goods[i].flows.begin()); it != st->goods[i].flows.end(); ++it) {
+ _num_flows += (uint32)it->second.GetShares()->size();
+ }
SlObject(&st->goods[i], GetGoodsDesc());
+ for (FlowStatMap::const_iterator outer_it(st->goods[i].flows.begin()); outer_it != st->goods[i].flows.end(); ++outer_it) {
+ const FlowStat::SharesMap *shares = outer_it->second.GetShares();
+ uint32 sum_shares = 0;
+ FlowSaveLoad flow;
+ flow.source = outer_it->first;
+ for (FlowStat::SharesMap::const_iterator inner_it(shares->begin()); inner_it != shares->end(); ++inner_it) {
+ flow.via = inner_it->second;
+ flow.share = inner_it->first - sum_shares;
+ sum_shares = inner_it->first;
+ assert(flow.share > 0);
+ SlObject(&flow, _flow_desc);
+ }
+ }
}
}
@@ -451,6 +486,18 @@ static void Load_STNN()
for (CargoID i = 0; i < NUM_CARGO; i++) {
SlObject(&st->goods[i], GetGoodsDesc());
+ FlowSaveLoad flow;
+ FlowStat *fs = NULL;
+ StationID prev_source = INVALID_STATION;
+ for (uint32 j = 0; j < _num_flows; ++j) {
+ SlObject(&flow, _flow_desc);
+ if (fs == NULL || prev_source != flow.source) {
+ fs = &(st->goods[i].flows.insert(std::make_pair(flow.source, FlowStat(flow.via, flow.share))).first->second);
+ } else {
+ fs->AppendShare(flow.via, flow.share);
+ }
+ prev_source = flow.source;
+ }
}
}