10 #include "../stdafx.h"
11 #include "../station_base.h"
12 #include "../waypoint_base.h"
13 #include "../roadstop_base.h"
14 #include "../vehicle_base.h"
15 #include "../newgrf_station.h"
18 #include "table/strings.h"
20 #include "../safeguards.h"
28 if (!o->
IsType(OT_GOTO_STATION))
return;
61 StationID index = st->index;
63 Town *town = st->town;
65 std::string name = st->
name;
66 Date build_date = st->build_date;
69 TileArea train_st = st->train_station;
79 wp->
string_id = train ? STR_SV_STNAME_WAYPOINT : STR_SV_STNAME_BUOY;
85 if (
IsInsideBS(string_id, STR_SV_STNAME_BUOY, 9)) wp->
town_cn = string_id - STR_SV_STNAME_BUOY;
92 SB(
_me[t].m6, 3, 3, STATION_WAYPOINT);
93 wp->
rect.BeforeAddTile(t, StationRect::ADD_FORCE);
99 wp->
rect.BeforeAddTile(xy, StationRect::ADD_FORCE);
105 void AfterLoadStations()
109 for (uint i = 0; i < st->num_specs; i++) {
110 if (st->speclist[i].grfid == 0)
continue;
112 st->speclist[i].spec = StationClass::GetByGrf(st->speclist[i].grfid, st->speclist[i].localidx,
nullptr);
143 static const SaveLoad _roadstop_desc[] = {
161 static const SaveLoad _old_station_desc[] = {
220 static uint16 _waiting_acceptance;
221 static uint32 _num_flows;
222 static uint16 _cargo_source;
223 static uint32 _cargo_source_xy;
224 static uint8 _cargo_days;
225 static Money _cargo_feeder_share;
227 static const SaveLoad _station_speclist_desc[] = {
234 std::list<CargoPacket *> _packets;
238 FlowSaveLoad() : source(0), via(0), share(0), restricted(
false) {}
245 static const SaveLoad _flow_desc[] = {
260 static const SaveLoad goods_desc[] = {
288 typedef std::pair<const StationID, std::list<CargoPacket *> > StationCargoPair;
290 static const SaveLoad _cargo_list_desc[] = {
291 SLE_VAR(StationCargoPair, first, SLE_UINT16),
305 if (_packets.empty()) {
306 std::map<StationID, std::list<CargoPacket *> >::iterator it(ge_packets.find(INVALID_STATION));
307 if (it == ge_packets.end()) {
310 it->second.swap(_packets);
313 assert(ge_packets[INVALID_STATION].empty());
314 ge_packets[INVALID_STATION].swap(_packets);
318 static void Load_STNS()
320 _cargo_source_xy = 0;
322 _cargo_feeder_share = 0;
331 _waiting_acceptance = 0;
333 for (
CargoID i = 0; i < num_cargo; i++) {
339 if (
GB(_waiting_acceptance, 0, 12) != 0) {
350 CargoPacket *cp =
new CargoPacket(
GB(_waiting_acceptance, 0, 12), _cargo_days, source, _cargo_source_xy, _cargo_source_xy, _cargo_feeder_share);
360 for (uint i = 0; i < st->
num_specs; i++) {
367 static void Ptrs_STNS()
375 for (
CargoID i = 0; i < num_cargo; i++) {
387 static const SaveLoad _base_station_desc[] = {
407 static const SaveLoad _station_desc[] = {
447 static const SaveLoad _waypoint_desc[] = {
466 return _base_station_desc;
472 SlObject(bst, waypoint ? _waypoint_desc : _station_desc);
479 for (FlowStatMap::const_iterator it(st->
goods[i].
flows.begin()); it != st->
goods[i].
flows.end(); ++it) {
480 _num_flows += (uint32)it->second.GetShares()->size();
483 for (FlowStatMap::const_iterator outer_it(st->
goods[i].
flows.begin()); outer_it != st->
goods[i].
flows.end(); ++outer_it) {
484 const FlowStat::SharesMap *shares = outer_it->second.GetShares();
485 uint32 sum_shares = 0;
487 flow.source = outer_it->first;
488 for (FlowStat::SharesMap::const_iterator inner_it(shares->begin()); inner_it != shares->end(); ++inner_it) {
489 flow.via = inner_it->second;
490 flow.share = inner_it->first - sum_shares;
491 flow.restricted = inner_it->first > outer_it->second.GetUnrestricted();
492 sum_shares = inner_it->first;
493 assert(flow.share > 0);
498 SlObject(
const_cast<StationCargoPacketMap::value_type *
>(&(*it)), _cargo_list_desc);
503 for (uint i = 0; i < bst->
num_specs; i++) {
508 static void Save_STNN()
512 SlSetArrayIndex(st->
index);
517 static void Load_STNN()
527 SlObject(bst, waypoint ? _waypoint_desc : _station_desc);
540 for (
CargoID i = 0; i < num_cargo; i++) {
544 StationID prev_source = INVALID_STATION;
545 for (uint32 j = 0; j < _num_flows; ++j) {
547 if (fs ==
nullptr || prev_source != flow.source) {
548 fs = &(st->
goods[i].
flows.insert(std::make_pair(flow.source,
FlowStat(flow.via, flow.share, flow.restricted))).first->second);
550 fs->
AppendShare(flow.via, flow.share, flow.restricted);
552 prev_source = flow.source;
557 StationCargoPair pair;
558 for (uint j = 0; j < _num_dests; ++j) {
561 assert(pair.second.empty());
570 for (uint i = 0; i < bst->
num_specs; i++) {
577 static void Ptrs_STNN()
584 for (
CargoID i = 0; i < num_cargo; i++) {
592 for (StationCargoPacketMap::ConstMapIterator it = ge->
cargo.
Packets()->begin(); it != ge->
cargo.
Packets()->end(); ++it) {
593 SlObject(
const_cast<StationCargoPair *
>(&(*it)), _cargo_list_desc);
605 static void Save_ROADSTOP()
608 SlSetArrayIndex(rs->index);
613 static void Load_ROADSTOP()
624 static void Ptrs_ROADSTOP()
632 {
'STNS',
nullptr, Load_STNS, Ptrs_STNS,
nullptr, CH_ARRAY },
633 {
'STNN', Save_STNN, Load_STNN, Ptrs_STNN,
nullptr, CH_ARRAY },
634 {
'ROAD', Save_ROADSTOP, Load_ROADSTOP, Ptrs_ROADSTOP,
nullptr, CH_ARRAY |
CH_LAST},