23#include "table/strings.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;
74 TileArea train_st = st->train_station;
84 wp->
string_id = train ? STR_SV_STNAME_WAYPOINT : STR_SV_STNAME_BUOY;
85 wp->
name = std::move(name);
90 if (
IsInsideBS(string_id, STR_SV_STNAME_BUOY, 9)) wp->
town_cn = string_id - STR_SV_STNAME_BUOY;
99 wp->
rect.BeforeAddTile(t, StationRect::ADD_FORCE);
105 wp->
rect.BeforeAddTile(xy, StationRect::ADD_FORCE);
111void AfterLoadStations()
116 if (sm.grfid == 0)
continue;
120 if (sm.grfid == 0)
continue;
159static const SaveLoad _roadstop_desc[] = {
165static uint16_t _waiting_acceptance;
166static uint32_t _old_num_flows;
167static uint16_t _cargo_source;
168static uint32_t _cargo_source_xy;
169static uint8_t _cargo_periods;
170static Money _cargo_feeder_share;
172std::list<CargoPacket *> _packets;
173uint32_t _old_num_dests;
182typedef std::pair<const StationID, std::list<CargoPacket *> > StationCargoPair;
184static OldPersistentStorage _old_st_persistent_storage;
193 StationCargoPacketMap &ge_packets =
const_cast<StationCargoPacketMap &
>(*ge->
GetOrCreateData().cargo.Packets());
195 if (_packets.empty()) {
196 std::map<StationID, std::list<CargoPacket *> >::iterator it(ge_packets.find(StationID::Invalid()));
197 if (it == ge_packets.end()) {
200 it->second.swap(_packets);
203 assert(ge_packets[StationID::Invalid()].empty());
204 ge_packets[StationID::Invalid()].swap(_packets);
211 static inline const SaveLoad description[] = {
234 using StationWaitingTriggersPair = std::pair<const TileIndex, StationRandomTriggers>;
236 static inline const SaveLoad description[] = {
245 for (
const auto &pair : st->tile_waiting_random_triggers) {
253 if (num == 0)
return;
255 StationWaitingTriggersPair pair;
256 for (uint j = 0; j < num; ++j) {
258 st->tile_waiting_random_triggers.emplace(pair.first, pair.second);
265 static inline const SaveLoad description[] = {
280 for (StationCargoPacketMap::ConstMapIterator it(packets->begin()); it != packets->end(); ++it) {
288 if (num_dests == 0)
return;
291 StationCargoPair pair;
292 for (uint j = 0; j < num_dests; ++j) {
294 const_cast<StationCargoPacketMap &
>(*(data.
cargo.
Packets()))[pair.first].swap(pair.second);
295 assert(pair.second.empty());
311 static inline const SaveLoad description[] = {
326 size_t num_flows = 0;
328 num_flows += it.second.GetShares()->size();
333 const FlowStat::SharesMap *shares = outer_it.second.GetShares();
334 uint32_t sum_shares = 0;
336 flow.source = outer_it.first;
337 for (
auto &inner_it : *shares) {
338 flow.via = inner_it.second;
339 flow.share = inner_it.first - sum_shares;
340 flow.restricted = inner_it.first > outer_it.second.GetUnrestricted();
341 sum_shares = inner_it.first;
342 assert(flow.share > 0);
351 if (num_flows == 0)
return;
356 StationID prev_source = StationID::Invalid();
357 for (uint32_t j = 0; j < num_flows; ++j) {
359 if (fs ==
nullptr || prev_source != flow.source) {
360 fs = &(data.
flows.emplace(flow.source,
FlowStat(flow.via, flow.share, flow.restricted))).first->second;
362 fs->
AppendShare(flow.via, flow.share, flow.restricted);
364 prev_source = flow.source;
371 static inline uint cargo_reserved_count;
373 static inline const SaveLoad description[] = {
434 std::copy(std::begin(_old_st_persistent_storage.storage), std::end(_old_st_persistent_storage.storage), std::begin(st->
airport.
psa->
storage));
437 auto end = std::next(std::begin(st->
goods), std::min(this->GetNumCargo(), std::size(st->
goods)));
438 for (
auto it = std::begin(st->
goods); it != end; ++it) {
449 if (
GB(_waiting_acceptance, 0, 12) != 0) {
473 auto end = std::next(std::begin(st->
goods), std::min(num_cargo, std::size(st->
goods)));
474 for (
auto it = std::begin(st->
goods); it != end; ++it) {
487static const SaveLoad _old_station_desc[] = {
533struct STNSChunkHandler : ChunkHandler {
540 _cargo_source_xy = 0;
542 _cargo_feeder_share = 0;
548 _waiting_acceptance = 0;
568 static inline const SaveLoad description[] = {
584 static inline const SaveLoad description[] = {
623 static inline const SaveLoad description[] = {
682 static inline const SaveLoad description[] = {
715static const SaveLoad _station_desc[] = {
724struct STNNChunkHandler : ChunkHandler {
733 SlSetArrayIndex(st->index);
767struct ROADChunkHandler : ChunkHandler {
775 SlSetArrayIndex(rs->index);
std::vector< SpecMapping< T > > & GetStationSpecList(BaseStation *bst)
Get spec mapping list for each supported custom spec type.
constexpr T SB(T &x, const uint8_t s, const uint8_t n, const U d)
Set n bits in x starting at bit s to d.
static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
static constexpr CargoType NUM_CARGO
Maximum number of cargo types in a game.
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
constexpr Timpl & Set()
Set all bits.
const Tcont * Packets() const
Returns a pointer to the cargo packet list (so you can iterate over it etc).
Default handler for saving/loading an object to/from disk.
SaveLoadTable GetDescription() const override
Flow statistics telling how much flow should be sent along a link.
void AppendShare(StationID st, uint flow, bool restricted=false)
Add some flow to the end of the shares map.
static const StationSpec * GetByGrf(GrfID grfid, uint16_t local_id)
SaveLoadTable GetLoadDescription() const
Get the description for how to load the chunk.
std::vector< RoadStopTileData > & GetVector(BaseStation *bst) const override
Get instance of vector to load/save.
SaveLoad handler for the BaseStation, which all other stations / waypoints make use of.
void Save(BaseStation *bst) const override
Save the object to disk.
void Load(BaseStation *bst) const override
Load the object from disk.
void FixPointers(BaseStation *bst) const override
A post-load callback to fix SaveLoadType::Reference integers into pointers.
void Save(GoodsEntry *ge) const override
Save the object to disk.
void FixPointers(GoodsEntry *ge) const override
A post-load callback to fix SaveLoadType::Reference integers into pointers.
void Load(GoodsEntry *ge) const override
Load the object from disk.
void Load(GoodsEntry *ge) const override
Load the object from disk.
void Save(GoodsEntry *ge) const override
Save the object to disk.
size_t GetNumCargo() const
Get the number of cargoes used by this savegame version.
void FixPointers(BaseStation *bst) const override
A post-load callback to fix SaveLoadType::Reference integers into pointers.
void Load(BaseStation *bst) const override
Load the object from disk.
void Save(BaseStation *bst) const override
Save the object to disk.
SaveLoad handler for a normal station (read: not a waypoint).
void FixPointers(BaseStation *bst) const override
A post-load callback to fix SaveLoadType::Reference integers into pointers.
void Load(BaseStation *bst) const override
Load the object from disk.
void Save(BaseStation *bst) const override
Save the object to disk.
size_t GetLength() const override
Get number of elements to load into vector.
static uint8_t last_num_specs
Number of specs of the last loaded station.
std::vector< SpecMapping< T > > & GetVector(BaseStation *bst) const override
Get instance of vector to load/save.
void Load(BaseStation *st) const override
Load the object from disk.
void Save(BaseStation *st) const override
Save the object to disk.
void Save(BaseStation *bst) const override
Save the object to disk.
void FixPointers(BaseStation *bst) const override
A post-load callback to fix SaveLoadType::Reference integers into pointers.
void Load(BaseStation *bst) const override
Load the object from disk.
void Append(CargoPacket *cp, StationID next)
Appends the given cargo packet to the range of packets with the same next station.
uint reserved_count
Amount of cargo being reserved for loading.
Wrapper class to abstract away the way the tiles are stored.
uint8_t & m6()
General purpose.
StrongType::Typedef< int32_t, DateTag< struct Calendar >, StrongType::Compare, StrongType::Integer > Date
Default handler for saving/loading a vector to/from disk.
static constexpr Owner OWNER_NONE
The tile has no ownership.
@ NE
Northeast, upper right on your monitor.
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23).
constexpr bool IsInsideBS(const T x, const size_t base, const size_t size)
Checks if a value is between a window started at some base point.
@ Invalid
An invalid spec feature.
void RoadStopUpdateCachedTriggers(BaseStation *st)
Update the cached animation trigger bitmask for a station.
NewGRF definitions and structures for road stops.
void StationUpdateCachedTriggers(BaseStation *st)
Update the cached animation trigger bitmask for a station.
Header file for NewGRF stations.
Base class for roadstops.
A number of safeguards to prevent using unsafe methods.
std::vector< SaveLoad > SlCompatTableHeader(const SaveLoadTable &slt, const SaveLoadCompatTable &slct)
Load a table header in a savegame compatible way.
size_t SlGetStructListLength(size_t limit)
Get the length of this list; if it exceeds the limit, error out.
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
uint8_t SlReadByte()
Wrapper for reading a byte from the buffer.
void SlObject(void *object, const SaveLoadTable &slt)
Main SaveLoad function.
std::vector< SaveLoad > SlTableHeader(const SaveLoadTable &slt)
Save or Load a table header.
void SlSetStructListLength(size_t length)
Set the length of this list.
Functions/types related to saving and loading games.
@ U64
A 64 bit unsigned int.
@ U8
A 8 bit unsigned int.
@ U32
A 32 bit unsigned int.
@ I32
A 32 bit signed int.
@ I64
A 64 bit signed int.
@ U16
A 16 bit unsigned int.
#define SLEG_CONDARR(name, variable, type, length, from, to)
Storage of a global fixed-size array of SaveLoadType::Variable elements in some savegame versions.
@ U8
A 8 bit unsigned int.
@ U32
A 32 bit unsigned int.
@ U16
A 16 bit unsigned int.
#define SLEG_STRUCTLIST(name, handler)
Storage of a list of structs in every savegame version.
#define SLEG_CONDVAR(name, variable, type, from, to)
Storage of a global variable in some savegame versions.
#define SLE_VARNAME(base, variable, name, type)
Storage of a variable in every version of a savegame.
std::reference_wrapper< const ChunkHandler > ChunkHandlerRef
A reference to ChunkHandler.
@ CargoPacket
Load/save a reference to a cargo packet.
@ Storage
Load/save a reference to a persistent storage.
@ Town
Load/save a reference to a town.
@ Vehicle
Load/save a reference to a vehicle.
@ RoadStop
Load/save a reference to a bus/truck stop.
#define SLEG_CONDREFLIST(name, variable, type, from, to)
Storage of a global reference list in some savegame versions.
std::span< const ChunkHandlerRef > ChunkHandlerTable
A table of ChunkHandler entries.
#define SLE_SAVEBYTE(base, variable)
Only write byte during saving; never read it during loading.
#define SLE_REF(base, variable, type)
Storage of a reference in every version of a savegame.
#define SLE_CONDREFLIST(base, variable, type, from, to)
Storage of a list of SaveLoadType::Reference elements in some savegame versions.
#define SLE_REFLIST(base, variable, type)
Storage of a list of SaveLoadType::Reference elements in every savegame version.
std::span< const struct SaveLoadCompat > SaveLoadCompatTable
A table of SaveLoadCompat entries.
#define SLEG_STRUCT(name, handler)
Storage of a structs in every savegame version.
#define SLE_CONDSSTR(base, variable, type, from, to)
Storage of a std::string in some savegame versions.
#define SLE_CONDVAR(base, variable, type, from, to)
Storage of a variable in some savegame versions.
bool IsSavegameVersionBefore(SaveLoadVersion major, uint8_t minor=0)
Checks whether the savegame is below major.
#define SLE_SSTR(base, variable, type)
Storage of a std::string in every savegame version.
@ BigDates
Saveload version: 31, SVN revision: 5999 Change date from 1920 - 2090 to 0 - 5 000 000.
@ ExtendCargotypes
Saveload version: 199, GitHub pull request: 6802 Extend cargotypes to 64.
@ UnifyWaypointAndStation
Saveload version: 123, SVN revision: 16909 Unify stations and waypoints.
@ UnifyCurrency
Saveload version: 65, SVN revision: 10210 Make all variables related to currency 64 bits.
@ LinkgraphRestrictedFlow
Saveload version: 187, SVN revision: 25899 Linkgraph - restricted flows.
@ CargoReservation
Saveload version: 181, SVN revision: 25012 Persist the reservation of cargo for vehicles instead of ...
@ FifoLoading
Saveload version: 57, SVN revision: 9691 First-in-first-out loading of vehicles.
@ RoadWaypoints
Saveload version: 338, GitHub pull request: 12572 Road waypoints.
@ ReplaceCustomNameArray
Saveload version: 84, SVN revision: 11822 Replace single fixed size array of custom names,...
@ LastVehicleType
Saveload version: 26, SVN revision: 4466 Store the last vehicle type at stations instead of the vehi...
@ NewGRFSuppliedStationName
Saveload version: 103, SVN revision: 14598 NewGRF industry supplying default names for nearby statio...
@ VehicleCurrencyStationChanges
Saveload version: 2.0, release: 0.3.0 Adding vehicle state, larger currency size for statistics,...
@ MultitileDocks
Saveload version: 216, GitHub pull request: 7380 Multiple docks per station.
@ LargerCargoSource
Saveload version: 7.0, SVN revision: 1770 With more stations, the size of the cargo source needed to...
@ TownAcceptance
Saveload version: 127, SVN revision: 17439 Store mask of cargos accepted by town houses and head qua...
@ TransferOrder
Saveload version: 14.0, SVN revision: 2441 Transfer orders for feeder systems.
@ FractionalCargoDelivery
Saveload version: 150, SVN revision: 20857 When spreading cargo over stations, spread fractional amo...
@ NewGRFRoadStops
Saveload version: 303, GitHub pull request: 10144 NewGRF road stops.
@ CargoSourceTile
Saveload version: 44, SVN revision: 8144 Store the source tile of the cargo, so accurate payment can...
@ StoreAirportSize
Saveload version: 140, SVN revision: 19382 Store the size of the airport in the station.
@ ExtendEntityMapping
Saveload version: 311, GitHub pull request: 10672 Extend entity mapping range.
@ MultipleRoadStops
Saveload version: 6.0, SVN revision: 1721 Multi tile road stops, and some map size related fixes.
@ RoadStopTileData
Saveload version: 340, GitHub pull request: 12883 Move storage of road stop tile data,...
@ Cargodist
Saveload version: 183, SVN revision: 25363 Cargodist.
@ MoreAirportBlocks
Saveload version: 46, SVN revision: 8705 Increase number of blocks an airport can have.
@ MinVersion
First savegame version.
@ WaypointMoreLikeStation
Saveload version: 122, SVN revision: 16855 Make waypoint data look more like stations.
@ BiggerStationVariables
Saveload version: 3.0 Increase size of airport blocks/station build date.
@ NewGRFAirportSmoke
Saveload version: 145, SVN revision: 20376 NewGRF support for airport and configurable amount of smo...
@ SaveloadListLength
Saveload version: 293, GitHub pull request: 9374 Consistency in list length with SaveLoadType::Struc...
@ MultiTileWaypoints
Saveload version: 124, SVN revision: 16993 Waypoints can be bigger than a single tile.
@ NewGRFCargo
Saveload version: 55, SVN revision: 9638 Increase number of cargos and NewGRF control of cargos.
@ CargoPackets
Saveload version: 68, SVN revision: 10266 Account for individual units of cargo, i....
@ MaxVersion
Highest possible saveload version.
@ NewGRFStations
Saveload version: 27, SVN revision: 4757 NewGRF graphics for stations.
@ PersistentStoragePool
Saveload version: 161, SVN revision: 22567 Store persistent storage in a pool.
#define SLE_CONDREF(base, variable, type, from, to)
Storage of a reference in some savegame versions.
#define SLEG_CONDSTRUCTLIST(name, handler, from, to)
Storage of a list of structs in some savegame versions.
@ ReadOnly
Chunk is never saved.
@ Table
An Array with a header describing the elements.
#define SLE_VAR(base, variable, type)
Storage of a variable in every version of a savegame.
#define SLE_CONDVARNAME(base, variable, name, type, from, to)
Storage of a variable in some savegame versions.
Base classes/functions for stations.
void SetRailStationTileFlags(TileIndex tile, const StationSpec *statspec)
Set rail station tile flags for the given tile.
bool IsDriveThroughStopTile(Tile t)
Is tile t a drive through road stop station or waypoint?
StationID GetStationIndex(Tile t)
Get StationID from a tile.
bool HasStationTileRail(Tile t)
Has this station tile a rail?
bool IsBuoyTile(Tile t)
Is tile t a buoy tile?
void MoveBuoysToWaypoints()
Perform all steps to upgrade from the old station buoys to the new version that uses waypoints.
static void UpdateWaypointOrder(Order &o)
Update the buoy orders to be waypoint orders.
void AfterLoadRoadStops()
(Re)building of road stop caches after loading a savegame.
static void SwapPackets(GoodsEntry *ge)
Swap the temporary packets with the packets without specific destination in the given goods entry.
Loading of station chunks before table headers were added.
const SaveLoadCompat _station_base_sl_compat[]
Original field order for SlStationBase.
const SaveLoadCompat _roadstop_sl_compat[]
Original field order for _roadstop_desc.
const SaveLoadCompat _station_sl_compat[]
Original field order for _station_desc.
const SaveLoadCompat _station_cargo_sl_compat[]
Original field order for SlStationCargo.
const SaveLoadCompat _station_goods_sl_compat[]
Original field order for SlStationGoods.
const SaveLoadCompat _station_flow_sl_compat[]
Original field order for SlStationFlow.
const SaveLoadCompat _station_waypoint_sl_compat[]
Original field order for SlStationWaypoint.
const SaveLoadCompat _station_normal_sl_compat[]
Original field order for SlStationNormal.
const SaveLoadCompat _old_station_sl_compat[]
Original field order for _old_station_desc.
const SaveLoadCompat _station_spec_list_sl_compat[]
Original field order for SlStationSpecList.
@ Dock
Station with a dock.
@ Waypoint
Station is a waypoint.
@ Train
Station with train station.
@ Airport
Station with an airport.
@ RailWaypoint
Waypoint for trains.
EnumBitSet< StationFacility, uint8_t > StationFacilities
Bitset of StationFacility elements.
@ Waypoint
Station is a waypoint (Save load conversion and NewGRF only!).
Definition of base types and functions in a cross-platform compatible way.
@ AllowControlCode
Allow the special control codes.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
PersistentStorage * psa
Persistent storage for NewGRF airports.
Base class for all station-ish types.
StringID string_id
Default name (town area) of station.
StationFacilities facilities
The facilities that this station has.
TileArea train_station
Tile area the train 'station' part covers.
Owner owner
The owner of this station.
uint8_t delete_ctr
Delete counter. If greater than 0 then it is decremented until it reaches 0; the waypoint is then is ...
StationRect rect
NOSAVE: Station spread out rectangle maintained by StationRect::xxx() functions.
Town * town
The town this station is associated with.
std::vector< RoadStopTileData > custom_roadstop_tile_data
List of custom road stop tile data.
TimerGameCalendar::Date build_date
Date of construction.
std::string name
Custom name.
Container for cargo from the same location and time.
FlowStatMap flows
Planned flows through this station.
StationCargoList cargo
The cargo packets of cargo waiting in this station.
Stores station stats for a single cargo.
States status
Status of this cargo, see State.
@ Acceptance
Set when the station accepts the cargo currently for final deliveries.
@ Rating
This indicates whether a cargo has a rating at the station.
const GoodsEntryData & GetData() const
Get optional cargo packet/flow data.
bool HasData() const
Test if this goods entry has optional cargo packet/flow data.
GoodsEntryData & GetOrCreateData()
Get optional cargo packet/flow data.
static IterateWrapper Iterate()
Returns an iterable ensemble of all Tiles.
Shared order list linking together the linked list of orders and the list of vehicles sharing this or...
If you change this, keep in mind that it is also saved in 2 other places:
DestinationID GetDestination() const
Gets the destination of this order.
bool IsType(OrderType type) const
Check whether this order is of the given type.
void MakeGoToWaypoint(StationID destination)
Makes this order a Go To Waypoint order.
void Add(TileIndex to_add)
Add a single tile to a tile area; enlarge if needed.
StorageType storage
Memory for the storage array.
static Pool::IterateWrapper< OrderList > Iterate(size_t from=0)
static T * Create(Targs &&... args)
static T * CreateAtIndex(RoadStopID index, Targs &&... args)
static bool CanAllocateItem(size_t n=1)
void FixPointers() const override
Fix the pointers.
void Load() const override
Load the chunk.
void Save() const override
Save the chunk.
A Stop for a Road Vehicle.
@ BaseEntry
Non-zero when the entries on this road stop are the primary, i.e. the ones to delete.
RoadStop * next
Next stop of the given type at this station.
void FixPointers() const override
Fix the pointers.
void Save() const override
Save the chunk.
void Load() const override
Load the chunk.
void Load() const override
Load the chunk.
void FixPointers() const override
Fix the pointers.
static bool IsExpected(const BaseStation *st)
static Pool::IterateWrapper< Station > Iterate(size_t from=0)
static Waypoint * CreateAtIndex(StationID index, Targs &&... args)
static Station * Get(auto index)
static Station * From(BaseStation *st)
RoadStop * bus_stops
All the road stops.
std::array< GoodsEntry, NUM_CARGO > goods
Goods at this station.
TileArea bus_station
Tile area the bus 'station' part covers.
Airport airport
Tile area the airport covers.
TileArea truck_station
Tile area the truck 'station' part covers.
RoadStop * truck_stops
All the truck stops.
static constexpr VarType U16
Store a 16 bits unsigned int.
static constexpr VarType U8
Store a 8 bits unsigned int.
static constexpr VarType STR
Store string.
static constexpr VarType I64
Store a 64 bits signed int.
static constexpr VarType U64
Store a 64 bits unsigned int.
static constexpr VarType U32
Store a 32 bits unsigned int.
static constexpr VarType STRINGID
Store a StringID.
static constexpr VarType I32
Store a 32 bits signed int.
static constexpr VarType BOOL
Store a boolean (as int8).
Representation of a waypoint.
uint16_t town_cn
The N-1th waypoint for this town (consecutive number).
static bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Owner GetTileOwner(Tile tile)
Returns the owner of a tile.
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
@ Station
A tile of a station or airport.
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
Definition of the game-calendar-timer.
Base class for all vehicles.
VehicleType
Available vehicle types.
@ Train
Train vehicle type.