summaryrefslogtreecommitdiff
path: root/src/game/g_combat.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/g_combat.c')
-rw-r--r--src/game/g_combat.c119
1 files changed, 67 insertions, 52 deletions
diff --git a/src/game/g_combat.c b/src/game/g_combat.c
index 13441ac..966e595 100644
--- a/src/game/g_combat.c
+++ b/src/game/g_combat.c
@@ -45,15 +45,22 @@ void AddScore( gentity_t *ent, int score )
if( !ent->client )
return;
- // make alien and human scores equivalent
- if ( ent->client->pers.teamSelection == TEAM_ALIENS )
- {
- score = rint( ((float)score) / 2.0f );
- }
-
// scale values down to fit the scoreboard better
score = rint( ((float)score) / 50.0f );
+ switch( ent->client->pers.teamSelection ) {
+ case TEAM_ALIENS:
+ // make alien and human scores equivalent
+ score = rint( ((float)score) / 2.0f );
+ level.alienRewardScore += score;
+ break;
+ case TEAM_HUMANS:
+ level.humanRewardScore += score;
+ break;
+ default:
+ break;
+ }
+
ent->client->ps.persistant[ PERS_SCORE ] += score;
G_admin_add_score( ent, score );
@@ -184,60 +191,69 @@ float G_CamperRewardBonus( gentity_t *self )
return 1.0f;
}
-float G_TeamRewardScaleFactor( gentity_t *target )
-{
- if (level.humanRewardKills <= 0.0f || level.alienRewardKills <= 0.0f) return 1.0f;
- if( !target->client ) return 1.0f;
- if( target->client->ps.stats[ STAT_TEAM ] == TEAM_ALIENS) {
- return level.alienRewardKills/level.humanRewardKills;
- } else if( target->client->ps.stats[ STAT_TEAM ] == TEAM_HUMANS ) {
- return level.humanRewardKills/level.alienRewardKills;
- } else return 0;
-}
-
-float G_RewardScaleFactor( gentity_t *self, gentity_t *target, float teamFactor )
+float G_RewardScaleFactor( gentity_t *self, gentity_t *target )
{
- float result;
-
- if (self->client->pers.kills <= 0 || target->client->pers.kills <= 0) return 1.0f;
-
- result = g_ConstantRewardFactor.value;
- result += g_TeamRewardFactor.value*teamFactor;
- result += g_PlayerRewardFactor.value*target->client->pers.kills/self->client->pers.kills;
-
- if (result > 1.0f) result = 1.0f;
- return result;
+ float targetScore;
+ if( level.humanRewardScore <= 0.0f || level.alienRewardScore <= 0.0f ) return 1.0f;
+ switch( self->client->ps.stats[ STAT_TEAM ] ) {
+ case TEAM_ALIENS:
+ targetScore = level.humanRewardScore/level.alienRewardScore;
+ break;
+ case TEAM_HUMANS:
+ targetScore = level.alienRewardScore/level.humanRewardScore;
+ break;
+ default:
+ return 0;
+ }
+ if ( target->client != NULL ) {
+ if( self->client->ps.persistant[ PERS_SCORE ] <= 0 || target->client->ps.persistant[ PERS_SCORE ] <= 0) return targetScore;
+ targetScore *= target->client->ps.persistant[ PERS_SCORE ]/self->client->ps.persistant[ PERS_SCORE ];
+ }
+ targetScore *= 1.0f-g_ConstantRewardFactor.value;
+ targetScore += g_ConstantRewardFactor.value;
+ if (targetScore < g_MinRewardFactor.value) targetScore = g_MinRewardFactor.value;
+ else if (targetScore > g_MaxRewardFactor.value) targetScore = g_MaxRewardFactor.value;
+ return targetScore;
}
/* Instantly reward the current attacker */
float G_InstantRewardAttacker( gentity_t *self, gentity_t *target, float damage )
{
float value;
- int maxHealth;
+ int maxHealth,targetTeam;
if( damage <= 0.f ) return 0.0f;
if( !self->client ) return 0.0f;
- if( !target->client ) return 0.0f;
- if( OnSameTeam( self, target ) ) return 0.0f;
- if( target->s.eType == ET_BUILDABLE ) return 0.0f;
- maxHealth = target->client->ps.stats[ STAT_MAX_HEALTH ];
+ if( target->client != NULL ) {
+ maxHealth = target->client->ps.stats[ STAT_MAX_HEALTH ];
+ targetTeam = target->client->ps.stats[ STAT_TEAM ];
+ } else {
+ maxHealth = BG_Buildable( target->s.modelindex )->health;
+ targetTeam = target->buildableTeam;
+ }
+ if( targetTeam == self->client->ps.stats[ STAT_TEAM ] ) return 0.0f;
- // Only give credits for attacking players for now
value = damage / maxHealth;
if (value > 1.0f) value = 1.0f;
- value *= G_CamperRewardBonus( target );
- value *= BG_GetValueOfPlayer( &target->client->ps );
- if( target->client->ps.stats[ STAT_TEAM ] == TEAM_ALIENS) {
+ if( target->client != NULL ) {
+ value *= G_CamperRewardBonus( target );
+ value *= BG_GetValueOfPlayer( &target->client->ps );
+ } else {
+ value *= BG_Buildable( target->s.modelindex )->value;
+ value *= g_BuildingCreditsFactor.value;
+ }
+
+ if( targetTeam == TEAM_ALIENS) {
value *= g_InstantRewardMultiplierA.value;
- } else if( target->client->ps.stats[ STAT_TEAM ] == TEAM_HUMANS ) {
+ } else if( targetTeam == TEAM_HUMANS ) {
value *= g_InstantRewardMultiplierH.value;
- } else value = 0;
+ } else value = 0.f;
- value *= G_RewardScaleFactor( self, target, G_TeamRewardScaleFactor( target ) );
+ value *= G_RewardScaleFactor( self, target );
- if( value > 0 ) {
+ if( value > 0.f ) {
G_AddCreditToClient( self->client, value, qtrue );
if( self->client->ps.stats[ STAT_TEAM ] == TEAM_ALIENS ) {
trap_Cvar_Set( "g_alienCredits",
@@ -312,7 +328,6 @@ float G_RewardAttackers( gentity_t *self )
// Give credits and empty the array
- teamFactor = G_TeamRewardScaleFactor( self );
for( i = 0; i < level.maxclients; i++ )
{
int stageValue = value * self->credits[ i ] / totalDamage;
@@ -329,19 +344,17 @@ float G_RewardAttackers( gentity_t *self )
AddScore( player, stageValue );
- // killing buildables earns score, but not credits
- if( self->s.eType != ET_BUILDABLE )
- {
+ // killing buildables earns score, but not credits unless g_BuildingCreditsFactor > 0
+ if( self->s.eType == ET_BUILDABLE ) stageValue *= g_BuildingCreditsFactor.value;
+ if( stageValue > 0 ) {
// Com_Printf(S_COLOR_YELLOW "Killer: kills = %f deaths = %f percent_of_damage = %f -> factor = %f\n",player->client->pers.kills,player->client->pers.deaths,killValue,G_RewardScaleFactor( player, self, teamFactor) );
- stageValue *= G_RewardScaleFactor( player, self, teamFactor );
- player->client->pers.kills += killValue;
+ stageValue *= G_RewardScaleFactor( player, self );
+ player->client->pers.kills += killValue; // NOTE: Building kills will increase this too if g_BuildingCreditsFactor > 0
// add to stage counters
if( player->client->ps.stats[ STAT_TEAM ] == TEAM_ALIENS ) {
- level.alienRewardKills += killValue;
G_AddCreditToClient( player->client, g_KillRewardMultiplierH.value*stageValue, qtrue );
alienCredits += g_KillRewardMultiplierH.value*stageValue;
} else if( player->client->ps.stats[ STAT_TEAM ] == TEAM_HUMANS ) {
- level.humanRewardKills += killValue;
G_AddCreditToClient( player->client, g_KillRewardMultiplierA.value*stageValue, qtrue );
humanCredits += g_KillRewardMultiplierA.value*stageValue;
}
@@ -352,7 +365,7 @@ float G_RewardAttackers( gentity_t *self )
// ++self->client->pers.deaths;
// Com_Printf(S_COLOR_YELLOW "Killed: kills = %f deaths = %d\n",self->client->pers.kills,self->client->pers.deaths);
- // Com_Printf(S_COLOR_YELLOW "Team: kills = %f deaths = %f\n",level.alienRewardKills,level.humanRewardKills);
+ // Com_Printf(S_COLOR_YELLOW "Team: kills = %f deaths = %f\n",level.alienRewardScore,level.humanRewardScore);
if( alienCredits )
{
@@ -1568,8 +1581,10 @@ qboolean G_SelectiveRadiusDamage( vec3_t origin, gentity_t *attacker, float dama
points = damage * ( 1.0 - dist / radius );
- if( CanDamage( ent, origin ) && ent->client &&
- ent->client->ps.stats[ STAT_TEAM ] != team )
+ if( CanDamage( ent, origin ) &&
+ ( ( ent->client && ent->client->ps.stats[ STAT_TEAM ] != team ) ||
+ ( ent->s.eType == ET_BUILDABLE &&
+ BG_Buildable( ent->s.modelindex )->team != team ) ) )
{
VectorSubtract( ent->r.currentOrigin, origin, dir );
// push the center of mass higher than the origin so players