(svn r8849) -Codechange: Replace hardcoded global/climate cargo mapping tables with dynamically generated data. Change associated code to use new functions.

This commit is contained in:
2007-02-22 22:09:51 +00:00
parent 4f41a8a5e2
commit 6062004960
12 changed files with 75 additions and 131 deletions

View File

@@ -14,6 +14,12 @@ static CargoSpec _cargo[NUM_CARGO];
static const byte INVALID_CARGO = 0xFF;
/* Quick mapping from cargo type 'bitnums' to real cargo IDs */
static CargoID _cargo_bitnum_map[32];
/* Bitmask of cargo type 'bitnums' availabe */
uint32 _cargo_mask;
void SetupCargoForClimate(LandscapeID l)
{
@@ -23,6 +29,9 @@ void SetupCargoForClimate(LandscapeID l)
memset(_cargo, 0, sizeof(_cargo));
for (CargoID i = 0; i < lengthof(_cargo); i++) _cargo[i].bitnum = INVALID_CARGO;
memset(_cargo_bitnum_map, CT_INVALID, sizeof(_cargo_bitnum_map));
_cargo_mask = 0;
for (CargoID i = 0; i < lengthof(_default_climate_cargo[l]); i++) {
CargoLabel cl = _default_climate_cargo[l][i];
@@ -31,6 +40,13 @@ void SetupCargoForClimate(LandscapeID l)
for (uint j = 0; j < lengthof(_default_cargo); j++) {
if (_default_cargo[j].label == cl) {
_cargo[i] = _default_cargo[j];
/* Populate the bitnum map and masks */
byte bitnum = _cargo[i].bitnum;
if (bitnum < lengthof(_cargo_bitnum_map)) {
_cargo_bitnum_map[bitnum] = i;
SETBIT(_cargo_mask, bitnum);
}
break;
}
}
@@ -44,3 +60,10 @@ const CargoSpec *GetCargo(CargoID c)
return &_cargo[c];
}
CargoID GetCargoIDByBitnum(byte bitnum)
{
assert(bitnum < lengthof(_cargo_bitnum_map));
assert(_cargo_bitnum_map[bitnum] != CT_INVALID);
return _cargo_bitnum_map[bitnum];
}