2007-02-20 22:09:21 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file cargotype.h Types/functions related to cargos. */
|
2007-02-23 11:50:43 +00:00
|
|
|
|
2007-02-20 22:09:21 +00:00
|
|
|
#ifndef CARGOTYPE_H
|
|
|
|
#define CARGOTYPE_H
|
|
|
|
|
2007-12-21 22:50:51 +00:00
|
|
|
#include "cargo_type.h"
|
2007-12-23 10:56:02 +00:00
|
|
|
#include "gfx_type.h"
|
2008-04-17 11:47:22 +00:00
|
|
|
#include "strings_type.h"
|
2008-05-07 09:07:19 +00:00
|
|
|
#include "landscape_type.h"
|
2007-02-20 22:09:21 +00:00
|
|
|
|
|
|
|
typedef uint32 CargoLabel;
|
|
|
|
|
2007-03-15 22:48:46 +00:00
|
|
|
enum TownEffect {
|
|
|
|
TE_NONE,
|
|
|
|
TE_PASSENGERS,
|
|
|
|
TE_MAIL,
|
|
|
|
TE_GOODS,
|
|
|
|
TE_WATER,
|
|
|
|
TE_FOOD,
|
|
|
|
};
|
|
|
|
|
2007-02-20 22:09:21 +00:00
|
|
|
|
2009-06-25 23:49:59 +00:00
|
|
|
static const byte INVALID_CARGO = 0xFF;
|
|
|
|
|
2007-03-07 12:11:48 +00:00
|
|
|
struct CargoSpec {
|
2007-02-20 22:09:21 +00:00
|
|
|
uint8 bitnum;
|
|
|
|
CargoLabel label;
|
|
|
|
uint8 legend_colour;
|
|
|
|
uint8 rating_colour;
|
|
|
|
uint8 weight;
|
|
|
|
uint16 initial_payment;
|
|
|
|
uint8 transit_days[2];
|
|
|
|
|
|
|
|
bool is_freight;
|
2007-03-15 22:48:46 +00:00
|
|
|
TownEffect town_effect; ///< The effect this cargo type has on towns
|
2007-02-20 22:09:21 +00:00
|
|
|
uint16 multipliertowngrowth;
|
2007-03-22 23:19:40 +00:00
|
|
|
uint8 callback_mask;
|
2007-02-20 22:09:21 +00:00
|
|
|
|
2008-04-17 11:47:22 +00:00
|
|
|
StringID name;
|
|
|
|
StringID name_single;
|
|
|
|
StringID units_volume;
|
|
|
|
StringID quantifier;
|
|
|
|
StringID abbrev;
|
2007-02-20 22:09:21 +00:00
|
|
|
|
|
|
|
SpriteID sprite;
|
|
|
|
|
|
|
|
uint16 classes;
|
2008-07-30 18:23:12 +00:00
|
|
|
const struct GRFFile *grffile; ///< NewGRF where 'group' belongs to
|
2007-03-23 20:55:45 +00:00
|
|
|
const struct SpriteGroup *group;
|
2007-02-23 09:56:20 +00:00
|
|
|
|
2009-07-16 20:40:06 +00:00
|
|
|
/**
|
|
|
|
* Determines index of this cargospec
|
|
|
|
* @return index (in the CargoSpec::array array)
|
|
|
|
*/
|
|
|
|
FORCEINLINE CargoID Index() const
|
|
|
|
{
|
|
|
|
return this - CargoSpec::array;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests for validity of this cargospec
|
|
|
|
* @return is this cargospec valid?
|
|
|
|
* @note assert(cs->IsValid()) can be triggered when GRF config is modified
|
|
|
|
*/
|
|
|
|
FORCEINLINE bool IsValid() const
|
2009-06-25 23:49:59 +00:00
|
|
|
{
|
|
|
|
return this->bitnum != INVALID_CARGO;
|
|
|
|
}
|
2009-07-16 19:00:13 +00:00
|
|
|
|
2009-07-16 20:40:06 +00:00
|
|
|
/**
|
2009-07-16 21:37:59 +00:00
|
|
|
* Total number of cargospecs, both valid and invalid
|
|
|
|
* @return length of CargoSpec::array
|
2009-07-16 20:40:06 +00:00
|
|
|
*/
|
|
|
|
static FORCEINLINE size_t GetArraySize()
|
|
|
|
{
|
|
|
|
return lengthof(CargoSpec::array);
|
|
|
|
}
|
|
|
|
|
2009-07-16 19:00:13 +00:00
|
|
|
/**
|
|
|
|
* Retrieve cargo details for the given cargo ID
|
2009-07-16 20:40:06 +00:00
|
|
|
* @param index ID of cargo
|
|
|
|
* @pre index is a valid cargo ID
|
2009-07-16 19:00:13 +00:00
|
|
|
*/
|
2009-07-16 20:40:06 +00:00
|
|
|
static FORCEINLINE CargoSpec *Get(size_t index)
|
2009-07-16 19:00:13 +00:00
|
|
|
{
|
2009-07-16 20:40:06 +00:00
|
|
|
assert(index < lengthof(CargoSpec::array));
|
|
|
|
return &CargoSpec::array[index];
|
2009-07-16 19:00:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2009-07-16 21:37:59 +00:00
|
|
|
static CargoSpec array[NUM_CARGO]; ///< Array holding all CargoSpecs
|
2009-07-16 19:00:13 +00:00
|
|
|
|
|
|
|
friend void SetupCargoForClimate(LandscapeID l);
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2007-02-20 22:09:21 +00:00
|
|
|
|
2007-02-22 22:09:51 +00:00
|
|
|
extern uint32 _cargo_mask;
|
|
|
|
|
2007-02-20 22:09:21 +00:00
|
|
|
/* Set up the default cargo types for the given landscape type */
|
|
|
|
void SetupCargoForClimate(LandscapeID l);
|
2008-03-28 04:57:32 +00:00
|
|
|
/* Get the cargo icon for a given cargo ID */
|
|
|
|
SpriteID GetCargoSprite(CargoID i);
|
2007-02-24 19:36:47 +00:00
|
|
|
/* Get the cargo ID with the cargo label */
|
|
|
|
CargoID GetCargoIDByLabel(CargoLabel cl);
|
2007-04-13 19:32:18 +00:00
|
|
|
CargoID GetCargoIDByBitnum(uint8 bitnum);
|
2007-02-22 22:09:51 +00:00
|
|
|
|
2007-03-18 22:07:44 +00:00
|
|
|
static inline bool IsCargoInClass(CargoID c, uint16 cc)
|
|
|
|
{
|
2009-07-16 19:00:13 +00:00
|
|
|
return (CargoSpec::Get(c)->classes & cc) != 0;
|
2007-03-18 22:07:44 +00:00
|
|
|
}
|
|
|
|
|
2009-07-16 20:40:06 +00:00
|
|
|
#define FOR_ALL_CARGOSPECS_FROM(var, start) for (size_t cargospec_index = start; var = NULL, cargospec_index < CargoSpec::GetArraySize(); cargospec_index++) \
|
|
|
|
if ((var = CargoSpec::Get(cargospec_index))->IsValid())
|
|
|
|
#define FOR_ALL_CARGOSPECS(var) FOR_ALL_CARGOSPECS_FROM(var, 0)
|
|
|
|
|
2007-02-20 22:09:21 +00:00
|
|
|
#endif /* CARGOTYPE_H */
|