From 69a6c494bfb81e332e63376f4577a104a5a8e679 Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Sun, 21 Apr 2019 22:25:54 +0100 Subject: [PATCH] Codechange: Set VehicleType's base type to byte instead of using VehicleTypeByte --- src/engine_base.h | 2 +- src/group.h | 16 ++++++++-------- src/newgrf.cpp | 2 +- src/smallmap_gui.cpp | 2 +- src/vehicle_type.h | 8 +++----- 5 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/engine_base.h b/src/engine_base.h index ad41f52f20..32c5c9bf6d 100644 --- a/src/engine_base.h +++ b/src/engine_base.h @@ -148,7 +148,7 @@ struct Engine : EnginePool::PoolItem<&_engine_pool> { struct EngineIDMapping { uint32 grfid; ///< The GRF ID of the file the entity belongs to uint16 internal_id; ///< The internal ID within the GRF file - VehicleTypeByte type; ///< The engine type + VehicleType type; ///< The engine type uint8 substitute_id; ///< The (original) entity ID to use if this GRF is not available (currently not used) }; diff --git a/src/group.h b/src/group.h index 4c51e6ebd3..6672cff673 100644 --- a/src/group.h +++ b/src/group.h @@ -65,17 +65,17 @@ struct GroupStatistics { /** Group data. */ struct Group : GroupPool::PoolItem<&_group_pool> { - char *name; ///< Group Name - OwnerByte owner; ///< Group Owner - VehicleTypeByte vehicle_type; ///< Vehicle type of the group + char *name; ///< Group Name + OwnerByte owner; ///< Group Owner + VehicleType vehicle_type; ///< Vehicle type of the group - bool replace_protection; ///< If set to true, the global autoreplace have no effect on the group - Livery livery; ///< Custom colour scheme for vehicles in this group - GroupStatistics statistics; ///< NOSAVE: Statistics and caches on the vehicles in the group. + bool replace_protection; ///< If set to true, the global autoreplace have no effect on the group + Livery livery; ///< Custom colour scheme for vehicles in this group + GroupStatistics statistics; ///< NOSAVE: Statistics and caches on the vehicles in the group. - bool folded; ///< NOSAVE: Is this group folded in the group view? + bool folded; ///< NOSAVE: Is this group folded in the group view? - GroupID parent; ///< Parent group + GroupID parent; ///< Parent group Group(CompanyID owner = INVALID_COMPANY); ~Group(); diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 20408394ee..759c556a79 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -657,7 +657,7 @@ static Engine *GetNewEngine(const GRFFile *file, VehicleType type, uint16 intern _engine_mngr.push_back({ scope_grfid, // Note: this is INVALID_GRFID if dynamic_engines is disabled, so no reservation internal_id, - {static_cast(type)}, + type, static_cast(min(internal_id, _engine_counts[type])) // substitute_id == _engine_counts[subtype] means "no substitute" }); diff --git a/src/smallmap_gui.cpp b/src/smallmap_gui.cpp index 58e89c57fc..aa1e048155 100644 --- a/src/smallmap_gui.cpp +++ b/src/smallmap_gui.cpp @@ -566,7 +566,7 @@ static inline uint32 GetSmallMapOwnerPixels(TileIndex tile, TileType t) return MKCOLOUR_XXXX(_legend_land_owners[_company_to_list_pos[o]].colour); } -/** Vehicle colours in #SMT_VEHICLES mode. Indexed by #VehicleTypeByte. */ +/** Vehicle colours in #SMT_VEHICLES mode. Indexed by #VehicleType. */ static const byte _vehicle_type_colours[6] = { PC_RED, PC_YELLOW, PC_LIGHT_BLUE, PC_WHITE, PC_BLACK, PC_RED }; diff --git a/src/vehicle_type.h b/src/vehicle_type.h index 1bc5bcef41..74bd5660d3 100644 --- a/src/vehicle_type.h +++ b/src/vehicle_type.h @@ -19,8 +19,8 @@ typedef uint32 VehicleID; static const int GROUND_ACCELERATION = 9800; ///< Acceleration due to gravity, 9.8 m/s^2 -/** Available vehicle types. */ -enum VehicleType { +/** Available vehicle types. It needs to be 8bits, because we save and load it as such */ +enum VehicleType : byte { VEH_BEGIN, VEH_TRAIN = VEH_BEGIN, ///< %Train vehicle type. @@ -39,8 +39,6 @@ enum VehicleType { DECLARE_POSTFIX_INCREMENT(VehicleType) /** Helper information for extract tool. */ template <> struct EnumPropsT : MakeEnumPropsT {}; -/** It needs to be 8bits, because we save and load it as such */ -typedef SimpleTinyEnumT VehicleTypeByte; struct Vehicle; struct Train; @@ -53,7 +51,7 @@ struct DisasterVehicle; /** Base vehicle class. */ struct BaseVehicle { - VehicleTypeByte type; ///< Type of vehicle + VehicleType type; ///< Type of vehicle }; static const VehicleID INVALID_VEHICLE = 0xFFFFF; ///< Constant representing a non-existing vehicle.