newgrf_station.h
author KUDr
Sun, 31 Dec 2006 23:48:04 +0000
branchcustombridgeheads
changeset 5618 a7db50b9f817
parent 5060 2d577061b0ec
permissions -rw-r--r--
(svn r7710) [cbh] - Fix: [YAPF] one more assert fixed. Call from the TrainController() added by (r7705) has broken YAPF because it was called when vehicle was already on the next tile (with cbh choice). Before it was always called before the train entered tile with choice.
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
     1
/* $Id$ */
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
     2
2963
6645da0a5b4a (svn r3525) - Rename station_newgrf.[ch] to newgrf_station.[ch], and update project files.
peter1138
parents: 2625
diff changeset
     3
/** @file newgrf_station.h Header file for NewGRF stations */
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
     4
2963
6645da0a5b4a (svn r3525) - Rename station_newgrf.[ch] to newgrf_station.[ch], and update project files.
peter1138
parents: 2625
diff changeset
     5
#ifndef NEWGRF_STATION_H
6645da0a5b4a (svn r3525) - Rename station_newgrf.[ch] to newgrf_station.[ch], and update project files.
peter1138
parents: 2625
diff changeset
     6
#define NEWGRF_STATION_H
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
     7
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
     8
#include "engine.h"
3866
113de2b20059 (svn r4902) Newgrf : Introduction of the newgrf_cargo files.
belugas
parents: 3865
diff changeset
     9
#include "newgrf_cargo.h"
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    10
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    11
typedef enum {
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    12
	STAT_CLASS_DFLT,     ///< Default station class.
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    13
	STAT_CLASS_WAYP,     ///< Waypoint class.
3767
2c8990ba0313 (svn r4759) - Newstations: increase the number of station classes from 16 to 32. 16 was an arbitrary limit, 32 is the limit for dropdown lists...
peter1138
parents: 3766
diff changeset
    14
	STAT_CLASS_MAX = 32, ///< Maximum number of classes.
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    15
} StationClassID;
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    16
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    17
/* Station layout for given dimensions - it is a two-dimensional array
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    18
 * where index is computed as (x * platforms) + platform. */
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    19
typedef byte *StationLayout;
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    20
3688
c3bc748056d0 (svn r4613) - NewGRF: fix two struct declarations
peter1138
parents: 3676
diff changeset
    21
typedef struct StationSpec {
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    22
	uint32 grfid; ///< ID of GRF file station belongs to.
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    23
	int localidx; ///< Index within GRF file of station.
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    24
3780
9555a46e6ca9 (svn r4772) - Newstations: when allocating a custom station (via action 0x03) check if the station has already been allocated. (Fixes duplicate waypoints in newstatsw in non-temperate climate)
peter1138
parents: 3775
diff changeset
    25
	bool allocated; ///< Flag whether this station has been added to a station class list
9555a46e6ca9 (svn r4772) - Newstations: when allocating a custom station (via action 0x03) check if the station has already been allocated. (Fixes duplicate waypoints in newstatsw in non-temperate climate)
peter1138
parents: 3775
diff changeset
    26
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    27
	StationClassID sclass; ///< The class to which this spec belongs.
3594
31fd59e606c8 (svn r4484) - Newstations: Use StringIDs instead of char*s to reference our custom names.
peter1138
parents: 3587
diff changeset
    28
	StringID name; ///< Name of this station.
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    29
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    30
	/**
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    31
	 * Bitmask of number of platforms available for the station.
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    32
	 * 0..6 correpsond to 1..7, while bit 7 corresponds to >7 platforms.
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    33
	 */
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 2967
diff changeset
    34
	byte disallowed_platforms;
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    35
	/**
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    36
	 * Bitmask of platform lengths available for the station.
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    37
	 * 0..6 correpsond to 1..7, while bit 7 corresponds to >7 tiles long.
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    38
	 */
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 2967
diff changeset
    39
	byte disallowed_lengths;
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    40
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    41
	/** Number of tile layouts.
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    42
	 * A minimum of 8 is required is required for stations.
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    43
	 * 0-1 = plain platform
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    44
	 * 2-3 = platform with building
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    45
	 * 4-5 = platform with roof, left side
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    46
	 * 6-7 = platform with roof, right side
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    47
	 */
3570
f9749bae861e (svn r4452) - NewGRF: switch to unsigned ints for array indices.
peter1138
parents: 3505
diff changeset
    48
	uint tiles;
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    49
	DrawTileSprites *renderdata; ///< Array of tile layouts.
3740
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3688
diff changeset
    50
	bool copied_renderdata;
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    51
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 2967
diff changeset
    52
	/** Cargo threshold for choosing between little and lots of cargo
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 2967
diff changeset
    53
	 * @note little/lots are equivalent to the moving/loading states for vehicles
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 2967
diff changeset
    54
	 */
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 2967
diff changeset
    55
	uint16 cargo_threshold;
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 2967
diff changeset
    56
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 2967
diff changeset
    57
	uint32 cargo_triggers; ///< Bitmask of cargo types which cause trigger re-randomizing
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 2967
diff changeset
    58
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 2967
diff changeset
    59
	byte callbackmask; ///< Bitmask of callbacks to use, @see newgrf_callbacks.h
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 2967
diff changeset
    60
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 2967
diff changeset
    61
	byte flags; ///< Bitmask of flags, bit 0: use different sprite set; bit 1: divide cargo about by station size
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 2967
diff changeset
    62
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 2967
diff changeset
    63
	byte pylons;  ///< Bitmask of base tiles (0 - 7) which should contain elrail pylons
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 2967
diff changeset
    64
	byte wires;   ///< Bitmask of base tiles (0 - 7) which should contain elrail wires
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 2967
diff changeset
    65
	byte blocked; ///< Bitmask of base tiles (0 - 7) which are blocked to trains
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 2967
diff changeset
    66
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    67
	byte lengths;
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    68
	byte *platforms;
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    69
	StationLayout **layouts;
5060
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 4893
diff changeset
    70
	bool copied_layouts;
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    71
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    72
	/**
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    73
	 * NUM_GLOBAL_CID sprite groups.
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    74
	 * Used for obtaining the sprite offset of custom sprites, and for
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    75
	 * evaluating callbacks.
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    76
	 */
4893
07d158194395 (svn r6837) - Codechange: More const SpriteGroups missed in r6836
peter1138
parents: 4817
diff changeset
    77
	const struct SpriteGroup *spritegroup[NUM_GLOBAL_CID];
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    78
} StationSpec;
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    79
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    80
/**
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    81
 * Struct containing information relating to station classes.
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    82
 */
