Changeset - r28422:76582babb47f
[Not reviewed]
src/articulated_vehicles.cpp
Show inline comments
 
@@ -104,13 +104,13 @@ uint CountArticulatedParts(EngineID engi
 
 * @param cargo_type returns the default cargo type, if needed
 
 * @return capacity
 
 */
 
static inline uint16_t GetVehicleDefaultCapacity(EngineID engine, CargoID *cargo_type)
 
{
 
	const Engine *e = Engine::Get(engine);
 
	CargoID cargo = (e->CanCarryCargo() ? e->GetDefaultCargoType() : (CargoID)CT_INVALID);
 
	CargoID cargo = (e->CanCarryCargo() ? e->GetDefaultCargoType() : INVALID_CARGO);
 
	if (cargo_type != nullptr) *cargo_type = cargo;
 
	if (!IsValidCargoID(cargo)) return 0;
 
	return e->GetDisplayDefaultCapacity();
 
}
 

	
 
/**
 
@@ -256,27 +256,27 @@ CargoTypes GetUnionOfArticulatedRefitMas
 
}
 

	
 
/**
 
 * Get cargo mask of all cargoes carried by an articulated vehicle.
 
 * Note: Vehicles not carrying anything are ignored
 
 * @param v the first vehicle in the chain
 
 * @param cargo_type returns the common CargoID if needed. (CT_INVALID if no part is carrying something or they are carrying different things)
 
 * @param cargo_type returns the common CargoID if needed. (INVALID_CARGO if no part is carrying something or they are carrying different things)
 
 * @return cargo mask, may be 0 if the no vehicle parts have cargo capacity
 
 */
 
CargoTypes GetCargoTypesOfArticulatedVehicle(const Vehicle *v, CargoID *cargo_type)
 
{
 
	CargoTypes cargoes = 0;
 
	CargoID first_cargo = CT_INVALID;
 
	CargoID first_cargo = INVALID_CARGO;
 

	
 
	do {
 
		if (IsValidCargoID(v->cargo_type) && v->GetEngine()->CanCarryCargo()) {
 
			SetBit(cargoes, v->cargo_type);
 
			if (!IsValidCargoID(first_cargo)) first_cargo = v->cargo_type;
 
			if (first_cargo != v->cargo_type) {
 
				if (cargo_type != nullptr) {
 
					*cargo_type = CT_INVALID;
 
					*cargo_type = INVALID_CARGO;
 
					cargo_type = nullptr;
 
				}
 
			}
 
		}
 

	
 
		v = v->HasArticulatedPart() ? v->GetNextArticulatedPart() : nullptr;
src/autoreplace_cmd.cpp
Show inline comments
 
@@ -224,13 +224,13 @@ static int GetIncompatibleRefitOrderIdFo
 
 * Function to find what type of cargo to refit to when autoreplacing
 
 * @param *v Original vehicle that is being replaced.
 
 * @param engine_type The EngineID of the vehicle that is being replaced to
 
 * @param part_of_chain The vehicle is part of a train
 
 * @return The cargo type to replace to
 
 *    CT_NO_REFIT is returned if no refit is needed
 
 *    CT_INVALID is returned when both old and new vehicle got cargo capacity and refitting the new one to the old one's cargo type isn't possible
 
 *    INVALID_CARGO is returned when both old and new vehicle got cargo capacity and refitting the new one to the old one's cargo type isn't possible
 
 */
 
static CargoID GetNewCargoTypeForReplace(Vehicle *v, EngineID engine_type, bool part_of_chain)
 
{
 
	CargoTypes available_cargo_types, union_mask;
 
	GetArticulatedRefitMasks(engine_type, true, &union_mask, &available_cargo_types);
 

	
 
@@ -241,13 +241,13 @@ static CargoID GetNewCargoTypeForReplace
 
	if (!HasAtMostOneBit(cargo_mask)) {
 
		CargoTypes new_engine_default_cargoes = GetCargoTypesOfArticulatedParts(engine_type);
 
		if ((cargo_mask & new_engine_default_cargoes) == cargo_mask) {
 
			return CT_NO_REFIT; // engine_type is already a mixed cargo type which matches the incoming vehicle by default, no refit required
 
		}
 

	
 
		return CT_INVALID; // We cannot refit to mixed cargoes in an automated way
 
		return INVALID_CARGO; // We cannot refit to mixed cargoes in an automated way
 
	}
 

	
 
	if (!IsValidCargoID(cargo_type)) {
 
		if (v->type != VEH_TRAIN) return CT_NO_REFIT; // If the vehicle does not carry anything at all, every replacement is fine.
 

	
 
		if (!part_of_chain) return CT_NO_REFIT;
 
@@ -260,15 +260,15 @@ static CargoID GetNewCargoTypeForReplace
 
			/* Now we found a cargo type being carried on the train and we will see if it is possible to carry to this one */
 
			if (HasBit(available_cargo_types, v->cargo_type)) return v->cargo_type;
 
		}
 

	
 
		return CT_NO_REFIT; // We failed to find a cargo type on the old vehicle and we will not refit the new one
 
	} else {
 
		if (!HasBit(available_cargo_types, cargo_type)) return CT_INVALID; // We can't refit the vehicle to carry the cargo we want
 
		if (!HasBit(available_cargo_types, cargo_type)) return INVALID_CARGO; // We can't refit the vehicle to carry the cargo we want
 

	
 
		if (part_of_chain && !VerifyAutoreplaceRefitForOrders(v, engine_type)) return CT_INVALID; // Some refit orders lose their effect
 
		if (part_of_chain && !VerifyAutoreplaceRefitForOrders(v, engine_type)) return INVALID_CARGO; // Some refit orders lose their effect
 

	
 
		return cargo_type;
 
	}
 
}
 

	
 
/**
 
@@ -349,13 +349,13 @@ static CommandCost BuildReplacementVehic
 
		AddVehicleAdviceNewsItem(STR_NEWS_VEHICLE_AUTORENEW_FAILED, old_veh->index);
 
		return CommandCost();
 
	}
 

	
 
	/* Build the new vehicle */
 
	VehicleID new_veh_id;
 
	std::tie(cost, new_veh_id, std::ignore, std::ignore, std::ignore) = Command<CMD_BUILD_VEHICLE>::Do(DC_EXEC | DC_AUTOREPLACE, old_veh->tile, e, true, CT_INVALID, INVALID_CLIENT_ID);
 
	std::tie(cost, new_veh_id, std::ignore, std::ignore, std::ignore) = Command<CMD_BUILD_VEHICLE>::Do(DC_EXEC | DC_AUTOREPLACE, old_veh->tile, e, true, INVALID_CARGO, INVALID_CLIENT_ID);
 
	if (cost.Failed()) return cost;
 

	
 
	Vehicle *new_veh = Vehicle::Get(new_veh_id);
 
	*new_vehicle = new_veh;
 

	
 
	/* Refit the vehicle if needed */
src/build_vehicle_gui.cpp
Show inline comments
 
@@ -92,13 +92,13 @@ static const NWidgetPart _nested_build_v
 
		NWidget(WWT_RESIZEBOX, COLOUR_GREY),
 
	EndContainer(),
 
};
 

	
 
/** Special cargo filter criteria */
 
static const CargoID CF_ANY     = CT_NO_REFIT;   ///< Show all vehicles independent of carried cargo (i.e. no filtering)
 
static const CargoID CF_NONE    = CT_INVALID;    ///< Show only vehicles which do not carry cargo (e.g. train engines)
 
static const CargoID CF_NONE    = INVALID_CARGO; ///< Show only vehicles which do not carry cargo (e.g. train engines)
 
static const CargoID CF_ENGINES = CT_AUTO_REFIT; ///< Show only engines (for rail vehicles only)
 

	
 
bool _engine_sort_direction; ///< \c false = descending, \c true = ascending.
 
byte _engine_sort_last_criteria[]       = {0, 0, 0, 0};                 ///< Last set sort criteria, for each vehicle type.
 
bool _engine_sort_last_order[]          = {false, false, false, false}; ///< Last set direction of the sort order, for each vehicle type.
 
bool _engine_sort_show_hidden_engines[] = {false, false, false, false}; ///< Last set 'show hidden engines' setting for each vehicle type.
 
@@ -905,13 +905,13 @@ void TestedEngineDetails::FillDefaultCap
 
		this->mail_capacity = 0;
 
	} else {
 
		this->capacity = e->GetDisplayDefaultCapacity(&this->mail_capacity);
 
		this->all_capacities[this->cargo] = this->capacity;
 
		this->all_capacities[CT_MAIL] = this->mail_capacity;
 
	}
 
	if (this->all_capacities.GetCount() == 0) this->cargo = CT_INVALID;
 
	if (this->all_capacities.GetCount() == 0) this->cargo = INVALID_CARGO;
 
}
 

	
 
/**
 
 * Draw the purchase info details of a vehicle at a given location.
 
 * @param left,right,y location where to draw the info
 
 * @param engine_number the engine of which to draw the info of
 
@@ -951,13 +951,13 @@ int DrawVehiclePurchaseInfo(int left, in
 

	
 
	if (articulated_cargo) {
 
		/* Cargo type + capacity, or N/A */
 
		int new_y = DrawCargoCapacityInfo(left, right, y, te, refittable);
 

	
 
		if (new_y == y) {
 
			SetDParam(0, CT_INVALID);
 
			SetDParam(0, INVALID_CARGO);
 
			SetDParam(2, STR_EMPTY);
 
			DrawString(left, right, y, STR_PURCHASE_INFO_CAPACITY);
 
			y += GetCharacterHeight(FS_NORMAL);
 
		} else {
 
			y = new_y;
 
		}
 
