1
0
Fork 0

Codechange: make IndustryID an enum

pull/13416/head
Rubidium 2025-01-19 15:27:00 +01:00
parent 19f3e74c2f
commit b32ea0c222
9 changed files with 15 additions and 12 deletions

View File

@ -122,7 +122,7 @@ void AddCargoDelivery(CargoType cargo_type, CompanyID company, uint32_t amount,
/* Handle pickup update. */
switch (src.type) {
case SourceType::Industry: {
CargoMonitorID num = EncodeCargoIndustryMonitor(company, cargo_type, src.id);
CargoMonitorID num = EncodeCargoIndustryMonitor(company, cargo_type, static_cast<IndustryID>(src.id));
CargoMonitorMap::iterator iter = _cargo_pickups.find(num);
if (iter != _cargo_pickups.end()) iter->second += amount;
break;

View File

@ -125,7 +125,7 @@ inline bool MonitorMonitorsIndustry(CargoMonitorID num)
inline IndustryID DecodeMonitorIndustry(CargoMonitorID num)
{
if (!MonitorMonitorsIndustry(num)) return INVALID_INDUSTRY;
return GB(num, CCB_TOWN_IND_NUMBER_START, CCB_TOWN_IND_NUMBER_LENGTH);
return static_cast<IndustryID>(GB(num, CCB_TOWN_IND_NUMBER_START, CCB_TOWN_IND_NUMBER_LENGTH));
}
/**

View File

@ -1114,7 +1114,7 @@ static Money DeliverGoods(int num_pieces, CargoType cargo_type, StationID dest,
Station *st = Station::Get(dest);
/* Give the goods to the industry. */
uint accepted_ind = DeliverGoodsToIndustry(st, cargo_type, num_pieces, src.type == SourceType::Industry ? src.id : INVALID_INDUSTRY, company->index);
uint accepted_ind = DeliverGoodsToIndustry(st, cargo_type, num_pieces, src.type == SourceType::Industry ? static_cast<IndustryID>(src.id) : INVALID_INDUSTRY, company->index);
/* If this cargo type is always accepted, accept all */
uint accepted_total = HasBit(st->always_accepted, cargo_type) ? num_pieces : accepted_ind;

View File

@ -20,7 +20,7 @@
#include "timer/timer_game_economy.h"
typedef Pool<Industry, IndustryID, 64, 64000> IndustryPool;
typedef Pool<Industry, IndustryID, 64, INDUSTRY_END> IndustryPool;
extern IndustryPool _industry_pool;
static const TimerGameEconomy::Year PROCESSING_INDUSTRY_ABANDONMENT_YEARS{5}; ///< If a processing industry doesn't produce for this many consecutive economy years, it may close.

View File

@ -63,7 +63,7 @@ enum IndustryGraphics : uint8_t {
inline IndustryID GetIndustryIndex(Tile t)
{
assert(IsTileType(t, MP_INDUSTRY));
return t.m2();
return static_cast<IndustryID>(t.m2());
}
/**

View File

@ -10,7 +10,12 @@
#ifndef INDUSTRY_TYPE_H
#define INDUSTRY_TYPE_H
typedef uint16_t IndustryID;
enum IndustryID : uint16_t {
INDUSTRY_BEGIN = 0,
INDUSTRY_END = 64000,
INVALID_INDUSTRY = 0xFFFF
};
typedef uint16_t IndustryGfx;
typedef uint8_t IndustryType;
struct Industry;
@ -18,8 +23,6 @@ struct Industry;
struct IndustrySpec;
struct IndustryTileSpec;
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

View File

@ -36,7 +36,7 @@
if (type == GT_STORY_PAGE && ScriptStoryPage::IsValidStoryPage(static_cast<StoryPageID>(destination))) story_page = ::StoryPage::Get(static_cast<StoryPageID>(destination));
return (type == GT_NONE && destination == 0) ||
(type == GT_TILE && ScriptMap::IsValidTile(::TileIndex(destination))) ||
(type == GT_INDUSTRY && ScriptIndustry::IsValidIndustry(destination)) ||
(type == GT_INDUSTRY && ScriptIndustry::IsValidIndustry(static_cast<IndustryID>(destination))) ||
(type == GT_TOWN && ScriptTown::IsValidTown(destination)) ||
(type == GT_COMPANY && ScriptCompany::ResolveCompanyID((ScriptCompany::CompanyID)destination) != ScriptCompany::COMPANY_INVALID) ||
(type == GT_STORY_PAGE && story_page != nullptr && (c == INVALID_COMPANY ? story_page->company == INVALID_COMPANY : story_page->company == INVALID_COMPANY || story_page->company == c));

View File

@ -33,7 +33,7 @@
EnforcePrecondition(false, (ref_type == NR_NONE) ||
(ref_type == NR_TILE && ScriptMap::IsValidTile(::TileIndex(reference))) ||
(ref_type == NR_STATION && ScriptStation::IsValidStation(reference)) ||
(ref_type == NR_INDUSTRY && ScriptIndustry::IsValidIndustry(reference)) ||
(ref_type == NR_INDUSTRY && ScriptIndustry::IsValidIndustry(static_cast<IndustryID>(reference))) ||
(ref_type == NR_TOWN && ScriptTown::IsValidTown(reference)));
uint8_t c = company;

View File

@ -37,8 +37,8 @@
EnforcePrecondition(false, ScriptCargo::IsValidCargo(cargo_type));
EnforcePrecondition(false, from_type == SPT_INDUSTRY || from_type == SPT_TOWN);
EnforcePrecondition(false, to_type == SPT_INDUSTRY || to_type == SPT_TOWN);
EnforcePrecondition(false, (from_type == SPT_INDUSTRY && ScriptIndustry::IsValidIndustry(from_id)) || (from_type == SPT_TOWN && ScriptTown::IsValidTown(from_id)));
EnforcePrecondition(false, (to_type == SPT_INDUSTRY && ScriptIndustry::IsValidIndustry(to_id)) || (to_type == SPT_TOWN && ScriptTown::IsValidTown(to_id)));
EnforcePrecondition(false, (from_type == SPT_INDUSTRY && ScriptIndustry::IsValidIndustry(static_cast<IndustryID>(from_id))) || (from_type == SPT_TOWN && ScriptTown::IsValidTown(from_id)));
EnforcePrecondition(false, (to_type == SPT_INDUSTRY && ScriptIndustry::IsValidIndustry(static_cast<IndustryID>(to_id))) || (to_type == SPT_TOWN && ScriptTown::IsValidTown(to_id)));
Source from{static_cast<SourceID>(from_id), static_cast<SourceType>(from_type)};
Source to{static_cast<SourceID>(to_id), static_cast<SourceType>(to_type)};