Update to 14.0-beta1
This commit is contained in:
@@ -16,23 +16,35 @@
|
||||
#include "strings_type.h"
|
||||
#include "landscape_type.h"
|
||||
#include "core/bitmath_func.hpp"
|
||||
#include "core/span_type.hpp"
|
||||
#include <vector>
|
||||
|
||||
/** Globally unique label of a cargo type. */
|
||||
typedef uint32 CargoLabel;
|
||||
typedef uint32_t CargoLabel;
|
||||
|
||||
/** Town growth effect when delivering cargo. */
|
||||
enum TownEffect : byte {
|
||||
TE_BEGIN = 0,
|
||||
TE_NONE = TE_BEGIN, ///< Cargo has no effect.
|
||||
TE_PASSENGERS, ///< Cargo behaves passenger-like.
|
||||
TE_MAIL, ///< Cargo behaves mail-like.
|
||||
TE_GOODS, ///< Cargo behaves goods/candy-like.
|
||||
TE_WATER, ///< Cargo behaves water-like.
|
||||
TE_FOOD, ///< Cargo behaves food/fizzy-drinks-like.
|
||||
TE_END, ///< End of town effects.
|
||||
NUM_TE = TE_END, ///< Amount of town effects.
|
||||
enum TownAcceptanceEffect : byte {
|
||||
TAE_BEGIN = 0,
|
||||
TAE_NONE = TAE_BEGIN, ///< Cargo has no effect.
|
||||
TAE_PASSENGERS, ///< Cargo behaves passenger-like.
|
||||
TAE_MAIL, ///< Cargo behaves mail-like.
|
||||
TAE_GOODS, ///< Cargo behaves goods/candy-like.
|
||||
TAE_WATER, ///< Cargo behaves water-like.
|
||||
TAE_FOOD, ///< Cargo behaves food/fizzy-drinks-like.
|
||||
TAE_END, ///< End of town effects.
|
||||
NUM_TAE = TAE_END, ///< Amount of town effects.
|
||||
};
|
||||
|
||||
/** Town effect when producing cargo. */
|
||||
enum TownProductionEffect : byte {
|
||||
TPE_NONE, ///< Town will not produce this cargo type.
|
||||
TPE_PASSENGERS, ///< Cargo behaves passenger-like for production.
|
||||
TPE_MAIL, ///< Cargo behaves mail-like for production.
|
||||
NUM_TPE,
|
||||
|
||||
/**
|
||||
* Invalid town production effect. Used as a sentinel to indicate if a NewGRF has explicitly set an effect.
|
||||
* This does not 'exist' after cargo types are finalised.
|
||||
*/
|
||||
INVALID_TPE,
|
||||
};
|
||||
|
||||
/** Cargo classes. */
|
||||
@@ -51,22 +63,27 @@ enum CargoClass {
|
||||
CC_SPECIAL = 1 << 15, ///< Special bit used for livery refit tricks instead of normal cargoes.
|
||||
};
|
||||
|
||||
static const byte INVALID_CARGO = 0xFF; ///< Constant representing invalid cargo
|
||||
static const byte INVALID_CARGO_BITNUM = 0xFF; ///< Constant representing invalid cargo
|
||||
|
||||
static const uint TOWN_PRODUCTION_DIVISOR = 256;
|
||||
|
||||
/** Specification of a cargo type. */
|
||||
struct CargoSpec {
|
||||
uint8 bitnum; ///< Cargo bit number, is #INVALID_CARGO for a non-used spec.
|
||||
CargoLabel label; ///< Unique label of the cargo type.
|
||||
uint8 legend_colour;
|
||||
uint8 rating_colour;
|
||||
uint8 weight; ///< Weight of a single unit of this cargo type in 1/16 ton (62.5 kg).
|
||||
uint16 multiplier; ///< Capacity multiplier for vehicles. (8 fractional bits)
|
||||
int32 initial_payment; ///< Initial payment rate before inflation is applied.
|
||||
uint8 transit_days[2];
|
||||
uint8_t bitnum{INVALID_CARGO_BITNUM}; ///< Cargo bit number, is #INVALID_CARGO_BITNUM for a non-used spec.
|
||||
uint8_t legend_colour;
|
||||
uint8_t rating_colour;
|
||||
uint8_t weight; ///< Weight of a single unit of this cargo type in 1/16 ton (62.5 kg).
|
||||
uint16_t multiplier{0x100}; ///< Capacity multiplier for vehicles. (8 fractional bits)
|
||||
uint16_t classes; ///< Classes of this cargo type. @see CargoClass
|
||||
int32_t initial_payment; ///< Initial payment rate before inflation is applied.
|
||||
uint8_t transit_periods[2];
|
||||
|
||||
bool is_freight; ///< Cargo type is considered to be freight (affects train freight multiplier).
|
||||
TownEffect town_effect; ///< The effect that delivering this cargo type has on towns. Also affects destination of subsidies.
|
||||
uint8 callback_mask; ///< Bitmask of cargo callbacks that have to be called
|
||||
TownAcceptanceEffect town_acceptance_effect; ///< The effect that delivering this cargo type has on towns. Also affects destination of subsidies.
|
||||
TownProductionEffect town_production_effect{INVALID_TPE}; ///< The effect on town cargo production.
|
||||
uint16_t town_production_multiplier{TOWN_PRODUCTION_DIVISOR}; ///< Town production multipler, if commanded by TownProductionEffect.
|
||||
uint8_t callback_mask; ///< Bitmask of cargo callbacks that have to be called
|
||||
|
||||
StringID name; ///< Name of this type of cargo.
|
||||
StringID name_single; ///< Name of a single entity of this type of cargo.
|
||||
@@ -76,7 +93,6 @@ struct CargoSpec {
|
||||
|
||||
SpriteID sprite; ///< Icon to display this cargo type, may be \c 0xFFF (which means to resolve an action123 chain).
|
||||
|
||||
uint16 classes; ///< Classes of this cargo type. @see CargoClass
|
||||
const struct GRFFile *grffile; ///< NewGRF where #group belongs to.
|
||||
const struct SpriteGroup *group;
|
||||
|
||||
@@ -98,7 +114,7 @@ struct CargoSpec {
|
||||
*/
|
||||
inline bool IsValid() const
|
||||
{
|
||||
return this->bitnum != INVALID_CARGO;
|
||||
return this->bitnum != INVALID_CARGO_BITNUM;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -123,12 +139,12 @@ struct CargoSpec {
|
||||
|
||||
SpriteID GetCargoIcon() const;
|
||||
|
||||
inline uint64 WeightOfNUnits(uint32 n) const
|
||||
inline uint64_t WeightOfNUnits(uint32_t n) const
|
||||
{
|
||||
return n * this->weight / 16u;
|
||||
}
|
||||
|
||||
uint64 WeightOfNUnitsInTrain(uint32 n) const;
|
||||
uint64_t WeightOfNUnitsInTrain(uint32_t n) const;
|
||||
|
||||
/**
|
||||
* Iterator to iterate all valid CargoSpec
|
||||
@@ -173,10 +189,14 @@ struct CargoSpec {
|
||||
*/
|
||||
static IterateWrapper Iterate(size_t from = 0) { return IterateWrapper(from); }
|
||||
|
||||
/** List of cargo specs for each Town Product Effect. */
|
||||
static std::array<std::vector<const CargoSpec *>, NUM_TPE> town_production_cargoes;
|
||||
|
||||
private:
|
||||
static CargoSpec array[NUM_CARGO]; ///< Array holding all CargoSpecs
|
||||
|
||||
friend void SetupCargoForClimate(LandscapeID l);
|
||||
friend void FinaliseCargoArray();
|
||||
};
|
||||
|
||||
extern CargoTypes _cargo_mask;
|
||||
@@ -184,12 +204,14 @@ extern CargoTypes _standard_cargo_mask;
|
||||
|
||||
void SetupCargoForClimate(LandscapeID l);
|
||||
CargoID GetCargoIDByLabel(CargoLabel cl);
|
||||
CargoID GetCargoIDByBitnum(uint8 bitnum);
|
||||
CargoID GetCargoIDByBitnum(uint8_t bitnum);
|
||||
CargoID GetDefaultCargoID(LandscapeID l, CargoType ct);
|
||||
Dimension GetLargestCargoIconSize();
|
||||
|
||||
void InitializeSortedCargoSpecs();
|
||||
extern std::array<uint8_t, NUM_CARGO> _sorted_cargo_types;
|
||||
extern std::vector<const CargoSpec *> _sorted_cargo_specs;
|
||||
extern span<const CargoSpec *> _sorted_standard_cargo_specs;
|
||||
extern std::span<const CargoSpec *> _sorted_standard_cargo_specs;
|
||||
|
||||
/**
|
||||
* Does cargo \a c have cargo class \a cc?
|
||||
@@ -197,11 +219,16 @@ extern span<const CargoSpec *> _sorted_standard_cargo_specs;
|
||||
* @param cc Cargo class.
|
||||
* @return The type fits in the class.
|
||||
*/
|
||||
static inline bool IsCargoInClass(CargoID c, CargoClass cc)
|
||||
inline bool IsCargoInClass(CargoID c, CargoClass cc)
|
||||
{
|
||||
return (CargoSpec::Get(c)->classes & cc) != 0;
|
||||
}
|
||||
|
||||
using SetCargoBitIterator = SetBitIterator<CargoID, CargoTypes>;
|
||||
|
||||
/** Comparator to sort CargoID by according to desired order. */
|
||||
struct CargoIDComparator {
|
||||
bool operator() (const CargoID &lhs, const CargoID &rhs) const { return _sorted_cargo_types[lhs] < _sorted_cargo_types[rhs]; }
|
||||
};
|
||||
|
||||
#endif /* CARGOTYPE_H */
|
||||
|
||||
Reference in New Issue
Block a user