From 9ceb0b7b52b1eb6fd5ee95d7b92cd339052e8daa Mon Sep 17 00:00:00 2001 From: Dino Date: Wed, 2 Jul 2025 01:18:28 -0400 Subject: [PATCH] #1554, Tell user about goods a unit is carrying --- client/packhand.c | 1 + client/text.c | 7 +++++++ server/cityturn.c | 16 ++++++++++++---- server/unittools.c | 9 +++++---- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/client/packhand.c b/client/packhand.c index f7ab331991..1c7dd2675a 100644 --- a/client/packhand.c +++ b/client/packhand.c @@ -1983,6 +1983,7 @@ static bool handle_unit_packet_common(struct unit *packet_unit) punit->done_moving = packet_unit->done_moving; check_focus = TRUE; } + punit->carrying = packet_unit->carrying; /* This won't change punit; it enqueues the call for later handling. */ agents_unit_changed(punit); diff --git a/client/text.c b/client/text.c index f73caf7030..a3188608df 100644 --- a/client/text.c +++ b/client/text.c @@ -420,6 +420,13 @@ const char *popup_info_text(struct tile *ptile) /* TRANS: on own line immediately following \n, ... */ astr_add_line(&str, _("from %s"), city_name_get(hcity)); } + if (punit->carrying + /* this SHOULD be redundant, but if a savefile got hacked... */ + && unit_can_do_action(punit, ACTION_TRADE_ROUTE)) { + /* TRANS: on own line immediately following \n, from ... */ + astr_add_line(&str, _("carrying %s"), + goods_name_translation(punit->carrying)); + } } else if (owner != nullptr) { struct player_diplstate *ds = player_diplstate_get(plr, owner); diff --git a/server/cityturn.c b/server/cityturn.c index fcf04638d2..7bfa7292e8 100644 --- a/server/cityturn.c +++ b/server/cityturn.c @@ -2932,10 +2932,18 @@ static bool city_build_unit(struct player *pplayer, struct city *pcity) } if (punit) { - notify_player(pplayer, city_tile(pcity), E_UNIT_BUILT, ftc_server, - /* TRANS: is finished building . */ - _("%s is finished building %s."), - city_link(pcity), utype_name_translation(utype)); + if (punit->carrying) { + notify_player(pplayer, city_tile(pcity), E_UNIT_BUILT, ftc_server, + /* TRANS: is finished building , carrying . */ + _("%s is finished building %s, carrying %s."), + city_link(pcity), utype_name_translation(utype), + goods_name_translation(punit->carrying)); + } else { + notify_player(pplayer, city_tile(pcity), E_UNIT_BUILT, ftc_server, + /* TRANS: is finished building . */ + _("%s is finished building %s."), + city_link(pcity), utype_name_translation(utype)); + } } /* After we created the unit remove the citizen. This will also diff --git a/server/unittools.c b/server/unittools.c index 29c94fc68a..c8698de9c2 100644 --- a/server/unittools.c +++ b/server/unittools.c @@ -1616,11 +1616,12 @@ struct unit *create_unit(struct player *pplayer, struct tile *ptile, } /**********************************************************************//** - Set carried goods for unit. + Set carried goods for unit who can do the action "Establish Trade Route" **************************************************************************/ void unit_get_goods(struct unit *punit) { - if (punit->homecity != 0) { + if (punit->homecity != 0 + && unit_can_do_action(punit, ACTION_TRADE_ROUTE)) { struct city *home = game_city_by_number(punit->homecity); if (home != NULL && game.info.goods_selection == GSM_LEAVING) { @@ -1755,6 +1756,8 @@ bool place_unit(struct unit *punit, struct player *pplayer, punit->server.vision = vision_new(pplayer, ptile); unit_refresh_vision(punit); + unit_get_goods(punit); + send_unit_info(NULL, punit); wakeup_neighbor_sentries(punit); @@ -1762,8 +1765,6 @@ bool place_unit(struct unit *punit, struct player *pplayer, city_map_update_tile_now(ptile); sync_cities(); - unit_get_goods(punit); - CALL_FUNC_EACH_AI(unit_created, punit); CALL_PLR_AI_FUNC(unit_got, pplayer, punit); -- 2.31.0