OpenTTD Source
20240917-master-g9ab0a47812
|
Go to the documentation of this file.
10 #include "../stdafx.h"
11 #include "../waypoint_base.h"
13 #include "../newgrf_station.h"
14 #include "../vehicle_base.h"
16 #include "../newgrf.h"
17 #include "../timer/timer_game_calendar.h"
19 #include "table/strings.h"
23 #include "../safeguards.h"
53 if (!o->
IsType(OT_GOTO_WAYPOINT))
return;
75 if (wp.delete_ctr != 0)
continue;
79 tile.
m2() = (StationID)wp.index;
90 auto found = std::find_if(std::begin(specs), std::end(specs), [&wp](
const StationSpec *spec) {
return spec !=
nullptr && spec->
grf_prop.
grffile->grfid == wp.grfid && spec->
grf_prop.
local_id == wp.localidx; });
91 if (found != std::end(specs)) wp.spec = *found;
103 Debug(sl, 0,
"Found waypoint tile {} with invalid position", t);
106 Debug(sl, 0,
"Found actual waypoint position at {}", t);
116 new_wp->
town = wp.town;
118 new_wp->
name = wp.name;
121 new_wp->
owner = wp.owner;
122 new_wp->
string_id = STR_SV_STNAME_WAYPOINT;
135 if (wp.spec !=
nullptr) {
138 new_wp->
rect.BeforeAddTile(tile, StationRect::ADD_FORCE);
140 wp.new_index = new_wp->
index;
145 if (ol->GetFirstSharedVehicle()->type !=
VEH_TRAIN)
continue;
159 void ResetOldWaypoints()
165 static const SaveLoad _old_waypoint_desc[] = {
207 wp.town_cn = (wp.string_id & 0xC000) == 0xC000 ? (wp.string_id >> 8) & 0x3F : 0;
234 extern const ChunkHandlerTable _waypoint_chunk_handlers(waypoint_chunk_handlers);
int AllocateSpecToStation(const StationSpec *statspec, BaseStation *st, bool exec)
Allocate a StationSpec to a Station.
StationFacility facilities
The facilities that this station has.
debug_inline uint8_t & m5()
General purpose.
bool IsType(OrderType type) const
Check whether this order is of the given type.
static Titem * Get(size_t index)
Returns Titem with given index.
@ FACIL_TRAIN
Station with train station.
debug_inline uint8_t & m3()
General purpose.
@ REF_TOWN
Load/save a reference to a town.
Town * ClosestTownFromTile(TileIndex tile, uint threshold)
Return the town closest (in distance or ownership) to a given tile, within a given threshold.
#define SLE_CONDSSTR(base, variable, type, from, to)
Storage of a std::string in some savegame versions.
Town * town
The town this station is associated with.
DestinationID GetDestination() const
Gets the destination of this order.
std::reference_wrapper< const ChunkHandler > ChunkHandlerRef
A reference to ChunkHandler.
void MoveWaypointsToBaseStations()
Perform all steps to upgrade from the old waypoints to the new version that uses station.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
@ SL_MIN_VERSION
First savegame version.
constexpr static debug_inline uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
Owner
Enum for all companies/owners.
Tindex index
Index of this pool item.
@ VEH_TRAIN
Train vehicle type.
#define SLE_CONDVAR(base, variable, type, from, to)
Storage of a variable in some savegame versions.
Helper structure to convert from the old waypoint system.
void SlErrorCorrupt(const std::string &msg)
Error handler for corrupt savegames.
@ STAT_CLASS_WAYP
Waypoint class.
uint16_t town_cn
The N-1th waypoint for this town (consecutive number)
Representation of a waypoint.
Wrapper class to abstract away the way the tiles are stored.
Handlers and description of chunk.
debug_inline uint8_t & m4()
General purpose.
RailType GetRailType(Tile t)
Gets the rail type of the given tile.
Owner owner
The owner of this station.
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
StringID string_id
Default name (town area) of station.
debug_inline uint16_t & m2()
Primarily used for indices to towns, industries and stations.
std::span< Tspec *const > Specs() const
Get read-only span of specs of this class.
@ CH_READONLY
Chunk is never saved.
StationRect rect
NOSAVE: Station spread out rectangle maintained by StationRect::xxx() functions.
void SetDestination(DestinationID destination)
Sets the destination of this order.
std::string CopyFromOldName(StringID id)
Copy and convert old custom names to UTF-8.
void FixPointers() const override
Fix the pointers.
static void UpdateWaypointOrder(Order *o)
Update the waypoint orders to get the new waypoint ID.
void SetCustomStationSpecIndex(Tile t, uint8_t specindex)
Set the custom station spec for this tile.
#define SLE_CONDREF(base, variable, type, from, to)
Storage of a reference in some savegame versions.
static std::vector< OldWaypoint > _old_waypoints
Temporary array with old waypoints.
std::string name
Custom name.
Owner GetTileOwner(Tile tile)
Returns the owner of a tile.
@ SL_MAX_VERSION
Highest possible saveload version.
static debug_inline RailTileType GetRailTileType(Tile t)
Returns the RailTileType (normal with or without signals, waypoint or depot).
const Tspec * GetSpec(uint index) const
Get a spec from the class at a given index.
void SetRailStationReservation(Tile t, bool b)
Set the reservation state of the rail station.
uint16_t local_id
id defined by the grf file for this entity
#define SLE_VAR(base, variable, type)
Storage of a variable in every version of a savegame.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
uint8_t delete_ctr
Delete counter. If greater than 0 then it is decremented until it reaches 0; the waypoint is then is ...
Axis
Allow incrementing of DiagDirDiff variables.
static debug_inline uint Size()
Get the size of the map.
Shared order list linking together the linked list of orders and the list of vehicles sharing this or...
void MakeRailWaypoint(Tile t, Owner o, StationID sid, Axis a, uint8_t section, RailType rt)
Make the given tile a rail waypoint tile.
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function()
std::span< const ChunkHandlerRef > ChunkHandlerTable
A table of ChunkHandler entries.
GRFFilePropsBase< NUM_CARGO+3 > grf_prop
Properties related the the grf file.
void SlError(StringID string, const std::string &extra_msg)
Error handler.
@ SLV_17
17.0 3212 17.1 3218
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
const struct GRFFile * grffile
grf file that introduced this entity
void SlObject(void *object, const SaveLoadTable &slt)
Main SaveLoad function.
bool IsSavegameVersionBefore(SaveLoadVersion major, uint8_t minor=0)
Checks whether the savegame is below major.
static NewGRFClass * Get(Tindex class_index)
Get a particular class.
Order * next
Pointer to next order. If nullptr, end of list.
void Load() const override
Load the chunk.
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
TimerGameCalendar::Date build_date
Date of construction.
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.