From ef2daa5060e251834e82df1ba3e081579ff84f2f Mon Sep 17 00:00:00 2001 From: peter1138 Date: Tue, 20 Feb 2007 22:09:21 +0000 Subject: (svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels. --- src/cargotype.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/cargotype.cpp (limited to 'src/cargotype.cpp') diff --git a/src/cargotype.cpp b/src/cargotype.cpp new file mode 100644 index 000000000..e17bff0ef --- /dev/null +++ b/src/cargotype.cpp @@ -0,0 +1,46 @@ +/* $Id$ */ + +#include "stdafx.h" +#include "openttd.h" +#include "macros.h" +#include "table/sprites.h" +#include "table/strings.h" +#include "newgrf_cargo.h" +#include "cargotype.h" + +#include "table/cargo_const.h" + +static CargoSpec _cargo[NUM_CARGO]; + +static const byte INVALID_CARGO = 0xFF; + + +void SetupCargoForClimate(LandscapeID l) +{ + assert(l < lengthof(_default_climate_cargo)); + + /* Reset and disable all cargo types */ + memset(_cargo, 0, sizeof(_cargo)); + for (CargoID i = 0; i < lengthof(_cargo); i++) _cargo[i].bitnum = INVALID_CARGO; + + for (CargoID i = 0; i < lengthof(_default_climate_cargo[l]); i++) { + CargoLabel cl = _default_climate_cargo[l][i]; + + /* Loop through each of the default cargo types to see if + * the label matches */ + for (uint j = 0; j < lengthof(_default_cargo); j++) { + if (_default_cargo[j].label == cl) { + _cargo[i] = _default_cargo[j]; + break; + } + } + } +} + + +const CargoSpec *GetCargo(CargoID c) +{ + assert(c < lengthof(_cargo)); + return &_cargo[c]; +} + -- cgit v1.2.3-54-g00ecf