10 #include "../stdafx.h" 11 #include "../station_base.h" 12 #include "../waypoint_base.h" 13 #include "../roadstop_base.h" 14 #include "../vehicle_base.h" 15 #include "../newgrf_station.h" 18 #include "table/strings.h" 20 #include "../safeguards.h" 28 if (!o->
IsType(OT_GOTO_STATION))
return;
61 StationID index = st->index;
63 Town *town = st->town;
65 char *name = st->
name;
67 Date build_date = st->build_date;
70 TileArea train_st = st->train_station;
80 wp->
string_id = train ? STR_SV_STNAME_WAYPOINT : STR_SV_STNAME_BUOY;
86 if (
IsInsideBS(string_id, STR_SV_STNAME_BUOY, 9)) wp->
town_cn = string_id - STR_SV_STNAME_BUOY;
93 SB(
_me[t].m6, 3, 3, STATION_WAYPOINT);
94 wp->
rect.BeforeAddTile(t, StationRect::ADD_FORCE);
100 wp->
rect.BeforeAddTile(xy, StationRect::ADD_FORCE);
106 void AfterLoadStations()
110 for (uint i = 0; i < st->num_specs; i++) {
111 if (st->speclist[i].grfid == 0)
continue;
113 st->speclist[i].spec = StationClass::GetByGrf(st->speclist[i].grfid, st->speclist[i].localidx,
nullptr);
151 if (st->ship_station.tile !=
INVALID_TILE) UpdateStationDockingTiles(st);
155 static const SaveLoad _roadstop_desc[] = {
173 static const SaveLoad _old_station_desc[] = {
232 static uint16 _waiting_acceptance;
233 static uint32 _num_flows;
234 static uint16 _cargo_source;
235 static uint32 _cargo_source_xy;
236 static uint8 _cargo_days;
237 static Money _cargo_feeder_share;
239 static const SaveLoad _station_speclist_desc[] = {
246 std::list<CargoPacket *> _packets;
250 FlowSaveLoad() : source(0), via(0), share(0), restricted(
false) {}
257 static const SaveLoad _flow_desc[] = {
272 static const SaveLoad goods_desc[] = {
300 typedef std::pair<const StationID, std::list<CargoPacket *> > StationCargoPair;
302 static const SaveLoad _cargo_list_desc[] = {
303 SLE_VAR(StationCargoPair, first, SLE_UINT16),
317 if (_packets.empty()) {
318 std::map<StationID, std::list<CargoPacket *> >::iterator it(ge_packets.find(INVALID_STATION));
319 if (it == ge_packets.end()) {
322 it->second.swap(_packets);
325 assert(ge_packets[INVALID_STATION].empty());
326 ge_packets[INVALID_STATION].swap(_packets);
330 static void Load_STNS()
332 _cargo_source_xy = 0;
334 _cargo_feeder_share = 0;
343 _waiting_acceptance = 0;
345 for (
CargoID i = 0; i < num_cargo; i++) {
351 if (
GB(_waiting_acceptance, 0, 12) != 0) {
362 CargoPacket *cp =
new CargoPacket(
GB(_waiting_acceptance, 0, 12), _cargo_days, source, _cargo_source_xy, _cargo_source_xy, _cargo_feeder_share);
372 for (uint i = 0; i < st->
num_specs; i++) {
379 static void Ptrs_STNS()
387 for (
CargoID i = 0; i < num_cargo; i++) {
399 static const SaveLoad _base_station_desc[] = {
419 static const SaveLoad _station_desc[] = {
459 static const SaveLoad _waypoint_desc[] = {
478 return _base_station_desc;
484 SlObject(bst, waypoint ? _waypoint_desc : _station_desc);
491 for (FlowStatMap::const_iterator it(st->
goods[i].
flows.begin()); it != st->
goods[i].
flows.end(); ++it) {
492 _num_flows += (uint32)it->second.GetShares()->size();
495 for (FlowStatMap::const_iterator outer_it(st->
goods[i].
flows.begin()); outer_it != st->
goods[i].
flows.end(); ++outer_it) {
496 const FlowStat::SharesMap *shares = outer_it->second.GetShares();
497 uint32 sum_shares = 0;
499 flow.source = outer_it->first;
500 for (FlowStat::SharesMap::const_iterator inner_it(shares->begin()); inner_it != shares->end(); ++inner_it) {
501 flow.via = inner_it->second;
502 flow.share = inner_it->first - sum_shares;
503 flow.restricted = inner_it->first > outer_it->second.GetUnrestricted();
504 sum_shares = inner_it->first;
505 assert(flow.share > 0);
510 SlObject(const_cast<StationCargoPacketMap::value_type *>(&(*it)), _cargo_list_desc);
515 for (uint i = 0; i < bst->
num_specs; i++) {
520 static void Save_STNN()
524 SlSetArrayIndex(st->index);
529 static void Load_STNN()
539 SlObject(bst, waypoint ? _waypoint_desc : _station_desc);
552 for (
CargoID i = 0; i < num_cargo; i++) {
556 StationID prev_source = INVALID_STATION;
557 for (uint32 j = 0; j < _num_flows; ++j) {
559 if (fs ==
nullptr || prev_source != flow.source) {
560 fs = &(st->
goods[i].
flows.insert(std::make_pair(flow.source,
FlowStat(flow.via, flow.share, flow.restricted))).first->second);
562 fs->
AppendShare(flow.via, flow.share, flow.restricted);
564 prev_source = flow.source;
569 StationCargoPair pair;
570 for (uint j = 0; j < _num_dests; ++j) {
573 assert(pair.second.empty());
582 for (uint i = 0; i < bst->
num_specs; i++) {
589 static void Ptrs_STNN()
596 for (
CargoID i = 0; i < num_cargo; i++) {
604 for (StationCargoPacketMap::ConstMapIterator it = ge->
cargo.
Packets()->begin(); it != ge->
cargo.
Packets()->end(); ++it) {
605 SlObject(const_cast<StationCargoPair *>(&(*it)), _cargo_list_desc);
617 static void Save_ROADSTOP()
620 SlSetArrayIndex(rs->index);
625 static void Load_ROADSTOP()
636 static void Ptrs_ROADSTOP()
644 {
'STNS',
nullptr, Load_STNS, Ptrs_STNS,
nullptr, CH_ARRAY },
645 {
'STNN', Save_STNN, Load_STNN, Ptrs_STNN,
nullptr, CH_ARRAY },
646 {
'ROAD', Save_ROADSTOP, Load_ROADSTOP, Ptrs_ROADSTOP,
nullptr, CH_ARRAY |
CH_LAST},
#define SLE_CONDNULL(length, from, to)
Empty space in some savegame versions.
StationFacility facilities
The facilities that this station has.
uint16 town_cn
The N-1th waypoint for this town (consecutive number)
static bool IsSavegameVersionBefore(SaveLoadVersion major, byte minor=0)
Checks whether the savegame is below major.
TileArea bus_station
Tile area the bus 'station' part covers.
2.0 0.3.0 2.1 0.3.1, 0.3.2
#define SLE_CONDSTR(base, variable, type, length, from, to)
Storage of a string in some savegame versions.
#define SLE_CONDREF(base, variable, type, from, to)
Storage of a reference in some savegame versions.
uint8 num_specs
Number of specs in the speclist.
#define SLE_LST(base, variable, type)
Storage of a list in every savegame version.
#define SLE_REF(base, variable, type)
Storage of a reference in every version of a savegame.
Maximal number of cargo types in a game.
VehicleType
Available vehicle types.
static void UpdateWaypointOrder(Order *o)
Update the buoy orders to be waypoint orders.
TileArea train_station
Tile area the train 'station' part covers.
static bool IsExpected(const BaseStation *st)
Helper for checking whether the given station is of this type.
StationRect rect
NOSAVE: Station spread out rectangle maintained by StationRect::xxx() functions.
Stores station stats for a single cargo.
Load/save a reference to a town.
Representation of a waypoint.
static Pool::IterateWrapper< Station > Iterate(size_t from=0)
Returns an iterable ensemble of all valid stations of type T.
const SaveLoad * GetBaseStationDescription()
Get the base station description to be used for SL_ST_INCLUDE.
StationCargoList cargo
The cargo packets of cargo waiting in this station.
static bool IsDriveThroughStopTile(TileIndex t)
Is tile t a drive through road stop station?
Town * town
The town this station is associated with.
void MoveBuoysToWaypoints()
Perform all steps to upgrade from the old station buoys to the new version that uses waypoints...
#define SLE_CONDLST(base, variable, type, from, to)
Storage of a list in some savegame versions.
void StationUpdateCachedTriggers(BaseStation *st)
Update the cached animation trigger bitmask for a station.
#define SLEG_CONDARR(variable, type, length, from, to)
Storage of a global array in some savegame versions.
GoodsEntry goods[NUM_CARGO]
Goods at this station.
static T SB(T &x, const uint8 s, const uint8 n, const U d)
Set n bits in x starting at bit s to d.
static Station * From(BaseStation *st)
Converts a BaseStation to SpecializedStation with type checking.
static 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.
byte delete_ctr
Delete counter. If greater than 0 then it is decremented until it reaches 0; the waypoint is then is ...
Order * next
Pointer to next order. If nullptr, end of list.
Class for persistent storage of data.
Station is a waypoint (NewGRF only!)
Load/save a reference to a bus/truck stop.
Shared order list linking together the linked list of orders and the list of vehicles sharing this or...
Hand-rolled multimap as map of lists.
The tile has no ownership.
Functions/types related to saving and loading games.
#define SLE_CONDVAR(base, variable, type, from, to)
Storage of a variable in some savegame versions.
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
RoadStop * truck_stops
All the truck stops.
This indicates whether a cargo has a rating at the station.
void Add(TileIndex to_add)
Add a single tile to a tile area; enlarge if needed.
const SaveLoad * GetGoodsDesc()
Wrapper function to get the GoodsEntry's internal structure while some of the variables itself are pr...
Highest possible saveload version.
allow control codes in the strings
5.0 1429 5.1 1440 5.2 1525 0.3.6
bool IsType(OrderType type) const
Check whether this order is of the given type.
TileArea truck_station
Tile area the truck 'station' part covers.
static Owner GetTileOwner(TileIndex tile)
Returns the owner of a tile.
void AfterLoadScanDockingTiles()
(Re)scan for station docking tiles after loading a savegame.
byte status
Status of this cargo, see GoodsEntryStatus.
Container for cargo from the same location and time.
#define TILE_AREA_LOOP(var, ta)
A loop which iterates over the tiles of a TileArea.
#define SLE_WRITEBYTE(base, variable)
Translate values ingame to different values in the savegame and vv.
TileExtended * _me
Extended Tiles of the map.
struct RoadStop * next
Next stop of the given type at this station.
TYPE storage[SIZE]
Memory to for the storage array.
static bool IsBuoyTile(TileIndex t)
Is tile t a buoy tile?
Represents the covered area of e.g.
Class for pooled persistent storage of data.
StationSpecList * speclist
List of station specs of this station.
PersistentStorage * psa
Persistent storage for NewGRF airports.
byte SlReadByte()
Wrapper for reading a byte from the buffer.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
Load/save a reference to a vehicle.
RoadStop * bus_stops
All the road stops.
Handlers and description of chunk.
static void SwapPackets(GoodsEntry *ge)
Swap the temporary packets with the packets without specific destination in the given goods entry...
FlowStatMap flows
Planned flows through this station.
#define SLEG_CONDVAR(variable, type, from, to)
Storage of a global variable in some savegame versions.
#define SLE_END()
End marker of a struct/class save or load.
static StationID GetStationIndex(TileIndex t)
Get StationID from a tile.
Load/save a reference to a cargo packet.
DestinationID GetDestination() const
Gets the destination of this order.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
size_t MapSize() const
Count the number of ranges with equal keys in this MultiMap.
uint32 TileIndex
The index/ID of a Tile.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
void AppendShare(StationID st, uint flow, bool restricted=false)
Add some flow to the end of the shares map.
void SlObject(void *object, const SaveLoad *sld)
Main SaveLoad function.
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function() ...
Flow statistics telling how much flow should be sent along a link.
char * name
Custom town name. If nullptr, the town was not renamed and uses the generated name.
A Stop for a Road Vehicle.
Owner owner
The owner of this station.
void SlAutolength(AutolengthProc *proc, void *arg)
Do something of which I have no idea what it is :P.
int32 Date
The type to store our dates in.
Airport airport
Tile area the airport covers.
void MakeGoToWaypoint(StationID destination)
Makes this order a Go To Waypoint order.
#define SLE_VAR(base, variable, type)
Storage of a variable in every version of a savegame.
const Tcont * Packets() const
Returns a pointer to the cargo packet list (so you can iterate over it etc).
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
#define SLE_STR(base, variable, type, length)
Storage of a string in every savegame version.
Northeast, upper right on your monitor.
216 PR#7380 Multiple docks per station.
byte CargoID
Cargo slots to indicate a cargo type within a game.
Station with train station.
Non-zero when the entries on this road stop are the primary, i.e. the ones to delete.
199 PR#6802 Extend cargotypes to 64
187 25899 Linkgraph - restricted flows
static Station * Get(size_t index)
Gets station with given index.
StringID string_id
Default name (town area) of station.
void Append(CargoPacket *cp, StationID next)
Appends the given cargo packet to the range of packets with the same next station.
Base class for all station-ish types.
Set when the station accepts the cargo currently for final deliveries.
#define SLEG_CONDLST(variable, type, from, to)
Storage of a global list in some savegame versions.
Date build_date
Date of construction.
void AfterLoadRoadStops()
(Re)building of road stop caches after loading a savegame.
Last chunk in this array.
4.0 1 4.1 122 0.3.3, 0.3.4 4.2 1222 0.3.5 4.3 1417 4.4 1426
Load/save a reference to a persistent storage.