author | peter1138 |
Sun, 03 Aug 2008 17:35:08 +0000 | |
changeset 9834 | 7474149531c1 |
parent 9750 | 7114408dd1fa |
child 10177 | 41ce7529a331 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
9111
48ce04029fe4
(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
parents:
9070
diff
changeset
|
3 |
/** @file newgrf_engine.cpp NewGRF handling of engines. */ |
6348
6dd01da7a02b
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents:
6259
diff
changeset
|
4 |
|
0 | 5 |
#include "stdafx.h" |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1883
diff
changeset
|
6 |
#include "openttd.h" |
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
7 |
#include "variables.h" |
1299
39c06aba09aa
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
1197
diff
changeset
|
8 |
#include "debug.h" |
8786
1823ff88a054
(svn r12490) -Codechange: rename engine.h to engine_func.h and remove unneeded inclusions of engine.h and/or replace them with engine_type.h.
rubidium
parents:
8785
diff
changeset
|
9 |
#include "engine_func.h" |
9070
dd0121143eba
(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
parents:
9062
diff
changeset
|
10 |
#include "engine_base.h" |
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
11 |
#include "train.h" |
8254
1496654ca5e7
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8236
diff
changeset
|
12 |
#include "player_func.h" |
1496654ca5e7
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8236
diff
changeset
|
13 |
#include "player_base.h" |
8785
871586967963
(svn r12489) -Codechange: split station.h into station_base.h and station_func.h.
rubidium
parents:
8758
diff
changeset
|
14 |
#include "station_base.h" |
3702
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
15 |
#include "airport.h" |
3924
d06b513d65c3
(svn r5059) - NewGRF: store a GRFFile pointer reference for each pointer, instead of just the GRF ID.
peter1138
parents:
3920
diff
changeset
|
16 |
#include "newgrf.h" |
2982
eb7f50dcb249
(svn r3557) - NewGRF: move callback enums to a new file as more than just engines will use them
peter1138
parents:
2971
diff
changeset
|
17 |
#include "newgrf_callbacks.h" |
2962
f0a49b646c48
(svn r3524) - Split newgrf features from engine.[ch] into newgrf_engine.[ch], and add the new files to project files.
peter1138
parents:
2951
diff
changeset
|
18 |
#include "newgrf_engine.h" |
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
19 |
#include "newgrf_station.h" |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
20 |
#include "newgrf_spritegroup.h" |
3866
b13553406a0a
(svn r4902) Newgrf : Introduction of the newgrf_cargo files.
belugas
parents:
3862
diff
changeset
|
21 |
#include "newgrf_cargo.h" |
6091
c8827d9ae04a
(svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138
parents:
6032
diff
changeset
|
22 |
#include "cargotype.h" |
8140
0d0d8c94f84b
(svn r11702) -Codechange: move all date related stuff to date*.
rubidium
parents:
8131
diff
changeset
|
23 |
#include "date_func.h" |
8144
65cec0877b78
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents:
8140
diff
changeset
|
24 |
#include "vehicle_func.h" |
8213
7bdd7593eb9b
(svn r11776) -Codechange: more header splittings to reduce the dependencies.
rubidium
parents:
8198
diff
changeset
|
25 |
#include "core/random_func.hpp" |
8236
8a5dd0b42e47
(svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents:
8235
diff
changeset
|
26 |
#include "direction_func.h" |
8665
1afa0aa5b77f
(svn r12330) -Feature: [NewGRF] vehicle variable FE bit 5 and 6
glx
parents:
8654
diff
changeset
|
27 |
#include "rail_map.h" |
1afa0aa5b77f
(svn r12330) -Feature: [NewGRF] vehicle variable FE bit 5 and 6
glx
parents:
8654
diff
changeset
|
28 |
#include "rail.h" |
9070
dd0121143eba
(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
parents:
9062
diff
changeset
|
29 |
#include "settings_type.h" |
dd0121143eba
(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
parents:
9062
diff
changeset
|
30 |
#include <map> |
3843
03f39cd3dc56
(svn r4867) - NewGRF: implement partial support for engine variable 0x42
peter1138
parents:
3785
diff
changeset
|
31 |
|
03f39cd3dc56
(svn r4867) - NewGRF: implement partial support for engine variable 0x42
peter1138
parents:
3785
diff
changeset
|
32 |
|
3785
7d4c0a7850b2
(svn r4781) - NewGRF: give _traininfo_vehicle_pitch a proper declaration
peter1138
parents:
3739
diff
changeset
|
33 |
int _traininfo_vehicle_pitch = 0; |
3845
af6eb0103fed
(svn r4869) - NewGRF: support setting train list vehicle width to 32 instead of 29 pixels, for sets which use 32 pixel long engines/wagons.
peter1138
parents:
3843
diff
changeset
|
34 |
int _traininfo_vehicle_width = 29; |
3785
7d4c0a7850b2
(svn r4781) - NewGRF: give _traininfo_vehicle_pitch a proper declaration
peter1138
parents:
3739
diff
changeset
|
35 |
|
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
36 |
struct WagonOverride { |
8198
a1d062c165b5
(svn r11761) -Codechange: Use appropriate variable types for NewGRF engine overrides, and adjust scope while there.
peter1138
parents:
8193
diff
changeset
|
37 |
EngineID *train_id; |
a1d062c165b5
(svn r11761) -Codechange: Use appropriate variable types for NewGRF engine overrides, and adjust scope while there.
peter1138
parents:
8193
diff
changeset
|
38 |
uint trains; |
4869
3a75d9b3b5ea
(svn r6795) - NewGRF: Add support for cargo-specific wagon overrides.
peter1138
parents:
4832
diff
changeset
|
39 |
CargoID cargo; |
3693
c154dbd20439
(svn r4629) - NewGRF: constify more code that deals with sprite groups, now that ref counting is gone.
peter1138
parents:
3686
diff
changeset
|
40 |
const SpriteGroup *group; |
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
41 |
}; |
0 | 42 |
|
8198
a1d062c165b5
(svn r11761) -Codechange: Use appropriate variable types for NewGRF engine overrides, and adjust scope while there.
peter1138
parents:
8193
diff
changeset
|
43 |
void SetWagonOverrideSprites(EngineID engine, CargoID cargo, const SpriteGroup *group, EngineID *train_id, uint trains) |
0 | 44 |
{ |
9070
dd0121143eba
(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
parents:
9062
diff
changeset
|
45 |
Engine *e = GetEngine(engine); |
1477 | 46 |
WagonOverride *wo; |
0 | 47 |
|
6157
ed6db74cdf30
(svn r8903) -Regression (r8891): CT_PURCHASE does apply to aircraft overrides...
peter1138
parents:
6148
diff
changeset
|
48 |
assert(cargo < NUM_CARGO + 2); // Include CT_DEFAULT and CT_PURCHASE pseudo cargos. |
5338
a78592405640
(svn r7503) -Codechange: [NewGRF] Add bounds checking for spriteset cargo types. (NewCargo support will change this rule a bit...)
peter1138
parents:
5175
diff
changeset
|
49 |
|
9070
dd0121143eba
(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
parents:
9062
diff
changeset
|
50 |
e->overrides_count++; |
dd0121143eba
(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
parents:
9062
diff
changeset
|
51 |
e->overrides = ReallocT(e->overrides, e->overrides_count); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
114
diff
changeset
|
52 |
|
9070
dd0121143eba
(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
parents:
9062
diff
changeset
|
53 |
wo = &e->overrides[e->overrides_count - 1]; |
2488
1e98c71e5f6a
(svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents:
2477
diff
changeset
|
54 |
wo->group = group; |
4869
3a75d9b3b5ea
(svn r6795) - NewGRF: Add support for cargo-specific wagon overrides.
peter1138
parents:
4832
diff
changeset
|
55 |
wo->cargo = cargo; |
0 | 56 |
wo->trains = trains; |
8198
a1d062c165b5
(svn r11761) -Codechange: Use appropriate variable types for NewGRF engine overrides, and adjust scope while there.
peter1138
parents:
8193
diff
changeset
|
57 |
wo->train_id = MallocT<EngineID>(trains); |
a1d062c165b5
(svn r11761) -Codechange: Use appropriate variable types for NewGRF engine overrides, and adjust scope while there.
peter1138
parents:
8193
diff
changeset
|
58 |
memcpy(wo->train_id, train_id, trains * sizeof *train_id); |
0 | 59 |
} |
60 |
||
8198
a1d062c165b5
(svn r11761) -Codechange: Use appropriate variable types for NewGRF engine overrides, and adjust scope while there.
peter1138
parents:
8193
diff
changeset
|
61 |
const SpriteGroup *GetWagonOverrideSpriteSet(EngineID engine, CargoID cargo, EngineID overriding_engine) |
0 | 62 |
{ |
9070
dd0121143eba
(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
parents:
9062
diff
changeset
|
63 |
const Engine *e = GetEngine(engine); |
0 | 64 |
|
6348
6dd01da7a02b
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents:
6259
diff
changeset
|
65 |
/* XXX: This could turn out to be a timesink on profiles. We could |
6dd01da7a02b
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents:
6259
diff
changeset
|
66 |
* always just dedicate 65535 bytes for an [engine][train] trampoline |
6dd01da7a02b
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents:
6259
diff
changeset
|
67 |
* for O(1). Or O(logMlogN) and searching binary tree or smt. like |
6dd01da7a02b
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents:
6259
diff
changeset
|
68 |
* that. --pasky */ |
0 | 69 |
|
9070
dd0121143eba
(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
parents:
9062
diff
changeset
|
70 |
for (uint i = 0; i < e->overrides_count; i++) { |
dd0121143eba
(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
parents:
9062
diff
changeset
|
71 |
const WagonOverride *wo = &e->overrides[i]; |
0 | 72 |
|
6603
076b05312635
(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
parents:
6589
diff
changeset
|
73 |
if (wo->cargo != cargo && wo->cargo != CT_DEFAULT) continue; |
076b05312635
(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
parents:
6589
diff
changeset
|
74 |
|
8198
a1d062c165b5
(svn r11761) -Codechange: Use appropriate variable types for NewGRF engine overrides, and adjust scope while there.
peter1138
parents:
8193
diff
changeset
|
75 |
for (uint j = 0; j < wo->trains; j++) { |
6603
076b05312635
(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
parents:
6589
diff
changeset
|
76 |
if (wo->train_id[j] == overriding_engine) return wo->group; |
0 | 77 |
} |
78 |
} |
|
79 |
return NULL; |
|
80 |
} |
|
81 |
||
2491
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2490
diff
changeset
|
82 |
/** |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2490
diff
changeset
|
83 |
* Unload all wagon override sprite groups. |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2490
diff
changeset
|
84 |
*/ |
9070
dd0121143eba
(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
parents:
9062
diff
changeset
|
85 |
void UnloadWagonOverrides(Engine *e) |
2491
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2490
diff
changeset
|
86 |
{ |
9070
dd0121143eba
(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
parents:
9062
diff
changeset
|
87 |
for (uint i = 0; i < e->overrides_count; i++) { |
dd0121143eba
(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
parents:
9062
diff
changeset
|
88 |
WagonOverride *wo = &e->overrides[i]; |
dd0121143eba
(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
parents:
9062
diff
changeset
|
89 |
free(wo->train_id); |
2491
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2490
diff
changeset
|
90 |
} |
9070
dd0121143eba
(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
parents:
9062
diff
changeset
|
91 |
free(e->overrides); |
dd0121143eba
(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
parents:
9062
diff
changeset
|
92 |
e->overrides_count = 0; |
dd0121143eba
(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
parents:
9062
diff
changeset
|
93 |
e->overrides = NULL; |
2491
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2490
diff
changeset
|
94 |
} |
0 | 95 |
|
96 |
||
3693
c154dbd20439
(svn r4629) - NewGRF: constify more code that deals with sprite groups, now that ref counting is gone.
peter1138
parents:
3686
diff
changeset
|
97 |
void SetCustomEngineSprites(EngineID engine, byte cargo, const SpriteGroup *group) |
0 | 98 |
{ |
9070
dd0121143eba
(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
parents:
9062
diff
changeset
|
99 |
Engine *e = GetEngine(engine); |
dd0121143eba
(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
parents:
9062
diff
changeset
|
100 |
assert(cargo < lengthof(e->group)); |
5338
a78592405640
(svn r7503) -Codechange: [NewGRF] Add bounds checking for spriteset cargo types. (NewCargo support will change this rule a bit...)
peter1138
parents:
5175
diff
changeset
|
101 |
|
9070
dd0121143eba
(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
parents:
9062
diff
changeset
|
102 |
if (e->group[cargo] != NULL) { |
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5338
diff
changeset
|
103 |
grfmsg(6, "SetCustomEngineSprites: engine %d cargo %d already has group -- replacing", engine, cargo); |
2491
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2490
diff
changeset
|
104 |
} |
9070
dd0121143eba
(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
parents:
9062
diff
changeset
|
105 |
e->group[cargo] = group; |
0 | 106 |
} |
107 |
||
2491
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2490
diff
changeset
|
108 |
|
3924
d06b513d65c3
(svn r5059) - NewGRF: store a GRFFile pointer reference for each pointer, instead of just the GRF ID.
peter1138
parents:
3920
diff
changeset
|
109 |
/** |
d06b513d65c3
(svn r5059) - NewGRF: store a GRFFile pointer reference for each pointer, instead of just the GRF ID.
peter1138
parents:
3920
diff
changeset
|
110 |
* Tie a GRFFile entry to an engine, to allow us to retrieve GRF parameters |
d06b513d65c3
(svn r5059) - NewGRF: store a GRFFile pointer reference for each pointer, instead of just the GRF ID.
peter1138
parents:
3920
diff
changeset
|
111 |
* etc during a game. |
d06b513d65c3
(svn r5059) - NewGRF: store a GRFFile pointer reference for each pointer, instead of just the GRF ID.
peter1138
parents:
3920
diff
changeset
|
112 |
* @param engine Engine ID to tie the GRFFile to. |
d06b513d65c3
(svn r5059) - NewGRF: store a GRFFile pointer reference for each pointer, instead of just the GRF ID.
peter1138
parents:
3920
diff
changeset
|
113 |
* @param file Pointer of GRFFile to tie. |
d06b513d65c3
(svn r5059) - NewGRF: store a GRFFile pointer reference for each pointer, instead of just the GRF ID.
peter1138
parents:
3920
diff
changeset
|
114 |
*/ |
d06b513d65c3
(svn r5059) - NewGRF: store a GRFFile pointer reference for each pointer, instead of just the GRF ID.
peter1138
parents:
3920
diff
changeset
|
115 |
void SetEngineGRF(EngineID engine, const GRFFile *file) |
3648
d234c46bb37a
(svn r4559) - NewGRF: keep a record of which grf an engine is defined in. Will be used in the future.
peter1138
parents:
3630
diff
changeset
|
116 |
{ |
9070
dd0121143eba
(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
parents:
9062
diff
changeset
|
117 |
Engine *e = GetEngine(engine); |
dd0121143eba
(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
parents:
9062
diff
changeset
|
118 |
e->grffile = file; |
3648
d234c46bb37a
(svn r4559) - NewGRF: keep a record of which grf an engine is defined in. Will be used in the future.
peter1138
parents:
3630
diff
changeset
|
119 |
} |
d234c46bb37a
(svn r4559) - NewGRF: keep a record of which grf an engine is defined in. Will be used in the future.
peter1138
parents:
3630
diff
changeset
|
120 |
|
3924
d06b513d65c3
(svn r5059) - NewGRF: store a GRFFile pointer reference for each pointer, instead of just the GRF ID.
peter1138
parents:
3920
diff
changeset
|
121 |
|
d06b513d65c3
(svn r5059) - NewGRF: store a GRFFile pointer reference for each pointer, instead of just the GRF ID.
peter1138
parents:
3920
diff
changeset
|
122 |
/** |
d06b513d65c3
(svn r5059) - NewGRF: store a GRFFile pointer reference for each pointer, instead of just the GRF ID.
peter1138
parents:
3920
diff
changeset
|
123 |
* Retrieve the GRFFile tied to an engine |
d06b513d65c3
(svn r5059) - NewGRF: store a GRFFile pointer reference for each pointer, instead of just the GRF ID.
peter1138
parents:
3920
diff
changeset
|
124 |
* @param engine Engine ID to retrieve. |
d06b513d65c3
(svn r5059) - NewGRF: store a GRFFile pointer reference for each pointer, instead of just the GRF ID.
peter1138
parents:
3920
diff
changeset
|
125 |
* @return Pointer to GRFFile. |
d06b513d65c3
(svn r5059) - NewGRF: store a GRFFile pointer reference for each pointer, instead of just the GRF ID.
peter1138
parents:
3920
diff
changeset
|
126 |
*/ |
d06b513d65c3
(svn r5059) - NewGRF: store a GRFFile pointer reference for each pointer, instead of just the GRF ID.
peter1138
parents:
3920
diff
changeset
|
127 |
const GRFFile *GetEngineGRF(EngineID engine) |
d06b513d65c3
(svn r5059) - NewGRF: store a GRFFile pointer reference for each pointer, instead of just the GRF ID.
peter1138
parents:
3920
diff
changeset
|
128 |
{ |
9070
dd0121143eba
(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
parents:
9062
diff
changeset
|
129 |
return GetEngine(engine)->grffile; |
3924
d06b513d65c3
(svn r5059) - NewGRF: store a GRFFile pointer reference for each pointer, instead of just the GRF ID.
peter1138
parents:
3920
diff
changeset
|
130 |
} |
d06b513d65c3
(svn r5059) - NewGRF: store a GRFFile pointer reference for each pointer, instead of just the GRF ID.
peter1138
parents:
3920
diff
changeset
|
131 |
|
d06b513d65c3
(svn r5059) - NewGRF: store a GRFFile pointer reference for each pointer, instead of just the GRF ID.
peter1138
parents:
3920
diff
changeset
|
132 |
|
d06b513d65c3
(svn r5059) - NewGRF: store a GRFFile pointer reference for each pointer, instead of just the GRF ID.
peter1138
parents:
3920
diff
changeset
|
133 |
/** |
d06b513d65c3
(svn r5059) - NewGRF: store a GRFFile pointer reference for each pointer, instead of just the GRF ID.
peter1138
parents:
3920
diff
changeset
|
134 |
* Retrieve the GRF ID of the GRFFile tied to an engine |
d06b513d65c3
(svn r5059) - NewGRF: store a GRFFile pointer reference for each pointer, instead of just the GRF ID.
peter1138
parents:
3920
diff
changeset
|
135 |
* @param engine Engine ID to retrieve. |
d06b513d65c3
(svn r5059) - NewGRF: store a GRFFile pointer reference for each pointer, instead of just the GRF ID.
peter1138
parents:
3920
diff
changeset
|
136 |
* @return 32 bit GRFID value. |
d06b513d65c3
(svn r5059) - NewGRF: store a GRFFile pointer reference for each pointer, instead of just the GRF ID.
peter1138
parents:
3920
diff
changeset
|
137 |
*/ |
3648
d234c46bb37a
(svn r4559) - NewGRF: keep a record of which grf an engine is defined in. Will be used in the future.
peter1138
parents:
3630
diff
changeset
|
138 |
uint32 GetEngineGRFID(EngineID engine) |
d234c46bb37a
(svn r4559) - NewGRF: keep a record of which grf an engine is defined in. Will be used in the future.
peter1138
parents:
3630
diff
changeset
|
139 |
{ |
9070
dd0121143eba
(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
parents:
9062
diff
changeset
|
140 |
return GetEngineGRF(engine)->grfid; |
3648
d234c46bb37a
(svn r4559) - NewGRF: keep a record of which grf an engine is defined in. Will be used in the future.
peter1138
parents:
3630
diff
changeset
|
141 |
} |
d234c46bb37a
(svn r4559) - NewGRF: keep a record of which grf an engine is defined in. Will be used in the future.
peter1138
parents:
3630
diff
changeset
|
142 |
|
d234c46bb37a
(svn r4559) - NewGRF: keep a record of which grf an engine is defined in. Will be used in the future.
peter1138
parents:
3630
diff
changeset
|
143 |
|
2708
48714bad9499
(svn r3252) - NewGRF: Map new train subtypes to old types for rail vehicles.
peter1138
parents:
2639
diff
changeset
|
144 |
static int MapOldSubType(const Vehicle *v) |
48714bad9499
(svn r3252) - NewGRF: Map new train subtypes to old types for rail vehicles.
peter1138
parents:
2639
diff
changeset
|
145 |
{ |
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6248
diff
changeset
|
146 |
if (v->type != VEH_TRAIN) return v->subtype; |
2708
48714bad9499
(svn r3252) - NewGRF: Map new train subtypes to old types for rail vehicles.
peter1138
parents:
2639
diff
changeset
|
147 |
if (IsTrainEngine(v)) return 0; |
48714bad9499
(svn r3252) - NewGRF: Map new train subtypes to old types for rail vehicles.
peter1138
parents:
2639
diff
changeset
|
148 |
if (IsFreeWagon(v)) return 4; |
48714bad9499
(svn r3252) - NewGRF: Map new train subtypes to old types for rail vehicles.
peter1138
parents:
2639
diff
changeset
|
149 |
return 2; |
48714bad9499
(svn r3252) - NewGRF: Map new train subtypes to old types for rail vehicles.
peter1138
parents:
2639
diff
changeset
|
150 |
} |
48714bad9499
(svn r3252) - NewGRF: Map new train subtypes to old types for rail vehicles.
peter1138
parents:
2639
diff
changeset
|
151 |
|
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
152 |
|
3702
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
153 |
/* TTDP style aircraft movement states for GRF Action 2 Var 0xE2 */ |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
154 |
enum { |
4055
582a469d6c5c
(svn r5335) - Newgrf: correct spelling of hangar
peter1138
parents:
4050
diff
changeset
|
155 |
AMS_TTDP_HANGAR, |
582a469d6c5c
(svn r5335) - Newgrf: correct spelling of hangar
peter1138
parents:
4050
diff
changeset
|
156 |
AMS_TTDP_TO_HANGAR, |
3702
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
157 |
AMS_TTDP_TO_PAD1, |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
158 |
AMS_TTDP_TO_PAD2, |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
159 |
AMS_TTDP_TO_PAD3, |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
160 |
AMS_TTDP_TO_ENTRY_2_AND_3, |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
161 |
AMS_TTDP_TO_ENTRY_2_AND_3_AND_H, |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
162 |
AMS_TTDP_TO_JUNCTION, |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
163 |
AMS_TTDP_LEAVE_RUNWAY, |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
164 |
AMS_TTDP_TO_INWAY, |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
165 |
AMS_TTDP_TO_RUNWAY, |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
166 |
AMS_TTDP_TO_OUTWAY, |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
167 |
AMS_TTDP_WAITING, |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
168 |
AMS_TTDP_TAKEOFF, |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
169 |
AMS_TTDP_TO_TAKEOFF, |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
170 |
AMS_TTDP_CLIMBING, |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
171 |
AMS_TTDP_FLIGHT_APPROACH, |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
172 |
AMS_TTDP_UNUSED_0x11, |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
173 |
AMS_TTDP_FLIGHT_TO_TOWER, |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
174 |
AMS_TTDP_UNUSED_0x13, |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
175 |
AMS_TTDP_FLIGHT_FINAL, |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
176 |
AMS_TTDP_FLIGHT_DESCENT, |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
177 |
AMS_TTDP_BRAKING, |
3920
cca65c17b760
(svn r5047) - NewGRF: fix typo of AIRPORT in enum
peter1138
parents:
3893
diff
changeset
|
178 |
AMS_TTDP_HELI_TAKEOFF_AIRPORT, |
cca65c17b760
(svn r5047) - NewGRF: fix typo of AIRPORT in enum
peter1138
parents:
3893
diff
changeset
|
179 |
AMS_TTDP_HELI_TO_TAKEOFF_AIRPORT, |
cca65c17b760
(svn r5047) - NewGRF: fix typo of AIRPORT in enum
peter1138
parents:
3893
diff
changeset
|
180 |
AMS_TTDP_HELI_LAND_AIRPORT, |
3702
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
181 |
AMS_TTDP_HELI_TAKEOFF_HELIPORT, |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
182 |
AMS_TTDP_HELI_TO_TAKEOFF_HELIPORT, |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
183 |
AMS_TTDP_HELI_LAND_HELIPORT, |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
184 |
}; |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
185 |
|
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
186 |
|
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
187 |
/** |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
188 |
* Map OTTD aircraft movement states to TTDPatch style movement states |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
189 |
* (VarAction 2 Variable 0xE2) |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
190 |
*/ |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
191 |
static byte MapAircraftMovementState(const Vehicle *v) |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
192 |
{ |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
193 |
const Station *st = GetStation(v->u.air.targetairport); |
6912
259420c519b9
(svn r10165) -Fix [FS#874]: crash when trying to get the aircraft movement state of an aircraft going to a just deleted airport.
rubidium
parents:
6857
diff
changeset
|
194 |
if (st->airport_tile == 0) return AMS_TTDP_FLIGHT_TO_TOWER; |
259420c519b9
(svn r10165) -Fix [FS#874]: crash when trying to get the aircraft movement state of an aircraft going to a just deleted airport.
rubidium
parents:
6857
diff
changeset
|
195 |
|
6032 | 196 |
const AirportFTAClass *afc = st->Airport(); |
6604
3ee954a2c95e
(svn r9819) -Codechange: Take account of AMED_HOLD in OTTD/TTDP state translation (bulb)
peter1138
parents:
6603
diff
changeset
|
197 |
uint16 amdflag = afc->MovingData(v->u.air.pos)->flag; |
3702
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
198 |
|
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
199 |
switch (v->u.air.state) { |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
200 |
case HANGAR: |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
201 |
/* The international airport is a special case as helicopters can land in |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
202 |
* front of the hanger. Helicopters also change their air.state to |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
203 |
* AMED_HELI_LOWER some time before actually descending. */ |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
204 |
|
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
205 |
/* This condition only occurs for helicopters, during descent, |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
206 |
* to a landing by the hanger of an international airport. */ |
3920
cca65c17b760
(svn r5047) - NewGRF: fix typo of AIRPORT in enum
peter1138
parents:
3893
diff
changeset
|
207 |
if (amdflag & AMED_HELI_LOWER) return AMS_TTDP_HELI_LAND_AIRPORT; |
3702
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
208 |
|
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
209 |
/* This condition only occurs for helicopters, before starting descent, |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
210 |
* to a landing by the hanger of an international airport. */ |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
211 |
if (amdflag & AMED_SLOWTURN) return AMS_TTDP_FLIGHT_TO_TOWER; |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
212 |
|
6348
6dd01da7a02b
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents:
6259
diff
changeset
|
213 |
/* The final two conditions apply to helicopters or aircraft. |
6dd01da7a02b
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents:
6259
diff
changeset
|
214 |
* Has reached hanger? */ |
4055
582a469d6c5c
(svn r5335) - Newgrf: correct spelling of hangar
peter1138
parents:
4050
diff
changeset
|
215 |
if (amdflag & AMED_EXACTPOS) return AMS_TTDP_HANGAR; |
3702
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
216 |
|
6348
6dd01da7a02b
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents:
6259
diff
changeset
|
217 |
/* Still moving towards hanger. */ |
4055
582a469d6c5c
(svn r5335) - Newgrf: correct spelling of hangar
peter1138
parents:
4050
diff
changeset
|
218 |
return AMS_TTDP_TO_HANGAR; |
3702
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
219 |
|
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
220 |
case TERM1: |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
221 |
if (amdflag & AMED_EXACTPOS) return AMS_TTDP_TO_PAD1; |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
222 |
return AMS_TTDP_TO_JUNCTION; |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
223 |
|
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
224 |
case TERM2: |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
225 |
if (amdflag & AMED_EXACTPOS) return AMS_TTDP_TO_PAD2; |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
226 |
return AMS_TTDP_TO_ENTRY_2_AND_3_AND_H; |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
227 |
|
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
228 |
case TERM3: |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
229 |
case TERM4: |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
230 |
case TERM5: |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
231 |
case TERM6: |
4059
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4058
diff
changeset
|
232 |
case TERM7: |
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4058
diff
changeset
|
233 |
case TERM8: |
3702
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
234 |
/* TTDPatch only has 3 terminals, so treat these states the same */ |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
235 |
if (amdflag & AMED_EXACTPOS) return AMS_TTDP_TO_PAD3; |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
236 |
return AMS_TTDP_TO_ENTRY_2_AND_3_AND_H; |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
237 |
|
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
238 |
case HELIPAD1: |
4059
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4058
diff
changeset
|
239 |
case HELIPAD2: |
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4058
diff
changeset
|
240 |
case HELIPAD3: |
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4058
diff
changeset
|
241 |
case HELIPAD4: // Will only occur for helicopters. |
3920
cca65c17b760
(svn r5047) - NewGRF: fix typo of AIRPORT in enum
peter1138
parents:
3893
diff
changeset
|
242 |
if (amdflag & AMED_HELI_LOWER) return AMS_TTDP_HELI_LAND_AIRPORT; // Descending. |
3702
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
243 |
if (amdflag & AMED_SLOWTURN) return AMS_TTDP_FLIGHT_TO_TOWER; // Still hasn't started descent. |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
244 |
return AMS_TTDP_TO_JUNCTION; // On the ground. |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
245 |
|
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
246 |
case TAKEOFF: // Moving to takeoff position. |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
247 |
return AMS_TTDP_TO_OUTWAY; |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
248 |
|
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
249 |
case STARTTAKEOFF: // Accelerating down runway. |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
250 |
return AMS_TTDP_TAKEOFF; |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
251 |
|
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
252 |
case ENDTAKEOFF: // Ascent |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
253 |
return AMS_TTDP_CLIMBING; |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
254 |
|
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
255 |
case HELITAKEOFF: // Helicopter is moving to take off position. |
6020 | 256 |
if (afc->delta_z == 0) { |
257 |
return amdflag & AMED_HELI_RAISE ? |
|
258 |
AMS_TTDP_HELI_TAKEOFF_AIRPORT : AMS_TTDP_TO_JUNCTION; |
|
259 |
} else { |
|
260 |
return AMS_TTDP_HELI_TAKEOFF_HELIPORT; |
|
3702
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
261 |
} |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
262 |
|
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
263 |
case FLYING: |
6604
3ee954a2c95e
(svn r9819) -Codechange: Take account of AMED_HOLD in OTTD/TTDP state translation (bulb)
peter1138
parents:
6603
diff
changeset
|
264 |
return amdflag & AMED_HOLD ? AMS_TTDP_FLIGHT_APPROACH : AMS_TTDP_FLIGHT_TO_TOWER; |
3702
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
265 |
|
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
266 |
case LANDING: // Descent |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
267 |
return AMS_TTDP_FLIGHT_DESCENT; |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
268 |
|
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
269 |
case ENDLANDING: // On the runway braking |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
270 |
if (amdflag & AMED_BRAKE) return AMS_TTDP_BRAKING; |
6348
6dd01da7a02b
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents:
6259
diff
changeset
|
271 |
/* Landed - moving off runway */ |
3702
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
272 |
return AMS_TTDP_TO_INWAY; |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
273 |
|
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
274 |
case HELILANDING: |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
275 |
case HELIENDLANDING: // Helicoptor is decending. |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
276 |
if (amdflag & AMED_HELI_LOWER) { |
6020 | 277 |
return afc->delta_z == 0 ? |
278 |
AMS_TTDP_HELI_LAND_AIRPORT : AMS_TTDP_HELI_LAND_HELIPORT; |
|
279 |
} else { |
|
280 |
return AMS_TTDP_FLIGHT_TO_TOWER; |
|
3702
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
281 |
} |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
282 |
|
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
283 |
default: |
4055
582a469d6c5c
(svn r5335) - Newgrf: correct spelling of hangar
peter1138
parents:
4050
diff
changeset
|
284 |
return AMS_TTDP_HANGAR; |
3702
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
285 |
} |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
286 |
} |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
287 |
|
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
288 |
|
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
289 |
/* TTDP style aircraft movement action for GRF Action 2 Var 0xE6 */ |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
290 |
enum { |
4055
582a469d6c5c
(svn r5335) - Newgrf: correct spelling of hangar
peter1138
parents:
4050
diff
changeset
|
291 |
AMA_TTDP_IN_HANGAR, |
3702
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
292 |
AMA_TTDP_ON_PAD1, |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
293 |
AMA_TTDP_ON_PAD2, |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
294 |
AMA_TTDP_ON_PAD3, |
4055
582a469d6c5c
(svn r5335) - Newgrf: correct spelling of hangar
peter1138
parents:
4050
diff
changeset
|
295 |
AMA_TTDP_HANGAR_TO_PAD1, |
582a469d6c5c
(svn r5335) - Newgrf: correct spelling of hangar
peter1138
parents:
4050
diff
changeset
|
296 |
AMA_TTDP_HANGAR_TO_PAD2, |
582a469d6c5c
(svn r5335) - Newgrf: correct spelling of hangar
peter1138
parents:
4050
diff
changeset
|
297 |
AMA_TTDP_HANGAR_TO_PAD3, |
3702
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
298 |
AMA_TTDP_LANDING_TO_PAD1, |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
299 |
AMA_TTDP_LANDING_TO_PAD2, |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
300 |
AMA_TTDP_LANDING_TO_PAD3, |
4055
582a469d6c5c
(svn r5335) - Newgrf: correct spelling of hangar
peter1138
parents:
4050
diff
changeset
|
301 |
AMA_TTDP_PAD1_TO_HANGAR, |
582a469d6c5c
(svn r5335) - Newgrf: correct spelling of hangar
peter1138
parents:
4050
diff
changeset
|
302 |
AMA_TTDP_PAD2_TO_HANGAR, |
582a469d6c5c
(svn r5335) - Newgrf: correct spelling of hangar
peter1138
parents:
4050
diff
changeset
|
303 |
AMA_TTDP_PAD3_TO_HANGAR, |
3702
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
304 |
AMA_TTDP_PAD1_TO_TAKEOFF, |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
305 |
AMA_TTDP_PAD2_TO_TAKEOFF, |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
306 |
AMA_TTDP_PAD3_TO_TAKEOFF, |
4055
582a469d6c5c
(svn r5335) - Newgrf: correct spelling of hangar
peter1138
parents:
4050
diff
changeset
|
307 |
AMA_TTDP_HANGAR_TO_TAKOFF, |
582a469d6c5c
(svn r5335) - Newgrf: correct spelling of hangar
peter1138
parents:
4050
diff
changeset
|
308 |
AMA_TTDP_LANDING_TO_HANGAR, |
3702
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
309 |
AMA_TTDP_IN_FLIGHT, |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
310 |
}; |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
311 |
|
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
312 |
|
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
313 |
/** |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
314 |
* Map OTTD aircraft movement states to TTDPatch style movement actions |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
315 |
* (VarAction 2 Variable 0xE6) |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
316 |
* This is not fully supported yet but it's enough for Planeset. |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
317 |
*/ |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
318 |
static byte MapAircraftMovementAction(const Vehicle *v) |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
319 |
{ |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
320 |
switch (v->u.air.state) { |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
321 |
case HANGAR: |
4055
582a469d6c5c
(svn r5335) - Newgrf: correct spelling of hangar
peter1138
parents:
4050
diff
changeset
|
322 |
return (v->cur_speed > 0) ? AMA_TTDP_LANDING_TO_HANGAR : AMA_TTDP_IN_HANGAR; |
3702
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
323 |
|
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
324 |
case TERM1: |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
325 |
case HELIPAD1: |
8836
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8786
diff
changeset
|
326 |
return (v->current_order.IsType(OT_LOADING)) ? AMA_TTDP_ON_PAD1 : AMA_TTDP_LANDING_TO_PAD1; |
3702
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
327 |
|
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
328 |
case TERM2: |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
329 |
case HELIPAD2: |
8836
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8786
diff
changeset
|
330 |
return (v->current_order.IsType(OT_LOADING)) ? AMA_TTDP_ON_PAD2 : AMA_TTDP_LANDING_TO_PAD2; |
3702
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
331 |
|
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
332 |
case TERM3: |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
333 |
case TERM4: |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
334 |
case TERM5: |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
335 |
case TERM6: |
4059
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4058
diff
changeset
|
336 |
case TERM7: |
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4058
diff
changeset
|
337 |
case TERM8: |
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4058
diff
changeset
|
338 |
case HELIPAD3: |
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4058
diff
changeset
|
339 |
case HELIPAD4: |
8836
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8786
diff
changeset
|
340 |
return (v->current_order.IsType(OT_LOADING)) ? AMA_TTDP_ON_PAD3 : AMA_TTDP_LANDING_TO_PAD3; |
3702
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
341 |
|
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
342 |
case TAKEOFF: // Moving to takeoff position |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
343 |
case STARTTAKEOFF: // Accelerating down runway |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
344 |
case ENDTAKEOFF: // Ascent |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
345 |
case HELITAKEOFF: |
6348
6dd01da7a02b
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents:
6259
diff
changeset
|
346 |
/* @todo Need to find which terminal (or hanger) we've come from. How? */ |
3702
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
347 |
return AMA_TTDP_PAD1_TO_TAKEOFF; |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
348 |
|
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
349 |
case FLYING: |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
350 |
return AMA_TTDP_IN_FLIGHT; |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
351 |
|
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
352 |
case LANDING: // Descent |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
353 |
case ENDLANDING: // On the runway braking |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
354 |
case HELILANDING: |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
355 |
case HELIENDLANDING: |
6348
6dd01da7a02b
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents:
6259
diff
changeset
|
356 |
/* @todo Need to check terminal we're landing to. Is it known yet? */ |
8836
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8786
diff
changeset
|
357 |
return (v->current_order.IsType(OT_GOTO_DEPOT)) ? |
4055
582a469d6c5c
(svn r5335) - Newgrf: correct spelling of hangar
peter1138
parents:
4050
diff
changeset
|
358 |
AMA_TTDP_LANDING_TO_HANGAR : AMA_TTDP_LANDING_TO_PAD1; |
3702
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
359 |
|
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
360 |
default: |
4055
582a469d6c5c
(svn r5335) - Newgrf: correct spelling of hangar
peter1138
parents:
4050
diff
changeset
|
361 |
return AMA_TTDP_IN_HANGAR; |
3702
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
362 |
} |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
363 |
} |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
364 |
|
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
365 |
|
3703
3c815d04affb
(svn r4644) - NewGRF: support for variable 0x44, aircraft information. (mart3p)
peter1138
parents:
3702
diff
changeset
|
366 |
/* TTDP airport types. Used to map our types to TTDPatch's */ |
3c815d04affb
(svn r4644) - NewGRF: support for variable 0x44, aircraft information. (mart3p)
peter1138
parents:
3702
diff
changeset
|
367 |
enum { |
3c815d04affb
(svn r4644) - NewGRF: support for variable 0x44, aircraft information. (mart3p)
peter1138
parents:
3702
diff
changeset
|
368 |
ATP_TTDP_SMALL, |
3c815d04affb
(svn r4644) - NewGRF: support for variable 0x44, aircraft information. (mart3p)
peter1138
parents:
3702
diff
changeset
|
369 |
ATP_TTDP_LARGE, |
3c815d04affb
(svn r4644) - NewGRF: support for variable 0x44, aircraft information. (mart3p)
peter1138
parents:
3702
diff
changeset
|
370 |
ATP_TTDP_HELIPORT, |
3c815d04affb
(svn r4644) - NewGRF: support for variable 0x44, aircraft information. (mart3p)
peter1138
parents:
3702
diff
changeset
|
371 |
ATP_TTDP_OILRIG, |
3c815d04affb
(svn r4644) - NewGRF: support for variable 0x44, aircraft information. (mart3p)
peter1138
parents:
3702
diff
changeset
|
372 |
}; |
3c815d04affb
(svn r4644) - NewGRF: support for variable 0x44, aircraft information. (mart3p)
peter1138
parents:
3702
diff
changeset
|
373 |
|
3c815d04affb
(svn r4644) - NewGRF: support for variable 0x44, aircraft information. (mart3p)
peter1138
parents:
3702
diff
changeset
|
374 |
|
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
375 |
/* Vehicle Resolver Functions */ |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
376 |
static inline const Vehicle *GRV(const ResolverObject *object) |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
377 |
{ |
8756
b6f8dc6a246f
(svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx
parents:
8666
diff
changeset
|
378 |
switch (object->scope) { |
b6f8dc6a246f
(svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx
parents:
8666
diff
changeset
|
379 |
default: NOT_REACHED(); |
b6f8dc6a246f
(svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx
parents:
8666
diff
changeset
|
380 |
case VSG_SCOPE_SELF: return object->u.vehicle.self; |
b6f8dc6a246f
(svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx
parents:
8666
diff
changeset
|
381 |
case VSG_SCOPE_PARENT: return object->u.vehicle.parent; |
b6f8dc6a246f
(svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx
parents:
8666
diff
changeset
|
382 |
case VSG_SCOPE_RELATIVE: { |
8758
d2655b49862b
(svn r12454) -Fix (r12452): incorrect calculation for 'first vehicle in this chain of vehicles with the same ID' (thx DaleStan)
glx
parents:
8756
diff
changeset
|
383 |
const Vehicle *v = NULL; |
8756
b6f8dc6a246f
(svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx
parents:
8666
diff
changeset
|
384 |
switch (GB(object->count, 6, 2)) { |
b6f8dc6a246f
(svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx
parents:
8666
diff
changeset
|
385 |
default: NOT_REACHED(); |
b6f8dc6a246f
(svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx
parents:
8666
diff
changeset
|
386 |
case 0x00: // count back (away from the engine), starting at this vehicle |
b6f8dc6a246f
(svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx
parents:
8666
diff
changeset
|
387 |
case 0x01: // count forward (toward the engine), starting at this vehicle |
b6f8dc6a246f
(svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx
parents:
8666
diff
changeset
|
388 |
v = object->u.vehicle.self; |
b6f8dc6a246f
(svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx
parents:
8666
diff
changeset
|
389 |
break; |
b6f8dc6a246f
(svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx
parents:
8666
diff
changeset
|
390 |
case 0x02: // count back, starting at the engine |
b6f8dc6a246f
(svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx
parents:
8666
diff
changeset
|
391 |
v = object->u.vehicle.parent; |
b6f8dc6a246f
(svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx
parents:
8666
diff
changeset
|
392 |
break; |
8758
d2655b49862b
(svn r12454) -Fix (r12452): incorrect calculation for 'first vehicle in this chain of vehicles with the same ID' (thx DaleStan)
glx
parents:
8756
diff
changeset
|
393 |
case 0x03: { // count back, starting at the first vehicle in this chain of vehicles with the same ID, as for vehicle variable 41 |
d2655b49862b
(svn r12454) -Fix (r12452): incorrect calculation for 'first vehicle in this chain of vehicles with the same ID' (thx DaleStan)
glx
parents:
8756
diff
changeset
|
394 |
const Vehicle *self = object->u.vehicle.self; |
d2655b49862b
(svn r12454) -Fix (r12452): incorrect calculation for 'first vehicle in this chain of vehicles with the same ID' (thx DaleStan)
glx
parents:
8756
diff
changeset
|
395 |
for (const Vehicle *u = self->First(); u != self; u = u->Next()) { |
d2655b49862b
(svn r12454) -Fix (r12452): incorrect calculation for 'first vehicle in this chain of vehicles with the same ID' (thx DaleStan)
glx
parents:
8756
diff
changeset
|
396 |
if (u->engine_type != self->engine_type) { |
d2655b49862b
(svn r12454) -Fix (r12452): incorrect calculation for 'first vehicle in this chain of vehicles with the same ID' (thx DaleStan)
glx
parents:
8756
diff
changeset
|
397 |
v = NULL; |
d2655b49862b
(svn r12454) -Fix (r12452): incorrect calculation for 'first vehicle in this chain of vehicles with the same ID' (thx DaleStan)
glx
parents:
8756
diff
changeset
|
398 |
} else { |
d2655b49862b
(svn r12454) -Fix (r12452): incorrect calculation for 'first vehicle in this chain of vehicles with the same ID' (thx DaleStan)
glx
parents:
8756
diff
changeset
|
399 |
if (v == NULL) v = u; |
d2655b49862b
(svn r12454) -Fix (r12452): incorrect calculation for 'first vehicle in this chain of vehicles with the same ID' (thx DaleStan)
glx
parents:
8756
diff
changeset
|
400 |
} |
d2655b49862b
(svn r12454) -Fix (r12452): incorrect calculation for 'first vehicle in this chain of vehicles with the same ID' (thx DaleStan)
glx
parents:
8756
diff
changeset
|
401 |
} |
d2655b49862b
(svn r12454) -Fix (r12452): incorrect calculation for 'first vehicle in this chain of vehicles with the same ID' (thx DaleStan)
glx
parents:
8756
diff
changeset
|
402 |
if (v == NULL) v = self; |
d2655b49862b
(svn r12454) -Fix (r12452): incorrect calculation for 'first vehicle in this chain of vehicles with the same ID' (thx DaleStan)
glx
parents:
8756
diff
changeset
|
403 |
} break; |
8756
b6f8dc6a246f
(svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx
parents:
8666
diff
changeset
|
404 |
} |
b6f8dc6a246f
(svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx
parents:
8666
diff
changeset
|
405 |
uint32 count = GB(object->count, 0, 4); |
b6f8dc6a246f
(svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx
parents:
8666
diff
changeset
|
406 |
if (count == 0) count = GetRegister(0x100); |
b6f8dc6a246f
(svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx
parents:
8666
diff
changeset
|
407 |
while (v != NULL && count-- != 0) v = (GB(object->count, 6, 2) == 0x01) ? v->Previous() : v->Next(); |
b6f8dc6a246f
(svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx
parents:
8666
diff
changeset
|
408 |
return v; |
b6f8dc6a246f
(svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx
parents:
8666
diff
changeset
|
409 |
} |
b6f8dc6a246f
(svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx
parents:
8666
diff
changeset
|
410 |
} |
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
411 |
} |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
412 |
|
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
413 |
|
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
414 |
static uint32 VehicleGetRandomBits(const ResolverObject *object) |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
415 |
{ |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
416 |
return GRV(object) == NULL ? 0 : GRV(object)->random_bits; |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
417 |
} |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
418 |
|
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
419 |
|
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
420 |
static uint32 VehicleGetTriggers(const ResolverObject *object) |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
421 |
{ |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
422 |
return GRV(object) == NULL ? 0 : GRV(object)->waiting_triggers; |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
423 |
} |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
424 |
|
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
425 |
|
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
426 |
static void VehicleSetTriggers(const ResolverObject *object, int triggers) |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
427 |
{ |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
428 |
/* Evil cast to get around const-ness. This used to be achieved by an |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
429 |
* innocent looking function pointer cast... Currently I cannot see a |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
430 |
* way of avoiding this without removing consts deep within gui code. |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
431 |
*/ |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
432 |
Vehicle *v = (Vehicle*)GRV(object); |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
433 |
|
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
434 |
/* This function must only be called when processing triggers -- any |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
435 |
* other time is an error. */ |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
436 |
assert(object->trigger != 0); |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
437 |
|
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
438 |
if (v != NULL) v->waiting_triggers = triggers; |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
439 |
} |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
440 |
|
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
441 |
|
6516
0d14650b196b
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents:
6490
diff
changeset
|
442 |
static uint8 LiveryHelper(EngineID engine, const Vehicle *v) |
0d14650b196b
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents:
6490
diff
changeset
|
443 |
{ |
0d14650b196b
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents:
6490
diff
changeset
|
444 |
const Livery *l; |
0d14650b196b
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents:
6490
diff
changeset
|
445 |
|
0d14650b196b
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents:
6490
diff
changeset
|
446 |
if (v == NULL) { |
9652
0405e98d8e96
(svn r13719) -Codechange: rename IsValidPlayer to IsValidPlayerID in line with all other structs/classes that are in a pool.
rubidium
parents:
9472
diff
changeset
|
447 |
if (!IsValidPlayerID(_current_player)) return 0; |
6516
0d14650b196b
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents:
6490
diff
changeset
|
448 |
l = GetEngineLivery(engine, _current_player, INVALID_ENGINE, NULL); |
0d14650b196b
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents:
6490
diff
changeset
|
449 |
} else if (v->type == VEH_TRAIN) { |
0d14650b196b
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents:
6490
diff
changeset
|
450 |
l = GetEngineLivery((v->u.rail.first_engine != INVALID_ENGINE && (IsArticulatedPart(v) || UsesWagonOverride(v))) ? v->u.rail.first_engine : v->engine_type, v->owner, v->u.rail.first_engine, v); |
0d14650b196b
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents:
6490
diff
changeset
|
451 |
} else { |
0d14650b196b
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents:
6490
diff
changeset
|
452 |
l = GetEngineLivery(v->engine_type, v->owner, INVALID_ENGINE, v); |
0d14650b196b
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents:
6490
diff
changeset
|
453 |
} |
0d14650b196b
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents:
6490
diff
changeset
|
454 |
|
0d14650b196b
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents:
6490
diff
changeset
|
455 |
return l->colour1 + l->colour2 * 16; |
0d14650b196b
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents:
6490
diff
changeset
|
456 |
} |
0d14650b196b
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents:
6490
diff
changeset
|
457 |
|
0d14650b196b
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents:
6490
diff
changeset
|
458 |
|
3893
ced26054ee00
(svn r4960) - NewGRF: explicitly handle unsupported variables, instead of returning -1.
peter1138
parents:
3870
diff
changeset
|
459 |
static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, byte parameter, bool *available) |
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
460 |
{ |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
461 |
const Vehicle *v = GRV(object); |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
462 |
|
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
463 |
if (v == NULL) { |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
464 |
/* Vehicle does not exist, so we're in a purchase list */ |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
465 |
switch (variable) { |
6516
0d14650b196b
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents:
6490
diff
changeset
|
466 |
case 0x43: return _current_player | (LiveryHelper(object->u.vehicle.self_type, NULL) << 24); // Owner information |
6348
6dd01da7a02b
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents:
6259
diff
changeset
|
467 |
case 0x46: return 0; // Motion counter |
6dd01da7a02b
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents:
6259
diff
changeset
|
468 |
case 0x48: return GetEngine(object->u.vehicle.self_type)->flags; // Vehicle Type Info |
9459
755259d8f701
(svn r13377) -Codechange: Let 'long format' build year work in vehicle purchase list.
peter1138
parents:
9458
diff
changeset
|
469 |
case 0x49: return _cur_year; // 'Long' format build year |
7922
a7e266f966d9
(svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents:
7881
diff
changeset
|
470 |
case 0xC4: return Clamp(_cur_year, ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR) - ORIGINAL_BASE_YEAR; // Build year |
6348
6dd01da7a02b
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents:
6259
diff
changeset
|
471 |
case 0xDA: return INVALID_VEHICLE; // Next vehicle |
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
472 |
} |
3893
ced26054ee00
(svn r4960) - NewGRF: explicitly handle unsupported variables, instead of returning -1.
peter1138
parents:
3870
diff
changeset
|
473 |
|
ced26054ee00
(svn r4960) - NewGRF: explicitly handle unsupported variables, instead of returning -1.
peter1138
parents:
3870
diff
changeset
|
474 |
*available = false; |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
475 |
return UINT_MAX; |
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
476 |
} |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
477 |
|
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
478 |
/* Calculated vehicle parameters */ |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
479 |
switch (variable) { |
6348
6dd01da7a02b
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents:
6259
diff
changeset
|
480 |
case 0x40: // Get length of consist |
6dd01da7a02b
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents:
6259
diff
changeset
|
481 |
case 0x41: // Get length of same consecutive wagons |
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
482 |
{ |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
483 |
const Vehicle* u; |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
484 |
byte chain_before = 0; |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
485 |
byte chain_after = 0; |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
486 |
|
7497
40e457c0a8ac
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium
parents:
7492
diff
changeset
|
487 |
for (u = v->First(); u != v; u = u->Next()) { |
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
488 |
chain_before++; |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
489 |
if (variable == 0x41 && u->engine_type != v->engine_type) chain_before = 0; |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
490 |
} |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
491 |
|
7492
35acee076719
(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
parents:
7327
diff
changeset
|
492 |
while (u->Next() != NULL && (variable == 0x40 || u->Next()->engine_type == v->engine_type)) { |
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
493 |
chain_after++; |
7492
35acee076719
(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
parents:
7327
diff
changeset
|
494 |
u = u->Next(); |
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
495 |
} |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
496 |
|
5174
0f31845853d3
(svn r7284) -Fix (r2361): off by one when calculating vehicle newgrf variable 41 result, partly blamed by vague documentation... (thanks lakie)
peter1138
parents:
5172
diff
changeset
|
497 |
return chain_before | chain_after << 8 | (chain_before + chain_after + (variable == 0x41)) << 16; |
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
498 |
} |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
499 |
|
6348
6dd01da7a02b
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents:
6259
diff
changeset
|
500 |
case 0x42: { // Consist cargo information |
3843
03f39cd3dc56
(svn r4867) - NewGRF: implement partial support for engine variable 0x42
peter1138
parents:
3785
diff
changeset
|
501 |
const Vehicle *u; |
03f39cd3dc56
(svn r4867) - NewGRF: implement partial support for engine variable 0x42
peter1138
parents:
3785
diff
changeset
|
502 |
byte cargo_classes = 0; |
6822
f3544cc05d18
(svn r10061) -Codechange: [NewGRF] Add common cargo subtype support to vehicle var 42
peter1138
parents:
6621
diff
changeset
|
503 |
uint8 common_cargo_best = 0; |
f3544cc05d18
(svn r10061) -Codechange: [NewGRF] Add common cargo subtype support to vehicle var 42
peter1138
parents:
6621
diff
changeset
|
504 |
uint8 common_cargos[NUM_CARGO]; |
f3544cc05d18
(svn r10061) -Codechange: [NewGRF] Add common cargo subtype support to vehicle var 42
peter1138
parents:
6621
diff
changeset
|
505 |
uint8 common_subtype_best = 0; |
f3544cc05d18
(svn r10061) -Codechange: [NewGRF] Add common cargo subtype support to vehicle var 42
peter1138
parents:
6621
diff
changeset
|
506 |
uint8 common_subtypes[256]; |
3862
fe7b57944a39
(svn r4896) - NewGRF: add support for vehicle property 0x25 (user defined data) used by variable 0x42.
peter1138
parents:
3848
diff
changeset
|
507 |
byte user_def_data = 0; |
6113
a10ede03ac58
(svn r8849) -Codechange: Replace hardcoded global/climate cargo mapping tables with dynamically generated data. Change associated code to use new functions.
peter1138
parents:
6091
diff
changeset
|
508 |
CargoID common_cargo_type = CT_PASSENGERS; |
6822
f3544cc05d18
(svn r10061) -Codechange: [NewGRF] Add common cargo subtype support to vehicle var 42
peter1138
parents:
6621
diff
changeset
|
509 |
uint8 common_subtype = 0; |
3843
03f39cd3dc56
(svn r4867) - NewGRF: implement partial support for engine variable 0x42
peter1138
parents:
3785
diff
changeset
|
510 |
|
03f39cd3dc56
(svn r4867) - NewGRF: implement partial support for engine variable 0x42
peter1138
parents:
3785
diff
changeset
|
511 |
/* Reset our arrays */ |
03f39cd3dc56
(svn r4867) - NewGRF: implement partial support for engine variable 0x42
peter1138
parents:
3785
diff
changeset
|
512 |
memset(common_cargos, 0, sizeof(common_cargos)); |
6822
f3544cc05d18
(svn r10061) -Codechange: [NewGRF] Add common cargo subtype support to vehicle var 42
peter1138
parents:
6621
diff
changeset
|
513 |
memset(common_subtypes, 0, sizeof(common_subtypes)); |
3843
03f39cd3dc56
(svn r4867) - NewGRF: implement partial support for engine variable 0x42
peter1138
parents:
3785
diff
changeset
|
514 |
|
7492
35acee076719
(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
parents:
7327
diff
changeset
|
515 |
for (u = v; u != NULL; u = u->Next()) { |
8654
d5968016055b
(svn r12314) -Fix (r4896): Include prop 25 data for all train parts, not just those that carry cargo.
peter1138
parents:
8614
diff
changeset
|
516 |
if (v->type == VEH_TRAIN) user_def_data |= u->u.rail.user_def_data; |
d5968016055b
(svn r12314) -Fix (r4896): Include prop 25 data for all train parts, not just those that carry cargo.
peter1138
parents:
8614
diff
changeset
|
517 |
|
3843
03f39cd3dc56
(svn r4867) - NewGRF: implement partial support for engine variable 0x42
peter1138
parents:
3785
diff
changeset
|
518 |
/* Skip empty engines */ |
03f39cd3dc56
(svn r4867) - NewGRF: implement partial support for engine variable 0x42
peter1138
parents:
3785
diff
changeset
|
519 |
if (u->cargo_cap == 0) continue; |
6113
a10ede03ac58
(svn r8849) -Codechange: Replace hardcoded global/climate cargo mapping tables with dynamically generated data. Change associated code to use new functions.
peter1138
parents:
6091
diff
changeset
|
520 |
|
a10ede03ac58
(svn r8849) -Codechange: Replace hardcoded global/climate cargo mapping tables with dynamically generated data. Change associated code to use new functions.
peter1138
parents:
6091
diff
changeset
|
521 |
cargo_classes |= GetCargo(u->cargo_type)->classes; |
a10ede03ac58
(svn r8849) -Codechange: Replace hardcoded global/climate cargo mapping tables with dynamically generated data. Change associated code to use new functions.
peter1138
parents:
6091
diff
changeset
|
522 |
common_cargos[u->cargo_type]++; |
6822
f3544cc05d18
(svn r10061) -Codechange: [NewGRF] Add common cargo subtype support to vehicle var 42
peter1138
parents:
6621
diff
changeset
|
523 |
common_subtypes[u->cargo_subtype]++; |
3843
03f39cd3dc56
(svn r4867) - NewGRF: implement partial support for engine variable 0x42
peter1138
parents:
3785
diff
changeset
|
524 |
} |
03f39cd3dc56
(svn r4867) - NewGRF: implement partial support for engine variable 0x42
peter1138
parents:
3785
diff
changeset
|
525 |
|
03f39cd3dc56
(svn r4867) - NewGRF: implement partial support for engine variable 0x42
peter1138
parents:
3785
diff
changeset
|
526 |
/* Pick the most common cargo type */ |
6113
a10ede03ac58
(svn r8849) -Codechange: Replace hardcoded global/climate cargo mapping tables with dynamically generated data. Change associated code to use new functions.
peter1138
parents:
6091
diff
changeset
|
527 |
for (CargoID cargo = 0; cargo < NUM_CARGO; cargo++) { |
3843
03f39cd3dc56
(svn r4867) - NewGRF: implement partial support for engine variable 0x42
peter1138
parents:
3785
diff
changeset
|
528 |
if (common_cargos[cargo] > common_cargo_best) { |
03f39cd3dc56
(svn r4867) - NewGRF: implement partial support for engine variable 0x42
peter1138
parents:
3785
diff
changeset
|
529 |
common_cargo_best = common_cargos[cargo]; |
6113
a10ede03ac58
(svn r8849) -Codechange: Replace hardcoded global/climate cargo mapping tables with dynamically generated data. Change associated code to use new functions.
peter1138
parents:
6091
diff
changeset
|
530 |
common_cargo_type = GetCargo(cargo)->bitnum; |
3843
03f39cd3dc56
(svn r4867) - NewGRF: implement partial support for engine variable 0x42
peter1138
parents:
3785
diff
changeset
|
531 |
} |
03f39cd3dc56
(svn r4867) - NewGRF: implement partial support for engine variable 0x42
peter1138
parents:
3785
diff
changeset
|
532 |
} |
03f39cd3dc56
(svn r4867) - NewGRF: implement partial support for engine variable 0x42
peter1138
parents:
3785
diff
changeset
|
533 |
|
6822
f3544cc05d18
(svn r10061) -Codechange: [NewGRF] Add common cargo subtype support to vehicle var 42
peter1138
parents:
6621
diff
changeset
|
534 |
for (uint i = 0; i < lengthof(common_subtypes); i++) { |
f3544cc05d18
(svn r10061) -Codechange: [NewGRF] Add common cargo subtype support to vehicle var 42
peter1138
parents:
6621
diff
changeset
|
535 |
if (common_subtypes[i] > common_subtype_best) { |
f3544cc05d18
(svn r10061) -Codechange: [NewGRF] Add common cargo subtype support to vehicle var 42
peter1138
parents:
6621
diff
changeset
|
536 |
common_subtype_best = common_subtypes[i]; |
f3544cc05d18
(svn r10061) -Codechange: [NewGRF] Add common cargo subtype support to vehicle var 42
peter1138
parents:
6621
diff
changeset
|
537 |
common_subtype = i; |
f3544cc05d18
(svn r10061) -Codechange: [NewGRF] Add common cargo subtype support to vehicle var 42
peter1138
parents:
6621
diff
changeset
|
538 |
} |
f3544cc05d18
(svn r10061) -Codechange: [NewGRF] Add common cargo subtype support to vehicle var 42
peter1138
parents:
6621
diff
changeset
|
539 |
} |
f3544cc05d18
(svn r10061) -Codechange: [NewGRF] Add common cargo subtype support to vehicle var 42
peter1138
parents:
6621
diff
changeset
|
540 |
|
f3544cc05d18
(svn r10061) -Codechange: [NewGRF] Add common cargo subtype support to vehicle var 42
peter1138
parents:
6621
diff
changeset
|
541 |
return cargo_classes | (common_cargo_type << 8) | (common_subtype << 16) | (user_def_data << 24); |
3843
03f39cd3dc56
(svn r4867) - NewGRF: implement partial support for engine variable 0x42
peter1138
parents:
3785
diff
changeset
|
542 |
} |
03f39cd3dc56
(svn r4867) - NewGRF: implement partial support for engine variable 0x42
peter1138
parents:
3785
diff
changeset
|
543 |
|
6348
6dd01da7a02b
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents:
6259
diff
changeset
|
544 |
case 0x43: // Player information |
6516
0d14650b196b
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents:
6490
diff
changeset
|
545 |
return v->owner | (GetPlayer(v->owner)->is_ai ? 0x10000 : 0) | (LiveryHelper(v->engine_type, v) << 24); |
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
546 |
|
6348
6dd01da7a02b
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents:
6259
diff
changeset
|
547 |
case 0x44: // Aircraft information |
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6248
diff
changeset
|
548 |
if (v->type != VEH_AIRCRAFT) return UINT_MAX; |
3703
3c815d04affb
(svn r4644) - NewGRF: support for variable 0x44, aircraft information. (mart3p)
peter1138
parents:
3702
diff
changeset
|
549 |
|
3c815d04affb
(svn r4644) - NewGRF: support for variable 0x44, aircraft information. (mart3p)
peter1138
parents:
3702
diff
changeset
|
550 |
{ |
7492
35acee076719
(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
parents:
7327
diff
changeset
|
551 |
const Vehicle *w = v->Next(); |
6348
6dd01da7a02b
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents:
6259
diff
changeset
|
552 |
uint16 altitude = v->z_pos - w->z_pos; // Aircraft height - shadow height |
3703
3c815d04affb
(svn r4644) - NewGRF: support for variable 0x44, aircraft information. (mart3p)
peter1138
parents:
3702
diff
changeset
|
553 |
byte airporttype; |
3c815d04affb
(svn r4644) - NewGRF: support for variable 0x44, aircraft information. (mart3p)
peter1138
parents:
3702
diff
changeset
|
554 |
|
3c815d04affb
(svn r4644) - NewGRF: support for variable 0x44, aircraft information. (mart3p)
peter1138
parents:
3702
diff
changeset
|
555 |
switch (GetStation(v->u.air.targetairport)->airport_type) { |
4059
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4058
diff
changeset
|
556 |
/* Note, Helidepot and Helistation are treated as small airports |
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4058
diff
changeset
|
557 |
* as they are at ground level. */ |
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4058
diff
changeset
|
558 |
case AT_HELIDEPOT: |
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4058
diff
changeset
|
559 |
case AT_HELISTATION: |
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4058
diff
changeset
|
560 |
case AT_COMMUTER: |
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4058
diff
changeset
|
561 |
case AT_SMALL: airporttype = ATP_TTDP_SMALL; break; |
3703
3c815d04affb
(svn r4644) - NewGRF: support for variable 0x44, aircraft information. (mart3p)
peter1138
parents:
3702
diff
changeset
|
562 |
case AT_METROPOLITAN: |
3c815d04affb
(svn r4644) - NewGRF: support for variable 0x44, aircraft information. (mart3p)
peter1138
parents:
3702
diff
changeset
|
563 |
case AT_INTERNATIONAL: |
4059
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4058
diff
changeset
|
564 |
case AT_INTERCON: |
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4058
diff
changeset
|
565 |
case AT_LARGE: airporttype = ATP_TTDP_LARGE; break; |
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4058
diff
changeset
|
566 |
case AT_HELIPORT: airporttype = ATP_TTDP_HELIPORT; break; |
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4058
diff
changeset
|
567 |
case AT_OILRIG: airporttype = ATP_TTDP_OILRIG; break; |
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4058
diff
changeset
|
568 |
default: airporttype = ATP_TTDP_LARGE; break; |
3703
3c815d04affb
(svn r4644) - NewGRF: support for variable 0x44, aircraft information. (mart3p)
peter1138
parents:
3702
diff
changeset
|
569 |
} |
3c815d04affb
(svn r4644) - NewGRF: support for variable 0x44, aircraft information. (mart3p)
peter1138
parents:
3702
diff
changeset
|
570 |
|
3c815d04affb
(svn r4644) - NewGRF: support for variable 0x44, aircraft information. (mart3p)
peter1138
parents:
3702
diff
changeset
|
571 |
return (altitude << 8) | airporttype; |
3c815d04affb
(svn r4644) - NewGRF: support for variable 0x44, aircraft information. (mart3p)
peter1138
parents:
3702
diff
changeset
|
572 |
} |
3c815d04affb
(svn r4644) - NewGRF: support for variable 0x44, aircraft information. (mart3p)
peter1138
parents:
3702
diff
changeset
|
573 |
|
6589
8e4f5d2de99a
(svn r9803) -Feature(tte): support for "curvature info", Action 2 for train, variable 45 (mart3p).
rubidium
parents:
6517
diff
changeset
|
574 |
case 0x45: { // Curvature info |
8e4f5d2de99a
(svn r9803) -Feature(tte): support for "curvature info", Action 2 for train, variable 45 (mart3p).
rubidium
parents:
6517
diff
changeset
|
575 |
/* Format: xxxTxBxF |
8e4f5d2de99a
(svn r9803) -Feature(tte): support for "curvature info", Action 2 for train, variable 45 (mart3p).
rubidium
parents:
6517
diff
changeset
|
576 |
* F - previous wagon to current wagon, 0 if vehicle is first |
8e4f5d2de99a
(svn r9803) -Feature(tte): support for "curvature info", Action 2 for train, variable 45 (mart3p).
rubidium
parents:
6517
diff
changeset
|
577 |
* B - current wagon to next wagon, 0 if wagon is last |
8e4f5d2de99a
(svn r9803) -Feature(tte): support for "curvature info", Action 2 for train, variable 45 (mart3p).
rubidium
parents:
6517
diff
changeset
|
578 |
* T - previous wagon to next wagon, 0 in an S-bend |
8e4f5d2de99a
(svn r9803) -Feature(tte): support for "curvature info", Action 2 for train, variable 45 (mart3p).
rubidium
parents:
6517
diff
changeset
|
579 |
*/ |
8e4f5d2de99a
(svn r9803) -Feature(tte): support for "curvature info", Action 2 for train, variable 45 (mart3p).
rubidium
parents:
6517
diff
changeset
|
580 |
if (v->type != VEH_TRAIN) return 0; |
8e4f5d2de99a
(svn r9803) -Feature(tte): support for "curvature info", Action 2 for train, variable 45 (mart3p).
rubidium
parents:
6517
diff
changeset
|
581 |
|
7497
40e457c0a8ac
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium
parents:
7492
diff
changeset
|
582 |
const Vehicle *u_p = v->Previous(); |
7492
35acee076719
(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
parents:
7327
diff
changeset
|
583 |
const Vehicle *u_n = v->Next(); |
6589
8e4f5d2de99a
(svn r9803) -Feature(tte): support for "curvature info", Action 2 for train, variable 45 (mart3p).
rubidium
parents:
6517
diff
changeset
|
584 |
DirDiff f = (u_p == NULL) ? DIRDIFF_SAME : DirDifference(u_p->direction, v->direction); |
8e4f5d2de99a
(svn r9803) -Feature(tte): support for "curvature info", Action 2 for train, variable 45 (mart3p).
rubidium
parents:
6517
diff
changeset
|
585 |
DirDiff b = (u_n == NULL) ? DIRDIFF_SAME : DirDifference(v->direction, u_n->direction); |
8e4f5d2de99a
(svn r9803) -Feature(tte): support for "curvature info", Action 2 for train, variable 45 (mart3p).
rubidium
parents:
6517
diff
changeset
|
586 |
DirDiff t = ChangeDirDiff(f, b); |
8e4f5d2de99a
(svn r9803) -Feature(tte): support for "curvature info", Action 2 for train, variable 45 (mart3p).
rubidium
parents:
6517
diff
changeset
|
587 |
|
8e4f5d2de99a
(svn r9803) -Feature(tte): support for "curvature info", Action 2 for train, variable 45 (mart3p).
rubidium
parents:
6517
diff
changeset
|
588 |
return ((t > DIRDIFF_REVERSE ? t | 8 : t) << 16) | |
8e4f5d2de99a
(svn r9803) -Feature(tte): support for "curvature info", Action 2 for train, variable 45 (mart3p).
rubidium
parents:
6517
diff
changeset
|
589 |
((b > DIRDIFF_REVERSE ? b | 8 : b) << 8) | |
8e4f5d2de99a
(svn r9803) -Feature(tte): support for "curvature info", Action 2 for train, variable 45 (mart3p).
rubidium
parents:
6517
diff
changeset
|
590 |
( f > DIRDIFF_REVERSE ? f | 8 : f); |
8e4f5d2de99a
(svn r9803) -Feature(tte): support for "curvature info", Action 2 for train, variable 45 (mart3p).
rubidium
parents:
6517
diff
changeset
|
591 |
} |
8e4f5d2de99a
(svn r9803) -Feature(tte): support for "curvature info", Action 2 for train, variable 45 (mart3p).
rubidium
parents:
6517
diff
changeset
|
592 |
|
6348
6dd01da7a02b
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents:
6259
diff
changeset
|
593 |
case 0x46: // Motion counter |
4656
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4331
diff
changeset
|
594 |
return v->motion_counter; |
3723
efb172c37d8c
(svn r4696) - NewGRF: add support for vehicle variable 0x60, count vehicle type occurance.
peter1138
parents:
3720
diff
changeset
|
595 |
|
6348
6dd01da7a02b
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents:
6259
diff
changeset
|
596 |
case 0x47: { // Vehicle cargo info |
3848
ad94e6144369
(svn r4872) - NewGRF: add support for vehicle variable 0x47 (mart3p)
peter1138
parents:
3845
diff
changeset
|
597 |
/* Format: ccccwwtt |
ad94e6144369
(svn r4872) - NewGRF: add support for vehicle variable 0x47 (mart3p)
peter1138
parents:
3845
diff
changeset
|
598 |
* tt - the cargo type transported by the vehicle, |
ad94e6144369
(svn r4872) - NewGRF: add support for vehicle variable 0x47 (mart3p)
peter1138
parents:
3845
diff
changeset
|
599 |
* translated if a translation table has been installed. |
ad94e6144369
(svn r4872) - NewGRF: add support for vehicle variable 0x47 (mart3p)
peter1138
parents:
3845
diff
changeset
|
600 |
* ww - cargo unit weight in 1/16 tons, same as cargo prop. 0F. |
ad94e6144369
(svn r4872) - NewGRF: add support for vehicle variable 0x47 (mart3p)
peter1138
parents:
3845
diff
changeset
|
601 |
* cccc - the cargo class value of the cargo transported by the vehicle. |
ad94e6144369
(svn r4872) - NewGRF: add support for vehicle variable 0x47 (mart3p)
peter1138
parents:
3845
diff
changeset
|
602 |
*/ |
6091
c8827d9ae04a
(svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138
parents:
6032
diff
changeset
|
603 |
const CargoSpec *cs = GetCargo(v->cargo_type); |
3848
ad94e6144369
(svn r4872) - NewGRF: add support for vehicle variable 0x47 (mart3p)
peter1138
parents:
3845
diff
changeset
|
604 |
|
6147
ee050ca3889f
(svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents:
6126
diff
changeset
|
605 |
return (cs->classes << 16) | (cs->weight << 8) | GetEngineGRF(v->engine_type)->cargo_map[v->cargo_type]; |
3848
ad94e6144369
(svn r4872) - NewGRF: add support for vehicle variable 0x47 (mart3p)
peter1138
parents:
3845
diff
changeset
|
606 |
} |
ad94e6144369
(svn r4872) - NewGRF: add support for vehicle variable 0x47 (mart3p)
peter1138
parents:
3845
diff
changeset
|
607 |
|
6348
6dd01da7a02b
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents:
6259
diff
changeset
|
608 |
case 0x48: return GetEngine(v->engine_type)->flags; // Vehicle Type Info |
9458
9b2af80a696f
(svn r13376) -Feature: Add access to current long year and date from Action 7/9/D and VarAction2 (23/24 or A3/A4)
belugas
parents:
9436
diff
changeset
|
609 |
case 0x49: return v->build_year; |
4058
7d1e904e79b5
(svn r5338) - NewGRF: add support for vehicle variable 48, vehicle type info (more mart3p)
peter1138
parents:
4057
diff
changeset
|
610 |
|
3723
efb172c37d8c
(svn r4696) - NewGRF: add support for vehicle variable 0x60, count vehicle type occurance.
peter1138
parents:
3720
diff
changeset
|
611 |
/* Variables which use the parameter */ |
6348
6dd01da7a02b
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents:
6259
diff
changeset
|
612 |
case 0x60: // Count consist's engine ID occurance |
9070
dd0121143eba
(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
parents:
9062
diff
changeset
|
613 |
//EngineID engine = GetNewEngineID(GetEngineGRF(v->engine_type), v->type, parameter); |
dd0121143eba
(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
parents:
9062
diff
changeset
|
614 |
if (v->type != VEH_TRAIN) return GetEngine(v->engine_type)->internal_id == parameter; |
3723
efb172c37d8c
(svn r4696) - NewGRF: add support for vehicle variable 0x60, count vehicle type occurance.
peter1138
parents:
3720
diff
changeset
|
615 |
|
efb172c37d8c
(svn r4696) - NewGRF: add support for vehicle variable 0x60, count vehicle type occurance.
peter1138
parents:
3720
diff
changeset
|
616 |
{ |
efb172c37d8c
(svn r4696) - NewGRF: add support for vehicle variable 0x60, count vehicle type occurance.
peter1138
parents:
3720
diff
changeset
|
617 |
uint count = 0; |
7492
35acee076719
(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
parents:
7327
diff
changeset
|
618 |
for (; v != NULL; v = v->Next()) { |
9070
dd0121143eba
(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
parents:
9062
diff
changeset
|
619 |
if (GetEngine(v->engine_type)->internal_id == parameter) count++; |
3723
efb172c37d8c
(svn r4696) - NewGRF: add support for vehicle variable 0x60, count vehicle type occurance.
peter1138
parents:
3720
diff
changeset
|
620 |
} |
efb172c37d8c
(svn r4696) - NewGRF: add support for vehicle variable 0x60, count vehicle type occurance.
peter1138
parents:
3720
diff
changeset
|
621 |
return count; |
efb172c37d8c
(svn r4696) - NewGRF: add support for vehicle variable 0x60, count vehicle type occurance.
peter1138
parents:
3720
diff
changeset
|
622 |
} |
3925
80f987b4c2e2
(svn r5060) - NewGRF: add support for variable 7F (retrieve GRF parameter) for vehicles
peter1138
parents:
3924
diff
changeset
|
623 |
|
6176
153f0f24dc1b
(svn r8946) -Feature: [NewGRF] Add support for vehicle variables 0xFE and 0xFF bit 10,
maedhros
parents:
6173
diff
changeset
|
624 |
case 0xFE: |
153f0f24dc1b
(svn r8946) -Feature: [NewGRF] Add support for vehicle variables 0xFE and 0xFF bit 10,
maedhros
parents:
6173
diff
changeset
|
625 |
case 0xFF: { |
153f0f24dc1b
(svn r8946) -Feature: [NewGRF] Add support for vehicle variables 0xFE and 0xFF bit 10,
maedhros
parents:
6173
diff
changeset
|
626 |
uint16 modflags = 0; |
153f0f24dc1b
(svn r8946) -Feature: [NewGRF] Add support for vehicle variables 0xFE and 0xFF bit 10,
maedhros
parents:
6173
diff
changeset
|
627 |
|
8665
1afa0aa5b77f
(svn r12330) -Feature: [NewGRF] vehicle variable FE bit 5 and 6
glx
parents:
8654
diff
changeset
|
628 |
if (v->type == VEH_TRAIN) { |
1afa0aa5b77f
(svn r12330) -Feature: [NewGRF] vehicle variable FE bit 5 and 6
glx
parents:
8654
diff
changeset
|
629 |
const Vehicle *u = IsTrainWagon(v) && HasBit(v->vehicle_flags, VRF_POWEREDWAGON) ? v->First() : v; |
1afa0aa5b77f
(svn r12330) -Feature: [NewGRF] vehicle variable FE bit 5 and 6
glx
parents:
8654
diff
changeset
|
630 |
RailType railtype = GetRailType(v->tile); |
1afa0aa5b77f
(svn r12330) -Feature: [NewGRF] vehicle variable FE bit 5 and 6
glx
parents:
8654
diff
changeset
|
631 |
bool powered = IsTrainEngine(v) || (IsTrainWagon(v) && HasBit(v->vehicle_flags, VRF_POWEREDWAGON)); |
1afa0aa5b77f
(svn r12330) -Feature: [NewGRF] vehicle variable FE bit 5 and 6
glx
parents:
8654
diff
changeset
|
632 |
bool has_power = powered && HasPowerOnRail(u->u.rail.railtype, railtype); |
1afa0aa5b77f
(svn r12330) -Feature: [NewGRF] vehicle variable FE bit 5 and 6
glx
parents:
8654
diff
changeset
|
633 |
bool is_electric = powered && u->u.rail.railtype == RAILTYPE_ELECTRIC; |
8666
e3ee55ec96bb
(svn r12331) -Feature: [NewGRF] vehicle variable FE bit 8
glx
parents:
8665
diff
changeset
|
634 |
|
8665
1afa0aa5b77f
(svn r12330) -Feature: [NewGRF] vehicle variable FE bit 5 and 6
glx
parents:
8654
diff
changeset
|
635 |
if (has_power) SetBit(modflags, 5); |
1afa0aa5b77f
(svn r12330) -Feature: [NewGRF] vehicle variable FE bit 5 and 6
glx
parents:
8654
diff
changeset
|
636 |
if (is_electric && !has_power) SetBit(modflags, 6); |
8666
e3ee55ec96bb
(svn r12331) -Feature: [NewGRF] vehicle variable FE bit 8
glx
parents:
8665
diff
changeset
|
637 |
if (HasBit(v->u.rail.flags, VRF_TOGGLE_REVERSE)) SetBit(modflags, 8); |
8665
1afa0aa5b77f
(svn r12330) -Feature: [NewGRF] vehicle variable FE bit 5 and 6
glx
parents:
8654
diff
changeset
|
638 |
} |
7931
b0a46cd92225
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents:
7928
diff
changeset
|
639 |
if (HasBit(v->vehicle_flags, VF_BUILT_AS_PROTOTYPE)) SetBit(modflags, 10); |
6176
153f0f24dc1b
(svn r8946) -Feature: [NewGRF] Add support for vehicle variables 0xFE and 0xFF bit 10,
maedhros
parents:
6173
diff
changeset
|
640 |
|
153f0f24dc1b
(svn r8946) -Feature: [NewGRF] Add support for vehicle variables 0xFE and 0xFF bit 10,
maedhros
parents:
6173
diff
changeset
|
641 |
return variable == 0xFE ? modflags : GB(modflags, 8, 8); |
153f0f24dc1b
(svn r8946) -Feature: [NewGRF] Add support for vehicle variables 0xFE and 0xFF bit 10,
maedhros
parents:
6173
diff
changeset
|
642 |
} |
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
643 |
} |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
644 |
|
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
645 |
/* General vehicle properties */ |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
646 |
switch (variable - 0x80) { |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
647 |
case 0x00: return v->type; |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
648 |
case 0x01: return MapOldSubType(v); |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
649 |
case 0x04: return v->index; |
5172
285d1ab82403
(svn r7282) -Fix (r625): ttdpatch vars are little endian
peter1138
parents:
4901
diff
changeset
|
650 |
case 0x05: return GB(v->index, 8, 8); |
8839
6337281b393b
(svn r12587) -Codechange: unduplicate some code in the Unpack*Order functions and move the 'normal' case Pack/Unpack to Order.
rubidium
parents:
8836
diff
changeset
|
651 |
case 0x0A: return v->current_order.Pack(); |
6337281b393b
(svn r12587) -Codechange: unduplicate some code in the Unpack*Order functions and move the 'normal' case Pack/Unpack to Order.
rubidium
parents:
8836
diff
changeset
|
652 |
case 0x0B: return GB(v->current_order.Pack(), 8, 8); |
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
653 |
case 0x0C: return v->num_orders; |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
654 |
case 0x0D: return v->cur_order_index; |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
655 |
case 0x10: return v->load_unload_time_rem; |
5172
285d1ab82403
(svn r7282) -Fix (r625): ttdpatch vars are little endian
peter1138
parents:
4901
diff
changeset
|
656 |
case 0x11: return GB(v->load_unload_time_rem, 8, 8); |
4331
ec584824ffb8
(svn r6013) -Fix: some newgrf properties returned the date in the new format where the newgrf's expect the original format. Thanks to michi_cc for finding these and providing the initial patch.
rubidium
parents:
4322
diff
changeset
|
657 |
case 0x12: return max(v->date_of_last_service - DAYS_TILL_ORIGINAL_BASE_YEAR, 0); |
5172
285d1ab82403
(svn r7282) -Fix (r625): ttdpatch vars are little endian
peter1138
parents:
4901
diff
changeset
|
658 |
case 0x13: return GB(max(v->date_of_last_service - DAYS_TILL_ORIGINAL_BASE_YEAR, 0), 8, 8); |
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
659 |
case 0x14: return v->service_interval; |
5172
285d1ab82403
(svn r7282) -Fix (r625): ttdpatch vars are little endian
peter1138
parents:
4901
diff
changeset
|
660 |
case 0x15: return GB(v->service_interval, 8, 8); |
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
661 |
case 0x16: return v->last_station_visited; |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
662 |
case 0x17: return v->tick_counter; |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
663 |
case 0x18: return v->max_speed; |
5172
285d1ab82403
(svn r7282) -Fix (r625): ttdpatch vars are little endian
peter1138
parents:
4901
diff
changeset
|
664 |
case 0x19: return GB(v->max_speed, 8, 8); |
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
665 |
case 0x1A: return v->x_pos; |
5172
285d1ab82403
(svn r7282) -Fix (r625): ttdpatch vars are little endian
peter1138
parents:
4901
diff
changeset
|
666 |
case 0x1B: return GB(v->x_pos, 8, 8); |
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
667 |
case 0x1C: return v->y_pos; |
5172
285d1ab82403
(svn r7282) -Fix (r625): ttdpatch vars are little endian
peter1138
parents:
4901
diff
changeset
|
668 |
case 0x1D: return GB(v->y_pos, 8, 8); |
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
669 |
case 0x1E: return v->z_pos; |
4056
7899dc230a12
(svn r5336) - NewGRF: draw custom helicopter rotor sprites in vehicle info window, ensuring the correct direction is used (inspiration from mart3p)
peter1138
parents:
4055
diff
changeset
|
670 |
case 0x1F: return object->info_view ? DIR_W : v->direction; |
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
671 |
case 0x28: return v->cur_image; |
5172
285d1ab82403
(svn r7282) -Fix (r625): ttdpatch vars are little endian
peter1138
parents:
4901
diff
changeset
|
672 |
case 0x29: return GB(v->cur_image, 8, 8); |
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
673 |
case 0x32: return v->vehstatus; |
5175
e528d197bbdd
(svn r7285) -Fix (r7282): Our vehstatus is a byte, not a word.
peter1138
parents:
5174
diff
changeset
|
674 |
case 0x33: return 0; // non-existent high byte of vehstatus |
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
675 |
case 0x34: return v->cur_speed; |
5172
285d1ab82403
(svn r7282) -Fix (r625): ttdpatch vars are little endian
peter1138
parents:
4901
diff
changeset
|
676 |
case 0x35: return GB(v->cur_speed, 8, 8); |
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
677 |
case 0x36: return v->subspeed; |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
678 |
case 0x37: return v->acceleration; |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
679 |
case 0x39: return v->cargo_type; |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
680 |
case 0x3A: return v->cargo_cap; |
5172
285d1ab82403
(svn r7282) -Fix (r625): ttdpatch vars are little endian
peter1138
parents:
4901
diff
changeset
|
681 |
case 0x3B: return GB(v->cargo_cap, 8, 8); |
7010
6f0d9f03180d
(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
parents:
6990
diff
changeset
|
682 |
case 0x3C: return v->cargo.Count(); |
6f0d9f03180d
(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
parents:
6990
diff
changeset
|
683 |
case 0x3D: return GB(v->cargo.Count(), 8, 8); |
6f0d9f03180d
(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
parents:
6990
diff
changeset
|
684 |
case 0x3E: return v->cargo.Source(); |
6f0d9f03180d
(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
parents:
6990
diff
changeset
|
685 |
case 0x3F: return v->cargo.DaysInTransit(); |
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
686 |
case 0x40: return v->age; |
5172
285d1ab82403
(svn r7282) -Fix (r625): ttdpatch vars are little endian
peter1138
parents:
4901
diff
changeset
|
687 |
case 0x41: return GB(v->age, 8, 8); |
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
688 |
case 0x42: return v->max_age; |
5172
285d1ab82403
(svn r7282) -Fix (r625): ttdpatch vars are little endian
peter1138
parents:
4901
diff
changeset
|
689 |
case 0x43: return GB(v->max_age, 8, 8); |
7922
a7e266f966d9
(svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents:
7881
diff
changeset
|
690 |
case 0x44: return Clamp(v->build_year, ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR) - ORIGINAL_BASE_YEAR; |
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
691 |
case 0x45: return v->unitnumber; |
9070
dd0121143eba
(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
parents:
9062
diff
changeset
|
692 |
case 0x46: return GetEngine(v->engine_type)->internal_id; |
dd0121143eba
(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
parents:
9062
diff
changeset
|
693 |
case 0x47: return GB(GetEngine(v->engine_type)->internal_id, 8, 8); |
9059
8a44f3e58eaf
(svn r12910) -Fix: Report reverse sprite status (FD/FE) to NewGRF for manually toggled vehicles.
peter1138
parents:
9046
diff
changeset
|
694 |
case 0x48: |
8a44f3e58eaf
(svn r12910) -Fix: Report reverse sprite status (FD/FE) to NewGRF for manually toggled vehicles.
peter1138
parents:
9046
diff
changeset
|
695 |
if (v->type != VEH_TRAIN || v->spritenum != 0xFD) return v->spritenum; |
8a44f3e58eaf
(svn r12910) -Fix: Report reverse sprite status (FD/FE) to NewGRF for manually toggled vehicles.
peter1138
parents:
9046
diff
changeset
|
696 |
return HasBit(v->u.rail.flags, VRF_REVERSE_DIRECTION) ? 0xFE : 0xFD; |
8a44f3e58eaf
(svn r12910) -Fix: Report reverse sprite status (FD/FE) to NewGRF for manually toggled vehicles.
peter1138
parents:
9046
diff
changeset
|
697 |
|
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
698 |
case 0x49: return v->day_counter; |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
699 |
case 0x4A: return v->breakdowns_since_last_service; |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
700 |
case 0x4B: return v->breakdown_ctr; |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
701 |
case 0x4C: return v->breakdown_delay; |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
702 |
case 0x4D: return v->breakdown_chance; |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
703 |
case 0x4E: return v->reliability; |
5172
285d1ab82403
(svn r7282) -Fix (r625): ttdpatch vars are little endian
peter1138
parents:
4901
diff
changeset
|
704 |
case 0x4F: return GB(v->reliability, 8, 8); |
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
705 |
case 0x50: return v->reliability_spd_dec; |
5172
285d1ab82403
(svn r7282) -Fix (r625): ttdpatch vars are little endian
peter1138
parents:
4901
diff
changeset
|
706 |
case 0x51: return GB(v->reliability_spd_dec, 8, 8); |
8614
4c67a883c4c4
(svn r12197) -Fix [FS#1788](r12134): show correct last year profit when the train had negative income
smatz
parents:
8599
diff
changeset
|
707 |
case 0x52: return ClampToI32(v->GetDisplayProfitThisYear()); |
4c67a883c4c4
(svn r12197) -Fix [FS#1788](r12134): show correct last year profit when the train had negative income
smatz
parents:
8599
diff
changeset
|
708 |
case 0x53: return GB(ClampToI32(v->GetDisplayProfitThisYear()), 8, 24); |
4c67a883c4c4
(svn r12197) -Fix [FS#1788](r12134): show correct last year profit when the train had negative income
smatz
parents:
8599
diff
changeset
|
709 |
case 0x54: return GB(ClampToI32(v->GetDisplayProfitThisYear()), 16, 16); |
4c67a883c4c4
(svn r12197) -Fix [FS#1788](r12134): show correct last year profit when the train had negative income
smatz
parents:
8599
diff
changeset
|
710 |
case 0x55: return GB(ClampToI32(v->GetDisplayProfitThisYear()), 24, 8); |
4c67a883c4c4
(svn r12197) -Fix [FS#1788](r12134): show correct last year profit when the train had negative income
smatz
parents:
8599
diff
changeset
|
711 |
case 0x56: return ClampToI32(v->GetDisplayProfitLastYear()); |
4c67a883c4c4
(svn r12197) -Fix [FS#1788](r12134): show correct last year profit when the train had negative income
smatz
parents:
8599
diff
changeset
|
712 |
case 0x57: return GB(ClampToI32(v->GetDisplayProfitLastYear()), 8, 24); |
4c67a883c4c4
(svn r12197) -Fix [FS#1788](r12134): show correct last year profit when the train had negative income
smatz
parents:
8599
diff
changeset
|
713 |
case 0x58: return GB(ClampToI32(v->GetDisplayProfitLastYear()), 16, 16); |
4c67a883c4c4
(svn r12197) -Fix [FS#1788](r12134): show correct last year profit when the train had negative income
smatz
parents:
8599
diff
changeset
|
714 |
case 0x59: return GB(ClampToI32(v->GetDisplayProfitLastYear()), 24, 8); |
7492
35acee076719
(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
parents:
7327
diff
changeset
|
715 |
case 0x5A: return v->Next() == NULL ? INVALID_VEHICLE : v->Next()->index; |
6990
136a08baf0ed
(svn r10246) -Fix (r10297): some forgotten money conversions and truncation issues. Thanks to benc for providing the patch.
rubidium
parents:
6912
diff
changeset
|
716 |
case 0x5C: return ClampToI32(v->value); |
136a08baf0ed
(svn r10246) -Fix (r10297): some forgotten money conversions and truncation issues. Thanks to benc for providing the patch.
rubidium
parents:
6912
diff
changeset
|
717 |
case 0x5D: return GB(ClampToI32(v->value), 8, 24); |
136a08baf0ed
(svn r10246) -Fix (r10297): some forgotten money conversions and truncation issues. Thanks to benc for providing the patch.
rubidium
parents:
6912
diff
changeset
|
718 |
case 0x5E: return GB(ClampToI32(v->value), 16, 16); |
136a08baf0ed
(svn r10246) -Fix (r10297): some forgotten money conversions and truncation issues. Thanks to benc for providing the patch.
rubidium
parents:
6912
diff
changeset
|
719 |
case 0x5F: return GB(ClampToI32(v->value), 24, 8); |
3870
d9ebc4ea750a
(svn r4910) - NewGRF: add and initialize cargo subtype for vehicle visual variations
peter1138
parents:
3866
diff
changeset
|
720 |
case 0x72: return v->cargo_subtype; |
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
721 |
case 0x7A: return v->random_bits; |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
722 |
case 0x7B: return v->waiting_triggers; |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
723 |
} |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
724 |
|
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
725 |
/* Vehicle specific properties */ |
3014
1a60d4541d3c
(svn r3594) - NewGRF: Add support for some vehicle specific properties and a give a debug message for unknown variables.
peter1138
parents:
2982
diff
changeset
|
726 |
switch (v->type) { |
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6248
diff
changeset
|
727 |
case VEH_TRAIN: |
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
728 |
switch (variable - 0x80) { |
3014
1a60d4541d3c
(svn r3594) - NewGRF: Add support for some vehicle specific properties and a give a debug message for unknown variables.
peter1138
parents:
2982
diff
changeset
|
729 |
case 0x62: return v->u.rail.track; |
1a60d4541d3c
(svn r3594) - NewGRF: Add support for some vehicle specific properties and a give a debug message for unknown variables.
peter1138
parents:
2982
diff
changeset
|
730 |
case 0x66: return v->u.rail.railtype; |
1a60d4541d3c
(svn r3594) - NewGRF: Add support for some vehicle specific properties and a give a debug message for unknown variables.
peter1138
parents:
2982
diff
changeset
|
731 |
case 0x73: return v->u.rail.cached_veh_length; |
1a60d4541d3c
(svn r3594) - NewGRF: Add support for some vehicle specific properties and a give a debug message for unknown variables.
peter1138
parents:
2982
diff
changeset
|
732 |
case 0x74: return v->u.rail.cached_power; |
5172
285d1ab82403
(svn r7282) -Fix (r625): ttdpatch vars are little endian
peter1138
parents:
4901
diff
changeset
|
733 |
case 0x75: return GB(v->u.rail.cached_power, 8, 24); |
285d1ab82403
(svn r7282) -Fix (r625): ttdpatch vars are little endian
peter1138
parents:
4901
diff
changeset
|
734 |
case 0x76: return GB(v->u.rail.cached_power, 16, 16); |
285d1ab82403
(svn r7282) -Fix (r625): ttdpatch vars are little endian
peter1138
parents:
4901
diff
changeset
|
735 |
case 0x77: return GB(v->u.rail.cached_power, 24, 8); |
7497
40e457c0a8ac
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium
parents:
7492
diff
changeset
|
736 |
case 0x7C: return v->First()->index; |
40e457c0a8ac
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium
parents:
7492
diff
changeset
|
737 |
case 0x7D: return GB(v->First()->index, 8, 8); |
4050
012c308c2870
(svn r5320) - NewGRF: make sets using TTDPatch's train reversing hack/feature happier (and consistent) by returning 0 for the flag it uses.
peter1138
parents:
4023
diff
changeset
|
738 |
case 0x7F: return 0; // Used for vehicle reversing hack in TTDP |
3014
1a60d4541d3c
(svn r3594) - NewGRF: Add support for some vehicle specific properties and a give a debug message for unknown variables.
peter1138
parents:
2982
diff
changeset
|
739 |
} |
1a60d4541d3c
(svn r3594) - NewGRF: Add support for some vehicle specific properties and a give a debug message for unknown variables.
peter1138
parents:
2982
diff
changeset
|
740 |
break; |
1a60d4541d3c
(svn r3594) - NewGRF: Add support for some vehicle specific properties and a give a debug message for unknown variables.
peter1138
parents:
2982
diff
changeset
|
741 |
|
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6248
diff
changeset
|
742 |
case VEH_ROAD: |
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
743 |
switch (variable - 0x80) { |
3014
1a60d4541d3c
(svn r3594) - NewGRF: Add support for some vehicle specific properties and a give a debug message for unknown variables.
peter1138
parents:
2982
diff
changeset
|
744 |
case 0x62: return v->u.road.state; |
1a60d4541d3c
(svn r3594) - NewGRF: Add support for some vehicle specific properties and a give a debug message for unknown variables.
peter1138
parents:
2982
diff
changeset
|
745 |
case 0x64: return v->u.road.blocked_ctr; |
5172
285d1ab82403
(svn r7282) -Fix (r625): ttdpatch vars are little endian
peter1138
parents:
4901
diff
changeset
|
746 |
case 0x65: return GB(v->u.road.blocked_ctr, 8, 8); |
3014
1a60d4541d3c
(svn r3594) - NewGRF: Add support for some vehicle specific properties and a give a debug message for unknown variables.
peter1138
parents:
2982
diff
changeset
|
747 |
case 0x66: return v->u.road.overtaking; |
1a60d4541d3c
(svn r3594) - NewGRF: Add support for some vehicle specific properties and a give a debug message for unknown variables.
peter1138
parents:
2982
diff
changeset
|
748 |
case 0x67: return v->u.road.overtaking_ctr; |
1a60d4541d3c
(svn r3594) - NewGRF: Add support for some vehicle specific properties and a give a debug message for unknown variables.
peter1138
parents:
2982
diff
changeset
|
749 |
case 0x68: return v->u.road.crashed_ctr; |
5172
285d1ab82403
(svn r7282) -Fix (r625): ttdpatch vars are little endian
peter1138
parents:
4901
diff
changeset
|
750 |
case 0x69: return GB(v->u.road.crashed_ctr, 8, 8); |
3014
1a60d4541d3c
(svn r3594) - NewGRF: Add support for some vehicle specific properties and a give a debug message for unknown variables.
peter1138
parents:
2982
diff
changeset
|
751 |
} |
1a60d4541d3c
(svn r3594) - NewGRF: Add support for some vehicle specific properties and a give a debug message for unknown variables.
peter1138
parents:
2982
diff
changeset
|
752 |
break; |
1a60d4541d3c
(svn r3594) - NewGRF: Add support for some vehicle specific properties and a give a debug message for unknown variables.
peter1138
parents:
2982
diff
changeset
|
753 |
|
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6248
diff
changeset
|
754 |
case VEH_AIRCRAFT: |
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
755 |
switch (variable - 0x80) { |
3702
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
756 |
case 0x62: return MapAircraftMovementState(v); // Current movement state |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
757 |
case 0x63: return v->u.air.targetairport; // Airport to which the action refers |
219fc5d61455
(svn r4643) - NewGRF: Add support for ttdp aircraft states. This involves mapping from our own state. (heavily based on mart3p's code)
peter1138
parents:
3696
diff
changeset
|
758 |
case 0x66: return MapAircraftMovementAction(v); // Current movement action |
3014
1a60d4541d3c
(svn r3594) - NewGRF: Add support for some vehicle specific properties and a give a debug message for unknown variables.
peter1138
parents:
2982
diff
changeset
|
759 |
} |
1a60d4541d3c
(svn r3594) - NewGRF: Add support for some vehicle specific properties and a give a debug message for unknown variables.
peter1138
parents:
2982
diff
changeset
|
760 |
break; |
6621
441559124aea
(svn r9841) -Codechange: add a little more type strictness to the vehicle types.
rubidium
parents:
6604
diff
changeset
|
761 |
|
441559124aea
(svn r9841) -Codechange: add a little more type strictness to the vehicle types.
rubidium
parents:
6604
diff
changeset
|
762 |
default: break; |
3014
1a60d4541d3c
(svn r3594) - NewGRF: Add support for some vehicle specific properties and a give a debug message for unknown variables.
peter1138
parents:
2982
diff
changeset
|
763 |
} |
1a60d4541d3c
(svn r3594) - NewGRF: Add support for some vehicle specific properties and a give a debug message for unknown variables.
peter1138
parents:
2982
diff
changeset
|
764 |
|
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5338
diff
changeset
|
765 |
DEBUG(grf, 1, "Unhandled vehicle property 0x%X, type 0x%X", variable, v->type); |
3014
1a60d4541d3c
(svn r3594) - NewGRF: Add support for some vehicle specific properties and a give a debug message for unknown variables.
peter1138
parents:
2982
diff
changeset
|
766 |
|
3893
ced26054ee00
(svn r4960) - NewGRF: explicitly handle unsupported variables, instead of returning -1.
peter1138
parents:
3870
diff
changeset
|
767 |
*available = false; |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
768 |
return UINT_MAX; |
3014
1a60d4541d3c
(svn r3594) - NewGRF: Add support for some vehicle specific properties and a give a debug message for unknown variables.
peter1138
parents:
2982
diff
changeset
|
769 |
} |
1a60d4541d3c
(svn r3594) - NewGRF: Add support for some vehicle specific properties and a give a debug message for unknown variables.
peter1138
parents:
2982
diff
changeset
|
770 |
|
426
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
771 |
|
3734
5b331306e6fe
(svn r4714) - NewGRF: simplify evaluation of 'real' sprite groups.
peter1138
parents:
3731
diff
changeset
|
772 |
static const SpriteGroup *VehicleResolveReal(const ResolverObject *object, const SpriteGroup *group) |
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
773 |
{ |
3720
8a82d64ea485
(svn r4691) - Codechange: don't use unnamed unions as GCC 2.95.ancient won't compile it. Needed for our MorphOS user ;)
peter1138
parents:
3706
diff
changeset
|
774 |
const Vehicle *v = object->u.vehicle.self; |
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
775 |
uint totalsets; |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
776 |
uint set; |
426
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
777 |
|
8599
35ed84aec9f4
(svn r12180) -Fix: Test purchase list loading/loaded sprites instead of unconditionally returning a possibly non-existant sprite.
peter1138
parents:
8556
diff
changeset
|
778 |
if (v == NULL) { |
35ed84aec9f4
(svn r12180) -Fix: Test purchase list loading/loaded sprites instead of unconditionally returning a possibly non-existant sprite.
peter1138
parents:
8556
diff
changeset
|
779 |
if (group->g.real.num_loading > 0) return group->g.real.loading[0]; |
35ed84aec9f4
(svn r12180) -Fix: Test purchase list loading/loaded sprites instead of unconditionally returning a possibly non-existant sprite.
peter1138
parents:
8556
diff
changeset
|
780 |
if (group->g.real.num_loaded > 0) return group->g.real.loaded[0]; |
35ed84aec9f4
(svn r12180) -Fix: Test purchase list loading/loaded sprites instead of unconditionally returning a possibly non-existant sprite.
peter1138
parents:
8556
diff
changeset
|
781 |
return NULL; |
35ed84aec9f4
(svn r12180) -Fix: Test purchase list loading/loaded sprites instead of unconditionally returning a possibly non-existant sprite.
peter1138
parents:
8556
diff
changeset
|
782 |
} |
3734
5b331306e6fe
(svn r4714) - NewGRF: simplify evaluation of 'real' sprite groups.
peter1138
parents:
3731
diff
changeset
|
783 |
|
8836
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8786
diff
changeset
|
784 |
bool in_motion = !v->First()->current_order.IsType(OT_LOADING); |
445
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
785 |
|
3734
5b331306e6fe
(svn r4714) - NewGRF: simplify evaluation of 'real' sprite groups.
peter1138
parents:
3731
diff
changeset
|
786 |
totalsets = in_motion ? group->g.real.num_loaded : group->g.real.num_loading; |
445
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
787 |
|
8193
a6680b9d7eb1
(svn r11756) -Fix: Out of bounds access caused if a vehicle's cargo amount was higher than its capacity when resolving sprite groups.
peter1138
parents:
8144
diff
changeset
|
788 |
if (v->cargo.Count() >= v->cargo_cap || totalsets == 1) { |
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
789 |
set = totalsets - 1; |
7010
6f0d9f03180d
(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
parents:
6990
diff
changeset
|
790 |
} else if (v->cargo.Empty() || totalsets == 2) { |
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
791 |
set = 0; |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
792 |
} else { |
7010
6f0d9f03180d
(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
parents:
6990
diff
changeset
|
793 |
set = v->cargo.Count() * (totalsets - 2) / max((uint16)1, v->cargo_cap) + 1; |
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
794 |
} |
426
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
795 |
|
3734
5b331306e6fe
(svn r4714) - NewGRF: simplify evaluation of 'real' sprite groups.
peter1138
parents:
3731
diff
changeset
|
796 |
return in_motion ? group->g.real.loaded[set] : group->g.real.loading[set]; |
426
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
797 |
} |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
798 |
|
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
799 |
|
4057
863fce30596d
(svn r5337) - NewGRF: pass the engine type to the engine resolver, to allow support for variable 7F for unbuilt vehicles (mart3p)
peter1138
parents:
4056
diff
changeset
|
800 |
static inline void NewVehicleResolver(ResolverObject *res, EngineID engine_type, const Vehicle *v) |
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
801 |
{ |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
802 |
res->GetRandomBits = &VehicleGetRandomBits; |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
803 |
res->GetTriggers = &VehicleGetTriggers; |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
804 |
res->SetTriggers = &VehicleSetTriggers; |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
805 |
res->GetVariable = &VehicleGetVariable; |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
806 |
res->ResolveReal = &VehicleResolveReal; |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
807 |
|
3720
8a82d64ea485
(svn r4691) - Codechange: don't use unnamed unions as GCC 2.95.ancient won't compile it. Needed for our MorphOS user ;)
peter1138
parents:
3706
diff
changeset
|
808 |
res->u.vehicle.self = v; |
7548
3a679b6e8b30
(svn r11068) -Codechange: remove Vehicle::HasFront as all vehicles have the Vehicle::first pointer correctly set.
rubidium
parents:
7497
diff
changeset
|
809 |
res->u.vehicle.parent = (v != NULL) ? v->First() : v; |
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
810 |
|
4057
863fce30596d
(svn r5337) - NewGRF: pass the engine type to the engine resolver, to allow support for variable 7F for unbuilt vehicles (mart3p)
peter1138
parents:
4056
diff
changeset
|
811 |
res->u.vehicle.self_type = engine_type; |
863fce30596d
(svn r5337) - NewGRF: pass the engine type to the engine resolver, to allow support for variable 7F for unbuilt vehicles (mart3p)
peter1138
parents:
4056
diff
changeset
|
812 |
|
4056
7899dc230a12
(svn r5336) - NewGRF: draw custom helicopter rotor sprites in vehicle info window, ensuring the correct direction is used (inspiration from mart3p)
peter1138
parents:
4055
diff
changeset
|
813 |
res->info_view = false; |
7899dc230a12
(svn r5336) - NewGRF: draw custom helicopter rotor sprites in vehicle info window, ensuring the correct direction is used (inspiration from mart3p)
peter1138
parents:
4055
diff
changeset
|
814 |
|
7327
d810677fb909
(svn r10690) -Codechange: use the enum that describes all callback IDs in favor of "just" using an untyped integer.
rubidium
parents:
7169
diff
changeset
|
815 |
res->callback = CBID_NO_CALLBACK; |
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
816 |
res->callback_param1 = 0; |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
817 |
res->callback_param2 = 0; |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
818 |
res->last_value = 0; |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
819 |
res->trigger = 0; |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
820 |
res->reseed = 0; |
8756
b6f8dc6a246f
(svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx
parents:
8666
diff
changeset
|
821 |
res->count = 0; |
9750
7114408dd1fa
(svn r13885) -Fix [FS#2168]: Var 0x7F is not feature-specific.
frosch
parents:
9672
diff
changeset
|
822 |
|
7114408dd1fa
(svn r13885) -Fix [FS#2168]: Var 0x7F is not feature-specific.
frosch
parents:
9672
diff
changeset
|
823 |
const Engine *e = GetEngine(engine_type); |
7114408dd1fa
(svn r13885) -Fix [FS#2168]: Var 0x7F is not feature-specific.
frosch
parents:
9672
diff
changeset
|
824 |
res->grffile = (e != NULL ? e->grffile : NULL); |
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
825 |
} |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
826 |
|
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
827 |
|
4901
c07d76c5d3f7
(svn r6870) - Codechange: (re-)unify the code to retrieve the sprite group for a vehicle.
peter1138
parents:
4869
diff
changeset
|
828 |
/** Retrieve the SpriteGroup for the specified vehicle. |
c07d76c5d3f7
(svn r6870) - Codechange: (re-)unify the code to retrieve the sprite group for a vehicle.
peter1138
parents:
4869
diff
changeset
|
829 |
* If the vehicle is not specified, the purchase list group for the engine is |
c07d76c5d3f7
(svn r6870) - Codechange: (re-)unify the code to retrieve the sprite group for a vehicle.
peter1138
parents:
4869
diff
changeset
|
830 |
* chosen. For trains, an additional engine override lookup is performed. |
7863
afc89a02465c
(svn r11413) -Fix [FS#1405]: don't use cached override spriteset for callbacks
glx
parents:
7861
diff
changeset
|
831 |
* @param engine Engine type of the vehicle. |
afc89a02465c
(svn r11413) -Fix [FS#1405]: don't use cached override spriteset for callbacks
glx
parents:
7861
diff
changeset
|
832 |
* @param v The vehicle itself. |
afc89a02465c
(svn r11413) -Fix [FS#1405]: don't use cached override spriteset for callbacks
glx
parents:
7861
diff
changeset
|
833 |
* @param use_cache Use cached override |
afc89a02465c
(svn r11413) -Fix [FS#1405]: don't use cached override spriteset for callbacks
glx
parents:
7861
diff
changeset
|
834 |
* @returns The selected SpriteGroup for the vehicle. |
4901
c07d76c5d3f7
(svn r6870) - Codechange: (re-)unify the code to retrieve the sprite group for a vehicle.
peter1138
parents:
4869
diff
changeset
|
835 |
*/ |
7863
afc89a02465c
(svn r11413) -Fix [FS#1405]: don't use cached override spriteset for callbacks
glx
parents:
7861
diff
changeset
|
836 |
static const SpriteGroup *GetVehicleSpriteGroup(EngineID engine, const Vehicle *v, bool use_cache = true) |
4901
c07d76c5d3f7
(svn r6870) - Codechange: (re-)unify the code to retrieve the sprite group for a vehicle.
peter1138
parents:
4869
diff
changeset
|
837 |
{ |
c07d76c5d3f7
(svn r6870) - Codechange: (re-)unify the code to retrieve the sprite group for a vehicle.
peter1138
parents:
4869
diff
changeset
|
838 |
const SpriteGroup *group; |
c07d76c5d3f7
(svn r6870) - Codechange: (re-)unify the code to retrieve the sprite group for a vehicle.
peter1138
parents:
4869
diff
changeset
|
839 |
CargoID cargo; |
c07d76c5d3f7
(svn r6870) - Codechange: (re-)unify the code to retrieve the sprite group for a vehicle.
peter1138
parents:
4869
diff
changeset
|
840 |
|
c07d76c5d3f7
(svn r6870) - Codechange: (re-)unify the code to retrieve the sprite group for a vehicle.
peter1138
parents:
4869
diff
changeset
|
841 |
if (v == NULL) { |
6148
5247b66aad19
(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
parents:
6147
diff
changeset
|
842 |
cargo = CT_PURCHASE; |
4901
c07d76c5d3f7
(svn r6870) - Codechange: (re-)unify the code to retrieve the sprite group for a vehicle.
peter1138
parents:
4869
diff
changeset
|
843 |
} else { |
6148
5247b66aad19
(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
parents:
6147
diff
changeset
|
844 |
cargo = v->cargo_type; |
4901
c07d76c5d3f7
(svn r6870) - Codechange: (re-)unify the code to retrieve the sprite group for a vehicle.
peter1138
parents:
4869
diff
changeset
|
845 |
|
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6248
diff
changeset
|
846 |
if (v->type == VEH_TRAIN) { |
7863
afc89a02465c
(svn r11413) -Fix [FS#1405]: don't use cached override spriteset for callbacks
glx
parents:
7861
diff
changeset
|
847 |
/* We always use cached value, except for callbacks because the override spriteset |
afc89a02465c
(svn r11413) -Fix [FS#1405]: don't use cached override spriteset for callbacks
glx
parents:
7861
diff
changeset
|
848 |
* to use may be different than the one cached. It happens for callback 0x15 (refit engine), |
afc89a02465c
(svn r11413) -Fix [FS#1405]: don't use cached override spriteset for callbacks
glx
parents:
7861
diff
changeset
|
849 |
* as v->cargo_type is temporary changed to the new type */ |
afc89a02465c
(svn r11413) -Fix [FS#1405]: don't use cached override spriteset for callbacks
glx
parents:
7861
diff
changeset
|
850 |
group = use_cache ? v->u.rail.cached_override : GetWagonOverrideSpriteSet(v->engine_type, v->cargo_type, v->u.rail.first_engine); |
4901
c07d76c5d3f7
(svn r6870) - Codechange: (re-)unify the code to retrieve the sprite group for a vehicle.
peter1138
parents:
4869
diff
changeset
|
851 |
if (group != NULL) return group; |
c07d76c5d3f7
(svn r6870) - Codechange: (re-)unify the code to retrieve the sprite group for a vehicle.
peter1138
parents:
4869
diff
changeset
|
852 |
} |
c07d76c5d3f7
(svn r6870) - Codechange: (re-)unify the code to retrieve the sprite group for a vehicle.
peter1138
parents:
4869
diff
changeset
|
853 |
} |
c07d76c5d3f7
(svn r6870) - Codechange: (re-)unify the code to retrieve the sprite group for a vehicle.
peter1138
parents:
4869
diff
changeset
|
854 |
|
9070
dd0121143eba
(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
parents:
9062
diff
changeset
|
855 |
const Engine *e = GetEngine(engine); |
dd0121143eba
(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
parents:
9062
diff
changeset
|
856 |
|
dd0121143eba
(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
parents:
9062
diff
changeset
|
857 |
group = e->group[cargo]; |
4901
c07d76c5d3f7
(svn r6870) - Codechange: (re-)unify the code to retrieve the sprite group for a vehicle.
peter1138
parents:
4869
diff
changeset
|
858 |
if (group != NULL) return group; |
c07d76c5d3f7
(svn r6870) - Codechange: (re-)unify the code to retrieve the sprite group for a vehicle.
peter1138
parents:
4869
diff
changeset
|
859 |
|
c07d76c5d3f7
(svn r6870) - Codechange: (re-)unify the code to retrieve the sprite group for a vehicle.
peter1138
parents:
4869
diff
changeset
|
860 |
/* Fall back to the default set if the selected cargo type is not defined */ |
9070
dd0121143eba
(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
parents:
9062
diff
changeset
|
861 |
return e->group[CT_DEFAULT]; |
4901
c07d76c5d3f7
(svn r6870) - Codechange: (re-)unify the code to retrieve the sprite group for a vehicle.
peter1138
parents:
4869
diff
changeset
|
862 |
} |
c07d76c5d3f7
(svn r6870) - Codechange: (re-)unify the code to retrieve the sprite group for a vehicle.
peter1138
parents:
4869
diff
changeset
|
863 |
|
c07d76c5d3f7
(svn r6870) - Codechange: (re-)unify the code to retrieve the sprite group for a vehicle.
peter1138
parents:
4869
diff
changeset
|
864 |
|
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
865 |
SpriteID GetCustomEngineSprite(EngineID engine, const Vehicle *v, Direction direction) |
0 | 866 |
{ |
2242
512eae2cf006
(svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents:
2204
diff
changeset
|
867 |
const SpriteGroup *group; |
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
868 |
ResolverObject object; |
0 | 869 |
|
4057
863fce30596d
(svn r5337) - NewGRF: pass the engine type to the engine resolver, to allow support for variable 7F for unbuilt vehicles (mart3p)
peter1138
parents:
4056
diff
changeset
|
870 |
NewVehicleResolver(&object, engine, v); |
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
871 |
|
4901
c07d76c5d3f7
(svn r6870) - Codechange: (re-)unify the code to retrieve the sprite group for a vehicle.
peter1138
parents:
4869
diff
changeset
|
872 |
group = Resolve(GetVehicleSpriteGroup(engine, v), &object); |
9472
708400e63e4b
(svn r13397) -Fix: Do not crash when resolving vehicle sprite groups with zero sprites.
frosch
parents:
9459
diff
changeset
|
873 |
if (group == NULL || group->type != SGT_RESULT || group->g.result.num_sprites == 0) return 0; |
3668
42325f12e7d8
(svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents:
3648
diff
changeset
|
874 |
|
42325f12e7d8
(svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents:
3648
diff
changeset
|
875 |
return group->g.result.sprite + (direction % group->g.result.num_sprites); |
0 | 876 |
} |
877 |
||
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
878 |
|
4056
7899dc230a12
(svn r5336) - NewGRF: draw custom helicopter rotor sprites in vehicle info window, ensuring the correct direction is used (inspiration from mart3p)
peter1138
parents:
4055
diff
changeset
|
879 |
SpriteID GetRotorOverrideSprite(EngineID engine, const Vehicle *v, bool info_view) |
3695
e1d5608f4d32
(svn r4632) - NewGRF: support loading of helicopter rotor sprites (mart3p)
peter1138
parents:
3693
diff
changeset
|
880 |
{ |
9070
dd0121143eba
(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
parents:
9062
diff
changeset
|
881 |
const Engine *e = GetEngine(engine); |
3695
e1d5608f4d32
(svn r4632) - NewGRF: support loading of helicopter rotor sprites (mart3p)
peter1138
parents:
3693
diff
changeset
|
882 |
|
e1d5608f4d32
(svn r4632) - NewGRF: support loading of helicopter rotor sprites (mart3p)
peter1138
parents:
3693
diff
changeset
|
883 |
/* Only valid for helicopters */ |
9436
2eabc2c8ac08
(svn r13351) -Codechange: disable warnings about unused variable for builds without asserts
smatz
parents:
9413
diff
changeset
|
884 |
assert(e->type == VEH_AIRCRAFT); |
9070
dd0121143eba
(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
parents:
9062
diff
changeset
|
885 |
assert(!(e->u.air.subtype & AIR_CTOL)); |
3695
e1d5608f4d32
(svn r4632) - NewGRF: support loading of helicopter rotor sprites (mart3p)
peter1138
parents:
3693
diff
changeset
|
886 |
|
9436
2eabc2c8ac08
(svn r13351) -Codechange: disable warnings about unused variable for builds without asserts
smatz
parents:
9413
diff
changeset
|
887 |
ResolverObject object; |
2eabc2c8ac08
(svn r13351) -Codechange: disable warnings about unused variable for builds without asserts
smatz
parents:
9413
diff
changeset
|
888 |
|
4057
863fce30596d
(svn r5337) - NewGRF: pass the engine type to the engine resolver, to allow support for variable 7F for unbuilt vehicles (mart3p)
peter1138
parents:
4056
diff
changeset
|
889 |
NewVehicleResolver(&object, engine, v); |
3695
e1d5608f4d32
(svn r4632) - NewGRF: support loading of helicopter rotor sprites (mart3p)
peter1138
parents:
3693
diff
changeset
|
890 |
|
4056
7899dc230a12
(svn r5336) - NewGRF: draw custom helicopter rotor sprites in vehicle info window, ensuring the correct direction is used (inspiration from mart3p)
peter1138
parents:
4055
diff
changeset
|
891 |
object.info_view = info_view; |
7899dc230a12
(svn r5336) - NewGRF: draw custom helicopter rotor sprites in vehicle info window, ensuring the correct direction is used (inspiration from mart3p)
peter1138
parents:
4055
diff
changeset
|
892 |
|
9436
2eabc2c8ac08
(svn r13351) -Codechange: disable warnings about unused variable for builds without asserts
smatz
parents:
9413
diff
changeset
|
893 |
const SpriteGroup *group = GetWagonOverrideSpriteSet(engine, CT_DEFAULT, engine); |
3695
e1d5608f4d32
(svn r4632) - NewGRF: support loading of helicopter rotor sprites (mart3p)
peter1138
parents:
3693
diff
changeset
|
894 |
group = Resolve(group, &object); |
e1d5608f4d32
(svn r4632) - NewGRF: support loading of helicopter rotor sprites (mart3p)
peter1138
parents:
3693
diff
changeset
|
895 |
|
9472
708400e63e4b
(svn r13397) -Fix: Do not crash when resolving vehicle sprite groups with zero sprites.
frosch
parents:
9459
diff
changeset
|
896 |
if (group == NULL || group->type != SGT_RESULT || group->g.result.num_sprites == 0) return 0; |
3695
e1d5608f4d32
(svn r4632) - NewGRF: support loading of helicopter rotor sprites (mart3p)
peter1138
parents:
3693
diff
changeset
|
897 |
|
e1d5608f4d32
(svn r4632) - NewGRF: support loading of helicopter rotor sprites (mart3p)
peter1138
parents:
3693
diff
changeset
|
898 |
if (v == NULL) return group->g.result.sprite; |
e1d5608f4d32
(svn r4632) - NewGRF: support loading of helicopter rotor sprites (mart3p)
peter1138
parents:
3693
diff
changeset
|
899 |
|
7492
35acee076719
(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
parents:
7327
diff
changeset
|
900 |
return group->g.result.sprite + (info_view ? 0 : (v->Next()->Next()->u.air.state % group->g.result.num_sprites)); |
3695
e1d5608f4d32
(svn r4632) - NewGRF: support loading of helicopter rotor sprites (mart3p)
peter1138
parents:
3693
diff
changeset
|
901 |
} |
e1d5608f4d32
(svn r4632) - NewGRF: support loading of helicopter rotor sprites (mart3p)
peter1138
parents:
3693
diff
changeset
|
902 |
|
e1d5608f4d32
(svn r4632) - NewGRF: support loading of helicopter rotor sprites (mart3p)
peter1138
parents:
3693
diff
changeset
|
903 |
|
1883
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
904 |
/** |
1908
2fa391fed79a
(svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents:
1904
diff
changeset
|
905 |
* Check if a wagon is currently using a wagon override |
2fa391fed79a
(svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents:
1904
diff
changeset
|
906 |
* @param v The wagon to check |
2fa391fed79a
(svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents:
1904
diff
changeset
|
907 |
* @return true if it is using an override, false otherwise |
2fa391fed79a
(svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents:
1904
diff
changeset
|
908 |
*/ |
2548
49c8a096033f
(svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents:
2530
diff
changeset
|
909 |
bool UsesWagonOverride(const Vehicle* v) |
49c8a096033f
(svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents:
2530
diff
changeset
|
910 |
{ |
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6248
diff
changeset
|
911 |
assert(v->type == VEH_TRAIN); |
6603
076b05312635
(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
parents:
6589
diff
changeset
|
912 |
return v->u.rail.cached_override != NULL; |
1908
2fa391fed79a
(svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents:
1904
diff
changeset
|
913 |
} |
2fa391fed79a
(svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents:
1904
diff
changeset
|
914 |
|
2fa391fed79a
(svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents:
1904
diff
changeset
|
915 |
/** |
3390
ae4b0872dc78
(svn r4198) - NewGRF: Rename GetCallBackResult() to GetVehicleCallback(), as other types will exist later, and use separate parameters instead of bitshifting.
peter1138
parents:
3348
diff
changeset
|
916 |
* Evaluate a newgrf callback for vehicles |
ae4b0872dc78
(svn r4198) - NewGRF: Rename GetCallBackResult() to GetVehicleCallback(), as other types will exist later, and use separate parameters instead of bitshifting.
peter1138
parents:
3348
diff
changeset
|
917 |
* @param callback The callback to evalute |
ae4b0872dc78
(svn r4198) - NewGRF: Rename GetCallBackResult() to GetVehicleCallback(), as other types will exist later, and use separate parameters instead of bitshifting.
peter1138
parents:
3348
diff
changeset
|
918 |
* @param param1 First parameter of the callback |
ae4b0872dc78
(svn r4198) - NewGRF: Rename GetCallBackResult() to GetVehicleCallback(), as other types will exist later, and use separate parameters instead of bitshifting.
peter1138
parents:
3348
diff
changeset
|
919 |
* @param param2 Second parameter of the callback |
ae4b0872dc78
(svn r4198) - NewGRF: Rename GetCallBackResult() to GetVehicleCallback(), as other types will exist later, and use separate parameters instead of bitshifting.
peter1138
parents:
3348
diff
changeset
|
920 |
* @param engine Engine type of the vehicle to evaluate the callback for |
6481
85ad87daf4b0
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6348
diff
changeset
|
921 |
* @param v The vehicle to evaluate the callback for, or NULL if it doesnt exist yet |
1883
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
922 |
* @return The value the callback returned, or CALLBACK_FAILED if it failed |
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
923 |
*/ |
7327
d810677fb909
(svn r10690) -Codechange: use the enum that describes all callback IDs in favor of "just" using an untyped integer.
rubidium
parents:
7169
diff
changeset
|
924 |
uint16 GetVehicleCallback(CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v) |
1883
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
925 |
{ |
2242
512eae2cf006
(svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents:
2204
diff
changeset
|
926 |
const SpriteGroup *group; |
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
927 |
ResolverObject object; |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
928 |
|
4057
863fce30596d
(svn r5337) - NewGRF: pass the engine type to the engine resolver, to allow support for variable 7F for unbuilt vehicles (mart3p)
peter1138
parents:
4056
diff
changeset
|
929 |
NewVehicleResolver(&object, engine, v); |
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
930 |
|
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
931 |
object.callback = callback; |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
932 |
object.callback_param1 = param1; |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
933 |
object.callback_param2 = param2; |
1883
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
934 |
|
7863
afc89a02465c
(svn r11413) -Fix [FS#1405]: don't use cached override spriteset for callbacks
glx
parents:
7861
diff
changeset
|
935 |
group = Resolve(GetVehicleSpriteGroup(engine, v, false), &object); |
4811
94f23d625b95
(svn r6735) - Codestyle: Just some tidying up...
peter1138
parents:
4656
diff
changeset
|
936 |
if (group == NULL || group->type != SGT_CALLBACK) return CALLBACK_FAILED; |
1883
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
937 |
|
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
938 |
return group->g.callback.result; |
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
939 |
} |
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
940 |
|
3726
f44617056b8f
(svn r4702) - NewGRF: add support for 'special' vehicle callbacks that use a different vehicle for parent scope than the first vehicle in the consist.
peter1138
parents:
3724
diff
changeset
|
941 |
/** |
f44617056b8f
(svn r4702) - NewGRF: add support for 'special' vehicle callbacks that use a different vehicle for parent scope than the first vehicle in the consist.
peter1138
parents:
3724
diff
changeset
|
942 |
* Evaluate a newgrf callback for vehicles with a different vehicle for parent scope. |
f44617056b8f
(svn r4702) - NewGRF: add support for 'special' vehicle callbacks that use a different vehicle for parent scope than the first vehicle in the consist.
peter1138
parents:
3724
diff
changeset
|
943 |
* @param callback The callback to evalute |
f44617056b8f
(svn r4702) - NewGRF: add support for 'special' vehicle callbacks that use a different vehicle for parent scope than the first vehicle in the consist.
peter1138
parents:
3724
diff
changeset
|
944 |
* @param param1 First parameter of the callback |
f44617056b8f
(svn r4702) - NewGRF: add support for 'special' vehicle callbacks that use a different vehicle for parent scope than the first vehicle in the consist.
peter1138
parents:
3724
diff
changeset
|
945 |
* @param param2 Second parameter of the callback |
f44617056b8f
(svn r4702) - NewGRF: add support for 'special' vehicle callbacks that use a different vehicle for parent scope than the first vehicle in the consist.
peter1138
parents:
3724
diff
changeset
|
946 |
* @param engine Engine type of the vehicle to evaluate the callback for |
f44617056b8f
(svn r4702) - NewGRF: add support for 'special' vehicle callbacks that use a different vehicle for parent scope than the first vehicle in the consist.
peter1138
parents:
3724
diff
changeset
|
947 |
* @param v The vehicle to evaluate the callback for, or NULL if it doesnt exist yet |
f44617056b8f
(svn r4702) - NewGRF: add support for 'special' vehicle callbacks that use a different vehicle for parent scope than the first vehicle in the consist.
peter1138
parents:
3724
diff
changeset
|
948 |
* @param parent The vehicle to use for parent scope |
f44617056b8f
(svn r4702) - NewGRF: add support for 'special' vehicle callbacks that use a different vehicle for parent scope than the first vehicle in the consist.
peter1138
parents:
3724
diff
changeset
|
949 |
* @return The value the callback returned, or CALLBACK_FAILED if it failed |
f44617056b8f
(svn r4702) - NewGRF: add support for 'special' vehicle callbacks that use a different vehicle for parent scope than the first vehicle in the consist.
peter1138
parents:
3724
diff
changeset
|
950 |
*/ |
7327
d810677fb909
(svn r10690) -Codechange: use the enum that describes all callback IDs in favor of "just" using an untyped integer.
rubidium
parents:
7169
diff
changeset
|
951 |
uint16 GetVehicleCallbackParent(CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v, const Vehicle *parent) |
3726
f44617056b8f
(svn r4702) - NewGRF: add support for 'special' vehicle callbacks that use a different vehicle for parent scope than the first vehicle in the consist.
peter1138
parents:
3724
diff
changeset
|
952 |
{ |
f44617056b8f
(svn r4702) - NewGRF: add support for 'special' vehicle callbacks that use a different vehicle for parent scope than the first vehicle in the consist.
peter1138
parents:
3724
diff
changeset
|
953 |
const SpriteGroup *group; |
f44617056b8f
(svn r4702) - NewGRF: add support for 'special' vehicle callbacks that use a different vehicle for parent scope than the first vehicle in the consist.
peter1138
parents:
3724
diff
changeset
|
954 |
ResolverObject object; |
f44617056b8f
(svn r4702) - NewGRF: add support for 'special' vehicle callbacks that use a different vehicle for parent scope than the first vehicle in the consist.
peter1138
parents:
3724
diff
changeset
|
955 |
|
4057
863fce30596d
(svn r5337) - NewGRF: pass the engine type to the engine resolver, to allow support for variable 7F for unbuilt vehicles (mart3p)
peter1138
parents:
4056
diff
changeset
|
956 |
NewVehicleResolver(&object, engine, v); |
3726
f44617056b8f
(svn r4702) - NewGRF: add support for 'special' vehicle callbacks that use a different vehicle for parent scope than the first vehicle in the consist.
peter1138
parents:
3724
diff
changeset
|
957 |
|
f44617056b8f
(svn r4702) - NewGRF: add support for 'special' vehicle callbacks that use a different vehicle for parent scope than the first vehicle in the consist.
peter1138
parents:
3724
diff
changeset
|
958 |
object.callback = callback; |
f44617056b8f
(svn r4702) - NewGRF: add support for 'special' vehicle callbacks that use a different vehicle for parent scope than the first vehicle in the consist.
peter1138
parents:
3724
diff
changeset
|
959 |
object.callback_param1 = param1; |
f44617056b8f
(svn r4702) - NewGRF: add support for 'special' vehicle callbacks that use a different vehicle for parent scope than the first vehicle in the consist.
peter1138
parents:
3724
diff
changeset
|
960 |
object.callback_param2 = param2; |
f44617056b8f
(svn r4702) - NewGRF: add support for 'special' vehicle callbacks that use a different vehicle for parent scope than the first vehicle in the consist.
peter1138
parents:
3724
diff
changeset
|
961 |
|
f44617056b8f
(svn r4702) - NewGRF: add support for 'special' vehicle callbacks that use a different vehicle for parent scope than the first vehicle in the consist.
peter1138
parents:
3724
diff
changeset
|
962 |
object.u.vehicle.parent = parent; |
f44617056b8f
(svn r4702) - NewGRF: add support for 'special' vehicle callbacks that use a different vehicle for parent scope than the first vehicle in the consist.
peter1138
parents:
3724
diff
changeset
|
963 |
|
7863
afc89a02465c
(svn r11413) -Fix [FS#1405]: don't use cached override spriteset for callbacks
glx
parents:
7861
diff
changeset
|
964 |
group = Resolve(GetVehicleSpriteGroup(engine, v, false), &object); |
4811
94f23d625b95
(svn r6735) - Codestyle: Just some tidying up...
peter1138
parents:
4656
diff
changeset
|
965 |
if (group == NULL || group->type != SGT_CALLBACK) return CALLBACK_FAILED; |
3726
f44617056b8f
(svn r4702) - NewGRF: add support for 'special' vehicle callbacks that use a different vehicle for parent scope than the first vehicle in the consist.
peter1138
parents:
3724
diff
changeset
|
966 |
|
f44617056b8f
(svn r4702) - NewGRF: add support for 'special' vehicle callbacks that use a different vehicle for parent scope than the first vehicle in the consist.
peter1138
parents:
3724
diff
changeset
|
967 |
return group->g.callback.result; |
f44617056b8f
(svn r4702) - NewGRF: add support for 'special' vehicle callbacks that use a different vehicle for parent scope than the first vehicle in the consist.
peter1138
parents:
3724
diff
changeset
|
968 |
} |
1883
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
969 |
|
6490
fe4443fba5e3
(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
parents:
6481
diff
changeset
|
970 |
|
6517
295b16f8fa7d
(svn r9703) -Codechange: support callback 36 in vehicle purchase lists
peter1138
parents:
6516
diff
changeset
|
971 |
/* Callback 36 handlers */ |
6490
fe4443fba5e3
(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
parents:
6481
diff
changeset
|
972 |
uint GetVehicleProperty(const Vehicle *v, uint8 property, uint orig_value) |
fe4443fba5e3
(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
parents:
6481
diff
changeset
|
973 |
{ |
fe4443fba5e3
(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
parents:
6481
diff
changeset
|
974 |
uint16 callback = GetVehicleCallback(CBID_VEHICLE_MODIFY_PROPERTY, property, 0, v->engine_type, v); |
fe4443fba5e3
(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
parents:
6481
diff
changeset
|
975 |
if (callback != CALLBACK_FAILED) return callback; |
fe4443fba5e3
(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
parents:
6481
diff
changeset
|
976 |
|
fe4443fba5e3
(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
parents:
6481
diff
changeset
|
977 |
return orig_value; |
fe4443fba5e3
(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
parents:
6481
diff
changeset
|
978 |
} |
fe4443fba5e3
(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
parents:
6481
diff
changeset
|
979 |
|
fe4443fba5e3
(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
parents:
6481
diff
changeset
|
980 |
|
6517
295b16f8fa7d
(svn r9703) -Codechange: support callback 36 in vehicle purchase lists
peter1138
parents:
6516
diff
changeset
|
981 |
uint GetEngineProperty(EngineID engine, uint8 property, uint orig_value) |
295b16f8fa7d
(svn r9703) -Codechange: support callback 36 in vehicle purchase lists
peter1138
parents:
6516
diff
changeset
|
982 |
{ |
295b16f8fa7d
(svn r9703) -Codechange: support callback 36 in vehicle purchase lists
peter1138
parents:
6516
diff
changeset
|
983 |
uint16 callback = GetVehicleCallback(CBID_VEHICLE_MODIFY_PROPERTY, property, 0, engine, NULL); |
295b16f8fa7d
(svn r9703) -Codechange: support callback 36 in vehicle purchase lists
peter1138
parents:
6516
diff
changeset
|
984 |
if (callback != CALLBACK_FAILED) return callback; |
295b16f8fa7d
(svn r9703) -Codechange: support callback 36 in vehicle purchase lists
peter1138
parents:
6516
diff
changeset
|
985 |
|
295b16f8fa7d
(svn r9703) -Codechange: support callback 36 in vehicle purchase lists
peter1138
parents:
6516
diff
changeset
|
986 |
return orig_value; |
295b16f8fa7d
(svn r9703) -Codechange: support callback 36 in vehicle purchase lists
peter1138
parents:
6516
diff
changeset
|
987 |
} |
295b16f8fa7d
(svn r9703) -Codechange: support callback 36 in vehicle purchase lists
peter1138
parents:
6516
diff
changeset
|
988 |
|
295b16f8fa7d
(svn r9703) -Codechange: support callback 36 in vehicle purchase lists
peter1138
parents:
6516
diff
changeset
|
989 |
|
3680 | 990 |
static void DoTriggerVehicle(Vehicle *v, VehicleTrigger trigger, byte base_random_bits, bool first) |
445
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
991 |
{ |
2242
512eae2cf006
(svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents:
2204
diff
changeset
|
992 |
const SpriteGroup *group; |
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
993 |
ResolverObject object; |
445
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
994 |
byte new_random_bits; |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
995 |
|
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
996 |
/* We can't trigger a non-existent vehicle... */ |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
997 |
assert(v != NULL); |
1883
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
998 |
|
4057
863fce30596d
(svn r5337) - NewGRF: pass the engine type to the engine resolver, to allow support for variable 7F for unbuilt vehicles (mart3p)
peter1138
parents:
4056
diff
changeset
|
999 |
NewVehicleResolver(&object, v->engine_type, v); |
7169
314b046af3a1
(svn r10443) -Fix: randomizing triggers should be called with callback type set to 1
peter1138
parents:
7010
diff
changeset
|
1000 |
object.callback = CBID_RANDOM_TRIGGER; |
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
1001 |
object.trigger = trigger; |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
1002 |
|
4901
c07d76c5d3f7
(svn r6870) - Codechange: (re-)unify the code to retrieve the sprite group for a vehicle.
peter1138
parents:
4869
diff
changeset
|
1003 |
group = Resolve(GetVehicleSpriteGroup(v->engine_type, v), &object); |
7861
77e12b5259fe
(svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents:
7803
diff
changeset
|
1004 |
if (group == NULL) return; |
1883
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
1005 |
|
542 | 1006 |
new_random_bits = Random(); |
3686
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
1007 |
v->random_bits &= ~object.reseed; |
16627c28741d
(svn r4611) - NewGRF: introduce new vehicle sprite group resolver code. This also fixes some known bugs (e.g. the 'Standard Five' in UKRS is now the correct colour)
peter1138
parents:
3684
diff
changeset
|
1008 |
v->random_bits |= (first ? new_random_bits : base_random_bits) & object.reseed; |
445
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
1009 |
|
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
1010 |
switch (trigger) { |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
1011 |
case VEHICLE_TRIGGER_NEW_CARGO: |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
1012 |
/* All vehicles in chain get ANY_NEW_CARGO trigger now. |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
1013 |
* So we call it for the first one and they will recurse. */ |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
1014 |
/* Indexing part of vehicle random bits needs to be |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
1015 |
* same for all triggered vehicles in the chain (to get |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
1016 |
* all the random-cargo wagons carry the same cargo, |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
1017 |
* i.e.), so we give them all the NEW_CARGO triggered |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
1018 |
* vehicle's portion of random bits. */ |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
1019 |
assert(first); |
7550
dc1fcce38fb8
(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
parents:
7548
diff
changeset
|
1020 |
DoTriggerVehicle(v->First(), VEHICLE_TRIGGER_ANY_NEW_CARGO, new_random_bits, false); |
445
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
1021 |
break; |
3680 | 1022 |
|
445
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
1023 |
case VEHICLE_TRIGGER_DEPOT: |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
1024 |
/* We now trigger the next vehicle in chain recursively. |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
1025 |
* The random bits portions may be different for each |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
1026 |
* vehicle in chain. */ |
7492
35acee076719
(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
parents:
7327
diff
changeset
|
1027 |
if (v->Next() != NULL) DoTriggerVehicle(v->Next(), trigger, 0, true); |
445
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
1028 |
break; |
3680 | 1029 |
|
445
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
1030 |
case VEHICLE_TRIGGER_EMPTY: |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
1031 |
/* We now trigger the next vehicle in chain |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
1032 |
* recursively. The random bits portions must be same |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
1033 |
* for each vehicle in chain, so we give them all |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
1034 |
* first chained vehicle's portion of random bits. */ |
7492
35acee076719
(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
parents:
7327
diff
changeset
|
1035 |
if (v->Next() != NULL) DoTriggerVehicle(v->Next(), trigger, first ? new_random_bits : base_random_bits, false); |
445
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
1036 |
break; |
3680 | 1037 |
|
445
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
1038 |
case VEHICLE_TRIGGER_ANY_NEW_CARGO: |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
1039 |
/* Now pass the trigger recursively to the next vehicle |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
1040 |
* in chain. */ |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
1041 |
assert(!first); |
7492
35acee076719
(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
parents:
7327
diff
changeset
|
1042 |
if (v->Next() != NULL) DoTriggerVehicle(v->Next(), VEHICLE_TRIGGER_ANY_NEW_CARGO, base_random_bits, false); |
445
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
1043 |
break; |
7803
55307751965b
(svn r11353) -Codechange: add support for newgrf callback 32
glx
parents:
7550
diff
changeset
|
1044 |
|
55307751965b
(svn r11353) -Codechange: add support for newgrf callback 32
glx
parents:
7550
diff
changeset
|
1045 |
case VEHICLE_TRIGGER_CALLBACK_32: |
55307751965b
(svn r11353) -Codechange: add support for newgrf callback 32
glx
parents:
7550
diff
changeset
|
1046 |
/* Do not do any recursion */ |
55307751965b
(svn r11353) -Codechange: add support for newgrf callback 32
glx
parents:
7550
diff
changeset
|
1047 |
break; |
445
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
1048 |
} |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
1049 |
} |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
1050 |
|
3680 | 1051 |
void TriggerVehicle(Vehicle *v, VehicleTrigger trigger) |
445
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
1052 |
{ |
2589
3640c75148f2
(svn r3126) Autoreplace: Only the first vehicle in a chain should be marked as entering a depot, so call moved out of DoVehicleTrigger loop.
peter1138
parents:
2574
diff
changeset
|
1053 |
if (trigger == VEHICLE_TRIGGER_DEPOT) { |
6348
6dd01da7a02b
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents:
6259
diff
changeset
|
1054 |
/* store that the vehicle entered a depot this tick */ |
3680 | 1055 |
VehicleEnteredDepotThisTick(v); |
2589
3640c75148f2
(svn r3126) Autoreplace: Only the first vehicle in a chain should be marked as entering a depot, so call moved out of DoVehicleTrigger loop.
peter1138
parents:
2574
diff
changeset
|
1056 |
} |
3640c75148f2
(svn r3126) Autoreplace: Only the first vehicle in a chain should be marked as entering a depot, so call moved out of DoVehicleTrigger loop.
peter1138
parents:
2574
diff
changeset
|
1057 |
|
3680 | 1058 |
DoTriggerVehicle(v, trigger, 0, true); |
445
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
1059 |
} |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
1060 |
|
6348
6dd01da7a02b
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents:
6259
diff
changeset
|
1061 |
/* Functions for changing the order of vehicle purchase lists |
6dd01da7a02b
(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents:
6259
diff
changeset
|
1062 |
* This is currently only implemented for rail vehicles. */ |
2971
cae3a81e8674
(svn r3546) - NewGRF feature: Implement rail vehicle 'property' 0x1A: allows shuffling order of rail vehicle purchase list (and replace vehicle list)
peter1138
parents:
2962
diff
changeset
|
1063 |
|
4812
d71b2e7d11e0
(svn r6736) - Add a function to get the list position of an engine ID, for use with sorting. This is basically a reversed version of GetRailVehAtPosition()
peter1138
parents:
4811
diff
changeset
|
1064 |
/** |
d71b2e7d11e0
(svn r6736) - Add a function to get the list position of an engine ID, for use with sorting. This is basically a reversed version of GetRailVehAtPosition()
peter1138
parents:
4811
diff
changeset
|
1065 |
* Get the list position of an engine. |
d71b2e7d11e0
(svn r6736) - Add a function to get the list position of an engine ID, for use with sorting. This is basically a reversed version of GetRailVehAtPosition()
peter1138
parents:
4811
diff
changeset
|
1066 |
* Used when sorting a list of engines. |
d71b2e7d11e0
(svn r6736) - Add a function to get the list position of an engine ID, for use with sorting. This is basically a reversed version of GetRailVehAtPosition()
peter1138
parents:
4811
diff
changeset
|
1067 |
* @param engine ID of the engine. |
d71b2e7d11e0
(svn r6736) - Add a function to get the list position of an engine ID, for use with sorting. This is basically a reversed version of GetRailVehAtPosition()
peter1138
parents:
4811
diff
changeset
|
1068 |
* @return The list position of the engine. |
d71b2e7d11e0
(svn r6736) - Add a function to get the list position of an engine ID, for use with sorting. This is basically a reversed version of GetRailVehAtPosition()
peter1138
parents:
4811
diff
changeset
|
1069 |
*/ |
9070
dd0121143eba
(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
parents:
9062
diff
changeset
|
1070 |
uint ListPositionOfEngine(EngineID engine) |
4812
d71b2e7d11e0
(svn r6736) - Add a function to get the list position of an engine ID, for use with sorting. This is basically a reversed version of GetRailVehAtPosition()
peter1138
parents:
4811
diff
changeset
|
1071 |
{ |
9070
dd0121143eba
(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
parents:
9062
diff
changeset
|
1072 |
const Engine *e = GetEngine(engine); |
dd0121143eba
(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
parents:
9062
diff
changeset
|
1073 |
if (e->grffile == NULL) return e->list_position; |
dd0121143eba
(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
parents:
9062
diff
changeset
|
1074 |
|
dd0121143eba
(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
parents:
9062
diff
changeset
|
1075 |
/* Crude sorting to group by GRF ID */ |
dd0121143eba
(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
parents:
9062
diff
changeset
|
1076 |
return (e->grffile->grfid * 256) + e->list_position; |
2971
cae3a81e8674
(svn r3546) - NewGRF feature: Implement rail vehicle 'property' 0x1A: allows shuffling order of rail vehicle purchase list (and replace vehicle list)
peter1138
parents:
2962
diff
changeset
|
1077 |
} |
cae3a81e8674
(svn r3546) - NewGRF feature: Implement rail vehicle 'property' 0x1A: allows shuffling order of rail vehicle purchase list (and replace vehicle list)
peter1138
parents:
2962
diff
changeset
|
1078 |
|
9070
dd0121143eba
(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
parents:
9062
diff
changeset
|
1079 |
struct ListOrderChange { |
dd0121143eba
(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
parents:
9062
diff
changeset
|
1080 |
EngineID engine; |
dd0121143eba
(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
parents:
9062
diff
changeset
|
1081 |
EngineID target; |
dd0121143eba
(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
parents:
9062
diff
changeset
|
1082 |
}; |
dd0121143eba
(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
parents:
9062
diff
changeset
|
1083 |
|
dd0121143eba
(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
parents:
9062
diff
changeset
|
1084 |
static std::list<ListOrderChange> _list_order_changes; |
dd0121143eba
(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
parents:
9062
diff
changeset
|
1085 |
|
9672
02fe9b0dc41b
(svn r13761) -Codechange: Remove dependency on rail for altering purchase list position (mostly function renaming)
peter1138
parents:
9652
diff
changeset
|
1086 |
void AlterVehicleListOrder(EngineID engine, EngineID target) |
2971
cae3a81e8674
(svn r3546) - NewGRF feature: Implement rail vehicle 'property' 0x1A: allows shuffling order of rail vehicle purchase list (and replace vehicle list)
peter1138
parents:
2962
diff
changeset
|
1087 |
{ |
9070
dd0121143eba
(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
parents:
9062
diff
changeset
|
1088 |
/* Add the list order change to a queue */ |
dd0121143eba
(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
parents:
9062
diff
changeset
|
1089 |
ListOrderChange loc; |
dd0121143eba
(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
parents:
9062
diff
changeset
|
1090 |
loc.engine = engine; |
dd0121143eba
(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
parents:
9062
diff
changeset
|
1091 |
loc.target = target; |
dd0121143eba
(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
parents:
9062
diff
changeset
|
1092 |
_list_order_changes.push_back(loc); |
dd0121143eba
(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
parents:
9062
diff
changeset
|
1093 |
} |
2971
cae3a81e8674
(svn r3546) - NewGRF feature: Implement rail vehicle 'property' 0x1A: allows shuffling order of rail vehicle purchase list (and replace vehicle list)
peter1138
parents:
2962
diff
changeset
|
1094 |
|
9672
02fe9b0dc41b
(svn r13761) -Codechange: Remove dependency on rail for altering purchase list position (mostly function renaming)
peter1138
parents:
9652
diff
changeset
|
1095 |
void CommitVehicleListOrderChanges() |
9070
dd0121143eba
(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
parents:
9062
diff
changeset
|
1096 |
{ |
dd0121143eba
(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
parents:
9062
diff
changeset
|
1097 |
/* List position to Engine map */ |
dd0121143eba
(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
parents:
9062
diff
changeset
|
1098 |
typedef std::map<uint16, Engine*> ListPositionMap; |
dd0121143eba
(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
parents:
9062
diff
changeset
|
1099 |
ListPositionMap lptr_map; |
2971
cae3a81e8674
(svn r3546) - NewGRF feature: Implement rail vehicle 'property' 0x1A: allows shuffling order of rail vehicle purchase list (and replace vehicle list)
peter1138
parents:
2962
diff
changeset
|
1100 |
|
9070
dd0121143eba
(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
parents:
9062
diff
changeset
|
1101 |
std::list<ListOrderChange>::iterator it; |
dd0121143eba
(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
parents:
9062
diff
changeset
|
1102 |
for (it = _list_order_changes.begin(); it != _list_order_changes.end(); ++it) { |
dd0121143eba
(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
parents:
9062
diff
changeset
|
1103 |
EngineID engine = it->engine; |
dd0121143eba
(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
parents:
9062
diff
changeset
|
1104 |
EngineID target = it->target; |
dd0121143eba
(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
parents:
9062
diff
changeset
|
1105 |
|
dd0121143eba
(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
parents:
9062
diff
changeset
|
1106 |
if (engine == target) continue; |
dd0121143eba
(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
parents:
9062
diff
changeset
|
1107 |
|
dd0121143eba
(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
parents:
9062
diff
changeset
|
1108 |
Engine *source_e = GetEngine(engine); |
dd0121143eba
(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
parents:
9062
diff
changeset
|
1109 |
Engine *target_e = NULL; |
dd0121143eba
(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
parents:
9062
diff
changeset
|
1110 |
|
dd0121143eba
(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
parents:
9062
diff
changeset
|
1111 |
/* Populate map with current list positions */ |
dd0121143eba
(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
parents:
9062
diff
changeset
|
1112 |
Engine *e; |
9672
02fe9b0dc41b
(svn r13761) -Codechange: Remove dependency on rail for altering purchase list position (mostly function renaming)
peter1138
parents:
9652
diff
changeset
|
1113 |
FOR_ALL_ENGINES_OF_TYPE(e, source_e->type) { |
9413
7042a8ec3fa8
(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
parents:
9354
diff
changeset
|
1114 |
if (!_settings_game.vehicle.dynamic_engines || e->grffile == source_e->grffile) { |
9070
dd0121143eba
(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
parents:
9062
diff
changeset
|
1115 |
if (e->internal_id == target) target_e = e; |
dd0121143eba
(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
parents:
9062
diff
changeset
|
1116 |
lptr_map[e->list_position] = e; |
dd0121143eba
(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
parents:
9062
diff
changeset
|
1117 |
} |
dd0121143eba
(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
parents:
9062
diff
changeset
|
1118 |
} |
dd0121143eba
(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
parents:
9062
diff
changeset
|
1119 |
|
dd0121143eba
(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
parents:
9062
diff
changeset
|
1120 |
/* Get the target position, if it exists */ |
dd0121143eba
(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
parents:
9062
diff
changeset
|
1121 |
if (target_e != NULL) { |
dd0121143eba
(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
parents:
9062
diff
changeset
|
1122 |
uint16 target_position = target_e->list_position; |
dd0121143eba
(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
parents:
9062
diff
changeset
|
1123 |
|
dd0121143eba
(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
parents:
9062
diff
changeset
|
1124 |
bool moving = false; |
dd0121143eba
(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
parents:
9062
diff
changeset
|
1125 |
for (ListPositionMap::iterator it = lptr_map.begin(); it != lptr_map.end(); ++it) { |
dd0121143eba
(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
parents:
9062
diff
changeset
|
1126 |
if (it->first == target_position) moving = true; |
dd0121143eba
(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
parents:
9062
diff
changeset
|
1127 |
if (moving) it->second->list_position++; |
dd0121143eba
(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
parents:
9062
diff
changeset
|
1128 |
} |
dd0121143eba
(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
parents:
9062
diff
changeset
|
1129 |
|
dd0121143eba
(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
parents:
9062
diff
changeset
|
1130 |
source_e->list_position = target_position; |
dd0121143eba
(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
parents:
9062
diff
changeset
|
1131 |
} |
dd0121143eba
(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
parents:
9062
diff
changeset
|
1132 |
|
dd0121143eba
(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
parents:
9062
diff
changeset
|
1133 |
lptr_map.clear(); |
2971
cae3a81e8674
(svn r3546) - NewGRF feature: Implement rail vehicle 'property' 0x1A: allows shuffling order of rail vehicle purchase list (and replace vehicle list)
peter1138
parents:
2962
diff
changeset
|
1134 |
} |
cae3a81e8674
(svn r3546) - NewGRF feature: Implement rail vehicle 'property' 0x1A: allows shuffling order of rail vehicle purchase list (and replace vehicle list)
peter1138
parents:
2962
diff
changeset
|
1135 |
|
9070
dd0121143eba
(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
parents:
9062
diff
changeset
|
1136 |
/* Clear out the queue */ |
dd0121143eba
(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
parents:
9062
diff
changeset
|
1137 |
_list_order_changes.clear(); |
2971
cae3a81e8674
(svn r3546) - NewGRF feature: Implement rail vehicle 'property' 0x1A: allows shuffling order of rail vehicle purchase list (and replace vehicle list)
peter1138
parents:
2962
diff
changeset
|
1138 |
} |