1
0
Fork 0

Codechange: Make SpriteType, CargoSortType, SourceType and ScriptType enum classes. (#10663)

This avoids a (soft) namespace conflict between the four ST_* enums.
pull/10668/head
PeterN 2023-04-16 20:00:55 +01:00 committed by GitHub
parent 32c8e7feb8
commit e97bf271dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
42 changed files with 189 additions and 189 deletions

View File

@ -332,13 +332,13 @@ foreach(LINE IN LISTS SOURCE_LINES)
endif() endif()
string(APPEND SQUIRREL_EXPORT "\n") string(APPEND SQUIRREL_EXPORT "\n")
string(APPEND SQUIRREL_EXPORT "\ntemplate <> const char *GetClassName<${CLS}, ST_${APIUC}>() { return \"${API_CLS}\"; }") string(APPEND SQUIRREL_EXPORT "\ntemplate <> const char *GetClassName<${CLS}, ScriptType::${APIUC}>() { return \"${API_CLS}\"; }")
string(APPEND SQUIRREL_EXPORT "\n") string(APPEND SQUIRREL_EXPORT "\n")
# Then do the registration functions of the class. # Then do the registration functions of the class.
string(APPEND SQUIRREL_EXPORT "\nvoid SQ${API_CLS}_Register(Squirrel *engine)") string(APPEND SQUIRREL_EXPORT "\nvoid SQ${API_CLS}_Register(Squirrel *engine)")
string(APPEND SQUIRREL_EXPORT "\n{") string(APPEND SQUIRREL_EXPORT "\n{")
string(APPEND SQUIRREL_EXPORT "\n DefSQClass<${CLS}, ST_${APIUC}> SQ${API_CLS}(\"${API_CLS}\");") string(APPEND SQUIRREL_EXPORT "\n DefSQClass<${CLS}, ScriptType::${APIUC}> SQ${API_CLS}(\"${API_CLS}\");")
if("${SUPER_CLS}" STREQUAL "Text" OR "${SUPER_CLS}" STREQUAL "ScriptObject" OR "${SUPER_CLS}" STREQUAL "AIAbstractiveList::Valuator") if("${SUPER_CLS}" STREQUAL "Text" OR "${SUPER_CLS}" STREQUAL "ScriptObject" OR "${SUPER_CLS}" STREQUAL "AIAbstractiveList::Valuator")
string(APPEND SQUIRREL_EXPORT "\n SQ${API_CLS}.PreRegister(engine);") string(APPEND SQUIRREL_EXPORT "\n SQ${API_CLS}.PreRegister(engine);")
else() else()

View File

@ -32,12 +32,12 @@ static bool CheckAPIVersion(const char *api_version)
#if defined(_WIN32) #if defined(_WIN32)
#undef GetClassName #undef GetClassName
#endif /* _WIN32 */ #endif /* _WIN32 */
template <> const char *GetClassName<AIInfo, ST_AI>() { return "AIInfo"; } template <> const char *GetClassName<AIInfo, ScriptType::AI>() { return "AIInfo"; }
/* static */ void AIInfo::RegisterAPI(Squirrel *engine) /* static */ void AIInfo::RegisterAPI(Squirrel *engine)
{ {
/* Create the AIInfo class, and add the RegisterAI function */ /* Create the AIInfo class, and add the RegisterAI function */
DefSQClass<AIInfo, ST_AI> SQAIInfo("AIInfo"); DefSQClass<AIInfo, ScriptType::AI> SQAIInfo("AIInfo");
SQAIInfo.PreRegister(engine); SQAIInfo.PreRegister(engine);
SQAIInfo.AddConstructor<void (AIInfo::*)(), 1>(engine, "x"); SQAIInfo.AddConstructor<void (AIInfo::*)(), 1>(engine, "x");
SQAIInfo.DefSQAdvancedMethod(engine, &AIInfo::AddSetting, "AddSetting"); SQAIInfo.DefSQAdvancedMethod(engine, &AIInfo::AddSetting, "AddSetting");

View File

@ -293,7 +293,7 @@ template <bool Tpal_to_rgb> Sprite *Blitter_32bppOptimized::EncodeInternal(const
ZoomLevel zoom_min; ZoomLevel zoom_min;
ZoomLevel zoom_max; ZoomLevel zoom_max;
if (sprite->type == ST_FONT) { if (sprite->type == SpriteType::Font) {
zoom_min = ZOOM_LVL_NORMAL; zoom_min = ZOOM_LVL_NORMAL;
zoom_max = ZOOM_LVL_NORMAL; zoom_max = ZOOM_LVL_NORMAL;
} else { } else {

View File

@ -28,7 +28,7 @@ Sprite *Blitter_32bppSSE_Base::Encode(const SpriteLoader::Sprite *sprite, Alloca
*/ */
ZoomLevel zoom_min = ZOOM_LVL_NORMAL; ZoomLevel zoom_min = ZOOM_LVL_NORMAL;
ZoomLevel zoom_max = ZOOM_LVL_NORMAL; ZoomLevel zoom_max = ZOOM_LVL_NORMAL;
if (sprite->type != ST_FONT) { if (sprite->type != SpriteType::Font) {
zoom_min = _settings_client.gui.zoom_min; zoom_min = _settings_client.gui.zoom_min;
zoom_max = _settings_client.gui.zoom_max; zoom_max = _settings_client.gui.zoom_max;
if (zoom_max == zoom_min) zoom_max = ZOOM_LVL_MAX; if (zoom_max == zoom_min) zoom_max = ZOOM_LVL_MAX;

View File

@ -354,7 +354,7 @@ void Blitter_40bppAnim::DrawColourMappingRect(void *dst, int width, int height,
anim = anim - width + _screen.pitch; anim = anim - width + _screen.pitch;
} while (--height); } while (--height);
} else if (pal == PALETTE_NEWSPAPER) { } else if (pal == PALETTE_NEWSPAPER) {
const uint8 *remap = GetNonSprite(pal, ST_RECOLOUR) + 1; const uint8 *remap = GetNonSprite(pal, SpriteType::Recolour) + 1;
do { do {
for (int i = 0; i != width; i++) { for (int i = 0; i != width; i++) {
if (*anim == 0) *udst = MakeGrey(*udst); if (*anim == 0) *udst = MakeGrey(*udst);
@ -366,7 +366,7 @@ void Blitter_40bppAnim::DrawColourMappingRect(void *dst, int width, int height,
anim = anim - width + _screen.pitch; anim = anim - width + _screen.pitch;
} while (--height); } while (--height);
} else { } else {
const uint8 *remap = GetNonSprite(pal, ST_RECOLOUR) + 1; const uint8 *remap = GetNonSprite(pal, SpriteType::Recolour) + 1;
do { do {
for (int i = 0; i != width; i++) { for (int i = 0; i != width; i++) {
*anim = remap[*anim]; *anim = remap[*anim];

View File

@ -16,7 +16,7 @@
void Blitter_8bppBase::DrawColourMappingRect(void *dst, int width, int height, PaletteID pal) void Blitter_8bppBase::DrawColourMappingRect(void *dst, int width, int height, PaletteID pal)
{ {
const uint8 *ctab = GetNonSprite(pal, ST_RECOLOUR) + 1; const uint8 *ctab = GetNonSprite(pal, SpriteType::Recolour) + 1;
do { do {
for (int i = 0; i != width; i++) *((uint8 *)dst + i) = ctab[((uint8 *)dst)[i]]; for (int i = 0; i != width; i++) *((uint8 *)dst + i) = ctab[((uint8 *)dst)[i]];

View File

@ -127,7 +127,7 @@ Sprite *Blitter_8bppOptimized::Encode(const SpriteLoader::Sprite *sprite, Alloca
ZoomLevel zoom_min; ZoomLevel zoom_min;
ZoomLevel zoom_max; ZoomLevel zoom_max;
if (sprite->type == ST_FONT) { if (sprite->type == SpriteType::Font) {
zoom_min = ZOOM_LVL_NORMAL; zoom_min = ZOOM_LVL_NORMAL;
zoom_max = ZOOM_LVL_NORMAL; zoom_max = ZOOM_LVL_NORMAL;
} else { } else {

View File

@ -144,10 +144,10 @@ public:
/** Types of cargo source and destination */ /** Types of cargo source and destination */
enum SourceType : byte { enum class SourceType : byte {
ST_INDUSTRY, ///< Source/destination is an industry Industry, ///< Source/destination is an industry
ST_TOWN, ///< Source/destination is a town Town, ///< Source/destination is a town
ST_HEADQUARTERS, ///< Source/destination are company headquarters Headquarters, ///< Source/destination are company headquarters
}; };
typedef uint16 SourceID; ///< Contains either industry ID, town ID or company ID (or INVALID_SOURCE) typedef uint16 SourceID; ///< Contains either industry ID, town ID or company ID (or INVALID_SOURCE)

View File

@ -124,13 +124,13 @@ void AddCargoDelivery(CargoID cargo_type, CompanyID company, uint32 amount, Sour
if (src != INVALID_SOURCE) { if (src != INVALID_SOURCE) {
/* Handle pickup update. */ /* Handle pickup update. */
switch (src_type) { switch (src_type) {
case ST_INDUSTRY: { case SourceType::Industry: {
CargoMonitorID num = EncodeCargoIndustryMonitor(company, cargo_type, src); CargoMonitorID num = EncodeCargoIndustryMonitor(company, cargo_type, src);
CargoMonitorMap::iterator iter = _cargo_pickups.find(num); CargoMonitorMap::iterator iter = _cargo_pickups.find(num);
if (iter != _cargo_pickups.end()) iter->second += amount; if (iter != _cargo_pickups.end()) iter->second += amount;
break; break;
} }
case ST_TOWN: { case SourceType::Town: {
CargoMonitorID num = EncodeCargoTownMonitor(company, cargo_type, src); CargoMonitorID num = EncodeCargoTownMonitor(company, cargo_type, src);
CargoMonitorMap::iterator iter = _cargo_pickups.find(num); CargoMonitorMap::iterator iter = _cargo_pickups.find(num);
if (iter != _cargo_pickups.end()) iter->second += amount; if (iter != _cargo_pickups.end()) iter->second += amount;

View File

@ -26,7 +26,7 @@ INSTANTIATE_POOL_METHODS(CargoPacket)
*/ */
CargoPacket::CargoPacket() CargoPacket::CargoPacket()
{ {
this->source_type = ST_INDUSTRY; this->source_type = SourceType::Industry;
this->source_id = INVALID_SOURCE; this->source_id = INVALID_SOURCE;
} }

View File

@ -66,7 +66,7 @@ public:
CargoPacket(); CargoPacket();
CargoPacket(StationID source, TileIndex source_xy, uint16 count, SourceType source_type, SourceID source_id); CargoPacket(StationID source, TileIndex source_xy, uint16 count, SourceType source_type, SourceID source_id);
CargoPacket(uint16 count, byte days_in_transit, StationID source, TileIndex source_xy, TileIndex loaded_at_xy, Money feeder_share = 0, SourceType source_type = ST_INDUSTRY, SourceID source_id = INVALID_SOURCE); CargoPacket(uint16 count, byte days_in_transit, StationID source, TileIndex source_xy, TileIndex loaded_at_xy, Money feeder_share = 0, SourceType source_type = SourceType::Industry, SourceID source_id = INVALID_SOURCE);
/** Destroy the packet. */ /** Destroy the packet. */
~CargoPacket() { } ~CargoPacket() { }

View File

@ -1087,7 +1087,7 @@ static uint DeliverGoodsToIndustry(const Station *st, CargoID cargo_type, uint n
accepted += amount; accepted += amount;
/* Update the cargo monitor. */ /* Update the cargo monitor. */
AddCargoDelivery(cargo_type, company, amount, ST_INDUSTRY, source, st, ind->index); AddCargoDelivery(cargo_type, company, amount, SourceType::Industry, source, st, ind->index);
} }
return accepted; return accepted;
@ -1113,7 +1113,7 @@ static Money DeliverGoods(int num_pieces, CargoID cargo_type, StationID dest, Ti
Station *st = Station::Get(dest); Station *st = Station::Get(dest);
/* Give the goods to the industry. */ /* Give the goods to the industry. */
uint accepted_ind = DeliverGoodsToIndustry(st, cargo_type, num_pieces, src_type == ST_INDUSTRY ? src : INVALID_INDUSTRY, company->index); uint accepted_ind = DeliverGoodsToIndustry(st, cargo_type, num_pieces, src_type == SourceType::Industry ? src : INVALID_INDUSTRY, company->index);
/* If this cargo type is always accepted, accept all */ /* If this cargo type is always accepted, accept all */
uint accepted_total = HasBit(st->always_accepted, cargo_type) ? num_pieces : accepted_ind; uint accepted_total = HasBit(st->always_accepted, cargo_type) ? num_pieces : accepted_ind;

View File

@ -241,7 +241,7 @@ const Sprite *FreeTypeFontCache::InternalGetGlyph(GlyphID key, bool aa)
/* FreeType has rendered the glyph, now we allocate a sprite and copy the image into it */ /* FreeType has rendered the glyph, now we allocate a sprite and copy the image into it */
SpriteLoader::Sprite sprite; SpriteLoader::Sprite sprite;
sprite.AllocateData(ZOOM_LVL_NORMAL, static_cast<size_t>(width) * height); sprite.AllocateData(ZOOM_LVL_NORMAL, static_cast<size_t>(width) * height);
sprite.type = ST_FONT; sprite.type = SpriteType::Font;
sprite.colours = (aa ? SCC_PAL | SCC_ALPHA : SCC_PAL); sprite.colours = (aa ? SCC_PAL | SCC_ALPHA : SCC_PAL);
sprite.width = width; sprite.width = width;
sprite.height = height; sprite.height = height;

View File

@ -113,14 +113,14 @@ const Sprite *SpriteFontCache::GetGlyph(GlyphID key)
{ {
SpriteID sprite = this->GetUnicodeGlyph(key); SpriteID sprite = this->GetUnicodeGlyph(key);
if (sprite == 0) sprite = this->GetUnicodeGlyph('?'); if (sprite == 0) sprite = this->GetUnicodeGlyph('?');
return GetSprite(sprite, ST_FONT); return GetSprite(sprite, SpriteType::Font);
} }
uint SpriteFontCache::GetGlyphWidth(GlyphID key) uint SpriteFontCache::GetGlyphWidth(GlyphID key)
{ {
SpriteID sprite = this->GetUnicodeGlyph(key); SpriteID sprite = this->GetUnicodeGlyph(key);
if (sprite == 0) sprite = this->GetUnicodeGlyph('?'); if (sprite == 0) sprite = this->GetUnicodeGlyph('?');
return SpriteExists(sprite) ? GetSprite(sprite, ST_FONT)->width + ScaleSpriteTrad(this->fs != FS_NORMAL ? 1 : 0) : 0; return SpriteExists(sprite) ? GetSprite(sprite, SpriteType::Font)->width + ScaleSpriteTrad(this->fs != FS_NORMAL ? 1 : 0) : 0;
} }
bool SpriteFontCache::GetDrawGlyphShadow() bool SpriteFontCache::GetDrawGlyphShadow()

View File

@ -141,7 +141,7 @@ const Sprite *TrueTypeFontCache::GetGlyph(GlyphID key)
8, // width 8, // width
0, // x_offs 0, // x_offs
0, // y_offs 0, // y_offs
ST_FONT, SpriteType::Font,
SCC_PAL, SCC_PAL,
builtin_questionmark_data builtin_questionmark_data
}; };

View File

@ -30,12 +30,12 @@ static bool CheckAPIVersion(const char *api_version)
#if defined(_WIN32) #if defined(_WIN32)
#undef GetClassName #undef GetClassName
#endif /* _WIN32 */ #endif /* _WIN32 */
template <> const char *GetClassName<GameInfo, ST_GS>() { return "GSInfo"; } template <> const char *GetClassName<GameInfo, ScriptType::GS>() { return "GSInfo"; }
/* static */ void GameInfo::RegisterAPI(Squirrel *engine) /* static */ void GameInfo::RegisterAPI(Squirrel *engine)
{ {
/* Create the GSInfo class, and add the RegisterGS function */ /* Create the GSInfo class, and add the RegisterGS function */
DefSQClass<GameInfo, ST_GS> SQGSInfo("GSInfo"); DefSQClass<GameInfo, ScriptType::GS> SQGSInfo("GSInfo");
SQGSInfo.PreRegister(engine); SQGSInfo.PreRegister(engine);
SQGSInfo.AddConstructor<void (GameInfo::*)(), 1>(engine, "x"); SQGSInfo.AddConstructor<void (GameInfo::*)(), 1>(engine, "x");
SQGSInfo.DefSQAdvancedMethod(engine, &GameInfo::AddSetting, "AddSetting"); SQGSInfo.DefSQAdvancedMethod(engine, &GameInfo::AddSetting, "AddSetting");

View File

@ -74,7 +74,7 @@ int _gui_scale_cfg; ///< GUI scale in config.
*/ */
static Rect _invalid_rect; static Rect _invalid_rect;
static const byte *_colour_remap_ptr; static const byte *_colour_remap_ptr;
static byte _string_colourremap[3]; ///< Recoloursprite for stringdrawing. The grf loader ensures that #ST_FONT sprites only use colours 0 to 2. static byte _string_colourremap[3]; ///< Recoloursprite for stringdrawing. The grf loader ensures that #SpriteType::Font sprites only use colours 0 to 2.
static const uint DIRTY_BLOCK_HEIGHT = 8; static const uint DIRTY_BLOCK_HEIGHT = 8;
static const uint DIRTY_BLOCK_WIDTH = 64; static const uint DIRTY_BLOCK_WIDTH = 64;
@ -992,7 +992,7 @@ void DrawCharCentered(WChar c, const Rect &r, TextColour colour)
*/ */
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom) Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
{ {
const Sprite *sprite = GetSprite(sprid, ST_NORMAL); const Sprite *sprite = GetSprite(sprid, SpriteType::Normal);
if (offset != nullptr) { if (offset != nullptr) {
offset->x = UnScaleByZoom(sprite->x_offs, zoom); offset->x = UnScaleByZoom(sprite->x_offs, zoom);
@ -1032,17 +1032,17 @@ void DrawSpriteViewport(SpriteID img, PaletteID pal, int x, int y, const SubSpri
{ {
SpriteID real_sprite = GB(img, 0, SPRITE_WIDTH); SpriteID real_sprite = GB(img, 0, SPRITE_WIDTH);
if (HasBit(img, PALETTE_MODIFIER_TRANSPARENT)) { if (HasBit(img, PALETTE_MODIFIER_TRANSPARENT)) {
_colour_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), ST_RECOLOUR) + 1; _colour_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), SpriteType::Recolour) + 1;
GfxMainBlitterViewport(GetSprite(real_sprite, ST_NORMAL), x, y, BM_TRANSPARENT, sub, real_sprite); GfxMainBlitterViewport(GetSprite(real_sprite, SpriteType::Normal), x, y, BM_TRANSPARENT, sub, real_sprite);
} else if (pal != PAL_NONE) { } else if (pal != PAL_NONE) {
if (HasBit(pal, PALETTE_TEXT_RECOLOUR)) { if (HasBit(pal, PALETTE_TEXT_RECOLOUR)) {
SetColourRemap((TextColour)GB(pal, 0, PALETTE_WIDTH)); SetColourRemap((TextColour)GB(pal, 0, PALETTE_WIDTH));
} else { } else {
_colour_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), ST_RECOLOUR) + 1; _colour_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), SpriteType::Recolour) + 1;
} }
GfxMainBlitterViewport(GetSprite(real_sprite, ST_NORMAL), x, y, GetBlitterMode(pal), sub, real_sprite); GfxMainBlitterViewport(GetSprite(real_sprite, SpriteType::Normal), x, y, GetBlitterMode(pal), sub, real_sprite);
} else { } else {
GfxMainBlitterViewport(GetSprite(real_sprite, ST_NORMAL), x, y, BM_NORMAL, sub, real_sprite); GfxMainBlitterViewport(GetSprite(real_sprite, SpriteType::Normal), x, y, BM_NORMAL, sub, real_sprite);
} }
} }
@ -1059,17 +1059,17 @@ void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub,
{ {
SpriteID real_sprite = GB(img, 0, SPRITE_WIDTH); SpriteID real_sprite = GB(img, 0, SPRITE_WIDTH);
if (HasBit(img, PALETTE_MODIFIER_TRANSPARENT)) { if (HasBit(img, PALETTE_MODIFIER_TRANSPARENT)) {
_colour_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), ST_RECOLOUR) + 1; _colour_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), SpriteType::Recolour) + 1;
GfxMainBlitter(GetSprite(real_sprite, ST_NORMAL), x, y, BM_TRANSPARENT, sub, real_sprite, zoom); GfxMainBlitter(GetSprite(real_sprite, SpriteType::Normal), x, y, BM_TRANSPARENT, sub, real_sprite, zoom);
} else if (pal != PAL_NONE) { } else if (pal != PAL_NONE) {
if (HasBit(pal, PALETTE_TEXT_RECOLOUR)) { if (HasBit(pal, PALETTE_TEXT_RECOLOUR)) {
SetColourRemap((TextColour)GB(pal, 0, PALETTE_WIDTH)); SetColourRemap((TextColour)GB(pal, 0, PALETTE_WIDTH));
} else { } else {
_colour_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), ST_RECOLOUR) + 1; _colour_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), SpriteType::Recolour) + 1;
} }
GfxMainBlitter(GetSprite(real_sprite, ST_NORMAL), x, y, GetBlitterMode(pal), sub, real_sprite, zoom); GfxMainBlitter(GetSprite(real_sprite, SpriteType::Normal), x, y, GetBlitterMode(pal), sub, real_sprite, zoom);
} else { } else {
GfxMainBlitter(GetSprite(real_sprite, ST_NORMAL), x, y, BM_NORMAL, sub, real_sprite, zoom); GfxMainBlitter(GetSprite(real_sprite, SpriteType::Normal), x, y, BM_NORMAL, sub, real_sprite, zoom);
} }
} }
@ -1220,7 +1220,7 @@ std::unique_ptr<uint32[]> DrawSpriteToRgbaBuffer(SpriteID spriteId, ZoomLevel zo
/* Gather information about the sprite to write, reserve memory */ /* Gather information about the sprite to write, reserve memory */
const SpriteID real_sprite = GB(spriteId, 0, SPRITE_WIDTH); const SpriteID real_sprite = GB(spriteId, 0, SPRITE_WIDTH);
const Sprite *sprite = GetSprite(real_sprite, ST_NORMAL); const Sprite *sprite = GetSprite(real_sprite, SpriteType::Normal);
Dimension dim = GetSpriteSize(real_sprite, nullptr, zoom); Dimension dim = GetSpriteSize(real_sprite, nullptr, zoom);
size_t dim_size = static_cast<size_t>(dim.width) * dim.height; size_t dim_size = static_cast<size_t>(dim.width) * dim.height;
std::unique_ptr<uint32[]> result(new uint32[dim_size]); std::unique_ptr<uint32[]> result(new uint32[dim_size]);
@ -1843,7 +1843,7 @@ void UpdateCursorSize()
static_assert(lengthof(_cursor.sprite_seq) == lengthof(_cursor.sprite_pos)); static_assert(lengthof(_cursor.sprite_seq) == lengthof(_cursor.sprite_pos));
assert(_cursor.sprite_count <= lengthof(_cursor.sprite_seq)); assert(_cursor.sprite_count <= lengthof(_cursor.sprite_seq));
for (uint i = 0; i < _cursor.sprite_count; ++i) { for (uint i = 0; i < _cursor.sprite_count; ++i) {
const Sprite *p = GetSprite(GB(_cursor.sprite_seq[i].sprite, 0, SPRITE_WIDTH), ST_NORMAL); const Sprite *p = GetSprite(GB(_cursor.sprite_seq[i].sprite, 0, SPRITE_WIDTH), SpriteType::Normal);
Point offs, size; Point offs, size;
offs.x = UnScaleGUI(p->x_offs) + _cursor.sprite_pos[i].x; offs.x = UnScaleGUI(p->x_offs) + _cursor.sprite_pos[i].x;
offs.y = UnScaleGUI(p->y_offs) + _cursor.sprite_pos[i].y; offs.y = UnScaleGUI(p->y_offs) + _cursor.sprite_pos[i].y;

View File

@ -305,12 +305,12 @@ enum PaletteType {
}; };
/** Types of sprites that might be loaded */ /** Types of sprites that might be loaded */
enum SpriteType : byte { enum class SpriteType : byte {
ST_NORMAL = 0, ///< The most basic (normal) sprite Normal = 0, ///< The most basic (normal) sprite
ST_MAPGEN = 1, ///< Special sprite for the map generator MapGen = 1, ///< Special sprite for the map generator
ST_FONT = 2, ///< A sprite used for fonts Font = 2, ///< A sprite used for fonts
ST_RECOLOUR = 3, ///< Recolour sprite Recolour = 3, ///< Recolour sprite
ST_INVALID = 4, ///< Pseudosprite or other unusable sprite, used only internally Invalid = 4, ///< Pseudosprite or other unusable sprite, used only internally
}; };
/** /**

View File

@ -197,8 +197,8 @@ Industry::~Industry()
CloseWindowById(WC_INDUSTRY_VIEW, this->index); CloseWindowById(WC_INDUSTRY_VIEW, this->index);
DeleteNewGRFInspectWindow(GSF_INDUSTRIES, this->index); DeleteNewGRFInspectWindow(GSF_INDUSTRIES, this->index);
DeleteSubsidyWith(ST_INDUSTRY, this->index); DeleteSubsidyWith(SourceType::Industry, this->index);
CargoPacket::InvalidateAllFrom(ST_INDUSTRY, this->index); CargoPacket::InvalidateAllFrom(SourceType::Industry, this->index);
for (Station *st : this->stations_near) { for (Station *st : this->stations_near) {
st->RemoveIndustryToDeliver(this); st->RemoveIndustryToDeliver(this);
@ -546,7 +546,7 @@ static bool TransportIndustryGoods(TileIndex tile)
i->this_month_production[j] += cw; i->this_month_production[j] += cw;
uint am = MoveGoodsToStation(i->produced_cargo[j], cw, ST_INDUSTRY, i->index, &i->stations_near, i->exclusive_consumer); uint am = MoveGoodsToStation(i->produced_cargo[j], cw, SourceType::Industry, i->index, &i->stations_near, i->exclusive_consumer);
i->this_month_transported[j] += am; i->this_month_transported[j] += am;
moved_cargo |= (am != 0); moved_cargo |= (am != 0);

View File

@ -817,7 +817,7 @@ static void GenerateTerrain(int type, uint flag)
uint32 r = Random(); uint32 r = Random();
/* Choose one of the templates from the graphics file. */ /* Choose one of the templates from the graphics file. */
const Sprite *templ = GetSprite((((r >> 24) * _genterrain_tbl_1[type]) >> 8) + _genterrain_tbl_2[type] + SPR_MAPGEN_BEGIN, ST_MAPGEN); const Sprite *templ = GetSprite((((r >> 24) * _genterrain_tbl_1[type]) >> 8) + _genterrain_tbl_2[type] + SPR_MAPGEN_BEGIN, SpriteType::MapGen);
if (templ == nullptr) usererror("Map generator sprites could not be loaded"); if (templ == nullptr) usererror("Map generator sprites could not be loaded");
/* Chose a random location to apply the template to. */ /* Chose a random location to apply the template to. */

View File

@ -546,7 +546,7 @@ void ShowSelectGameWindow();
void SetupColoursAndInitialWindow() void SetupColoursAndInitialWindow()
{ {
for (uint i = 0; i != 16; i++) { for (uint i = 0; i != 16; i++) {
const byte *b = GetNonSprite(PALETTE_RECOLOUR_START + i, ST_RECOLOUR); const byte *b = GetNonSprite(PALETTE_RECOLOUR_START + i, SpriteType::Recolour);
assert(b); assert(b);
memcpy(_colour_gradient[i], b + 0xC6, sizeof(_colour_gradient[i])); memcpy(_colour_gradient[i], b + 0xC6, sizeof(_colour_gradient[i]));

View File

@ -841,12 +841,12 @@ struct SpriteAlignerWindow : Window {
this->SetWidgetLoweredState(WID_SA_CROSSHAIR, SpriteAlignerWindow::crosshair); this->SetWidgetLoweredState(WID_SA_CROSSHAIR, SpriteAlignerWindow::crosshair);
/* Oh yes, we assume there is at least one normal sprite! */ /* Oh yes, we assume there is at least one normal sprite! */
while (GetSpriteType(this->current_sprite) != ST_NORMAL) this->current_sprite++; while (GetSpriteType(this->current_sprite) != SpriteType::Normal) this->current_sprite++;
} }
void SetStringParameters(int widget) const override void SetStringParameters(int widget) const override
{ {
const Sprite *spr = GetSprite(this->current_sprite, ST_NORMAL); const Sprite *spr = GetSprite(this->current_sprite, SpriteType::Normal);
switch (widget) { switch (widget) {
case WID_SA_CAPTION: case WID_SA_CAPTION:
SetDParam(0, this->current_sprite); SetDParam(0, this->current_sprite);
@ -901,7 +901,7 @@ struct SpriteAlignerWindow : Window {
switch (widget) { switch (widget) {
case WID_SA_SPRITE: { case WID_SA_SPRITE: {
/* Center the sprite ourselves */ /* Center the sprite ourselves */
const Sprite *spr = GetSprite(this->current_sprite, ST_NORMAL); const Sprite *spr = GetSprite(this->current_sprite, SpriteType::Normal);
Rect ir = r.Shrink(WidgetDimensions::scaled.bevel); Rect ir = r.Shrink(WidgetDimensions::scaled.bevel);
int x; int x;
int y; int y;
@ -949,7 +949,7 @@ struct SpriteAlignerWindow : Window {
case WID_SA_PREVIOUS: case WID_SA_PREVIOUS:
do { do {
this->current_sprite = (this->current_sprite == 0 ? GetMaxSpriteID() : this->current_sprite) - 1; this->current_sprite = (this->current_sprite == 0 ? GetMaxSpriteID() : this->current_sprite) - 1;
} while (GetSpriteType(this->current_sprite) != ST_NORMAL); } while (GetSpriteType(this->current_sprite) != SpriteType::Normal);
this->SetDirty(); this->SetDirty();
break; break;
@ -960,7 +960,7 @@ struct SpriteAlignerWindow : Window {
case WID_SA_NEXT: case WID_SA_NEXT:
do { do {
this->current_sprite = (this->current_sprite + 1) % GetMaxSpriteID(); this->current_sprite = (this->current_sprite + 1) % GetMaxSpriteID();
} while (GetSpriteType(this->current_sprite) != ST_NORMAL); } while (GetSpriteType(this->current_sprite) != SpriteType::Normal);
this->SetDirty(); this->SetDirty();
break; break;
@ -977,7 +977,7 @@ struct SpriteAlignerWindow : Window {
uint i = this->vscroll->GetPosition() + (pt.y - nwid->pos_y) / step_size; uint i = this->vscroll->GetPosition() + (pt.y - nwid->pos_y) / step_size;
if (i < _newgrf_debug_sprite_picker.sprites.size()) { if (i < _newgrf_debug_sprite_picker.sprites.size()) {
SpriteID spr = _newgrf_debug_sprite_picker.sprites[i]; SpriteID spr = _newgrf_debug_sprite_picker.sprites[i];
if (GetSpriteType(spr) == ST_NORMAL) this->current_sprite = spr; if (GetSpriteType(spr) == SpriteType::Normal) this->current_sprite = spr;
} }
this->SetDirty(); this->SetDirty();
break; break;
@ -1000,7 +1000,7 @@ struct SpriteAlignerWindow : Window {
* used by someone and the sprite cache isn't big enough for that * used by someone and the sprite cache isn't big enough for that
* particular NewGRF developer. * particular NewGRF developer.
*/ */
Sprite *spr = const_cast<Sprite *>(GetSprite(this->current_sprite, ST_NORMAL)); Sprite *spr = const_cast<Sprite *>(GetSprite(this->current_sprite, SpriteType::Normal));
/* Remember the original offsets of the current sprite, if not already in mapping. */ /* Remember the original offsets of the current sprite, if not already in mapping. */
if (!(this->offs_start_map.Contains(this->current_sprite))) { if (!(this->offs_start_map.Contains(this->current_sprite))) {
@ -1045,7 +1045,7 @@ struct SpriteAlignerWindow : Window {
this->current_sprite = atoi(str); this->current_sprite = atoi(str);
if (this->current_sprite >= GetMaxSpriteID()) this->current_sprite = 0; if (this->current_sprite >= GetMaxSpriteID()) this->current_sprite = 0;
while (GetSpriteType(this->current_sprite) != ST_NORMAL) { while (GetSpriteType(this->current_sprite) != SpriteType::Normal) {
this->current_sprite = (this->current_sprite + 1) % GetMaxSpriteID(); this->current_sprite = (this->current_sprite + 1) % GetMaxSpriteID();
} }
this->SetDirty(); this->SetDirty();

View File

@ -588,7 +588,7 @@ static CommandCost ClearTile_Object(TileIndex tile, DoCommandFlag flags)
if (flags & DC_EXEC) { if (flags & DC_EXEC) {
c->location_of_HQ = INVALID_TILE; // reset HQ position c->location_of_HQ = INVALID_TILE; // reset HQ position
SetWindowDirty(WC_COMPANY, c->index); SetWindowDirty(WC_COMPANY, c->index);
CargoPacket::InvalidateAllFrom(ST_HEADQUARTERS, c->index); CargoPacket::InvalidateAllFrom(SourceType::Headquarters, c->index);
} }
/* cost of relocating company is 1% of company value */ /* cost of relocating company is 1% of company value */
@ -686,7 +686,7 @@ static void TileLoop_Object(TileIndex tile)
if (GB(r, 0, 8) < (256 / 4 / (6 - level))) { if (GB(r, 0, 8) < (256 / 4 / (6 - level))) {
uint amt = GB(r, 0, 8) / 8 / 4 + 1; uint amt = GB(r, 0, 8) / 8 / 4 + 1;
if (EconomyIsInRecession()) amt = (amt + 1) >> 1; if (EconomyIsInRecession()) amt = (amt + 1) >> 1;
MoveGoodsToStation(CT_PASSENGERS, amt, ST_HEADQUARTERS, GetTileOwner(tile), stations.GetStations()); MoveGoodsToStation(CT_PASSENGERS, amt, SourceType::Headquarters, GetTileOwner(tile), stations.GetStations());
} }
/* Top town building generates 90, HQ can make up to 196. The /* Top town building generates 90, HQ can make up to 196. The
@ -695,7 +695,7 @@ static void TileLoop_Object(TileIndex tile)
if (GB(r, 8, 8) < (196 / 4 / (6 - level))) { if (GB(r, 8, 8) < (196 / 4 / (6 - level))) {
uint amt = GB(r, 8, 8) / 8 / 4 + 1; uint amt = GB(r, 8, 8) / 8 / 4 + 1;
if (EconomyIsInRecession()) amt = (amt + 1) >> 1; if (EconomyIsInRecession()) amt = (amt + 1) >> 1;
MoveGoodsToStation(CT_MAIL, amt, ST_HEADQUARTERS, GetTileOwner(tile), stations.GetStations()); MoveGoodsToStation(CT_MAIL, amt, SourceType::Headquarters, GetTileOwner(tile), stations.GetStations());
} }
} }

View File

@ -287,7 +287,7 @@ const Sprite *CoreTextFontCache::InternalGetGlyph(GlyphID key, bool use_aa)
SpriteLoader::Sprite sprite; SpriteLoader::Sprite sprite;
sprite.AllocateData(ZOOM_LVL_NORMAL, width * height); sprite.AllocateData(ZOOM_LVL_NORMAL, width * height);
sprite.type = ST_FONT; sprite.type = SpriteType::Font;
sprite.colours = (use_aa ? SCC_PAL | SCC_ALPHA : SCC_PAL); sprite.colours = (use_aa ? SCC_PAL | SCC_ALPHA : SCC_PAL);
sprite.width = width; sprite.width = width;
sprite.height = height; sprite.height = height;

View File

@ -456,7 +456,7 @@ void Win32FontCache::ClearFontCache()
/* GDI has rendered the glyph, now we allocate a sprite and copy the image into it. */ /* GDI has rendered the glyph, now we allocate a sprite and copy the image into it. */
SpriteLoader::Sprite sprite; SpriteLoader::Sprite sprite;
sprite.AllocateData(ZOOM_LVL_NORMAL, width * height); sprite.AllocateData(ZOOM_LVL_NORMAL, width * height);
sprite.type = ST_FONT; sprite.type = SpriteType::Font;
sprite.colours = (aa ? SCC_PAL | SCC_ALPHA : SCC_PAL); sprite.colours = (aa ? SCC_PAL | SCC_ALPHA : SCC_PAL);
sprite.width = width; sprite.width = width;
sprite.height = height; sprite.height = height;

View File

@ -2254,19 +2254,19 @@ bool AfterLoadGame()
case TE_PASSENGERS: case TE_PASSENGERS:
case TE_MAIL: case TE_MAIL:
/* Town -> Town */ /* Town -> Town */
s->src_type = s->dst_type = ST_TOWN; s->src_type = s->dst_type = SourceType::Town;
if (Town::IsValidID(s->src) && Town::IsValidID(s->dst)) continue; if (Town::IsValidID(s->src) && Town::IsValidID(s->dst)) continue;
break; break;
case TE_GOODS: case TE_GOODS:
case TE_FOOD: case TE_FOOD:
/* Industry -> Town */ /* Industry -> Town */
s->src_type = ST_INDUSTRY; s->src_type = SourceType::Industry;
s->dst_type = ST_TOWN; s->dst_type = SourceType::Town;
if (Industry::IsValidID(s->src) && Town::IsValidID(s->dst)) continue; if (Industry::IsValidID(s->src) && Town::IsValidID(s->dst)) continue;
break; break;
default: default:
/* Industry -> Industry */ /* Industry -> Industry */
s->src_type = s->dst_type = ST_INDUSTRY; s->src_type = s->dst_type = SourceType::Industry;
if (Industry::IsValidID(s->src) && Industry::IsValidID(s->dst)) continue; if (Industry::IsValidID(s->src) && Industry::IsValidID(s->dst)) continue;
break; break;
} }
@ -2284,7 +2284,7 @@ bool AfterLoadGame()
const Station *sd = Station::GetIfValid(s->dst); const Station *sd = Station::GetIfValid(s->dst);
if (ss != nullptr && sd != nullptr && ss->owner == sd->owner && if (ss != nullptr && sd != nullptr && ss->owner == sd->owner &&
Company::IsValidID(ss->owner)) { Company::IsValidID(ss->owner)) {
s->src_type = s->dst_type = ST_TOWN; s->src_type = s->dst_type = SourceType::Town;
s->src = ss->town->index; s->src = ss->town->index;
s->dst = sd->town->index; s->dst = sd->town->index;
s->awarded = ss->owner; s->awarded = ss->owner;

View File

@ -7,11 +7,11 @@
#include "../script_controller.hpp" #include "../script_controller.hpp"
template <> const char *GetClassName<ScriptController, ST_AI>() { return "AIController"; } template <> const char *GetClassName<ScriptController, ScriptType::AI>() { return "AIController"; }
void SQAIController_Register(Squirrel *engine) void SQAIController_Register(Squirrel *engine)
{ {
DefSQClass<ScriptController, ST_AI> SQAIController("AIController"); DefSQClass<ScriptController, ScriptType::AI> SQAIController("AIController");
SQAIController.PreRegister(engine); SQAIController.PreRegister(engine);
SQAIController.DefSQStaticMethod(engine, &ScriptController::GetTick, "GetTick", 1, "."); SQAIController.DefSQStaticMethod(engine, &ScriptController::GetTick, "GetTick", 1, ".");

View File

@ -7,11 +7,11 @@
#include "../script_controller.hpp" #include "../script_controller.hpp"
template <> const char *GetClassName<ScriptController, ST_GS>() { return "GSController"; } template <> const char *GetClassName<ScriptController, ScriptType::GS>() { return "GSController"; }
void SQGSController_Register(Squirrel *engine) void SQGSController_Register(Squirrel *engine)
{ {
DefSQClass<ScriptController, ST_GS> SQGSController("GSController"); DefSQClass<ScriptController, ScriptType::GS> SQGSController("GSController");
SQGSController.PreRegister(engine); SQGSController.PreRegister(engine);
SQGSController.DefSQStaticMethod(engine, &ScriptController::GetTick, "GetTick", 1, "."); SQGSController.DefSQStaticMethod(engine, &ScriptController::GetTick, "GetTick", 1, ".");

View File

@ -25,7 +25,7 @@ public:
*/ */
enum SubsidyParticipantType { enum SubsidyParticipantType {
/* Values are important, as they represent the internal state of the game. /* Values are important, as they represent the internal state of the game.
* It is originally named SourceType. ST_HEADQUARTERS is intentionally * It is originally named SourceType. SourceType::Headquarters is intentionally
* left out, as it cannot be used for Subsidies. */ * left out, as it cannot be used for Subsidies. */
SPT_INDUSTRY = 0, ///< Subsidy participant is an industry SPT_INDUSTRY = 0, ///< Subsidy participant is an industry
SPT_TOWN = 1, ///< Subsidy participant is a town SPT_TOWN = 1, ///< Subsidy participant is a town

View File

@ -13,9 +13,9 @@
#include <squirrel.h> #include <squirrel.h>
/** The type of script we're working with, i.e. for who is it? */ /** The type of script we're working with, i.e. for who is it? */
enum ScriptType { enum class ScriptType {
ST_AI, ///< The script is for AI scripts. AI, ///< The script is for AI scripts.
ST_GS, ///< The script is for Game scripts. GS, ///< The script is for Game scripts.
}; };
struct ScriptAllocator; struct ScriptAllocator;

View File

@ -119,7 +119,7 @@ void DrawCommonTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32 orig
Point pt = RemapCoords(dtss->delta_x, dtss->delta_y, dtss->delta_z); Point pt = RemapCoords(dtss->delta_x, dtss->delta_y, dtss->delta_z);
DrawSprite(image, pal, x + UnScaleGUI(pt.x), y + UnScaleGUI(pt.y)); DrawSprite(image, pal, x + UnScaleGUI(pt.x), y + UnScaleGUI(pt.y));
const Sprite *spr = GetSprite(image & SPRITE_MASK, ST_NORMAL); const Sprite *spr = GetSprite(image & SPRITE_MASK, SpriteType::Normal);
child_offset.x = UnScaleGUI(pt.x + spr->x_offs); child_offset.x = UnScaleGUI(pt.x + spr->x_offs);
child_offset.y = UnScaleGUI(pt.y + spr->y_offs); child_offset.y = UnScaleGUI(pt.y + spr->y_offs);
} else { } else {

View File

@ -162,7 +162,7 @@ bool SpriteExists(SpriteID id)
*/ */
SpriteType GetSpriteType(SpriteID sprite) SpriteType GetSpriteType(SpriteID sprite)
{ {
if (!SpriteExists(sprite)) return ST_INVALID; if (!SpriteExists(sprite)) return SpriteType::Invalid;
return GetSpriteCache(sprite)->type; return GetSpriteCache(sprite)->type;
} }
@ -461,8 +461,8 @@ static void *ReadSprite(const SpriteCache *sc, SpriteID id, SpriteType sprite_ty
SpriteFile &file = *sc->file; SpriteFile &file = *sc->file;
size_t file_pos = sc->file_pos; size_t file_pos = sc->file_pos;
assert(sprite_type != ST_RECOLOUR); assert(sprite_type != SpriteType::Recolour);
assert(IsMapgenSpriteID(id) == (sprite_type == ST_MAPGEN)); assert(IsMapgenSpriteID(id) == (sprite_type == SpriteType::MapGen));
assert(sc->type == sprite_type); assert(sc->type == sprite_type);
Debug(sprite, 9, "Load sprite {}", id); Debug(sprite, 9, "Load sprite {}", id);
@ -472,7 +472,7 @@ static void *ReadSprite(const SpriteCache *sc, SpriteID id, SpriteType sprite_ty
sprite[ZOOM_LVL_NORMAL].type = sprite_type; sprite[ZOOM_LVL_NORMAL].type = sprite_type;
SpriteLoaderGrf sprite_loader(file.GetContainerVersion()); SpriteLoaderGrf sprite_loader(file.GetContainerVersion());
if (sprite_type != ST_MAPGEN && encoder->Is32BppSupported()) { if (sprite_type != SpriteType::MapGen && encoder->Is32BppSupported()) {
/* Try for 32bpp sprites first. */ /* Try for 32bpp sprites first. */
sprite_avail = sprite_loader.LoadSprite(sprite, file, file_pos, sprite_type, true, sc->control_flags); sprite_avail = sprite_loader.LoadSprite(sprite, file, file_pos, sprite_type, true, sc->control_flags);
} }
@ -481,12 +481,12 @@ static void *ReadSprite(const SpriteCache *sc, SpriteID id, SpriteType sprite_ty
} }
if (sprite_avail == 0) { if (sprite_avail == 0) {
if (sprite_type == ST_MAPGEN) return nullptr; if (sprite_type == SpriteType::MapGen) return nullptr;
if (id == SPR_IMG_QUERY) usererror("Okay... something went horribly wrong. I couldn't load the fallback sprite. What should I do?"); if (id == SPR_IMG_QUERY) usererror("Okay... something went horribly wrong. I couldn't load the fallback sprite. What should I do?");
return (void*)GetRawSprite(SPR_IMG_QUERY, ST_NORMAL, allocator, encoder); return (void*)GetRawSprite(SPR_IMG_QUERY, SpriteType::Normal, allocator, encoder);
} }
if (sprite_type == ST_MAPGEN) { if (sprite_type == SpriteType::MapGen) {
/* Ugly hack to work around the problem that the old landscape /* Ugly hack to work around the problem that the old landscape
* generator assumes that those sprites are stored uncompressed in * generator assumes that those sprites are stored uncompressed in
* the memory, and they are only read directly by the code, never * the memory, and they are only read directly by the code, never
@ -516,10 +516,10 @@ static void *ReadSprite(const SpriteCache *sc, SpriteID id, SpriteType sprite_ty
if (!ResizeSprites(sprite, sprite_avail, encoder)) { if (!ResizeSprites(sprite, sprite_avail, encoder)) {
if (id == SPR_IMG_QUERY) usererror("Okay... something went horribly wrong. I couldn't resize the fallback sprite. What should I do?"); if (id == SPR_IMG_QUERY) usererror("Okay... something went horribly wrong. I couldn't resize the fallback sprite. What should I do?");
return (void*)GetRawSprite(SPR_IMG_QUERY, ST_NORMAL, allocator, encoder); return (void*)GetRawSprite(SPR_IMG_QUERY, SpriteType::Normal, allocator, encoder);
} }
if (sprite->type == ST_FONT && ZOOM_LVL_GUI != ZOOM_LVL_NORMAL) { if (sprite->type == SpriteType::Font && ZOOM_LVL_GUI != ZOOM_LVL_NORMAL) {
/* Make ZOOM_LVL_NORMAL be ZOOM_LVL_GUI */ /* Make ZOOM_LVL_NORMAL be ZOOM_LVL_GUI */
sprite[ZOOM_LVL_NORMAL].width = sprite[ZOOM_LVL_GUI].width; sprite[ZOOM_LVL_NORMAL].width = sprite[ZOOM_LVL_GUI].width;
sprite[ZOOM_LVL_NORMAL].height = sprite[ZOOM_LVL_GUI].height; sprite[ZOOM_LVL_NORMAL].height = sprite[ZOOM_LVL_GUI].height;
@ -629,7 +629,7 @@ bool LoadNextSprite(int load_index, SpriteFile &file, uint file_sprite_id)
file.ReadByte(); file.ReadByte();
return false; return false;
} }
type = ST_RECOLOUR; type = SpriteType::Recolour;
data = ReadRecolourSprite(file, num); data = ReadRecolourSprite(file, num);
} else if (file.GetContainerVersion() >= 2 && grf_type == 0xFD) { } else if (file.GetContainerVersion() >= 2 && grf_type == 0xFD) {
if (num != 4) { if (num != 4) {
@ -645,15 +645,15 @@ bool LoadNextSprite(int load_index, SpriteFile &file, uint file_sprite_id)
} else { } else {
file_pos = SIZE_MAX; file_pos = SIZE_MAX;
} }
type = ST_NORMAL; type = SpriteType::Normal;
} else { } else {
file.SkipBytes(7); file.SkipBytes(7);
type = SkipSpriteData(file, grf_type, num - 8) ? ST_NORMAL : ST_INVALID; type = SkipSpriteData(file, grf_type, num - 8) ? SpriteType::Normal : SpriteType::Invalid;
/* Inline sprites are not supported for container version >= 2. */ /* Inline sprites are not supported for container version >= 2. */
if (file.GetContainerVersion() >= 2) return false; if (file.GetContainerVersion() >= 2) return false;
} }
if (type == ST_INVALID) return false; if (type == SpriteType::Invalid) return false;
if (load_index >= MAX_SPRITES) { if (load_index >= MAX_SPRITES) {
usererror("Tried to load too many sprites (#%d; max %d)", load_index, MAX_SPRITES); usererror("Tried to load too many sprites (#%d; max %d)", load_index, MAX_SPRITES);
@ -662,8 +662,8 @@ bool LoadNextSprite(int load_index, SpriteFile &file, uint file_sprite_id)
bool is_mapgen = IsMapgenSpriteID(load_index); bool is_mapgen = IsMapgenSpriteID(load_index);
if (is_mapgen) { if (is_mapgen) {
if (type != ST_NORMAL) usererror("Uhm, would you be so kind not to load a NewGRF that changes the type of the map generator sprites?"); if (type != SpriteType::Normal) usererror("Uhm, would you be so kind not to load a NewGRF that changes the type of the map generator sprites?");
type = ST_MAPGEN; type = SpriteType::MapGen;
} }
SpriteCache *sc = AllocateSpriteCache(load_index); SpriteCache *sc = AllocateSpriteCache(load_index);
@ -828,7 +828,7 @@ static void DeleteEntryFromSpriteCache()
cur_lru = 0xffff; cur_lru = 0xffff;
for (SpriteID i = 0; i != _spritecache_items; i++) { for (SpriteID i = 0; i != _spritecache_items; i++) {
SpriteCache *sc = GetSpriteCache(i); SpriteCache *sc = GetSpriteCache(i);
if (sc->type != ST_RECOLOUR && sc->ptr != nullptr && sc->lru < cur_lru) { if (sc->type != SpriteType::Recolour && sc->ptr != nullptr && sc->lru < cur_lru) {
cur_lru = sc->lru; cur_lru = sc->lru;
best = i; best = i;
} }
@ -888,7 +888,7 @@ void *SimpleSpriteAlloc(size_t size)
/** /**
* Handles the case when a sprite of different type is requested than is present in the SpriteCache. * Handles the case when a sprite of different type is requested than is present in the SpriteCache.
* For ST_FONT sprites, it is normal. In other cases, default sprite is loaded instead. * For SpriteType::Font sprites, it is normal. In other cases, default sprite is loaded instead.
* @param sprite ID of loaded sprite * @param sprite ID of loaded sprite
* @param requested requested sprite type * @param requested requested sprite type
* @param sc the currently known sprite cache for the requested sprite * @param sc the currently known sprite cache for the requested sprite
@ -898,33 +898,33 @@ void *SimpleSpriteAlloc(size_t size)
static void *HandleInvalidSpriteRequest(SpriteID sprite, SpriteType requested, SpriteCache *sc, AllocatorProc *allocator) static void *HandleInvalidSpriteRequest(SpriteID sprite, SpriteType requested, SpriteCache *sc, AllocatorProc *allocator)
{ {
static const char * const sprite_types[] = { static const char * const sprite_types[] = {
"normal", // ST_NORMAL "normal", // SpriteType::Normal
"map generator", // ST_MAPGEN "map generator", // SpriteType::MapGen
"character", // ST_FONT "character", // SpriteType::Font
"recolour", // ST_RECOLOUR "recolour", // SpriteType::Recolour
}; };
SpriteType available = sc->type; SpriteType available = sc->type;
if (requested == ST_FONT && available == ST_NORMAL) { if (requested == SpriteType::Font && available == SpriteType::Normal) {
if (sc->ptr == nullptr) sc->type = ST_FONT; if (sc->ptr == nullptr) sc->type = SpriteType::Font;
return GetRawSprite(sprite, sc->type, allocator); return GetRawSprite(sprite, sc->type, allocator);
} }
byte warning_level = sc->warned ? 6 : 0; byte warning_level = sc->warned ? 6 : 0;
sc->warned = true; sc->warned = true;
Debug(sprite, warning_level, "Tried to load {} sprite #{} as a {} sprite. Probable cause: NewGRF interference", sprite_types[available], sprite, sprite_types[requested]); Debug(sprite, warning_level, "Tried to load {} sprite #{} as a {} sprite. Probable cause: NewGRF interference", sprite_types[static_cast<byte>(available)], sprite, sprite_types[static_cast<byte>(requested)]);
switch (requested) { switch (requested) {
case ST_NORMAL: case SpriteType::Normal:
if (sprite == SPR_IMG_QUERY) usererror("Uhm, would you be so kind not to load a NewGRF that makes the 'query' sprite a non-normal sprite?"); if (sprite == SPR_IMG_QUERY) usererror("Uhm, would you be so kind not to load a NewGRF that makes the 'query' sprite a non-normal sprite?");
FALLTHROUGH; FALLTHROUGH;
case ST_FONT: case SpriteType::Font:
return GetRawSprite(SPR_IMG_QUERY, ST_NORMAL, allocator); return GetRawSprite(SPR_IMG_QUERY, SpriteType::Normal, allocator);
case ST_RECOLOUR: case SpriteType::Recolour:
if (sprite == PALETTE_TO_DARK_BLUE) usererror("Uhm, would you be so kind not to load a NewGRF that makes the 'PALETTE_TO_DARK_BLUE' sprite a non-remap sprite?"); if (sprite == PALETTE_TO_DARK_BLUE) usererror("Uhm, would you be so kind not to load a NewGRF that makes the 'PALETTE_TO_DARK_BLUE' sprite a non-remap sprite?");
return GetRawSprite(PALETTE_TO_DARK_BLUE, ST_RECOLOUR, allocator); return GetRawSprite(PALETTE_TO_DARK_BLUE, SpriteType::Recolour, allocator);
case ST_MAPGEN: case SpriteType::MapGen:
/* this shouldn't happen, overriding of ST_MAPGEN sprites is checked in LoadNextSprite() /* this shouldn't happen, overriding of SpriteType::MapGen sprites is checked in LoadNextSprite()
* (the only case the check fails is when these sprites weren't even loaded...) */ * (the only case the check fails is when these sprites weren't even loaded...) */
default: default:
NOT_REACHED(); NOT_REACHED();
@ -942,8 +942,8 @@ static void *HandleInvalidSpriteRequest(SpriteID sprite, SpriteType requested, S
*/ */
void *GetRawSprite(SpriteID sprite, SpriteType type, AllocatorProc *allocator, SpriteEncoder *encoder) void *GetRawSprite(SpriteID sprite, SpriteType type, AllocatorProc *allocator, SpriteEncoder *encoder)
{ {
assert(type != ST_MAPGEN || IsMapgenSpriteID(sprite)); assert(type != SpriteType::MapGen || IsMapgenSpriteID(sprite));
assert(type < ST_INVALID); assert(type < SpriteType::Invalid);
if (!SpriteExists(sprite)) { if (!SpriteExists(sprite)) {
Debug(sprite, 1, "Tried to load non-existing sprite #{}. Probable cause: Wrong/missing NewGRFs", sprite); Debug(sprite, 1, "Tried to load non-existing sprite #{}. Probable cause: Wrong/missing NewGRFs", sprite);
@ -1042,7 +1042,7 @@ void GfxClearSpriteCache()
/* Clear sprite ptr for all cached items */ /* Clear sprite ptr for all cached items */
for (uint i = 0; i != _spritecache_items; i++) { for (uint i = 0; i != _spritecache_items; i++) {
SpriteCache *sc = GetSpriteCache(i); SpriteCache *sc = GetSpriteCache(i);
if (sc->type != ST_RECOLOUR && sc->ptr != nullptr) DeleteEntryFromSpriteCache(i); if (sc->type != SpriteType::Recolour && sc->ptr != nullptr) DeleteEntryFromSpriteCache(i);
} }
VideoDriver::GetInstance()->ClearSystemSprites(); VideoDriver::GetInstance()->ClearSystemSprites();

View File

@ -46,13 +46,13 @@ uint GetMaxSpriteID();
static inline const Sprite *GetSprite(SpriteID sprite, SpriteType type) static inline const Sprite *GetSprite(SpriteID sprite, SpriteType type)
{ {
assert(type != ST_RECOLOUR); assert(type != SpriteType::Recolour);
return (Sprite*)GetRawSprite(sprite, type); return (Sprite*)GetRawSprite(sprite, type);
} }
static inline const byte *GetNonSprite(SpriteID sprite, SpriteType type) static inline const byte *GetNonSprite(SpriteID sprite, SpriteType type)
{ {
assert(type == ST_RECOLOUR); assert(type == SpriteType::Recolour);
return (byte*)GetRawSprite(sprite, type); return (byte*)GetRawSprite(sprite, type);
} }

View File

@ -164,8 +164,8 @@ bool DecodeSingleSprite(SpriteLoader::Sprite *sprite, SpriteFile &file, size_t f
data->a = (colour_fmt & SCC_ALPHA) ? *dest++ : 0xFF; data->a = (colour_fmt & SCC_ALPHA) ? *dest++ : 0xFF;
if (colour_fmt & SCC_PAL) { if (colour_fmt & SCC_PAL) {
switch (sprite_type) { switch (sprite_type) {
case ST_NORMAL: data->m = file.NeedsPaletteRemap() ? _palmap_w2d[*dest] : *dest; break; case SpriteType::Normal: data->m = file.NeedsPaletteRemap() ? _palmap_w2d[*dest] : *dest; break;
case ST_FONT: data->m = std::min<uint>(*dest, 2u); break; case SpriteType::Font: data->m = std::min<uint>(*dest, 2u); break;
default: data->m = *dest; break; default: data->m = *dest; break;
} }
/* Magic blue. */ /* Magic blue. */
@ -201,8 +201,8 @@ bool DecodeSingleSprite(SpriteLoader::Sprite *sprite, SpriteFile &file, size_t f
sprite->data[i].a = (colour_fmt & SCC_ALPHA) ? *pixel++ : 0xFF; sprite->data[i].a = (colour_fmt & SCC_ALPHA) ? *pixel++ : 0xFF;
if (colour_fmt & SCC_PAL) { if (colour_fmt & SCC_PAL) {
switch (sprite_type) { switch (sprite_type) {
case ST_NORMAL: sprite->data[i].m = file.NeedsPaletteRemap() ? _palmap_w2d[*pixel] : *pixel; break; case SpriteType::Normal: sprite->data[i].m = file.NeedsPaletteRemap() ? _palmap_w2d[*pixel] : *pixel; break;
case ST_FONT: sprite->data[i].m = std::min<uint>(*pixel, 2u); break; case SpriteType::Font: sprite->data[i].m = std::min<uint>(*pixel, 2u); break;
default: sprite->data[i].m = *pixel; break; default: sprite->data[i].m = *pixel; break;
} }
/* Magic blue. */ /* Magic blue. */
@ -230,7 +230,7 @@ uint8 LoadSpriteV1(SpriteLoader::Sprite *sprite, SpriteFile &file, size_t file_p
/* Type 0xFF indicates either a colourmap or some other non-sprite info; we do not handle them here */ /* Type 0xFF indicates either a colourmap or some other non-sprite info; we do not handle them here */
if (type == 0xFF) return 0; if (type == 0xFF) return 0;
ZoomLevel zoom_lvl = (sprite_type != ST_MAPGEN) ? ZOOM_LVL_OUT_4X : ZOOM_LVL_NORMAL; ZoomLevel zoom_lvl = (sprite_type != SpriteType::MapGen) ? ZOOM_LVL_OUT_4X : ZOOM_LVL_NORMAL;
sprite[zoom_lvl].height = file.ReadByte(); sprite[zoom_lvl].height = file.ReadByte();
sprite[zoom_lvl].width = file.ReadWord(); sprite[zoom_lvl].width = file.ReadWord();
@ -279,7 +279,7 @@ uint8 LoadSpriteV2(SpriteLoader::Sprite *sprite, SpriteFile &file, size_t file_p
bool is_wanted_colour_depth = (colour != 0 && (load_32bpp ? colour != SCC_PAL : colour == SCC_PAL)); bool is_wanted_colour_depth = (colour != 0 && (load_32bpp ? colour != SCC_PAL : colour == SCC_PAL));
bool is_wanted_zoom_lvl; bool is_wanted_zoom_lvl;
if (sprite_type != ST_MAPGEN) { if (sprite_type != SpriteType::MapGen) {
if (zoom < lengthof(zoom_lvl_map)) { if (zoom < lengthof(zoom_lvl_map)) {
is_wanted_zoom_lvl = true; is_wanted_zoom_lvl = true;
if (_settings_client.gui.sprite_zoom_min >= ZOOM_LVL_OUT_2X && if (_settings_client.gui.sprite_zoom_min >= ZOOM_LVL_OUT_2X &&
@ -298,7 +298,7 @@ uint8 LoadSpriteV2(SpriteLoader::Sprite *sprite, SpriteFile &file, size_t file_p
} }
if (is_wanted_colour_depth && is_wanted_zoom_lvl) { if (is_wanted_colour_depth && is_wanted_zoom_lvl) {
ZoomLevel zoom_lvl = (sprite_type != ST_MAPGEN) ? zoom_lvl_map[zoom] : ZOOM_LVL_NORMAL; ZoomLevel zoom_lvl = (sprite_type != SpriteType::MapGen) ? zoom_lvl_map[zoom] : ZOOM_LVL_NORMAL;
if (HasBit(loaded_sprites, zoom_lvl)) { if (HasBit(loaded_sprites, zoom_lvl)) {
/* We already have this zoom level, skip sprite. */ /* We already have this zoom level, skip sprite. */

View File

@ -831,17 +831,17 @@ enum SortOrder {
class CargoDataEntry; class CargoDataEntry;
enum CargoSortType { enum class CargoSortType : byte {
ST_AS_GROUPING, ///< by the same principle the entries are being grouped AsGrouping, ///< by the same principle the entries are being grouped
ST_COUNT, ///< by amount of cargo Count, ///< by amount of cargo
ST_STATION_STRING, ///< by station name StationString, ///< by station name
ST_STATION_ID, ///< by station id StationID, ///< by station id
ST_CARGO_ID, ///< by cargo id CargoID, ///< by cargo id
}; };
class CargoSorter { class CargoSorter {
public: public:
CargoSorter(CargoSortType t = ST_STATION_ID, SortOrder o = SO_ASCENDING) : type(t), order(o) {} CargoSorter(CargoSortType t = CargoSortType::StationID, SortOrder o = SO_ASCENDING) : type(t), order(o) {}
CargoSortType GetSortType() {return this->type;} CargoSortType GetSortType() {return this->type;}
bool operator()(const CargoDataEntry *cd1, const CargoDataEntry *cd2) const; bool operator()(const CargoDataEntry *cd1, const CargoDataEntry *cd2) const;
@ -1012,7 +1012,7 @@ CargoDataEntry::CargoDataEntry() :
station(INVALID_STATION), station(INVALID_STATION),
num_children(0), num_children(0),
count(0), count(0),
children(new CargoDataSet(CargoSorter(ST_CARGO_ID))) children(new CargoDataSet(CargoSorter(CargoSortType::CargoID)))
{} {}
CargoDataEntry::CargoDataEntry(CargoID cargo, uint count, CargoDataEntry *parent) : CargoDataEntry::CargoDataEntry(CargoID cargo, uint count, CargoDataEntry *parent) :
@ -1101,7 +1101,7 @@ CargoDataEntry *CargoDataEntry::InsertOrRetrieve(Tid child_id)
return *(this->children->insert(new CargoDataEntry(child_id, 0, this)).first); return *(this->children->insert(new CargoDataEntry(child_id, 0, this)).first);
} else { } else {
CargoDataEntry *ret = *i; CargoDataEntry *ret = *i;
assert(this->children->value_comp().GetSortType() != ST_COUNT); assert(this->children->value_comp().GetSortType() != CargoSortType::Count);
return ret; return ret;
} }
} }
@ -1138,7 +1138,7 @@ CargoDataEntry *CargoDataEntry::Retrieve(CargoDataSet::iterator i) const
if (i == this->children->end()) { if (i == this->children->end()) {
return nullptr; return nullptr;
} else { } else {
assert(this->children->value_comp().GetSortType() != ST_COUNT); assert(this->children->value_comp().GetSortType() != CargoSortType::Count);
return *i; return *i;
} }
} }
@ -1146,13 +1146,13 @@ CargoDataEntry *CargoDataEntry::Retrieve(CargoDataSet::iterator i) const
bool CargoSorter::operator()(const CargoDataEntry *cd1, const CargoDataEntry *cd2) const bool CargoSorter::operator()(const CargoDataEntry *cd1, const CargoDataEntry *cd2) const
{ {
switch (this->type) { switch (this->type) {
case ST_STATION_ID: case CargoSortType::StationID:
return this->SortId<StationID>(cd1->GetStation(), cd2->GetStation()); return this->SortId<StationID>(cd1->GetStation(), cd2->GetStation());
case ST_CARGO_ID: case CargoSortType::CargoID:
return this->SortId<CargoID>(cd1->GetCargo(), cd2->GetCargo()); return this->SortId<CargoID>(cd1->GetCargo(), cd2->GetCargo());
case ST_COUNT: case CargoSortType::Count:
return this->SortCount(cd1, cd2); return this->SortCount(cd1, cd2);
case ST_STATION_STRING: case CargoSortType::StationString:
return this->SortStation(cd1->GetStation(), cd2->GetStation()); return this->SortStation(cd1->GetStation(), cd2->GetStation());
default: default:
NOT_REACHED(); NOT_REACHED();
@ -1268,7 +1268,7 @@ struct StationViewWindow : public Window {
/** /**
* Sort types of the different 'columns'. * Sort types of the different 'columns'.
* In fact only ST_COUNT and ST_AS_GROUPING are active and you can only * In fact only CargoSortType::Count and CargoSortType::AsGrouping are active and you can only
* sort all the columns in the same way. The other options haven't been * sort all the columns in the same way. The other options haven't been
* included in the GUI due to lack of space. * included in the GUI due to lack of space.
*/ */
@ -1298,7 +1298,7 @@ struct StationViewWindow : public Window {
this->FinishInitNested(window_number); this->FinishInitNested(window_number);
this->groupings[0] = GR_CARGO; this->groupings[0] = GR_CARGO;
this->sortings[0] = ST_AS_GROUPING; this->sortings[0] = CargoSortType::AsGrouping;
this->SelectGroupBy(_settings_client.gui.station_gui_group_order); this->SelectGroupBy(_settings_client.gui.station_gui_group_order);
this->SelectSortBy(_settings_client.gui.station_gui_sort_by); this->SelectSortBy(_settings_client.gui.station_gui_sort_by);
this->sort_orders[0] = SO_ASCENDING; this->sort_orders[0] = SO_ASCENDING;
@ -1715,12 +1715,12 @@ struct StationViewWindow : public Window {
*/ */
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 = CT_INVALID)
{ {
if (this->sortings[column] == ST_AS_GROUPING) { if (this->sortings[column] == CargoSortType::AsGrouping) {
if (this->groupings[column] != GR_CARGO) { if (this->groupings[column] != GR_CARGO) {
entry->Resort(ST_STATION_STRING, this->sort_orders[column]); entry->Resort(CargoSortType::StationString, this->sort_orders[column]);
} }
} else { } else {
entry->Resort(ST_COUNT, this->sort_orders[column]); entry->Resort(CargoSortType::Count, this->sort_orders[column]);
} }
for (CargoDataSet::iterator i = entry->Begin(); i != entry->End(); ++i) { for (CargoDataSet::iterator i = entry->Begin(); i != entry->End(); ++i) {
CargoDataEntry *cd = *i; CargoDataEntry *cd = *i;
@ -1940,7 +1940,7 @@ struct StationViewWindow : public Window {
* sorted by cargo ID. The others can theoretically be sorted * sorted by cargo ID. The others can theoretically be sorted
* by different things but there is no UI for that. */ * by different things but there is no UI for that. */
ShowDropDownMenu(this, _sort_names, ShowDropDownMenu(this, _sort_names,
this->current_mode * 2 + (this->sortings[1] == ST_COUNT ? 1 : 0), this->current_mode * 2 + (this->sortings[1] == CargoSortType::Count ? 1 : 0),
WID_SV_SORT_BY, 0, 0); WID_SV_SORT_BY, 0, 0);
break; break;
} }
@ -1980,19 +1980,19 @@ struct StationViewWindow : public Window {
switch (_sort_names[index]) { switch (_sort_names[index]) {
case STR_STATION_VIEW_WAITING_STATION: case STR_STATION_VIEW_WAITING_STATION:
this->current_mode = MODE_WAITING; this->current_mode = MODE_WAITING;
this->sortings[1] = this->sortings[2] = this->sortings[3] = ST_AS_GROUPING; this->sortings[1] = this->sortings[2] = this->sortings[3] = CargoSortType::AsGrouping;
break; break;
case STR_STATION_VIEW_WAITING_AMOUNT: case STR_STATION_VIEW_WAITING_AMOUNT:
this->current_mode = MODE_WAITING; this->current_mode = MODE_WAITING;
this->sortings[1] = this->sortings[2] = this->sortings[3] = ST_COUNT; this->sortings[1] = this->sortings[2] = this->sortings[3] = CargoSortType::Count;
break; break;
case STR_STATION_VIEW_PLANNED_STATION: case STR_STATION_VIEW_PLANNED_STATION:
this->current_mode = MODE_PLANNED; this->current_mode = MODE_PLANNED;
this->sortings[1] = this->sortings[2] = this->sortings[3] = ST_AS_GROUPING; this->sortings[1] = this->sortings[2] = this->sortings[3] = CargoSortType::AsGrouping;
break; break;
case STR_STATION_VIEW_PLANNED_AMOUNT: case STR_STATION_VIEW_PLANNED_AMOUNT:
this->current_mode = MODE_PLANNED; this->current_mode = MODE_PLANNED;
this->sortings[1] = this->sortings[2] = this->sortings[3] = ST_COUNT; this->sortings[1] = this->sortings[2] = this->sortings[3] = CargoSortType::Count;
break; break;
default: default:
NOT_REACHED(); NOT_REACHED();

View File

@ -82,11 +82,11 @@ std::pair<NewsReferenceType, NewsReferenceType> SetupSubsidyDecodeParam(const Su
SetDParam(parameter_offset, cs->name); SetDParam(parameter_offset, cs->name);
switch (s->src_type) { switch (s->src_type) {
case ST_INDUSTRY: case SourceType::Industry:
reftype1 = NR_INDUSTRY; reftype1 = NR_INDUSTRY;
SetDParam(parameter_offset + 1, STR_INDUSTRY_NAME); SetDParam(parameter_offset + 1, STR_INDUSTRY_NAME);
break; break;
case ST_TOWN: case SourceType::Town:
reftype1 = NR_TOWN; reftype1 = NR_TOWN;
SetDParam(parameter_offset + 1, STR_TOWN_NAME); SetDParam(parameter_offset + 1, STR_TOWN_NAME);
break; break;
@ -95,11 +95,11 @@ std::pair<NewsReferenceType, NewsReferenceType> SetupSubsidyDecodeParam(const Su
SetDParam(parameter_offset + 2, s->src); SetDParam(parameter_offset + 2, s->src);
switch (s->dst_type) { switch (s->dst_type) {
case ST_INDUSTRY: case SourceType::Industry:
reftype2 = NR_INDUSTRY; reftype2 = NR_INDUSTRY;
SetDParam(parameter_offset + 4, STR_INDUSTRY_NAME); SetDParam(parameter_offset + 4, STR_INDUSTRY_NAME);
break; break;
case ST_TOWN: case SourceType::Town:
reftype2 = NR_TOWN; reftype2 = NR_TOWN;
SetDParam(parameter_offset + 4, STR_TOWN_NAME); SetDParam(parameter_offset + 4, STR_TOWN_NAME);
break; break;
@ -124,8 +124,8 @@ std::pair<NewsReferenceType, NewsReferenceType> SetupSubsidyDecodeParam(const Su
static inline void SetPartOfSubsidyFlag(SourceType type, SourceID index, PartOfSubsidy flag) static inline void SetPartOfSubsidyFlag(SourceType type, SourceID index, PartOfSubsidy flag)
{ {
switch (type) { switch (type) {
case ST_INDUSTRY: Industry::Get(index)->part_of_subsidy |= flag; return; case SourceType::Industry: Industry::Get(index)->part_of_subsidy |= flag; return;
case ST_TOWN: Town::Get(index)->cache.part_of_subsidy |= flag; return; case SourceType::Town: Town::Get(index)->cache.part_of_subsidy |= flag; return;
default: NOT_REACHED(); default: NOT_REACHED();
} }
} }
@ -196,8 +196,8 @@ static bool CheckSubsidyDuplicate(CargoID cargo, SourceType src_type, SourceID s
*/ */
static bool CheckSubsidyDistance(SourceType src_type, SourceID src, SourceType dst_type, SourceID dst) static bool CheckSubsidyDistance(SourceType src_type, SourceID src, SourceType dst_type, SourceID dst)
{ {
TileIndex tile_src = (src_type == ST_TOWN) ? Town::Get(src)->xy : Industry::Get(src)->location.tile; TileIndex tile_src = (src_type == SourceType::Town) ? Town::Get(src)->xy : Industry::Get(src)->location.tile;
TileIndex tile_dst = (dst_type == ST_TOWN) ? Town::Get(dst)->xy : Industry::Get(dst)->location.tile; TileIndex tile_dst = (dst_type == SourceType::Town) ? Town::Get(dst)->xy : Industry::Get(dst)->location.tile;
return (DistanceManhattan(tile_src, tile_dst) <= SUBSIDY_MAX_DISTANCE); return (DistanceManhattan(tile_src, tile_dst) <= SUBSIDY_MAX_DISTANCE);
} }
@ -250,20 +250,20 @@ CommandCost CmdCreateSubsidy(DoCommandFlag flags, CargoID cid, SourceType src_ty
if (cid >= NUM_CARGO || !::CargoSpec::Get(cid)->IsValid()) return CMD_ERROR; if (cid >= NUM_CARGO || !::CargoSpec::Get(cid)->IsValid()) return CMD_ERROR;
switch (src_type) { switch (src_type) {
case ST_TOWN: case SourceType::Town:
if (!Town::IsValidID(src)) return CMD_ERROR; if (!Town::IsValidID(src)) return CMD_ERROR;
break; break;
case ST_INDUSTRY: case SourceType::Industry:
if (!Industry::IsValidID(src)) return CMD_ERROR; if (!Industry::IsValidID(src)) return CMD_ERROR;
break; break;
default: default:
return CMD_ERROR; return CMD_ERROR;
} }
switch (dst_type) { switch (dst_type) {
case ST_TOWN: case SourceType::Town:
if (!Town::IsValidID(dst)) return CMD_ERROR; if (!Town::IsValidID(dst)) return CMD_ERROR;
break; break;
case ST_INDUSTRY: case SourceType::Industry:
if (!Industry::IsValidID(dst)) return CMD_ERROR; if (!Industry::IsValidID(dst)) return CMD_ERROR;
break; break;
default: default:
@ -297,9 +297,9 @@ bool FindSubsidyPassengerRoute()
} }
if (DistanceManhattan(src->xy, dst->xy) > SUBSIDY_MAX_DISTANCE) return false; if (DistanceManhattan(src->xy, dst->xy) > SUBSIDY_MAX_DISTANCE) return false;
if (CheckSubsidyDuplicate(CT_PASSENGERS, ST_TOWN, src->index, ST_TOWN, dst->index)) return false; if (CheckSubsidyDuplicate(CT_PASSENGERS, SourceType::Town, src->index, SourceType::Town, dst->index)) return false;
CreateSubsidy(CT_PASSENGERS, ST_TOWN, src->index, ST_TOWN, dst->index); CreateSubsidy(CT_PASSENGERS, SourceType::Town, src->index, SourceType::Town, dst->index);
return true; return true;
} }
@ -315,7 +315,7 @@ bool FindSubsidyTownCargoRoute()
{ {
if (!Subsidy::CanAllocateItem()) return false; if (!Subsidy::CanAllocateItem()) return false;
SourceType src_type = ST_TOWN; SourceType src_type = SourceType::Town;
/* Select a random town. */ /* Select a random town. */
const Town *src_town = Town::GetRandom(); const Town *src_town = Town::GetRandom();
@ -373,7 +373,7 @@ bool FindSubsidyIndustryCargoRoute()
{ {
if (!Subsidy::CanAllocateItem()) return false; if (!Subsidy::CanAllocateItem()) return false;
SourceType src_type = ST_INDUSTRY; SourceType src_type = SourceType::Industry;
/* Select a random industry. */ /* Select a random industry. */
const Industry *src_ind = Industry::GetRandom(); const Industry *src_ind = Industry::GetRandom();
@ -424,11 +424,11 @@ bool FindSubsidyIndustryCargoRoute()
bool FindSubsidyCargoDestination(CargoID cid, SourceType src_type, SourceID src) bool FindSubsidyCargoDestination(CargoID cid, SourceType src_type, SourceID src)
{ {
/* Choose a random destination. */ /* Choose a random destination. */
SourceType dst_type = Chance16(1, 2) ? ST_TOWN : ST_INDUSTRY; SourceType dst_type = Chance16(1, 2) ? SourceType::Town : SourceType::Industry;
SourceID dst; SourceID dst;
switch (dst_type) { switch (dst_type) {
case ST_TOWN: { case SourceType::Town: {
/* Select a random town. */ /* Select a random town. */
const Town *dst_town = Town::GetRandom(); const Town *dst_town = Town::GetRandom();
@ -448,7 +448,7 @@ bool FindSubsidyCargoDestination(CargoID cid, SourceType src_type, SourceID src)
break; break;
} }
case ST_INDUSTRY: { case SourceType::Industry: {
/* Select a random industry. */ /* Select a random industry. */
const Industry *dst_ind = Industry::GetRandom(); const Industry *dst_ind = Industry::GetRandom();
if (dst_ind == nullptr) return false; if (dst_ind == nullptr) return false;
@ -565,10 +565,10 @@ bool CheckSubsidised(CargoID cargo_type, CompanyID company, SourceType src_type,
/* If the source isn't subsidised, don't continue */ /* If the source isn't subsidised, don't continue */
if (src == INVALID_SOURCE) return false; if (src == INVALID_SOURCE) return false;
switch (src_type) { switch (src_type) {
case ST_INDUSTRY: case SourceType::Industry:
if (!(Industry::Get(src)->part_of_subsidy & POS_SRC)) return false; if (!(Industry::Get(src)->part_of_subsidy & POS_SRC)) return false;
break; break;
case ST_TOWN: case SourceType::Town:
if (!(Town::Get(src)->cache.part_of_subsidy & POS_SRC)) return false; if (!(Town::Get(src)->cache.part_of_subsidy & POS_SRC)) return false;
break; break;
default: return false; default: return false;
@ -580,7 +580,7 @@ bool CheckSubsidised(CargoID cargo_type, CompanyID company, SourceType src_type,
if (!st->rect.IsEmpty()) { if (!st->rect.IsEmpty()) {
for (const Subsidy *s : Subsidy::Iterate()) { for (const Subsidy *s : Subsidy::Iterate()) {
/* Don't create the cache if there is no applicable subsidy with town as destination */ /* Don't create the cache if there is no applicable subsidy with town as destination */
if (s->dst_type != ST_TOWN) continue; if (s->dst_type != SourceType::Town) continue;
if (s->cargo_type != cargo_type || s->src_type != src_type || s->src != src) continue; if (s->cargo_type != cargo_type || s->src_type != src_type || s->src != src) continue;
if (s->IsAwarded() && s->awarded != company) continue; if (s->IsAwarded() && s->awarded != company) continue;
@ -601,7 +601,7 @@ bool CheckSubsidised(CargoID cargo_type, CompanyID company, SourceType src_type,
for (Subsidy *s : Subsidy::Iterate()) { for (Subsidy *s : Subsidy::Iterate()) {
if (s->cargo_type == cargo_type && s->src_type == src_type && s->src == src && (!s->IsAwarded() || s->awarded == company)) { if (s->cargo_type == cargo_type && s->src_type == src_type && s->src == src && (!s->IsAwarded() || s->awarded == company)) {
switch (s->dst_type) { switch (s->dst_type) {
case ST_INDUSTRY: case SourceType::Industry:
for (const auto &i : st->industries_near) { for (const auto &i : st->industries_near) {
if (s->dst == i.industry->index) { if (s->dst == i.industry->index) {
assert(i.industry->part_of_subsidy & POS_DST); assert(i.industry->part_of_subsidy & POS_DST);
@ -610,7 +610,7 @@ bool CheckSubsidised(CargoID cargo_type, CompanyID company, SourceType src_type,
} }
} }
break; break;
case ST_TOWN: case SourceType::Town:
for (const Town *tp : towns_near) { for (const Town *tp : towns_near) {
if (s->dst == tp->index) { if (s->dst == tp->index) {
assert(tp->cache.part_of_subsidy & POS_DST); assert(tp->cache.part_of_subsidy & POS_DST);

View File

@ -23,8 +23,8 @@ 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, CT_INVALID for invalid subsidy
uint16 remaining; ///< Remaining months when this subsidy is valid uint16 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 CompanyID awarded; ///< Subsidy is awarded to this company; INVALID_COMPANY if it's not awarded to anyone
SourceType src_type; ///< Source of subsidised path (ST_INDUSTRY or ST_TOWN) SourceType src_type; ///< Source of subsidised path (SourceType::Industry or SourceType::Town)
SourceType dst_type; ///< Destination of subsidised path (ST_INDUSTRY or ST_TOWN) SourceType dst_type; ///< Destination of subsidised path (SourceType::Industry or SourceType::Town)
SourceID src; ///< Index of source. Either TownID or IndustryID SourceID src; ///< Index of source. Either TownID or IndustryID
SourceID dst; ///< Index of destination. Either TownID or IndustryID SourceID dst; ///< Index of destination. Either TownID or IndustryID

View File

@ -77,8 +77,8 @@ struct SubsidyListWindow : Window {
/* determine src coordinate for subsidy and try to scroll to it */ /* determine src coordinate for subsidy and try to scroll to it */
TileIndex xy; TileIndex xy;
switch (s->src_type) { switch (s->src_type) {
case ST_INDUSTRY: xy = Industry::Get(s->src)->location.tile; break; case SourceType::Industry: xy = Industry::Get(s->src)->location.tile; break;
case ST_TOWN: xy = Town::Get(s->src)->xy; break; case SourceType::Town: xy = Town::Get(s->src)->xy; break;
default: NOT_REACHED(); default: NOT_REACHED();
} }
@ -87,8 +87,8 @@ struct SubsidyListWindow : Window {
/* otherwise determine dst coordinate for subsidy and scroll to it */ /* otherwise determine dst coordinate for subsidy and scroll to it */
switch (s->dst_type) { switch (s->dst_type) {
case ST_INDUSTRY: xy = Industry::Get(s->dst)->location.tile; break; case SourceType::Industry: xy = Industry::Get(s->dst)->location.tile; break;
case ST_TOWN: xy = Town::Get(s->dst)->xy; break; case SourceType::Town: xy = Town::Get(s->dst)->xy; break;
default: NOT_REACHED(); default: NOT_REACHED();
} }

View File

@ -145,9 +145,9 @@ Town::~Town()
/* Clear the persistent storage list. */ /* Clear the persistent storage list. */
this->psa_list.clear(); this->psa_list.clear();
DeleteSubsidyWith(ST_TOWN, this->index); DeleteSubsidyWith(SourceType::Town, this->index);
DeleteNewGRFInspectWindow(GSF_FAKE_TOWNS, this->index); DeleteNewGRFInspectWindow(GSF_FAKE_TOWNS, this->index);
CargoPacket::InvalidateAllFrom(ST_TOWN, this->index); CargoPacket::InvalidateAllFrom(SourceType::Town, this->index);
MarkWholeScreenDirty(); MarkWholeScreenDirty();
} }
@ -566,7 +566,7 @@ static void TileLoop_Town(TileIndex tile)
uint amt = GB(callback, 0, 8); uint amt = GB(callback, 0, 8);
if (amt == 0) continue; if (amt == 0) continue;
uint moved = MoveGoodsToStation(cargo, amt, ST_TOWN, t->index, stations.GetStations()); uint moved = MoveGoodsToStation(cargo, amt, SourceType::Town, t->index, stations.GetStations());
const CargoSpec *cs = CargoSpec::Get(cargo); const CargoSpec *cs = CargoSpec::Get(cargo);
t->supplied[cs->Index()].new_max += amt; t->supplied[cs->Index()].new_max += amt;
@ -581,7 +581,7 @@ static void TileLoop_Town(TileIndex tile)
if (EconomyIsInRecession()) amt = (amt + 1) >> 1; if (EconomyIsInRecession()) amt = (amt + 1) >> 1;
t->supplied[CT_PASSENGERS].new_max += amt; t->supplied[CT_PASSENGERS].new_max += amt;
t->supplied[CT_PASSENGERS].new_act += MoveGoodsToStation(CT_PASSENGERS, amt, ST_TOWN, t->index, stations.GetStations()); t->supplied[CT_PASSENGERS].new_act += MoveGoodsToStation(CT_PASSENGERS, amt, SourceType::Town, t->index, stations.GetStations());
} }
if (GB(r, 8, 8) < hs->mail_generation) { if (GB(r, 8, 8) < hs->mail_generation) {
@ -589,7 +589,7 @@ static void TileLoop_Town(TileIndex tile)
if (EconomyIsInRecession()) amt = (amt + 1) >> 1; if (EconomyIsInRecession()) amt = (amt + 1) >> 1;
t->supplied[CT_MAIL].new_max += amt; t->supplied[CT_MAIL].new_max += amt;
t->supplied[CT_MAIL].new_act += MoveGoodsToStation(CT_MAIL, amt, ST_TOWN, t->index, stations.GetStations()); t->supplied[CT_MAIL].new_act += MoveGoodsToStation(CT_MAIL, amt, SourceType::Town, t->index, stations.GetStations());
} }
break; break;
@ -606,7 +606,7 @@ static void TileLoop_Town(TileIndex tile)
/* Adjust and apply */ /* Adjust and apply */
if (EconomyIsInRecession()) amt = (amt + 1) >> 1; if (EconomyIsInRecession()) amt = (amt + 1) >> 1;
t->supplied[CT_PASSENGERS].new_max += amt; t->supplied[CT_PASSENGERS].new_max += amt;
t->supplied[CT_PASSENGERS].new_act += MoveGoodsToStation(CT_PASSENGERS, amt, ST_TOWN, t->index, stations.GetStations()); t->supplied[CT_PASSENGERS].new_act += MoveGoodsToStation(CT_PASSENGERS, amt, SourceType::Town, t->index, stations.GetStations());
/* Do the same for mail, with a fresh random */ /* Do the same for mail, with a fresh random */
r = Random(); r = Random();
@ -615,7 +615,7 @@ static void TileLoop_Town(TileIndex tile)
amt = CountBits(r & genmask); amt = CountBits(r & genmask);
if (EconomyIsInRecession()) amt = (amt + 1) >> 1; if (EconomyIsInRecession()) amt = (amt + 1) >> 1;
t->supplied[CT_MAIL].new_max += amt; t->supplied[CT_MAIL].new_max += amt;
t->supplied[CT_MAIL].new_act += MoveGoodsToStation(CT_MAIL, amt, ST_TOWN, t->index, stations.GetStations()); t->supplied[CT_MAIL].new_act += MoveGoodsToStation(CT_MAIL, amt, SourceType::Town, t->index, stations.GetStations());
} }
break; break;

View File

@ -102,7 +102,7 @@ void VehicleSpriteSeq::GetBounds(Rect *bounds) const
{ {
bounds->left = bounds->top = bounds->right = bounds->bottom = 0; bounds->left = bounds->top = bounds->right = bounds->bottom = 0;
for (uint i = 0; i < this->count; ++i) { for (uint i = 0; i < this->count; ++i) {
const Sprite *spr = GetSprite(this->seq[i].sprite, ST_NORMAL); const Sprite *spr = GetSprite(this->seq[i].sprite, SpriteType::Normal);
if (i == 0) { if (i == 0) {
bounds->left = spr->x_offs; bounds->left = spr->x_offs;
bounds->top = spr->y_offs; bounds->top = spr->y_offs;

View File

@ -1114,7 +1114,7 @@ void OpenGLBackend::PopulateCursorCache()
SpriteID sprite = _cursor.sprite_seq[i].sprite; SpriteID sprite = _cursor.sprite_seq[i].sprite;
if (!this->cursor_cache.Contains(sprite)) { if (!this->cursor_cache.Contains(sprite)) {
Sprite *old = this->cursor_cache.Insert(sprite, (Sprite *)GetRawSprite(sprite, ST_NORMAL, &SimpleSpriteAlloc, this)); Sprite *old = this->cursor_cache.Insert(sprite, (Sprite *)GetRawSprite(sprite, SpriteType::Normal, &SimpleSpriteAlloc, this));
if (old != nullptr) { if (old != nullptr) {
OpenGLSprite *gl_sprite = (OpenGLSprite *)old->data; OpenGLSprite *gl_sprite = (OpenGLSprite *)old->data;
gl_sprite->~OpenGLSprite(); gl_sprite->~OpenGLSprite();
@ -1272,10 +1272,10 @@ void OpenGLBackend::ReleaseAnimBuffer(const Rect &update_rect)
Sprite *dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + sizeof(OpenGLSprite)); Sprite *dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + sizeof(OpenGLSprite));
OpenGLSprite *gl_sprite = (OpenGLSprite *)dest_sprite->data; OpenGLSprite *gl_sprite = (OpenGLSprite *)dest_sprite->data;
new (gl_sprite) OpenGLSprite(sprite->width, sprite->height, sprite->type == ST_FONT ? 1 : ZOOM_LVL_COUNT, sprite->colours); new (gl_sprite) OpenGLSprite(sprite->width, sprite->height, sprite->type == SpriteType::Font ? 1 : ZOOM_LVL_COUNT, sprite->colours);
/* Upload texture data. */ /* Upload texture data. */
for (int i = 0; i < (sprite->type == ST_FONT ? 1 : ZOOM_LVL_COUNT); i++) { for (int i = 0; i < (sprite->type == SpriteType::Font ? 1 : ZOOM_LVL_COUNT); i++) {
gl_sprite->Update(sprite[i].width, sprite[i].height, i, sprite[i].data); gl_sprite->Update(sprite[i].width, sprite[i].height, i, sprite[i].data);
} }
@ -1310,7 +1310,7 @@ void OpenGLBackend::RenderOglSprite(OpenGLSprite *gl_sprite, PaletteID pal, int
_glBindBuffer(GL_PIXEL_UNPACK_BUFFER, OpenGLSprite::pal_pbo); _glBindBuffer(GL_PIXEL_UNPACK_BUFFER, OpenGLSprite::pal_pbo);
_glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); _glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
_glBufferSubData(GL_PIXEL_UNPACK_BUFFER, 0, 256, GetNonSprite(GB(pal, 0, PALETTE_WIDTH), ST_RECOLOUR) + 1); _glBufferSubData(GL_PIXEL_UNPACK_BUFFER, 0, 256, GetNonSprite(GB(pal, 0, PALETTE_WIDTH), SpriteType::Recolour) + 1);
_glTexSubImage1D(GL_TEXTURE_1D, 0, 0, 256, GL_RED, GL_UNSIGNED_BYTE, nullptr); _glTexSubImage1D(GL_TEXTURE_1D, 0, 0, 256, GL_RED, GL_UNSIGNED_BYTE, nullptr);
_glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); _glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);

View File

@ -625,7 +625,7 @@ void OffsetGroundSprite(int x, int y)
static void AddCombinedSprite(SpriteID image, PaletteID pal, int x, int y, int z, const SubSprite *sub) static void AddCombinedSprite(SpriteID image, PaletteID pal, int x, int y, int z, const SubSprite *sub)
{ {
Point pt = RemapCoords(x, y, z); Point pt = RemapCoords(x, y, z);
const Sprite *spr = GetSprite(image & SPRITE_MASK, ST_NORMAL); const Sprite *spr = GetSprite(image & SPRITE_MASK, SpriteType::Normal);
if (pt.x + spr->x_offs >= _vd.dpi.left + _vd.dpi.width || if (pt.x + spr->x_offs >= _vd.dpi.left + _vd.dpi.width ||
pt.x + spr->x_offs + spr->width <= _vd.dpi.left || pt.x + spr->x_offs + spr->width <= _vd.dpi.left ||
@ -691,7 +691,7 @@ void AddSortableSpriteToDraw(SpriteID image, PaletteID pal, int x, int y, int w,
top = tmp_top = RemapCoords(x + bb_offset_x, y + bb_offset_y, z + dz ).y; top = tmp_top = RemapCoords(x + bb_offset_x, y + bb_offset_y, z + dz ).y;
bottom = RemapCoords(x + w , y + h , z + bb_offset_z).y + 1; bottom = RemapCoords(x + w , y + h , z + bb_offset_z).y + 1;
} else { } else {
const Sprite *spr = GetSprite(image & SPRITE_MASK, ST_NORMAL); const Sprite *spr = GetSprite(image & SPRITE_MASK, SpriteType::Normal);
left = tmp_left = (pt.x += spr->x_offs); left = tmp_left = (pt.x += spr->x_offs);
right = (pt.x + spr->width ); right = (pt.x + spr->width );
top = tmp_top = (pt.y += spr->y_offs); top = tmp_top = (pt.y += spr->y_offs);