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 |
|
|
15 |
static CargoSpec _cargo[NUM_CARGO];
|
|
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++) {
|
|
67 |
if (_cargo[c].label == cl) return c;
|
|
68 |
}
|
|
69 |
|
|
70 |
/* No matching label was found, so it is invalid */
|
|
71 |
return CT_INVALID;
|
|
72 |
}
|