diff --git a/src/economy_type.h b/src/economy_type.h index e4d0ea077a..73f2f384ea 100644 --- a/src/economy_type.h +++ b/src/economy_type.h @@ -86,7 +86,7 @@ struct ScoreInfo { * Enumeration of all base prices for use with #Prices. * The prices are ordered as they are expected by NewGRF cost multipliers, so don't shuffle them. */ -enum Price { +enum Price : uint8_t { PR_BEGIN = 0, PR_STATION_VALUE = 0, PR_BUILD_RAIL, diff --git a/src/engine_base.h b/src/engine_base.h index de552bd9a7..3d7ce8d207 100644 --- a/src/engine_base.h +++ b/src/engine_base.h @@ -35,9 +35,15 @@ typedef Pool EnginePool; extern EnginePool _engine_pool; struct Engine : EnginePool::PoolItem<&_engine_pool> { + CompanyMask company_avail; ///< Bit for each company whether the engine is available for that company. + CompanyMask company_hidden; ///< Bit for each company whether the engine is normally hidden in the build gui for that company. + CompanyMask preview_asked; ///< Bit for each company which has already been offered a preview. + std::string name; ///< Custom name of engine. + TimerGameCalendar::Date intro_date; ///< Date of introduction of the engine. int32_t age; ///< Age of the engine in months. + uint16_t reliability; ///< Current reliability of the engine. uint16_t reliability_spd_dec; ///< Speed of reliability decay between services (per day). uint16_t reliability_start; ///< Initial reliability of the engine. @@ -47,17 +53,14 @@ struct Engine : EnginePool::PoolItem<&_engine_pool> { uint16_t duration_phase_2; ///< Second reliability phase in months, keeping #reliability_max. uint16_t duration_phase_3; ///< Third reliability phase in months, decaying to #reliability_final. uint8_t flags; ///< Flags of the engine. @see EngineFlags - CompanyMask preview_asked; ///< Bit for each company which has already been offered a preview. + CompanyID preview_company; ///< Company which is currently being offered a preview \c INVALID_COMPANY means no company. uint8_t preview_wait; ///< Daily countdown timer for timeout of offering the engine to the #preview_company company. - CompanyMask company_avail; ///< Bit for each company whether the engine is available for that company. - CompanyMask company_hidden; ///< Bit for each company whether the engine is normally hidden in the build gui for that company. uint8_t original_image_index; ///< Original vehicle image index, thus the image index of the overridden vehicle VehicleType type; ///< %Vehicle type, ie #VEH_ROAD, #VEH_TRAIN, etc. EngineDisplayFlags display_flags; ///< NOSAVE client-side-only display flags for build engine list. EngineID display_last_variant; ///< NOSAVE client-side-only last variant selected. - EngineInfo info; union { @@ -67,6 +70,8 @@ struct Engine : EnginePool::PoolItem<&_engine_pool> { AircraftVehicleInfo air; } u; + uint16_t list_position; + /* NewGRF related data */ /** * Properties related the the grf file. @@ -76,7 +81,6 @@ struct Engine : EnginePool::PoolItem<&_engine_pool> { */ GRFFilePropsBase grf_prop; std::vector overrides; - uint16_t list_position; Engine() {} Engine(VehicleType type, EngineID base); diff --git a/src/engine_type.h b/src/engine_type.h index d5a28ced3e..dda1ab5dec 100644 --- a/src/engine_type.h +++ b/src/engine_type.h @@ -23,14 +23,14 @@ typedef uint16_t EngineID; ///< Unique identification number of an engine. struct Engine; /** Available types of rail vehicles. */ -enum RailVehicleTypes { +enum RailVehicleTypes : uint8_t { RAILVEH_SINGLEHEAD, ///< indicates a "standalone" locomotive RAILVEH_MULTIHEAD, ///< indicates a combination of two locomotives RAILVEH_WAGON, ///< simple wagon, not motorized }; /** Type of rail engine. */ -enum EngineClass { +enum EngineClass : uint8_t { EC_STEAM, ///< Steam rail engine. EC_DIESEL, ///< Diesel rail engine. EC_ELECTRIC, ///< Electric rail engine. @@ -45,6 +45,7 @@ struct RailVehicleInfo { uint8_t cost_factor; ///< Purchase cost factor; For multiheaded engines the sum of both engine prices. RailType railtype; ///< Railtype, mangled if elrail is disabled. RailType intended_railtype; ///< Intended railtype, regardless of elrail being enabled or disabled. + uint8_t ai_passenger_only; ///< Bit value to tell AI that this engine is for passenger use only uint16_t max_speed; ///< Maximum speed (1 unit = 1/1.6 mph = 1 km-ish/h) uint16_t power; ///< Power of engine (hp); For multiheaded engines the sum of both engine powers. uint16_t weight; ///< Weight of vehicle (tons); For multiheaded engines the weight of each single engine. @@ -52,7 +53,6 @@ struct RailVehicleInfo { Price running_cost_class; EngineClass engclass; ///< Class of engine for this vehicle uint8_t capacity; ///< Cargo capacity of vehicle; For multiheaded engines the capacity of each single engine. - uint8_t ai_passenger_only; ///< Bit value to tell AI that this engine is for passenger use only uint16_t pow_wag_power; ///< Extra power applied to consist if wagon should be powered uint8_t pow_wag_weight; ///< Extra weight applied to consist if wagon should be powered uint8_t visual_effect; ///< Bitstuffed NewGRF visual effect data @@ -67,10 +67,10 @@ struct RailVehicleInfo { struct ShipVehicleInfo { uint8_t image_index; uint8_t cost_factor; + uint8_t running_cost; uint8_t acceleration; ///< Acceleration (1 unit = 1/3.2 mph per tick = 0.5 km-ish/h per tick) uint16_t max_speed; ///< Maximum speed (1 unit = 1/3.2 mph = 0.5 km-ish/h) uint16_t capacity; - uint8_t running_cost; SoundID sfx; bool old_refittable; ///< Is ship refittable; only used during initialisation. Later use EngineInfo::refit_mask. uint8_t visual_effect; ///< Bitstuffed NewGRF visual effect data @@ -103,8 +103,8 @@ struct AircraftVehicleInfo { uint8_t running_cost; uint8_t subtype; ///< Type of aircraft. @see AircraftSubTypeBits SoundID sfx; - uint8_t acceleration; uint16_t max_speed; ///< Maximum speed (1 unit = 8 mph = 12.8 km-ish/h) + uint8_t acceleration; uint8_t mail_capacity; ///< Mail capacity (bags). uint16_t passenger_capacity; ///< Passenger capacity (persons). uint16_t max_range; ///< Maximum range of this aircraft. @@ -128,7 +128,11 @@ struct RoadVehicleInfo { RoadType roadtype; ///< Road type }; -enum class ExtraEngineFlags : uint32_t { +/** + * Extra engine flags for NewGRF features. + * This is defined in the specification a 32 bit value, but most bits are not currently used. + */ +enum class ExtraEngineFlags : uint16_t { None = 0, NoNews = (1U << 0), ///< No 'new vehicle' news will be generated. NoPreview = (1U << 1), ///< No exclusive preview will be offered. @@ -155,10 +159,10 @@ struct EngineInfo { uint8_t misc_flags; ///< Miscellaneous flags. @see EngineMiscFlags uint16_t callback_mask; ///< Bitmask of vehicle callbacks that have to be called int8_t retire_early; ///< Number of years early to retire vehicle + ExtraEngineFlags extra_flags; StringID string_id; ///< Default name of engine uint16_t cargo_age_period; ///< Number of ticks before carried cargo is aged. EngineID variant_id; ///< Engine variant ID. If set, will be treated specially in purchase lists. - ExtraEngineFlags extra_flags; }; /** diff --git a/src/table/engines.h b/src/table/engines.h index e1f42c1c1e..61b98a9469 100644 --- a/src/table/engines.h +++ b/src/table/engines.h @@ -24,7 +24,7 @@ * @param f Bitmask of the climates * @note the 5 between b and f is the load amount */ -#define MT(a, b, c, d, e, f) { CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR + a, c, d, b, 5, f, INVALID_CARGO, e, 0, 8, 0, 0, 0, STR_EMPTY, Ticks::CARGO_AGING_TICKS, INVALID_ENGINE, ExtraEngineFlags::None } +#define MT(a, b, c, d, e, f) { CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR + a, c, d, b, 5, f, INVALID_CARGO, e, 0, 8, 0, 0, 0, ExtraEngineFlags::None, STR_EMPTY, Ticks::CARGO_AGING_TICKS, INVALID_ENGINE } /** * Writes the properties of a multiple-unit train into the EngineInfo struct. @@ -37,7 +37,7 @@ * @param f Bitmask of the climates * @note the 5 between b and f is the load amount */ -#define MM(a, b, c, d, e, f) { CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR + a, c, d, b, 5, f, INVALID_CARGO, e, 0, 8, 1 << EF_RAIL_IS_MU, 0, 0, STR_EMPTY, Ticks::CARGO_AGING_TICKS, INVALID_ENGINE, ExtraEngineFlags::None } +#define MM(a, b, c, d, e, f) { CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR + a, c, d, b, 5, f, INVALID_CARGO, e, 0, 8, 1 << EF_RAIL_IS_MU, 0, 0, ExtraEngineFlags::None, STR_EMPTY, Ticks::CARGO_AGING_TICKS, INVALID_ENGINE } /** * Writes the properties of a train carriage into the EngineInfo struct. @@ -50,7 +50,7 @@ * @see MT * @note the 5 between b and f is the load amount */ -#define MW(a, b, c, d, e, f) { CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR + a, c, d, b, 5, f, INVALID_CARGO, e, 0, 8, 0, 0, 0, STR_EMPTY, Ticks::CARGO_AGING_TICKS, INVALID_ENGINE, ExtraEngineFlags::None } +#define MW(a, b, c, d, e, f) { CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR + a, c, d, b, 5, f, INVALID_CARGO, e, 0, 8, 0, 0, 0, ExtraEngineFlags::None, STR_EMPTY, Ticks::CARGO_AGING_TICKS, INVALID_ENGINE } /** * Writes the properties of a road vehicle into the EngineInfo struct. @@ -63,7 +63,7 @@ * @param f Bitmask of the climates * @note the 5 between b and f is the load amount */ -#define MR(a, b, c, d, e, f) { CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR + a, c, d, b, 5, f, INVALID_CARGO, e, 0, 8, 0, 0, 0, STR_EMPTY, Ticks::CARGO_AGING_TICKS, INVALID_ENGINE, ExtraEngineFlags::None } +#define MR(a, b, c, d, e, f) { CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR + a, c, d, b, 5, f, INVALID_CARGO, e, 0, 8, 0, 0, 0, ExtraEngineFlags::None, STR_EMPTY, Ticks::CARGO_AGING_TICKS, INVALID_ENGINE } /** * Writes the properties of a ship into the EngineInfo struct. @@ -75,7 +75,7 @@ * @param f Bitmask of the climates * @note the 10 between b and f is the load amount */ -#define MS(a, b, c, d, e, f) { CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR + a, c, d, b, 10, f, INVALID_CARGO, e, 0, 8, 0, 0, 0, STR_EMPTY, Ticks::CARGO_AGING_TICKS, INVALID_ENGINE, ExtraEngineFlags::None } +#define MS(a, b, c, d, e, f) { CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR + a, c, d, b, 10, f, INVALID_CARGO, e, 0, 8, 0, 0, 0, ExtraEngineFlags::None, STR_EMPTY, Ticks::CARGO_AGING_TICKS, INVALID_ENGINE } /** * Writes the properties of an aeroplane into the EngineInfo struct. @@ -86,7 +86,7 @@ * @param e Bitmask of the climates * @note the 20 between b and e is the load amount */ -#define MA(a, b, c, d, e) { CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR + a, c, d, b, 20, e, INVALID_CARGO, CT_INVALID, 0, 8, 0, 0, 0, STR_EMPTY, Ticks::CARGO_AGING_TICKS, INVALID_ENGINE, ExtraEngineFlags::None } +#define MA(a, b, c, d, e) { CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR + a, c, d, b, 20, e, INVALID_CARGO, CT_INVALID, 0, 8, 0, 0, 0, ExtraEngineFlags::None, STR_EMPTY, Ticks::CARGO_AGING_TICKS, INVALID_ENGINE } /* Climates * T = Temperate @@ -97,7 +97,7 @@ #define A 2 #define S 4 #define Y 8 -static const EngineInfo _orig_engine_info[] = { +static constexpr EngineInfo _orig_engine_info[] = { /* base_intro base_life * | decay_speed cargo_type * | | lifelength | climates @@ -386,7 +386,7 @@ static const EngineInfo _orig_engine_info[] = { * Tractive effort coefficient by default is the same as TTDPatch, 0.30*256=76 * Air drag value depends on the top speed of the vehicle. */ -#define RVI(a, b, c, d, e, f, g, h, i, j, k) { a, b, c, j, j, d, e, f, g, h, k, i, 0, 0, 0, VE_DEFAULT, 0, 76, 0, 0, 0 } +#define RVI(a, b, c, d, e, f, g, h, i, j, k) { a, b, c, j, j, 0, d, e, f, g, h, k, i, 0, 0, VE_DEFAULT, 0, 76, 0, 0, 0 } #define M RAILVEH_MULTIHEAD #define W RAILVEH_WAGON #define G RAILVEH_SINGLEHEAD @@ -408,7 +408,7 @@ static const EngineInfo _orig_engine_info[] = { #define RC_E PR_RUNNING_TRAIN_ELECTRIC #define RC_W INVALID_PRICE -static const RailVehicleInfo _orig_rail_vehicle_info[] = { +static constexpr RailVehicleInfo _orig_rail_vehicle_info[] = { /* image_index max_speed running_cost engclass * | type | power | running_cost_class * | | cost_factor | weight | | capacity @@ -564,8 +564,8 @@ static const RailVehicleInfo _orig_rail_vehicle_info[] = { * @param g sound effect * @param h refittable */ -#define SVI(a, b, c, d, e, f, g, h) { a, b, c, d, e, f, g, h, VE_DEFAULT, 0, 0 } -static const ShipVehicleInfo _orig_ship_vehicle_info[] = { +#define SVI(a, b, c, d, e, f, g, h) { a, b, f, c, d, e, g, h, VE_DEFAULT, 0, 0 } +static constexpr ShipVehicleInfo _orig_ship_vehicle_info[] = { /* image_index max_speed sfx refittable * | cost_factor capacity | | * | | acceleration running_cost | @@ -597,11 +597,11 @@ static const ShipVehicleInfo _orig_ship_vehicle_info[] = { * @param h mail_capacity (bags) * @param i passenger_capacity (persons) */ -#define AVI(a, b, c, d, e, f, g, h, i) { a, b, c, d, e, f, (g * 128) / 10, h, i, 0 } +#define AVI(a, b, c, d, e, f, g, h, i) { a, b, c, d, e, (g * 128) / 10, f, h, i, 0 } #define H AIR_HELI #define P AIR_CTOL #define J AIR_CTOL | AIR_FAST -static const AircraftVehicleInfo _orig_aircraft_vehicle_info[] = { +static constexpr AircraftVehicleInfo _orig_aircraft_vehicle_info[] = { /* image_index sfx acceleration * | cost_factor | | max_speed * | | running_cost | | mail_capacity @@ -669,7 +669,7 @@ static const AircraftVehicleInfo _orig_aircraft_vehicle_info[] = { * Air drag value depends on the top speed of the vehicle. */ #define ROV(a, b, c, d, e, f, g, h) { a, b, c, PR_RUNNING_ROADVEH, d, e, f, g, h, 76, 0, VE_DEFAULT, 0, ROADTYPE_ROAD } -static const RoadVehicleInfo _orig_road_vehicle_info[] = { +static constexpr RoadVehicleInfo _orig_road_vehicle_info[] = { /* image_index sfx max_speed power * | cost_factor | | capacity | * | | running_cost | | weight