Fix #13299: Merge IT_INVALID and INVALID_INDUSTRYTYPE (#13300)

* Fix #13299: Merge IT_INVALID and INVALID_INDUSTRYTYPE

* Codefix: Use NUM_INDUSTRYTILES where it's intended
This commit is contained in:
Loïc Guilloux 2025-01-10 01:17:11 +01:00 committed by GitHub
parent c0edbe0d37
commit 46f181c8a6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 32 additions and 34 deletions

View File

@ -136,7 +136,7 @@ const IndustrySpec *GetIndustrySpec(IndustryType thistype)
*/
const IndustryTileSpec *GetIndustryTileSpec(IndustryGfx gfx)
{
assert(gfx < INVALID_INDUSTRYTILE);
assert(gfx < NUM_INDUSTRYTILES);
return &_industry_tile_specs[gfx];
}

View File

@ -316,7 +316,7 @@ class BuildIndustryWindow : public Window {
void UpdateAvailability()
{
this->enabled = this->selected_type != INVALID_INDUSTRYTYPE && (_game_mode == GM_EDITOR || GetIndustryProbabilityCallback(this->selected_type, IACT_USERCREATION, 1) > 0);
this->enabled = this->selected_type != IT_INVALID && (_game_mode == GM_EDITOR || GetIndustryProbabilityCallback(this->selected_type, IACT_USERCREATION, 1) > 0);
}
void SetupArrays()
@ -335,7 +335,7 @@ class BuildIndustryWindow : public Window {
* and raw ones are loaded only when setting allows it */
if (_game_mode != GM_EDITOR && indsp->IsRawIndustry() && _settings_game.construction.raw_industry_construction == 0) {
/* Unselect if the industry is no longer in the list */
if (this->selected_type == ind) this->selected_type = INVALID_INDUSTRYTYPE;
if (this->selected_type == ind) this->selected_type = IT_INVALID;
continue;
}
@ -344,7 +344,7 @@ class BuildIndustryWindow : public Window {
}
/* First industry type is selected if the current selection is invalid. */
if (this->selected_type == INVALID_INDUSTRYTYPE && !this->list.empty()) this->selected_type = this->list[0];
if (this->selected_type == IT_INVALID && !this->list.empty()) this->selected_type = this->list[0];
this->UpdateAvailability();
@ -354,8 +354,8 @@ class BuildIndustryWindow : public Window {
/** Update status of the fund and display-chain widgets. */
void SetButtons()
{
this->SetWidgetDisabledState(WID_DPI_FUND_WIDGET, this->selected_type != INVALID_INDUSTRYTYPE && !this->enabled);
this->SetWidgetDisabledState(WID_DPI_DISPLAY_WIDGET, this->selected_type == INVALID_INDUSTRYTYPE && this->enabled);
this->SetWidgetDisabledState(WID_DPI_FUND_WIDGET, this->selected_type != IT_INVALID && !this->enabled);
this->SetWidgetDisabledState(WID_DPI_DISPLAY_WIDGET, this->selected_type == IT_INVALID && this->enabled);
}
/**
@ -406,7 +406,7 @@ class BuildIndustryWindow : public Window {
public:
BuildIndustryWindow() : Window(_build_industry_desc)
{
this->selected_type = INVALID_INDUSTRYTYPE;
this->selected_type = IT_INVALID;
this->CreateNestedTree();
this->vscroll = this->GetScrollbar(WID_DPI_SCROLLBAR);
@ -512,7 +512,7 @@ public:
/* We've chosen many random industries but no industries have been specified */
SetDParam(0, STR_FUND_INDUSTRY_BUILD_NEW_INDUSTRY);
} else {
if (this->selected_type != INVALID_INDUSTRYTYPE) {
if (this->selected_type != IT_INVALID) {
const IndustrySpec *indsp = GetIndustrySpec(this->selected_type);
SetDParam(0, (_settings_game.construction.raw_industry_construction == 2 && indsp->IsRawIndustry()) ? STR_FUND_INDUSTRY_PROSPECT_NEW_INDUSTRY : STR_FUND_INDUSTRY_FUND_NEW_INDUSTRY);
} else {
@ -558,7 +558,7 @@ public:
case WID_DPI_INFOPANEL: {
Rect ir = r.Shrink(WidgetDimensions::scaled.framerect);
if (this->selected_type == INVALID_INDUSTRYTYPE) {
if (this->selected_type == IT_INVALID) {
DrawStringMultiLine(ir, STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES_TOOLTIP);
break;
}
@ -676,11 +676,11 @@ public:
}
case WID_DPI_DISPLAY_WIDGET:
if (this->selected_type != INVALID_INDUSTRYTYPE) ShowIndustryCargoesWindow(this->selected_type);
if (this->selected_type != IT_INVALID) ShowIndustryCargoesWindow(this->selected_type);
break;
case WID_DPI_FUND_WIDGET: {
if (this->selected_type != INVALID_INDUSTRYTYPE) {
if (this->selected_type != IT_INVALID) {
if (_game_mode != GM_EDITOR && _settings_game.construction.raw_industry_construction == 2 && GetIndustrySpec(this->selected_type)->IsRawIndustry()) {
Command<CMD_BUILD_INDUSTRY>::Post(STR_ERROR_CAN_T_CONSTRUCT_THIS_INDUSTRY, TileIndex{}, this->selected_type, 0, false, InteractiveRandom());
this->HandleButtonClick(WID_DPI_FUND_WIDGET);
@ -734,7 +734,7 @@ public:
IntervalTimer<TimerWindow> update_interval = {std::chrono::seconds(3), [this](auto) {
if (_game_mode == GM_EDITOR) return;
if (this->selected_type == INVALID_INDUSTRYTYPE) return;
if (this->selected_type == IT_INVALID) return;
bool enabled = this->enabled;
this->UpdateAvailability();

View File

@ -23,8 +23,8 @@ static const IndustryID INVALID_INDUSTRY = 0xFFFF;
static const IndustryType NUM_INDUSTRYTYPES_PER_GRF = 128; ///< maximum number of industry types per NewGRF; limited to 128 because bit 7 has a special meaning in some variables/callbacks (see MapNewGRFIndustryType).
static const IndustryType NEW_INDUSTRYOFFSET = 37; ///< original number of industry types
static const IndustryType NUM_INDUSTRYTYPES = 240; ///< total number of industry types, new and old; limited to 240 because we need some special ids like INVALID_INDUSTRYTYPE, IT_AI_UNKNOWN, IT_AI_TOWN, ...
static const IndustryType INVALID_INDUSTRYTYPE = NUM_INDUSTRYTYPES; ///< one above amount is considered invalid
static const IndustryType NUM_INDUSTRYTYPES = 240; ///< total number of industry types, new and old; limited to 240 because we need some special ids like IT_INVALID, IT_AI_UNKNOWN, IT_AI_TOWN, ...
static const IndustryType IT_INVALID = 0xFF;
static const IndustryGfx NUM_INDUSTRYTILES_PER_GRF = 255; ///< Maximum number of industry tiles per NewGRF; limited to 255 to allow extending Action3 with an extended byte later on.

View File

@ -194,7 +194,7 @@ inline IndustryGfx GetTranslatedIndustryTileID(IndustryGfx gfx)
* will never be assigned as a tile index and is only required in order to do some
* tests while building the industry (as in WATER REQUIRED */
if (gfx != 0xFF) {
assert(gfx < INVALID_INDUSTRYTILE);
assert(gfx < NUM_INDUSTRYTILES);
const IndustryTileSpec *it = &_industry_tile_specs[gfx];
return it->grf_prop.override == INVALID_INDUSTRYTILE ? gfx : it->grf_prop.override;
} else {
@ -202,6 +202,4 @@ inline IndustryGfx GetTranslatedIndustryTileID(IndustryGfx gfx)
}
}
static const uint8_t IT_INVALID = 255;
#endif /* INDUSTRYTYPE_H */

View File

@ -210,13 +210,13 @@ uint16_t GetAiPurchaseCallbackResult(uint8_t feature, CargoID cargo_type, uint8_
if (src_industry != IT_AI_UNKNOWN && src_industry != IT_AI_TOWN) {
const IndustrySpec *is = GetIndustrySpec(src_industry);
/* If this is no original industry, use the substitute type */
if (is->grf_prop.subst_id != INVALID_INDUSTRYTYPE) src_industry = is->grf_prop.subst_id;
if (is->grf_prop.subst_id != IT_INVALID) src_industry = is->grf_prop.subst_id;
}
if (dst_industry != IT_AI_UNKNOWN && dst_industry != IT_AI_TOWN) {
const IndustrySpec *is = GetIndustrySpec(dst_industry);
/* If this is no original industry, use the substitute type */
if (is->grf_prop.subst_id != INVALID_INDUSTRYTYPE) dst_industry = is->grf_prop.subst_id;
if (is->grf_prop.subst_id != IT_INVALID) dst_industry = is->grf_prop.subst_id;
}
object.generic_scope.cargo_type = cargo_type;

View File

@ -28,7 +28,7 @@
/* Since the industry IDs defined by the GRF file don't necessarily correlate
* to those used by the game, the IDs used for overriding old industries must be
* translated when the idustry spec is set. */
IndustryOverrideManager _industry_mngr(NEW_INDUSTRYOFFSET, NUM_INDUSTRYTYPES, INVALID_INDUSTRYTYPE);
IndustryOverrideManager _industry_mngr(NEW_INDUSTRYOFFSET, NUM_INDUSTRYTYPES, IT_INVALID);
IndustryTileOverrideManager _industile_mngr(NEW_INDUSTRYTILEOFFSET, NUM_INDUSTRYTILES, INVALID_INDUSTRYTILE);
/**

View File

@ -214,7 +214,7 @@
/* static */ IndustryType ScriptIndustry::GetIndustryType(IndustryID industry_id)
{
if (!IsValidIndustry(industry_id)) return INVALID_INDUSTRYTYPE;
if (!IsValidIndustry(industry_id)) return IT_INVALID;
return ::Industry::Get(industry_id)->type;
}

View File

@ -160,7 +160,7 @@
/* static */ IndustryType ScriptIndustryType::ResolveNewGRFID(SQInteger grfid, SQInteger grf_local_id)
{
EnforcePrecondition(INVALID_INDUSTRYTYPE, IsInsideBS(grf_local_id, 0x00, NUM_INDUSTRYTYPES_PER_GRF));
EnforcePrecondition(IT_INVALID, IsInsideBS(grf_local_id, 0x00, NUM_INDUSTRYTYPES_PER_GRF));
grfid = BSWAP32(GB(grfid, 0, 32)); // Match people's expectations.
return _industry_mngr.GetID(grf_local_id, grfid);

View File

@ -60,25 +60,25 @@ static uint8_t _linkstat_colours_in_legenda[] = {0, 1, 3, 5, 7, 9, 11};
static const int NUM_NO_COMPANY_ENTRIES = 4; ///< Number of entries in the owner legend that are not companies.
/** Macro for ordinary entry of LegendAndColour */
#define MK(a, b) {a, b, INVALID_INDUSTRYTYPE, 0, INVALID_COMPANY, true, false, false}
#define MK(a, b) {a, b, IT_INVALID, 0, INVALID_COMPANY, true, false, false}
/** Macro for a height legend entry with configurable colour. */
#define MC(col_break) {0, STR_TINY_BLACK_HEIGHT, INVALID_INDUSTRYTYPE, 0, INVALID_COMPANY, true, false, col_break}
#define MC(col_break) {0, STR_TINY_BLACK_HEIGHT, IT_INVALID, 0, INVALID_COMPANY, true, false, col_break}
/** Macro for non-company owned property entry of LegendAndColour */
#define MO(a, b) {a, b, INVALID_INDUSTRYTYPE, 0, INVALID_COMPANY, true, false, false}
#define MO(a, b) {a, b, IT_INVALID, 0, INVALID_COMPANY, true, false, false}
/** Macro used for forcing a rebuild of the owner legend the first time it is used. */
#define MOEND() {0, STR_NULL, INVALID_INDUSTRYTYPE, 0, OWNER_NONE, true, true, false}
#define MOEND() {0, STR_NULL, IT_INVALID, 0, OWNER_NONE, true, true, false}
/** Macro for end of list marker in arrays of LegendAndColour */
#define MKEND() {0, STR_NULL, INVALID_INDUSTRYTYPE, 0, INVALID_COMPANY, true, true, false}
#define MKEND() {0, STR_NULL, IT_INVALID, 0, INVALID_COMPANY, true, true, false}
/**
* Macro for break marker in arrays of LegendAndColour.
* It will have valid data, though
*/
#define MS(a, b) {a, b, INVALID_INDUSTRYTYPE, 0, INVALID_COMPANY, true, false, true}
#define MS(a, b) {a, b, IT_INVALID, 0, INVALID_COMPANY, true, false, true}
/** Legend text giving the colours to look for on the minimap */
static LegendAndColour _legend_land_contours[] = {
@ -177,7 +177,7 @@ static uint16_t _industry_to_name_string_width[NUM_INDUSTRYTYPES];
/** Show heightmap in industry and owner mode of smallmap window. */
static bool _smallmap_show_heightmap = false;
/** Highlight a specific industry type */
static IndustryType _smallmap_industry_highlight = INVALID_INDUSTRYTYPE;
static IndustryType _smallmap_industry_highlight = IT_INVALID;
/** State of highlight blinking */
static bool _smallmap_industry_highlight_state;
/** For connecting company ID to position in owner list (small map legend) */
@ -1429,7 +1429,7 @@ protected:
/** Blink the industries (if hover over an industry). */
void Blink()
{
if (_smallmap_industry_highlight == INVALID_INDUSTRYTYPE) return;
if (_smallmap_industry_highlight == IT_INVALID) return;
_smallmap_industry_highlight_state = !_smallmap_industry_highlight_state;
@ -1440,7 +1440,7 @@ protected:
/** Force a full refresh of the map. */
void ForceRefresh()
{
if (_smallmap_industry_highlight != INVALID_INDUSTRYTYPE) return;
if (_smallmap_industry_highlight != IT_INVALID) return;
this->UpdateLinks();
this->SetDirty();
@ -1451,7 +1451,7 @@ public:
SmallMapWindow(WindowDesc &desc, int window_number) : Window(desc)
{
_smallmap_industry_highlight = INVALID_INDUSTRYTYPE;
_smallmap_industry_highlight = IT_INVALID;
this->overlay = std::make_unique<LinkGraphOverlay>(this, WID_SM_MAP, 0, this->GetOverlayCompanyMask(), 1);
this->CreateNestedTree();
this->LowerWidget(WID_SM_CONTOUR + this->map_type);
@ -1878,7 +1878,7 @@ public:
void OnMouseOver([[maybe_unused]] Point pt, WidgetID widget) override
{
IndustryType new_highlight = INVALID_INDUSTRYTYPE;
IndustryType new_highlight = IT_INVALID;
if (widget == WID_SM_LEGEND && this->map_type == SMT_INDUSTRY) {
int industry_pos = GetPositionOnLegend(pt);
if (industry_pos >= 0 && industry_pos < _smallmap_industry_count) {

View File

@ -1133,7 +1133,7 @@ enum IndustryTypes {
{INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO}, \
{{im1, 0}, {im2, 0}, {im3, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}}, \
pr, clim, bev, col, in, intx, s1, s2, s3, STR_UNDEFINED, {ai1, ai2, ai3, ai4}, {ag1, ag2, ag3, ag4}, \
0, true, GRFFileProps(INVALID_INDUSTRYTYPE), snd, \
0, true, GRFFileProps(IT_INVALID), snd, \
{{p1, p2}}, {{a1, a2, a3}}}
/* Format:
tile table count and sounds table