annotate src/newgrf_engine.cpp @ 17564:d5ff867052a5 draft

(svn r22328) -Add: a flag to GroundVehicles to disable insertion and removal of automatic orders until the next real order is reached.
author frosch <frosch@openttd.org>
date Sat, 16 Apr 2011 16:45:35 +0000
parents b590eca5d805
children 2d62fee43556
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: 12433
diff changeset
3 /*
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12433
diff changeset
4 * This file is part of OpenTTD.
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12433
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: 12433
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: 12433
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: 12433
diff changeset
8 */
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12433
diff changeset
9
9111
d48433370037 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium <rubidium@openttd.org>
parents: 9070
diff changeset
10 /** @file newgrf_engine.cpp NewGRF handling of engines. */
6348
bcf98ba27bbf (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents: 6259
diff changeset
11
5584
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 "debug.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 "train.h"
11984
b6d3e583be86 (svn r16390) -Codechange: move u.road to RoadVehicle.
rubidium <rubidium@openttd.org>
parents: 11982
diff changeset
15 #include "roadveh.h"
10208
39cf8eebfda5 (svn r14422) -Codechange: also reflect the changes of r14421 in the filenames.
rubidium <rubidium@openttd.org>
parents: 10207
diff changeset
16 #include "company_func.h"
12232
b5e93af93fc2 (svn r16647) -Codechange: remove newgrf.h include from newgrf_engine.h to prevent unnecessary inclusion newgrf.h anyway
yexo <yexo@openttd.org>
parents: 12228
diff changeset
17 #include "newgrf.h"
13466
a6e569a5cc14 (svn r17976) -Codechange: Move CargoClass to cargotype.h and clean up including of newgrf_cargo.h
frosch <frosch@openttd.org>
parents: 13186
diff changeset
18 #include "newgrf_cargo.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
19 #include "newgrf_spritegroup.h"
8140
fb8a05d579da (svn r11702) -Codechange: move all date related stuff to date*.
rubidium <rubidium@openttd.org>
parents: 8131
diff changeset
20 #include "date_func.h"
8144
d18c8a0bb638 (svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium <rubidium@openttd.org>
parents: 8140
diff changeset
21 #include "vehicle_func.h"
8213
87c85bb42d6f (svn r11776) -Codechange: more header splittings to reduce the dependencies.
rubidium <rubidium@openttd.org>
parents: 8198
diff changeset
22 #include "core/random_func.hpp"
10177
2748e8fea4a2 (svn r14383) -Fix [FS#2316](r14343): handle invalid 'v->u.air.targetairport' in the NewGRF code, too
smatz <smatz@openttd.org>
parents: 9750
diff changeset
23 #include "aircraft.h"
12228
240adc64d01a (svn r16643) -Codechange: replace GetStationByTile() by Station::GetByTile()
smatz <smatz@openttd.org>
parents: 12220
diff changeset
24 #include "station_base.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: 14213
diff changeset
25 #include "company_base.h"
15512
9129648e0ffd (svn r20165) -Feature: [NewGRF] Information (var 4A) about the current railtype a train is on.
michi_cc <michi_cc@openttd.org>
parents: 15457
diff changeset
26 #include "newgrf_railtype.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
27
6248
0789677a15a0 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents: 6247
diff changeset
28 struct WagonOverride {
8198
dbc8b8dbeda4 (svn r11761) -Codechange: Use appropriate variable types for NewGRF engine overrides, and adjust scope while there.
peter1138 <peter1138@openttd.org>
parents: 8193
diff changeset
29 EngineID *train_id;
dbc8b8dbeda4 (svn r11761) -Codechange: Use appropriate variable types for NewGRF engine overrides, and adjust scope while there.
peter1138 <peter1138@openttd.org>
parents: 8193
diff changeset
30 uint trains;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
31 CargoID cargo;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
32 const SpriteGroup *group;
6248
0789677a15a0 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents: 6247
diff changeset
33 };
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
34
8198
dbc8b8dbeda4 (svn r11761) -Codechange: Use appropriate variable types for NewGRF engine overrides, and adjust scope while there.
peter1138 <peter1138@openttd.org>
parents: 8193
diff changeset
35 void SetWagonOverrideSprites(EngineID engine, CargoID cargo, const SpriteGroup *group, EngineID *train_id, uint trains)
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 {
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11875
diff changeset
37 Engine *e = Engine::Get(engine);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
38 WagonOverride *wo;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
39
6157
e080eca511f9 (svn r8903) -Regression (r8891): CT_PURCHASE does apply to aircraft overrides...
peter1138 <peter1138@openttd.org>
parents: 6148
diff changeset
40 assert(cargo < NUM_CARGO + 2); // Include CT_DEFAULT and CT_PURCHASE pseudo cargos.
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
41
9070
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
42 e->overrides_count++;
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
43 e->overrides = ReallocT(e->overrides, e->overrides_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
44
9070
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
45 wo = &e->overrides[e->overrides_count - 1];
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
46 wo->group = group;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
47 wo->cargo = cargo;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
48 wo->trains = trains;
8198
dbc8b8dbeda4 (svn r11761) -Codechange: Use appropriate variable types for NewGRF engine overrides, and adjust scope while there.
peter1138 <peter1138@openttd.org>
parents: 8193
diff changeset
49 wo->train_id = MallocT<EngineID>(trains);
dbc8b8dbeda4 (svn r11761) -Codechange: Use appropriate variable types for NewGRF engine overrides, and adjust scope while there.
peter1138 <peter1138@openttd.org>
parents: 8193
diff changeset
50 memcpy(wo->train_id, train_id, trains * sizeof *train_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
51 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
52
8198
dbc8b8dbeda4 (svn r11761) -Codechange: Use appropriate variable types for NewGRF engine overrides, and adjust scope while there.
peter1138 <peter1138@openttd.org>
parents: 8193
diff changeset
53 const SpriteGroup *GetWagonOverrideSpriteSet(EngineID engine, CargoID cargo, EngineID overriding_engine)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
54 {
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11875
diff changeset
55 const Engine *e = Engine::Get(engine);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
56
6348
bcf98ba27bbf (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents: 6259
diff changeset
57 /* XXX: This could turn out to be a timesink on profiles. We could
bcf98ba27bbf (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents: 6259
diff changeset
58 * always just dedicate 65535 bytes for an [engine][train] trampoline
bcf98ba27bbf (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents: 6259
diff changeset
59 * for O(1). Or O(logMlogN) and searching binary tree or smt. like
bcf98ba27bbf (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents: 6259
diff changeset
60 * that. --pasky */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
61
9070
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
62 for (uint i = 0; i < e->overrides_count; i++) {
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
63 const WagonOverride *wo = &e->overrides[i];
6603
2124b871a178 (svn r9818) -Codechange: Cache wagon override sprite set whenever consist is changed, instead of 'recalculating' it every time it is used or just tested.
peter1138 <peter1138@openttd.org>
parents: 6589
diff changeset
64
2124b871a178 (svn r9818) -Codechange: Cache wagon override sprite set whenever consist is changed, instead of 'recalculating' it every time it is used or just tested.
peter1138 <peter1138@openttd.org>
parents: 6589
diff changeset
65 if (wo->cargo != cargo && wo->cargo != CT_DEFAULT) continue;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
66
8198
dbc8b8dbeda4 (svn r11761) -Codechange: Use appropriate variable types for NewGRF engine overrides, and adjust scope while there.
peter1138 <peter1138@openttd.org>
parents: 8193
diff changeset
67 for (uint j = 0; j < wo->trains; j++) {
6603
2124b871a178 (svn r9818) -Codechange: Cache wagon override sprite set whenever consist is changed, instead of 'recalculating' it every time it is used or just tested.
peter1138 <peter1138@openttd.org>
parents: 6589
diff changeset
68 if (wo->train_id[j] == overriding_engine) return wo->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
69 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
70 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
71 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
72 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
73
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
74 /**
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
75 * Unload all wagon override sprite groups.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
76 */
9070
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
77 void UnloadWagonOverrides(Engine *e)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
78 {
9070
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
79 for (uint i = 0; i < e->overrides_count; i++) {
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
80 WagonOverride *wo = &e->overrides[i];
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
81 free(wo->train_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
82 }
9070
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
83 free(e->overrides);
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
84 e->overrides_count = 0;
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
85 e->overrides = 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
86 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
87
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
88
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
89 void SetCustomEngineSprites(EngineID engine, byte cargo, 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
90 {
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11875
diff changeset
91 Engine *e = Engine::Get(engine);
15763
a60a50f29f64 (svn r20437) -Codechange: lets Engines use GRFFilePropsBase as well
rubidium <rubidium@openttd.org>
parents: 15620
diff changeset
92 assert(cargo < lengthof(e->grf_prop.spritegroup));
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
93
15763
a60a50f29f64 (svn r20437) -Codechange: lets Engines use GRFFilePropsBase as well
rubidium <rubidium@openttd.org>
parents: 15620
diff changeset
94 if (e->grf_prop.spritegroup[cargo] != 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 grfmsg(6, "SetCustomEngineSprites: engine %d cargo %d already has group -- replacing", engine, cargo);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
96 }
15763
a60a50f29f64 (svn r20437) -Codechange: lets Engines use GRFFilePropsBase as well
rubidium <rubidium@openttd.org>
parents: 15620
diff changeset
97 e->grf_prop.spritegroup[cargo] = 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
98 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
99
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
100
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
101 /**
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
102 * Tie a GRFFile entry to an engine, to allow us to retrieve GRF parameters
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
103 * etc during a game.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
104 * @param engine Engine ID to tie the GRFFile to.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
105 * @param file Pointer of GRFFile to tie.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
106 */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
107 void SetEngineGRF(EngineID engine, const GRFFile *file)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
108 {
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11875
diff changeset
109 Engine *e = Engine::Get(engine);
15763
a60a50f29f64 (svn r20437) -Codechange: lets Engines use GRFFilePropsBase as well
rubidium <rubidium@openttd.org>
parents: 15620
diff changeset
110 e->grf_prop.grffile = file;
5584
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
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
113
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
114 /**
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
115 * Retrieve the GRFFile tied to an engine
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
116 * @param engine Engine ID to retrieve.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
117 * @return Pointer to GRFFile.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
118 */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
119 const GRFFile *GetEngineGRF(EngineID engine)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
120 {
15763
a60a50f29f64 (svn r20437) -Codechange: lets Engines use GRFFilePropsBase as well
rubidium <rubidium@openttd.org>
parents: 15620
diff changeset
121 return Engine::Get(engine)->grf_prop.grffile;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
122 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
123
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
124
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
125 /**
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
126 * Retrieve the GRF ID of the GRFFile tied to an engine
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
127 * @param engine Engine ID to retrieve.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
128 * @return 32 bit GRFID value.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
129 */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
130 uint32 GetEngineGRFID(EngineID engine)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
131 {
11386
5c3e9447c441 (svn r15739) -Codechange: Expose GRF ID of engines in var action property 0x25.
peter1138 <peter1138@openttd.org>
parents: 11368
diff changeset
132 const GRFFile *file = GetEngineGRF(engine);
5c3e9447c441 (svn r15739) -Codechange: Expose GRF ID of engines in var action property 0x25.
peter1138 <peter1138@openttd.org>
parents: 11368
diff changeset
133 return file == NULL ? 0 : file->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
134 }
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
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
137 static int MapOldSubType(const Vehicle *v)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
138 {
12199
8e20cb543b87 (svn r16613) -Fix [NewGRF]: some of the var action 2 80+ variables contained wrong results due to OpenTTD codechanges
yexo <yexo@openttd.org>
parents: 12114
diff changeset
139 switch (v->type) {
8e20cb543b87 (svn r16613) -Fix [NewGRF]: some of the var action 2 80+ variables contained wrong results due to OpenTTD codechanges
yexo <yexo@openttd.org>
parents: 12114
diff changeset
140 case VEH_TRAIN:
12302
fc8e41f34b8c (svn r16719) -Codechange: make IsArticulatedPart(), IsTrainEngine(), IsTrainWagon(), IsMultiheaded(), EngineHasArticPart() and IsRearDualheaded() members of Train
smatz <smatz@openttd.org>
parents: 12301
diff changeset
141 if (Train::From(v)->IsEngine()) return 0;
12301
218a41d3d557 (svn r16718) -Codechange: make IsFreeWagon() member of Train
smatz <smatz@openttd.org>
parents: 12232
diff changeset
142 if (Train::From(v)->IsFreeWagon()) return 4;
12199
8e20cb543b87 (svn r16613) -Fix [NewGRF]: some of the var action 2 80+ variables contained wrong results due to OpenTTD codechanges
yexo <yexo@openttd.org>
parents: 12114
diff changeset
143 return 2;
8e20cb543b87 (svn r16613) -Fix [NewGRF]: some of the var action 2 80+ variables contained wrong results due to OpenTTD codechanges
yexo <yexo@openttd.org>
parents: 12114
diff changeset
144 case VEH_ROAD:
8e20cb543b87 (svn r16613) -Fix [NewGRF]: some of the var action 2 80+ variables contained wrong results due to OpenTTD codechanges
yexo <yexo@openttd.org>
parents: 12114
diff changeset
145 case VEH_SHIP: return 0;
8e20cb543b87 (svn r16613) -Fix [NewGRF]: some of the var action 2 80+ variables contained wrong results due to OpenTTD codechanges
yexo <yexo@openttd.org>
parents: 12114
diff changeset
146 case VEH_AIRCRAFT:
8e20cb543b87 (svn r16613) -Fix [NewGRF]: some of the var action 2 80+ variables contained wrong results due to OpenTTD codechanges
yexo <yexo@openttd.org>
parents: 12114
diff changeset
147 case VEH_DISASTER: return v->subtype;
8e20cb543b87 (svn r16613) -Fix [NewGRF]: some of the var action 2 80+ variables contained wrong results due to OpenTTD codechanges
yexo <yexo@openttd.org>
parents: 12114
diff changeset
148 case VEH_EFFECT: return v->subtype << 1;
8e20cb543b87 (svn r16613) -Fix [NewGRF]: some of the var action 2 80+ variables contained wrong results due to OpenTTD codechanges
yexo <yexo@openttd.org>
parents: 12114
diff changeset
149 default: NOT_REACHED();
8e20cb543b87 (svn r16613) -Fix [NewGRF]: some of the var action 2 80+ variables contained wrong results due to OpenTTD codechanges
yexo <yexo@openttd.org>
parents: 12114
diff changeset
150 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
151 }
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
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
154 /* TTDP style aircraft movement states for GRF Action 2 Var 0xE2 */
15185
418c3a29b00b (svn r19814) -Codechange: give some more unnamed enums a name, in case they consisted of unrelated values use static const (u)int
rubidium <rubidium@openttd.org>
parents: 15153
diff changeset
155 enum TTDPAircraftMovementStates {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
156 AMS_TTDP_HANGAR,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
157 AMS_TTDP_TO_HANGAR,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
158 AMS_TTDP_TO_PAD1,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
159 AMS_TTDP_TO_PAD2,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
160 AMS_TTDP_TO_PAD3,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
161 AMS_TTDP_TO_ENTRY_2_AND_3,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
162 AMS_TTDP_TO_ENTRY_2_AND_3_AND_H,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
163 AMS_TTDP_TO_JUNCTION,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
164 AMS_TTDP_LEAVE_RUNWAY,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
165 AMS_TTDP_TO_INWAY,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
166 AMS_TTDP_TO_RUNWAY,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
167 AMS_TTDP_TO_OUTWAY,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
168 AMS_TTDP_WAITING,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
169 AMS_TTDP_TAKEOFF,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
170 AMS_TTDP_TO_TAKEOFF,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
171 AMS_TTDP_CLIMBING,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
172 AMS_TTDP_FLIGHT_APPROACH,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
173 AMS_TTDP_UNUSED_0x11,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
174 AMS_TTDP_FLIGHT_TO_TOWER,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
175 AMS_TTDP_UNUSED_0x13,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
176 AMS_TTDP_FLIGHT_FINAL,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
177 AMS_TTDP_FLIGHT_DESCENT,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
178 AMS_TTDP_BRAKING,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
179 AMS_TTDP_HELI_TAKEOFF_AIRPORT,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
180 AMS_TTDP_HELI_TO_TAKEOFF_AIRPORT,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
181 AMS_TTDP_HELI_LAND_AIRPORT,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
182 AMS_TTDP_HELI_TAKEOFF_HELIPORT,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
183 AMS_TTDP_HELI_TO_TAKEOFF_HELIPORT,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
184 AMS_TTDP_HELI_LAND_HELIPORT,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
185 };
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
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
188 /**
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
189 * Map OTTD aircraft movement states to TTDPatch style movement states
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
190 * (VarAction 2 Variable 0xE2)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
191 */
11981
cf1aad9b971c (svn r16387) -Codechange: use Aircraft instead of Vehicle where appropriate
rubidium <rubidium@openttd.org>
parents: 11924
diff changeset
192 static byte MapAircraftMovementState(const Aircraft *v)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
193 {
10177
2748e8fea4a2 (svn r14383) -Fix [FS#2316](r14343): handle invalid 'v->u.air.targetairport' in the NewGRF code, too
smatz <smatz@openttd.org>
parents: 9750
diff changeset
194 const Station *st = GetTargetAirportIfValid(v);
2748e8fea4a2 (svn r14383) -Fix [FS#2316](r14343): handle invalid 'v->u.air.targetairport' in the NewGRF code, too
smatz <smatz@openttd.org>
parents: 9750
diff changeset
195 if (st == NULL) return AMS_TTDP_FLIGHT_TO_TOWER;
6912
d397e2eea1a2 (svn r10165) -Fix [FS#874]: crash when trying to get the aircraft movement state of an aircraft going to a just deleted airport.
rubidium <rubidium@openttd.org>
parents: 6857
diff changeset
196
14859
304d377a82af (svn r19455) -Codechange: split all airport information in Station to a seperate class
yexo <yexo@openttd.org>
parents: 14750
diff changeset
197 const AirportFTAClass *afc = st->airport.GetFTA();
11982
9add5306a01e (svn r16388) -Codechange: move u.air to Aircraft
rubidium <rubidium@openttd.org>
parents: 11981
diff changeset
198 uint16 amdflag = afc->MovingData(v->pos)->flag;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
199
11982
9add5306a01e (svn r16388) -Codechange: move u.air to Aircraft
rubidium <rubidium@openttd.org>
parents: 11981
diff changeset
200 switch (v->state) {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
201 case HANGAR:
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
202 /* The international airport is a special case as helicopters can land in
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
203 * front of the hanger. Helicopters also change their air.state to
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
204 * AMED_HELI_LOWER some time before actually descending. */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
205
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
206 /* This condition only occurs for helicopters, during descent,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
207 * to a landing by the hanger of an international airport. */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
208 if (amdflag & AMED_HELI_LOWER) return AMS_TTDP_HELI_LAND_AIRPORT;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
209
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
210 /* This condition only occurs for helicopters, before starting descent,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
211 * to a landing by the hanger of an international airport. */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
212 if (amdflag & AMED_SLOWTURN) return AMS_TTDP_FLIGHT_TO_TOWER;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
213
6348
bcf98ba27bbf (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents: 6259
diff changeset
214 /* The final two conditions apply to helicopters or aircraft.
bcf98ba27bbf (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents: 6259
diff changeset
215 * Has reached hanger? */
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 if (amdflag & AMED_EXACTPOS) return AMS_TTDP_HANGAR;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
217
6348
bcf98ba27bbf (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents: 6259
diff changeset
218 /* Still moving towards hanger. */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
219 return AMS_TTDP_TO_HANGAR;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
220
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
221 case TERM1:
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 (amdflag & AMED_EXACTPOS) return AMS_TTDP_TO_PAD1;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
223 return AMS_TTDP_TO_JUNCTION;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
224
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
225 case TERM2:
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
226 if (amdflag & AMED_EXACTPOS) return AMS_TTDP_TO_PAD2;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
227 return AMS_TTDP_TO_ENTRY_2_AND_3_AND_H;
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 case TERM3:
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
230 case TERM4:
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
231 case TERM5:
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
232 case TERM6:
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
233 case TERM7:
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
234 case TERM8:
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
235 /* TTDPatch only has 3 terminals, so treat these states the same */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
236 if (amdflag & AMED_EXACTPOS) return AMS_TTDP_TO_PAD3;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
237 return AMS_TTDP_TO_ENTRY_2_AND_3_AND_H;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
238
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
239 case HELIPAD1:
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
240 case HELIPAD2:
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
241 case HELIPAD3:
15802
c0e7e98fe4b7 (svn r20477) -Codechange: remove some airport-related constants/functions and add some documentation
yexo <yexo@openttd.org>
parents: 15763
diff changeset
242 /* Will only occur for helicopters.*/
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
243 if (amdflag & AMED_HELI_LOWER) return AMS_TTDP_HELI_LAND_AIRPORT; // Descending.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
244 if (amdflag & AMED_SLOWTURN) return AMS_TTDP_FLIGHT_TO_TOWER; // Still hasn't started descent.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
245 return AMS_TTDP_TO_JUNCTION; // On the ground.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
246
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
247 case TAKEOFF: // Moving to takeoff position.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
248 return AMS_TTDP_TO_OUTWAY;
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 case STARTTAKEOFF: // Accelerating down runway.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
251 return AMS_TTDP_TAKEOFF;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
252
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
253 case ENDTAKEOFF: // Ascent
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
254 return AMS_TTDP_CLIMBING;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
255
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
256 case HELITAKEOFF: // Helicopter is moving to take off position.
6020
266a75e54b50 (svn r8743) -Fix
tron <tron@openttd.org>
parents: 5924
diff changeset
257 if (afc->delta_z == 0) {
266a75e54b50 (svn r8743) -Fix
tron <tron@openttd.org>
parents: 5924
diff changeset
258 return amdflag & AMED_HELI_RAISE ?
266a75e54b50 (svn r8743) -Fix
tron <tron@openttd.org>
parents: 5924
diff changeset
259 AMS_TTDP_HELI_TAKEOFF_AIRPORT : AMS_TTDP_TO_JUNCTION;
266a75e54b50 (svn r8743) -Fix
tron <tron@openttd.org>
parents: 5924
diff changeset
260 } else {
266a75e54b50 (svn r8743) -Fix
tron <tron@openttd.org>
parents: 5924
diff changeset
261 return AMS_TTDP_HELI_TAKEOFF_HELIPORT;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
262 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
263
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
264 case FLYING:
6604
601751c6ba02 (svn r9819) -Codechange: Take account of AMED_HOLD in OTTD/TTDP state translation (bulb)
peter1138 <peter1138@openttd.org>
parents: 6603
diff changeset
265 return amdflag & AMED_HOLD ? AMS_TTDP_FLIGHT_APPROACH : AMS_TTDP_FLIGHT_TO_TOWER;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
266
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
267 case LANDING: // Descent
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
268 return AMS_TTDP_FLIGHT_DESCENT;
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 case ENDLANDING: // On the runway braking
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
271 if (amdflag & AMED_BRAKE) return AMS_TTDP_BRAKING;
6348
bcf98ba27bbf (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents: 6259
diff changeset
272 /* Landed - moving off runway */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
273 return AMS_TTDP_TO_INWAY;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
274
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
275 case HELILANDING:
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
276 case HELIENDLANDING: // Helicoptor is decending.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
277 if (amdflag & AMED_HELI_LOWER) {
6020
266a75e54b50 (svn r8743) -Fix
tron <tron@openttd.org>
parents: 5924
diff changeset
278 return afc->delta_z == 0 ?
266a75e54b50 (svn r8743) -Fix
tron <tron@openttd.org>
parents: 5924
diff changeset
279 AMS_TTDP_HELI_LAND_AIRPORT : AMS_TTDP_HELI_LAND_HELIPORT;
266a75e54b50 (svn r8743) -Fix
tron <tron@openttd.org>
parents: 5924
diff changeset
280 } else {
266a75e54b50 (svn r8743) -Fix
tron <tron@openttd.org>
parents: 5924
diff changeset
281 return AMS_TTDP_FLIGHT_TO_TOWER;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
282 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
283
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
284 default:
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
285 return AMS_TTDP_HANGAR;
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 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
288
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
289
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
290 /* TTDP style aircraft movement action for GRF Action 2 Var 0xE6 */
15185
418c3a29b00b (svn r19814) -Codechange: give some more unnamed enums a name, in case they consisted of unrelated values use static const (u)int
rubidium <rubidium@openttd.org>
parents: 15153
diff changeset
291 enum TTDPAircraftMovementActions {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
292 AMA_TTDP_IN_HANGAR,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
293 AMA_TTDP_ON_PAD1,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
294 AMA_TTDP_ON_PAD2,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
295 AMA_TTDP_ON_PAD3,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
296 AMA_TTDP_HANGAR_TO_PAD1,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
297 AMA_TTDP_HANGAR_TO_PAD2,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
298 AMA_TTDP_HANGAR_TO_PAD3,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
299 AMA_TTDP_LANDING_TO_PAD1,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
300 AMA_TTDP_LANDING_TO_PAD2,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
301 AMA_TTDP_LANDING_TO_PAD3,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
302 AMA_TTDP_PAD1_TO_HANGAR,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
303 AMA_TTDP_PAD2_TO_HANGAR,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
304 AMA_TTDP_PAD3_TO_HANGAR,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
305 AMA_TTDP_PAD1_TO_TAKEOFF,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
306 AMA_TTDP_PAD2_TO_TAKEOFF,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
307 AMA_TTDP_PAD3_TO_TAKEOFF,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
308 AMA_TTDP_HANGAR_TO_TAKOFF,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
309 AMA_TTDP_LANDING_TO_HANGAR,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
310 AMA_TTDP_IN_FLIGHT,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
311 };
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
312
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
313
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 * Map OTTD aircraft movement states to TTDPatch style movement actions
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
316 * (VarAction 2 Variable 0xE6)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
317 * This is not fully supported yet but it's enough for Planeset.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
318 */
11981
cf1aad9b971c (svn r16387) -Codechange: use Aircraft instead of Vehicle where appropriate
rubidium <rubidium@openttd.org>
parents: 11924
diff changeset
319 static byte MapAircraftMovementAction(const Aircraft *v)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
320 {
11982
9add5306a01e (svn r16388) -Codechange: move u.air to Aircraft
rubidium <rubidium@openttd.org>
parents: 11981
diff changeset
321 switch (v->state) {
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 case HANGAR:
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
323 return (v->cur_speed > 0) ? AMA_TTDP_LANDING_TO_HANGAR : AMA_TTDP_IN_HANGAR;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
324
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
325 case TERM1:
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
326 case HELIPAD1:
8836
890a77315801 (svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents: 8786
diff changeset
327 return (v->current_order.IsType(OT_LOADING)) ? AMA_TTDP_ON_PAD1 : AMA_TTDP_LANDING_TO_PAD1;
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 case TERM2:
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
330 case HELIPAD2:
8836
890a77315801 (svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents: 8786
diff changeset
331 return (v->current_order.IsType(OT_LOADING)) ? AMA_TTDP_ON_PAD2 : AMA_TTDP_LANDING_TO_PAD2;
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 case TERM3:
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
334 case TERM4:
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
335 case TERM5:
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
336 case TERM6:
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
337 case TERM7:
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
338 case TERM8:
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
339 case HELIPAD3:
8836
890a77315801 (svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents: 8786
diff changeset
340 return (v->current_order.IsType(OT_LOADING)) ? AMA_TTDP_ON_PAD3 : AMA_TTDP_LANDING_TO_PAD3;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
341
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
342 case TAKEOFF: // Moving to takeoff position
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
343 case STARTTAKEOFF: // Accelerating down runway
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
344 case ENDTAKEOFF: // Ascent
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
345 case HELITAKEOFF:
6348
bcf98ba27bbf (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents: 6259
diff changeset
346 /* @todo Need to find which terminal (or hanger) we've come from. How? */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
347 return AMA_TTDP_PAD1_TO_TAKEOFF;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
348
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
349 case FLYING:
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
350 return AMA_TTDP_IN_FLIGHT;
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 case LANDING: // Descent
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
353 case ENDLANDING: // On the runway braking
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
354 case HELILANDING:
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
355 case HELIENDLANDING:
6348
bcf98ba27bbf (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents: 6259
diff changeset
356 /* @todo Need to check terminal we're landing to. Is it known yet? */
8836
890a77315801 (svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents: 8786
diff changeset
357 return (v->current_order.IsType(OT_GOTO_DEPOT)) ?
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
358 AMA_TTDP_LANDING_TO_HANGAR : AMA_TTDP_LANDING_TO_PAD1;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
359
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
360 default:
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
361 return AMA_TTDP_IN_HANGAR;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
362 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
363 }
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 /* Vehicle 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
367 static inline const Vehicle *GRV(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 {
8756
ae0ec91bb55e (svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx <glx@openttd.org>
parents: 8666
diff changeset
369 switch (object->scope) {
ae0ec91bb55e (svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx <glx@openttd.org>
parents: 8666
diff changeset
370 default: NOT_REACHED();
ae0ec91bb55e (svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx <glx@openttd.org>
parents: 8666
diff changeset
371 case VSG_SCOPE_SELF: return object->u.vehicle.self;
ae0ec91bb55e (svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx <glx@openttd.org>
parents: 8666
diff changeset
372 case VSG_SCOPE_PARENT: return object->u.vehicle.parent;
ae0ec91bb55e (svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx <glx@openttd.org>
parents: 8666
diff changeset
373 case VSG_SCOPE_RELATIVE: {
15153
9aaf67d04ded (svn r19782) -Fix [FS#3828]: NULL pointer deference when testing relative scope *action2 on an unbuilt engine.
peter1138 <peter1138@openttd.org>
parents: 15132
diff changeset
374 if (object->u.vehicle.self == NULL) return NULL;
8758
f6add1d6e9ff (svn r12454) -Fix (r12452): incorrect calculation for 'first vehicle in this chain of vehicles with the same ID' (thx DaleStan)
glx <glx@openttd.org>
parents: 8756
diff changeset
375 const Vehicle *v = NULL;
8756
ae0ec91bb55e (svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx <glx@openttd.org>
parents: 8666
diff changeset
376 switch (GB(object->count, 6, 2)) {
ae0ec91bb55e (svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx <glx@openttd.org>
parents: 8666
diff changeset
377 default: NOT_REACHED();
ae0ec91bb55e (svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx <glx@openttd.org>
parents: 8666
diff changeset
378 case 0x00: // count back (away from the engine), starting at this vehicle
ae0ec91bb55e (svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx <glx@openttd.org>
parents: 8666
diff changeset
379 case 0x01: // count forward (toward the engine), starting at this vehicle
ae0ec91bb55e (svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx <glx@openttd.org>
parents: 8666
diff changeset
380 v = object->u.vehicle.self;
ae0ec91bb55e (svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx <glx@openttd.org>
parents: 8666
diff changeset
381 break;
ae0ec91bb55e (svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx <glx@openttd.org>
parents: 8666
diff changeset
382 case 0x02: // count back, starting at the engine
ae0ec91bb55e (svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx <glx@openttd.org>
parents: 8666
diff changeset
383 v = object->u.vehicle.parent;
ae0ec91bb55e (svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx <glx@openttd.org>
parents: 8666
diff changeset
384 break;
8758
f6add1d6e9ff (svn r12454) -Fix (r12452): incorrect calculation for 'first vehicle in this chain of vehicles with the same ID' (thx DaleStan)
glx <glx@openttd.org>
parents: 8756
diff changeset
385 case 0x03: { // count back, starting at the first vehicle in this chain of vehicles with the same ID, as for vehicle variable 41
f6add1d6e9ff (svn r12454) -Fix (r12452): incorrect calculation for 'first vehicle in this chain of vehicles with the same ID' (thx DaleStan)
glx <glx@openttd.org>
parents: 8756
diff changeset
386 const Vehicle *self = object->u.vehicle.self;
f6add1d6e9ff (svn r12454) -Fix (r12452): incorrect calculation for 'first vehicle in this chain of vehicles with the same ID' (thx DaleStan)
glx <glx@openttd.org>
parents: 8756
diff changeset
387 for (const Vehicle *u = self->First(); u != self; u = u->Next()) {
f6add1d6e9ff (svn r12454) -Fix (r12452): incorrect calculation for 'first vehicle in this chain of vehicles with the same ID' (thx DaleStan)
glx <glx@openttd.org>
parents: 8756
diff changeset
388 if (u->engine_type != self->engine_type) {
f6add1d6e9ff (svn r12454) -Fix (r12452): incorrect calculation for 'first vehicle in this chain of vehicles with the same ID' (thx DaleStan)
glx <glx@openttd.org>
parents: 8756
diff changeset
389 v = NULL;
f6add1d6e9ff (svn r12454) -Fix (r12452): incorrect calculation for 'first vehicle in this chain of vehicles with the same ID' (thx DaleStan)
glx <glx@openttd.org>
parents: 8756
diff changeset
390 } else {
f6add1d6e9ff (svn r12454) -Fix (r12452): incorrect calculation for 'first vehicle in this chain of vehicles with the same ID' (thx DaleStan)
glx <glx@openttd.org>
parents: 8756
diff changeset
391 if (v == NULL) v = u;
f6add1d6e9ff (svn r12454) -Fix (r12452): incorrect calculation for 'first vehicle in this chain of vehicles with the same ID' (thx DaleStan)
glx <glx@openttd.org>
parents: 8756
diff changeset
392 }
f6add1d6e9ff (svn r12454) -Fix (r12452): incorrect calculation for 'first vehicle in this chain of vehicles with the same ID' (thx DaleStan)
glx <glx@openttd.org>
parents: 8756
diff changeset
393 }
f6add1d6e9ff (svn r12454) -Fix (r12452): incorrect calculation for 'first vehicle in this chain of vehicles with the same ID' (thx DaleStan)
glx <glx@openttd.org>
parents: 8756
diff changeset
394 if (v == NULL) v = self;
15618
e4640748f223 (svn r20281) -Codechange: unify case scope closure + break coding style
rubidium <rubidium@openttd.org>
parents: 15540
diff changeset
395 break;
e4640748f223 (svn r20281) -Codechange: unify case scope closure + break coding style
rubidium <rubidium@openttd.org>
parents: 15540
diff changeset
396 }
8756
ae0ec91bb55e (svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx <glx@openttd.org>
parents: 8666
diff changeset
397 }
ae0ec91bb55e (svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx <glx@openttd.org>
parents: 8666
diff changeset
398 uint32 count = GB(object->count, 0, 4);
ae0ec91bb55e (svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx <glx@openttd.org>
parents: 8666
diff changeset
399 if (count == 0) count = GetRegister(0x100);
ae0ec91bb55e (svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx <glx@openttd.org>
parents: 8666
diff changeset
400 while (v != NULL && count-- != 0) v = (GB(object->count, 6, 2) == 0x01) ? v->Previous() : v->Next();
ae0ec91bb55e (svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx <glx@openttd.org>
parents: 8666
diff changeset
401 return v;
ae0ec91bb55e (svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx <glx@openttd.org>
parents: 8666
diff changeset
402 }
ae0ec91bb55e (svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx <glx@openttd.org>
parents: 8666
diff changeset
403 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
404 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
405
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
406
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
407 static uint32 VehicleGetRandomBits(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
408 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
409 return GRV(object) == NULL ? 0 : GRV(object)->random_bits;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
410 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
411
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
412
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
413 static uint32 VehicleGetTriggers(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
414 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
415 return GRV(object) == NULL ? 0 : GRV(object)->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
416 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
417
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
418
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
419 static void VehicleSetTriggers(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
420 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
421 /* Evil cast to get around const-ness. This used to be achieved by an
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
422 * innocent looking function pointer cast... Currently I cannot see a
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
423 * way of avoiding this without removing consts deep within gui code.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
424 */
12016
d45475f68f60 (svn r16422) -Codechange: use const_cast for removing const and warn when const is (accidentally?) removed using C-style casts.
rubidium <rubidium@openttd.org>
parents: 12015
diff changeset
425 Vehicle *v = const_cast<Vehicle *>(GRV(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
426
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
427 /* This function must only be called when processing triggers -- any
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
428 * other time is an error. */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
429 assert(object->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
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 if (v != NULL) v->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
432 }
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
6516
f8eb4662e1e5 (svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents: 6490
diff changeset
435 static uint8 LiveryHelper(EngineID engine, const Vehicle *v)
f8eb4662e1e5 (svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents: 6490
diff changeset
436 {
f8eb4662e1e5 (svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents: 6490
diff changeset
437 const Livery *l;
f8eb4662e1e5 (svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents: 6490
diff changeset
438
f8eb4662e1e5 (svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents: 6490
diff changeset
439 if (v == NULL) {
11924
fccc9cea27a7 (svn r16327) -Codechange: replace IsValidPoolItemID(index) by PoolItem::IsValidID(index)
smatz <smatz@openttd.org>
parents: 11922
diff changeset
440 if (!Company::IsValidID(_current_company)) return 0;
15921
7c1f97a04d96 (svn r20605) -Fix [FS#4063]: let NewGRFs var43 var (information about liveries) for vehicles not be influenced by the local setting determining whether to show liveries or not.
rubidium <rubidium@openttd.org>
parents: 15823
diff changeset
441 l = GetEngineLivery(engine, _current_company, INVALID_ENGINE, NULL, LIT_ALL);
16788
efb0333e5aad (svn r21521) -Codechange: Unify some cached values that were present in both road vehicles and trains.
terkhen <terkhen@openttd.org>
parents: 16785
diff changeset
442 } else if (v->IsGroundVehicle()) {
efb0333e5aad (svn r21521) -Codechange: Unify some cached values that were present in both road vehicles and trains.
terkhen <terkhen@openttd.org>
parents: 16785
diff changeset
443 l = GetEngineLivery(v->engine_type, v->owner, v->GetGroundVehicleCache()->first_engine, v, LIT_ALL);
6516
f8eb4662e1e5 (svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents: 6490
diff changeset
444 } else {
15921
7c1f97a04d96 (svn r20605) -Fix [FS#4063]: let NewGRFs var43 var (information about liveries) for vehicles not be influenced by the local setting determining whether to show liveries or not.
rubidium <rubidium@openttd.org>
parents: 15823
diff changeset
445 l = GetEngineLivery(v->engine_type, v->owner, INVALID_ENGINE, v, LIT_ALL);
6516
f8eb4662e1e5 (svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents: 6490
diff changeset
446 }
f8eb4662e1e5 (svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents: 6490
diff changeset
447
f8eb4662e1e5 (svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents: 6490
diff changeset
448 return l->colour1 + l->colour2 * 16;
f8eb4662e1e5 (svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents: 6490
diff changeset
449 }
f8eb4662e1e5 (svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents: 6490
diff changeset
450
11268
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
451 /**
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
452 * Helper to get the position of a vehicle within a chain of vehicles.
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
453 * @param v the vehicle to get the position of.
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
454 * @param consecutive whether to look at the whole chain or the vehicles
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
455 * with the same 'engine type'.
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
456 * @return the position in the chain from front and tail and chain length.
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
457 */
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
458 static uint32 PositionHelper(const Vehicle *v, bool consecutive)
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
459 {
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
460 const Vehicle *u;
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
461 byte chain_before = 0;
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
462 byte chain_after = 0;
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
463
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
464 for (u = v->First(); u != v; u = u->Next()) {
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
465 chain_before++;
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
466 if (consecutive && u->engine_type != v->engine_type) chain_before = 0;
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
467 }
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
468
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
469 while (u->Next() != NULL && (!consecutive || u->Next()->engine_type == v->engine_type)) {
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
470 chain_after++;
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
471 u = u->Next();
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
472 }
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
473
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
474 return chain_before | chain_after << 8 | (chain_before + chain_after + consecutive) << 16;
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
475 }
6516
f8eb4662e1e5 (svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents: 6490
diff changeset
476
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
477 static uint32 VehicleGetVariable(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
478 {
11268
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
479 Vehicle *v = const_cast<Vehicle*>(GRV(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
480
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
481 if (v == NULL) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
482 /* Vehicle 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
483 switch (variable) {
15132
2a673f4c8d15 (svn r19761) -Fix: [NewGRF] Vehicle var 43 missed AI information in purchase list.
frosch <frosch@openttd.org>
parents: 15081
diff changeset
484 case 0x43: return _current_company | (Company::IsValidAiID(_current_company) ? 0x10000 : 0) | (LiveryHelper(object->u.vehicle.self_type, NULL) << 24); // Owner information
6348
bcf98ba27bbf (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents: 6259
diff changeset
485 case 0x46: return 0; // Motion counter
11189
c993bfe070b7 (svn r15542) -Feature(ette): Support vehicle vars 0x47 and 0xF2 in purchase list.
frosch <frosch@openttd.org>
parents: 11188
diff changeset
486 case 0x47: { // Vehicle cargo info
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11875
diff changeset
487 const Engine *e = Engine::Get(object->u.vehicle.self_type);
11189
c993bfe070b7 (svn r15542) -Feature(ette): Support vehicle vars 0x47 and 0xF2 in purchase list.
frosch <frosch@openttd.org>
parents: 11188
diff changeset
488 CargoID cargo_type = e->GetDefaultCargoType();
c993bfe070b7 (svn r15542) -Feature(ette): Support vehicle vars 0x47 and 0xF2 in purchase list.
frosch <frosch@openttd.org>
parents: 11188
diff changeset
489 if (cargo_type != CT_INVALID) {
12415
6a77d1df56e2 (svn r16849) -Codechange: replace GetCargo() by CargoSpec::Get()
smatz <smatz@openttd.org>
parents: 12302
diff changeset
490 const CargoSpec *cs = CargoSpec::Get(cargo_type);
11189
c993bfe070b7 (svn r15542) -Feature(ette): Support vehicle vars 0x47 and 0xF2 in purchase list.
frosch <frosch@openttd.org>
parents: 11188
diff changeset
491 return (cs->classes << 16) | (cs->weight << 8) | GetEngineGRF(e->index)->cargo_map[cargo_type];
c993bfe070b7 (svn r15542) -Feature(ette): Support vehicle vars 0x47 and 0xF2 in purchase list.
frosch <frosch@openttd.org>
parents: 11188
diff changeset
492 } else {
c993bfe070b7 (svn r15542) -Feature(ette): Support vehicle vars 0x47 and 0xF2 in purchase list.
frosch <frosch@openttd.org>
parents: 11188
diff changeset
493 return 0x000000FF;
c993bfe070b7 (svn r15542) -Feature(ette): Support vehicle vars 0x47 and 0xF2 in purchase list.
frosch <frosch@openttd.org>
parents: 11188
diff changeset
494 }
c993bfe070b7 (svn r15542) -Feature(ette): Support vehicle vars 0x47 and 0xF2 in purchase list.
frosch <frosch@openttd.org>
parents: 11188
diff changeset
495 }
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11875
diff changeset
496 case 0x48: return Engine::Get(object->u.vehicle.self_type)->flags; // Vehicle Type Info
9459
c2025eda93f4 (svn r13377) -Codechange: Let 'long format' build year work in vehicle purchase list.
peter1138 <peter1138@openttd.org>
parents: 9458
diff changeset
497 case 0x49: return _cur_year; // 'Long' format build year
7922
ff1975ced735 (svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13 <skidd13@openttd.org>
parents: 7881
diff changeset
498 case 0xC4: return Clamp(_cur_year, ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR) - ORIGINAL_BASE_YEAR; // Build year
6348
bcf98ba27bbf (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents: 6259
diff changeset
499 case 0xDA: return INVALID_VEHICLE; // Next vehicle
11189
c993bfe070b7 (svn r15542) -Feature(ette): Support vehicle vars 0x47 and 0xF2 in purchase list.
frosch <frosch@openttd.org>
parents: 11188
diff changeset
500 case 0xF2: return 0; // Cargo subtype
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
501 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
502
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
503 *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
504 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
505 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
506
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
507 /* Calculated vehicle parameters */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
508 switch (variable) {
11386
5c3e9447c441 (svn r15739) -Codechange: Expose GRF ID of engines in var action property 0x25.
peter1138 <peter1138@openttd.org>
parents: 11368
diff changeset
509 case 0x25: // Get engine GRF ID
5c3e9447c441 (svn r15739) -Codechange: Expose GRF ID of engines in var action property 0x25.
peter1138 <peter1138@openttd.org>
parents: 11368
diff changeset
510 return GetEngineGRFID(v->engine_type);
5c3e9447c441 (svn r15739) -Codechange: Expose GRF ID of engines in var action property 0x25.
peter1138 <peter1138@openttd.org>
parents: 11368
diff changeset
511
6348
bcf98ba27bbf (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents: 6259
diff changeset
512 case 0x40: // Get length of consist
16375
b1d08f95d3d5 (svn r21091) -Codechange: Add bit constants for checking NewGRFCache validity.
terkhen <terkhen@openttd.org>
parents: 16374
diff changeset
513 if (!HasBit(v->grf_cache.cache_valid, NCVV_POSITION_CONSIST_LENGTH)) {
16374
9f154b53990e (svn r21090) -Codechange: Rename VehicleCache to NewGRFCache.
terkhen <terkhen@openttd.org>
parents: 16107
diff changeset
514 v->grf_cache.position_consist_length = PositionHelper(v, false);
16375
b1d08f95d3d5 (svn r21091) -Codechange: Add bit constants for checking NewGRFCache validity.
terkhen <terkhen@openttd.org>
parents: 16374
diff changeset
515 SetBit(v->grf_cache.cache_valid, NCVV_POSITION_CONSIST_LENGTH);
11268
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
516 }
16374
9f154b53990e (svn r21090) -Codechange: Rename VehicleCache to NewGRFCache.
terkhen <terkhen@openttd.org>
parents: 16107
diff changeset
517 return v->grf_cache.position_consist_length;
11268
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
518
6348
bcf98ba27bbf (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents: 6259
diff changeset
519 case 0x41: // Get length of same consecutive wagons
16375
b1d08f95d3d5 (svn r21091) -Codechange: Add bit constants for checking NewGRFCache validity.
terkhen <terkhen@openttd.org>
parents: 16374
diff changeset
520 if (!HasBit(v->grf_cache.cache_valid, NCVV_POSITION_SAME_ID_LENGTH)) {
16374
9f154b53990e (svn r21090) -Codechange: Rename VehicleCache to NewGRFCache.
terkhen <terkhen@openttd.org>
parents: 16107
diff changeset
521 v->grf_cache.position_same_id_length = PositionHelper(v, true);
16375
b1d08f95d3d5 (svn r21091) -Codechange: Add bit constants for checking NewGRFCache validity.
terkhen <terkhen@openttd.org>
parents: 16374
diff changeset
522 SetBit(v->grf_cache.cache_valid, NCVV_POSITION_SAME_ID_LENGTH);
11268
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
523 }
16374
9f154b53990e (svn r21090) -Codechange: Rename VehicleCache to NewGRFCache.
terkhen <terkhen@openttd.org>
parents: 16107
diff changeset
524 return v->grf_cache.position_same_id_length;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
525
11268
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
526 case 0x42: // Consist cargo information
16375
b1d08f95d3d5 (svn r21091) -Codechange: Add bit constants for checking NewGRFCache validity.
terkhen <terkhen@openttd.org>
parents: 16374
diff changeset
527 if (!HasBit(v->grf_cache.cache_valid, NCVV_CONSIST_CARGO_INFORMATION)) {
11268
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
528 const Vehicle *u;
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
529 byte cargo_classes = 0;
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
530 uint8 common_cargos[NUM_CARGO];
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
531 uint8 common_subtypes[256];
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
532 byte user_def_data = 0;
12071
a50b1fcac71b (svn r16478) -Fix (r15378): Determining most common (sub-)cargo-type was broken due to someone confusing similiary named variables.
frosch <frosch@openttd.org>
parents: 12016
diff changeset
533 CargoID common_cargo_type = CT_INVALID;
a50b1fcac71b (svn r16478) -Fix (r15378): Determining most common (sub-)cargo-type was broken due to someone confusing similiary named variables.
frosch <frosch@openttd.org>
parents: 12016
diff changeset
534 uint8 common_subtype = 0xFF; // Return 0xFF if nothing is carried
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
535
11268
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
536 /* Reset our arrays */
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
537 memset(common_cargos, 0, sizeof(common_cargos));
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
538 memset(common_subtypes, 0, sizeof(common_subtypes));
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
539
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
540 for (u = v; u != NULL; u = u->Next()) {
12114
f020ec6be498 (svn r16527) -Codechange: use static member functions instead of simple casts when converting Vehicle to specialised vehicle types. Includes safety check
smatz <smatz@openttd.org>
parents: 12073
diff changeset
541 if (v->type == VEH_TRAIN) user_def_data |= Train::From(u)->tcache.user_def_data;
11268
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
542
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
543 /* Skip empty engines */
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
544 if (u->cargo_cap == 0) continue;
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
545
12415
6a77d1df56e2 (svn r16849) -Codechange: replace GetCargo() by CargoSpec::Get()
smatz <smatz@openttd.org>
parents: 12302
diff changeset
546 cargo_classes |= CargoSpec::Get(u->cargo_type)->classes;
11268
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
547 common_cargos[u->cargo_type]++;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
548 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
549
11268
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
550 /* Pick the most common cargo type */
12071
a50b1fcac71b (svn r16478) -Fix (r15378): Determining most common (sub-)cargo-type was broken due to someone confusing similiary named variables.
frosch <frosch@openttd.org>
parents: 12016
diff changeset
551 uint common_cargo_best_amount = 0;
11268
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
552 for (CargoID cargo = 0; cargo < NUM_CARGO; cargo++) {
12071
a50b1fcac71b (svn r16478) -Fix (r15378): Determining most common (sub-)cargo-type was broken due to someone confusing similiary named variables.
frosch <frosch@openttd.org>
parents: 12016
diff changeset
553 if (common_cargos[cargo] > common_cargo_best_amount) {
a50b1fcac71b (svn r16478) -Fix (r15378): Determining most common (sub-)cargo-type was broken due to someone confusing similiary named variables.
frosch <frosch@openttd.org>
parents: 12016
diff changeset
554 common_cargo_best_amount = common_cargos[cargo];
11268
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
555 common_cargo_type = cargo;
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
556 }
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
557 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
558
11268
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
559 /* Count subcargo types of common_cargo_type */
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
560 for (u = v; u != NULL; u = u->Next()) {
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
561 /* Skip empty engines and engines not carrying common_cargo_type */
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
562 if (u->cargo_cap == 0 || u->cargo_type != common_cargo_type) continue;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
563
11268
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
564 common_subtypes[u->cargo_subtype]++;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
565 }
11038
1251bbc83146 (svn r15378) -Fix: The subcargo returned by vehicle variable 0x42 should be the most-common-subcargo of the most-common-cargo. If nothing is transported 0x..FFFF00 should be returned.
frosch <frosch@openttd.org>
parents: 10960
diff changeset
566
11268
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
567 /* Pick the most common subcargo type*/
12071
a50b1fcac71b (svn r16478) -Fix (r15378): Determining most common (sub-)cargo-type was broken due to someone confusing similiary named variables.
frosch <frosch@openttd.org>
parents: 12016
diff changeset
568 uint common_subtype_best_amount = 0;
11268
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
569 for (uint i = 0; i < lengthof(common_subtypes); i++) {
12071
a50b1fcac71b (svn r16478) -Fix (r15378): Determining most common (sub-)cargo-type was broken due to someone confusing similiary named variables.
frosch <frosch@openttd.org>
parents: 12016
diff changeset
570 if (common_subtypes[i] > common_subtype_best_amount) {
a50b1fcac71b (svn r16478) -Fix (r15378): Determining most common (sub-)cargo-type was broken due to someone confusing similiary named variables.
frosch <frosch@openttd.org>
parents: 12016
diff changeset
571 common_subtype_best_amount = common_subtypes[i];
11268
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
572 common_subtype = i;
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
573 }
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
574 }
11038
1251bbc83146 (svn r15378) -Fix: The subcargo returned by vehicle variable 0x42 should be the most-common-subcargo of the most-common-cargo. If nothing is transported 0x..FFFF00 should be returned.
frosch <frosch@openttd.org>
parents: 10960
diff changeset
575
12415
6a77d1df56e2 (svn r16849) -Codechange: replace GetCargo() by CargoSpec::Get()
smatz <smatz@openttd.org>
parents: 12302
diff changeset
576 uint8 common_bitnum = (common_cargo_type == CT_INVALID ? 0xFF : CargoSpec::Get(common_cargo_type)->bitnum);
16374
9f154b53990e (svn r21090) -Codechange: Rename VehicleCache to NewGRFCache.
terkhen <terkhen@openttd.org>
parents: 16107
diff changeset
577 v->grf_cache.consist_cargo_information = cargo_classes | (common_bitnum << 8) | (common_subtype << 16) | (user_def_data << 24);
16375
b1d08f95d3d5 (svn r21091) -Codechange: Add bit constants for checking NewGRFCache validity.
terkhen <terkhen@openttd.org>
parents: 16374
diff changeset
578 SetBit(v->grf_cache.cache_valid, NCVV_CONSIST_CARGO_INFORMATION);
6822
08fc353e6a6b (svn r10061) -Codechange: [NewGRF] Add common cargo subtype support to vehicle var 42
peter1138 <peter1138@openttd.org>
parents: 6621
diff changeset
579 }
16374
9f154b53990e (svn r21090) -Codechange: Rename VehicleCache to NewGRFCache.
terkhen <terkhen@openttd.org>
parents: 16107
diff changeset
580 return v->grf_cache.consist_cargo_information;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
581
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: 10177
diff changeset
582 case 0x43: // Company information
16375
b1d08f95d3d5 (svn r21091) -Codechange: Add bit constants for checking NewGRFCache validity.
terkhen <terkhen@openttd.org>
parents: 16374
diff changeset
583 if (!HasBit(v->grf_cache.cache_valid, NCVV_COMPANY_INFORMATION)) {
16374
9f154b53990e (svn r21090) -Codechange: Rename VehicleCache to NewGRFCache.
terkhen <terkhen@openttd.org>
parents: 16107
diff changeset
584 v->grf_cache.company_information = v->owner | (Company::IsHumanID(v->owner) ? 0 : 0x10000) | (LiveryHelper(v->engine_type, v) << 24);
16375
b1d08f95d3d5 (svn r21091) -Codechange: Add bit constants for checking NewGRFCache validity.
terkhen <terkhen@openttd.org>
parents: 16374
diff changeset
585 SetBit(v->grf_cache.cache_valid, NCVV_COMPANY_INFORMATION);
11268
e0ddd5124002 (svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents: 11189
diff changeset
586 }
16374
9f154b53990e (svn r21090) -Codechange: Rename VehicleCache to NewGRFCache.
terkhen <terkhen@openttd.org>
parents: 16107
diff changeset
587 return v->grf_cache.company_information;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
588
6348
bcf98ba27bbf (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents: 6259
diff changeset
589 case 0x44: // Aircraft information
6259
4a39d6291d58 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium <rubidium@openttd.org>
parents: 6248
diff changeset
590 if (v->type != VEH_AIRCRAFT) 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
591
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
592 {
7492
09743324277c (svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium <rubidium@openttd.org>
parents: 7327
diff changeset
593 const Vehicle *w = v->Next();
6348
bcf98ba27bbf (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents: 6259
diff changeset
594 uint16 altitude = v->z_pos - w->z_pos; // Aircraft height - shadow height
10177
2748e8fea4a2 (svn r14383) -Fix [FS#2316](r14343): handle invalid 'v->u.air.targetairport' in the NewGRF code, too
smatz <smatz@openttd.org>
parents: 9750
diff changeset
595 byte airporttype = ATP_TTDP_LARGE;
2748e8fea4a2 (svn r14383) -Fix [FS#2316](r14343): handle invalid 'v->u.air.targetairport' in the NewGRF code, too
smatz <smatz@openttd.org>
parents: 9750
diff changeset
596
12114
f020ec6be498 (svn r16527) -Codechange: use static member functions instead of simple casts when converting Vehicle to specialised vehicle types. Includes safety check
smatz <smatz@openttd.org>
parents: 12073
diff changeset
597 const Station *st = GetTargetAirportIfValid(Aircraft::From(v));
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
598
14715
aa004cf5c288 (svn r19299) -Codechange: store the most compatible ttd airport type in AirportSpec
yexo <yexo@openttd.org>
parents: 14378
diff changeset
599 if (st != NULL && st->airport.tile != INVALID_TILE) {
14859
304d377a82af (svn r19455) -Codechange: split all airport information in Station to a seperate class
yexo <yexo@openttd.org>
parents: 14750
diff changeset
600 airporttype = st->airport.GetSpec()->ttd_airport_type;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
601 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
602
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
603 return (altitude << 8) | airporttype;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
604 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
605
6589
3c89f72535f3 (svn r9803) -Feature(tte): support for "curvature info", Action 2 for train, variable 45 (mart3p).
rubidium <rubidium@openttd.org>
parents: 6517
diff changeset
606 case 0x45: { // Curvature info
3c89f72535f3 (svn r9803) -Feature(tte): support for "curvature info", Action 2 for train, variable 45 (mart3p).
rubidium <rubidium@openttd.org>
parents: 6517
diff changeset
607 /* Format: xxxTxBxF
3c89f72535f3 (svn r9803) -Feature(tte): support for "curvature info", Action 2 for train, variable 45 (mart3p).
rubidium <rubidium@openttd.org>
parents: 6517
diff changeset
608 * F - previous wagon to current wagon, 0 if vehicle is first
3c89f72535f3 (svn r9803) -Feature(tte): support for "curvature info", Action 2 for train, variable 45 (mart3p).
rubidium <rubidium@openttd.org>
parents: 6517
diff changeset
609 * B - current wagon to next wagon, 0 if wagon is last
3c89f72535f3 (svn r9803) -Feature(tte): support for "curvature info", Action 2 for train, variable 45 (mart3p).
rubidium <rubidium@openttd.org>
parents: 6517
diff changeset
610 * T - previous wagon to next wagon, 0 in an S-bend
3c89f72535f3 (svn r9803) -Feature(tte): support for "curvature info", Action 2 for train, variable 45 (mart3p).
rubidium <rubidium@openttd.org>
parents: 6517
diff changeset
611 */
16783
37b5683941fa (svn r21516) -Codechange: Add IsGroundVehicle function to the Vehicle class.
terkhen <terkhen@openttd.org>
parents: 16608
diff changeset
612 if (!v->IsGroundVehicle()) return 0;
6589
3c89f72535f3 (svn r9803) -Feature(tte): support for "curvature info", Action 2 for train, variable 45 (mart3p).
rubidium <rubidium@openttd.org>
parents: 6517
diff changeset
613
7497
797ff0b0e0a5 (svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium <rubidium@openttd.org>
parents: 7492
diff changeset
614 const Vehicle *u_p = v->Previous();
7492
09743324277c (svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium <rubidium@openttd.org>
parents: 7327
diff changeset
615 const Vehicle *u_n = v->Next();
6589
3c89f72535f3 (svn r9803) -Feature(tte): support for "curvature info", Action 2 for train, variable 45 (mart3p).
rubidium <rubidium@openttd.org>
parents: 6517
diff changeset
616 DirDiff f = (u_p == NULL) ? DIRDIFF_SAME : DirDifference(u_p->direction, v->direction);
3c89f72535f3 (svn r9803) -Feature(tte): support for "curvature info", Action 2 for train, variable 45 (mart3p).
rubidium <rubidium@openttd.org>
parents: 6517
diff changeset
617 DirDiff b = (u_n == NULL) ? DIRDIFF_SAME : DirDifference(v->direction, u_n->direction);
3c89f72535f3 (svn r9803) -Feature(tte): support for "curvature info", Action 2 for train, variable 45 (mart3p).
rubidium <rubidium@openttd.org>
parents: 6517
diff changeset
618 DirDiff t = ChangeDirDiff(f, b);
3c89f72535f3 (svn r9803) -Feature(tte): support for "curvature info", Action 2 for train, variable 45 (mart3p).
rubidium <rubidium@openttd.org>
parents: 6517
diff changeset
619
3c89f72535f3 (svn r9803) -Feature(tte): support for "curvature info", Action 2 for train, variable 45 (mart3p).
rubidium <rubidium@openttd.org>
parents: 6517
diff changeset
620 return ((t > DIRDIFF_REVERSE ? t | 8 : t) << 16) |
3c89f72535f3 (svn r9803) -Feature(tte): support for "curvature info", Action 2 for train, variable 45 (mart3p).
rubidium <rubidium@openttd.org>
parents: 6517
diff changeset
621 ((b > DIRDIFF_REVERSE ? b | 8 : b) << 8) |
3c89f72535f3 (svn r9803) -Feature(tte): support for "curvature info", Action 2 for train, variable 45 (mart3p).
rubidium <rubidium@openttd.org>
parents: 6517
diff changeset
622 ( f > DIRDIFF_REVERSE ? f | 8 : f);
3c89f72535f3 (svn r9803) -Feature(tte): support for "curvature info", Action 2 for train, variable 45 (mart3p).
rubidium <rubidium@openttd.org>
parents: 6517
diff changeset
623 }
3c89f72535f3 (svn r9803) -Feature(tte): support for "curvature info", Action 2 for train, variable 45 (mart3p).
rubidium <rubidium@openttd.org>
parents: 6517
diff changeset
624
6348
bcf98ba27bbf (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents: 6259
diff changeset
625 case 0x46: // Motion counter
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 return v->motion_counter;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
627
6348
bcf98ba27bbf (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents: 6259
diff changeset
628 case 0x47: { // Vehicle cargo info
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
629 /* Format: ccccwwtt
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
630 * tt - the cargo type transported by the vehicle,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
631 * translated if a translation table has been installed.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
632 * ww - cargo unit weight in 1/16 tons, same as cargo prop. 0F.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
633 * cccc - the cargo class value of the cargo transported by the vehicle.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
634 */
12415
6a77d1df56e2 (svn r16849) -Codechange: replace GetCargo() by CargoSpec::Get()
smatz <smatz@openttd.org>
parents: 12302
diff changeset
635 const CargoSpec *cs = CargoSpec::Get(v->cargo_type);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
636
6147
a7aecaae3414 (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138 <peter1138@openttd.org>
parents: 6126
diff changeset
637 return (cs->classes << 16) | (cs->weight << 8) | GetEngineGRF(v->engine_type)->cargo_map[v->cargo_type];
5584
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
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11875
diff changeset
640 case 0x48: return Engine::Get(v->engine_type)->flags; // Vehicle Type Info
9458
4d6876b83195 (svn r13376) -Feature: Add access to current long year and date from Action 7/9/D and VarAction2 (23/24 or A3/A4)
belugas <belugas@openttd.org>
parents: 9436
diff changeset
641 case 0x49: return v->build_year;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
642
15512
9129648e0ffd (svn r20165) -Feature: [NewGRF] Information (var 4A) about the current railtype a train is on.
michi_cc <michi_cc@openttd.org>
parents: 15457
diff changeset
643 case 0x4A: {
9129648e0ffd (svn r20165) -Feature: [NewGRF] Information (var 4A) about the current railtype a train is on.
michi_cc <michi_cc@openttd.org>
parents: 15457
diff changeset
644 if (v->type != VEH_TRAIN) return 0;
9129648e0ffd (svn r20165) -Feature: [NewGRF] Information (var 4A) about the current railtype a train is on.
michi_cc <michi_cc@openttd.org>
parents: 15457
diff changeset
645 RailType rt = GetTileRailType(v->tile);
9129648e0ffd (svn r20165) -Feature: [NewGRF] Information (var 4A) about the current railtype a train is on.
michi_cc <michi_cc@openttd.org>
parents: 15457
diff changeset
646 return (HasPowerOnRail(Train::From(v)->railtype, rt) ? 0x100 : 0) | GetReverseRailTypeTranslation(rt, object->grffile);
9129648e0ffd (svn r20165) -Feature: [NewGRF] Information (var 4A) about the current railtype a train is on.
michi_cc <michi_cc@openttd.org>
parents: 15457
diff changeset
647 }
9129648e0ffd (svn r20165) -Feature: [NewGRF] Information (var 4A) about the current railtype a train is on.
michi_cc <michi_cc@openttd.org>
parents: 15457
diff changeset
648
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
649 /* Variables which use the parameter */
6348
bcf98ba27bbf (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents: 6259
diff changeset
650 case 0x60: // Count consist's engine ID occurance
9070
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
651 //EngineID engine = GetNewEngineID(GetEngineGRF(v->engine_type), v->type, parameter);
15763
a60a50f29f64 (svn r20437) -Codechange: lets Engines use GRFFilePropsBase as well
rubidium <rubidium@openttd.org>
parents: 15620
diff changeset
652 if (v->type != VEH_TRAIN) return Engine::Get(v->engine_type)->grf_prop.local_id == parameter;
5584
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 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
655 uint count = 0;
7492
09743324277c (svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium <rubidium@openttd.org>
parents: 7327
diff changeset
656 for (; v != NULL; v = v->Next()) {
15763
a60a50f29f64 (svn r20437) -Codechange: lets Engines use GRFFilePropsBase as well
rubidium <rubidium@openttd.org>
parents: 15620
diff changeset
657 if (Engine::Get(v->engine_type)->grf_prop.local_id == parameter) 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
658 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
659 return count;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
660 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
661
6176
863c86137fc1 (svn r8946) -Feature: [NewGRF] Add support for vehicle variables 0xFE and 0xFF bit 10,
maedhros <maedhros@openttd.org>
parents: 6173
diff changeset
662 case 0xFE:
863c86137fc1 (svn r8946) -Feature: [NewGRF] Add support for vehicle variables 0xFE and 0xFF bit 10,
maedhros <maedhros@openttd.org>
parents: 6173
diff changeset
663 case 0xFF: {
863c86137fc1 (svn r8946) -Feature: [NewGRF] Add support for vehicle variables 0xFE and 0xFF bit 10,
maedhros <maedhros@openttd.org>
parents: 6173
diff changeset
664 uint16 modflags = 0;
863c86137fc1 (svn r8946) -Feature: [NewGRF] Add support for vehicle variables 0xFE and 0xFF bit 10,
maedhros <maedhros@openttd.org>
parents: 6173
diff changeset
665
8665
5e82cdbe1cc1 (svn r12330) -Feature: [NewGRF] vehicle variable FE bit 5 and 6
glx <glx@openttd.org>
parents: 8654
diff changeset
666 if (v->type == VEH_TRAIN) {
12114
f020ec6be498 (svn r16527) -Codechange: use static member functions instead of simple casts when converting Vehicle to specialised vehicle types. Includes safety check
smatz <smatz@openttd.org>
parents: 12073
diff changeset
667 const Train *t = Train::From(v);
15823
d9032e02c0c5 (svn r20502) -Fix (r12330): VRF_POWEREDWAGON is part of train flags, not vehicle_flags.
frosch <frosch@openttd.org>
parents: 15802
diff changeset
668 bool is_powered_wagon = HasBit(t->flags, VRF_POWEREDWAGON);
d9032e02c0c5 (svn r20502) -Fix (r12330): VRF_POWEREDWAGON is part of train flags, not vehicle_flags.
frosch <frosch@openttd.org>
parents: 15802
diff changeset
669 const Train *u = is_powered_wagon ? t->First() : t; // for powered wagons the engine defines the type of engine (i.e. railtype)
8665
5e82cdbe1cc1 (svn r12330) -Feature: [NewGRF] vehicle variable FE bit 5 and 6
glx <glx@openttd.org>
parents: 8654
diff changeset
670 RailType railtype = GetRailType(v->tile);
15823
d9032e02c0c5 (svn r20502) -Fix (r12330): VRF_POWEREDWAGON is part of train flags, not vehicle_flags.
frosch <frosch@openttd.org>
parents: 15802
diff changeset
671 bool powered = t->IsEngine() || is_powered_wagon;
15521
b56282f31197 (svn r20175) -Change: [NewGRF] Adapt vehicle var FE bit 6 to new railtypes.
frosch <frosch@openttd.org>
parents: 15512
diff changeset
672 bool has_power = HasPowerOnRail(u->railtype, railtype);
8666
ae052ccde3db (svn r12331) -Feature: [NewGRF] vehicle variable FE bit 8
glx <glx@openttd.org>
parents: 8665
diff changeset
673
15521
b56282f31197 (svn r20175) -Change: [NewGRF] Adapt vehicle var FE bit 6 to new railtypes.
frosch <frosch@openttd.org>
parents: 15512
diff changeset
674 if (powered && has_power) SetBit(modflags, 5);
b56282f31197 (svn r20175) -Change: [NewGRF] Adapt vehicle var FE bit 6 to new railtypes.
frosch <frosch@openttd.org>
parents: 15512
diff changeset
675 if (powered && !has_power) SetBit(modflags, 6);
11986
78abb48a4fba (svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents: 11985
diff changeset
676 if (HasBit(t->flags, VRF_TOGGLE_REVERSE)) SetBit(modflags, 8);
8665
5e82cdbe1cc1 (svn r12330) -Feature: [NewGRF] vehicle variable FE bit 5 and 6
glx <glx@openttd.org>
parents: 8654
diff changeset
677 }
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
678 if (HasBit(v->vehicle_flags, VF_BUILT_AS_PROTOTYPE)) SetBit(modflags, 10);
6176
863c86137fc1 (svn r8946) -Feature: [NewGRF] Add support for vehicle variables 0xFE and 0xFF bit 10,
maedhros <maedhros@openttd.org>
parents: 6173
diff changeset
679
863c86137fc1 (svn r8946) -Feature: [NewGRF] Add support for vehicle variables 0xFE and 0xFF bit 10,
maedhros <maedhros@openttd.org>
parents: 6173
diff changeset
680 return variable == 0xFE ? modflags : GB(modflags, 8, 8);
863c86137fc1 (svn r8946) -Feature: [NewGRF] Add support for vehicle variables 0xFE and 0xFF bit 10,
maedhros <maedhros@openttd.org>
parents: 6173
diff changeset
681 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
682 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
683
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
684 /* General vehicle properties */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
685 switch (variable - 0x80) {
12201
b28426ff9e8c (svn r16615) -Fix (r16613): 0x10 != 2
yexo <yexo@openttd.org>
parents: 12199
diff changeset
686 case 0x00: return v->type + 0x10;
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 case 0x01: return MapOldSubType(v);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
688 case 0x04: return v->index;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
689 case 0x05: return GB(v->index, 8, 8);
12199
8e20cb543b87 (svn r16613) -Fix [NewGRF]: some of the var action 2 80+ variables contained wrong results due to OpenTTD codechanges
yexo <yexo@openttd.org>
parents: 12114
diff changeset
690 case 0x0A: return v->current_order.MapOldOrder();
8e20cb543b87 (svn r16613) -Fix [NewGRF]: some of the var action 2 80+ variables contained wrong results due to OpenTTD codechanges
yexo <yexo@openttd.org>
parents: 12114
diff changeset
691 case 0x0B: return v->current_order.GetDestination();
10544
836dfaca2a32 (svn r14801) -Codechange: don't reference Vehicle::num_orders directly but through a method GetNumOrders() (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10519
diff changeset
692 case 0x0C: return v->GetNumOrders();
17194
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 16788
diff changeset
693 case 0x0D: return v->cur_real_order_index;
14378
1e5bf41c11d5 (svn r18935) -Fix [FS#3551] (r18764): value of variables 90 and 91 weren't what NARS expects
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
694 case 0x10:
1e5bf41c11d5 (svn r18935) -Fix [FS#3551] (r18764): value of variables 90 and 91 weren't what NARS expects
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
695 case 0x11: {
1e5bf41c11d5 (svn r18935) -Fix [FS#3551] (r18764): value of variables 90 and 91 weren't what NARS expects
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
696 uint ticks;
1e5bf41c11d5 (svn r18935) -Fix [FS#3551] (r18764): value of variables 90 and 91 weren't what NARS expects
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
697 if (v->current_order.IsType(OT_LOADING)) {
1e5bf41c11d5 (svn r18935) -Fix [FS#3551] (r18764): value of variables 90 and 91 weren't what NARS expects
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
698 ticks = v->load_unload_ticks;
1e5bf41c11d5 (svn r18935) -Fix [FS#3551] (r18764): value of variables 90 and 91 weren't what NARS expects
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
699 } else {
1e5bf41c11d5 (svn r18935) -Fix [FS#3551] (r18764): value of variables 90 and 91 weren't what NARS expects
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
700 switch (v->type) {
1e5bf41c11d5 (svn r18935) -Fix [FS#3551] (r18764): value of variables 90 and 91 weren't what NARS expects
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
701 case VEH_TRAIN: ticks = Train::From(v)->wait_counter; break;
1e5bf41c11d5 (svn r18935) -Fix [FS#3551] (r18764): value of variables 90 and 91 weren't what NARS expects
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
702 case VEH_AIRCRAFT: ticks = Aircraft::From(v)->turn_counter; break;
1e5bf41c11d5 (svn r18935) -Fix [FS#3551] (r18764): value of variables 90 and 91 weren't what NARS expects
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
703 default: ticks = 0; break;
1e5bf41c11d5 (svn r18935) -Fix [FS#3551] (r18764): value of variables 90 and 91 weren't what NARS expects
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
704 }
1e5bf41c11d5 (svn r18935) -Fix [FS#3551] (r18764): value of variables 90 and 91 weren't what NARS expects
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
705 }
1e5bf41c11d5 (svn r18935) -Fix [FS#3551] (r18764): value of variables 90 and 91 weren't what NARS expects
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
706 return (variable - 0x80) == 0x10 ? ticks : GB(ticks, 8, 8);
1e5bf41c11d5 (svn r18935) -Fix [FS#3551] (r18764): value of variables 90 and 91 weren't what NARS expects
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
707 }
16107
f1922c797590 (svn r20800) -Fix: [NewGRF] clamp some more vehicle variables
yexo <yexo@openttd.org>
parents: 16106
diff changeset
708 case 0x12: return Clamp(v->date_of_last_service - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 0xFFFF);
f1922c797590 (svn r20800) -Fix: [NewGRF] clamp some more vehicle variables
yexo <yexo@openttd.org>
parents: 16106
diff changeset
709 case 0x13: return GB(Clamp(v->date_of_last_service - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 0xFFFF), 8, 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
710 case 0x14: return v->service_interval;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
711 case 0x15: return GB(v->service_interval, 8, 8);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
712 case 0x16: return v->last_station_visited;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
713 case 0x17: return v->tick_counter;
16099
084184db4653 (svn r20792) -Fix (r8973): [NewGRF] vehicle vars 0x98 and 0xB4 (max speed and current speed) used the wrong unit for aircraft (Hirundo)
yexo <yexo@openttd.org>
parents: 15944
diff changeset
714 case 0x18:
084184db4653 (svn r20792) -Fix (r8973): [NewGRF] vehicle vars 0x98 and 0xB4 (max speed and current speed) used the wrong unit for aircraft (Hirundo)
yexo <yexo@openttd.org>
parents: 15944
diff changeset
715 case 0x19: {
16379
89526f638fa4 (svn r21095) -Codechange: Use a function to convert aircraft speed to old units.
terkhen <terkhen@openttd.org>
parents: 16375
diff changeset
716 uint max_speed;
89526f638fa4 (svn r21095) -Codechange: Use a function to convert aircraft speed to old units.
terkhen <terkhen@openttd.org>
parents: 16375
diff changeset
717 switch (v->type) {
89526f638fa4 (svn r21095) -Codechange: Use a function to convert aircraft speed to old units.
terkhen <terkhen@openttd.org>
parents: 16375
diff changeset
718 case VEH_AIRCRAFT:
89526f638fa4 (svn r21095) -Codechange: Use a function to convert aircraft speed to old units.
terkhen <terkhen@openttd.org>
parents: 16375
diff changeset
719 max_speed = Aircraft::From(v)->GetSpeedOldUnits(); // Convert to old units.
89526f638fa4 (svn r21095) -Codechange: Use a function to convert aircraft speed to old units.
terkhen <terkhen@openttd.org>
parents: 16375
diff changeset
720 break;
89526f638fa4 (svn r21095) -Codechange: Use a function to convert aircraft speed to old units.
terkhen <terkhen@openttd.org>
parents: 16375
diff changeset
721
89526f638fa4 (svn r21095) -Codechange: Use a function to convert aircraft speed to old units.
terkhen <terkhen@openttd.org>
parents: 16375
diff changeset
722 default:
16383
6dd97e032309 (svn r21099) -Codechange: Store road vehicle max speed in the vehicle cache.
terkhen <terkhen@openttd.org>
parents: 16382
diff changeset
723 max_speed = v->vcache.cached_max_speed;
16379
89526f638fa4 (svn r21095) -Codechange: Use a function to convert aircraft speed to old units.
terkhen <terkhen@openttd.org>
parents: 16375
diff changeset
724 break;
89526f638fa4 (svn r21095) -Codechange: Use a function to convert aircraft speed to old units.
terkhen <terkhen@openttd.org>
parents: 16375
diff changeset
725 }
16099
084184db4653 (svn r20792) -Fix (r8973): [NewGRF] vehicle vars 0x98 and 0xB4 (max speed and current speed) used the wrong unit for aircraft (Hirundo)
yexo <yexo@openttd.org>
parents: 15944
diff changeset
726 return (variable - 0x80) == 0x18 ? max_speed : GB(max_speed, 8, 8);
084184db4653 (svn r20792) -Fix (r8973): [NewGRF] vehicle vars 0x98 and 0xB4 (max speed and current speed) used the wrong unit for aircraft (Hirundo)
yexo <yexo@openttd.org>
parents: 15944
diff changeset
727 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
728 case 0x1A: return v->x_pos;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
729 case 0x1B: return GB(v->x_pos, 8, 8);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
730 case 0x1C: return v->y_pos;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
731 case 0x1D: return GB(v->y_pos, 8, 8);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
732 case 0x1E: return v->z_pos;
13166
ac8a6c5b739c (svn r17671) -Codechange: Move ResolverObject::info_view into u.vehicle as it is only needed for them.
frosch <frosch@openttd.org>
parents: 13114
diff changeset
733 case 0x1F: return object->u.vehicle.info_view ? DIR_W : v->direction;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
734 case 0x28: return v->cur_image;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
735 case 0x29: return GB(v->cur_image, 8, 8);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
736 case 0x32: return v->vehstatus;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
737 case 0x33: return 0; // non-existent high byte of vehstatus
16099
084184db4653 (svn r20792) -Fix (r8973): [NewGRF] vehicle vars 0x98 and 0xB4 (max speed and current speed) used the wrong unit for aircraft (Hirundo)
yexo <yexo@openttd.org>
parents: 15944
diff changeset
738 case 0x34: return v->type == VEH_AIRCRAFT ? (v->cur_speed * 10) / 128 : v->cur_speed;
084184db4653 (svn r20792) -Fix (r8973): [NewGRF] vehicle vars 0x98 and 0xB4 (max speed and current speed) used the wrong unit for aircraft (Hirundo)
yexo <yexo@openttd.org>
parents: 15944
diff changeset
739 case 0x35: return GB(v->type == VEH_AIRCRAFT ? (v->cur_speed * 10) / 128 : v->cur_speed, 8, 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
740 case 0x36: return v->subspeed;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
741 case 0x37: return v->acceleration;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
742 case 0x39: return v->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
743 case 0x3A: return v->cargo_cap;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
744 case 0x3B: return GB(v->cargo_cap, 8, 8);
16107
f1922c797590 (svn r20800) -Fix: [NewGRF] clamp some more vehicle variables
yexo <yexo@openttd.org>
parents: 16106
diff changeset
745 case 0x3C: return ClampToU16(v->cargo.Count());
f1922c797590 (svn r20800) -Fix: [NewGRF] clamp some more vehicle variables
yexo <yexo@openttd.org>
parents: 16106
diff changeset
746 case 0x3D: return GB(ClampToU16(v->cargo.Count()), 8, 8);
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: 6990
diff changeset
747 case 0x3E: return v->cargo.Source();
16107
f1922c797590 (svn r20800) -Fix: [NewGRF] clamp some more vehicle variables
yexo <yexo@openttd.org>
parents: 16106
diff changeset
748 case 0x3F: return ClampU(v->cargo.DaysInTransit(), 0, 0xFF);
15457
a4ca05c4772a (svn r20106) -Fix (r5999): Engine and vehicle age were clamped at 0xFFFF, though there are 32bit available.
frosch <frosch@openttd.org>
parents: 15185
diff changeset
749 case 0x40: return ClampToU16(v->age);
a4ca05c4772a (svn r20106) -Fix (r5999): Engine and vehicle age were clamped at 0xFFFF, though there are 32bit available.
frosch <frosch@openttd.org>
parents: 15185
diff changeset
750 case 0x41: return GB(ClampToU16(v->age), 8, 8);
16106
530933b50339 (svn r20799) -Fix: [NewGRF] clamp vehicle var 0xC2 (max age) to uint16 (Hirundo)
yexo <yexo@openttd.org>
parents: 16099
diff changeset
751 case 0x42: return ClampToU16(v->max_age);
530933b50339 (svn r20799) -Fix: [NewGRF] clamp vehicle var 0xC2 (max age) to uint16 (Hirundo)
yexo <yexo@openttd.org>
parents: 16099
diff changeset
752 case 0x43: return GB(ClampToU16(v->max_age), 8, 8);
7922
ff1975ced735 (svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13 <skidd13@openttd.org>
parents: 7881
diff changeset
753 case 0x44: return Clamp(v->build_year, ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR) - ORIGINAL_BASE_YEAR;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
754 case 0x45: return v->unitnumber;
15763
a60a50f29f64 (svn r20437) -Codechange: lets Engines use GRFFilePropsBase as well
rubidium <rubidium@openttd.org>
parents: 15620
diff changeset
755 case 0x46: return Engine::Get(v->engine_type)->grf_prop.local_id;
a60a50f29f64 (svn r20437) -Codechange: lets Engines use GRFFilePropsBase as well
rubidium <rubidium@openttd.org>
parents: 15620
diff changeset
756 case 0x47: return GB(Engine::Get(v->engine_type)->grf_prop.local_id, 8, 8);
9059
323c3edf9c0d (svn r12910) -Fix: Report reverse sprite status (FD/FE) to NewGRF for manually toggled vehicles.
peter1138 <peter1138@openttd.org>
parents: 9046
diff changeset
757 case 0x48:
323c3edf9c0d (svn r12910) -Fix: Report reverse sprite status (FD/FE) to NewGRF for manually toggled vehicles.
peter1138 <peter1138@openttd.org>
parents: 9046
diff changeset
758 if (v->type != VEH_TRAIN || v->spritenum != 0xFD) return v->spritenum;
12114
f020ec6be498 (svn r16527) -Codechange: use static member functions instead of simple casts when converting Vehicle to specialised vehicle types. Includes safety check
smatz <smatz@openttd.org>
parents: 12073
diff changeset
759 return HasBit(Train::From(v)->flags, VRF_REVERSE_DIRECTION) ? 0xFE : 0xFD;
9059
323c3edf9c0d (svn r12910) -Fix: Report reverse sprite status (FD/FE) to NewGRF for manually toggled vehicles.
peter1138 <peter1138@openttd.org>
parents: 9046
diff changeset
760
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
761 case 0x49: return v->day_counter;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
762 case 0x4A: return v->breakdowns_since_last_service;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
763 case 0x4B: return v->breakdown_ctr;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
764 case 0x4C: return v->breakdown_delay;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
765 case 0x4D: return v->breakdown_chance;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
766 case 0x4E: return v->reliability;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
767 case 0x4F: return GB(v->reliability, 8, 8);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
768 case 0x50: return v->reliability_spd_dec;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
769 case 0x51: return GB(v->reliability_spd_dec, 8, 8);
8614
36bb76188638 (svn r12197) -Fix [FS#1788](r12134): show correct last year profit when the train had negative income
smatz <smatz@openttd.org>
parents: 8599
diff changeset
770 case 0x52: return ClampToI32(v->GetDisplayProfitThisYear());
36bb76188638 (svn r12197) -Fix [FS#1788](r12134): show correct last year profit when the train had negative income
smatz <smatz@openttd.org>
parents: 8599
diff changeset
771 case 0x53: return GB(ClampToI32(v->GetDisplayProfitThisYear()), 8, 24);
36bb76188638 (svn r12197) -Fix [FS#1788](r12134): show correct last year profit when the train had negative income
smatz <smatz@openttd.org>
parents: 8599
diff changeset
772 case 0x54: return GB(ClampToI32(v->GetDisplayProfitThisYear()), 16, 16);
36bb76188638 (svn r12197) -Fix [FS#1788](r12134): show correct last year profit when the train had negative income
smatz <smatz@openttd.org>
parents: 8599
diff changeset
773 case 0x55: return GB(ClampToI32(v->GetDisplayProfitThisYear()), 24, 8);
36bb76188638 (svn r12197) -Fix [FS#1788](r12134): show correct last year profit when the train had negative income
smatz <smatz@openttd.org>
parents: 8599
diff changeset
774 case 0x56: return ClampToI32(v->GetDisplayProfitLastYear());
36bb76188638 (svn r12197) -Fix [FS#1788](r12134): show correct last year profit when the train had negative income
smatz <smatz@openttd.org>
parents: 8599
diff changeset
775 case 0x57: return GB(ClampToI32(v->GetDisplayProfitLastYear()), 8, 24);
36bb76188638 (svn r12197) -Fix [FS#1788](r12134): show correct last year profit when the train had negative income
smatz <smatz@openttd.org>
parents: 8599
diff changeset
776 case 0x58: return GB(ClampToI32(v->GetDisplayProfitLastYear()), 16, 16);
36bb76188638 (svn r12197) -Fix [FS#1788](r12134): show correct last year profit when the train had negative income
smatz <smatz@openttd.org>
parents: 8599
diff changeset
777 case 0x59: return GB(ClampToI32(v->GetDisplayProfitLastYear()), 24, 8);
7492
09743324277c (svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium <rubidium@openttd.org>
parents: 7327
diff changeset
778 case 0x5A: return v->Next() == NULL ? INVALID_VEHICLE : v->Next()->index;
6990
a19700261804 (svn r10246) -Fix (r10297): some forgotten money conversions and truncation issues. Thanks to benc for providing the patch.
rubidium <rubidium@openttd.org>
parents: 6912
diff changeset
779 case 0x5C: return ClampToI32(v->value);
a19700261804 (svn r10246) -Fix (r10297): some forgotten money conversions and truncation issues. Thanks to benc for providing the patch.
rubidium <rubidium@openttd.org>
parents: 6912
diff changeset
780 case 0x5D: return GB(ClampToI32(v->value), 8, 24);
a19700261804 (svn r10246) -Fix (r10297): some forgotten money conversions and truncation issues. Thanks to benc for providing the patch.
rubidium <rubidium@openttd.org>
parents: 6912
diff changeset
781 case 0x5E: return GB(ClampToI32(v->value), 16, 16);
a19700261804 (svn r10246) -Fix (r10297): some forgotten money conversions and truncation issues. Thanks to benc for providing the patch.
rubidium <rubidium@openttd.org>
parents: 6912
diff changeset
782 case 0x5F: return GB(ClampToI32(v->value), 24, 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
783 case 0x72: return v->cargo_subtype;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
784 case 0x7A: return v->random_bits;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
785 case 0x7B: return v->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
786 }
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 /* Vehicle specific properties */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
789 switch (v->type) {
11985
e05790b0a6c6 (svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents: 11984
diff changeset
790 case VEH_TRAIN: {
12114
f020ec6be498 (svn r16527) -Codechange: use static member functions instead of simple casts when converting Vehicle to specialised vehicle types. Includes safety check
smatz <smatz@openttd.org>
parents: 12073
diff changeset
791 Train *t = Train::From(v);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
792 switch (variable - 0x80) {
11986
78abb48a4fba (svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents: 11985
diff changeset
793 case 0x62: return t->track;
78abb48a4fba (svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents: 11985
diff changeset
794 case 0x66: return t->railtype;
16788
efb0333e5aad (svn r21521) -Codechange: Unify some cached values that were present in both road vehicles and trains.
terkhen <terkhen@openttd.org>
parents: 16785
diff changeset
795 case 0x73: return t->gcache.cached_veh_length;
16785
775f357828e3 (svn r21518) -Codechange: Rename AccelerationCache to GroundVehicleCache.
terkhen <terkhen@openttd.org>
parents: 16783
diff changeset
796 case 0x74: return t->gcache.cached_power;
775f357828e3 (svn r21518) -Codechange: Rename AccelerationCache to GroundVehicleCache.
terkhen <terkhen@openttd.org>
parents: 16783
diff changeset
797 case 0x75: return GB(t->gcache.cached_power, 8, 24);
775f357828e3 (svn r21518) -Codechange: Rename AccelerationCache to GroundVehicleCache.
terkhen <terkhen@openttd.org>
parents: 16783
diff changeset
798 case 0x76: return GB(t->gcache.cached_power, 16, 16);
775f357828e3 (svn r21518) -Codechange: Rename AccelerationCache to GroundVehicleCache.
terkhen <terkhen@openttd.org>
parents: 16783
diff changeset
799 case 0x77: return GB(t->gcache.cached_power, 24, 8);
11985
e05790b0a6c6 (svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents: 11984
diff changeset
800 case 0x7C: return t->First()->index;
e05790b0a6c6 (svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents: 11984
diff changeset
801 case 0x7D: return GB(t->First()->index, 8, 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
802 case 0x7F: return 0; // Used for vehicle reversing hack in TTDP
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
803 }
15618
e4640748f223 (svn r20281) -Codechange: unify case scope closure + break coding style
rubidium <rubidium@openttd.org>
parents: 15540
diff changeset
804 break;
e4640748f223 (svn r20281) -Codechange: unify case scope closure + break coding style
rubidium <rubidium@openttd.org>
parents: 15540
diff changeset
805 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
806
11984
b6d3e583be86 (svn r16390) -Codechange: move u.road to RoadVehicle.
rubidium <rubidium@openttd.org>
parents: 11982
diff changeset
807 case VEH_ROAD: {
12114
f020ec6be498 (svn r16527) -Codechange: use static member functions instead of simple casts when converting Vehicle to specialised vehicle types. Includes safety check
smatz <smatz@openttd.org>
parents: 12073
diff changeset
808 RoadVehicle *rv = RoadVehicle::From(v);
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 switch (variable - 0x80) {
11984
b6d3e583be86 (svn r16390) -Codechange: move u.road to RoadVehicle.
rubidium <rubidium@openttd.org>
parents: 11982
diff changeset
810 case 0x62: return rv->state;
b6d3e583be86 (svn r16390) -Codechange: move u.road to RoadVehicle.
rubidium <rubidium@openttd.org>
parents: 11982
diff changeset
811 case 0x64: return rv->blocked_ctr;
b6d3e583be86 (svn r16390) -Codechange: move u.road to RoadVehicle.
rubidium <rubidium@openttd.org>
parents: 11982
diff changeset
812 case 0x65: return GB(rv->blocked_ctr, 8, 8);
b6d3e583be86 (svn r16390) -Codechange: move u.road to RoadVehicle.
rubidium <rubidium@openttd.org>
parents: 11982
diff changeset
813 case 0x66: return rv->overtaking;
b6d3e583be86 (svn r16390) -Codechange: move u.road to RoadVehicle.
rubidium <rubidium@openttd.org>
parents: 11982
diff changeset
814 case 0x67: return rv->overtaking_ctr;
b6d3e583be86 (svn r16390) -Codechange: move u.road to RoadVehicle.
rubidium <rubidium@openttd.org>
parents: 11982
diff changeset
815 case 0x68: return rv->crashed_ctr;
b6d3e583be86 (svn r16390) -Codechange: move u.road to RoadVehicle.
rubidium <rubidium@openttd.org>
parents: 11982
diff changeset
816 case 0x69: return GB(rv->crashed_ctr, 8, 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
817 }
15618
e4640748f223 (svn r20281) -Codechange: unify case scope closure + break coding style
rubidium <rubidium@openttd.org>
parents: 15540
diff changeset
818 break;
e4640748f223 (svn r20281) -Codechange: unify case scope closure + break coding style
rubidium <rubidium@openttd.org>
parents: 15540
diff changeset
819 }
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
11981
cf1aad9b971c (svn r16387) -Codechange: use Aircraft instead of Vehicle where appropriate
rubidium <rubidium@openttd.org>
parents: 11924
diff changeset
821 case VEH_AIRCRAFT: {
12114
f020ec6be498 (svn r16527) -Codechange: use static member functions instead of simple casts when converting Vehicle to specialised vehicle types. Includes safety check
smatz <smatz@openttd.org>
parents: 12073
diff changeset
822 Aircraft *a = Aircraft::From(v);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
823 switch (variable - 0x80) {
11981
cf1aad9b971c (svn r16387) -Codechange: use Aircraft instead of Vehicle where appropriate
rubidium <rubidium@openttd.org>
parents: 11924
diff changeset
824 case 0x62: return MapAircraftMovementState(a); // Current movement state
11982
9add5306a01e (svn r16388) -Codechange: move u.air to Aircraft
rubidium <rubidium@openttd.org>
parents: 11981
diff changeset
825 case 0x63: return a->targetairport; // Airport to which the action refers
11981
cf1aad9b971c (svn r16387) -Codechange: use Aircraft instead of Vehicle where appropriate
rubidium <rubidium@openttd.org>
parents: 11924
diff changeset
826 case 0x66: return MapAircraftMovementAction(a); // Current movement action
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
827 }
15618
e4640748f223 (svn r20281) -Codechange: unify case scope closure + break coding style
rubidium <rubidium@openttd.org>
parents: 15540
diff changeset
828 break;
e4640748f223 (svn r20281) -Codechange: unify case scope closure + break coding style
rubidium <rubidium@openttd.org>
parents: 15540
diff changeset
829 }
6621
c751437b3bac (svn r9841) -Codechange: add a little more type strictness to the vehicle types.
rubidium <rubidium@openttd.org>
parents: 6604
diff changeset
830
c751437b3bac (svn r9841) -Codechange: add a little more type strictness to the vehicle types.
rubidium <rubidium@openttd.org>
parents: 6604
diff changeset
831 default: 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
832 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
833
16474
17ecbae7d3b4 (svn r21198) -Fix: don't call variables properties in debug messages
rubidium <rubidium@openttd.org>
parents: 16383
diff changeset
834 DEBUG(grf, 1, "Unhandled vehicle variable 0x%X, type 0x%X", variable, (uint)v->type);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
835
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
836 *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
837 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
838 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
839
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
840
11990
db0e49f419d9 (svn r16396) -Codechange: split NewGRF spritegroup into multiple subclasses instead of using a big union
rubidium <rubidium@openttd.org>
parents: 11988
diff changeset
841 static const SpriteGroup *VehicleResolveReal(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
842 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
843 const Vehicle *v = object->u.vehicle.self;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
844
8599
8d23ba9f619f (svn r12180) -Fix: Test purchase list loading/loaded sprites instead of unconditionally returning a possibly non-existant sprite.
peter1138 <peter1138@openttd.org>
parents: 8556
diff changeset
845 if (v == NULL) {
11990
db0e49f419d9 (svn r16396) -Codechange: split NewGRF spritegroup into multiple subclasses instead of using a big union
rubidium <rubidium@openttd.org>
parents: 11988
diff changeset
846 if (group->num_loading > 0) return group->loading[0];
db0e49f419d9 (svn r16396) -Codechange: split NewGRF spritegroup into multiple subclasses instead of using a big union
rubidium <rubidium@openttd.org>
parents: 11988
diff changeset
847 if (group->num_loaded > 0) return group->loaded[0];
8599
8d23ba9f619f (svn r12180) -Fix: Test purchase list loading/loaded sprites instead of unconditionally returning a possibly non-existant sprite.
peter1138 <peter1138@openttd.org>
parents: 8556
diff changeset
848 return NULL;
8d23ba9f619f (svn r12180) -Fix: Test purchase list loading/loaded sprites instead of unconditionally returning a possibly non-existant sprite.
peter1138 <peter1138@openttd.org>
parents: 8556
diff changeset
849 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
850
8836
890a77315801 (svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents: 8786
diff changeset
851 bool in_motion = !v->First()->current_order.IsType(OT_LOADING);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
852
11990
db0e49f419d9 (svn r16396) -Codechange: split NewGRF spritegroup into multiple subclasses instead of using a big union
rubidium <rubidium@openttd.org>
parents: 11988
diff changeset
853 uint totalsets = in_motion ? group->num_loaded : group->num_loading;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
854
15540
f47ab35641c8 (svn r20199) -Fix [FS#3964]: NewGRFs that defined a vehicle without either loaded or loading groups could crash OpenTTD
yexo <yexo@openttd.org>
parents: 15521
diff changeset
855 if (totalsets == 0) return NULL;
f47ab35641c8 (svn r20199) -Fix [FS#3964]: NewGRFs that defined a vehicle without either loaded or loading groups could crash OpenTTD
yexo <yexo@openttd.org>
parents: 15521
diff changeset
856
10425
3375c20e9bae (svn r14678) -Fix [FS#2435]: gradual filling graphics were not chosen according to the NewGRF spec (Maedhros)
rubidium <rubidium@openttd.org>
parents: 10416
diff changeset
857 uint set = (v->cargo.Count() * totalsets) / max((uint16)1, v->cargo_cap);
3375c20e9bae (svn r14678) -Fix [FS#2435]: gradual filling graphics were not chosen according to the NewGRF spec (Maedhros)
rubidium <rubidium@openttd.org>
parents: 10416
diff changeset
858 set = min(set, totalsets - 1);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
859
11990
db0e49f419d9 (svn r16396) -Codechange: split NewGRF spritegroup into multiple subclasses instead of using a big union
rubidium <rubidium@openttd.org>
parents: 11988
diff changeset
860 return in_motion ? group->loaded[set] : 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
861 }
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
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
864 static inline void NewVehicleResolver(ResolverObject *res, EngineID engine_type, const Vehicle *v)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
865 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
866 res->GetRandomBits = &VehicleGetRandomBits;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
867 res->GetTriggers = &VehicleGetTriggers;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
868 res->SetTriggers = &VehicleSetTriggers;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
869 res->GetVariable = &VehicleGetVariable;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
870 res->ResolveReal = &VehicleResolveReal;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
871
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
872 res->u.vehicle.self = v;
7548
c0e537dd249b (svn r11068) -Codechange: remove Vehicle::HasFront as all vehicles have the Vehicle::first pointer correctly set.
rubidium <rubidium@openttd.org>
parents: 7497
diff changeset
873 res->u.vehicle.parent = (v != NULL) ? v->First() : v;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
874
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
875 res->u.vehicle.self_type = engine_type;
13166
ac8a6c5b739c (svn r17671) -Codechange: Move ResolverObject::info_view into u.vehicle as it is only needed for them.
frosch <frosch@openttd.org>
parents: 13114
diff changeset
876 res->u.vehicle.info_view = false;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
877
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: 7169
diff changeset
878 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
879 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
880 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
881 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
882 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
883 res->reseed = 0;
8756
ae0ec91bb55e (svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx <glx@openttd.org>
parents: 8666
diff changeset
884 res->count = 0;
9750
0654bf387d06 (svn r13885) -Fix [FS#2168]: Var 0x7F is not feature-specific.
frosch <frosch@openttd.org>
parents: 9672
diff changeset
885
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11875
diff changeset
886 const Engine *e = Engine::Get(engine_type);
15763
a60a50f29f64 (svn r20437) -Codechange: lets Engines use GRFFilePropsBase as well
rubidium <rubidium@openttd.org>
parents: 15620
diff changeset
887 res->grffile = (e != NULL ? e->grf_prop.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
888 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
889
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
890
15620
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15618
diff changeset
891 /**
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15618
diff changeset
892 * Retrieve the SpriteGroup for the specified vehicle.
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
893 * If the vehicle is not specified, the purchase list group for the engine is
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
894 * chosen. For trains, an additional engine override lookup is performed.
7863
ea337dd0527c (svn r11413) -Fix [FS#1405]: don't use cached override spriteset for callbacks
glx <glx@openttd.org>
parents: 7861
diff changeset
895 * @param engine Engine type of the vehicle.
ea337dd0527c (svn r11413) -Fix [FS#1405]: don't use cached override spriteset for callbacks
glx <glx@openttd.org>
parents: 7861
diff changeset
896 * @param v The vehicle itself.
ea337dd0527c (svn r11413) -Fix [FS#1405]: don't use cached override spriteset for callbacks
glx <glx@openttd.org>
parents: 7861
diff changeset
897 * @param use_cache Use cached override
ea337dd0527c (svn r11413) -Fix [FS#1405]: don't use cached override spriteset for callbacks
glx <glx@openttd.org>
parents: 7861
diff changeset
898 * @returns The selected SpriteGroup for the vehicle.
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 */
7863
ea337dd0527c (svn r11413) -Fix [FS#1405]: don't use cached override spriteset for callbacks
glx <glx@openttd.org>
parents: 7861
diff changeset
900 static const SpriteGroup *GetVehicleSpriteGroup(EngineID engine, const Vehicle *v, bool use_cache = true)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
901 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
902 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
903 CargoID cargo;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
904
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
905 if (v == 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: 6147
diff changeset
906 cargo = 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
907 } else {
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: 6147
diff changeset
908 cargo = v->cargo_type;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
909
16788
efb0333e5aad (svn r21521) -Codechange: Unify some cached values that were present in both road vehicles and trains.
terkhen <terkhen@openttd.org>
parents: 16785
diff changeset
910 if (v->IsGroundVehicle()) {
efb0333e5aad (svn r21521) -Codechange: Unify some cached values that were present in both road vehicles and trains.
terkhen <terkhen@openttd.org>
parents: 16785
diff changeset
911 /* For trains we always use cached value, except for callbacks because the override spriteset
7863
ea337dd0527c (svn r11413) -Fix [FS#1405]: don't use cached override spriteset for callbacks
glx <glx@openttd.org>
parents: 7861
diff changeset
912 * to use may be different than the one cached. It happens for callback 0x15 (refit engine),
ea337dd0527c (svn r11413) -Fix [FS#1405]: don't use cached override spriteset for callbacks
glx <glx@openttd.org>
parents: 7861
diff changeset
913 * as v->cargo_type is temporary changed to the new type */
16788
efb0333e5aad (svn r21521) -Codechange: Unify some cached values that were present in both road vehicles and trains.
terkhen <terkhen@openttd.org>
parents: 16785
diff changeset
914 if (use_cache && v->type == VEH_TRAIN) {
efb0333e5aad (svn r21521) -Codechange: Unify some cached values that were present in both road vehicles and trains.
terkhen <terkhen@openttd.org>
parents: 16785
diff changeset
915 group = Train::From(v)->tcache.cached_override;
efb0333e5aad (svn r21521) -Codechange: Unify some cached values that were present in both road vehicles and trains.
terkhen <terkhen@openttd.org>
parents: 16785
diff changeset
916 } else {
efb0333e5aad (svn r21521) -Codechange: Unify some cached values that were present in both road vehicles and trains.
terkhen <terkhen@openttd.org>
parents: 16785
diff changeset
917 group = GetWagonOverrideSpriteSet(v->engine_type, v->cargo_type, v->GetGroundVehicleCache()->first_engine);
efb0333e5aad (svn r21521) -Codechange: Unify some cached values that were present in both road vehicles and trains.
terkhen <terkhen@openttd.org>
parents: 16785
diff changeset
918 }
11166
504cd363813f (svn r15516) -Fix (r10097): Livery overrides for articulated parts of roadvehicles were not applied.
frosch <frosch@openttd.org>
parents: 11059
diff changeset
919 if (group != NULL) return 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
920 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
921 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
922
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11875
diff changeset
923 const Engine *e = Engine::Get(engine);
9070
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
924
15763
a60a50f29f64 (svn r20437) -Codechange: lets Engines use GRFFilePropsBase as well
rubidium <rubidium@openttd.org>
parents: 15620
diff changeset
925 assert(cargo < lengthof(e->grf_prop.spritegroup));
a60a50f29f64 (svn r20437) -Codechange: lets Engines use GRFFilePropsBase as well
rubidium <rubidium@openttd.org>
parents: 15620
diff changeset
926 group = e->grf_prop.spritegroup[cargo];
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
927 if (group != NULL) return group;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
928
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
929 /* Fall back to the default set if the selected cargo type is not defined */
15763
a60a50f29f64 (svn r20437) -Codechange: lets Engines use GRFFilePropsBase as well
rubidium <rubidium@openttd.org>
parents: 15620
diff changeset
930 return e->grf_prop.spritegroup[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
931 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
932
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
933
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
934 SpriteID GetCustomEngineSprite(EngineID engine, const Vehicle *v, Direction direction)
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 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
937 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
938
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
939 NewVehicleResolver(&object, engine, v);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
940
11996
b43cf6c7ea61 (svn r16402) -Codechange: make Resolve a function of SpriteGroup
rubidium <rubidium@openttd.org>
parents: 11990
diff changeset
941 group = SpriteGroup::Resolve(GetVehicleSpriteGroup(engine, v), &object);
11990
db0e49f419d9 (svn r16396) -Codechange: split NewGRF spritegroup into multiple subclasses instead of using a big union
rubidium <rubidium@openttd.org>
parents: 11988
diff changeset
942 if (group == NULL || group->GetNumResults() == 0) 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
943
11990
db0e49f419d9 (svn r16396) -Codechange: split NewGRF spritegroup into multiple subclasses instead of using a big union
rubidium <rubidium@openttd.org>
parents: 11988
diff changeset
944 return group->GetResult() + (direction % group->GetNumResults());
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
945 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
946
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
947
11981
cf1aad9b971c (svn r16387) -Codechange: use Aircraft instead of Vehicle where appropriate
rubidium <rubidium@openttd.org>
parents: 11924
diff changeset
948 SpriteID GetRotorOverrideSprite(EngineID engine, const Aircraft *v, bool info_view)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
949 {
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11875
diff changeset
950 const Engine *e = Engine::Get(engine);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
951
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
952 /* Only valid for helicopters */
9436
b3969ef775ba (svn r13351) -Codechange: disable warnings about unused variable for builds without asserts
smatz <smatz@openttd.org>
parents: 9413
diff changeset
953 assert(e->type == VEH_AIRCRAFT);
9070
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
954 assert(!(e->u.air.subtype & AIR_CTOL));
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
955
9436
b3969ef775ba (svn r13351) -Codechange: disable warnings about unused variable for builds without asserts
smatz <smatz@openttd.org>
parents: 9413
diff changeset
956 ResolverObject object;
b3969ef775ba (svn r13351) -Codechange: disable warnings about unused variable for builds without asserts
smatz <smatz@openttd.org>
parents: 9413
diff changeset
957
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
958 NewVehicleResolver(&object, engine, v);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
959
13166
ac8a6c5b739c (svn r17671) -Codechange: Move ResolverObject::info_view into u.vehicle as it is only needed for them.
frosch <frosch@openttd.org>
parents: 13114
diff changeset
960 object.u.vehicle.info_view = info_view;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
961
9436
b3969ef775ba (svn r13351) -Codechange: disable warnings about unused variable for builds without asserts
smatz <smatz@openttd.org>
parents: 9413
diff changeset
962 const SpriteGroup *group = GetWagonOverrideSpriteSet(engine, CT_DEFAULT, engine);
11996
b43cf6c7ea61 (svn r16402) -Codechange: make Resolve a function of SpriteGroup
rubidium <rubidium@openttd.org>
parents: 11990
diff changeset
963 group = 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
964
11990
db0e49f419d9 (svn r16396) -Codechange: split NewGRF spritegroup into multiple subclasses instead of using a big union
rubidium <rubidium@openttd.org>
parents: 11988
diff changeset
965 if (group == NULL || group->GetNumResults() == 0) 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
966
11990
db0e49f419d9 (svn r16396) -Codechange: split NewGRF spritegroup into multiple subclasses instead of using a big union
rubidium <rubidium@openttd.org>
parents: 11988
diff changeset
967 if (v == NULL) return group->GetResult();
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
968
11990
db0e49f419d9 (svn r16396) -Codechange: split NewGRF spritegroup into multiple subclasses instead of using a big union
rubidium <rubidium@openttd.org>
parents: 11988
diff changeset
969 return group->GetResult() + (info_view ? 0 : (v->Next()->Next()->state % group->GetNumResults()));
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
970 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
971
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
972
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
973 /**
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
974 * Check if a wagon is currently using a wagon override
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
975 * @param v The wagon to check
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
976 * @return true if it is using an override, false otherwise
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
977 */
10647
592ae9307430 (svn r14949) -Cleanup: pointer coding style
rubidium <rubidium@openttd.org>
parents: 10643
diff changeset
978 bool UsesWagonOverride(const Vehicle *v)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
979 {
6259
4a39d6291d58 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium <rubidium@openttd.org>
parents: 6248
diff changeset
980 assert(v->type == VEH_TRAIN);
12114
f020ec6be498 (svn r16527) -Codechange: use static member functions instead of simple casts when converting Vehicle to specialised vehicle types. Includes safety check
smatz <smatz@openttd.org>
parents: 12073
diff changeset
981 return Train::From(v)->tcache.cached_override != 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
982 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
983
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
984 /**
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
985 * Evaluate a newgrf callback for vehicles
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
986 * @param callback The callback to evalute
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
987 * @param param1 First parameter of the callback
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
988 * @param param2 Second parameter of the callback
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
989 * @param engine Engine type of the vehicle to evaluate the callback for
6481
85a1a79387a2 (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas <belugas@openttd.org>
parents: 6348
diff changeset
990 * @param v The vehicle to evaluate the callback for, or NULL if it doesnt exist yet
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
991 * @return The value the callback returned, or CALLBACK_FAILED if it failed
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
992 */
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: 7169
diff changeset
993 uint16 GetVehicleCallback(CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
994 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
995 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
996 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
997
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
998 NewVehicleResolver(&object, engine, v);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
999
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1000 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
1001 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
1002 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
1003
11996
b43cf6c7ea61 (svn r16402) -Codechange: make Resolve a function of SpriteGroup
rubidium <rubidium@openttd.org>
parents: 11990
diff changeset
1004 group = SpriteGroup::Resolve(GetVehicleSpriteGroup(engine, v, false), &object);
11990
db0e49f419d9 (svn r16396) -Codechange: split NewGRF spritegroup into multiple subclasses instead of using a big union
rubidium <rubidium@openttd.org>
parents: 11988
diff changeset
1005 if (group == NULL) return CALLBACK_FAILED;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1006
11990
db0e49f419d9 (svn r16396) -Codechange: split NewGRF spritegroup into multiple subclasses instead of using a big union
rubidium <rubidium@openttd.org>
parents: 11988
diff changeset
1007 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
1008 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1009
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1010 /**
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1011 * Evaluate a newgrf callback for vehicles with a different vehicle for parent scope.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1012 * @param callback The callback to evalute
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1013 * @param param1 First parameter of the callback
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1014 * @param param2 Second parameter of the callback
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1015 * @param engine Engine type of the vehicle to evaluate the callback for
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1016 * @param v The vehicle to evaluate the callback for, or NULL if it doesnt exist yet
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1017 * @param parent The vehicle to use for parent scope
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1018 * @return The value the callback returned, or CALLBACK_FAILED if it failed
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1019 */
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: 7169
diff changeset
1020 uint16 GetVehicleCallbackParent(CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v, const Vehicle *parent)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1021 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1022 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
1023 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
1024
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1025 NewVehicleResolver(&object, engine, v);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1026
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1027 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
1028 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
1029 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
1030
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1031 object.u.vehicle.parent = parent;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1032
11996
b43cf6c7ea61 (svn r16402) -Codechange: make Resolve a function of SpriteGroup
rubidium <rubidium@openttd.org>
parents: 11990
diff changeset
1033 group = SpriteGroup::Resolve(GetVehicleSpriteGroup(engine, v, false), &object);
11990
db0e49f419d9 (svn r16396) -Codechange: split NewGRF spritegroup into multiple subclasses instead of using a big union
rubidium <rubidium@openttd.org>
parents: 11988
diff changeset
1034 if (group == NULL) return CALLBACK_FAILED;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1035
11990
db0e49f419d9 (svn r16396) -Codechange: split NewGRF spritegroup into multiple subclasses instead of using a big union
rubidium <rubidium@openttd.org>
parents: 11988
diff changeset
1036 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
1037 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1038
6490
fcc1843c68c6 (svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138 <peter1138@openttd.org>
parents: 6481
diff changeset
1039
6517
bfa6449a2b3a (svn r9703) -Codechange: support callback 36 in vehicle purchase lists
peter1138 <peter1138@openttd.org>
parents: 6516
diff changeset
1040 /* Callback 36 handlers */
13114
940252f91c5f (svn r17616) -Codechange [FS#3222]: Enumerize properties used in callback 0x36. Based on Terkhen's work.
frosch <frosch@openttd.org>
parents: 13054
diff changeset
1041 uint GetVehicleProperty(const Vehicle *v, PropertyID property, uint orig_value)
6490
fcc1843c68c6 (svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138 <peter1138@openttd.org>
parents: 6481
diff changeset
1042 {
fcc1843c68c6 (svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138 <peter1138@openttd.org>
parents: 6481
diff changeset
1043 uint16 callback = GetVehicleCallback(CBID_VEHICLE_MODIFY_PROPERTY, property, 0, v->engine_type, v);
fcc1843c68c6 (svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138 <peter1138@openttd.org>
parents: 6481
diff changeset
1044 if (callback != CALLBACK_FAILED) return callback;
fcc1843c68c6 (svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138 <peter1138@openttd.org>
parents: 6481
diff changeset
1045
fcc1843c68c6 (svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138 <peter1138@openttd.org>
parents: 6481
diff changeset
1046 return orig_value;
fcc1843c68c6 (svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138 <peter1138@openttd.org>
parents: 6481
diff changeset
1047 }
fcc1843c68c6 (svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138 <peter1138@openttd.org>
parents: 6481
diff changeset
1048
fcc1843c68c6 (svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138 <peter1138@openttd.org>
parents: 6481
diff changeset
1049
13114
940252f91c5f (svn r17616) -Codechange [FS#3222]: Enumerize properties used in callback 0x36. Based on Terkhen's work.
frosch <frosch@openttd.org>
parents: 13054
diff changeset
1050 uint GetEngineProperty(EngineID engine, PropertyID property, uint orig_value)
6517
bfa6449a2b3a (svn r9703) -Codechange: support callback 36 in vehicle purchase lists
peter1138 <peter1138@openttd.org>
parents: 6516
diff changeset
1051 {
bfa6449a2b3a (svn r9703) -Codechange: support callback 36 in vehicle purchase lists
peter1138 <peter1138@openttd.org>
parents: 6516
diff changeset
1052 uint16 callback = GetVehicleCallback(CBID_VEHICLE_MODIFY_PROPERTY, property, 0, engine, NULL);
bfa6449a2b3a (svn r9703) -Codechange: support callback 36 in vehicle purchase lists
peter1138 <peter1138@openttd.org>
parents: 6516
diff changeset
1053 if (callback != CALLBACK_FAILED) return callback;
bfa6449a2b3a (svn r9703) -Codechange: support callback 36 in vehicle purchase lists
peter1138 <peter1138@openttd.org>
parents: 6516
diff changeset
1054
bfa6449a2b3a (svn r9703) -Codechange: support callback 36 in vehicle purchase lists
peter1138 <peter1138@openttd.org>
parents: 6516
diff changeset
1055 return orig_value;
bfa6449a2b3a (svn r9703) -Codechange: support callback 36 in vehicle purchase lists
peter1138 <peter1138@openttd.org>
parents: 6516
diff changeset
1056 }
bfa6449a2b3a (svn r9703) -Codechange: support callback 36 in vehicle purchase lists
peter1138 <peter1138@openttd.org>
parents: 6516
diff changeset
1057
bfa6449a2b3a (svn r9703) -Codechange: support callback 36 in vehicle purchase lists
peter1138 <peter1138@openttd.org>
parents: 6516
diff changeset
1058
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1059 static void DoTriggerVehicle(Vehicle *v, VehicleTrigger trigger, byte base_random_bits, bool first)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1060 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1061 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
1062 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
1063 byte new_random_bits;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1064
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1065 /* We can't trigger a non-existent vehicle... */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1066 assert(v != NULL);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1067
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1068 NewVehicleResolver(&object, v->engine_type, v);
7169
bb0d45d67816 (svn r10443) -Fix: randomizing triggers should be called with callback type set to 1
peter1138 <peter1138@openttd.org>
parents: 7010
diff changeset
1069 object.callback = CBID_RANDOM_TRIGGER;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1070 object.trigger = trigger;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1071
11996
b43cf6c7ea61 (svn r16402) -Codechange: make Resolve a function of SpriteGroup
rubidium <rubidium@openttd.org>
parents: 11990
diff changeset
1072 group = SpriteGroup::Resolve(GetVehicleSpriteGroup(v->engine_type, v), &object);
7861
6986bc3b90e4 (svn r11411) -Codechange: implement random triggers for houses.
rubidium <rubidium@openttd.org>
parents: 7803
diff changeset
1073 if (group == NULL) 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
1074
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1075 new_random_bits = Random();
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1076 v->random_bits &= ~object.reseed;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1077 v->random_bits |= (first ? new_random_bits : base_random_bits) & object.reseed;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1078
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1079 switch (trigger) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1080 case VEHICLE_TRIGGER_NEW_CARGO:
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1081 /* All vehicles in chain get ANY_NEW_CARGO trigger now.
11368
82c90cd591ab (svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
rubidium <rubidium@openttd.org>
parents: 11268
diff changeset
1082 * So we call it for the first one and they will recurse.
82c90cd591ab (svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
rubidium <rubidium@openttd.org>
parents: 11268
diff changeset
1083 * Indexing part of vehicle random bits needs to be
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1084 * same for all triggered vehicles in the chain (to get
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1085 * all the random-cargo wagons carry the same cargo,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1086 * i.e.), so we give them all the NEW_CARGO triggered
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1087 * vehicle's portion of random bits. */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1088 assert(first);
7550
407f019260d3 (svn r11070) -Fix [FS#1217]: due to making an Action2 variable work properly, the NewGRF called other code too that wasn't prepared for non-train vehicles.
rubidium <rubidium@openttd.org>
parents: 7548
diff changeset
1089 DoTriggerVehicle(v->First(), VEHICLE_TRIGGER_ANY_NEW_CARGO, new_random_bits, false);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1090 break;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1091
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1092 case VEHICLE_TRIGGER_DEPOT:
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1093 /* We now trigger the next vehicle in chain recursively.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1094 * The random bits portions may be different for each
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1095 * vehicle in chain. */
7492
09743324277c (svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium <rubidium@openttd.org>
parents: 7327
diff changeset
1096 if (v->Next() != NULL) DoTriggerVehicle(v->Next(), trigger, 0, true);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1097 break;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1098
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1099 case VEHICLE_TRIGGER_EMPTY:
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1100 /* We now trigger the next vehicle in chain
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1101 * recursively. The random bits portions must be same
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1102 * for each vehicle in chain, so we give them all
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1103 * first chained vehicle's portion of random bits. */
7492
09743324277c (svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium <rubidium@openttd.org>
parents: 7327
diff changeset
1104 if (v->Next() != NULL) DoTriggerVehicle(v->Next(), trigger, first ? new_random_bits : base_random_bits, false);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1105 break;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1106
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1107 case VEHICLE_TRIGGER_ANY_NEW_CARGO:
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1108 /* Now pass the trigger recursively to the next vehicle
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1109 * in chain. */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1110 assert(!first);
7492
09743324277c (svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium <rubidium@openttd.org>
parents: 7327
diff changeset
1111 if (v->Next() != NULL) DoTriggerVehicle(v->Next(), VEHICLE_TRIGGER_ANY_NEW_CARGO, base_random_bits, false);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1112 break;
7803
1ad76d7d65b8 (svn r11353) -Codechange: add support for newgrf callback 32
glx <glx@openttd.org>
parents: 7550
diff changeset
1113
1ad76d7d65b8 (svn r11353) -Codechange: add support for newgrf callback 32
glx <glx@openttd.org>
parents: 7550
diff changeset
1114 case VEHICLE_TRIGGER_CALLBACK_32:
1ad76d7d65b8 (svn r11353) -Codechange: add support for newgrf callback 32
glx <glx@openttd.org>
parents: 7550
diff changeset
1115 /* Do not do any recursion */
1ad76d7d65b8 (svn r11353) -Codechange: add support for newgrf callback 32
glx <glx@openttd.org>
parents: 7550
diff changeset
1116 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
1117 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1118 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1119
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1120 void TriggerVehicle(Vehicle *v, VehicleTrigger trigger)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1121 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1122 if (trigger == VEHICLE_TRIGGER_DEPOT) {
6348
bcf98ba27bbf (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents: 6259
diff changeset
1123 /* store that the vehicle entered a depot this tick */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1124 VehicleEnteredDepotThisTick(v);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1125 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1126
12073
02d3a628e6db (svn r16480) -Fix (r15617): Invalidate newgrf variable caches of more vehicles in more places. Esp. they were only invalidated for trains.
frosch <frosch@openttd.org>
parents: 12071
diff changeset
1127 v->InvalidateNewGRFCacheOfChain();
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1128 DoTriggerVehicle(v, trigger, 0, true);
12073
02d3a628e6db (svn r16480) -Fix (r15617): Invalidate newgrf variable caches of more vehicles in more places. Esp. they were only invalidated for trains.
frosch <frosch@openttd.org>
parents: 12071
diff changeset
1129 v->InvalidateNewGRFCacheOfChain();
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1130 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1131
6348
bcf98ba27bbf (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents: 6259
diff changeset
1132 /* Functions for changing the order of vehicle purchase lists
bcf98ba27bbf (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents: 6259
diff changeset
1133 * This is currently only implemented for rail vehicles. */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1134
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1135 /**
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1136 * Get the list position of an engine.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1137 * Used when sorting a list of engines.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1138 * @param engine ID of the engine.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1139 * @return The list position of the engine.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1140 */
9070
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
1141 uint ListPositionOfEngine(EngineID engine)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1142 {
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11875
diff changeset
1143 const Engine *e = Engine::Get(engine);
15763
a60a50f29f64 (svn r20437) -Codechange: lets Engines use GRFFilePropsBase as well
rubidium <rubidium@openttd.org>
parents: 15620
diff changeset
1144 if (e->grf_prop.grffile == NULL) return e->list_position;
9070
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
1145
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
1146 /* Crude sorting to group by GRF ID */
15763
a60a50f29f64 (svn r20437) -Codechange: lets Engines use GRFFilePropsBase as well
rubidium <rubidium@openttd.org>
parents: 15620
diff changeset
1147 return (e->grf_prop.grffile->grfid * 256) + e->list_position;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1148 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1149
9070
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
1150 struct ListOrderChange {
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
1151 EngineID engine;
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
1152 EngineID target;
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
1153 };
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
1154
10416
25ae1dbfcf45 (svn r14669) -Codechange: use SmallVector instead of std::list at one place
smatz <smatz@openttd.org>
parents: 10208
diff changeset
1155 static SmallVector<ListOrderChange, 16> _list_order_changes;
9070
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
1156
9672
28e252610709 (svn r13761) -Codechange: Remove dependency on rail for altering purchase list position (mostly function renaming)
peter1138 <peter1138@openttd.org>
parents: 9652
diff changeset
1157 void AlterVehicleListOrder(EngineID engine, EngineID target)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1158 {
9070
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
1159 /* Add the list order change to a queue */
10416
25ae1dbfcf45 (svn r14669) -Codechange: use SmallVector instead of std::list at one place
smatz <smatz@openttd.org>
parents: 10208
diff changeset
1160 ListOrderChange *loc = _list_order_changes.Append();
25ae1dbfcf45 (svn r14669) -Codechange: use SmallVector instead of std::list at one place
smatz <smatz@openttd.org>
parents: 10208
diff changeset
1161 loc->engine = engine;
25ae1dbfcf45 (svn r14669) -Codechange: use SmallVector instead of std::list at one place
smatz <smatz@openttd.org>
parents: 10208
diff changeset
1162 loc->target = target;
9070
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
1163 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1164
9672
28e252610709 (svn r13761) -Codechange: Remove dependency on rail for altering purchase list position (mostly function renaming)
peter1138 <peter1138@openttd.org>
parents: 9652
diff changeset
1165 void CommitVehicleListOrderChanges()
9070
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
1166 {
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
1167 /* List position to Engine map */
10487
75d47d3e0644 (svn r14742) -Codechange: use SmallMap in two cases to reduce compilation time and binary size
smatz <smatz@openttd.org>
parents: 10425
diff changeset
1168 typedef SmallMap<uint16, Engine *, 16> ListPositionMap;
9070
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
1169 ListPositionMap lptr_map;
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
1170
10416
25ae1dbfcf45 (svn r14669) -Codechange: use SmallVector instead of std::list at one place
smatz <smatz@openttd.org>
parents: 10208
diff changeset
1171 const ListOrderChange *end = _list_order_changes.End();
25ae1dbfcf45 (svn r14669) -Codechange: use SmallVector instead of std::list at one place
smatz <smatz@openttd.org>
parents: 10208
diff changeset
1172 for (const ListOrderChange *it = _list_order_changes.Begin(); it != end; ++it) {
9070
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
1173 EngineID engine = it->engine;
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
1174 EngineID target = it->target;
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
1175
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
1176 if (engine == target) continue;
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
1177
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11875
diff changeset
1178 Engine *source_e = Engine::Get(engine);
9070
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
1179 Engine *target_e = 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
1180
9070
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
1181 /* Populate map with current list positions */
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
1182 Engine *e;
9672
28e252610709 (svn r13761) -Codechange: Remove dependency on rail for altering purchase list position (mostly function renaming)
peter1138 <peter1138@openttd.org>
parents: 9652
diff changeset
1183 FOR_ALL_ENGINES_OF_TYPE(e, source_e->type) {
15763
a60a50f29f64 (svn r20437) -Codechange: lets Engines use GRFFilePropsBase as well
rubidium <rubidium@openttd.org>
parents: 15620
diff changeset
1184 if (!_settings_game.vehicle.dynamic_engines || e->grf_prop.grffile == source_e->grf_prop.grffile) {
a60a50f29f64 (svn r20437) -Codechange: lets Engines use GRFFilePropsBase as well
rubidium <rubidium@openttd.org>
parents: 15620
diff changeset
1185 if (e->grf_prop.local_id == target) target_e = e;
9070
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
1186 lptr_map[e->list_position] = e;
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
1187 }
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
1188 }
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
1189
10519
49cdb0bc8ad6 (svn r14776) -Fix (r14742): ListPositionMap relied on std::map having sorted the map, which is now done by a manual key sorter on SmallMap. This fixes engine ID list sorting.
peter1138 <peter1138@openttd.org>
parents: 10487
diff changeset
1190 /* std::map sorted by default, SmallMap does not */
49cdb0bc8ad6 (svn r14776) -Fix (r14742): ListPositionMap relied on std::map having sorted the map, which is now done by a manual key sorter on SmallMap. This fixes engine ID list sorting.
peter1138 <peter1138@openttd.org>
parents: 10487
diff changeset
1191 lptr_map.SortByKey();
49cdb0bc8ad6 (svn r14776) -Fix (r14742): ListPositionMap relied on std::map having sorted the map, which is now done by a manual key sorter on SmallMap. This fixes engine ID list sorting.
peter1138 <peter1138@openttd.org>
parents: 10487
diff changeset
1192
9070
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
1193 /* Get the target position, if it exists */
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
1194 if (target_e != NULL) {
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
1195 uint16 target_position = target_e->list_position;
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
1196
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
1197 bool moving = false;
10487
75d47d3e0644 (svn r14742) -Codechange: use SmallMap in two cases to reduce compilation time and binary size
smatz <smatz@openttd.org>
parents: 10425
diff changeset
1198 const ListPositionMap::Pair *end = lptr_map.End();
75d47d3e0644 (svn r14742) -Codechange: use SmallMap in two cases to reduce compilation time and binary size
smatz <smatz@openttd.org>
parents: 10425
diff changeset
1199 for (ListPositionMap::Pair *it = lptr_map.Begin(); it != end; ++it) {
9070
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
1200 if (it->first == target_position) moving = true;
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
1201 if (moving) it->second->list_position++;
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
1202 }
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
1203
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
1204 source_e->list_position = target_position;
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
1205 }
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
1206
10487
75d47d3e0644 (svn r14742) -Codechange: use SmallMap in two cases to reduce compilation time and binary size
smatz <smatz@openttd.org>
parents: 10425
diff changeset
1207 lptr_map.Clear();
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1208 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1209
9070
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9062
diff changeset
1210 /* Clear out the queue */
10416
25ae1dbfcf45 (svn r14669) -Codechange: use SmallVector instead of std::list at one place
smatz <smatz@openttd.org>
parents: 10208
diff changeset
1211 _list_order_changes.Reset();
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1212 }
15081
961ab6166e79 (svn r19707) -Add: helper functions to instantiate/fill ResolverObjects
rubidium <rubidium@openttd.org>
parents: 14859
diff changeset
1213
961ab6166e79 (svn r19707) -Add: helper functions to instantiate/fill ResolverObjects
rubidium <rubidium@openttd.org>
parents: 14859
diff changeset
1214 /**
961ab6166e79 (svn r19707) -Add: helper functions to instantiate/fill ResolverObjects
rubidium <rubidium@openttd.org>
parents: 14859
diff changeset
1215 * Resolve an engine's spec and such so we can get a variable.
961ab6166e79 (svn r19707) -Add: helper functions to instantiate/fill ResolverObjects
rubidium <rubidium@openttd.org>
parents: 14859
diff changeset
1216 * @param ro The resolver object to fill.
961ab6166e79 (svn r19707) -Add: helper functions to instantiate/fill ResolverObjects
rubidium <rubidium@openttd.org>
parents: 14859
diff changeset
1217 * @param index The vehicle to get the data from.
961ab6166e79 (svn r19707) -Add: helper functions to instantiate/fill ResolverObjects
rubidium <rubidium@openttd.org>
parents: 14859
diff changeset
1218 */
961ab6166e79 (svn r19707) -Add: helper functions to instantiate/fill ResolverObjects
rubidium <rubidium@openttd.org>
parents: 14859
diff changeset
1219 void GetVehicleResolver(ResolverObject *ro, uint index)
961ab6166e79 (svn r19707) -Add: helper functions to instantiate/fill ResolverObjects
rubidium <rubidium@openttd.org>
parents: 14859
diff changeset
1220 {
961ab6166e79 (svn r19707) -Add: helper functions to instantiate/fill ResolverObjects
rubidium <rubidium@openttd.org>
parents: 14859
diff changeset
1221 Vehicle *v = Vehicle::Get(index);
961ab6166e79 (svn r19707) -Add: helper functions to instantiate/fill ResolverObjects
rubidium <rubidium@openttd.org>
parents: 14859
diff changeset
1222 NewVehicleResolver(ro, v->engine_type, v);
961ab6166e79 (svn r19707) -Add: helper functions to instantiate/fill ResolverObjects
rubidium <rubidium@openttd.org>
parents: 14859
diff changeset
1223 }
16608
9537147e9ffb (svn r21338) -Fix [FS#4272]: bogus cache mismatch warnings with desync debugging because some cache was invalidated but never reset
rubidium <rubidium@openttd.org>
parents: 16474
diff changeset
1224
9537147e9ffb (svn r21338) -Fix [FS#4272]: bogus cache mismatch warnings with desync debugging because some cache was invalidated but never reset
rubidium <rubidium@openttd.org>
parents: 16474
diff changeset
1225 /**
9537147e9ffb (svn r21338) -Fix [FS#4272]: bogus cache mismatch warnings with desync debugging because some cache was invalidated but never reset
rubidium <rubidium@openttd.org>
parents: 16474
diff changeset
1226 * Fill the grf_cache of the given vehicle.
9537147e9ffb (svn r21338) -Fix [FS#4272]: bogus cache mismatch warnings with desync debugging because some cache was invalidated but never reset
rubidium <rubidium@openttd.org>
parents: 16474
diff changeset
1227 * @param v The vehicle to fill the cache for.
9537147e9ffb (svn r21338) -Fix [FS#4272]: bogus cache mismatch warnings with desync debugging because some cache was invalidated but never reset
rubidium <rubidium@openttd.org>
parents: 16474
diff changeset
1228 */
9537147e9ffb (svn r21338) -Fix [FS#4272]: bogus cache mismatch warnings with desync debugging because some cache was invalidated but never reset
rubidium <rubidium@openttd.org>
parents: 16474
diff changeset
1229 void FillNewGRFVehicleCache(const Vehicle *v)
9537147e9ffb (svn r21338) -Fix [FS#4272]: bogus cache mismatch warnings with desync debugging because some cache was invalidated but never reset
rubidium <rubidium@openttd.org>
parents: 16474
diff changeset
1230 {
9537147e9ffb (svn r21338) -Fix [FS#4272]: bogus cache mismatch warnings with desync debugging because some cache was invalidated but never reset
rubidium <rubidium@openttd.org>
parents: 16474
diff changeset
1231 ResolverObject ro;
9537147e9ffb (svn r21338) -Fix [FS#4272]: bogus cache mismatch warnings with desync debugging because some cache was invalidated but never reset
rubidium <rubidium@openttd.org>
parents: 16474
diff changeset
1232 memset(&ro, 0, sizeof(ro));
9537147e9ffb (svn r21338) -Fix [FS#4272]: bogus cache mismatch warnings with desync debugging because some cache was invalidated but never reset
rubidium <rubidium@openttd.org>
parents: 16474
diff changeset
1233 GetVehicleResolver(&ro, v->index);
9537147e9ffb (svn r21338) -Fix [FS#4272]: bogus cache mismatch warnings with desync debugging because some cache was invalidated but never reset
rubidium <rubidium@openttd.org>
parents: 16474
diff changeset
1234
9537147e9ffb (svn r21338) -Fix [FS#4272]: bogus cache mismatch warnings with desync debugging because some cache was invalidated but never reset
rubidium <rubidium@openttd.org>
parents: 16474
diff changeset
1235 /* These variables we have to check; these are the ones with a cache. */
9537147e9ffb (svn r21338) -Fix [FS#4272]: bogus cache mismatch warnings with desync debugging because some cache was invalidated but never reset
rubidium <rubidium@openttd.org>
parents: 16474
diff changeset
1236 static const int cache_entries[][2] = {
9537147e9ffb (svn r21338) -Fix [FS#4272]: bogus cache mismatch warnings with desync debugging because some cache was invalidated but never reset
rubidium <rubidium@openttd.org>
parents: 16474
diff changeset
1237 { 0x40, NCVV_POSITION_CONSIST_LENGTH },
9537147e9ffb (svn r21338) -Fix [FS#4272]: bogus cache mismatch warnings with desync debugging because some cache was invalidated but never reset
rubidium <rubidium@openttd.org>
parents: 16474
diff changeset
1238 { 0x41, NCVV_POSITION_SAME_ID_LENGTH },
9537147e9ffb (svn r21338) -Fix [FS#4272]: bogus cache mismatch warnings with desync debugging because some cache was invalidated but never reset
rubidium <rubidium@openttd.org>
parents: 16474
diff changeset
1239 { 0x42, NCVV_CONSIST_CARGO_INFORMATION },
9537147e9ffb (svn r21338) -Fix [FS#4272]: bogus cache mismatch warnings with desync debugging because some cache was invalidated but never reset
rubidium <rubidium@openttd.org>
parents: 16474
diff changeset
1240 { 0x43, NCVV_COMPANY_INFORMATION },
9537147e9ffb (svn r21338) -Fix [FS#4272]: bogus cache mismatch warnings with desync debugging because some cache was invalidated but never reset
rubidium <rubidium@openttd.org>
parents: 16474
diff changeset
1241 };
9537147e9ffb (svn r21338) -Fix [FS#4272]: bogus cache mismatch warnings with desync debugging because some cache was invalidated but never reset
rubidium <rubidium@openttd.org>
parents: 16474
diff changeset
1242 assert_compile(NCVV_END == lengthof(cache_entries));
9537147e9ffb (svn r21338) -Fix [FS#4272]: bogus cache mismatch warnings with desync debugging because some cache was invalidated but never reset
rubidium <rubidium@openttd.org>
parents: 16474
diff changeset
1243
9537147e9ffb (svn r21338) -Fix [FS#4272]: bogus cache mismatch warnings with desync debugging because some cache was invalidated but never reset
rubidium <rubidium@openttd.org>
parents: 16474
diff changeset
1244 /* Resolve all the variables, so their caches are set. */
9537147e9ffb (svn r21338) -Fix [FS#4272]: bogus cache mismatch warnings with desync debugging because some cache was invalidated but never reset
rubidium <rubidium@openttd.org>
parents: 16474
diff changeset
1245 for (size_t i = 0; i < lengthof(cache_entries); i++) {
9537147e9ffb (svn r21338) -Fix [FS#4272]: bogus cache mismatch warnings with desync debugging because some cache was invalidated but never reset
rubidium <rubidium@openttd.org>
parents: 16474
diff changeset
1246 /* Only resolve when the cache isn't valid. */
9537147e9ffb (svn r21338) -Fix [FS#4272]: bogus cache mismatch warnings with desync debugging because some cache was invalidated but never reset
rubidium <rubidium@openttd.org>
parents: 16474
diff changeset
1247 if (HasBit(v->grf_cache.cache_valid, cache_entries[i][1])) continue;
9537147e9ffb (svn r21338) -Fix [FS#4272]: bogus cache mismatch warnings with desync debugging because some cache was invalidated but never reset
rubidium <rubidium@openttd.org>
parents: 16474
diff changeset
1248 bool stub;
9537147e9ffb (svn r21338) -Fix [FS#4272]: bogus cache mismatch warnings with desync debugging because some cache was invalidated but never reset
rubidium <rubidium@openttd.org>
parents: 16474
diff changeset
1249 ro.GetVariable(&ro, cache_entries[i][0], 0, &stub);
9537147e9ffb (svn r21338) -Fix [FS#4272]: bogus cache mismatch warnings with desync debugging because some cache was invalidated but never reset
rubidium <rubidium@openttd.org>
parents: 16474
diff changeset
1250 }
9537147e9ffb (svn r21338) -Fix [FS#4272]: bogus cache mismatch warnings with desync debugging because some cache was invalidated but never reset
rubidium <rubidium@openttd.org>
parents: 16474
diff changeset
1251
9537147e9ffb (svn r21338) -Fix [FS#4272]: bogus cache mismatch warnings with desync debugging because some cache was invalidated but never reset
rubidium <rubidium@openttd.org>
parents: 16474
diff changeset
1252 /* Make sure really all bits are set. */
9537147e9ffb (svn r21338) -Fix [FS#4272]: bogus cache mismatch warnings with desync debugging because some cache was invalidated but never reset
rubidium <rubidium@openttd.org>
parents: 16474
diff changeset
1253 assert(v->grf_cache.cache_valid == (1 << NCVV_END) - 1);
9537147e9ffb (svn r21338) -Fix [FS#4272]: bogus cache mismatch warnings with desync debugging because some cache was invalidated but never reset
rubidium <rubidium@openttd.org>
parents: 16474
diff changeset
1254 }