author | rubidium |
Thu, 24 Apr 2008 11:48:09 +0000 | |
branch | 0.6 |
changeset 10323 | 57d8fd25473e |
parent 9191 | ae14770c829a |
child 10328 | 721fe18a2176 |
permissions | -rw-r--r-- |
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 |
|
6443
b8f06d8eb7be
(svn r8853) -Cleanup: doxygen changes. Correct forgotten c files to cpp files with the @file tag as well as a few general comments style
belugas
parents:
6439
diff
changeset
|
3 |
/** @file newgrf_station.cpp Functions for dealing with station classes and custom stations. */ |
2625
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
4 |
|
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
5 |
#include "stdafx.h" |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
6 |
#include "openttd.h" |
3743
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
7 |
#include "variables.h" |
8615
6b91ca653bad
(svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium
parents:
8614
diff
changeset
|
8 |
#include "tile_cmd.h" |
6669
487ac09b95c4
(svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents:
6573
diff
changeset
|
9 |
#include "landscape.h" |
2625
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
10 |
#include "debug.h" |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
11 |
#include "sprite.h" |
2967
4208a82bf0d9
(svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents:
2963
diff
changeset
|
12 |
#include "station.h" |
3587 | 13 |
#include "station_map.h" |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5172
diff
changeset
|
14 |
#include "newgrf.h" |
3752
a7cdd7c0c928
(svn r4740) - Newstations: add function to evaluate station callbacks
peter1138
parents:
3751
diff
changeset
|
15 |
#include "newgrf_callbacks.h" |
7345
6fab61079176
(svn r10089) -Fix (r10040): Use GetTileZ instead of GetClearGround in GetTerrainType as
maedhros
parents:
7179
diff
changeset
|
16 |
#include "newgrf_commons.h" |
2963
6645da0a5b4a
(svn r3525) - Rename station_newgrf.[ch] to newgrf_station.[ch], and update project files.
peter1138
parents:
2625
diff
changeset
|
17 |
#include "newgrf_station.h" |
3743
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
18 |
#include "newgrf_spritegroup.h" |
6439
99a5807852b1
(svn r8849) -Codechange: Replace hardcoded global/climate cargo mapping tables with dynamically generated data. Change associated code to use new functions.
peter1138
parents:
6432
diff
changeset
|
19 |
#include "cargotype.h" |
6680
2e9f42d9aafa
(svn r9393) -Codechange: Use newgrf town resolver as station parent scope handler
peter1138
parents:
6674
diff
changeset
|
20 |
#include "town_map.h" |
2e9f42d9aafa
(svn r9393) -Codechange: Use newgrf town resolver as station parent scope handler
peter1138
parents:
6674
diff
changeset
|
21 |
#include "newgrf_town.h" |
8619
c2434269c3eb
(svn r11684) -Codechange: split gfx.h in a type and functional header.
rubidium
parents:
8617
diff
changeset
|
22 |
#include "gfx_func.h" |
8636
2b158acb649c
(svn r11702) -Codechange: move all date related stuff to date*.
rubidium
parents:
8626
diff
changeset
|
23 |
#include "date_func.h" |
8750
fdd6054e7bae
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8733
diff
changeset
|
24 |
#include "player_func.h" |
2625
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
25 |
|
8760
ce0891c412ce
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8750
diff
changeset
|
26 |
#include "table/sprites.h" |
ce0891c412ce
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8750
diff
changeset
|
27 |
#include "table/strings.h" |
ce0891c412ce
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8750
diff
changeset
|
28 |
|
8812
1d894693b4da
(svn r11881) -Cleanup: Code style for global variables.
peter1138
parents:
8791
diff
changeset
|
29 |
static StationClass _station_classes[STAT_CLASS_MAX]; |
2625
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
30 |
|
3786
73784d02aa69
(svn r4782) - Newstations: fix issue with saving/loading games with newstations on big endian architectures.
peter1138
parents:
3780
diff
changeset
|
31 |
enum { |
73784d02aa69
(svn r4782) - Newstations: fix issue with saving/loading games with newstations on big endian architectures.
peter1138
parents:
3780
diff
changeset
|
32 |
MAX_SPECLIST = 255, |
73784d02aa69
(svn r4782) - Newstations: fix issue with saving/loading games with newstations on big endian architectures.
peter1138
parents:
3780
diff
changeset
|
33 |
}; |
73784d02aa69
(svn r4782) - Newstations: fix issue with saving/loading games with newstations on big endian architectures.
peter1138
parents:
3780
diff
changeset
|
34 |
|
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 |
* Reset station classes to their default state. |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
37 |
* This includes initialising the Default and Waypoint classes with an empty |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
38 |
* entry, for standard stations and waypoints. |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
39 |
*/ |
6573 | 40 |
void ResetStationClasses() |
2625
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
41 |
{ |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
42 |
for (StationClassID i = STAT_CLASS_BEGIN; i < STAT_CLASS_MAX; i++) { |
8812
1d894693b4da
(svn r11881) -Cleanup: Code style for global variables.
peter1138
parents:
8791
diff
changeset
|
43 |
_station_classes[i].id = 0; |
1d894693b4da
(svn r11881) -Cleanup: Code style for global variables.
peter1138
parents:
8791
diff
changeset
|
44 |
_station_classes[i].name = STR_EMPTY; |
1d894693b4da
(svn r11881) -Cleanup: Code style for global variables.
peter1138
parents:
8791
diff
changeset
|
45 |
_station_classes[i].stations = 0; |
2625
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
46 |
|
8812
1d894693b4da
(svn r11881) -Cleanup: Code style for global variables.
peter1138
parents:
8791
diff
changeset
|
47 |
free(_station_classes[i].spec); |
1d894693b4da
(svn r11881) -Cleanup: Code style for global variables.
peter1138
parents:
8791
diff
changeset
|
48 |
_station_classes[i].spec = NULL; |
2625
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
49 |
} |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
50 |
|
6674
64f4781b4653
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents:
6669
diff
changeset
|
51 |
/* Set up initial data */ |
8812
1d894693b4da
(svn r11881) -Cleanup: Code style for global variables.
peter1138
parents:
8791
diff
changeset
|
52 |
_station_classes[0].id = 'DFLT'; |
1d894693b4da
(svn r11881) -Cleanup: Code style for global variables.
peter1138
parents:
8791
diff
changeset
|
53 |
_station_classes[0].name = STR_STAT_CLASS_DFLT; |
1d894693b4da
(svn r11881) -Cleanup: Code style for global variables.
peter1138
parents:
8791
diff
changeset
|
54 |
_station_classes[0].stations = 1; |
1d894693b4da
(svn r11881) -Cleanup: Code style for global variables.
peter1138
parents:
8791
diff
changeset
|
55 |
_station_classes[0].spec = MallocT<StationSpec*>(1); |
1d894693b4da
(svn r11881) -Cleanup: Code style for global variables.
peter1138
parents:
8791
diff
changeset
|
56 |
_station_classes[0].spec[0] = NULL; |
2625
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
57 |
|
8812
1d894693b4da
(svn r11881) -Cleanup: Code style for global variables.
peter1138
parents:
8791
diff
changeset
|
58 |
_station_classes[1].id = 'WAYP'; |
1d894693b4da
(svn r11881) -Cleanup: Code style for global variables.
peter1138
parents:
8791
diff
changeset
|
59 |
_station_classes[1].name = STR_STAT_CLASS_WAYP; |
1d894693b4da
(svn r11881) -Cleanup: Code style for global variables.
peter1138
parents:
8791
diff
changeset
|
60 |
_station_classes[1].stations = 1; |
1d894693b4da
(svn r11881) -Cleanup: Code style for global variables.
peter1138
parents:
8791
diff
changeset
|
61 |
_station_classes[1].spec = MallocT<StationSpec*>(1); |
1d894693b4da
(svn r11881) -Cleanup: Code style for global variables.
peter1138
parents:
8791
diff
changeset
|
62 |
_station_classes[1].spec[0] = NULL; |
2625
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
63 |
} |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
64 |
|
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
65 |
/** |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
66 |
* Allocate a station class for the given class id. |
6977
67b989528f3d
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6956
diff
changeset
|
67 |
* @param cls A 32 bit value identifying the class. |
8812
1d894693b4da
(svn r11881) -Cleanup: Code style for global variables.
peter1138
parents:
8791
diff
changeset
|
68 |
* @return Index into _station_classes of allocated class. |
2625
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
69 |
*/ |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
70 |
StationClassID AllocateStationClass(uint32 cls) |
2625
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
71 |
{ |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
72 |
for (StationClassID i = STAT_CLASS_BEGIN; i < STAT_CLASS_MAX; i++) { |
8812
1d894693b4da
(svn r11881) -Cleanup: Code style for global variables.
peter1138
parents:
8791
diff
changeset
|
73 |
if (_station_classes[i].id == cls) { |
6674
64f4781b4653
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents:
6669
diff
changeset
|
74 |
/* ClassID is already allocated, so reuse it. */ |
2625
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
75 |
return i; |
8812
1d894693b4da
(svn r11881) -Cleanup: Code style for global variables.
peter1138
parents:
8791
diff
changeset
|
76 |
} else if (_station_classes[i].id == 0) { |
6674
64f4781b4653
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents:
6669
diff
changeset
|
77 |
/* This class is empty, so allocate it to the ClassID. */ |
8812
1d894693b4da
(svn r11881) -Cleanup: Code style for global variables.
peter1138
parents:
8791
diff
changeset
|
78 |
_station_classes[i].id = cls; |
2625
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
79 |
return i; |
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 |
} |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
82 |
|
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5172
diff
changeset
|
83 |
grfmsg(2, "StationClassAllocate: already allocated %d classes, using default", STAT_CLASS_MAX); |
2625
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
84 |
return STAT_CLASS_DFLT; |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
85 |
} |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
86 |
|
3642
a247e07fafdf
(svn r4551) - NewGRF: add string handling for newstations.
peter1138
parents:
3594
diff
changeset
|
87 |
/** Set the name of a custom station class */ |
a247e07fafdf
(svn r4551) - NewGRF: add string handling for newstations.
peter1138
parents:
3594
diff
changeset
|
88 |
void SetStationClassName(StationClassID sclass, StringID name) |
a247e07fafdf
(svn r4551) - NewGRF: add string handling for newstations.
peter1138
parents:
3594
diff
changeset
|
89 |
{ |
a247e07fafdf
(svn r4551) - NewGRF: add string handling for newstations.
peter1138
parents:
3594
diff
changeset
|
90 |
assert(sclass < STAT_CLASS_MAX); |
8812
1d894693b4da
(svn r11881) -Cleanup: Code style for global variables.
peter1138
parents:
8791
diff
changeset
|
91 |
_station_classes[sclass].name = name; |
3642
a247e07fafdf
(svn r4551) - NewGRF: add string handling for newstations.
peter1138
parents:
3594
diff
changeset
|
92 |
} |
a247e07fafdf
(svn r4551) - NewGRF: add string handling for newstations.
peter1138
parents:
3594
diff
changeset
|
93 |
|
a247e07fafdf
(svn r4551) - NewGRF: add string handling for newstations.
peter1138
parents:
3594
diff
changeset
|
94 |
/** Retrieve the name of a custom station class */ |
a247e07fafdf
(svn r4551) - NewGRF: add string handling for newstations.
peter1138
parents:
3594
diff
changeset
|
95 |
StringID GetStationClassName(StationClassID sclass) |
a247e07fafdf
(svn r4551) - NewGRF: add string handling for newstations.
peter1138
parents:
3594
diff
changeset
|
96 |
{ |
a247e07fafdf
(svn r4551) - NewGRF: add string handling for newstations.
peter1138
parents:
3594
diff
changeset
|
97 |
assert(sclass < STAT_CLASS_MAX); |
8812
1d894693b4da
(svn r11881) -Cleanup: Code style for global variables.
peter1138
parents:
8791
diff
changeset
|
98 |
return _station_classes[sclass].name; |
3642
a247e07fafdf
(svn r4551) - NewGRF: add string handling for newstations.
peter1138
parents:
3594
diff
changeset
|
99 |
} |
a247e07fafdf
(svn r4551) - NewGRF: add string handling for newstations.
peter1138
parents:
3594
diff
changeset
|
100 |
|
2625
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
101 |
/** |
3587 | 102 |
* Get the number of station classes in use. |
103 |
* @return Number of station classes. |
|
104 |
*/ |
|
6573 | 105 |
uint GetNumStationClasses() |
3587 | 106 |
{ |
107 |
uint i; |
|
9191
ae14770c829a
(svn r12368) -Codechange: use explicit body for loops and conditions and remove -Wno-empty-body from the configure script
smatz
parents:
9112
diff
changeset
|
108 |
for (i = 0; i < STAT_CLASS_MAX && _station_classes[i].id != 0; i++) {} |
3587 | 109 |
return i; |
110 |
} |
|
111 |
||
112 |
/** |
|
2625
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
113 |
* Return the number of stations for the given station class. |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
114 |
* @param sclass Index of the station class. |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
115 |
* @return Number of stations in the class. |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
116 |
*/ |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
117 |
uint GetNumCustomStations(StationClassID sclass) |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
118 |
{ |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
119 |
assert(sclass < STAT_CLASS_MAX); |
8812
1d894693b4da
(svn r11881) -Cleanup: Code style for global variables.
peter1138
parents:
8791
diff
changeset
|
120 |
return _station_classes[sclass].stations; |
2625
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
121 |
} |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
122 |
|
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
123 |
/** |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
124 |
* Tie a station spec to its station class. |
6977
67b989528f3d
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6956
diff
changeset
|
125 |
* @param statspec The station spec. |
2625
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
126 |
*/ |
3676
48444d881fbe
(svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents:
3668
diff
changeset
|
127 |
void SetCustomStationSpec(StationSpec *statspec) |
2625
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
128 |
{ |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
129 |
StationClass *station_class; |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
130 |
int i; |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
131 |
|
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
|
132 |
/* If the station has already been allocated, don't reallocate it. */ |
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
|
133 |
if (statspec->allocated) return; |
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
|
134 |
|
3676
48444d881fbe
(svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents:
3668
diff
changeset
|
135 |
assert(statspec->sclass < STAT_CLASS_MAX); |
8812
1d894693b4da
(svn r11881) -Cleanup: Code style for global variables.
peter1138
parents:
8791
diff
changeset
|
136 |
station_class = &_station_classes[statspec->sclass]; |
2625
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
137 |
|
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
138 |
i = station_class->stations++; |
5860
7fdc9b423ba1
(svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents:
5838
diff
changeset
|
139 |
station_class->spec = ReallocT(station_class->spec, station_class->stations); |
2625
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
140 |
|
3676
48444d881fbe
(svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents:
3668
diff
changeset
|
141 |
station_class->spec[i] = statspec; |
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
|
142 |
statspec->allocated = true; |
2625
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
143 |
} |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
144 |
|
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
145 |
/** |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
146 |
* Retrieve a station spec from a class. |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
147 |
* @param sclass Index of the station class. |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
148 |
* @param station The station index with the class. |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
149 |
* @return The station spec. |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
150 |
*/ |
3676
48444d881fbe
(svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents:
3668
diff
changeset
|
151 |
const StationSpec *GetCustomStationSpec(StationClassID sclass, uint station) |
2625
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
152 |
{ |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
153 |
assert(sclass < STAT_CLASS_MAX); |
8812
1d894693b4da
(svn r11881) -Cleanup: Code style for global variables.
peter1138
parents:
8791
diff
changeset
|
154 |
if (station < _station_classes[sclass].stations) |
1d894693b4da
(svn r11881) -Cleanup: Code style for global variables.
peter1138
parents:
8791
diff
changeset
|
155 |
return _station_classes[sclass].spec[station]; |
2625
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
156 |
|
6674
64f4781b4653
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents:
6669
diff
changeset
|
157 |
/* If the custom station isn't defined any more, then the GRF file |
64f4781b4653
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents:
6669
diff
changeset
|
158 |
* probably was not loaded. */ |
2625
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
159 |
return NULL; |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
160 |
} |
2967
4208a82bf0d9
(svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents:
2963
diff
changeset
|
161 |
|
4208a82bf0d9
(svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents:
2963
diff
changeset
|
162 |
|
3765
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3764
diff
changeset
|
163 |
const StationSpec *GetCustomStationSpecByGrf(uint32 grfid, byte localidx) |
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3764
diff
changeset
|
164 |
{ |
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3764
diff
changeset
|
165 |
uint j; |
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3764
diff
changeset
|
166 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
167 |
for (StationClassID i = STAT_CLASS_BEGIN; i < STAT_CLASS_MAX; i++) { |
8812
1d894693b4da
(svn r11881) -Cleanup: Code style for global variables.
peter1138
parents:
8791
diff
changeset
|
168 |
for (j = 0; j < _station_classes[i].stations; j++) { |
1d894693b4da
(svn r11881) -Cleanup: Code style for global variables.
peter1138
parents:
8791
diff
changeset
|
169 |
const StationSpec *statspec = _station_classes[i].spec[j]; |
3765
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3764
diff
changeset
|
170 |
if (statspec == NULL) continue; |
6947
c21859ab4493
(svn r9601) -Codechange: Store grf file reference in station spec, not just GRF ID
peter1138
parents:
6683
diff
changeset
|
171 |
if (statspec->grffile->grfid == grfid && statspec->localidx == localidx) return statspec; |
3765
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3764
diff
changeset
|
172 |
} |
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3764
diff
changeset
|
173 |
} |
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3764
diff
changeset
|
174 |
|
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3764
diff
changeset
|
175 |
return NULL; |
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3764
diff
changeset
|
176 |
} |
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3764
diff
changeset
|
177 |
|
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3764
diff
changeset
|
178 |
|
3756
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
179 |
/* Evaluate a tile's position within a station, and return the result a bitstuffed format. |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
180 |
* if not centred: .TNLcCpP, if centred: .TNL..CP |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
181 |
* T = Tile layout number (GetStationGfx), N = Number of platforms, L = Length of platforms |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
182 |
* C = Current platform number from start, c = from end |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
183 |
* P = Position along platform from start, p = from end |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
184 |
* if centred, C/P start from the centre and c/p are not available. |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
185 |
*/ |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
186 |
uint32 GetPlatformInfo(Axis axis, byte tile, int platforms, int length, int x, int y, bool centred) |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
187 |
{ |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
188 |
uint32 retval = 0; |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
189 |
|
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
190 |
if (axis == AXIS_X) { |
6432 | 191 |
Swap(platforms, length); |
192 |
Swap(x, y); |
|
3756
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
193 |
} |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
194 |
|
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
195 |
/* Limit our sizes to 4 bits */ |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
196 |
platforms = min(15, platforms); |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
197 |
length = min(15, length); |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
198 |
x = min(15, x); |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
199 |
y = min(15, y); |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
200 |
if (centred) { |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
201 |
x -= platforms / 2; |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
202 |
y -= length / 2; |
3790
66700f2c57a9
(svn r4786) - Newstations: in GetPlatformInfo() ensure negative values are only four bits
peter1138
parents:
3789
diff
changeset
|
203 |
SB(retval, 0, 4, y & 0xF); |
66700f2c57a9
(svn r4786) - Newstations: in GetPlatformInfo() ensure negative values are only four bits
peter1138
parents:
3789
diff
changeset
|
204 |
SB(retval, 4, 4, x & 0xF); |
3756
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
205 |
} else { |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
206 |
SB(retval, 0, 4, y); |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
207 |
SB(retval, 4, 4, length - y - 1); |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
208 |
SB(retval, 8, 4, x); |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
209 |
SB(retval, 12, 4, platforms - x - 1); |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
210 |
} |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
211 |
SB(retval, 16, 4, length); |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
212 |
SB(retval, 20, 4, platforms); |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
213 |
SB(retval, 24, 4, tile); |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
214 |
|
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
215 |
return retval; |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
216 |
} |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
217 |
|
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
218 |
|
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
219 |
/* Find the end of a railway station, from the tile, in the direction of delta. |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
220 |
* If check_type is set, we stop if the custom station type changes. |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
221 |
* If check_axis is set, we stop if the station direction changes. |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
222 |
*/ |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
223 |
static TileIndex FindRailStationEnd(TileIndex tile, TileIndexDiff delta, bool check_type, bool check_axis) |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
224 |
{ |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
225 |
bool waypoint; |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
226 |
byte orig_type = 0; |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
227 |
Axis orig_axis = AXIS_X; |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
228 |
|
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
229 |
waypoint = IsTileType(tile, MP_RAILWAY); |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
230 |
|
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
231 |
if (waypoint) { |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
232 |
if (check_axis) orig_axis = GetWaypointAxis(tile); |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
233 |
} else { |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
234 |
if (check_type) orig_type = GetCustomStationSpecIndex(tile); |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
235 |
if (check_axis) orig_axis = GetRailStationAxis(tile); |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
236 |
} |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
237 |
|
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
238 |
while (true) { |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
239 |
TileIndex new_tile = TILE_ADD(tile, delta); |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
240 |
|
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
241 |
if (waypoint) { |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
242 |
if (!IsTileType(new_tile, MP_RAILWAY)) break; |
4182
20d711816338
(svn r5624) Use {IsPlainRailTile,IsRailDepot,IsRailWaypoint,HasSignals}() instead of GetRailTile{T,Subt}ype() - this is more concise and a bit more flexible if/when the rail tile encoding changes
tron
parents:
3893
diff
changeset
|
243 |
if (!IsRailWaypoint(new_tile)) break; |
3756
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
244 |
if (check_axis && GetWaypointAxis(new_tile) != orig_axis) break; |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
245 |
} else { |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
246 |
if (!IsRailwayStationTile(new_tile)) break; |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
247 |
if (check_type && GetCustomStationSpecIndex(new_tile) != orig_type) break; |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
248 |
if (check_axis && GetRailStationAxis(new_tile) != orig_axis) break; |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
249 |
} |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
250 |
|
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
251 |
tile = new_tile; |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
252 |
} |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
253 |
return tile; |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
254 |
} |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
255 |
|
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
256 |
|
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
257 |
static uint32 GetPlatformInfoHelper(TileIndex tile, bool check_type, bool check_axis, bool centred) |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
258 |
{ |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
259 |
int tx = TileX(tile); |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
260 |
int ty = TileY(tile); |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
261 |
int sx = TileX(FindRailStationEnd(tile, TileDiffXY(-1, 0), check_type, check_axis)); |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
262 |
int sy = TileY(FindRailStationEnd(tile, TileDiffXY( 0, -1), check_type, check_axis)); |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
263 |
int ex = TileX(FindRailStationEnd(tile, TileDiffXY( 1, 0), check_type, check_axis)) + 1; |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
264 |
int ey = TileY(FindRailStationEnd(tile, TileDiffXY( 0, 1), check_type, check_axis)) + 1; |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
265 |
Axis axis = IsTileType(tile, MP_RAILWAY) ? GetWaypointAxis(tile) : GetRailStationAxis(tile); |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
266 |
|
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
267 |
tx -= sx; ex -= sx; |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
268 |
ty -= sy; ey -= sy; |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
269 |
|
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
270 |
return GetPlatformInfo(axis, IsTileType(tile, MP_RAILWAY) ? 2 : GetStationGfx(tile), ex, ey, tx, ty, centred); |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
271 |
} |
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
272 |
|
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
273 |
|
5660
600fdb6cb88f
(svn r7606) -Codechange: [NewStations] Add support for variables 45 and 65.
peter1138
parents:
5568
diff
changeset
|
274 |
static uint32 GetRailContinuationInfo(TileIndex tile) |
600fdb6cb88f
(svn r7606) -Codechange: [NewStations] Add support for variables 45 and 65.
peter1138
parents:
5568
diff
changeset
|
275 |
{ |
600fdb6cb88f
(svn r7606) -Codechange: [NewStations] Add support for variables 45 and 65.
peter1138
parents:
5568
diff
changeset
|
276 |
/* Tile offsets and exit dirs for X axis */ |
7653
898ee6432dc3
(svn r10431) -Codechange: constness on static array
peter1138
parents:
7506
diff
changeset
|
277 |
static const Direction x_dir[8] = { DIR_SW, DIR_NE, DIR_SE, DIR_NW, DIR_S, DIR_E, DIR_W, DIR_N }; |
898ee6432dc3
(svn r10431) -Codechange: constness on static array
peter1138
parents:
7506
diff
changeset
|
278 |
static const DiagDirection x_exits[8] = { DIAGDIR_SW, DIAGDIR_NE, DIAGDIR_SE, DIAGDIR_NW, DIAGDIR_SW, DIAGDIR_NE, DIAGDIR_SW, DIAGDIR_NE }; |
5660
600fdb6cb88f
(svn r7606) -Codechange: [NewStations] Add support for variables 45 and 65.
peter1138
parents:
5568
diff
changeset
|
279 |
|
600fdb6cb88f
(svn r7606) -Codechange: [NewStations] Add support for variables 45 and 65.
peter1138
parents:
5568
diff
changeset
|
280 |
/* Tile offsets and exit dirs for Y axis */ |
7653
898ee6432dc3
(svn r10431) -Codechange: constness on static array
peter1138
parents:
7506
diff
changeset
|
281 |
static const Direction y_dir[8] = { DIR_SE, DIR_NW, DIR_SW, DIR_NE, DIR_S, DIR_W, DIR_E, DIR_N }; |
898ee6432dc3
(svn r10431) -Codechange: constness on static array
peter1138
parents:
7506
diff
changeset
|
282 |
static const DiagDirection y_exits[8] = { DIAGDIR_SE, DIAGDIR_NW, DIAGDIR_SW, DIAGDIR_NE, DIAGDIR_SE, DIAGDIR_NW, DIAGDIR_SE, DIAGDIR_NW }; |
5660
600fdb6cb88f
(svn r7606) -Codechange: [NewStations] Add support for variables 45 and 65.
peter1138
parents:
5568
diff
changeset
|
283 |
|
600fdb6cb88f
(svn r7606) -Codechange: [NewStations] Add support for variables 45 and 65.
peter1138
parents:
5568
diff
changeset
|
284 |
Axis axis = IsTileType(tile, MP_RAILWAY) ? GetWaypointAxis(tile) : GetRailStationAxis(tile); |
600fdb6cb88f
(svn r7606) -Codechange: [NewStations] Add support for variables 45 and 65.
peter1138
parents:
5568
diff
changeset
|
285 |
|
600fdb6cb88f
(svn r7606) -Codechange: [NewStations] Add support for variables 45 and 65.
peter1138
parents:
5568
diff
changeset
|
286 |
/* Choose appropriate lookup table to use */ |
7653
898ee6432dc3
(svn r10431) -Codechange: constness on static array
peter1138
parents:
7506
diff
changeset
|
287 |
const Direction *dir = axis == AXIS_X ? x_dir : y_dir; |
898ee6432dc3
(svn r10431) -Codechange: constness on static array
peter1138
parents:
7506
diff
changeset
|
288 |
const DiagDirection *diagdir = axis == AXIS_X ? x_exits : y_exits; |
5660
600fdb6cb88f
(svn r7606) -Codechange: [NewStations] Add support for variables 45 and 65.
peter1138
parents:
5568
diff
changeset
|
289 |
|
600fdb6cb88f
(svn r7606) -Codechange: [NewStations] Add support for variables 45 and 65.
peter1138
parents:
5568
diff
changeset
|
290 |
uint32 res = 0; |
600fdb6cb88f
(svn r7606) -Codechange: [NewStations] Add support for variables 45 and 65.
peter1138
parents:
5568
diff
changeset
|
291 |
uint i; |
600fdb6cb88f
(svn r7606) -Codechange: [NewStations] Add support for variables 45 and 65.
peter1138
parents:
5568
diff
changeset
|
292 |
|
600fdb6cb88f
(svn r7606) -Codechange: [NewStations] Add support for variables 45 and 65.
peter1138
parents:
5568
diff
changeset
|
293 |
for (i = 0; i < lengthof(x_dir); i++, dir++, diagdir++) { |
9112
ec6800eaa340
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
9067
diff
changeset
|
294 |
TrackBits trackbits = TrackStatusToTrackBits(GetTileTrackStatus(tile + TileOffsByDir(*dir), TRANSPORT_RAIL, 0)); |
ec6800eaa340
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
9067
diff
changeset
|
295 |
if (trackbits != TRACK_BIT_NONE) { |
5660
600fdb6cb88f
(svn r7606) -Codechange: [NewStations] Add support for variables 45 and 65.
peter1138
parents:
5568
diff
changeset
|
296 |
/* If there is any track on the tile, set the bit in the second byte */ |
8427
143b0be22af1
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents:
8424
diff
changeset
|
297 |
SetBit(res, i + 8); |
5660
600fdb6cb88f
(svn r7606) -Codechange: [NewStations] Add support for variables 45 and 65.
peter1138
parents:
5568
diff
changeset
|
298 |
|
600fdb6cb88f
(svn r7606) -Codechange: [NewStations] Add support for variables 45 and 65.
peter1138
parents:
5568
diff
changeset
|
299 |
/* If any track reaches our exit direction, set the bit in the lower byte */ |
9112
ec6800eaa340
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
9067
diff
changeset
|
300 |
if (trackbits & DiagdirReachesTracks(*diagdir)) SetBit(res, i); |
5660
600fdb6cb88f
(svn r7606) -Codechange: [NewStations] Add support for variables 45 and 65.
peter1138
parents:
5568
diff
changeset
|
301 |
} |
600fdb6cb88f
(svn r7606) -Codechange: [NewStations] Add support for variables 45 and 65.
peter1138
parents:
5568
diff
changeset
|
302 |
} |
600fdb6cb88f
(svn r7606) -Codechange: [NewStations] Add support for variables 45 and 65.
peter1138
parents:
5568
diff
changeset
|
303 |
|
600fdb6cb88f
(svn r7606) -Codechange: [NewStations] Add support for variables 45 and 65.
peter1138
parents:
5568
diff
changeset
|
304 |
return res; |
600fdb6cb88f
(svn r7606) -Codechange: [NewStations] Add support for variables 45 and 65.
peter1138
parents:
5568
diff
changeset
|
305 |
} |
600fdb6cb88f
(svn r7606) -Codechange: [NewStations] Add support for variables 45 and 65.
peter1138
parents:
5568
diff
changeset
|
306 |
|
600fdb6cb88f
(svn r7606) -Codechange: [NewStations] Add support for variables 45 and 65.
peter1138
parents:
5568
diff
changeset
|
307 |
|
3743
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
308 |
/* Station Resolver Functions */ |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
309 |
static uint32 StationGetRandomBits(const ResolverObject *object) |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
310 |
{ |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
311 |
const Station *st = object->u.station.st; |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
312 |
const TileIndex tile = object->u.station.tile; |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
313 |
return (st == NULL ? 0 : st->random_bits) | (tile == INVALID_TILE ? 0 : GetStationTileRandomBits(tile) << 16); |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
314 |
} |
2967
4208a82bf0d9
(svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents:
2963
diff
changeset
|
315 |
|
3743
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
316 |
|
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
317 |
static uint32 StationGetTriggers(const ResolverObject *object) |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
318 |
{ |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
319 |
const Station *st = object->u.station.st; |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
320 |
return st == NULL ? 0 : st->waiting_triggers; |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
321 |
} |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
322 |
|
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
323 |
|
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
324 |
static void StationSetTriggers(const ResolverObject *object, int triggers) |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
325 |
{ |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
326 |
Station *st = (Station*)object->u.station.st; |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
327 |
assert(st != NULL); |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
328 |
st->waiting_triggers = triggers; |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
329 |
} |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
330 |
|
7726
c5e6d417672a
(svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138
parents:
7688
diff
changeset
|
331 |
/** |
c5e6d417672a
(svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138
parents:
7688
diff
changeset
|
332 |
* Station variable cache |
c5e6d417672a
(svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138
parents:
7688
diff
changeset
|
333 |
* This caches 'expensive' station variable lookups which iterate over |
c5e6d417672a
(svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138
parents:
7688
diff
changeset
|
334 |
* several tiles that may be called multiple times per Resolve(). |
c5e6d417672a
(svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138
parents:
7688
diff
changeset
|
335 |
*/ |
c5e6d417672a
(svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138
parents:
7688
diff
changeset
|
336 |
static struct { |
c5e6d417672a
(svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138
parents:
7688
diff
changeset
|
337 |
uint32 v40; |
c5e6d417672a
(svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138
parents:
7688
diff
changeset
|
338 |
uint32 v41; |
c5e6d417672a
(svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138
parents:
7688
diff
changeset
|
339 |
uint32 v45; |
c5e6d417672a
(svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138
parents:
7688
diff
changeset
|
340 |
uint32 v46; |
c5e6d417672a
(svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138
parents:
7688
diff
changeset
|
341 |
uint32 v47; |
c5e6d417672a
(svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138
parents:
7688
diff
changeset
|
342 |
uint32 v49; |
c5e6d417672a
(svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138
parents:
7688
diff
changeset
|
343 |
uint8 valid; |
c5e6d417672a
(svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138
parents:
7688
diff
changeset
|
344 |
} _svc; |
3743
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
345 |
|
3893
46169364701b
(svn r4960) - NewGRF: explicitly handle unsupported variables, instead of returning -1.
peter1138
parents:
3834
diff
changeset
|
346 |
static uint32 StationGetVariable(const ResolverObject *object, byte variable, byte parameter, bool *available) |
3743
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
347 |
{ |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
348 |
const Station *st = object->u.station.st; |
3756
b3835d8eca4d
(svn r4747) - Newstations: implement support for variables 40, 41, 46, 47 and 49.
peter1138
parents:
3755
diff
changeset
|
349 |
TileIndex tile = object->u.station.tile; |
3743
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
350 |
|
6680
2e9f42d9aafa
(svn r9393) -Codechange: Use newgrf town resolver as station parent scope handler
peter1138
parents:
6674
diff
changeset
|
351 |
if (object->scope == VSG_SCOPE_PARENT) { |
2e9f42d9aafa
(svn r9393) -Codechange: Use newgrf town resolver as station parent scope handler
peter1138
parents:
6674
diff
changeset
|
352 |
/* Pass the request on to the town of the station */ |
2e9f42d9aafa
(svn r9393) -Codechange: Use newgrf town resolver as station parent scope handler
peter1138
parents:
6674
diff
changeset
|
353 |
Town *t; |
2e9f42d9aafa
(svn r9393) -Codechange: Use newgrf town resolver as station parent scope handler
peter1138
parents:
6674
diff
changeset
|
354 |
|
2e9f42d9aafa
(svn r9393) -Codechange: Use newgrf town resolver as station parent scope handler
peter1138
parents:
6674
diff
changeset
|
355 |
if (st != NULL) { |
2e9f42d9aafa
(svn r9393) -Codechange: Use newgrf town resolver as station parent scope handler
peter1138
parents:
6674
diff
changeset
|
356 |
t = st->town; |
2e9f42d9aafa
(svn r9393) -Codechange: Use newgrf town resolver as station parent scope handler
peter1138
parents:
6674
diff
changeset
|
357 |
} else if (tile != INVALID_TILE) { |
2e9f42d9aafa
(svn r9393) -Codechange: Use newgrf town resolver as station parent scope handler
peter1138
parents:
6674
diff
changeset
|
358 |
t = GetTownByTile(tile); |
2e9f42d9aafa
(svn r9393) -Codechange: Use newgrf town resolver as station parent scope handler
peter1138
parents:
6674
diff
changeset
|
359 |
} else { |
2e9f42d9aafa
(svn r9393) -Codechange: Use newgrf town resolver as station parent scope handler
peter1138
parents:
6674
diff
changeset
|
360 |
*available = false; |
2e9f42d9aafa
(svn r9393) -Codechange: Use newgrf town resolver as station parent scope handler
peter1138
parents:
6674
diff
changeset
|
361 |
return UINT_MAX; |
2e9f42d9aafa
(svn r9393) -Codechange: Use newgrf town resolver as station parent scope handler
peter1138
parents:
6674
diff
changeset
|
362 |
} |
2e9f42d9aafa
(svn r9393) -Codechange: Use newgrf town resolver as station parent scope handler
peter1138
parents:
6674
diff
changeset
|
363 |
|
2e9f42d9aafa
(svn r9393) -Codechange: Use newgrf town resolver as station parent scope handler
peter1138
parents:
6674
diff
changeset
|
364 |
return TownGetVariable(variable, parameter, available, t); |
2e9f42d9aafa
(svn r9393) -Codechange: Use newgrf town resolver as station parent scope handler
peter1138
parents:
6674
diff
changeset
|
365 |
} |
2e9f42d9aafa
(svn r9393) -Codechange: Use newgrf town resolver as station parent scope handler
peter1138
parents:
6674
diff
changeset
|
366 |
|
3743
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
367 |
if (st == NULL) { |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
368 |
/* Station does not exist, so we're in a purchase list */ |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
369 |
switch (variable) { |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
370 |
case 0x40: |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
371 |
case 0x41: |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
372 |
case 0x46: |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
373 |
case 0x47: |
6674
64f4781b4653
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents:
6669
diff
changeset
|
374 |
case 0x49: return 0x2110000; // Platforms, tracks & position |
64f4781b4653
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents:
6669
diff
changeset
|
375 |
case 0x42: return 0; // Rail type (XXX Get current type from GUI?) |
64f4781b4653
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents:
6669
diff
changeset
|
376 |
case 0x43: return _current_player; // Station owner |
64f4781b4653
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents:
6669
diff
changeset
|
377 |
case 0x44: return 2; // PBS status |
8418
b49fc6be1ab9
(svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents:
8138
diff
changeset
|
378 |
case 0xFA: return Clamp(_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 65535); // Build date, clamped to a 16 bit value |
3743
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
379 |
} |
3893
46169364701b
(svn r4960) - NewGRF: explicitly handle unsupported variables, instead of returning -1.
peter1138
parents:
3834
diff
changeset
|
380 |
|
46169364701b
(svn r4960) - NewGRF: explicitly handle unsupported variables, instead of returning -1.
peter1138
parents:
3834
diff
changeset
|
381 |
*available = false; |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
382 |
return UINT_MAX; |
3743
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
383 |
} |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
384 |
|
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
385 |
switch (variable) { |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
386 |
/* Calculated station variables */ |
7726
c5e6d417672a
(svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138
parents:
7688
diff
changeset
|
387 |
case 0x40: |
8427
143b0be22af1
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents:
8424
diff
changeset
|
388 |
if (!HasBit(_svc.valid, 0)) { _svc.v40 = GetPlatformInfoHelper(tile, false, false, false); SetBit(_svc.valid, 0); } |
7726
c5e6d417672a
(svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138
parents:
7688
diff
changeset
|
389 |
return _svc.v40; |
c5e6d417672a
(svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138
parents:
7688
diff
changeset
|
390 |
|
c5e6d417672a
(svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138
parents:
7688
diff
changeset
|
391 |
case 0x41: |
8427
143b0be22af1
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents:
8424
diff
changeset
|
392 |
if (!HasBit(_svc.valid, 1)) { _svc.v41 = GetPlatformInfoHelper(tile, true, false, false); SetBit(_svc.valid, 1); } |
7726
c5e6d417672a
(svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138
parents:
7688
diff
changeset
|
393 |
return _svc.v41; |
c5e6d417672a
(svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138
parents:
7688
diff
changeset
|
394 |
|
7345
6fab61079176
(svn r10089) -Fix (r10040): Use GetTileZ instead of GetClearGround in GetTerrainType as
maedhros
parents:
7179
diff
changeset
|
395 |
case 0x42: return GetTerrainType(tile) | (GetRailType(tile) << 8); |
6674
64f4781b4653
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents:
6669
diff
changeset
|
396 |
case 0x43: return st->owner; // Station owner |
64f4781b4653
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents:
6669
diff
changeset
|
397 |
case 0x44: return 2; // PBS status |
7726
c5e6d417672a
(svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138
parents:
7688
diff
changeset
|
398 |
case 0x45: |
8427
143b0be22af1
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents:
8424
diff
changeset
|
399 |
if (!HasBit(_svc.valid, 2)) { _svc.v45 = GetRailContinuationInfo(tile); SetBit(_svc.valid, 2); } |
7726
c5e6d417672a
(svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138
parents:
7688
diff
changeset
|
400 |
return _svc.v45; |
c5e6d417672a
(svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138
parents:
7688
diff
changeset
|
401 |
|
c5e6d417672a
(svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138
parents:
7688
diff
changeset
|
402 |
case 0x46: |
8427
143b0be22af1
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents:
8424
diff
changeset
|
403 |
if (!HasBit(_svc.valid, 3)) { _svc.v46 = GetPlatformInfoHelper(tile, false, false, true); SetBit(_svc.valid, 3); } |
7726
c5e6d417672a
(svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138
parents:
7688
diff
changeset
|
404 |
return _svc.v46; |
c5e6d417672a
(svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138
parents:
7688
diff
changeset
|
405 |
|
c5e6d417672a
(svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138
parents:
7688
diff
changeset
|
406 |
case 0x47: |
8427
143b0be22af1
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents:
8424
diff
changeset
|
407 |
if (!HasBit(_svc.valid, 4)) { _svc.v47 = GetPlatformInfoHelper(tile, true, false, true); SetBit(_svc.valid, 4); } |
7726
c5e6d417672a
(svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138
parents:
7688
diff
changeset
|
408 |
return _svc.v47; |
c5e6d417672a
(svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138
parents:
7688
diff
changeset
|
409 |
|
6674
64f4781b4653
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents:
6669
diff
changeset
|
410 |
case 0x48: { // Accepted cargo types |
3743
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
411 |
CargoID cargo_type; |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
412 |
uint32 value = 0; |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
413 |
|
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
414 |
for (cargo_type = 0; cargo_type < NUM_CARGO; cargo_type++) { |
8427
143b0be22af1
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents:
8424
diff
changeset
|
415 |
if (HasBit(st->goods[cargo_type].acceptance_pickup, GoodsEntry::PICKUP)) SetBit(value, cargo_type); |
2967
4208a82bf0d9
(svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents:
2963
diff
changeset
|
416 |
} |
3743
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
417 |
return value; |
2967
4208a82bf0d9
(svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents:
2963
diff
changeset
|
418 |
} |
7726
c5e6d417672a
(svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138
parents:
7688
diff
changeset
|
419 |
case 0x49: |
8427
143b0be22af1
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents:
8424
diff
changeset
|
420 |
if (!HasBit(_svc.valid, 5)) { _svc.v49 = GetPlatformInfoHelper(tile, false, true, false); SetBit(_svc.valid, 5); } |
7726
c5e6d417672a
(svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138
parents:
7688
diff
changeset
|
421 |
return _svc.v49; |
2967
4208a82bf0d9
(svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents:
2963
diff
changeset
|
422 |
|
3743
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
423 |
/* Variables which use the parameter */ |
6956
0d884da2fd1c
(svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138
parents:
6947
diff
changeset
|
424 |
/* Variables 0x60 to 0x65 are handled separately below */ |
8614
21126f54f5c8
(svn r11679) -Add: [newgrf] support for station vars 67 and 68
glx
parents:
8427
diff
changeset
|
425 |
case 0x67: { // Land info of nearby tiles |
21126f54f5c8
(svn r11679) -Add: [newgrf] support for station vars 67 and 68
glx
parents:
8427
diff
changeset
|
426 |
Axis axis = GetRailStationAxis(tile); |
21126f54f5c8
(svn r11679) -Add: [newgrf] support for station vars 67 and 68
glx
parents:
8427
diff
changeset
|
427 |
|
21126f54f5c8
(svn r11679) -Add: [newgrf] support for station vars 67 and 68
glx
parents:
8427
diff
changeset
|
428 |
if (parameter != 0) tile = GetNearbyTile(parameter, tile); // only perform if it is required |
21126f54f5c8
(svn r11679) -Add: [newgrf] support for station vars 67 and 68
glx
parents:
8427
diff
changeset
|
429 |
|
8954
ca1d17502817
(svn r12028) -Codechange: Split common part of station var 0x67, house var 0x62, indtile var 0x60 and industry var 0x62 to 'newgrf_commons.cpp'.
frosch
parents:
8812
diff
changeset
|
430 |
Slope tileh = GetTileSlope(tile, NULL); |
ca1d17502817
(svn r12028) -Codechange: Split common part of station var 0x67, house var 0x62, indtile var 0x60 and industry var 0x62 to 'newgrf_commons.cpp'.
frosch
parents:
8812
diff
changeset
|
431 |
bool swap = (axis == AXIS_Y && HasBit(tileh, SLOPE_W) != HasBit(tileh, SLOPE_E)); |
ca1d17502817
(svn r12028) -Codechange: Split common part of station var 0x67, house var 0x62, indtile var 0x60 and industry var 0x62 to 'newgrf_commons.cpp'.
frosch
parents:
8812
diff
changeset
|
432 |
|
ca1d17502817
(svn r12028) -Codechange: Split common part of station var 0x67, house var 0x62, indtile var 0x60 and industry var 0x62 to 'newgrf_commons.cpp'.
frosch
parents:
8812
diff
changeset
|
433 |
return GetNearbyTileInformation(tile) ^ (swap ? SLOPE_EW : 0); |
8614
21126f54f5c8
(svn r11679) -Add: [newgrf] support for station vars 67 and 68
glx
parents:
8427
diff
changeset
|
434 |
} |
21126f54f5c8
(svn r11679) -Add: [newgrf] support for station vars 67 and 68
glx
parents:
8427
diff
changeset
|
435 |
|
21126f54f5c8
(svn r11679) -Add: [newgrf] support for station vars 67 and 68
glx
parents:
8427
diff
changeset
|
436 |
case 0x68: { // Station info of nearby tiles |
21126f54f5c8
(svn r11679) -Add: [newgrf] support for station vars 67 and 68
glx
parents:
8427
diff
changeset
|
437 |
TileIndex nearby_tile = GetNearbyTile(parameter, tile); |
21126f54f5c8
(svn r11679) -Add: [newgrf] support for station vars 67 and 68
glx
parents:
8427
diff
changeset
|
438 |
|
21126f54f5c8
(svn r11679) -Add: [newgrf] support for station vars 67 and 68
glx
parents:
8427
diff
changeset
|
439 |
if (!IsRailwayStationTile(nearby_tile)) return 0xFFFFFFFF; |
21126f54f5c8
(svn r11679) -Add: [newgrf] support for station vars 67 and 68
glx
parents:
8427
diff
changeset
|
440 |
|
21126f54f5c8
(svn r11679) -Add: [newgrf] support for station vars 67 and 68
glx
parents:
8427
diff
changeset
|
441 |
uint32 grfid = st->speclist[GetCustomStationSpecIndex(tile)].grfid; |
21126f54f5c8
(svn r11679) -Add: [newgrf] support for station vars 67 and 68
glx
parents:
8427
diff
changeset
|
442 |
bool perpendicular = GetRailStationAxis(tile) != GetRailStationAxis(nearby_tile); |
21126f54f5c8
(svn r11679) -Add: [newgrf] support for station vars 67 and 68
glx
parents:
8427
diff
changeset
|
443 |
bool same_station = st->TileBelongsToRailStation(nearby_tile); |
21126f54f5c8
(svn r11679) -Add: [newgrf] support for station vars 67 and 68
glx
parents:
8427
diff
changeset
|
444 |
uint32 res = GB(GetStationGfx(nearby_tile), 1, 2) << 12 | !!perpendicular << 11 | !!same_station << 10; |
21126f54f5c8
(svn r11679) -Add: [newgrf] support for station vars 67 and 68
glx
parents:
8427
diff
changeset
|
445 |
|
21126f54f5c8
(svn r11679) -Add: [newgrf] support for station vars 67 and 68
glx
parents:
8427
diff
changeset
|
446 |
if (IsCustomStationSpecIndex(nearby_tile)) { |
21126f54f5c8
(svn r11679) -Add: [newgrf] support for station vars 67 and 68
glx
parents:
8427
diff
changeset
|
447 |
const StationSpecList ssl = GetStationByTile(nearby_tile)->speclist[GetCustomStationSpecIndex(nearby_tile)]; |
21126f54f5c8
(svn r11679) -Add: [newgrf] support for station vars 67 and 68
glx
parents:
8427
diff
changeset
|
448 |
res |= 1 << (ssl.grfid != grfid ? 9 : 8) | ssl.localidx; |
21126f54f5c8
(svn r11679) -Add: [newgrf] support for station vars 67 and 68
glx
parents:
8427
diff
changeset
|
449 |
} |
21126f54f5c8
(svn r11679) -Add: [newgrf] support for station vars 67 and 68
glx
parents:
8427
diff
changeset
|
450 |
return res; |
21126f54f5c8
(svn r11679) -Add: [newgrf] support for station vars 67 and 68
glx
parents:
8427
diff
changeset
|
451 |
} |
3743
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
452 |
|
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
453 |
/* General station properties */ |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
454 |
case 0x82: return 50; |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
455 |
case 0x84: return st->string_id; |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
456 |
case 0x86: return 0; |
3746
bde65debf648
(svn r4734) - Newstations: add more variables and fix a division by zero.
peter1138
parents:
3743
diff
changeset
|
457 |
case 0x8A: return st->had_vehicle_of_type; |
3743
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
458 |
case 0xF0: return st->facilities; |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
459 |
case 0xF1: return st->airport_type; |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
460 |
case 0xF2: return st->truck_stops->status; |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
461 |
case 0xF3: return st->bus_stops->status; |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
462 |
case 0xF6: return st->airport_flags; |
5172
7e64b65d3c54
(svn r7282) -Fix (r625): ttdpatch vars are little endian
peter1138
parents:
4817
diff
changeset
|
463 |
case 0xF7: return GB(st->airport_flags, 8, 8); |
8418
b49fc6be1ab9
(svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents:
8138
diff
changeset
|
464 |
case 0xFA: return Clamp(st->build_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 65535); |
2967
4208a82bf0d9
(svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents:
2963
diff
changeset
|
465 |
} |
3743
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
466 |
|
6956
0d884da2fd1c
(svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138
parents:
6947
diff
changeset
|
467 |
/* Handle cargo variables with parameter, 0x60 to 0x65 */ |
0d884da2fd1c
(svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138
parents:
6947
diff
changeset
|
468 |
if (variable >= 0x60 && variable <= 0x65) { |
0d884da2fd1c
(svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138
parents:
6947
diff
changeset
|
469 |
CargoID c = GetCargoTranslation(parameter, object->u.station.statspec->grffile); |
0d884da2fd1c
(svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138
parents:
6947
diff
changeset
|
470 |
|
0d884da2fd1c
(svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138
parents:
6947
diff
changeset
|
471 |
if (c == CT_INVALID) return 0; |
0d884da2fd1c
(svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138
parents:
6947
diff
changeset
|
472 |
const GoodsEntry *ge = &st->goods[c]; |
0d884da2fd1c
(svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138
parents:
6947
diff
changeset
|
473 |
|
0d884da2fd1c
(svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138
parents:
6947
diff
changeset
|
474 |
switch (variable) { |
7506
e52d89f5c7c1
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
7345
diff
changeset
|
475 |
case 0x60: return min(ge->cargo.Count(), 4095); |
6956
0d884da2fd1c
(svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138
parents:
6947
diff
changeset
|
476 |
case 0x61: return ge->days_since_pickup; |
0d884da2fd1c
(svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138
parents:
6947
diff
changeset
|
477 |
case 0x62: return ge->rating; |
7506
e52d89f5c7c1
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
7345
diff
changeset
|
478 |
case 0x63: return ge->cargo.DaysInTransit(); |
6956
0d884da2fd1c
(svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138
parents:
6947
diff
changeset
|
479 |
case 0x64: return ge->last_speed | (ge->last_age << 8); |
7970
204ece3a05d5
(svn r10981) -Fix [FS#1156] (r10970): stations gave ratings for accepted cargo too.
rubidium
parents:
7823
diff
changeset
|
480 |
case 0x65: return GB(ge->acceptance_pickup, GoodsEntry::ACCEPTANCE, 1) << 3; |
6956
0d884da2fd1c
(svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138
parents:
6947
diff
changeset
|
481 |
} |
0d884da2fd1c
(svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138
parents:
6947
diff
changeset
|
482 |
} |
0d884da2fd1c
(svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138
parents:
6947
diff
changeset
|
483 |
|
3746
bde65debf648
(svn r4734) - Newstations: add more variables and fix a division by zero.
peter1138
parents:
3743
diff
changeset
|
484 |
/* Handle cargo variables (deprecated) */ |
bde65debf648
(svn r4734) - Newstations: add more variables and fix a division by zero.
peter1138
parents:
3743
diff
changeset
|
485 |
if (variable >= 0x8C && variable <= 0xEC) { |
bde65debf648
(svn r4734) - Newstations: add more variables and fix a division by zero.
peter1138
parents:
3743
diff
changeset
|
486 |
const GoodsEntry *g = &st->goods[GB(variable - 0x8C, 3, 4)]; |
bde65debf648
(svn r4734) - Newstations: add more variables and fix a division by zero.
peter1138
parents:
3743
diff
changeset
|
487 |
switch (GB(variable - 0x8C, 0, 3)) { |
7506
e52d89f5c7c1
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
7345
diff
changeset
|
488 |
case 0: return g->cargo.Count(); |
7970
204ece3a05d5
(svn r10981) -Fix [FS#1156] (r10970): stations gave ratings for accepted cargo too.
rubidium
parents:
7823
diff
changeset
|
489 |
case 1: return GB(min(g->cargo.Count(), 4095), 0, 4) | (GB(g->acceptance_pickup, GoodsEntry::ACCEPTANCE, 1) << 7); |
3746
bde65debf648
(svn r4734) - Newstations: add more variables and fix a division by zero.
peter1138
parents:
3743
diff
changeset
|
490 |
case 2: return g->days_since_pickup; |
bde65debf648
(svn r4734) - Newstations: add more variables and fix a division by zero.
peter1138
parents:
3743
diff
changeset
|
491 |
case 3: return g->rating; |
7506
e52d89f5c7c1
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
7345
diff
changeset
|
492 |
case 4: return g->cargo.Source(); |
e52d89f5c7c1
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
7345
diff
changeset
|
493 |
case 5: return g->cargo.DaysInTransit(); |
3746
bde65debf648
(svn r4734) - Newstations: add more variables and fix a division by zero.
peter1138
parents:
3743
diff
changeset
|
494 |
case 6: return g->last_speed; |
bde65debf648
(svn r4734) - Newstations: add more variables and fix a division by zero.
peter1138
parents:
3743
diff
changeset
|
495 |
case 7: return g->last_age; |
bde65debf648
(svn r4734) - Newstations: add more variables and fix a division by zero.
peter1138
parents:
3743
diff
changeset
|
496 |
} |
bde65debf648
(svn r4734) - Newstations: add more variables and fix a division by zero.
peter1138
parents:
3743
diff
changeset
|
497 |
} |
bde65debf648
(svn r4734) - Newstations: add more variables and fix a division by zero.
peter1138
parents:
3743
diff
changeset
|
498 |
|
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5172
diff
changeset
|
499 |
DEBUG(grf, 1, "Unhandled station property 0x%X", variable); |
3743
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
500 |
|
3893
46169364701b
(svn r4960) - NewGRF: explicitly handle unsupported variables, instead of returning -1.
peter1138
parents:
3834
diff
changeset
|
501 |
*available = false; |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
502 |
return UINT_MAX; |
2967
4208a82bf0d9
(svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents:
2963
diff
changeset
|
503 |
} |
4208a82bf0d9
(svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents:
2963
diff
changeset
|
504 |
|
4208a82bf0d9
(svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents:
2963
diff
changeset
|
505 |
|
3743
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
506 |
static const SpriteGroup *StationResolveReal(const ResolverObject *object, const SpriteGroup *group) |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
507 |
{ |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
508 |
const Station *st = object->u.station.st; |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
509 |
const StationSpec *statspec = object->u.station.statspec; |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
510 |
uint set; |
2967
4208a82bf0d9
(svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents:
2963
diff
changeset
|
511 |
|
3743
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
512 |
uint cargo = 0; |
4817
413372173231
(svn r6741) - Codechange: Simplify and unify resolving of station groups, and use the first available cargo type instead of only the default.
peter1138
parents:
4331
diff
changeset
|
513 |
CargoID cargo_type = object->u.station.cargo_type; |
3743
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
514 |
|
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
515 |
if (st == NULL || statspec->sclass == STAT_CLASS_WAYP) { |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
516 |
return group->g.real.loading[0]; |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
517 |
} |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
518 |
|
4817
413372173231
(svn r6741) - Codechange: Simplify and unify resolving of station groups, and use the first available cargo type instead of only the default.
peter1138
parents:
4331
diff
changeset
|
519 |
switch (cargo_type) { |
6474
24e7ceeb25f5
(svn r8891) -Codechange: Remove remains of global cargo scheme. All cargo mapping is now dealt with only in NewGRF code, on load where possible.
peter1138
parents:
6448
diff
changeset
|
520 |
case CT_INVALID: |
24e7ceeb25f5
(svn r8891) -Codechange: Remove remains of global cargo scheme. All cargo mapping is now dealt with only in NewGRF code, on load where possible.
peter1138
parents:
6448
diff
changeset
|
521 |
case CT_DEFAULT_NA: |
24e7ceeb25f5
(svn r8891) -Codechange: Remove remains of global cargo scheme. All cargo mapping is now dealt with only in NewGRF code, on load where possible.
peter1138
parents:
6448
diff
changeset
|
522 |
case CT_PURCHASE: |
4817
413372173231
(svn r6741) - Codechange: Simplify and unify resolving of station groups, and use the first available cargo type instead of only the default.
peter1138
parents:
4331
diff
changeset
|
523 |
cargo = 0; |
413372173231
(svn r6741) - Codechange: Simplify and unify resolving of station groups, and use the first available cargo type instead of only the default.
peter1138
parents:
4331
diff
changeset
|
524 |
break; |
413372173231
(svn r6741) - Codechange: Simplify and unify resolving of station groups, and use the first available cargo type instead of only the default.
peter1138
parents:
4331
diff
changeset
|
525 |
|
6474
24e7ceeb25f5
(svn r8891) -Codechange: Remove remains of global cargo scheme. All cargo mapping is now dealt with only in NewGRF code, on load where possible.
peter1138
parents:
6448
diff
changeset
|
526 |
case CT_DEFAULT: |
4817
413372173231
(svn r6741) - Codechange: Simplify and unify resolving of station groups, and use the first available cargo type instead of only the default.
peter1138
parents:
4331
diff
changeset
|
527 |
for (cargo_type = 0; cargo_type < NUM_CARGO; cargo_type++) { |
7506
e52d89f5c7c1
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
7345
diff
changeset
|
528 |
cargo += st->goods[cargo_type].cargo.Count(); |
4817
413372173231
(svn r6741) - Codechange: Simplify and unify resolving of station groups, and use the first available cargo type instead of only the default.
peter1138
parents:
4331
diff
changeset
|
529 |
} |
413372173231
(svn r6741) - Codechange: Simplify and unify resolving of station groups, and use the first available cargo type instead of only the default.
peter1138
parents:
4331
diff
changeset
|
530 |
break; |
413372173231
(svn r6741) - Codechange: Simplify and unify resolving of station groups, and use the first available cargo type instead of only the default.
peter1138
parents:
4331
diff
changeset
|
531 |
|
413372173231
(svn r6741) - Codechange: Simplify and unify resolving of station groups, and use the first available cargo type instead of only the default.
peter1138
parents:
4331
diff
changeset
|
532 |
default: |
7506
e52d89f5c7c1
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
7345
diff
changeset
|
533 |
cargo = st->goods[cargo_type].cargo.Count(); |
4817
413372173231
(svn r6741) - Codechange: Simplify and unify resolving of station groups, and use the first available cargo type instead of only the default.
peter1138
parents:
4331
diff
changeset
|
534 |
break; |
3743
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
535 |
} |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
536 |
|
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8418
diff
changeset
|
537 |
if (HasBit(statspec->flags, 1)) cargo /= (st->trainst_w + st->trainst_h); |
3743
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
538 |
cargo = min(0xfff, cargo); |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
539 |
|
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
540 |
if (cargo > statspec->cargo_threshold) { |
3749
96b36cc10188
(svn r4737) - Newstations: 'real' groups picked the wrong set of loading or loaded sprites
peter1138
parents:
3748
diff
changeset
|
541 |
if (group->g.real.num_loading > 0) { |
3787
a71d1c53e679
(svn r4783) - Newstations: fix graphical bug that affected some stations when a station has a high amount of cargo waiting.
peter1138
parents:
3786
diff
changeset
|
542 |
set = ((cargo - statspec->cargo_threshold) * group->g.real.num_loading) / (4096 - statspec->cargo_threshold); |
3749
96b36cc10188
(svn r4737) - Newstations: 'real' groups picked the wrong set of loading or loaded sprites
peter1138
parents:
3748
diff
changeset
|
543 |
return group->g.real.loading[set]; |
3743
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
544 |
} |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
545 |
} else { |
3749
96b36cc10188
(svn r4737) - Newstations: 'real' groups picked the wrong set of loading or loaded sprites
peter1138
parents:
3748
diff
changeset
|
546 |
if (group->g.real.num_loaded > 0) { |
96b36cc10188
(svn r4737) - Newstations: 'real' groups picked the wrong set of loading or loaded sprites
peter1138
parents:
3748
diff
changeset
|
547 |
set = (cargo * group->g.real.num_loaded) / (statspec->cargo_threshold + 1); |
96b36cc10188
(svn r4737) - Newstations: 'real' groups picked the wrong set of loading or loaded sprites
peter1138
parents:
3748
diff
changeset
|
548 |
return group->g.real.loaded[set]; |
3743
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
549 |
} |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
550 |
} |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
551 |
|
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
552 |
return group->g.real.loading[0]; |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
553 |
} |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
554 |
|
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
555 |
|
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
556 |
static void NewStationResolver(ResolverObject *res, const StationSpec *statspec, const Station *st, TileIndex tile) |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
557 |
{ |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
558 |
res->GetRandomBits = StationGetRandomBits; |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
559 |
res->GetTriggers = StationGetTriggers; |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
560 |
res->SetTriggers = StationSetTriggers; |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
561 |
res->GetVariable = StationGetVariable; |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
562 |
res->ResolveReal = StationResolveReal; |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
563 |
|
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
564 |
res->u.station.st = st; |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
565 |
res->u.station.statspec = statspec; |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
566 |
res->u.station.tile = tile; |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
567 |
|
7823
cad4dec2b899
(svn r10690) -Codechange: use the enum that describes all callback IDs in favor of "just" using an untyped integer.
rubidium
parents:
7768
diff
changeset
|
568 |
res->callback = CBID_NO_CALLBACK; |
3743
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
569 |
res->callback_param1 = 0; |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
570 |
res->callback_param2 = 0; |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
571 |
res->last_value = 0; |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
572 |
res->trigger = 0; |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
573 |
res->reseed = 0; |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
574 |
} |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
575 |
|
6100 | 576 |
static const SpriteGroup *ResolveStation(ResolverObject *object) |
4817
413372173231
(svn r6741) - Codechange: Simplify and unify resolving of station groups, and use the first available cargo type instead of only the default.
peter1138
parents:
4331
diff
changeset
|
577 |
{ |
413372173231
(svn r6741) - Codechange: Simplify and unify resolving of station groups, and use the first available cargo type instead of only the default.
peter1138
parents:
4331
diff
changeset
|
578 |
const SpriteGroup *group; |
6474
24e7ceeb25f5
(svn r8891) -Codechange: Remove remains of global cargo scheme. All cargo mapping is now dealt with only in NewGRF code, on load where possible.
peter1138
parents:
6448
diff
changeset
|
579 |
CargoID ctype = CT_DEFAULT_NA; |
4817
413372173231
(svn r6741) - Codechange: Simplify and unify resolving of station groups, and use the first available cargo type instead of only the default.
peter1138
parents:
4331
diff
changeset
|
580 |
|
6100 | 581 |
if (object->u.station.st == NULL) { |
4817
413372173231
(svn r6741) - Codechange: Simplify and unify resolving of station groups, and use the first available cargo type instead of only the default.
peter1138
parents:
4331
diff
changeset
|
582 |
/* No station, so we are in a purchase list */ |
6474
24e7ceeb25f5
(svn r8891) -Codechange: Remove remains of global cargo scheme. All cargo mapping is now dealt with only in NewGRF code, on load where possible.
peter1138
parents:
6448
diff
changeset
|
583 |
ctype = CT_PURCHASE; |
4817
413372173231
(svn r6741) - Codechange: Simplify and unify resolving of station groups, and use the first available cargo type instead of only the default.
peter1138
parents:
4331
diff
changeset
|
584 |
} else { |
413372173231
(svn r6741) - Codechange: Simplify and unify resolving of station groups, and use the first available cargo type instead of only the default.
peter1138
parents:
4331
diff
changeset
|
585 |
/* Pick the first cargo that we have waiting */ |
6439
99a5807852b1
(svn r8849) -Codechange: Replace hardcoded global/climate cargo mapping tables with dynamically generated data. Change associated code to use new functions.
peter1138
parents:
6432
diff
changeset
|
586 |
for (CargoID cargo = 0; cargo < NUM_CARGO; cargo++) { |
99a5807852b1
(svn r8849) -Codechange: Replace hardcoded global/climate cargo mapping tables with dynamically generated data. Change associated code to use new functions.
peter1138
parents:
6432
diff
changeset
|
587 |
const CargoSpec *cs = GetCargo(cargo); |
6474
24e7ceeb25f5
(svn r8891) -Codechange: Remove remains of global cargo scheme. All cargo mapping is now dealt with only in NewGRF code, on load where possible.
peter1138
parents:
6448
diff
changeset
|
588 |
if (cs->IsValid() && object->u.station.statspec->spritegroup[cargo] != NULL && |
7506
e52d89f5c7c1
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
7345
diff
changeset
|
589 |
!object->u.station.st->goods[cargo].cargo.Empty()) { |
6474
24e7ceeb25f5
(svn r8891) -Codechange: Remove remains of global cargo scheme. All cargo mapping is now dealt with only in NewGRF code, on load where possible.
peter1138
parents:
6448
diff
changeset
|
590 |
ctype = cargo; |
4817
413372173231
(svn r6741) - Codechange: Simplify and unify resolving of station groups, and use the first available cargo type instead of only the default.
peter1138
parents:
4331
diff
changeset
|
591 |
break; |
413372173231
(svn r6741) - Codechange: Simplify and unify resolving of station groups, and use the first available cargo type instead of only the default.
peter1138
parents:
4331
diff
changeset
|
592 |
} |
413372173231
(svn r6741) - Codechange: Simplify and unify resolving of station groups, and use the first available cargo type instead of only the default.
peter1138
parents:
4331
diff
changeset
|
593 |
} |
413372173231
(svn r6741) - Codechange: Simplify and unify resolving of station groups, and use the first available cargo type instead of only the default.
peter1138
parents:
4331
diff
changeset
|
594 |
} |
413372173231
(svn r6741) - Codechange: Simplify and unify resolving of station groups, and use the first available cargo type instead of only the default.
peter1138
parents:
4331
diff
changeset
|
595 |
|
6100 | 596 |
group = object->u.station.statspec->spritegroup[ctype]; |
4817
413372173231
(svn r6741) - Codechange: Simplify and unify resolving of station groups, and use the first available cargo type instead of only the default.
peter1138
parents:
4331
diff
changeset
|
597 |
if (group == NULL) { |
6474
24e7ceeb25f5
(svn r8891) -Codechange: Remove remains of global cargo scheme. All cargo mapping is now dealt with only in NewGRF code, on load where possible.
peter1138
parents:
6448
diff
changeset
|
598 |
ctype = CT_DEFAULT; |
6100 | 599 |
group = object->u.station.statspec->spritegroup[ctype]; |
4817
413372173231
(svn r6741) - Codechange: Simplify and unify resolving of station groups, and use the first available cargo type instead of only the default.
peter1138
parents:
4331
diff
changeset
|
600 |
} |
413372173231
(svn r6741) - Codechange: Simplify and unify resolving of station groups, and use the first available cargo type instead of only the default.
peter1138
parents:
4331
diff
changeset
|
601 |
|
413372173231
(svn r6741) - Codechange: Simplify and unify resolving of station groups, and use the first available cargo type instead of only the default.
peter1138
parents:
4331
diff
changeset
|
602 |
if (group == NULL) return NULL; |
413372173231
(svn r6741) - Codechange: Simplify and unify resolving of station groups, and use the first available cargo type instead of only the default.
peter1138
parents:
4331
diff
changeset
|
603 |
|
413372173231
(svn r6741) - Codechange: Simplify and unify resolving of station groups, and use the first available cargo type instead of only the default.
peter1138
parents:
4331
diff
changeset
|
604 |
/* Remember the cargo type we've picked */ |
413372173231
(svn r6741) - Codechange: Simplify and unify resolving of station groups, and use the first available cargo type instead of only the default.
peter1138
parents:
4331
diff
changeset
|
605 |
object->u.station.cargo_type = ctype; |
413372173231
(svn r6741) - Codechange: Simplify and unify resolving of station groups, and use the first available cargo type instead of only the default.
peter1138
parents:
4331
diff
changeset
|
606 |
|
7726
c5e6d417672a
(svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138
parents:
7688
diff
changeset
|
607 |
/* Invalidate all cached vars */ |
c5e6d417672a
(svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138
parents:
7688
diff
changeset
|
608 |
_svc.valid = 0; |
c5e6d417672a
(svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138
parents:
7688
diff
changeset
|
609 |
|
4817
413372173231
(svn r6741) - Codechange: Simplify and unify resolving of station groups, and use the first available cargo type instead of only the default.
peter1138
parents:
4331
diff
changeset
|
610 |
return Resolve(group, object); |
413372173231
(svn r6741) - Codechange: Simplify and unify resolving of station groups, and use the first available cargo type instead of only the default.
peter1138
parents:
4331
diff
changeset
|
611 |
} |
3743
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
612 |
|
3751
785501c18d0d
(svn r4739) - Newstations: remove cargo type parameter of GetCustomStationRelocation() as we can determine it internally
peter1138
parents:
3750
diff
changeset
|
613 |
SpriteID GetCustomStationRelocation(const StationSpec *statspec, const Station *st, TileIndex tile) |
3743
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
614 |
{ |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
615 |
const SpriteGroup *group; |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
616 |
ResolverObject object; |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
617 |
|
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
618 |
NewStationResolver(&object, statspec, st, tile); |
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
619 |
|
6100 | 620 |
group = ResolveStation(&object); |
3743
c6efbe2e3a28
(svn r4729) - Newstations: replace old station resolver with new resolver code (as has happened for vehicles)
peter1138
parents:
3741
diff
changeset
|
621 |
if (group == NULL || group->type != SGT_RESULT) return 0; |
3775
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3766
diff
changeset
|
622 |
return group->g.result.sprite - 0x42D; |
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3766
diff
changeset
|
623 |
} |
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3766
diff
changeset
|
624 |
|
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3766
diff
changeset
|
625 |
|
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3766
diff
changeset
|
626 |
SpriteID GetCustomStationGroundRelocation(const StationSpec *statspec, const Station *st, TileIndex tile) |
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3766
diff
changeset
|
627 |
{ |
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3766
diff
changeset
|
628 |
const SpriteGroup *group; |
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3766
diff
changeset
|
629 |
ResolverObject object; |
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3766
diff
changeset
|
630 |
|
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3766
diff
changeset
|
631 |
NewStationResolver(&object, statspec, st, tile); |
6674
64f4781b4653
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents:
6669
diff
changeset
|
632 |
object.callback_param1 = 1; // Indicate we are resolving the ground sprite |
3775
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3766
diff
changeset
|
633 |
|
6100 | 634 |
group = ResolveStation(&object); |
3775
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3766
diff
changeset
|
635 |
if (group == NULL || group->type != SGT_RESULT) return 0; |
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3766
diff
changeset
|
636 |
return group->g.result.sprite - 0x42D; |
2967
4208a82bf0d9
(svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents:
2963
diff
changeset
|
637 |
} |
3587 | 638 |
|
639 |
||
7823
cad4dec2b899
(svn r10690) -Codechange: use the enum that describes all callback IDs in favor of "just" using an untyped integer.
rubidium
parents:
7768
diff
changeset
|
640 |
uint16 GetStationCallback(CallbackID callback, uint32 param1, uint32 param2, const StationSpec *statspec, const Station *st, TileIndex tile) |
3752
a7cdd7c0c928
(svn r4740) - Newstations: add function to evaluate station callbacks
peter1138
parents:
3751
diff
changeset
|
641 |
{ |
a7cdd7c0c928
(svn r4740) - Newstations: add function to evaluate station callbacks
peter1138
parents:
3751
diff
changeset
|
642 |
const SpriteGroup *group; |
a7cdd7c0c928
(svn r4740) - Newstations: add function to evaluate station callbacks
peter1138
parents:
3751
diff
changeset
|
643 |
ResolverObject object; |
a7cdd7c0c928
(svn r4740) - Newstations: add function to evaluate station callbacks
peter1138
parents:
3751
diff
changeset
|
644 |
|
a7cdd7c0c928
(svn r4740) - Newstations: add function to evaluate station callbacks
peter1138
parents:
3751
diff
changeset
|
645 |
NewStationResolver(&object, statspec, st, tile); |
a7cdd7c0c928
(svn r4740) - Newstations: add function to evaluate station callbacks
peter1138
parents:
3751
diff
changeset
|
646 |
|
a7cdd7c0c928
(svn r4740) - Newstations: add function to evaluate station callbacks
peter1138
parents:
3751
diff
changeset
|
647 |
object.callback = callback; |
a7cdd7c0c928
(svn r4740) - Newstations: add function to evaluate station callbacks
peter1138
parents:
3751
diff
changeset
|
648 |
object.callback_param1 = param1; |
a7cdd7c0c928
(svn r4740) - Newstations: add function to evaluate station callbacks
peter1138
parents:
3751
diff
changeset
|
649 |
object.callback_param2 = param2; |
a7cdd7c0c928
(svn r4740) - Newstations: add function to evaluate station callbacks
peter1138
parents:
3751
diff
changeset
|
650 |
|
6100 | 651 |
group = ResolveStation(&object); |
3752
a7cdd7c0c928
(svn r4740) - Newstations: add function to evaluate station callbacks
peter1138
parents:
3751
diff
changeset
|
652 |
if (group == NULL || group->type != SGT_CALLBACK) return CALLBACK_FAILED; |
a7cdd7c0c928
(svn r4740) - Newstations: add function to evaluate station callbacks
peter1138
parents:
3751
diff
changeset
|
653 |
return group->g.callback.result; |
a7cdd7c0c928
(svn r4740) - Newstations: add function to evaluate station callbacks
peter1138
parents:
3751
diff
changeset
|
654 |
} |
a7cdd7c0c928
(svn r4740) - Newstations: add function to evaluate station callbacks
peter1138
parents:
3751
diff
changeset
|
655 |
|
a7cdd7c0c928
(svn r4740) - Newstations: add function to evaluate station callbacks
peter1138
parents:
3751
diff
changeset
|
656 |
|
3587 | 657 |
/** |
658 |
* Allocate a StationSpec to a Station. This is called once per build operation. |
|
6977
67b989528f3d
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6956
diff
changeset
|
659 |
* @param statspec StationSpec to allocate. |
3587 | 660 |
* @param st Station to allocate it to. |
661 |
* @param exec Whether to actually allocate the spec. |
|
662 |
* @return Index within the Station's spec list, or -1 if the allocation failed. |
|
663 |
*/ |
|
3676
48444d881fbe
(svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents:
3668
diff
changeset
|
664 |
int AllocateSpecToStation(const StationSpec *statspec, Station *st, bool exec) |
3587 | 665 |
{ |
666 |
uint i; |
|
667 |
||
10323
57d8fd25473e
(svn r12864) [0.6] -Backport from trunk r12859, r12857, r12855, r12845, r12844:
rubidium
parents:
9191
diff
changeset
|
668 |
if (statspec == NULL || st == NULL) return 0; |
3587 | 669 |
|
670 |
/* Check if this spec has already been allocated */ |
|
3786
73784d02aa69
(svn r4782) - Newstations: fix issue with saving/loading games with newstations on big endian architectures.
peter1138
parents:
3780
diff
changeset
|
671 |
for (i = 1; i < st->num_specs && i < MAX_SPECLIST; i++) { |
3676
48444d881fbe
(svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents:
3668
diff
changeset
|
672 |
if (st->speclist[i].spec == statspec) return i; |
3587 | 673 |
} |
674 |
||
3786
73784d02aa69
(svn r4782) - Newstations: fix issue with saving/loading games with newstations on big endian architectures.
peter1138
parents:
3780
diff
changeset
|
675 |
for (i = 1; i < st->num_specs && i < MAX_SPECLIST; i++) { |
3587 | 676 |
if (st->speclist[i].spec == NULL && st->speclist[i].grfid == 0) break; |
677 |
} |
|
678 |
||
3786
73784d02aa69
(svn r4782) - Newstations: fix issue with saving/loading games with newstations on big endian architectures.
peter1138
parents:
3780
diff
changeset
|
679 |
if (i == MAX_SPECLIST) return -1; |
3587 | 680 |
|
3730
1aca9dabaeea
(svn r4707) - NewGRF: minor code duffage; return early and less indentation.
peter1138
parents:
3676
diff
changeset
|
681 |
if (exec) { |
1aca9dabaeea
(svn r4707) - NewGRF: minor code duffage; return early and less indentation.
peter1138
parents:
3676
diff
changeset
|
682 |
if (i >= st->num_specs) { |
1aca9dabaeea
(svn r4707) - NewGRF: minor code duffage; return early and less indentation.
peter1138
parents:
3676
diff
changeset
|
683 |
st->num_specs = i + 1; |
5860
7fdc9b423ba1
(svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents:
5838
diff
changeset
|
684 |
st->speclist = ReallocT(st->speclist, st->num_specs); |
3730
1aca9dabaeea
(svn r4707) - NewGRF: minor code duffage; return early and less indentation.
peter1138
parents:
3676
diff
changeset
|
685 |
|
1aca9dabaeea
(svn r4707) - NewGRF: minor code duffage; return early and less indentation.
peter1138
parents:
3676
diff
changeset
|
686 |
if (st->num_specs == 2) { |
1aca9dabaeea
(svn r4707) - NewGRF: minor code duffage; return early and less indentation.
peter1138
parents:
3676
diff
changeset
|
687 |
/* Initial allocation */ |
1aca9dabaeea
(svn r4707) - NewGRF: minor code duffage; return early and less indentation.
peter1138
parents:
3676
diff
changeset
|
688 |
st->speclist[0].spec = NULL; |
1aca9dabaeea
(svn r4707) - NewGRF: minor code duffage; return early and less indentation.
peter1138
parents:
3676
diff
changeset
|
689 |
st->speclist[0].grfid = 0; |
1aca9dabaeea
(svn r4707) - NewGRF: minor code duffage; return early and less indentation.
peter1138
parents:
3676
diff
changeset
|
690 |
st->speclist[0].localidx = 0; |
3587 | 691 |
} |
3730
1aca9dabaeea
(svn r4707) - NewGRF: minor code duffage; return early and less indentation.
peter1138
parents:
3676
diff
changeset
|
692 |
} |
3587 | 693 |
|
3730
1aca9dabaeea
(svn r4707) - NewGRF: minor code duffage; return early and less indentation.
peter1138
parents:
3676
diff
changeset
|
694 |
st->speclist[i].spec = statspec; |
6947
c21859ab4493
(svn r9601) -Codechange: Store grf file reference in station spec, not just GRF ID
peter1138
parents:
6683
diff
changeset
|
695 |
st->speclist[i].grfid = statspec->grffile->grfid; |
3730
1aca9dabaeea
(svn r4707) - NewGRF: minor code duffage; return early and less indentation.
peter1138
parents:
3676
diff
changeset
|
696 |
st->speclist[i].localidx = statspec->localidx; |
3587 | 697 |
} |
698 |
||
3730
1aca9dabaeea
(svn r4707) - NewGRF: minor code duffage; return early and less indentation.
peter1138
parents:
3676
diff
changeset
|
699 |
return i; |
3587 | 700 |
} |
701 |
||
702 |
||
703 |
/** Deallocate a StationSpec from a Station. Called when removing a single station tile. |
|
704 |
* @param st Station to work with. |
|
705 |
* @param specindex Index of the custom station within the Station's spec list. |
|
706 |
* @return Indicates whether the StationSpec was deallocated. |
|
707 |
*/ |
|
4190
24d5420b6242
(svn r5632) Replace a boolean variable in DeallocateSpecFromStation() by a return
tron
parents:
4182
diff
changeset
|
708 |
void DeallocateSpecFromStation(Station* st, byte specindex) |
3587 | 709 |
{ |
710 |
/* specindex of 0 (default) is never freeable */ |
|
4190
24d5420b6242
(svn r5632) Replace a boolean variable in DeallocateSpecFromStation() by a return
tron
parents:
4182
diff
changeset
|
711 |
if (specindex == 0) return; |
3587 | 712 |
|
713 |
/* Check all tiles over the station to check if the specindex is still in use */ |
|
714 |
BEGIN_TILE_LOOP(tile, st->trainst_w, st->trainst_h, st->train_tile) { |
|
715 |
if (IsTileType(tile, MP_STATION) && GetStationIndex(tile) == st->index && IsRailwayStation(tile) && GetCustomStationSpecIndex(tile) == specindex) { |
|
4190
24d5420b6242
(svn r5632) Replace a boolean variable in DeallocateSpecFromStation() by a return
tron
parents:
4182
diff
changeset
|
716 |
return; |
3587 | 717 |
} |
718 |
} END_TILE_LOOP(tile, st->trainst_w, st->trainst_h, st->train_tile) |
|
719 |
||
4190
24d5420b6242
(svn r5632) Replace a boolean variable in DeallocateSpecFromStation() by a return
tron
parents:
4182
diff
changeset
|
720 |
/* This specindex is no longer in use, so deallocate it */ |
24d5420b6242
(svn r5632) Replace a boolean variable in DeallocateSpecFromStation() by a return
tron
parents:
4182
diff
changeset
|
721 |
st->speclist[specindex].spec = NULL; |
24d5420b6242
(svn r5632) Replace a boolean variable in DeallocateSpecFromStation() by a return
tron
parents:
4182
diff
changeset
|
722 |
st->speclist[specindex].grfid = 0; |
24d5420b6242
(svn r5632) Replace a boolean variable in DeallocateSpecFromStation() by a return
tron
parents:
4182
diff
changeset
|
723 |
st->speclist[specindex].localidx = 0; |
3587 | 724 |
|
4190
24d5420b6242
(svn r5632) Replace a boolean variable in DeallocateSpecFromStation() by a return
tron
parents:
4182
diff
changeset
|
725 |
/* If this was the highest spec index, reallocate */ |
24d5420b6242
(svn r5632) Replace a boolean variable in DeallocateSpecFromStation() by a return
tron
parents:
4182
diff
changeset
|
726 |
if (specindex == st->num_specs - 1) { |
9191
ae14770c829a
(svn r12368) -Codechange: use explicit body for loops and conditions and remove -Wno-empty-body from the configure script
smatz
parents:
9112
diff
changeset
|
727 |
for (; st->speclist[st->num_specs - 1].grfid == 0 && st->num_specs > 1; st->num_specs--) {} |
3587 | 728 |
|
4190
24d5420b6242
(svn r5632) Replace a boolean variable in DeallocateSpecFromStation() by a return
tron
parents:
4182
diff
changeset
|
729 |
if (st->num_specs > 1) { |
5860
7fdc9b423ba1
(svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents:
5838
diff
changeset
|
730 |
st->speclist = ReallocT(st->speclist, st->num_specs); |
4190
24d5420b6242
(svn r5632) Replace a boolean variable in DeallocateSpecFromStation() by a return
tron
parents:
4182
diff
changeset
|
731 |
} else { |
24d5420b6242
(svn r5632) Replace a boolean variable in DeallocateSpecFromStation() by a return
tron
parents:
4182
diff
changeset
|
732 |
free(st->speclist); |
24d5420b6242
(svn r5632) Replace a boolean variable in DeallocateSpecFromStation() by a return
tron
parents:
4182
diff
changeset
|
733 |
st->num_specs = 0; |
24d5420b6242
(svn r5632) Replace a boolean variable in DeallocateSpecFromStation() by a return
tron
parents:
4182
diff
changeset
|
734 |
st->speclist = NULL; |
3587 | 735 |
} |
736 |
} |
|
737 |
} |
|
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:
3758
diff
changeset
|
738 |
|
ebcaf412fb3a
(svn r4755) - Newstations: add a gui station tile drawing routine and use it in place of the existing one for waypoints.
peter1138
parents:
3758
diff
changeset
|
739 |
/** Draw representation of a station tile for GUI purposes. |
6977
67b989528f3d
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6956
diff
changeset
|
740 |
* @param x Position x of image. |
67b989528f3d
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6956
diff
changeset
|
741 |
* @param y Position y of image. |
67b989528f3d
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6956
diff
changeset
|
742 |
* @param axis Axis. |
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:
3758
diff
changeset
|
743 |
* @param railtype Rail type. |
ebcaf412fb3a
(svn r4755) - Newstations: add a gui station tile drawing routine and use it in place of the existing one for waypoints.
peter1138
parents:
3758
diff
changeset
|
744 |
* @param sclass, station Type of station. |
6977
67b989528f3d
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6956
diff
changeset
|
745 |
* @param station station ID |
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:
3758
diff
changeset
|
746 |
* @return True if the tile was drawn (allows for fallback to default graphic) |
ebcaf412fb3a
(svn r4755) - Newstations: add a gui station tile drawing routine and use it in place of the existing one for waypoints.
peter1138
parents:
3758
diff
changeset
|
747 |
*/ |
ebcaf412fb3a
(svn r4755) - Newstations: add a gui station tile drawing routine and use it in place of the existing one for waypoints.
peter1138
parents:
3758
diff
changeset
|
748 |
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:
3758
diff
changeset
|
749 |
{ |
ebcaf412fb3a
(svn r4755) - Newstations: add a gui station tile drawing routine and use it in place of the existing one for waypoints.
peter1138
parents:
3758
diff
changeset
|
750 |
const StationSpec *statspec; |
ebcaf412fb3a
(svn r4755) - Newstations: add a gui station tile drawing routine and use it in place of the existing one for waypoints.
peter1138
parents:
3758
diff
changeset
|
751 |
const DrawTileSprites *sprites; |
ebcaf412fb3a
(svn r4755) - Newstations: add a gui station tile drawing routine and use it in place of the existing one for waypoints.
peter1138
parents:
3758
diff
changeset
|
752 |
const DrawTileSeqStruct *seq; |
ebcaf412fb3a
(svn r4755) - Newstations: add a gui station tile drawing routine and use it in place of the existing one for waypoints.
peter1138
parents:
3758
diff
changeset
|
753 |
const RailtypeInfo *rti = GetRailTypeInfo(railtype); |
ebcaf412fb3a
(svn r4755) - Newstations: add a gui station tile drawing routine and use it in place of the existing one for waypoints.
peter1138
parents:
3758
diff
changeset
|
754 |
SpriteID relocation; |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5860
diff
changeset
|
755 |
SpriteID image; |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5860
diff
changeset
|
756 |
SpriteID pal = PLAYER_SPRITE_COLOR(_local_player); |
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:
3758
diff
changeset
|
757 |
uint tile = 2; |
ebcaf412fb3a
(svn r4755) - Newstations: add a gui station tile drawing routine and use it in place of the existing one for waypoints.
peter1138
parents:
3758
diff
changeset
|
758 |
|
ebcaf412fb3a
(svn r4755) - Newstations: add a gui station tile drawing routine and use it in place of the existing one for waypoints.
peter1138
parents:
3758
diff
changeset
|
759 |
statspec = GetCustomStationSpec(sclass, 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:
3758
diff
changeset
|
760 |
if (statspec == NULL) return false; |
ebcaf412fb3a
(svn r4755) - Newstations: add a gui station tile drawing routine and use it in place of the existing one for waypoints.
peter1138
parents:
3758
diff
changeset
|
761 |
|
ebcaf412fb3a
(svn r4755) - Newstations: add a gui station tile drawing routine and use it in place of the existing one for waypoints.
peter1138
parents:
3758
diff
changeset
|
762 |
relocation = GetCustomStationRelocation(statspec, NULL, INVALID_TILE); |
ebcaf412fb3a
(svn r4755) - Newstations: add a gui station tile drawing routine and use it in place of the existing one for waypoints.
peter1138
parents:
3758
diff
changeset
|
763 |
|
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8418
diff
changeset
|
764 |
if (HasBit(statspec->callbackmask, CBM_STATION_SPRITE_LAYOUT)) { |
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:
3758
diff
changeset
|
765 |
uint16 callback = GetStationCallback(CBID_STATION_SPRITE_LAYOUT, 0x2110000, 0, statspec, NULL, INVALID_TILE); |
ebcaf412fb3a
(svn r4755) - Newstations: add a gui station tile drawing routine and use it in place of the existing one for waypoints.
peter1138
parents:
3758
diff
changeset
|
766 |
if (callback != CALLBACK_FAILED) tile = callback; |
ebcaf412fb3a
(svn r4755) - Newstations: add a gui station tile drawing routine and use it in place of the existing one for waypoints.
peter1138
parents:
3758
diff
changeset
|
767 |
} |
ebcaf412fb3a
(svn r4755) - Newstations: add a gui station tile drawing routine and use it in place of the existing one for waypoints.
peter1138
parents:
3758
diff
changeset
|
768 |
|
ebcaf412fb3a
(svn r4755) - Newstations: add a gui station tile drawing routine and use it in place of the existing one for waypoints.
peter1138
parents:
3758
diff
changeset
|
769 |
if (statspec->renderdata == NULL) { |
7768
2060e8d65a72
(svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents:
7726
diff
changeset
|
770 |
sprites = GetStationTileLayout(STATION_RAIL, tile + axis); |
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:
3758
diff
changeset
|
771 |
} else { |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
772 |
sprites = &statspec->renderdata[(tile < statspec->tiles) ? tile + axis : (uint)axis]; |
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:
3758
diff
changeset
|
773 |
} |
ebcaf412fb3a
(svn r4755) - Newstations: add a gui station tile drawing routine and use it in place of the existing one for waypoints.
peter1138
parents:
3758
diff
changeset
|
774 |
|
9067
88f2bc991236
(svn r12149) -Codechange: Merge 'ground_sprite' and 'ground_pal' of DrawTileSprites into one PalSpriteID
frosch
parents:
9066
diff
changeset
|
775 |
image = sprites->ground.sprite; |
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8418
diff
changeset
|
776 |
if (HasBit(image, SPRITE_MODIFIER_USE_OFFSET)) { |
3775
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3766
diff
changeset
|
777 |
image += GetCustomStationGroundRelocation(statspec, NULL, INVALID_TILE); |
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3766
diff
changeset
|
778 |
image += rti->custom_ground_offset; |
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3766
diff
changeset
|
779 |
} else { |
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3766
diff
changeset
|
780 |
image += rti->total_offset; |
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3766
diff
changeset
|
781 |
} |
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:
3758
diff
changeset
|
782 |
|
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5860
diff
changeset
|
783 |
DrawSprite(image, PAL_NONE, x, y); |
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:
3758
diff
changeset
|
784 |
|
ebcaf412fb3a
(svn r4755) - Newstations: add a gui station tile drawing routine and use it in place of the existing one for waypoints.
peter1138
parents:
3758
diff
changeset
|
785 |
foreach_draw_tile_seq(seq, sprites->seq) { |
ebcaf412fb3a
(svn r4755) - Newstations: add a gui station tile drawing routine and use it in place of the existing one for waypoints.
peter1138
parents:
3758
diff
changeset
|
786 |
Point pt; |
9066
29d5a0dfc329
(svn r12148) -Codechange: Merge 'image' and 'pal' of DrawTileSeqStruct into one PalSpriteID
frosch
parents:
8954
diff
changeset
|
787 |
image = seq->image.sprite; |
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8418
diff
changeset
|
788 |
if (HasBit(image, SPRITE_MODIFIER_USE_OFFSET)) { |
3775
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3766
diff
changeset
|
789 |
image += rti->total_offset; |
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3766
diff
changeset
|
790 |
} else { |
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3766
diff
changeset
|
791 |
image += relocation; |
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3766
diff
changeset
|
792 |
} |
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:
3758
diff
changeset
|
793 |
|
ebcaf412fb3a
(svn r4755) - Newstations: add a gui station tile drawing routine and use it in place of the existing one for waypoints.
peter1138
parents:
3758
diff
changeset
|
794 |
if ((byte)seq->delta_z != 0x80) { |
ebcaf412fb3a
(svn r4755) - Newstations: add a gui station tile drawing routine and use it in place of the existing one for waypoints.
peter1138
parents:
3758
diff
changeset
|
795 |
pt = RemapCoords(seq->delta_x, seq->delta_y, seq->delta_z); |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5860
diff
changeset
|
796 |
DrawSprite(image, pal, x + pt.x, y + pt.y); |
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:
3758
diff
changeset
|
797 |
} |
ebcaf412fb3a
(svn r4755) - Newstations: add a gui station tile drawing routine and use it in place of the existing one for waypoints.
peter1138
parents:
3758
diff
changeset
|
798 |
} |
ebcaf412fb3a
(svn r4755) - Newstations: add a gui station tile drawing routine and use it in place of the existing one for waypoints.
peter1138
parents:
3758
diff
changeset
|
799 |
|
ebcaf412fb3a
(svn r4755) - Newstations: add a gui station tile drawing routine and use it in place of the existing one for waypoints.
peter1138
parents:
3758
diff
changeset
|
800 |
return true; |
ebcaf412fb3a
(svn r4755) - Newstations: add a gui station tile drawing routine and use it in place of the existing one for waypoints.
peter1138
parents:
3758
diff
changeset
|
801 |
} |
ebcaf412fb3a
(svn r4755) - Newstations: add a gui station tile drawing routine and use it in place of the existing one for waypoints.
peter1138
parents:
3758
diff
changeset
|
802 |
|
4206
599a0c60e964
(svn r5690) Factor common code to reduce code duplication
tron
parents:
4205
diff
changeset
|
803 |
|
599a0c60e964
(svn r5690) Factor common code to reduce code duplication
tron
parents:
4205
diff
changeset
|
804 |
static const StationSpec* GetStationSpec(TileIndex t) |
599a0c60e964
(svn r5690) Factor common code to reduce code duplication
tron
parents:
4205
diff
changeset
|
805 |
{ |
599a0c60e964
(svn r5690) Factor common code to reduce code duplication
tron
parents:
4205
diff
changeset
|
806 |
const Station* st; |
599a0c60e964
(svn r5690) Factor common code to reduce code duplication
tron
parents:
4205
diff
changeset
|
807 |
uint specindex; |
599a0c60e964
(svn r5690) Factor common code to reduce code duplication
tron
parents:
4205
diff
changeset
|
808 |
|
599a0c60e964
(svn r5690) Factor common code to reduce code duplication
tron
parents:
4205
diff
changeset
|
809 |
if (!IsCustomStationSpecIndex(t)) return NULL; |
599a0c60e964
(svn r5690) Factor common code to reduce code duplication
tron
parents:
4205
diff
changeset
|
810 |
|
599a0c60e964
(svn r5690) Factor common code to reduce code duplication
tron
parents:
4205
diff
changeset
|
811 |
st = GetStationByTile(t); |
599a0c60e964
(svn r5690) Factor common code to reduce code duplication
tron
parents:
4205
diff
changeset
|
812 |
specindex = GetCustomStationSpecIndex(t); |
599a0c60e964
(svn r5690) Factor common code to reduce code duplication
tron
parents:
4205
diff
changeset
|
813 |
return specindex < st->num_specs ? st->speclist[specindex].spec : NULL; |
599a0c60e964
(svn r5690) Factor common code to reduce code duplication
tron
parents:
4205
diff
changeset
|
814 |
} |
599a0c60e964
(svn r5690) Factor common code to reduce code duplication
tron
parents:
4205
diff
changeset
|
815 |
|
599a0c60e964
(svn r5690) Factor common code to reduce code duplication
tron
parents:
4205
diff
changeset
|
816 |
|
3766
f0077e6b6f99
(svn r4758) - Newstations: add support for 'blocked' station tiles, which no train can pass.
peter1138
parents:
3765
diff
changeset
|
817 |
/* 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
|
818 |
* XXX This could be cached (during build) in the map array to save on all the dereferencing */ |
f0077e6b6f99
(svn r4758) - Newstations: add support for 'blocked' station tiles, which no train can pass.
peter1138
parents:
3765
diff
changeset
|
819 |
bool IsStationTileBlocked(TileIndex tile) |
f0077e6b6f99
(svn r4758) - Newstations: add support for 'blocked' station tiles, which no train can pass.
peter1138
parents:
3765
diff
changeset
|
820 |
{ |
4206
599a0c60e964
(svn r5690) Factor common code to reduce code duplication
tron
parents:
4205
diff
changeset
|
821 |
const StationSpec* statspec = GetStationSpec(tile); |
3766
f0077e6b6f99
(svn r4758) - Newstations: add support for 'blocked' station tiles, which no train can pass.
peter1138
parents:
3765
diff
changeset
|
822 |
|
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8418
diff
changeset
|
823 |
return statspec != NULL && HasBit(statspec->blocked, GetStationGfx(tile)); |
3766
f0077e6b6f99
(svn r4758) - Newstations: add support for 'blocked' station tiles, which no train can pass.
peter1138
parents:
3765
diff
changeset
|
824 |
} |
3789
bf75e48227de
(svn r4785) - Newstations: don't draw catenary on non-track tiles
glx
parents:
3787
diff
changeset
|
825 |
|
bf75e48227de
(svn r4785) - Newstations: don't draw catenary on non-track tiles
glx
parents:
3787
diff
changeset
|
826 |
/* Check if a rail station tile is electrifiable. |
bf75e48227de
(svn r4785) - Newstations: don't draw catenary on non-track tiles
glx
parents:
3787
diff
changeset
|
827 |
* XXX This could be cached (during build) in the map array to save on all the dereferencing */ |
bf75e48227de
(svn r4785) - Newstations: don't draw catenary on non-track tiles
glx
parents:
3787
diff
changeset
|
828 |
bool IsStationTileElectrifiable(TileIndex tile) |
bf75e48227de
(svn r4785) - Newstations: don't draw catenary on non-track tiles
glx
parents:
3787
diff
changeset
|
829 |
{ |
4206
599a0c60e964
(svn r5690) Factor common code to reduce code duplication
tron
parents:
4205
diff
changeset
|
830 |
const StationSpec* statspec = GetStationSpec(tile); |
3789
bf75e48227de
(svn r4785) - Newstations: don't draw catenary on non-track tiles
glx
parents:
3787
diff
changeset
|
831 |
|
4206
599a0c60e964
(svn r5690) Factor common code to reduce code duplication
tron
parents:
4205
diff
changeset
|
832 |
return |
599a0c60e964
(svn r5690) Factor common code to reduce code duplication
tron
parents:
4205
diff
changeset
|
833 |
statspec == NULL || |
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8418
diff
changeset
|
834 |
HasBit(statspec->pylons, GetStationGfx(tile)) || |
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8418
diff
changeset
|
835 |
!HasBit(statspec->wires, GetStationGfx(tile)); |
3789
bf75e48227de
(svn r4785) - Newstations: don't draw catenary on non-track tiles
glx
parents:
3787
diff
changeset
|
836 |
} |