diff options
author | Tim Angus <tim@ngus.net> | 2004-10-10 22:37:08 +0000 |
---|---|---|
committer | Tim Angus <tim@ngus.net> | 2004-10-10 22:37:08 +0000 |
commit | 97143eb45a8a29904b97ae8251d8d1d349ebd5c7 (patch) | |
tree | c1764cf63534f570c085395cb7c0267e0d76a1ee | |
parent | 7d66cee2661d2717ff76a4e6f73b75ddeea6d93e (diff) |
* Heavily revised alien frag sharing
* Other assorted changes
-rw-r--r-- | src/game/bg_misc.c | 1 | ||||
-rw-r--r-- | src/game/g_active.c | 4 | ||||
-rw-r--r-- | src/game/g_buildable.c | 14 | ||||
-rw-r--r-- | src/game/g_client.c | 30 | ||||
-rw-r--r-- | src/game/g_cmds.c | 104 | ||||
-rw-r--r-- | src/game/g_combat.c | 118 | ||||
-rw-r--r-- | src/game/g_local.h | 1 | ||||
-rw-r--r-- | src/game/tremulous.h | 2 |
8 files changed, 220 insertions, 54 deletions
diff --git a/src/game/bg_misc.c b/src/game/bg_misc.c index f39f1ec0..446ff176 100644 --- a/src/game/bg_misc.c +++ b/src/game/bg_misc.c @@ -4880,6 +4880,7 @@ int BG_GetValueOfHuman( playerState_t *ps ) } portion = worth / (float)HUMAN_MAXED; + Com_Printf( "portion: %f, worth: %d\n", portion, worth ); if( portion < 0.01f ) portion = 0.01f; diff --git a/src/game/g_active.c b/src/game/g_active.c index 8ba8723b..f056d4c2 100644 --- a/src/game/g_active.c +++ b/src/game/g_active.c @@ -1219,7 +1219,7 @@ void ClientThink_real( gentity_t *ent ) traceEnt = &g_entities[ trace.entityNum ]; - if( traceEnt->use ) + if( traceEnt && traceEnt->biteam == client->ps.stats[ STAT_PTEAM ] && traceEnt->use ) traceEnt->use( traceEnt, ent, ent ); //other and activator are the same in this context else { @@ -1233,7 +1233,7 @@ void ClientThink_real( gentity_t *ent ) { traceEnt = &g_entities[ entityList[ i ] ]; - if( traceEnt->use ) + if( traceEnt && traceEnt->biteam == client->ps.stats[ STAT_PTEAM ] && traceEnt->use ) { traceEnt->use( traceEnt, ent, ent ); //other and activator are the same in this context break; diff --git a/src/game/g_buildable.c b/src/game/g_buildable.c index 17cd1402..fd0a5b49 100644 --- a/src/game/g_buildable.c +++ b/src/game/g_buildable.c @@ -581,12 +581,9 @@ void ASpawn_Die( gentity_t *self, gentity_t *inflictor, gentity_t *attacker, int if( attacker && attacker->client && attacker->client->ps.stats[ STAT_PTEAM ] == PTE_HUMANS ) { if( self->s.modelindex == BA_A_OVERMIND ) - attacker->client->ps.persistant[ PERS_CREDIT ] += OVERMIND_VALUE; + G_AddCreditToClient( attacker->client, OVERMIND_VALUE ); else if( self->s.modelindex == BA_A_SPAWN ) - attacker->client->ps.persistant[ PERS_CREDIT ] += ASPAWN_VALUE; - - if( attacker->client->ps.persistant[ PERS_CREDIT ] > HUMAN_MAX_CREDITS ) - attacker->client->ps.persistant[ PERS_CREDIT ] = HUMAN_MAX_CREDITS; + G_AddCreditToClient( attacker->client, ASPAWN_VALUE ); } } @@ -2132,12 +2129,9 @@ void HSpawn_Die( gentity_t *self, gentity_t *inflictor, gentity_t *attacker, int if( attacker && attacker->client && attacker->client->ps.stats[ STAT_PTEAM ] == PTE_ALIENS ) { if( self->s.modelindex == BA_H_REACTOR ) - attacker->client->ps.persistant[ PERS_CREDIT ] += REACTOR_VALUE; + G_AddCreditToClient( attacker->client, REACTOR_VALUE ); else if( self->s.modelindex == BA_H_SPAWN ) - attacker->client->ps.persistant[ PERS_CREDIT ] += HSPAWN_VALUE; - - if( attacker->client->ps.persistant[ PERS_CREDIT ] > ALIEN_MAX_KILLS ) - attacker->client->ps.persistant[ PERS_CREDIT ] = ALIEN_MAX_KILLS; + G_AddCreditToClient( attacker->client, HSPAWN_VALUE ); } } diff --git a/src/game/g_client.c b/src/game/g_client.c index 35b68f1a..da2f3d25 100644 --- a/src/game/g_client.c +++ b/src/game/g_client.c @@ -72,6 +72,32 @@ void SP_info_human_intermission( gentity_t *ent ) { } +/* +=============== +G_AddCreditToClient +=============== +*/ +void G_AddCreditToClient( gclient_t *client, short credit ) +{ + if( !client ) + return; + + client->ps.persistant[ PERS_CREDIT ] += credit; + + if( client->ps.stats[ STAT_PTEAM ] == PTE_ALIENS ) + { + if( client->ps.persistant[ PERS_CREDIT ] > ALIEN_MAX_KILLS ) + client->ps.persistant[ PERS_CREDIT ] = ALIEN_MAX_KILLS; + } + else if( client->ps.stats[ STAT_PTEAM ] == PTE_HUMANS ) + { + if( client->ps.persistant[ PERS_CREDIT ] > HUMAN_MAX_CREDITS ) + client->ps.persistant[ PERS_CREDIT ] = HUMAN_MAX_CREDITS; + } + + if( client->ps.persistant[ PERS_CREDIT ] < 0 ) + client->ps.persistant[ PERS_CREDIT ] = 0; +} /* @@ -1167,10 +1193,10 @@ void ClientBegin( int clientNum ) // send event tent = G_TempEntity( ent->client->ps.origin, EV_PLAYER_TELEPORT_IN ); tent->s.clientNum = ent->s.clientNum; - - trap_SendServerCommand( -1, va( "print \"%s" S_COLOR_WHITE " entered the game\n\"", client->pers.netname ) ); } + trap_SendServerCommand( -1, va( "print \"%s" S_COLOR_WHITE " entered the game\n\"", client->pers.netname ) ); + G_LogPrintf( "ClientBegin: %i\n", clientNum ); // count current clients and rank for scoreboard diff --git a/src/game/g_cmds.c b/src/game/g_cmds.c index 17503b26..c1d492b5 100644 --- a/src/game/g_cmds.c +++ b/src/game/g_cmds.c @@ -280,9 +280,9 @@ void Cmd_Give_f( gentity_t *ent ) int credits = atoi( name + 6 ); if( !credits ) - ent->client->ps.persistant[ PERS_CREDIT ]++; + G_AddCreditToClient( ent->client, 1 ); else - ent->client->ps.persistant[ PERS_CREDIT ] += credits; + G_AddCreditToClient( ent->client, credits ); if( !give_all ) return; @@ -1191,7 +1191,7 @@ void Cmd_Class_f( gentity_t *ent ) if( numLevels >= 0 && BG_FindStagesForClass( ent->client->pers.classSelection, g_alienStage.integer ) ) { //remove credit - ent->client->ps.persistant[ PERS_CREDIT ] -= (short)numLevels; + G_AddCreditToClient( ent->client, -(short)numLevels ); ClientUserinfoChanged( clientNum ); VectorCopy( infestOrigin, ent->s.pos.trBase ); @@ -1560,7 +1560,7 @@ void Cmd_Buy_f( gentity_t *ent ) ent->client->ps.stats[ STAT_MISC ] = 0; //subtract from funds - ent->client->ps.persistant[ PERS_CREDIT ] -= (short)BG_FindPriceForWeapon( weapon ); + G_AddCreditToClient( ent->client, -(short)BG_FindPriceForWeapon( weapon ) ); } else if( upgrade != UP_NONE ) { @@ -1645,7 +1645,7 @@ void Cmd_Buy_f( gentity_t *ent ) } //subtract from funds - ent->client->ps.persistant[ PERS_CREDIT ] -= (short)BG_FindPriceForUpgrade( upgrade ); + G_AddCreditToClient( ent->client, -(short)BG_FindPriceForUpgrade( upgrade ) ); } else { @@ -1721,7 +1721,7 @@ void Cmd_Sell_f( gentity_t *ent ) BG_removeWeapon( weapon, ent->client->ps.stats ); //add to funds - ent->client->ps.persistant[ PERS_CREDIT ] += (short)BG_FindPriceForWeapon( weapon ); + G_AddCreditToClient( ent->client, (short)BG_FindPriceForWeapon( weapon ) ); } //if we have this weapon selected, force a new selection @@ -1756,7 +1756,7 @@ void Cmd_Sell_f( gentity_t *ent ) } //add to funds - ent->client->ps.persistant[ PERS_CREDIT ] += (short)BG_FindPriceForUpgrade( upgrade ); + G_AddCreditToClient( ent->client, (short)BG_FindPriceForUpgrade( upgrade ) ); } //if we have this upgrade selected, force a new selection @@ -1772,7 +1772,7 @@ void Cmd_Sell_f( gentity_t *ent ) BG_removeWeapon( i, ent->client->ps.stats ); //add to funds - ent->client->ps.persistant[ PERS_CREDIT ] += (short)BG_FindPriceForWeapon( i ); + G_AddCreditToClient( ent->client, (short)BG_FindPriceForWeapon( i ) ); } //if we have this weapon selected, force a new selection @@ -1810,7 +1810,7 @@ void Cmd_Sell_f( gentity_t *ent ) } //add to funds - ent->client->ps.persistant[ PERS_CREDIT ] += (short)BG_FindPriceForUpgrade( i ); + G_AddCreditToClient( ent->client, (short)BG_FindPriceForUpgrade( i ) ); } //if we have this upgrade selected, force a new selection @@ -2141,6 +2141,90 @@ void Cmd_Test_f( gentity_t *ent ) /* ================= +Cmd_Evolve_Debug_f +================= +*/ +void Cmd_Evolve_Debug_f( gentity_t *ent ) +{ +#define USE_OBJECT_RANGE 64 + + int entityList[ MAX_GENTITIES ]; + vec3_t range = { USE_OBJECT_RANGE, USE_OBJECT_RANGE, USE_OBJECT_RANGE }; + vec3_t mins, maxs, dir; + int i, num; + int j; + qboolean upgrade = qfalse; + gclient_t *client = ent->client; + trace_t trace; + gentity_t *traceEnt; + vec3_t point, view; + + //TA: look for object infront of player + AngleVectors( client->ps.viewangles, view, NULL, NULL ); + VectorMA( client->ps.origin, USE_OBJECT_RANGE, view, point ); + trap_Trace( &trace, client->ps.origin, NULL, NULL, point, ent->s.number, MASK_SHOT ); + + traceEnt = &g_entities[ trace.entityNum ]; + + if( traceEnt && traceEnt->biteam == client->ps.stats[ STAT_PTEAM ] && traceEnt->use ) + trap_SendServerCommand( ent - g_entities, + va( "print \"Trying to use entity \"%s\"\n\"", traceEnt->classname ) ); + else + { + //no entity in front of player - do a small area search + + VectorAdd( client->ps.origin, range, maxs ); + VectorSubtract( client->ps.origin, range, mins ); + + num = trap_EntitiesInBox( mins, maxs, entityList, MAX_GENTITIES ); + for( i = 0; i < num; i++ ) + { + traceEnt = &g_entities[ entityList[ i ] ]; + + if( traceEnt && traceEnt->biteam == client->ps.stats[ STAT_PTEAM ] && traceEnt->use ) + { + trap_SendServerCommand( ent - g_entities, + va( "print \"Trying to use entity \"%s\"\n\"", traceEnt->classname ) ); + break; + } + } + + trap_SendServerCommand( ent - g_entities, + va( "print \"i:%d == num:%d\n\"", i, num ) ); + + if( i == num && client->ps.stats[ STAT_PTEAM ] == PTE_ALIENS ) + { + for( j = PCL_NONE + 1; j < PCL_NUM_CLASSES; j++ ) + { + trap_SendServerCommand( ent - g_entities, + va( "print \"BG_ClassCanEvolveFromTo( %d, %d, %d, 0 ) = %d\n\"", + client->ps.stats[ STAT_PCLASS ], j, client->ps.persistant[ PERS_CREDIT ], + BG_ClassCanEvolveFromTo( client->ps.stats[ STAT_PCLASS ], j, + client->ps.persistant[ PERS_CREDIT ], 0 ) ) ); + + trap_SendServerCommand( ent - g_entities, + va( "print \"BG_FindStagesForClass( %d, %d ) = %d\n\"", + j, g_alienStage.integer, + BG_FindStagesForClass( j, g_alienStage.integer ) ) ); + + if( BG_ClassCanEvolveFromTo( client->ps.stats[ STAT_PCLASS ], j, + client->ps.persistant[ PERS_CREDIT ], 0 ) >= 0 && + BG_FindStagesForClass( j, g_alienStage.integer ) ) + { + upgrade = qtrue; + break; + } + } + + trap_SendServerCommand( ent - g_entities, + va( "print \"upgrade = %d\n\"", upgrade ) ); + } + } +} + + +/* +================= ClientCommand ================= */ @@ -2245,6 +2329,8 @@ void ClientCommand( int clientNum ) Cmd_SetViewpos_f( ent ); else if( Q_stricmp( cmd, "test" ) == 0 ) Cmd_Test_f( ent ); + else if( Q_stricmp( cmd, "evolvebug" ) == 0 ) + Cmd_Evolve_Debug_f( ent ); else trap_SendServerCommand( clientNum, va( "print \"unknown cmd %s\n\"", cmd ) ); } diff --git a/src/game/g_combat.c b/src/game/g_combat.c index b90adde4..bf2e479d 100644 --- a/src/game/g_combat.c +++ b/src/game/g_combat.c @@ -151,7 +151,7 @@ void player_die( gentity_t *self, gentity_t *inflictor, gentity_t *attacker, int int anim; int contents; int killer; - int i; + int i, j; char *killerName, *obit; if( self->client->ps.pm_type == PM_DEAD ) @@ -220,12 +220,9 @@ void player_die( gentity_t *self, gentity_t *inflictor, gentity_t *attacker, int //punish team kills and suicides if( attacker->client->ps.stats[ STAT_PTEAM ] == PTE_ALIENS ) - attacker->client->ps.persistant[ PERS_CREDIT ]--; + G_AddCreditToClient( attacker->client, -1 ); else if( attacker->client->ps.stats[ STAT_PTEAM ] == PTE_HUMANS ) - attacker->client->ps.persistant[ PERS_CREDIT ] -= ASPAWN_VALUE; - - if( attacker->client->ps.persistant[ PERS_CREDIT ] < 0 ) - attacker->client->ps.persistant[ PERS_CREDIT ] = 0; + G_AddCreditToClient( attacker->client, -ASPAWN_VALUE ); } else { @@ -246,45 +243,106 @@ void player_die( gentity_t *self, gentity_t *inflictor, gentity_t *attacker, int if( attacker && attacker->client ) { int clientNum = attacker->client->ps.clientNum; - float denominator, numerator = self->credits[ clientNum ]; - int total = 0; + int totalDamage = 0; gentity_t *player; //total up all the damage done by every client for( i = 0; i < MAX_CLIENTS; i++ ) - total += self->credits[ i ]; - - denominator = total; + totalDamage += self->credits[ i ]; - for( i = 0; i < MAX_CLIENTS; i++ ) + if( totalDamage > 0.0f ) { - player = g_entities + i; - if( self->client->ps.stats[ STAT_PTEAM ] == PTE_ALIENS && player->client && player->client->ps.stats[ STAT_PTEAM ] == PTE_HUMANS ) { - int classValue = BG_FindValueOfClass( self->client->ps.stats[ STAT_PCLASS ] ); - numerator = self->credits[ i ]; + //nice simple happy bouncy human land + float classValue = BG_FindValueOfClass( self->client->ps.stats[ STAT_PCLASS ] ); - //add credit - player->client->ps.persistant[ PERS_CREDIT ] += - (int)( (float)classValue * ( numerator / denominator ) ); - - if( player->client->ps.persistant[ PERS_CREDIT ] > HUMAN_MAX_CREDITS ) - player->client->ps.persistant[ PERS_CREDIT ] = HUMAN_MAX_CREDITS; + for( i = 0; i < MAX_CLIENTS; i++ ) + { + player = g_entities + i; + + if( !self->credits[ i ] ) + continue; + + //add credit + G_AddCreditToClient( player->client, + (int)( classValue * ( self->credits[ i ] / totalDamage ) ) ); + } } else if( self->client->ps.stats[ STAT_PTEAM ] == PTE_HUMANS && - player->client && player->client->ps.stats[ STAT_PTEAM ] == PTE_ALIENS ) + player->client && player->client->ps.stats[ STAT_PTEAM ] == PTE_ALIENS ) { - int classValue = BG_GetValueOfHuman( self->client->ps ); - numerator = self->credits[ i ]; + //horribly complex nasty alien land + float humanValue = BG_GetValueOfHuman( self->client->ps ); + int frags; + int unclaimedFrags = (int)humanValue; - //add kills - player->client->ps.persistant[ PERS_CREDIT ] += - (int)round( (float)classValue * ( numerator / denominator ) ); + for( i = 0; i < MAX_CLIENTS; i++ ) + { + player = g_entities + i; + + //this client did no damage + if( !self->credits[ i ] ) + continue; + + //nothing left to claim + if( !unclaimedFrags ) + break; + + frags = (int)floor( humanValue * ( self->credits[ i ] / totalDamage ) ); + + if( frags > 0 ) + { + //add kills + G_AddCreditToClient( player->client, frags ); + + //can't revist this account later + self->credits[ i ] = 0; + + //reduce frags left to be claimed + unclaimedFrags -= frags; + } + } - if( player->client->ps.persistant[ PERS_CREDIT ] > ALIEN_MAX_KILLS ) - player->client->ps.persistant[ PERS_CREDIT ] = ALIEN_MAX_KILLS; + //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; + + 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 + G_AddCreditToClient( player->client, 1 ); + + //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 ee802f47..6fe638e9 100644 --- a/src/game/g_local.h +++ b/src/game/g_local.h @@ -754,6 +754,7 @@ void ChargeAttack( gentity_t *ent, gentity_t *victim ); // // g_client.c // +void G_AddCreditToClient( gclient_t *client, short credit ); team_t TeamCount( int ignoreClientNum, int team ); void SetClientViewAngle( gentity_t *ent, vec3_t angle ); gentity_t *SelectTremulousSpawnPoint( pTeam_t team, vec3_t origin, vec3_t angles ); diff --git a/src/game/tremulous.h b/src/game/tremulous.h index 0b30b0e6..a053de4f 100644 --- a/src/game/tremulous.h +++ b/src/game/tremulous.h @@ -306,7 +306,7 @@ * */ -#define HUMAN_WDMG_MODIFIER 1.12f +#define HUMAN_WDMG_MODIFIER 1.13f #define HDM(d) ((int)((float)d*HUMAN_WDMG_MODIFIER)) #define BLASTER_REPEAT 600 |