summaryrefslogtreecommitdiff
path: root/src/game/g_mover.c
diff options
context:
space:
mode:
authorTim Angus <tim@ngus.net>2002-09-09 23:32:27 +0000
committerTim Angus <tim@ngus.net>2002-09-09 23:32:27 +0000
commitc0e95997d9e9fcaa220704c8c67b50d6761d1b66 (patch)
tree307242d290de1715df0f4f28dd7e08ccb7006f5c /src/game/g_mover.c
parent9af7c524043a8f296ea5f45ec7f73c16e29921b5 (diff)
* General tidy up and beautification of code
* Removal of most of the legacy Q3A stuff * Cursor no longer displayed on load screen * (Biggest commit EVAR?)
Diffstat (limited to 'src/game/g_mover.c')
-rw-r--r--src/game/g_mover.c914
1 files changed, 496 insertions, 418 deletions
diff --git a/src/game/g_mover.c b/src/game/g_mover.c
index 13d99ff5..7327c4cd 100644
--- a/src/game/g_mover.c
+++ b/src/game/g_mover.c
@@ -28,13 +28,15 @@ PUSHMOVE
void MatchTeam( gentity_t *teamLeader, int moverState, int time );
-typedef struct {
+typedef struct
+{
gentity_t *ent;
vec3_t origin;
vec3_t angles;
float deltayaw;
} pushed_t;
-pushed_t pushed[MAX_GENTITIES], *pushed_p;
+
+pushed_t pushed[ MAX_GENTITIES ], *pushed_p;
/*
@@ -43,22 +45,22 @@ G_TestEntityPosition
============
*/
-gentity_t *G_TestEntityPosition( gentity_t *ent ) {
+gentity_t *G_TestEntityPosition( gentity_t *ent )
+{
trace_t tr;
int mask;
- if ( ent->clipmask ) {
+ if( ent->clipmask )
mask = ent->clipmask;
- } else {
+ else
mask = MASK_SOLID;
- }
- if ( ent->client ) {
+
+ if( ent->client )
trap_Trace( &tr, ent->client->ps.origin, ent->r.mins, ent->r.maxs, ent->client->ps.origin, ent->s.number, mask );
- } else {
+ else
trap_Trace( &tr, ent->s.pos.trBase, ent->r.mins, ent->r.maxs, ent->s.pos.trBase, ent->s.number, mask );
- }
- if (tr.startsolid)
+ if( tr.startsolid )
return &g_entities[ tr.entityNum ];
return NULL;
@@ -69,9 +71,10 @@ gentity_t *G_TestEntityPosition( gentity_t *ent ) {
G_CreateRotationMatrix
================
*/
-void G_CreateRotationMatrix(vec3_t angles, vec3_t matrix[3]) {
- AngleVectors(angles, matrix[0], matrix[1], matrix[2]);
- VectorInverse(matrix[1]);
+void G_CreateRotationMatrix( vec3_t angles, vec3_t matrix[ 3 ] )
+{
+ AngleVectors( angles, matrix[ 0 ], matrix[ 1 ], matrix[ 2 ] );
+ VectorInverse( matrix[ 1 ] );
}
/*
@@ -79,11 +82,15 @@ void G_CreateRotationMatrix(vec3_t angles, vec3_t matrix[3]) {
G_TransposeMatrix
================
*/
-void G_TransposeMatrix(vec3_t matrix[3], vec3_t transpose[3]) {
+void G_TransposeMatrix( vec3_t matrix[ 3 ], vec3_t transpose[ 3 ] )
+{
int i, j;
- for (i = 0; i < 3; i++) {
- for (j = 0; j < 3; j++) {
- transpose[i][j] = matrix[j][i];
+
+ for( i = 0; i < 3; i++ )
+ {
+ for( j = 0; j < 3; j++ )
+ {
+ transpose[ i ][ j ] = matrix[ j ][ i ];
}
}
}
@@ -93,13 +100,14 @@ void G_TransposeMatrix(vec3_t matrix[3], vec3_t transpose[3]) {
G_RotatePoint
================
*/
-void G_RotatePoint(vec3_t point, vec3_t matrix[3]) {
+void G_RotatePoint( vec3_t point, vec3_t matrix[ 3 ] )
+{
vec3_t tvec;
- VectorCopy(point, tvec);
- point[0] = DotProduct(matrix[0], tvec);
- point[1] = DotProduct(matrix[1], tvec);
- point[2] = DotProduct(matrix[2], tvec);
+ VectorCopy( point, tvec );
+ point[ 0 ] = DotProduct( matrix[ 0 ], tvec );
+ point[ 1 ] = DotProduct( matrix[ 1 ], tvec );
+ point[ 2 ] = DotProduct( matrix[ 2 ], tvec );
}
/*
@@ -109,28 +117,30 @@ G_TryPushingEntity
Returns qfalse if the move is blocked
==================
*/
-qboolean G_TryPushingEntity( gentity_t *check, gentity_t *pusher, vec3_t move, vec3_t amove ) {
- vec3_t matrix[3], transpose[3];
+qboolean G_TryPushingEntity( gentity_t *check, gentity_t *pusher, vec3_t move, vec3_t amove )
+{
+ vec3_t matrix[ 3 ], transpose[ 3 ];
vec3_t org, org2, move2;
gentity_t *block;
// EF_MOVER_STOP will just stop when contacting another entity
// instead of pushing it, but entities can still ride on top of it
- if ( ( pusher->s.eFlags & EF_MOVER_STOP ) &&
- check->s.groundEntityNum != pusher->s.number ) {
+ if( ( pusher->s.eFlags & EF_MOVER_STOP ) &&
+ check->s.groundEntityNum != pusher->s.number )
return qfalse;
- }
// save off the old position
- if (pushed_p > &pushed[MAX_GENTITIES]) {
+ if( pushed_p > &pushed[ MAX_GENTITIES ] )
G_Error( "pushed_p > &pushed[MAX_GENTITIES]" );
- }
+
pushed_p->ent = check;
- VectorCopy (check->s.pos.trBase, pushed_p->origin);
- VectorCopy (check->s.apos.trBase, pushed_p->angles);
- if ( check->client ) {
- pushed_p->deltayaw = check->client->ps.delta_angles[YAW];
- VectorCopy (check->client->ps.origin, pushed_p->origin);
+ VectorCopy( check->s.pos.trBase, pushed_p->origin );
+ VectorCopy( check->s.apos.trBase, pushed_p->angles );
+
+ if( check->client )
+ {
+ pushed_p->deltayaw = check->client->ps.delta_angles[ YAW ];
+ VectorCopy( check->client->ps.origin, pushed_p->origin );
}
pushed_p++;
@@ -138,52 +148,58 @@ qboolean G_TryPushingEntity( gentity_t *check, gentity_t *pusher, vec3_t move,
// figure movement due to the pusher's amove
G_CreateRotationMatrix( amove, transpose );
G_TransposeMatrix( transpose, matrix );
- if ( check->client ) {
- VectorSubtract (check->client->ps.origin, pusher->r.currentOrigin, org);
- }
- else {
- VectorSubtract (check->s.pos.trBase, pusher->r.currentOrigin, org);
- }
+
+ if( check->client )
+ VectorSubtract( check->client->ps.origin, pusher->r.currentOrigin, org );
+ else
+ VectorSubtract( check->s.pos.trBase, pusher->r.currentOrigin, org );
+
VectorCopy( org, org2 );
G_RotatePoint( org2, matrix );
- VectorSubtract (org2, org, move2);
+ VectorSubtract( org2, org, move2 );
// add movement
- VectorAdd (check->s.pos.trBase, move, check->s.pos.trBase);
- VectorAdd (check->s.pos.trBase, move2, check->s.pos.trBase);
- if ( check->client ) {
- VectorAdd (check->client->ps.origin, move, check->client->ps.origin);
- VectorAdd (check->client->ps.origin, move2, check->client->ps.origin);
+ VectorAdd( check->s.pos.trBase, move, check->s.pos.trBase );
+ VectorAdd( check->s.pos.trBase, move2, check->s.pos.trBase );
+
+ if( check->client )
+ {
+ VectorAdd( check->client->ps.origin, move, check->client->ps.origin );
+ VectorAdd( check->client->ps.origin, move2, check->client->ps.origin );
// make sure the client's view rotates when on a rotating mover
- check->client->ps.delta_angles[YAW] += ANGLE2SHORT(amove[YAW]);
+ check->client->ps.delta_angles[ YAW ] += ANGLE2SHORT( amove[ YAW ] );
}
// may have pushed them off an edge
- if ( check->s.groundEntityNum != pusher->s.number ) {
+ if( check->s.groundEntityNum != pusher->s.number )
check->s.groundEntityNum = -1;
- }
block = G_TestEntityPosition( check );
- if (!block) {
+
+ if( !block )
+ {
// pushed ok
- if ( check->client ) {
+ if( check->client )
VectorCopy( check->client->ps.origin, check->r.currentOrigin );
- } else {
+ else
VectorCopy( check->s.pos.trBase, check->r.currentOrigin );
- }
- trap_LinkEntity (check);
+
+ trap_LinkEntity( check );
return qtrue;
}
// if it is ok to leave in the old position, do it
// this is only relevent for riding entities, not pushed
// Sliding trapdoors can cause this.
- VectorCopy( (pushed_p-1)->origin, check->s.pos.trBase);
- if ( check->client ) {
- VectorCopy( (pushed_p-1)->origin, check->client->ps.origin);
- }
- VectorCopy( (pushed_p-1)->angles, check->s.apos.trBase );
- block = G_TestEntityPosition (check);
- if ( !block ) {
+ VectorCopy( ( pushed_p - 1 )->origin, check->s.pos.trBase );
+
+ if( check->client )
+ VectorCopy( ( pushed_p - 1 )->origin, check->client->ps.origin );
+
+ VectorCopy( ( pushed_p - 1 )->angles, check->s.apos.trBase );
+ block = G_TestEntityPosition( check );
+
+ if( !block )
+ {
check->s.groundEntityNum = -1;
pushed_p--;
return qtrue;
@@ -203,13 +219,14 @@ otherwise riders would continue to slide.
If qfalse is returned, *obstacle will be the blocking entity
============
*/
-qboolean G_MoverPush( gentity_t *pusher, vec3_t move, vec3_t amove, gentity_t **obstacle ) {
- int i, e;
+qboolean G_MoverPush( gentity_t *pusher, vec3_t move, vec3_t amove, gentity_t **obstacle )
+{
+ int i, e;
gentity_t *check;
vec3_t mins, maxs;
pushed_t *p;
- int entityList[MAX_GENTITIES];
- int listedEntities;
+ int entityList[ MAX_GENTITIES ];
+ int listedEntities;
vec3_t totalMins, totalMaxs;
*obstacle = NULL;
@@ -217,31 +234,37 @@ qboolean G_MoverPush( gentity_t *pusher, vec3_t move, vec3_t amove, gentity_t **
// mins/maxs are the bounds at the destination
// totalMins / totalMaxs are the bounds for the entire move
- if ( pusher->r.currentAngles[0] || pusher->r.currentAngles[1] || pusher->r.currentAngles[2]
- || amove[0] || amove[1] || amove[2] ) {
+ if( pusher->r.currentAngles[ 0 ] || pusher->r.currentAngles[ 1 ] || pusher->r.currentAngles[ 2 ]
+ || amove[ 0 ] || amove[ 1 ] || amove[ 2 ] )
+ {
float radius;
radius = RadiusFromBounds( pusher->r.mins, pusher->r.maxs );
- for ( i = 0 ; i < 3 ; i++ ) {
- mins[i] = pusher->r.currentOrigin[i] + move[i] - radius;
- maxs[i] = pusher->r.currentOrigin[i] + move[i] + radius;
- totalMins[i] = mins[i] - move[i];
- totalMaxs[i] = maxs[i] - move[i];
+
+ for( i = 0 ; i < 3 ; i++ )
+ {
+ mins[ i ] = pusher->r.currentOrigin[ i ] + move[ i ] - radius;
+ maxs[ i ] = pusher->r.currentOrigin[ i ] + move[ i ] + radius;
+ totalMins[ i ] = mins[ i ] - move[ i ];
+ totalMaxs[ i ] = maxs[ i ] - move[ i ];
}
- } else {
- for (i=0 ; i<3 ; i++) {
- mins[i] = pusher->r.absmin[i] + move[i];
- maxs[i] = pusher->r.absmax[i] + move[i];
+ }
+ else
+ {
+ for( i = 0; i < 3; i++ )
+ {
+ mins[ i ] = pusher->r.absmin[ i ] + move[ i ];
+ maxs[ i ] = pusher->r.absmax[ i ] + move[ i ];
}
VectorCopy( pusher->r.absmin, totalMins );
VectorCopy( pusher->r.absmax, totalMaxs );
- for (i=0 ; i<3 ; i++) {
- if ( move[i] > 0 ) {
- totalMaxs[i] += move[i];
- } else {
- totalMins[i] += move[i];
- }
+ for( i = 0; i < 3; i++ )
+ {
+ if( move[ i ] > 0 )
+ totalMaxs[ i ] += move[ i ];
+ else
+ totalMins[ i ] += move[ i ];
}
}
@@ -256,43 +279,43 @@ qboolean G_MoverPush( gentity_t *pusher, vec3_t move, vec3_t amove, gentity_t **
trap_LinkEntity( pusher );
// see if any solid entities are inside the final position
- for ( e = 0 ; e < listedEntities ; e++ ) {
+ for( e = 0 ; e < listedEntities ; e++ )
+ {
check = &g_entities[ entityList[ e ] ];
// only push items and players
- if ( check->s.eType != ET_ITEM && check->s.eType != ET_BUILDABLE &&
- check->s.eType != ET_CORPSE && check->s.eType != ET_PLAYER &&
- !check->physicsObject ) {
+ if( check->s.eType != ET_ITEM && check->s.eType != ET_BUILDABLE &&
+ check->s.eType != ET_CORPSE && check->s.eType != ET_PLAYER &&
+ !check->physicsObject )
continue;
- }
// if the entity is standing on the pusher, it will definitely be moved
- if ( check->s.groundEntityNum != pusher->s.number ) {
+ if( check->s.groundEntityNum != pusher->s.number )
+ {
// see if the ent needs to be tested
- if ( check->r.absmin[0] >= maxs[0]
- || check->r.absmin[1] >= maxs[1]
- || check->r.absmin[2] >= maxs[2]
- || check->r.absmax[0] <= mins[0]
- || check->r.absmax[1] <= mins[1]
- || check->r.absmax[2] <= mins[2] ) {
+ if( check->r.absmin[ 0 ] >= maxs[ 0 ]
+ || check->r.absmin[ 1 ] >= maxs[ 1 ]
+ || check->r.absmin[ 2 ] >= maxs[ 2 ]
+ || check->r.absmax[ 0 ] <= mins[ 0 ]
+ || check->r.absmax[ 1 ] <= mins[ 1 ]
+ || check->r.absmax[ 2 ] <= mins[ 2 ] )
continue;
- }
+
// see if the ent's bbox is inside the pusher's final position
// this does allow a fast moving object to pass through a thin entity...
- if (!G_TestEntityPosition (check)) {
+ if( !G_TestEntityPosition( check ) )
continue;
- }
}
// the entity needs to be pushed
- if ( G_TryPushingEntity( check, pusher, move, amove ) ) {
+ if( G_TryPushingEntity( check, pusher, move, amove ) )
continue;
- }
// the move was blocked an entity
// bobbing entities are instant-kill and never get blocked
- if ( pusher->s.pos.trType == TR_SINE || pusher->s.apos.trType == TR_SINE ) {
+ if( pusher->s.pos.trType == TR_SINE || pusher->s.apos.trType == TR_SINE )
+ {
G_Damage( check, pusher, pusher, NULL, NULL, 99999, 0, MOD_CRUSH );
continue;
}
@@ -304,15 +327,20 @@ qboolean G_MoverPush( gentity_t *pusher, vec3_t move, vec3_t amove, gentity_t **
// move back any entities we already moved
// go backwards, so if the same entity was pushed
// twice, it goes back to the original position
- for ( p=pushed_p-1 ; p>=pushed ; p-- ) {
- VectorCopy (p->origin, p->ent->s.pos.trBase);
- VectorCopy (p->angles, p->ent->s.apos.trBase);
- if ( p->ent->client ) {
- p->ent->client->ps.delta_angles[YAW] = p->deltayaw;
- VectorCopy (p->origin, p->ent->client->ps.origin);
+ for( p = pushed_p - 1; p >= pushed; p-- )
+ {
+ VectorCopy( p->origin, p->ent->s.pos.trBase );
+ VectorCopy( p->angles, p->ent->s.apos.trBase );
+
+ if( p->ent->client )
+ {
+ p->ent->client->ps.delta_angles[ YAW ] = p->deltayaw;
+ VectorCopy( p->origin, p->ent->client->ps.origin );
}
- trap_LinkEntity (p->ent);
+
+ trap_LinkEntity( p->ent );
}
+
return qfalse;
}
@@ -325,7 +353,8 @@ qboolean G_MoverPush( gentity_t *pusher, vec3_t move, vec3_t amove, gentity_t **
G_MoverTeam
=================
*/
-void G_MoverTeam( gentity_t *ent ) {
+void G_MoverTeam( gentity_t *ent )
+{
vec3_t move, amove;
gentity_t *part, *obstacle;
vec3_t origin, angles;
@@ -336,20 +365,22 @@ void G_MoverTeam( gentity_t *ent ) {
// any moves or calling any think functions
// if the move is blocked, all moved objects will be backed out
pushed_p = pushed;
- for (part = ent ; part ; part=part->teamchain) {
+ for( part = ent; part; part = part->teamchain )
+ {
// get current position
BG_EvaluateTrajectory( &part->s.pos, level.time, origin );
BG_EvaluateTrajectory( &part->s.apos, level.time, angles );
VectorSubtract( origin, part->r.currentOrigin, move );
VectorSubtract( angles, part->r.currentAngles, amove );
- if ( !G_MoverPush( part, move, amove, &obstacle ) ) {
+ if( !G_MoverPush( part, move, amove, &obstacle ) )
break; // move was blocked
- }
}
- if (part) {
+ if( part )
+ {
// go back to the previous position
- for ( part = ent ; part ; part = part->teamchain ) {
+ for( part = ent; part; part = part->teamchain )
+ {
part->s.pos.trTime += level.time - level.previousTime;
part->s.apos.trTime += level.time - level.previousTime;
BG_EvaluateTrajectory( &part->s.pos, level.time, part->r.currentOrigin );
@@ -358,20 +389,22 @@ void G_MoverTeam( gentity_t *ent ) {
}
// if the pusher has a "blocked" function, call it
- if (ent->blocked) {
+ if( ent->blocked )
ent->blocked( ent, obstacle );
- }
+
return;
}
// the move succeeded
- for ( part = ent ; part ; part = part->teamchain ) {
+ for( part = ent; part; part = part->teamchain )
+ {
// call the reached function if time is at or past end point
- if ( part->s.pos.trType == TR_LINEAR_STOP ) {
- if ( level.time >= part->s.pos.trTime + part->s.pos.trDuration ) {
- if ( part->reached ) {
+ if( part->s.pos.trType == TR_LINEAR_STOP )
+ {
+ if( level.time >= part->s.pos.trTime + part->s.pos.trDuration )
+ {
+ if( part->reached )
part->reached( part );
- }
}
}
}
@@ -383,17 +416,16 @@ G_RunMover
================
*/
-void G_RunMover( gentity_t *ent ) {
+void G_RunMover( gentity_t *ent )
+{
// if not a team captain, don't do anything, because
// the captain will handle everything
- if ( ent->flags & FL_TEAMSLAVE ) {
+ if( ent->flags & FL_TEAMSLAVE )
return;
- }
// if stationary at one of the positions, don't move anything
- if ( ent->s.pos.trType != TR_STATIONARY || ent->s.apos.trType != TR_STATIONARY ) {
+ if( ent->s.pos.trType != TR_STATIONARY || ent->s.apos.trType != TR_STATIONARY )
G_MoverTeam( ent );
- }
// check think function
G_RunThink( ent );
@@ -414,37 +446,43 @@ Pos1 is "at rest", pos2 is "activated"
SetMoverState
===============
*/
-void SetMoverState( gentity_t *ent, moverState_t moverState, int time ) {
- vec3_t delta;
- float f;
+void SetMoverState( gentity_t *ent, moverState_t moverState, int time )
+{
+ vec3_t delta;
+ float f;
ent->moverState = moverState;
ent->s.pos.trTime = time;
- switch( moverState ) {
- case MOVER_POS1:
- VectorCopy( ent->pos1, ent->s.pos.trBase );
- ent->s.pos.trType = TR_STATIONARY;
- break;
- case MOVER_POS2:
- VectorCopy( ent->pos2, ent->s.pos.trBase );
- ent->s.pos.trType = TR_STATIONARY;
- break;
- case MOVER_1TO2:
- VectorCopy( ent->pos1, ent->s.pos.trBase );
- VectorSubtract( ent->pos2, ent->pos1, delta );
- f = 1000.0 / ent->s.pos.trDuration;
- VectorScale( delta, f, ent->s.pos.trDelta );
- ent->s.pos.trType = TR_LINEAR_STOP;
- break;
- case MOVER_2TO1:
- VectorCopy( ent->pos2, ent->s.pos.trBase );
- VectorSubtract( ent->pos1, ent->pos2, delta );
- f = 1000.0 / ent->s.pos.trDuration;
- VectorScale( delta, f, ent->s.pos.trDelta );
- ent->s.pos.trType = TR_LINEAR_STOP;
- break;
- }
+ switch( moverState )
+ {
+ case MOVER_POS1:
+ VectorCopy( ent->pos1, ent->s.pos.trBase );
+ ent->s.pos.trType = TR_STATIONARY;
+ break;
+
+ case MOVER_POS2:
+ VectorCopy( ent->pos2, ent->s.pos.trBase );
+ ent->s.pos.trType = TR_STATIONARY;
+ break;
+
+ case MOVER_1TO2:
+ VectorCopy( ent->pos1, ent->s.pos.trBase );
+ VectorSubtract( ent->pos2, ent->pos1, delta );
+ f = 1000.0 / ent->s.pos.trDuration;
+ VectorScale( delta, f, ent->s.pos.trDelta );
+ ent->s.pos.trType = TR_LINEAR_STOP;
+ break;
+
+ case MOVER_2TO1:
+ VectorCopy( ent->pos2, ent->s.pos.trBase );
+ VectorSubtract( ent->pos1, ent->pos2, delta );
+ f = 1000.0 / ent->s.pos.trDuration;
+ VectorScale( delta, f, ent->s.pos.trDelta );
+ ent->s.pos.trType = TR_LINEAR_STOP;
+ break;
+ }
+
BG_EvaluateTrajectory( &ent->s.pos, level.time, ent->r.currentOrigin );
trap_LinkEntity( ent );
}
@@ -457,12 +495,12 @@ All entities in a mover team will move from pos1 to pos2
in the same amount of time
================
*/
-void MatchTeam( gentity_t *teamLeader, int moverState, int time ) {
+void MatchTeam( gentity_t *teamLeader, int moverState, int time )
+{
gentity_t *slave;
- for ( slave = teamLeader ; slave ; slave = slave->teamchain ) {
+ for( slave = teamLeader; slave; slave = slave->teamchain )
SetMoverState( slave, moverState, time );
- }
}
@@ -472,16 +510,16 @@ void MatchTeam( gentity_t *teamLeader, int moverState, int time ) {
ReturnToPos1
================
*/
-void ReturnToPos1( gentity_t *ent ) {
+void ReturnToPos1( gentity_t *ent )
+{
MatchTeam( ent, MOVER_2TO1, level.time );
// looping sound
ent->s.loopSound = ent->soundLoop;
// starting sound
- if ( ent->sound2to1 ) {
+ if( ent->sound2to1 )
G_AddEvent( ent, EV_GENERAL_SOUND, ent->sound2to1 );
- }
}
@@ -490,45 +528,45 @@ void ReturnToPos1( gentity_t *ent ) {
Reached_BinaryMover
================
*/
-void Reached_BinaryMover( gentity_t *ent ) {
-
+void Reached_BinaryMover( gentity_t *ent )
+{
// stop the looping sound
ent->s.loopSound = ent->soundLoop;
- if ( ent->moverState == MOVER_1TO2 ) {
+ if( ent->moverState == MOVER_1TO2 )
+ {
// reached pos2
SetMoverState( ent, MOVER_POS2, level.time );
// play sound
- if ( ent->soundPos2 ) {
+ if( ent->soundPos2 )
G_AddEvent( ent, EV_GENERAL_SOUND, ent->soundPos2 );
- }
// return to pos1 after a delay
ent->think = ReturnToPos1;
ent->nextthink = level.time + ent->wait;
// fire targets
- if ( !ent->activator ) {
+ if( !ent->activator )
ent->activator = ent;
- }
+
G_UseTargets( ent, ent->activator );
- } else if ( ent->moverState == MOVER_2TO1 ) {
+ }
+ else if( ent->moverState == MOVER_2TO1 )
+ {
// reached pos1
SetMoverState( ent, MOVER_POS1, level.time );
// play sound
- if ( ent->soundPos1 ) {
+ if( ent->soundPos1 )
G_AddEvent( ent, EV_GENERAL_SOUND, ent->soundPos1 );
- }
// close areaportals
- if ( ent->teammaster == ent || !ent->teammaster ) {
+ if( ent->teammaster == ent || !ent->teammaster )
trap_AdjustAreaPortalState( ent, qfalse );
- }
- } else {
- G_Error( "Reached_BinaryMover: bad moverState" );
}
+ else
+ G_Error( "Reached_BinaryMover: bad moverState" );
}
@@ -537,73 +575,78 @@ void Reached_BinaryMover( gentity_t *ent ) {
Use_BinaryMover
================
*/
-void Use_BinaryMover( gentity_t *ent, gentity_t *other, gentity_t *activator ) {
+void Use_BinaryMover( gentity_t *ent, gentity_t *other, gentity_t *activator )
+{
int total;
int partial;
// only the master should be used
- if ( ent->flags & FL_TEAMSLAVE ) {
+ if( ent->flags & FL_TEAMSLAVE )
+ {
Use_BinaryMover( ent->teammaster, other, activator );
return;
}
ent->activator = activator;
- if ( ent->moverState == MOVER_POS1 ) {
+ if( ent->moverState == MOVER_POS1 )
+ {
// start moving 50 msec later, becase if this was player
// triggered, level.time hasn't been advanced yet
MatchTeam( ent, MOVER_1TO2, level.time + 50 );
// starting sound
- if ( ent->sound1to2 ) {
+ if( ent->sound1to2 )
G_AddEvent( ent, EV_GENERAL_SOUND, ent->sound1to2 );
- }
// looping sound
ent->s.loopSound = ent->soundLoop;
// open areaportal
- if ( ent->teammaster == ent || !ent->teammaster ) {
+ if( ent->teammaster == ent || !ent->teammaster )
trap_AdjustAreaPortalState( ent, qtrue );
- }
+
return;
}
// if all the way up, just delay before coming down
- if ( ent->moverState == MOVER_POS2 ) {
+ if( ent->moverState == MOVER_POS2 )
+ {
ent->nextthink = level.time + ent->wait;
return;
}
// only partway down before reversing
- if ( ent->moverState == MOVER_2TO1 ) {
+ if( ent->moverState == MOVER_2TO1 )
+ {
total = ent->s.pos.trDuration;
partial = level.time - ent->s.pos.trTime;
- if ( partial > total ) {
+
+ if( partial > total )
partial = total;
- }
MatchTeam( ent, MOVER_1TO2, level.time - ( total - partial ) );
- if ( ent->sound1to2 ) {
+ if( ent->sound1to2 )
G_AddEvent( ent, EV_GENERAL_SOUND, ent->sound1to2 );
- }
+
return;
}
// only partway up before reversing
- if ( ent->moverState == MOVER_1TO2 ) {
+ if( ent->moverState == MOVER_1TO2 )
+ {
total = ent->s.pos.trDuration;
partial = level.time - ent->s.pos.trTime;
- if ( partial > total ) {
+
+ if( partial > total )
partial = total;
- }
MatchTeam( ent, MOVER_2TO1, level.time - ( total - partial ) );
- if ( ent->sound2to1 ) {
+ if( ent->sound2to1 )
G_AddEvent( ent, EV_GENERAL_SOUND, ent->sound2to1 );
- }
+
return;
}
}
@@ -618,47 +661,48 @@ InitMover
so the movement delta can be calculated
================
*/
-void InitMover( gentity_t *ent ) {
+void InitMover( gentity_t *ent )
+{
vec3_t move;
- float distance;
- float light;
+ float distance;
+ float light;
vec3_t color;
qboolean lightSet, colorSet;
- char *sound;
+ char *sound;
// if the "model2" key is set, use a seperate model
// for drawing, but clip against the brushes
- if ( ent->model2 ) {
+ if( ent->model2 )
ent->s.modelindex2 = G_ModelIndex( ent->model2 );
- }
// if the "loopsound" key is set, use a constant looping sound when moving
- if ( G_SpawnString( "noise", "100", &sound ) ) {
+ if( G_SpawnString( "noise", "100", &sound ) )
ent->s.loopSound = G_SoundIndex( sound );
- }
// if the "color" or "light" keys are set, setup constantLight
lightSet = G_SpawnFloat( "light", "100", &light );
colorSet = G_SpawnVector( "color", "1 1 1", color );
- if ( lightSet || colorSet ) {
+
+ if( lightSet || colorSet )
+ {
int r, g, b, i;
- r = color[0] * 255;
- if ( r > 255 ) {
+ r = color[ 0 ] * 255;
+ if( r > 255 )
r = 255;
- }
- g = color[1] * 255;
- if ( g > 255 ) {
+
+ g = color[ 1 ] * 255;
+ if( g > 255 )
g = 255;
- }
- b = color[2] * 255;
- if ( b > 255 ) {
+
+ b = color[ 2 ] * 255;
+ if( b > 255 )
b = 255;
- }
+
i = light / 4;
- if ( i > 255 ) {
+ if( i > 255 )
i = 255;
- }
+
ent->s.constantLight = r | ( g << 8 ) | ( b << 16 ) | ( i << 24 );
}
@@ -669,8 +713,8 @@ void InitMover( gentity_t *ent ) {
ent->moverState = MOVER_POS1;
ent->r.svFlags = SVF_USE_CURRENT_ORIGIN;
ent->s.eType = ET_MOVER;
- VectorCopy (ent->pos1, ent->r.currentOrigin);
- trap_LinkEntity (ent);
+ VectorCopy( ent->pos1, ent->r.currentOrigin );
+ trap_LinkEntity( ent );
ent->s.pos.trType = TR_STATIONARY;
VectorCopy( ent->pos1, ent->s.pos.trBase );
@@ -678,14 +722,14 @@ void InitMover( gentity_t *ent ) {
// calculate time to reach second position from speed
VectorSubtract( ent->pos2, ent->pos1, move );
distance = VectorLength( move );
- if ( ! ent->speed ) {
+ if( ! ent->speed )
ent->speed = 100;
- }
+
VectorScale( move, ent->speed, ent->s.pos.trDelta );
ent->s.pos.trDuration = distance * 1000 / ent->speed;
- if ( ent->s.pos.trDuration <= 0 ) {
+
+ if( ent->s.pos.trDuration <= 0 )
ent->s.pos.trDuration = 1;
- }
}
@@ -705,21 +749,22 @@ targeted by another entity.
Blocked_Door
================
*/
-void Blocked_Door( gentity_t *ent, gentity_t *other ) {
+void Blocked_Door( gentity_t *ent, gentity_t *other )
+{
// remove anything other than a client
- if ( !other->client ) {
+ if( !other->client )
+ {
// except CTF flags!!!!
G_TempEntity( other->s.origin, EV_ITEM_POP );
G_FreeEntity( other );
return;
}
- if ( ent->damage ) {
+ if( ent->damage )
G_Damage( other, ent, ent, NULL, NULL, ent->damage, 0, MOD_CRUSH );
- }
- if ( ent->spawnflags & 4 ) {
+
+ if( ent->spawnflags & 4 )
return; // crushers don't reverse
- }
// reverse direction
Use_BinaryMover( ent, ent, other );
@@ -730,27 +775,36 @@ void Blocked_Door( gentity_t *ent, gentity_t *other ) {
Touch_DoorTriggerSpectator
================
*/
-static void Touch_DoorTriggerSpectator( gentity_t *ent, gentity_t *other, trace_t *trace ) {
- int i, axis;
- vec3_t origin, dir, angles;
+static void Touch_DoorTriggerSpectator( gentity_t *ent, gentity_t *other, trace_t *trace )
+{
+ int i, axis;
+ vec3_t origin, dir, angles;
axis = ent->count;
- VectorClear(dir);
- if (fabs(other->s.origin[axis] - ent->r.absmax[axis]) <
- fabs(other->s.origin[axis] - ent->r.absmin[axis])) {
- origin[axis] = ent->r.absmin[axis] - 10;
- dir[axis] = -1;
- }
- else {
- origin[axis] = ent->r.absmax[axis] + 10;
- dir[axis] = 1;
- }
- for (i = 0; i < 3; i++) {
- if (i == axis) continue;
- origin[i] = (ent->r.absmin[i] + ent->r.absmax[i]) * 0.5;
+ VectorClear( dir );
+
+ if( fabs( other->s.origin[ axis ] - ent->r.absmax[ axis ] ) <
+ fabs( other->s.origin[ axis ] - ent->r.absmin[ axis ] ) )
+ {
+ origin[ axis ] = ent->r.absmin[ axis ] - 10;
+ dir[ axis ] = -1;
+ }
+ else
+ {
+ origin[ axis ] = ent->r.absmax[ axis ] + 10;
+ dir[ axis ] = 1;
+ }
+
+ for( i = 0; i < 3; i++ )
+ {
+ if( i == axis )
+ continue;
+
+ origin[ i ] = ( ent->r.absmin[ i ] + ent->r.absmax[ i ] ) * 0.5;
}
- vectoangles(dir, angles);
- TeleportPlayer(other, origin, angles );
+
+ vectoangles( dir, angles );
+ TeleportPlayer( other, origin, angles );
}
/*
@@ -758,17 +812,17 @@ static void Touch_DoorTriggerSpectator( gentity_t *ent, gentity_t *other, trace_
Touch_DoorTrigger
================
*/
-void Touch_DoorTrigger( gentity_t *ent, gentity_t *other, trace_t *trace ) {
- if ( other->client && other->client->sess.sessionTeam == TEAM_SPECTATOR ) {
+void Touch_DoorTrigger( gentity_t *ent, gentity_t *other, trace_t *trace )
+{
+ if( other->client && other->client->sess.sessionTeam == TEAM_SPECTATOR )
+ {
// if the door is not open and not opening
- if ( ent->parent->moverState != MOVER_1TO2 &&
- ent->parent->moverState != MOVER_POS2) {
+ if( ent->parent->moverState != MOVER_1TO2 &&
+ ent->parent->moverState != MOVER_POS2 )
Touch_DoorTriggerSpectator( ent, other, trace );
- }
}
- else if ( ent->parent->moverState != MOVER_1TO2 ) {
+ else if( ent->parent->moverState != MOVER_1TO2 )
Use_BinaryMover( ent->parent, ent, other );
- }
}
@@ -780,51 +834,54 @@ All of the parts of a door have been spawned, so create
a trigger that encloses all of them
======================
*/
-void Think_SpawnNewDoorTrigger( gentity_t *ent ) {
- gentity_t *other;
+void Think_SpawnNewDoorTrigger( gentity_t *ent )
+{
+ gentity_t *other;
vec3_t mins, maxs;
- int i, best;
+ int i, best;
// set all of the slaves as shootable
- for ( other = ent ; other ; other = other->teamchain ) {
+ for( other = ent; other; other = other->teamchain )
other->takedamage = qtrue;
- }
// find the bounds of everything on the team
- VectorCopy (ent->r.absmin, mins);
- VectorCopy (ent->r.absmax, maxs);
+ VectorCopy( ent->r.absmin, mins );
+ VectorCopy( ent->r.absmax, maxs );
- for (other = ent->teamchain ; other ; other=other->teamchain) {
- AddPointToBounds (other->r.absmin, mins, maxs);
- AddPointToBounds (other->r.absmax, mins, maxs);
+ for( other = ent->teamchain; other; other=other->teamchain )
+ {
+ AddPointToBounds( other->r.absmin, mins, maxs );
+ AddPointToBounds( other->r.absmax, mins, maxs );
}
// find the thinnest axis, which will be the one we expand
best = 0;
- for ( i = 1 ; i < 3 ; i++ ) {
- if ( maxs[i] - mins[i] < maxs[best] - mins[best] ) {
+ for( i = 1; i < 3; i++ )
+ {
+ if( maxs[ i ] - mins[ i ] < maxs[ best ] - mins[ best ] )
best = i;
- }
}
- maxs[best] += 120;
- mins[best] -= 120;
+
+ maxs[ best ] += 120;
+ mins[ best ] -= 120;
// create a trigger with this size
- other = G_Spawn ();
+ other = G_Spawn( );
other->classname = "door_trigger";
- VectorCopy (mins, other->r.mins);
- VectorCopy (maxs, other->r.maxs);
+ VectorCopy( mins, other->r.mins );
+ VectorCopy( maxs, other->r.maxs );
other->parent = ent;
other->r.contents = CONTENTS_TRIGGER;
other->touch = Touch_DoorTrigger;
// remember the thinnest axis
other->count = best;
- trap_LinkEntity (other);
+ trap_LinkEntity( other );
MatchTeam( ent, ent->moverState, level.time );
}
-void Think_MatchTeam( gentity_t *ent ) {
+void Think_MatchTeam( gentity_t *ent )
+{
MatchTeam( ent, ent->moverState, level.time );
}
@@ -845,24 +902,26 @@ NOMONSTER monsters will not trigger this door
"light" constantLight radius
"health" if set, the door must be shot open
*/
-void SP_func_door (gentity_t *ent) {
+void SP_func_door( gentity_t *ent )
+{
vec3_t abs_movedir;
- float distance;
+ float distance;
vec3_t size;
- float lip;
+ float lip;
- ent->sound1to2 = ent->sound2to1 = G_SoundIndex("sound/movers/doors/dr1_strt.wav");
- ent->soundPos1 = ent->soundPos2 = G_SoundIndex("sound/movers/doors/dr1_end.wav");
+ ent->sound1to2 = ent->sound2to1 = G_SoundIndex( "sound/movers/doors/dr1_strt.wav" );
+ ent->soundPos1 = ent->soundPos2 = G_SoundIndex( "sound/movers/doors/dr1_end.wav" );
ent->blocked = Blocked_Door;
// default speed of 400
- if (!ent->speed)
+ if( !ent->speed )
ent->speed = 400;
// default wait of 2 seconds
- if (!ent->wait)
+ if( !ent->wait )
ent->wait = 2;
+
ent->wait *= 1000;
// default lip of 8 units
@@ -876,16 +935,17 @@ void SP_func_door (gentity_t *ent) {
// calculate second position
trap_SetBrushModel( ent, ent->model );
- G_SetMovedir (ent->s.angles, ent->movedir);
- abs_movedir[0] = fabs(ent->movedir[0]);
- abs_movedir[1] = fabs(ent->movedir[1]);
- abs_movedir[2] = fabs(ent->movedir[2]);
+ G_SetMovedir( ent->s.angles, ent->movedir );
+ abs_movedir[ 0 ] = fabs( ent->movedir[ 0 ] );
+ abs_movedir[ 1 ] = fabs( ent->movedir[ 1 ] );
+ abs_movedir[ 2 ] = fabs( ent->movedir[ 2 ] );
VectorSubtract( ent->r.maxs, ent->r.mins, size );
distance = DotProduct( abs_movedir, size ) - lip;
VectorMA( ent->pos1, distance, ent->movedir, ent->pos2 );
// if "start_open", reverse position 1 and 2
- if ( ent->spawnflags & 1 ) {
+ if( ent->spawnflags & 1 )
+ {
vec3_t temp;
VectorCopy( ent->pos2, temp );
@@ -897,22 +957,22 @@ void SP_func_door (gentity_t *ent) {
ent->nextthink = level.time + FRAMETIME;
- if ( ! (ent->flags & FL_TEAMSLAVE ) ) {
+ if( ! (ent->flags & FL_TEAMSLAVE ) )
+ {
int health;
G_SpawnInt( "health", "0", &health );
- if ( health ) {
+ if( health )
ent->takedamage = qtrue;
- }
- if ( ent->targetname || health ) {
+
+ if( ent->targetname || health )
+ {
// non touch/shoot doors
ent->think = Think_MatchTeam;
- } else {
- ent->think = Think_SpawnNewDoorTrigger;
}
+ else
+ ent->think = Think_SpawnNewDoorTrigger;
}
-
-
}
/*
@@ -930,15 +990,14 @@ Touch_Plat
Don't allow decent if a living player is on it
===============
*/
-void Touch_Plat( gentity_t *ent, gentity_t *other, trace_t *trace ) {
- if ( !other->client || other->client->ps.stats[STAT_HEALTH] <= 0 ) {
+void Touch_Plat( gentity_t *ent, gentity_t *other, trace_t *trace )
+{
+ if( !other->client || other->client->ps.stats[ STAT_HEALTH ] <= 0 )
return;
- }
// delay return-to-pos1 by one second
- if ( ent->moverState == MOVER_POS2 ) {
+ if( ent->moverState == MOVER_POS2 )
ent->nextthink = level.time + 1000;
- }
}
/*
@@ -948,14 +1007,13 @@ Touch_PlatCenterTrigger
If the plat is at the bottom position, start it going up
===============
*/
-void Touch_PlatCenterTrigger(gentity_t *ent, gentity_t *other, trace_t *trace ) {
- if ( !other->client ) {
+void Touch_PlatCenterTrigger( gentity_t *ent, gentity_t *other, trace_t *trace )
+{
+ if( !other->client )
return;
- }
- if ( ent->parent->moverState == MOVER_POS1 ) {
+ if( ent->parent->moverState == MOVER_POS1 )
Use_BinaryMover( ent->parent, ent, other );
- }
}
@@ -968,39 +1026,43 @@ Elevator cars require that the trigger extend through the entire low position,
not just sit on top of it.
================
*/
-void SpawnPlatTrigger( gentity_t *ent ) {
+void SpawnPlatTrigger( gentity_t *ent )
+{
gentity_t *trigger;
- vec3_t tmin, tmax;
+ vec3_t tmin, tmax;
// the middle trigger will be a thin trigger just
// above the starting position
- trigger = G_Spawn();
+ trigger = G_Spawn( );
trigger->classname = "plat_trigger";
trigger->touch = Touch_PlatCenterTrigger;
trigger->r.contents = CONTENTS_TRIGGER;
trigger->parent = ent;
- tmin[0] = ent->pos1[0] + ent->r.mins[0] + 33;
- tmin[1] = ent->pos1[1] + ent->r.mins[1] + 33;
- tmin[2] = ent->pos1[2] + ent->r.mins[2];
+ tmin[ 0 ] = ent->pos1[ 0 ] + ent->r.mins[ 0 ] + 33;
+ tmin[ 1 ] = ent->pos1[ 1 ] + ent->r.mins[ 1 ] + 33;
+ tmin[ 2 ] = ent->pos1[ 2 ] + ent->r.mins[ 2 ];
- tmax[0] = ent->pos1[0] + ent->r.maxs[0] - 33;
- tmax[1] = ent->pos1[1] + ent->r.maxs[1] - 33;
- tmax[2] = ent->pos1[2] + ent->r.maxs[2] + 8;
+ tmax[ 0 ] = ent->pos1[ 0 ] + ent->r.maxs[ 0 ] - 33;
+ tmax[ 1 ] = ent->pos1[ 1 ] + ent->r.maxs[ 1 ] - 33;
+ tmax[ 2 ] = ent->pos1[ 2 ] + ent->r.maxs[ 2 ] + 8;
- if ( tmax[0] <= tmin[0] ) {
- tmin[0] = ent->pos1[0] + (ent->r.mins[0] + ent->r.maxs[0]) *0.5;
- tmax[0] = tmin[0] + 1;
+ if( tmax[ 0 ] <= tmin[ 0 ] )
+ {
+ tmin[ 0 ] = ent->pos1[ 0 ] + ( ent->r.mins[ 0 ] + ent->r.maxs[ 0 ] ) * 0.5;
+ tmax[ 0 ] = tmin[ 0 ] + 1;
}
- if ( tmax[1] <= tmin[1] ) {
- tmin[1] = ent->pos1[1] + (ent->r.mins[1] + ent->r.maxs[1]) *0.5;
- tmax[1] = tmin[1] + 1;
+
+ if( tmax[ 1 ] <= tmin[ 1 ] )
+ {
+ tmin[ 1 ] = ent->pos1[ 1 ] + ( ent->r.mins[ 1 ] + ent->r.maxs[ 1 ] ) * 0.5;
+ tmax[ 1 ] = tmin[ 1 ] + 1;
}
- VectorCopy (tmin, trigger->r.mins);
- VectorCopy (tmax, trigger->r.maxs);
+ VectorCopy( tmin, trigger->r.mins );
+ VectorCopy( tmax, trigger->r.maxs );
- trap_LinkEntity (trigger);
+ trap_LinkEntity( trigger );
}
@@ -1015,13 +1077,14 @@ Plats are always drawn in the extended position so they will light correctly.
"color" constantLight color
"light" constantLight radius
*/
-void SP_func_plat (gentity_t *ent) {
- float lip, height;
+void SP_func_plat( gentity_t *ent )
+{
+ float lip, height;
- ent->sound1to2 = ent->sound2to1 = G_SoundIndex("sound/movers/plats/pt1_strt.wav");
- ent->soundPos1 = ent->soundPos2 = G_SoundIndex("sound/movers/plats/pt1_end.wav");
+ ent->sound1to2 = ent->sound2to1 = G_SoundIndex( "sound/movers/plats/pt1_strt.wav" );
+ ent->soundPos1 = ent->soundPos2 = G_SoundIndex( "sound/movers/plats/pt1_end.wav" );
- VectorClear (ent->s.angles);
+ VectorClear( ent->s.angles );
G_SpawnFloat( "speed", "200", &ent->speed );
G_SpawnInt( "dmg", "2", &ent->damage );
@@ -1033,14 +1096,13 @@ void SP_func_plat (gentity_t *ent) {
// create second position
trap_SetBrushModel( ent, ent->model );
- if ( !G_SpawnFloat( "height", "0", &height ) ) {
- height = (ent->r.maxs[2] - ent->r.mins[2]) - lip;
- }
+ if( !G_SpawnFloat( "height", "0", &height ) )
+ height = ( ent->r.maxs[ 2 ] - ent->r.mins[ 2 ] ) - lip;
// pos1 is the rest (bottom) position, pos2 is the top
VectorCopy( ent->s.origin, ent->pos2 );
VectorCopy( ent->pos2, ent->pos1 );
- ent->pos1[2] -= height;
+ ent->pos1[ 2 ] -= height;
InitMover( ent );
@@ -1053,9 +1115,8 @@ void SP_func_plat (gentity_t *ent) {
ent->parent = ent; // so it can be treated as a door
// spawn the trigger if one hasn't been custom made
- if ( !ent->targetname ) {
- SpawnPlatTrigger(ent);
- }
+ if( !ent->targetname )
+ SpawnPlatTrigger( ent );
}
@@ -1073,14 +1134,13 @@ Touch_Button
===============
*/
-void Touch_Button(gentity_t *ent, gentity_t *other, trace_t *trace ) {
- if ( !other->client ) {
+void Touch_Button( gentity_t *ent, gentity_t *other, trace_t *trace )
+{
+ if( !other->client )
return;
- }
- if ( ent->moverState == MOVER_POS1 ) {
+ if( ent->moverState == MOVER_POS1 )
Use_BinaryMover( ent, other, other );
- }
}
@@ -1097,21 +1157,21 @@ When a button is touched, it moves some distance in the direction of it's angle,
"color" constantLight color
"light" constantLight radius
*/
-void SP_func_button( gentity_t *ent ) {
- vec3_t abs_movedir;
+void SP_func_button( gentity_t *ent )
+{
+ vec3_t abs_movedir;
float distance;
- vec3_t size;
+ vec3_t size;
float lip;
- ent->sound1to2 = G_SoundIndex("sound/movers/switches/butn2.wav");
+ ent->sound1to2 = G_SoundIndex( "sound/movers/switches/butn2.wav" );
- if ( !ent->speed ) {
+ if( !ent->speed )
ent->speed = 40;
- }
- if ( !ent->wait ) {
+ if( !ent->wait )
ent->wait = 1;
- }
+
ent->wait *= 1000;
// first position
@@ -1123,17 +1183,20 @@ void SP_func_button( gentity_t *ent ) {
G_SpawnFloat( "lip", "4", &lip );
G_SetMovedir( ent->s.angles, ent->movedir );
- abs_movedir[0] = fabs(ent->movedir[0]);
- abs_movedir[1] = fabs(ent->movedir[1]);
- abs_movedir[2] = fabs(ent->movedir[2]);
+ abs_movedir[ 0 ] = fabs( ent->movedir[ 0 ] );
+ abs_movedir[ 1 ] = fabs( ent->movedir[ 1 ] );
+ abs_movedir[ 2 ] = fabs( ent->movedir[ 2 ] );
VectorSubtract( ent->r.maxs, ent->r.mins, size );
- distance = abs_movedir[0] * size[0] + abs_movedir[1] * size[1] + abs_movedir[2] * size[2] - lip;
- VectorMA (ent->pos1, distance, ent->movedir, ent->pos2);
+ distance = abs_movedir[ 0 ] * size[ 0 ] + abs_movedir[ 1 ] * size[ 1 ] + abs_movedir[ 2 ] * size[ 2 ] - lip;
+ VectorMA( ent->pos1, distance, ent->movedir, ent->pos2 );
- if (ent->health) {
+ if( ent->health )
+ {
// shootable button
ent->takedamage = qtrue;
- } else {
+ }
+ else
+ {
// touchable button
ent->touch = Touch_Button;
}
@@ -1163,7 +1226,8 @@ Think_BeginMoving
The wait time at a corner has completed, so start moving again
===============
*/
-void Think_BeginMoving( gentity_t *ent ) {
+void Think_BeginMoving( gentity_t *ent )
+{
ent->s.pos.trTime = level.time;
ent->s.pos.trType = TR_LINEAR_STOP;
}
@@ -1173,17 +1237,17 @@ void Think_BeginMoving( gentity_t *ent ) {
Reached_Train
===============
*/
-void Reached_Train( gentity_t *ent ) {
- gentity_t *next;
+void Reached_Train( gentity_t *ent )
+{
+ gentity_t *next;
float speed;
- vec3_t move;
+ vec3_t move;
float length;
// copy the apropriate values
next = ent->nextTrain;
- if ( !next || !next->nextTrain ) {
+ if( !next || !next->nextTrain )
return; // just stop
- }
// fire all other targets
G_UseTargets( next, NULL );
@@ -1194,15 +1258,18 @@ void Reached_Train( gentity_t *ent ) {
VectorCopy( next->nextTrain->s.origin, ent->pos2 );
// if the path_corner has a speed, use that
- if ( next->speed ) {
+ if( next->speed )
+ {
speed = next->speed;
- } else {
+ }
+ else
+ {
// otherwise use the train's speed
speed = ent->speed;
}
- if ( speed < 1 ) {
+
+ if( speed < 1 )
speed = 1;
- }
// calculate duration
VectorSubtract( ent->pos2, ent->pos1, move );
@@ -1217,7 +1284,8 @@ void Reached_Train( gentity_t *ent ) {
SetMoverState( ent, MOVER_1TO2, level.time );
// if there is a "wait" value on the target, don't start moving yet
- if ( next->wait ) {
+ if( next->wait )
+ {
ent->nextthink = level.time + next->wait * 1000;
ent->think = Think_BeginMoving;
ent->s.pos.trType = TR_STATIONARY;
@@ -1232,25 +1300,29 @@ Think_SetupTrainTargets
Link all the corners together
===============
*/
-void Think_SetupTrainTargets( gentity_t *ent ) {
- gentity_t *path, *next, *start;
-
- ent->nextTrain = G_Find( NULL, FOFS(targetname), ent->target );
- if ( !ent->nextTrain ) {
+void Think_SetupTrainTargets( gentity_t *ent )
+{
+ gentity_t *path, *next, *start;
+
+ ent->nextTrain = G_Find( NULL, FOFS( targetname ), ent->target );
+
+ if( !ent->nextTrain )
+ {
G_Printf( "func_train at %s with an unfound target\n",
- vtos(ent->r.absmin) );
+ vtos( ent->r.absmin ) );
return;
}
start = NULL;
- for ( path = ent->nextTrain ; path != start ; path = next ) {
- if ( !start ) {
+ for( path = ent->nextTrain; path != start; path = next )
+ {
+ if( !start )
start = path;
- }
- if ( !path->target ) {
+ if( !path->target )
+ {
G_Printf( "Train corner at %s without a target\n",
- vtos(path->s.origin) );
+ vtos( path->s.origin ) );
return;
}
@@ -1258,14 +1330,17 @@ void Think_SetupTrainTargets( gentity_t *ent ) {
// there may also be other targets that get fired when the corner
// is reached
next = NULL;
- do {
- next = G_Find( next, FOFS(targetname), path->target );
- if ( !next ) {
+ do
+ {
+ next = G_Find( next, FOFS( targetname ), path->target );
+
+ if( !next )
+ {
G_Printf( "Train corner at %s without a target path_corner\n",
- vtos(path->s.origin) );
+ vtos( path->s.origin ) );
return;
}
- } while ( strcmp( next->classname, "path_corner" ) );
+ } while( strcmp( next->classname, "path_corner" ) );
path->nextTrain = next;
}
@@ -1282,9 +1357,11 @@ Target: next path corner and other targets to fire
"speed" speed to move to the next corner
"wait" seconds to wait before behining move to next corner
*/
-void SP_path_corner( gentity_t *self ) {
- if ( !self->targetname ) {
- G_Printf ("path_corner with no targetname at %s\n", vtos(self->s.origin));
+void SP_path_corner( gentity_t *self )
+{
+ if( !self->targetname )
+ {
+ G_Printf( "path_corner with no targetname at %s\n", vtos( self->s.origin ) );
G_FreeEntity( self );
return;
}
@@ -1305,23 +1382,23 @@ The train spawns at the first target it is pointing at.
"color" constantLight color
"light" constantLight radius
*/
-void SP_func_train (gentity_t *self) {
- VectorClear (self->s.angles);
+void SP_func_train( gentity_t *self )
+{
+ VectorClear( self->s.angles );
- if (self->spawnflags & TRAIN_BLOCK_STOPS) {
+ if( self->spawnflags & TRAIN_BLOCK_STOPS )
+ {
self->damage = 0;
- } else {
- if (!self->damage) {
- self->damage = 2;
- }
}
+ else if( !self->damage )
+ self->damage = 2;
- if ( !self->speed ) {
+ if( !self->speed )
self->speed = 100;
- }
- if ( !self->target ) {
- G_Printf ("func_train without a target at %s\n", vtos(self->r.absmin));
+ if( !self->target )
+ {
+ G_Printf( "func_train without a target at %s\n", vtos( self->r.absmin ) );
G_FreeEntity( self );
return;
}
@@ -1352,7 +1429,8 @@ A bmodel that just sits there, doing nothing. Can be used for conditional walls
"color" constantLight color
"light" constantLight radius
*/
-void SP_func_static( gentity_t *ent ) {
+void SP_func_static( gentity_t *ent )
+{
trap_SetBrushModel( ent, ent->model );
InitMover( ent );
VectorCopy( ent->s.origin, ent->s.pos.trBase );
@@ -1380,24 +1458,23 @@ check either the X_AXIS or Y_AXIS box to change that.
"color" constantLight color
"light" constantLight radius
*/
-void SP_func_rotating (gentity_t *ent) {
- if ( !ent->speed ) {
+void SP_func_rotating( gentity_t *ent )
+{
+ if( !ent->speed )
ent->speed = 100;
- }
// set the axis of rotation
ent->s.apos.trType = TR_LINEAR;
- if ( ent->spawnflags & 4 ) {
- ent->s.apos.trDelta[2] = ent->speed;
- } else if ( ent->spawnflags & 8 ) {
- ent->s.apos.trDelta[0] = ent->speed;
- } else {
- ent->s.apos.trDelta[1] = ent->speed;
- }
- if (!ent->damage) {
+ if( ent->spawnflags & 4 )
+ ent->s.apos.trDelta[ 2 ] = ent->speed;
+ else if( ent->spawnflags & 8 )
+ ent->s.apos.trDelta[ 0 ] = ent->speed;
+ else
+ ent->s.apos.trDelta[ 1 ] = ent->speed;
+
+ if( !ent->damage )
ent->damage = 2;
- }
trap_SetBrushModel( ent, ent->model );
InitMover( ent );
@@ -1429,7 +1506,8 @@ Normally bobs on the Z axis
"color" constantLight color
"light" constantLight radius
*/
-void SP_func_bobbing (gentity_t *ent) {
+void SP_func_bobbing( gentity_t *ent )
+{
float height;
float phase;
@@ -1449,13 +1527,12 @@ void SP_func_bobbing (gentity_t *ent) {
ent->s.pos.trType = TR_SINE;
// set the axis of bobbing
- if ( ent->spawnflags & 1 ) {
- ent->s.pos.trDelta[0] = height;
- } else if ( ent->spawnflags & 2 ) {
- ent->s.pos.trDelta[1] = height;
- } else {
- ent->s.pos.trDelta[2] = height;
- }
+ if( ent->spawnflags & 1 )
+ ent->s.pos.trDelta[ 0 ] = height;
+ else if( ent->spawnflags & 2 )
+ ent->s.pos.trDelta[ 1 ] = height;
+ else
+ ent->s.pos.trDelta[ 2 ] = height;
}
/*
@@ -1478,11 +1555,12 @@ Pendulum frequency is a physical constant based on the length of the beam and gr
"color" constantLight color
"light" constantLight radius
*/
-void SP_func_pendulum(gentity_t *ent) {
- float freq;
- float length;
- float phase;
- float speed;
+void SP_func_pendulum( gentity_t *ent )
+{
+ float freq;
+ float length;
+ float phase;
+ float speed;
G_SpawnFloat( "speed", "30", &speed );
G_SpawnInt( "dmg", "2", &ent->damage );
@@ -1491,10 +1569,10 @@ void SP_func_pendulum(gentity_t *ent) {
trap_SetBrushModel( ent, ent->model );
// find pendulum length
- length = fabs( ent->r.mins[2] );
- if ( length < 8 ) {
+ length = fabs( ent->r.mins[ 2 ] );
+
+ if( length < 8 )
length = 8;
- }
freq = 1 / ( M_PI * 2 ) * sqrt( g_gravity.value / ( 3 * length ) );
@@ -1510,5 +1588,5 @@ void SP_func_pendulum(gentity_t *ent) {
ent->s.apos.trDuration = 1000 / freq;
ent->s.apos.trTime = ent->s.apos.trDuration * phase;
ent->s.apos.trType = TR_SINE;
- ent->s.apos.trDelta[2] = speed;
+ ent->s.apos.trDelta[ 2 ] = speed;
}