annotate src/newgrf_cargo.cpp @ 18302:4925b06e241f draft

(svn r23138) -Feature: [NewGRF] Allow passing 32bit parameters to 60+x variables (using var 7B). Currently most useful for vehicle var 60.
author frosch <frosch@openttd.org>
date Tue, 08 Nov 2011 17:23:30 +0000
parents 2d62fee43556
children 88567087417f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6365
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
1 /* $Id$ */
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
2
12778
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12415
diff changeset
3 /*
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12415
diff changeset
4 * This file is part of OpenTTD.
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12415
diff changeset
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12415
diff changeset
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12415
diff changeset
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12415
diff changeset
8 */
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12415
diff changeset
9
9111
d48433370037 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium <rubidium@openttd.org>
parents: 8756
diff changeset
10 /** @file newgrf_cargo.cpp Implementation of NewGRF cargoes. */
d48433370037 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium <rubidium@openttd.org>
parents: 8756
diff changeset
11
6365
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
12 #include "stdafx.h"
6383
1c59b042b9e3 (svn r9473) -Codechange: add 'unhandled variable' debug message to newcargo resolver
peter1138 <peter1138@openttd.org>
parents: 6365
diff changeset
13 #include "debug.h"
6365
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
14 #include "newgrf.h"
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
15 #include "newgrf_spritegroup.h"
14258
a899d4e5ee1a (svn r18809) -Codechange/Cleanup: remove unneeded headers from some files, if a header require a header make it include that header
rubidium <rubidium@openttd.org>
parents: 13186
diff changeset
16 #include "core/bitmath_func.hpp"
6365
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
17
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
18 static uint32 CargoGetRandomBits(const ResolverObject *object)
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
19 {
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
20 return 0;
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
21 }
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
22
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
23
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
24 static uint32 CargoGetTriggers(const ResolverObject *object)
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
25 {
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
26 return 0;
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
27 }
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
28
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
29
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
30 static void CargoSetTriggers(const ResolverObject *object, int triggers)
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
31 {
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
32 return;
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
33 }
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
34
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
35
18302
4925b06e241f (svn r23138) -Feature: [NewGRF] Allow passing 32bit parameters to 60+x variables (using var 7B). Currently most useful for vehicle var 60.
frosch <frosch@openttd.org>
parents: 17843
diff changeset
36 static uint32 CargoGetVariable(const ResolverObject *object, byte variable, uint32 parameter, bool *available)
6365
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
37 {
16474
17ecbae7d3b4 (svn r21198) -Fix: don't call variables properties in debug messages
rubidium <rubidium@openttd.org>
parents: 14561
diff changeset
38 DEBUG(grf, 1, "Unhandled cargo variable 0x%X", variable);
6383
1c59b042b9e3 (svn r9473) -Codechange: add 'unhandled variable' debug message to newcargo resolver
peter1138 <peter1138@openttd.org>
parents: 6365
diff changeset
39
6365
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
40 *available = false;
11163
dbb22d77aec1 (svn r15513) -Cleanup: Unavailable varaction variable value does not matter, but at least it can be consistent.
peter1138 <peter1138@openttd.org>
parents: 10960
diff changeset
41 return UINT_MAX;
6365
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
42 }
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
43
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
44
11990
db0e49f419d9 (svn r16396) -Codechange: split NewGRF spritegroup into multiple subclasses instead of using a big union
rubidium <rubidium@openttd.org>
parents: 11163
diff changeset
45 static const SpriteGroup *CargoResolveReal(const ResolverObject *object, const RealSpriteGroup *group)
6365
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
46 {
6657
05dc53b3e64a (svn r9888) -Codechange: [NewGRF] allow non-spec cargo action2s to work, and using the goods sprite if really nothing is returned.
peter1138 <peter1138@openttd.org>
parents: 6460
diff changeset
47 /* Cargo action 2s should always have only 1 "loaded" state, but some
05dc53b3e64a (svn r9888) -Codechange: [NewGRF] allow non-spec cargo action2s to work, and using the goods sprite if really nothing is returned.
peter1138 <peter1138@openttd.org>
parents: 6460
diff changeset
48 * times things don't follow the spec... */
11990
db0e49f419d9 (svn r16396) -Codechange: split NewGRF spritegroup into multiple subclasses instead of using a big union
rubidium <rubidium@openttd.org>
parents: 11163
diff changeset
49 if (group->num_loaded > 0) return group->loaded[0];
db0e49f419d9 (svn r16396) -Codechange: split NewGRF spritegroup into multiple subclasses instead of using a big union
rubidium <rubidium@openttd.org>
parents: 11163
diff changeset
50 if (group->num_loading > 0) return group->loading[0];
6365
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
51
6657
05dc53b3e64a (svn r9888) -Codechange: [NewGRF] allow non-spec cargo action2s to work, and using the goods sprite if really nothing is returned.
peter1138 <peter1138@openttd.org>
parents: 6460
diff changeset
52 return NULL;
6365
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
53 }
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
54
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
55
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
56 static void NewCargoResolver(ResolverObject *res, const CargoSpec *cs)
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
57 {
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
58 res->GetRandomBits = &CargoGetRandomBits;
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
59 res->GetTriggers = &CargoGetTriggers;
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
60 res->SetTriggers = &CargoSetTriggers;
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
61 res->GetVariable = &CargoGetVariable;
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
62 res->ResolveReal = &CargoResolveReal;
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
63
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
64 res->u.cargo.cs = cs;
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
65
7327
0ab2820a1e52 (svn r10690) -Codechange: use the enum that describes all callback IDs in favor of "just" using an untyped integer.
rubidium <rubidium@openttd.org>
parents: 7199
diff changeset
66 res->callback = CBID_NO_CALLBACK;
6365
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
67 res->callback_param1 = 0;
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
68 res->callback_param2 = 0;
17843
2d62fee43556 (svn r22634) -Codechange: Deduplicate some code. Note that zeroing 'count' is intentionally removed, it is only used together with 'scope'.
frosch <frosch@openttd.org>
parents: 16474
diff changeset
69 res->ResetState();
2d62fee43556 (svn r22634) -Codechange: Deduplicate some code. Note that zeroing 'count' is intentionally removed, it is only used together with 'scope'.
frosch <frosch@openttd.org>
parents: 16474
diff changeset
70
9750
0654bf387d06 (svn r13885) -Fix [FS#2168]: Var 0x7F is not feature-specific.
frosch <frosch@openttd.org>
parents: 9728
diff changeset
71 res->grffile = cs->grffile;
6365
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
72 }
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
73
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
74
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
75 SpriteID GetCustomCargoSprite(const CargoSpec *cs)
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
76 {
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
77 const SpriteGroup *group;
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
78 ResolverObject object;
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
79
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
80 NewCargoResolver(&object, cs);
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
81
11996
b43cf6c7ea61 (svn r16402) -Codechange: make Resolve a function of SpriteGroup
rubidium <rubidium@openttd.org>
parents: 11990
diff changeset
82 group = SpriteGroup::Resolve(cs->group, &object);
11990
db0e49f419d9 (svn r16396) -Codechange: split NewGRF spritegroup into multiple subclasses instead of using a big union
rubidium <rubidium@openttd.org>
parents: 11163
diff changeset
83 if (group == NULL) return 0;
6365
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
84
11990
db0e49f419d9 (svn r16396) -Codechange: split NewGRF spritegroup into multiple subclasses instead of using a big union
rubidium <rubidium@openttd.org>
parents: 11163
diff changeset
85 return group->GetResult();
6365
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
86 }
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
87
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
88
7327
0ab2820a1e52 (svn r10690) -Codechange: use the enum that describes all callback IDs in favor of "just" using an untyped integer.
rubidium <rubidium@openttd.org>
parents: 7199
diff changeset
89 uint16 GetCargoCallback(CallbackID callback, uint32 param1, uint32 param2, const CargoSpec *cs)
6365
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
90 {
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
91 ResolverObject object;
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
92 const SpriteGroup *group;
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
93
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
94 NewCargoResolver(&object, cs);
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
95 object.callback = callback;
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
96 object.callback_param1 = param1;
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
97 object.callback_param2 = param2;
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
98
11996
b43cf6c7ea61 (svn r16402) -Codechange: make Resolve a function of SpriteGroup
rubidium <rubidium@openttd.org>
parents: 11990
diff changeset
99 group = SpriteGroup::Resolve(cs->group, &object);
11990
db0e49f419d9 (svn r16396) -Codechange: split NewGRF spritegroup into multiple subclasses instead of using a big union
rubidium <rubidium@openttd.org>
parents: 11163
diff changeset
100 if (group == NULL) return CALLBACK_FAILED;
6365
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
101
11990
db0e49f419d9 (svn r16396) -Codechange: split NewGRF spritegroup into multiple subclasses instead of using a big union
rubidium <rubidium@openttd.org>
parents: 11163
diff changeset
102 return group->GetCallbackResult();
6365
0d8a8ec46519 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138 <peter1138@openttd.org>
parents:
diff changeset
103 }
6460
cebf3bbc9227 (svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138 <peter1138@openttd.org>
parents: 6383
diff changeset
104
cebf3bbc9227 (svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138 <peter1138@openttd.org>
parents: 6383
diff changeset
105
7717
8dbe339637d3 (svn r11252) -Revert r11239, Fix r9620: cargo translation was not done correctly
glx <glx@openttd.org>
parents: 7327
diff changeset
106 CargoID GetCargoTranslation(uint8 cargo, const GRFFile *grffile, bool usebit)
6460
cebf3bbc9227 (svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138 <peter1138@openttd.org>
parents: 6383
diff changeset
107 {
cebf3bbc9227 (svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138 <peter1138@openttd.org>
parents: 6383
diff changeset
108 /* Pre-version 7 uses the 'climate dependent' ID, i.e. cargo is the cargo ID */
7717
8dbe339637d3 (svn r11252) -Revert r11239, Fix r9620: cargo translation was not done correctly
glx <glx@openttd.org>
parents: 7327
diff changeset
109 if (grffile->grf_version < 7) {
8dbe339637d3 (svn r11252) -Revert r11239, Fix r9620: cargo translation was not done correctly
glx <glx@openttd.org>
parents: 7327
diff changeset
110 if (!usebit) return cargo;
8dbe339637d3 (svn r11252) -Revert r11239, Fix r9620: cargo translation was not done correctly
glx <glx@openttd.org>
parents: 7327
diff changeset
111 /* Else the cargo value is a 'climate independent' 'bitnum' */
7928
4e8dfd103163 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents: 7717
diff changeset
112 if (HasBit(_cargo_mask, cargo)) return GetCargoIDByBitnum(cargo);
7717
8dbe339637d3 (svn r11252) -Revert r11239, Fix r9620: cargo translation was not done correctly
glx <glx@openttd.org>
parents: 7327
diff changeset
113 } else {
9728
e3d8ea8e7db4 (svn r13855) -Fix [FS#2157]: Cargo type lookup was incorrect for GRFv7 files without a translation table.
peter1138 <peter1138@openttd.org>
parents: 9111
diff changeset
114 /* If the GRF contains a translation table... */
e3d8ea8e7db4 (svn r13855) -Fix [FS#2157]: Cargo type lookup was incorrect for GRFv7 files without a translation table.
peter1138 <peter1138@openttd.org>
parents: 9111
diff changeset
115 if (grffile->cargo_max > 0) {
e3d8ea8e7db4 (svn r13855) -Fix [FS#2157]: Cargo type lookup was incorrect for GRFv7 files without a translation table.
peter1138 <peter1138@openttd.org>
parents: 9111
diff changeset
116 /* ...and the cargo is in bounds, then get the cargo ID for
e3d8ea8e7db4 (svn r13855) -Fix [FS#2157]: Cargo type lookup was incorrect for GRFv7 files without a translation table.
peter1138 <peter1138@openttd.org>
parents: 9111
diff changeset
117 * the label */
e3d8ea8e7db4 (svn r13855) -Fix [FS#2157]: Cargo type lookup was incorrect for GRFv7 files without a translation table.
peter1138 <peter1138@openttd.org>
parents: 9111
diff changeset
118 if (cargo < grffile->cargo_max) return GetCargoIDByLabel(grffile->cargo_list[cargo]);
e3d8ea8e7db4 (svn r13855) -Fix [FS#2157]: Cargo type lookup was incorrect for GRFv7 files without a translation table.
peter1138 <peter1138@openttd.org>
parents: 9111
diff changeset
119 } else {
e3d8ea8e7db4 (svn r13855) -Fix [FS#2157]: Cargo type lookup was incorrect for GRFv7 files without a translation table.
peter1138 <peter1138@openttd.org>
parents: 9111
diff changeset
120 /* Else the cargo value is a 'climate independent' 'bitnum' */
e3d8ea8e7db4 (svn r13855) -Fix [FS#2157]: Cargo type lookup was incorrect for GRFv7 files without a translation table.
peter1138 <peter1138@openttd.org>
parents: 9111
diff changeset
121 if (HasBit(_cargo_mask, cargo)) return GetCargoIDByBitnum(cargo);
e3d8ea8e7db4 (svn r13855) -Fix [FS#2157]: Cargo type lookup was incorrect for GRFv7 files without a translation table.
peter1138 <peter1138@openttd.org>
parents: 9111
diff changeset
122 }
7717
8dbe339637d3 (svn r11252) -Revert r11239, Fix r9620: cargo translation was not done correctly
glx <glx@openttd.org>
parents: 7327
diff changeset
123 }
8dbe339637d3 (svn r11252) -Revert r11239, Fix r9620: cargo translation was not done correctly
glx <glx@openttd.org>
parents: 7327
diff changeset
124 return CT_INVALID;
6460
cebf3bbc9227 (svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138 <peter1138@openttd.org>
parents: 6383
diff changeset
125 }
7199
0814b1155c40 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium <rubidium@openttd.org>
parents: 6657
diff changeset
126
0814b1155c40 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium <rubidium@openttd.org>
parents: 6657
diff changeset
127 uint8 GetReverseCargoTranslation(CargoID cargo, const GRFFile *grffile)
0814b1155c40 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium <rubidium@openttd.org>
parents: 6657
diff changeset
128 {
8564
2785566a8c4e (svn r12142) -Fix [FS#1766]: Callback 0x3D always gets a cargobit in var 0x18, independent of grf version.
frosch <frosch@openttd.org>
parents: 7928
diff changeset
129 /* Note: All grf versions use CargoBit here. Pre-version 7 do NOT use the 'climate dependent' ID. */
12415
6a77d1df56e2 (svn r16849) -Codechange: replace GetCargo() by CargoSpec::Get()
smatz <smatz@openttd.org>
parents: 11996
diff changeset
130 const CargoSpec *cs = CargoSpec::Get(cargo);
7199
0814b1155c40 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium <rubidium@openttd.org>
parents: 6657
diff changeset
131
0814b1155c40 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium <rubidium@openttd.org>
parents: 6657
diff changeset
132 /* If the GRF contains a translation table (and the cargo is in the table)
0814b1155c40 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium <rubidium@openttd.org>
parents: 6657
diff changeset
133 * then get the cargo ID for the label */
0814b1155c40 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium <rubidium@openttd.org>
parents: 6657
diff changeset
134 for (uint i = 0; i < grffile->cargo_max; i++) {
0814b1155c40 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium <rubidium@openttd.org>
parents: 6657
diff changeset
135 if (cs->label == grffile->cargo_list[i]) return i;
0814b1155c40 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium <rubidium@openttd.org>
parents: 6657
diff changeset
136 }
0814b1155c40 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium <rubidium@openttd.org>
parents: 6657
diff changeset
137
0814b1155c40 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium <rubidium@openttd.org>
parents: 6657
diff changeset
138 /* No matching label was found, so we return the 'climate independent' 'bitnum' */
14561
c94cddea6802 (svn r19132) -Codechange: No need to end a line with ;;.
alberth <alberth@openttd.org>
parents: 14258
diff changeset
139 return cs->bitnum;
7199
0814b1155c40 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium <rubidium@openttd.org>
parents: 6657
diff changeset
140 }