OpenTTD Source
20240917-master-g9ab0a47812
|
49 static const uint NUM_ROADSTOPSPECS_PER_STATION = 63;
53 if (this->
st ==
nullptr)
return 0;
69 auto get_road_type_variable = [&](RoadTramType rtt) -> uint32_t {
74 rt = GetRoadType(this->
tile, rtt);
85 case 0x40:
return this->
view;
89 if (this->
type == STATION_BUS)
return 0;
90 if (this->
type == STATION_TRUCK)
return 1;
97 case 0x43:
return get_road_type_variable(RTT_ROAD);
100 case 0x44:
return get_road_type_variable(RTT_TRAM);
160 uint32_t res =
GetStationGfx(nearby_tile) << 12 | !same_orientation << 11 | !!same_station << 10;
162 if (
type == STATION_TRUCK) res |= (1 << 16);
163 if (
type == STATION_ROADWAYPOINT) res |= (2 << 16);
168 res |= 1 << (sm.grfid != grfid ? 9 : 8) | ClampTo<uint8_t>(sm.localidx);
196 if (sm.grfid == grfid) {
216 if (group ==
nullptr)
return nullptr;
222 CallbackID callback, uint32_t param1, uint32_t param2)
223 :
ResolverObject(roadstopspec->grf_prop.grffile, callback, param1, param2), roadstop_scope(*this, st, roadstopspec, tile, roadtype, type, view)
260 if (t ==
nullptr)
return nullptr;
269 return object.ResolveCallback();
284 assert(spec !=
nullptr);
289 if (group ==
nullptr || group->type != SGT_TILELAYOUT)
return;
301 draw_mode = spec->draw_mode;
304 if (type == STATION_ROADWAYPOINT) {
305 DrawSprite(SPR_ROAD_PAVED_STRAIGHT_X, PAL_NONE, x, y);
315 uint sprite_offset = 5 - view;
319 if (rti->UsesOverlay()) {
321 DrawSprite(ground + sprite_offset, PAL_NONE, x, y);
324 if (overlay)
DrawSprite(overlay + sprite_offset, PAL_NONE, x, y);
325 }
else if (RoadTypeIsTram(roadtype)) {
326 DrawSprite(SPR_TRAMWAY_TRAM + sprite_offset, PAL_NONE, x, y);
347 static uint8_t Get(
BaseStation *st,
TileIndex tile) {
return st->GetRoadStopAnimationFrame(tile); }
348 static bool Set(
BaseStation *st,
TileIndex tile, uint8_t frame) {
return st->SetRoadStopAnimationFrame(tile, frame); }
363 if (ss ==
nullptr)
return;
377 uint16_t random_bits = Random();
378 auto process_tile = [&](
TileIndex cur_tile) {
383 cargo = INVALID_CARGO;
393 process_tile(tile_data.tile);
396 process_tile(trigger_tile);
419 uint32_t whole_reseed = 0;
424 uint32_t used_triggers = 0;
425 auto process_tile = [&](
TileIndex cur_tile) {
427 if (ss ==
nullptr)
return;
440 if (group ==
nullptr)
return;
442 used_triggers |=
object.used_triggers;
444 uint32_t reseed =
object.GetReseedSum();
446 whole_reseed |= reseed;
450 uint8_t random_bits = st->GetRoadStopRandomBits(cur_tile);
451 random_bits &= ~reseed;
452 random_bits |= Random() & reseed;
453 st->SetRoadStopRandomBits(cur_tile, random_bits);
461 process_tile(tile_data.tile);
469 if ((whole_reseed & 0xFFFF) != 0) {
502 for (
const auto spec : roadstopclass->
Specs()) {
518 if (roadstopspec ==
nullptr)
return true;
553 if (statspec ==
nullptr || st ==
nullptr)
return 0;
556 for (i = 1; i < st->
roadstop_speclist.size() && i < NUM_ROADSTOPSPECS_PER_STATION; i++) {
561 for (i = 1; i < st->
roadstop_speclist.size() && i < NUM_ROADSTOPSPECS_PER_STATION; i++) {
565 if (i == NUM_ROADSTOPSPECS_PER_STATION) {
582 void DeallocateSpecFromRoadStop(
BaseStation *st, uint8_t specindex)
585 if (specindex == 0)
return;
630 for (
const auto &sm : GetStationSpecList<RoadStopSpec>(st)) {
631 if (sm.spec ==
nullptr)
continue;
struct BaseStation * st
Instance of the station.
@ ROADSTOPTYPE_FREIGHT
This RoadStop is for freight (truck) stops.
@ ROADSTOP_BUS
A standard stop for buses.
@ RSF_DRAW_MODE_REGISTER
Read draw mode from register 0x100.
StationFacility facilities
The facilities that this station has.
@ ROTSG_GROUND
Required: Main group of ground images.
PaletteID GroundSpritePaletteTransform(SpriteID image, PaletteID pal, PaletteID default_pal)
Applies PALETTE_MODIFIER_COLOUR to a palette entry of a ground sprite.
GoodsEntry goods[NUM_CARGO]
Goods at this station.
@ RSF_CB141_RANDOM_BITS
Callback 141 needs random bits.
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
CargoTypes cached_roadstop_cargo_triggers
NOSAVE: Combined cargo trigger bitmask for road stops.
static constexpr TimerGame< struct Calendar >::Date DAYS_TILL_ORIGINAL_BASE_YEAR
The date of the first day of the original base year.
Town * ClosestTownFromTile(TileIndex tile, uint threshold)
Return the town closest (in distance or ownership) to a given tile, within a given threshold.
@ SAT_250_TICKS
Trigger station every 250 ticks.
@ SPRITE_WIDTH
number of bits for the sprite number
Town * town
The town this station is associated with.
static BaseStation * GetByTile(TileIndex tile)
Get the base station belonging to a specific tile.
Slope GetTileSlope(TileIndex tile)
Return the slope of a given tile inside the map.
uint16_t triggers
The triggers that trigger animation.
@ SAT_NEW_CARGO
Trigger station on new cargo arrival.
@ RSRT_CARGO_TAKEN
Trigger roadstop when cargo is completely taken.
uint32_t GetVariable(uint8_t variable, [[maybe_unused]] uint32_t parameter, bool &available) const override
Get a variable value.
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.
uint32_t GetRegister(uint i)
Gets the value of a so-called newgrf "register".
Tindex index
Index of this pool item.
RoadStopDrawMode
Different draw modes to disallow rendering of some parts of the stop or road.
SpriteID sprite
The 'real' sprite.
TileIndex tile
Tile of the station.
Interface for SpriteGroup-s to access the gamestate.
@ SAT_CARGO_TAKEN
Trigger station when cargo is completely taken.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
const GRFFile * grffile
GRFFile the resolved SpriteGroup belongs to.
RoadType roadtype
Road type (used when no tile)
RoadStopCallbackMask
Callback masks for road stops.
static IterateWrapper Iterate(size_t from=0)
Returns an iterable ensemble of all valid CargoSpec.
TileIndex xy
town center tile
Specification of a cargo type.
bool GetIfNewStopsByType(RoadStopType rs, RoadType roadtype)
Checks if there's any new stations by a specific RoadStopType.
uint32_t GetTerrainType(TileIndex tile, TileContext context)
Function used by houses (and soon industries) to get information on type of "terrain" the tile it is ...
void DrawCommonTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32_t orig_offset, uint32_t newgrf_offset, PaletteID default_palette, bool child_offset_is_unsigned)
Draws a tile sprite sequence in the GUI.
CallbackID
List of implemented NewGRF callbacks.
static void InsertDefaults()
Initialise the defaults.
@ ROADSTOP_CLASS_DFLT
Default road stop class.
bool IsUIAvailable(uint index) const
Check whether the spec will be available to the user at some point in time.
uint32_t PaletteID
The number of the palette.
void TriggerRoadStopRandomisation(Station *st, TileIndex tile, RoadStopRandomTrigger trigger, CargoID cargo_type=INVALID_CARGO)
Trigger road stop randomisation.
Owner owner
The owner of this station.
StringID name
Name of this class.
@ ROADSTOP_TRUCK
A standard stop for trucks.
uint8_t GetReverseRoadTypeTranslation(RoadType roadtype, const GRFFile *grffile)
Perform a reverse roadtype lookup to get the GRF internal ID.
uint TotalCount() const
Returns total count of cargo at the station, including cargo which is already reserved for loading.
StationType
Station types.
bool IsCustomRoadStopSpecIndex(Tile t)
Is there a custom road stop spec on this tile?
@ ROADSTOP_DRAW_MODE_OVERLAY
Drive-through stops: Draw the road overlay, e.g. pavement.
HouseZonesBits GetTownRadiusGroup(const Town *t, TileIndex tile)
Returns the bit corresponding to the town zone of the specified tile.
void DrawRoadStopTile(int x, int y, RoadType roadtype, const RoadStopSpec *spec, StationType type, int view)
Draw representation of a road stop tile for GUI purposes.
StationCargoList cargo
The cargo packets of cargo waiting in this station.
PalSpriteID ground
Palette and sprite for the ground.
SpriteID GetCustomRoadSprite(const RoadTypeInfo *rti, TileIndex tile, RoadTypeSpriteGroup rtsg, TileContext context, uint *num_results)
Get the sprite to draw for the given tile.
@ RSF_BUILD_MENU_TRAM_ONLY
Only show in the tram build menu (not road).
std::vector< const SpriteGroup * > loading
List of loading groups (can be SpriteIDs or Callback results)
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
@ CBM_ROAD_STOP_ANIMATION_SPEED
Customize the animation speed of the road stop.
StationGfx GetStationGfx(Tile t)
Get the station graphics of this tile.
@ CBM_ROAD_STOP_ANIMATION_NEXT_FRAME
Use a custom next frame callback.
std::span< Tspec *const > Specs() const
Get read-only span of specs of this class.
uint32_t GetCompanyInfo(CompanyID owner, const Livery *l)
Returns company information like in vehicle var 43 or station var 43.
static std::span< NewGRFClass< Tspec, Tindex, Tmax > const > Classes()
Get read-only span of all classes of this type.
const SpriteGroup * root_spritegroup
Root SpriteGroup to use for resolving.
static bool IsExpected(const BaseStation *st)
Helper for checking whether the given station is of this type.
std::optional< TownScopeResolver > town_scope
The town scope resolver (created on the first call).
static constexpr CargoID SG_DEFAULT
Default type used when no more-specific cargo matches.
CargoTypes GetEmptyMask(const Station *st)
Get a mask of the cargo types that are empty at the station.
uint32_t GetNearbyTileInformation(TileIndex tile, bool grf_version8)
Common part of station var 0x67, house var 0x62, indtile var 0x60, industry var 0x62.
RoadType
The different roadtypes we support.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
@ ROTSG_ROADSTOP
Required: Bay stop surface.
Ground palette sprite of a tile, together with its sprite layout.
@ TCX_NORMAL
Nothing special.
GRFFilePropsBase< NUM_CARGO+3 > grf_prop
Properties related the the grf file.
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
static void ChangeAnimationFrame(CallbackID cb, const RoadStopSpec *spec, BaseStation *obj, TileIndex tile, uint32_t random_bits, uint32_t trigger, int extra_data=0)
Check a callback to determine what the next animation step is and execute that step.
@ INVALID_ROADTYPE
flag for invalid roadtype
Scope resolver for a town.
TileIndex GetNearbyTile(uint8_t parameter, TileIndex tile, bool signed_offsets, Axis axis)
Get the tile at the given offset.
static Station * From(BaseStation *st)
Converts a BaseStation to SpecializedStation with type checking.
@ ROADSTOPTYPE_ALL
This RoadStop is for both types of station road stops.
uint GetCustomRoadStopSpecIndex(Tile t)
Get the custom road stop spec for this tile.
@ CBID_STATION_ANIM_NEXT_FRAME
Called to determine station tile next animation frame.
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
StationType GetStationType(Tile t)
Get the station type of this tile.
@ ROADSTOPTYPE_PASSENGER
This RoadStop is for passenger (bus) stops.
CargoID cargo_type
Type of cargo of the station.
uint16_t local_id
id defined by the grf file for this entity
const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
@ ROADSTOP_DRAW_MODE_WAYP_GROUND
Waypoints: Draw the sprite layout ground tile (on top of the road)
uint DistanceSquare(TileIndex t0, TileIndex t1)
Gets the 'Square' distance between the two given tiles.
CompanyID _current_company
Company currently doing an action.
@ CBID_STATION_ANIM_START_STOP
Called for periodically starting or stopping the animation.
StationID GetStationIndex(Tile t)
Get StationID from a tile.
const struct RoadStopSpec * roadstopspec
Station (type) specification.
bool IsWaypointClass(const RoadStopClass &cls)
Test if a RoadStopClass is the waypoint class.
@ ROTSG_OVERLAY
Optional: Images for overlaying track.
@ RSRT_NEW_CARGO
Trigger roadstop on arrival of new cargo.
static Tindex Allocate(uint32_t global_id)
Allocate a class with a given global class ID.
StationAnimationTrigger
Animation triggers for station.
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
static constexpr CargoID SG_PURCHASE
Used in purchase lists before an item exists.
static Station * GetByTile(TileIndex tile)
Get the station belonging to a specific tile.
uint8_t CargoID
Cargo slots to indicate a cargo type within a game.
@ CBID_STATION_ANIMATION_SPEED
Called to indicate how long the current animation frame should last.
Struct containing information relating to NewGRF classes for stations and airports.
uint8_t waiting_triggers
Waiting triggers (NewGRF) for this station.
Base class for all station-ish types.
RoadStopScopeResolver roadstop_scope
The stop scope resolver.
static void AnimateTile(const RoadStopSpec *spec, BaseStation *obj, TileIndex tile, bool random_animation, int extra_data=0)
Animate a single tile.
@ RSF_BUILD_MENU_ROAD_ONLY
Only show in the road build menu (not tram).
uint16_t random_bits
Random bits assigned to this station.
const SpriteGroup * ResolveReal(const RealSpriteGroup *group) const override
Get the real sprites of the grf.
virtual const SpriteGroup * Resolve([[maybe_unused]] ResolverObject &object) const
Base sprite group resolver.
uint8_t cached_roadstop_anim_triggers
NOSAVE: Combined animation trigger bitmask for road stops, used to determine if trigger processing sh...
@ ROADSTOP_DRAW_MODE_ROAD
Bay stops: Draw the road itself.
void Insert(Tspec *spec)
Insert a spec into the class, and update its index.
RoadStopType
Types of RoadStops.
static constexpr CargoID SG_DEFAULT_NA
Used only by stations and roads when no more-specific cargo matches.
bool IsValidCargoID(CargoID t)
Test whether cargo type is not INVALID_CARGO.
PaletteID pal
The palette (use PAL_NONE) if not needed)
static Date date
Current date in days (day counter).
uint32_t GetRandomBits() const override
Get a few random bits.
ResolverObject & ro
Surrounding resolver object.
std::vector< SpecMapping< RoadStopSpec > > roadstop_speclist
List of road stop specs of this station.
void RoadStopUpdateCachedTriggers(BaseStation *st)
Update the cached animation trigger bitmask for a station.
const struct GRFFile * grffile
grf file that introduced this entity
bool GetIfClassHasNewStopsByType(const RoadStopClass *roadstopclass, RoadStopType rs, RoadType roadtype)
Checks if the given RoadStopClass has any specs assigned to it, compatible with the given RoadStopTyp...
static NewGRFClass * Get(Tindex class_index)
Get a particular class.
virtual uint32_t GetNewGRFVariable(const struct ResolverObject &object, uint8_t variable, uint8_t parameter, bool &available) const =0
Helper function to get a NewGRF variable that isn't implemented by the base class.
uint32_t GetTriggers() const override
Get the triggers.
uint8_t view
Station axis.
Helper class for animation control.
std::vector< RoadStopTileData > custom_roadstop_tile_data
List of custom road stop tile data.
bool GetIfStopIsForType(const RoadStopSpec *roadstopspec, RoadStopType rs, RoadType roadtype)
Checks if the given RoadStopSpec is compatible with the given RoadStopType.
std::array< uint8_t, NUM_CARGO > cargo_map
Inverse cargo translation table (CargoID -> local ID)
bool IsAnyRoadStopTile(Tile t)
Is tile t a road stop station?
std::array< const struct SpriteGroup *, Tcnt > spritegroup
pointers to the different sprites of the entity
CargoTypes cargo_triggers
Bitmask of cargo types which cause trigger re-randomizing.
StationType type
Station type.
Action 2 sprite layout for houses, industry tiles, objects and airport tiles.
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.