Skip to content

Commit

Permalink
Fallback to legacy behaviour if empty caches are detected
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
blabber authored and lmoureaux committed Sep 1, 2024
1 parent 57dba79 commit 625c10c
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions common/city.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 625c10c

Please sign in to comment.