Changeset - r28424:913b64f47f66
[Not reviewed]
master
0 5 0
Peter Nelson - 11 months ago 2024-01-08 21:40:09
peter1138@openttd.org
Codechange: Rename and move SpriteGroup-specific cargo types into a namespace.

These 'cargo types' have special defined uses and must not be used elsewhere. This makes it clearer that they are special.
5 files changed with 30 insertions and 23 deletions:
0 comments (0 inline, 0 general)
src/newgrf.cpp
Show inline comments
 
@@ -5508,8 +5508,8 @@ static void NewSpriteGroup(ByteReader *b
 
static CargoID TranslateCargo(uint8_t feature, uint8_t ctype)
 
{
 
	/* Special cargo types for purchase list and stations */
 
	if ((feature == GSF_STATIONS || feature == GSF_ROADSTOPS) && ctype == 0xFE) return CT_DEFAULT_NA;
 
	if (ctype == 0xFF) return CT_PURCHASE;
 
	if ((feature == GSF_STATIONS || feature == GSF_ROADSTOPS) && ctype == 0xFE) return SpriteGroupCargo::SG_DEFAULT_NA;
 
	if (ctype == 0xFF) return SpriteGroupCargo::SG_PURCHASE;
 

	
 
	if (_cur.grffile->cargo_list.empty()) {
 
		/* No cargo table, so use bitnum values */
 
@@ -5637,9 +5637,9 @@ static void VehicleMapSpriteGroup(ByteRe
 
		EngineID engine = engines[i];
 

	
 
		if (wagover) {
 
			SetWagonOverrideSprites(engine, CT_DEFAULT, _cur.spritegroups[groupid], last_engines, last_engines_count);
 
			SetWagonOverrideSprites(engine, SpriteGroupCargo::SG_DEFAULT, _cur.spritegroups[groupid], last_engines, last_engines_count);
 
		} else {
 
			SetCustomEngineSprites(engine, CT_DEFAULT, _cur.spritegroups[groupid]);
 
			SetCustomEngineSprites(engine, SpriteGroupCargo::SG_DEFAULT, _cur.spritegroups[groupid]);
 
			SetEngineGRF(engine, _cur.grffile);
 
		}
 
	}
 
@@ -5722,7 +5722,7 @@ static void StationMapSpriteGroup(ByteRe
 
			continue;
 
		}
 

	
 
		statspec->grf_prop.spritegroup[CT_DEFAULT] = _cur.spritegroups[groupid];
 
		statspec->grf_prop.spritegroup[SpriteGroupCargo::SG_DEFAULT] = _cur.spritegroups[groupid];
 
		statspec->grf_prop.grffile = _cur.grffile;
 
		statspec->grf_prop.local_id = station;
 
		StationClass::Assign(statspec);
 
@@ -6092,7 +6092,7 @@ static void RoadStopMapSpriteGroup(ByteR
 
			continue;
 
		}
 

	
 
		roadstopspec->grf_prop.spritegroup[CT_DEFAULT] = _cur.spritegroups[groupid];
 
		roadstopspec->grf_prop.spritegroup[SpriteGroupCargo::SG_DEFAULT] = _cur.spritegroups[groupid];
 
		roadstopspec->grf_prop.grffile = _cur.grffile;
 
		roadstopspec->grf_prop.local_id = roadstop;
 
		RoadStopClass::Assign(roadstopspec);
src/newgrf_cargo.h
Show inline comments
 
@@ -14,9 +14,16 @@
 
#include "cargo_type.h"
 
#include "gfx_type.h"
 

	
 
static const CargoID CT_DEFAULT      = NUM_CARGO + 0;
 
static const CargoID CT_PURCHASE     = NUM_CARGO + 1;
 
static const CargoID CT_DEFAULT_NA   = NUM_CARGO + 2;
 
/**
 
 * Sprite Group Cargo types.
 
 * These special cargo types are used when resolving sprite groups when non-cargo-specific sprites or callbacks are needed,
 
 * e.g. in purchase lists, or if no specific cargo type sprite group is supplied.
 
 */
 
namespace SpriteGroupCargo {
 
	static constexpr CargoID SG_DEFAULT    = NUM_CARGO;     ///< Default type used when no more-specific cargo matches.
 
	static constexpr CargoID SG_PURCHASE   = NUM_CARGO + 1; ///< Used in purchase lists before an item exists.
 
	static constexpr CargoID SG_DEFAULT_NA = NUM_CARGO + 2; ///< Used only by stations and roads when no more-specific cargo matches.
 
};
 

	
 
/* Forward declarations of structs used */
 
struct CargoSpec;
src/newgrf_engine.cpp
Show inline comments
 
@@ -31,7 +31,7 @@ void SetWagonOverrideSprites(EngineID en
 
{
 
	Engine *e = Engine::Get(engine);
 

	
 
	assert(cargo < NUM_CARGO + 2); // Include CT_DEFAULT and CT_PURCHASE pseudo cargoes.
 
	assert(cargo < NUM_CARGO + 2); // Include SpriteGroupCargo::SG_DEFAULT and SpriteGroupCargo::SG_PURCHASE pseudo cargoes.
 

	
 
	WagonOverride *wo = &e->overrides.emplace_back();
 
	wo->group = group;
 
@@ -44,7 +44,7 @@ const SpriteGroup *GetWagonOverrideSprit
 
	const Engine *e = Engine::Get(engine);
 

	
 
	for (const WagonOverride &wo : e->overrides) {
 
		if (wo.cargo != cargo && wo.cargo != CT_DEFAULT) continue;
 
		if (wo.cargo != cargo && wo.cargo != SpriteGroupCargo::SG_DEFAULT) continue;
 
		if (std::find(wo.engines.begin(), wo.engines.end(), overriding_engine) != wo.engines.end()) return wo.group;
 
	}
 
	return nullptr;
 
@@ -1044,7 +1044,7 @@ VehicleResolverObject::VehicleResolverOb
 
	cached_relative_count(0)
 
{
 
	if (wagon_override == WO_SELF) {
 
		this->root_spritegroup = GetWagonOverrideSpriteSet(engine_type, CT_DEFAULT, engine_type);
 
		this->root_spritegroup = GetWagonOverrideSpriteSet(engine_type, SpriteGroupCargo::SG_DEFAULT, engine_type);
 
	} else {
 
		if (wagon_override != WO_NONE && v != nullptr && v->IsGroundVehicle()) {
 
			assert(v->engine_type == engine_type); // overrides make little sense with fake scopes
 
@@ -1061,9 +1061,9 @@ VehicleResolverObject::VehicleResolverOb
 

	
 
		if (this->root_spritegroup == nullptr) {
 
			const Engine *e = Engine::Get(engine_type);
 
			CargoID cargo = v != nullptr ? v->cargo_type : CT_PURCHASE;
 
			CargoID cargo = v != nullptr ? v->cargo_type : SpriteGroupCargo::SG_PURCHASE;
 
			assert(cargo < lengthof(e->grf_prop.spritegroup));
 
			this->root_spritegroup = e->grf_prop.spritegroup[cargo] != nullptr ? e->grf_prop.spritegroup[cargo] : e->grf_prop.spritegroup[CT_DEFAULT];
 
			this->root_spritegroup = e->grf_prop.spritegroup[cargo] != nullptr ? e->grf_prop.spritegroup[cargo] : e->grf_prop.spritegroup[SpriteGroupCargo::SG_DEFAULT];
 
		}
 
	}
 
}
src/newgrf_roadstop.cpp
Show inline comments
 
@@ -196,11 +196,11 @@ RoadStopResolverObject::RoadStopResolver
 

	
 
	this->town_scope = nullptr;
 

	
 
	CargoID ctype = CT_DEFAULT_NA;
 
	CargoID ctype = SpriteGroupCargo::SG_DEFAULT_NA;
 

	
 
	if (st == nullptr) {
 
		/* No station, so we are in a purchase list */
 
		ctype = CT_PURCHASE;
 
		ctype = SpriteGroupCargo::SG_PURCHASE;
 
	} else if (Station::IsExpected(st)) {
 
		const Station *station = Station::From(st);
 
		/* Pick the first cargo that we have waiting */
 
@@ -214,7 +214,7 @@ RoadStopResolverObject::RoadStopResolver
 
	}
 

	
 
	if (roadstopspec->grf_prop.spritegroup[ctype] == nullptr) {
 
		ctype = CT_DEFAULT;
 
		ctype = SpriteGroupCargo::SG_DEFAULT;
 
	}
 

	
 
	/* Remember the cargo type we've picked */
src/newgrf_station.cpp
Show inline comments
 
@@ -496,12 +496,12 @@ uint32_t Waypoint::GetNewGRFVariable(con
 

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

	
 
		case CT_DEFAULT:
 
		case SpriteGroupCargo::SG_DEFAULT:
 
			for (const GoodsEntry &ge : st->goods) {
 
				cargo += ge.cargo.TotalCount();
 
			}
 
@@ -557,11 +557,11 @@ StationResolverObject::StationResolverOb
 
	/* Invalidate all cached vars */
 
	_svc.valid = 0;
 

	
 
	CargoID ctype = CT_DEFAULT_NA;
 
	CargoID ctype = SpriteGroupCargo::SG_DEFAULT_NA;
 

	
 
	if (this->station_scope.st == nullptr) {
 
		/* No station, so we are in a purchase list */
 
		ctype = CT_PURCHASE;
 
		ctype = SpriteGroupCargo::SG_PURCHASE;
 
	} else if (Station::IsExpected(this->station_scope.st)) {
 
		const Station *st = Station::From(this->station_scope.st);
 
		/* Pick the first cargo that we have waiting */
 
@@ -575,7 +575,7 @@ StationResolverObject::StationResolverOb
 
	}
 

	
 
	if (this->station_scope.statspec->grf_prop.spritegroup[ctype] == nullptr) {
 
		ctype = CT_DEFAULT;
 
		ctype = SpriteGroupCargo::SG_DEFAULT;
 
	}
 

	
 
	/* Remember the cargo type we've picked */
0 comments (0 inline, 0 general)