From 214f0a02c6e6e189439892bcf1fbffb579780eb4 Mon Sep 17 00:00:00 2001
From: Sweet Tea Dorminy <sweettea-kernel@dorminy.me>
Date: Sat, 21 Nov 2026 16:49:16 -0800
Subject: [PATCH] resolve_city_emergency(): Disband an idle boat too

The emergency meant to spare a boat carrying units, and tested the
ferry's passenger field against 0. dai_ferry_init_ferry() sets that
field to FERRY_AVAILABLE (-1) on every boat, loaded or empty, so no
boat was ever disbanded. One Trireme idle outside the borders can then
keep a small city in disorder until the government falls.

Spare a boat that carries units or that a passenger has booked, and
disband the rest like any other unit causing unrest.

See RM #2496

Signed-off-by: Sweet Tea Dorminy <sweettea-kernel@dorminy.me>
---
 ai/default/daicity.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/ai/default/daicity.c b/ai/default/daicity.c
index 89990e249f..95f0724b99 100644
--- a/ai/default/daicity.c
+++ b/ai/default/daicity.c
@@ -1077,7 +1077,11 @@ static void resolve_city_emergency(struct ai_type *ait, struct player *pplayer,
     if (city_unhappy(pcity)
         && (utype_happy_cost(unit_type_get(punit), pplayer) > 0
             && (unit_being_aggressive(nmap, punit) || is_field_unit(punit)))
-        && def_ai_unit_data(punit, ait)->passenger == 0) {
+        /* Spare a boat that carries units or that a passenger has
+         * booked. An unbooked boat's passenger field is negative, not 0,
+         * so the field alone cannot tell an idle boat from a loaded one. */
+        && get_transporter_occupancy(punit) == 0
+        && def_ai_unit_data(punit, ait)->passenger <= 0) {
       UNIT_LOG(LOG_EMERGENCY, punit, "is causing unrest, disbanded");
       /* TODO: If Help Wonder stops blocking Disband Unit there may be
        * cases where Disband Unit should be selected. Example: Field unit
-- 
2.55.0

