summaryrefslogtreecommitdiff
path: root/src/game/g_client.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/g_client.c')
-rw-r--r--src/game/g_client.c118
1 files changed, 74 insertions, 44 deletions
diff --git a/src/game/g_client.c b/src/game/g_client.c
index b30b9c7..6bbc93b 100644
--- a/src/game/g_client.c
+++ b/src/game/g_client.c
@@ -84,17 +84,22 @@ void SP_info_human_intermission( gentity_t *ent )
G_OverflowCredits
===============
*/
-void G_OverflowCredits( gclient_t *doner, int credits )
+void G_OverflowCredits( gclient_t *doner, float credits )
{
int i;
int maxCredits;
int clientNum;
+ float fractionalCredit = 0.0f;
if( !g_creditOverflow.integer )
return;
if( doner->ps.stats[ STAT_PTEAM ] == PTE_ALIENS )
{
+ int buffer = (int)floor(credits);
+
+ fractionalCredit = credits - buffer;
+ credits = buffer;
maxCredits = ALIEN_MAX_KILLS;
clientNum = level.lastCreditedAlien;
}
@@ -127,12 +132,33 @@ void G_OverflowCredits( gclient_t *doner, int credits )
continue;
if( vic->client->ps.stats[ STAT_PTEAM ] == PTE_ALIENS )
+ {
+ if( fractionalCredit > 0 )
+ vic->client->pers.fractionalCredit += fractionalCredit;
+
+ if( vic->client->pers.fractionalCredit > 1.0f )
+ {
+ int buffer;
+
+ buffer = floor( vic->client->pers.fractionalCredit );
+ vic->client->pers.fractionalCredit -= buffer;
+ credits += buffer;
+ }
+
level.lastCreditedAlien = clientNum;
+ }
else
+ {
level.lastCreditedHuman = clientNum;
+ }
if( vic->client->ps.persistant[ PERS_CREDIT ] + credits > maxCredits )
{
+ if ( vic->client->pers.fractionalCredit > 0 ) {
+ fractionalCredit += vic->client->pers.fractionalCredit;
+ vic->client->pers.fractionalCredit = 0.0f;
+ }
+
credits -= maxCredits - vic->client->ps.persistant[ PERS_CREDIT ];
vic->client->ps.persistant[ PERS_CREDIT ] = maxCredits;
}
@@ -156,8 +182,28 @@ void G_OverflowCredits( gclient_t *doner, int credits )
cl->ps.persistant[ PERS_CREDIT ] >= maxCredits )
continue;
+ if( cl->ps.stats[ STAT_PTEAM ] == PTE_ALIENS )
+ {
+ if( fractionalCredit > 0 )
+ cl->pers.fractionalCredit += fractionalCredit;
+
+ if( cl->pers.fractionalCredit > 1.0f )
+ {
+ int buffer;
+
+ buffer = floor( cl->pers.fractionalCredit );
+ cl->pers.fractionalCredit -= buffer;
+ credits += buffer;
+ }
+ }
+
if( cl->ps.persistant[ PERS_CREDIT ] + credits > maxCredits )
{
+ if ( cl->pers.fractionalCredit > 0 ) {
+ fractionalCredit += cl->pers.fractionalCredit;
+ cl->pers.fractionalCredit = 0.0f;
+ }
+
credits -= maxCredits - cl->ps.persistant[ PERS_CREDIT ];
cl->ps.persistant[ PERS_CREDIT ] = maxCredits;
}
@@ -175,62 +221,46 @@ void G_OverflowCredits( gclient_t *doner, int credits )
G_AddCreditToClient
===============
*/
-void G_AddCreditToClient( gclient_t *client, short credit, qboolean cap )
+void G_AddCreditToClient(gclient_t *client, float credit, qboolean cap)
{
- if( !client )
+ if (!client)
return;
- //if we're already at the max and trying to add credit then stop
- if( cap )
- {
- if( client->pers.teamSelection == PTE_ALIENS )
- {
- if( client->pers.credit >= ALIEN_MAX_KILLS &&
- credit > 0 )
- {
- G_OverflowCredits( client, credit );
- return;
- }
- }
- else if( client->pers.teamSelection == PTE_HUMANS )
- {
- if( client->pers.credit >= HUMAN_MAX_CREDITS &&
- credit > 0 )
- {
- G_OverflowCredits( client, credit );
- return;
- }
- }
- }
+ if (cap) {
+ int max = 0;
+ float buffer = credit;
- client->pers.credit += credit;
+ if (client->pers.teamSelection == PTE_ALIENS) {
+ max = ALIEN_MAX_KILLS;
+ client->pers.fractionalCredit += credit;
- if( cap )
- {
- if( client->pers.teamSelection == PTE_ALIENS )
- {
- if( client->pers.credit > ALIEN_MAX_KILLS )
- {
- G_OverflowCredits( client, client->ps.persistant[ PERS_CREDIT ] - ALIEN_MAX_KILLS );
- client->pers.credit = ALIEN_MAX_KILLS;
+ if (client->pers.fractionalCredit > 1.0f) {
+ credit = floor(client->pers.fractionalCredit);
+ client->pers.fractionalCredit -= credit;
}
+ } else if (client->pers.teamSelection == PTE_HUMANS) {
+ max = HUMAN_MAX_CREDITS;
}
- else if( client->pers.teamSelection == PTE_HUMANS )
- {
- if( client->pers.credit > HUMAN_MAX_CREDITS )
- {
- G_OverflowCredits( client, client->ps.persistant[ PERS_CREDIT ] - HUMAN_MAX_CREDITS );
- client->pers.credit = HUMAN_MAX_CREDITS;
- }
+
+ buffer = client->pers.credit + credit - max;
+
+ if (buffer > 0) {
+ G_OverflowCredits(client, buffer + client->pers.fractionalCredit);
+ client->pers.credit = max;
+ client->pers.fractionalCredit = 0.0f;
+ } else {
+ client->pers.credit += (short)credit;
}
+ } else {
+ client->pers.credit += (short)credit;
}
- if( client->pers.credit < 0 )
+ if (client->pers.credit < 0)
client->pers.credit = 0;
// keep PERS_CREDIT in sync if not following
- if( client->sess.spectatorState != SPECTATOR_FOLLOW )
- client->ps.persistant[ PERS_CREDIT ] = client->pers.credit;
+ if (client->sess.spectatorState != SPECTATOR_FOLLOW)
+ client->ps.persistant[PERS_CREDIT] = client->pers.credit;
}