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);
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
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.
std::span< Tspec *const > Specs() const
Get read-only span of specs of this class.
static NewGRFClass * Get(Tindex class_index)
Get a particular class.
const Tspec * GetSpec(uint index) const
Get a spec from the class at a given index.
Wrapper class to abstract away the way the tiles are stored.
debug_inline uint8_t & m5()
General purpose.
debug_inline uint8_t & m4()
General purpose.
debug_inline uint16_t & m2()
Primarily used for indices to towns, industries and stations.
debug_inline uint8_t & m3()
General purpose.
Owner
Enum for all companies/owners.
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
Axis
Allow incrementing of DiagDirDiff variables.
int AllocateSpecToStation(const StationSpec *statspec, BaseStation *st, bool exec)
Allocate a StationSpec to a Station.
@ STAT_CLASS_WAYP
Waypoint class.
RailType GetRailType(Tile t)
Gets the rail type of the given tile.
static debug_inline RailTileType GetRailTileType(Tile t)
Returns the RailTileType (normal with or without signals, waypoint or depot).
void SlError(StringID string, const std::string &extra_msg)
Error handler.
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
void SlErrorCorrupt(const std::string &msg)
Error handler for corrupt savegames.
void SlObject(void *object, const SaveLoadTable &slt)
Main SaveLoad function.
@ CH_READONLY
Chunk is never saved.
std::reference_wrapper< const ChunkHandler > ChunkHandlerRef
A reference to ChunkHandler.
std::span< const ChunkHandlerRef > ChunkHandlerTable
A table of ChunkHandler entries.
#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.
@ SLV_17
17.0 3212 17.1 3218
@ SL_MAX_VERSION
Highest possible saveload version.
@ SL_MIN_VERSION
First savegame version.
#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.
#define SLE_VAR(base, variable, type)
Storage of a variable in every version of a savegame.
Declaration of functions used in more save/load files.
std::string CopyFromOldName(StringID id)
Copy and convert old custom names to UTF-8.
void SetCustomStationSpecIndex(Tile t, uint8_t specindex)
Set the custom station spec for this tile.
void SetRailStationReservation(Tile t, bool b)
Set the reservation state of the rail station.
void MakeRailWaypoint(Tile t, Owner o, StationID sid, Axis a, uint8_t section, RailType rt)
Make the given tile a rail waypoint tile.
@ FACIL_TRAIN
Station with train station.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
StationFacility facilities
The facilities that this station has.
StringID string_id
Default name (town area) of station.
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.
TimerGameCalendar::Date build_date
Date of construction.
std::string name
Custom name.
void Load() const override
Load the chunk.
void FixPointers() const override
Fix the pointers.
Handlers and description of chunk.
uint16_t local_id
id defined by the grf file for this entity
const struct GRFFile * grffile
grf file that introduced this entity
static debug_inline uint Size()
Get the size of the map.
Helper structure to convert from the old waypoint system.
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.
Order * next
Pointer to next order. If nullptr, end of list.
void SetDestination(DestinationID destination)
Sets the destination of this order.
Tindex index
Index of this pool item.
static Titem * Get(size_t index)
Returns Titem with given index.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function()
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
GRFFilePropsBase< NUM_CARGO+3 > grf_prop
Properties related the the grf file.
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.
Town * ClosestTownFromTile(TileIndex tile, uint threshold)
Return the town closest (in distance or ownership) to a given tile, within a given threshold.
@ VEH_TRAIN
Train vehicle type.
static void UpdateWaypointOrder(Order *o)
Update the waypoint orders to get the new waypoint ID.
static std::vector< OldWaypoint > _old_waypoints
Temporary array with old waypoints.
void MoveWaypointsToBaseStations()
Perform all steps to upgrade from the old waypoints to the new version that uses station.