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 (
auto &sm : GetStationSpecList<StationSpec>(st)) {
116 if (sm.grfid == 0)
continue;
119 for (
auto &sm : GetStationSpecList<RoadStopSpec>(st)) {
120 if (sm.grfid == 0)
continue;
153 static const SaveLoad _roadstop_desc[] = {
159 static uint16_t _waiting_acceptance;
160 static uint32_t _old_num_flows;
161 static uint16_t _cargo_source;
162 static uint32_t _cargo_source_xy;
163 static uint8_t _cargo_periods;
164 static Money _cargo_feeder_share;
166 std::list<CargoPacket *> _packets;
167 uint32_t _old_num_dests;
170 FlowSaveLoad() : source(0), via(0), share(0), restricted(
false) {}
177 typedef std::pair<const StationID, std::list<CargoPacket *> > StationCargoPair;
190 if (_packets.empty()) {
191 std::map<StationID, std::list<CargoPacket *> >::iterator it(ge_packets.find(INVALID_STATION));
192 if (it == ge_packets.end()) {
195 it->second.swap(_packets);
198 assert(ge_packets[INVALID_STATION].empty());
199 ge_packets[INVALID_STATION].swap(_packets);
203 template <
typename T>
206 inline static const SaveLoad description[] = {
217 auto &speclist = GetStationSpecList<T>(bst);
219 for (
auto &sm : speclist) {
228 auto &speclist = GetStationSpecList<T>(bst);
229 speclist.reserve(num_specs);
230 for (
size_t index = 0; index < num_specs; ++index) {
231 auto &sm = speclist.emplace_back();
243 inline static const SaveLoad description[] = {
244 SLE_VAR(StationCargoPair, first, SLE_UINT16),
252 for (StationCargoPacketMap::ConstMapIterator it(ge->
cargo.
Packets()->begin()); it != ge->
cargo.
Packets()->end(); ++it) {
253 SlObject(
const_cast<StationCargoPacketMap::value_type *
>(&(*it)), this->GetDescription());
261 StationCargoPair pair;
262 for (uint j = 0; j < num_dests; ++j) {
263 SlObject(&pair, this->GetLoadDescription());
265 assert(pair.second.empty());
269 void FixPointers(
GoodsEntry *ge)
const override
271 for (StationCargoPacketMap::ConstMapIterator it = ge->
cargo.
Packets()->begin(); it != ge->
cargo.
Packets()->end(); ++it) {
272 SlObject(
const_cast<StationCargoPair *
>(&(*it)), this->GetDescription());
279 inline static const SaveLoad description[] = {
289 size_t num_flows = 0;
290 for (
const auto &it : ge->
flows) {
291 num_flows += it.second.GetShares()->size();
295 for (
const auto &outer_it : ge->
flows) {
296 const FlowStat::SharesMap *shares = outer_it.second.GetShares();
297 uint32_t sum_shares = 0;
299 flow.source = outer_it.first;
300 for (
auto &inner_it : *shares) {
301 flow.via = inner_it.second;
302 flow.share = inner_it.first - sum_shares;
303 flow.restricted = inner_it.first > outer_it.second.GetUnrestricted();
304 sum_shares = inner_it.first;
305 assert(flow.share > 0);
306 SlObject(&flow, this->GetDescription());
317 StationID prev_source = INVALID_STATION;
318 for (uint32_t j = 0; j < num_flows; ++j) {
319 SlObject(&flow, this->GetLoadDescription());
320 if (fs ==
nullptr || prev_source != flow.source) {
321 fs = &(ge->
flows.emplace(flow.source,
FlowStat(flow.via, flow.share, flow.restricted))).first->second;
323 fs->
AppendShare(flow.via, flow.share, flow.restricted);
325 prev_source = flow.source;
332 inline static const SaveLoad description[] = {
395 auto end = std::next(std::begin(st->
goods), std::min(this->GetNumCargo(), std::size(st->
goods)));
396 for (
auto it = std::begin(st->
goods); it != end; ++it) {
404 if (
GB(_waiting_acceptance, 0, 12) != 0) {
415 CargoPacket *cp =
new CargoPacket(
GB(_waiting_acceptance, 0, 12), _cargo_periods, source, _cargo_source_xy, _cargo_feeder_share);
428 auto end = std::next(std::begin(st->
goods), std::min(num_cargo, std::size(st->
goods)));
429 for (
auto it = std::begin(st->
goods); it != end; ++it) {
442 static const SaveLoad _old_station_desc[] = {
495 _cargo_source_xy = 0;
497 _cargo_feeder_share = 0;
503 _waiting_acceptance = 0;
523 inline static const SaveLoad description[] = {
542 for (uint i = 0; i < num_tiles; i++) {
554 inline static const SaveLoad description[] = {
592 inline static const SaveLoad description[] = {
651 inline static const SaveLoad description[] = {
684 static const SaveLoad _station_desc[] = {
702 SlSetArrayIndex(st->
index);
744 SlSetArrayIndex(rs->index);