annotate src/newgrf_station.cpp @ 14287:5b16d3caeef6 draft

(svn r18839) -Codechange: Detriplicate drawing of spritelayouts in the GUI.
author frosch <frosch@openttd.org>
date Sat, 16 Jan 2010 22:44:03 +0000
parents a899d4e5ee1a
children 9a47b3371031
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1 /* $Id$ */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2
12778
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12632
diff changeset
3 /*
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12632
diff changeset
4 * This file is part of OpenTTD.
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12632
diff changeset
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12632
diff changeset
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12632
diff changeset
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12632
diff changeset
8 */
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12632
diff changeset
9
6117
6def6ecb1bf7 (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 <belugas@openttd.org>
parents: 6113
diff changeset
10 /** @file newgrf_station.cpp Functions for dealing with station classes and custom stations. */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
11
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
12 #include "stdafx.h"
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
13 #include "variables.h"
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
14 #include "debug.h"
12228
240adc64d01a (svn r16643) -Codechange: replace GetStationByTile() by Station::GetByTile()
smatz <smatz@openttd.org>
parents: 12225
diff changeset
15 #include "station_base.h"
12475
c133b51890f4 (svn r16912) -Codechange: split waypoint.h in waypoint_base.h and waypoint_func.h
rubidium <rubidium@openttd.org>
parents: 12472
diff changeset
16 #include "waypoint_base.h"
12225
4f649aa97318 (svn r16640) -Codechange: move roadstop stuff to separate files
smatz <smatz@openttd.org>
parents: 12016
diff changeset
17 #include "roadstop_base.h"
13466
a6e569a5cc14 (svn r17976) -Codechange: Move CargoClass to cargotype.h and clean up including of newgrf_cargo.h
frosch <frosch@openttd.org>
parents: 13036
diff changeset
18 #include "newgrf_cargo.h"
6849
cbe1a12e652d (svn r10089) -Fix (r10040): Use GetTileZ instead of GetClearGround in GetTerrainType as
maedhros <maedhros@openttd.org>
parents: 6683
diff changeset
19 #include "newgrf_commons.h"
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
20 #include "newgrf_station.h"
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
21 #include "newgrf_spritegroup.h"
9018
9dcf32675eb5 (svn r12817) -Feature: the ability to play NewGRF sounds for industries and stations.
rubidium <rubidium@openttd.org>
parents: 9006
diff changeset
22 #include "newgrf_sound.h"
9726
06221034cf54 (svn r13851) -Fix (r9393): GetTownByTile() is only valid for houses and roads.
frosch <frosch@openttd.org>
parents: 9714
diff changeset
23 #include "town.h"
6354
4595b3acd03d (svn r9393) -Codechange: Use newgrf town resolver as station parent scope handler
peter1138 <peter1138@openttd.org>
parents: 6348
diff changeset
24 #include "newgrf_town.h"
8140
fb8a05d579da (svn r11702) -Codechange: move all date related stuff to date*.
rubidium <rubidium@openttd.org>
parents: 8130
diff changeset
25 #include "date_func.h"
10208
39cf8eebfda5 (svn r14422) -Codechange: also reflect the changes of r14421 in the filenames.
rubidium <rubidium@openttd.org>
parents: 10207
diff changeset
26 #include "company_func.h"
9005
5bb8efb6051a (svn r12800) -Codechange: move the animated tile related functions out of texteff.cpp (it isn't a text effect after all). Also remove a few more functions from functions.
rubidium <rubidium@openttd.org>
parents: 9004
diff changeset
27 #include "animated_tile_func.h"
9006
9bf1de259ada (svn r12801) -Codechange: remove the dependency of function.h in town_map.h
rubidium <rubidium@openttd.org>
parents: 9005
diff changeset
28 #include "functions.h"
9662
cf5657f9e445 (svn r13734) -Fix: NewGRF rail continuation would always mark a tunnel on the same axis as connected, even when the tunnel faces the wrong direction.
rubidium <rubidium@openttd.org>
parents: 9038
diff changeset
29 #include "tunnelbridge_map.h"
14258
a899d4e5ee1a (svn r18809) -Codechange/Cleanup: remove unneeded headers from some files, if a header require a header make it include that header
rubidium <rubidium@openttd.org>
parents: 14188
diff changeset
30 #include "newgrf.h"
a899d4e5ee1a (svn r18809) -Codechange/Cleanup: remove unneeded headers from some files, if a header require a header make it include that header
rubidium <rubidium@openttd.org>
parents: 14188
diff changeset
31 #include "core/random_func.hpp"
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
32
8264
2495310e220f (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium <rubidium@openttd.org>
parents: 8254
diff changeset
33 #include "table/strings.h"
2495310e220f (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium <rubidium@openttd.org>
parents: 8254
diff changeset
34
11091
c4c35a89bad7 (svn r15436) -Codechange: Return index of station spec within station class as a return parameter of GetCustomStationSpecByGrf(), as the index is already known. Saves on an extra loop and an extern...
peter1138 <peter1138@openttd.org>
parents: 11085
diff changeset
35 static StationClass _station_classes[STAT_CLASS_MAX];
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
36
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
37 enum {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
38 MAX_SPECLIST = 255,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
39 };
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
40
12462
4dd085f22d88 (svn r16896) -Codechange: make station spec allocation and station animation functions work for both stations and waypoints
rubidium <rubidium@openttd.org>
parents: 12454
diff changeset
41 enum TriggerArea {
4dd085f22d88 (svn r16896) -Codechange: make station spec allocation and station animation functions work for both stations and waypoints
rubidium <rubidium@openttd.org>
parents: 12454
diff changeset
42 TA_TILE,
4dd085f22d88 (svn r16896) -Codechange: make station spec allocation and station animation functions work for both stations and waypoints
rubidium <rubidium@openttd.org>
parents: 12454
diff changeset
43 TA_PLATFORM,
4dd085f22d88 (svn r16896) -Codechange: make station spec allocation and station animation functions work for both stations and waypoints
rubidium <rubidium@openttd.org>
parents: 12454
diff changeset
44 TA_WHOLE,
4dd085f22d88 (svn r16896) -Codechange: make station spec allocation and station animation functions work for both stations and waypoints
rubidium <rubidium@openttd.org>
parents: 12454
diff changeset
45 };
4dd085f22d88 (svn r16896) -Codechange: make station spec allocation and station animation functions work for both stations and waypoints
rubidium <rubidium@openttd.org>
parents: 12454
diff changeset
46
4dd085f22d88 (svn r16896) -Codechange: make station spec allocation and station animation functions work for both stations and waypoints
rubidium <rubidium@openttd.org>
parents: 12454
diff changeset
47 struct ETileArea : TileArea {
4dd085f22d88 (svn r16896) -Codechange: make station spec allocation and station animation functions work for both stations and waypoints
rubidium <rubidium@openttd.org>
parents: 12454
diff changeset
48 ETileArea(const BaseStation *st, TileIndex tile, TriggerArea ta)
4dd085f22d88 (svn r16896) -Codechange: make station spec allocation and station animation functions work for both stations and waypoints
rubidium <rubidium@openttd.org>
parents: 12454
diff changeset
49 {
4dd085f22d88 (svn r16896) -Codechange: make station spec allocation and station animation functions work for both stations and waypoints
rubidium <rubidium@openttd.org>
parents: 12454
diff changeset
50 switch (ta) {
4dd085f22d88 (svn r16896) -Codechange: make station spec allocation and station animation functions work for both stations and waypoints
rubidium <rubidium@openttd.org>
parents: 12454
diff changeset
51 default: NOT_REACHED();
4dd085f22d88 (svn r16896) -Codechange: make station spec allocation and station animation functions work for both stations and waypoints
rubidium <rubidium@openttd.org>
parents: 12454
diff changeset
52
4dd085f22d88 (svn r16896) -Codechange: make station spec allocation and station animation functions work for both stations and waypoints
rubidium <rubidium@openttd.org>
parents: 12454
diff changeset
53 case TA_TILE:
4dd085f22d88 (svn r16896) -Codechange: make station spec allocation and station animation functions work for both stations and waypoints
rubidium <rubidium@openttd.org>
parents: 12454
diff changeset
54 this->tile = tile;
4dd085f22d88 (svn r16896) -Codechange: make station spec allocation and station animation functions work for both stations and waypoints
rubidium <rubidium@openttd.org>
parents: 12454
diff changeset
55 this->w = 1;
4dd085f22d88 (svn r16896) -Codechange: make station spec allocation and station animation functions work for both stations and waypoints
rubidium <rubidium@openttd.org>
parents: 12454
diff changeset
56 this->h = 1;
4dd085f22d88 (svn r16896) -Codechange: make station spec allocation and station animation functions work for both stations and waypoints
rubidium <rubidium@openttd.org>
parents: 12454
diff changeset
57 break;
4dd085f22d88 (svn r16896) -Codechange: make station spec allocation and station animation functions work for both stations and waypoints
rubidium <rubidium@openttd.org>
parents: 12454
diff changeset
58
4dd085f22d88 (svn r16896) -Codechange: make station spec allocation and station animation functions work for both stations and waypoints
rubidium <rubidium@openttd.org>
parents: 12454
diff changeset
59 case TA_PLATFORM: {
4dd085f22d88 (svn r16896) -Codechange: make station spec allocation and station animation functions work for both stations and waypoints
rubidium <rubidium@openttd.org>
parents: 12454
diff changeset
60 TileIndex start, end;
4dd085f22d88 (svn r16896) -Codechange: make station spec allocation and station animation functions work for both stations and waypoints
rubidium <rubidium@openttd.org>
parents: 12454
diff changeset
61 Axis axis = GetRailStationAxis(tile);
4dd085f22d88 (svn r16896) -Codechange: make station spec allocation and station animation functions work for both stations and waypoints
rubidium <rubidium@openttd.org>
parents: 12454
diff changeset
62 TileIndexDiff delta = TileOffsByDiagDir(AxisToDiagDir(axis));
4dd085f22d88 (svn r16896) -Codechange: make station spec allocation and station animation functions work for both stations and waypoints
rubidium <rubidium@openttd.org>
parents: 12454
diff changeset
63
12502
9472b49c61a1 (svn r16939) -Codechange: s/RailwayStation/RailStation/ to unify the way it's written.
rubidium <rubidium@openttd.org>
parents: 12501
diff changeset
64 for (end = tile; IsRailStationTile(end + delta) && IsCompatibleTrainStationTile(tile, end + delta); end += delta) { /* Nothing */ }
9472b49c61a1 (svn r16939) -Codechange: s/RailwayStation/RailStation/ to unify the way it's written.
rubidium <rubidium@openttd.org>
parents: 12501
diff changeset
65 for (start = tile; IsRailStationTile(start - delta) && IsCompatibleTrainStationTile(tile, start - delta); start -= delta) { /* Nothing */ }
12462
4dd085f22d88 (svn r16896) -Codechange: make station spec allocation and station animation functions work for both stations and waypoints
rubidium <rubidium@openttd.org>
parents: 12454
diff changeset
66
4dd085f22d88 (svn r16896) -Codechange: make station spec allocation and station animation functions work for both stations and waypoints
rubidium <rubidium@openttd.org>
parents: 12454
diff changeset
67 this->tile = start;
4dd085f22d88 (svn r16896) -Codechange: make station spec allocation and station animation functions work for both stations and waypoints
rubidium <rubidium@openttd.org>
parents: 12454
diff changeset
68 this->w = TileX(end) - TileX(start) + 1;
4dd085f22d88 (svn r16896) -Codechange: make station spec allocation and station animation functions work for both stations and waypoints
rubidium <rubidium@openttd.org>
parents: 12454
diff changeset
69 this->h = TileY(end) - TileY(start) + 1;
4dd085f22d88 (svn r16896) -Codechange: make station spec allocation and station animation functions work for both stations and waypoints
rubidium <rubidium@openttd.org>
parents: 12454
diff changeset
70 break;
4dd085f22d88 (svn r16896) -Codechange: make station spec allocation and station animation functions work for both stations and waypoints
rubidium <rubidium@openttd.org>
parents: 12454
diff changeset
71 }
4dd085f22d88 (svn r16896) -Codechange: make station spec allocation and station animation functions work for both stations and waypoints
rubidium <rubidium@openttd.org>
parents: 12454
diff changeset
72
4dd085f22d88 (svn r16896) -Codechange: make station spec allocation and station animation functions work for both stations and waypoints
rubidium <rubidium@openttd.org>
parents: 12454
diff changeset
73 case TA_WHOLE:
4dd085f22d88 (svn r16896) -Codechange: make station spec allocation and station animation functions work for both stations and waypoints
rubidium <rubidium@openttd.org>
parents: 12454
diff changeset
74 st->GetTileArea(this, Station::IsExpected(st) ? STATION_RAIL : STATION_WAYPOINT);
4dd085f22d88 (svn r16896) -Codechange: make station spec allocation and station animation functions work for both stations and waypoints
rubidium <rubidium@openttd.org>
parents: 12454
diff changeset
75 break;
4dd085f22d88 (svn r16896) -Codechange: make station spec allocation and station animation functions work for both stations and waypoints
rubidium <rubidium@openttd.org>
parents: 12454
diff changeset
76 }
4dd085f22d88 (svn r16896) -Codechange: make station spec allocation and station animation functions work for both stations and waypoints
rubidium <rubidium@openttd.org>
parents: 12454
diff changeset
77 }
4dd085f22d88 (svn r16896) -Codechange: make station spec allocation and station animation functions work for both stations and waypoints
rubidium <rubidium@openttd.org>
parents: 12454
diff changeset
78 };
4dd085f22d88 (svn r16896) -Codechange: make station spec allocation and station animation functions work for both stations and waypoints
rubidium <rubidium@openttd.org>
parents: 12454
diff changeset
79
4dd085f22d88 (svn r16896) -Codechange: make station spec allocation and station animation functions work for both stations and waypoints
rubidium <rubidium@openttd.org>
parents: 12454
diff changeset
80
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
81 /**
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
82 * Reset station classes to their default state.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
83 * This includes initialising the Default and Waypoint classes with an empty
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
84 * entry, for standard stations and waypoints.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
85 */
6247
57363e064324 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents: 6148
diff changeset
86 void ResetStationClasses()
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
87 {
5587
c44c070c5032 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium <rubidium@openttd.org>
parents: 5584
diff changeset
88 for (StationClassID i = STAT_CLASS_BEGIN; i < STAT_CLASS_MAX; i++) {
8316
a3f30e43d561 (svn r11881) -Cleanup: Code style for global variables.
peter1138 <peter1138@openttd.org>
parents: 8295
diff changeset
89 _station_classes[i].id = 0;
a3f30e43d561 (svn r11881) -Cleanup: Code style for global variables.
peter1138 <peter1138@openttd.org>
parents: 8295
diff changeset
90 _station_classes[i].name = STR_EMPTY;
a3f30e43d561 (svn r11881) -Cleanup: Code style for global variables.
peter1138 <peter1138@openttd.org>
parents: 8295
diff changeset
91 _station_classes[i].stations = 0;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
92
8316
a3f30e43d561 (svn r11881) -Cleanup: Code style for global variables.
peter1138 <peter1138@openttd.org>
parents: 8295
diff changeset
93 free(_station_classes[i].spec);
a3f30e43d561 (svn r11881) -Cleanup: Code style for global variables.
peter1138 <peter1138@openttd.org>
parents: 8295
diff changeset
94 _station_classes[i].spec = NULL;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
95 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
96
6348
bcf98ba27bbf (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents: 6343
diff changeset
97 /* Set up initial data */
8316
a3f30e43d561 (svn r11881) -Cleanup: Code style for global variables.
peter1138 <peter1138@openttd.org>
parents: 8295
diff changeset
98 _station_classes[0].id = 'DFLT';
12632
e41943276802 (svn r17075) -Codechange: rename ~750 strings to be more uniform with their relatives
rubidium <rubidium@openttd.org>
parents: 12607
diff changeset
99 _station_classes[0].name = STR_STATION_CLASS_DFLT;
8316
a3f30e43d561 (svn r11881) -Cleanup: Code style for global variables.
peter1138 <peter1138@openttd.org>
parents: 8295
diff changeset
100 _station_classes[0].stations = 1;
a3f30e43d561 (svn r11881) -Cleanup: Code style for global variables.
peter1138 <peter1138@openttd.org>
parents: 8295
diff changeset
101 _station_classes[0].spec = MallocT<StationSpec*>(1);
a3f30e43d561 (svn r11881) -Cleanup: Code style for global variables.
peter1138 <peter1138@openttd.org>
parents: 8295
diff changeset
102 _station_classes[0].spec[0] = NULL;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
103
8316
a3f30e43d561 (svn r11881) -Cleanup: Code style for global variables.
peter1138 <peter1138@openttd.org>
parents: 8295
diff changeset
104 _station_classes[1].id = 'WAYP';
12632
e41943276802 (svn r17075) -Codechange: rename ~750 strings to be more uniform with their relatives
rubidium <rubidium@openttd.org>
parents: 12607
diff changeset
105 _station_classes[1].name = STR_STATION_CLASS_WAYP;
8316
a3f30e43d561 (svn r11881) -Cleanup: Code style for global variables.
peter1138 <peter1138@openttd.org>
parents: 8295
diff changeset
106 _station_classes[1].stations = 1;
a3f30e43d561 (svn r11881) -Cleanup: Code style for global variables.
peter1138 <peter1138@openttd.org>
parents: 8295
diff changeset
107 _station_classes[1].spec = MallocT<StationSpec*>(1);
a3f30e43d561 (svn r11881) -Cleanup: Code style for global variables.
peter1138 <peter1138@openttd.org>
parents: 8295
diff changeset
108 _station_classes[1].spec[0] = NULL;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
109 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
110
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
111 /**
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
112 * Allocate a station class for the given class id.
6481
85a1a79387a2 (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas <belugas@openttd.org>
parents: 6460
diff changeset
113 * @param cls A 32 bit value identifying the class.
8316
a3f30e43d561 (svn r11881) -Cleanup: Code style for global variables.
peter1138 <peter1138@openttd.org>
parents: 8295
diff changeset
114 * @return Index into _station_classes of allocated class.
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
115 */
5587
c44c070c5032 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium <rubidium@openttd.org>
parents: 5584
diff changeset
116 StationClassID AllocateStationClass(uint32 cls)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
117 {
5587
c44c070c5032 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium <rubidium@openttd.org>
parents: 5584
diff changeset
118 for (StationClassID i = STAT_CLASS_BEGIN; i < STAT_CLASS_MAX; i++) {
8316
a3f30e43d561 (svn r11881) -Cleanup: Code style for global variables.
peter1138 <peter1138@openttd.org>
parents: 8295
diff changeset
119 if (_station_classes[i].id == cls) {
6348
bcf98ba27bbf (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents: 6343
diff changeset
120 /* ClassID is already allocated, so reuse it. */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
121 return i;
8316
a3f30e43d561 (svn r11881) -Cleanup: Code style for global variables.
peter1138 <peter1138@openttd.org>
parents: 8295
diff changeset
122 } else if (_station_classes[i].id == 0) {
6348
bcf98ba27bbf (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents: 6343
diff changeset
123 /* This class is empty, so allocate it to the ClassID. */
8316
a3f30e43d561 (svn r11881) -Cleanup: Code style for global variables.
peter1138 <peter1138@openttd.org>
parents: 8295
diff changeset
124 _station_classes[i].id = cls;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
125 return i;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
126 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
127 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
128
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
129 grfmsg(2, "StationClassAllocate: already allocated %d classes, using default", STAT_CLASS_MAX);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
130 return STAT_CLASS_DFLT;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
131 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
132
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
133 /** Set the name of a custom station class */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
134 void SetStationClassName(StationClassID sclass, StringID name)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
135 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
136 assert(sclass < STAT_CLASS_MAX);
8316
a3f30e43d561 (svn r11881) -Cleanup: Code style for global variables.
peter1138 <peter1138@openttd.org>
parents: 8295
diff changeset
137 _station_classes[sclass].name = name;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
138 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
139
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
140 /** Retrieve the name of a custom station class */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
141 StringID GetStationClassName(StationClassID sclass)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
142 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
143 assert(sclass < STAT_CLASS_MAX);
8316
a3f30e43d561 (svn r11881) -Cleanup: Code style for global variables.
peter1138 <peter1138@openttd.org>
parents: 8295
diff changeset
144 return _station_classes[sclass].name;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
145 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
146
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
147 /**
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
148 * Get the number of station classes in use.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
149 * @return Number of station classes.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
150 */
6247
57363e064324 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents: 6148
diff changeset
151 uint GetNumStationClasses()
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
152 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
153 uint i;
8695
9ee0730039f4 (svn r12368) -Codechange: use explicit body for loops and conditions and remove -Wno-empty-body from the configure script
smatz <smatz@openttd.org>
parents: 8616
diff changeset
154 for (i = 0; i < STAT_CLASS_MAX && _station_classes[i].id != 0; i++) {}
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
155 return i;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
156 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
157
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
158 /**
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
159 * Return the number of stations for the given station class.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
160 * @param sclass Index of the station class.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
161 * @return Number of stations in the class.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
162 */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
163 uint GetNumCustomStations(StationClassID sclass)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
164 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
165 assert(sclass < STAT_CLASS_MAX);
8316
a3f30e43d561 (svn r11881) -Cleanup: Code style for global variables.
peter1138 <peter1138@openttd.org>
parents: 8295
diff changeset
166 return _station_classes[sclass].stations;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
167 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
168
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
169 /**
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
170 * Tie a station spec to its station class.
6481
85a1a79387a2 (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas <belugas@openttd.org>
parents: 6460
diff changeset
171 * @param statspec The station spec.
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
172 */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
173 void SetCustomStationSpec(StationSpec *statspec)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
174 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
175 StationClass *station_class;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
176 int i;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
177
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
178 /* If the station has already been allocated, don't reallocate it. */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
179 if (statspec->allocated) return;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
180
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
181 assert(statspec->sclass < STAT_CLASS_MAX);
8316
a3f30e43d561 (svn r11881) -Cleanup: Code style for global variables.
peter1138 <peter1138@openttd.org>
parents: 8295
diff changeset
182 station_class = &_station_classes[statspec->sclass];
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
183
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
184 i = station_class->stations++;
5609
358c07fb3212 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr <KUDr@openttd.org>
parents: 5587
diff changeset
185 station_class->spec = ReallocT(station_class->spec, station_class->stations);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
186
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
187 station_class->spec[i] = statspec;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
188 statspec->allocated = true;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
189 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
190
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
191 /**
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
192 * Retrieve a station spec from a class.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
193 * @param sclass Index of the station class.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
194 * @param station The station index with the class.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
195 * @return The station spec.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
196 */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
197 const StationSpec *GetCustomStationSpec(StationClassID sclass, uint station)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
198 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
199 assert(sclass < STAT_CLASS_MAX);
8316
a3f30e43d561 (svn r11881) -Cleanup: Code style for global variables.
peter1138 <peter1138@openttd.org>
parents: 8295
diff changeset
200 if (station < _station_classes[sclass].stations)
a3f30e43d561 (svn r11881) -Cleanup: Code style for global variables.
peter1138 <peter1138@openttd.org>
parents: 8295
diff changeset
201 return _station_classes[sclass].spec[station];
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
202
6348
bcf98ba27bbf (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents: 6343
diff changeset
203 /* If the custom station isn't defined any more, then the GRF file
bcf98ba27bbf (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents: 6343
diff changeset
204 * probably was not loaded. */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
205 return NULL;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
206 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
207
11091
c4c35a89bad7 (svn r15436) -Codechange: Return index of station spec within station class as a return parameter of GetCustomStationSpecByGrf(), as the index is already known. Saves on an extra loop and an extern...
peter1138 <peter1138@openttd.org>
parents: 11085
diff changeset
208 /**
c4c35a89bad7 (svn r15436) -Codechange: Return index of station spec within station class as a return parameter of GetCustomStationSpecByGrf(), as the index is already known. Saves on an extra loop and an extern...
peter1138 <peter1138@openttd.org>
parents: 11085
diff changeset
209 * Retrieve a station spec by GRF location.
c4c35a89bad7 (svn r15436) -Codechange: Return index of station spec within station class as a return parameter of GetCustomStationSpecByGrf(), as the index is already known. Saves on an extra loop and an extern...
peter1138 <peter1138@openttd.org>
parents: 11085
diff changeset
210 * @param grfid GRF ID of station spec.
c4c35a89bad7 (svn r15436) -Codechange: Return index of station spec within station class as a return parameter of GetCustomStationSpecByGrf(), as the index is already known. Saves on an extra loop and an extern...
peter1138 <peter1138@openttd.org>
parents: 11085
diff changeset
211 * @param localidx Index within GRF file of station spec.
c4c35a89bad7 (svn r15436) -Codechange: Return index of station spec within station class as a return parameter of GetCustomStationSpecByGrf(), as the index is already known. Saves on an extra loop and an extern...
peter1138 <peter1138@openttd.org>
parents: 11085
diff changeset
212 * @param index Pointer to return the index of the station spec in its station class. If NULL then not used.
c4c35a89bad7 (svn r15436) -Codechange: Return index of station spec within station class as a return parameter of GetCustomStationSpecByGrf(), as the index is already known. Saves on an extra loop and an extern...
peter1138 <peter1138@openttd.org>
parents: 11085
diff changeset
213 * @return The station spec.
c4c35a89bad7 (svn r15436) -Codechange: Return index of station spec within station class as a return parameter of GetCustomStationSpecByGrf(), as the index is already known. Saves on an extra loop and an extern...
peter1138 <peter1138@openttd.org>
parents: 11085
diff changeset
214 */
c4c35a89bad7 (svn r15436) -Codechange: Return index of station spec within station class as a return parameter of GetCustomStationSpecByGrf(), as the index is already known. Saves on an extra loop and an extern...
peter1138 <peter1138@openttd.org>
parents: 11085
diff changeset
215 const StationSpec *GetCustomStationSpecByGrf(uint32 grfid, byte localidx, int *index)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
216 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
217 uint j;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
218
5587
c44c070c5032 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium <rubidium@openttd.org>
parents: 5584
diff changeset
219 for (StationClassID i = STAT_CLASS_BEGIN; i < STAT_CLASS_MAX; i++) {
8316
a3f30e43d561 (svn r11881) -Cleanup: Code style for global variables.
peter1138 <peter1138@openttd.org>
parents: 8295
diff changeset
220 for (j = 0; j < _station_classes[i].stations; j++) {
a3f30e43d561 (svn r11881) -Cleanup: Code style for global variables.
peter1138 <peter1138@openttd.org>
parents: 8295
diff changeset
221 const StationSpec *statspec = _station_classes[i].spec[j];
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
222 if (statspec == NULL) continue;
11091
c4c35a89bad7 (svn r15436) -Codechange: Return index of station spec within station class as a return parameter of GetCustomStationSpecByGrf(), as the index is already known. Saves on an extra loop and an extern...
peter1138 <peter1138@openttd.org>
parents: 11085
diff changeset
223 if (statspec->grffile->grfid == grfid && statspec->localidx == localidx) {
c4c35a89bad7 (svn r15436) -Codechange: Return index of station spec within station class as a return parameter of GetCustomStationSpecByGrf(), as the index is already known. Saves on an extra loop and an extern...
peter1138 <peter1138@openttd.org>
parents: 11085
diff changeset
224 if (index != NULL) *index = j;
c4c35a89bad7 (svn r15436) -Codechange: Return index of station spec within station class as a return parameter of GetCustomStationSpecByGrf(), as the index is already known. Saves on an extra loop and an extern...
peter1138 <peter1138@openttd.org>
parents: 11085
diff changeset
225 return statspec;
c4c35a89bad7 (svn r15436) -Codechange: Return index of station spec within station class as a return parameter of GetCustomStationSpecByGrf(), as the index is already known. Saves on an extra loop and an extern...
peter1138 <peter1138@openttd.org>
parents: 11085
diff changeset
226 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
227 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
228 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
229
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
230 return NULL;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
231 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
232
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
233
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
234 /* Evaluate a tile's position within a station, and return the result a bitstuffed format.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
235 * if not centred: .TNLcCpP, if centred: .TNL..CP
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
236 * T = Tile layout number (GetStationGfx), N = Number of platforms, L = Length of platforms
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
237 * C = Current platform number from start, c = from end
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
238 * P = Position along platform from start, p = from end
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
239 * if centred, C/P start from the centre and c/p are not available.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
240 */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
241 uint32 GetPlatformInfo(Axis axis, byte tile, int platforms, int length, int x, int y, bool centred)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
242 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
243 uint32 retval = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
244
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
245 if (axis == AXIS_X) {
6106
230764f1a316 (svn r8841) -Fix
tron <tron@openttd.org>
parents: 5849
diff changeset
246 Swap(platforms, length);
230764f1a316 (svn r8841) -Fix
tron <tron@openttd.org>
parents: 5849
diff changeset
247 Swap(x, y);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
248 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
249
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
250 /* Limit our sizes to 4 bits */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
251 platforms = min(15, platforms);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
252 length = min(15, length);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
253 x = min(15, x);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
254 y = min(15, y);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
255 if (centred) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
256 x -= platforms / 2;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
257 y -= length / 2;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
258 SB(retval, 0, 4, y & 0xF);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
259 SB(retval, 4, 4, x & 0xF);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
260 } else {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
261 SB(retval, 0, 4, y);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
262 SB(retval, 4, 4, length - y - 1);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
263 SB(retval, 8, 4, x);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
264 SB(retval, 12, 4, platforms - x - 1);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
265 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
266 SB(retval, 16, 4, length);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
267 SB(retval, 20, 4, platforms);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
268 SB(retval, 24, 4, tile);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
269
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
270 return retval;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
271 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
272
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
273
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
274 /* Find the end of a railway station, from the tile, in the direction of delta.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
275 * If check_type is set, we stop if the custom station type changes.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
276 * If check_axis is set, we stop if the station direction changes.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
277 */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
278 static TileIndex FindRailStationEnd(TileIndex tile, TileIndexDiff delta, bool check_type, bool check_axis)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
279 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
280 byte orig_type = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
281 Axis orig_axis = AXIS_X;
12472
604a2cfc77ab (svn r16909) -Fix [FS#2996]: NewGRF stations would be triggering assertions all over the place when using the more advanced station types.
rubidium <rubidium@openttd.org>
parents: 12471
diff changeset
282 StationID sid = GetStationIndex(tile);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
283
12472
604a2cfc77ab (svn r16909) -Fix [FS#2996]: NewGRF stations would be triggering assertions all over the place when using the more advanced station types.
rubidium <rubidium@openttd.org>
parents: 12471
diff changeset
284 if (check_type) orig_type = GetCustomStationSpecIndex(tile);
604a2cfc77ab (svn r16909) -Fix [FS#2996]: NewGRF stations would be triggering assertions all over the place when using the more advanced station types.
rubidium <rubidium@openttd.org>
parents: 12471
diff changeset
285 if (check_axis) orig_axis = GetRailStationAxis(tile);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
286
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
287 while (true) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
288 TileIndex new_tile = TILE_ADD(tile, delta);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
289
12472
604a2cfc77ab (svn r16909) -Fix [FS#2996]: NewGRF stations would be triggering assertions all over the place when using the more advanced station types.
rubidium <rubidium@openttd.org>
parents: 12471
diff changeset
290 if (!IsTileType(new_tile, MP_STATION) || GetStationIndex(new_tile) != sid) break;
12501
44606771f552 (svn r16938) -Codechange: introduce helper function to tell whether a tile is either a rail station or rail waypoint tile
rubidium <rubidium@openttd.org>
parents: 12475
diff changeset
291 if (!HasStationRail(new_tile)) break;
12472
604a2cfc77ab (svn r16909) -Fix [FS#2996]: NewGRF stations would be triggering assertions all over the place when using the more advanced station types.
rubidium <rubidium@openttd.org>
parents: 12471
diff changeset
292 if (check_type && GetCustomStationSpecIndex(new_tile) != orig_type) break;
604a2cfc77ab (svn r16909) -Fix [FS#2996]: NewGRF stations would be triggering assertions all over the place when using the more advanced station types.
rubidium <rubidium@openttd.org>
parents: 12471
diff changeset
293 if (check_axis && GetRailStationAxis(new_tile) != orig_axis) break;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
294
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
295 tile = new_tile;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
296 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
297 return tile;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
298 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
299
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
300
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
301 static uint32 GetPlatformInfoHelper(TileIndex tile, bool check_type, bool check_axis, bool centred)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
302 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
303 int tx = TileX(tile);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
304 int ty = TileY(tile);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
305 int sx = TileX(FindRailStationEnd(tile, TileDiffXY(-1, 0), check_type, check_axis));
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
306 int sy = TileY(FindRailStationEnd(tile, TileDiffXY( 0, -1), check_type, check_axis));
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
307 int ex = TileX(FindRailStationEnd(tile, TileDiffXY( 1, 0), check_type, check_axis)) + 1;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
308 int ey = TileY(FindRailStationEnd(tile, TileDiffXY( 0, 1), check_type, check_axis)) + 1;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
309
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
310 tx -= sx; ex -= sx;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
311 ty -= sy; ey -= sy;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
312
12472
604a2cfc77ab (svn r16909) -Fix [FS#2996]: NewGRF stations would be triggering assertions all over the place when using the more advanced station types.
rubidium <rubidium@openttd.org>
parents: 12471
diff changeset
313 return GetPlatformInfo(GetRailStationAxis(tile), GetStationGfx(tile), ex, ey, tx, ty, centred);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
314 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
315
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
316
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
317 static uint32 GetRailContinuationInfo(TileIndex tile)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
318 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
319 /* Tile offsets and exit dirs for X axis */
7157
7e46225ed50b (svn r10431) -Codechange: constness on static array
peter1138 <peter1138@openttd.org>
parents: 7010
diff changeset
320 static const Direction x_dir[8] = { DIR_SW, DIR_NE, DIR_SE, DIR_NW, DIR_S, DIR_E, DIR_W, DIR_N };
7e46225ed50b (svn r10431) -Codechange: constness on static array
peter1138 <peter1138@openttd.org>
parents: 7010
diff changeset
321 static const DiagDirection x_exits[8] = { DIAGDIR_SW, DIAGDIR_NE, DIAGDIR_SE, DIAGDIR_NW, DIAGDIR_SW, DIAGDIR_NE, DIAGDIR_SW, DIAGDIR_NE };
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
322
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
323 /* Tile offsets and exit dirs for Y axis */
7157
7e46225ed50b (svn r10431) -Codechange: constness on static array
peter1138 <peter1138@openttd.org>
parents: 7010
diff changeset
324 static const Direction y_dir[8] = { DIR_SE, DIR_NW, DIR_SW, DIR_NE, DIR_S, DIR_W, DIR_E, DIR_N };
7e46225ed50b (svn r10431) -Codechange: constness on static array
peter1138 <peter1138@openttd.org>
parents: 7010
diff changeset
325 static const DiagDirection y_exits[8] = { DIAGDIR_SE, DIAGDIR_NW, DIAGDIR_SW, DIAGDIR_NE, DIAGDIR_SE, DIAGDIR_NW, DIAGDIR_SE, DIAGDIR_NW };
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
326
12472
604a2cfc77ab (svn r16909) -Fix [FS#2996]: NewGRF stations would be triggering assertions all over the place when using the more advanced station types.
rubidium <rubidium@openttd.org>
parents: 12471
diff changeset
327 Axis axis = GetRailStationAxis(tile);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
328
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
329 /* Choose appropriate lookup table to use */
7157
7e46225ed50b (svn r10431) -Codechange: constness on static array
peter1138 <peter1138@openttd.org>
parents: 7010
diff changeset
330 const Direction *dir = axis == AXIS_X ? x_dir : y_dir;
7e46225ed50b (svn r10431) -Codechange: constness on static array
peter1138 <peter1138@openttd.org>
parents: 7010
diff changeset
331 const DiagDirection *diagdir = axis == AXIS_X ? x_exits : y_exits;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
332
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
333 uint32 res = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
334 uint i;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
335
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
336 for (i = 0; i < lengthof(x_dir); i++, dir++, diagdir++) {
9662
cf5657f9e445 (svn r13734) -Fix: NewGRF rail continuation would always mark a tunnel on the same axis as connected, even when the tunnel faces the wrong direction.
rubidium <rubidium@openttd.org>
parents: 9038
diff changeset
337 TileIndex neighbour_tile = tile + TileOffsByDir(*dir);
cf5657f9e445 (svn r13734) -Fix: NewGRF rail continuation would always mark a tunnel on the same axis as connected, even when the tunnel faces the wrong direction.
rubidium <rubidium@openttd.org>
parents: 9038
diff changeset
338 TrackBits trackbits = TrackStatusToTrackBits(GetTileTrackStatus(neighbour_tile, TRANSPORT_RAIL, 0));
8616
9e46ac001a8c (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch <frosch@openttd.org>
parents: 8571
diff changeset
339 if (trackbits != TRACK_BIT_NONE) {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
340 /* If there is any track on the tile, set the bit in the second byte */
7931
44ff7a6d801f (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents: 7928
diff changeset
341 SetBit(res, i + 8);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
342
9662
cf5657f9e445 (svn r13734) -Fix: NewGRF rail continuation would always mark a tunnel on the same axis as connected, even when the tunnel faces the wrong direction.
rubidium <rubidium@openttd.org>
parents: 9038
diff changeset
343 /* With tunnels and bridges the tile has tracks, but they are not necessarily connected
cf5657f9e445 (svn r13734) -Fix: NewGRF rail continuation would always mark a tunnel on the same axis as connected, even when the tunnel faces the wrong direction.
rubidium <rubidium@openttd.org>
parents: 9038
diff changeset
344 * with the next tile because the ramp is not going in the right direction. */
cf5657f9e445 (svn r13734) -Fix: NewGRF rail continuation would always mark a tunnel on the same axis as connected, even when the tunnel faces the wrong direction.
rubidium <rubidium@openttd.org>
parents: 9038
diff changeset
345 if (IsTileType(neighbour_tile, MP_TUNNELBRIDGE) && GetTunnelBridgeDirection(neighbour_tile) != *diagdir) {
cf5657f9e445 (svn r13734) -Fix: NewGRF rail continuation would always mark a tunnel on the same axis as connected, even when the tunnel faces the wrong direction.
rubidium <rubidium@openttd.org>
parents: 9038
diff changeset
346 continue;
cf5657f9e445 (svn r13734) -Fix: NewGRF rail continuation would always mark a tunnel on the same axis as connected, even when the tunnel faces the wrong direction.
rubidium <rubidium@openttd.org>
parents: 9038
diff changeset
347 }
cf5657f9e445 (svn r13734) -Fix: NewGRF rail continuation would always mark a tunnel on the same axis as connected, even when the tunnel faces the wrong direction.
rubidium <rubidium@openttd.org>
parents: 9038
diff changeset
348
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
349 /* If any track reaches our exit direction, set the bit in the lower byte */
8616
9e46ac001a8c (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch <frosch@openttd.org>
parents: 8571
diff changeset
350 if (trackbits & DiagdirReachesTracks(*diagdir)) SetBit(res, i);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
351 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
352 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
353
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
354 return res;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
355 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
356
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
357
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
358 /* Station Resolver Functions */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
359 static uint32 StationGetRandomBits(const ResolverObject *object)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
360 {
12425
d9e9b7477507 (svn r16859) -Codechange: split the Station struct into two so parts of it can be reused for Waypoints.
rubidium <rubidium@openttd.org>
parents: 12418
diff changeset
361 const BaseStation *st = object->u.station.st;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
362 const TileIndex tile = object->u.station.tile;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
363 return (st == NULL ? 0 : st->random_bits) | (tile == INVALID_TILE ? 0 : GetStationTileRandomBits(tile) << 16);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
364 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
365
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
366
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
367 static uint32 StationGetTriggers(const ResolverObject *object)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
368 {
12425
d9e9b7477507 (svn r16859) -Codechange: split the Station struct into two so parts of it can be reused for Waypoints.
rubidium <rubidium@openttd.org>
parents: 12418
diff changeset
369 const BaseStation *st = object->u.station.st;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
370 return st == NULL ? 0 : st->waiting_triggers;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
371 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
372
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
373
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
374 static void StationSetTriggers(const ResolverObject *object, int triggers)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
375 {
12425
d9e9b7477507 (svn r16859) -Codechange: split the Station struct into two so parts of it can be reused for Waypoints.
rubidium <rubidium@openttd.org>
parents: 12418
diff changeset
376 BaseStation *st = const_cast<BaseStation *>(object->u.station.st);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
377 assert(st != NULL);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
378 st->waiting_triggers = triggers;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
379 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
380
7230
9b7fbae562c3 (svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138 <peter1138@openttd.org>
parents: 7192
diff changeset
381 /**
9b7fbae562c3 (svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138 <peter1138@openttd.org>
parents: 7192
diff changeset
382 * Station variable cache
9b7fbae562c3 (svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138 <peter1138@openttd.org>
parents: 7192
diff changeset
383 * This caches 'expensive' station variable lookups which iterate over
9b7fbae562c3 (svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138 <peter1138@openttd.org>
parents: 7192
diff changeset
384 * several tiles that may be called multiple times per Resolve().
9b7fbae562c3 (svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138 <peter1138@openttd.org>
parents: 7192
diff changeset
385 */
9b7fbae562c3 (svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138 <peter1138@openttd.org>
parents: 7192
diff changeset
386 static struct {
9b7fbae562c3 (svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138 <peter1138@openttd.org>
parents: 7192
diff changeset
387 uint32 v40;
9b7fbae562c3 (svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138 <peter1138@openttd.org>
parents: 7192
diff changeset
388 uint32 v41;
9b7fbae562c3 (svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138 <peter1138@openttd.org>
parents: 7192
diff changeset
389 uint32 v45;
9b7fbae562c3 (svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138 <peter1138@openttd.org>
parents: 7192
diff changeset
390 uint32 v46;
9b7fbae562c3 (svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138 <peter1138@openttd.org>
parents: 7192
diff changeset
391 uint32 v47;
9b7fbae562c3 (svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138 <peter1138@openttd.org>
parents: 7192
diff changeset
392 uint32 v49;
9b7fbae562c3 (svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138 <peter1138@openttd.org>
parents: 7192
diff changeset
393 uint8 valid;
9b7fbae562c3 (svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138 <peter1138@openttd.org>
parents: 7192
diff changeset
394 } _svc;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
395
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
396 static uint32 StationGetVariable(const ResolverObject *object, byte variable, byte parameter, bool *available)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
397 {
12425
d9e9b7477507 (svn r16859) -Codechange: split the Station struct into two so parts of it can be reused for Waypoints.
rubidium <rubidium@openttd.org>
parents: 12418
diff changeset
398 const BaseStation *st = object->u.station.st;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
399 TileIndex tile = object->u.station.tile;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
400
6354
4595b3acd03d (svn r9393) -Codechange: Use newgrf town resolver as station parent scope handler
peter1138 <peter1138@openttd.org>
parents: 6348
diff changeset
401 if (object->scope == VSG_SCOPE_PARENT) {
4595b3acd03d (svn r9393) -Codechange: Use newgrf town resolver as station parent scope handler
peter1138 <peter1138@openttd.org>
parents: 6348
diff changeset
402 /* Pass the request on to the town of the station */
9726
06221034cf54 (svn r13851) -Fix (r9393): GetTownByTile() is only valid for houses and roads.
frosch <frosch@openttd.org>
parents: 9714
diff changeset
403 const Town *t;
6354
4595b3acd03d (svn r9393) -Codechange: Use newgrf town resolver as station parent scope handler
peter1138 <peter1138@openttd.org>
parents: 6348
diff changeset
404
4595b3acd03d (svn r9393) -Codechange: Use newgrf town resolver as station parent scope handler
peter1138 <peter1138@openttd.org>
parents: 6348
diff changeset
405 if (st != NULL) {
4595b3acd03d (svn r9393) -Codechange: Use newgrf town resolver as station parent scope handler
peter1138 <peter1138@openttd.org>
parents: 6348
diff changeset
406 t = st->town;
4595b3acd03d (svn r9393) -Codechange: Use newgrf town resolver as station parent scope handler
peter1138 <peter1138@openttd.org>
parents: 6348
diff changeset
407 } else if (tile != INVALID_TILE) {
9726
06221034cf54 (svn r13851) -Fix (r9393): GetTownByTile() is only valid for houses and roads.
frosch <frosch@openttd.org>
parents: 9714
diff changeset
408 t = ClosestTownFromTile(tile, UINT_MAX);
6354
4595b3acd03d (svn r9393) -Codechange: Use newgrf town resolver as station parent scope handler
peter1138 <peter1138@openttd.org>
parents: 6348
diff changeset
409 } else {
4595b3acd03d (svn r9393) -Codechange: Use newgrf town resolver as station parent scope handler
peter1138 <peter1138@openttd.org>
parents: 6348
diff changeset
410 *available = false;
4595b3acd03d (svn r9393) -Codechange: Use newgrf town resolver as station parent scope handler
peter1138 <peter1138@openttd.org>
parents: 6348
diff changeset
411 return UINT_MAX;
4595b3acd03d (svn r9393) -Codechange: Use newgrf town resolver as station parent scope handler
peter1138 <peter1138@openttd.org>
parents: 6348
diff changeset
412 }
4595b3acd03d (svn r9393) -Codechange: Use newgrf town resolver as station parent scope handler
peter1138 <peter1138@openttd.org>
parents: 6348
diff changeset
413
4595b3acd03d (svn r9393) -Codechange: Use newgrf town resolver as station parent scope handler
peter1138 <peter1138@openttd.org>
parents: 6348
diff changeset
414 return TownGetVariable(variable, parameter, available, t);
4595b3acd03d (svn r9393) -Codechange: Use newgrf town resolver as station parent scope handler
peter1138 <peter1138@openttd.org>
parents: 6348
diff changeset
415 }
4595b3acd03d (svn r9393) -Codechange: Use newgrf town resolver as station parent scope handler
peter1138 <peter1138@openttd.org>
parents: 6348
diff changeset
416
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
417 if (st == NULL) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
418 /* Station does not exist, so we're in a purchase list */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
419 switch (variable) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
420 case 0x40:
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
421 case 0x41:
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
422 case 0x46:
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
423 case 0x47:
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10099
diff changeset
424 case 0x49: return 0x2110000; // Platforms, tracks & position
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10099
diff changeset
425 case 0x42: return 0; // Rail type (XXX Get current type from GUI?)
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10099
diff changeset
426 case 0x43: return _current_company; // Station owner
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10099
diff changeset
427 case 0x44: return 2; // PBS status
7922
ff1975ced735 (svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13 <skidd13@openttd.org>
parents: 7642
diff changeset
428 case 0xFA: return Clamp(_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 65535); // Build date, clamped to a 16 bit value
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
429 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
430
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
431 *available = false;
5587
c44c070c5032 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium <rubidium@openttd.org>
parents: 5584
diff changeset
432 return UINT_MAX;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
433 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
434
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
435 switch (variable) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
436 /* Calculated station variables */
7230
9b7fbae562c3 (svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138 <peter1138@openttd.org>
parents: 7192
diff changeset
437 case 0x40:
7931
44ff7a6d801f (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents: 7928
diff changeset
438 if (!HasBit(_svc.valid, 0)) { _svc.v40 = GetPlatformInfoHelper(tile, false, false, false); SetBit(_svc.valid, 0); }
7230
9b7fbae562c3 (svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138 <peter1138@openttd.org>
parents: 7192
diff changeset
439 return _svc.v40;
9b7fbae562c3 (svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138 <peter1138@openttd.org>
parents: 7192
diff changeset
440
9b7fbae562c3 (svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138 <peter1138@openttd.org>
parents: 7192
diff changeset
441 case 0x41:
7931
44ff7a6d801f (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents: 7928
diff changeset
442 if (!HasBit(_svc.valid, 1)) { _svc.v41 = GetPlatformInfoHelper(tile, true, false, false); SetBit(_svc.valid, 1); }
7230
9b7fbae562c3 (svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138 <peter1138@openttd.org>
parents: 7192
diff changeset
443 return _svc.v41;
9b7fbae562c3 (svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138 <peter1138@openttd.org>
parents: 7192
diff changeset
444
6849
cbe1a12e652d (svn r10089) -Fix (r10040): Use GetTileZ instead of GetClearGround in GetTerrainType as
maedhros <maedhros@openttd.org>
parents: 6683
diff changeset
445 case 0x42: return GetTerrainType(tile) | (GetRailType(tile) << 8);
6348
bcf98ba27bbf (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents: 6343
diff changeset
446 case 0x43: return st->owner; // Station owner
12472
604a2cfc77ab (svn r16909) -Fix [FS#2996]: NewGRF stations would be triggering assertions all over the place when using the more advanced station types.
rubidium <rubidium@openttd.org>
parents: 12471
diff changeset
447 case 0x44: return HasStationReservation(tile) ? 7 : 4; // PBS status
7230
9b7fbae562c3 (svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138 <peter1138@openttd.org>
parents: 7192
diff changeset
448 case 0x45:
7931
44ff7a6d801f (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents: 7928
diff changeset
449 if (!HasBit(_svc.valid, 2)) { _svc.v45 = GetRailContinuationInfo(tile); SetBit(_svc.valid, 2); }
7230
9b7fbae562c3 (svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138 <peter1138@openttd.org>
parents: 7192
diff changeset
450 return _svc.v45;
9b7fbae562c3 (svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138 <peter1138@openttd.org>
parents: 7192
diff changeset
451
9b7fbae562c3 (svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138 <peter1138@openttd.org>
parents: 7192
diff changeset
452 case 0x46:
7931
44ff7a6d801f (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents: 7928
diff changeset
453 if (!HasBit(_svc.valid, 3)) { _svc.v46 = GetPlatformInfoHelper(tile, false, false, true); SetBit(_svc.valid, 3); }
7230
9b7fbae562c3 (svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138 <peter1138@openttd.org>
parents: 7192
diff changeset
454 return _svc.v46;
9b7fbae562c3 (svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138 <peter1138@openttd.org>
parents: 7192
diff changeset
455
9b7fbae562c3 (svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138 <peter1138@openttd.org>
parents: 7192
diff changeset
456 case 0x47:
7931
44ff7a6d801f (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents: 7928
diff changeset
457 if (!HasBit(_svc.valid, 4)) { _svc.v47 = GetPlatformInfoHelper(tile, true, false, true); SetBit(_svc.valid, 4); }
7230
9b7fbae562c3 (svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138 <peter1138@openttd.org>
parents: 7192
diff changeset
458 return _svc.v47;
9b7fbae562c3 (svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138 <peter1138@openttd.org>
parents: 7192
diff changeset
459
9b7fbae562c3 (svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138 <peter1138@openttd.org>
parents: 7192
diff changeset
460 case 0x49:
7931
44ff7a6d801f (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents: 7928
diff changeset
461 if (!HasBit(_svc.valid, 5)) { _svc.v49 = GetPlatformInfoHelper(tile, false, true, false); SetBit(_svc.valid, 5); }
7230
9b7fbae562c3 (svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138 <peter1138@openttd.org>
parents: 7192
diff changeset
462 return _svc.v49;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
463
8956
9368ed6c6424 (svn r12747) -Codechange: Add varaction retrieval of station animation frame
peter1138 <peter1138@openttd.org>
parents: 8906
diff changeset
464 case 0x4A: // Animation frame of tile
9368ed6c6424 (svn r12747) -Codechange: Add varaction retrieval of station animation frame
peter1138 <peter1138@openttd.org>
parents: 8906
diff changeset
465 return GetStationAnimationFrame(tile);
9368ed6c6424 (svn r12747) -Codechange: Add varaction retrieval of station animation frame
peter1138 <peter1138@openttd.org>
parents: 8906
diff changeset
466
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
467 /* Variables which use the parameter */
6460
cebf3bbc9227 (svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138 <peter1138@openttd.org>
parents: 6451
diff changeset
468 /* Variables 0x60 to 0x65 are handled separately below */
8956
9368ed6c6424 (svn r12747) -Codechange: Add varaction retrieval of station animation frame
peter1138 <peter1138@openttd.org>
parents: 8906
diff changeset
469 case 0x66: // Animation frame of nearby tile
9368ed6c6424 (svn r12747) -Codechange: Add varaction retrieval of station animation frame
peter1138 <peter1138@openttd.org>
parents: 8906
diff changeset
470 if (parameter != 0) tile = GetNearbyTile(parameter, tile);
9368ed6c6424 (svn r12747) -Codechange: Add varaction retrieval of station animation frame
peter1138 <peter1138@openttd.org>
parents: 8906
diff changeset
471 return st->TileBelongsToRailStation(tile) ? GetStationAnimationFrame(tile) : UINT_MAX;
9368ed6c6424 (svn r12747) -Codechange: Add varaction retrieval of station animation frame
peter1138 <peter1138@openttd.org>
parents: 8906
diff changeset
472
9368ed6c6424 (svn r12747) -Codechange: Add varaction retrieval of station animation frame
peter1138 <peter1138@openttd.org>
parents: 8906
diff changeset
473 case 0x67: { // Land info of nearby tile
8118
854a73832899 (svn r11679) -Add: [newgrf] support for station vars 67 and 68
glx <glx@openttd.org>
parents: 7931
diff changeset
474 Axis axis = GetRailStationAxis(tile);
854a73832899 (svn r11679) -Add: [newgrf] support for station vars 67 and 68
glx <glx@openttd.org>
parents: 7931
diff changeset
475
854a73832899 (svn r11679) -Add: [newgrf] support for station vars 67 and 68
glx <glx@openttd.org>
parents: 7931
diff changeset
476 if (parameter != 0) tile = GetNearbyTile(parameter, tile); // only perform if it is required
854a73832899 (svn r11679) -Add: [newgrf] support for station vars 67 and 68
glx <glx@openttd.org>
parents: 7931
diff changeset
477
8458
44b11233507f (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 <frosch@openttd.org>
parents: 8316
diff changeset
478 Slope tileh = GetTileSlope(tile, NULL);
14188
3567fc0ac6ee (svn r18737) -Fix (r12028): Var67 data wasn't swapped properly for orientation.
peter1138 <peter1138@openttd.org>
parents: 14170
diff changeset
479 bool swap = (axis == AXIS_Y && HasBit(tileh, CORNER_W) != HasBit(tileh, CORNER_E));
8458
44b11233507f (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 <frosch@openttd.org>
parents: 8316
diff changeset
480
44b11233507f (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 <frosch@openttd.org>
parents: 8316
diff changeset
481 return GetNearbyTileInformation(tile) ^ (swap ? SLOPE_EW : 0);
8118
854a73832899 (svn r11679) -Add: [newgrf] support for station vars 67 and 68
glx <glx@openttd.org>
parents: 7931
diff changeset
482 }
854a73832899 (svn r11679) -Add: [newgrf] support for station vars 67 and 68
glx <glx@openttd.org>
parents: 7931
diff changeset
483
854a73832899 (svn r11679) -Add: [newgrf] support for station vars 67 and 68
glx <glx@openttd.org>
parents: 7931
diff changeset
484 case 0x68: { // Station info of nearby tiles
854a73832899 (svn r11679) -Add: [newgrf] support for station vars 67 and 68
glx <glx@openttd.org>
parents: 7931
diff changeset
485 TileIndex nearby_tile = GetNearbyTile(parameter, tile);
854a73832899 (svn r11679) -Add: [newgrf] support for station vars 67 and 68
glx <glx@openttd.org>
parents: 7931
diff changeset
486
12501
44606771f552 (svn r16938) -Codechange: introduce helper function to tell whether a tile is either a rail station or rail waypoint tile
rubidium <rubidium@openttd.org>
parents: 12475
diff changeset
487 if (!HasStationTileRail(nearby_tile)) return 0xFFFFFFFF;
8118
854a73832899 (svn r11679) -Add: [newgrf] support for station vars 67 and 68
glx <glx@openttd.org>
parents: 7931
diff changeset
488
854a73832899 (svn r11679) -Add: [newgrf] support for station vars 67 and 68
glx <glx@openttd.org>
parents: 7931
diff changeset
489 uint32 grfid = st->speclist[GetCustomStationSpecIndex(tile)].grfid;
854a73832899 (svn r11679) -Add: [newgrf] support for station vars 67 and 68
glx <glx@openttd.org>
parents: 7931
diff changeset
490 bool perpendicular = GetRailStationAxis(tile) != GetRailStationAxis(nearby_tile);
854a73832899 (svn r11679) -Add: [newgrf] support for station vars 67 and 68
glx <glx@openttd.org>
parents: 7931
diff changeset
491 bool same_station = st->TileBelongsToRailStation(nearby_tile);
854a73832899 (svn r11679) -Add: [newgrf] support for station vars 67 and 68
glx <glx@openttd.org>
parents: 7931
diff changeset
492 uint32 res = GB(GetStationGfx(nearby_tile), 1, 2) << 12 | !!perpendicular << 11 | !!same_station << 10;
854a73832899 (svn r11679) -Add: [newgrf] support for station vars 67 and 68
glx <glx@openttd.org>
parents: 7931
diff changeset
493
854a73832899 (svn r11679) -Add: [newgrf] support for station vars 67 and 68
glx <glx@openttd.org>
parents: 7931
diff changeset
494 if (IsCustomStationSpecIndex(nearby_tile)) {
12425
d9e9b7477507 (svn r16859) -Codechange: split the Station struct into two so parts of it can be reused for Waypoints.
rubidium <rubidium@openttd.org>
parents: 12418
diff changeset
495 const StationSpecList ssl = BaseStation::GetByTile(nearby_tile)->speclist[GetCustomStationSpecIndex(nearby_tile)];
8118
854a73832899 (svn r11679) -Add: [newgrf] support for station vars 67 and 68
glx <glx@openttd.org>
parents: 7931
diff changeset
496 res |= 1 << (ssl.grfid != grfid ? 9 : 8) | ssl.localidx;
854a73832899 (svn r11679) -Add: [newgrf] support for station vars 67 and 68
glx <glx@openttd.org>
parents: 7931
diff changeset
497 }
854a73832899 (svn r11679) -Add: [newgrf] support for station vars 67 and 68
glx <glx@openttd.org>
parents: 7931
diff changeset
498 return res;
854a73832899 (svn r11679) -Add: [newgrf] support for station vars 67 and 68
glx <glx@openttd.org>
parents: 7931
diff changeset
499 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
500
12430
5e6b5186ef8a (svn r16864) -Codechange: make Waypoints a subclass of BaseStation.
rubidium <rubidium@openttd.org>
parents: 12425
diff changeset
501 /* General station variables */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
502 case 0x82: return 50;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
503 case 0x84: return st->string_id;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
504 case 0x86: return 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
505 case 0xF0: return st->facilities;
7922
ff1975ced735 (svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13 <skidd13@openttd.org>
parents: 7642
diff changeset
506 case 0xFA: return Clamp(st->build_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 65535);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
507 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
508
12425
d9e9b7477507 (svn r16859) -Codechange: split the Station struct into two so parts of it can be reused for Waypoints.
rubidium <rubidium@openttd.org>
parents: 12418
diff changeset
509 return st->GetNewGRFVariable(object, variable, parameter, available);
d9e9b7477507 (svn r16859) -Codechange: split the Station struct into two so parts of it can be reused for Waypoints.
rubidium <rubidium@openttd.org>
parents: 12418
diff changeset
510 }
d9e9b7477507 (svn r16859) -Codechange: split the Station struct into two so parts of it can be reused for Waypoints.
rubidium <rubidium@openttd.org>
parents: 12418
diff changeset
511
d9e9b7477507 (svn r16859) -Codechange: split the Station struct into two so parts of it can be reused for Waypoints.
rubidium <rubidium@openttd.org>
parents: 12418
diff changeset
512 uint32 Station::GetNewGRFVariable(const ResolverObject *object, byte variable, byte parameter, bool *available) const
d9e9b7477507 (svn r16859) -Codechange: split the Station struct into two so parts of it can be reused for Waypoints.
rubidium <rubidium@openttd.org>
parents: 12418
diff changeset
513 {
d9e9b7477507 (svn r16859) -Codechange: split the Station struct into two so parts of it can be reused for Waypoints.
rubidium <rubidium@openttd.org>
parents: 12418
diff changeset
514 switch (variable) {
d9e9b7477507 (svn r16859) -Codechange: split the Station struct into two so parts of it can be reused for Waypoints.
rubidium <rubidium@openttd.org>
parents: 12418
diff changeset
515 case 0x48: { // Accepted cargo types
d9e9b7477507 (svn r16859) -Codechange: split the Station struct into two so parts of it can be reused for Waypoints.
rubidium <rubidium@openttd.org>
parents: 12418
diff changeset
516 CargoID cargo_type;
d9e9b7477507 (svn r16859) -Codechange: split the Station struct into two so parts of it can be reused for Waypoints.
rubidium <rubidium@openttd.org>
parents: 12418
diff changeset
517 uint32 value = 0;
d9e9b7477507 (svn r16859) -Codechange: split the Station struct into two so parts of it can be reused for Waypoints.
rubidium <rubidium@openttd.org>
parents: 12418
diff changeset
518
d9e9b7477507 (svn r16859) -Codechange: split the Station struct into two so parts of it can be reused for Waypoints.
rubidium <rubidium@openttd.org>
parents: 12418
diff changeset
519 for (cargo_type = 0; cargo_type < NUM_CARGO; cargo_type++) {
d9e9b7477507 (svn r16859) -Codechange: split the Station struct into two so parts of it can be reused for Waypoints.
rubidium <rubidium@openttd.org>
parents: 12418
diff changeset
520 if (HasBit(this->goods[cargo_type].acceptance_pickup, GoodsEntry::PICKUP)) SetBit(value, cargo_type);
d9e9b7477507 (svn r16859) -Codechange: split the Station struct into two so parts of it can be reused for Waypoints.
rubidium <rubidium@openttd.org>
parents: 12418
diff changeset
521 }
d9e9b7477507 (svn r16859) -Codechange: split the Station struct into two so parts of it can be reused for Waypoints.
rubidium <rubidium@openttd.org>
parents: 12418
diff changeset
522 return value;
d9e9b7477507 (svn r16859) -Codechange: split the Station struct into two so parts of it can be reused for Waypoints.
rubidium <rubidium@openttd.org>
parents: 12418
diff changeset
523 }
d9e9b7477507 (svn r16859) -Codechange: split the Station struct into two so parts of it can be reused for Waypoints.
rubidium <rubidium@openttd.org>
parents: 12418
diff changeset
524
d9e9b7477507 (svn r16859) -Codechange: split the Station struct into two so parts of it can be reused for Waypoints.
rubidium <rubidium@openttd.org>
parents: 12418
diff changeset
525 case 0x8A: return this->had_vehicle_of_type;
d9e9b7477507 (svn r16859) -Codechange: split the Station struct into two so parts of it can be reused for Waypoints.
rubidium <rubidium@openttd.org>
parents: 12418
diff changeset
526 case 0xF1: return this->airport_type;
d9e9b7477507 (svn r16859) -Codechange: split the Station struct into two so parts of it can be reused for Waypoints.
rubidium <rubidium@openttd.org>
parents: 12418
diff changeset
527 case 0xF2: return this->truck_stops->status;
d9e9b7477507 (svn r16859) -Codechange: split the Station struct into two so parts of it can be reused for Waypoints.
rubidium <rubidium@openttd.org>
parents: 12418
diff changeset
528 case 0xF3: return this->bus_stops->status;
d9e9b7477507 (svn r16859) -Codechange: split the Station struct into two so parts of it can be reused for Waypoints.
rubidium <rubidium@openttd.org>
parents: 12418
diff changeset
529 case 0xF6: return this->airport_flags;
d9e9b7477507 (svn r16859) -Codechange: split the Station struct into two so parts of it can be reused for Waypoints.
rubidium <rubidium@openttd.org>
parents: 12418
diff changeset
530 case 0xF7: return GB(this->airport_flags, 8, 8);
d9e9b7477507 (svn r16859) -Codechange: split the Station struct into two so parts of it can be reused for Waypoints.
rubidium <rubidium@openttd.org>
parents: 12418
diff changeset
531 }
d9e9b7477507 (svn r16859) -Codechange: split the Station struct into two so parts of it can be reused for Waypoints.
rubidium <rubidium@openttd.org>
parents: 12418
diff changeset
532
6460
cebf3bbc9227 (svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138 <peter1138@openttd.org>
parents: 6451
diff changeset
533 /* Handle cargo variables with parameter, 0x60 to 0x65 */
cebf3bbc9227 (svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138 <peter1138@openttd.org>
parents: 6451
diff changeset
534 if (variable >= 0x60 && variable <= 0x65) {
cebf3bbc9227 (svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138 <peter1138@openttd.org>
parents: 6451
diff changeset
535 CargoID c = GetCargoTranslation(parameter, object->u.station.statspec->grffile);
cebf3bbc9227 (svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138 <peter1138@openttd.org>
parents: 6451
diff changeset
536
cebf3bbc9227 (svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138 <peter1138@openttd.org>
parents: 6451
diff changeset
537 if (c == CT_INVALID) return 0;
12425
d9e9b7477507 (svn r16859) -Codechange: split the Station struct into two so parts of it can be reused for Waypoints.
rubidium <rubidium@openttd.org>
parents: 12418
diff changeset
538 const GoodsEntry *ge = &this->goods[c];
6460
cebf3bbc9227 (svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138 <peter1138@openttd.org>
parents: 6451
diff changeset
539
cebf3bbc9227 (svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138 <peter1138@openttd.org>
parents: 6451
diff changeset
540 switch (variable) {
7010
f0f87c5a431e (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 <rubidium@openttd.org>
parents: 6849
diff changeset
541 case 0x60: return min(ge->cargo.Count(), 4095);
6460
cebf3bbc9227 (svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138 <peter1138@openttd.org>
parents: 6451
diff changeset
542 case 0x61: return ge->days_since_pickup;
cebf3bbc9227 (svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138 <peter1138@openttd.org>
parents: 6451
diff changeset
543 case 0x62: return ge->rating;
7010
f0f87c5a431e (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 <rubidium@openttd.org>
parents: 6849
diff changeset
544 case 0x63: return ge->cargo.DaysInTransit();
6460
cebf3bbc9227 (svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138 <peter1138@openttd.org>
parents: 6451
diff changeset
545 case 0x64: return ge->last_speed | (ge->last_age << 8);
7474
7b35fd1cc99d (svn r10981) -Fix [FS#1156] (r10970): stations gave ratings for accepted cargo too.
rubidium <rubidium@openttd.org>
parents: 7327
diff changeset
546 case 0x65: return GB(ge->acceptance_pickup, GoodsEntry::ACCEPTANCE, 1) << 3;
6460
cebf3bbc9227 (svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138 <peter1138@openttd.org>
parents: 6451
diff changeset
547 }
cebf3bbc9227 (svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138 <peter1138@openttd.org>
parents: 6451
diff changeset
548 }
cebf3bbc9227 (svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138 <peter1138@openttd.org>
parents: 6451
diff changeset
549
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
550 /* Handle cargo variables (deprecated) */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
551 if (variable >= 0x8C && variable <= 0xEC) {
12425
d9e9b7477507 (svn r16859) -Codechange: split the Station struct into two so parts of it can be reused for Waypoints.
rubidium <rubidium@openttd.org>
parents: 12418
diff changeset
552 const GoodsEntry *g = &this->goods[GB(variable - 0x8C, 3, 4)];
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
553 switch (GB(variable - 0x8C, 0, 3)) {
7010
f0f87c5a431e (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 <rubidium@openttd.org>
parents: 6849
diff changeset
554 case 0: return g->cargo.Count();
7474
7b35fd1cc99d (svn r10981) -Fix [FS#1156] (r10970): stations gave ratings for accepted cargo too.
rubidium <rubidium@openttd.org>
parents: 7327
diff changeset
555 case 1: return GB(min(g->cargo.Count(), 4095), 0, 4) | (GB(g->acceptance_pickup, GoodsEntry::ACCEPTANCE, 1) << 7);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
556 case 2: return g->days_since_pickup;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
557 case 3: return g->rating;
7010
f0f87c5a431e (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 <rubidium@openttd.org>
parents: 6849
diff changeset
558 case 4: return g->cargo.Source();
f0f87c5a431e (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 <rubidium@openttd.org>
parents: 6849
diff changeset
559 case 5: return g->cargo.DaysInTransit();
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
560 case 6: return g->last_speed;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
561 case 7: return g->last_age;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
562 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
563 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
564
12430
5e6b5186ef8a (svn r16864) -Codechange: make Waypoints a subclass of BaseStation.
rubidium <rubidium@openttd.org>
parents: 12425
diff changeset
565 DEBUG(grf, 1, "Unhandled station variable 0x%X", variable);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
566
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
567 *available = false;
5587
c44c070c5032 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium <rubidium@openttd.org>
parents: 5584
diff changeset
568 return UINT_MAX;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
569 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
570
12430
5e6b5186ef8a (svn r16864) -Codechange: make Waypoints a subclass of BaseStation.
rubidium <rubidium@openttd.org>
parents: 12425
diff changeset
571 uint32 Waypoint::GetNewGRFVariable(const ResolverObject *object, byte variable, byte parameter, bool *available) const
5e6b5186ef8a (svn r16864) -Codechange: make Waypoints a subclass of BaseStation.
rubidium <rubidium@openttd.org>
parents: 12425
diff changeset
572 {
5e6b5186ef8a (svn r16864) -Codechange: make Waypoints a subclass of BaseStation.
rubidium <rubidium@openttd.org>
parents: 12425
diff changeset
573 switch (variable) {
5e6b5186ef8a (svn r16864) -Codechange: make Waypoints a subclass of BaseStation.
rubidium <rubidium@openttd.org>
parents: 12425
diff changeset
574 case 0x48: return 0; // Accepted cargo types
12472
604a2cfc77ab (svn r16909) -Fix [FS#2996]: NewGRF stations would be triggering assertions all over the place when using the more advanced station types.
rubidium <rubidium@openttd.org>
parents: 12471
diff changeset
575 case 0x8A: return HVOT_WAYPOINT;
12430
5e6b5186ef8a (svn r16864) -Codechange: make Waypoints a subclass of BaseStation.
rubidium <rubidium@openttd.org>
parents: 12425
diff changeset
576 case 0xF1: return 0; // airport type
5e6b5186ef8a (svn r16864) -Codechange: make Waypoints a subclass of BaseStation.
rubidium <rubidium@openttd.org>
parents: 12425
diff changeset
577 case 0xF2: return 0; // truck stop status
5e6b5186ef8a (svn r16864) -Codechange: make Waypoints a subclass of BaseStation.
rubidium <rubidium@openttd.org>
parents: 12425
diff changeset
578 case 0xF3: return 0; // bus stop status
5e6b5186ef8a (svn r16864) -Codechange: make Waypoints a subclass of BaseStation.
rubidium <rubidium@openttd.org>
parents: 12425
diff changeset
579 case 0xF6: return 0; // airport flags
5e6b5186ef8a (svn r16864) -Codechange: make Waypoints a subclass of BaseStation.
rubidium <rubidium@openttd.org>
parents: 12425
diff changeset
580 case 0xF7: return 0; // airport flags cont.
5e6b5186ef8a (svn r16864) -Codechange: make Waypoints a subclass of BaseStation.
rubidium <rubidium@openttd.org>
parents: 12425
diff changeset
581 }
5e6b5186ef8a (svn r16864) -Codechange: make Waypoints a subclass of BaseStation.
rubidium <rubidium@openttd.org>
parents: 12425
diff changeset
582
5e6b5186ef8a (svn r16864) -Codechange: make Waypoints a subclass of BaseStation.
rubidium <rubidium@openttd.org>
parents: 12425
diff changeset
583 /* Handle cargo variables with parameter, 0x60 to 0x65 */
5e6b5186ef8a (svn r16864) -Codechange: make Waypoints a subclass of BaseStation.
rubidium <rubidium@openttd.org>
parents: 12425
diff changeset
584 if (variable >= 0x60 && variable <= 0x65) {
5e6b5186ef8a (svn r16864) -Codechange: make Waypoints a subclass of BaseStation.
rubidium <rubidium@openttd.org>
parents: 12425
diff changeset
585 return 0;
5e6b5186ef8a (svn r16864) -Codechange: make Waypoints a subclass of BaseStation.
rubidium <rubidium@openttd.org>
parents: 12425
diff changeset
586 }
5e6b5186ef8a (svn r16864) -Codechange: make Waypoints a subclass of BaseStation.
rubidium <rubidium@openttd.org>
parents: 12425
diff changeset
587
5e6b5186ef8a (svn r16864) -Codechange: make Waypoints a subclass of BaseStation.
rubidium <rubidium@openttd.org>
parents: 12425
diff changeset
588 /* Handle cargo variables (deprecated) */
5e6b5186ef8a (svn r16864) -Codechange: make Waypoints a subclass of BaseStation.
rubidium <rubidium@openttd.org>
parents: 12425
diff changeset
589 if (variable >= 0x8C && variable <= 0xEC) {
5e6b5186ef8a (svn r16864) -Codechange: make Waypoints a subclass of BaseStation.
rubidium <rubidium@openttd.org>
parents: 12425
diff changeset
590 switch (GB(variable - 0x8C, 0, 3)) {
5e6b5186ef8a (svn r16864) -Codechange: make Waypoints a subclass of BaseStation.
rubidium <rubidium@openttd.org>
parents: 12425
diff changeset
591 case 3: return INITIAL_STATION_RATING;
5e6b5186ef8a (svn r16864) -Codechange: make Waypoints a subclass of BaseStation.
rubidium <rubidium@openttd.org>
parents: 12425
diff changeset
592 case 4: return INVALID_STATION;
5e6b5186ef8a (svn r16864) -Codechange: make Waypoints a subclass of BaseStation.
rubidium <rubidium@openttd.org>
parents: 12425
diff changeset
593 default: return 0;
5e6b5186ef8a (svn r16864) -Codechange: make Waypoints a subclass of BaseStation.
rubidium <rubidium@openttd.org>
parents: 12425
diff changeset
594 }
5e6b5186ef8a (svn r16864) -Codechange: make Waypoints a subclass of BaseStation.
rubidium <rubidium@openttd.org>
parents: 12425
diff changeset
595 }
5e6b5186ef8a (svn r16864) -Codechange: make Waypoints a subclass of BaseStation.
rubidium <rubidium@openttd.org>
parents: 12425
diff changeset
596
5e6b5186ef8a (svn r16864) -Codechange: make Waypoints a subclass of BaseStation.
rubidium <rubidium@openttd.org>
parents: 12425
diff changeset
597 DEBUG(grf, 1, "Unhandled station variable 0x%X", variable);
5e6b5186ef8a (svn r16864) -Codechange: make Waypoints a subclass of BaseStation.
rubidium <rubidium@openttd.org>
parents: 12425
diff changeset
598
5e6b5186ef8a (svn r16864) -Codechange: make Waypoints a subclass of BaseStation.
rubidium <rubidium@openttd.org>
parents: 12425
diff changeset
599 *available = false;
5e6b5186ef8a (svn r16864) -Codechange: make Waypoints a subclass of BaseStation.
rubidium <rubidium@openttd.org>
parents: 12425
diff changeset
600 return UINT_MAX;
5e6b5186ef8a (svn r16864) -Codechange: make Waypoints a subclass of BaseStation.
rubidium <rubidium@openttd.org>
parents: 12425
diff changeset
601 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
602
11990
db0e49f419d9 (svn r16396) -Codechange: split NewGRF spritegroup into multiple subclasses instead of using a big union
rubidium <rubidium@openttd.org>
parents: 11586
diff changeset
603 static const SpriteGroup *StationResolveReal(const ResolverObject *object, const RealSpriteGroup *group)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
604 {
12425
d9e9b7477507 (svn r16859) -Codechange: split the Station struct into two so parts of it can be reused for Waypoints.
rubidium <rubidium@openttd.org>
parents: 12418
diff changeset
605 const BaseStation *bst = object->u.station.st;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
606 const StationSpec *statspec = object->u.station.statspec;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
607 uint set;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
608
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
609 uint cargo = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
610 CargoID cargo_type = object->u.station.cargo_type;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
611
12425
d9e9b7477507 (svn r16859) -Codechange: split the Station struct into two so parts of it can be reused for Waypoints.
rubidium <rubidium@openttd.org>
parents: 12418
diff changeset
612 if (bst == NULL || statspec->sclass == STAT_CLASS_WAYP) {
11990
db0e49f419d9 (svn r16396) -Codechange: split NewGRF spritegroup into multiple subclasses instead of using a big union
rubidium <rubidium@openttd.org>
parents: 11586
diff changeset
613 return group->loading[0];
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
614 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
615
12425
d9e9b7477507 (svn r16859) -Codechange: split the Station struct into two so parts of it can be reused for Waypoints.
rubidium <rubidium@openttd.org>
parents: 12418
diff changeset
616 const Station *st = Station::From(bst);
d9e9b7477507 (svn r16859) -Codechange: split the Station struct into two so parts of it can be reused for Waypoints.
rubidium <rubidium@openttd.org>
parents: 12418
diff changeset
617
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
618 switch (cargo_type) {
6148
4b171c8e99ce (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 <peter1138@openttd.org>
parents: 6122
diff changeset
619 case CT_INVALID:
4b171c8e99ce (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 <peter1138@openttd.org>
parents: 6122
diff changeset
620 case CT_DEFAULT_NA:
4b171c8e99ce (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 <peter1138@openttd.org>
parents: 6122
diff changeset
621 case CT_PURCHASE:
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
622 cargo = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
623 break;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
624
6148
4b171c8e99ce (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 <peter1138@openttd.org>
parents: 6122
diff changeset
625 case CT_DEFAULT:
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
626 for (cargo_type = 0; cargo_type < NUM_CARGO; cargo_type++) {
7010
f0f87c5a431e (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 <rubidium@openttd.org>
parents: 6849
diff changeset
627 cargo += st->goods[cargo_type].cargo.Count();
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
628 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
629 break;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
630
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
631 default:
7010
f0f87c5a431e (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 <rubidium@openttd.org>
parents: 6849
diff changeset
632 cargo = st->goods[cargo_type].cargo.Count();
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
633 break;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
634 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
635
12510
3e976121ced2 (svn r16947) -Codechange: use TileArea instead of train_tile, trainst_w and trainst_h.
rubidium <rubidium@openttd.org>
parents: 12502
diff changeset
636 if (HasBit(statspec->flags, SSF_DIV_BY_STATION_SIZE)) cargo /= (st->train_station.w + st->train_station.h);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
637 cargo = min(0xfff, cargo);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
638
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
639 if (cargo > statspec->cargo_threshold) {
11990
db0e49f419d9 (svn r16396) -Codechange: split NewGRF spritegroup into multiple subclasses instead of using a big union
rubidium <rubidium@openttd.org>
parents: 11586
diff changeset
640 if (group->num_loading > 0) {
db0e49f419d9 (svn r16396) -Codechange: split NewGRF spritegroup into multiple subclasses instead of using a big union
rubidium <rubidium@openttd.org>
parents: 11586
diff changeset
641 set = ((cargo - statspec->cargo_threshold) * group->num_loading) / (4096 - statspec->cargo_threshold);
db0e49f419d9 (svn r16396) -Codechange: split NewGRF spritegroup into multiple subclasses instead of using a big union
rubidium <rubidium@openttd.org>
parents: 11586
diff changeset
642 return group->loading[set];
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
643 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
644 } else {
11990
db0e49f419d9 (svn r16396) -Codechange: split NewGRF spritegroup into multiple subclasses instead of using a big union
rubidium <rubidium@openttd.org>
parents: 11586
diff changeset
645 if (group->num_loaded > 0) {
db0e49f419d9 (svn r16396) -Codechange: split NewGRF spritegroup into multiple subclasses instead of using a big union
rubidium <rubidium@openttd.org>
parents: 11586
diff changeset
646 set = (cargo * group->num_loaded) / (statspec->cargo_threshold + 1);
db0e49f419d9 (svn r16396) -Codechange: split NewGRF spritegroup into multiple subclasses instead of using a big union
rubidium <rubidium@openttd.org>
parents: 11586
diff changeset
647 return group->loaded[set];
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
648 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
649 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
650
11990
db0e49f419d9 (svn r16396) -Codechange: split NewGRF spritegroup into multiple subclasses instead of using a big union
rubidium <rubidium@openttd.org>
parents: 11586
diff changeset
651 return group->loading[0];
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
652 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
653
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
654
12425
d9e9b7477507 (svn r16859) -Codechange: split the Station struct into two so parts of it can be reused for Waypoints.
rubidium <rubidium@openttd.org>
parents: 12418
diff changeset
655 static void NewStationResolver(ResolverObject *res, const StationSpec *statspec, const BaseStation *st, TileIndex tile)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
656 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
657 res->GetRandomBits = StationGetRandomBits;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
658 res->GetTriggers = StationGetTriggers;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
659 res->SetTriggers = StationSetTriggers;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
660 res->GetVariable = StationGetVariable;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
661 res->ResolveReal = StationResolveReal;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
662
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
663 res->u.station.st = st;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
664 res->u.station.statspec = statspec;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
665 res->u.station.tile = tile;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
666
7327
0ab2820a1e52 (svn r10690) -Codechange: use the enum that describes all callback IDs in favor of "just" using an untyped integer.
rubidium <rubidium@openttd.org>
parents: 7272
diff changeset
667 res->callback = CBID_NO_CALLBACK;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
668 res->callback_param1 = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
669 res->callback_param2 = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
670 res->last_value = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
671 res->trigger = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
672 res->reseed = 0;
8756
ae0ec91bb55e (svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx <glx@openttd.org>
parents: 8695
diff changeset
673 res->count = 0;
9750
0654bf387d06 (svn r13885) -Fix [FS#2168]: Var 0x7F is not feature-specific.
frosch <frosch@openttd.org>
parents: 9726
diff changeset
674 res->grffile = (statspec != NULL ? statspec->grffile : NULL);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
675 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
676
5849
de5286746a3a (svn r8423) -Fix
tron <tron@openttd.org>
parents: 5825
diff changeset
677 static const SpriteGroup *ResolveStation(ResolverObject *object)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
678 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
679 const SpriteGroup *group;
6148
4b171c8e99ce (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 <peter1138@openttd.org>
parents: 6122
diff changeset
680 CargoID ctype = CT_DEFAULT_NA;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
681
5849
de5286746a3a (svn r8423) -Fix
tron <tron@openttd.org>
parents: 5825
diff changeset
682 if (object->u.station.st == NULL) {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
683 /* No station, so we are in a purchase list */
6148
4b171c8e99ce (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 <peter1138@openttd.org>
parents: 6122
diff changeset
684 ctype = CT_PURCHASE;
12454
737f00243322 (svn r16888) -Fix (r16864): crash when trying to build (some?) NewGRF waypoints
rubidium <rubidium@openttd.org>
parents: 12430
diff changeset
685 } else if (Station::IsExpected(object->u.station.st)) {
12425
d9e9b7477507 (svn r16859) -Codechange: split the Station struct into two so parts of it can be reused for Waypoints.
rubidium <rubidium@openttd.org>
parents: 12418
diff changeset
686 const Station *st = Station::From(object->u.station.st);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
687 /* Pick the first cargo that we have waiting */
12418
0d8340a4c70e (svn r16852) -Codechange: use FOR_ALL_CARGOSPECS for iterating over all valid CargoSpecs
smatz <smatz@openttd.org>
parents: 12415
diff changeset
688 const CargoSpec *cs;
0d8340a4c70e (svn r16852) -Codechange: use FOR_ALL_CARGOSPECS for iterating over all valid CargoSpecs
smatz <smatz@openttd.org>
parents: 12415
diff changeset
689 FOR_ALL_CARGOSPECS(cs) {
0d8340a4c70e (svn r16852) -Codechange: use FOR_ALL_CARGOSPECS for iterating over all valid CargoSpecs
smatz <smatz@openttd.org>
parents: 12415
diff changeset
690 if (object->u.station.statspec->spritegroup[cs->Index()] != NULL &&
12425
d9e9b7477507 (svn r16859) -Codechange: split the Station struct into two so parts of it can be reused for Waypoints.
rubidium <rubidium@openttd.org>
parents: 12418
diff changeset
691 !st->goods[cs->Index()].cargo.Empty()) {
12418
0d8340a4c70e (svn r16852) -Codechange: use FOR_ALL_CARGOSPECS for iterating over all valid CargoSpecs
smatz <smatz@openttd.org>
parents: 12415
diff changeset
692 ctype = cs->Index();
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
693 break;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
694 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
695 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
696 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
697
5849
de5286746a3a (svn r8423) -Fix
tron <tron@openttd.org>
parents: 5825
diff changeset
698 group = object->u.station.statspec->spritegroup[ctype];
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
699 if (group == NULL) {
6148
4b171c8e99ce (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 <peter1138@openttd.org>
parents: 6122
diff changeset
700 ctype = CT_DEFAULT;
5849
de5286746a3a (svn r8423) -Fix
tron <tron@openttd.org>
parents: 5825
diff changeset
701 group = object->u.station.statspec->spritegroup[ctype];
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
702 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
703
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
704 if (group == NULL) return NULL;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
705
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
706 /* Remember the cargo type we've picked */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
707 object->u.station.cargo_type = ctype;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
708
7230
9b7fbae562c3 (svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138 <peter1138@openttd.org>
parents: 7192
diff changeset
709 /* Invalidate all cached vars */
9b7fbae562c3 (svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138 <peter1138@openttd.org>
parents: 7192
diff changeset
710 _svc.valid = 0;
9b7fbae562c3 (svn r10509) -Codechange: cache expensive newgrf station variables during
peter1138 <peter1138@openttd.org>
parents: 7192
diff changeset
711
11996
b43cf6c7ea61 (svn r16402) -Codechange: make Resolve a function of SpriteGroup
rubidium <rubidium@openttd.org>
parents: 11990
diff changeset
712 return SpriteGroup::Resolve(group, object);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
713 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
714
12425
d9e9b7477507 (svn r16859) -Codechange: split the Station struct into two so parts of it can be reused for Waypoints.
rubidium <rubidium@openttd.org>
parents: 12418
diff changeset
715 SpriteID GetCustomStationRelocation(const StationSpec *statspec, const BaseStation *st, TileIndex tile)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
716 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
717 const SpriteGroup *group;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
718 ResolverObject object;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
719
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
720 NewStationResolver(&object, statspec, st, tile);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
721
5849
de5286746a3a (svn r8423) -Fix
tron <tron@openttd.org>
parents: 5825
diff changeset
722 group = ResolveStation(&object);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
723 if (group == NULL || group->type != SGT_RESULT) return 0;
11990
db0e49f419d9 (svn r16396) -Codechange: split NewGRF spritegroup into multiple subclasses instead of using a big union
rubidium <rubidium@openttd.org>
parents: 11586
diff changeset
724 return group->GetResult() - 0x42D;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
725 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
726
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
727
12425
d9e9b7477507 (svn r16859) -Codechange: split the Station struct into two so parts of it can be reused for Waypoints.
rubidium <rubidium@openttd.org>
parents: 12418
diff changeset
728 SpriteID GetCustomStationGroundRelocation(const StationSpec *statspec, const BaseStation *st, TileIndex tile)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
729 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
730 const SpriteGroup *group;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
731 ResolverObject object;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
732
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
733 NewStationResolver(&object, statspec, st, tile);
11586
97ba565c6123 (svn r15957) -Fix (r4767): Set callback_param1 (var 10) to 1 only when requested.
peter1138 <peter1138@openttd.org>
parents: 11585
diff changeset
734 if (HasBit(statspec->flags, SSF_SEPARATE_GROUND)) {
97ba565c6123 (svn r15957) -Fix (r4767): Set callback_param1 (var 10) to 1 only when requested.
peter1138 <peter1138@openttd.org>
parents: 11585
diff changeset
735 object.callback_param1 = 1; // Indicate we are resolving the ground sprite
97ba565c6123 (svn r15957) -Fix (r4767): Set callback_param1 (var 10) to 1 only when requested.
peter1138 <peter1138@openttd.org>
parents: 11585
diff changeset
736 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
737
5849
de5286746a3a (svn r8423) -Fix
tron <tron@openttd.org>
parents: 5825
diff changeset
738 group = ResolveStation(&object);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
739 if (group == NULL || group->type != SGT_RESULT) return 0;
11990
db0e49f419d9 (svn r16396) -Codechange: split NewGRF spritegroup into multiple subclasses instead of using a big union
rubidium <rubidium@openttd.org>
parents: 11586
diff changeset
740 return group->GetResult() - 0x42D;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
741 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
742
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
743
14160
6eb541d75e51 (svn r18708) -Feature: [NewGRF] Add support for custom station foundation graphics.
peter1138 <peter1138@openttd.org>
parents: 14134
diff changeset
744 SpriteID GetCustomStationFoundationRelocation(const StationSpec *statspec, const BaseStation *st, TileIndex tile)
6eb541d75e51 (svn r18708) -Feature: [NewGRF] Add support for custom station foundation graphics.
peter1138 <peter1138@openttd.org>
parents: 14134
diff changeset
745 {
6eb541d75e51 (svn r18708) -Feature: [NewGRF] Add support for custom station foundation graphics.
peter1138 <peter1138@openttd.org>
parents: 14134
diff changeset
746 const SpriteGroup *group;
6eb541d75e51 (svn r18708) -Feature: [NewGRF] Add support for custom station foundation graphics.
peter1138 <peter1138@openttd.org>
parents: 14134
diff changeset
747 ResolverObject object;
6eb541d75e51 (svn r18708) -Feature: [NewGRF] Add support for custom station foundation graphics.
peter1138 <peter1138@openttd.org>
parents: 14134
diff changeset
748
6eb541d75e51 (svn r18708) -Feature: [NewGRF] Add support for custom station foundation graphics.
peter1138 <peter1138@openttd.org>
parents: 14134
diff changeset
749 NewStationResolver(&object, statspec, st, tile);
6eb541d75e51 (svn r18708) -Feature: [NewGRF] Add support for custom station foundation graphics.
peter1138 <peter1138@openttd.org>
parents: 14134
diff changeset
750 object.callback_param1 = 2; // Indicate we are resolving the foundation sprites
6eb541d75e51 (svn r18708) -Feature: [NewGRF] Add support for custom station foundation graphics.
peter1138 <peter1138@openttd.org>
parents: 14134
diff changeset
751
6eb541d75e51 (svn r18708) -Feature: [NewGRF] Add support for custom station foundation graphics.
peter1138 <peter1138@openttd.org>
parents: 14134
diff changeset
752 group = ResolveStation(&object);
6eb541d75e51 (svn r18708) -Feature: [NewGRF] Add support for custom station foundation graphics.
peter1138 <peter1138@openttd.org>
parents: 14134
diff changeset
753 if (group == NULL || group->type != SGT_RESULT) return 0;
6eb541d75e51 (svn r18708) -Feature: [NewGRF] Add support for custom station foundation graphics.
peter1138 <peter1138@openttd.org>
parents: 14134
diff changeset
754 return group->GetResult() + GetRegister(0x100);
6eb541d75e51 (svn r18708) -Feature: [NewGRF] Add support for custom station foundation graphics.
peter1138 <peter1138@openttd.org>
parents: 14134
diff changeset
755 }
6eb541d75e51 (svn r18708) -Feature: [NewGRF] Add support for custom station foundation graphics.
peter1138 <peter1138@openttd.org>
parents: 14134
diff changeset
756
6eb541d75e51 (svn r18708) -Feature: [NewGRF] Add support for custom station foundation graphics.
peter1138 <peter1138@openttd.org>
parents: 14134
diff changeset
757
12425
d9e9b7477507 (svn r16859) -Codechange: split the Station struct into two so parts of it can be reused for Waypoints.
rubidium <rubidium@openttd.org>
parents: 12418
diff changeset
758 uint16 GetStationCallback(CallbackID callback, uint32 param1, uint32 param2, const StationSpec *statspec, const BaseStation *st, TileIndex tile)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
759 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
760 const SpriteGroup *group;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
761 ResolverObject object;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
762
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
763 NewStationResolver(&object, statspec, st, tile);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
764
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
765 object.callback = callback;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
766 object.callback_param1 = param1;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
767 object.callback_param2 = param2;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
768
5849
de5286746a3a (svn r8423) -Fix
tron <tron@openttd.org>
parents: 5825
diff changeset
769 group = ResolveStation(&object);
11990
db0e49f419d9 (svn r16396) -Codechange: split NewGRF spritegroup into multiple subclasses instead of using a big union
rubidium <rubidium@openttd.org>
parents: 11586
diff changeset
770 if (group == NULL) return CALLBACK_FAILED;
db0e49f419d9 (svn r16396) -Codechange: split NewGRF spritegroup into multiple subclasses instead of using a big union
rubidium <rubidium@openttd.org>
parents: 11586
diff changeset
771 return group->GetCallbackResult();
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
772 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
773
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
774
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
775 /**
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
776 * Allocate a StationSpec to a Station. This is called once per build operation.
6481
85a1a79387a2 (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas <belugas@openttd.org>
parents: 6460
diff changeset
777 * @param statspec StationSpec to allocate.
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
778 * @param st Station to allocate it to.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
779 * @param exec Whether to actually allocate the spec.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
780 * @return Index within the Station's spec list, or -1 if the allocation failed.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
781 */
12462
4dd085f22d88 (svn r16896) -Codechange: make station spec allocation and station animation functions work for both stations and waypoints
rubidium <rubidium@openttd.org>
parents: 12454
diff changeset
782 int AllocateSpecToStation(const StationSpec *statspec, BaseStation *st, bool exec)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
783 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
784 uint i;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
785
9038
6e86ab2cba9f (svn r12857) -Fix [FS#1948]: remove the last uses of AutoPtr in the station code.
rubidium <rubidium@openttd.org>
parents: 9018
diff changeset
786 if (statspec == NULL || st == NULL) return 0;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
787
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
788 for (i = 1; i < st->num_specs && i < MAX_SPECLIST; i++) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
789 if (st->speclist[i].spec == NULL && st->speclist[i].grfid == 0) break;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
790 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
791
10654
2ee530966ead (svn r14956) -Fix [FS#1832]: building new station parts didn't allocate a new station spec effectively breaking variable 41. This was due to the limited number of station specs that we can have per station. This fix makes newly build station parts create a new spec until one cannot allocate new station specs anymore and it'll revert to the old behaviour (sharing station specs).
rubidium <rubidium@openttd.org>
parents: 10647
diff changeset
792 if (i == MAX_SPECLIST) {
2ee530966ead (svn r14956) -Fix [FS#1832]: building new station parts didn't allocate a new station spec effectively breaking variable 41. This was due to the limited number of station specs that we can have per station. This fix makes newly build station parts create a new spec until one cannot allocate new station specs anymore and it'll revert to the old behaviour (sharing station specs).
rubidium <rubidium@openttd.org>
parents: 10647
diff changeset
793 /* As final effort when the spec list is already full...
2ee530966ead (svn r14956) -Fix [FS#1832]: building new station parts didn't allocate a new station spec effectively breaking variable 41. This was due to the limited number of station specs that we can have per station. This fix makes newly build station parts create a new spec until one cannot allocate new station specs anymore and it'll revert to the old behaviour (sharing station specs).
rubidium <rubidium@openttd.org>
parents: 10647
diff changeset
794 * try to find the same spec and return that one. This might
2ee530966ead (svn r14956) -Fix [FS#1832]: building new station parts didn't allocate a new station spec effectively breaking variable 41. This was due to the limited number of station specs that we can have per station. This fix makes newly build station parts create a new spec until one cannot allocate new station specs anymore and it'll revert to the old behaviour (sharing station specs).
rubidium <rubidium@openttd.org>
parents: 10647
diff changeset
795 * result in slighty "wrong" (as per specs) looking stations,
2ee530966ead (svn r14956) -Fix [FS#1832]: building new station parts didn't allocate a new station spec effectively breaking variable 41. This was due to the limited number of station specs that we can have per station. This fix makes newly build station parts create a new spec until one cannot allocate new station specs anymore and it'll revert to the old behaviour (sharing station specs).
rubidium <rubidium@openttd.org>
parents: 10647
diff changeset
796 * but it's fairly unlikely that one reaches the limit anyways.
2ee530966ead (svn r14956) -Fix [FS#1832]: building new station parts didn't allocate a new station spec effectively breaking variable 41. This was due to the limited number of station specs that we can have per station. This fix makes newly build station parts create a new spec until one cannot allocate new station specs anymore and it'll revert to the old behaviour (sharing station specs).
rubidium <rubidium@openttd.org>
parents: 10647
diff changeset
797 */
2ee530966ead (svn r14956) -Fix [FS#1832]: building new station parts didn't allocate a new station spec effectively breaking variable 41. This was due to the limited number of station specs that we can have per station. This fix makes newly build station parts create a new spec until one cannot allocate new station specs anymore and it'll revert to the old behaviour (sharing station specs).
rubidium <rubidium@openttd.org>
parents: 10647
diff changeset
798 for (i = 1; i < st->num_specs && i < MAX_SPECLIST; i++) {
2ee530966ead (svn r14956) -Fix [FS#1832]: building new station parts didn't allocate a new station spec effectively breaking variable 41. This was due to the limited number of station specs that we can have per station. This fix makes newly build station parts create a new spec until one cannot allocate new station specs anymore and it'll revert to the old behaviour (sharing station specs).
rubidium <rubidium@openttd.org>
parents: 10647
diff changeset
799 if (st->speclist[i].spec == statspec) return i;
2ee530966ead (svn r14956) -Fix [FS#1832]: building new station parts didn't allocate a new station spec effectively breaking variable 41. This was due to the limited number of station specs that we can have per station. This fix makes newly build station parts create a new spec until one cannot allocate new station specs anymore and it'll revert to the old behaviour (sharing station specs).
rubidium <rubidium@openttd.org>
parents: 10647
diff changeset
800 }
2ee530966ead (svn r14956) -Fix [FS#1832]: building new station parts didn't allocate a new station spec effectively breaking variable 41. This was due to the limited number of station specs that we can have per station. This fix makes newly build station parts create a new spec until one cannot allocate new station specs anymore and it'll revert to the old behaviour (sharing station specs).
rubidium <rubidium@openttd.org>
parents: 10647
diff changeset
801
2ee530966ead (svn r14956) -Fix [FS#1832]: building new station parts didn't allocate a new station spec effectively breaking variable 41. This was due to the limited number of station specs that we can have per station. This fix makes newly build station parts create a new spec until one cannot allocate new station specs anymore and it'll revert to the old behaviour (sharing station specs).
rubidium <rubidium@openttd.org>
parents: 10647
diff changeset
802 return -1;
2ee530966ead (svn r14956) -Fix [FS#1832]: building new station parts didn't allocate a new station spec effectively breaking variable 41. This was due to the limited number of station specs that we can have per station. This fix makes newly build station parts create a new spec until one cannot allocate new station specs anymore and it'll revert to the old behaviour (sharing station specs).
rubidium <rubidium@openttd.org>
parents: 10647
diff changeset
803 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
804
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
805 if (exec) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
806 if (i >= st->num_specs) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
807 st->num_specs = i + 1;
5609
358c07fb3212 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr <KUDr@openttd.org>
parents: 5587
diff changeset
808 st->speclist = ReallocT(st->speclist, st->num_specs);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
809
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
810 if (st->num_specs == 2) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
811 /* Initial allocation */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
812 st->speclist[0].spec = NULL;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
813 st->speclist[0].grfid = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
814 st->speclist[0].localidx = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
815 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
816 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
817
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
818 st->speclist[i].spec = statspec;
6451
25c7793c8d9a (svn r9601) -Codechange: Store grf file reference in station spec, not just GRF ID
peter1138 <peter1138@openttd.org>
parents: 6357
diff changeset
819 st->speclist[i].grfid = statspec->grffile->grfid;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
820 st->speclist[i].localidx = statspec->localidx;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
821 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
822
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
823 return i;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
824 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
825
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
826
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
827 /** Deallocate a StationSpec from a Station. Called when removing a single station tile.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
828 * @param st Station to work with.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
829 * @param specindex Index of the custom station within the Station's spec list.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
830 * @return Indicates whether the StationSpec was deallocated.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
831 */
12462
4dd085f22d88 (svn r16896) -Codechange: make station spec allocation and station animation functions work for both stations and waypoints
rubidium <rubidium@openttd.org>
parents: 12454
diff changeset
832 void DeallocateSpecFromStation(BaseStation *st, byte specindex)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
833 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
834 /* specindex of 0 (default) is never freeable */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
835 if (specindex == 0) return;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
836
12462
4dd085f22d88 (svn r16896) -Codechange: make station spec allocation and station animation functions work for both stations and waypoints
rubidium <rubidium@openttd.org>
parents: 12454
diff changeset
837 ETileArea area = ETileArea(st, INVALID_TILE, TA_WHOLE);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
838 /* Check all tiles over the station to check if the specindex is still in use */
14170
31fbd9c51a5f (svn r18718) -Codechange: make a wrapper macro for looping TileAreas
rubidium <rubidium@openttd.org>
parents: 14160
diff changeset
839 TILE_AREA_LOOP(tile, area) {
12607
58a2a1840d79 (svn r17050) -Codechange: replace custom implementation of TILE_LOOP with TILE_LOOP.
rubidium <rubidium@openttd.org>
parents: 12510
diff changeset
840 if (st->TileBelongsToRailStation(tile) && GetCustomStationSpecIndex(tile) == specindex) {
58a2a1840d79 (svn r17050) -Codechange: replace custom implementation of TILE_LOOP with TILE_LOOP.
rubidium <rubidium@openttd.org>
parents: 12510
diff changeset
841 return;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
842 }
12462
4dd085f22d88 (svn r16896) -Codechange: make station spec allocation and station animation functions work for both stations and waypoints
rubidium <rubidium@openttd.org>
parents: 12454
diff changeset
843 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
844
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
845 /* This specindex is no longer in use, so deallocate it */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
846 st->speclist[specindex].spec = NULL;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
847 st->speclist[specindex].grfid = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
848 st->speclist[specindex].localidx = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
849
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
850 /* If this was the highest spec index, reallocate */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
851 if (specindex == st->num_specs - 1) {
8695
9ee0730039f4 (svn r12368) -Codechange: use explicit body for loops and conditions and remove -Wno-empty-body from the configure script
smatz <smatz@openttd.org>
parents: 8616
diff changeset
852 for (; st->speclist[st->num_specs - 1].grfid == 0 && st->num_specs > 1; st->num_specs--) {}
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
853
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
854 if (st->num_specs > 1) {
5609
358c07fb3212 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr <KUDr@openttd.org>
parents: 5587
diff changeset
855 st->speclist = ReallocT(st->speclist, st->num_specs);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
856 } else {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
857 free(st->speclist);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
858 st->num_specs = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
859 st->speclist = NULL;
9003
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
860 st->cached_anim_triggers = 0;
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
861 return;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
862 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
863 }
9003
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
864
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
865 StationUpdateAnimTriggers(st);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
866 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
867
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
868 /** Draw representation of a station tile for GUI purposes.
6481
85a1a79387a2 (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas <belugas@openttd.org>
parents: 6460
diff changeset
869 * @param x Position x of image.
85a1a79387a2 (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas <belugas@openttd.org>
parents: 6460
diff changeset
870 * @param y Position y of image.
85a1a79387a2 (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas <belugas@openttd.org>
parents: 6460
diff changeset
871 * @param axis Axis.
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
872 * @param railtype Rail type.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
873 * @param sclass, station Type of station.
6481
85a1a79387a2 (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas <belugas@openttd.org>
parents: 6460
diff changeset
874 * @param station station ID
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
875 * @return True if the tile was drawn (allows for fallback to default graphic)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
876 */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
877 bool DrawStationTile(int x, int y, RailType railtype, Axis axis, StationClassID sclass, uint station)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
878 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
879 const StationSpec *statspec;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
880 const DrawTileSprites *sprites;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
881 const RailtypeInfo *rti = GetRailTypeInfo(railtype);
11085
8da1855e9f14 (svn r15428) -Codechange: consistently use colour instead of having both color and colour.
rubidium <rubidium@openttd.org>
parents: 10960
diff changeset
882 SpriteID palette = COMPANY_SPRITE_COLOUR(_local_company);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
883 uint tile = 2;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
884
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
885 statspec = GetCustomStationSpec(sclass, station);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
886 if (statspec == NULL) return false;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
887
14287
5b16d3caeef6 (svn r18839) -Codechange: Detriplicate drawing of spritelayouts in the GUI.
frosch <frosch@openttd.org>
parents: 14258
diff changeset
888 uint relocation = GetCustomStationRelocation(statspec, NULL, INVALID_TILE);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
889
13036
8e2a0e8fa275 (svn r17534) -Codechange: unify the naming of callback masks/flags
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
890 if (HasBit(statspec->callback_mask, CBM_STATION_SPRITE_LAYOUT)) {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
891 uint16 callback = GetStationCallback(CBID_STATION_SPRITE_LAYOUT, 0x2110000, 0, statspec, NULL, INVALID_TILE);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
892 if (callback != CALLBACK_FAILED) tile = callback;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
893 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
894
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
895 if (statspec->renderdata == NULL) {
7272
dc7fb38ec443 (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium <rubidium@openttd.org>
parents: 7230
diff changeset
896 sprites = GetStationTileLayout(STATION_RAIL, tile + axis);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
897 } else {
5587
c44c070c5032 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium <rubidium@openttd.org>
parents: 5584
diff changeset
898 sprites = &statspec->renderdata[(tile < statspec->tiles) ? tile + axis : (uint)axis];
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
899 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
900
14287
5b16d3caeef6 (svn r18839) -Codechange: Detriplicate drawing of spritelayouts in the GUI.
frosch <frosch@openttd.org>
parents: 14258
diff changeset
901 SpriteID image = sprites->ground.sprite;
10355
f8ae3c876003 (svn r14606) -Codechange: Unify usage of PALETTE_MODIFIER_TRANSPARENT and PALETTE_MODIFIER_COLOR in spritelayout drawing.
frosch <frosch@openttd.org>
parents: 10256
diff changeset
902 SpriteID pal = sprites->ground.pal;
7928
4e8dfd103163 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents: 7922
diff changeset
903 if (HasBit(image, SPRITE_MODIFIER_USE_OFFSET)) {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
904 image += GetCustomStationGroundRelocation(statspec, NULL, INVALID_TILE);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
905 image += rti->custom_ground_offset;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
906 } else {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
907 image += rti->total_offset;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
908 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
909
10355
f8ae3c876003 (svn r14606) -Codechange: Unify usage of PALETTE_MODIFIER_TRANSPARENT and PALETTE_MODIFIER_COLOR in spritelayout drawing.
frosch <frosch@openttd.org>
parents: 10256
diff changeset
910 DrawSprite(image, GroundSpritePaletteTransform(image, pal, palette), x, y);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
911
14287
5b16d3caeef6 (svn r18839) -Codechange: Detriplicate drawing of spritelayouts in the GUI.
frosch <frosch@openttd.org>
parents: 14258
diff changeset
912 DrawCommonTileSeqInGUI(x, y, sprites, rti->total_offset, relocation, palette);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
913
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
914 return true;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
915 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
916
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
917
9714
cb9766ae1255 (svn r13830) -Feature: show additional NewGRF info in the Tile Info window for stations, houses and industries
smatz <smatz@openttd.org>
parents: 9662
diff changeset
918 const StationSpec *GetStationSpec(TileIndex t)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
919 {
12472
604a2cfc77ab (svn r16909) -Fix [FS#2996]: NewGRF stations would be triggering assertions all over the place when using the more advanced station types.
rubidium <rubidium@openttd.org>
parents: 12471
diff changeset
920 if (!IsCustomStationSpecIndex(t)) return NULL;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
921
12472
604a2cfc77ab (svn r16909) -Fix [FS#2996]: NewGRF stations would be triggering assertions all over the place when using the more advanced station types.
rubidium <rubidium@openttd.org>
parents: 12471
diff changeset
922 const BaseStation *st = BaseStation::GetByTile(t);
604a2cfc77ab (svn r16909) -Fix [FS#2996]: NewGRF stations would be triggering assertions all over the place when using the more advanced station types.
rubidium <rubidium@openttd.org>
parents: 12471
diff changeset
923 uint specindex = GetCustomStationSpecIndex(t);
604a2cfc77ab (svn r16909) -Fix [FS#2996]: NewGRF stations would be triggering assertions all over the place when using the more advanced station types.
rubidium <rubidium@openttd.org>
parents: 12471
diff changeset
924 return specindex < st->num_specs ? st->speclist[specindex].spec : NULL;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
925 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
926
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
927
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
928 /* Check if a rail station tile is traversable.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
929 * XXX This could be cached (during build) in the map array to save on all the dereferencing */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
930 bool IsStationTileBlocked(TileIndex tile)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
931 {
10647
592ae9307430 (svn r14949) -Cleanup: pointer coding style
rubidium <rubidium@openttd.org>
parents: 10355
diff changeset
932 const StationSpec *statspec = GetStationSpec(tile);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
933
7928
4e8dfd103163 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents: 7922
diff changeset
934 return statspec != NULL && HasBit(statspec->blocked, GetStationGfx(tile));
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
935 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
936
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
937 /* Check if a rail station tile is electrifiable.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
938 * XXX This could be cached (during build) in the map array to save on all the dereferencing */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
939 bool IsStationTileElectrifiable(TileIndex tile)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
940 {
10647
592ae9307430 (svn r14949) -Cleanup: pointer coding style
rubidium <rubidium@openttd.org>
parents: 10355
diff changeset
941 const StationSpec *statspec = GetStationSpec(tile);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
942
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
943 return
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
944 statspec == NULL ||
7928
4e8dfd103163 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents: 7922
diff changeset
945 HasBit(statspec->pylons, GetStationGfx(tile)) ||
4e8dfd103163 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents: 7922
diff changeset
946 !HasBit(statspec->wires, GetStationGfx(tile));
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
947 }
9003
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
948
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
949 void AnimateStationTile(TileIndex tile)
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
950 {
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
951 const StationSpec *ss = GetStationSpec(tile);
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
952 if (ss == NULL) return;
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
953
12425
d9e9b7477507 (svn r16859) -Codechange: split the Station struct into two so parts of it can be reused for Waypoints.
rubidium <rubidium@openttd.org>
parents: 12418
diff changeset
954 const BaseStation *st = BaseStation::GetByTile(tile);
9003
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
955
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
956 uint8 animation_speed = ss->anim_speed;
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
957
13036
8e2a0e8fa275 (svn r17534) -Codechange: unify the naming of callback masks/flags
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
958 if (HasBit(ss->callback_mask, CBM_STATION_ANIMATION_SPEED)) {
9003
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
959 uint16 callback = GetStationCallback(CBID_STATION_ANIMATION_SPEED, 0, 0, ss, st, tile);
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
960 if (callback != CALLBACK_FAILED) animation_speed = Clamp(callback & 0xFF, 0, 16);
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
961 }
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
962
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
963 if (_tick_counter % (1 << animation_speed) != 0) return;
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
964
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
965 uint8 frame = GetStationAnimationFrame(tile);
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
966 uint8 num_frames = ss->anim_frames;
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
967
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
968 bool frame_set_by_callback = false;
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
969
13036
8e2a0e8fa275 (svn r17534) -Codechange: unify the naming of callback masks/flags
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
970 if (HasBit(ss->callback_mask, CBM_STATION_ANIMATION_NEXT_FRAME)) {
11585
a5688eed8d7a (svn r15956) -Codechange: Enumorize station spec flags.
peter1138 <peter1138@openttd.org>
parents: 11091
diff changeset
971 uint32 param = HasBit(ss->flags, SSF_CB141_RANDOM_BITS) ? Random() : 0;
9003
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
972 uint16 callback = GetStationCallback(CBID_STATION_ANIM_NEXT_FRAME, param, 0, ss, st, tile);
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
973
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
974 if (callback != CALLBACK_FAILED) {
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
975 frame_set_by_callback = true;
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
976
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
977 switch (callback & 0xFF) {
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
978 case 0xFF:
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
979 DeleteAnimatedTile(tile);
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
980 break;
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
981
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
982 case 0xFE:
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
983 frame_set_by_callback = false;
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
984 break;
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
985
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
986 default:
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
987 frame = callback & 0xFF;
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
988 break;
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
989 }
9018
9dcf32675eb5 (svn r12817) -Feature: the ability to play NewGRF sounds for industries and stations.
rubidium <rubidium@openttd.org>
parents: 9006
diff changeset
990
9dcf32675eb5 (svn r12817) -Feature: the ability to play NewGRF sounds for industries and stations.
rubidium <rubidium@openttd.org>
parents: 9006
diff changeset
991 /* If the lower 7 bits of the upper byte of the callback
9dcf32675eb5 (svn r12817) -Feature: the ability to play NewGRF sounds for industries and stations.
rubidium <rubidium@openttd.org>
parents: 9006
diff changeset
992 * result are not empty, it is a sound effect. */
9dcf32675eb5 (svn r12817) -Feature: the ability to play NewGRF sounds for industries and stations.
rubidium <rubidium@openttd.org>
parents: 9006
diff changeset
993 if (GB(callback, 8, 7) != 0) PlayTileSound(ss->grffile, GB(callback, 8, 7), tile);
9003
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
994 }
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
995 }
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
996
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
997 if (!frame_set_by_callback) {
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
998 if (frame < num_frames) {
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
999 frame++;
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1000 } else if (frame == num_frames && HasBit(ss->anim_status, 0)) {
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1001 /* This animation loops, so start again from the beginning */
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1002 frame = 0;
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1003 } else {
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1004 /* This animation doesn't loop, so stay here */
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1005 DeleteAnimatedTile(tile);
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1006 }
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1007 }
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1008
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1009 SetStationAnimationFrame(tile, frame);
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1010 MarkTileDirtyByTile(tile);
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1011 }
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1012
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1013
12425
d9e9b7477507 (svn r16859) -Codechange: split the Station struct into two so parts of it can be reused for Waypoints.
rubidium <rubidium@openttd.org>
parents: 12418
diff changeset
1014 static void ChangeStationAnimationFrame(const StationSpec *ss, const BaseStation *st, TileIndex tile, uint16 random_bits, StatAnimTrigger trigger, CargoID cargo_type)
9003
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1015 {
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1016 uint16 callback = GetStationCallback(CBID_STATION_ANIM_START_STOP, (random_bits << 16) | Random(), (uint8)trigger | (cargo_type << 8), ss, st, tile);
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1017 if (callback == CALLBACK_FAILED) return;
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1018
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1019 switch (callback & 0xFF) {
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1020 case 0xFD: /* Do nothing. */ break;
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1021 case 0xFE: AddAnimatedTile(tile); break;
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1022 case 0xFF: DeleteAnimatedTile(tile); break;
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1023 default:
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1024 SetStationAnimationFrame(tile, callback);
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1025 AddAnimatedTile(tile);
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1026 break;
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1027 }
9018
9dcf32675eb5 (svn r12817) -Feature: the ability to play NewGRF sounds for industries and stations.
rubidium <rubidium@openttd.org>
parents: 9006
diff changeset
1028
9dcf32675eb5 (svn r12817) -Feature: the ability to play NewGRF sounds for industries and stations.
rubidium <rubidium@openttd.org>
parents: 9006
diff changeset
1029 /* If the lower 7 bits of the upper byte of the callback
9dcf32675eb5 (svn r12817) -Feature: the ability to play NewGRF sounds for industries and stations.
rubidium <rubidium@openttd.org>
parents: 9006
diff changeset
1030 * result are not empty, it is a sound effect. */
9dcf32675eb5 (svn r12817) -Feature: the ability to play NewGRF sounds for industries and stations.
rubidium <rubidium@openttd.org>
parents: 9006
diff changeset
1031 if (GB(callback, 8, 7) != 0) PlayTileSound(ss->grffile, GB(callback, 8, 7), tile);
9003
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1032 }
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1033
12425
d9e9b7477507 (svn r16859) -Codechange: split the Station struct into two so parts of it can be reused for Waypoints.
rubidium <rubidium@openttd.org>
parents: 12418
diff changeset
1034 void StationAnimationTrigger(const BaseStation *st, TileIndex tile, StatAnimTrigger trigger, CargoID cargo_type)
9003
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1035 {
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1036 /* List of coverage areas for each animation trigger */
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1037 static const TriggerArea tas[] = {
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1038 TA_TILE, TA_WHOLE, TA_WHOLE, TA_PLATFORM, TA_PLATFORM, TA_PLATFORM, TA_WHOLE
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1039 };
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1040
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1041 /* Get Station if it wasn't supplied */
12425
d9e9b7477507 (svn r16859) -Codechange: split the Station struct into two so parts of it can be reused for Waypoints.
rubidium <rubidium@openttd.org>
parents: 12418
diff changeset
1042 if (st == NULL) st = BaseStation::GetByTile(tile);
9003
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1043
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1044 /* Check the cached animation trigger bitmask to see if we need
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1045 * to bother with any further processing. */
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1046 if (!HasBit(st->cached_anim_triggers, trigger)) return;
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1047
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1048 uint16 random_bits = Random();
12462
4dd085f22d88 (svn r16896) -Codechange: make station spec allocation and station animation functions work for both stations and waypoints
rubidium <rubidium@openttd.org>
parents: 12454
diff changeset
1049 ETileArea area = ETileArea(st, tile, tas[trigger]);
9003
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1050
12462
4dd085f22d88 (svn r16896) -Codechange: make station spec allocation and station animation functions work for both stations and waypoints
rubidium <rubidium@openttd.org>
parents: 12454
diff changeset
1051 /* Check all tiles over the station to check if the specindex is still in use */
14170
31fbd9c51a5f (svn r18718) -Codechange: make a wrapper macro for looping TileAreas
rubidium <rubidium@openttd.org>
parents: 14160
diff changeset
1052 TILE_AREA_LOOP(tile, area) {
14134
848cca01530a (svn r18681) -Codechange: Use existing TILE_LOOP method for iterating trigger area.
peter1138 <peter1138@openttd.org>
parents: 14133
diff changeset
1053 if (st->TileBelongsToRailStation(tile)) {
848cca01530a (svn r18681) -Codechange: Use existing TILE_LOOP method for iterating trigger area.
peter1138 <peter1138@openttd.org>
parents: 14133
diff changeset
1054 const StationSpec *ss = GetStationSpec(tile);
848cca01530a (svn r18681) -Codechange: Use existing TILE_LOOP method for iterating trigger area.
peter1138 <peter1138@openttd.org>
parents: 14133
diff changeset
1055 if (ss != NULL && HasBit(ss->anim_triggers, trigger)) {
848cca01530a (svn r18681) -Codechange: Use existing TILE_LOOP method for iterating trigger area.
peter1138 <peter1138@openttd.org>
parents: 14133
diff changeset
1056 CargoID cargo;
848cca01530a (svn r18681) -Codechange: Use existing TILE_LOOP method for iterating trigger area.
peter1138 <peter1138@openttd.org>
parents: 14133
diff changeset
1057 if (cargo_type == CT_INVALID) {
848cca01530a (svn r18681) -Codechange: Use existing TILE_LOOP method for iterating trigger area.
peter1138 <peter1138@openttd.org>
parents: 14133
diff changeset
1058 cargo = CT_INVALID;
848cca01530a (svn r18681) -Codechange: Use existing TILE_LOOP method for iterating trigger area.
peter1138 <peter1138@openttd.org>
parents: 14133
diff changeset
1059 } else {
848cca01530a (svn r18681) -Codechange: Use existing TILE_LOOP method for iterating trigger area.
peter1138 <peter1138@openttd.org>
parents: 14133
diff changeset
1060 cargo = GetReverseCargoTranslation(cargo_type, ss->grffile);
9003
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1061 }
14134
848cca01530a (svn r18681) -Codechange: Use existing TILE_LOOP method for iterating trigger area.
peter1138 <peter1138@openttd.org>
parents: 14133
diff changeset
1062 ChangeStationAnimationFrame(ss, st, tile, random_bits, trigger, cargo);
9003
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1063 }
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1064 }
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1065 }
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1066 }
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1067
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1068 /**
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1069 * Update the cached animation trigger bitmask for a station.
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1070 * @param st Station to update.
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1071 */
12425
d9e9b7477507 (svn r16859) -Codechange: split the Station struct into two so parts of it can be reused for Waypoints.
rubidium <rubidium@openttd.org>
parents: 12418
diff changeset
1072 void StationUpdateAnimTriggers(BaseStation *st)
9003
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1073 {
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1074 st->cached_anim_triggers = 0;
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1075
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1076 /* Combine animation trigger bitmask for all station specs
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1077 * of this station. */
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1078 for (uint i = 0; i < st->num_specs; i++) {
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1079 const StationSpec *ss = st->speclist[i].spec;
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1080 if (ss != NULL) st->cached_anim_triggers |= ss->anim_triggers;
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1081 }
ac23e012c9d7 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138 <peter1138@openttd.org>
parents: 8956
diff changeset
1082 }