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"
20 #include "../newgrf_roadstop.h"
21 #include "../timer/timer_game_calendar.h"
23 #include "table/strings.h"
25 #include "../safeguards.h"
33 if (!o->
IsType(OT_GOTO_STATION))
return;
66 StationID index = st->index;
68 Town *town = st->town;
70 std::string name = st->
name;
71 TimerGameCalendar::Date build_date = st->build_date;
74 TileArea train_st = st->train_station;
84 wp->
string_id = train ? STR_SV_STNAME_WAYPOINT : STR_SV_STNAME_BUOY;
90 if (
IsInsideBS(string_id, STR_SV_STNAME_BUOY, 9)) wp->
town_cn = string_id - STR_SV_STNAME_BUOY;
98 SB(tile.
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 (uint i = 0; i < st->speclist.size(); i++) {
116 if (st->speclist[i].grfid == 0)
continue;
118 st->speclist[i].spec = StationClass::GetByGrf(st->speclist[i].grfid, st->speclist[i].localidx,
nullptr);
120 for (uint i = 0; i < st->roadstop_speclist.size(); i++) {
121 if (st->roadstop_speclist[i].grfid == 0)
continue;
123 st->roadstop_speclist[i].spec = RoadStopClass::GetByGrf(st->roadstop_speclist[i].grfid, st->roadstop_speclist[i].localidx,
nullptr);
155 static const SaveLoad _roadstop_desc[] = {
161 static uint16_t _waiting_acceptance;
162 static uint32_t _old_num_flows;
163 static uint16_t _cargo_source;
164 static uint32_t _cargo_source_xy;
165 static uint8_t _cargo_periods;
166 static Money _cargo_feeder_share;
168 std::list<CargoPacket *> _packets;
169 uint32_t _old_num_dests;
172 FlowSaveLoad() : source(0), via(0), share(0), restricted(
false) {}
179 typedef std::pair<const StationID, std::list<CargoPacket *> > StationCargoPair;
192 if (_packets.empty()) {
193 std::map<StationID, std::list<CargoPacket *> >::iterator it(ge_packets.find(INVALID_STATION));
194 if (it == ge_packets.end()) {
197 it->second.swap(_packets);
200 assert(ge_packets[INVALID_STATION].empty());
201 ge_packets[INVALID_STATION].swap(_packets);
207 inline static const SaveLoad description[] = {
219 for (uint i = 0; i < bst->
speclist.size(); i++) {
229 for (uint i = 0; i < num_specs; i++) {
239 inline static const SaveLoad description[] = {
259 for (uint i = 0; i < num_specs; i++) {
267 inline static const SaveLoad description[] = {
268 SLE_VAR(StationCargoPair, first, SLE_UINT16),
276 for (StationCargoPacketMap::ConstMapIterator it(ge->
cargo.
Packets()->begin()); it != ge->
cargo.
Packets()->end(); ++it) {
285 StationCargoPair pair;
286 for (uint j = 0; j < num_dests; ++j) {
289 assert(pair.second.empty());
293 void FixPointers(
GoodsEntry *ge)
const override
295 for (StationCargoPacketMap::ConstMapIterator it = ge->
cargo.
Packets()->begin(); it != ge->
cargo.
Packets()->end(); ++it) {
303 inline static const SaveLoad description[] = {
313 size_t num_flows = 0;
314 for (
const auto &it : ge->
flows) {
315 num_flows += it.second.GetShares()->size();
319 for (
const auto &outer_it : ge->
flows) {
320 const FlowStat::SharesMap *shares = outer_it.second.GetShares();
321 uint32_t sum_shares = 0;
323 flow.source = outer_it.first;
324 for (
auto &inner_it : *shares) {
325 flow.via = inner_it.second;
326 flow.share = inner_it.first - sum_shares;
327 flow.restricted = inner_it.first > outer_it.second.GetUnrestricted();
328 sum_shares = inner_it.first;
329 assert(flow.share > 0);
341 StationID prev_source = INVALID_STATION;
342 for (uint32_t j = 0; j < num_flows; ++j) {
344 if (fs ==
nullptr || prev_source != flow.source) {
345 fs = &(ge->
flows.insert(std::make_pair(flow.source,
FlowStat(flow.via, flow.share, flow.restricted))).first->second);
347 fs->
AppendShare(flow.via, flow.share, flow.restricted);
349 prev_source = flow.source;
356 #if defined(_MSC_VER) && (_MSC_VER == 1915 || _MSC_VER == 1916)
361 inline static const SaveLoad description[] = {{}};
366 static const SaveLoad description[] = {
390 #if defined(_MSC_VER) && (_MSC_VER == 1915 || _MSC_VER == 1916)
432 auto end = std::next(std::begin(st->
goods), std::min(this->GetNumCargo(), std::size(st->
goods)));
433 for (
auto it = std::begin(st->
goods); it != end; ++it) {
441 if (
GB(_waiting_acceptance, 0, 12) != 0) {
452 CargoPacket *cp =
new CargoPacket(
GB(_waiting_acceptance, 0, 12), _cargo_periods, source, _cargo_source_xy, _cargo_feeder_share);
465 auto end = std::next(std::begin(st->
goods), std::min(num_cargo, std::size(st->
goods)));
466 for (
auto it = std::begin(st->
goods); it != end; ++it) {
479 static const SaveLoad _old_station_desc[] = {
532 _cargo_source_xy = 0;
534 _cargo_feeder_share = 0;
540 _waiting_acceptance = 0;
560 inline static const SaveLoad description[] = {
581 for (uint i = 0; i < num_tiles; i++) {
593 inline static const SaveLoad description[] = {
631 inline static const SaveLoad description[] = {
690 inline static const SaveLoad description[] = {
719 static const SaveLoad _station_desc[] = {
736 SlSetArrayIndex(st->
index);
778 SlSetArrayIndex(rs->index);