diff options
author | Theriaca <reichmeister@protonmail.com> | 2019-01-21 20:47:29 +0100 |
---|---|---|
committer | Paweł Redman <pawel.redman@gmail.com> | 2019-02-10 14:47:47 +0100 |
commit | 77fcca7900b417bcaae0538879853b88aecff503 (patch) | |
tree | cf4a2e0cbf93d3215f54b023de141a792d47310f /src | |
parent | 8808724c0296da1e59e238e9bf4e759440159b3d (diff) |
implement fractional evos for aliens
- rewrite and optimize G_AddCreditToClient()
- remove unclaimedFrags trashcode in player_die
Overflowing of fractional evos is supported; sharing isn't (yet?)
Diffstat (limited to 'src')
-rw-r--r-- | src/game/g_client.c | 118 | ||||
-rw-r--r-- | src/game/g_combat.c | 69 | ||||
-rw-r--r-- | src/game/g_local.h | 3 |
3 files changed, 86 insertions, 104 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; } diff --git a/src/game/g_combat.c b/src/game/g_combat.c index 8dd4a44..7b58f1f 100644 --- a/src/game/g_combat.c +++ b/src/game/g_combat.c @@ -131,7 +131,7 @@ void player_die( gentity_t *self, gentity_t *inflictor, gentity_t *attacker, int gentity_t *ent; int anim; int killer; - int i, j; + int i; char *killerName, *obit; float totalTK = 0; float totalDamage = 0.0f; @@ -541,11 +541,10 @@ void player_die( gentity_t *self, gentity_t *inflictor, gentity_t *attacker, int { //horribly complex nasty alien land float humanValue = BG_GetValueOfHuman( &self->client->ps ) * level.alienHandicap; - int frags; - int unclaimedFrags = (int)humanValue; for( i = 0; i < MAX_CLIENTS; i++ ) { + float frags; player = g_entities + i; if( !player->client ) @@ -558,19 +557,16 @@ void player_die( gentity_t *self, gentity_t *inflictor, gentity_t *attacker, int if( !self->credits[ i ] ) continue; - //nothing left to claim - if( !unclaimedFrags ) - break; - percentDamage = (float)self->credits[ i ] / totalDamage; - if( percentDamage > 0 && percentDamage < 1) - { - player->client->pers.statscounters.assists++; - player->client->pers.karma += 25; - level.alienStatsCounters.assists++; - } + + if( percentDamage > 0 && percentDamage < 1 ) + { + player->client->pers.statscounters.assists++; + player->client->pers.karma += 25; + level.alienStatsCounters.assists++; + } - frags = (int)floor( humanValue * percentDamage); + frags = humanValue * percentDamage; if( frags > 0 ) { @@ -582,51 +578,6 @@ void player_die( gentity_t *self, gentity_t *inflictor, gentity_t *attacker, int //can't revist this account later self->credits[ i ] = 0; - - //reduce frags left to be claimed - unclaimedFrags -= frags; - } - } - - //there are frags still to be claimed - if( unclaimedFrags ) - { - //the clients remaining at this point do not - //have enough credit to claim even one frag - //so simply give the top <unclaimedFrags> clients - //a frag each - - for( i = 0; i < unclaimedFrags; i++ ) - { - int maximum = 0; - int topClient = 0; - - for( j = 0; j < MAX_CLIENTS; j++ ) - { - //this client did no damage - if( !self->credits[ j ] ) - continue; - - if( self->credits[ j ] > maximum ) - { - maximum = self->credits[ j ]; - topClient = j; - } - } - - if( maximum > 0 ) - { - player = g_entities + topClient; - - //add kills - if( spreeRate && player == attacker ) - G_AddCreditToClient( player->client, spreeRate, qtrue ); - else - G_AddCreditToClient( player->client, 1, qtrue ); - - //can't revist this account again - self->credits[ topClient ] = 0; - } } } } diff --git a/src/game/g_local.h b/src/game/g_local.h index f4961fd..708a85a 100644 --- a/src/game/g_local.h +++ b/src/game/g_local.h @@ -409,6 +409,7 @@ typedef struct // used to save playerState_t values while in SPECTATOR_FOLLOW mode int score; int credit; + float fractionalCredit; // alien-only int ping; int lastTeamStatus; @@ -1123,7 +1124,7 @@ void G_UpdateZaps( int msec ); // // g_client.c // -void G_AddCreditToClient( gclient_t *client, short credit, qboolean cap ); +void G_AddCreditToClient( gclient_t *client, float credit, qboolean cap ); team_t TeamCount( int ignoreClientNum, int team ); void G_SetClientViewAngle( gentity_t *ent, vec3_t angle ); gentity_t *G_SelectTremulousSpawnPoint( pTeam_t team, vec3_t preference, vec3_t origin, vec3_t angles ); |