peter1138@6417: /* $Id$ */ peter1138@6417: belugas@6449: /** @file cargotype.cpp */ belugas@6449: peter1138@6417: #include "stdafx.h" peter1138@6417: #include "openttd.h" peter1138@6417: #include "macros.h" peter1138@6417: #include "table/sprites.h" peter1138@6417: #include "table/strings.h" peter1138@6417: #include "newgrf_cargo.h" peter1138@6417: #include "cargotype.h" peter1138@6417: peter1138@6417: #include "table/cargo_const.h" peter1138@6417: peter1138@6417: static CargoSpec _cargo[NUM_CARGO]; peter1138@6417: peter1138@6417: static const byte INVALID_CARGO = 0xFF; peter1138@6417: peter1138@6474: /* Bitmask of cargo types available */ peter1138@6439: uint32 _cargo_mask; peter1138@6439: peter1138@6417: peter1138@6417: void SetupCargoForClimate(LandscapeID l) peter1138@6417: { peter1138@6417: assert(l < lengthof(_default_climate_cargo)); peter1138@6417: peter1138@6417: /* Reset and disable all cargo types */ peter1138@6417: memset(_cargo, 0, sizeof(_cargo)); peter1138@6417: for (CargoID i = 0; i < lengthof(_cargo); i++) _cargo[i].bitnum = INVALID_CARGO; peter1138@6417: peter1138@6439: _cargo_mask = 0; peter1138@6439: peter1138@6417: for (CargoID i = 0; i < lengthof(_default_climate_cargo[l]); i++) { peter1138@6417: CargoLabel cl = _default_climate_cargo[l][i]; peter1138@6417: peter1138@6417: /* Loop through each of the default cargo types to see if peter1138@6417: * the label matches */ peter1138@6417: for (uint j = 0; j < lengthof(_default_cargo); j++) { peter1138@6417: if (_default_cargo[j].label == cl) { peter1138@6417: _cargo[i] = _default_cargo[j]; peter1138@6439: peter1138@6474: /* Populate the available cargo mask */ peter1138@6474: SETBIT(_cargo_mask, i); peter1138@6417: break; peter1138@6417: } peter1138@6417: } peter1138@6417: } peter1138@6417: } peter1138@6417: peter1138@6417: peter1138@6417: const CargoSpec *GetCargo(CargoID c) peter1138@6417: { peter1138@6417: assert(c < lengthof(_cargo)); peter1138@6417: return &_cargo[c]; peter1138@6417: } peter1138@6417: peter1138@6439: peter1138@6448: bool CargoSpec::IsValid() const peter1138@6448: { peter1138@6448: return bitnum != INVALID_CARGO; peter1138@6448: } peter1138@6469: peter1138@6469: peter1138@6469: CargoID GetCargoIDByLabel(CargoLabel cl) peter1138@6469: { peter1138@6469: for (CargoID c = 0; c < lengthof(_cargo); c++) { peter1138@6469: if (_cargo[c].label == cl) return c; peter1138@6469: } peter1138@6469: peter1138@6469: /* No matching label was found, so it is invalid */ peter1138@6469: return CT_INVALID; peter1138@6469: }