diff options
author | Tim Angus <tim@ngus.net> | 2002-09-09 23:32:27 +0000 |
---|---|---|
committer | Tim Angus <tim@ngus.net> | 2002-09-09 23:32:27 +0000 |
commit | c0e95997d9e9fcaa220704c8c67b50d6761d1b66 (patch) | |
tree | 307242d290de1715df0f4f28dd7e08ccb7006f5c /src/game/g_target.c | |
parent | 9af7c524043a8f296ea5f45ec7f73c16e29921b5 (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_target.c')
-rw-r--r-- | src/game/g_target.c | 211 |
1 files changed, 116 insertions, 95 deletions
diff --git a/src/game/g_target.c b/src/game/g_target.c index 2f938a65..249d120a 100644 --- a/src/game/g_target.c +++ b/src/game/g_target.c @@ -58,15 +58,16 @@ void SP_target_give( gentity_t *ent ) takes away all the activators powerups. Used to drop flight powerups into death puts. */ -void Use_target_remove_powerups( gentity_t *ent, gentity_t *other, gentity_t *activator ) { - if( !activator->client ) { +void Use_target_remove_powerups( gentity_t *ent, gentity_t *other, gentity_t *activator ) +{ + if( !activator->client ) return; - } memset( activator->client->ps.powerups, 0, sizeof( activator->client->ps.powerups ) ); } -void SP_target_remove_powerups( gentity_t *ent ) { +void SP_target_remove_powerups( gentity_t *ent ) +{ ent->use = Use_target_remove_powerups; } @@ -77,25 +78,27 @@ void SP_target_remove_powerups( gentity_t *ent ) { "wait" seconds to pause before firing targets. "random" delay variance, total delay = delay +/- random seconds */ -void Think_Target_Delay( gentity_t *ent ) { +void Think_Target_Delay( gentity_t *ent ) +{ G_UseTargets( ent, ent->activator ); } -void Use_Target_Delay( gentity_t *ent, gentity_t *other, gentity_t *activator ) { - ent->nextthink = level.time + ( ent->wait + ent->random * crandom() ) * 1000; +void Use_Target_Delay( gentity_t *ent, gentity_t *other, gentity_t *activator ) +{ + ent->nextthink = level.time + ( ent->wait + ent->random * crandom( ) ) * 1000; ent->think = Think_Target_Delay; ent->activator = activator; } -void SP_target_delay( gentity_t *ent ) { +void SP_target_delay( gentity_t *ent ) +{ // check delay for backwards compatability - if ( !G_SpawnFloat( "delay", "0", &ent->wait ) ) { + if( !G_SpawnFloat( "delay", "0", &ent->wait ) ) G_SpawnFloat( "wait", "1", &ent->wait ); - } - if ( !ent->wait ) { + if( !ent->wait ) ent->wait = 1; - } + ent->use = Use_Target_Delay; } @@ -107,14 +110,16 @@ void SP_target_delay( gentity_t *ent ) { The activator is given this many points. */ -void Use_Target_Score (gentity_t *ent, gentity_t *other, gentity_t *activator) { +void Use_Target_Score( gentity_t *ent, gentity_t *other, gentity_t *activator ) +{ AddScore( activator, ent->count ); } -void SP_target_score( gentity_t *ent ) { - if ( !ent->count ) { +void SP_target_score( gentity_t *ent ) +{ + if( !ent->count ) ent->count = 1; - } + ent->use = Use_Target_Score; } @@ -125,7 +130,7 @@ void SP_target_score( gentity_t *ent ) { "message" text to print If "private", only the activator gets the message. If no checks, all clients get the message. */ -void Use_Target_Print (gentity_t *ent, gentity_t *other, gentity_t *activator) +void Use_Target_Print( gentity_t *ent, gentity_t *other, gentity_t *activator ) { if( activator->client && ( ent->spawnflags & 4 ) ) { @@ -146,7 +151,8 @@ void Use_Target_Print (gentity_t *ent, gentity_t *other, gentity_t *activator) trap_SendServerCommand( -1, va("cp \"%s\"", ent->message ) ); } -void SP_target_print( gentity_t *ent ) { +void SP_target_print( gentity_t *ent ) +{ ent->use = Use_Target_Print; } @@ -166,46 +172,49 @@ Multiple identical looping sounds will just increase volume without any speed co "wait" : Seconds between auto triggerings, 0 = don't auto trigger "random" wait variance, default is 0 */ -void Use_Target_Speaker (gentity_t *ent, gentity_t *other, gentity_t *activator) { - if (ent->spawnflags & 3) { // looping sound toggles - if (ent->s.loopSound) +void Use_Target_Speaker( gentity_t *ent, gentity_t *other, gentity_t *activator ) +{ + if( ent->spawnflags & 3 ) + { // looping sound toggles + if( ent->s.loopSound ) ent->s.loopSound = 0; // turn it off else ent->s.loopSound = ent->noise_index; // start it - }else { // normal sound - if ( ent->spawnflags & 8 ) { + } + else + { + // normal sound + if( ent->spawnflags & 8 ) G_AddEvent( activator, EV_GENERAL_SOUND, ent->noise_index ); - } else if (ent->spawnflags & 4) { + else if( ent->spawnflags & 4 ) G_AddEvent( ent, EV_GLOBAL_SOUND, ent->noise_index ); - } else { + else G_AddEvent( ent, EV_GENERAL_SOUND, ent->noise_index ); - } } } -void SP_target_speaker( gentity_t *ent ) { - char buffer[MAX_QPATH]; +void SP_target_speaker( gentity_t *ent ) +{ + char buffer[ MAX_QPATH ]; char *s; G_SpawnFloat( "wait", "0", &ent->wait ); G_SpawnFloat( "random", "0", &ent->random ); - if ( !G_SpawnString( "noise", "NOSOUND", &s ) ) { + if( !G_SpawnString( "noise", "NOSOUND", &s ) ) G_Error( "target_speaker without a noise key at %s", vtos( ent->s.origin ) ); - } // force all client reletive sounds to be "activator" speakers that // play on the entity that activates it - if ( s[0] == '*' ) { + if( s[ 0 ] == '*' ) ent->spawnflags |= 8; - } - if (!strstr( s, ".wav" )) { - Com_sprintf (buffer, sizeof(buffer), "%s.wav", s ); - } else { - Q_strncpyz( buffer, s, sizeof(buffer) ); - } - ent->noise_index = G_SoundIndex(buffer); + if( !strstr( s, ".wav" ) ) + Com_sprintf( buffer, sizeof( buffer ), "%s.wav", s ); + else + Q_strncpyz( buffer, s, sizeof( buffer ) ); + + ent->noise_index = G_SoundIndex( buffer ); // a repeating speaker can be done completely client side ent->s.eType = ET_SPEAKER; @@ -215,15 +224,13 @@ void SP_target_speaker( gentity_t *ent ) { // check for prestarted looping sound - if ( ent->spawnflags & 1 ) { + if( ent->spawnflags & 1 ) ent->s.loopSound = ent->noise_index; - } ent->use = Use_Target_Speaker; - if (ent->spawnflags & 4) { + if( ent->spawnflags & 4 ) ent->r.svFlags |= SVF_BROADCAST; - } VectorCopy( ent->s.origin, ent->s.pos.trBase ); @@ -239,88 +246,94 @@ void SP_target_speaker( gentity_t *ent ) { /*QUAKED target_laser (0 .5 .8) (-8 -8 -8) (8 8 8) START_ON When triggered, fires a laser. You can either set a target or a direction. */ -void target_laser_think (gentity_t *self) { +void target_laser_think( gentity_t *self ) +{ vec3_t end; trace_t tr; vec3_t point; // if pointed at another entity, set movedir to point at it - if ( self->enemy ) { - VectorMA (self->enemy->s.origin, 0.5, self->enemy->r.mins, point); - VectorMA (point, 0.5, self->enemy->r.maxs, point); - VectorSubtract (point, self->s.origin, self->movedir); - VectorNormalize (self->movedir); + if( self->enemy ) + { + VectorMA( self->enemy->s.origin, 0.5, self->enemy->r.mins, point ); + VectorMA( point, 0.5, self->enemy->r.maxs, point ); + VectorSubtract( point, self->s.origin, self->movedir ); + VectorNormalize( self->movedir ); } // fire forward and see what we hit - VectorMA (self->s.origin, 2048, self->movedir, end); + VectorMA( self->s.origin, 2048, self->movedir, end ); - trap_Trace( &tr, self->s.origin, NULL, NULL, end, self->s.number, CONTENTS_SOLID|CONTENTS_BODY|CONTENTS_CORPSE); + trap_Trace( &tr, self->s.origin, NULL, NULL, end, self->s.number, + CONTENTS_SOLID | CONTENTS_BODY | CONTENTS_CORPSE ); - if ( tr.entityNum ) { + if( tr.entityNum ) + { // hurt it if we can - G_Damage ( &g_entities[tr.entityNum], self, self->activator, self->movedir, - tr.endpos, self->damage, DAMAGE_NO_KNOCKBACK, MOD_TARGET_LASER); + G_Damage( &g_entities[ tr.entityNum ], self, self->activator, self->movedir, + tr.endpos, self->damage, DAMAGE_NO_KNOCKBACK, MOD_TARGET_LASER ); } - VectorCopy (tr.endpos, self->s.origin2); + VectorCopy( tr.endpos, self->s.origin2 ); trap_LinkEntity( self ); self->nextthink = level.time + FRAMETIME; } -void target_laser_on (gentity_t *self) +void target_laser_on( gentity_t *self ) { - if (!self->activator) + if( !self->activator ) self->activator = self; - target_laser_think (self); + + target_laser_think( self ); } -void target_laser_off (gentity_t *self) +void target_laser_off( gentity_t *self ) { trap_UnlinkEntity( self ); self->nextthink = 0; } -void target_laser_use (gentity_t *self, gentity_t *other, gentity_t *activator) +void target_laser_use( gentity_t *self, gentity_t *other, gentity_t *activator ) { self->activator = activator; - if ( self->nextthink > 0 ) - target_laser_off (self); + if( self->nextthink > 0 ) + target_laser_off( self ); else - target_laser_on (self); + target_laser_on( self ); } -void target_laser_start (gentity_t *self) +void target_laser_start( gentity_t *self ) { gentity_t *ent; self->s.eType = ET_BEAM; - if (self->target) { - ent = G_Find (NULL, FOFS(targetname), self->target); - if (!ent) { - G_Printf ("%s at %s: %s is a bad target\n", self->classname, vtos(self->s.origin), self->target); - } + if( self->target ) + { + ent = G_Find( NULL, FOFS( targetname ), self->target ); + + if( !ent ) + G_Printf ( "%s at %s: %s is a bad target\n", self->classname, vtos( self->s.origin ), self->target ); + self->enemy = ent; - } else { - G_SetMovedir (self->s.angles, self->movedir); } + else + G_SetMovedir( self->s.angles, self->movedir ); self->use = target_laser_use; self->think = target_laser_think; - if ( !self->damage ) { + if( !self->damage ) self->damage = 1; - } - if (self->spawnflags & 1) - target_laser_on (self); + if( self->spawnflags & 1 ) + target_laser_on( self ); else - target_laser_off (self); + target_laser_off( self ); } -void SP_target_laser (gentity_t *self) +void SP_target_laser( gentity_t *self ) { // let everything else get spawned before we start firing self->think = target_laser_start; @@ -330,14 +343,18 @@ void SP_target_laser (gentity_t *self) //========================================================== -void target_teleporter_use( gentity_t *self, gentity_t *other, gentity_t *activator ) { +void target_teleporter_use( gentity_t *self, gentity_t *other, gentity_t *activator ) +{ gentity_t *dest; - if (!activator->client) + if( !activator->client ) return; + dest = G_PickTarget( self->target ); - if (!dest) { - G_Printf ("Couldn't find teleporter destination\n"); + + if( !dest ) + { + G_Printf( "Couldn't find teleporter destination\n" ); return; } @@ -347,9 +364,10 @@ void target_teleporter_use( gentity_t *self, gentity_t *other, gentity_t *activa /*QUAKED target_teleporter (1 0 0) (-8 -8 -8) (8 8 8) The activator will be teleported away. */ -void SP_target_teleporter( gentity_t *self ) { - if (!self->targetname) - G_Printf("untargeted %s at %s\n", self->classname, vtos(self->s.origin)); +void SP_target_teleporter( gentity_t *self ) +{ + if( !self->targetname ) + G_Printf( "untargeted %s at %s\n", self->classname, vtos( self->s.origin ) ); self->use = target_teleporter_use; } @@ -397,27 +415,30 @@ void SP_target_relay( gentity_t *self ) /*QUAKED target_kill (.5 .5 .5) (-8 -8 -8) (8 8 8) Kills the activator. */ -void target_kill_use( gentity_t *self, gentity_t *other, gentity_t *activator ) { - G_Damage ( activator, NULL, NULL, NULL, NULL, 100000, DAMAGE_NO_PROTECTION, MOD_TELEFRAG); +void target_kill_use( gentity_t *self, gentity_t *other, gentity_t *activator ) +{ + G_Damage( activator, NULL, NULL, NULL, NULL, 100000, DAMAGE_NO_PROTECTION, MOD_TELEFRAG ); } -void SP_target_kill( gentity_t *self ) { +void SP_target_kill( gentity_t *self ) +{ self->use = target_kill_use; } /*QUAKED target_position (0 0.5 0) (-4 -4 -4) (4 4 4) Used as a positional target for in-game calculation, like jumppad targets. */ -void SP_target_position( gentity_t *self ){ +void SP_target_position( gentity_t *self ) +{ G_SetOrigin( self, self->s.origin ); } -static void target_location_linkup(gentity_t *ent) +static void target_location_linkup( gentity_t *ent ) { int i; int n; - if (level.locationLinked) + if( level.locationLinked ) return; level.locationLinked = qtrue; @@ -426,10 +447,10 @@ static void target_location_linkup(gentity_t *ent) trap_SetConfigstring( CS_LOCATIONS, "unknown" ); - for (i = 0, ent = g_entities, n = 1; - i < level.num_entities; - i++, ent++) { - if (ent->classname && !Q_stricmp(ent->classname, "target_location")) { + for( i = 0, ent = g_entities, n = 1; i < level.num_entities; i++, ent++) + { + if( ent->classname && !Q_stricmp( ent->classname, "target_location" ) ) + { // lets overload some variables! ent->health = n; // use for location marking trap_SetConfigstring( CS_LOCATIONS + n, ent->message ); @@ -438,7 +459,6 @@ static void target_location_linkup(gentity_t *ent) level.locationHead = ent; } } - // All linked together now } @@ -450,7 +470,8 @@ Set "count" to 0-7 for color. Closest target_location in sight used for the location, if none in site, closest in distance */ -void SP_target_location( gentity_t *self ){ +void SP_target_location( gentity_t *self ) +{ self->think = target_location_linkup; self->nextthink = level.time + 200; // Let them all spawn first |