From 34d18867cb6762846c4cb60a6df9b3b8c4232047 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Fri, 27 May 2022 04:45:49 +0300 Subject: [PATCH 37/37] 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 56f19892b6..f1803cc529 100644 --- a/server/gamehand.c +++ b/server/gamehand.c @@ -112,12 +112,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); @@ -125,11 +128,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