From a564d72a66d8043983b2594ed9664307576448f0 Mon Sep 17 00:00:00 2001 From: Dino Date: Sun, 4 Oct 2026 22:58:10 -0400 Subject: [PATCH] city_add_unit(): handle spec_type either nullptr or not RM #2334 --- server/unithand.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/server/unithand.c b/server/unithand.c index 54a9f84217..1539bd5449 100644 --- a/server/unithand.c +++ b/server/unithand.c @@ -4245,6 +4245,7 @@ static bool city_add_unit(struct player *pplayer, struct unit *punit, const struct unit_type *act_utype; int new_food; int savings_pct = city_growth_granary_savings(pcity); + Specialist_type_id sspec; /* Sanity check: The actor is still alive. */ fc_assert_ret_val(punit, FALSE); @@ -4263,7 +4264,7 @@ static bool city_add_unit(struct player *pplayer, struct unit *punit, citizens_update(pcity, unit_nationality(punit)); if (is_super_specialist(act_utype->spec_type)) { - Specialist_type_id sspec = specialist_index(act_utype->spec_type); + sspec = specialist_index(act_utype->spec_type); fc_assert_ret_val(pcity->specialists[sspec] < MAX_CITY_SIZE, FALSE); pcity->specialists[sspec]++; @@ -4271,8 +4272,12 @@ static bool city_add_unit(struct player *pplayer, struct unit *punit, city_refresh(pcity); } else { fc_assert_ret_val(amount > 0, FALSE); + + sspec = act_utype->spec_type ? + specialist_index(act_utype->spec_type) : + DEFAULT_SPECIALIST; /* Make the new people something, otherwise city fails the checks */ - pcity->specialists[DEFAULT_SPECIALIST] += amount; + pcity->specialists[sspec] += amount; /* Make the new people do something useful */ auto_arrange_workers(pcity); /* this calls city_refresh(pcity) */ } -- 2.31.0