diff --git a/src/newgrf_optimiser.cpp b/src/newgrf_optimiser.cpp index 59a9bb591a..708776f6db 100644 --- a/src/newgrf_optimiser.cpp +++ b/src/newgrf_optimiser.cpp @@ -2647,7 +2647,7 @@ void OptimiseVarAction2DeterministicSpriteGroup(VarAction2OptimiseState &state, } } if (sg != nullptr && sg->type == SGT_CALLBACK) { - if (!state.ignore_cb_handler) { + if (!state.ignore_cb_handler && static_cast(sg)->result != CALLBACK_FAILED) { group->dsg_flags |= DSGF_CB_RESULT; state.have_cb_handler = true; } @@ -2698,6 +2698,10 @@ void OptimiseVarAction2DeterministicSpriteGroup(VarAction2OptimiseState &state, } if (possible_callback_handler) group->dsg_flags |= DSGF_CB_HANDLER; + if ((group->dsg_flags & (DSGF_CB_HANDLER | DSGF_CB_RESULT)) == 0) { + group->sg_flags |= SGF_SKIP_CB; + } + if (!HasGrfOptimiserFlag(NGOF_NO_OPT_VARACT2_GROUP_PRUNE) && group->ranges.empty() && !group->calculated_result && !seen_req_var1C) { /* There is only one option, remove any redundant adjustments when the result will be ignored anyway */ while (!group->adjusts.empty()) { diff --git a/src/newgrf_spritegroup.cpp b/src/newgrf_spritegroup.cpp index 56778e731c..5287ff1de7 100644 --- a/src/newgrf_spritegroup.cpp +++ b/src/newgrf_spritegroup.cpp @@ -253,6 +253,11 @@ static bool RangeHighComparator(const DeterministicSpriteGroupRange& range, uint const SpriteGroup *DeterministicSpriteGroup::Resolve(ResolverObject &object) const { + if ((this->sg_flags & SGF_SKIP_CB) != 0 && object.callback > 1) { + static CallbackResultSpriteGroup cbfail(CALLBACK_FAILED); + return &cbfail; + } + uint32 last_value = 0; uint32 value = 0; @@ -615,6 +620,7 @@ void SpriteGroupDumper::DumpSpriteGroup(const SpriteGroup *sg, const char *paddi char extra_info[64] = ""; if (sg->sg_flags & SGF_ACTION6) strecat(extra_info, " (action 6 modified)", lastof(extra_info)); + if (sg->sg_flags & SGF_SKIP_CB) strecat(extra_info, " (skip CB)", lastof(extra_info)); if (HasBit(_misc_debug_flags, MDF_NEWGRF_SG_DUMP_MORE_DETAIL)) { if (sg->sg_flags & SGF_INLINING) strecat(extra_info, " (inlining)", lastof(extra_info)); } diff --git a/src/newgrf_spritegroup.h b/src/newgrf_spritegroup.h index 8b743f7446..23baee3253 100644 --- a/src/newgrf_spritegroup.h +++ b/src/newgrf_spritegroup.h @@ -63,6 +63,7 @@ enum SpriteGroupFlags : uint8 { SGF_NONE = 0, SGF_ACTION6 = 1 << 0, SGF_INLINING = 1 << 1, + SGF_SKIP_CB = 1 << 2, }; DECLARE_ENUM_AS_BIT_SET(SpriteGroupFlags)