src/cargotype.h
author rubidium
Tue, 15 Jan 2008 13:19:49 +0000
changeset 8794 ccb35d65645b
parent 8760 ce0891c412ce
child 9258 c00ebaa5bf90
permissions -rw-r--r--
(svn r11862) -Fix [FS#1559]: when two NewGRFs 'fight' to define the same cargo it could happen that the strings are defined by one cargo and the 'action2' by another and when one assumes that both come from the same NewGRF... So store the GRF ID with the strings. To be extra sure add the same protection mechanism to industries and towns too.
/* $Id$ */

/** @file cargotype.h */

#ifndef CARGOTYPE_H
#define CARGOTYPE_H

#include "cargo_type.h"
#include "gfx_type.h"
#include "newgrf_string_type.h"

typedef uint32 CargoLabel;

enum TownEffect {
	TE_NONE,
	TE_PASSENGERS,
	TE_MAIL,
	TE_GOODS,
	TE_WATER,
	TE_FOOD,
};


struct CargoSpec {
	uint8 bitnum;
	CargoLabel label;
	uint32 grfid;
	uint8 legend_colour;
	uint8 rating_colour;
	uint8 weight;
	uint16 initial_payment;
	uint8 transit_days[2];

	bool is_freight;
	TownEffect town_effect; ///< The effect this cargo type has on towns
	uint16 multipliertowngrowth;
	uint8 callback_mask;

	GRFMappedStringID name;
	GRFMappedStringID name_single;
	GRFMappedStringID units_volume;
	GRFMappedStringID quantifier;
	GRFMappedStringID abbrev;

	SpriteID sprite;

	uint16 classes;
	const struct SpriteGroup *group;

	bool IsValid() const;
};


extern uint32 _cargo_mask;
extern CargoSpec _cargo[NUM_CARGO];


/* Set up the default cargo types for the given landscape type */
void SetupCargoForClimate(LandscapeID l);
/* Retrieve cargo details for the given cargo ID */
const CargoSpec *GetCargo(CargoID c);
/* Get the cargo ID with the cargo label */
CargoID GetCargoIDByLabel(CargoLabel cl);
CargoID GetCargoIDByBitnum(uint8 bitnum);

static inline bool IsCargoInClass(CargoID c, uint16 cc)
{
	return (GetCargo(c)->classes & cc) != 0;
}


#endif /* CARGOTYPE_H */