summaryrefslogtreecommitdiff
path: root/src/game/g_active.c
diff options
context:
space:
mode:
authorPetr Pudlak <petr.mvd@gmail.com>2014-08-16 14:26:16 +0200
committerPetr Pudlak <petr.mvd@gmail.com>2014-08-16 14:26:16 +0200
commit8816244ec329acdd5eb64e0518e69ae77df1cd75 (patch)
treec7a7614c537a79b29452695c94ee7597b69e7993 /src/game/g_active.c
parentfc765f5f146627d282b4374dd0c575895d64a900 (diff)
Add the ability for humans to heal their team members
The medkit handling is moved to a new function G_UseMedkit. If there is a human within a given range that is either more wounded than the player, or poisoned, the medkit is applied to him (see G_NeedsMedkit). The range and the breadth of the action is configurable by cvars. The original patch was used on a server, but this port wasn't tested (only that it compiles).
Diffstat (limited to 'src/game/g_active.c')
-rw-r--r--src/game/g_active.c101
1 files changed, 69 insertions, 32 deletions
diff --git a/src/game/g_active.c b/src/game/g_active.c
index fc32ed6..2f7f906 100644
--- a/src/game/g_active.c
+++ b/src/game/g_active.c
@@ -426,6 +426,74 @@ void G_TouchTriggers( gentity_t *ent )
static qboolean ClientInactivityTimer( gentity_t *ent, qboolean active );
/*
+============
+G_NeedsMedkit
+
+============
+*/
+qboolean G_NeedsMedkit( gclient_t *client )
+{
+ //not if currently using a medkit or have no need for a medkit now
+ return !( client->ps.stats[ STAT_STATE ] & SS_HEALING_2X ) &&
+ ( client->ps.stats[ STAT_HEALTH ] < client->ps.stats[ STAT_MAX_HEALTH ] ||
+ ( client->ps.stats[ STAT_STATE ] & SS_POISONED ) );
+}
+/*
+============
+G_UseMedkit
+
+============
+*/
+void G_UseMedkit( gentity_t *ent )
+{
+ gclient_t *client = ent->client;
+ gentity_t *targetEnt = NULL;
+ gclient_t *tclient = NULL;
+ qboolean clientNeedsMedkit;
+
+ if( client->ps.stats[ STAT_HEALTH ] <= 0 )
+ return;
+
+ clientNeedsMedkit = G_NeedsMedkit( client );
+ //look for a teammate that would need healing
+ targetEnt = G_MedkitTarget( ent );
+ if( ( targetEnt != NULL ) &&
+ ( ( tclient = targetEnt->client ) != NULL ) &&
+ ( tclient->ps.stats[ STAT_HEALTH ] > 0 ) &&
+ ( tclient->ps.stats[ STAT_TEAM ] == TEAM_HUMANS ) &&
+ ( G_NeedsMedkit( tclient ) ) &&
+ ( ( client->ps.stats[ STAT_HEALTH ] >= tclient->ps.stats[ STAT_HEALTH ] ) ||
+ !clientNeedsMedkit )
+ )
+ ;
+ else if( clientNeedsMedkit )
+ {
+ targetEnt = ent;
+ tclient = client;
+ } else {
+ BG_DeactivateUpgrade( UP_MEDKIT, client->ps.stats );
+ return;
+ }
+
+ //remove anti toxin
+ BG_DeactivateUpgrade( UP_MEDKIT, client->ps.stats );
+ BG_RemoveUpgradeFromInventory( UP_MEDKIT, client->ps.stats );
+
+ // don't poison and/or infect the client anymore
+ tclient->ps.stats[ STAT_STATE ] &= ~( SS_POISONED | SS_INFECTED );
+ tclient->poisonImmunityTime = level.time + MEDKIT_POISON_IMMUNITY_TIME;
+
+ tclient->ps.stats[ STAT_STATE ] |= SS_HEALING_2X;
+ tclient->lastMedKitTime = level.time;
+ tclient->medKitHealthToRestore =
+ tclient->ps.stats[ STAT_MAX_HEALTH ] - tclient->ps.stats[ STAT_HEALTH ];
+ tclient->medKitIncrementTime = level.time +
+ ( MEDKIT_STARTUP_TIME / MEDKIT_STARTUP_SPEED );
+
+ G_AddEvent( targetEnt, EV_MEDKIT_USED, ent->s.number );
+}
+
+/*
=================
SpectatorThink
=================
@@ -1685,38 +1753,7 @@ void ClientThink_real( gentity_t *ent )
if( BG_InventoryContainsUpgrade( UP_MEDKIT, client->ps.stats ) &&
BG_UpgradeIsActive( UP_MEDKIT, client->ps.stats ) )
- {
- //if currently using a medkit or have no need for a medkit now
- if( client->ps.stats[ STAT_STATE ] & SS_HEALING_2X ||
- ( client->ps.stats[ STAT_HEALTH ] == client->ps.stats[ STAT_MAX_HEALTH ] &&
- !( client->ps.stats[ STAT_STATE ] & SS_POISONED ) ) )
- {
- BG_DeactivateUpgrade( UP_MEDKIT, client->ps.stats );
- }
- else if( client->ps.stats[ STAT_HEALTH ] > 0 )
- {
- //remove anti toxin
- BG_DeactivateUpgrade( UP_MEDKIT, client->ps.stats );
- BG_RemoveUpgradeFromInventory( UP_MEDKIT, client->ps.stats );
-
- // don't poison and/or infect the client anymore
- client->ps.stats[ STAT_STATE ] &= ~SS_POISONED;
-
- if( client->ps.stats[ STAT_STATE ] & SS_INFECTED )
- client->ps.stats[ STAT_STATE ] &= ~SS_INFECTED;
-
- client->poisonImmunityTime = level.time + MEDKIT_POISON_IMMUNITY_TIME;
-
- client->ps.stats[ STAT_STATE ] |= SS_HEALING_2X;
- client->lastMedKitTime = level.time;
- client->medKitHealthToRestore =
- client->ps.stats[ STAT_MAX_HEALTH ] - client->ps.stats[ STAT_HEALTH ];
- client->medKitIncrementTime = level.time +
- ( MEDKIT_STARTUP_TIME / MEDKIT_STARTUP_SPEED );
-
- G_AddEvent( ent, EV_MEDKIT_USED, 0 );
- }
- }
+ G_UseMedkit( ent );
if( BG_InventoryContainsUpgrade( UP_CLOAK, client->ps.stats ) &&
BG_UpgradeIsActive( UP_CLOAK, client->ps.stats ) )