mirror of https://github.com/OpenTTD/OpenTTD
Codechange: make EngineID an enum
parent
ab8177ea77
commit
9015c3651f
|
@ -508,7 +508,7 @@ bool Engine::IsVariantHidden(CompanyID c) const
|
|||
*/
|
||||
void EngineOverrideManager::ResetToDefaultMapping()
|
||||
{
|
||||
EngineID id = 0;
|
||||
EngineID id = ENGINE_BEGIN;
|
||||
for (VehicleType type = VEH_TRAIN; type <= VEH_AIRCRAFT; type++) {
|
||||
auto &map = this->mappings[type];
|
||||
map.clear();
|
||||
|
|
|
@ -32,7 +32,7 @@ enum class EngineDisplayFlag : uint8_t {
|
|||
|
||||
using EngineDisplayFlags = EnumBitSet<EngineDisplayFlag, uint8_t>;
|
||||
|
||||
typedef Pool<Engine, EngineID, 64, 64000> EnginePool;
|
||||
typedef Pool<Engine, EngineID, 64, ENGINE_END> EnginePool;
|
||||
extern EnginePool _engine_pool;
|
||||
|
||||
struct Engine : EnginePool::PoolItem<&_engine_pool> {
|
||||
|
|
|
@ -83,7 +83,7 @@ struct EnginePreviewWindow : Window {
|
|||
if (widget != WID_EP_QUESTION) return;
|
||||
|
||||
/* Get size of engine sprite, on loan from depot_gui.cpp */
|
||||
EngineID engine = this->window_number;
|
||||
EngineID engine = static_cast<EngineID>(this->window_number);
|
||||
EngineImageType image_type = EIT_PURCHASE;
|
||||
uint x, y;
|
||||
int x_offs, y_offs;
|
||||
|
@ -109,7 +109,7 @@ struct EnginePreviewWindow : Window {
|
|||
{
|
||||
if (widget != WID_EP_QUESTION) return;
|
||||
|
||||
EngineID engine = this->window_number;
|
||||
EngineID engine = static_cast<EngineID>(this->window_number);
|
||||
SetDParam(0, GetEngineCategoryName(engine));
|
||||
int y = DrawStringMultiLine(r, STR_ENGINE_PREVIEW_MESSAGE, TC_FROMSTRING, SA_HOR_CENTER | SA_TOP) + WidgetDimensions::scaled.vsep_wide;
|
||||
|
||||
|
@ -127,7 +127,7 @@ struct EnginePreviewWindow : Window {
|
|||
{
|
||||
switch (widget) {
|
||||
case WID_EP_YES:
|
||||
Command<CMD_WANT_ENGINE_PREVIEW>::Post(this->window_number);
|
||||
Command<CMD_WANT_ENGINE_PREVIEW>::Post(static_cast<EngineID>(this->window_number));
|
||||
[[fallthrough]];
|
||||
case WID_EP_NO:
|
||||
if (!_shift_pressed) this->Close();
|
||||
|
@ -139,7 +139,7 @@ struct EnginePreviewWindow : Window {
|
|||
{
|
||||
if (!gui_scope) return;
|
||||
|
||||
EngineID engine = this->window_number;
|
||||
EngineID engine = static_cast<EngineID>(this->window_number);
|
||||
if (Engine::Get(engine)->preview_company != _local_company) this->Close();
|
||||
}
|
||||
};
|
||||
|
|
|
@ -20,7 +20,13 @@
|
|||
#include "sound_type.h"
|
||||
#include "strings_type.h"
|
||||
|
||||
typedef uint16_t EngineID; ///< Unique identification number of an engine.
|
||||
/** Unique identification number of an engine. */
|
||||
enum EngineID : uint16_t {
|
||||
ENGINE_BEGIN = 0,
|
||||
ENGINE_END = 64000,
|
||||
INVALID_ENGINE = 0xFFFF ///< Constant denoting an invalid engine.
|
||||
};
|
||||
DECLARE_INCREMENT_DECREMENT_OPERATORS(EngineID)
|
||||
|
||||
struct Engine;
|
||||
|
||||
|
@ -213,6 +219,4 @@ inline uint64_t PackEngineNameDParam(EngineID engine_id, EngineNameContext conte
|
|||
|
||||
static const uint MAX_LENGTH_ENGINE_NAME_CHARS = 32; ///< The maximum length of an engine name in characters including '\0'
|
||||
|
||||
static const EngineID INVALID_ENGINE = 0xFFFF; ///< Constant denoting an invalid engine.
|
||||
|
||||
#endif /* ENGINE_TYPE_H */
|
||||
|
|
|
@ -1336,7 +1336,7 @@ static ChangeInfoResult RailVehicleChangeInfo(uint first, uint last, int prop, B
|
|||
break;
|
||||
|
||||
case 0x2F: // Engine variant
|
||||
ei->variant_id = buf.ReadWord();
|
||||
ei->variant_id = static_cast<EngineID>(buf.ReadWord());
|
||||
break;
|
||||
|
||||
case 0x30: // Extra miscellaneous flags
|
||||
|
@ -1547,7 +1547,7 @@ static ChangeInfoResult RoadVehicleChangeInfo(uint first, uint last, int prop, B
|
|||
}
|
||||
|
||||
case 0x26: // Engine variant
|
||||
ei->variant_id = buf.ReadWord();
|
||||
ei->variant_id = static_cast<EngineID>(buf.ReadWord());
|
||||
break;
|
||||
|
||||
case 0x27: // Extra miscellaneous flags
|
||||
|
@ -1736,7 +1736,7 @@ static ChangeInfoResult ShipVehicleChangeInfo(uint first, uint last, int prop, B
|
|||
}
|
||||
|
||||
case 0x20: // Engine variant
|
||||
ei->variant_id = buf.ReadWord();
|
||||
ei->variant_id = static_cast<EngineID>(buf.ReadWord());
|
||||
break;
|
||||
|
||||
case 0x21: // Extra miscellaneous flags
|
||||
|
@ -1919,7 +1919,7 @@ static ChangeInfoResult AircraftVehicleChangeInfo(uint first, uint last, int pro
|
|||
break;
|
||||
|
||||
case 0x20: // Engine variant
|
||||
ei->variant_id = buf.ReadWord();
|
||||
ei->variant_id = static_cast<EngineID>(buf.ReadWord());
|
||||
break;
|
||||
|
||||
case 0x21: // Extra miscellaneous flags
|
||||
|
|
|
@ -1332,7 +1332,7 @@ void CommitVehicleListOrderChanges()
|
|||
{
|
||||
/* Build a list of EngineIDs. EngineIDs are sequential from 0 up to the number of pool items with no gaps. */
|
||||
std::vector<EngineID> ordering(Engine::GetNumItems());
|
||||
std::iota(std::begin(ordering), std::end(ordering), 0);
|
||||
std::iota(std::begin(ordering), std::end(ordering), ENGINE_BEGIN);
|
||||
|
||||
/* Pre-sort engines by scope-grfid and local index */
|
||||
std::ranges::sort(ordering, EnginePreSort);
|
||||
|
|
|
@ -458,7 +458,7 @@ struct NewsWindow : Window {
|
|||
|
||||
case WID_N_VEH_INFO: {
|
||||
assert(this->ni->reftype1 == NewsReferenceType::Engine);
|
||||
EngineID engine = this->ni->ref1;
|
||||
EngineID engine = static_cast<EngineID>(this->ni->ref1);
|
||||
str = GetEngineInfoString(engine);
|
||||
break;
|
||||
}
|
||||
|
@ -542,14 +542,14 @@ struct NewsWindow : Window {
|
|||
|
||||
case WID_N_VEH_SPR: {
|
||||
assert(this->ni->reftype1 == NewsReferenceType::Engine);
|
||||
EngineID engine = this->ni->ref1;
|
||||
EngineID engine = static_cast<EngineID>(this->ni->ref1);
|
||||
DrawVehicleEngine(r.left, r.right, CenterBounds(r.left, r.right, 0), CenterBounds(r.top, r.bottom, 0), engine, GetEnginePalette(engine, _local_company), EIT_PREVIEW);
|
||||
GfxFillRect(r.left, r.top, r.right, r.bottom, PALETTE_NEWSPAPER, FILLRECT_RECOLOUR);
|
||||
break;
|
||||
}
|
||||
case WID_N_VEH_INFO: {
|
||||
assert(this->ni->reftype1 == NewsReferenceType::Engine);
|
||||
EngineID engine = this->ni->ref1;
|
||||
EngineID engine = static_cast<EngineID>(this->ni->ref1);
|
||||
DrawStringMultiLine(r.left, r.right, r.top, r.bottom, GetEngineInfoString(engine), TC_FROMSTRING, SA_CENTER);
|
||||
break;
|
||||
}
|
||||
|
@ -678,7 +678,7 @@ private:
|
|||
StringID GetNewVehicleMessageString(WidgetID widget) const
|
||||
{
|
||||
assert(this->ni->reftype1 == NewsReferenceType::Engine);
|
||||
EngineID engine = this->ni->ref1;
|
||||
EngineID engine = static_cast<EngineID>(this->ni->ref1);
|
||||
|
||||
switch (widget) {
|
||||
case WID_N_VEH_TITLE:
|
||||
|
|
|
@ -76,7 +76,7 @@ struct ENGNChunkHandler : ChunkHandler {
|
|||
* engine pool after processing NewGRFs by CopyTempEngineData(). */
|
||||
int index;
|
||||
while ((index = SlIterateArray()) != -1) {
|
||||
Engine *e = GetTempDataEngine(index);
|
||||
Engine *e = GetTempDataEngine(static_cast<EngineID>(index));
|
||||
SlObject(e, slt);
|
||||
|
||||
if (IsSavegameVersionBefore(SLV_179)) {
|
||||
|
@ -139,7 +139,7 @@ struct ENGSChunkHandler : ChunkHandler {
|
|||
SlCopy(names, lengthof(names), SLE_STRINGID);
|
||||
|
||||
/* Copy each string into the temporary engine array. */
|
||||
for (EngineID engine = 0; engine < lengthof(names); engine++) {
|
||||
for (EngineID engine = ENGINE_BEGIN; engine < lengthof(names); engine++) {
|
||||
Engine *e = GetTempDataEngine(engine);
|
||||
e->name = CopyFromOldName(names[engine]);
|
||||
}
|
||||
|
@ -193,7 +193,7 @@ struct EIDSChunkHandler : ChunkHandler {
|
|||
while ((index = SlIterateArray()) != -1) {
|
||||
EngineIDMapping eid;
|
||||
SlObject(&eid, slt);
|
||||
_engine_mngr.SetID(eid.type, eid.internal_id, eid.grfid, eid.substitute_id, index);
|
||||
_engine_mngr.SetID(eid.type, eid.internal_id, eid.grfid, eid.substitute_id, static_cast<EngineID>(index));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -378,7 +378,7 @@ static bool FixTTOEngines()
|
|||
|
||||
/* Load the default engine set. Many of them will be overridden later */
|
||||
{
|
||||
uint j = 0;
|
||||
EngineID j = ENGINE_BEGIN;
|
||||
for (uint16_t i = 0; i < lengthof(_orig_rail_vehicle_info); i++, j++) new (GetTempDataEngine(j)) Engine(VEH_TRAIN, i);
|
||||
for (uint16_t i = 0; i < lengthof(_orig_road_vehicle_info); i++, j++) new (GetTempDataEngine(j)) Engine(VEH_ROAD, i);
|
||||
for (uint16_t i = 0; i < lengthof(_orig_ship_vehicle_info); i++, j++) new (GetTempDataEngine(j)) Engine(VEH_SHIP, i);
|
||||
|
@ -388,7 +388,7 @@ static bool FixTTOEngines()
|
|||
TimerGameCalendar::Date aging_date = std::min(TimerGameCalendar::date + CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR, TimerGameCalendar::ConvertYMDToDate(TimerGameCalendar::Year{2050}, 0, 1));
|
||||
TimerGameCalendar::YearMonthDay aging_ymd = TimerGameCalendar::ConvertDateToYMD(aging_date);
|
||||
|
||||
for (EngineID i = 0; i < 256; i++) {
|
||||
for (EngineID i = ENGINE_BEGIN; i < 256; i++) {
|
||||
OldEngineID oi = ttd_to_tto[i];
|
||||
Engine *e = GetTempDataEngine(i);
|
||||
|
||||
|
@ -1455,13 +1455,13 @@ static const OldChunks engine_chunk[] = {
|
|||
|
||||
static bool LoadOldEngine(LoadgameState &ls, int num)
|
||||
{
|
||||
Engine *e = _savegame_type == SGT_TTO ? &_old_engines[num] : GetTempDataEngine(num);
|
||||
Engine *e = _savegame_type == SGT_TTO ? &_old_engines[num] : GetTempDataEngine(static_cast<EngineID>(num));
|
||||
return LoadChunk(ls, e, engine_chunk);
|
||||
}
|
||||
|
||||
static bool LoadOldEngineName(LoadgameState &ls, int num)
|
||||
{
|
||||
Engine *e = GetTempDataEngine(num);
|
||||
Engine *e = GetTempDataEngine(static_cast<EngineID>(num));
|
||||
e->name = CopyFromOldName(RemapOldStringID(ReadUint16(ls)));
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue