author | Darkvater |
Sun, 26 Mar 2006 22:23:32 +0000 | |
changeset 3344 | fc86351d4641 |
parent 3300 | 073fe603d5ba |
child 3348 | 0d0442be01d4 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
0 | 3 |
#include "stdafx.h" |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1883
diff
changeset
|
4 |
#include "openttd.h" |
1299
39c06aba09aa
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
1197
diff
changeset
|
5 |
#include "debug.h" |
2163
b17b313113a0
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2159
diff
changeset
|
6 |
#include "functions.h" |
2201 | 7 |
#include "string.h" |
8 |
#include "strings.h" |
|
0 | 9 |
#include "engine.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
|
10 |
#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
|
11 |
#include "newgrf_engine.h" |
405
415546028e8d
(svn r602) -newgrf: Move DrawTileSeqStruct & co and struct SpriteGroup to sprite.h (pasky)
darkvater
parents:
369
diff
changeset
|
12 |
#include "sprite.h" |
2159
f6284cf5fab0
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2147
diff
changeset
|
13 |
#include "variables.h" |
2708
48714bad9499
(svn r3252) - NewGRF: Map new train subtypes to old types for rail vehicles.
peter1138
parents:
2639
diff
changeset
|
14 |
#include "train.h" |
0 | 15 |
|
16 |
// TODO: We don't support cargo-specific wagon overrides. Pretty exotic... ;-) --pasky |
|
17 |
||
1477 | 18 |
typedef struct WagonOverride { |
0 | 19 |
byte *train_id; |
20 |
int trains; |
|
2488
1e98c71e5f6a
(svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents:
2477
diff
changeset
|
21 |
SpriteGroup *group; |
1477 | 22 |
} WagonOverride; |
0 | 23 |
|
1477 | 24 |
typedef struct WagonOverrides { |
0 | 25 |
int overrides_count; |
1477 | 26 |
WagonOverride *overrides; |
27 |
} WagonOverrides; |
|
0 | 28 |
|
1477 | 29 |
static WagonOverrides _engine_wagon_overrides[TOTAL_NUM_ENGINES]; |
30 |
||
2477
225b2916fe2a
(svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents:
2469
diff
changeset
|
31 |
void SetWagonOverrideSprites(EngineID engine, SpriteGroup *group, byte *train_id, |
1477 | 32 |
int trains) |
0 | 33 |
{ |
1477 | 34 |
WagonOverrides *wos; |
35 |
WagonOverride *wo; |
|
0 | 36 |
|
37 |
wos = &_engine_wagon_overrides[engine]; |
|
38 |
wos->overrides_count++; |
|
39 |
wos->overrides = realloc(wos->overrides, |
|
1477 | 40 |
wos->overrides_count * sizeof(*wos->overrides)); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
114
diff
changeset
|
41 |
|
0 | 42 |
wo = &wos->overrides[wos->overrides_count - 1]; |
408
48da21eb9ff2
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
43 |
/* FIXME: If we are replacing an override, release original SpriteGroup |
48da21eb9ff2
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
44 |
* to prevent leaks. But first we need to refcount the SpriteGroup. |
48da21eb9ff2
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
45 |
* --pasky */ |
2488
1e98c71e5f6a
(svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents:
2477
diff
changeset
|
46 |
wo->group = group; |
2490
0eac698c33cf
(svn r3016) -NewGRF: Implement the start of reference counting for sprite groups. This will allow unloading.
peter1138
parents:
2489
diff
changeset
|
47 |
group->ref_count++; |
0 | 48 |
wo->trains = trains; |
49 |
wo->train_id = malloc(trains); |
|
50 |
memcpy(wo->train_id, train_id, trains); |
|
51 |
} |
|
52 |
||
2477
225b2916fe2a
(svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents:
2469
diff
changeset
|
53 |
static const SpriteGroup *GetWagonOverrideSpriteSet(EngineID engine, byte overriding_engine) |
0 | 54 |
{ |
2242
512eae2cf006
(svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents:
2204
diff
changeset
|
55 |
const WagonOverrides *wos = &_engine_wagon_overrides[engine]; |
0 | 56 |
int i; |
57 |
||
408
48da21eb9ff2
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
58 |
// XXX: This could turn out to be a timesink on profiles. We could |
48da21eb9ff2
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
59 |
// always just dedicate 65535 bytes for an [engine][train] trampoline |
48da21eb9ff2
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
60 |
// for O(1). Or O(logMlogN) and searching binary tree or smt. like |
48da21eb9ff2
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
61 |
// that. --pasky |
0 | 62 |
|
63 |
for (i = 0; i < wos->overrides_count; i++) { |
|
2242
512eae2cf006
(svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents:
2204
diff
changeset
|
64 |
const WagonOverride *wo = &wos->overrides[i]; |
0 | 65 |
int j; |
66 |
||
67 |
for (j = 0; j < wo->trains; j++) { |
|
68 |
if (wo->train_id[j] == overriding_engine) |
|
2488
1e98c71e5f6a
(svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents:
2477
diff
changeset
|
69 |
return wo->group; |
0 | 70 |
} |
71 |
} |
|
72 |
return NULL; |
|
73 |
} |
|
74 |
||
2491
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2490
diff
changeset
|
75 |
/** |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2490
diff
changeset
|
76 |
* Unload all wagon override sprite groups. |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2490
diff
changeset
|
77 |
*/ |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2490
diff
changeset
|
78 |
void UnloadWagonOverrides(void) |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2490
diff
changeset
|
79 |
{ |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2490
diff
changeset
|
80 |
WagonOverrides *wos; |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2490
diff
changeset
|
81 |
WagonOverride *wo; |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2490
diff
changeset
|
82 |
EngineID engine; |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2490
diff
changeset
|
83 |
int i; |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2490
diff
changeset
|
84 |
|
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2490
diff
changeset
|
85 |
for (engine = 0; engine < TOTAL_NUM_ENGINES; engine++) { |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2490
diff
changeset
|
86 |
wos = &_engine_wagon_overrides[engine]; |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2490
diff
changeset
|
87 |
for (i = 0; i < wos->overrides_count; i++) { |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2490
diff
changeset
|
88 |
wo = &wos->overrides[i]; |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2490
diff
changeset
|
89 |
UnloadSpriteGroup(&wo->group); |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2490
diff
changeset
|
90 |
free(wo->train_id); |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2490
diff
changeset
|
91 |
} |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2490
diff
changeset
|
92 |
free(wos->overrides); |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2490
diff
changeset
|
93 |
wos->overrides_count = 0; |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2490
diff
changeset
|
94 |
wos->overrides = NULL; |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2490
diff
changeset
|
95 |
} |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2490
diff
changeset
|
96 |
} |
0 | 97 |
|
98 |
// 0 - 28 are cargos, 29 is default, 30 is the advert (purchase list) |
|
99 |
// (It isn't and shouldn't be like this in the GRF files since new cargo types |
|
100 |
// may appear in future - however it's more convenient to store it like this in |
|
101 |
// memory. --pasky) |
|
2488
1e98c71e5f6a
(svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents:
2477
diff
changeset
|
102 |
static SpriteGroup *engine_custom_sprites[TOTAL_NUM_ENGINES][NUM_GLOBAL_CID]; |
0 | 103 |
|
2477
225b2916fe2a
(svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents:
2469
diff
changeset
|
104 |
void SetCustomEngineSprites(EngineID engine, byte cargo, SpriteGroup *group) |
0 | 105 |
{ |
2491
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2490
diff
changeset
|
106 |
if (engine_custom_sprites[engine][cargo] != NULL) { |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2490
diff
changeset
|
107 |
DEBUG(grf, 6)("SetCustomEngineSprites: engine `%d' cargo `%d' already has group -- removing.", engine, cargo); |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2490
diff
changeset
|
108 |
UnloadSpriteGroup(&engine_custom_sprites[engine][cargo]); |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2490
diff
changeset
|
109 |
} |
2488
1e98c71e5f6a
(svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents:
2477
diff
changeset
|
110 |
engine_custom_sprites[engine][cargo] = group; |
2490
0eac698c33cf
(svn r3016) -NewGRF: Implement the start of reference counting for sprite groups. This will allow unloading.
peter1138
parents:
2489
diff
changeset
|
111 |
group->ref_count++; |
0 | 112 |
} |
113 |
||
2491
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2490
diff
changeset
|
114 |
/** |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2490
diff
changeset
|
115 |
* Unload all engine sprite groups. |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2490
diff
changeset
|
116 |
*/ |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2490
diff
changeset
|
117 |
void UnloadCustomEngineSprites(void) |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2490
diff
changeset
|
118 |
{ |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2490
diff
changeset
|
119 |
EngineID engine; |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2490
diff
changeset
|
120 |
CargoID cargo; |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2490
diff
changeset
|
121 |
|
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2490
diff
changeset
|
122 |
for (engine = 0; engine < TOTAL_NUM_ENGINES; engine++) { |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2490
diff
changeset
|
123 |
for (cargo = 0; cargo < NUM_GLOBAL_CID; cargo++) { |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2490
diff
changeset
|
124 |
if (engine_custom_sprites[engine][cargo] != NULL) { |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2490
diff
changeset
|
125 |
DEBUG(grf, 6)("UnloadCustomEngineSprites: Unloading group for engine `%d' cargo `%d'.", engine, cargo); |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2490
diff
changeset
|
126 |
UnloadSpriteGroup(&engine_custom_sprites[engine][cargo]); |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2490
diff
changeset
|
127 |
} |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2490
diff
changeset
|
128 |
} |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2490
diff
changeset
|
129 |
} |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2490
diff
changeset
|
130 |
} |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2490
diff
changeset
|
131 |
|
2708
48714bad9499
(svn r3252) - NewGRF: Map new train subtypes to old types for rail vehicles.
peter1138
parents:
2639
diff
changeset
|
132 |
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
|
133 |
{ |
48714bad9499
(svn r3252) - NewGRF: Map new train subtypes to old types for rail vehicles.
peter1138
parents:
2639
diff
changeset
|
134 |
if (v->type != VEH_Train) return v->subtype; |
48714bad9499
(svn r3252) - NewGRF: Map new train subtypes to old types for rail vehicles.
peter1138
parents:
2639
diff
changeset
|
135 |
if (IsTrainEngine(v)) return 0; |
48714bad9499
(svn r3252) - NewGRF: Map new train subtypes to old types for rail vehicles.
peter1138
parents:
2639
diff
changeset
|
136 |
if (IsFreeWagon(v)) return 4; |
48714bad9499
(svn r3252) - NewGRF: Map new train subtypes to old types for rail vehicles.
peter1138
parents:
2639
diff
changeset
|
137 |
return 2; |
48714bad9499
(svn r3252) - NewGRF: Map new train subtypes to old types for rail vehicles.
peter1138
parents:
2639
diff
changeset
|
138 |
} |
48714bad9499
(svn r3252) - NewGRF: Map new train subtypes to old types for rail vehicles.
peter1138
parents:
2639
diff
changeset
|
139 |
|
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
|
140 |
static int VehicleSpecificProperty(const Vehicle *v, byte var) { |
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
|
141 |
switch (v->type) { |
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
|
142 |
case VEH_Train: |
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
|
143 |
switch (var) { |
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
|
144 |
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
|
145 |
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
|
146 |
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
|
147 |
case 0x74: return v->u.rail.cached_power; |
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
|
148 |
case 0x75: return v->u.rail.cached_power & 0xFFFFFF; |
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
|
149 |
case 0x76: return v->u.rail.cached_power & 0xFFFF; |
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
|
150 |
case 0x77: return v->u.rail.cached_power & 0xFF; |
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
|
151 |
case 0x7C: return v->first->index; |
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
|
152 |
case 0x7D: return v->first->index & 0xFF; |
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
|
153 |
} |
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
|
154 |
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
|
155 |
|
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
|
156 |
case VEH_Road: |
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
|
157 |
switch (var) { |
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
|
158 |
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
|
159 |
case 0x64: return v->u.road.blocked_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
|
160 |
case 0x65: return v->u.road.blocked_ctr & 0xFF; |
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
|
161 |
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
|
162 |
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
|
163 |
case 0x68: return v->u.road.crashed_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
|
164 |
case 0x69: return v->u.road.crashed_ctr & 0xFF; |
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
|
165 |
} |
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
|
166 |
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
|
167 |
|
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
|
168 |
case VEH_Aircraft: |
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
|
169 |
switch (var) { |
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
|
170 |
// case 0x62: XXX Need to convert from ottd to ttdp 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
|
171 |
case 0x63: return v->u.air.targetairport; |
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
|
172 |
// case 0x66: XXX |
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
|
173 |
} |
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
|
174 |
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
|
175 |
} |
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
|
176 |
|
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
|
177 |
DEBUG(grf, 1)("Unhandled vehicle property 0x%x (var 0x%x), type 0x%x", var, var + 0x80, v->type); |
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
|
178 |
|
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
|
179 |
return -1; |
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
|
180 |
} |
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
|
181 |
|
2242
512eae2cf006
(svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents:
2204
diff
changeset
|
182 |
typedef SpriteGroup *(*resolve_callback)(const SpriteGroup *spritegroup, |
1883
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
183 |
const Vehicle *veh, uint16 callback_info, void *resolve_func); /* XXX data pointer used as function pointer */ |
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
|
184 |
|
2242
512eae2cf006
(svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents:
2204
diff
changeset
|
185 |
static const SpriteGroup* ResolveVehicleSpriteGroup(const SpriteGroup *spritegroup, |
1883
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
186 |
const Vehicle *veh, uint16 callback_info, resolve_callback resolve_func) |
426
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
187 |
{ |
2488
1e98c71e5f6a
(svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents:
2477
diff
changeset
|
188 |
if (spritegroup == NULL) |
1e98c71e5f6a
(svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents:
2477
diff
changeset
|
189 |
return NULL; |
1e98c71e5f6a
(svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents:
2477
diff
changeset
|
190 |
|
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
|
191 |
//debug("spgt %d", spritegroup->type); |
426
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
192 |
switch (spritegroup->type) { |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
193 |
case SGT_REAL: |
1883
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
194 |
case SGT_CALLBACK: |
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
195 |
return spritegroup; |
426
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
196 |
|
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
197 |
case SGT_DETERMINISTIC: { |
2242
512eae2cf006
(svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents:
2204
diff
changeset
|
198 |
const DeterministicSpriteGroup *dsg = &spritegroup->g.determ; |
512eae2cf006
(svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents:
2204
diff
changeset
|
199 |
const SpriteGroup *target; |
426
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
200 |
int value = -1; |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
201 |
|
433
a2cbd6cf3f37
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
202 |
//debug("[%p] Having fun resolving variable %x", veh, dsg->variable); |
1883
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
203 |
if (dsg->variable == 0x0C) { |
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
204 |
/* Callback ID */ |
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
205 |
value = callback_info & 0xFF; |
2602
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2589
diff
changeset
|
206 |
} else if (dsg->variable == 0x10) { |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2589
diff
changeset
|
207 |
value = (callback_info >> 8) & 0xFF; |
1883
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
208 |
} else if ((dsg->variable >> 6) == 0) { |
426
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
209 |
/* General property */ |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
210 |
value = GetDeterministicSpriteValue(dsg->variable); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
211 |
} else { |
433
a2cbd6cf3f37
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
212 |
/* Vehicle-specific property. */ |
a2cbd6cf3f37
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
213 |
|
a2cbd6cf3f37
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
214 |
if (veh == NULL) { |
a2cbd6cf3f37
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
215 |
/* We are in a purchase list of something, |
a2cbd6cf3f37
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
216 |
* and we are checking for something undefined. |
a2cbd6cf3f37
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
217 |
* That means we should get the first target |
a2cbd6cf3f37
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
218 |
* (NOT the default one). */ |
a2cbd6cf3f37
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
219 |
if (dsg->num_ranges > 0) { |
2488
1e98c71e5f6a
(svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents:
2477
diff
changeset
|
220 |
target = dsg->ranges[0].group; |
433
a2cbd6cf3f37
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
221 |
} else { |
a2cbd6cf3f37
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
222 |
target = dsg->default_group; |
a2cbd6cf3f37
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
223 |
} |
1883
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
224 |
return resolve_func(target, NULL, callback_info, resolve_func); |
433
a2cbd6cf3f37
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
225 |
} |
a2cbd6cf3f37
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
226 |
|
426
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
227 |
if (dsg->var_scope == VSG_SCOPE_PARENT) { |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
228 |
/* First engine in the vehicle chain */ |
433
a2cbd6cf3f37
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
229 |
if (veh->type == VEH_Train) |
426
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
230 |
veh = GetFirstVehicleInChain(veh); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
231 |
} |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
232 |
|
1855
6c7ade86caa7
(svn r2361) - Feature: [newgrf] Implement varaction2 property 0x41 and 0xDA. These are the position in and length of chain of consecutive vehicles with the same type, and index of the next wagon in the chain (INVALID_VEHICLE if last), resp. Improves displaying of some engines in the dbsetxl.
hackykid
parents:
1840
diff
changeset
|
233 |
if (dsg->variable == 0x40 || dsg->variable == 0x41) { |
433
a2cbd6cf3f37
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
234 |
if (veh->type == VEH_Train) { |
2242
512eae2cf006
(svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents:
2204
diff
changeset
|
235 |
const Vehicle *u = GetFirstVehicleInChain(veh); |
426
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
236 |
byte chain_before = 0, chain_after = 0; |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
237 |
|
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
238 |
while (u != veh) { |
1855
6c7ade86caa7
(svn r2361) - Feature: [newgrf] Implement varaction2 property 0x41 and 0xDA. These are the position in and length of chain of consecutive vehicles with the same type, and index of the next wagon in the chain (INVALID_VEHICLE if last), resp. Improves displaying of some engines in the dbsetxl.
hackykid
parents:
1840
diff
changeset
|
239 |
chain_before++; |
6c7ade86caa7
(svn r2361) - Feature: [newgrf] Implement varaction2 property 0x41 and 0xDA. These are the position in and length of chain of consecutive vehicles with the same type, and index of the next wagon in the chain (INVALID_VEHICLE if last), resp. Improves displaying of some engines in the dbsetxl.
hackykid
parents:
1840
diff
changeset
|
240 |
if (dsg->variable == 0x41 && u->engine_type != veh->engine_type) |
6c7ade86caa7
(svn r2361) - Feature: [newgrf] Implement varaction2 property 0x41 and 0xDA. These are the position in and length of chain of consecutive vehicles with the same type, and index of the next wagon in the chain (INVALID_VEHICLE if last), resp. Improves displaying of some engines in the dbsetxl.
hackykid
parents:
1840
diff
changeset
|
241 |
chain_before = 0; |
426
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
242 |
u = u->next; |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
243 |
} |
1855
6c7ade86caa7
(svn r2361) - Feature: [newgrf] Implement varaction2 property 0x41 and 0xDA. These are the position in and length of chain of consecutive vehicles with the same type, and index of the next wagon in the chain (INVALID_VEHICLE if last), resp. Improves displaying of some engines in the dbsetxl.
hackykid
parents:
1840
diff
changeset
|
244 |
while (u->next != NULL && (dsg->variable == 0x40 || u->next->engine_type == veh->engine_type)) { |
6c7ade86caa7
(svn r2361) - Feature: [newgrf] Implement varaction2 property 0x41 and 0xDA. These are the position in and length of chain of consecutive vehicles with the same type, and index of the next wagon in the chain (INVALID_VEHICLE if last), resp. Improves displaying of some engines in the dbsetxl.
hackykid
parents:
1840
diff
changeset
|
245 |
chain_after++; |
426
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
246 |
u = u->next; |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
247 |
}; |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
248 |
|
1559
c0d5d35b25db
(svn r2063) Fix: the 0x40 deterministic spritegroup for vehicles was wrong, modified to match the wiki again. (The wiki was partially wrong, too! ;) (Patch by HackyKid.)
pasky
parents:
1539
diff
changeset
|
249 |
value = chain_before | chain_after << 8 |
c0d5d35b25db
(svn r2063) Fix: the 0x40 deterministic spritegroup for vehicles was wrong, modified to match the wiki again. (The wiki was partially wrong, too! ;) (Patch by HackyKid.)
pasky
parents:
1539
diff
changeset
|
250 |
| (chain_before + chain_after) << 16; |
426
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
251 |
} else { |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
252 |
value = 1; /* 1 vehicle in the chain */ |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
253 |
} |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
254 |
|
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
255 |
} else { |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
256 |
// TTDPatch runs on little-endian arch; |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
257 |
// Variable is 0x80 + offset in TTD's vehicle structure |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
258 |
switch (dsg->variable - 0x80) { |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
259 |
#define veh_prop(id_, value_) case (id_): value = (value_); break |
426
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
260 |
veh_prop(0x00, veh->type); |
2708
48714bad9499
(svn r3252) - NewGRF: Map new train subtypes to old types for rail vehicles.
peter1138
parents:
2639
diff
changeset
|
261 |
veh_prop(0x01, MapOldSubType(veh)); |
426
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
262 |
veh_prop(0x04, veh->index); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
263 |
veh_prop(0x05, veh->index & 0xFF); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
264 |
/* XXX? Is THIS right? */ |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
265 |
veh_prop(0x0A, PackOrder(&veh->current_order)); |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
266 |
veh_prop(0x0B, PackOrder(&veh->current_order) & 0xff); |
426
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
267 |
veh_prop(0x0C, veh->num_orders); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
268 |
veh_prop(0x0D, veh->cur_order_index); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
269 |
veh_prop(0x10, veh->load_unload_time_rem); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
270 |
veh_prop(0x11, veh->load_unload_time_rem & 0xFF); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
271 |
veh_prop(0x12, veh->date_of_last_service); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
272 |
veh_prop(0x13, veh->date_of_last_service & 0xFF); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
273 |
veh_prop(0x14, veh->service_interval); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
274 |
veh_prop(0x15, veh->service_interval & 0xFF); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
275 |
veh_prop(0x16, veh->last_station_visited); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
276 |
veh_prop(0x17, veh->tick_counter); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
277 |
veh_prop(0x18, veh->max_speed); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
278 |
veh_prop(0x19, veh->max_speed & 0xFF); |
3300
073fe603d5ba
(svn r4039) - NewGRF: Add support for a few more vehicle variables. These are sometimes used for animation of sprites.
peter1138
parents:
3157
diff
changeset
|
279 |
veh_prop(0x1A, veh->x_pos); |
073fe603d5ba
(svn r4039) - NewGRF: Add support for a few more vehicle variables. These are sometimes used for animation of sprites.
peter1138
parents:
3157
diff
changeset
|
280 |
veh_prop(0x1B, veh->x_pos & 0xFF); |
073fe603d5ba
(svn r4039) - NewGRF: Add support for a few more vehicle variables. These are sometimes used for animation of sprites.
peter1138
parents:
3157
diff
changeset
|
281 |
veh_prop(0x1C, veh->y_pos); |
073fe603d5ba
(svn r4039) - NewGRF: Add support for a few more vehicle variables. These are sometimes used for animation of sprites.
peter1138
parents:
3157
diff
changeset
|
282 |
veh_prop(0x1D, veh->y_pos & 0xFF); |
073fe603d5ba
(svn r4039) - NewGRF: Add support for a few more vehicle variables. These are sometimes used for animation of sprites.
peter1138
parents:
3157
diff
changeset
|
283 |
veh_prop(0x1E, veh->z_pos); |
426
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
284 |
veh_prop(0x1F, veh->direction); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
285 |
veh_prop(0x28, veh->cur_image); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
286 |
veh_prop(0x29, veh->cur_image & 0xFF); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
287 |
veh_prop(0x32, veh->vehstatus); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
288 |
veh_prop(0x33, veh->vehstatus); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
289 |
veh_prop(0x34, veh->cur_speed); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
290 |
veh_prop(0x35, veh->cur_speed & 0xFF); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
291 |
veh_prop(0x36, veh->subspeed); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
292 |
veh_prop(0x37, veh->acceleration); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
293 |
veh_prop(0x39, veh->cargo_type); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
294 |
veh_prop(0x3A, veh->cargo_cap); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
295 |
veh_prop(0x3B, veh->cargo_cap & 0xFF); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
296 |
veh_prop(0x3C, veh->cargo_count); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
297 |
veh_prop(0x3D, veh->cargo_count & 0xFF); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
298 |
veh_prop(0x3E, veh->cargo_source); // Probably useless; so what |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
299 |
veh_prop(0x3F, veh->cargo_days); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
300 |
veh_prop(0x40, veh->age); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
301 |
veh_prop(0x41, veh->age & 0xFF); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
302 |
veh_prop(0x42, veh->max_age); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
303 |
veh_prop(0x43, veh->max_age & 0xFF); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
304 |
veh_prop(0x44, veh->build_year); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
305 |
veh_prop(0x45, veh->unitnumber); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
306 |
veh_prop(0x46, veh->engine_type); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
307 |
veh_prop(0x47, veh->engine_type & 0xFF); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
308 |
veh_prop(0x48, veh->spritenum); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
309 |
veh_prop(0x49, veh->day_counter); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
310 |
veh_prop(0x4A, veh->breakdowns_since_last_service); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
311 |
veh_prop(0x4B, veh->breakdown_ctr); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
312 |
veh_prop(0x4C, veh->breakdown_delay); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
313 |
veh_prop(0x4D, veh->breakdown_chance); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
314 |
veh_prop(0x4E, veh->reliability); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
315 |
veh_prop(0x4F, veh->reliability & 0xFF); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
316 |
veh_prop(0x50, veh->reliability_spd_dec); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
317 |
veh_prop(0x51, veh->reliability_spd_dec & 0xFF); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
318 |
veh_prop(0x52, veh->profit_this_year); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
319 |
veh_prop(0x53, veh->profit_this_year & 0xFFFFFF); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
320 |
veh_prop(0x54, veh->profit_this_year & 0xFFFF); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
321 |
veh_prop(0x55, veh->profit_this_year & 0xFF); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
322 |
veh_prop(0x56, veh->profit_last_year); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
323 |
veh_prop(0x57, veh->profit_last_year & 0xFF); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
324 |
veh_prop(0x58, veh->profit_last_year); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
325 |
veh_prop(0x59, veh->profit_last_year & 0xFF); |
1855
6c7ade86caa7
(svn r2361) - Feature: [newgrf] Implement varaction2 property 0x41 and 0xDA. These are the position in and length of chain of consecutive vehicles with the same type, and index of the next wagon in the chain (INVALID_VEHICLE if last), resp. Improves displaying of some engines in the dbsetxl.
hackykid
parents:
1840
diff
changeset
|
326 |
veh_prop(0x5A, veh->next == NULL ? INVALID_VEHICLE : veh->next->index); |
426
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
327 |
veh_prop(0x5C, veh->value); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
328 |
veh_prop(0x5D, veh->value & 0xFFFFFF); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
329 |
veh_prop(0x5E, veh->value & 0xFFFF); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
330 |
veh_prop(0x5F, veh->value & 0xFF); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
331 |
veh_prop(0x60, veh->string_id); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
332 |
veh_prop(0x61, veh->string_id & 0xFF); |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
333 |
|
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
|
334 |
veh_prop(0x72, 0); // XXX Refit cycle currently unsupported |
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
|
335 |
veh_prop(0x7A, veh->random_bits); |
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
|
336 |
veh_prop(0x7B, veh->waiting_triggers); |
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
|
337 |
#undef veh_prop |
426
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
338 |
|
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
|
339 |
// Handle vehicle specific properties. |
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
|
340 |
default: value = VehicleSpecificProperty(veh, dsg->variable - 0x80); break; |
426
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
341 |
} |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
342 |
} |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
343 |
} |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
344 |
|
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
345 |
target = value != -1 ? EvalDeterministicSpriteGroup(dsg, value) : dsg->default_group; |
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
|
346 |
//debug("Resolved variable %x: %d, %p", dsg->variable, value, callback); |
1883
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
347 |
return resolve_func(target, veh, callback_info, resolve_func); |
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
|
348 |
} |
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
|
349 |
|
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
|
350 |
case SGT_RANDOMIZED: { |
2242
512eae2cf006
(svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents:
2204
diff
changeset
|
351 |
const RandomizedSpriteGroup *rsg = &spritegroup->g.random; |
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
|
352 |
|
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
|
353 |
if (veh == NULL) { |
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
|
354 |
/* Purchase list of something. Show the first one. */ |
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
|
355 |
assert(rsg->num_groups > 0); |
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
|
356 |
//debug("going for %p: %d", rsg->groups[0], rsg->groups[0].type); |
2488
1e98c71e5f6a
(svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents:
2477
diff
changeset
|
357 |
return resolve_func(rsg->groups[0], NULL, callback_info, resolve_func); |
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
|
358 |
} |
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
|
359 |
|
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
|
360 |
if (rsg->var_scope == VSG_SCOPE_PARENT) { |
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
|
361 |
/* First engine in the vehicle 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
|
362 |
if (veh->type == VEH_Train) |
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
|
363 |
veh = GetFirstVehicleInChain(veh); |
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
|
364 |
} |
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
|
365 |
|
1883
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
366 |
return resolve_func(EvalRandomizedSpriteGroup(rsg, veh->random_bits), veh, callback_info, resolve_func); |
426
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
367 |
} |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
368 |
|
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
369 |
default: |
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
|
370 |
error("I don't know how to handle such a spritegroup %d!", spritegroup->type); |
426
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
371 |
return NULL; |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
372 |
} |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
373 |
} |
381172276dc6
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
374 |
|
2477
225b2916fe2a
(svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents:
2469
diff
changeset
|
375 |
static const SpriteGroup *GetVehicleSpriteGroup(EngineID engine, const Vehicle *v) |
0 | 376 |
{ |
2242
512eae2cf006
(svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents:
2204
diff
changeset
|
377 |
const SpriteGroup *group; |
3344
fc86351d4641
(svn r4128) - CodeChange: Add proper semantics for CargoID for such variables instead of using the general byte-type.
Darkvater
parents:
3300
diff
changeset
|
378 |
CargoID cargo = GC_PURCHASE; |
0 | 379 |
|
414
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
410
diff
changeset
|
380 |
if (v != NULL) { |
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
410
diff
changeset
|
381 |
cargo = _global_cargo_id[_opt.landscape][v->cargo_type]; |
1802
da61740cc1e7
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1786
diff
changeset
|
382 |
assert(cargo != GC_INVALID); |
414
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
410
diff
changeset
|
383 |
} |
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
410
diff
changeset
|
384 |
|
2488
1e98c71e5f6a
(svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents:
2477
diff
changeset
|
385 |
group = engine_custom_sprites[engine][cargo]; |
414
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
410
diff
changeset
|
386 |
|
1560
d040e4763f45
(svn r2064) - Codechange: GetVehicleSpriteGroup() cleanup - drop overriding_engine, which was around probably only for historical reasons. (Paralellily developed by HackyKid.)
pasky
parents:
1559
diff
changeset
|
387 |
if (v != NULL && v->type == VEH_Train) { |
2242
512eae2cf006
(svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents:
2204
diff
changeset
|
388 |
const SpriteGroup *overset = GetWagonOverrideSpriteSet(engine, v->u.rail.first_engine); |
0 | 389 |
|
1477 | 390 |
if (overset != NULL) group = overset; |
0 | 391 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
114
diff
changeset
|
392 |
|
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
|
393 |
return group; |
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
|
394 |
} |
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
|
395 |
|
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3014
diff
changeset
|
396 |
int GetCustomEngineSprite(EngineID engine, const Vehicle* v, Direction direction) |
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
|
397 |
{ |
2242
512eae2cf006
(svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents:
2204
diff
changeset
|
398 |
const SpriteGroup *group; |
512eae2cf006
(svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents:
2204
diff
changeset
|
399 |
const RealSpriteGroup *rsg; |
1802
da61740cc1e7
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1786
diff
changeset
|
400 |
byte cargo = GC_PURCHASE; |
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
|
401 |
byte loaded = 0; |
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
|
402 |
bool in_motion = 0; |
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
|
403 |
int totalsets, spriteset; |
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
|
404 |
int r; |
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
|
405 |
|
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
|
406 |
if (v != NULL) { |
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
|
407 |
int capacity = v->cargo_cap; |
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
|
408 |
|
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
|
409 |
cargo = _global_cargo_id[_opt.landscape][v->cargo_type]; |
1802
da61740cc1e7
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1786
diff
changeset
|
410 |
assert(cargo != GC_INVALID); |
da61740cc1e7
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1786
diff
changeset
|
411 |
|
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
|
412 |
if (capacity == 0) capacity = 1; |
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
|
413 |
loaded = (v->cargo_count * 100) / capacity; |
2830
655a34aef536
(svn r3378) - NewGRF Fix: Use order status to determine whether a vehicle is loading instead
peter1138
parents:
2817
diff
changeset
|
414 |
|
655a34aef536
(svn r3378) - NewGRF Fix: Use order status to determine whether a vehicle is loading instead
peter1138
parents:
2817
diff
changeset
|
415 |
if (v->type == VEH_Train) { |
655a34aef536
(svn r3378) - NewGRF Fix: Use order status to determine whether a vehicle is loading instead
peter1138
parents:
2817
diff
changeset
|
416 |
in_motion = GetFirstVehicleInChain(v)->current_order.type != OT_LOADING; |
655a34aef536
(svn r3378) - NewGRF Fix: Use order status to determine whether a vehicle is loading instead
peter1138
parents:
2817
diff
changeset
|
417 |
} else { |
655a34aef536
(svn r3378) - NewGRF Fix: Use order status to determine whether a vehicle is loading instead
peter1138
parents:
2817
diff
changeset
|
418 |
in_motion = v->current_order.type != OT_LOADING; |
655a34aef536
(svn r3378) - NewGRF Fix: Use order status to determine whether a vehicle is loading instead
peter1138
parents:
2817
diff
changeset
|
419 |
} |
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
|
420 |
} |
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
|
421 |
|
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
|
422 |
group = GetVehicleSpriteGroup(engine, v); |
1883
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
423 |
group = ResolveVehicleSpriteGroup(group, v, 0, (resolve_callback) ResolveVehicleSpriteGroup); |
408
48da21eb9ff2
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
424 |
|
2488
1e98c71e5f6a
(svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents:
2477
diff
changeset
|
425 |
if (group == NULL && cargo != GC_DEFAULT) { |
369
3742b39b6cca
(svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents:
292
diff
changeset
|
426 |
// This group is empty but perhaps there'll be a default one. |
2488
1e98c71e5f6a
(svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents:
2477
diff
changeset
|
427 |
group = ResolveVehicleSpriteGroup(engine_custom_sprites[engine][GC_DEFAULT], v, 0, |
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
|
428 |
(resolve_callback) ResolveVehicleSpriteGroup); |
0 | 429 |
} |
430 |
||
2488
1e98c71e5f6a
(svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents:
2477
diff
changeset
|
431 |
if (group == NULL) |
1e98c71e5f6a
(svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents:
2477
diff
changeset
|
432 |
return 0; |
1e98c71e5f6a
(svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents:
2477
diff
changeset
|
433 |
|
1883
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
434 |
assert(group->type == SGT_REAL); |
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
435 |
rsg = &group->g.real; |
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
436 |
|
408
48da21eb9ff2
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
437 |
if (!rsg->sprites_per_set) { |
369
3742b39b6cca
(svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents:
292
diff
changeset
|
438 |
// This group is empty. This function users should therefore |
0 | 439 |
// look up the sprite number in _engine_original_sprites. |
440 |
return 0; |
|
441 |
} |
|
442 |
||
1988
c23f5c7139bb
(svn r2494) - Fix: [newgrf] Dont assume a spriteset can only have 4 or 8 sprites.
hackykid
parents:
1962
diff
changeset
|
443 |
assert(rsg->sprites_per_set <= 8); |
c23f5c7139bb
(svn r2494) - Fix: [newgrf] Dont assume a spriteset can only have 4 or 8 sprites.
hackykid
parents:
1962
diff
changeset
|
444 |
direction %= rsg->sprites_per_set; |
0 | 445 |
|
408
48da21eb9ff2
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
446 |
totalsets = in_motion ? rsg->loaded_count : rsg->loading_count; |
0 | 447 |
|
448 |
// My aim here is to make it possible to visually determine absolutely |
|
449 |
// empty and totally full vehicles. --pasky |
|
450 |
if (loaded == 100 || totalsets == 1) { // full |
|
451 |
spriteset = totalsets - 1; |
|
452 |
} else if (loaded == 0 || totalsets == 2) { // empty |
|
453 |
spriteset = 0; |
|
454 |
} else { // something inbetween |
|
455 |
spriteset = loaded * (totalsets - 2) / 100 + 1; |
|
456 |
// correct possible rounding errors |
|
457 |
if (!spriteset) |
|
458 |
spriteset = 1; |
|
459 |
else if (spriteset == totalsets - 1) |
|
460 |
spriteset--; |
|
461 |
} |
|
462 |
||
2489
6fbb72b64e07
(svn r3015) -NewGRF: Add a new sprite group result type, and support loading of callbacks results within random and "real" groups. (Not fully supported yet.)
peter1138
parents:
2488
diff
changeset
|
463 |
r = (in_motion ? rsg->loaded[spriteset]->g.result.result : rsg->loading[spriteset]->g.result.result) + direction; |
0 | 464 |
return r; |
465 |
} |
|
466 |
||
1883
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
467 |
/** |
1908
2fa391fed79a
(svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents:
1904
diff
changeset
|
468 |
* 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
|
469 |
* @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
|
470 |
* @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
|
471 |
*/ |
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
|
472 |
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
|
473 |
{ |
1908
2fa391fed79a
(svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents:
1904
diff
changeset
|
474 |
assert(v->type == VEH_Train); |
2242
512eae2cf006
(svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents:
2204
diff
changeset
|
475 |
return GetWagonOverrideSpriteSet(v->engine_type, v->u.rail.first_engine) != NULL; |
1908
2fa391fed79a
(svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents:
1904
diff
changeset
|
476 |
} |
2fa391fed79a
(svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents:
1904
diff
changeset
|
477 |
|
2fa391fed79a
(svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents:
1904
diff
changeset
|
478 |
/** |
1883
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
479 |
* Evaluates a newgrf callback |
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
480 |
* @param callback_info info about which callback to evaluate |
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
481 |
* (bit 0-7) = CallBack id of the callback to use, see CallBackId enum |
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
482 |
* (bit 8-15) = Other info some callbacks need to have, callback specific, see CallBackId enum, not used yet |
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
483 |
* @param engine Engine type of the vehicle to evaluate the callback for |
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
484 |
* @param vehicle The vehicle to evaluate the callback for, NULL if it doesnt exist (yet) |
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
485 |
* @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
|
486 |
*/ |
2477
225b2916fe2a
(svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents:
2469
diff
changeset
|
487 |
uint16 GetCallBackResult(uint16 callback_info, EngineID engine, const Vehicle *v) |
1883
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
488 |
{ |
2242
512eae2cf006
(svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents:
2204
diff
changeset
|
489 |
const SpriteGroup *group; |
1883
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
490 |
byte cargo = GC_DEFAULT; |
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
491 |
|
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
492 |
if (v != NULL) |
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
493 |
cargo = _global_cargo_id[_opt.landscape][v->cargo_type]; |
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
494 |
|
2488
1e98c71e5f6a
(svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents:
2477
diff
changeset
|
495 |
group = engine_custom_sprites[engine][cargo]; |
1904
6459332eded4
(svn r2410) - Fix: [newgrf] When resolving callbacks, dont ignore wagon overrides.
hackykid
parents:
1891
diff
changeset
|
496 |
|
6459332eded4
(svn r2410) - Fix: [newgrf] When resolving callbacks, dont ignore wagon overrides.
hackykid
parents:
1891
diff
changeset
|
497 |
if (v != NULL && v->type == VEH_Train) { |
2242
512eae2cf006
(svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents:
2204
diff
changeset
|
498 |
const SpriteGroup *overset = GetWagonOverrideSpriteSet(engine, v->u.rail.first_engine); |
1904
6459332eded4
(svn r2410) - Fix: [newgrf] When resolving callbacks, dont ignore wagon overrides.
hackykid
parents:
1891
diff
changeset
|
499 |
|
6459332eded4
(svn r2410) - Fix: [newgrf] When resolving callbacks, dont ignore wagon overrides.
hackykid
parents:
1891
diff
changeset
|
500 |
if (overset != NULL) group = overset; |
6459332eded4
(svn r2410) - Fix: [newgrf] When resolving callbacks, dont ignore wagon overrides.
hackykid
parents:
1891
diff
changeset
|
501 |
} |
6459332eded4
(svn r2410) - Fix: [newgrf] When resolving callbacks, dont ignore wagon overrides.
hackykid
parents:
1891
diff
changeset
|
502 |
|
1883
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
503 |
group = ResolveVehicleSpriteGroup(group, v, callback_info, (resolve_callback) ResolveVehicleSpriteGroup); |
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
504 |
|
2488
1e98c71e5f6a
(svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents:
2477
diff
changeset
|
505 |
if (group == NULL && cargo != GC_DEFAULT) { |
1883
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
506 |
// This group is empty but perhaps there'll be a default one. |
2488
1e98c71e5f6a
(svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents:
2477
diff
changeset
|
507 |
group = ResolveVehicleSpriteGroup(engine_custom_sprites[engine][GC_DEFAULT], v, callback_info, |
1883
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
508 |
(resolve_callback) ResolveVehicleSpriteGroup); |
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
509 |
} |
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
510 |
|
2488
1e98c71e5f6a
(svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents:
2477
diff
changeset
|
511 |
if (group == NULL || group->type != SGT_CALLBACK) |
1883
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
512 |
return CALLBACK_FAILED; |
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
513 |
|
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
514 |
return group->g.callback.result; |
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
515 |
} |
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
516 |
|
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
517 |
|
0 | 518 |
|
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
|
519 |
// Global variables are evil, yes, but we would end up with horribly overblown |
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
|
520 |
// calling convention otherwise and this should be 100% reentrant. |
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
|
521 |
static byte _vsg_random_triggers; |
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
|
522 |
static byte _vsg_bits_to_reseed; |
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
|
523 |
|
2242
512eae2cf006
(svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents:
2204
diff
changeset
|
524 |
static const SpriteGroup *TriggerVehicleSpriteGroup(const SpriteGroup *spritegroup, |
1883
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
525 |
Vehicle *veh, uint16 callback_info, resolve_callback resolve_func) |
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
|
526 |
{ |
2488
1e98c71e5f6a
(svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents:
2477
diff
changeset
|
527 |
if (spritegroup == NULL) |
1e98c71e5f6a
(svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents:
2477
diff
changeset
|
528 |
return NULL; |
1e98c71e5f6a
(svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents:
2477
diff
changeset
|
529 |
|
1477 | 530 |
if (spritegroup->type == SGT_RANDOMIZED) { |
531 |
_vsg_bits_to_reseed |= RandomizedSpriteGroupTriggeredBits( |
|
532 |
&spritegroup->g.random, |
|
533 |
_vsg_random_triggers, |
|
534 |
&veh->waiting_triggers |
|
535 |
); |
|
536 |
} |
|
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
|
537 |
|
1883
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
538 |
return ResolveVehicleSpriteGroup(spritegroup, veh, callback_info, resolve_func); |
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
|
539 |
} |
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
|
540 |
|
1477 | 541 |
static void DoTriggerVehicle(Vehicle *veh, 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
|
542 |
{ |
2242
512eae2cf006
(svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents:
2204
diff
changeset
|
543 |
const SpriteGroup *group; |
512eae2cf006
(svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents:
2204
diff
changeset
|
544 |
const RealSpriteGroup *rsg; |
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
|
545 |
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
|
546 |
|
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
|
547 |
_vsg_random_triggers = 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
|
548 |
_vsg_bits_to_reseed = 0; |
1883
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
549 |
group = TriggerVehicleSpriteGroup(GetVehicleSpriteGroup(veh->engine_type, veh), veh, 0, |
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
550 |
(resolve_callback) TriggerVehicleSpriteGroup); |
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
551 |
|
2488
1e98c71e5f6a
(svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents:
2477
diff
changeset
|
552 |
if (group == NULL && veh->cargo_type != GC_DEFAULT) { |
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
|
553 |
// This group turned out to be empty but perhaps there'll be a default one. |
2488
1e98c71e5f6a
(svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents:
2477
diff
changeset
|
554 |
group = TriggerVehicleSpriteGroup(engine_custom_sprites[veh->engine_type][GC_DEFAULT], veh, 0, |
1883
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
555 |
(resolve_callback) TriggerVehicleSpriteGroup); |
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
|
556 |
} |
1883
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
557 |
|
2488
1e98c71e5f6a
(svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents:
2477
diff
changeset
|
558 |
if (group == NULL) |
1e98c71e5f6a
(svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents:
2477
diff
changeset
|
559 |
return; |
1e98c71e5f6a
(svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents:
2477
diff
changeset
|
560 |
|
1883
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
561 |
assert(group->type == SGT_REAL); |
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
562 |
rsg = &group->g.real; |
ad68cd0a0a25
(svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents:
1881
diff
changeset
|
563 |
|
542 | 564 |
new_random_bits = Random(); |
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
|
565 |
veh->random_bits &= ~_vsg_bits_to_reseed; |
542 | 566 |
veh->random_bits |= (first ? new_random_bits : base_random_bits) & _vsg_bits_to_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
|
567 |
|
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
|
568 |
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
|
569 |
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
|
570 |
/* 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
|
571 |
* 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
|
572 |
/* 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
|
573 |
* 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
|
574 |
* 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
|
575 |
* 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
|
576 |
* 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
|
577 |
assert(first); |
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
|
578 |
DoTriggerVehicle(GetFirstVehicleInChain(veh), VEHICLE_TRIGGER_ANY_NEW_CARGO, new_random_bits, false); |
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
|
579 |
break; |
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
|
580 |
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
|
581 |
/* 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
|
582 |
* 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
|
583 |
* 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
|
584 |
if (veh->next != NULL) |
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
|
585 |
DoTriggerVehicle(veh->next, trigger, 0, true); |
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
|
586 |
break; |
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
|
587 |
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
|
588 |
/* 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
|
589 |
* 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
|
590 |
* 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
|
591 |
* first chained 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
|
592 |
if (veh->next != NULL) |
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
|
593 |
DoTriggerVehicle(veh->next, trigger, first ? new_random_bits : base_random_bits, false); |
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
|
594 |
break; |
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
|
595 |
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
|
596 |
/* 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
|
597 |
* 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
|
598 |
assert(!first); |
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
|
599 |
if (veh->next != NULL) |
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
|
600 |
DoTriggerVehicle(veh->next, VEHICLE_TRIGGER_ANY_NEW_CARGO, base_random_bits, false); |
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
|
601 |
break; |
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
|
602 |
} |
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
|
603 |
} |
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
|
604 |
|
1477 | 605 |
void TriggerVehicle(Vehicle *veh, 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
|
606 |
{ |
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
|
607 |
if (trigger == VEHICLE_TRIGGER_DEPOT) { |
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
|
608 |
// store that the vehicle entered a depot this tick |
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
|
609 |
VehicleEnteredDepotThisTick(veh); |
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
|
610 |
} |
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
|
611 |
|
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
|
612 |
DoTriggerVehicle(veh, trigger, 0, true); |
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
|
613 |
} |
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
|
614 |
|
1474
a26a21fa10ef
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1329
diff
changeset
|
615 |
static char *_engine_custom_names[TOTAL_NUM_ENGINES]; |
0 | 616 |
|
2477
225b2916fe2a
(svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents:
2469
diff
changeset
|
617 |
void SetCustomEngineName(EngineID engine, const char *name) |
0 | 618 |
{ |
619 |
_engine_custom_names[engine] = strdup(name); |
|
620 |
} |
|
621 |
||
2769
eab49a86038e
(svn r3316) - NewGRF: Unload engine names before loading grf files. This fixes names in climates where the engines don't get loaded. Renamed function to reflect its purpose.
peter1138
parents:
2763
diff
changeset
|
622 |
void UnloadCustomEngineNames(void) |
1474
a26a21fa10ef
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1329
diff
changeset
|
623 |
{ |
a26a21fa10ef
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1329
diff
changeset
|
624 |
char **i; |
a26a21fa10ef
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1329
diff
changeset
|
625 |
for (i = _engine_custom_names; i != endof(_engine_custom_names); i++) { |
a26a21fa10ef
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1329
diff
changeset
|
626 |
free(*i); |
a26a21fa10ef
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1329
diff
changeset
|
627 |
*i = NULL; |
a26a21fa10ef
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1329
diff
changeset
|
628 |
} |
a26a21fa10ef
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1329
diff
changeset
|
629 |
} |
a26a21fa10ef
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1329
diff
changeset
|
630 |
|
2477
225b2916fe2a
(svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents:
2469
diff
changeset
|
631 |
StringID GetCustomEngineName(EngineID engine) |
0 | 632 |
{ |
633 |
if (!_engine_custom_names[engine]) |
|
634 |
return _engine_name_strings[engine]; |
|
2201 | 635 |
ttd_strlcpy(_userstring, _engine_custom_names[engine], lengthof(_userstring)); |
0 | 636 |
return STR_SPEC_USERSTRING; |
637 |
} |
|
638 |
||
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
|
639 |
// Functions for changing the order of vehicle purchase lists |
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
|
640 |
// This is currently only implemented for rail vehicles. |
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
|
641 |
static EngineID engine_list_order[NUM_TRAIN_ENGINES]; |
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
|
642 |
|
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
|
643 |
void ResetEngineListOrder(void) |
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
|
644 |
{ |
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
|
645 |
EngineID i; |
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
|
646 |
|
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
|
647 |
for (i = 0; i < NUM_TRAIN_ENGINES; i++) |
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
|
648 |
engine_list_order[i] = i; |
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
|
649 |
} |
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
|
650 |
|
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
|
651 |
EngineID GetRailVehAtPosition(EngineID pos) |
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
|
652 |
{ |
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
|
653 |
return engine_list_order[pos]; |
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
|
654 |
} |
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
|
655 |
|
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
|
656 |
void AlterRailVehListOrder(EngineID engine, EngineID target) |
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
|
657 |
{ |
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
|
658 |
EngineID i; |
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
|
659 |
bool moving = false; |
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
|
660 |
|
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
|
661 |
if (engine == target) return; |
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
|
662 |
|
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
|
663 |
// First, remove our ID from the list. |
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
|
664 |
for (i = 0; i < NUM_TRAIN_ENGINES - 1; i++) { |
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
|
665 |
if (engine_list_order[i] == engine) |
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
|
666 |
moving = true; |
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
|
667 |
if (moving) |
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
|
668 |
engine_list_order[i] = engine_list_order[i + 1]; |
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
|
669 |
} |
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
|
670 |
|
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
|
671 |
// Now, insert it again, before the target engine. |
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
|
672 |
for (i = NUM_TRAIN_ENGINES - 1; i > 0; i--) { |
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
|
673 |
engine_list_order[i] = engine_list_order[i - 1]; |
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
|
674 |
if (engine_list_order[i] == target) { |
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
|
675 |
engine_list_order[i - 1] = engine; |
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
|
676 |
break; |
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
|
677 |
} |
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
|
678 |
} |
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
|
679 |
} |