summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaweł Redman <pawel.redman@gmail.com>2019-02-10 17:57:53 +0100
committerPaweł Redman <pawel.redman@gmail.com>2019-02-10 17:57:53 +0100
commitc2f8ef14e564125d141c4341a4a1863bacb21be9 (patch)
treeb061aef0ff9f4a1d6c1ca910e30d8143775db808 /src
parent7cf6bb398cf895ecc9a436dcec6525920a0ea551 (diff)
Fractional sharing and donating
Diffstat (limited to 'src')
-rw-r--r--src/game/g_client.c15
-rw-r--r--src/game/g_cmds.c81
-rw-r--r--src/game/g_local.h1
3 files changed, 66 insertions, 31 deletions
diff --git a/src/game/g_client.c b/src/game/g_client.c
index b8b4968..02b827f 100644
--- a/src/game/g_client.c
+++ b/src/game/g_client.c
@@ -79,6 +79,21 @@ void SP_info_human_intermission( gentity_t *ent )
{
}
+/*
+===============
+G_RoundFunds
+
+Credits are rounded to the nearest integer, evos to the nearest 100th.
+===============
+*/
+float G_RoundFunds(float funds, pTeam_t team)
+{
+ if (team == PTE_ALIENS)
+ return roundf(funds * 100.0f) / 100.0f;
+ else
+ return roundf(funds);
+}
+
static int compare_client_funds(const void *c1, const void *c2)
{
return (((const gclient_t *)c1)->pers.funds - ((const gclient_t *)c2)->pers.funds);
diff --git a/src/game/g_cmds.c b/src/game/g_cmds.c
index 17db035..eac9ac4 100644
--- a/src/game/g_cmds.c
+++ b/src/game/g_cmds.c
@@ -5117,7 +5117,8 @@ static void Cmd_Ignore_f( gentity_t *ent )
*/
void Cmd_Share_f( gentity_t *ent )
{
- int i, clientNum = 0, creds = 0, skipargs = 0;
+ int i, clientNum = 0, skipargs = 0;
+ float creds = 0.0f;
int clientNums[ MAX_CLIENTS ] = { -1 };
char cmd[ 12 ];
char arg1[ MAX_STRING_TOKENS ];
@@ -5252,11 +5253,11 @@ static void Cmd_Ignore_f( gentity_t *ent )
}
// credit count from parameter
- creds = atoi( arg2 );
+ creds = G_RoundFunds( atof( arg2 ), team );
}
// player specified "0" to transfer
- if( creds <= 0 )
+ if( creds <= 0.0f )
{
trap_SendServerCommand( ent-g_entities,
"print \"Ooh, you are a generous one, indeed!\n\"" );
@@ -5270,7 +5271,7 @@ static void Cmd_Ignore_f( gentity_t *ent )
}
// player has no credits
- if( creds <= 0 )
+ if( creds <= 0.0f )
{
trap_SendServerCommand( ent-g_entities,
"print \"Earn some first, lazy gal!\n\"" );
@@ -5290,7 +5291,7 @@ static void Cmd_Ignore_f( gentity_t *ent )
}
// target cannot take any more credits
- if( creds <= 0 )
+ if( creds <= 0.0f )
{
trap_SendServerCommand( ent-g_entities,
va( "print \"share: player cannot receive any more %s.\n\"",
@@ -5300,17 +5301,28 @@ static void Cmd_Ignore_f( gentity_t *ent )
// transfer credits
G_AddFundsToClient( ent->client, -creds, qfalse );
- trap_SendServerCommand( ent-g_entities,
- va( "print \"share: transferred %d %s to %s^7.\n\"", creds,
- ( team == PTE_HUMANS ) ? "credits" : "evolvepoints",
- level.clients[ clientNum ].pers.netname ) );
- G_AddFundsToClient( &(level.clients[ clientNum ]), creds, qtrue );
- trap_SendServerCommand( clientNum,
- va( "print \"You have received %d %s from %s^7.\n\"", creds,
- ( team == PTE_HUMANS ) ? "credits" : "evolvepoints",
- ent->client->pers.netname ) );
+ G_AddFundsToClient( level.clients + clientNum, creds, qtrue );
+
+ if (team == PTE_ALIENS)
+ {
+ trap_SendServerCommand( ent-g_entities,
+ va( "print \"share: transferred %.2f evolvepoints to %s^7.\n\"", creds,
+ level.clients[ clientNum ].pers.netname ) );
+ trap_SendServerCommand( clientNum,
+ va( "print \"You have received %.2f evolvepoints from %s^7.\n\"", creds,
+ ent->client->pers.netname ) );
+ }
+ else
+ {
+ trap_SendServerCommand( ent-g_entities,
+ va( "print \"share: transferred %.0f credits to %s^7.\n\"", creds,
+ level.clients[ clientNum ].pers.netname ) );
+ trap_SendServerCommand( clientNum,
+ va( "print \"You have received %.0f credits from %s^7.\n\"", creds,
+ ent->client->pers.netname ) );
+ }
- G_LogPrintf( "Share: %i %i %i %d: %s^7 transferred %d%s to %s^7\n",
+ G_LogPrintf( "Share: %i %i %i %d: %s^7 transferred %f%s to %s^7\n",
ent->client->ps.clientNum,
clientNum,
team,
@@ -5330,8 +5342,8 @@ static void Cmd_Ignore_f( gentity_t *ent )
*/
void Cmd_Donate_f( gentity_t *ent ) {
char s[ MAX_TOKEN_CHARS ] = "", *type = "evo(s)";
- int i, value, divisor, portion, new_credits, total=0,
- max = ALIEN_MAX_KILLS, *amounts;
+ int i, divisor, max = ALIEN_MAX_KILLS;
+ float value, total = 0.0f, amounts[ MAX_CLIENTS ] = {0.0f};
qboolean donated = qtrue;
if( !ent->client ) return;
@@ -5369,7 +5381,7 @@ static void Cmd_Ignore_f( gentity_t *ent )
}
trap_Argv( 1, s, sizeof( s ) );
- value = atoi(s);
+ value = G_RoundFunds(atof(s), ent->client->pers.teamSelection);
if( value <= 0 ) {
trap_SendServerCommand( ent-g_entities,
"print \"donate: very funny\n\"" );
@@ -5377,14 +5389,13 @@ static void Cmd_Ignore_f( gentity_t *ent )
}
if( value > ent->client->pers.funds)
value = ent->client->pers.funds;
-
- // allocate memory for distribution amounts
- amounts = G_Alloc( level.maxclients * sizeof( int ) );
- for( i = 0; i < level.maxclients; i++ ) amounts[ i ] = 0;
+
// determine donation amounts for each client
total = value;
while( donated && value ) {
+ float portion, new_credits;
+
donated = qfalse;
portion = value / divisor;
if( portion < 1 ) portion = 1;
@@ -5412,16 +5423,24 @@ static void Cmd_Ignore_f( gentity_t *ent )
G_AddFundsToClient( ent->client, value - total, qtrue );
for( i = 0; i < level.maxclients; i++ )
if( amounts[ i ] ) {
- trap_SendServerCommand( i,
- va( "print \"%s^7 donated %d %s to you, don't forget to say 'thank you'!\n\"",
- ent->client->pers.netname, amounts[ i ], type ) );
+ if( ent->client->pers.teamSelection == PTE_ALIENS)
+ trap_SendServerCommand( i,
+ va( "print \"%s^7 donated %.3f %s to you, don't forget to say 'thank you'!\n\"",
+ ent->client->pers.netname, amounts[ i ], type ) );
+ else
+ trap_SendServerCommand( i,
+ va( "print \"%s^7 donated %.0f %s to you, don't forget to say 'thank you'!\n\"",
+ ent->client->pers.netname, amounts[ i ], type ) );
}
-
- G_Free( amounts );
-
- trap_SendServerCommand( ent-g_entities,
- va( "print \"Donated %d %s to the cause.\n\"",
- total-value, type ) );
+
+ if( ent->client->pers.teamSelection == PTE_ALIENS)
+ trap_SendServerCommand( ent-g_entities,
+ va( "print \"Donated %.3f %s to the cause.\n\"",
+ total-value, type ) );
+ else
+ trap_SendServerCommand( ent-g_entities,
+ va( "print \"Donated %.0f %s to the cause.\n\"",
+ total-value, type ) );
}
diff --git a/src/game/g_local.h b/src/game/g_local.h
index 51ab249..76e646b 100644
--- a/src/game/g_local.h
+++ b/src/game/g_local.h
@@ -1123,6 +1123,7 @@ void G_UpdateZaps( int msec );
//
// g_client.c
//
+float G_RoundFunds(float funds, pTeam_t team);
void G_AddFundsToClient( gclient_t *client, float funds, qboolean cap );
team_t TeamCount( int ignoreClientNum, int team );
void G_SetClientViewAngle( gentity_t *ent, vec3_t angle );