3688
c3bc748056d0 (svn r4613) - NewGRF: fix two struct declarations
peter1138
parents: 3676
diff changeset
    83
typedef struct StationClass {
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    84
	uint32 id;          ///< ID of this class, e.g. 'DFLT', 'WAYP', etc.
3594
31fd59e606c8 (svn r4484) - Newstations: Use StringIDs instead of char*s to reference our custom names.
peter1138
parents: 3587
diff changeset
    85
	StringID name;      ///< Name of this class.
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    86
	uint stations;      ///< Number of stations in this class.
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    87
	StationSpec **spec; ///< Array of station specifications.
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    88
} StationClass;
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    89
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    90
void ResetStationClasses(void);
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3866
diff changeset
    91
StationClassID AllocateStationClass(uint32 cls);
3642
a247e07fafdf (svn r4551) - NewGRF: add string handling for newstations.
peter1138
parents: 3594
diff changeset
    92
void SetStationClassName(StationClassID sclass, StringID name);
a247e07fafdf (svn r4551) - NewGRF: add string handling for newstations.
peter1138
parents: 3594
diff changeset
    93
StringID GetStationClassName(StationClassID sclass);
a247e07fafdf (svn r4551) - NewGRF: add string handling for newstations.
peter1138
parents: 3594
diff changeset
    94
StringID *BuildStationClassDropdown(void);
a247e07fafdf (svn r4551) - NewGRF: add string handling for newstations.
peter1138
parents: 3594
diff changeset
    95
3587
2eb52db0b872 (svn r4473) - Newstations:
peter1138
parents: 3570
diff changeset
    96
uint GetNumStationClasses(void);
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    97
uint GetNumCustomStations(StationClassID sclass);
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    98
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3642
diff changeset
    99
void SetCustomStationSpec(StationSpec *statspec);
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3642
diff changeset
   100