@@ -1290,13 +1290,13 @@ struct BuildVehicleWindow : Window {
 
		this->eng_list.SetFilterState(this->cargo_filter_criteria != CF_ANY);
 
	}
 

	
 
	void SelectEngine(EngineID engine)
 
	{
 
		CargoID cargo = this->cargo_filter_criteria;
 
		if (cargo == CF_ANY || cargo == CF_ENGINES || cargo == CF_NONE) cargo = CT_INVALID;
 
		if (cargo == CF_ANY || cargo == CF_ENGINES || cargo == CF_NONE) cargo = INVALID_CARGO;
 

	
 
		this->sel_engine = engine;
 
		this->SetBuyVehicleText();
 

	
 
		if (this->sel_engine == INVALID_ENGINE) return;
 

	
 
@@ -1649,13 +1649,13 @@ struct BuildVehicleWindow : Window {
 
			}
 

	
 
			case WID_BV_BUILD: {
 
				EngineID sel_eng = this->sel_engine;
 
				if (sel_eng != INVALID_ENGINE) {
 
					CargoID cargo = this->cargo_filter_criteria;
 
					if (cargo == CF_ANY || cargo == CF_ENGINES || cargo == CF_NONE) cargo = CT_INVALID;
 
					if (cargo == CF_ANY || cargo == CF_ENGINES || cargo == CF_NONE) cargo = INVALID_CARGO;
 
					if (this->vehicle_type == VEH_TRAIN && RailVehInfo(sel_eng)->railveh_type == RAILVEH_WAGON) {
 
						Command<CMD_BUILD_VEHICLE>::Post(GetCmdBuildVehMsg(this->vehicle_type), CcBuildWagon, this->window_number, sel_eng, true, cargo, INVALID_CLIENT_ID);
 
					} else {
 
						Command<CMD_BUILD_VEHICLE>::Post(GetCmdBuildVehMsg(this->vehicle_type), CcBuildPrimaryVehicle, this->window_number, sel_eng, true, cargo, INVALID_CLIENT_ID);
 
					}
 

	
src/cargo_type.h
Show inline comments
 
@@ -66,16 +66,18 @@ enum CargoType {
 

	
 
	CT_AUTO_REFIT   = 0xFD, ///< Automatically choose cargo type when doing auto refitting.
 
	CT_NO_REFIT     = 0xFE, ///< Do not refit cargo of a vehicle (used in vehicle orders and auto-replace/auto-new).
 
	CT_INVALID      = 0xFF, ///< Invalid cargo type.
 
};
 

	
 
static const CargoID INVALID_CARGO = UINT8_MAX;
 

	
 
/** Test whether cargo type is not CT_INVALID */
 
inline bool IsValidCargoType(CargoType t) { return t != CT_INVALID; }
 
/** Test whether cargo type is not CT_INVALID */
 
inline bool IsValidCargoID(CargoID t) { return t != CT_INVALID; }
 
/** Test whether cargo type is not INVALID_CARGO */
 
inline bool IsValidCargoID(CargoID t) { return t != INVALID_CARGO; }
 

	
 
typedef uint64_t CargoTypes;
 

	
 
static const CargoTypes ALL_CARGOTYPES = (CargoTypes)UINT64_MAX;
 

	
 
/** Class for storing amounts of cargo */
src/cargotype.cpp
Show inline comments
 
@@ -85,19 +85,19 @@ Dimension GetLargestCargoIconSize()
 
}
 

	
 
/**
 
 * Get the cargo ID of a default cargo, if present.
 
 * @param l Landscape
 
 * @param ct Default cargo type.
 
 * @return ID number if the cargo exists, else #CT_INVALID
 
 * @return ID number if the cargo exists, else #INVALID_CARGO
 
 */
 
CargoID GetDefaultCargoID(LandscapeID l, CargoType ct)
 
{
 
	assert(l < lengthof(_default_climate_cargo));
 

	
 
	if (!IsValidCargoType(ct)) return CT_INVALID;
 
	if (!IsValidCargoType(ct)) return INVALID_CARGO;
 

	
 
	assert(ct < lengthof(_default_climate_cargo[0]));
 
	CargoLabel cl = _default_climate_cargo[l][ct];
 
	/* Bzzt: check if cl is just an index into the cargo table */
 
	if (cl < lengthof(_default_cargo)) {
 
		cl = _default_cargo[cl].label;
 
@@ -106,40 +106,40 @@ CargoID GetDefaultCargoID(LandscapeID l,
 
	return GetCargoIDByLabel(cl);
 
}
 

	
 
/**
 
 * Get the cargo ID by cargo label.
 
 * @param cl Cargo type to get.
 
 * @return ID number if the cargo exists, else #CT_INVALID
 
 * @return ID number if the cargo exists, else #INVALID_CARGO
 
 */
 
CargoID GetCargoIDByLabel(CargoLabel cl)
 
{
 
	for (const CargoSpec *cs : CargoSpec::Iterate()) {
 
		if (cs->label == cl) return cs->Index();
 
	}
 

	
 
	/* No matching label was found, so it is invalid */
 
	return CT_INVALID;
 
	return INVALID_CARGO;
 
}
 

	
 

	
 
/**
 
 * Find the CargoID of a 'bitnum' value.
 
 * @param bitnum 'bitnum' to find.
 
 * @return First CargoID with the given bitnum, or #CT_INVALID if not found or if the provided \a bitnum is invalid.
 
 * @return First CargoID with the given bitnum, or #INVALID_CARGO if not found or if the provided \a bitnum is invalid.
 
 */
 
CargoID GetCargoIDByBitnum(uint8_t bitnum)
 
{
 
	if (bitnum == INVALID_CARGO_BITNUM) return CT_INVALID;
 
	if (bitnum == INVALID_CARGO_BITNUM) return INVALID_CARGO;
 

	
 
	for (const CargoSpec *cs : CargoSpec::Iterate()) {
 
		if (cs->bitnum == bitnum) return cs->Index();
 
	}
 

	
 
	/* No matching label was found, so it is invalid */
 
	return CT_INVALID;
 
	return INVALID_CARGO;
 
}
 

	
 
/**
 
 * Get sprite for showing cargo of this type.
 
 * @return Sprite number to use.
 
 */
src/engine.cpp
Show inline comments
 
@@ -82,14 +82,14 @@ Engine::Engine(VehicleType type, EngineI
 
		/* 'power' defaults to zero, so we also have to default to 'wagon' */
 
		if (type == VEH_TRAIN) this->u.rail.railveh_type = RAILVEH_WAGON;
 
		/* Set model life to maximum to make wagons available */
 
		this->info.base_life = 0xFF;
 
		/* Set road vehicle tractive effort to the default value */
 
		if (type == VEH_ROAD) this->u.road.tractive_effort = 0x4C;
 
		/* Aircraft must have CT_INVALID as default, as there is no property */
 
		if (type == VEH_AIRCRAFT) this->info.cargo_type = CT_INVALID;
 
		/* Aircraft must have INVALID_CARGO as default, as there is no property */
 
		if (type == VEH_AIRCRAFT) this->info.cargo_type = INVALID_CARGO;
 
		/* Set visual effect to the default value */
 
		switch (type) {
 
			case VEH_TRAIN: this->u.rail.visual_effect = VE_DEFAULT; break;
 
			case VEH_ROAD:  this->u.road.visual_effect = VE_DEFAULT; break;
 
			case VEH_SHIP:  this->u.ship.visual_effect = VE_DEFAULT; break;
 
			default: break; // The aircraft, disasters and especially visual effects have no NewGRF configured visual effects
src/engine_base.h
Show inline comments
 
@@ -85,13 +85,13 @@ struct Engine : EnginePool::PoolItem<&_e
 
	/**
 
	 * Determines the default cargo type of an engine.
 
	 *
 
	 * Usually a valid cargo is returned, even though the vehicle has zero capacity, and can therefore not carry anything. But the cargotype is still used
 
	 * for livery selection etc..
 
	 *
 
	 * Vehicles with CT_INVALID as default cargo are usually not available, but it can appear as default cargo of articulated parts.
 
	 * Vehicles with INVALID_CARGO as default cargo are usually not available, but it can appear as default cargo of articulated parts.
 
	 *
 
	 * @return The default cargo type.
 
	 * @see CanCarryCargo
 
	 */
 
	CargoID GetDefaultCargoType() const
 
	{
src/engine_gui.cpp
Show inline comments
 
@@ -180,13 +180,13 @@ static StringID GetTrainEngineInfoString
 

	
 
	uint capacity = GetTotalCapacityOfArticulatedParts(e->index);
 
	if (capacity != 0) {
 
		SetDParam(5, e->GetDefaultCargoType());
 
		SetDParam(6, capacity);
 
	} else {
 
		SetDParam(5, CT_INVALID);
 
		SetDParam(5, INVALID_CARGO);
 
	}
 
	return (_settings_game.vehicle.train_acceleration_model != AM_ORIGINAL && GetRailTypeInfo(e->u.rail.railtype)->acceleration_type != 2) ? STR_ENGINE_PREVIEW_COST_WEIGHT_SPEED_POWER_MAX_TE : STR_ENGINE_PREVIEW_COST_WEIGHT_SPEED_POWER;
 
}
 

	
 
static StringID GetAircraftEngineInfoString(const Engine *e)
 
{
 
@@ -221,13 +221,13 @@ static StringID GetRoadVehEngineInfoStri
 
		SetDParam(1, PackVelocity(e->GetDisplayMaxSpeed(), e->type));
 
		uint capacity = GetTotalCapacityOfArticulatedParts(e->index);
 
		if (capacity != 0) {
 
			SetDParam(2, e->GetDefaultCargoType());
 
			SetDParam(3, capacity);
 
		} else {
 
			SetDParam(2, CT_INVALID);
 
			SetDParam(2, INVALID_CARGO);
 
		}
 
		SetDParam(4, e->GetRunningCost());
 
		return STR_ENGINE_PREVIEW_COST_MAX_SPEED_CAP_RUNCOST;
 
	} else {
 
		SetDParam(0, e->GetCost());
 
		SetDParam(2, PackVelocity(e->GetDisplayMaxSpeed(), e->type));
 
@@ -239,13 +239,13 @@ static StringID GetRoadVehEngineInfoStri
 

	
 
		uint capacity = GetTotalCapacityOfArticulatedParts(e->index);
 
		if (capacity != 0) {
 
			SetDParam(5, e->GetDefaultCargoType());
 
			SetDParam(6, capacity);
 
		} else {
 
			SetDParam(5, CT_INVALID);
 
			SetDParam(5, INVALID_CARGO);
 
		}
 
		return STR_ENGINE_PREVIEW_COST_WEIGHT_SPEED_POWER_MAX_TE;
 
	}
 
}
 

	
 
static StringID GetShipEngineInfoString(const Engine *e)
src/industry_cmd.cpp
Show inline comments
 
@@ -421,25 +421,25 @@ static void AddAcceptedCargo_Industry(Ti
 
	if (itspec->special_flags & INDTILE_SPECIAL_ACCEPTS_ALL_CARGO) {
 
		/* Copy all accepted cargoes from industry itself */
 
		for (const auto &a : ind->accepted) {
 
			auto pos = std::find(std::begin(accepts_cargo), std::end(accepts_cargo), a.cargo);
 
			if (pos == std::end(accepts_cargo)) {
 
				/* Not found, insert */
 
				pos = std::find(std::begin(accepts_cargo), std::end(accepts_cargo), CT_INVALID);
 
				pos = std::find(std::begin(accepts_cargo), std::end(accepts_cargo), INVALID_CARGO);
 
				if (pos == std::end(accepts_cargo)) continue; // nowhere to place, give up on this one
 
				*pos = a.cargo;
 
			}
 
			cargo_acceptance[std::distance(std::begin(accepts_cargo), pos)] += 8;
 
		}
 
	}
 

	
 
	if (HasBit(itspec->callback_mask, CBM_INDT_ACCEPT_CARGO)) {
 
		/* Try callback for accepts list, if success override all existing accepts */
 
		uint16_t res = GetIndustryTileCallback(CBID_INDTILE_ACCEPT_CARGO, 0, 0, gfx, Industry::GetByTile(tile), tile);
 
		if (res != CALLBACK_FAILED) {
 
			accepts_cargo.fill(CT_INVALID);
 
			accepts_cargo.fill(INVALID_CARGO);
 
			for (uint i = 0; i < 3; i++) accepts_cargo[i] = GetCargoTranslation(GB(res, i * 5, 5), itspec->grf_prop.grffile);
 
		}
 
	}
 

	
 
	if (HasBit(itspec->callback_mask, CBM_INDT_CARGO_ACCEPTANCE)) {
 
		/* Try callback for acceptance list, if success override all existing acceptance */
 
@@ -1835,13 +1835,13 @@ static void DoCreateNewIndustry(Industry
 
			i->random_colour = GB(res, 0, 4);
 
		}
 
	}
 

	
 
	if (HasBit(indspec->callback_mask, CBM_IND_INPUT_CARGO_TYPES)) {
 
		/* Clear all input cargo types */
 
		for (auto &a : i->accepted) a.cargo = CT_INVALID;
 
		for (auto &a : i->accepted) a.cargo = INVALID_CARGO;
 
		/* Query actual types */
 
		uint maxcargoes = (indspec->behaviour & INDUSTRYBEH_CARGOTYPES_UNLIMITED) ? static_cast<uint>(i->accepted.size()) : 3;
 
		for (uint j = 0; j < maxcargoes; j++) {
 
			uint16_t res = GetIndustryCallback(CBID_INDUSTRY_INPUT_CARGO_TYPES, j, 0, i, type, INVALID_TILE);
 
			if (res == CALLBACK_FAILED || GB(res, 0, 8) == CT_INVALID) break;
 
			if (indspec->grf_prop.grffile->grf_version >= 8 && res >= 0x100) {
 
@@ -1867,13 +1867,13 @@ static void DoCreateNewIndustry(Industry
 
			i->accepted[j].cargo = cargo;
 
		}
 
	}
 

	
 
	if (HasBit(indspec->callback_mask, CBM_IND_OUTPUT_CARGO_TYPES)) {
 
		/* Clear all output cargo types */
 
		for (auto &p : i->produced) p.cargo = CT_INVALID;
 
		for (auto &p : i->produced) p.cargo = INVALID_CARGO;
 
		/* Query actual types */
 
		uint maxcargoes = (indspec->behaviour & INDUSTRYBEH_CARGOTYPES_UNLIMITED) ? static_cast<uint>(i->produced.size()) : 2;
 
		for (uint j = 0; j < maxcargoes; j++) {
 
			uint16_t res = GetIndustryCallback(CBID_INDUSTRY_OUTPUT_CARGO_TYPES, j, 0, i, type, INVALID_TILE);
 
			if (res == CALLBACK_FAILED || GB(res, 0, 8) == CT_INVALID) break;
 
			if (indspec->grf_prop.grffile->grf_version >= 8 && res >= 0x100) {
src/industry_gui.cpp
Show inline comments
 
@@ -145,13 +145,13 @@ enum CargoSuffixInOut {
 
 * Gets all strings to display after the cargoes of industries (using callback 37)
 
 * @param use_input get suffixes for output cargoes or input cargoes?
 
 * @param cst the cargo suffix type (for which window is it requested). @see CargoSuffixType
 
 * @param ind the industry (nullptr if in fund window)
 
 * @param ind_type the industry type
 
 * @param indspec the industry spec
 
 * @param cargoes array with cargotypes. for CT_INVALID no suffix will be determined
 
 * @param cargoes array with cargotypes. for INVALID_CARGO no suffix will be determined
 
 * @param suffixes is filled with the suffixes
 
 */
 
template <typename TC, typename TS>
 
static inline void GetAllCargoSuffixes(CargoSuffixInOut use_input, CargoSuffixType cst, const Industry *ind, IndustryType ind_type, const IndustrySpec *indspec, const TC &cargoes, TS &suffixes)
 
{
 
	static_assert(lengthof(cargoes) <= lengthof(suffixes));
 
@@ -194,13 +194,13 @@ static inline void GetAllCargoSuffixes(C
 
 * Gets the strings to display after the cargo of industries (using callback 37)
 
 * @param use_input get suffixes for output cargo or input cargo?
 
 * @param cst the cargo suffix type (for which window is it requested). @see CargoSuffixType
 
 * @param ind the industry (nullptr if in fund window)
 
 * @param ind_type the industry type
 
 * @param indspec the industry spec
 
 * @param cargo cargotype. for CT_INVALID no suffix will be determined
 
 * @param cargo cargotype. for INVALID_CARGO no suffix will be determined
 
 * @param slot accepts/produced slot number, used for old-style 3-in/2-out industries.
 
 * @param suffix is filled with the suffix
 
 */
 
void GetCargoSuffix(CargoSuffixInOut use_input, CargoSuffixType cst, const Industry *ind, IndustryType ind_type, const IndustrySpec *indspec, CargoID cargo, uint8_t slot, CargoSuffix &suffix)
 
{
 
	suffix.text[0] = '\0';
 
@@ -1245,13 +1245,13 @@ static const NWidgetPart _nested_industr
 

	
 
typedef GUIList<const Industry *, const CargoID &, const std::pair<CargoID, CargoID> &> GUIIndustryList;
 

	
 
/** Special cargo filter criteria */
 
enum CargoFilterSpecialType {
 
	CF_ANY  = CT_NO_REFIT, ///< Show all industries (i.e. no filtering)
 
	CF_NONE = CT_INVALID,  ///< Show only industries which do not produce/accept cargo
 
	CF_NONE = INVALID_CARGO, ///< Show only industries which do not produce/accept cargo
 
};
 

	
 
/** Cargo filter functions */
 
/**
 
 * Check whether an industry accepts and produces a certain cargo pair.
 
 * @param industry The industry whose cargoes will being checked.
 
@@ -1992,21 +1992,21 @@ struct CargoesField {
 
		struct {
 
			IndustryType ind_type;                 ///< Industry type (#NUM_INDUSTRYTYPES means 'houses').
 
			CargoID other_produced[MAX_CARGOES];   ///< Cargoes produced but not used in this figure.
 
			CargoID other_accepted[MAX_CARGOES];   ///< Cargoes accepted but not used in this figure.
 
		} industry; ///< Industry data (for #CFT_INDUSTRY).
 
		struct {
 
			CargoID vertical_cargoes[MAX_CARGOES]; ///< Cargoes running from top to bottom (cargo ID or #CT_INVALID).
 
			CargoID vertical_cargoes[MAX_CARGOES]; ///< Cargoes running from top to bottom (cargo ID or #INVALID_CARGO).
 
			uint8_t num_cargoes;                   ///< Number of cargoes.
 
			CargoID supp_cargoes[MAX_CARGOES];     ///< Cargoes entering from the left (index in #vertical_cargoes, or #CT_INVALID).
 
			CargoID supp_cargoes[MAX_CARGOES];     ///< Cargoes entering from the left (index in #vertical_cargoes, or #INVALID_CARGO).
 
			uint8_t top_end;                       ///< Stop at the top of the vertical cargoes.
 
			CargoID cust_cargoes[MAX_CARGOES];     ///< Cargoes leaving to the right (index in #vertical_cargoes, or #CT_INVALID).
 
			CargoID cust_cargoes[MAX_CARGOES];     ///< Cargoes leaving to the right (index in #vertical_cargoes, or #INVALID_CARGO).
 
			uint8_t bottom_end;                    ///< Stop at the bottom of the vertical cargoes.
 
		} cargo; ///< Cargo data (for #CFT_CARGO).
 
		struct {
 
			CargoID cargoes[MAX_CARGOES];          ///< Cargoes to display (or #CT_INVALID).
 
			CargoID cargoes[MAX_CARGOES];          ///< Cargoes to display (or #INVALID_CARGO).
 
			bool left_align;                       ///< Align all cargo texts to the left (else align to the right).
 
		} cargo_label;   ///< Label data (for #CFT_CARGO_LABEL).
 
		StringID header; ///< Header text (for #CFT_HEADER).
 
	} u; // Data for each type.
 

	
 
	/**
 
@@ -2024,14 +2024,14 @@ struct CargoesField {
 
	 * @note #other_accepted and #other_produced should be filled later.
 
	 */
 
	void MakeIndustry(IndustryType ind_type)
 
	{
 
		this->type = CFT_INDUSTRY;
 
		this->u.industry.ind_type = ind_type;
 
		std::fill(std::begin(this->u.industry.other_accepted), std::end(this->u.industry.other_accepted), CT_INVALID);
 
		std::fill(std::begin(this->u.industry.other_produced), std::end(this->u.industry.other_produced), CT_INVALID);
 
		std::fill(std::begin(this->u.industry.other_accepted), std::end(this->u.industry.other_accepted), INVALID_CARGO);
 
		std::fill(std::begin(this->u.industry.other_produced), std::end(this->u.industry.other_produced), INVALID_CARGO);
 
	}
 

	
 
	/**
 
	 * Connect a cargo from an industry to the #CFT_CARGO column.
 
	 * @param cargo Cargo to connect.
 
	 * @param producer Cargo is produced (if \c false, cargo is assumed to be accepted).
 
@@ -2076,13 +2076,13 @@ struct CargoesField {
 
		}
 
		return false;
 
	}
 

	
 
	/**
 
	 * Make a piece of cargo column.
 
	 * @param cargoes    Array of #CargoID (may contain #CT_INVALID).
 
	 * @param cargoes    Array of #CargoID (may contain #INVALID_CARGO).
 
	 * @param length     Number of cargoes in \a cargoes.
 
	 * @param count      Number of cargoes to display (should be at least the number of valid cargoes, or \c -1 to let the method compute it).
 
	 * @param top_end    This is the first cargo field of this column.
 
	 * @param bottom_end This is the last cargo field of this column.
 
	 * @note #supp_cargoes and #cust_cargoes should be filled in later.
 
	 */
 
@@ -2096,31 +2096,31 @@ struct CargoesField {
 
				++insert;
 
			}
 
		}
 
		this->u.cargo.num_cargoes = (count < 0) ? static_cast<uint8_t>(insert - std::begin(this->u.cargo.vertical_cargoes)) : count;
 
		CargoIDComparator comparator;
 
		std::sort(std::begin(this->u.cargo.vertical_cargoes), insert, comparator);
 
		std::fill(insert, std::end(this->u.cargo.vertical_cargoes), CT_INVALID);
 
		std::fill(insert, std::end(this->u.cargo.vertical_cargoes), INVALID_CARGO);
 
		this->u.cargo.top_end = top_end;
 
		this->u.cargo.bottom_end = bottom_end;
 
		std::fill(std::begin(this->u.cargo.supp_cargoes), std::end(this->u.cargo.supp_cargoes), CT_INVALID);
 
		std::fill(std::begin(this->u.cargo.cust_cargoes), std::end(this->u.cargo.cust_cargoes), CT_INVALID);
 
		std::fill(std::begin(this->u.cargo.supp_cargoes), std::end(this->u.cargo.supp_cargoes), INVALID_CARGO);
 
		std::fill(std::begin(this->u.cargo.cust_cargoes), std::end(this->u.cargo.cust_cargoes), INVALID_CARGO);
 
	}
 

	
 
	/**
 
	 * Make a field displaying cargo type names.
 
	 * @param cargoes    Array of #CargoID (may contain #CT_INVALID).
 
	 * @param cargoes    Array of #CargoID (may contain #INVALID_CARGO).
 
	 * @param length     Number of cargoes in \a cargoes.
 
	 * @param left_align ALign texts to the left (else to the right).
 
	 */
 
	void MakeCargoLabel(const CargoID *cargoes, uint length, bool left_align)
 
	{
 
		this->type = CFT_CARGO_LABEL;
 
		uint i;
 
		for (i = 0; i < MAX_CARGOES && i < length; i++) this->u.cargo_label.cargoes[i] = cargoes[i];
 
		for (; i < MAX_CARGOES; i++) this->u.cargo_label.cargoes[i] = CT_INVALID;
 
		for (; i < MAX_CARGOES; i++) this->u.cargo_label.cargoes[i] = INVALID_CARGO;
 
		this->u.cargo_label.left_align = left_align;
 
	}
 

	
 
	/**
 
	 * Make a header above an industry column.
 
	 * @param textid Text to display.
 
@@ -2287,13 +2287,13 @@ struct CargoesField {
 

	
 
	/**
 
	 * Decide which cargo was clicked at in a #CFT_CARGO field.
 
	 * @param left  Left industry neighbour if available (else \c nullptr should be supplied).
 
	 * @param right Right industry neighbour if available (else \c nullptr should be supplied).
 
	 * @param pt    Click position in the cargo field.
 
	 * @return Cargo clicked at, or #CT_INVALID if none.
 
	 * @return Cargo clicked at, or #INVALID_CARGO if none.
 
	 */
 
	CargoID CargoClickedAt(const CargoesField *left, const CargoesField *right, Point pt) const
 
	{
 
		assert(this->type == CFT_CARGO);
 

	
 
		/* Vertical matching. */
 
@@ -2306,65 +2306,65 @@ struct CargoesField {
 
		}
 
		/* col = 0 -> left of first col, 1 -> left of 2nd col, ... this->u.cargo.num_cargoes right of last-col. */
 

	
 
		int vpos = vert_inter_industry_space / 2 + CargoesField::cargo_border.width;
 
		uint row;
 
		for (row = 0; row < MAX_CARGOES; row++) {
 
			if (pt.y < vpos) return CT_INVALID;
 
			if (pt.y < vpos) return INVALID_CARGO;
 
			if (pt.y < vpos + GetCharacterHeight(FS_NORMAL)) break;
 
			vpos += GetCharacterHeight(FS_NORMAL) + CargoesField::cargo_space.width;
 
		}
 
		if (row == MAX_CARGOES) return CT_INVALID;
 
		if (row == MAX_CARGOES) return INVALID_CARGO;
 

	
 
		/* row = 0 -> at first horizontal row, row = 1 -> second horizontal row, 2 = 3rd horizontal row. */
 
		if (col == 0) {
 
			if (IsValidCargoID(this->u.cargo.supp_cargoes[row])) return this->u.cargo.vertical_cargoes[this->u.cargo.supp_cargoes[row]];
 
			if (left != nullptr) {
 
				if (left->type == CFT_INDUSTRY) return left->u.industry.other_produced[row];
 
				if (left->type == CFT_CARGO_LABEL && !left->u.cargo_label.left_align) return left->u.cargo_label.cargoes[row];
 
			}
 
			return CT_INVALID;
 
			return INVALID_CARGO;
 
		}
 
		if (col == this->u.cargo.num_cargoes) {
 
			if (IsValidCargoID(this->u.cargo.cust_cargoes[row])) return this->u.cargo.vertical_cargoes[this->u.cargo.cust_cargoes[row]];
 
			if (right != nullptr) {
 
				if (right->type == CFT_INDUSTRY) return right->u.industry.other_accepted[row];
 
				if (right->type == CFT_CARGO_LABEL && right->u.cargo_label.left_align) return right->u.cargo_label.cargoes[row];
 
			}
 
			return CT_INVALID;
 
			return INVALID_CARGO;
 
		}
 
		if (row >= col) {
 
			/* Clicked somewhere in-between vertical cargo connection.
 
			 * Since the horizontal connection is made in the same order as the vertical list, the above condition
 
			 * ensures we are left-below the main diagonal, thus at the supplying side.
 
			 */
 
			if (IsValidCargoID(this->u.cargo.supp_cargoes[row])) return this->u.cargo.vertical_cargoes[this->u.cargo.supp_cargoes[row]];
 
			return CT_INVALID;
 
			return INVALID_CARGO;
 
		}
 
		/* Clicked at a customer connection. */
 
		if (IsValidCargoID(this->u.cargo.cust_cargoes[row])) return this->u.cargo.vertical_cargoes[this->u.cargo.cust_cargoes[row]];
 
		return CT_INVALID;
 
		return INVALID_CARGO;
 
	}
 

	
 
	/**
 
	 * Decide what cargo the user clicked in the cargo label field.
 
	 * @param pt Click position in the cargo label field.
 
	 * @return Cargo clicked at, or #CT_INVALID if none.
 
	 * @return Cargo clicked at, or #INVALID_CARGO if none.
 
	 */
 
	CargoID CargoLabelClickedAt(Point pt) const
 
	{
 
		assert(this->type == CFT_CARGO_LABEL);
 

	
 
		int vpos = vert_inter_industry_space / 2 + CargoesField::cargo_border.height;
 
		uint row;
 
		for (row = 0; row < MAX_CARGOES; row++) {
 
			if (pt.y < vpos) return CT_INVALID;
 
			if (pt.y < vpos) return INVALID_CARGO;
 
			if (pt.y < vpos + GetCharacterHeight(FS_NORMAL)) break;
 
			vpos += GetCharacterHeight(FS_NORMAL) + CargoesField::cargo_space.height;
 
		}
 
		if (row == MAX_CARGOES) return CT_INVALID;
 
		if (row == MAX_CARGOES) return INVALID_CARGO;
 
		return this->u.cargo_label.cargoes[row];
 
	}
 

	
 
private:
 
	/**
 
	 * Draw a horizontal cargo connection.
 
@@ -2413,13 +2413,13 @@ struct CargoesRow {
 
	void ConnectIndustryProduced(int column)
 
	{
 
		CargoesField *ind_fld   = this->columns + column;
 
		CargoesField *cargo_fld = this->columns + column + 1;
 
		assert(ind_fld->type == CFT_INDUSTRY && cargo_fld->type == CFT_CARGO);
 

	
 
		std::fill(std::begin(ind_fld->u.industry.other_produced), std::end(ind_fld->u.industry.other_produced), CT_INVALID);
 
		std::fill(std::begin(ind_fld->u.industry.other_produced), std::end(ind_fld->u.industry.other_produced), INVALID_CARGO);
 

	
 
		if (ind_fld->u.industry.ind_type < NUM_INDUSTRYTYPES) {
 
			CargoID others[MAX_CARGOES]; // Produced cargoes not carried in the cargo column.
 
			int other_count = 0;
 

	
 
			const IndustrySpec *indsp = GetIndustrySpec(ind_fld->u.industry.ind_type);
 
@@ -2447,13 +2447,13 @@ struct CargoesRow {
 
	 * @param column    Column to create the new field.
 
	 * @param accepting Display accepted cargo (if \c false, display produced cargo).
 
	 */
 
	void MakeCargoLabel(int column, bool accepting)
 
	{
 
		CargoID cargoes[MAX_CARGOES];
 
		std::fill(std::begin(cargoes), std::end(cargoes), CT_INVALID);
 
		std::fill(std::begin(cargoes), std::end(cargoes), INVALID_CARGO);
 

	
 
		CargoesField *label_fld = this->columns + column;
 
		CargoesField *cargo_fld = this->columns + (accepting ? column - 1 : column + 1);
 

	
 
		assert(cargo_fld->type == CFT_CARGO && label_fld->type == CFT_EMPTY);
 
		for (uint i = 0; i < cargo_fld->u.cargo.num_cargoes; i++) {
 
@@ -2471,13 +2471,13 @@ struct CargoesRow {
 
	void ConnectIndustryAccepted(int column)
 
	{
 
		CargoesField *ind_fld   = this->columns + column;
 
		CargoesField *cargo_fld = this->columns + column - 1;
 
		assert(ind_fld->type == CFT_INDUSTRY && cargo_fld->type == CFT_CARGO);
 

	
 
		std::fill(std::begin(ind_fld->u.industry.other_accepted), std::end(ind_fld->u.industry.other_accepted), CT_INVALID);
 
		std::fill(std::begin(ind_fld->u.industry.other_accepted), std::end(ind_fld->u.industry.other_accepted), INVALID_CARGO);
 

	
 
		if (ind_fld->u.industry.ind_type < NUM_INDUSTRYTYPES) {
 
			CargoID others[MAX_CARGOES]; // Accepted cargoes not carried in the cargo column.
 
			int other_count = 0;
 

	
 
			const IndustrySpec *indsp = GetIndustrySpec(ind_fld->u.industry.ind_type);
 
@@ -3154,13 +3154,13 @@ struct IndustryCargoesWindow : public Wi
 
		if (widget != WID_IC_PANEL) return false;
 

	
 
		Point fieldxy, xy;
 
		if (!CalculatePositionInWidget(pt, &fieldxy, &xy)) return false;
 

	
 
		const CargoesField *fld = this->fields[fieldxy.y].columns + fieldxy.x;
 
		CargoID cid = CT_INVALID;
 
		CargoID cid = INVALID_CARGO;
 
		switch (fld->type) {
 
			case CFT_CARGO: {
 
				CargoesField *lft = (fieldxy.x > 0) ? this->fields[fieldxy.y].columns + fieldxy.x - 1 : nullptr;
 
				CargoesField *rgt = (fieldxy.x < 4) ? this->fields[fieldxy.y].columns + fieldxy.x + 1 : nullptr;
 
				cid = fld->CargoClickedAt(lft, rgt, xy);
 
				break;
src/linkgraph/linkgraph.h
Show inline comments
 
@@ -186,13 +186,13 @@ public:
 
	inline static uint Scale(uint val, TimerGameCalendar::Date target_age, TimerGameCalendar::Date orig_age)
 
	{
 
		return val > 0 ? std::max(1U, val * target_age.base() / orig_age.base()) : 0;
 
	}
 

	
 
	/** Bare constructor, only for save/load. */
 
	LinkGraph() : cargo(CT_INVALID), last_compression(0) {}
 
	LinkGraph() : cargo(INVALID_CARGO), last_compression(0) {}
 
	/**
 
	 * Real constructor.
 
	 * @param cargo Cargo the link graph is about.
 
	 */
 
	LinkGraph(CargoID cargo) : cargo(cargo), last_compression(TimerGameCalendar::date) {}
 

	
src/linkgraph/linkgraph_gui.h
Show inline comments
 
@@ -18,13 +18,13 @@
 

	
 
/**
 
 * Monthly statistics for a link between two stations.
 
 * Only the cargo type of the most saturated linkgraph is taken into account.
 
 */
 
struct LinkProperties {
 
	LinkProperties() : cargo(CT_INVALID), capacity(0), usage(0), planned(0), shared(false) {}
 
	LinkProperties() : cargo(INVALID_CARGO), capacity(0), usage(0), planned(0), shared(false) {}
 

	
 
	/** Return the usage of the link to display. */
 
	uint Usage() const { return std::max(this->usage, this->planned); }
 

	
 
	CargoID cargo; ///< Cargo type of the link.
 
	uint capacity; ///< Capacity of the link.
src/linkgraph/refresh.cpp
Show inline comments
 
@@ -64,13 +64,13 @@ bool LinkRefresher::Hop::operator<(const
 
 * @param seen_hops Set of hops already seen. This is shared between this
 
 *                  refresher and all its children.
 
 * @param allow_merge If the refresher is allowed to merge or extend link graphs.
 
 * @param is_full_loading If the vehicle is full loading.
 
 */
 
LinkRefresher::LinkRefresher(Vehicle *vehicle, HopSet *seen_hops, bool allow_merge, bool is_full_loading) :
 
	vehicle(vehicle), seen_hops(seen_hops), cargo(CT_INVALID), allow_merge(allow_merge),
 
	vehicle(vehicle), seen_hops(seen_hops), cargo(INVALID_CARGO), allow_merge(allow_merge),
 
	is_full_loading(is_full_loading)
 
{
 
	memset(this->capacities, 0, sizeof(this->capacities));
 

	
 
	/* Assemble list of capacities and set last loading stations to 0. */
 
	for (Vehicle *v = this->vehicle; v != nullptr; v = v->Next()) {
src/linkgraph/refresh.h
Show inline comments
 
@@ -53,13 +53,13 @@ protected:
 
	 * are facing the halting problem here. At some point we have to draw the
 
	 * line.
 
	 */
 
	struct Hop {
 
		OrderID from;  ///< Last order where vehicle could interact with cargo or absolute first order.
 
		OrderID to;    ///< Next order to be processed.
 
		CargoID cargo; ///< Cargo the consist is probably carrying or CT_INVALID if unknown.
 
		CargoID cargo; ///< Cargo the consist is probably carrying or INVALID_CARGO if unknown.
 

	
 
		/**
 
		 * Default constructor should not be called but has to be visible for
 
		 * usage in std::set.
 
		 */
 
		Hop() {NOT_REACHED();}
src/newgrf.cpp
Show inline comments
 
@@ -1137,21 +1137,21 @@ static ChangeInfoResult RailVehicleChang
 
			case 0x15: { // Cargo type
 
				_gted[e->index].defaultcargo_grf = _cur.grffile;
 
				uint8_t ctype = buf->ReadByte();
 

	
 
				if (ctype == 0xFF) {
 
					/* 0xFF is specified as 'use first refittable' */
 
					ei->cargo_type = CT_INVALID;
 
					ei->cargo_type = INVALID_CARGO;
 
				} else if (_cur.grffile->grf_version >= 8) {
 
					/* Use translated cargo. Might result in CT_INVALID (first refittable), if cargo is not defined. */
 
					/* Use translated cargo. Might result in INVALID_CARGO (first refittable), if cargo is not defined. */
 
					ei->cargo_type = GetCargoTranslation(ctype, _cur.grffile);
 
				} else if (ctype < NUM_CARGO) {
 
					/* Use untranslated cargo. */
 
					ei->cargo_type = ctype;
 
				} else {
 
					ei->cargo_type = CT_INVALID;
 
					ei->cargo_type = INVALID_CARGO;
 
					GrfMsg(2, "RailVehicleChangeInfo: Invalid cargo type {}, using first refittable", ctype);
 
				}
 
				break;
 
			}
 

	
 
			case PROP_TRAIN_WEIGHT: // 0x16 Weight
 
@@ -1398,21 +1398,21 @@ static ChangeInfoResult RoadVehicleChang
 
			case 0x10: { // Cargo type
 
				_gted[e->index].defaultcargo_grf = _cur.grffile;
 
				uint8_t ctype = buf->ReadByte();
 

	
 
				if (ctype == 0xFF) {
 
					/* 0xFF is specified as 'use first refittable' */
 
					ei->cargo_type = CT_INVALID;
 
					ei->cargo_type = INVALID_CARGO;
 
				} else if (_cur.grffile->grf_version >= 8) {
 
					/* Use translated cargo. Might result in CT_INVALID (first refittable), if cargo is not defined. */
 
					/* Use translated cargo. Might result in INVALID_CARGO (first refittable), if cargo is not defined. */
 
					ei->cargo_type = GetCargoTranslation(ctype, _cur.grffile);
 
				} else if (ctype < NUM_CARGO) {
 
					/* Use untranslated cargo. */
 
					ei->cargo_type = ctype;
 
				} else {
 
					ei->cargo_type = CT_INVALID;
 
					ei->cargo_type = INVALID_CARGO;
 
					GrfMsg(2, "RailVehicleChangeInfo: Invalid cargo type {}, using first refittable", ctype);
 
				}
 
				break;
 
			}
 

	
 
			case PROP_ROADVEH_COST_FACTOR: // 0x11 Cost factor
 
@@ -1593,21 +1593,21 @@ static ChangeInfoResult ShipVehicleChang
 
			case 0x0C: { // Cargo type
 
				_gted[e->index].defaultcargo_grf = _cur.grffile;
 
				uint8_t ctype = buf->ReadByte();
 

	
 
				if (ctype == 0xFF) {
 
					/* 0xFF is specified as 'use first refittable' */
 
					ei->cargo_type = CT_INVALID;
 
					ei->cargo_type = INVALID_CARGO;
 
				} else if (_cur.grffile->grf_version >= 8) {
 
					/* Use translated cargo. Might result in CT_INVALID (first refittable), if cargo is not defined. */
 
					/* Use translated cargo. Might result in INVALID_CARGO (first refittable), if cargo is not defined. */
 
					ei->cargo_type = GetCargoTranslation(ctype, _cur.grffile);
 
				} else if (ctype < NUM_CARGO) {
 
					/* Use untranslated cargo. */
 
					ei->cargo_type = ctype;
 
				} else {
 
					ei->cargo_type = CT_INVALID;
 
					ei->cargo_type = INVALID_CARGO;
 
					GrfMsg(2, "ShipVehicleChangeInfo: Invalid cargo type {}, using first refittable", ctype);
 
				}
 
				break;
 
			}
 

	
 
			case PROP_SHIP_CARGO_CAPACITY: // 0x0D Cargo capacity
 
@@ -2585,13 +2585,13 @@ static ChangeInfoResult TownHouseChangeI
 
				 * any risks of array overrun. */
 
				for (uint i = 0; i < lengthof(housespec->accepts_cargo); i++) {
 
					if (i < count) {
 
						housespec->accepts_cargo[i] = GetCargoTranslation(buf->ReadByte(), _cur.grffile);
 
						housespec->cargo_acceptance[i] = buf->ReadByte();
 
					} else {
 
						housespec->accepts_cargo[i] = CT_INVALID;
 
						housespec->accepts_cargo[i] = INVALID_CARGO;
 
						housespec->cargo_acceptance[i] = 0;
 
					}
 
				}
 
				break;
 
			}
 

	
 
@@ -3303,13 +3303,13 @@ static ChangeInfoResult IndustrytilesCha
 
				for (uint i = 0; i < std::size(tsp->acceptance); i++) {
 
					if (i < num_cargoes) {
 
						tsp->accepts_cargo[i] = GetCargoTranslation(buf->ReadByte(), _cur.grffile);
 
						/* Tile acceptance can be negative to counteract the INDTILE_SPECIAL_ACCEPTS_ALL_CARGO flag */
 
						tsp->acceptance[i] = (int8_t)buf->ReadByte();
 
					} else {
 
						tsp->accepts_cargo[i] = CT_INVALID;
 
						tsp->accepts_cargo[i] = INVALID_CARGO;
 
						tsp->acceptance[i] = 0;
 
					}
 
				}
 
				break;
 
			}
 

	
 
@@ -3750,13 +3750,13 @@ static ChangeInfoResult IndustriesChange
 
				}
 
				for (uint i = 0; i < lengthof(indsp->produced_cargo); i++) {
 
					if (i < num_cargoes) {
 
						CargoID cargo = GetCargoTranslation(buf->ReadByte(), _cur.grffile);
 
						indsp->produced_cargo[i] = cargo;
 
					} else {
 
						indsp->produced_cargo[i] = CT_INVALID;
 
						indsp->produced_cargo[i] = INVALID_CARGO;
 
					}
 
				}
 
				break;
 
			}
 

	
 
			case 0x26: { // variable length accepted cargoes
 
@@ -3768,13 +3768,13 @@ static ChangeInfoResult IndustriesChange
 
				}
 
				for (uint i = 0; i < lengthof(indsp->accepts_cargo); i++) {
 
					if (i < num_cargoes) {
 
						CargoID cargo = GetCargoTranslation(buf->ReadByte(), _cur.grffile);
 
						indsp->accepts_cargo[i] = cargo;
 
					} else {
 
						indsp->accepts_cargo[i] = CT_INVALID;
 
						indsp->accepts_cargo[i] = INVALID_CARGO;
 
					}
 
				}
 
				break;
 
			}
 

	
 
			case 0x27: { // variable length production rates
 
@@ -5512,47 +5512,47 @@ static CargoID TranslateCargo(uint8_t fe
 
	if (ctype == 0xFF) return CT_PURCHASE;
 

	
 
	if (_cur.grffile->cargo_list.empty()) {
 
		/* No cargo table, so use bitnum values */
 
		if (ctype >= 32) {
 
			GrfMsg(1, "TranslateCargo: Cargo bitnum {} out of range (max 31), skipping.", ctype);
 
			return CT_INVALID;
 
			return INVALID_CARGO;
 
		}
 

	
 
		for (const CargoSpec *cs : CargoSpec::Iterate()) {
 
			if (cs->bitnum == ctype) {
 
				GrfMsg(6, "TranslateCargo: Cargo bitnum {} mapped to cargo type {}.", ctype, cs->Index());
 
				return cs->Index();
 
			}
 
		}
 

	
 
		GrfMsg(5, "TranslateCargo: Cargo bitnum {} not available in this climate, skipping.", ctype);
 
		return CT_INVALID;
 
		return INVALID_CARGO;
 
	}
 

	
 
	/* Check if the cargo type is out of bounds of the cargo translation table */
 
	if (ctype >= _cur.grffile->cargo_list.size()) {
 
		GrfMsg(1, "TranslateCargo: Cargo type {} out of range (max {}), skipping.", ctype, (unsigned int)_cur.grffile->cargo_list.size() - 1);
 
		return CT_INVALID;
 
		return INVALID_CARGO;
 
	}
 

	
 
	/* Look up the cargo label from the translation table */
 
	CargoLabel cl = _cur.grffile->cargo_list[ctype];
 
	if (cl == 0) {
 
		GrfMsg(5, "TranslateCargo: Cargo type {} not available in this climate, skipping.", ctype);
 
		return CT_INVALID;
 
	}
 

	
 
	ctype = GetCargoIDByLabel(cl);
 
	if (!IsValidCargoID(ctype)) {
 
		return INVALID_CARGO;
 
	}
 

	
 
	CargoID cid = GetCargoIDByLabel(cl);
 
	if (!IsValidCargoID(cid)) {
 
		GrfMsg(5, "TranslateCargo: Cargo '{:c}{:c}{:c}{:c}' unsupported, skipping.", GB(cl, 24, 8), GB(cl, 16, 8), GB(cl, 8, 8), GB(cl, 0, 8));
 
		return CT_INVALID;
 
	}
 

	
 
	GrfMsg(6, "TranslateCargo: Cargo '{:c}{:c}{:c}{:c}' mapped to cargo type {}.", GB(cl, 24, 8), GB(cl, 16, 8), GB(cl, 8, 8), GB(cl, 0, 8), ctype);
 
	return ctype;
 
		return INVALID_CARGO;
 
	}
 

	
 
	GrfMsg(6, "TranslateCargo: Cargo '{:c}{:c}{:c}{:c}' mapped to cargo type {}.", GB(cl, 24, 8), GB(cl, 16, 8), GB(cl, 8, 8), GB(cl, 0, 8), cid);
 
	return cid;
 
}
 

	
 

	
 
static bool IsValidGroupID(uint16_t groupid, const char *function)
 
{
 
	if (groupid > MAX_SPRITEGROUP || _cur.spritegroups[groupid] == nullptr) {
 
@@ -5609,24 +5609,24 @@ static void VehicleMapSpriteGroup(ByteRe
 
		uint8_t ctype = buf->ReadByte();
 
		uint16_t groupid = buf->ReadWord();
 
		if (!IsValidGroupID(groupid, "VehicleMapSpriteGroup")) continue;
 

	
 
		GrfMsg(8, "VehicleMapSpriteGroup: * [{}] Cargo type 0x{:X}, group id 0x{:02X}", c, ctype, groupid);
 

	
 
		ctype = TranslateCargo(feature, ctype);
 
		if (!IsValidCargoID(ctype)) continue;
 
		CargoID cid = TranslateCargo(feature, ctype);
 
		if (!IsValidCargoID(cid)) continue;
 

	
 
		for (uint i = 0; i < idcount; i++) {
 
			EngineID engine = engines[i];
 

	
 
			GrfMsg(7, "VehicleMapSpriteGroup: [{}] Engine {}...", i, engine);
 

	
 
			if (wagover) {
 
				SetWagonOverrideSprites(engine, ctype, _cur.spritegroups[groupid], last_engines, last_engines_count);
 
				SetWagonOverrideSprites(engine, cid, _cur.spritegroups[groupid], last_engines, last_engines_count);
 
			} else {
 
				SetCustomEngineSprites(engine, ctype, _cur.spritegroups[groupid]);
 
				SetCustomEngineSprites(engine, cid, _cur.spritegroups[groupid]);
 
			}
 
		}
 
	}
 

	
 
	uint16_t groupid = buf->ReadWord();
 
	if (!IsValidGroupID(groupid, "VehicleMapSpriteGroup")) return;
 
@@ -9052,18 +9052,18 @@ static void CalculateRefitMasks()
 
			/* Apply explicit refit includes/excludes. */
 
			ei->refit_mask |= _gted[engine].ctt_include_mask;
 
			ei->refit_mask &= ~_gted[engine].ctt_exclude_mask;
 
		}
 

	
 
		/* Clear invalid cargoslots (from default vehicles or pre-NewCargo GRFs) */
 
		if (IsValidCargoID(ei->cargo_type) && !HasBit(_cargo_mask, ei->cargo_type)) ei->cargo_type = CT_INVALID;
 
		if (IsValidCargoID(ei->cargo_type) && !HasBit(_cargo_mask, ei->cargo_type)) ei->cargo_type = INVALID_CARGO;
 

	
 
		/* Ensure that the vehicle is either not refittable, or that the default cargo is one of the refittable cargoes.
 
		 * Note: Vehicles refittable to no cargo are handle differently to vehicle refittable to a single cargo. The latter might have subtypes. */
 
		if (!only_defaultcargo && (e->type != VEH_SHIP || e->u.ship.old_refittable) && IsValidCargoID(ei->cargo_type) && !HasBit(ei->refit_mask, ei->cargo_type)) {
 
			ei->cargo_type = CT_INVALID;
 
			ei->cargo_type = INVALID_CARGO;
 
		}
 

	
 
		/* Check if this engine's cargo type is valid. If not, set to the first refittable
 
		 * cargo type. Finally disable the vehicle, if there is still no cargo. */
 
		if (!IsValidCargoID(ei->cargo_type) && ei->refit_mask != 0) {
 
			/* Figure out which CTT to use for the default cargo, if it is 'first refittable'. */
src/newgrf_airporttiles.h
Show inline comments
 
@@ -82,11 +82,11 @@ private:
 
	static AirportTileSpec tiles[NUM_AIRPORTTILES];
 

	
 
	friend void AirportTileOverrideManager::SetEntitySpec(const AirportTileSpec *airpts);
 
};
 

	
 
void AnimateAirportTile(TileIndex tile);
 
void AirportTileAnimationTrigger(Station *st, TileIndex tile, AirpAnimationTrigger trigger, CargoID cargo_type = CT_INVALID);
 
void AirportAnimationTrigger(Station *st, AirpAnimationTrigger trigger, CargoID cargo_type = CT_INVALID);
 
void AirportTileAnimationTrigger(Station *st, TileIndex tile, AirpAnimationTrigger trigger, CargoID cargo_type = INVALID_CARGO);
 
void AirportAnimationTrigger(Station *st, AirpAnimationTrigger trigger, CargoID cargo_type = INVALID_CARGO);
 
bool DrawNewAirportTile(TileInfo *ti, Station *st, const AirportTileSpec *airts);
 

	
 
#endif /* NEWGRF_AIRPORTTILES_H */
src/newgrf_cargo.cpp
Show inline comments
 
@@ -71,19 +71,19 @@ uint16_t GetCargoCallback(CallbackID cal
 
 * Translate a GRF-local cargo slot/bitnum into a CargoID.
 
 * @param cargo   GRF-local cargo slot/bitnum.
 
 * @param grffile Originating GRF file.
 
 * @param usebit  Defines the meaning of \a cargo for GRF version < 7.
 
 *                If true, then \a cargo is a bitnum. If false, then \a cargo is a cargoslot.
 
 *                For GRF version >= 7 \a cargo is always a translated cargo bit.
 
 * @return CargoID or CT_INVALID if the cargo is not available.
 
 * @return CargoID or INVALID_CARGO if the cargo is not available.
 
 */
 
CargoID GetCargoTranslation(uint8_t cargo, const GRFFile *grffile, bool usebit)
 
{
 
	/* Pre-version 7 uses the 'climate dependent' ID in callbacks and properties, i.e. cargo is the cargo ID */
 
	if (grffile->grf_version < 7 && !usebit) {
 
		if (cargo >= CargoSpec::GetArraySize() || !CargoSpec::Get(cargo)->IsValid()) return CT_INVALID;
 
		if (cargo >= CargoSpec::GetArraySize() || !CargoSpec::Get(cargo)->IsValid()) return INVALID_CARGO;
 
		return cargo;
 
	}
 

	
 
	/* Other cases use (possibly translated) cargobits */
 

	
 
	if (!grffile->cargo_list.empty()) {
 
@@ -91,8 +91,8 @@ CargoID GetCargoTranslation(uint8_t carg
 
		 * the label */
 
		if (cargo < grffile->cargo_list.size()) return GetCargoIDByLabel(grffile->cargo_list[cargo]);
 
	} else {
 
		/* Else the cargo value is a 'climate independent' 'bitnum' */
 
		return GetCargoIDByBitnum(cargo);
 
	}
 
	return CT_INVALID;
 
	return INVALID_CARGO;
 
}
src/newgrf_engine.cpp
Show inline comments
 
@@ -448,14 +448,14 @@ static uint32_t VehicleGetVariable(Vehic
 
					cargo_classes |= CargoSpec::Get(u->cargo_type)->classes;
 
					common_cargoes[u->cargo_type]++;
 
				}
 

	
 
				/* Pick the most common cargo type */
 
				auto cargo_it = std::max_element(std::begin(common_cargoes), std::end(common_cargoes));
 
				/* Return CT_INVALID if nothing is carried */
 
				CargoID common_cargo_type = (*cargo_it == 0) ? (CargoID)CT_INVALID : static_cast<CargoID>(std::distance(std::begin(common_cargoes), cargo_it));
 
				/* Return INVALID_CARGO if nothing is carried */
 
				CargoID common_cargo_type = (*cargo_it == 0) ? INVALID_CARGO : static_cast<CargoID>(std::distance(std::begin(common_cargoes), cargo_it));
 

	
 
				/* Count subcargo types of common_cargo_type */
 
				std::array<uint8_t, UINT8_MAX + 1> common_subtypes{};
 
				for (const Vehicle *u = v; u != nullptr; u = u->Next()) {
 
					/* Skip empty engines and engines not carrying common_cargo_type */
 
					if (u->cargo_type != common_cargo_type || !u->GetEngine()->CanCarryCargo()) continue;
 
@@ -483,13 +483,13 @@ static uint32_t VehicleGetVariable(Vehic
 
			 *    is object->ro.grffile.
 
			 *    In case of CBID_TRAIN_ALLOW_WAGON_ATTACH this is not the same as v->GetGRF().
 
			 *  - The grffile == nullptr case only happens if this function is called for default vehicles.
 
			 *    And this is only done by CheckCaches().
 
			 */
 
			const GRFFile *grffile = object->ro.grffile;
 
			uint8_t common_bitnum = (common_cargo_type == CT_INVALID) ? 0xFF :
 
			uint8_t common_bitnum = (common_cargo_type == INVALID_CARGO) ? 0xFF :
 
				(grffile == nullptr || grffile->grf_version < 8) ? CargoSpec::Get(common_cargo_type)->bitnum : grffile->cargo_map[common_cargo_type];
 

	
 
			return (v->grf_cache.consist_cargo_information & 0xFFFF00FF) | common_bitnum << 8;
 
		}
 

	
 
		case 0x43: // Company information
src/newgrf_roadstop.cpp
Show inline comments
 
@@ -344,13 +344,13 @@ void TriggerRoadStopAnimation(BaseStatio
 
	uint16_t random_bits = Random();
 
	auto process_tile = [&](TileIndex cur_tile) {
 
		const RoadStopSpec *ss = GetRoadStopSpec(cur_tile);
 
		if (ss != nullptr && HasBit(ss->animation.triggers, trigger)) {
 
			CargoID cargo;
 
			if (!IsValidCargoID(cargo_type)) {
 
				cargo = CT_INVALID;
 
				cargo = INVALID_CARGO;
 
			} else {
 
				cargo = ss->grf_prop.grffile->cargo_map[cargo_type];
 
			}
 
			RoadStopAnimationBase::ChangeAnimationFrame(CBID_STATION_ANIM_START_STOP, ss, st, cur_tile, (random_bits << 16) | Random(), (uint8_t)trigger | (cargo << 8));
 
		}
 
	};
src/newgrf_roadstop.h
Show inline comments
 
@@ -166,14 +166,14 @@ typedef NewGRFClass<RoadStopSpec, RoadSt
 
void DrawRoadStopTile(int x, int y, RoadType roadtype, const RoadStopSpec *spec, StationType type, int view);
 

	
 
uint16_t GetRoadStopCallback(CallbackID callback, uint32_t param1, uint32_t param2, const RoadStopSpec *roadstopspec, BaseStation *st, TileIndex tile, RoadType roadtype, StationType type, uint8_t view);
 

	
 
void AnimateRoadStopTile(TileIndex tile);
 
uint8_t GetRoadStopTileAnimationSpeed(TileIndex tile);
 
void TriggerRoadStopAnimation(BaseStation *st, TileIndex tile, StationAnimationTrigger trigger, CargoID cargo_type = CT_INVALID);
 
void TriggerRoadStopRandomisation(Station *st, TileIndex tile, RoadStopRandomTrigger trigger, CargoID cargo_type = CT_INVALID);
 
void TriggerRoadStopAnimation(BaseStation *st, TileIndex tile, StationAnimationTrigger trigger, CargoID cargo_type = INVALID_CARGO);
 
void TriggerRoadStopRandomisation(Station *st, TileIndex tile, RoadStopRandomTrigger trigger, CargoID cargo_type = INVALID_CARGO);
 

	
 
bool GetIfNewStopsByType(RoadStopType rs, RoadType roadtype);
 
bool GetIfClassHasNewStopsByType(RoadStopClass *roadstopclass, RoadStopType rs, RoadType roadtype);
 
bool GetIfStopIsForType(const RoadStopSpec *roadstopspec, RoadStopType rs, RoadType roadtype);
 

	
 
uint GetCountOfCompatibleStopsByType(RoadStopClass *roadstopclass, RoadStopType rs);
src/newgrf_station.cpp
Show inline comments
 
@@ -492,13 +492,13 @@ uint32_t Waypoint::GetNewGRFVariable(con
 
	}
 

	
 
	uint cargo = 0;
 
	const Station *st = Station::From(this->station_scope.st);
 

	
 
	switch (this->station_scope.cargo_type) {
 
		case CT_INVALID:
 
		case INVALID_CARGO:
 
		case CT_DEFAULT_NA:
 
		case CT_PURCHASE:
 
			cargo = 0;
 
			break;
 

	
 
		case CT_DEFAULT:
 
@@ -884,13 +884,13 @@ void TriggerStationAnimation(BaseStation
 
	for (TileIndex tile : area) {
 
		if (st->TileBelongsToRailStation(tile)) {
 
			const StationSpec *ss = GetStationSpec(tile);
 
			if (ss != nullptr && HasBit(ss->animation.triggers, trigger)) {
 
				CargoID cargo;
 
				if (!IsValidCargoID(cargo_type)) {
 
					cargo = CT_INVALID;
 
					cargo = INVALID_CARGO;
 
				} else {
 
					cargo = ss->grf_prop.grffile->cargo_map[cargo_type];
 
				}
 
				StationAnimationBase::ChangeAnimationFrame(CBID_STATION_ANIM_START_STOP, ss, st, tile, (random_bits << 16) | GB(Random(), 0, 16), (uint8_t)trigger | (cargo << 8));
 
			}
 
		}
src/newgrf_station.h
Show inline comments
 
@@ -33,13 +33,13 @@ struct StationScopeResolver : public Sco
 
	 * @param ro Surrounding resolver.
 
	 * @param statspec Station (type) specification.
 
	 * @param st Instance of the station.
 
	 * @param tile %Tile of the station.
 
	 */
 
	StationScopeResolver(ResolverObject &ro, const StationSpec *statspec, BaseStation *st, TileIndex tile)
 
		: ScopeResolver(ro), tile(tile), st(st), statspec(statspec), cargo_type(CT_INVALID), axis(INVALID_AXIS)
 
		: ScopeResolver(ro), tile(tile), st(st), statspec(statspec), cargo_type(INVALID_CARGO), axis(INVALID_AXIS)
 
	{
 
	}
 

	
 
	uint32_t GetRandomBits() const override;
 
	uint32_t GetTriggers() const override;
 

	
 
@@ -195,11 +195,11 @@ int AllocateSpecToStation(const StationS
 
void DeallocateSpecFromStation(BaseStation *st, byte specindex);
 

	
 
/* Draw representation of a station tile for GUI purposes. */
 
bool DrawStationTile(int x, int y, RailType railtype, Axis axis, StationClassID sclass, uint station);
 

	
 
void AnimateStationTile(TileIndex tile);
 
void TriggerStationAnimation(BaseStation *st, TileIndex tile, StationAnimationTrigger trigger, CargoID cargo_type = CT_INVALID);
 
void TriggerStationRandomisation(Station *st, TileIndex tile, StationRandomTrigger trigger, CargoID cargo_type = CT_INVALID);
 
void TriggerStationAnimation(BaseStation *st, TileIndex tile, StationAnimationTrigger trigger, CargoID cargo_type = INVALID_CARGO);
 
void TriggerStationRandomisation(Station *st, TileIndex tile, StationRandomTrigger trigger, CargoID cargo_type = INVALID_CARGO);
 
void StationUpdateCachedTriggers(BaseStation *st);
 

	
 
#endif /* NEWGRF_STATION_H */
src/saveload/afterload.cpp
Show inline comments
 
@@ -3026,19 +3026,19 @@ bool AfterLoadGame()
 
	}
 

	
 
	if (IsSavegameVersionBefore(SLV_EXTEND_INDUSTRY_CARGO_SLOTS)) {
 
		/* Make sure added industry cargo slots are cleared */
 
		for (Industry *i : Industry::Iterate()) {
 
			for (auto it = std::begin(i->produced) + 2; it != std::end(i->produced); ++it) {
 
				it->cargo = CT_INVALID;
 
				it->cargo = INVALID_CARGO;
 
				it->waiting = 0;
 
				it->rate = 0;
 
				it->history = {};
 
			}
 
			for (auto it = std::begin(i->accepted) + 3; it != std::end(i->accepted); ++it) {
 
				it->cargo = CT_INVALID;
 
				it->cargo = INVALID_CARGO;
 
				it->waiting = 0;
 
			}
 
			/* Make sure last_cargo_accepted_at is copied to elements for every valid input cargo.
 
			 * The loading routine should put the original singular value into the first array element. */
 
			for (auto &a : i->accepted) {
 
				if (IsValidCargoID(a.cargo)) {
src/script/api/script_cargo.hpp
Show inline comments
 
@@ -54,13 +54,13 @@ public:
 
	 * Special cargo types.
 
	 */
 
	enum SpecialCargoID {
 
		/* Note: these values represent part of the in-game CargoTypes enum */
 
		CT_AUTO_REFIT = ::CT_AUTO_REFIT, ///< Automatically choose cargo type when doing auto-refitting.
 
		CT_NO_REFIT   = ::CT_NO_REFIT,   ///< Do not refit cargo of a vehicle.
 
		CT_INVALID    = ::CT_INVALID,    ///< An invalid cargo type.
 
		CT_INVALID    = ::INVALID_CARGO, ///< An invalid cargo type.
 
	};
 

	
 
	/**
 
	 * Type of cargo distribution.
 
	 */
 
	enum DistributionType {
src/script/api/script_engine.cpp
Show inline comments
 
@@ -49,18 +49,18 @@
 
	::SetDParam(0, engine_id);
 
	return GetString(STR_ENGINE_NAME);
 
}
 

	
 
/* static */ CargoID ScriptEngine::GetCargoType(EngineID engine_id)
 
{
 
	if (!IsValidEngine(engine_id)) return CT_INVALID;
 
	if (!IsValidEngine(engine_id)) return INVALID_CARGO;
 

	
 
	CargoArray cap = ::GetCapacityOfArticulatedParts(engine_id);
 

	
 
	auto it = std::max_element(std::cbegin(cap), std::cend(cap));
 
	if (*it == 0) return CT_INVALID;
 
	if (*it == 0) return INVALID_CARGO;
 

	
 
	return CargoID(std::distance(std::cbegin(cap), it));
 
}
 

	
 
/* static */ bool ScriptEngine::CanRefitCargo(EngineID engine_id, CargoID cargo_id)
 
{
src/script/api/script_event_types.cpp
Show inline comments
 
@@ -36,17 +36,17 @@ std::optional<std::string> ScriptEventEn
 
	::SetDParam(0, this->engine);
 
	return GetString(STR_ENGINE_NAME);
 
}
 

	
 
CargoID ScriptEventEnginePreview::GetCargoType()
 
{
 
	if (!this->IsEngineValid()) return CT_INVALID;
 
	if (!this->IsEngineValid()) return INVALID_CARGO;
 
	CargoArray cap = ::GetCapacityOfArticulatedParts(this->engine);
 

	
 
	auto it = std::max_element(std::cbegin(cap), std::cend(cap));
 
	if (*it == 0) return CT_INVALID;
 
	if (*it == 0) return INVALID_CARGO;
 

	
 
	return CargoID(std::distance(std::cbegin(cap), it));
 
}
 

	
 
int32_t ScriptEventEnginePreview::GetCapacity()
 
{
src/script/api/script_industry.hpp
Show inline comments
 
@@ -254,15 +254,15 @@ public:
 
	 */
 
	static SQInteger GetLastProductionYear(IndustryID industry_id);
 

	
 
	/**
 
	 * Get the last date this industry accepted any cargo delivery.
 
	 * @param industry_id The index of the industry.
 
	 * @param cargo_type The cargo to query, or CT_INVALID to query latest of all accepted cargoes.
 
	 * @param cargo_type The cargo to query, or INVALID_CARGO to query latest of all accepted cargoes.
 
	 * @pre IsValidIndustry(industry_id).
 
	 * @pre IsValidCargo(cargo_type) || cargo_type == CT_INVALID.
 
	 * @pre IsValidCargo(cargo_type) || cargo_type == INVALID_CARGO.
 
	 * @return Date the industry last received cargo from a delivery, or ScriptDate::DATE_INVALID on error.
 
	 * @api -ai
 
	 */
 
	static ScriptDate::Date GetCargoLastAcceptedDate(IndustryID industry_id, CargoID cargo_type);
 

	
 
	/**
src/script/api/script_subsidy.cpp
Show inline comments
 
@@ -64,13 +64,13 @@
 

	
 
	return ScriptDate::GetDate(year, month, 1);
 
}
 

	
 
/* static */ CargoID ScriptSubsidy::GetCargoType(SubsidyID subsidy_id)
 
{
 
	if (!IsValidSubsidy(subsidy_id)) return CT_INVALID;
 
	if (!IsValidSubsidy(subsidy_id)) return INVALID_CARGO;
 

	
 
	return ::Subsidy::Get(subsidy_id)->cargo_type;
 
}
 

	
 
/* static */ ScriptSubsidy::SubsidyParticipantType ScriptSubsidy::GetSourceType(SubsidyID subsidy_id)
 
{
src/script/api/script_vehicle.cpp
Show inline comments
 
@@ -86,13 +86,13 @@
 
	/* In case of test-mode, we return VehicleID 0 */
 
	return 0;
 
}
 

	
 
/* static */ VehicleID ScriptVehicle::BuildVehicle(TileIndex depot, EngineID engine_id)
 
{
 
	return _BuildVehicleInternal(depot, engine_id, CT_INVALID);
 
	return _BuildVehicleInternal(depot, engine_id, INVALID_CARGO);
 
}
 

	
 
/* static */ VehicleID ScriptVehicle::BuildVehicleWithRefit(TileIndex depot, EngineID engine_id, CargoID cargo)
 
{
 
	EnforcePrecondition(VEHICLE_INVALID, ScriptCargo::IsValidCargo(cargo));
 
	return _BuildVehicleInternal(depot, engine_id, cargo);
src/station_gui.cpp
Show inline comments
 
@@ -1747,13 +1747,13 @@ struct StationViewWindow : public Window
 
	 * @param pos Current row to be drawn to (counted down from 0 to -maxrows, same as vscroll->GetPosition()).
 
	 * @param maxrows Maximum row to be drawn.
 
	 * @param column Current "column" being drawn.
 
	 * @param cargo Current cargo being drawn (if cargo column has been passed).
 
	 * @return row (in "pos" counting) after the one we have last drawn to.
 
	 */
 
	int DrawEntries(CargoDataEntry *entry, const Rect &r, int pos, int maxrows, int column, CargoID cargo = CT_INVALID)
 
	int DrawEntries(CargoDataEntry *entry, const Rect &r, int pos, int maxrows, int column, CargoID cargo = INVALID_CARGO)
 
	{
 
		if (this->sortings[column] == CargoSortType::AsGrouping) {
 
			if (this->groupings[column] != GR_CARGO) {
 
				entry->Resort(CargoSortType::StationString, this->sort_orders[column]);
 
			}
 
		} else {
src/subsidy_base.h
Show inline comments
 
@@ -17,13 +17,13 @@
 

	
 
typedef Pool<Subsidy, SubsidyID, 1, 256> SubsidyPool;
 
extern SubsidyPool _subsidy_pool;
 

	
 
/** Struct about subsidies, offered and awarded */
 
struct Subsidy : SubsidyPool::PoolItem<&_subsidy_pool> {
 
	CargoID cargo_type;  ///< Cargo type involved in this subsidy, CT_INVALID for invalid subsidy
 
	CargoID cargo_type;  ///< Cargo type involved in this subsidy, INVALID_CARGO for invalid subsidy
 
	uint16_t remaining;    ///< Remaining months when this subsidy is valid
 
	CompanyID awarded;   ///< Subsidy is awarded to this company; INVALID_COMPANY if it's not awarded to anyone
 
	SourceType src_type; ///< Source of subsidised path (SourceType::Industry or SourceType::Town)
 
	SourceType dst_type; ///< Destination of subsidised path (SourceType::Industry or SourceType::Town)
 
	SourceID src;        ///< Index of source. Either TownID or IndustryID
 
	SourceID dst;        ///< Index of destination. Either TownID or IndustryID
src/train_gui.cpp
Show inline comments
 
@@ -270,13 +270,13 @@ static void GetCargoSummaryOfArticulated
 
{
 
	summary.clear();
 
	do {
 
		if (!v->GetEngine()->CanCarryCargo()) continue;
 

	
 
		CargoSummaryItem new_item;
 
		new_item.cargo = v->cargo_cap > 0 ? v->cargo_type : (CargoID)CT_INVALID;
 
		new_item.cargo = v->cargo_cap > 0 ? v->cargo_type : INVALID_CARGO;
 
		new_item.subtype = GetCargoSubtypeText(v);
 
		if (!IsValidCargoID(new_item.cargo) && new_item.subtype == STR_EMPTY) continue;
 

	
 
		auto item = std::find(std::begin(summary), std::end(summary), new_item);
 
		if (item == std::end(summary)) {
 
			item = summary.emplace(std::end(summary));
src/vehicle.cpp
Show inline comments
 
@@ -1899,13 +1899,13 @@ bool CanBuildVehicleInfrastructure(Vehic
 
 * @param parent_engine_type Engine of the front vehicle, #INVALID_ENGINE if vehicle is at front itself.
 
 * @param v the vehicle, \c nullptr if in purchase list etc.
 
 * @return livery scheme to use.
 
 */
 
LiveryScheme GetEngineLiveryScheme(EngineID engine_type, EngineID parent_engine_type, const Vehicle *v)
 
{
 
	CargoID cargo_type = v == nullptr ? (CargoID)CT_INVALID : v->cargo_type;
 
	CargoID cargo_type = v == nullptr ? INVALID_CARGO : v->cargo_type;
 
	const Engine *e = Engine::Get(engine_type);
 
	switch (e->type) {
 
		default: NOT_REACHED();
 
		case VEH_TRAIN:
 
			if (v != nullptr && parent_engine_type != INVALID_ENGINE && (UsesWagonOverride(v) || (v->IsArticulatedPart() && e->u.rail.railveh_type != RAILVEH_WAGON))) {
 
				/* Wagonoverrides use the colour scheme of the front engine.
src/vehicle_cmd.cpp
Show inline comments
 
@@ -871,13 +871,13 @@ std::tuple<CommandCost, VehicleID> CmdCl
 
		 * engine. This caused the vehicle to be not build as 'the limit' had been
 
		 * reached, resulting in partially build vehicles and such. */
 
		DoCommandFlag build_flags = flags;
 
		if ((flags & DC_EXEC) && !v->IsPrimaryVehicle()) build_flags |= DC_AUTOREPLACE;
 

	
 
		CommandCost cost;
 
		std::tie(cost, new_veh_id, std::ignore, std::ignore, std::ignore) = Command<CMD_BUILD_VEHICLE>::Do(build_flags, tile, v->engine_type, false, CT_INVALID, INVALID_CLIENT_ID);
 
		std::tie(cost, new_veh_id, std::ignore, std::ignore, std::ignore) = Command<CMD_BUILD_VEHICLE>::Do(build_flags, tile, v->engine_type, false, INVALID_CARGO, INVALID_CLIENT_ID);
 

	
 
		if (cost.Failed()) {
 
			/* Can't build a part, then sell the stuff we already made; clear up the mess */
 
			if (w_front != nullptr) Command<CMD_SELL_VEHICLE>::Do(flags, w_front->index, true, false, INVALID_CLIENT_ID);
 
			return { cost, INVALID_VEHICLE };
 
		}
 
@@ -950,13 +950,13 @@ std::tuple<CommandCost, VehicleID> CmdCl
 
					w = w->GetNextArticulatedPart();
 
				} else {
 
					break;
 
				}
 
			} else {
 
				const Engine *e = v->GetEngine();
 
				CargoID initial_cargo = (e->CanCarryCargo() ? e->GetDefaultCargoType() : (CargoID)CT_INVALID);
 
				CargoID initial_cargo = (e->CanCarryCargo() ? e->GetDefaultCargoType() : INVALID_CARGO);
 

	
 
				if (v->cargo_type != initial_cargo && IsValidCargoID(initial_cargo)) {
 
					bool dummy;
 
					total_cost.AddCost(GetRefitCost(nullptr, v->engine_type, v->cargo_type, v->cargo_subtype, &dummy));
 
				}
 
			}
src/vehicle_gui.cpp
Show inline comments
 
@@ -776,13 +776,13 @@ struct RefitWindow : public Window {
 
	 * Refresh scrollbar after selection changed
 
	 */
 
	void RefreshScrollbar()
 
	{
 
		size_t scroll_row = 0;
 
		size_t rows = 0;
 
		CargoID cargo = this->selected_refit == nullptr ? (CargoID)CT_INVALID : this->selected_refit->cargo;
 
		CargoID cargo = this->selected_refit == nullptr ? INVALID_CARGO : this->selected_refit->cargo;
 

	
 
		for (const auto &pair : this->refit_list) {
 
			if (pair.first == cargo) {
 
				/* selected_refit points to an element in the vector so no need to search for it. */
 
				scroll_row = rows + (this->selected_refit - pair.second.data());
 
				rows += pair.second.size();
src/vehicle_gui_base.h
Show inline comments
 
@@ -72,13 +72,13 @@ struct BaseVehicleListWindow : public Wi
 

	
 
		GB_END,
 
	};
 

	
 
	/** Special cargo filter criteria */
 
	enum CargoFilterSpecialType {
 
		CF_NONE = CT_INVALID,       ///< Show only vehicles which do not carry cargo (e.g. train engines)
 
		CF_NONE = INVALID_CARGO,    ///< Show only vehicles which do not carry cargo (e.g. train engines)
 
		CF_ANY = CT_NO_REFIT,       ///< Show all vehicles independent of carried cargo (i.e. no filtering)
 
		CF_FREIGHT = CT_AUTO_REFIT, ///< Show only vehicles which carry any freight (non-passenger) cargo
 
	};
 

	
 
	GroupBy grouping;                           ///< How we want to group the list.
 
	VehicleList vehicles;                       ///< List of vehicles.  This is the buffer for `vehgroups` to point into; if this is structurally modified, `vehgroups` must be rebuilt.
0 comments (0 inline, 0 general)