6268
|
1 |
/* $Id$ */
|
|
2 |
|
|
3 |
/** @file cargotype.cpp */
|
|
4 |
|
|
5 |
#include "stdafx.h"
|
|
6 |
#include "openttd.h"
|
|
7 |
#include "macros.h"
|
|
8 |
#include "table/sprites.h"
|
|
9 |
#include "table/strings.h"
|
|
10 |
#include "newgrf_cargo.h"
|
|
11 |
#include "cargotype.h"
|
|
12 |
|
|
13 |
#include "table/cargo_const.h"
|
|
14 |
|
6303
|
15 |
CargoSpec _cargo[NUM_CARGO];
|
6268
|
16 |
|
|
17 |
static const byte INVALID_CARGO = 0xFF;
|
|
18 |
|
|
19 |
/* Bitmask of cargo types available */
|
|
20 |
uint32 _cargo_mask;
|
|
21 |
|
|
22 |
|
|
23 |
void SetupCargoForClimate(LandscapeID l)
|
|
24 |
{
|
|
25 |
assert(l < lengthof(_default_climate_cargo));
|
|
26 |
|
|
27 |
/* Reset and disable all cargo types */
|
|
28 |
memset(_cargo, 0, sizeof(_cargo));
|
|
29 |
for (CargoID i = 0; i < lengthof(_cargo); i++) _cargo[i].bitnum = INVALID_CARGO;
|
|
30 |
|
|
31 |
_cargo_mask = 0;
|
|
32 |
|
|
33 |
for (CargoID i = 0; i < lengthof(_default_climate_cargo[l]); i++) {
|
|
34 |
CargoLabel cl = _default_climate_cargo[l][i];
|
|
35 |
|
|
36 |
/* Loop through each of the default cargo types to see if
|
|
37 |
* the label matches */
|
|
38 |
for (uint j = 0; j < lengthof(_default_cargo); j++) {
|
|
39 |
if (_default_cargo[j].label == cl) {
|
|
40 |
_cargo[i] = _default_cargo[j];
|
|
41 |
|
|
42 |
/* Populate the available cargo mask */
|
|
43 |
SETBIT(_cargo_mask, i);
|
|
44 |
break;
|
|
45 |
}
|
|
46 |
}
|
|
47 |
}
|
|
48 |
}
|
|
49 |
|
|
50 |
|
|
51 |
const CargoSpec *GetCargo(CargoID c)
|
|
52 |
{
|
|
53 |
assert(c < lengthof(_cargo));
|
|
54 |
return &_cargo[c];
|
|
55 |
}
|
|
56 |
|
|
57 |
|
|
58 |
bool CargoSpec::IsValid() const
|
|
59 |
{
|
|
60 |
return bitnum != INVALID_CARGO;
|
|
61 |
}
|
|
62 |
|
|
63 |
|
|
64 |
CargoID GetCargoIDByLabel(CargoLabel cl)
|
|
65 |
{
|
|
66 |
for (CargoID c = 0; c < lengthof(_cargo); c++) {
|
6303
|
67 |
if (_cargo[c].bitnum == INVALID_CARGO) continue;
|
6268
|
68 |
if (_cargo[c].label == cl) return c;
|
|
69 |
}
|
|
70 |
|
|
71 |
/* No matching label was found, so it is invalid */
|
|
72 |
return CT_INVALID;
|
|
73 |
}
|
6307
|
74 |
|
|
75 |
|
|
76 |
/** Find the CargoID of a 'bitnum' value.
|
|
77 |
* @param bitnum 'bitnum' to find.
|
|
78 |
* @return First CargoID with the given bitnum, or CT_INVALID if not found.
|
|
79 |
*/
|
|
80 |
CargoID GetCargoIDByBitnum(uint8 bitnum)
|
|
81 |
{
|
|
82 |
if (bitnum == INVALID_CARGO) return CT_INVALID;
|
|
83 |
|
|
84 |
for (CargoID c = 0; c < lengthof(_cargo); c++) {
|
|
85 |
if (_cargo[c].bitnum == bitnum) return c;
|
|
86 |
}
|
|
87 |
|
|
88 |
/* No matching label was found, so it is invalid */
|
|
89 |
return CT_INVALID;
|
|
90 |
}
|
|
91 |
|