const StationSpec *GetCustomStationSpec(StationClassID sclass, uint station);
3765
e057e2b740d4 (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3764
diff changeset
   101
const StationSpec *GetCustomStationSpecByGrf(uint32 grfid, byte localidx);
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
   102
3769
2fd087fd336f (svn r4761) - Newstations: support platform information in variable 10 (callback parameter 1) when building a station
peter1138
parents: 3767
diff changeset
   103
/* Evaluate a tile's position within a station, and return the result a bitstuffed format. */
2fd087fd336f (svn r4761) - Newstations: support platform information in variable 10 (callback parameter 1) when building a station
peter1138
parents: 3767
diff changeset
   104
uint32 GetPlatformInfo(Axis axis, byte tile, int platforms, int length, int x, int y, bool centred);
2fd087fd336f (svn r4761) - Newstations: support platform information in variable 10 (callback parameter 1) when building a station
peter1138
parents: 3767
diff changeset
   105
2967
4208a82bf0d9 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   106
/* Get sprite offset for a given custom station and station structure (may be
3751
785501c18d0d (svn r4739) - Newstations: remove cargo type parameter of GetCustomStationRelocation() as we can determine it internally
peter1138
parents: 3743
diff changeset
   107
 * NULL - that means we are in a build dialog). The station structure is used
785501c18d0d (svn r4739) - Newstations: remove cargo type parameter of GetCustomStationRelocation() as we can determine it internally
peter1138
parents: 3743
diff changeset
   108
 * for variational sprite groups. */
785501c18d0d (svn r4739) - Newstations: remove cargo type parameter of GetCustomStationRelocation() as we can determine it internally
peter1138
parents: 3743
diff changeset
   109
SpriteID GetCustomStationRelocation(const StationSpec *statspec, const Station *st, TileIndex tile);
3775
f3f1ba3111fa (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3769
diff changeset
   110
SpriteID GetCustomStationGroundRelocation(const StationSpec *statspec, const Station *st, TileIndex tile);
3752
a7cdd7c0c928 (svn r4740) - Newstations: add function to evaluate station callbacks
peter1138
parents: 3751
diff changeset
   111
uint16 GetStationCallback(uint16 callback, uint32 param1, uint32 param2, const StationSpec *statspec, const Station *st, TileIndex tile);
2967
4208a82bf0d9 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   112
3766
f0077e6b6f99 (svn r4758) - Newstations: add support for 'blocked' station tiles, which no train can pass.
peter1138
parents: 3765
diff changeset
   113
/* Check if a rail station tile is traversable. */
f0077e6b6f99 (svn r4758) - Newstations: add support for 'blocked' station tiles, which no train can pass.
peter1138
parents: 3765
diff changeset
   114
bool IsStationTileBlocked(TileIndex tile);
f0077e6b6f99 (svn r4758) - Newstations: add support for 'blocked' station tiles, which no train can pass.
peter1138
parents: 3765
diff changeset
   115
3789
bf75e48227de (svn r4785) - Newstations: don't draw catenary on non-track tiles
glx
parents: 3780
diff changeset
   116
/* Check if a rail station tile is electrifiable. */
bf75e48227de (svn r4785) - Newstations: don't draw catenary on non-track tiles
glx
parents: 3780
diff changeset
   117
bool IsStationTileElectrifiable(TileIndex tile);
bf75e48227de (svn r4785) - Newstations: don't draw catenary on non-track tiles
glx
parents: 3780
diff changeset
   118
3587
2eb52db0b872 (svn r4473) - Newstations:
peter1138
parents: 3570
diff changeset
   119
/* Allocate a StationSpec to a Station. This is called once per build operation. */
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3642
diff changeset
   120
int AllocateSpecToStation(const StationSpec *statspec, Station *st, bool exec);
3587
2eb52db0b872 (svn r4473) - Newstations:
peter1138
parents: 3570
diff changeset
   121
2eb52db0b872 (svn r4473) - Newstations:
peter1138
parents: 3570
diff changeset
   122
/* Deallocate a StationSpec from a Station. Called when removing a single station tile. */
4190
24d5420b6242 (svn r5632) Replace a boolean variable in DeallocateSpecFromStation() by a return
tron
parents: 3900
diff changeset
   123
void DeallocateSpecFromStation(Station* st, byte specindex);
3587
2eb52db0b872 (svn r4473) - Newstations:
peter1138
parents: 3570
diff changeset
   124
3764
ebcaf412fb3a (svn r4755) - Newstations: add a gui station tile drawing routine and use it in place of the existing one for waypoints.
peter1138
parents: 3752
diff changeset
   125
/* Draw representation of a station tile for GUI purposes. */
ebcaf412fb3a (svn r4755) - Newstations: add a gui station tile drawing routine and use it in place of the existing one for waypoints.
peter1138
parents: 3752
diff changeset
   126
bool DrawStationTile(int x, int y, RailType railtype, Axis axis, StationClassID sclass, uint station);
ebcaf412fb3a (svn r4755) - Newstations: add a gui station tile drawing routine and use it in place of the existing one for waypoints.
peter1138
parents: 3752
diff changeset
   127
2963
6645da0a5b4a (svn r3525) - Rename station_newgrf.[ch] to newgrf_station.[ch], and update project files.
peter1138
parents: 2625
diff changeset
   128
#endif /* NEWGRF_STATION_H */