summaryrefslogtreecommitdiff
path: root/src/game
diff options
context:
space:
mode:
authorMichael Levin <risujin@fastmail.fm>2009-10-03 11:17:37 +0000
committerTim Angus <tim@ngus.net>2013-01-03 00:14:51 +0000
commita0c96de3cd2b5fd1b57276caafc07e17a54d001a (patch)
tree62bd36fdfa3e4a6fb6878898010d7cf3711f0a3a /src/game
parent6916f8fb5d3a19bf0bdfb84948b19445954306d9 (diff)
Some more work on the Mass Driver:
* Fixed a bug in SnapVectorTowards which would snap incorrectly if the point was below the world origin. Also added an analogous function to work with normals (SnapVectorNormal). * Added weapon.cfg to source control to set alwaysImpact (to show flash along with blood spurt when hitting a player). * The maximum number of hits allowed moved to tremulous.h, set MDRIVER_MAX_HITS. * Since a the visual effects changed, removed old massDriverFire() function and toggle switch.
Diffstat (limited to 'src/game')
-rw-r--r--src/game/g_weapon.c86
-rw-r--r--src/game/tremulous.h2
2 files changed, 27 insertions, 61 deletions
diff --git a/src/game/g_weapon.c b/src/game/g_weapon.c
index 22d4dd74..52624862 100644
--- a/src/game/g_weapon.c
+++ b/src/game/g_weapon.c
@@ -197,6 +197,7 @@ static void G_WideTrace( trace_t *tr, gentity_t *ent, float range,
/*
======================
SnapVectorTowards
+SnapVectorNormal
Round a vector to integers for more efficient network
transmission, but make sure that it rounds towards a given point
@@ -210,10 +211,23 @@ void SnapVectorTowards( vec3_t v, vec3_t to )
for( i = 0 ; i < 3 ; i++ )
{
- if( to[ i ] <= v[ i ] )
- v[ i ] = (int)v[ i ];
+ if( v[ i ] >= 0 )
+ v[ i ] = (int)( v[ i ] + ( to[ i ] <= v[ i ] ? 0 : 1 ) );
else
- v[ i ] = (int)v[ i ] + 1;
+ v[ i ] = (int)( v[ i ] + ( to[ i ] <= v[ i ] ? -1 : 0 ) );
+ }
+}
+
+void SnapVectorNormal( vec3_t v, vec3_t normal )
+{
+ int i;
+
+ for( i = 0 ; i < 3 ; i++ )
+ {
+ if( v[ i ] >= 0 )
+ v[ i ] = (int)( v[ i ] + ( normal[ i ] <= 0 ? 0 : 1 ) );
+ else
+ v[ i ] = (int)( v[ i ] + ( normal[ i ] <= 0 ? -1 : 0 ) );
}
}
@@ -437,14 +451,11 @@ MASS DRIVER
======================================================================
*/
-#ifdef MDRIVER_SHOOT_THROUGH
-#define MDRIVER_MAX_HITS 16
-
void massDriverFire( gentity_t *ent )
{
trace_t tr;
vec3_t hitPoints[ MDRIVER_MAX_HITS ], hitNormals[ MDRIVER_MAX_HITS ],
- origin, originToEnd, muzzleToOrigin, end;
+ origin, originToEnd, muzzleToEnd, muzzleToOrigin, end;
gentity_t *traceEnts[ MDRIVER_MAX_HITS ], *traceEnt, *tent;
float length_offset;
int i, hits = 0, skipent;
@@ -480,17 +491,15 @@ void massDriverFire( gentity_t *ent )
// save the hit entity, position, and normal
VectorCopy( tr.endpos, hitPoints[ hits ] );
VectorCopy( tr.plane.normal, hitNormals[ hits ] );
- SnapVectorTowards( hitPoints[ hits ], muzzle );
+ SnapVectorNormal( hitPoints[ hits ], tr.plane.normal );
traceEnts[ hits++ ] = traceEnt;
}
- if( !hits )
- return;
// originate trail line from the gun tip, not the head!
VectorCopy( muzzle, origin );
- VectorMA( origin, -8, up, origin );
- VectorMA( origin, 6, right, origin );
- VectorMA( origin, 48, forward, origin );
+ VectorMA( origin, -6, up, origin );
+ VectorMA( origin, 4, right, origin );
+ VectorMA( origin, 24, forward, origin );
// save the final position
VectorCopy( tr.endpos, end );
@@ -499,7 +508,9 @@ void massDriverFire( gentity_t *ent )
// origin is further in front than muzzle, need to adjust length
VectorSubtract( origin, muzzle, muzzleToOrigin );
- length_offset = VectorLength( muzzleToOrigin );
+ VectorSubtract( end, muzzle, muzzleToEnd );
+ VectorNormalize( muzzleToEnd );
+ length_offset = DotProduct( muzzleToEnd, muzzleToOrigin );
// now that the trace is finished, we know where we stopped and can generate
// visually correct impact locations
@@ -535,7 +546,7 @@ void massDriverFire( gentity_t *ent )
}
// create an event entity for the trail, doubles as an impact event
- SnapVectorTowards( end, muzzle );
+ SnapVectorNormal( end, tr.plane.normal );
tent = G_TempEntity( end, EV_MASS_DRIVER );
tent->s.eventParm = DirToByte( tr.plane.normal );
tent->s.weapon = ent->s.weapon;
@@ -545,51 +556,6 @@ void massDriverFire( gentity_t *ent )
G_UnlaggedOff( );
}
-#else
-
-void massDriverFire( gentity_t *ent )
-{
- trace_t tr;
- vec3_t end;
- gentity_t *tent;
- gentity_t *traceEnt;
-
- VectorMA( muzzle, 8192 * 16, forward, end );
-
- G_UnlaggedOn( muzzle, 8192 * 16 );
- trap_Trace( &tr, muzzle, NULL, NULL, end, ent->s.number, MASK_SHOT );
- G_UnlaggedOff( );
-
- if( tr.surfaceFlags & SURF_NOIMPACT )
- return;
-
- traceEnt = &g_entities[ tr.entityNum ];
-
- // snap the endpos to integers, but nudged towards the line
- SnapVectorTowards( tr.endpos, muzzle );
-
- // send impact
- if( traceEnt->takedamage && traceEnt->client )
- {
- BloodSpurt( ent, traceEnt, &tr );
- }
- else
- {
- tent = G_TempEntity( tr.endpos, EV_MISSILE_MISS );
- tent->s.eventParm = DirToByte( tr.plane.normal );
- tent->s.weapon = ent->s.weapon;
- tent->s.generic1 = ent->s.generic1; //weaponMode
- }
-
- if( traceEnt->takedamage )
- {
- G_Damage( traceEnt, ent, ent, forward, tr.endpos,
- MDRIVER_DMG, 0, MOD_MDRIVER );
- }
-}
-
-#endif
-
/*
======================================================================
diff --git a/src/game/tremulous.h b/src/game/tremulous.h
index ae56f4a4..55761533 100644
--- a/src/game/tremulous.h
+++ b/src/game/tremulous.h
@@ -422,7 +422,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#define MDRIVER_REPEAT 1000
#define MDRIVER_K_SCALE 1.0f
#define MDRIVER_RELOAD 2000
-#define MDRIVER_SHOOT_THROUGH // uncomment to enable MD shooting through entities
+#define MDRIVER_MAX_HITS 16
#define CHAINGUN_PRICE 400
#define CHAINGUN_BULLETS 300