mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Use EnumBitSet for GrfMiscBits. (#13873)
parent
af49320637
commit
21d2a94809
|
@ -119,7 +119,7 @@ static void DrawTile_Clear(TileInfo *ti)
|
|||
break;
|
||||
|
||||
case CLEAR_ROCKS:
|
||||
DrawGroundSprite((HasGrfMiscBit(GMB_SECOND_ROCKY_TILE_SET) && (TileHash(ti->x, ti->y) & 1) ? SPR_FLAT_ROCKY_LAND_2 : SPR_FLAT_ROCKY_LAND_1) + SlopeToSpriteOffset(ti->tileh), PAL_NONE);
|
||||
DrawGroundSprite((HasGrfMiscBit(GrfMiscBit::SecondRockyTileSet) && (TileHash(ti->x, ti->y) & 1) ? SPR_FLAT_ROCKY_LAND_2 : SPR_FLAT_ROCKY_LAND_1) + SlopeToSpriteOffset(ti->tileh), PAL_NONE);
|
||||
break;
|
||||
|
||||
case CLEAR_FIELDS:
|
||||
|
|
|
@ -78,7 +78,7 @@ const std::vector<GRFFile *> &GetAllGRFFiles()
|
|||
}
|
||||
|
||||
/** Miscellaneous GRF features, set by Action 0x0D, parameter 0x9E */
|
||||
uint8_t _misc_grf_features = 0;
|
||||
GrfMiscBits _misc_grf_features{};
|
||||
|
||||
/** 32 * 8 = 256 flags. Apparently TTDPatch uses this many.. */
|
||||
static uint32_t _ttdpatch_flags[8];
|
||||
|
@ -6953,13 +6953,16 @@ bool GetGlobalVariable(uint8_t param, uint32_t *value, const GRFFile *grffile)
|
|||
*value = 1;
|
||||
return true;
|
||||
|
||||
case 0x1E: // Miscellaneous GRF features
|
||||
*value = _misc_grf_features;
|
||||
case 0x1E: { // Miscellaneous GRF features
|
||||
GrfMiscBits bits = _misc_grf_features;
|
||||
|
||||
/* Add the local flags */
|
||||
assert(!HasBit(*value, GMB_TRAIN_WIDTH_32_PIXELS));
|
||||
if (_cur.grffile->traininfo_vehicle_width == VEHICLEINFO_FULL_VEHICLE_WIDTH) SetBit(*value, GMB_TRAIN_WIDTH_32_PIXELS);
|
||||
assert(!bits.Test(GrfMiscBit::TrainWidth32Pixels));
|
||||
if (_cur.grffile->traininfo_vehicle_width == VEHICLEINFO_FULL_VEHICLE_WIDTH) bits.Set(GrfMiscBit::TrainWidth32Pixels);
|
||||
|
||||
*value = bits.base();
|
||||
return true;
|
||||
}
|
||||
|
||||
/* case 0x1F: // locale dependent settings not implemented to avoid desync */
|
||||
|
||||
|
@ -8000,22 +8003,25 @@ static void ParamSet(ByteReader &buf)
|
|||
GrfMsg(7, "ParamSet: Skipping unimplemented target 0x{:02X}", target);
|
||||
break;
|
||||
|
||||
case 0x9E: // Miscellaneous GRF features
|
||||
case 0x9E: { // Miscellaneous GRF features
|
||||
GrfMiscBits bits(res);
|
||||
|
||||
/* Set train list engine width */
|
||||
_cur.grffile->traininfo_vehicle_width = HasBit(res, GMB_TRAIN_WIDTH_32_PIXELS) ? VEHICLEINFO_FULL_VEHICLE_WIDTH : TRAININFO_DEFAULT_VEHICLE_WIDTH;
|
||||
_cur.grffile->traininfo_vehicle_width = bits.Test(GrfMiscBit::TrainWidth32Pixels) ? VEHICLEINFO_FULL_VEHICLE_WIDTH : TRAININFO_DEFAULT_VEHICLE_WIDTH;
|
||||
/* Remove the local flags from the global flags */
|
||||
ClrBit(res, GMB_TRAIN_WIDTH_32_PIXELS);
|
||||
bits.Reset(GrfMiscBit::TrainWidth32Pixels);
|
||||
|
||||
/* Only copy safe bits for static grfs */
|
||||
if (_cur.grfconfig->flags.Test(GRFConfigFlag::Static)) {
|
||||
uint32_t safe_bits = 0;
|
||||
SetBit(safe_bits, GMB_SECOND_ROCKY_TILE_SET);
|
||||
GrfMiscBits safe_bits = GrfMiscBit::SecondRockyTileSet;
|
||||
|
||||
_misc_grf_features = (_misc_grf_features & ~safe_bits) | (res & safe_bits);
|
||||
_misc_grf_features.Reset(safe_bits);
|
||||
_misc_grf_features.Set(bits & safe_bits);
|
||||
} else {
|
||||
_misc_grf_features = res;
|
||||
_misc_grf_features = bits;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 0x9F: // locale-dependent settings
|
||||
GrfMsg(7, "ParamSet: Skipping unimplemented target 0x{:02X}", target);
|
||||
|
@ -9134,7 +9140,7 @@ void ResetNewGRFData()
|
|||
SetupCargoForClimate(_settings_game.game_creation.landscape);
|
||||
|
||||
/* Reset misc GRF features and train list display variables */
|
||||
_misc_grf_features = 0;
|
||||
_misc_grf_features = {};
|
||||
|
||||
_loaded_newgrf_features.has_2CC = false;
|
||||
_loaded_newgrf_features.used_liveries = 1 << LS_DEFAULT;
|
||||
|
|
22
src/newgrf.h
22
src/newgrf.h
|
@ -55,16 +55,18 @@ enum GrfLoadingStage : uint8_t {
|
|||
|
||||
DECLARE_INCREMENT_DECREMENT_OPERATORS(GrfLoadingStage)
|
||||
|
||||
enum GrfMiscBit : uint8_t {
|
||||
GMB_DESERT_TREES_FIELDS = 0, // Unsupported.
|
||||
GMB_DESERT_PAVED_ROADS = 1,
|
||||
GMB_FIELD_BOUNDING_BOX = 2, // Unsupported.
|
||||
GMB_TRAIN_WIDTH_32_PIXELS = 3, ///< Use 32 pixels per train vehicle in depot gui and vehicle details. Never set in the global variable; @see GRFFile::traininfo_vehicle_width
|
||||
GMB_AMBIENT_SOUND_CALLBACK = 4,
|
||||
GMB_CATENARY_ON_3RD_TRACK = 5, // Unsupported.
|
||||
GMB_SECOND_ROCKY_TILE_SET = 6,
|
||||
enum class GrfMiscBit : uint8_t {
|
||||
DesertTreesFields = 0, // Unsupported.
|
||||
DesertPavedRoads = 1,
|
||||
FieldBoundingBox = 2, // Unsupported.
|
||||
TrainWidth32Pixels = 3, ///< Use 32 pixels per train vehicle in depot gui and vehicle details. Never set in the global variable; @see GRFFile::traininfo_vehicle_width
|
||||
AmbientSoundCallback = 4,
|
||||
CatenaryOn3rdTrack = 5, // Unsupported.
|
||||
SecondRockyTileSet = 6,
|
||||
};
|
||||
|
||||
using GrfMiscBits = EnumBitSet<GrfMiscBit, uint8_t>;
|
||||
|
||||
enum GrfSpecFeature : uint8_t {
|
||||
GSF_TRAINS,
|
||||
GSF_ROADVEHICLES,
|
||||
|
@ -192,8 +194,8 @@ struct GRFLoadedFeatures {
|
|||
*/
|
||||
inline bool HasGrfMiscBit(GrfMiscBit bit)
|
||||
{
|
||||
extern uint8_t _misc_grf_features;
|
||||
return HasBit(_misc_grf_features, bit);
|
||||
extern GrfMiscBits _misc_grf_features;
|
||||
return _misc_grf_features.Test(bit);
|
||||
}
|
||||
|
||||
/* Indicates which are the newgrf features currently loaded ingame */
|
||||
|
|
|
@ -54,7 +54,7 @@ void AmbientSoundEffectCallback(TileIndex tile);
|
|||
inline void AmbientSoundEffect(TileIndex tile)
|
||||
{
|
||||
/* Only run callback if enabled. */
|
||||
if (!HasGrfMiscBit(GMB_AMBIENT_SOUND_CALLBACK)) return;
|
||||
if (!HasGrfMiscBit(GrfMiscBit::AmbientSoundCallback)) return;
|
||||
|
||||
AmbientSoundEffectCallback(tile);
|
||||
}
|
||||
|
|
|
@ -1362,7 +1362,7 @@ static uint GetRoadSpriteOffset(Slope slope, RoadBits bits)
|
|||
static bool DrawRoadAsSnowDesert(bool snow_or_desert, Roadside roadside)
|
||||
{
|
||||
return (snow_or_desert &&
|
||||
!(_settings_game.game_creation.landscape == LandscapeType::Tropic && HasGrfMiscBit(GMB_DESERT_PAVED_ROADS) &&
|
||||
!(_settings_game.game_creation.landscape == LandscapeType::Tropic && HasGrfMiscBit(GrfMiscBit::DesertPavedRoads) &&
|
||||
roadside != ROADSIDE_BARREN && roadside != ROADSIDE_GRASS && roadside != ROADSIDE_GRASS_ROAD_WORKS));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue