From b07b3edda86a6739191334b231537165b139f2e5 Mon Sep 17 00:00:00 2001 From: Paweł Redman Date: Sun, 10 Feb 2019 14:55:05 +0100 Subject: Refactor G_AddFundsToClient. --- src/game/g_client.c | 44 +++++++++++++++++++------------------------- 1 file changed, 19 insertions(+), 25 deletions(-) (limited to 'src/game') diff --git a/src/game/g_client.c b/src/game/g_client.c index 0eafac0..b8b4968 100644 --- a/src/game/g_client.c +++ b/src/game/g_client.c @@ -149,36 +149,30 @@ G_AddFundsToClient */ void G_AddFundsToClient(gclient_t *client, float funds, qboolean cap) { - if (!client || funds == 0) - return; - - if (cap) { - float max = 0.0f; - float buffer = funds; + if (!client) + return; - if (client->pers.teamSelection == PTE_ALIENS) - max = ALIEN_MAX_KILLS; - else if (client->pers.teamSelection == PTE_HUMANS) - max = HUMAN_MAX_CREDITS; + client->pers.funds += funds; + if (client->pers.funds < 0) + client->pers.funds = 0; - buffer = client->pers.funds + funds - max; + if (cap) { + float max; - if (buffer > 0) { - G_OverflowFunds(client, buffer); - client->pers.funds = max; - } else { - client->pers.funds += funds; - } - } else { - client->pers.funds += funds; - } + if (client->pers.teamSelection == PTE_ALIENS) + max = ALIEN_MAX_KILLS; + else + max = HUMAN_MAX_CREDITS; - if (client->pers.funds < 0) - client->pers.funds = 0; + if (client->pers.funds > max) { + G_OverflowFunds(client, client->pers.funds - max); + client->pers.funds = max; + } + } - // keep PERS_CREDIT in sync if not following - if (client->sess.spectatorState != SPECTATOR_FOLLOW) - client->ps.persistant[PERS_CREDIT] = floorf(client->pers.funds); + // keep PERS_CREDIT in sync if not following + if (client->sess.spectatorState != SPECTATOR_FOLLOW) + client->ps.persistant[PERS_CREDIT] = floorf(client->pers.funds); } -- cgit