Skip to content

Commit

Permalink
Turn defensive conditionals into assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
blabber committed Aug 30, 2024
1 parent 0daf5f5 commit 55b8ed3
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions common/city.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2247,9 +2247,12 @@ void add_specialist_output(
// This is more than just an optimization. For governors that forbid
// 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());

output_type_iterate(stat_index)
{
int amount = pcsoutputs && !pcsoutputs->empty()
int amount = pcsoutputs
? pcsoutputs->at(sp)[stat_index]
: get_specialist_output(pcity, sp, stat_index);

Expand Down Expand Up @@ -2876,10 +2879,12 @@ void set_city_production(struct city *pcity,
* 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->empty() ? &pcwaste->at(o) : nullptr);
gov_centers, pcwaste ? &pcwaste->at(o) : nullptr);
}
output_type_iterate_end;

Expand Down

0 comments on commit 55b8ed3

Please sign in to comment.