Mercurial > hg > openttd
annotate src/newgrf_engine.cpp @ 15823:d9032e02c0c5 draft
(svn r20502) -Fix (r12330): VRF_POWEREDWAGON is part of train flags, not vehicle_flags.
author | frosch <frosch@openttd.org> |
---|---|
date | Sun, 15 Aug 2010 18:25:57 +0000 |
parents | c0e7e98fe4b7 |
children | 7c1f97a04d96 |
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_engine.h" |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
20 #include "newgrf_spritegroup.h" |
8140
fb8a05d579da
(svn r11702) -Codechange: move all date related stuff to date*.
rubidium <rubidium@openttd.org>
parents:
8131
diff
changeset
|
21 #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
|
22 #include "vehicle_func.h" |
8213
87c85bb42d6f
(svn r11776) -Codechange: more header splittings to reduce the dependencies.
rubidium <rubidium@openttd.org>
parents:
8198
diff
changeset
|
23 #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
|
24 #include "aircraft.h" |
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
|
25 #include "core/smallmap_type.hpp" |
12228
240adc64d01a
(svn r16643) -Codechange: replace GetStationByTile() by Station::GetByTile()
smatz <smatz@openttd.org>
parents:
12220
diff
changeset
|
26 #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
|
27 #include "engine_base.h" |
a899d4e5ee1a
(svn r18809) -Codechange/Cleanup: remove unneeded headers from some files, if a header require a header make it include that header
rubidium <rubidium@openttd.org>
parents:
14213
diff
changeset
|
28 #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
|
29 #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
|
30 |
6248
0789677a15a0
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents:
6247
diff
changeset
|
31 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
|
32 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
|
33 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
|
34 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
|
35 const SpriteGroup *group; |
6248
0789677a15a0
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents:
6247
diff
changeset
|
36 }; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
37 |
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
|
38 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
|
39 { |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11875
diff
changeset
|
40 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
|
41 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
|
42 |
6157
e080eca511f9
(svn r8903) -Regression (r8891): CT_PURCHASE does apply to aircraft overrides...
peter1138 <peter1138@openttd.org>
parents:
6148
diff
changeset
|
43 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
|
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 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
|
46 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
|
47 |
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
|
48 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
|
49 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
|
50 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
|
51 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
|
52 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
|
53 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
|
54 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
55 |
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
|
56 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
|
57 { |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11875
diff
changeset
|
58 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
|
59 |
6348
bcf98ba27bbf
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents:
6259
diff
changeset
|
60 /* 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
|
61 * 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
|
62 * 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
|
63 * 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
|
64 |
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
|
65 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
|
66 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
|
67 |
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->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
|
69 |
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
|
70 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
|
71 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
|
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 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
|
75 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
76 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
77 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
78 * 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
|
79 */ |
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
|
80 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
|
81 { |
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
|
82 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
|
83 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
|
84 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
|
85 } |
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
|
86 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
|
87 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
|
88 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
|
89 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
90 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
91 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
92 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
|
93 { |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11875
diff
changeset
|
94 Engine *e = Engine::Get(engine); |
15763
a60a50f29f64
(svn r20437) -Codechange: lets Engines use GRFFilePropsBase as well
rubidium <rubidium@openttd.org>
parents:
15620
diff
changeset
|
95 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
|
96 |
15763
a60a50f29f64
(svn r20437) -Codechange: lets Engines use GRFFilePropsBase as well
rubidium <rubidium@openttd.org>
parents:
15620
diff
changeset
|
97 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
|
98 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
|
99 } |
15763
a60a50f29f64
(svn r20437) -Codechange: lets Engines use GRFFilePropsBase as well
rubidium <rubidium@openttd.org>
parents:
15620
diff
changeset
|
100 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
|
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 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
103 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
104 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
105 * 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
|
106 * 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
|
107 * @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
|
108 * @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
|
109 */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
110 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
|
111 { |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11875
diff
changeset
|
112 Engine *e = Engine::Get(engine); |
15763
a60a50f29f64
(svn r20437) -Codechange: lets Engines use GRFFilePropsBase as well
rubidium <rubidium@openttd.org>
parents:
15620
diff
changeset
|
113 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
|
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 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
116 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
117 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
118 * 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
|
119 * @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
|
120 * @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
|
121 */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
122 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
|
123 { |
15763
a60a50f29f64
(svn r20437) -Codechange: lets Engines use GRFFilePropsBase as well
rubidium <rubidium@openttd.org>
parents:
15620
diff
changeset
|
124 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
|
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 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
127 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
128 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
129 * 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
|
130 * @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
|
131 * @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
|
132 */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
133 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
|
134 { |
11386
5c3e9447c441
(svn r15739) -Codechange: Expose GRF ID of engines in var action property 0x25.
peter1138 <peter1138@openttd.org>
parents:
11368
diff
changeset
|
135 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
|
136 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
|
137 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
138 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
139 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
140 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
|
141 { |
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
|
142 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
|
143 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
|
144 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
|
145 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
|
146 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
|
147 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
|
148 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
|
149 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
|
150 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
|
151 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
|
152 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
|
153 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
154 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
155 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
156 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
157 /* 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
|
158 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
|
159 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
|
160 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
|
161 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
|
162 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
|
163 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
|
164 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
|
165 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
|
166 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
|
167 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
|
168 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
|
169 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
|
170 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
|
171 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
|
172 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
|
173 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
|
174 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
|
175 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
|
176 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
|
177 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
|
178 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
|
179 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
|
180 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
|
181 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
|
182 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
|
183 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
|
184 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
|
185 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
|
186 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
|
187 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
|
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 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
190 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
191 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
192 * 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
|
193 * (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
|
194 */ |
11981
cf1aad9b971c
(svn r16387) -Codechange: use Aircraft instead of Vehicle where appropriate
rubidium <rubidium@openttd.org>
parents:
11924
diff
changeset
|
195 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
|
196 { |
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
|
197 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
|
198 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
|
199 |
14859
304d377a82af
(svn r19455) -Codechange: split all airport information in Station to a seperate class
yexo <yexo@openttd.org>
parents:
14750
diff
changeset
|
200 const AirportFTAClass *afc = st->airport.GetFTA(); |
11982
9add5306a01e
(svn r16388) -Codechange: move u.air to Aircraft
rubidium <rubidium@openttd.org>
parents:
11981
diff
changeset
|
201 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
|
202 |
11982
9add5306a01e
(svn r16388) -Codechange: move u.air to Aircraft
rubidium <rubidium@openttd.org>
parents:
11981
diff
changeset
|
203 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
|
204 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
|
205 /* 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
|
206 * 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
|
207 * 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
|
208 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
209 /* 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
|
210 * 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
|
211 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
|
212 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
213 /* 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
|
214 * 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
|
215 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
|
216 |
6348
bcf98ba27bbf
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents:
6259
diff
changeset
|
217 /* 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
|
218 * 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
|
219 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
|
220 |
6348
bcf98ba27bbf
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents:
6259
diff
changeset
|
221 /* 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
|
222 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
|
223 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
224 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
|
225 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
|
226 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
|
227 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
228 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
|
229 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
|
230 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
|
231 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
232 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
|
233 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
|
234 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
|
235 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
|
236 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
|
237 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
|
238 /* 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
|
239 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
|
240 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
|
241 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
242 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
|
243 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
|
244 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
|
245 /* 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
|
246 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
|
247 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
|
248 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
|
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 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
|
251 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
|
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 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
|
254 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
|
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 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
|
257 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
|
258 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
259 case HELITAKEOFF: // Helicopter is moving to take off position. |
6020 | 260 if (afc->delta_z == 0) { |
261 return amdflag & AMED_HELI_RAISE ? | |
262 AMS_TTDP_HELI_TAKEOFF_AIRPORT : AMS_TTDP_TO_JUNCTION; | |
263 } else { | |
264 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
|
265 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
266 |
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 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
|
268 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
|
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 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
|
271 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
|
272 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
273 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
|
274 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
|
275 /* 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
|
276 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
|
277 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
278 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
|
279 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
|
280 if (amdflag & AMED_HELI_LOWER) { |
6020 | 281 return afc->delta_z == 0 ? |
282 AMS_TTDP_HELI_LAND_AIRPORT : AMS_TTDP_HELI_LAND_HELIPORT; | |
283 } else { | |
284 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
|
285 } |
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 default: |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
288 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
|
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 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
291 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
292 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
293 /* 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
|
294 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
|
295 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
|
296 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
|
297 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
|
298 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
|
299 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
|
300 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
|
301 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
|
302 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
|
303 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
|
304 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
|
305 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
|
306 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
|
307 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
|
308 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
|
309 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
|
310 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
|
311 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
|
312 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
|
313 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
|
314 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
315 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
316 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
317 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
318 * 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
|
319 * (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
|
320 * 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
|
321 */ |
11981
cf1aad9b971c
(svn r16387) -Codechange: use Aircraft instead of Vehicle where appropriate
rubidium <rubidium@openttd.org>
parents:
11924
diff
changeset
|
322 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
|
323 { |
11982
9add5306a01e
(svn r16388) -Codechange: move u.air to Aircraft
rubidium <rubidium@openttd.org>
parents:
11981
diff
changeset
|
324 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
|
325 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
|
326 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
|
327 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
328 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
|
329 case HELIPAD1: |
8836
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8786
diff
changeset
|
330 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
|
331 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
332 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
|
333 case HELIPAD2: |
8836
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8786
diff
changeset
|
334 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
|
335 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
336 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
|
337 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
|
338 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
|
339 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
|
340 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
|
341 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
|
342 case HELIPAD3: |
8836
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8786
diff
changeset
|
343 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
|
344 |
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 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
|
346 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
|
347 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
|
348 case HELITAKEOFF: |
6348
bcf98ba27bbf
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents:
6259
diff
changeset
|
349 /* @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
|
350 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
|
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 FLYING: |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
353 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
|
354 |
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 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
|
356 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
|
357 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
|
358 case HELIENDLANDING: |
6348
bcf98ba27bbf
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents:
6259
diff
changeset
|
359 /* @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
|
360 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
|
361 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
|
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 default: |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
364 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
|
365 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
366 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
367 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
368 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
369 /* 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
|
370 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
|
371 { |
8756
ae0ec91bb55e
(svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx <glx@openttd.org>
parents:
8666
diff
changeset
|
372 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
|
373 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
|
374 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
|
375 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
|
376 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
|
377 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
|
378 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
|
379 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
|
380 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
|
381 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
|
382 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
|
383 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
|
384 break; |
ae0ec91bb55e
(svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx <glx@openttd.org>
parents:
8666
diff
changeset
|
385 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
|
386 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
|
387 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
|
388 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
|
389 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
|
390 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
|
391 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
|
392 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
|
393 } 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
|
394 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
|
395 } |
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
|
396 } |
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
|
397 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
|
398 break; |
e4640748f223
(svn r20281) -Codechange: unify case scope closure + break coding style
rubidium <rubidium@openttd.org>
parents:
15540
diff
changeset
|
399 } |
8756
ae0ec91bb55e
(svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx <glx@openttd.org>
parents:
8666
diff
changeset
|
400 } |
ae0ec91bb55e
(svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx <glx@openttd.org>
parents:
8666
diff
changeset
|
401 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
|
402 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
|
403 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
|
404 return v; |
ae0ec91bb55e
(svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx <glx@openttd.org>
parents:
8666
diff
changeset
|
405 } |
ae0ec91bb55e
(svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx <glx@openttd.org>
parents:
8666
diff
changeset
|
406 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
407 } |
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 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
410 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
|
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 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
|
413 } |
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 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
416 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
|
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 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
|
419 } |
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 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
422 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
|
423 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
424 /* 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
|
425 * 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
|
426 * 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
|
427 */ |
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
|
428 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
|
429 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
430 /* 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
|
431 * 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
|
432 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
|
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 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
|
435 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
436 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
437 |
6516
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6490
diff
changeset
|
438 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
|
439 { |
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6490
diff
changeset
|
440 const Livery *l; |
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6490
diff
changeset
|
441 |
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6490
diff
changeset
|
442 if (v == NULL) { |
11924
fccc9cea27a7
(svn r16327) -Codechange: replace IsValidPoolItemID(index) by PoolItem::IsValidID(index)
smatz <smatz@openttd.org>
parents:
11922
diff
changeset
|
443 if (!Company::IsValidID(_current_company)) return 0; |
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
|
444 l = GetEngineLivery(engine, _current_company, INVALID_ENGINE, NULL); |
6516
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6490
diff
changeset
|
445 } else 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
|
446 l = GetEngineLivery(v->engine_type, v->owner, Train::From(v)->tcache.first_engine, v); |
11167
2194f431a931
(svn r15517) -Fix [FS#2642](r6455): Wagonoverrides and articulated engine parts use the colour scheme of the engine, but not its recolour callback, nor its 2CC flag. Same applies to roadvehicles.
frosch <frosch@openttd.org>
parents:
11166
diff
changeset
|
447 } else if (v->type == 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
|
448 l = GetEngineLivery(v->engine_type, v->owner, RoadVehicle::From(v)->rcache.first_engine, v); |
6516
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6490
diff
changeset
|
449 } else { |
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6490
diff
changeset
|
450 l = GetEngineLivery(v->engine_type, v->owner, INVALID_ENGINE, v); |
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6490
diff
changeset
|
451 } |
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6490
diff
changeset
|
452 |
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6490
diff
changeset
|
453 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
|
454 } |
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6490
diff
changeset
|
455 |
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
|
456 /** |
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 * 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
|
458 * @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
|
459 * @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
|
460 * 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
|
461 * @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
|
462 */ |
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 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
|
464 { |
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 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
|
466 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
|
467 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
|
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 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
|
470 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
|
471 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
|
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 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
|
475 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
|
476 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
|
477 } |
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
|
478 |
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 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
|
480 } |
6516
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6490
diff
changeset
|
481 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
482 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
|
483 { |
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
|
484 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
|
485 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
486 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
|
487 /* 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
|
488 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
|
489 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
|
490 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
|
491 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
|
492 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
|
493 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
|
494 if (cargo_type != CT_INVALID) { |
12415
6a77d1df56e2
(svn r16849) -Codechange: replace GetCargo() by CargoSpec::Get()
smatz <smatz@openttd.org>
parents:
12302
diff
changeset
|
495 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
|
496 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
|
497 } else { |
c993bfe070b7
(svn r15542) -Feature(ette): Support vehicle vars 0x47 and 0xF2 in purchase list.
frosch <frosch@openttd.org>
parents:
11188
diff
changeset
|
498 return 0x000000FF; |
c993bfe070b7
(svn r15542) -Feature(ette): Support vehicle vars 0x47 and 0xF2 in purchase list.
frosch <frosch@openttd.org>
parents:
11188
diff
changeset
|
499 } |
c993bfe070b7
(svn r15542) -Feature(ette): Support vehicle vars 0x47 and 0xF2 in purchase list.
frosch <frosch@openttd.org>
parents:
11188
diff
changeset
|
500 } |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11875
diff
changeset
|
501 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
|
502 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
|
503 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
|
504 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
|
505 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
|
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 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
508 *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
|
509 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
|
510 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
511 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
512 /* 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
|
513 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
|
514 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
|
515 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
|
516 |
6348
bcf98ba27bbf
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents:
6259
diff
changeset
|
517 case 0x40: // Get length of consist |
11988
935e4f91c83c
(svn r16394) -Codechange: move (NewGRF) cache variables into a separate struct so (some vehicle related) NewGRF cache 'desyncs' can be tested easier.
rubidium <rubidium@openttd.org>
parents:
11987
diff
changeset
|
518 if (!HasBit(v->vcache.cache_valid, 0)) { |
935e4f91c83c
(svn r16394) -Codechange: move (NewGRF) cache variables into a separate struct so (some vehicle related) NewGRF cache 'desyncs' can be tested easier.
rubidium <rubidium@openttd.org>
parents:
11987
diff
changeset
|
519 v->vcache.cached_var40 = PositionHelper(v, false); |
935e4f91c83c
(svn r16394) -Codechange: move (NewGRF) cache variables into a separate struct so (some vehicle related) NewGRF cache 'desyncs' can be tested easier.
rubidium <rubidium@openttd.org>
parents:
11987
diff
changeset
|
520 SetBit(v->vcache.cache_valid, 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
|
521 } |
11988
935e4f91c83c
(svn r16394) -Codechange: move (NewGRF) cache variables into a separate struct so (some vehicle related) NewGRF cache 'desyncs' can be tested easier.
rubidium <rubidium@openttd.org>
parents:
11987
diff
changeset
|
522 return v->vcache.cached_var40; |
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 |
6348
bcf98ba27bbf
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents:
6259
diff
changeset
|
524 case 0x41: // Get length of same consecutive wagons |
11988
935e4f91c83c
(svn r16394) -Codechange: move (NewGRF) cache variables into a separate struct so (some vehicle related) NewGRF cache 'desyncs' can be tested easier.
rubidium <rubidium@openttd.org>
parents:
11987
diff
changeset
|
525 if (!HasBit(v->vcache.cache_valid, 1)) { |
935e4f91c83c
(svn r16394) -Codechange: move (NewGRF) cache variables into a separate struct so (some vehicle related) NewGRF cache 'desyncs' can be tested easier.
rubidium <rubidium@openttd.org>
parents:
11987
diff
changeset
|
526 v->vcache.cached_var41 = PositionHelper(v, true); |
935e4f91c83c
(svn r16394) -Codechange: move (NewGRF) cache variables into a separate struct so (some vehicle related) NewGRF cache 'desyncs' can be tested easier.
rubidium <rubidium@openttd.org>
parents:
11987
diff
changeset
|
527 SetBit(v->vcache.cache_valid, 1); |
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 } |
11988
935e4f91c83c
(svn r16394) -Codechange: move (NewGRF) cache variables into a separate struct so (some vehicle related) NewGRF cache 'desyncs' can be tested easier.
rubidium <rubidium@openttd.org>
parents:
11987
diff
changeset
|
529 return v->vcache.cached_var41; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
530 |
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
|
531 case 0x42: // Consist cargo information |
11988
935e4f91c83c
(svn r16394) -Codechange: move (NewGRF) cache variables into a separate struct so (some vehicle related) NewGRF cache 'desyncs' can be tested easier.
rubidium <rubidium@openttd.org>
parents:
11987
diff
changeset
|
532 if (!HasBit(v->vcache.cache_valid, 2)) { |
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
|
533 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
|
534 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
|
535 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
|
536 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
|
537 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
|
538 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
|
539 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
|
540 |
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
|
541 /* 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
|
542 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
|
543 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
|
544 |
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 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
|
546 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
|
547 |
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
|
548 /* 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
|
549 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
|
550 |
12415
6a77d1df56e2
(svn r16849) -Codechange: replace GetCargo() by CargoSpec::Get()
smatz <smatz@openttd.org>
parents:
12302
diff
changeset
|
551 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
|
552 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
|
553 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
554 |
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 /* 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
|
556 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
|
557 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
|
558 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
|
559 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
|
560 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
|
561 } |
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 } |
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 /* 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
|
565 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
|
566 /* 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
|
567 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
|
568 |
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 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
|
570 } |
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
|
571 |
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 /* 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
|
573 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
|
574 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
|
575 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
|
576 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
|
577 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
|
578 } |
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
|
579 } |
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
|
580 |
12415
6a77d1df56e2
(svn r16849) -Codechange: replace GetCargo() by CargoSpec::Get()
smatz <smatz@openttd.org>
parents:
12302
diff
changeset
|
581 uint8 common_bitnum = (common_cargo_type == CT_INVALID ? 0xFF : CargoSpec::Get(common_cargo_type)->bitnum); |
11988
935e4f91c83c
(svn r16394) -Codechange: move (NewGRF) cache variables into a separate struct so (some vehicle related) NewGRF cache 'desyncs' can be tested easier.
rubidium <rubidium@openttd.org>
parents:
11987
diff
changeset
|
582 v->vcache.cached_var42 = cargo_classes | (common_bitnum << 8) | (common_subtype << 16) | (user_def_data << 24); |
935e4f91c83c
(svn r16394) -Codechange: move (NewGRF) cache variables into a separate struct so (some vehicle related) NewGRF cache 'desyncs' can be tested easier.
rubidium <rubidium@openttd.org>
parents:
11987
diff
changeset
|
583 SetBit(v->vcache.cache_valid, 2); |
6822
08fc353e6a6b
(svn r10061) -Codechange: [NewGRF] Add common cargo subtype support to vehicle var 42
peter1138 <peter1138@openttd.org>
parents:
6621
diff
changeset
|
584 } |
11988
935e4f91c83c
(svn r16394) -Codechange: move (NewGRF) cache variables into a separate struct so (some vehicle related) NewGRF cache 'desyncs' can be tested easier.
rubidium <rubidium@openttd.org>
parents:
11987
diff
changeset
|
585 return v->vcache.cached_var42; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
586 |
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
|
587 case 0x43: // Company information |
11988
935e4f91c83c
(svn r16394) -Codechange: move (NewGRF) cache variables into a separate struct so (some vehicle related) NewGRF cache 'desyncs' can be tested easier.
rubidium <rubidium@openttd.org>
parents:
11987
diff
changeset
|
588 if (!HasBit(v->vcache.cache_valid, 3)) { |
12220
8c5b158f0d40
(svn r16634) -Codechange: use Company::IsHumanID() instead of IsHumanCompany()
smatz <smatz@openttd.org>
parents:
12201
diff
changeset
|
589 v->vcache.cached_var43 = v->owner | (Company::IsHumanID(v->owner) ? 0 : 0x10000) | (LiveryHelper(v->engine_type, v) << 24); |
11988
935e4f91c83c
(svn r16394) -Codechange: move (NewGRF) cache variables into a separate struct so (some vehicle related) NewGRF cache 'desyncs' can be tested easier.
rubidium <rubidium@openttd.org>
parents:
11987
diff
changeset
|
590 SetBit(v->vcache.cache_valid, 3); |
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
|
591 } |
11988
935e4f91c83c
(svn r16394) -Codechange: move (NewGRF) cache variables into a separate struct so (some vehicle related) NewGRF cache 'desyncs' can be tested easier.
rubidium <rubidium@openttd.org>
parents:
11987
diff
changeset
|
592 return v->vcache.cached_var43; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
593 |
6348
bcf98ba27bbf
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents:
6259
diff
changeset
|
594 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
|
595 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
|
596 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
597 { |
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
|
598 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
|
599 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
|
600 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
|
601 |
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
|
602 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
|
603 |
14715
aa004cf5c288
(svn r19299) -Codechange: store the most compatible ttd airport type in AirportSpec
yexo <yexo@openttd.org>
parents:
14378
diff
changeset
|
604 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
|
605 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
|
606 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
607 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
608 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
|
609 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
610 |
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
|
611 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
|
612 /* 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
|
613 * 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
|
614 * 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
|
615 * 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
|
616 */ |
10643
9c1b0524a8a1
(svn r14945) -Feature(ette): Support var 0x45 (curvature info) also for road vehicles.
frosch <frosch@openttd.org>
parents:
10544
diff
changeset
|
617 if (v->type != VEH_TRAIN && v->type != VEH_ROAD) 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
|
618 |
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
|
619 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
|
620 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
|
621 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
|
622 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
|
623 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
|
624 |
3c89f72535f3
(svn r9803) -Feature(tte): support for "curvature info", Action 2 for train, variable 45 (mart3p).
rubidium <rubidium@openttd.org>
parents:
6517
diff
changeset
|
625 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
|
626 ((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
|
627 ( 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
|
628 } |
3c89f72535f3
(svn r9803) -Feature(tte): support for "curvature info", Action 2 for train, variable 45 (mart3p).
rubidium <rubidium@openttd.org>
parents:
6517
diff
changeset
|
629 |
6348
bcf98ba27bbf
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents:
6259
diff
changeset
|
630 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
|
631 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
|
632 |
6348
bcf98ba27bbf
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents:
6259
diff
changeset
|
633 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
|
634 /* 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
|
635 * 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
|
636 * 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
|
637 * 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
|
638 * 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
|
639 */ |
12415
6a77d1df56e2
(svn r16849) -Codechange: replace GetCargo() by CargoSpec::Get()
smatz <smatz@openttd.org>
parents:
12302
diff
changeset
|
640 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
|
641 |
6147
a7aecaae3414
(svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138 <peter1138@openttd.org>
parents:
6126
diff
changeset
|
642 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
|
643 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
644 |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11875
diff
changeset
|
645 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
|
646 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
|
647 |
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
|
648 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
|
649 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
|
650 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
|
651 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
|
652 } |
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
|
653 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
654 /* 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
|
655 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
|
656 //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
|
657 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
|
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 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
660 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
|
661 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
|
662 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
|
663 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
664 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
|
665 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
666 |
6176
863c86137fc1
(svn r8946) -Feature: [NewGRF] Add support for vehicle variables 0xFE and 0xFF bit 10,
maedhros <maedhros@openttd.org>
parents:
6173
diff
changeset
|
667 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
|
668 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
|
669 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
|
670 |
8665
5e82cdbe1cc1
(svn r12330) -Feature: [NewGRF] vehicle variable FE bit 5 and 6
glx <glx@openttd.org>
parents:
8654
diff
changeset
|
671 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
|
672 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
|
673 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
|
674 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
|
675 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
|
676 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
|
677 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
|
678 |
15521
b56282f31197
(svn r20175) -Change: [NewGRF] Adapt vehicle var FE bit 6 to new railtypes.
frosch <frosch@openttd.org>
parents:
15512
diff
changeset
|
679 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
|
680 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
|
681 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
|
682 } |
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
|
683 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
|
684 |
863c86137fc1
(svn r8946) -Feature: [NewGRF] Add support for vehicle variables 0xFE and 0xFF bit 10,
maedhros <maedhros@openttd.org>
parents:
6173
diff
changeset
|
685 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
|
686 } |
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 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
688 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
689 /* 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
|
690 switch (variable - 0x80) { |
12201
b28426ff9e8c
(svn r16615) -Fix (r16613): 0x10 != 2
yexo <yexo@openttd.org>
parents:
12199
diff
changeset
|
691 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
|
692 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
|
693 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
|
694 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
|
695 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
|
696 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
|
697 case 0x0C: return v->GetNumOrders(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
698 case 0x0D: return v->cur_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
|
699 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
|
700 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
|
701 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
|
702 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
|
703 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
|
704 } 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
|
705 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
|
706 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
|
707 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
|
708 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
|
709 } |
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
|
710 } |
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
|
711 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
|
712 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
713 case 0x12: return max(v->date_of_last_service - DAYS_TILL_ORIGINAL_BASE_YEAR, 0); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
714 case 0x13: return GB(max(v->date_of_last_service - DAYS_TILL_ORIGINAL_BASE_YEAR, 0), 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
|
715 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
|
716 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
|
717 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
|
718 case 0x17: return v->tick_counter; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
719 case 0x18: return v->max_speed; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
720 case 0x19: return GB(v->max_speed, 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
|
721 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
|
722 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
|
723 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
|
724 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
|
725 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
|
726 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
|
727 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
|
728 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
|
729 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
|
730 case 0x33: return 0; // non-existent high byte of vehstatus |
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 0x34: return v->cur_speed; |
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 0x35: return GB(v->cur_speed, 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
|
733 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
|
734 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
|
735 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
|
736 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
|
737 case 0x3B: return GB(v->cargo_cap, 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
|
738 case 0x3C: return v->cargo.Count(); |
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
|
739 case 0x3D: return GB(v->cargo.Count(), 8, 8); |
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
|
740 case 0x3E: return v->cargo.Source(); |
f0f87c5a431e
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium <rubidium@openttd.org>
parents:
6990
diff
changeset
|
741 case 0x3F: return v->cargo.DaysInTransit(); |
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
|
742 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
|
743 case 0x41: return GB(ClampToU16(v->age), 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
|
744 case 0x42: return v->max_age; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
745 case 0x43: return GB(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
|
746 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
|
747 case 0x45: return v->unitnumber; |
15763
a60a50f29f64
(svn r20437) -Codechange: lets Engines use GRFFilePropsBase as well
rubidium <rubidium@openttd.org>
parents:
15620
diff
changeset
|
748 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
|
749 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
|
750 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
|
751 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
|
752 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
|
753 |
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 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
|
755 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
|
756 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
|
757 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
|
758 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
|
759 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
|
760 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
|
761 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
|
762 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
|
763 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
|
764 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
|
765 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
|
766 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
|
767 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
|
768 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
|
769 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
|
770 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
|
771 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
|
772 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
|
773 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
|
774 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
|
775 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
|
776 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
|
777 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
|
778 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
|
779 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
780 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
781 /* 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
|
782 switch (v->type) { |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11984
diff
changeset
|
783 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
|
784 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
|
785 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
|
786 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
|
787 case 0x66: return t->railtype; |
11987
81554d4e6d76
(svn r16393) -Codechange: move VehicleRail to Train.
rubidium <rubidium@openttd.org>
parents:
11986
diff
changeset
|
788 case 0x73: return t->tcache.cached_veh_length; |
14750
bf6990330311
(svn r19338) -Codechange: Move the acceleration cache to GroundVehicle.
terkhen <terkhen@openttd.org>
parents:
14715
diff
changeset
|
789 case 0x74: return t->acc_cache.cached_power; |
bf6990330311
(svn r19338) -Codechange: Move the acceleration cache to GroundVehicle.
terkhen <terkhen@openttd.org>
parents:
14715
diff
changeset
|
790 case 0x75: return GB(t->acc_cache.cached_power, 8, 24); |
bf6990330311
(svn r19338) -Codechange: Move the acceleration cache to GroundVehicle.
terkhen <terkhen@openttd.org>
parents:
14715
diff
changeset
|
791 case 0x76: return GB(t->acc_cache.cached_power, 16, 16); |
bf6990330311
(svn r19338) -Codechange: Move the acceleration cache to GroundVehicle.
terkhen <terkhen@openttd.org>
parents:
14715
diff
changeset
|
792 case 0x77: return GB(t->acc_cache.cached_power, 24, 8); |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11984
diff
changeset
|
793 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
|
794 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
|
795 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
|
796 } |
15618
e4640748f223
(svn r20281) -Codechange: unify case scope closure + break coding style
rubidium <rubidium@openttd.org>
parents:
15540
diff
changeset
|
797 break; |
e4640748f223
(svn r20281) -Codechange: unify case scope closure + break coding style
rubidium <rubidium@openttd.org>
parents:
15540
diff
changeset
|
798 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
799 |
11984
b6d3e583be86
(svn r16390) -Codechange: move u.road to RoadVehicle.
rubidium <rubidium@openttd.org>
parents:
11982
diff
changeset
|
800 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
|
801 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
|
802 switch (variable - 0x80) { |
11984
b6d3e583be86
(svn r16390) -Codechange: move u.road to RoadVehicle.
rubidium <rubidium@openttd.org>
parents:
11982
diff
changeset
|
803 case 0x62: return rv->state; |
b6d3e583be86
(svn r16390) -Codechange: move u.road to RoadVehicle.
rubidium <rubidium@openttd.org>
parents:
11982
diff
changeset
|
804 case 0x64: return rv->blocked_ctr; |
b6d3e583be86
(svn r16390) -Codechange: move u.road to RoadVehicle.
rubidium <rubidium@openttd.org>
parents:
11982
diff
changeset
|
805 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
|
806 case 0x66: return rv->overtaking; |
b6d3e583be86
(svn r16390) -Codechange: move u.road to RoadVehicle.
rubidium <rubidium@openttd.org>
parents:
11982
diff
changeset
|
807 case 0x67: return rv->overtaking_ctr; |
b6d3e583be86
(svn r16390) -Codechange: move u.road to RoadVehicle.
rubidium <rubidium@openttd.org>
parents:
11982
diff
changeset
|
808 case 0x68: return rv->crashed_ctr; |
b6d3e583be86
(svn r16390) -Codechange: move u.road to RoadVehicle.
rubidium <rubidium@openttd.org>
parents:
11982
diff
changeset
|
809 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
|
810 } |
15618
e4640748f223
(svn r20281) -Codechange: unify case scope closure + break coding style
rubidium <rubidium@openttd.org>
parents:
15540
diff
changeset
|
811 break; |
e4640748f223
(svn r20281) -Codechange: unify case scope closure + break coding style
rubidium <rubidium@openttd.org>
parents:
15540
diff
changeset
|
812 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
813 |
11981
cf1aad9b971c
(svn r16387) -Codechange: use Aircraft instead of Vehicle where appropriate
rubidium <rubidium@openttd.org>
parents:
11924
diff
changeset
|
814 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
|
815 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
|
816 switch (variable - 0x80) { |
11981
cf1aad9b971c
(svn r16387) -Codechange: use Aircraft instead of Vehicle where appropriate
rubidium <rubidium@openttd.org>
parents:
11924
diff
changeset
|
817 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
|
818 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
|
819 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
|
820 } |
15618
e4640748f223
(svn r20281) -Codechange: unify case scope closure + break coding style
rubidium <rubidium@openttd.org>
parents:
15540
diff
changeset
|
821 break; |
e4640748f223
(svn r20281) -Codechange: unify case scope closure + break coding style
rubidium <rubidium@openttd.org>
parents:
15540
diff
changeset
|
822 } |
6621
c751437b3bac
(svn r9841) -Codechange: add a little more type strictness to the vehicle types.
rubidium <rubidium@openttd.org>
parents:
6604
diff
changeset
|
823 |
c751437b3bac
(svn r9841) -Codechange: add a little more type strictness to the vehicle types.
rubidium <rubidium@openttd.org>
parents:
6604
diff
changeset
|
824 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
|
825 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
826 |
11875
86fca539ec7a
(svn r16269) -Codechange: use gcc's ability to check parameters sent to printf-like functions
smatz <smatz@openttd.org>
parents:
11386
diff
changeset
|
827 DEBUG(grf, 1, "Unhandled vehicle property 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
|
828 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
829 *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
|
830 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
|
831 } |
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 |
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
|
834 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
|
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 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
|
837 |
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
|
838 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
|
839 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
|
840 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
|
841 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
|
842 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
843 |
8836
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8786
diff
changeset
|
844 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
|
845 |
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 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
|
847 |
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
|
848 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
|
849 |
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
|
850 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
|
851 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
|
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 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
|
854 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
855 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
856 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
857 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
|
858 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
859 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
|
860 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
|
861 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
|
862 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
|
863 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
|
864 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
865 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
|
866 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
|
867 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
868 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
|
869 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
|
870 |
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
|
871 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
|
872 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
|
873 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
|
874 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
|
875 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
|
876 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
|
877 res->count = 0; |
9750
0654bf387d06
(svn r13885) -Fix [FS#2168]: Var 0x7F is not feature-specific.
frosch <frosch@openttd.org>
parents:
9672
diff
changeset
|
878 |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11875
diff
changeset
|
879 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
|
880 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
|
881 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
882 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
883 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15618
diff
changeset
|
884 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15618
diff
changeset
|
885 * 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
|
886 * 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
|
887 * 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
|
888 * @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
|
889 * @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
|
890 * @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
|
891 * @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
|
892 */ |
7863
ea337dd0527c
(svn r11413) -Fix [FS#1405]: don't use cached override spriteset for callbacks
glx <glx@openttd.org>
parents:
7861
diff
changeset
|
893 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
|
894 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
895 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
|
896 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
|
897 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
898 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
|
899 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
|
900 } 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
|
901 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
|
902 |
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
|
903 if (v->type == VEH_TRAIN) { |
7863
ea337dd0527c
(svn r11413) -Fix [FS#1405]: don't use cached override spriteset for callbacks
glx <glx@openttd.org>
parents:
7861
diff
changeset
|
904 /* We always use cached value, except for callbacks because the override spriteset |
ea337dd0527c
(svn r11413) -Fix [FS#1405]: don't use cached override spriteset for callbacks
glx <glx@openttd.org>
parents:
7861
diff
changeset
|
905 * 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
|
906 * as v->cargo_type is temporary changed to the new type */ |
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
|
907 group = use_cache ? Train::From(v)->tcache.cached_override : GetWagonOverrideSpriteSet(v->engine_type, v->cargo_type, Train::From(v)->tcache.first_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
|
908 if (group != NULL) return group; |
11166
504cd363813f
(svn r15516) -Fix (r10097): Livery overrides for articulated parts of roadvehicles were not applied.
frosch <frosch@openttd.org>
parents:
11059
diff
changeset
|
909 } else if (v->type == 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
|
910 group = GetWagonOverrideSpriteSet(v->engine_type, v->cargo_type, RoadVehicle::From(v)->rcache.first_engine); |
11166
504cd363813f
(svn r15516) -Fix (r10097): Livery overrides for articulated parts of roadvehicles were not applied.
frosch <frosch@openttd.org>
parents:
11059
diff
changeset
|
911 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
|
912 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
913 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
914 |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11875
diff
changeset
|
915 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
|
916 |
15763
a60a50f29f64
(svn r20437) -Codechange: lets Engines use GRFFilePropsBase as well
rubidium <rubidium@openttd.org>
parents:
15620
diff
changeset
|
917 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
|
918 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
|
919 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
|
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 /* 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
|
922 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
|
923 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
924 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
925 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
926 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
|
927 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
928 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
|
929 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
|
930 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
931 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
|
932 |
11996
b43cf6c7ea61
(svn r16402) -Codechange: make Resolve a function of SpriteGroup
rubidium <rubidium@openttd.org>
parents:
11990
diff
changeset
|
933 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
|
934 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
|
935 |
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
|
936 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
|
937 } |
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 |
11981
cf1aad9b971c
(svn r16387) -Codechange: use Aircraft instead of Vehicle where appropriate
rubidium <rubidium@openttd.org>
parents:
11924
diff
changeset
|
940 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
|
941 { |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11875
diff
changeset
|
942 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
|
943 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
944 /* 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
|
945 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
|
946 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
|
947 |
9436
b3969ef775ba
(svn r13351) -Codechange: disable warnings about unused variable for builds without asserts
smatz <smatz@openttd.org>
parents:
9413
diff
changeset
|
948 ResolverObject object; |
b3969ef775ba
(svn r13351) -Codechange: disable warnings about unused variable for builds without asserts
smatz <smatz@openttd.org>
parents:
9413
diff
changeset
|
949 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
950 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
|
951 |
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
|
952 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
|
953 |
9436
b3969ef775ba
(svn r13351) -Codechange: disable warnings about unused variable for builds without asserts
smatz <smatz@openttd.org>
parents:
9413
diff
changeset
|
954 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
|
955 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
|
956 |
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
|
957 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
|
958 |
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
|
959 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
|
960 |
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
|
961 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
|
962 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
963 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
964 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
965 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
966 * 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
|
967 * @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
|
968 * @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
|
969 */ |
10647
592ae9307430
(svn r14949) -Cleanup: pointer coding style
rubidium <rubidium@openttd.org>
parents:
10643
diff
changeset
|
970 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
|
971 { |
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
|
972 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
|
973 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
|
974 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
975 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
976 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
977 * 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
|
978 * @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
|
979 * @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
|
980 * @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
|
981 * @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
|
982 * @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
|
983 * @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
|
984 */ |
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
|
985 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
|
986 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
987 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
|
988 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
|
989 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
990 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
|
991 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
992 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
|
993 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
|
994 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
|
995 |
11996
b43cf6c7ea61
(svn r16402) -Codechange: make Resolve a function of SpriteGroup
rubidium <rubidium@openttd.org>
parents:
11990
diff
changeset
|
996 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
|
997 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
|
998 |
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
|
999 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
|
1000 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1001 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1002 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1003 * 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
|
1004 * @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
|
1005 * @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
|
1006 * @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
|
1007 * @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
|
1008 * @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
|
1009 * @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
|
1010 * @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
|
1011 */ |
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
|
1012 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
|
1013 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1014 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
|
1015 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
|
1016 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1017 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
|
1018 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1019 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
|
1020 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
|
1021 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
|
1022 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1023 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
|
1024 |
11996
b43cf6c7ea61
(svn r16402) -Codechange: make Resolve a function of SpriteGroup
rubidium <rubidium@openttd.org>
parents:
11990
diff
changeset
|
1025 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
|
1026 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
|
1027 |
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
|
1028 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
|
1029 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1030 |
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
|
1031 |
6517
bfa6449a2b3a
(svn r9703) -Codechange: support callback 36 in vehicle purchase lists
peter1138 <peter1138@openttd.org>
parents:
6516
diff
changeset
|
1032 /* 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
|
1033 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
|
1034 { |
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
|
1035 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
|
1036 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
|
1037 |
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
|
1038 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
|
1039 } |
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
|
1040 |
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
|
1041 |
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
|
1042 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
|
1043 { |
bfa6449a2b3a
(svn r9703) -Codechange: support callback 36 in vehicle purchase lists
peter1138 <peter1138@openttd.org>
parents:
6516
diff
changeset
|
1044 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
|
1045 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
|
1046 |
bfa6449a2b3a
(svn r9703) -Codechange: support callback 36 in vehicle purchase lists
peter1138 <peter1138@openttd.org>
parents:
6516
diff
changeset
|
1047 return orig_value; |
bfa6449a2b3a
(svn r9703) -Codechange: support callback 36 in vehicle purchase lists
peter1138 <peter1138@openttd.org>
parents:
6516
diff
changeset
|
1048 } |
bfa6449a2b3a
(svn r9703) -Codechange: support callback 36 in vehicle purchase lists
peter1138 <peter1138@openttd.org>
parents:
6516
diff
changeset
|
1049 |
bfa6449a2b3a
(svn r9703) -Codechange: support callback 36 in vehicle purchase lists
peter1138 <peter1138@openttd.org>
parents:
6516
diff
changeset
|
1050 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1051 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
|
1052 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1053 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
|
1054 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
|
1055 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
|
1056 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1057 /* 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
|
1058 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
|
1059 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1060 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
|
1061 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
|
1062 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
|
1063 |
11996
b43cf6c7ea61
(svn r16402) -Codechange: make Resolve a function of SpriteGroup
rubidium <rubidium@openttd.org>
parents:
11990
diff
changeset
|
1064 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
|
1065 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
|
1066 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1067 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
|
1068 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
|
1069 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
|
1070 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1071 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
|
1072 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
|
1073 /* 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
|
1074 * 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
|
1075 * 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
|
1076 * 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
|
1077 * 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
|
1078 * 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
|
1079 * 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
|
1080 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
|
1081 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
|
1082 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1083 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1084 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
|
1085 /* 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
|
1086 * 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
|
1087 * 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
|
1088 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
|
1089 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1090 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1091 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
|
1092 /* 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
|
1093 * 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
|
1094 * 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
|
1095 * 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
|
1096 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
|
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_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
|
1100 /* 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
|
1101 * 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
|
1102 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
|
1103 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
|
1104 break; |
7803
1ad76d7d65b8
(svn r11353) -Codechange: add support for newgrf callback 32
glx <glx@openttd.org>
parents:
7550
diff
changeset
|
1105 |
1ad76d7d65b8
(svn r11353) -Codechange: add support for newgrf callback 32
glx <glx@openttd.org>
parents:
7550
diff
changeset
|
1106 case VEHICLE_TRIGGER_CALLBACK_32: |
1ad76d7d65b8
(svn r11353) -Codechange: add support for newgrf callback 32
glx <glx@openttd.org>
parents:
7550
diff
changeset
|
1107 /* Do not do any recursion */ |
1ad76d7d65b8
(svn r11353) -Codechange: add support for newgrf callback 32
glx <glx@openttd.org>
parents:
7550
diff
changeset
|
1108 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
|
1109 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1110 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1111 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1112 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
|
1113 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1114 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
|
1115 /* 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
|
1116 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
|
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 |
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
|
1119 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
|
1120 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
|
1121 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
|
1122 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1123 |
6348
bcf98ba27bbf
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents:
6259
diff
changeset
|
1124 /* 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
|
1125 * 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
|
1126 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1127 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1128 * 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
|
1129 * 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
|
1130 * @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
|
1131 * @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
|
1132 */ |
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
|
1133 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
|
1134 { |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11875
diff
changeset
|
1135 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
|
1136 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
|
1137 |
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
|
1138 /* 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
|
1139 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
|
1140 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1141 |
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
|
1142 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
|
1143 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
|
1144 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
|
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 |
10416
25ae1dbfcf45
(svn r14669) -Codechange: use SmallVector instead of std::list at one place
smatz <smatz@openttd.org>
parents:
10208
diff
changeset
|
1147 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
|
1148 |
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
|
1149 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
|
1150 { |
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
|
1151 /* 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
|
1152 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
|
1153 loc->engine = engine; |
25ae1dbfcf45
(svn r14669) -Codechange: use SmallVector instead of std::list at one place
smatz <smatz@openttd.org>
parents:
10208
diff
changeset
|
1154 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
|
1155 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
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 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
|
1158 { |
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 /* 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
|
1160 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
|
1161 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
|
1162 |
10416
25ae1dbfcf45
(svn r14669) -Codechange: use SmallVector instead of std::list at one place
smatz <smatz@openttd.org>
parents:
10208
diff
changeset
|
1163 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
|
1164 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
|
1165 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
|
1166 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
|
1167 |
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
|
1168 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
|
1169 |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11875
diff
changeset
|
1170 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
|
1171 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
|
1172 |
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 /* 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
|
1174 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
|
1175 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
|
1176 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
|
1177 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
|
1178 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
|
1179 } |
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
|
1180 } |
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 |
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
|
1182 /* 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
|
1183 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
|
1184 |
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
|
1185 /* 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
|
1186 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
|
1187 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
|
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 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
|
1190 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
|
1191 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
|
1192 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
|
1193 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
|
1194 } |
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 |
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 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
|
1197 } |
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
|
1198 |
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
|
1199 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
|
1200 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1201 |
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
|
1202 /* 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
|
1203 _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
|
1204 } |
15081
961ab6166e79
(svn r19707) -Add: helper functions to instantiate/fill ResolverObjects
rubidium <rubidium@openttd.org>
parents:
14859
diff
changeset
|
1205 |
961ab6166e79
(svn r19707) -Add: helper functions to instantiate/fill ResolverObjects
rubidium <rubidium@openttd.org>
parents:
14859
diff
changeset
|
1206 /** |
961ab6166e79
(svn r19707) -Add: helper functions to instantiate/fill ResolverObjects
rubidium <rubidium@openttd.org>
parents:
14859
diff
changeset
|
1207 * 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
|
1208 * @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
|
1209 * @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
|
1210 */ |
961ab6166e79
(svn r19707) -Add: helper functions to instantiate/fill ResolverObjects
rubidium <rubidium@openttd.org>
parents:
14859
diff
changeset
|
1211 void GetVehicleResolver(ResolverObject *ro, uint index) |
961ab6166e79
(svn r19707) -Add: helper functions to instantiate/fill ResolverObjects
rubidium <rubidium@openttd.org>
parents:
14859
diff
changeset
|
1212 { |
961ab6166e79
(svn r19707) -Add: helper functions to instantiate/fill ResolverObjects
rubidium <rubidium@openttd.org>
parents:
14859
diff
changeset
|
1213 Vehicle *v = Vehicle::Get(index); |
961ab6166e79
(svn r19707) -Add: helper functions to instantiate/fill ResolverObjects
rubidium <rubidium@openttd.org>
parents:
14859
diff
changeset
|
1214 NewVehicleResolver(ro, v->engine_type, v); |
961ab6166e79
(svn r19707) -Add: helper functions to instantiate/fill ResolverObjects
rubidium <rubidium@openttd.org>
parents:
14859
diff
changeset
|
1215 } |