12 #include "../stdafx.h" 13 #include "../station_base.h" 14 #include "../waypoint_base.h" 15 #include "../roadstop_base.h" 16 #include "../vehicle_base.h" 17 #include "../newgrf_station.h" 20 #include "table/strings.h" 22 #include "../safeguards.h" 30 if (!o->
IsType(OT_GOTO_STATION))
return;
46 FOR_ALL_ORDER_LISTS(ol) {
63 FOR_ALL_STATIONS(st) {
66 StationID index = st->
index;
70 char *name = st->
name;
85 wp->
string_id = train ? STR_SV_STNAME_WAYPOINT : STR_SV_STNAME_BUOY;
91 if (
IsInsideBS(string_id, STR_SV_STNAME_BUOY, 9)) wp->
town_cn = string_id - STR_SV_STNAME_BUOY;
98 SB(
_me[t].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_ALL_BASE_STATIONS(st) {
116 for (uint i = 0; i < st->
num_specs; i++) {
139 FOR_ALL_ROADSTOPS(rs) {
143 FOR_ALL_ROADSTOPS(rs) {
151 static const SaveLoad _roadstop_desc[] = {
169 static const SaveLoad _old_station_desc[] = {
228 static uint16 _waiting_acceptance;
229 static uint32 _num_flows;
230 static uint16 _cargo_source;
231 static uint32 _cargo_source_xy;
232 static uint8 _cargo_days;
233 static Money _cargo_feeder_share;
235 static const SaveLoad _station_speclist_desc[] = {
242 std::list<CargoPacket *> _packets;
246 FlowSaveLoad() : source(0), via(0), share(0), restricted(
false) {}
253 static const SaveLoad _flow_desc[] = {
268 static const SaveLoad goods_desc[] = {
274 SLEG_CONDVAR( _cargo_source, SLE_FILE_U8 | SLE_VAR_U16, 0, 6),
280 SLEG_CONDVAR( _cargo_feeder_share, SLE_FILE_U32 | SLE_VAR_I64, 14, 64),
296 typedef std::pair<const StationID, std::list<CargoPacket *> > StationCargoPair;
298 static const SaveLoad _cargo_list_desc[] = {
299 SLE_VAR(StationCargoPair, first, SLE_UINT16),
313 if (_packets.empty()) {
314 std::map<StationID, std::list<CargoPacket *> >::iterator it(ge_packets.find(INVALID_STATION));
315 if (it == ge_packets.end()) {
318 it->second.swap(_packets);
321 assert(ge_packets[INVALID_STATION].empty());
322 ge_packets[INVALID_STATION].swap(_packets);
326 static void Load_STNS()
328 _cargo_source_xy = 0;
330 _cargo_feeder_share = 0;
338 _waiting_acceptance = 0;
341 for (
CargoID i = 0; i < num_cargo; i++) {
347 if (
GB(_waiting_acceptance, 0, 12) != 0) {
358 CargoPacket *cp =
new CargoPacket(
GB(_waiting_acceptance, 0, 12), _cargo_days, source, _cargo_source_xy, _cargo_source_xy, _cargo_feeder_share);
368 for (uint i = 0; i < st->
num_specs; i++) {
375 static void Ptrs_STNS()
381 FOR_ALL_STATIONS(st) {
395 static const SaveLoad _base_station_desc[] = {
415 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 FOR_ALL_BASE_STATIONS(st) {
514 SlSetArrayIndex(st->
index);
519 static void Load_STNN()
528 SlObject(bst, waypoint ? _waypoint_desc : _station_desc);
545 StationID prev_source = INVALID_STATION;
546 for (uint32 j = 0; j < _num_flows; ++j) {
548 if (fs == NULL || 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()
584 FOR_ALL_STATIONS(st) {
593 for (StationCargoPacketMap::ConstMapIterator it = ge->
cargo.
Packets()->begin(); it != ge->
cargo.
Packets()->end(); ++it) {
594 SlObject(const_cast<StationCargoPair *>(&(*it)), _cargo_list_desc);
607 static void Save_ROADSTOP()
611 FOR_ALL_ROADSTOPS(rs) {
612 SlSetArrayIndex(rs->
index);
617 static void Load_ROADSTOP()
628 static void Ptrs_ROADSTOP()
631 FOR_ALL_ROADSTOPS(rs) {
637 {
'STNS', NULL, Load_STNS, Ptrs_STNS, NULL, CH_ARRAY },
638 {
'STNN', Save_STNN, Load_STNN, Ptrs_STNN, NULL, CH_ARRAY },
639 {
'ROAD', Save_ROADSTOP, Load_ROADSTOP, Ptrs_ROADSTOP, NULL, CH_ARRAY |
CH_LAST},
#define SLE_CONDNULL(length, from, to)
Empty space in some savegame versions.
uint16 town_cn
The N-1th waypoint for this town (consecutive number)
byte status
Current status of the Stop,.
TileArea bus_station
Tile area the bus 'station' part covers.
#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.
TileIndex xy
Position on the map.
void MakeDriveThrough()
Join this road stop to another 'base' road stop if possible; fill all necessary data to become an act...
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.
static bool IsInsideBS(const T x, const uint base, const uint size)
Checks if a value is between a window started at some base point.
StationRect rect
NOSAVE: Station spread out rectangle maintained by StationRect::xxx() functions.
Stores station stats for a single cargo.
Tindex index
Index of this pool item.
Northeast, upper right on your monitor.
Load/save a reference to a town.
Representation of a waypoint.
#define SLE_WRITEBYTE(base, variable, value)
Translate values ingame to different values in the savegame and vv.
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.
Vehicle * GetFirstSharedVehicle() const
Get the first vehicle of this vehicle chain.
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.
Station is a waypoint (NewGRF only!)
static Station * From(BaseStation *st)
Converts a BaseStation to SpecializedStation with type checking.
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 NULL, end of list.
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.
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 give 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...
allow control codes in the strings
VehicleType
Available vehicle types.
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.
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.
Order * GetFirstOrder() const
Get the first order of the order chain.
StationSpecList * speclist
List of station specs of this station.
The tile has no ownership.
PersistentStorage * psa
Persistent storage for NewGRF airports.
StationFacilityByte facilities
The facilities that this station has.
#define SL_MAX_VERSION
Highest possible savegame version.
static bool IsSavegameVersionBefore(uint16 major, byte minor=0)
Checks whether the savegame is below major.
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.
Maximal number of cargo types in a game.
TileIndex tile
The base tile of the area.
OwnerByte owner
The owner of this station.
#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.
size_t MapSize() const
Count the number of ranges with equal keys in this MultiMap.
uint32 TileIndex
The index/ID of a Tile.
TileIndex xy
Base tile of the station.
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.
Station with train station.
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.
const Entry * GetEntry(DiagDirection dir) const
Get the drive through road stop entry struct for the given direction.
A Stop for a Road Vehicle.
uint8 localidx
Station ID within GRF of 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.
#define FOR_ALL_VEHICLES(var)
Iterate over all vehicles.
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.
byte CargoID
Cargo slots to indicate a cargo type within a game.
Non-zero when the entries on this road stop are the primary, i.e. the ones to delete.
void Rebuild(const RoadStop *rs, int side=-1)
Rebuild, from scratch, the vehicles and other metadata on this stop.
static Station * Get(size_t index)
Gets station with given index.
StringID string_id
Default name (town area) of station.
VehicleTypeByte type
Type of vehicle.
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.
Order current_order
The current order (+ status, like: loading)
#define SLEG_CONDLST(variable, type, from, to)
Storage of a global list in some savegame versions.
uint32 grfid
GRF ID of this custom station.
The station has no facilities at all.
#define FOR_ALL_WAYPOINTS(var)
Iterate over all waypoints.
Date build_date
Date of construction.
void AfterLoadRoadStops()
(Re)building of road stop caches after loading a savegame.
Last chunk in this array.
Load/save a reference to a persistent storage.