mirror of
https://github.com/OpenTTD/OpenTTD
synced 2026-01-21 19:32:54 +01:00
Codechange: Use EnumBitSet for callback masks.
This commit is contained in:
committed by
Peter Nelson
parent
1dd4adc50c
commit
40aeedeade
@@ -403,7 +403,7 @@ static Foundation GetFoundation_Industry(TileIndex tile, Slope tileh)
|
||||
*/
|
||||
if (gfx >= NEW_INDUSTRYTILEOFFSET) {
|
||||
const IndustryTileSpec *indts = GetIndustryTileSpec(gfx);
|
||||
if (indts->grf_prop.spritegroup[0] != nullptr && HasBit(indts->callback_mask, CBM_INDT_DRAW_FOUNDATIONS)) {
|
||||
if (indts->grf_prop.spritegroup[0] != nullptr && indts->callback_mask.Test(IndustryTileCallbackMask::DrawFoundations)) {
|
||||
uint32_t callback_res = GetIndustryTileCallback(CBID_INDTILE_DRAW_FOUNDATIONS, 0, 0, gfx, Industry::GetByTile(tile), tile);
|
||||
if (callback_res != CALLBACK_FAILED && !ConvertBooleanCallback(indts->grf_prop.grffile, CBID_INDTILE_DRAW_FOUNDATIONS, callback_res)) return FOUNDATION_NONE;
|
||||
}
|
||||
@@ -435,7 +435,7 @@ static void AddAcceptedCargo_Industry(TileIndex tile, CargoArray &acceptance, Ca
|
||||
}
|
||||
}
|
||||
|
||||
if (HasBit(itspec->callback_mask, CBM_INDT_ACCEPT_CARGO)) {
|
||||
if (itspec->callback_mask.Test(IndustryTileCallbackMask::AcceptCargo)) {
|
||||
/* Try callback for accepts list, if success override all existing accepts */
|
||||
uint16_t res = GetIndustryTileCallback(CBID_INDTILE_ACCEPT_CARGO, 0, 0, gfx, Industry::GetByTile(tile), tile);
|
||||
if (res != CALLBACK_FAILED) {
|
||||
@@ -444,7 +444,7 @@ static void AddAcceptedCargo_Industry(TileIndex tile, CargoArray &acceptance, Ca
|
||||
}
|
||||
}
|
||||
|
||||
if (HasBit(itspec->callback_mask, CBM_INDT_CARGO_ACCEPTANCE)) {
|
||||
if (itspec->callback_mask.Test(IndustryTileCallbackMask::CargoAcceptance)) {
|
||||
/* Try callback for acceptance list, if success override all existing acceptance */
|
||||
uint16_t res = GetIndustryTileCallback(CBID_INDTILE_CARGO_ACCEPTANCE, 0, 0, gfx, Industry::GetByTile(tile), tile);
|
||||
if (res != CALLBACK_FAILED) {
|
||||
@@ -1182,7 +1182,7 @@ static void ProduceIndustryGoods(Industry *i)
|
||||
i->counter--;
|
||||
|
||||
/* If using an industry callback, scale the callback interval by cargo scale percentage. */
|
||||
if (HasBit(indsp->callback_mask, CBM_IND_PRODUCTION_256_TICKS)) {
|
||||
if (indsp->callback_mask.Test(IndustryCallbackMask::Production256Ticks)) {
|
||||
if (i->counter % ScaleByInverseCargoScale(Ticks::INDUSTRY_PRODUCE_TICKS, false) == 0) {
|
||||
IndustryProductionCallback(i, 1);
|
||||
ProduceIndustryGoodsHelper(i, false);
|
||||
@@ -1195,13 +1195,13 @@ static void ProduceIndustryGoods(Industry *i)
|
||||
*/
|
||||
if ((i->counter % Ticks::INDUSTRY_PRODUCE_TICKS) == 0) {
|
||||
/* Handle non-callback cargo production. */
|
||||
if (!HasBit(indsp->callback_mask, CBM_IND_PRODUCTION_256_TICKS)) ProduceIndustryGoodsHelper(i, true);
|
||||
if (!indsp->callback_mask.Test(IndustryCallbackMask::Production256Ticks)) ProduceIndustryGoodsHelper(i, true);
|
||||
|
||||
IndustryBehaviour indbehav = indsp->behaviour;
|
||||
|
||||
if ((indbehav & INDUSTRYBEH_PLANT_FIELDS) != 0) {
|
||||
uint16_t cb_res = CALLBACK_FAILED;
|
||||
if (HasBit(indsp->callback_mask, CBM_IND_SPECIAL_EFFECT)) {
|
||||
if (indsp->callback_mask.Test(IndustryCallbackMask::SpecialEffect)) {
|
||||
cb_res = GetIndustryCallback(CBID_INDUSTRY_SPECIAL_EFFECT, Random(), 0, i, i->type, i->location.tile);
|
||||
}
|
||||
|
||||
@@ -1216,7 +1216,7 @@ static void ProduceIndustryGoods(Industry *i)
|
||||
}
|
||||
if ((indbehav & INDUSTRYBEH_CUT_TREES) != 0) {
|
||||
uint16_t cb_res = CALLBACK_FAILED;
|
||||
if (HasBit(indsp->callback_mask, CBM_IND_SPECIAL_EFFECT)) {
|
||||
if (indsp->callback_mask.Test(IndustryCallbackMask::SpecialEffect)) {
|
||||
cb_res = GetIndustryCallback(CBID_INDUSTRY_SPECIAL_EFFECT, Random(), 1, i, i->type, i->location.tile);
|
||||
}
|
||||
|
||||
@@ -1545,7 +1545,7 @@ static CommandCost CheckIfIndustryTileSlopes(TileIndex tile, const IndustryTileL
|
||||
if (gfx != GFX_WATERTILE_SPECIALCHECK) {
|
||||
const IndustryTileSpec *its = GetIndustryTileSpec(gfx);
|
||||
|
||||
if (HasBit(its->callback_mask, CBM_INDT_SHAPE_CHECK)) {
|
||||
if (its->callback_mask.Test(IndustryTileCallbackMask::ShapeCheck)) {
|
||||
custom_shape = true;
|
||||
CommandCost ret = PerformIndustryTileSlopeCheck(tile, cur_tile, its, type, gfx, layout_index, initial_random_bits, founder, creation_type);
|
||||
if (ret.Failed()) return ret;
|
||||
@@ -1822,7 +1822,7 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, IndustryType type,
|
||||
|
||||
/* Call callbacks after the regular fields got initialised. */
|
||||
|
||||
if (HasBit(indspec->callback_mask, CBM_IND_PROD_CHANGE_BUILD)) {
|
||||
if (indspec->callback_mask.Test(IndustryCallbackMask::ProdChangeBuild)) {
|
||||
uint16_t res = GetIndustryCallback(CBID_INDUSTRY_PROD_CHANGE_BUILD, 0, Random(), i, type, INVALID_TILE);
|
||||
if (res != CALLBACK_FAILED) {
|
||||
if (res < PRODLEVEL_MINIMUM || res > PRODLEVEL_MAXIMUM) {
|
||||
@@ -1835,7 +1835,7 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, IndustryType type,
|
||||
}
|
||||
|
||||
if (_generating_world) {
|
||||
if (HasBit(indspec->callback_mask, CBM_IND_PRODUCTION_256_TICKS)) {
|
||||
if (indspec->callback_mask.Test(IndustryCallbackMask::Production256Ticks)) {
|
||||
IndustryProductionCallback(i, 1);
|
||||
for (auto &p : i->produced) {
|
||||
p.history[LAST_MONTH].production = p.waiting * 8;
|
||||
@@ -1848,7 +1848,7 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, IndustryType type,
|
||||
}
|
||||
}
|
||||
|
||||
if (HasBit(indspec->callback_mask, CBM_IND_DECIDE_COLOUR)) {
|
||||
if (indspec->callback_mask.Test(IndustryCallbackMask::DecideColour)) {
|
||||
uint16_t res = GetIndustryCallback(CBID_INDUSTRY_DECIDE_COLOUR, 0, 0, i, type, INVALID_TILE);
|
||||
if (res != CALLBACK_FAILED) {
|
||||
if (GB(res, 4, 11) != 0) ErrorUnknownCallbackResult(indspec->grf_prop.grfid, CBID_INDUSTRY_DECIDE_COLOUR, res);
|
||||
@@ -1856,7 +1856,7 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, IndustryType type,
|
||||
}
|
||||
}
|
||||
|
||||
if (HasBit(indspec->callback_mask, CBM_IND_INPUT_CARGO_TYPES)) {
|
||||
if (indspec->callback_mask.Test(IndustryCallbackMask::InputCargoTypes)) {
|
||||
/* Clear all input cargo types */
|
||||
i->accepted.clear();
|
||||
/* Query actual types */
|
||||
@@ -1894,7 +1894,7 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, IndustryType type,
|
||||
}
|
||||
}
|
||||
|
||||
if (HasBit(indspec->callback_mask, CBM_IND_OUTPUT_CARGO_TYPES)) {
|
||||
if (indspec->callback_mask.Test(IndustryCallbackMask::OutputCargoTypes)) {
|
||||
/* Clear all output cargo types */
|
||||
i->produced.clear();
|
||||
/* Query actual types */
|
||||
@@ -2007,7 +2007,7 @@ static CommandCost CreateNewIndustryHelper(TileIndex tile, IndustryType type, Do
|
||||
if (ret.Failed()) return ret;
|
||||
|
||||
/* 3. NewGRF-defined checks on industry level. */
|
||||
if (HasBit(GetIndustrySpec(type)->callback_mask, CBM_IND_LOCATION)) {
|
||||
if (GetIndustrySpec(type)->callback_mask.Test(IndustryCallbackMask::Location)) {
|
||||
ret = CheckIfCallBackAllowsCreation(tile, type, layout_index, random_var8f, random_initial_bits, founder, creation_type);
|
||||
} else {
|
||||
ret = _check_new_industry_procs[indspec->check_proc](tile);
|
||||
@@ -2806,7 +2806,7 @@ static void ChangeIndustryProduction(Industry *i, bool monthly)
|
||||
uint8_t mul = 0;
|
||||
int8_t increment = 0;
|
||||
|
||||
bool callback_enabled = HasBit(indspec->callback_mask, monthly ? CBM_IND_MONTHLYPROD_CHANGE : CBM_IND_PRODUCTION_CHANGE);
|
||||
bool callback_enabled = indspec->callback_mask.Test(monthly ? IndustryCallbackMask::MonthlyProdChange : IndustryCallbackMask::ProductionChange);
|
||||
if (callback_enabled) {
|
||||
uint16_t res = GetIndustryCallback(monthly ? CBID_INDUSTRY_MONTHLYPROD_CHANGE : CBID_INDUSTRY_PRODUCTION_CHANGE, 0, Random(), i, i->type, i->location.tile);
|
||||
if (res != CALLBACK_FAILED) { // failed callback means "do nothing"
|
||||
@@ -3150,8 +3150,12 @@ Money IndustrySpec::GetRemovalCost() const
|
||||
bool IndustrySpec::UsesOriginalEconomy() const
|
||||
{
|
||||
return _settings_game.economy.type == ET_ORIGINAL ||
|
||||
HasBit(this->callback_mask, CBM_IND_PRODUCTION_256_TICKS) || HasBit(this->callback_mask, CBM_IND_PRODUCTION_CARGO_ARRIVAL) || // production callbacks
|
||||
HasBit(this->callback_mask, CBM_IND_MONTHLYPROD_CHANGE) || HasBit(this->callback_mask, CBM_IND_PRODUCTION_CHANGE) || HasBit(this->callback_mask, CBM_IND_PROD_CHANGE_BUILD); // production change callbacks
|
||||
this->callback_mask.Any({
|
||||
IndustryCallbackMask::Production256Ticks,
|
||||
IndustryCallbackMask::ProductionCargoArrival, // production callbacks
|
||||
IndustryCallbackMask::MonthlyProdChange,
|
||||
IndustryCallbackMask::ProductionChange,
|
||||
IndustryCallbackMask::ProdChangeBuild}); // production change callbacks
|
||||
}
|
||||
|
||||
static CommandCost TerraformTile_Industry(TileIndex tile, DoCommandFlag flags, int z_new, Slope tileh_new)
|
||||
@@ -3170,7 +3174,7 @@ static CommandCost TerraformTile_Industry(TileIndex tile, DoCommandFlag flags, i
|
||||
const IndustryTileSpec *itspec = GetIndustryTileSpec(gfx);
|
||||
|
||||
/* Call callback 3C 'disable autosloping for industry tiles'. */
|
||||
if (HasBit(itspec->callback_mask, CBM_INDT_AUTOSLOPE)) {
|
||||
if (itspec->callback_mask.Test(IndustryTileCallbackMask::Autoslope)) {
|
||||
/* If the callback fails, allow autoslope. */
|
||||
uint16_t res = GetIndustryTileCallback(CBID_INDTILE_AUTOSLOPE, 0, 0, gfx, Industry::GetByTile(tile), tile);
|
||||
if (res == CALLBACK_FAILED || !ConvertBooleanCallback(itspec->grf_prop.grffile, CBID_INDTILE_AUTOSLOPE, res)) return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]);
|
||||
|
||||
Reference in New Issue
Block a user