Mercurial > hg > openttd
annotate src/cargotype.cpp @ 17564:d5ff867052a5 draft
(svn r22328) -Add: a flag to GroundVehicles to disable insertion and removal of automatic orders until the next real order is reached.
author | frosch <frosch@openttd.org> |
---|---|
date | Sat, 16 Apr 2011 16:45:35 +0000 (2011-04-16) |
parents | 1111794047a4 |
children | 6bf2acbcbea5 |
rev | line source |
---|---|
6091
17ebeb5a2c37
(svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138 <peter1138@openttd.org>
parents:
diff
changeset
|
1 /* $Id$ */ |
17ebeb5a2c37
(svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138 <peter1138@openttd.org>
parents:
diff
changeset
|
2 |
12778
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12419
diff
changeset
|
3 /* |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12419
diff
changeset
|
4 * This file is part of OpenTTD. |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12419
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:
12419
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:
12419
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:
12419
diff
changeset
|
8 */ |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12419
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:
8264
diff
changeset
|
10 /** @file cargotype.cpp Implementation of cargos. */ |
6123
595dc16a6fd8
(svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
6122
diff
changeset
|
11 |
6091
17ebeb5a2c37
(svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138 <peter1138@openttd.org>
parents:
diff
changeset
|
12 #include "stdafx.h" |
17ebeb5a2c37
(svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138 <peter1138@openttd.org>
parents:
diff
changeset
|
13 #include "cargotype.h" |
8113
c35412099303
(svn r11674) -Codechange: refactor some functions out of macros.h into more logical locations.
rubidium <rubidium@openttd.org>
parents:
7931
diff
changeset
|
14 #include "core/bitmath_func.hpp" |
13881
693e91b02346
(svn r18410) -Codechange: Move GetCargoSprite() to CargoSpec::GetCargoIcon().
alberth <alberth@openttd.org>
parents:
13466
diff
changeset
|
15 #include "newgrf_cargo.h" |
14932
a1cadfd0c372
(svn r19534) -Add: Keep a list of cargo specifications sorted by cargo class / name.
terkhen <terkhen@openttd.org>
parents:
13884
diff
changeset
|
16 #include "strings_func.h" |
a1cadfd0c372
(svn r19534) -Add: Keep a list of cargo specifications sorted by cargo class / name.
terkhen <terkhen@openttd.org>
parents:
13884
diff
changeset
|
17 #include "core/sort_func.hpp" |
6091
17ebeb5a2c37
(svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138 <peter1138@openttd.org>
parents:
diff
changeset
|
18 |
8264
2495310e220f
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium <rubidium@openttd.org>
parents:
8195
diff
changeset
|
19 #include "table/sprites.h" |
2495310e220f
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium <rubidium@openttd.org>
parents:
8195
diff
changeset
|
20 #include "table/strings.h" |
6091
17ebeb5a2c37
(svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138 <peter1138@openttd.org>
parents:
diff
changeset
|
21 #include "table/cargo_const.h" |
17ebeb5a2c37
(svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138 <peter1138@openttd.org>
parents:
diff
changeset
|
22 |
12418
0d8340a4c70e
(svn r16852) -Codechange: use FOR_ALL_CARGOSPECS for iterating over all valid CargoSpecs
smatz <smatz@openttd.org>
parents:
12415
diff
changeset
|
23 CargoSpec CargoSpec::array[NUM_CARGO]; |
6091
17ebeb5a2c37
(svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138 <peter1138@openttd.org>
parents:
diff
changeset
|
24 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
14965
diff
changeset
|
25 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
14965
diff
changeset
|
26 * Bitmask of cargo types available. |
13884
0ee48164ffe2
(svn r18413) -Doc: Added doxygen strings for cargo-type related enums, structs, and functions.
alberth <alberth@openttd.org>
parents:
13881
diff
changeset
|
27 * Initialized during a call to #SetupCargoForClimate. |
0ee48164ffe2
(svn r18413) -Doc: Added doxygen strings for cargo-type related enums, structs, and functions.
alberth <alberth@openttd.org>
parents:
13881
diff
changeset
|
28 */ |
6113
5cf0c6849eee
(svn r8849) -Codechange: Replace hardcoded global/climate cargo mapping tables with dynamically generated data. Change associated code to use new functions.
peter1138 <peter1138@openttd.org>
parents:
6091
diff
changeset
|
29 uint32 _cargo_mask; |
5cf0c6849eee
(svn r8849) -Codechange: Replace hardcoded global/climate cargo mapping tables with dynamically generated data. Change associated code to use new functions.
peter1138 <peter1138@openttd.org>
parents:
6091
diff
changeset
|
30 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
14965
diff
changeset
|
31 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
14965
diff
changeset
|
32 * Set up the default cargo types for the given landscape type. |
13884
0ee48164ffe2
(svn r18413) -Doc: Added doxygen strings for cargo-type related enums, structs, and functions.
alberth <alberth@openttd.org>
parents:
13881
diff
changeset
|
33 * @param l Landscape |
0ee48164ffe2
(svn r18413) -Doc: Added doxygen strings for cargo-type related enums, structs, and functions.
alberth <alberth@openttd.org>
parents:
13881
diff
changeset
|
34 */ |
6091
17ebeb5a2c37
(svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138 <peter1138@openttd.org>
parents:
diff
changeset
|
35 void SetupCargoForClimate(LandscapeID l) |
17ebeb5a2c37
(svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138 <peter1138@openttd.org>
parents:
diff
changeset
|
36 { |
17ebeb5a2c37
(svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138 <peter1138@openttd.org>
parents:
diff
changeset
|
37 assert(l < lengthof(_default_climate_cargo)); |
17ebeb5a2c37
(svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138 <peter1138@openttd.org>
parents:
diff
changeset
|
38 |
17ebeb5a2c37
(svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138 <peter1138@openttd.org>
parents:
diff
changeset
|
39 /* Reset and disable all cargo types */ |
12418
0d8340a4c70e
(svn r16852) -Codechange: use FOR_ALL_CARGOSPECS for iterating over all valid CargoSpecs
smatz <smatz@openttd.org>
parents:
12415
diff
changeset
|
40 memset(CargoSpec::array, 0, sizeof(CargoSpec::array)); |
0d8340a4c70e
(svn r16852) -Codechange: use FOR_ALL_CARGOSPECS for iterating over all valid CargoSpecs
smatz <smatz@openttd.org>
parents:
12415
diff
changeset
|
41 for (CargoID i = 0; i < lengthof(CargoSpec::array); i++) CargoSpec::Get(i)->bitnum = INVALID_CARGO; |
6091
17ebeb5a2c37
(svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138 <peter1138@openttd.org>
parents:
diff
changeset
|
42 |
6113
5cf0c6849eee
(svn r8849) -Codechange: Replace hardcoded global/climate cargo mapping tables with dynamically generated data. Change associated code to use new functions.
peter1138 <peter1138@openttd.org>
parents:
6091
diff
changeset
|
43 _cargo_mask = 0; |
5cf0c6849eee
(svn r8849) -Codechange: Replace hardcoded global/climate cargo mapping tables with dynamically generated data. Change associated code to use new functions.
peter1138 <peter1138@openttd.org>
parents:
6091
diff
changeset
|
44 |
6091
17ebeb5a2c37
(svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138 <peter1138@openttd.org>
parents:
diff
changeset
|
45 for (CargoID i = 0; i < lengthof(_default_climate_cargo[l]); i++) { |
17ebeb5a2c37
(svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138 <peter1138@openttd.org>
parents:
diff
changeset
|
46 CargoLabel cl = _default_climate_cargo[l][i]; |
17ebeb5a2c37
(svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138 <peter1138@openttd.org>
parents:
diff
changeset
|
47 |
6640
1205cb260ebd
(svn r9871) -Fix (r8826): Some cargo costs were wrong for different climates. Multiple definitions of the same cargo type are sometimes required.
peter1138 <peter1138@openttd.org>
parents:
6460
diff
changeset
|
48 /* Bzzt: check if cl is just an index into the cargo table */ |
1205cb260ebd
(svn r9871) -Fix (r8826): Some cargo costs were wrong for different climates. Multiple definitions of the same cargo type are sometimes required.
peter1138 <peter1138@openttd.org>
parents:
6460
diff
changeset
|
49 if (cl < lengthof(_default_cargo)) { |
1205cb260ebd
(svn r9871) -Fix (r8826): Some cargo costs were wrong for different climates. Multiple definitions of the same cargo type are sometimes required.
peter1138 <peter1138@openttd.org>
parents:
6460
diff
changeset
|
50 /* Copy the indexed cargo */ |
12415
6a77d1df56e2
(svn r16849) -Codechange: replace GetCargo() by CargoSpec::Get()
smatz <smatz@openttd.org>
parents:
12246
diff
changeset
|
51 CargoSpec *cargo = CargoSpec::Get(i); |
6a77d1df56e2
(svn r16849) -Codechange: replace GetCargo() by CargoSpec::Get()
smatz <smatz@openttd.org>
parents:
12246
diff
changeset
|
52 *cargo = _default_cargo[cl]; |
6a77d1df56e2
(svn r16849) -Codechange: replace GetCargo() by CargoSpec::Get()
smatz <smatz@openttd.org>
parents:
12246
diff
changeset
|
53 if (cargo->bitnum != INVALID_CARGO) SetBit(_cargo_mask, i); |
6640
1205cb260ebd
(svn r9871) -Fix (r8826): Some cargo costs were wrong for different climates. Multiple definitions of the same cargo type are sometimes required.
peter1138 <peter1138@openttd.org>
parents:
6460
diff
changeset
|
54 continue; |
1205cb260ebd
(svn r9871) -Fix (r8826): Some cargo costs were wrong for different climates. Multiple definitions of the same cargo type are sometimes required.
peter1138 <peter1138@openttd.org>
parents:
6460
diff
changeset
|
55 } |
1205cb260ebd
(svn r9871) -Fix (r8826): Some cargo costs were wrong for different climates. Multiple definitions of the same cargo type are sometimes required.
peter1138 <peter1138@openttd.org>
parents:
6460
diff
changeset
|
56 |
6091
17ebeb5a2c37
(svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138 <peter1138@openttd.org>
parents:
diff
changeset
|
57 /* Loop through each of the default cargo types to see if |
17ebeb5a2c37
(svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138 <peter1138@openttd.org>
parents:
diff
changeset
|
58 * the label matches */ |
17ebeb5a2c37
(svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138 <peter1138@openttd.org>
parents:
diff
changeset
|
59 for (uint j = 0; j < lengthof(_default_cargo); j++) { |
17ebeb5a2c37
(svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138 <peter1138@openttd.org>
parents:
diff
changeset
|
60 if (_default_cargo[j].label == cl) { |
12415
6a77d1df56e2
(svn r16849) -Codechange: replace GetCargo() by CargoSpec::Get()
smatz <smatz@openttd.org>
parents:
12246
diff
changeset
|
61 *CargoSpec::Get(i) = _default_cargo[j]; |
6113
5cf0c6849eee
(svn r8849) -Codechange: Replace hardcoded global/climate cargo mapping tables with dynamically generated data. Change associated code to use new functions.
peter1138 <peter1138@openttd.org>
parents:
6091
diff
changeset
|
62 |
6148
4b171c8e99ce
(svn r8891) -Codechange: Remove remains of global cargo scheme. All cargo mapping is now dealt with only in NewGRF code, on load where possible.
peter1138 <peter1138@openttd.org>
parents:
6143
diff
changeset
|
63 /* Populate the available cargo mask */ |
7931
44ff7a6d801f
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
6640
diff
changeset
|
64 SetBit(_cargo_mask, i); |
6091
17ebeb5a2c37
(svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138 <peter1138@openttd.org>
parents:
diff
changeset
|
65 break; |
17ebeb5a2c37
(svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138 <peter1138@openttd.org>
parents:
diff
changeset
|
66 } |
17ebeb5a2c37
(svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138 <peter1138@openttd.org>
parents:
diff
changeset
|
67 } |
17ebeb5a2c37
(svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138 <peter1138@openttd.org>
parents:
diff
changeset
|
68 } |
17ebeb5a2c37
(svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138 <peter1138@openttd.org>
parents:
diff
changeset
|
69 } |
17ebeb5a2c37
(svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138 <peter1138@openttd.org>
parents:
diff
changeset
|
70 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
14965
diff
changeset
|
71 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
14965
diff
changeset
|
72 * Get the cargo ID by cargo label. |
13884
0ee48164ffe2
(svn r18413) -Doc: Added doxygen strings for cargo-type related enums, structs, and functions.
alberth <alberth@openttd.org>
parents:
13881
diff
changeset
|
73 * @param cl Cargo type to get. |
0ee48164ffe2
(svn r18413) -Doc: Added doxygen strings for cargo-type related enums, structs, and functions.
alberth <alberth@openttd.org>
parents:
13881
diff
changeset
|
74 * @return ID number if the cargo exists, else #CT_INVALID |
0ee48164ffe2
(svn r18413) -Doc: Added doxygen strings for cargo-type related enums, structs, and functions.
alberth <alberth@openttd.org>
parents:
13881
diff
changeset
|
75 */ |
6143
bccc948d9804
(svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138 <peter1138@openttd.org>
parents:
6123
diff
changeset
|
76 CargoID GetCargoIDByLabel(CargoLabel cl) |
bccc948d9804
(svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138 <peter1138@openttd.org>
parents:
6123
diff
changeset
|
77 { |
12419
2ffd2f301bf5
(svn r16853) -Codechange: make CargoSpec const at two places
smatz <smatz@openttd.org>
parents:
12418
diff
changeset
|
78 const CargoSpec *cs; |
12418
0d8340a4c70e
(svn r16852) -Codechange: use FOR_ALL_CARGOSPECS for iterating over all valid CargoSpecs
smatz <smatz@openttd.org>
parents:
12415
diff
changeset
|
79 FOR_ALL_CARGOSPECS(cs) { |
0d8340a4c70e
(svn r16852) -Codechange: use FOR_ALL_CARGOSPECS for iterating over all valid CargoSpecs
smatz <smatz@openttd.org>
parents:
12415
diff
changeset
|
80 if (cs->label == cl) return cs->Index(); |
6143
bccc948d9804
(svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138 <peter1138@openttd.org>
parents:
6123
diff
changeset
|
81 } |
bccc948d9804
(svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138 <peter1138@openttd.org>
parents:
6123
diff
changeset
|
82 |
bccc948d9804
(svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138 <peter1138@openttd.org>
parents:
6123
diff
changeset
|
83 /* No matching label was found, so it is invalid */ |
bccc948d9804
(svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138 <peter1138@openttd.org>
parents:
6123
diff
changeset
|
84 return CT_INVALID; |
bccc948d9804
(svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138 <peter1138@openttd.org>
parents:
6123
diff
changeset
|
85 } |
6460
cebf3bbc9227
(svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138 <peter1138@openttd.org>
parents:
6360
diff
changeset
|
86 |
cebf3bbc9227
(svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138 <peter1138@openttd.org>
parents:
6360
diff
changeset
|
87 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
14965
diff
changeset
|
88 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
14965
diff
changeset
|
89 * Find the CargoID of a 'bitnum' value. |
6460
cebf3bbc9227
(svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138 <peter1138@openttd.org>
parents:
6360
diff
changeset
|
90 * @param bitnum 'bitnum' to find. |
13884
0ee48164ffe2
(svn r18413) -Doc: Added doxygen strings for cargo-type related enums, structs, and functions.
alberth <alberth@openttd.org>
parents:
13881
diff
changeset
|
91 * @return First CargoID with the given bitnum, or #CT_INVALID if not found or if the provided \a bitnum is invalid. |
6460
cebf3bbc9227
(svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138 <peter1138@openttd.org>
parents:
6360
diff
changeset
|
92 */ |
cebf3bbc9227
(svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138 <peter1138@openttd.org>
parents:
6360
diff
changeset
|
93 CargoID GetCargoIDByBitnum(uint8 bitnum) |
cebf3bbc9227
(svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138 <peter1138@openttd.org>
parents:
6360
diff
changeset
|
94 { |
cebf3bbc9227
(svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138 <peter1138@openttd.org>
parents:
6360
diff
changeset
|
95 if (bitnum == INVALID_CARGO) return CT_INVALID; |
cebf3bbc9227
(svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138 <peter1138@openttd.org>
parents:
6360
diff
changeset
|
96 |
12419
2ffd2f301bf5
(svn r16853) -Codechange: make CargoSpec const at two places
smatz <smatz@openttd.org>
parents:
12418
diff
changeset
|
97 const CargoSpec *cs; |
12418
0d8340a4c70e
(svn r16852) -Codechange: use FOR_ALL_CARGOSPECS for iterating over all valid CargoSpecs
smatz <smatz@openttd.org>
parents:
12415
diff
changeset
|
98 FOR_ALL_CARGOSPECS(cs) { |
0d8340a4c70e
(svn r16852) -Codechange: use FOR_ALL_CARGOSPECS for iterating over all valid CargoSpecs
smatz <smatz@openttd.org>
parents:
12415
diff
changeset
|
99 if (cs->bitnum == bitnum) return cs->Index(); |
6460
cebf3bbc9227
(svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138 <peter1138@openttd.org>
parents:
6360
diff
changeset
|
100 } |
cebf3bbc9227
(svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138 <peter1138@openttd.org>
parents:
6360
diff
changeset
|
101 |
cebf3bbc9227
(svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138 <peter1138@openttd.org>
parents:
6360
diff
changeset
|
102 /* No matching label was found, so it is invalid */ |
cebf3bbc9227
(svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138 <peter1138@openttd.org>
parents:
6360
diff
changeset
|
103 return CT_INVALID; |
cebf3bbc9227
(svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138 <peter1138@openttd.org>
parents:
6360
diff
changeset
|
104 } |
cebf3bbc9227
(svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138 <peter1138@openttd.org>
parents:
6360
diff
changeset
|
105 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
14965
diff
changeset
|
106 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
14965
diff
changeset
|
107 * Get sprite for showing cargo of this type. |
13881
693e91b02346
(svn r18410) -Codechange: Move GetCargoSprite() to CargoSpec::GetCargoIcon().
alberth <alberth@openttd.org>
parents:
13466
diff
changeset
|
108 * @return Sprite number to use. |
693e91b02346
(svn r18410) -Codechange: Move GetCargoSprite() to CargoSpec::GetCargoIcon().
alberth <alberth@openttd.org>
parents:
13466
diff
changeset
|
109 */ |
693e91b02346
(svn r18410) -Codechange: Move GetCargoSprite() to CargoSpec::GetCargoIcon().
alberth <alberth@openttd.org>
parents:
13466
diff
changeset
|
110 SpriteID CargoSpec::GetCargoIcon() const |
693e91b02346
(svn r18410) -Codechange: Move GetCargoSprite() to CargoSpec::GetCargoIcon().
alberth <alberth@openttd.org>
parents:
13466
diff
changeset
|
111 { |
693e91b02346
(svn r18410) -Codechange: Move GetCargoSprite() to CargoSpec::GetCargoIcon().
alberth <alberth@openttd.org>
parents:
13466
diff
changeset
|
112 SpriteID sprite = this->sprite; |
693e91b02346
(svn r18410) -Codechange: Move GetCargoSprite() to CargoSpec::GetCargoIcon().
alberth <alberth@openttd.org>
parents:
13466
diff
changeset
|
113 if (sprite == 0xFFFF) { |
693e91b02346
(svn r18410) -Codechange: Move GetCargoSprite() to CargoSpec::GetCargoIcon().
alberth <alberth@openttd.org>
parents:
13466
diff
changeset
|
114 /* A value of 0xFFFF indicates we should draw a custom icon */ |
693e91b02346
(svn r18410) -Codechange: Move GetCargoSprite() to CargoSpec::GetCargoIcon().
alberth <alberth@openttd.org>
parents:
13466
diff
changeset
|
115 sprite = GetCustomCargoSprite(this); |
693e91b02346
(svn r18410) -Codechange: Move GetCargoSprite() to CargoSpec::GetCargoIcon().
alberth <alberth@openttd.org>
parents:
13466
diff
changeset
|
116 } |
693e91b02346
(svn r18410) -Codechange: Move GetCargoSprite() to CargoSpec::GetCargoIcon().
alberth <alberth@openttd.org>
parents:
13466
diff
changeset
|
117 |
693e91b02346
(svn r18410) -Codechange: Move GetCargoSprite() to CargoSpec::GetCargoIcon().
alberth <alberth@openttd.org>
parents:
13466
diff
changeset
|
118 if (sprite == 0) sprite = SPR_CARGO_GOODS; |
693e91b02346
(svn r18410) -Codechange: Move GetCargoSprite() to CargoSpec::GetCargoIcon().
alberth <alberth@openttd.org>
parents:
13466
diff
changeset
|
119 |
693e91b02346
(svn r18410) -Codechange: Move GetCargoSprite() to CargoSpec::GetCargoIcon().
alberth <alberth@openttd.org>
parents:
13466
diff
changeset
|
120 return sprite; |
693e91b02346
(svn r18410) -Codechange: Move GetCargoSprite() to CargoSpec::GetCargoIcon().
alberth <alberth@openttd.org>
parents:
13466
diff
changeset
|
121 } |
693e91b02346
(svn r18410) -Codechange: Move GetCargoSprite() to CargoSpec::GetCargoIcon().
alberth <alberth@openttd.org>
parents:
13466
diff
changeset
|
122 |
14932
a1cadfd0c372
(svn r19534) -Add: Keep a list of cargo specifications sorted by cargo class / name.
terkhen <terkhen@openttd.org>
parents:
13884
diff
changeset
|
123 const CargoSpec *_sorted_cargo_specs[NUM_CARGO]; ///< Cargo specifications sorted alphabetically by name. |
14965
8616df9ca587
(svn r19573) -Fix (r19541): Special cargos did not appear at the refit list.
terkhen <terkhen@openttd.org>
parents:
14932
diff
changeset
|
124 uint8 _sorted_cargo_specs_size; ///< Number of cargo specifications stored at the _sorted_cargo_specs array (including special cargos). |
8616df9ca587
(svn r19573) -Fix (r19541): Special cargos did not appear at the refit list.
terkhen <terkhen@openttd.org>
parents:
14932
diff
changeset
|
125 uint8 _sorted_standard_cargo_specs_size; ///< Number of standard cargo specifications stored at the _sorted_cargo_specs array. |
8616df9ca587
(svn r19573) -Fix (r19541): Special cargos did not appear at the refit list.
terkhen <terkhen@openttd.org>
parents:
14932
diff
changeset
|
126 |
14932
a1cadfd0c372
(svn r19534) -Add: Keep a list of cargo specifications sorted by cargo class / name.
terkhen <terkhen@openttd.org>
parents:
13884
diff
changeset
|
127 |
a1cadfd0c372
(svn r19534) -Add: Keep a list of cargo specifications sorted by cargo class / name.
terkhen <terkhen@openttd.org>
parents:
13884
diff
changeset
|
128 /** Sort cargo specifications by their name. */ |
a1cadfd0c372
(svn r19534) -Add: Keep a list of cargo specifications sorted by cargo class / name.
terkhen <terkhen@openttd.org>
parents:
13884
diff
changeset
|
129 static int CDECL CargoSpecNameSorter(const CargoSpec * const *a, const CargoSpec * const *b) |
a1cadfd0c372
(svn r19534) -Add: Keep a list of cargo specifications sorted by cargo class / name.
terkhen <terkhen@openttd.org>
parents:
13884
diff
changeset
|
130 { |
a1cadfd0c372
(svn r19534) -Add: Keep a list of cargo specifications sorted by cargo class / name.
terkhen <terkhen@openttd.org>
parents:
13884
diff
changeset
|
131 static char a_name[64]; |
a1cadfd0c372
(svn r19534) -Add: Keep a list of cargo specifications sorted by cargo class / name.
terkhen <terkhen@openttd.org>
parents:
13884
diff
changeset
|
132 static char b_name[64]; |
a1cadfd0c372
(svn r19534) -Add: Keep a list of cargo specifications sorted by cargo class / name.
terkhen <terkhen@openttd.org>
parents:
13884
diff
changeset
|
133 |
a1cadfd0c372
(svn r19534) -Add: Keep a list of cargo specifications sorted by cargo class / name.
terkhen <terkhen@openttd.org>
parents:
13884
diff
changeset
|
134 GetString(a_name, (*a)->name, lastof(a_name)); |
a1cadfd0c372
(svn r19534) -Add: Keep a list of cargo specifications sorted by cargo class / name.
terkhen <terkhen@openttd.org>
parents:
13884
diff
changeset
|
135 GetString(b_name, (*b)->name, lastof(b_name)); |
a1cadfd0c372
(svn r19534) -Add: Keep a list of cargo specifications sorted by cargo class / name.
terkhen <terkhen@openttd.org>
parents:
13884
diff
changeset
|
136 |
16614
1111794047a4
(svn r21344) -Feature [FS#4214]: Natural sorting of strings using ICU.
terkhen <terkhen@openttd.org>
parents:
15620
diff
changeset
|
137 int res = strnatcmp(a_name, b_name); // Sort by name (natural sorting). |
14932
a1cadfd0c372
(svn r19534) -Add: Keep a list of cargo specifications sorted by cargo class / name.
terkhen <terkhen@openttd.org>
parents:
13884
diff
changeset
|
138 |
a1cadfd0c372
(svn r19534) -Add: Keep a list of cargo specifications sorted by cargo class / name.
terkhen <terkhen@openttd.org>
parents:
13884
diff
changeset
|
139 /* If the names are equal, sort by cargo bitnum. */ |
a1cadfd0c372
(svn r19534) -Add: Keep a list of cargo specifications sorted by cargo class / name.
terkhen <terkhen@openttd.org>
parents:
13884
diff
changeset
|
140 return (res != 0) ? res : ((*a)->bitnum - (*b)->bitnum); |
a1cadfd0c372
(svn r19534) -Add: Keep a list of cargo specifications sorted by cargo class / name.
terkhen <terkhen@openttd.org>
parents:
13884
diff
changeset
|
141 } |
a1cadfd0c372
(svn r19534) -Add: Keep a list of cargo specifications sorted by cargo class / name.
terkhen <terkhen@openttd.org>
parents:
13884
diff
changeset
|
142 |
a1cadfd0c372
(svn r19534) -Add: Keep a list of cargo specifications sorted by cargo class / name.
terkhen <terkhen@openttd.org>
parents:
13884
diff
changeset
|
143 /** Sort cargo specifications by their cargo class. */ |
a1cadfd0c372
(svn r19534) -Add: Keep a list of cargo specifications sorted by cargo class / name.
terkhen <terkhen@openttd.org>
parents:
13884
diff
changeset
|
144 static int CDECL CargoSpecClassSorter(const CargoSpec * const *a, const CargoSpec * const *b) |
a1cadfd0c372
(svn r19534) -Add: Keep a list of cargo specifications sorted by cargo class / name.
terkhen <terkhen@openttd.org>
parents:
13884
diff
changeset
|
145 { |
a1cadfd0c372
(svn r19534) -Add: Keep a list of cargo specifications sorted by cargo class / name.
terkhen <terkhen@openttd.org>
parents:
13884
diff
changeset
|
146 int res = ((*b)->classes & CC_PASSENGERS) - ((*a)->classes & CC_PASSENGERS); |
a1cadfd0c372
(svn r19534) -Add: Keep a list of cargo specifications sorted by cargo class / name.
terkhen <terkhen@openttd.org>
parents:
13884
diff
changeset
|
147 if (res == 0) { |
a1cadfd0c372
(svn r19534) -Add: Keep a list of cargo specifications sorted by cargo class / name.
terkhen <terkhen@openttd.org>
parents:
13884
diff
changeset
|
148 res = ((*b)->classes & CC_MAIL) - ((*a)->classes & CC_MAIL); |
a1cadfd0c372
(svn r19534) -Add: Keep a list of cargo specifications sorted by cargo class / name.
terkhen <terkhen@openttd.org>
parents:
13884
diff
changeset
|
149 if (res == 0) { |
14965
8616df9ca587
(svn r19573) -Fix (r19541): Special cargos did not appear at the refit list.
terkhen <terkhen@openttd.org>
parents:
14932
diff
changeset
|
150 res = ((*a)->classes & CC_SPECIAL) - ((*b)->classes & CC_SPECIAL); |
8616df9ca587
(svn r19573) -Fix (r19541): Special cargos did not appear at the refit list.
terkhen <terkhen@openttd.org>
parents:
14932
diff
changeset
|
151 if (res == 0) { |
8616df9ca587
(svn r19573) -Fix (r19541): Special cargos did not appear at the refit list.
terkhen <terkhen@openttd.org>
parents:
14932
diff
changeset
|
152 return CargoSpecNameSorter(a, b); |
8616df9ca587
(svn r19573) -Fix (r19541): Special cargos did not appear at the refit list.
terkhen <terkhen@openttd.org>
parents:
14932
diff
changeset
|
153 } |
14932
a1cadfd0c372
(svn r19534) -Add: Keep a list of cargo specifications sorted by cargo class / name.
terkhen <terkhen@openttd.org>
parents:
13884
diff
changeset
|
154 } |
a1cadfd0c372
(svn r19534) -Add: Keep a list of cargo specifications sorted by cargo class / name.
terkhen <terkhen@openttd.org>
parents:
13884
diff
changeset
|
155 } |
a1cadfd0c372
(svn r19534) -Add: Keep a list of cargo specifications sorted by cargo class / name.
terkhen <terkhen@openttd.org>
parents:
13884
diff
changeset
|
156 |
a1cadfd0c372
(svn r19534) -Add: Keep a list of cargo specifications sorted by cargo class / name.
terkhen <terkhen@openttd.org>
parents:
13884
diff
changeset
|
157 return res; |
a1cadfd0c372
(svn r19534) -Add: Keep a list of cargo specifications sorted by cargo class / name.
terkhen <terkhen@openttd.org>
parents:
13884
diff
changeset
|
158 } |
a1cadfd0c372
(svn r19534) -Add: Keep a list of cargo specifications sorted by cargo class / name.
terkhen <terkhen@openttd.org>
parents:
13884
diff
changeset
|
159 |
a1cadfd0c372
(svn r19534) -Add: Keep a list of cargo specifications sorted by cargo class / name.
terkhen <terkhen@openttd.org>
parents:
13884
diff
changeset
|
160 /** Initialize the list of sorted cargo specifications. */ |
a1cadfd0c372
(svn r19534) -Add: Keep a list of cargo specifications sorted by cargo class / name.
terkhen <terkhen@openttd.org>
parents:
13884
diff
changeset
|
161 void InitializeSortedCargoSpecs() |
a1cadfd0c372
(svn r19534) -Add: Keep a list of cargo specifications sorted by cargo class / name.
terkhen <terkhen@openttd.org>
parents:
13884
diff
changeset
|
162 { |
a1cadfd0c372
(svn r19534) -Add: Keep a list of cargo specifications sorted by cargo class / name.
terkhen <terkhen@openttd.org>
parents:
13884
diff
changeset
|
163 _sorted_cargo_specs_size = 0; |
14965
8616df9ca587
(svn r19573) -Fix (r19541): Special cargos did not appear at the refit list.
terkhen <terkhen@openttd.org>
parents:
14932
diff
changeset
|
164 const CargoSpec *cargo; |
14932
a1cadfd0c372
(svn r19534) -Add: Keep a list of cargo specifications sorted by cargo class / name.
terkhen <terkhen@openttd.org>
parents:
13884
diff
changeset
|
165 /* Add each cargo spec to the list. */ |
a1cadfd0c372
(svn r19534) -Add: Keep a list of cargo specifications sorted by cargo class / name.
terkhen <terkhen@openttd.org>
parents:
13884
diff
changeset
|
166 FOR_ALL_CARGOSPECS(cargo) { |
a1cadfd0c372
(svn r19534) -Add: Keep a list of cargo specifications sorted by cargo class / name.
terkhen <terkhen@openttd.org>
parents:
13884
diff
changeset
|
167 _sorted_cargo_specs[_sorted_cargo_specs_size] = cargo; |
a1cadfd0c372
(svn r19534) -Add: Keep a list of cargo specifications sorted by cargo class / name.
terkhen <terkhen@openttd.org>
parents:
13884
diff
changeset
|
168 _sorted_cargo_specs_size++; |
a1cadfd0c372
(svn r19534) -Add: Keep a list of cargo specifications sorted by cargo class / name.
terkhen <terkhen@openttd.org>
parents:
13884
diff
changeset
|
169 } |
a1cadfd0c372
(svn r19534) -Add: Keep a list of cargo specifications sorted by cargo class / name.
terkhen <terkhen@openttd.org>
parents:
13884
diff
changeset
|
170 |
a1cadfd0c372
(svn r19534) -Add: Keep a list of cargo specifications sorted by cargo class / name.
terkhen <terkhen@openttd.org>
parents:
13884
diff
changeset
|
171 /* Sort cargo specifications by cargo class and name. */ |
a1cadfd0c372
(svn r19534) -Add: Keep a list of cargo specifications sorted by cargo class / name.
terkhen <terkhen@openttd.org>
parents:
13884
diff
changeset
|
172 QSortT(_sorted_cargo_specs, _sorted_cargo_specs_size, &CargoSpecClassSorter); |
14965
8616df9ca587
(svn r19573) -Fix (r19541): Special cargos did not appear at the refit list.
terkhen <terkhen@openttd.org>
parents:
14932
diff
changeset
|
173 |
8616df9ca587
(svn r19573) -Fix (r19541): Special cargos did not appear at the refit list.
terkhen <terkhen@openttd.org>
parents:
14932
diff
changeset
|
174 _sorted_standard_cargo_specs_size = 0; |
8616df9ca587
(svn r19573) -Fix (r19541): Special cargos did not appear at the refit list.
terkhen <terkhen@openttd.org>
parents:
14932
diff
changeset
|
175 FOR_ALL_SORTED_CARGOSPECS(cargo) { |
8616df9ca587
(svn r19573) -Fix (r19541): Special cargos did not appear at the refit list.
terkhen <terkhen@openttd.org>
parents:
14932
diff
changeset
|
176 if (cargo->classes & CC_SPECIAL) break; |
8616df9ca587
(svn r19573) -Fix (r19541): Special cargos did not appear at the refit list.
terkhen <terkhen@openttd.org>
parents:
14932
diff
changeset
|
177 _sorted_standard_cargo_specs_size++; |
8616df9ca587
(svn r19573) -Fix (r19541): Special cargos did not appear at the refit list.
terkhen <terkhen@openttd.org>
parents:
14932
diff
changeset
|
178 } |
14932
a1cadfd0c372
(svn r19534) -Add: Keep a list of cargo specifications sorted by cargo class / name.
terkhen <terkhen@openttd.org>
parents:
13884
diff
changeset
|
179 } |
a1cadfd0c372
(svn r19534) -Add: Keep a list of cargo specifications sorted by cargo class / name.
terkhen <terkhen@openttd.org>
parents:
13884
diff
changeset
|
180 |