From 51d09c1784e671150674fbcd44a5aa5b9eed750b Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Sat, 30 Mar 2024 12:20:25 +0200
Subject: [PATCH 17/17] cityresult_fill(): Check city center result existence
 always

Also in non-debug builds. It was just an assert.

See RM #377

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 ai/default/daisettler.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/ai/default/daisettler.c b/ai/default/daisettler.c
index cc7f71ba97..d5d4eacc98 100644
--- a/ai/default/daisettler.c
+++ b/ai/default/daisettler.c
@@ -295,7 +295,7 @@ static struct cityresult *cityresult_fill(struct ai_type *ait,
   /* Create a city result and set default values. */
   result = cityresult_new(center);
 
-  if (!pcity) {
+  if (pcity == NULL) {
     pcity = create_city_virtual(pplayer, result->tile, "Virtuaville");
     saved_owner = tile_owner(result->tile);
     saved_claimer = tile_claimer(result->tile);
@@ -315,7 +315,7 @@ static struct cityresult *cityresult_fill(struct ai_type *ait,
 
     if (reserved < 0
         || (handicap && !map_is_known(ptile, pplayer))
-        || NULL != tile_worked(ptile)) {
+        || tile_worked(ptile) != NULL) {
       /* Tile is reserved or we can't see it */
       ptdc = tile_data_cache_new();
       ptdc->shield = 0;
@@ -326,6 +326,7 @@ static struct cityresult *cityresult_fill(struct ai_type *ait,
       /* ptdc->turn was set by tile_data_cache_new(). */
     } else {
       const struct tile_data_cache *ptdc_hit = tdc_plr_get(ait, pplayer, tindex);
+
       if (!ptdc_hit || city_center) {
         /* We cannot read city center from cache */
         ptdc = tile_data_cache_new();
@@ -391,7 +392,11 @@ static struct cityresult *cityresult_fill(struct ai_type *ait,
   } city_tile_iterate_index_end;
 
   /* We need a city center. */
-  fc_assert_ret_val(result->city_center.tdc != NULL, NULL);
+  if (result->city_center.tdc == NULL) {
+    fc_assert(result->city_center.tdc != NULL);
+
+    return NULL;
+  }
 
   if (virtual_city) {
     /* Baseline is a size one city (city center + best extra tile). */
-- 
2.43.0

