No more default 800 gravity on items

Thrown knife+Glass fix - NiceAss
This commit is contained in:
Bryce Hutchings 2002-01-14 01:20:45 +00:00
parent 8b181630b7
commit 95a9f25d00
6 changed files with 161 additions and 28 deletions

View file

@ -5,6 +5,10 @@
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// //
// $Log$ // $Log$
// Revision 1.30 2002/01/14 01:20:45 niceass
// No more default 800 gravity on items
// Thrown knife+Glass fix - NiceAss
//
// Revision 1.29 2002/01/11 20:20:58 jbravo // Revision 1.29 2002/01/11 20:20:58 jbravo
// Adding TP to main branch // Adding TP to main branch
// //
@ -1355,7 +1359,7 @@ void G_BounceItem( gentity_t *ent, trace_t *trace ) {
// reflect the velocity on the trace plane // reflect the velocity on the trace plane
hitTime = level.previousTime + ( level.time - level.previousTime ) * trace->fraction; hitTime = level.previousTime + ( level.time - level.previousTime ) * trace->fraction;
BG_EvaluateTrajectoryDelta( &ent->s.pos, hitTime, velocity ); G_EvaluateTrajectoryDelta( &ent->s.pos, hitTime, velocity );
dot = DotProduct( velocity, trace->plane.normal ); dot = DotProduct( velocity, trace->plane.normal );
VectorMA( velocity, -2*dot, trace->plane.normal, ent->s.pos.trDelta ); VectorMA( velocity, -2*dot, trace->plane.normal, ent->s.pos.trDelta );
@ -1407,7 +1411,7 @@ void G_RunItem( gentity_t *ent ) {
} }
// get current position // get current position
BG_EvaluateTrajectory( &ent->s.pos, level.time, origin ); G_EvaluateTrajectory( &ent->s.pos, level.time, origin );
// trace a line from the previous position to the current position // trace a line from the previous position to the current position
if ( ent->clipmask ) { if ( ent->clipmask ) {

View file

@ -5,6 +5,10 @@
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// //
// $Log$ // $Log$
// Revision 1.35 2002/01/14 01:20:45 niceass
// No more default 800 gravity on items
// Thrown knife+Glass fix - NiceAss
//
// Revision 1.34 2002/01/11 20:20:58 jbravo // Revision 1.34 2002/01/11 20:20:58 jbravo
// Adding TP to main branch // Adding TP to main branch
// //
@ -779,6 +783,9 @@ void DropPortalDestination( gentity_t *ent );
void G_BreakGlass( gentity_t *ent, vec3_t point, int mod );//Blaze: Breakable glass void G_BreakGlass( gentity_t *ent, vec3_t point, int mod );//Blaze: Breakable glass
void G_RunDlight ( gentity_t *ent ); // Elder: dlight running void G_RunDlight ( gentity_t *ent ); // Elder: dlight running
void G_EvaluateTrajectory( const trajectory_t *tr, int atTime, vec3_t result );
void G_EvaluateTrajectoryDelta( const trajectory_t *tr, int atTime, vec3_t result );
void G_GravityChange(void);
// //
// g_weapon.c // g_weapon.c

View file

@ -5,6 +5,10 @@
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// //
// $Log$ // $Log$
// Revision 1.17 2002/01/14 01:20:45 niceass
// No more default 800 gravity on items
// Thrown knife+Glass fix - NiceAss
//
// Revision 1.16 2002/01/11 20:20:58 jbravo // Revision 1.16 2002/01/11 20:20:58 jbravo
// Adding TP to main branch // Adding TP to main branch
// //
@ -418,7 +422,7 @@ void G_UpdateCvars( void ) {
if ( cv->modificationCount != cv->vmCvar->modificationCount ) { if ( cv->modificationCount != cv->vmCvar->modificationCount ) {
cv->modificationCount = cv->vmCvar->modificationCount; cv->modificationCount = cv->vmCvar->modificationCount;
if (Q_stricmp (cv->cvarName, "g_gravity") == 0) G_GravityChange();
if ( cv->trackChange ) { if ( cv->trackChange ) {
trap_SendServerCommand( -1, va("print \"Server: %s changed to %s\n\"", trap_SendServerCommand( -1, va("print \"Server: %s changed to %s\n\"",
cv->cvarName, cv->vmCvar->string ) ); cv->cvarName, cv->vmCvar->string ) );

View file

@ -5,6 +5,10 @@
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// //
// $Log$ // $Log$
// Revision 1.19 2002/01/14 01:20:45 niceass
// No more default 800 gravity on items
// Thrown knife+Glass fix - NiceAss
//
// Revision 1.18 2002/01/11 19:48:30 jbravo // Revision 1.18 2002/01/11 19:48:30 jbravo
// Formatted the source in non DOS format. // Formatted the source in non DOS format.
// //
@ -754,3 +758,112 @@ void DropPortalSource( gentity_t *player ) {
} }
#endif #endif
/*
================
G_EvaluateTrajectory
================
*/
void G_EvaluateTrajectory( const trajectory_t *tr, int atTime, vec3_t result ) {
float deltaTime;
float phase;
switch( tr->trType ) {
case TR_STATIONARY:
case TR_INTERPOLATE:
VectorCopy( tr->trBase, result );
break;
case TR_LINEAR:
deltaTime = ( atTime - tr->trTime ) * 0.001; // milliseconds to seconds
VectorMA( tr->trBase, deltaTime, tr->trDelta, result );
break;
case TR_SINE:
deltaTime = ( atTime - tr->trTime ) / (float) tr->trDuration;
phase = sin( deltaTime * M_PI * 2 );
VectorMA( tr->trBase, phase, tr->trDelta, result );
break;
case TR_LINEAR_STOP:
if ( atTime > tr->trTime + tr->trDuration ) {
atTime = tr->trTime + tr->trDuration;
}
deltaTime = ( atTime - tr->trTime ) * 0.001; // milliseconds to seconds
if ( deltaTime < 0 ) {
deltaTime = 0;
}
VectorMA( tr->trBase, deltaTime, tr->trDelta, result );
break;
case TR_GRAVITY:
deltaTime = ( atTime - tr->trTime ) * 0.001; // milliseconds to seconds
VectorMA( tr->trBase, deltaTime, tr->trDelta, result );
result[2] -= 0.5 * (float)g_gravity.integer * deltaTime * deltaTime;
break;
default:
Com_Error( ERR_DROP, "G_EvaluateTrajectory: unknown trType: %i", tr->trTime );
break;
}
}
/*
================
G_EvaluateTrajectoryDelta
For determining velocity at a given time
================
*/
void G_EvaluateTrajectoryDelta( const trajectory_t *tr, int atTime, vec3_t result ) {
float deltaTime;
float phase;
switch( tr->trType ) {
case TR_STATIONARY:
case TR_INTERPOLATE:
VectorClear( result );
break;
case TR_LINEAR:
VectorCopy( tr->trDelta, result );
break;
case TR_SINE:
deltaTime = ( atTime - tr->trTime ) / (float) tr->trDuration;
phase = cos( deltaTime * M_PI * 2 ); // derivative of sin = cos
phase *= 0.5;
VectorScale( tr->trDelta, phase, result );
break;
case TR_LINEAR_STOP:
if ( atTime > tr->trTime + tr->trDuration ) {
VectorClear( result );
return;
}
VectorCopy( tr->trDelta, result );
break;
case TR_GRAVITY:
deltaTime = ( atTime - tr->trTime ) * 0.001; // milliseconds to seconds
VectorCopy( tr->trDelta, result );
result[2] -= (float)g_gravity.integer * deltaTime;
break;
default:
Com_Error( ERR_DROP, "G_EvaluateTrajectoryDelta: unknown trType: %i", tr->trTime );
break;
}
}
/*
================
G_EvaluateTrajectoryDelta - By NiceAss
Will update all ET_MISSILE entities with TR_GRAVITY on a g_gravity change.
================*/
void G_GravityChange(void) {
int i;
gentity_t *ent;
ent = &g_entities[0];
for (i=0 ; i<level.num_entities ; i++, ent++) {
if ( ent->s.pos.trType == TR_GRAVITY &&
ent->s.eType == ET_MISSILE )
{
G_EvaluateTrajectoryDelta( &ent->s.pos, level.time, ent->s.pos.trDelta );
VectorCopy( ent->r.currentOrigin, ent->s.pos.trBase );
ent->s.pos.trTime = level.time;
}
}
}

View file

@ -5,6 +5,10 @@
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// //
// $Log$ // $Log$
// Revision 1.21 2002/01/14 01:20:45 niceass
// No more default 800 gravity on items
// Thrown knife+Glass fix - NiceAss
//
// Revision 1.20 2002/01/11 19:48:30 jbravo // Revision 1.20 2002/01/11 19:48:30 jbravo
// Formatted the source in non DOS format. // Formatted the source in non DOS format.
// //
@ -32,7 +36,7 @@ void G_BounceMissile( gentity_t *ent, trace_t *trace ) {
// reflect the velocity on the trace plane // reflect the velocity on the trace plane
hitTime = level.previousTime + ( level.time - level.previousTime ) * trace->fraction; hitTime = level.previousTime + ( level.time - level.previousTime ) * trace->fraction;
BG_EvaluateTrajectoryDelta( &ent->s.pos, hitTime, velocity ); G_EvaluateTrajectoryDelta( &ent->s.pos, hitTime, velocity );
dot = DotProduct( velocity, trace->plane.normal ); dot = DotProduct( velocity, trace->plane.normal );
VectorMA( velocity, -2*dot, trace->plane.normal, ent->s.pos.trDelta ); VectorMA( velocity, -2*dot, trace->plane.normal, ent->s.pos.trDelta );
@ -62,7 +66,7 @@ void G_ExplodeMissile( gentity_t *ent ) {
vec3_t dir; vec3_t dir;
vec3_t origin; vec3_t origin;
BG_EvaluateTrajectory( &ent->s.pos, level.time, origin ); G_EvaluateTrajectory( &ent->s.pos, level.time, origin );
SnapVector( origin ); SnapVector( origin );
G_SetOrigin( ent, origin ); G_SetOrigin( ent, origin );
@ -338,7 +342,7 @@ void G_MissileImpact( gentity_t *ent, trace_t *trace ) {
//g_entities[ent->r.ownerNum].client->grenHits++; //g_entities[ent->r.ownerNum].client->grenHits++;
hitClient = qtrue; hitClient = qtrue;
} }
BG_EvaluateTrajectoryDelta( &ent->s.pos, level.time, velocity ); G_EvaluateTrajectoryDelta( &ent->s.pos, level.time, velocity );
if ( VectorLength( velocity ) == 0 ) { if ( VectorLength( velocity ) == 0 ) {
velocity[2] = 1; // stepped on a grenade velocity[2] = 1; // stepped on a grenade
} }
@ -465,22 +469,19 @@ void G_MissileImpact( gentity_t *ent, trace_t *trace ) {
//spawn a knife at its trajectory end-point //spawn a knife at its trajectory end-point
xr_item = BG_FindItemForWeapon( WP_KNIFE ); xr_item = BG_FindItemForWeapon( WP_KNIFE );
BG_EvaluateTrajectoryDelta(&ent->s.pos, level.time, knifeVelocity); G_EvaluateTrajectoryDelta(&ent->s.pos, level.time, knifeVelocity);
if (other->s.eType == ET_BREAKABLE) { if (other->s.eType == ET_BREAKABLE) {
//VectorScale(knifeVelocity, -0.25, knifeVelocity); VectorCopy(trace->endpos, origin);
//Blaze: Moved from above, now deal the damage to the glass, and let the knife drop G_Damage (other, ent, &g_entities[ent->r.ownerNum], velocity, origin, THROW_DAMAGE, 0, MOD_KNIFE_THROWN);
if ( ent->s.weapon == WP_KNIFE && other->s.eType == ET_BREAKABLE ) {
BG_EvaluateTrajectory( &ent->s.pos, level.time, origin); // NiceAss: Find current position and set it.
//velocity[0] = 0; VectorCopy(trace->endpos, ent->s.pos.trBase);
//velocity[1] = 0; ent->s.pos.trTime = level.time;
//velocity[2] = 0; // And cut the velocity down.
G_Damage (other, ent, &g_entities[ent->r.ownerNum], velocity, origin, THROW_DAMAGE, 0, MOD_KNIFE_THROWN); VectorScale(ent->s.pos.trDelta, .2, ent->s.pos.trDelta);
}
// NiceAss: Cut its velocity in half.
VectorScale( ent->s.pos.trDelta, .6, ent->s.pos.trDelta);
return; return;
/* /* OLD METHOD
//breakable "hit"; make it fall to the ground //breakable "hit"; make it fall to the ground
xr_drop = LaunchItem(xr_item, trace->endpos, velocity, FL_DROPPED_ITEM); xr_drop = LaunchItem(xr_item, trace->endpos, velocity, FL_DROPPED_ITEM);
@ -568,7 +569,7 @@ void G_ExplodeMissile( gentity_t *ent ) {
vec3_t dir; vec3_t dir;
vec3_t origin; vec3_t origin;
BG_EvaluateTrajectory( &ent->s.pos, level.time, origin ); G_EvaluateTrajectory( &ent->s.pos, level.time, origin );
SnapVector( origin ); SnapVector( origin );
G_SetOrigin( ent, origin ); G_SetOrigin( ent, origin );
@ -604,7 +605,7 @@ void G_RunMissile( gentity_t *ent ) {
int passent; int passent;
// get current position // get current position
BG_EvaluateTrajectory( &ent->s.pos, level.time, origin ); G_EvaluateTrajectory( &ent->s.pos, level.time, origin );
// if this missile bounced off an invulnerability sphere // if this missile bounced off an invulnerability sphere
if ( ent->target_ent ) { if ( ent->target_ent ) {
@ -656,7 +657,7 @@ void G_RunMissile( gentity_t *ent ) {
{ {
vec3_t knifeVelocity; vec3_t knifeVelocity;
BG_EvaluateTrajectoryDelta(&ent->s.pos, level.time, knifeVelocity); G_EvaluateTrajectoryDelta(&ent->s.pos, level.time, knifeVelocity);
vectoangles(knifeVelocity, ent->s.angles); vectoangles(knifeVelocity, ent->s.angles);
ent->s.angles[0] += level.time % 360; ent->s.angles[0] += level.time % 360;
} }

View file

@ -5,6 +5,10 @@
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// //
// $Log$ // $Log$
// Revision 1.19 2002/01/14 01:20:44 niceass
// No more default 800 gravity on items
// Thrown knife+Glass fix - NiceAss
//
// Revision 1.18 2002/01/11 19:48:30 jbravo // Revision 1.18 2002/01/11 19:48:30 jbravo
// Formatted the source in non DOS format. // Formatted the source in non DOS format.
// //
@ -472,8 +476,8 @@ void G_MoverTeam( gentity_t *ent ) {
pushed_p = pushed; pushed_p = pushed;
for (part = ent ; part ; part=part->teamchain) { for (part = ent ; part ; part=part->teamchain) {
// get current position // get current position
BG_EvaluateTrajectory( &part->s.pos, level.time, origin ); G_EvaluateTrajectory( &part->s.pos, level.time, origin );
BG_EvaluateTrajectory( &part->s.apos, level.time, angles ); G_EvaluateTrajectory( &part->s.apos, level.time, angles );
VectorSubtract( origin, part->r.currentOrigin, move ); VectorSubtract( origin, part->r.currentOrigin, move );
VectorSubtract( angles, part->r.currentAngles, amove ); VectorSubtract( angles, part->r.currentAngles, amove );
if ( !G_MoverPush( part, move, amove, &obstacle ) ) { if ( !G_MoverPush( part, move, amove, &obstacle ) ) {
@ -486,8 +490,8 @@ void G_MoverTeam( gentity_t *ent ) {
for ( part = ent ; part ; part = part->teamchain ) { for ( part = ent ; part ; part = part->teamchain ) {
part->s.pos.trTime += level.time - level.previousTime; part->s.pos.trTime += level.time - level.previousTime;
part->s.apos.trTime += level.time - level.previousTime; part->s.apos.trTime += level.time - level.previousTime;
BG_EvaluateTrajectory( &part->s.pos, level.time, part->r.currentOrigin ); G_EvaluateTrajectory( &part->s.pos, level.time, part->r.currentOrigin );
BG_EvaluateTrajectory( &part->s.apos, level.time, part->r.currentAngles ); G_EvaluateTrajectory( &part->s.apos, level.time, part->r.currentAngles );
trap_LinkEntity( part ); trap_LinkEntity( part );
} }
@ -611,8 +615,8 @@ void SetMoverState( gentity_t *ent, moverState_t moverState, int time ) {
ent->s.apos.trType = TR_LINEAR_STOP; ent->s.apos.trType = TR_LINEAR_STOP;
break; break;
} }
BG_EvaluateTrajectory( &ent->s.pos, level.time, ent->r.currentOrigin ); G_EvaluateTrajectory( &ent->s.pos, level.time, ent->r.currentOrigin );
BG_EvaluateTrajectory( &ent->s.apos, level.time, ent->r.currentAngles ); G_EvaluateTrajectory( &ent->s.apos, level.time, ent->r.currentAngles );
trap_LinkEntity( ent ); trap_LinkEntity( ent );
} }