summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/game/bg_public.h2
-rw-r--r--src/game/g_weapon.c86
-rw-r--r--src/game/q_math.c25
3 files changed, 84 insertions, 29 deletions
diff --git a/src/game/bg_public.h b/src/game/bg_public.h
index 6cc3328b..bbaf6e53 100644
--- a/src/game/bg_public.h
+++ b/src/game/bg_public.h
@@ -1158,6 +1158,8 @@ qboolean BG_PlayerTouchesItem( playerState_t *ps, entityState_t *item, int atTi
//TA: conceptually should live in q_shared.h
void AxisToAngles( vec3_t axis[3], vec3_t angles );
#define Vector2Set(v, x, y) ((v)[0]=(x), (v)[1]=(y))
+float pointToLineDistance( const vec3_t point, const vec3_t p1, const vec3_t p2 );
+
// Ridah
void GetPerpendicularViewVector( const vec3_t point, const vec3_t p1,
diff --git a/src/game/g_weapon.c b/src/game/g_weapon.c
index 85acdf64..9e751209 100644
--- a/src/game/g_weapon.c
+++ b/src/game/g_weapon.c
@@ -715,7 +715,8 @@ ZAP
======================================================================
*/
-#define AREAZAP_DAMAGE 100.0f
+#define AREAZAP_DAMAGE 100.0f
+#define DIRECTZAP_DAMAGE 100.0f
/*
===============
@@ -737,7 +738,6 @@ void areaZapFire( gentity_t *ent )
VectorAdd( muzzle, range, maxs );
VectorSubtract( muzzle, range, mins );
- //do some damage
num = trap_EntitiesInBox( mins, maxs, entityList, MAX_GENTITIES );
for( i = 0; i < num; i++ )
{
@@ -764,6 +764,7 @@ void areaZapFire( gentity_t *ent )
VectorSubtract( enemy->s.origin, muzzle, dir );
VectorNormalize( dir );
+ //do some damage
G_Damage( enemy, ent, ent, dir, tr.endpos,
damage, DAMAGE_NO_KNOCKBACK, MOD_LIGHTNING );
@@ -787,42 +788,69 @@ directZapFire
*/
void directZapFire( gentity_t *ent )
{
- trace_t tr;
+ int entityList[ MAX_GENTITIES ];
+ int targetList[ MAX_GENTITIES ];
+ vec3_t range = { 200, 200, 200 };
+ vec3_t mins, maxs, dir;
+ int i, num, numTargets = 0;
+ gentity_t *enemy;
vec3_t end;
- gentity_t *traceEnt, *tent;
- int damage, i, passent;
-
- damage = 100;
-
- VectorMA( muzzle, LIGHTNING_RANGE, forward, end );
+ gentity_t *target = NULL, *tent;
+ float distance, minDist = 10000.0f;
+ trace_t tr;
- trap_Trace( &tr, muzzle, NULL, NULL, end, ent->s.number, MASK_SHOT );
+ VectorAdd( muzzle, range, maxs );
+ VectorSubtract( muzzle, range, mins );
+
+ num = trap_EntitiesInBox( mins, maxs, entityList, MAX_GENTITIES );
+ for( i = 0; i < num; i++ )
+ {
+ enemy = &g_entities[ entityList[ i ] ];
+
+ if( ( enemy->client && enemy->client->ps.stats[ STAT_PTEAM ] == PTE_HUMANS ) ||
+ ( enemy->s.eType == ET_BUILDABLE && BG_FindTeamForBuildable( enemy->s.modelindex ) == BIT_HUMANS ) )
+ {
+ trap_Trace( &tr, muzzle, NULL, NULL, enemy->s.origin, ent->s.number, MASK_SHOT );
+
+ //can't see target from here
+ if( tr.entityNum == ENTITYNUM_WORLD )
+ continue;
- if( tr.entityNum != ENTITYNUM_NONE )
- traceEnt = &g_entities[ tr.entityNum ];
+ targetList[ numTargets++ ] = entityList[ i ];
+ }
+ }
+
+ VectorAdd( muzzle, forward, end );
- if( traceEnt->takedamage )
+ for( i = 0; i < numTargets; i++ )
{
- G_Damage( traceEnt, ent, ent, forward, tr.endpos,
- damage, 0, MOD_LIGHTNING);
- }
+ enemy = &g_entities[ targetList[ i ] ];
- // snap the endpos to integers to save net bandwidth, but nudged towards the line
- SnapVectorTowards( tr.endpos, muzzle );
+ distance = pointToLineDistance( enemy->s.origin, muzzle, end );
+ if( distance < minDist )
+ {
+ target = enemy;
+ minDist = distance;
+ }
+ }
+
+ if( target != NULL )
+ {
+ //do some damage
+ G_Damage( target, ent, ent, dir, tr.endpos,
+ DIRECTZAP_DAMAGE, DAMAGE_NO_KNOCKBACK, MOD_LIGHTNING );
+
+ // snap the endpos to integers to save net bandwidth, but nudged towards the line
+ SnapVectorTowards( tr.endpos, muzzle );
- // send railgun beam effect
- tent = G_TempEntity( tr.endpos, EV_TESLATRAIL );
+ // send railgun beam effect
+ tent = G_TempEntity( target->s.pos.trBase, EV_TESLATRAIL );
- VectorCopy( muzzle, tent->s.origin2 );
+ VectorCopy( muzzle, tent->s.origin2 );
- tent->s.generic1 = ent->s.number; //src
- tent->s.clientNum = -1; //dest
-
- // no explosion at end if SURF_NOIMPACT, but still make the trail
- if( tr.surfaceFlags & SURF_NOIMPACT )
- tent->s.eventParm = 255; // don't make the explosion at the end
- else
- tent->s.eventParm = DirToByte( tr.plane.normal );
+ tent->s.generic1 = ent->s.number; //src
+ tent->s.clientNum = target->s.number; //dest
+ }
}
//======================================================================
diff --git a/src/game/q_math.c b/src/game/q_math.c
index 9c0e21d7..a23a3456 100644
--- a/src/game/q_math.c
+++ b/src/game/q_math.c
@@ -1344,6 +1344,31 @@ void PerpendicularVector( vec3_t dst, const vec3_t src )
VectorNormalize( dst );
}
+/*
+=================
+pointToLineDistance
+
+Distance from a point to some line
+=================
+*/
+float pointToLineDistance( const vec3_t p0, const vec3_t p1, const vec3_t p2 )
+{
+ vec3_t v, w, x, y;
+ float c1, c2, b;
+
+ VectorSubtract( p2, p1, v );
+ VectorSubtract( p1, p0, w );
+
+ CrossProduct( w, v, y );
+ c1 = VectorLength( y );
+ c2 = VectorLength( v );
+
+ if( c2 == 0.0f )
+ return 0.0f;
+ else
+ return c1 / c2;
+}
+
//TA: wolf trail stuff
// Ridah
/*