From e2aa89f23f774936e0099f4e1429f2bfd0d6f197 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Tue, 21 Jun 2022 16:51:10 +0300 Subject: [PATCH 56/56] kill_unit(): Call player_slot_count() just once See osdn #44797 Signed-off-by: Marko Lindqvist --- server/unittools.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/server/unittools.c b/server/unittools.c index bb88363ca8..eacc3bec09 100644 --- a/server/unittools.c +++ b/server/unittools.c @@ -2309,14 +2309,15 @@ void kill_unit(struct unit *pkiller, struct unit *punit, bool vet) wipe_unit(punit, ULR_KILLED, pvictor); } else { /* unitcount > 1 */ int i; - int num_killed[player_slot_count()]; - int num_escaped[player_slot_count()]; - struct unit *other_killed[player_slot_count()]; + int slots = player_slot_count(); + int num_killed[slots]; + int num_escaped[slots]; + struct unit *other_killed[slots]; fc_assert(unitcount > 1); /* initialize */ - for (i = 0; i < player_slot_count(); i++) { + for (i = 0; i < slots; i++) { num_killed[i] = 0; other_killed[i] = NULL; num_escaped[i] = 0; @@ -2408,7 +2409,7 @@ void kill_unit(struct unit *pkiller, struct unit *punit, bool vet) * * Also if a large number of units die you don't find out what type * they all are. */ - for (i = 0; i < player_slot_count(); i++) { + for (i = 0; i < slots; i++) { if (num_killed[i] == 1) { if (i == player_index(pvictim)) { fc_assert(other_killed[i] == NULL); @@ -2483,7 +2484,7 @@ void kill_unit(struct unit *pkiller, struct unit *punit, bool vet) * 'deftile' is the original tile they defended at, not where * they escaped to, as there might be multiple different tiles * different units escaped to. */ - for (i = 0; i < player_slot_count(); ++i) { + for (i = 0; i < slots; i++) { if (0 < num_escaped[i]) { notify_player(player_by_number(i), deftile, E_UNIT_ESCAPED, ftc_server, -- 2.35.1