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.
This commit is contained in:
Peter Nelson 2024-01-08 21:40:09 +00:00 committed by Peter Nelson
parent 400ae65ff2
commit 97e2bc612c
5 changed files with 30 additions and 23 deletions

View File

@ -5508,8 +5508,8 @@ static void NewSpriteGroup(ByteReader *buf)
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(ByteReader *buf, byte feature, uint8_t idcount
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(ByteReader *buf, uint8_t idcount)
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(ByteReader *buf, uint8_t idcount)
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);

View File

@ -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;

View File

@ -31,7 +31,7 @@ void SetWagonOverrideSprites(EngineID engine, CargoID cargo, const SpriteGroup *
{
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 *GetWagonOverrideSpriteSet(EngineID engine, CargoID cargo, Eng
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::VehicleResolverObject(EngineID engine_type, const Vehicle
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::VehicleResolverObject(EngineID engine_type, const Vehicle
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];
}
}
}

View File

@ -196,11 +196,11 @@ RoadStopResolverObject::RoadStopResolverObject(const RoadStopSpec *roadstopspec,
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::RoadStopResolverObject(const RoadStopSpec *roadstopspec,
}
if (roadstopspec->grf_prop.spritegroup[ctype] == nullptr) {
ctype = CT_DEFAULT;
ctype = SpriteGroupCargo::SG_DEFAULT;
}
/* Remember the cargo type we've picked */

View File

@ -496,12 +496,12 @@ uint32_t Waypoint::GetNewGRFVariable(const ResolverObject &, byte variable, [[ma
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::StationResolverObject(const StationSpec *statspec, BaseSt
/* 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::StationResolverObject(const StationSpec *statspec, BaseSt
}
if (this->station_scope.statspec->grf_prop.spritegroup[ctype] == nullptr) {
ctype = CT_DEFAULT;
ctype = SpriteGroupCargo::SG_DEFAULT;
}
/* Remember the cargo type we've picked */