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()
334 _waiting_acceptance = 0;
337 for (
CargoID i = 0; i < num_cargo; i++) {
343 if (
GB(_waiting_acceptance, 0, 12) != 0) {
354 CargoPacket *cp =
new CargoPacket(
GB(_waiting_acceptance, 0, 12), _cargo_days, source, _cargo_source_xy, _cargo_source_xy, _cargo_feeder_share);
364 for (uint i = 0; i < st->
num_specs; i++) {
371 static void Ptrs_STNS()
377 FOR_ALL_STATIONS(st) {
391 static const SaveLoad _base_station_desc[] = {
411 static const SaveLoad _station_desc[] = {
444 static const SaveLoad _waypoint_desc[] = {
463 return _base_station_desc;
469 SlObject(bst, waypoint ? _waypoint_desc : _station_desc);
476 for (FlowStatMap::const_iterator it(st->
goods[i].
flows.begin()); it != st->
goods[i].
flows.end(); ++it) {
477 _num_flows += (uint32)it->second.GetShares()->size();
480 for (FlowStatMap::const_iterator outer_it(st->
goods[i].
flows.begin()); outer_it != st->
goods[i].
flows.end(); ++outer_it) {
481 const FlowStat::SharesMap *shares = outer_it->second.GetShares();
482 uint32 sum_shares = 0;
484 flow.source = outer_it->first;
485 for (FlowStat::SharesMap::const_iterator inner_it(shares->begin()); inner_it != shares->end(); ++inner_it) {
486 flow.via = inner_it->second;
487 flow.share = inner_it->first - sum_shares;
488 flow.restricted = inner_it->first > outer_it->second.GetUnrestricted();
489 sum_shares = inner_it->first;
490 assert(flow.share > 0);
495 SlObject(const_cast<StationCargoPacketMap::value_type *>(&(*it)), _cargo_list_desc);
500 for (uint i = 0; i < bst->
num_specs; i++) {
505 static void Save_STNN()
509 FOR_ALL_BASE_STATIONS(st) {
510 SlSetArrayIndex(st->
index);
515 static void Load_STNN()
523 SlObject(bst, waypoint ? _waypoint_desc : _station_desc);
540 StationID prev_source = INVALID_STATION;
541 for (uint32 j = 0; j < _num_flows; ++j) {
543 if (fs == NULL || prev_source != flow.source) {
544 fs = &(st->
goods[i].
flows.insert(std::make_pair(flow.source,
FlowStat(flow.via, flow.share, flow.restricted))).first->second);
546 fs->
AppendShare(flow.via, flow.share, flow.restricted);
548 prev_source = flow.source;
553 StationCargoPair pair;
554 for (uint j = 0; j < _num_dests; ++j) {
557 assert(pair.second.empty());
563 if (bst->num_specs != 0) {
565 bst->speclist = CallocT<StationSpecList>(bst->num_specs);
566 for (uint i = 0; i < bst->num_specs; i++) {
567 SlObject(&bst->speclist[i], _station_speclist_desc);
573 static void Ptrs_STNN()
579 FOR_ALL_STATIONS(st) {
588 for (StationCargoPacketMap::ConstMapIterator it = ge->
cargo.
Packets()->begin(); it != ge->
cargo.
Packets()->end(); ++it) {
589 SlObject(const_cast<StationCargoPair *>(&(*it)), _cargo_list_desc);
602 static void Save_ROADSTOP()
606 FOR_ALL_ROADSTOPS(rs) {
607 SlSetArrayIndex(rs->
index);
612 static void Load_ROADSTOP()
623 static void Ptrs_ROADSTOP()
626 FOR_ALL_ROADSTOPS(rs) {
632 {
'STNS', NULL, Load_STNS, Ptrs_STNS, NULL, CH_ARRAY },
633 {
'STNN', Save_STNN, Load_STNN, Ptrs_STNN, NULL, CH_ARRAY },
634 {
'ROAD', Save_ROADSTOP, Load_ROADSTOP, Ptrs_ROADSTOP, NULL, CH_ARRAY |
CH_LAST},