Changeset - r27932:71246c40b69d
[Not reviewed]
master
0 2 0
Peter Nelson - 14 months ago 2023-04-27 12:26:10
peter1138@openttd.org
Codechange: Simplify initialization of default cargoes.
2 files changed with 3 insertions and 9 deletions:
0 comments (0 inline, 0 general)
src/cargotype.cpp
Show inline comments
 
@@ -39,19 +39,13 @@ CargoTypes _standard_cargo_mask;
 
 */
 
void SetupCargoForClimate(LandscapeID l)
 
{
 
	assert(l < lengthof(_default_climate_cargo));
 

	
 
	/* Reset and disable all cargo types */
 
	for (CargoID i = 0; i < lengthof(CargoSpec::array); i++) {
 
		*CargoSpec::Get(i) = {};
 
		CargoSpec::Get(i)->bitnum = INVALID_CARGO_BITNUM;
 

	
 
		/* Set defaults for newer properties, which old GRFs do not know */
 
		CargoSpec::Get(i)->multiplier = 0x100;
 
	}
 
	std::fill(std::begin(CargoSpec::array), std::end(CargoSpec::array), CargoSpec{});
 

	
 
	_cargo_mask = 0;
 

	
 
	for (CargoID i = 0; i < lengthof(_default_climate_cargo[l]); i++) {
 
		CargoLabel cl = _default_climate_cargo[l][i];
 

	
src/cargotype.h
Show inline comments
 
@@ -51,18 +51,18 @@ enum CargoClass {
 
};
 

	
 
static const byte INVALID_CARGO_BITNUM = 0xFF; ///< Constant representing invalid cargo
 

	
 
/** Specification of a cargo type. */
 
struct CargoSpec {
 
	uint8_t bitnum; ///< Cargo bit number, is #INVALID_CARGO_BITNUM for a non-used spec.
 
	uint8_t bitnum{INVALID_CARGO_BITNUM}; ///< Cargo bit number, is #INVALID_CARGO_BITNUM for a non-used spec.
 
	CargoLabel label;                ///< Unique label of the cargo type.
 
	uint8_t legend_colour;
 
	uint8_t rating_colour;
 
	uint8_t weight;                    ///< Weight of a single unit of this cargo type in 1/16 ton (62.5 kg).
 
	uint16_t multiplier;               ///< Capacity multiplier for vehicles. (8 fractional bits)
 
	uint16_t multiplier{0x100}; ///< Capacity multiplier for vehicles. (8 fractional bits)
 
	int32_t initial_payment;           ///< Initial payment rate before inflation is applied.
 
	uint8_t transit_periods[2];
 

	
 
	bool is_freight;                 ///< Cargo type is considered to be freight (affects train freight multiplier).
 
	TownEffect town_effect;          ///< The effect that delivering this cargo type has on towns. Also affects destination of subsidies.
 
	uint8_t callback_mask;             ///< Bitmask of cargo callbacks that have to be called
0 comments (0 inline, 0 general)