10 #include "../stdafx.h"
15 #include "../station_base.h"
16 #include "../waypoint_base.h"
17 #include "../roadstop_base.h"
18 #include "../vehicle_base.h"
19 #include "../newgrf_station.h"
21 #include "table/strings.h"
23 #include "../safeguards.h"
31 if (!o->
IsType(OT_GOTO_STATION))
return;
64 StationID index = st->index;
66 Town *town = st->town;
68 std::string name = st->
name;
69 Date build_date = st->build_date;
72 TileArea train_st = st->train_station;
82 wp->
string_id = train ? STR_SV_STNAME_WAYPOINT : STR_SV_STNAME_BUOY;
88 if (
IsInsideBS(string_id, STR_SV_STNAME_BUOY, 9)) wp->
town_cn = string_id - STR_SV_STNAME_BUOY;
95 SB(
_me[t].m6, 3, 3, STATION_WAYPOINT);
96 wp->
rect.BeforeAddTile(t, StationRect::ADD_FORCE);
102 wp->
rect.BeforeAddTile(xy, StationRect::ADD_FORCE);
108 void AfterLoadStations()
112 for (uint i = 0; i < st->num_specs; i++) {
113 if (st->speclist[i].grfid == 0)
continue;
115 st->speclist[i].spec = StationClass::GetByGrf(st->speclist[i].grfid, st->speclist[i].localidx,
nullptr);
146 static const SaveLoad _roadstop_desc[] = {
152 static uint16 _waiting_acceptance;
153 static uint32 _old_num_flows;
154 static uint16 _cargo_source;
155 static uint32 _cargo_source_xy;
156 static uint8 _cargo_days;
157 static Money _cargo_feeder_share;
159 std::list<CargoPacket *> _packets;
160 uint32 _old_num_dests;
163 FlowSaveLoad() : source(0), via(0), share(0), restricted(
false) {}
170 typedef std::pair<const StationID, std::list<CargoPacket *> > StationCargoPair;
183 if (_packets.empty()) {
184 std::map<StationID, std::list<CargoPacket *> >::iterator it(ge_packets.find(INVALID_STATION));
185 if (it == ge_packets.end()) {
188 it->second.swap(_packets);
191 assert(ge_packets[INVALID_STATION].empty());
192 ge_packets[INVALID_STATION].swap(_packets);
198 inline static const SaveLoad description[] = {
207 for (uint i = 0; i < bst->
num_specs; i++) {
221 for (uint i = 0; i < bst->
num_specs; i++) {
230 inline static const SaveLoad description[] = {
231 SLE_VAR(StationCargoPair, first, SLE_UINT16),
239 for (StationCargoPacketMap::ConstMapIterator it(ge->
cargo.
Packets()->begin()); it != ge->
cargo.
Packets()->end(); ++it) {
248 StationCargoPair pair;
249 for (uint j = 0; j < num_dests; ++j) {
252 assert(pair.second.empty());
256 void FixPointers(
GoodsEntry *ge)
const override
258 for (StationCargoPacketMap::ConstMapIterator it = ge->
cargo.
Packets()->begin(); it != ge->
cargo.
Packets()->end(); ++it) {
266 inline static const SaveLoad description[] = {
276 uint32 num_flows = 0;
277 for (FlowStatMap::const_iterator it(ge->
flows.begin()); it != ge->
flows.end(); ++it) {
278 num_flows += (uint32)it->second.GetShares()->size();
282 for (FlowStatMap::const_iterator outer_it(ge->
flows.begin()); outer_it != ge->
flows.end(); ++outer_it) {
283 const FlowStat::SharesMap *shares = outer_it->second.GetShares();
284 uint32 sum_shares = 0;
286 flow.source = outer_it->first;
287 for (FlowStat::SharesMap::const_iterator inner_it(shares->begin()); inner_it != shares->end(); ++inner_it) {
288 flow.via = inner_it->second;
289 flow.share = inner_it->first - sum_shares;
290 flow.restricted = inner_it->first > outer_it->second.GetUnrestricted();
291 sum_shares = inner_it->first;
292 assert(flow.share > 0);
304 StationID prev_source = INVALID_STATION;
305 for (uint32 j = 0; j < num_flows; ++j) {
307 if (fs ==
nullptr || prev_source != flow.source) {
308 fs = &(ge->
flows.insert(std::make_pair(flow.source,
FlowStat(flow.via, flow.share, flow.restricted))).first->second);
310 fs->
AppendShare(flow.via, flow.share, flow.restricted);
312 prev_source = flow.source;
319 #if defined(_MSC_VER) && (_MSC_VER == 1915 || _MSC_VER == 1916)
324 inline static const SaveLoad description[] = {{}};
329 static const SaveLoad description[] = {
353 #if defined(_MSC_VER) && (_MSC_VER == 1915 || _MSC_VER == 1916)
396 for (
CargoID i = 0; i < num_cargo; i++) {
404 if (
GB(_waiting_acceptance, 0, 12) != 0) {
415 CargoPacket *cp =
new CargoPacket(
GB(_waiting_acceptance, 0, 12), _cargo_days, source, _cargo_source_xy, _cargo_source_xy, _cargo_feeder_share);
428 for (
CargoID i = 0; i < num_cargo; i++) {
441 static const SaveLoad _old_station_desc[] = {
494 _cargo_source_xy = 0;
496 _cargo_feeder_share = 0;
502 _waiting_acceptance = 0;
526 inline static const SaveLoad description[] = {
564 inline static const SaveLoad description[] = {
622 inline static const SaveLoad description[] = {
651 static const SaveLoad _station_desc[] = {
667 SlSetArrayIndex(st->
index);
709 SlSetArrayIndex(rs->index);