From 8e0e24956b4a0cb3ca8e08e0fe45a2fb6b3d425a Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Fri, 27 May 2022 04:49:41 +0300 Subject: [PATCH 17/17] Check unit uniqueness within startunits Make sure that not multiple units that are supposed to be unique are granted as start units. Reported by Alexandro Ignatiev See osdn #44685 Signed-off-by: Marko Lindqvist --- server/gamehand.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/server/gamehand.c b/server/gamehand.c index 08a63e0118..39f19e8380 100644 --- a/server/gamehand.c +++ b/server/gamehand.c @@ -111,12 +111,15 @@ enum unit_role_id crole_to_role_id(char crole) } /**************************************************************************** - Get unit_type for given role character + Get unit_type for given role character. + If pplayer given, will check also that they don't already have + an unique unit. ****************************************************************************/ struct unit_type *crole_to_unit_type(char crole, struct player *pplayer) { struct unit_type *utype = NULL; enum unit_role_id role = crole_to_role_id(crole); + int num; if (role == 0) { fc_assert_ret_val(FALSE, NULL); @@ -124,11 +127,20 @@ struct unit_type *crole_to_unit_type(char crole, struct player *pplayer) } /* Create the unit of an appropriate type, if it exists */ - if (num_role_units(role) > 0) { + num = num_role_units(role); + if (num > 0) { if (pplayer != NULL) { + int i; + utype = first_role_unit_for_player(pplayer, role); - } - if (utype == NULL) { + for (i = 0; utype == NULL && i < num; i++) { + struct unit_type *ntype = get_role_unit(role, i); + + if (!utype_player_already_has_this_unique(pplayer, ntype)) { + utype = ntype; + } + } + } else { utype = get_role_unit(role, 0); } } -- 2.35.1