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);
111void AfterLoadStations()
116 if (sm.grfid == 0)
continue;
120 if (sm.grfid == 0)
continue;
131 RoadStopUpdateCachedTriggers(st);
153static const SaveLoad _roadstop_desc[] = {
159static uint16_t _waiting_acceptance;
160static uint32_t _old_num_flows;
161static uint16_t _cargo_source;
162static uint32_t _cargo_source_xy;
163static uint8_t _cargo_periods;
164static Money _cargo_feeder_share;
166std::list<CargoPacket *> _packets;
167uint32_t _old_num_dests;
170 FlowSaveLoad() : source(0), via(0), share(0), restricted(
false) {}
177typedef 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);
206 inline static const SaveLoad description[] = {
229 inline static const SaveLoad description[] = {
230 SLE_VAR(StationCargoPair, first, SLE_UINT16),
238 for (StationCargoPacketMap::ConstMapIterator it(ge->
cargo.
Packets()->begin()); it != ge->
cargo.
Packets()->end(); ++it) {
239 SlObject(
const_cast<StationCargoPacketMap::value_type *
>(&(*it)), this->GetDescription());
247 StationCargoPair pair;
248 for (uint j = 0; j < num_dests; ++j) {
249 SlObject(&pair, this->GetLoadDescription());
251 assert(pair.second.empty());
255 void FixPointers(
GoodsEntry *ge)
const override
257 for (StationCargoPacketMap::ConstMapIterator it = ge->
cargo.
Packets()->begin(); it != ge->
cargo.
Packets()->end(); ++it) {
258 SlObject(
const_cast<StationCargoPair *
>(&(*it)), this->GetDescription());
265 inline static const SaveLoad description[] = {
275 size_t num_flows = 0;
276 for (
const auto &it : ge->
flows) {
277 num_flows += it.second.GetShares()->size();
281 for (
const auto &outer_it : ge->
flows) {
282 const FlowStat::SharesMap *shares = outer_it.second.GetShares();
283 uint32_t sum_shares = 0;
285 flow.source = outer_it.first;
286 for (
auto &inner_it : *shares) {
287 flow.via = inner_it.second;
288 flow.share = inner_it.first - sum_shares;
289 flow.restricted = inner_it.first > outer_it.second.GetUnrestricted();
290 sum_shares = inner_it.first;
291 assert(flow.share > 0);
292 SlObject(&flow, this->GetDescription());
303 StationID prev_source = INVALID_STATION;
304 for (uint32_t j = 0; j < num_flows; ++j) {
305 SlObject(&flow, this->GetLoadDescription());
306 if (fs ==
nullptr || prev_source != flow.source) {
307 fs = &(ge->
flows.emplace(flow.source,
FlowStat(flow.via, flow.share, flow.restricted))).first->second;
309 fs->
AppendShare(flow.via, flow.share, flow.restricted);
311 prev_source = flow.source;
318 inline static const SaveLoad description[] = {
381 auto end = std::next(std::begin(st->
goods), std::min(this->GetNumCargo(), std::size(st->
goods)));
382 for (
auto it = std::begin(st->
goods); it != end; ++it) {
390 if (
GB(_waiting_acceptance, 0, 12) != 0) {
401 CargoPacket *cp =
new CargoPacket(
GB(_waiting_acceptance, 0, 12), _cargo_periods, source, _cargo_source_xy, _cargo_feeder_share);
414 auto end = std::next(std::begin(st->
goods), std::min(num_cargo, std::size(st->
goods)));
415 for (
auto it = std::begin(st->
goods); it != end; ++it) {
428static const SaveLoad _old_station_desc[] = {
481 _cargo_source_xy = 0;
483 _cargo_feeder_share = 0;
489 _waiting_acceptance = 0;
509 inline static const SaveLoad description[] = {
525 inline static const SaveLoad description[] = {
563 inline static const SaveLoad description[] = {
622 inline static const SaveLoad description[] = {
655static const SaveLoad _station_desc[] = {
673 SlSetArrayIndex(st->
index);
715 SlSetArrayIndex(rs->index);
std::vector< SpecMapping< T > > & GetStationSpecList(BaseStation *bst)
Get spec mapping list for each supported custom spec type.
debug_inline constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
constexpr T AssignBit(T &x, const uint8_t y, bool value)
Assigns a bit in a variable.
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.
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
debug_inline static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
static const CargoID NUM_CARGO
Maximum number of cargo types in a game.
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.
Hand-rolled multimap as map of lists.
size_t MapSize() const
Count the number of ranges with equal keys in this MultiMap.
static const Tspec * GetByGrf(uint32_t grfid, uint16_t local_id)
Retrieve a spec by GRF location.
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.
size_t GetNumCargo() const
Get the number of cargoes used by this savegame version.
SaveLoad handler for a normal station (read: not a waypoint).
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 Append(CargoPacket *cp, StationID next)
Appends the given cargo packet to the range of packets with the same next station.
Wrapper class to abstract away the way the tiles are stored.
debug_inline uint8_t & m6()
General purpose.
Default handler for saving/loading a vector to/from disk.
@ OWNER_NONE
The tile has no ownership.
@ DIAGDIR_NE
Northeast, upper right on your monitor.
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.
void StationUpdateCachedTriggers(BaseStation *st)
Update the cached animation trigger bitmask for a station.
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.
#define SLEG_CONDARR(name, variable, type, length, from, to)
Storage of a global fixed-size array of SL_VAR elements in some savegame versions.
#define SLEG_STRUCTLIST(name, handler)
Storage of a list of structs in every savegame version.
@ SLF_ALLOW_CONTROL
Allow control codes in the strings.
#define SLEG_CONDVAR(name, variable, type, from, to)
Storage of a global variable in some savegame versions.
@ CH_READONLY
Chunk is never saved.
std::reference_wrapper< const ChunkHandler > ChunkHandlerRef
A reference to ChunkHandler.
#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 SL_REF elements in some savegame versions.
#define SLE_REFLIST(base, variable, type)
Storage of a list of SL_REF 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.
@ SLV_ROAD_WAYPOINTS
338 PR#12572 Road waypoints
@ SLV_EXTEND_CARGOTYPES
199 PR#6802 Extend cargotypes to 64
@ SLV_SAVELOAD_LIST_LENGTH
293 PR#9374 Consistency in list length with SL_STRUCT / SL_STRUCTLIST / SL_DEQUE / SL_REFLIST.
@ SLV_MULTITILE_DOCKS
216 PR#7380 Multiple docks per station.
@ SL_MAX_VERSION
Highest possible saveload version.
@ SL_MIN_VERSION
First savegame version.
@ SLV_NEWGRF_ROAD_STOPS
303 PR#10144 NewGRF road stops.
@ SLV_2
2.0 0.3.0 2.1 0.3.1, 0.3.2
@ SLV_187
187 25899 Linkgraph - restricted flows
@ SLV_183
183 25363 Cargodist
@ SLV_EXTEND_ENTITY_MAPPING
311 PR#10672 Extend entity mapping range.
@ SLV_ROAD_STOP_TILE_DATA
340 PR#12883 Move storage of road stop tile data, also save for road waypoints.
#define SLE_CONDREF(base, variable, type, from, to)
Storage of a reference in some savegame versions.
@ REF_TOWN
Load/save a reference to a town.
@ REF_CARGO_PACKET
Load/save a reference to a cargo packet.
@ REF_STORAGE
Load/save a reference to a persistent storage.
@ REF_VEHICLE
Load/save a reference to a vehicle.
@ REF_ROADSTOPS
Load/save a reference to a bus/truck stop.
#define SLEG_CONDSTRUCTLIST(name, handler, from, to)
Storage of a list of structs in some savegame versions.
#define SLE_VAR(base, variable, type)
Storage of a variable in every version of a savegame.
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 IsBuoyTile(Tile t)
Is tile t a buoy tile?
static void UpdateWaypointOrder(Order *o)
Update the buoy orders to be waypoint orders.
void MoveBuoysToWaypoints()
Perform all steps to upgrade from the old station buoys to the new version that uses waypoints.
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.
@ HVOT_WAYPOINT
Station is a waypoint (NewGRF only!)
@ FACIL_DOCK
Station with a dock.
@ FACIL_AIRPORT
Station with an airport.
@ FACIL_WAYPOINT
Station is a waypoint.
@ FACIL_TRAIN
Station with train station.
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.
StationFacility facilities
The facilities that this station has.
StringID string_id
Default name (town area) of station.
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.
Handlers and description of chunk.
Stores station stats for a single cargo.
FlowStatMap flows
Planned flows through this station.
@ GES_ACCEPTANCE
Set when the station accepts the cargo currently for final deliveries.
@ GES_RATING
This indicates whether a cargo has a rating at the station.
StationCargoList cargo
The cargo packets of cargo waiting in this station.
uint8_t status
Status of this cargo, see GoodsEntryStatus.
Shared order list linking together the linked list of orders and the list of vehicles sharing this or...
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.
Order * next
Pointer to next order. If nullptr, end of list.
Represents the covered area of e.g.
void Add(TileIndex to_add)
Add a single tile to a tile area; enlarge if needed.
Class for persistent storage of data.
StorageType storage
Memory for the storage array.
Class for pooled persistent storage of data.
Tindex index
Index of this pool item.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function()
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.
@ RSSFB_BASE_ENTRY
Non-zero when the entries on this road stop are the primary, i.e. the ones to delete.
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)
Helper for checking whether the given station is of this type.
static Pool::IterateWrapper< Station > Iterate(size_t from=0)
Returns an iterable ensemble of all valid stations of type T.
static Station * Get(size_t index)
Gets station with given index.
static Station * From(BaseStation *st)
Converts a BaseStation to SpecializedStation with type checking.
RoadStop * bus_stops
All the road stops.
GoodsEntry goods[NUM_CARGO]
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.
std::string name
Custom town name. If empty, the town was not renamed and uses the generated name.
Representation of a waypoint.
uint16_t town_cn
The N-1th waypoint for this town (consecutive number)
Owner GetTileOwner(Tile tile)
Returns the owner of a tile.
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
@ MP_STATION
A tile of a station.
VehicleType
Available vehicle types.
@ VEH_SHIP
Ship vehicle type.
@ VEH_TRAIN
Train vehicle type.