From 9ed47c061f218e82eb5e81cf42bbb5e4590bc920 Mon Sep 17 00:00:00 2001 From: Tobias Rehbein Date: Sun, 1 Sep 2024 23:19:43 +0200 Subject: [PATCH] Fallback to legacy behaviour if empty caches are detected Fallback to the behavior used prior to the introduction of these caches, if the assertion checking for an empty cache is triggered. While here, move an assertion outside a loop to make sure it is not checked for each iteration. --- common/city.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/common/city.cpp b/common/city.cpp index a947826353..0772e700e0 100644 --- a/common/city.cpp +++ b/common/city.cpp @@ -2248,7 +2248,8 @@ void add_specialist_output( // specialists, the cache may not be filled. if (count > 0) { // If there is a cache it must not be empty. - fc_assert(!pcsoutputs || !pcsoutputs->empty()); + fc_assert_action(!pcsoutputs || !pcsoutputs->empty(), + pcsoutputs = nullptr); output_type_iterate(stat_index) { @@ -2873,15 +2874,15 @@ void set_city_production(struct city *pcity, trade_routes_iterate_end; pcity->prod[O_GOLD] += get_city_tithes_bonus(pcity); + // If there is a cache it must not be empty. + fc_assert_action(!pcwaste || !pcwaste->empty(), pcwaste = nullptr); + /* Account for waste. Note that waste is calculated before tax income is * calculated, so if you had "science waste" it would not include taxed * science. However waste is calculated after the bonuses are multiplied * on, so shield waste will include shield bonuses. */ output_type_iterate(o) { - // If there is a cache it must not be empty. - fc_assert(!pcwaste || !pcwaste->empty()); - pcity->waste[o] = city_waste(pcity, o, pcity->prod[o] * pcity->bonus[o] / 100, nullptr, gov_centers, pcwaste ? &pcwaste->at(o) : nullptr);