12 #include "../stdafx.h"
13 #include "../station_base.h"
14 #include "../waypoint_base.h"
15 #include "../roadstop_base.h"
16 #include "../vehicle_base.h"
17 #include "../newgrf_station.h"
20 #include "table/strings.h"
22 #include "../safeguards.h"
30 if (!o->
IsType(OT_GOTO_STATION))
return;
46 FOR_ALL_ORDER_LISTS(ol) {
63 FOR_ALL_STATIONS(st) {
66 StationID index = st->
index;
70 char *name = st->
name;
85 wp->
string_id = train ? STR_SV_STNAME_WAYPOINT : STR_SV_STNAME_BUOY;
91 if (
IsInsideBS(string_id, STR_SV_STNAME_BUOY, 9)) wp->
town_cn = string_id - STR_SV_STNAME_BUOY;
98 SB(
_me[t].m6, 3, 3, STATION_WAYPOINT);
99 wp->
rect.BeforeAddTile(t, StationRect::ADD_FORCE);
105 wp->
rect.BeforeAddTile(xy, StationRect::ADD_FORCE);
111 void AfterLoadStations()
115 FOR_ALL_BASE_STATIONS(st) {
116 for (uint i = 0; i < st->
num_specs; i++) {
139 FOR_ALL_ROADSTOPS(rs) {
143 FOR_ALL_ROADSTOPS(rs) {
151 static const SaveLoad _roadstop_desc[] = {
169 static const SaveLoad _old_station_desc[] = {
228 static uint16 _waiting_acceptance;
229 static uint32 _num_flows;
230 static uint16 _cargo_source;
231 static uint32 _cargo_source_xy;
232 static uint8 _cargo_days;
233 static Money _cargo_feeder_share;
235 static const SaveLoad _station_speclist_desc[] = {
242 std::list<CargoPacket *> _packets;
246 FlowSaveLoad() : source(0), via(0), share(0), restricted(
false) {}
253 static const SaveLoad _flow_desc[] = {
268 static const SaveLoad goods_desc[] = {
274 SLEG_CONDVAR( _cargo_source, SLE_FILE_U8 | SLE_VAR_U16, 0, 6),
280 SLEG_CONDVAR( _cargo_feeder_share, SLE_FILE_U32 | SLE_VAR_I64, 14, 64),
296 typedef std::pair<const StationID, std::list<CargoPacket *> > StationCargoPair;
298 static const SaveLoad _cargo_list_desc[] = {
299 SLE_VAR(StationCargoPair, first, SLE_UINT16),
313 if (_packets.empty()) {
314 std::map<StationID, std::list<CargoPacket *> >::iterator it(ge_packets.find(INVALID_STATION));
315 if (it == ge_packets.end()) {
318 it->second.swap(_packets);
321 assert(ge_packets[INVALID_STATION].empty());
322 ge_packets[INVALID_STATION].swap(_packets);
326 static void Load_STNS()
328 _cargo_source_xy = 0;
330 _cargo_feeder_share = 0;
338 _waiting_acceptance = 0;
341 for (
CargoID i = 0; i < num_cargo; i++) {
347 if (
GB(_waiting_acceptance, 0, 12) != 0) {
358 CargoPacket *cp =
new CargoPacket(
GB(_waiting_acceptance, 0, 12), _cargo_days, source, _cargo_source_xy, _cargo_source_xy, _cargo_feeder_share);
368 for (uint i = 0; i < st->
num_specs; i++) {
375 static void Ptrs_STNS()
381 FOR_ALL_STATIONS(st) {
395 static const SaveLoad _base_station_desc[] = {
415 static const SaveLoad _station_desc[] = {
448 static const SaveLoad _waypoint_desc[] = {
467 return _base_station_desc;
473 SlObject(bst, waypoint ? _waypoint_desc : _station_desc);
480 for (FlowStatMap::const_iterator it(st->
goods[i].
flows.begin()); it != st->
goods[i].
flows.end(); ++it) {
481 _num_flows += (uint32)it->second.GetShares()->size();
484 for (FlowStatMap::const_iterator outer_it(st->
goods[i].
flows.begin()); outer_it != st->
goods[i].
flows.end(); ++outer_it) {
485 const FlowStat::SharesMap *shares = outer_it->second.GetShares();
486 uint32 sum_shares = 0;
488 flow.source = outer_it->first;
489 for (FlowStat::SharesMap::const_iterator inner_it(shares->begin()); inner_it != shares->end(); ++inner_it) {
490 flow.via = inner_it->second;
491 flow.share = inner_it->first - sum_shares;
492 flow.restricted = inner_it->first > outer_it->second.GetUnrestricted();
493 sum_shares = inner_it->first;
494 assert(flow.share > 0);
499 SlObject(const_cast<StationCargoPacketMap::value_type *>(&(*it)), _cargo_list_desc);
504 for (uint i = 0; i < bst->
num_specs; i++) {
509 static void Save_STNN()
513 FOR_ALL_BASE_STATIONS(st) {
514 SlSetArrayIndex(st->
index);
519 static void Load_STNN()
528 SlObject(bst, waypoint ? _waypoint_desc : _station_desc);
545 StationID prev_source = INVALID_STATION;
546 for (uint32 j = 0; j < _num_flows; ++j) {
548 if (fs == NULL || prev_source != flow.source) {
549 fs = &(st->
goods[i].
flows.insert(std::make_pair(flow.source,
FlowStat(flow.via, flow.share, flow.restricted))).first->second);
551 fs->
AppendShare(flow.via, flow.share, flow.restricted);
553 prev_source = flow.source;
558 StationCargoPair pair;
559 for (uint j = 0; j < _num_dests; ++j) {
562 assert(pair.second.empty());
568 if (bst->num_specs != 0) {
570 bst->speclist = CallocT<StationSpecList>(bst->num_specs);
571 for (uint i = 0; i < bst->num_specs; i++) {
572 SlObject(&bst->speclist[i], _station_speclist_desc);
578 static void Ptrs_STNN()
584 FOR_ALL_STATIONS(st) {
593 for (StationCargoPacketMap::ConstMapIterator it = ge->
cargo.
Packets()->begin(); it != ge->
cargo.
Packets()->end(); ++it) {
594 SlObject(const_cast<StationCargoPair *>(&(*it)), _cargo_list_desc);
607 static void Save_ROADSTOP()
611 FOR_ALL_ROADSTOPS(rs) {
612 SlSetArrayIndex(rs->
index);
617 static void Load_ROADSTOP()
628 static void Ptrs_ROADSTOP()
631 FOR_ALL_ROADSTOPS(rs) {
637 {
'STNS', NULL, Load_STNS, Ptrs_STNS, NULL, CH_ARRAY },
638 {
'STNN', Save_STNN, Load_STNN, Ptrs_STNN, NULL, CH_ARRAY },
639 {
'ROAD', Save_ROADSTOP, Load_ROADSTOP, Ptrs_ROADSTOP, NULL, CH_ARRAY |
CH_LAST},