summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorenneract <trem.redman@gmail.com>2014-12-16 19:36:18 +0100
committerenneract <trem.redman@gmail.com>2014-12-16 19:36:18 +0100
commit3afe13c2a292e0940a05634b322300ccd1238541 (patch)
tree20d7bf596af96eabe55f709b7f6576671d46f962 /src
parent7c02e34b08a4e44a7f7935bf6b1bee45c3a8df6c (diff)
Make Lightning Gun's damage depend on precision.
Lightning Gun's damage now depends on where a target was hit. Firing directly at a target's center will yield the full damage output, while firing at a point far from the center will cause a lot less damage. Both players and buildings are affected.
Diffstat (limited to 'src')
-rw-r--r--src/game/g_local.h3
-rw-r--r--src/game/g_main.c8
-rw-r--r--src/game/g_weapon.c62
-rw-r--r--src/game/tremulous.h2
4 files changed, 68 insertions, 7 deletions
diff --git a/src/game/g_local.h b/src/game/g_local.h
index eb5f37e..873234b 100644
--- a/src/game/g_local.h
+++ b/src/game/g_local.h
@@ -1308,6 +1308,9 @@ extern vmCvar_t g_DretchBuildingDamage;
extern vmCvar_t g_OwnTeamBPFactor;
extern vmCvar_t g_EnemyTeamBPFactor;
+extern vmCvar_t g_lightningDamage;
+extern vmCvar_t g_lightningDifficulty;
+
void trap_Print( const char *fmt );
void trap_Error( const char *fmt );
int trap_Milliseconds( void );
diff --git a/src/game/g_main.c b/src/game/g_main.c
index 57b4af4..5b6b025 100644
--- a/src/game/g_main.c
+++ b/src/game/g_main.c
@@ -206,6 +206,9 @@ vmCvar_t g_DretchBuildingDamage;
vmCvar_t g_OwnTeamBPFactor;
vmCvar_t g_EnemyTeamBPFactor;
+vmCvar_t g_lightningDamage;
+vmCvar_t g_lightningDifficulty;
+
// copy cvars that can be set in worldspawn so they can be restored later
static char cv_gravity[ MAX_CVAR_VALUE_STRING ];
static char cv_humanMaxStage[ MAX_CVAR_VALUE_STRING ];
@@ -376,7 +379,10 @@ static cvarTable_t gameCvarTable[ ] =
{ &g_DretchTurretDamage, "g_DretchTurretDamage", "1", CVAR_ARCHIVE, 0, qfalse },
{ &g_DretchBuildingDamage, "g_DretchBuildingDamage", "0.5", CVAR_ARCHIVE, 0, qfalse },
{ &g_OwnTeamBPFactor, "g_OwnTeamBPFactor", "1.0", CVAR_ARCHIVE, 0, qfalse },
- { &g_EnemyTeamBPFactor, "g_EnemyTeamBPFactor", "0.0", CVAR_ARCHIVE, 0, qfalse }
+ { &g_EnemyTeamBPFactor, "g_EnemyTeamBPFactor", "0.0", CVAR_ARCHIVE, 0, qfalse },
+
+ { &g_lightningDamage, "g_lightningDamage", "140", 0, 0, qfalse },
+ { &g_lightningDifficulty, "g_lightningDifficulty", "1", 0, 0, qfalse }
};
static int gameCvarTableSize = sizeof( gameCvarTable ) / sizeof( gameCvarTable[ 0 ] );
void G_InitGame( int levelTime, int randomSeed, int restart );
diff --git a/src/game/g_weapon.c b/src/game/g_weapon.c
index 1c333ab..3bc3871 100644
--- a/src/game/g_weapon.c
+++ b/src/game/g_weapon.c
@@ -835,27 +835,80 @@ LIGHTNING GUN
======================================================================
*/
+float G_LightningAccuracy( const vec3_t ws_origin, const vec3_t ws_dir,
+ const vec3_t mins, const vec3_t maxs, const vec3_t ws_target )
+{
+ int i, damage;
+ vec3_t origin, dir, boxcenter, boxdelta;
+ float dist, chord;
+
+ VectorSubtract( ws_origin, ws_target, origin );
+ VectorSubtract( maxs, mins, boxdelta );
+
+ for( i = 0; i < 3; i++ )
+ boxcenter[ i ] = ( mins[ i ] + maxs[ i ] ) / 2.0f;
+
+ VectorSubtract( origin, boxcenter, origin );
+
+ for( i = 0; i < 3; i++ )
+ origin[ i ] *= 2.0f / boxdelta[ i ],
+ dir[ i ] = ws_dir[ i ] * 1.0f / boxdelta[ i ];
+
+ VectorNormalize( dir );
+
+ dist = VectorLength( origin );
+
+ if( dist <= 1.0f ) // inside the sphere (shouldn't happen)
+ return 1.0f;
+
+ chord = pow( DotProduct( origin, dir ), 2 ) - pow( dist, 2 ) + 1;
+
+ if( chord <= 0.0f )
+ return 0.0f;
+
+ chord = pow( chord, g_lightningDifficulty.value * 0.5f );
+
+ return chord;
+}
+
+
void lightningGunFire( gentity_t *ent )
{
- vec3_t start, end;
+ vec3_t start, end, mins, maxs, target_origin;
trace_t tr;
gentity_t *target;
+ int damage;
VectorMA( muzzle, LIGHTNING_RANGE, forward, end );
G_UnlaggedOn( ent, muzzle, LIGHTNING_RANGE );
+
trap_Trace( &tr, muzzle, NULL, NULL, end, ent->s.number, MASK_SHOT );
- G_UnlaggedOff( );
if( tr.fraction == 1.0f ||
tr.entityNum == ENTITYNUM_NONE ||
( tr.surfaceFlags & SURF_NOIMPACT ) )
+ {
+ G_UnlaggedOff( );
return;
+ }
target = g_entities + tr.entityNum;
+ damage = g_lightningDamage.value / ( 1000.0f / LIGHTNING_REPEAT );
+
if( target->s.eType == ET_PLAYER || target->s.eType == ET_BUILDABLE )
+ {
+ float acc;
+
+ VectorCopy( target->r.mins, mins );
+ VectorCopy( target->r.maxs, maxs );
+ VectorCopy( target->r.currentOrigin, target_origin );
BloodSpurt( ent, target, &tr );
+
+ acc = G_LightningAccuracy( muzzle, forward, mins, maxs, target_origin );
+ damage = MAX( round( (float)damage * acc ), 1 );
+ }
else
{
gentity_t *tent;
@@ -864,9 +917,10 @@ void lightningGunFire( gentity_t *ent )
tent->s.eventParm = DirToByte( tr.plane.normal );
tent->s.weapon = ent->s.weapon;
tent->s.generic1 = ent->s.generic1;
- }
+ }
- G_Damage( target, ent, ent, forward, tr.endpos, LIGHTNING_DAMAGE, 0, MOD_LIGHTNING );
+ G_UnlaggedOff( );
+ G_Damage( target, ent, ent, forward, tr.endpos, damage, 0, MOD_LIGHTNING );
}
diff --git a/src/game/tremulous.h b/src/game/tremulous.h
index 3b9c8bc..b3b9b92 100644
--- a/src/game/tremulous.h
+++ b/src/game/tremulous.h
@@ -517,9 +517,7 @@ TREMULOUS EDGE MOD SRC FILE
#define LIGHTNING_PRICE 500
#define LIGHTNING_AMMO 300
#define LIGHTNING_K_SCALE 1
-#define LIGHTNING_DPS 60 // damage per second
#define LIGHTNING_REPEAT 50 // keep it as low as possible
-#define LIGHTNING_DAMAGE ( LIGHTNING_DPS * LIGHTNING_REPEAT / 1000 )
#define LIGHTNING_RANGE 450
#define LCANNON_PRICE 600