From 0d9074769de7a25320bc274c31e039b9f1fdcb3f Mon Sep 17 00:00:00 2001 From: frosch Date: Sat, 26 Apr 2025 14:42:49 +0200 Subject: [PATCH] Change: [NewGRF] Animation-trigger 'construction stage changed' of houses and industries now also triggers at construction start. (#14089) --- src/industry_cmd.cpp | 11 ++++++++++- src/newgrf_house.cpp | 4 ++-- src/newgrf_house.h | 2 +- src/newgrf_industrytiles.cpp | 7 +++++++ src/newgrf_industrytiles.h | 1 + src/town_cmd.cpp | 9 ++++++++- 6 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp index dab8b7c9b9..44068b010b 100644 --- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -763,7 +763,7 @@ static void MakeIndustryTileBigger(TileIndex tile) uint8_t stage = GetIndustryConstructionStage(tile) + 1; SetIndustryConstructionCounter(tile, 0); SetIndustryConstructionStage(tile, stage); - TriggerIndustryTileAnimation(tile, IndustryAnimationTrigger::ConstructionStageChanged); + TriggerIndustryTileAnimation_ConstructionStageChanged(tile, false); if (stage == INDUSTRY_COMPLETED) SetIndustryCompleted(tile); MarkTileDirtyByTile(tile); @@ -1946,6 +1946,15 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, IndustryType type, } } + /* Call callbacks after all tiles have been created. */ + for (TileIndex cur_tile : i->location) { + if (i->TileBelongsToIndustry(cur_tile)) { + /* There are no shared random bits, consistent with "MakeIndustryTileBigger" in tile loop. + * So, trigger tiles individually */ + TriggerIndustryTileAnimation_ConstructionStageChanged(cur_tile, true); + } + } + if (GetIndustrySpec(i->type)->behaviour.Test(IndustryBehaviour::PlantOnBuild)) { for (uint j = 0; j != 50; j++) PlantRandomFarmField(i); } diff --git a/src/newgrf_house.cpp b/src/newgrf_house.cpp index 68002b1b92..0afa5ddd74 100644 --- a/src/newgrf_house.cpp +++ b/src/newgrf_house.cpp @@ -537,12 +537,12 @@ void AnimateNewHouseTile(TileIndex tile) HouseAnimationBase::AnimateTile(hs, Town::GetByTile(tile), tile, hs->extra_flags.Test(HouseExtraFlag::Callback1ARandomBits)); } -void TriggerHouseAnimation_ConstructionStageChanged(TileIndex tile) +void TriggerHouseAnimation_ConstructionStageChanged(TileIndex tile, bool first_call) { const HouseSpec *hs = HouseSpec::Get(GetHouseType(tile)); if (hs->callback_mask.Test(HouseCallbackMask::AnimationTriggerConstructionStageChanged)) { - HouseAnimationBase::ChangeAnimationFrame(CBID_HOUSE_ANIMATION_TRIGGER_CONSTRUCTION_STAGE_CHANGED, hs, Town::GetByTile(tile), tile, 0, 0); + HouseAnimationBase::ChangeAnimationFrame(CBID_HOUSE_ANIMATION_TRIGGER_CONSTRUCTION_STAGE_CHANGED, hs, Town::GetByTile(tile), tile, 0, first_call ? 1 : 0); } } diff --git a/src/newgrf_house.h b/src/newgrf_house.h index 941a9e611a..1201ff9054 100644 --- a/src/newgrf_house.h +++ b/src/newgrf_house.h @@ -100,7 +100,7 @@ std::span GetBuildingHouseIDCounts(); void DrawNewHouseTile(TileInfo *ti, HouseID house_id); void AnimateNewHouseTile(TileIndex tile); /* see also: void TriggerHouseAnimation_TileLoop(TileIndex tile, uint16_t random_bits) */ -void TriggerHouseAnimation_ConstructionStageChanged(TileIndex tile); +void TriggerHouseAnimation_ConstructionStageChanged(TileIndex tile, bool first_call); void TriggerHouseAnimation_WatchedCargoAccepted(TileIndex tile, CargoTypes trigger_cargoes); uint16_t GetHouseCallback(CallbackID callback, uint32_t param1, uint32_t param2, HouseID house_id, Town *town, TileIndex tile, diff --git a/src/newgrf_industrytiles.cpp b/src/newgrf_industrytiles.cpp index 6093580736..76e56c660c 100644 --- a/src/newgrf_industrytiles.cpp +++ b/src/newgrf_industrytiles.cpp @@ -285,8 +285,15 @@ static bool DoTriggerIndustryTileAnimation(TileIndex tile, IndustryAnimationTrig return true; } +bool TriggerIndustryTileAnimation_ConstructionStageChanged(TileIndex tile, bool first_call) +{ + auto iat = IndustryAnimationTrigger::ConstructionStageChanged; + return DoTriggerIndustryTileAnimation(tile, iat, Random(), first_call ? 0x100 : 0); +} + bool TriggerIndustryTileAnimation(TileIndex tile, IndustryAnimationTrigger iat) { + assert(iat != IndustryAnimationTrigger::ConstructionStageChanged); return DoTriggerIndustryTileAnimation(tile, iat, Random()); } diff --git a/src/newgrf_industrytiles.h b/src/newgrf_industrytiles.h index 6bcf7aa0ab..c74817c5a9 100644 --- a/src/newgrf_industrytiles.h +++ b/src/newgrf_industrytiles.h @@ -63,6 +63,7 @@ CommandCost PerformIndustryTileSlopeCheck(TileIndex ind_base_tile, TileIndex ind void AnimateNewIndustryTile(TileIndex tile); bool TriggerIndustryTileAnimation(TileIndex tile, IndustryAnimationTrigger iat); +bool TriggerIndustryTileAnimation_ConstructionStageChanged(TileIndex tile, bool first_call); bool TriggerIndustryAnimation(const Industry *ind, IndustryAnimationTrigger iat); void TriggerIndustryTileRandomisation(TileIndex t, IndustryRandomTrigger trigger); diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index 92196a59da..4a1d865499 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -503,7 +503,7 @@ static void AdvanceSingleHouseConstruction(TileIndex tile) IncHouseConstructionTick(tile); if (GetHouseConstructionTick(tile) != 0) return; - TriggerHouseAnimation_ConstructionStageChanged(tile); + TriggerHouseAnimation_ConstructionStageChanged(tile, false); if (IsHouseCompleted(tile)) { /* Now that construction is complete, we can add the population of the @@ -2705,6 +2705,13 @@ static void BuildTownHouse(Town *t, TileIndex tile, const HouseSpec *hs, HouseID MakeTownHouse(tile, t, construction_counter, construction_stage, house, random_bits, is_protected); UpdateTownRadius(t); UpdateTownGrowthRate(t); + + BuildingFlags size = hs->building_flags; + + TriggerHouseAnimation_ConstructionStageChanged(tile, true); + if (size.Any(BUILDING_2_TILES_Y)) TriggerHouseAnimation_ConstructionStageChanged(tile + TileDiffXY(0, 1), true); + if (size.Any(BUILDING_2_TILES_X)) TriggerHouseAnimation_ConstructionStageChanged(tile + TileDiffXY(1, 0), true); + if (size.Any(BUILDING_HAS_4_TILES)) TriggerHouseAnimation_ConstructionStageChanged(tile + TileDiffXY(1, 1), true); } /**