Mercurial > hg > openttd
annotate src/newgrf_engine.cpp @ 11981:cf1aad9b971c draft
(svn r16387) -Codechange: use Aircraft instead of Vehicle where appropriate
author | rubidium <rubidium@openttd.org> |
---|---|
date | Fri, 22 May 2009 20:03:26 +0000 |
parents | fccc9cea27a7 |
children | 9add5306a01e |
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 |
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
|
3 /** @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
|
4 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
5 #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
|
6 #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
|
7 #include "train.h" |
10208
39cf8eebfda5
(svn r14422) -Codechange: also reflect the changes of r14421 in the filenames.
rubidium <rubidium@openttd.org>
parents:
10207
diff
changeset
|
8 #include "company_func.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
|
9 #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
|
10 #include "newgrf_spritegroup.h" |
8140
fb8a05d579da
(svn r11702) -Codechange: move all date related stuff to date*.
rubidium <rubidium@openttd.org>
parents:
8131
diff
changeset
|
11 #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
|
12 #include "vehicle_func.h" |
8213
87c85bb42d6f
(svn r11776) -Codechange: more header splittings to reduce the dependencies.
rubidium <rubidium@openttd.org>
parents:
8198
diff
changeset
|
13 #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
|
14 #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
|
15 #include "core/smallmap_type.hpp" |
10960
a4e5b5d2837c
(svn r15299) -Cleanup: remove many redundant includes
smatz <smatz@openttd.org>
parents:
10647
diff
changeset
|
16 #include "settings_type.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
|
17 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
18 int _traininfo_vehicle_pitch = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
19 int _traininfo_vehicle_width = 29; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
20 |
6248
0789677a15a0
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents:
6247
diff
changeset
|
21 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
|
22 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
|
23 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
|
24 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
|
25 const SpriteGroup *group; |
6248
0789677a15a0
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents:
6247
diff
changeset
|
26 }; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
27 |
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
|
28 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
|
29 { |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11875
diff
changeset
|
30 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
|
31 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
|
32 |
6157
e080eca511f9
(svn r8903) -Regression (r8891): CT_PURCHASE does apply to aircraft overrides...
peter1138 <peter1138@openttd.org>
parents:
6148
diff
changeset
|
33 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
|
34 |
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
|
35 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
|
36 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
|
37 |
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
|
38 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
|
39 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
|
40 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
|
41 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
|
42 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
|
43 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
|
44 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
45 |
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
|
46 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
|
47 { |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11875
diff
changeset
|
48 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
|
49 |
6348
bcf98ba27bbf
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents:
6259
diff
changeset
|
50 /* 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
|
51 * 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
|
52 * 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
|
53 * 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
|
54 |
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
|
55 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
|
56 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
|
57 |
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
|
58 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
|
59 |
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
|
60 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
|
61 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
|
62 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
63 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
64 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
|
65 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
66 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
67 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
68 * 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
|
69 */ |
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
|
70 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
|
71 { |
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
|
72 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
|
73 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
|
74 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
|
75 } |
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
|
76 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
|
77 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
|
78 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
|
79 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
80 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
81 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
82 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
|
83 { |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11875
diff
changeset
|
84 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
|
85 assert(cargo < lengthof(e->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
|
86 |
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
|
87 if (e->group[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
|
88 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
|
89 } |
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
|
90 e->group[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
|
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 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
93 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
94 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
95 * 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
|
96 * 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
|
97 * @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
|
98 * @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
|
99 */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
100 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
|
101 { |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11875
diff
changeset
|
102 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
|
103 e->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
|
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 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
106 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
107 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
108 * 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
|
109 * @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
|
110 * @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
|
111 */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
112 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
|
113 { |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11875
diff
changeset
|
114 return Engine::Get(engine)->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
|
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 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
119 * 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
|
120 * @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
|
121 * @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
|
122 */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
123 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
|
124 { |
11386
5c3e9447c441
(svn r15739) -Codechange: Expose GRF ID of engines in var action property 0x25.
peter1138 <peter1138@openttd.org>
parents:
11368
diff
changeset
|
125 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
|
126 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
|
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 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
130 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
|
131 { |
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
|
132 if (v->type != VEH_TRAIN) return v->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
|
133 if (IsTrainEngine(v)) return 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
134 if (IsFreeWagon(v)) return 4; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
135 return 2; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
136 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
137 |
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 /* TTDP style aircraft movement states for GRF Action 2 Var 0xE2 */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
140 enum { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
141 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
|
142 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
|
143 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
|
144 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
|
145 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
|
146 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
|
147 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
|
148 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
|
149 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
|
150 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
|
151 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
|
152 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
|
153 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
|
154 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
|
155 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
|
156 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
|
157 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
|
158 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
|
159 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
|
160 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
|
161 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
|
162 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
|
163 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
|
164 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
|
165 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
|
166 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
|
167 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
|
168 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
|
169 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
|
170 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
171 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
172 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
173 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
174 * 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
|
175 * (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
|
176 */ |
11981
cf1aad9b971c
(svn r16387) -Codechange: use Aircraft instead of Vehicle where appropriate
rubidium <rubidium@openttd.org>
parents:
11924
diff
changeset
|
177 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
|
178 { |
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
|
179 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
|
180 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
|
181 |
6032 | 182 const AirportFTAClass *afc = st->Airport(); |
6604
601751c6ba02
(svn r9819) -Codechange: Take account of AMED_HOLD in OTTD/TTDP state translation (bulb)
peter1138 <peter1138@openttd.org>
parents:
6603
diff
changeset
|
183 uint16 amdflag = afc->MovingData(v->u.air.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
|
184 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
185 switch (v->u.air.state) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
186 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
|
187 /* 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
|
188 * 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
|
189 * 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
|
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 /* 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
|
192 * 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
|
193 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
|
194 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
195 /* 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
|
196 * 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
|
197 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
|
198 |
6348
bcf98ba27bbf
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents:
6259
diff
changeset
|
199 /* 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
|
200 * 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
|
201 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
|
202 |
6348
bcf98ba27bbf
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents:
6259
diff
changeset
|
203 /* 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
|
204 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
|
205 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
206 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
|
207 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
|
208 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
|
209 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
210 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
|
211 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
|
212 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
|
213 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
214 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
|
215 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
|
216 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
|
217 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
|
218 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
|
219 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
|
220 /* 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
|
221 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
|
222 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
|
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 HELIPAD1: |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
225 case HELIPAD2: |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
226 case HELIPAD3: |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
227 case HELIPAD4: // Will only occur for helicopters. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
228 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
|
229 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
|
230 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
|
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 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
|
233 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
|
234 |
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 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
|
236 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
|
237 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
238 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
|
239 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
|
240 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
241 case HELITAKEOFF: // Helicopter is moving to take off position. |
6020 | 242 if (afc->delta_z == 0) { |
243 return amdflag & AMED_HELI_RAISE ? | |
244 AMS_TTDP_HELI_TAKEOFF_AIRPORT : AMS_TTDP_TO_JUNCTION; | |
245 } else { | |
246 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
|
247 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
248 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
249 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
|
250 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
|
251 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
252 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
|
253 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
|
254 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
255 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
|
256 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
|
257 /* 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
|
258 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
|
259 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
260 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
|
261 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
|
262 if (amdflag & AMED_HELI_LOWER) { |
6020 | 263 return afc->delta_z == 0 ? |
264 AMS_TTDP_HELI_LAND_AIRPORT : AMS_TTDP_HELI_LAND_HELIPORT; | |
265 } else { | |
266 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
|
267 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
268 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
269 default: |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
270 return 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
|
271 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
272 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
273 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
274 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
275 /* TTDP style aircraft movement action for GRF Action 2 Var 0xE6 */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
276 enum { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
277 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
|
278 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
|
279 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
|
280 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
|
281 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
|
282 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
|
283 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
|
284 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
|
285 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
|
286 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
|
287 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
|
288 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
|
289 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
|
290 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
|
291 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
|
292 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
|
293 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
|
294 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
|
295 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
|
296 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
297 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
298 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
299 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
300 * 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
|
301 * (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
|
302 * 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
|
303 */ |
11981
cf1aad9b971c
(svn r16387) -Codechange: use Aircraft instead of Vehicle where appropriate
rubidium <rubidium@openttd.org>
parents:
11924
diff
changeset
|
304 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
|
305 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
306 switch (v->u.air.state) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
307 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
|
308 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
|
309 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
310 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
|
311 case HELIPAD1: |
8836
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8786
diff
changeset
|
312 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
|
313 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
314 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
|
315 case HELIPAD2: |
8836
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8786
diff
changeset
|
316 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
|
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 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
|
319 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
|
320 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
|
321 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
|
322 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
|
323 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
|
324 case HELIPAD3: |
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 HELIPAD4: |
8836
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8786
diff
changeset
|
326 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
|
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 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
|
329 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
|
330 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
|
331 case HELITAKEOFF: |
6348
bcf98ba27bbf
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents:
6259
diff
changeset
|
332 /* @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
|
333 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
|
334 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
335 case FLYING: |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
336 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
|
337 |
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 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
|
339 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
|
340 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
|
341 case HELIENDLANDING: |
6348
bcf98ba27bbf
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents:
6259
diff
changeset
|
342 /* @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
|
343 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
|
344 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
|
345 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
346 default: |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
347 return AMA_TTDP_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
|
348 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
349 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
350 |
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 /* TTDP airport types. Used to map our types to TTDPatch's */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
353 enum { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
354 ATP_TTDP_SMALL, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
355 ATP_TTDP_LARGE, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
356 ATP_TTDP_HELIPORT, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
357 ATP_TTDP_OILRIG, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
358 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
359 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
360 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
361 /* 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
|
362 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
|
363 { |
8756
ae0ec91bb55e
(svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx <glx@openttd.org>
parents:
8666
diff
changeset
|
364 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
|
365 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
|
366 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
|
367 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
|
368 case VSG_SCOPE_RELATIVE: { |
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
|
369 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
|
370 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
|
371 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
|
372 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
|
373 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
|
374 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
|
375 break; |
ae0ec91bb55e
(svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx <glx@openttd.org>
parents:
8666
diff
changeset
|
376 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
|
377 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
|
378 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
|
379 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
|
380 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
|
381 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
|
382 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
|
383 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
|
384 } 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
|
385 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
|
386 } |
f6add1d6e9ff
(svn r12454) -Fix (r12452): incorrect calculation for 'first vehicle in this chain of vehicles with the same ID' (thx DaleStan)
glx <glx@openttd.org>
parents:
8756
diff
changeset
|
387 } |
f6add1d6e9ff
(svn r12454) -Fix (r12452): incorrect calculation for 'first vehicle in this chain of vehicles with the same ID' (thx DaleStan)
glx <glx@openttd.org>
parents:
8756
diff
changeset
|
388 if (v == NULL) v = 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
|
389 } break; |
8756
ae0ec91bb55e
(svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx <glx@openttd.org>
parents:
8666
diff
changeset
|
390 } |
ae0ec91bb55e
(svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx <glx@openttd.org>
parents:
8666
diff
changeset
|
391 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
|
392 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
|
393 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
|
394 return v; |
ae0ec91bb55e
(svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx <glx@openttd.org>
parents:
8666
diff
changeset
|
395 } |
ae0ec91bb55e
(svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx <glx@openttd.org>
parents:
8666
diff
changeset
|
396 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
397 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
398 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
399 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
400 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
|
401 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
402 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
|
403 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
404 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
405 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
406 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
|
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 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
|
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 |
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 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
|
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 /* 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
|
415 * 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
|
416 * 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
|
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 Vehicle *v = (Vehicle*)GRV(object); |
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 /* 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
|
421 * 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
|
422 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
|
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 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
|
425 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
426 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
427 |
6516
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6490
diff
changeset
|
428 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
|
429 { |
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6490
diff
changeset
|
430 const Livery *l; |
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6490
diff
changeset
|
431 |
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6490
diff
changeset
|
432 if (v == NULL) { |
11924
fccc9cea27a7
(svn r16327) -Codechange: replace IsValidPoolItemID(index) by PoolItem::IsValidID(index)
smatz <smatz@openttd.org>
parents:
11922
diff
changeset
|
433 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
|
434 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
|
435 } else if (v->type == VEH_TRAIN) { |
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
|
436 l = GetEngineLivery(v->engine_type, v->owner, v->u.rail.first_engine, v); |
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
|
437 } else if (v->type == VEH_ROAD) { |
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
|
438 l = GetEngineLivery(v->engine_type, v->owner, v->u.road.first_engine, v); |
6516
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6490
diff
changeset
|
439 } else { |
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6490
diff
changeset
|
440 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
|
441 } |
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6490
diff
changeset
|
442 |
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6490
diff
changeset
|
443 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
|
444 } |
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6490
diff
changeset
|
445 |
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
|
446 /** |
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
|
447 * 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
|
448 * @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
|
449 * @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
|
450 * 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
|
451 * @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
|
452 */ |
e0ddd5124002
(svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents:
11189
diff
changeset
|
453 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
|
454 { |
e0ddd5124002
(svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents:
11189
diff
changeset
|
455 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
|
456 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
|
457 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
|
458 |
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 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
|
460 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
|
461 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
|
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 |
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 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
|
465 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
|
466 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
|
467 } |
e0ddd5124002
(svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents:
11189
diff
changeset
|
468 |
e0ddd5124002
(svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents:
11189
diff
changeset
|
469 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
|
470 } |
6516
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6490
diff
changeset
|
471 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
472 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
|
473 { |
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
|
474 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
|
475 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
476 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
|
477 /* 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
|
478 switch (variable) { |
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
|
479 case 0x43: return _current_company | (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
|
480 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
|
481 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
|
482 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
|
483 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
|
484 if (cargo_type != CT_INVALID) { |
c993bfe070b7
(svn r15542) -Feature(ette): Support vehicle vars 0x47 and 0xF2 in purchase list.
frosch <frosch@openttd.org>
parents:
11188
diff
changeset
|
485 const CargoSpec *cs = GetCargo(cargo_type); |
c993bfe070b7
(svn r15542) -Feature(ette): Support vehicle vars 0x47 and 0xF2 in purchase list.
frosch <frosch@openttd.org>
parents:
11188
diff
changeset
|
486 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
|
487 } else { |
c993bfe070b7
(svn r15542) -Feature(ette): Support vehicle vars 0x47 and 0xF2 in purchase list.
frosch <frosch@openttd.org>
parents:
11188
diff
changeset
|
488 return 0x000000FF; |
c993bfe070b7
(svn r15542) -Feature(ette): Support vehicle vars 0x47 and 0xF2 in purchase list.
frosch <frosch@openttd.org>
parents:
11188
diff
changeset
|
489 } |
c993bfe070b7
(svn r15542) -Feature(ette): Support vehicle vars 0x47 and 0xF2 in purchase list.
frosch <frosch@openttd.org>
parents:
11188
diff
changeset
|
490 } |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11875
diff
changeset
|
491 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
|
492 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
|
493 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
|
494 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
|
495 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
|
496 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
497 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
498 *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
|
499 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
|
500 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
501 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
502 /* 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
|
503 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
|
504 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
|
505 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
|
506 |
6348
bcf98ba27bbf
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents:
6259
diff
changeset
|
507 case 0x40: // Get length of consist |
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
|
508 if (!HasBit(v->cache_valid, 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
|
509 v->cached_var40 = PositionHelper(v, false); |
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
|
510 SetBit(v->cache_valid, 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
|
511 } |
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
|
512 return v->cached_var40; |
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
|
513 |
6348
bcf98ba27bbf
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents:
6259
diff
changeset
|
514 case 0x41: // Get length of same consecutive wagons |
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
|
515 if (!HasBit(v->cache_valid, 1)) { |
e0ddd5124002
(svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents:
11189
diff
changeset
|
516 v->cached_var41 = PositionHelper(v, true); |
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
|
517 SetBit(v->cache_valid, 1); |
e0ddd5124002
(svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents:
11189
diff
changeset
|
518 } |
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
|
519 return v->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
|
520 |
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 case 0x42: // Consist cargo information |
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
|
522 if (!HasBit(v->cache_valid, 2)) { |
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 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
|
524 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
|
525 CargoID common_cargo_best = CT_INVALID; |
e0ddd5124002
(svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents:
11189
diff
changeset
|
526 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
|
527 uint8 common_subtype_best = 0xFF; // Return 0xFF if nothing is carried |
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 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
|
529 byte user_def_data = 0; |
e0ddd5124002
(svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents:
11189
diff
changeset
|
530 CargoID common_cargo_type = CT_PASSENGERS; |
e0ddd5124002
(svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents:
11189
diff
changeset
|
531 uint8 common_subtype = 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
|
532 |
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 /* 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
|
534 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
|
535 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
|
536 |
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 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
|
538 if (v->type == VEH_TRAIN) user_def_data |= u->u.rail.user_def_data; |
e0ddd5124002
(svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents:
11189
diff
changeset
|
539 |
e0ddd5124002
(svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents:
11189
diff
changeset
|
540 /* 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
|
541 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
|
542 |
e0ddd5124002
(svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents:
11189
diff
changeset
|
543 cargo_classes |= GetCargo(u->cargo_type)->classes; |
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 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
|
545 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
546 |
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 /* Pick the most 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
|
548 for (CargoID cargo = 0; cargo < NUM_CARGO; 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
|
549 if (common_cargos[cargo] > common_cargo_best) { |
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 common_cargo_best = common_cargos[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
|
551 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
|
552 } |
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
|
553 } |
5584
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 /* 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
|
556 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
|
557 /* 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
|
558 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
|
559 |
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_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
|
561 } |
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
|
562 |
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
|
563 /* Pick the most common subcargo 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
|
564 for (uint i = 0; i < lengthof(common_subtypes); 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
|
565 if (common_subtypes[i] > common_subtype_best) { |
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 common_subtype_best = common_subtypes[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
|
567 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
|
568 } |
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 } |
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
|
570 |
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
|
571 uint8 common_bitnum = (common_cargo_type == CT_INVALID ? 0xFF : GetCargo(common_cargo_type)->bitnum); |
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 v->cached_var42 = cargo_classes | (common_bitnum << 8) | (common_subtype << 16) | (user_def_data << 24); |
e0ddd5124002
(svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents:
11189
diff
changeset
|
573 SetBit(v->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
|
574 } |
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
|
575 return v->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
|
576 |
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
|
577 case 0x43: // Company information |
11268
e0ddd5124002
(svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents:
11189
diff
changeset
|
578 if (!HasBit(v->cache_valid, 3)) { |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11875
diff
changeset
|
579 v->cached_var43 = v->owner | (Company::Get(v->owner)->is_ai ? 0x10000 : 0) | (LiveryHelper(v->engine_type, v) << 24); |
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
|
580 SetBit(v->cache_valid, 3); |
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
|
581 } |
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
|
582 return v->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
|
583 |
6348
bcf98ba27bbf
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents:
6259
diff
changeset
|
584 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
|
585 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
|
586 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
587 { |
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
|
588 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
|
589 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
|
590 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
|
591 |
11981
cf1aad9b971c
(svn r16387) -Codechange: use Aircraft instead of Vehicle where appropriate
rubidium <rubidium@openttd.org>
parents:
11924
diff
changeset
|
592 const Station *st = GetTargetAirportIfValid((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
|
593 |
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
|
594 if (st != NULL) { |
2748e8fea4a2
(svn r14383) -Fix [FS#2316](r14343): handle invalid 'v->u.air.targetairport' in the NewGRF code, too
smatz <smatz@openttd.org>
parents:
9750
diff
changeset
|
595 switch (st->airport_type) { |
2748e8fea4a2
(svn r14383) -Fix [FS#2316](r14343): handle invalid 'v->u.air.targetairport' in the NewGRF code, too
smatz <smatz@openttd.org>
parents:
9750
diff
changeset
|
596 /* Note, Helidepot and Helistation are treated as small airports |
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
|
597 * as they are at ground level. */ |
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
|
598 case AT_HELIDEPOT: |
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
|
599 case AT_HELISTATION: |
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 case AT_COMMUTER: |
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 case AT_SMALL: airporttype = ATP_TTDP_SMALL; break; |
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
|
602 case AT_METROPOLITAN: |
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
|
603 case AT_INTERNATIONAL: |
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
|
604 case AT_INTERCON: |
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
|
605 case AT_LARGE: airporttype = ATP_TTDP_LARGE; break; |
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
|
606 case AT_HELIPORT: airporttype = ATP_TTDP_HELIPORT; break; |
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
|
607 case AT_OILRIG: airporttype = ATP_TTDP_OILRIG; break; |
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
|
608 default: airporttype = ATP_TTDP_LARGE; break; |
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
|
609 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
610 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
611 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
612 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
|
613 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
614 |
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
|
615 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
|
616 /* 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
|
617 * 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
|
618 * 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
|
619 * 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
|
620 */ |
10643
9c1b0524a8a1
(svn r14945) -Feature(ette): Support var 0x45 (curvature info) also for road vehicles.
frosch <frosch@openttd.org>
parents:
10544
diff
changeset
|
621 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
|
622 |
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
|
623 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
|
624 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
|
625 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
|
626 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
|
627 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
|
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 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
|
630 ((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
|
631 ( 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
|
632 } |
3c89f72535f3
(svn r9803) -Feature(tte): support for "curvature info", Action 2 for train, variable 45 (mart3p).
rubidium <rubidium@openttd.org>
parents:
6517
diff
changeset
|
633 |
6348
bcf98ba27bbf
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents:
6259
diff
changeset
|
634 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
|
635 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
|
636 |
6348
bcf98ba27bbf
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents:
6259
diff
changeset
|
637 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
|
638 /* 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
|
639 * 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
|
640 * 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
|
641 * 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
|
642 * 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
|
643 */ |
6091
17ebeb5a2c37
(svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138 <peter1138@openttd.org>
parents:
6032
diff
changeset
|
644 const CargoSpec *cs = GetCargo(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
|
645 |
6147
a7aecaae3414
(svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138 <peter1138@openttd.org>
parents:
6126
diff
changeset
|
646 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
|
647 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
648 |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11875
diff
changeset
|
649 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
|
650 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
|
651 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
652 /* 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
|
653 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
|
654 //EngineID engine = GetNewEngineID(GetEngineGRF(v->engine_type), v->type, parameter); |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11875
diff
changeset
|
655 if (v->type != VEH_TRAIN) return Engine::Get(v->engine_type)->internal_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
|
656 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
657 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
658 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
|
659 for (; v != NULL; v = v->Next()) { |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11875
diff
changeset
|
660 if (Engine::Get(v->engine_type)->internal_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
|
661 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
662 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
|
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 |
6176
863c86137fc1
(svn r8946) -Feature: [NewGRF] Add support for vehicle variables 0xFE and 0xFF bit 10,
maedhros <maedhros@openttd.org>
parents:
6173
diff
changeset
|
665 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
|
666 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
|
667 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
|
668 |
8665
5e82cdbe1cc1
(svn r12330) -Feature: [NewGRF] vehicle variable FE bit 5 and 6
glx <glx@openttd.org>
parents:
8654
diff
changeset
|
669 if (v->type == VEH_TRAIN) { |
5e82cdbe1cc1
(svn r12330) -Feature: [NewGRF] vehicle variable FE bit 5 and 6
glx <glx@openttd.org>
parents:
8654
diff
changeset
|
670 const Vehicle *u = IsTrainWagon(v) && HasBit(v->vehicle_flags, VRF_POWEREDWAGON) ? v->First() : v; |
5e82cdbe1cc1
(svn r12330) -Feature: [NewGRF] vehicle variable FE bit 5 and 6
glx <glx@openttd.org>
parents:
8654
diff
changeset
|
671 RailType railtype = GetRailType(v->tile); |
5e82cdbe1cc1
(svn r12330) -Feature: [NewGRF] vehicle variable FE bit 5 and 6
glx <glx@openttd.org>
parents:
8654
diff
changeset
|
672 bool powered = IsTrainEngine(v) || (IsTrainWagon(v) && HasBit(v->vehicle_flags, VRF_POWEREDWAGON)); |
5e82cdbe1cc1
(svn r12330) -Feature: [NewGRF] vehicle variable FE bit 5 and 6
glx <glx@openttd.org>
parents:
8654
diff
changeset
|
673 bool has_power = powered && HasPowerOnRail(u->u.rail.railtype, railtype); |
5e82cdbe1cc1
(svn r12330) -Feature: [NewGRF] vehicle variable FE bit 5 and 6
glx <glx@openttd.org>
parents:
8654
diff
changeset
|
674 bool is_electric = powered && u->u.rail.railtype == RAILTYPE_ELECTRIC; |
8666
ae052ccde3db
(svn r12331) -Feature: [NewGRF] vehicle variable FE bit 8
glx <glx@openttd.org>
parents:
8665
diff
changeset
|
675 |
8665
5e82cdbe1cc1
(svn r12330) -Feature: [NewGRF] vehicle variable FE bit 5 and 6
glx <glx@openttd.org>
parents:
8654
diff
changeset
|
676 if (has_power) SetBit(modflags, 5); |
5e82cdbe1cc1
(svn r12330) -Feature: [NewGRF] vehicle variable FE bit 5 and 6
glx <glx@openttd.org>
parents:
8654
diff
changeset
|
677 if (is_electric && !has_power) SetBit(modflags, 6); |
8666
ae052ccde3db
(svn r12331) -Feature: [NewGRF] vehicle variable FE bit 8
glx <glx@openttd.org>
parents:
8665
diff
changeset
|
678 if (HasBit(v->u.rail.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
|
679 } |
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
|
680 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
|
681 |
863c86137fc1
(svn r8946) -Feature: [NewGRF] Add support for vehicle variables 0xFE and 0xFF bit 10,
maedhros <maedhros@openttd.org>
parents:
6173
diff
changeset
|
682 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
|
683 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
684 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
685 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
686 /* 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
|
687 switch (variable - 0x80) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
688 case 0x00: return v->type; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
689 case 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
|
690 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
|
691 case 0x05: return GB(v->index, 8, 8); |
8839
ebb630745ebc
(svn r12587) -Codechange: unduplicate some code in the Unpack*Order functions and move the 'normal' case Pack/Unpack to Order.
rubidium <rubidium@openttd.org>
parents:
8836
diff
changeset
|
692 case 0x0A: return v->current_order.Pack(); |
ebb630745ebc
(svn r12587) -Codechange: unduplicate some code in the Unpack*Order functions and move the 'normal' case Pack/Unpack to Order.
rubidium <rubidium@openttd.org>
parents:
8836
diff
changeset
|
693 case 0x0B: return GB(v->current_order.Pack(), 8, 8); |
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
|
694 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
|
695 case 0x0D: return v->cur_order_index; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
696 case 0x10: return v->load_unload_time_rem; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
697 case 0x11: return GB(v->load_unload_time_rem, 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
|
698 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
|
699 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
|
700 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
|
701 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
|
702 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
|
703 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
|
704 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
|
705 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
|
706 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
|
707 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
|
708 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
|
709 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
|
710 case 0x1E: return v->z_pos; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
711 case 0x1F: return object->info_view ? DIR_W : v->direction; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
712 case 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
|
713 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
|
714 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
|
715 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
|
716 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
|
717 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
|
718 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
|
719 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
|
720 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
|
721 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
|
722 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
|
723 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
|
724 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
|
725 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
|
726 case 0x3F: return v->cargo.DaysInTransit(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
727 case 0x40: return v->age; |
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 0x41: return GB(v->age, 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 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
|
730 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
|
731 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
|
732 case 0x45: return v->unitnumber; |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11875
diff
changeset
|
733 case 0x46: return Engine::Get(v->engine_type)->internal_id; |
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11875
diff
changeset
|
734 case 0x47: return GB(Engine::Get(v->engine_type)->internal_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
|
735 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
|
736 if (v->type != VEH_TRAIN || v->spritenum != 0xFD) return v->spritenum; |
323c3edf9c0d
(svn r12910) -Fix: Report reverse sprite status (FD/FE) to NewGRF for manually toggled vehicles.
peter1138 <peter1138@openttd.org>
parents:
9046
diff
changeset
|
737 return HasBit(v->u.rail.flags, VRF_REVERSE_DIRECTION) ? 0xFE : 0xFD; |
323c3edf9c0d
(svn r12910) -Fix: Report reverse sprite status (FD/FE) to NewGRF for manually toggled vehicles.
peter1138 <peter1138@openttd.org>
parents:
9046
diff
changeset
|
738 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
739 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
|
740 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
|
741 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
|
742 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
|
743 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
|
744 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
|
745 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
|
746 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
|
747 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
|
748 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
|
749 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
|
750 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
|
751 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
|
752 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
|
753 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
|
754 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
|
755 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
|
756 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
|
757 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
|
758 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
|
759 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
|
760 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
|
761 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
|
762 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
|
763 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
|
764 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
765 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
766 /* 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
|
767 switch (v->type) { |
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
|
768 case VEH_TRAIN: |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
769 switch (variable - 0x80) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
770 case 0x62: return v->u.rail.track; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
771 case 0x66: return v->u.rail.railtype; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
772 case 0x73: return v->u.rail.cached_veh_length; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
773 case 0x74: return v->u.rail.cached_power; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
774 case 0x75: return GB(v->u.rail.cached_power, 8, 24); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
775 case 0x76: return GB(v->u.rail.cached_power, 16, 16); |
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 0x77: return GB(v->u.rail.cached_power, 24, 8); |
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
|
777 case 0x7C: return v->First()->index; |
797ff0b0e0a5
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium <rubidium@openttd.org>
parents:
7492
diff
changeset
|
778 case 0x7D: return GB(v->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
|
779 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
|
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 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
782 |
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
|
783 case VEH_ROAD: |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
784 switch (variable - 0x80) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
785 case 0x62: return v->u.road.state; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
786 case 0x64: return v->u.road.blocked_ctr; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
787 case 0x65: return GB(v->u.road.blocked_ctr, 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
|
788 case 0x66: return v->u.road.overtaking; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
789 case 0x67: return v->u.road.overtaking_ctr; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
790 case 0x68: return v->u.road.crashed_ctr; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
791 case 0x69: return GB(v->u.road.crashed_ctr, 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
|
792 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
793 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
794 |
11981
cf1aad9b971c
(svn r16387) -Codechange: use Aircraft instead of Vehicle where appropriate
rubidium <rubidium@openttd.org>
parents:
11924
diff
changeset
|
795 case VEH_AIRCRAFT: { |
cf1aad9b971c
(svn r16387) -Codechange: use Aircraft instead of Vehicle where appropriate
rubidium <rubidium@openttd.org>
parents:
11924
diff
changeset
|
796 Aircraft *a = (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
|
797 switch (variable - 0x80) { |
11981
cf1aad9b971c
(svn r16387) -Codechange: use Aircraft instead of Vehicle where appropriate
rubidium <rubidium@openttd.org>
parents:
11924
diff
changeset
|
798 case 0x62: return MapAircraftMovementState(a); // Current movement 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
|
799 case 0x63: return v->u.air.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
|
800 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
|
801 } |
11981
cf1aad9b971c
(svn r16387) -Codechange: use Aircraft instead of Vehicle where appropriate
rubidium <rubidium@openttd.org>
parents:
11924
diff
changeset
|
802 } break; |
6621
c751437b3bac
(svn r9841) -Codechange: add a little more type strictness to the vehicle types.
rubidium <rubidium@openttd.org>
parents:
6604
diff
changeset
|
803 |
c751437b3bac
(svn r9841) -Codechange: add a little more type strictness to the vehicle types.
rubidium <rubidium@openttd.org>
parents:
6604
diff
changeset
|
804 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
|
805 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
806 |
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
|
807 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
|
808 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
809 *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
|
810 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
|
811 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
812 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
813 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
814 static const SpriteGroup *VehicleResolveReal(const ResolverObject *object, 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
|
815 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
816 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
|
817 |
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
|
818 if (v == 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
|
819 if (group->g.real.num_loading > 0) return group->g.real.loading[0]; |
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
|
820 if (group->g.real.num_loaded > 0) return group->g.real.loaded[0]; |
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
|
821 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
|
822 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
823 |
8836
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8786
diff
changeset
|
824 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
|
825 |
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
|
826 uint totalsets = in_motion ? group->g.real.num_loaded : group->g.real.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
|
827 |
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
|
828 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
|
829 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
|
830 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
831 return in_motion ? group->g.real.loaded[set] : group->g.real.loading[set]; |
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 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
834 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
835 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
|
836 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
837 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
|
838 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
|
839 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
|
840 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
|
841 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
|
842 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
843 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
|
844 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
|
845 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
846 res->u.vehicle.self_type = engine_type; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
847 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
848 res->info_view = false; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
849 |
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
|
850 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
|
851 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
|
852 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
|
853 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
|
854 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
|
855 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
|
856 res->count = 0; |
9750
0654bf387d06
(svn r13885) -Fix [FS#2168]: Var 0x7F is not feature-specific.
frosch <frosch@openttd.org>
parents:
9672
diff
changeset
|
857 |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11875
diff
changeset
|
858 const Engine *e = Engine::Get(engine_type); |
9750
0654bf387d06
(svn r13885) -Fix [FS#2168]: Var 0x7F is not feature-specific.
frosch <frosch@openttd.org>
parents:
9672
diff
changeset
|
859 res->grffile = (e != NULL ? e->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
|
860 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
861 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
862 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
863 /** Retrieve the SpriteGroup for the specified vehicle. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
864 * 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
|
865 * 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
|
866 * @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
|
867 * @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
|
868 * @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
|
869 * @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
|
870 */ |
7863
ea337dd0527c
(svn r11413) -Fix [FS#1405]: don't use cached override spriteset for callbacks
glx <glx@openttd.org>
parents:
7861
diff
changeset
|
871 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
|
872 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
873 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
|
874 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
|
875 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
876 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
|
877 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
|
878 } 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
|
879 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
|
880 |
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
|
881 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
|
882 /* 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
|
883 * 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
|
884 * as v->cargo_type is temporary changed to the new type */ |
ea337dd0527c
(svn r11413) -Fix [FS#1405]: don't use cached override spriteset for callbacks
glx <glx@openttd.org>
parents:
7861
diff
changeset
|
885 group = use_cache ? v->u.rail.cached_override : GetWagonOverrideSpriteSet(v->engine_type, v->cargo_type, v->u.rail.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
|
886 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
|
887 } else if (v->type == VEH_ROAD) { |
504cd363813f
(svn r15516) -Fix (r10097): Livery overrides for articulated parts of roadvehicles were not applied.
frosch <frosch@openttd.org>
parents:
11059
diff
changeset
|
888 group = GetWagonOverrideSpriteSet(v->engine_type, v->cargo_type, v->u.road.first_engine); |
504cd363813f
(svn r15516) -Fix (r10097): Livery overrides for articulated parts of roadvehicles were not applied.
frosch <frosch@openttd.org>
parents:
11059
diff
changeset
|
889 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
|
890 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
891 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
892 |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11875
diff
changeset
|
893 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
|
894 |
11059
b843df5d362a
(svn r15399) -Fix [FS#2617]: For articulated parts v->cargo_type == CT_INVALID is possible.
frosch <frosch@openttd.org>
parents:
11038
diff
changeset
|
895 assert(cargo < lengthof(e->group)); |
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
|
896 group = e->group[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
|
897 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
|
898 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
899 /* Fall back to the default set if the selected cargo type is not defined */ |
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
|
900 return e->group[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
|
901 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
902 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
903 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
904 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
|
905 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
906 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
|
907 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
|
908 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
909 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
|
910 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
911 group = Resolve(GetVehicleSpriteGroup(engine, v), &object); |
9472
4e50112e2fb9
(svn r13397) -Fix: Do not crash when resolving vehicle sprite groups with zero sprites.
frosch <frosch@openttd.org>
parents:
9459
diff
changeset
|
912 if (group == NULL || group->type != SGT_RESULT || group->g.result.num_sprites == 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
|
913 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
914 return group->g.result.sprite + (direction % group->g.result.num_sprites); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
915 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
916 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
917 |
11981
cf1aad9b971c
(svn r16387) -Codechange: use Aircraft instead of Vehicle where appropriate
rubidium <rubidium@openttd.org>
parents:
11924
diff
changeset
|
918 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
|
919 { |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11875
diff
changeset
|
920 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
|
921 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
922 /* 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
|
923 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
|
924 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
|
925 |
9436
b3969ef775ba
(svn r13351) -Codechange: disable warnings about unused variable for builds without asserts
smatz <smatz@openttd.org>
parents:
9413
diff
changeset
|
926 ResolverObject object; |
b3969ef775ba
(svn r13351) -Codechange: disable warnings about unused variable for builds without asserts
smatz <smatz@openttd.org>
parents:
9413
diff
changeset
|
927 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
928 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
|
929 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
930 object.info_view = info_view; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
931 |
9436
b3969ef775ba
(svn r13351) -Codechange: disable warnings about unused variable for builds without asserts
smatz <smatz@openttd.org>
parents:
9413
diff
changeset
|
932 const SpriteGroup *group = GetWagonOverrideSpriteSet(engine, CT_DEFAULT, 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
|
933 group = Resolve(group, &object); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
934 |
9472
4e50112e2fb9
(svn r13397) -Fix: Do not crash when resolving vehicle sprite groups with zero sprites.
frosch <frosch@openttd.org>
parents:
9459
diff
changeset
|
935 if (group == NULL || group->type != SGT_RESULT || group->g.result.num_sprites == 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
|
936 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
937 if (v == NULL) return group->g.result.sprite; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
938 |
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
|
939 return group->g.result.sprite + (info_view ? 0 : (v->Next()->Next()->u.air.state % group->g.result.num_sprites)); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
940 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
941 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
942 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
943 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
944 * 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
|
945 * @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
|
946 * @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
|
947 */ |
10647
592ae9307430
(svn r14949) -Cleanup: pointer coding style
rubidium <rubidium@openttd.org>
parents:
10643
diff
changeset
|
948 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
|
949 { |
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
|
950 assert(v->type == VEH_TRAIN); |
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
|
951 return v->u.rail.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
|
952 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
953 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
954 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
955 * 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
|
956 * @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
|
957 * @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
|
958 * @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
|
959 * @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
|
960 * @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
|
961 * @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
|
962 */ |
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
|
963 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
|
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 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
|
966 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
|
967 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
968 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
|
969 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
970 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
|
971 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
|
972 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
|
973 |
7863
ea337dd0527c
(svn r11413) -Fix [FS#1405]: don't use cached override spriteset for callbacks
glx <glx@openttd.org>
parents:
7861
diff
changeset
|
974 group = Resolve(GetVehicleSpriteGroup(engine, v, false), &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
|
975 if (group == NULL || group->type != SGT_CALLBACK) return CALLBACK_FAILED; |
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 return group->g.callback.result; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
978 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
979 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
980 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
981 * 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
|
982 * @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
|
983 * @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
|
984 * @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
|
985 * @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
|
986 * @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
|
987 * @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
|
988 * @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
|
989 */ |
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
|
990 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
|
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 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
|
993 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
|
994 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
995 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
|
996 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
997 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
|
998 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
|
999 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
|
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 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
|
1002 |
7863
ea337dd0527c
(svn r11413) -Fix [FS#1405]: don't use cached override spriteset for callbacks
glx <glx@openttd.org>
parents:
7861
diff
changeset
|
1003 group = Resolve(GetVehicleSpriteGroup(engine, v, false), &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
|
1004 if (group == NULL || group->type != SGT_CALLBACK) return CALLBACK_FAILED; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1005 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1006 return group->g.callback.result; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1007 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1008 |
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
|
1009 |
6517
bfa6449a2b3a
(svn r9703) -Codechange: support callback 36 in vehicle purchase lists
peter1138 <peter1138@openttd.org>
parents:
6516
diff
changeset
|
1010 /* Callback 36 handlers */ |
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
|
1011 uint GetVehicleProperty(const Vehicle *v, uint8 property, uint 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
|
1012 { |
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
|
1013 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
|
1014 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
|
1015 |
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
|
1016 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
|
1017 } |
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
|
1018 |
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
|
1019 |
6517
bfa6449a2b3a
(svn r9703) -Codechange: support callback 36 in vehicle purchase lists
peter1138 <peter1138@openttd.org>
parents:
6516
diff
changeset
|
1020 uint GetEngineProperty(EngineID engine, uint8 property, uint orig_value) |
bfa6449a2b3a
(svn r9703) -Codechange: support callback 36 in vehicle purchase lists
peter1138 <peter1138@openttd.org>
parents:
6516
diff
changeset
|
1021 { |
bfa6449a2b3a
(svn r9703) -Codechange: support callback 36 in vehicle purchase lists
peter1138 <peter1138@openttd.org>
parents:
6516
diff
changeset
|
1022 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
|
1023 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
|
1024 |
bfa6449a2b3a
(svn r9703) -Codechange: support callback 36 in vehicle purchase lists
peter1138 <peter1138@openttd.org>
parents:
6516
diff
changeset
|
1025 return orig_value; |
bfa6449a2b3a
(svn r9703) -Codechange: support callback 36 in vehicle purchase lists
peter1138 <peter1138@openttd.org>
parents:
6516
diff
changeset
|
1026 } |
bfa6449a2b3a
(svn r9703) -Codechange: support callback 36 in vehicle purchase lists
peter1138 <peter1138@openttd.org>
parents:
6516
diff
changeset
|
1027 |
bfa6449a2b3a
(svn r9703) -Codechange: support callback 36 in vehicle purchase lists
peter1138 <peter1138@openttd.org>
parents:
6516
diff
changeset
|
1028 |
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 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
|
1030 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1031 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
|
1032 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
|
1033 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
|
1034 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1035 /* 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
|
1036 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
|
1037 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1038 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
|
1039 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
|
1040 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
|
1041 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1042 group = 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
|
1043 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
|
1044 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1045 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
|
1046 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
|
1047 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
|
1048 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1049 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
|
1050 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
|
1051 /* 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
|
1052 * 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
|
1053 * 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
|
1054 * 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
|
1055 * 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
|
1056 * 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
|
1057 * 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
|
1058 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
|
1059 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
|
1060 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1061 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1062 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
|
1063 /* 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
|
1064 * 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
|
1065 * 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
|
1066 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
|
1067 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1068 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1069 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
|
1070 /* 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
|
1071 * 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
|
1072 * 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
|
1073 * 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
|
1074 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
|
1075 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1076 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1077 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
|
1078 /* 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
|
1079 * 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
|
1080 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
|
1081 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
|
1082 break; |
7803
1ad76d7d65b8
(svn r11353) -Codechange: add support for newgrf callback 32
glx <glx@openttd.org>
parents:
7550
diff
changeset
|
1083 |
1ad76d7d65b8
(svn r11353) -Codechange: add support for newgrf callback 32
glx <glx@openttd.org>
parents:
7550
diff
changeset
|
1084 case VEHICLE_TRIGGER_CALLBACK_32: |
1ad76d7d65b8
(svn r11353) -Codechange: add support for newgrf callback 32
glx <glx@openttd.org>
parents:
7550
diff
changeset
|
1085 /* Do not do any recursion */ |
1ad76d7d65b8
(svn r11353) -Codechange: add support for newgrf callback 32
glx <glx@openttd.org>
parents:
7550
diff
changeset
|
1086 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
|
1087 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1088 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1089 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1090 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
|
1091 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1092 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
|
1093 /* 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
|
1094 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
|
1095 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1096 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1097 DoTriggerVehicle(v, trigger, 0, true); |
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 |
6348
bcf98ba27bbf
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents:
6259
diff
changeset
|
1100 /* 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
|
1101 * 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
|
1102 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1103 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1104 * 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
|
1105 * 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
|
1106 * @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
|
1107 * @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
|
1108 */ |
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
|
1109 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
|
1110 { |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11875
diff
changeset
|
1111 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
|
1112 if (e->grffile == NULL) return 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
|
1113 |
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
|
1114 /* Crude sorting to group by GRF ID */ |
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
|
1115 return (e->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
|
1116 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1117 |
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
|
1118 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
|
1119 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
|
1120 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
|
1121 }; |
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
|
1122 |
10416
25ae1dbfcf45
(svn r14669) -Codechange: use SmallVector instead of std::list at one place
smatz <smatz@openttd.org>
parents:
10208
diff
changeset
|
1123 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
|
1124 |
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
|
1125 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
|
1126 { |
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
|
1127 /* 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
|
1128 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
|
1129 loc->engine = engine; |
25ae1dbfcf45
(svn r14669) -Codechange: use SmallVector instead of std::list at one place
smatz <smatz@openttd.org>
parents:
10208
diff
changeset
|
1130 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
|
1131 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1132 |
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
|
1133 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
|
1134 { |
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
|
1135 /* 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
|
1136 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
|
1137 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
|
1138 |
10416
25ae1dbfcf45
(svn r14669) -Codechange: use SmallVector instead of std::list at one place
smatz <smatz@openttd.org>
parents:
10208
diff
changeset
|
1139 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
|
1140 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
|
1141 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
|
1142 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
|
1143 |
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 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
|
1145 |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11875
diff
changeset
|
1146 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
|
1147 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
|
1148 |
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
|
1149 /* 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
|
1150 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
|
1151 FOR_ALL_ENGINES_OF_TYPE(e, source_e->type) { |
9413
512ea64da840
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents:
9354
diff
changeset
|
1152 if (!_settings_game.vehicle.dynamic_engines || e->grffile == source_e->grffile) { |
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
|
1153 if (e->internal_id == target) target_e = 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
|
1154 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
|
1155 } |
11b5b3f4175d
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents:
9062
diff
changeset
|
1156 } |
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
|
1157 |
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
|
1158 /* 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
|
1159 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
|
1160 |
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 /* 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
|
1162 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
|
1163 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
|
1164 |
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 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
|
1166 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
|
1167 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
|
1168 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
|
1169 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
|
1170 } |
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 |
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
|
1172 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
|
1173 } |
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 |
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
|
1175 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
|
1176 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1177 |
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 /* 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
|
1179 _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
|
1180 } |