Mercurial > hg > openttd
annotate src/newgrf_engine.cpp @ 12301:218a41d3d557 draft
(svn r16718) -Codechange: make IsFreeWagon() member of Train
author | smatz <smatz@openttd.org> |
---|---|
date | Wed, 01 Jul 2009 23:49:13 +0000 |
parents | b5e93af93fc2 |
children | fc8e41f34b8c |
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" |
11984
b6d3e583be86
(svn r16390) -Codechange: move u.road to RoadVehicle.
rubidium <rubidium@openttd.org>
parents:
11982
diff
changeset
|
8 #include "roadveh.h" |
10208
39cf8eebfda5
(svn r14422) -Codechange: also reflect the changes of r14421 in the filenames.
rubidium <rubidium@openttd.org>
parents:
10207
diff
changeset
|
9 #include "company_func.h" |
12232
b5e93af93fc2
(svn r16647) -Codechange: remove newgrf.h include from newgrf_engine.h to prevent unnecessary inclusion newgrf.h anyway
yexo <yexo@openttd.org>
parents:
12228
diff
changeset
|
10 #include "newgrf.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
|
11 #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
|
12 #include "newgrf_spritegroup.h" |
8140
fb8a05d579da
(svn r11702) -Codechange: move all date related stuff to date*.
rubidium <rubidium@openttd.org>
parents:
8131
diff
changeset
|
13 #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
|
14 #include "vehicle_func.h" |
8213
87c85bb42d6f
(svn r11776) -Codechange: more header splittings to reduce the dependencies.
rubidium <rubidium@openttd.org>
parents:
8198
diff
changeset
|
15 #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
|
16 #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
|
17 #include "core/smallmap_type.hpp" |
10960
a4e5b5d2837c
(svn r15299) -Cleanup: remove many redundant includes
smatz <smatz@openttd.org>
parents:
10647
diff
changeset
|
18 #include "settings_type.h" |
12228
240adc64d01a
(svn r16643) -Codechange: replace GetStationByTile() by Station::GetByTile()
smatz <smatz@openttd.org>
parents:
12220
diff
changeset
|
19 #include "station_base.h" |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
20 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
21 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
|
22 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
|
23 |
6248
0789677a15a0
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents:
6247
diff
changeset
|
24 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
|
25 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
|
26 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
|
27 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
|
28 const SpriteGroup *group; |
6248
0789677a15a0
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents:
6247
diff
changeset
|
29 }; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
30 |
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
|
31 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
|
32 { |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11875
diff
changeset
|
33 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
|
34 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
|
35 |
6157
e080eca511f9
(svn r8903) -Regression (r8891): CT_PURCHASE does apply to aircraft overrides...
peter1138 <peter1138@openttd.org>
parents:
6148
diff
changeset
|
36 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
|
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 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
|
39 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
|
40 |
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
|
41 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
|
42 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
|
43 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
|
44 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
|
45 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
|
46 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
|
47 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
48 |
8198
dbc8b8dbeda4
(svn r11761) -Codechange: Use appropriate variable types for NewGRF engine overrides, and adjust scope while there.
peter1138 <peter1138@openttd.org>
parents:
8193
diff
changeset
|
49 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
|
50 { |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11875
diff
changeset
|
51 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
|
52 |
6348
bcf98ba27bbf
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents:
6259
diff
changeset
|
53 /* 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
|
54 * 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
|
55 * 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
|
56 * 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
|
57 |
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
|
58 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
|
59 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
|
60 |
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->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
|
62 |
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
|
63 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
|
64 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
|
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 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
|
68 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
69 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
70 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
71 * 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
|
72 */ |
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
|
73 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
|
74 { |
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
|
75 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
|
76 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
|
77 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
|
78 } |
9070
11b5b3f4175d
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents:
9062
diff
changeset
|
79 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
|
80 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
|
81 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
|
82 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
83 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
84 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
85 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
|
86 { |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11875
diff
changeset
|
87 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
|
88 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
|
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 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
|
91 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
|
92 } |
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
|
93 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
|
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 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
96 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
97 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
98 * 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
|
99 * 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
|
100 * @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
|
101 * @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
|
102 */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
103 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
|
104 { |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11875
diff
changeset
|
105 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
|
106 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
|
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 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
109 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
110 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
111 * 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
|
112 * @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
|
113 * @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
|
114 */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
115 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
|
116 { |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11875
diff
changeset
|
117 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
|
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 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
120 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
121 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
122 * 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
|
123 * @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
|
124 * @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
|
125 */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
126 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
|
127 { |
11386
5c3e9447c441
(svn r15739) -Codechange: Expose GRF ID of engines in var action property 0x25.
peter1138 <peter1138@openttd.org>
parents:
11368
diff
changeset
|
128 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
|
129 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
|
130 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
131 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
132 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
133 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
|
134 { |
12199
8e20cb543b87
(svn r16613) -Fix [NewGRF]: some of the var action 2 80+ variables contained wrong results due to OpenTTD codechanges
yexo <yexo@openttd.org>
parents:
12114
diff
changeset
|
135 switch (v->type) { |
8e20cb543b87
(svn r16613) -Fix [NewGRF]: some of the var action 2 80+ variables contained wrong results due to OpenTTD codechanges
yexo <yexo@openttd.org>
parents:
12114
diff
changeset
|
136 case VEH_TRAIN: |
8e20cb543b87
(svn r16613) -Fix [NewGRF]: some of the var action 2 80+ variables contained wrong results due to OpenTTD codechanges
yexo <yexo@openttd.org>
parents:
12114
diff
changeset
|
137 if (IsTrainEngine(v)) return 0; |
12301
218a41d3d557
(svn r16718) -Codechange: make IsFreeWagon() member of Train
smatz <smatz@openttd.org>
parents:
12232
diff
changeset
|
138 if (Train::From(v)->IsFreeWagon()) return 4; |
12199
8e20cb543b87
(svn r16613) -Fix [NewGRF]: some of the var action 2 80+ variables contained wrong results due to OpenTTD codechanges
yexo <yexo@openttd.org>
parents:
12114
diff
changeset
|
139 return 2; |
8e20cb543b87
(svn r16613) -Fix [NewGRF]: some of the var action 2 80+ variables contained wrong results due to OpenTTD codechanges
yexo <yexo@openttd.org>
parents:
12114
diff
changeset
|
140 case VEH_ROAD: |
8e20cb543b87
(svn r16613) -Fix [NewGRF]: some of the var action 2 80+ variables contained wrong results due to OpenTTD codechanges
yexo <yexo@openttd.org>
parents:
12114
diff
changeset
|
141 case VEH_SHIP: return 0; |
8e20cb543b87
(svn r16613) -Fix [NewGRF]: some of the var action 2 80+ variables contained wrong results due to OpenTTD codechanges
yexo <yexo@openttd.org>
parents:
12114
diff
changeset
|
142 case VEH_AIRCRAFT: |
8e20cb543b87
(svn r16613) -Fix [NewGRF]: some of the var action 2 80+ variables contained wrong results due to OpenTTD codechanges
yexo <yexo@openttd.org>
parents:
12114
diff
changeset
|
143 case VEH_DISASTER: return v->subtype; |
8e20cb543b87
(svn r16613) -Fix [NewGRF]: some of the var action 2 80+ variables contained wrong results due to OpenTTD codechanges
yexo <yexo@openttd.org>
parents:
12114
diff
changeset
|
144 case VEH_EFFECT: return v->subtype << 1; |
8e20cb543b87
(svn r16613) -Fix [NewGRF]: some of the var action 2 80+ variables contained wrong results due to OpenTTD codechanges
yexo <yexo@openttd.org>
parents:
12114
diff
changeset
|
145 default: NOT_REACHED(); |
8e20cb543b87
(svn r16613) -Fix [NewGRF]: some of the var action 2 80+ variables contained wrong results due to OpenTTD codechanges
yexo <yexo@openttd.org>
parents:
12114
diff
changeset
|
146 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
147 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
148 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
149 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
150 /* 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
|
151 enum { |
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_HANGAR, |
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_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
|
154 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
|
155 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
|
156 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
|
157 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
|
158 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
|
159 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
|
160 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
|
161 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
|
162 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
|
163 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
|
164 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
|
165 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
|
166 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
|
167 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
|
168 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
|
169 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
|
170 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
|
171 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
|
172 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
|
173 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
|
174 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
|
175 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
|
176 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
|
177 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
|
178 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
|
179 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
|
180 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
|
181 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
182 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
183 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
184 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
185 * 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
|
186 * (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
|
187 */ |
11981
cf1aad9b971c
(svn r16387) -Codechange: use Aircraft instead of Vehicle where appropriate
rubidium <rubidium@openttd.org>
parents:
11924
diff
changeset
|
188 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
|
189 { |
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
|
190 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
|
191 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
|
192 |
6032 | 193 const AirportFTAClass *afc = st->Airport(); |
11982
9add5306a01e
(svn r16388) -Codechange: move u.air to Aircraft
rubidium <rubidium@openttd.org>
parents:
11981
diff
changeset
|
194 uint16 amdflag = afc->MovingData(v->pos)->flag; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
195 |
11982
9add5306a01e
(svn r16388) -Codechange: move u.air to Aircraft
rubidium <rubidium@openttd.org>
parents:
11981
diff
changeset
|
196 switch (v->state) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
197 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
|
198 /* 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
|
199 * 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
|
200 * 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
|
201 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
202 /* 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
|
203 * 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
|
204 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
|
205 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
206 /* This condition only occurs for helicopters, 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
|
207 * to a landing by the hanger of an international airport. */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
208 if (amdflag & AMED_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
|
209 |
6348
bcf98ba27bbf
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents:
6259
diff
changeset
|
210 /* 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
|
211 * 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
|
212 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
|
213 |
6348
bcf98ba27bbf
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents:
6259
diff
changeset
|
214 /* 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
|
215 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
|
216 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
217 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
|
218 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
|
219 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
|
220 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
221 case TERM2: |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
222 if (amdflag & AMED_EXACTPOS) return AMS_TTDP_TO_PAD2; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
223 return AMS_TTDP_TO_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
|
224 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
225 case TERM3: |
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 TERM4: |
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 TERM5: |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
228 case TERM6: |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
229 case TERM7: |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
230 case TERM8: |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
231 /* 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
|
232 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
|
233 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
|
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 HELIPAD1: |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
236 case HELIPAD2: |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
237 case HELIPAD3: |
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 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
|
239 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
|
240 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
|
241 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
|
242 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
243 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
|
244 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
|
245 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
246 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
|
247 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
|
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 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
|
250 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
|
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 HELITAKEOFF: // Helicopter is moving to take off position. |
6020 | 253 if (afc->delta_z == 0) { |
254 return amdflag & AMED_HELI_RAISE ? | |
255 AMS_TTDP_HELI_TAKEOFF_AIRPORT : AMS_TTDP_TO_JUNCTION; | |
256 } else { | |
257 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
|
258 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
259 |
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 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
|
261 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
|
262 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
263 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
|
264 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
|
265 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
266 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
|
267 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
|
268 /* 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
|
269 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
|
270 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
271 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
|
272 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
|
273 if (amdflag & AMED_HELI_LOWER) { |
6020 | 274 return afc->delta_z == 0 ? |
275 AMS_TTDP_HELI_LAND_AIRPORT : AMS_TTDP_HELI_LAND_HELIPORT; | |
276 } else { | |
277 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
|
278 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
279 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
280 default: |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
281 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
|
282 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
283 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
284 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
285 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
286 /* 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
|
287 enum { |
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_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
|
289 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
|
290 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
|
291 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
|
292 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
|
293 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
|
294 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
|
295 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
|
296 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
|
297 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
|
298 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
|
299 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
|
300 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
|
301 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
|
302 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
|
303 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
|
304 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
|
305 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
|
306 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
|
307 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
308 |
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 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
311 * 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
|
312 * (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
|
313 * 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
|
314 */ |
11981
cf1aad9b971c
(svn r16387) -Codechange: use Aircraft instead of Vehicle where appropriate
rubidium <rubidium@openttd.org>
parents:
11924
diff
changeset
|
315 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
|
316 { |
11982
9add5306a01e
(svn r16388) -Codechange: move u.air to Aircraft
rubidium <rubidium@openttd.org>
parents:
11981
diff
changeset
|
317 switch (v->state) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
318 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
|
319 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
|
320 |
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 TERM1: |
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 HELIPAD1: |
8836
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8786
diff
changeset
|
323 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
|
324 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
325 case TERM2: |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
326 case HELIPAD2: |
8836
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8786
diff
changeset
|
327 return (v->current_order.IsType(OT_LOADING)) ? AMA_TTDP_ON_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
|
328 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
329 case TERM3: |
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 TERM4: |
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 TERM5: |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
332 case TERM6: |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
333 case TERM7: |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
334 case TERM8: |
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 HELIPAD3: |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
336 case HELIPAD4: |
8836
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8786
diff
changeset
|
337 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
|
338 |
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 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
|
340 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
|
341 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
|
342 case HELITAKEOFF: |
6348
bcf98ba27bbf
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents:
6259
diff
changeset
|
343 /* @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
|
344 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
|
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 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
|
347 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
|
348 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
349 case 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
|
350 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
|
351 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
|
352 case HELIENDLANDING: |
6348
bcf98ba27bbf
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents:
6259
diff
changeset
|
353 /* @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
|
354 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
|
355 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
|
356 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
357 default: |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
358 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
|
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 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
362 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
363 /* 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
|
364 enum { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
365 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
|
366 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
|
367 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
|
368 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
|
369 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
370 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
371 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
372 /* 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
|
373 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
|
374 { |
8756
ae0ec91bb55e
(svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx <glx@openttd.org>
parents:
8666
diff
changeset
|
375 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
|
376 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
|
377 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
|
378 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
|
379 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
|
380 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
|
381 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
|
382 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
|
383 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
|
384 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
|
385 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
|
386 break; |
ae0ec91bb55e
(svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx <glx@openttd.org>
parents:
8666
diff
changeset
|
387 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
|
388 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
|
389 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
|
390 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
|
391 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
|
392 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
|
393 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
|
394 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
|
395 } 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
|
396 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
|
397 } |
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
|
398 } |
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
|
399 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
|
400 } break; |
8756
ae0ec91bb55e
(svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx <glx@openttd.org>
parents:
8666
diff
changeset
|
401 } |
ae0ec91bb55e
(svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx <glx@openttd.org>
parents:
8666
diff
changeset
|
402 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
|
403 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
|
404 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
|
405 return v; |
ae0ec91bb55e
(svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx <glx@openttd.org>
parents:
8666
diff
changeset
|
406 } |
ae0ec91bb55e
(svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx <glx@openttd.org>
parents:
8666
diff
changeset
|
407 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
408 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
409 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
410 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
411 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
|
412 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
413 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
|
414 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
415 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
416 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
417 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
|
418 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
419 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
|
420 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
421 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
422 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
423 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
|
424 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
425 /* 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
|
426 * 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
|
427 * 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
|
428 */ |
12016
d45475f68f60
(svn r16422) -Codechange: use const_cast for removing const and warn when const is (accidentally?) removed using C-style casts.
rubidium <rubidium@openttd.org>
parents:
12015
diff
changeset
|
429 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
|
430 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
431 /* 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
|
432 * 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
|
433 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
|
434 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
435 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
|
436 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
437 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
438 |
6516
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6490
diff
changeset
|
439 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
|
440 { |
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6490
diff
changeset
|
441 const Livery *l; |
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 if (v == NULL) { |
11924
fccc9cea27a7
(svn r16327) -Codechange: replace IsValidPoolItemID(index) by PoolItem::IsValidID(index)
smatz <smatz@openttd.org>
parents:
11922
diff
changeset
|
444 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
|
445 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
|
446 } else if (v->type == VEH_TRAIN) { |
12114
f020ec6be498
(svn r16527) -Codechange: use static member functions instead of simple casts when converting Vehicle to specialised vehicle types. Includes safety check
smatz <smatz@openttd.org>
parents:
12073
diff
changeset
|
447 l = GetEngineLivery(v->engine_type, v->owner, Train::From(v)->tcache.first_engine, v); |
11167
2194f431a931
(svn r15517) -Fix [FS#2642](r6455): Wagonoverrides and articulated engine parts use the colour scheme of the engine, but not its recolour callback, nor its 2CC flag. Same applies to roadvehicles.
frosch <frosch@openttd.org>
parents:
11166
diff
changeset
|
448 } else if (v->type == VEH_ROAD) { |
12114
f020ec6be498
(svn r16527) -Codechange: use static member functions instead of simple casts when converting Vehicle to specialised vehicle types. Includes safety check
smatz <smatz@openttd.org>
parents:
12073
diff
changeset
|
449 l = GetEngineLivery(v->engine_type, v->owner, RoadVehicle::From(v)->rcache.first_engine, v); |
6516
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6490
diff
changeset
|
450 } else { |
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6490
diff
changeset
|
451 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
|
452 } |
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6490
diff
changeset
|
453 |
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6490
diff
changeset
|
454 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
|
455 } |
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6490
diff
changeset
|
456 |
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
|
457 /** |
e0ddd5124002
(svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents:
11189
diff
changeset
|
458 * 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
|
459 * @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
|
460 * @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
|
461 * 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
|
462 * @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
|
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 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
|
465 { |
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 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
|
467 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
|
468 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
|
469 |
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 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
|
471 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
|
472 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
|
473 } |
e0ddd5124002
(svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents:
11189
diff
changeset
|
474 |
e0ddd5124002
(svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents:
11189
diff
changeset
|
475 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
|
476 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
|
477 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
|
478 } |
e0ddd5124002
(svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents:
11189
diff
changeset
|
479 |
e0ddd5124002
(svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents:
11189
diff
changeset
|
480 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
|
481 } |
6516
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6490
diff
changeset
|
482 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
483 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
|
484 { |
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
|
485 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
|
486 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
487 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
|
488 /* 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
|
489 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
|
490 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
|
491 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
|
492 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
|
493 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
|
494 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
|
495 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
|
496 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
|
497 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
|
498 } else { |
c993bfe070b7
(svn r15542) -Feature(ette): Support vehicle vars 0x47 and 0xF2 in purchase list.
frosch <frosch@openttd.org>
parents:
11188
diff
changeset
|
499 return 0x000000FF; |
c993bfe070b7
(svn r15542) -Feature(ette): Support vehicle vars 0x47 and 0xF2 in purchase list.
frosch <frosch@openttd.org>
parents:
11188
diff
changeset
|
500 } |
c993bfe070b7
(svn r15542) -Feature(ette): Support vehicle vars 0x47 and 0xF2 in purchase list.
frosch <frosch@openttd.org>
parents:
11188
diff
changeset
|
501 } |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11875
diff
changeset
|
502 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
|
503 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
|
504 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
|
505 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
|
506 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
|
507 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
508 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
509 *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
|
510 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
|
511 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
512 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
513 /* 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
|
514 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
|
515 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
|
516 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
|
517 |
6348
bcf98ba27bbf
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents:
6259
diff
changeset
|
518 case 0x40: // Get length of consist |
11988
935e4f91c83c
(svn r16394) -Codechange: move (NewGRF) cache variables into a separate struct so (some vehicle related) NewGRF cache 'desyncs' can be tested easier.
rubidium <rubidium@openttd.org>
parents:
11987
diff
changeset
|
519 if (!HasBit(v->vcache.cache_valid, 0)) { |
935e4f91c83c
(svn r16394) -Codechange: move (NewGRF) cache variables into a separate struct so (some vehicle related) NewGRF cache 'desyncs' can be tested easier.
rubidium <rubidium@openttd.org>
parents:
11987
diff
changeset
|
520 v->vcache.cached_var40 = PositionHelper(v, false); |
935e4f91c83c
(svn r16394) -Codechange: move (NewGRF) cache variables into a separate struct so (some vehicle related) NewGRF cache 'desyncs' can be tested easier.
rubidium <rubidium@openttd.org>
parents:
11987
diff
changeset
|
521 SetBit(v->vcache.cache_valid, 0); |
11268
e0ddd5124002
(svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents:
11189
diff
changeset
|
522 } |
11988
935e4f91c83c
(svn r16394) -Codechange: move (NewGRF) cache variables into a separate struct so (some vehicle related) NewGRF cache 'desyncs' can be tested easier.
rubidium <rubidium@openttd.org>
parents:
11987
diff
changeset
|
523 return v->vcache.cached_var40; |
11268
e0ddd5124002
(svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents:
11189
diff
changeset
|
524 |
6348
bcf98ba27bbf
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents:
6259
diff
changeset
|
525 case 0x41: // Get length of same consecutive wagons |
11988
935e4f91c83c
(svn r16394) -Codechange: move (NewGRF) cache variables into a separate struct so (some vehicle related) NewGRF cache 'desyncs' can be tested easier.
rubidium <rubidium@openttd.org>
parents:
11987
diff
changeset
|
526 if (!HasBit(v->vcache.cache_valid, 1)) { |
935e4f91c83c
(svn r16394) -Codechange: move (NewGRF) cache variables into a separate struct so (some vehicle related) NewGRF cache 'desyncs' can be tested easier.
rubidium <rubidium@openttd.org>
parents:
11987
diff
changeset
|
527 v->vcache.cached_var41 = PositionHelper(v, true); |
935e4f91c83c
(svn r16394) -Codechange: move (NewGRF) cache variables into a separate struct so (some vehicle related) NewGRF cache 'desyncs' can be tested easier.
rubidium <rubidium@openttd.org>
parents:
11987
diff
changeset
|
528 SetBit(v->vcache.cache_valid, 1); |
11268
e0ddd5124002
(svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents:
11189
diff
changeset
|
529 } |
11988
935e4f91c83c
(svn r16394) -Codechange: move (NewGRF) cache variables into a separate struct so (some vehicle related) NewGRF cache 'desyncs' can be tested easier.
rubidium <rubidium@openttd.org>
parents:
11987
diff
changeset
|
530 return v->vcache.cached_var41; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
531 |
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
|
532 case 0x42: // Consist cargo information |
11988
935e4f91c83c
(svn r16394) -Codechange: move (NewGRF) cache variables into a separate struct so (some vehicle related) NewGRF cache 'desyncs' can be tested easier.
rubidium <rubidium@openttd.org>
parents:
11987
diff
changeset
|
533 if (!HasBit(v->vcache.cache_valid, 2)) { |
11268
e0ddd5124002
(svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents:
11189
diff
changeset
|
534 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
|
535 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
|
536 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
|
537 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
|
538 byte user_def_data = 0; |
12071
a50b1fcac71b
(svn r16478) -Fix (r15378): Determining most common (sub-)cargo-type was broken due to someone confusing similiary named variables.
frosch <frosch@openttd.org>
parents:
12016
diff
changeset
|
539 CargoID common_cargo_type = CT_INVALID; |
a50b1fcac71b
(svn r16478) -Fix (r15378): Determining most common (sub-)cargo-type was broken due to someone confusing similiary named variables.
frosch <frosch@openttd.org>
parents:
12016
diff
changeset
|
540 uint8 common_subtype = 0xFF; // Return 0xFF if nothing is carried |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
541 |
11268
e0ddd5124002
(svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents:
11189
diff
changeset
|
542 /* 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
|
543 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
|
544 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
|
545 |
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
|
546 for (u = v; u != NULL; u = u->Next()) { |
12114
f020ec6be498
(svn r16527) -Codechange: use static member functions instead of simple casts when converting Vehicle to specialised vehicle types. Includes safety check
smatz <smatz@openttd.org>
parents:
12073
diff
changeset
|
547 if (v->type == VEH_TRAIN) user_def_data |= Train::From(u)->tcache.user_def_data; |
11268
e0ddd5124002
(svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents:
11189
diff
changeset
|
548 |
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 /* 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
|
550 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
|
551 |
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 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
|
553 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
|
554 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
555 |
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
|
556 /* Pick the most common cargo type */ |
12071
a50b1fcac71b
(svn r16478) -Fix (r15378): Determining most common (sub-)cargo-type was broken due to someone confusing similiary named variables.
frosch <frosch@openttd.org>
parents:
12016
diff
changeset
|
557 uint common_cargo_best_amount = 0; |
11268
e0ddd5124002
(svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents:
11189
diff
changeset
|
558 for (CargoID cargo = 0; cargo < NUM_CARGO; cargo++) { |
12071
a50b1fcac71b
(svn r16478) -Fix (r15378): Determining most common (sub-)cargo-type was broken due to someone confusing similiary named variables.
frosch <frosch@openttd.org>
parents:
12016
diff
changeset
|
559 if (common_cargos[cargo] > common_cargo_best_amount) { |
a50b1fcac71b
(svn r16478) -Fix (r15378): Determining most common (sub-)cargo-type was broken due to someone confusing similiary named variables.
frosch <frosch@openttd.org>
parents:
12016
diff
changeset
|
560 common_cargo_best_amount = common_cargos[cargo]; |
11268
e0ddd5124002
(svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents:
11189
diff
changeset
|
561 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
|
562 } |
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 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
564 |
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
|
565 /* 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
|
566 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
|
567 /* 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
|
568 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
|
569 |
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
|
570 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
|
571 } |
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
|
572 |
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
|
573 /* Pick the most common subcargo type*/ |
12071
a50b1fcac71b
(svn r16478) -Fix (r15378): Determining most common (sub-)cargo-type was broken due to someone confusing similiary named variables.
frosch <frosch@openttd.org>
parents:
12016
diff
changeset
|
574 uint common_subtype_best_amount = 0; |
11268
e0ddd5124002
(svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents:
11189
diff
changeset
|
575 for (uint i = 0; i < lengthof(common_subtypes); i++) { |
12071
a50b1fcac71b
(svn r16478) -Fix (r15378): Determining most common (sub-)cargo-type was broken due to someone confusing similiary named variables.
frosch <frosch@openttd.org>
parents:
12016
diff
changeset
|
576 if (common_subtypes[i] > common_subtype_best_amount) { |
a50b1fcac71b
(svn r16478) -Fix (r15378): Determining most common (sub-)cargo-type was broken due to someone confusing similiary named variables.
frosch <frosch@openttd.org>
parents:
12016
diff
changeset
|
577 common_subtype_best_amount = common_subtypes[i]; |
11268
e0ddd5124002
(svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents:
11189
diff
changeset
|
578 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
|
579 } |
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 } |
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
|
581 |
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
|
582 uint8 common_bitnum = (common_cargo_type == CT_INVALID ? 0xFF : GetCargo(common_cargo_type)->bitnum); |
11988
935e4f91c83c
(svn r16394) -Codechange: move (NewGRF) cache variables into a separate struct so (some vehicle related) NewGRF cache 'desyncs' can be tested easier.
rubidium <rubidium@openttd.org>
parents:
11987
diff
changeset
|
583 v->vcache.cached_var42 = cargo_classes | (common_bitnum << 8) | (common_subtype << 16) | (user_def_data << 24); |
935e4f91c83c
(svn r16394) -Codechange: move (NewGRF) cache variables into a separate struct so (some vehicle related) NewGRF cache 'desyncs' can be tested easier.
rubidium <rubidium@openttd.org>
parents:
11987
diff
changeset
|
584 SetBit(v->vcache.cache_valid, 2); |
6822
08fc353e6a6b
(svn r10061) -Codechange: [NewGRF] Add common cargo subtype support to vehicle var 42
peter1138 <peter1138@openttd.org>
parents:
6621
diff
changeset
|
585 } |
11988
935e4f91c83c
(svn r16394) -Codechange: move (NewGRF) cache variables into a separate struct so (some vehicle related) NewGRF cache 'desyncs' can be tested easier.
rubidium <rubidium@openttd.org>
parents:
11987
diff
changeset
|
586 return v->vcache.cached_var42; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
587 |
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
|
588 case 0x43: // Company information |
11988
935e4f91c83c
(svn r16394) -Codechange: move (NewGRF) cache variables into a separate struct so (some vehicle related) NewGRF cache 'desyncs' can be tested easier.
rubidium <rubidium@openttd.org>
parents:
11987
diff
changeset
|
589 if (!HasBit(v->vcache.cache_valid, 3)) { |
12220
8c5b158f0d40
(svn r16634) -Codechange: use Company::IsHumanID() instead of IsHumanCompany()
smatz <smatz@openttd.org>
parents:
12201
diff
changeset
|
590 v->vcache.cached_var43 = v->owner | (Company::IsHumanID(v->owner) ? 0 : 0x10000) | (LiveryHelper(v->engine_type, v) << 24); |
11988
935e4f91c83c
(svn r16394) -Codechange: move (NewGRF) cache variables into a separate struct so (some vehicle related) NewGRF cache 'desyncs' can be tested easier.
rubidium <rubidium@openttd.org>
parents:
11987
diff
changeset
|
591 SetBit(v->vcache.cache_valid, 3); |
11268
e0ddd5124002
(svn r15617) -Change [FS#2694]: vehicle variables 40-43 weren't cached (though spec stated they are). Caching these variables can yield a 10+% speed increase when those vehicle variables are queried often.
rubidium <rubidium@openttd.org>
parents:
11189
diff
changeset
|
592 } |
11988
935e4f91c83c
(svn r16394) -Codechange: move (NewGRF) cache variables into a separate struct so (some vehicle related) NewGRF cache 'desyncs' can be tested easier.
rubidium <rubidium@openttd.org>
parents:
11987
diff
changeset
|
593 return v->vcache.cached_var43; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
594 |
6348
bcf98ba27bbf
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents:
6259
diff
changeset
|
595 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
|
596 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
|
597 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
598 { |
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
|
599 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
|
600 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
|
601 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
|
602 |
12114
f020ec6be498
(svn r16527) -Codechange: use static member functions instead of simple casts when converting Vehicle to specialised vehicle types. Includes safety check
smatz <smatz@openttd.org>
parents:
12073
diff
changeset
|
603 const Station *st = GetTargetAirportIfValid(Aircraft::From(v)); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
604 |
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
|
605 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
|
606 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
|
607 /* 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
|
608 * 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
|
609 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
|
610 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
|
611 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
|
612 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
|
613 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
|
614 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
|
615 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
|
616 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
|
617 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
|
618 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
|
619 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
|
620 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
621 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
622 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
623 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
|
624 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
625 |
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
|
626 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
|
627 /* 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
|
628 * 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
|
629 * 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
|
630 * 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
|
631 */ |
10643
9c1b0524a8a1
(svn r14945) -Feature(ette): Support var 0x45 (curvature info) also for road vehicles.
frosch <frosch@openttd.org>
parents:
10544
diff
changeset
|
632 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
|
633 |
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
|
634 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
|
635 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
|
636 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
|
637 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
|
638 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
|
639 |
3c89f72535f3
(svn r9803) -Feature(tte): support for "curvature info", Action 2 for train, variable 45 (mart3p).
rubidium <rubidium@openttd.org>
parents:
6517
diff
changeset
|
640 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
|
641 ((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
|
642 ( 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
|
643 } |
3c89f72535f3
(svn r9803) -Feature(tte): support for "curvature info", Action 2 for train, variable 45 (mart3p).
rubidium <rubidium@openttd.org>
parents:
6517
diff
changeset
|
644 |
6348
bcf98ba27bbf
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents:
6259
diff
changeset
|
645 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
|
646 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
|
647 |
6348
bcf98ba27bbf
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents:
6259
diff
changeset
|
648 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
|
649 /* 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
|
650 * 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
|
651 * 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
|
652 * 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
|
653 * 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
|
654 */ |
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
|
655 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
|
656 |
6147
a7aecaae3414
(svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138 <peter1138@openttd.org>
parents:
6126
diff
changeset
|
657 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
|
658 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
659 |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11875
diff
changeset
|
660 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
|
661 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
|
662 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
663 /* 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
|
664 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
|
665 //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
|
666 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
|
667 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
668 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
669 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
|
670 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
|
671 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
|
672 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
673 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
|
674 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
675 |
6176
863c86137fc1
(svn r8946) -Feature: [NewGRF] Add support for vehicle variables 0xFE and 0xFF bit 10,
maedhros <maedhros@openttd.org>
parents:
6173
diff
changeset
|
676 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
|
677 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
|
678 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
|
679 |
8665
5e82cdbe1cc1
(svn r12330) -Feature: [NewGRF] vehicle variable FE bit 5 and 6
glx <glx@openttd.org>
parents:
8654
diff
changeset
|
680 if (v->type == VEH_TRAIN) { |
12114
f020ec6be498
(svn r16527) -Codechange: use static member functions instead of simple casts when converting Vehicle to specialised vehicle types. Includes safety check
smatz <smatz@openttd.org>
parents:
12073
diff
changeset
|
681 const Train *t = Train::From(v); |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11984
diff
changeset
|
682 const Train *u = IsTrainWagon(v) && HasBit(v->vehicle_flags, VRF_POWEREDWAGON) ? t->First() : t; |
8665
5e82cdbe1cc1
(svn r12330) -Feature: [NewGRF] vehicle variable FE bit 5 and 6
glx <glx@openttd.org>
parents:
8654
diff
changeset
|
683 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
|
684 bool powered = IsTrainEngine(v) || (IsTrainWagon(v) && HasBit(v->vehicle_flags, VRF_POWEREDWAGON)); |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
685 bool has_power = powered && HasPowerOnRail(u->railtype, railtype); |
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
686 bool is_electric = powered && u->railtype == RAILTYPE_ELECTRIC; |
8666
ae052ccde3db
(svn r12331) -Feature: [NewGRF] vehicle variable FE bit 8
glx <glx@openttd.org>
parents:
8665
diff
changeset
|
687 |
8665
5e82cdbe1cc1
(svn r12330) -Feature: [NewGRF] vehicle variable FE bit 5 and 6
glx <glx@openttd.org>
parents:
8654
diff
changeset
|
688 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
|
689 if (is_electric && !has_power) SetBit(modflags, 6); |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
690 if (HasBit(t->flags, VRF_TOGGLE_REVERSE)) SetBit(modflags, 8); |
8665
5e82cdbe1cc1
(svn r12330) -Feature: [NewGRF] vehicle variable FE bit 5 and 6
glx <glx@openttd.org>
parents:
8654
diff
changeset
|
691 } |
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
|
692 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
|
693 |
863c86137fc1
(svn r8946) -Feature: [NewGRF] Add support for vehicle variables 0xFE and 0xFF bit 10,
maedhros <maedhros@openttd.org>
parents:
6173
diff
changeset
|
694 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
|
695 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
696 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
697 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
698 /* 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
|
699 switch (variable - 0x80) { |
12201
b28426ff9e8c
(svn r16615) -Fix (r16613): 0x10 != 2
yexo <yexo@openttd.org>
parents:
12199
diff
changeset
|
700 case 0x00: return v->type + 0x10; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
701 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
|
702 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
|
703 case 0x05: return GB(v->index, 8, 8); |
12199
8e20cb543b87
(svn r16613) -Fix [NewGRF]: some of the var action 2 80+ variables contained wrong results due to OpenTTD codechanges
yexo <yexo@openttd.org>
parents:
12114
diff
changeset
|
704 case 0x0A: return v->current_order.MapOldOrder(); |
8e20cb543b87
(svn r16613) -Fix [NewGRF]: some of the var action 2 80+ variables contained wrong results due to OpenTTD codechanges
yexo <yexo@openttd.org>
parents:
12114
diff
changeset
|
705 case 0x0B: return v->current_order.GetDestination(); |
10544
836dfaca2a32
(svn r14801) -Codechange: don't reference Vehicle::num_orders directly but through a method GetNumOrders() (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10519
diff
changeset
|
706 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
|
707 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
|
708 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
|
709 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
|
710 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
|
711 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
|
712 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
|
713 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
|
714 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
|
715 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
|
716 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
|
717 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
|
718 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
|
719 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
|
720 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
|
721 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
|
722 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
|
723 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
|
724 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
|
725 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
|
726 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
|
727 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
|
728 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
|
729 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
|
730 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
|
731 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
|
732 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
|
733 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
|
734 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
|
735 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
|
736 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
|
737 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
|
738 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
|
739 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
|
740 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
|
741 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
|
742 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
|
743 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
|
744 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
|
745 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
|
746 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
|
747 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
|
748 if (v->type != VEH_TRAIN || v->spritenum != 0xFD) return v->spritenum; |
12114
f020ec6be498
(svn r16527) -Codechange: use static member functions instead of simple casts when converting Vehicle to specialised vehicle types. Includes safety check
smatz <smatz@openttd.org>
parents:
12073
diff
changeset
|
749 return HasBit(Train::From(v)->flags, VRF_REVERSE_DIRECTION) ? 0xFE : 0xFD; |
9059
323c3edf9c0d
(svn r12910) -Fix: Report reverse sprite status (FD/FE) to NewGRF for manually toggled vehicles.
peter1138 <peter1138@openttd.org>
parents:
9046
diff
changeset
|
750 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
751 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
|
752 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
|
753 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
|
754 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
|
755 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
|
756 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
|
757 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
|
758 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
|
759 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
|
760 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
|
761 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
|
762 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
|
763 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
|
764 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
|
765 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
|
766 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
|
767 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
|
768 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
|
769 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
|
770 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
|
771 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
|
772 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
|
773 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
|
774 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
|
775 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
|
776 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
777 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
778 /* 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
|
779 switch (v->type) { |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11984
diff
changeset
|
780 case VEH_TRAIN: { |
12114
f020ec6be498
(svn r16527) -Codechange: use static member functions instead of simple casts when converting Vehicle to specialised vehicle types. Includes safety check
smatz <smatz@openttd.org>
parents:
12073
diff
changeset
|
781 Train *t = Train::From(v); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
782 switch (variable - 0x80) { |
11986
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
783 case 0x62: return t->track; |
78abb48a4fba
(svn r16392) -Codechange: move some variables (the ones that aren't caches) from VehicleRail to Train
rubidium <rubidium@openttd.org>
parents:
11985
diff
changeset
|
784 case 0x66: return t->railtype; |
11987
81554d4e6d76
(svn r16393) -Codechange: move VehicleRail to Train.
rubidium <rubidium@openttd.org>
parents:
11986
diff
changeset
|
785 case 0x73: return t->tcache.cached_veh_length; |
81554d4e6d76
(svn r16393) -Codechange: move VehicleRail to Train.
rubidium <rubidium@openttd.org>
parents:
11986
diff
changeset
|
786 case 0x74: return t->tcache.cached_power; |
81554d4e6d76
(svn r16393) -Codechange: move VehicleRail to Train.
rubidium <rubidium@openttd.org>
parents:
11986
diff
changeset
|
787 case 0x75: return GB(t->tcache.cached_power, 8, 24); |
81554d4e6d76
(svn r16393) -Codechange: move VehicleRail to Train.
rubidium <rubidium@openttd.org>
parents:
11986
diff
changeset
|
788 case 0x76: return GB(t->tcache.cached_power, 16, 16); |
81554d4e6d76
(svn r16393) -Codechange: move VehicleRail to Train.
rubidium <rubidium@openttd.org>
parents:
11986
diff
changeset
|
789 case 0x77: return GB(t->tcache.cached_power, 24, 8); |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11984
diff
changeset
|
790 case 0x7C: return t->First()->index; |
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11984
diff
changeset
|
791 case 0x7D: return GB(t->First()->index, 8, 8); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
792 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
|
793 } |
11985
e05790b0a6c6
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
rubidium <rubidium@openttd.org>
parents:
11984
diff
changeset
|
794 } 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
|
795 |
11984
b6d3e583be86
(svn r16390) -Codechange: move u.road to RoadVehicle.
rubidium <rubidium@openttd.org>
parents:
11982
diff
changeset
|
796 case VEH_ROAD: { |
12114
f020ec6be498
(svn r16527) -Codechange: use static member functions instead of simple casts when converting Vehicle to specialised vehicle types. Includes safety check
smatz <smatz@openttd.org>
parents:
12073
diff
changeset
|
797 RoadVehicle *rv = RoadVehicle::From(v); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
798 switch (variable - 0x80) { |
11984
b6d3e583be86
(svn r16390) -Codechange: move u.road to RoadVehicle.
rubidium <rubidium@openttd.org>
parents:
11982
diff
changeset
|
799 case 0x62: return rv->state; |
b6d3e583be86
(svn r16390) -Codechange: move u.road to RoadVehicle.
rubidium <rubidium@openttd.org>
parents:
11982
diff
changeset
|
800 case 0x64: return rv->blocked_ctr; |
b6d3e583be86
(svn r16390) -Codechange: move u.road to RoadVehicle.
rubidium <rubidium@openttd.org>
parents:
11982
diff
changeset
|
801 case 0x65: return GB(rv->blocked_ctr, 8, 8); |
b6d3e583be86
(svn r16390) -Codechange: move u.road to RoadVehicle.
rubidium <rubidium@openttd.org>
parents:
11982
diff
changeset
|
802 case 0x66: return rv->overtaking; |
b6d3e583be86
(svn r16390) -Codechange: move u.road to RoadVehicle.
rubidium <rubidium@openttd.org>
parents:
11982
diff
changeset
|
803 case 0x67: return rv->overtaking_ctr; |
b6d3e583be86
(svn r16390) -Codechange: move u.road to RoadVehicle.
rubidium <rubidium@openttd.org>
parents:
11982
diff
changeset
|
804 case 0x68: return rv->crashed_ctr; |
b6d3e583be86
(svn r16390) -Codechange: move u.road to RoadVehicle.
rubidium <rubidium@openttd.org>
parents:
11982
diff
changeset
|
805 case 0x69: return GB(rv->crashed_ctr, 8, 8); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
806 } |
11984
b6d3e583be86
(svn r16390) -Codechange: move u.road to RoadVehicle.
rubidium <rubidium@openttd.org>
parents:
11982
diff
changeset
|
807 } 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
|
808 |
11981
cf1aad9b971c
(svn r16387) -Codechange: use Aircraft instead of Vehicle where appropriate
rubidium <rubidium@openttd.org>
parents:
11924
diff
changeset
|
809 case VEH_AIRCRAFT: { |
12114
f020ec6be498
(svn r16527) -Codechange: use static member functions instead of simple casts when converting Vehicle to specialised vehicle types. Includes safety check
smatz <smatz@openttd.org>
parents:
12073
diff
changeset
|
810 Aircraft *a = Aircraft::From(v); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
811 switch (variable - 0x80) { |
11981
cf1aad9b971c
(svn r16387) -Codechange: use Aircraft instead of Vehicle where appropriate
rubidium <rubidium@openttd.org>
parents:
11924
diff
changeset
|
812 case 0x62: return MapAircraftMovementState(a); // Current movement state |
11982
9add5306a01e
(svn r16388) -Codechange: move u.air to Aircraft
rubidium <rubidium@openttd.org>
parents:
11981
diff
changeset
|
813 case 0x63: return a->targetairport; // Airport to which the action refers |
11981
cf1aad9b971c
(svn r16387) -Codechange: use Aircraft instead of Vehicle where appropriate
rubidium <rubidium@openttd.org>
parents:
11924
diff
changeset
|
814 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
|
815 } |
11981
cf1aad9b971c
(svn r16387) -Codechange: use Aircraft instead of Vehicle where appropriate
rubidium <rubidium@openttd.org>
parents:
11924
diff
changeset
|
816 } break; |
6621
c751437b3bac
(svn r9841) -Codechange: add a little more type strictness to the vehicle types.
rubidium <rubidium@openttd.org>
parents:
6604
diff
changeset
|
817 |
c751437b3bac
(svn r9841) -Codechange: add a little more type strictness to the vehicle types.
rubidium <rubidium@openttd.org>
parents:
6604
diff
changeset
|
818 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
|
819 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
820 |
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
|
821 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
|
822 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
823 *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
|
824 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
|
825 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
826 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
827 |
11990
db0e49f419d9
(svn r16396) -Codechange: split NewGRF spritegroup into multiple subclasses instead of using a big union
rubidium <rubidium@openttd.org>
parents:
11988
diff
changeset
|
828 static const SpriteGroup *VehicleResolveReal(const ResolverObject *object, const RealSpriteGroup *group) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
829 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
830 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
|
831 |
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
|
832 if (v == NULL) { |
11990
db0e49f419d9
(svn r16396) -Codechange: split NewGRF spritegroup into multiple subclasses instead of using a big union
rubidium <rubidium@openttd.org>
parents:
11988
diff
changeset
|
833 if (group->num_loading > 0) return group->loading[0]; |
db0e49f419d9
(svn r16396) -Codechange: split NewGRF spritegroup into multiple subclasses instead of using a big union
rubidium <rubidium@openttd.org>
parents:
11988
diff
changeset
|
834 if (group->num_loaded > 0) return group->loaded[0]; |
8599
8d23ba9f619f
(svn r12180) -Fix: Test purchase list loading/loaded sprites instead of unconditionally returning a possibly non-existant sprite.
peter1138 <peter1138@openttd.org>
parents:
8556
diff
changeset
|
835 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
|
836 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
837 |
8836
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8786
diff
changeset
|
838 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
|
839 |
11990
db0e49f419d9
(svn r16396) -Codechange: split NewGRF spritegroup into multiple subclasses instead of using a big union
rubidium <rubidium@openttd.org>
parents:
11988
diff
changeset
|
840 uint totalsets = in_motion ? group->num_loaded : group->num_loading; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
841 |
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
|
842 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
|
843 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
|
844 |
11990
db0e49f419d9
(svn r16396) -Codechange: split NewGRF spritegroup into multiple subclasses instead of using a big union
rubidium <rubidium@openttd.org>
parents:
11988
diff
changeset
|
845 return in_motion ? group->loaded[set] : group->loading[set]; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
846 } |
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 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
849 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
|
850 { |
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->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
|
852 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
|
853 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
|
854 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
|
855 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
|
856 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
857 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
|
858 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
|
859 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
860 res->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
|
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 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
|
863 |
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
|
864 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
|
865 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
|
866 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
|
867 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
|
868 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
|
869 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
|
870 res->count = 0; |
9750
0654bf387d06
(svn r13885) -Fix [FS#2168]: Var 0x7F is not feature-specific.
frosch <frosch@openttd.org>
parents:
9672
diff
changeset
|
871 |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11875
diff
changeset
|
872 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
|
873 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
|
874 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
875 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
876 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
877 /** 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
|
878 * 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
|
879 * 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
|
880 * @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
|
881 * @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
|
882 * @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
|
883 * @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
|
884 */ |
7863
ea337dd0527c
(svn r11413) -Fix [FS#1405]: don't use cached override spriteset for callbacks
glx <glx@openttd.org>
parents:
7861
diff
changeset
|
885 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
|
886 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
887 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
|
888 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
|
889 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
890 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
|
891 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
|
892 } 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
|
893 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
|
894 |
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
|
895 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
|
896 /* 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
|
897 * 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
|
898 * as v->cargo_type is temporary changed to the new type */ |
12114
f020ec6be498
(svn r16527) -Codechange: use static member functions instead of simple casts when converting Vehicle to specialised vehicle types. Includes safety check
smatz <smatz@openttd.org>
parents:
12073
diff
changeset
|
899 group = use_cache ? Train::From(v)->tcache.cached_override : GetWagonOverrideSpriteSet(v->engine_type, v->cargo_type, Train::From(v)->tcache.first_engine); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
900 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
|
901 } else if (v->type == VEH_ROAD) { |
12114
f020ec6be498
(svn r16527) -Codechange: use static member functions instead of simple casts when converting Vehicle to specialised vehicle types. Includes safety check
smatz <smatz@openttd.org>
parents:
12073
diff
changeset
|
902 group = GetWagonOverrideSpriteSet(v->engine_type, v->cargo_type, RoadVehicle::From(v)->rcache.first_engine); |
11166
504cd363813f
(svn r15516) -Fix (r10097): Livery overrides for articulated parts of roadvehicles were not applied.
frosch <frosch@openttd.org>
parents:
11059
diff
changeset
|
903 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
|
904 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
905 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
906 |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11875
diff
changeset
|
907 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
|
908 |
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
|
909 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
|
910 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
|
911 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
|
912 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
913 /* 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
|
914 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
|
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 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
918 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
|
919 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
920 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
|
921 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
|
922 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
923 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
|
924 |
11996
b43cf6c7ea61
(svn r16402) -Codechange: make Resolve a function of SpriteGroup
rubidium <rubidium@openttd.org>
parents:
11990
diff
changeset
|
925 group = SpriteGroup::Resolve(GetVehicleSpriteGroup(engine, v), &object); |
11990
db0e49f419d9
(svn r16396) -Codechange: split NewGRF spritegroup into multiple subclasses instead of using a big union
rubidium <rubidium@openttd.org>
parents:
11988
diff
changeset
|
926 if (group == NULL || group->GetNumResults() == 0) return 0; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
927 |
11990
db0e49f419d9
(svn r16396) -Codechange: split NewGRF spritegroup into multiple subclasses instead of using a big union
rubidium <rubidium@openttd.org>
parents:
11988
diff
changeset
|
928 return group->GetResult() + (direction % group->GetNumResults()); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
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 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
931 |
11981
cf1aad9b971c
(svn r16387) -Codechange: use Aircraft instead of Vehicle where appropriate
rubidium <rubidium@openttd.org>
parents:
11924
diff
changeset
|
932 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
|
933 { |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11875
diff
changeset
|
934 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
|
935 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
936 /* 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
|
937 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
|
938 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
|
939 |
9436
b3969ef775ba
(svn r13351) -Codechange: disable warnings about unused variable for builds without asserts
smatz <smatz@openttd.org>
parents:
9413
diff
changeset
|
940 ResolverObject object; |
b3969ef775ba
(svn r13351) -Codechange: disable warnings about unused variable for builds without asserts
smatz <smatz@openttd.org>
parents:
9413
diff
changeset
|
941 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
942 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
|
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 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
|
945 |
9436
b3969ef775ba
(svn r13351) -Codechange: disable warnings about unused variable for builds without asserts
smatz <smatz@openttd.org>
parents:
9413
diff
changeset
|
946 const SpriteGroup *group = GetWagonOverrideSpriteSet(engine, CT_DEFAULT, engine); |
11996
b43cf6c7ea61
(svn r16402) -Codechange: make Resolve a function of SpriteGroup
rubidium <rubidium@openttd.org>
parents:
11990
diff
changeset
|
947 group = SpriteGroup::Resolve(group, &object); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
948 |
11990
db0e49f419d9
(svn r16396) -Codechange: split NewGRF spritegroup into multiple subclasses instead of using a big union
rubidium <rubidium@openttd.org>
parents:
11988
diff
changeset
|
949 if (group == NULL || group->GetNumResults() == 0) return 0; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
950 |
11990
db0e49f419d9
(svn r16396) -Codechange: split NewGRF spritegroup into multiple subclasses instead of using a big union
rubidium <rubidium@openttd.org>
parents:
11988
diff
changeset
|
951 if (v == NULL) return group->GetResult(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
952 |
11990
db0e49f419d9
(svn r16396) -Codechange: split NewGRF spritegroup into multiple subclasses instead of using a big union
rubidium <rubidium@openttd.org>
parents:
11988
diff
changeset
|
953 return group->GetResult() + (info_view ? 0 : (v->Next()->Next()->state % group->GetNumResults())); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
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 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
956 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
957 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
958 * 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
|
959 * @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
|
960 * @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
|
961 */ |
10647
592ae9307430
(svn r14949) -Cleanup: pointer coding style
rubidium <rubidium@openttd.org>
parents:
10643
diff
changeset
|
962 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
|
963 { |
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
|
964 assert(v->type == VEH_TRAIN); |
12114
f020ec6be498
(svn r16527) -Codechange: use static member functions instead of simple casts when converting Vehicle to specialised vehicle types. Includes safety check
smatz <smatz@openttd.org>
parents:
12073
diff
changeset
|
965 return Train::From(v)->tcache.cached_override != NULL; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
966 } |
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 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
969 * 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
|
970 * @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
|
971 * @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
|
972 * @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
|
973 * @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
|
974 * @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
|
975 * @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
|
976 */ |
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
|
977 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
|
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 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
|
980 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
|
981 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
982 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
|
983 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
984 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
|
985 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
|
986 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
|
987 |
11996
b43cf6c7ea61
(svn r16402) -Codechange: make Resolve a function of SpriteGroup
rubidium <rubidium@openttd.org>
parents:
11990
diff
changeset
|
988 group = SpriteGroup::Resolve(GetVehicleSpriteGroup(engine, v, false), &object); |
11990
db0e49f419d9
(svn r16396) -Codechange: split NewGRF spritegroup into multiple subclasses instead of using a big union
rubidium <rubidium@openttd.org>
parents:
11988
diff
changeset
|
989 if (group == NULL) return CALLBACK_FAILED; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
990 |
11990
db0e49f419d9
(svn r16396) -Codechange: split NewGRF spritegroup into multiple subclasses instead of using a big union
rubidium <rubidium@openttd.org>
parents:
11988
diff
changeset
|
991 return group->GetCallbackResult(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
992 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
993 |
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 * 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
|
996 * @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
|
997 * @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
|
998 * @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
|
999 * @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
|
1000 * @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
|
1001 * @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
|
1002 * @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
|
1003 */ |
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
|
1004 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
|
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 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
|
1007 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
|
1008 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1009 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
|
1010 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1011 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
|
1012 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
|
1013 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
|
1014 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1015 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
|
1016 |
11996
b43cf6c7ea61
(svn r16402) -Codechange: make Resolve a function of SpriteGroup
rubidium <rubidium@openttd.org>
parents:
11990
diff
changeset
|
1017 group = SpriteGroup::Resolve(GetVehicleSpriteGroup(engine, v, false), &object); |
11990
db0e49f419d9
(svn r16396) -Codechange: split NewGRF spritegroup into multiple subclasses instead of using a big union
rubidium <rubidium@openttd.org>
parents:
11988
diff
changeset
|
1018 if (group == NULL) return CALLBACK_FAILED; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1019 |
11990
db0e49f419d9
(svn r16396) -Codechange: split NewGRF spritegroup into multiple subclasses instead of using a big union
rubidium <rubidium@openttd.org>
parents:
11988
diff
changeset
|
1020 return group->GetCallbackResult(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1021 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1022 |
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
|
1023 |
6517
bfa6449a2b3a
(svn r9703) -Codechange: support callback 36 in vehicle purchase lists
peter1138 <peter1138@openttd.org>
parents:
6516
diff
changeset
|
1024 /* 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
|
1025 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
|
1026 { |
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
|
1027 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
|
1028 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
|
1029 |
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
|
1030 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
|
1031 } |
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
|
1032 |
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
|
1033 |
6517
bfa6449a2b3a
(svn r9703) -Codechange: support callback 36 in vehicle purchase lists
peter1138 <peter1138@openttd.org>
parents:
6516
diff
changeset
|
1034 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
|
1035 { |
bfa6449a2b3a
(svn r9703) -Codechange: support callback 36 in vehicle purchase lists
peter1138 <peter1138@openttd.org>
parents:
6516
diff
changeset
|
1036 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
|
1037 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
|
1038 |
bfa6449a2b3a
(svn r9703) -Codechange: support callback 36 in vehicle purchase lists
peter1138 <peter1138@openttd.org>
parents:
6516
diff
changeset
|
1039 return orig_value; |
bfa6449a2b3a
(svn r9703) -Codechange: support callback 36 in vehicle purchase lists
peter1138 <peter1138@openttd.org>
parents:
6516
diff
changeset
|
1040 } |
bfa6449a2b3a
(svn r9703) -Codechange: support callback 36 in vehicle purchase lists
peter1138 <peter1138@openttd.org>
parents:
6516
diff
changeset
|
1041 |
bfa6449a2b3a
(svn r9703) -Codechange: support callback 36 in vehicle purchase lists
peter1138 <peter1138@openttd.org>
parents:
6516
diff
changeset
|
1042 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1043 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
|
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 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
|
1046 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
|
1047 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
|
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 /* 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
|
1050 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
|
1051 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1052 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
|
1053 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
|
1054 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
|
1055 |
11996
b43cf6c7ea61
(svn r16402) -Codechange: make Resolve a function of SpriteGroup
rubidium <rubidium@openttd.org>
parents:
11990
diff
changeset
|
1056 group = SpriteGroup::Resolve(GetVehicleSpriteGroup(v->engine_type, v), &object); |
7861
6986bc3b90e4
(svn r11411) -Codechange: implement random triggers for houses.
rubidium <rubidium@openttd.org>
parents:
7803
diff
changeset
|
1057 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
|
1058 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1059 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
|
1060 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
|
1061 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
|
1062 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1063 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
|
1064 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
|
1065 /* 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
|
1066 * 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
|
1067 * 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
|
1068 * 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
|
1069 * 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
|
1070 * 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
|
1071 * 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
|
1072 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
|
1073 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
|
1074 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1075 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1076 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
|
1077 /* 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
|
1078 * 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
|
1079 * 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
|
1080 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
|
1081 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1082 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1083 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
|
1084 /* 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
|
1085 * 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
|
1086 * 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
|
1087 * 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
|
1088 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
|
1089 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1090 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1091 case VEHICLE_TRIGGER_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
|
1092 /* 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
|
1093 * 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
|
1094 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
|
1095 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
|
1096 break; |
7803
1ad76d7d65b8
(svn r11353) -Codechange: add support for newgrf callback 32
glx <glx@openttd.org>
parents:
7550
diff
changeset
|
1097 |
1ad76d7d65b8
(svn r11353) -Codechange: add support for newgrf callback 32
glx <glx@openttd.org>
parents:
7550
diff
changeset
|
1098 case VEHICLE_TRIGGER_CALLBACK_32: |
1ad76d7d65b8
(svn r11353) -Codechange: add support for newgrf callback 32
glx <glx@openttd.org>
parents:
7550
diff
changeset
|
1099 /* Do not do any recursion */ |
1ad76d7d65b8
(svn r11353) -Codechange: add support for newgrf callback 32
glx <glx@openttd.org>
parents:
7550
diff
changeset
|
1100 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
|
1101 } |
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 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
|
1105 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1106 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
|
1107 /* 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
|
1108 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
|
1109 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1110 |
12073
02d3a628e6db
(svn r16480) -Fix (r15617): Invalidate newgrf variable caches of more vehicles in more places. Esp. they were only invalidated for trains.
frosch <frosch@openttd.org>
parents:
12071
diff
changeset
|
1111 v->InvalidateNewGRFCacheOfChain(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1112 DoTriggerVehicle(v, trigger, 0, true); |
12073
02d3a628e6db
(svn r16480) -Fix (r15617): Invalidate newgrf variable caches of more vehicles in more places. Esp. they were only invalidated for trains.
frosch <frosch@openttd.org>
parents:
12071
diff
changeset
|
1113 v->InvalidateNewGRFCacheOfChain(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1114 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1115 |
6348
bcf98ba27bbf
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents:
6259
diff
changeset
|
1116 /* 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
|
1117 * 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
|
1118 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1119 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1120 * 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
|
1121 * 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
|
1122 * @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
|
1123 * @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
|
1124 */ |
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
|
1125 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
|
1126 { |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11875
diff
changeset
|
1127 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
|
1128 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
|
1129 |
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
|
1130 /* 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
|
1131 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
|
1132 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1133 |
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 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
|
1135 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
|
1136 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
|
1137 }; |
11b5b3f4175d
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents:
9062
diff
changeset
|
1138 |
10416
25ae1dbfcf45
(svn r14669) -Codechange: use SmallVector instead of std::list at one place
smatz <smatz@openttd.org>
parents:
10208
diff
changeset
|
1139 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
|
1140 |
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
|
1141 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
|
1142 { |
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
|
1143 /* 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
|
1144 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
|
1145 loc->engine = engine; |
25ae1dbfcf45
(svn r14669) -Codechange: use SmallVector instead of std::list at one place
smatz <smatz@openttd.org>
parents:
10208
diff
changeset
|
1146 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
|
1147 } |
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 |
9672
28e252610709
(svn r13761) -Codechange: Remove dependency on rail for altering purchase list position (mostly function renaming)
peter1138 <peter1138@openttd.org>
parents:
9652
diff
changeset
|
1149 void 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
|
1150 { |
11b5b3f4175d
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents:
9062
diff
changeset
|
1151 /* 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
|
1152 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
|
1153 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
|
1154 |
10416
25ae1dbfcf45
(svn r14669) -Codechange: use SmallVector instead of std::list at one place
smatz <smatz@openttd.org>
parents:
10208
diff
changeset
|
1155 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
|
1156 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
|
1157 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
|
1158 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
|
1159 |
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
|
1160 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
|
1161 |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11875
diff
changeset
|
1162 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
|
1163 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
|
1164 |
9070
11b5b3f4175d
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents:
9062
diff
changeset
|
1165 /* 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
|
1166 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
|
1167 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
|
1168 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
|
1169 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
|
1170 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
|
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 } |
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 |
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
|
1174 /* 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
|
1175 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
|
1176 |
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
|
1177 /* 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
|
1178 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
|
1179 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
|
1180 |
11b5b3f4175d
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents:
9062
diff
changeset
|
1181 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
|
1182 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
|
1183 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
|
1184 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
|
1185 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
|
1186 } |
11b5b3f4175d
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents:
9062
diff
changeset
|
1187 |
11b5b3f4175d
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents:
9062
diff
changeset
|
1188 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
|
1189 } |
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
|
1190 |
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
|
1191 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
|
1192 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1193 |
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
|
1194 /* 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
|
1195 _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
|
1196 } |