(svn r10167) -Codechange: Change the flagging system of grf loaded feature from a bitset to a bool evaluation.

Like easier to read and faster to evaluate :)
pull/155/head
belugas 17 years ago
parent 77b29ea3bc
commit 0f0b58d429

@ -76,7 +76,7 @@ static uint32 _ttdpatch_flags[8];
static byte *_preload_sprite = NULL; static byte *_preload_sprite = NULL;
/* Indicates which are the newgrf features currently loaded ingame */ /* Indicates which are the newgrf features currently loaded ingame */
uint8 _loaded_newgrf_features; GRFLoadedFeatures _loaded_newgrf_features;
enum GrfDataType { enum GrfDataType {
GDT_SOUND, GDT_SOUND,
@ -539,7 +539,7 @@ static bool RailVehicleChangeInfo(uint engine, int numinfo, int prop, byte **buf
case 0x27: // Miscellaneous flags case 0x27: // Miscellaneous flags
FOR_EACH_OBJECT { FOR_EACH_OBJECT {
ei[i].misc_flags = grf_load_byte(&buf); ei[i].misc_flags = grf_load_byte(&buf);
if (HASBIT(ei[i].misc_flags, EF_USES_2CC)) SETBIT(_loaded_newgrf_features, GRFLOADED_2CC); _loaded_newgrf_features.has_2CC = HASBIT(ei[i].misc_flags, EF_USES_2CC);
} }
break; break;
@ -661,7 +661,7 @@ static bool RoadVehicleChangeInfo(uint engine, int numinfo, int prop, byte **buf
case 0x1C: // Miscellaneous flags case 0x1C: // Miscellaneous flags
FOR_EACH_OBJECT { FOR_EACH_OBJECT {
ei[i].misc_flags = grf_load_byte(&buf); ei[i].misc_flags = grf_load_byte(&buf);
if (HASBIT(ei[i].misc_flags, EF_USES_2CC)) SETBIT(_loaded_newgrf_features, GRFLOADED_2CC); _loaded_newgrf_features.has_2CC = HASBIT(ei[i].misc_flags, EF_USES_2CC);
} }
break; break;
@ -772,7 +772,7 @@ static bool ShipVehicleChangeInfo(uint engine, int numinfo, int prop, byte **buf
case 0x17: // Miscellaneous flags case 0x17: // Miscellaneous flags
FOR_EACH_OBJECT { FOR_EACH_OBJECT {
ei[i].misc_flags = grf_load_byte(&buf); ei[i].misc_flags = grf_load_byte(&buf);
if (HASBIT(ei[i].misc_flags, EF_USES_2CC)) SETBIT(_loaded_newgrf_features, GRFLOADED_2CC); _loaded_newgrf_features.has_2CC = HASBIT(ei[i].misc_flags, EF_USES_2CC);
} }
break; break;
@ -888,7 +888,7 @@ static bool AircraftVehicleChangeInfo(uint engine, int numinfo, int prop, byte *
case 0x17: // Miscellaneous flags case 0x17: // Miscellaneous flags
FOR_EACH_OBJECT { FOR_EACH_OBJECT {
ei[i].misc_flags = grf_load_byte(&buf); ei[i].misc_flags = grf_load_byte(&buf);
if (HASBIT(ei[i].misc_flags, EF_USES_2CC)) SETBIT(_loaded_newgrf_features, GRFLOADED_2CC); _loaded_newgrf_features.has_2CC = HASBIT(ei[i].misc_flags, EF_USES_2CC);
} }
break; break;
@ -1297,7 +1297,7 @@ static bool TownHouseChangeInfo(uint hid, int numinfo, int prop, byte **bufp, in
* FinaliseHouseArray() for more details. */ * FinaliseHouseArray() for more details. */
if (housespec[i]->min_date < 1930) housespec[i]->min_date = 1930; if (housespec[i]->min_date < 1930) housespec[i]->min_date = 1930;
} }
SETBIT(_loaded_newgrf_features, GRFLOADED_NEWHOUSES); _loaded_newgrf_features.has_newhouses = true;
break; break;
case 0x09: // Building flags case 0x09: // Building flags
@ -4490,7 +4490,9 @@ static void ResetNewGRFData()
_traininfo_vehicle_pitch = 0; _traininfo_vehicle_pitch = 0;
_traininfo_vehicle_width = 29; _traininfo_vehicle_width = 29;
_loaded_newgrf_features = 0; _loaded_newgrf_features.has_2CC = false;
_loaded_newgrf_features.has_newhouses = false;
_loaded_newgrf_features.has_newindustries = false,
_signal_base = 0; _signal_base = 0;
_coast_base = 0; _coast_base = 0;

@ -88,14 +88,14 @@ extern GRFFile *_first_grffile;
extern SpriteID _signal_base; extern SpriteID _signal_base;
extern SpriteID _coast_base; extern SpriteID _coast_base;
enum GRFLoadedFeatures { struct GRFLoadedFeatures {
GRFLOADED_2CC, // Set if any vehicle is loaded which uses 2cc (two company colours). bool has_2CC; ///< Set if any vehicle is loaded which uses 2cc (two company colours).
GRFLOADED_NEWHOUSES, // Set if there are any newhouses loaded. bool has_newhouses; ///< Set if there are any newhouses loaded.
GRFLOADED_NEWINDUSTRIES, // Set if there are any newindustries loaded. bool has_newindustries; ///< Set if there are any newindustries loaded.
}; };
/* Indicates which are the newgrf features currently loaded ingame */ /* Indicates which are the newgrf features currently loaded ingame */
extern uint8 _loaded_newgrf_features; extern GRFLoadedFeatures _loaded_newgrf_features;
void LoadNewGRFFile(GRFConfig *config, uint file_index, GrfLoadingStage stage); void LoadNewGRFFile(GRFConfig *config, uint file_index, GrfLoadingStage stage);
void LoadNewGRF(uint load_index, uint file_index); void LoadNewGRF(uint load_index, uint file_index);

@ -83,7 +83,7 @@ void IncreaseBuildingCount(Town *t, HouseID house_id)
{ {
HouseClassID class_id = GetHouseSpecs(house_id)->class_id; HouseClassID class_id = GetHouseSpecs(house_id)->class_id;
if (!HASBIT(_loaded_newgrf_features, GRFLOADED_NEWHOUSES)) return; if (!_loaded_newgrf_features.has_newhouses) return;
/* If there are 255 buildings of this type in this town, there are also /* If there are 255 buildings of this type in this town, there are also
* at least that many houses of the same class in the town, and * at least that many houses of the same class in the town, and
@ -111,7 +111,7 @@ void DecreaseBuildingCount(Town *t, HouseID house_id)
{ {
HouseClassID class_id = GetHouseSpecs(house_id)->class_id; HouseClassID class_id = GetHouseSpecs(house_id)->class_id;
if (!HASBIT(_loaded_newgrf_features, GRFLOADED_NEWHOUSES)) return; if (!_loaded_newgrf_features.has_newhouses) return;
if (t->building_counts.id_count[house_id] > 0) t->building_counts.id_count[house_id]--; if (t->building_counts.id_count[house_id] > 0) t->building_counts.id_count[house_id]--;
if (_building_counts.id_count[house_id] > 0) _building_counts.id_count[house_id]--; if (_building_counts.id_count[house_id] > 0) _building_counts.id_count[house_id]--;
@ -129,7 +129,7 @@ void DecreaseBuildingCount(Town *t, HouseID house_id)
*/ */
void AfterLoadCountBuildings() void AfterLoadCountBuildings()
{ {
if (!HASBIT(_loaded_newgrf_features, GRFLOADED_NEWHOUSES)) return; if (!_loaded_newgrf_features.has_newhouses) return;
for (TileIndex t = 0; t < MapSize(); t++) { for (TileIndex t = 0; t < MapSize(); t++) {
if (!IsTileType(t, MP_HOUSE)) continue; if (!IsTileType(t, MP_HOUSE)) continue;

@ -329,7 +329,7 @@ static void SelectPlayerLiveryWndProc(Window *w, WindowEvent *e)
switch (e->event) { switch (e->event) {
case WE_CREATE: case WE_CREATE:
LowerWindowWidget(w, WP(w, livery_d).livery_class + 2); LowerWindowWidget(w, WP(w, livery_d).livery_class + 2);
if (!HASBIT(_loaded_newgrf_features, GRFLOADED_2CC)) { if (!_loaded_newgrf_features.has_2CC) {
HideWindowWidget(w, 11); HideWindowWidget(w, 11);
HideWindowWidget(w, 12); HideWindowWidget(w, 12);
} }
@ -371,7 +371,7 @@ static void SelectPlayerLiveryWndProc(Window *w, WindowEvent *e)
DrawSprite(SPR_SQUARE, GENERAL_SPRITE_COLOR(p->livery[scheme].colour1), 152, y); DrawSprite(SPR_SQUARE, GENERAL_SPRITE_COLOR(p->livery[scheme].colour1), 152, y);
DrawString(165, y, STR_00D1_DARK_BLUE + p->livery[scheme].colour1, sel ? 0xC : 2); DrawString(165, y, STR_00D1_DARK_BLUE + p->livery[scheme].colour1, sel ? 0xC : 2);
if (HASBIT(_loaded_newgrf_features, GRFLOADED_2CC)) { if (_loaded_newgrf_features.has_2CC) {
DrawSprite(SPR_SQUARE, GENERAL_SPRITE_COLOR(p->livery[scheme].colour2), 277, y); DrawSprite(SPR_SQUARE, GENERAL_SPRITE_COLOR(p->livery[scheme].colour2), 277, y);
DrawString(290, y, STR_00D1_DARK_BLUE + p->livery[scheme].colour2, sel ? 0xC : 2); DrawString(290, y, STR_00D1_DARK_BLUE + p->livery[scheme].colour2, sel ? 0xC : 2);
} }
@ -799,7 +799,7 @@ static void PlayerCompanyWndProc(Window *w, WindowEvent *e)
} }
case PCW_WIDGET_COLOR_SCHEME: { case PCW_WIDGET_COLOR_SCHEME: {
Window *wf = AllocateWindowDescFront(HASBIT(_loaded_newgrf_features, GRFLOADED_2CC) ? &_select_player_livery_2cc_desc : &_select_player_livery_desc, w->window_number); Window *wf = AllocateWindowDescFront(_loaded_newgrf_features.has_2CC ? &_select_player_livery_2cc_desc : &_select_player_livery_desc, w->window_number);
if (wf != NULL) { if (wf != NULL) {
wf->caption_color = wf->window_number; wf->caption_color = wf->window_number;
WP(wf, livery_d).livery_class = LC_OTHER; WP(wf, livery_d).livery_class = LC_OTHER;

@ -1668,7 +1668,7 @@ static void DoBuildTownHouse(Town *t, TileIndex tile)
for (i = 0; i < HOUSE_MAX; i++) { for (i = 0; i < HOUSE_MAX; i++) {
hs = GetHouseSpecs(i); hs = GetHouseSpecs(i);
if ((~hs->building_availability & bitmask) == 0 && hs->enabled) { if ((~hs->building_availability & bitmask) == 0 && hs->enabled) {
if (HASBIT(_loaded_newgrf_features, GRFLOADED_NEWHOUSES)) { if (_loaded_newgrf_features.has_newhouses) {
probability_max += hs->probability; probability_max += hs->probability;
cumulative_probs[num] = probability_max; cumulative_probs[num] = probability_max;
} }
@ -1677,7 +1677,7 @@ static void DoBuildTownHouse(Town *t, TileIndex tile)
} }
for (;;) { for (;;) {
if (HASBIT(_loaded_newgrf_features, GRFLOADED_NEWHOUSES)) { if (_loaded_newgrf_features.has_newhouses) {
uint r = RandomRange(probability_max); uint r = RandomRange(probability_max);
for (i = 0; i < num; i++) if (cumulative_probs[i] >= r) break; for (i = 0; i < num; i++) if (cumulative_probs[i] >= r) break;
@ -1688,7 +1688,7 @@ static void DoBuildTownHouse(Town *t, TileIndex tile)
hs = GetHouseSpecs(house); hs = GetHouseSpecs(house);
if (HASBIT(_loaded_newgrf_features, GRFLOADED_NEWHOUSES)) { if (_loaded_newgrf_features.has_newhouses) {
if (hs->override != 0) hs = GetHouseSpecs(hs->override); if (hs->override != 0) hs = GetHouseSpecs(hs->override);
if ((hs->extra_flags & BUILDING_IS_HISTORICAL) && !_generating_world) continue; if ((hs->extra_flags & BUILDING_IS_HISTORICAL) && !_generating_world) continue;

Loading…
Cancel
Save