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);
144 static const SaveLoad _roadstop_desc[] = {
162 static const SaveLoad _old_station_desc[] = {
221 static uint16 _waiting_acceptance;
222 static uint32 _num_flows;
223 static uint16 _cargo_source;
224 static uint32 _cargo_source_xy;
225 static uint8 _cargo_days;
226 static Money _cargo_feeder_share;
228 static const SaveLoad _station_speclist_desc[] = {
235 std::list<CargoPacket *> _packets;
239 FlowSaveLoad() : source(0), via(0), share(0), restricted(
false) {}
246 static const SaveLoad _flow_desc[] = {
261 static const SaveLoad goods_desc[] = {
289 typedef std::pair<const StationID, std::list<CargoPacket *> > StationCargoPair;
291 static const SaveLoad _cargo_list_desc[] = {
292 SLE_VAR(StationCargoPair, first, SLE_UINT16),
306 if (_packets.empty()) {
307 std::map<StationID, std::list<CargoPacket *> >::iterator it(ge_packets.find(INVALID_STATION));
308 if (it == ge_packets.end()) {
311 it->second.swap(_packets);
314 assert(ge_packets[INVALID_STATION].empty());
315 ge_packets[INVALID_STATION].swap(_packets);
319 static void Load_STNS()
321 _cargo_source_xy = 0;
323 _cargo_feeder_share = 0;
332 _waiting_acceptance = 0;
334 for (
CargoID i = 0; i < num_cargo; i++) {
340 if (
GB(_waiting_acceptance, 0, 12) != 0) {
351 CargoPacket *cp =
new CargoPacket(
GB(_waiting_acceptance, 0, 12), _cargo_days, source, _cargo_source_xy, _cargo_source_xy, _cargo_feeder_share);
361 for (uint i = 0; i < st->
num_specs; i++) {
368 static void Ptrs_STNS()
376 for (
CargoID i = 0; i < num_cargo; i++) {
388 static const SaveLoad _base_station_desc[] = {
408 static const SaveLoad _station_desc[] = {
448 static const SaveLoad _waypoint_desc[] = {
467 return _base_station_desc;
473 SlObject(bst, waypoint ? _waypoint_desc : _station_desc);
480 for (FlowStatMap::const_iterator it(st->
goods[i].
flows.begin()); it != st->
goods[i].
flows.end(); ++it) {
481 _num_flows += (uint32)it->second.GetShares()->size();
484 for (FlowStatMap::const_iterator outer_it(st->
goods[i].
flows.begin()); outer_it != st->
goods[i].
flows.end(); ++outer_it) {
485 const FlowStat::SharesMap *shares = outer_it->second.GetShares();
486 uint32 sum_shares = 0;
488 flow.source = outer_it->first;
489 for (FlowStat::SharesMap::const_iterator inner_it(shares->begin()); inner_it != shares->end(); ++inner_it) {
490 flow.via = inner_it->second;
491 flow.share = inner_it->first - sum_shares;
492 flow.restricted = inner_it->first > outer_it->second.GetUnrestricted();
493 sum_shares = inner_it->first;
494 assert(flow.share > 0);
499 SlObject(const_cast<StationCargoPacketMap::value_type *>(&(*it)), _cargo_list_desc);
504 for (uint i = 0; i < bst->
num_specs; i++) {
509 static void Save_STNN()
513 SlSetArrayIndex(st->index);
518 static void Load_STNN()
528 SlObject(bst, waypoint ? _waypoint_desc : _station_desc);
541 for (
CargoID i = 0; i < num_cargo; i++) {
545 StationID prev_source = INVALID_STATION;
546 for (uint32 j = 0; j < _num_flows; ++j) {
548 if (fs ==
nullptr || prev_source != flow.source) {
549 fs = &(st->
goods[i].
flows.insert(std::make_pair(flow.source,
FlowStat(flow.via, flow.share, flow.restricted))).first->second);
551 fs->
AppendShare(flow.via, flow.share, flow.restricted);
553 prev_source = flow.source;
558 StationCargoPair pair;
559 for (uint j = 0; j < _num_dests; ++j) {
562 assert(pair.second.empty());
571 for (uint i = 0; i < bst->
num_specs; i++) {
578 static void Ptrs_STNN()
585 for (
CargoID i = 0; i < num_cargo; i++) {
593 for (StationCargoPacketMap::ConstMapIterator it = ge->
cargo.
Packets()->begin(); it != ge->
cargo.
Packets()->end(); ++it) {
594 SlObject(const_cast<StationCargoPair *>(&(*it)), _cargo_list_desc);
606 static void Save_ROADSTOP()
609 SlSetArrayIndex(rs->index);
614 static void Load_ROADSTOP()
625 static void Ptrs_ROADSTOP()
633 {
'STNS',
nullptr, Load_STNS, Ptrs_STNS,
nullptr, CH_ARRAY },
634 {
'STNN', Save_STNN, Load_STNN, Ptrs_STNN,
nullptr, CH_ARRAY },
635 {
'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.
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.