diff options
-rw-r--r-- | src/game/g_active.c | 4 | ||||
-rw-r--r-- | src/game/g_buildable.c | 141 | ||||
-rw-r--r-- | src/game/g_cmds.c | 2 | ||||
-rw-r--r-- | src/game/g_local.h | 8 | ||||
-rw-r--r-- | src/game/g_main.c | 12 |
5 files changed, 49 insertions, 118 deletions
diff --git a/src/game/g_active.c b/src/game/g_active.c index 80c3df65..30171f53 100644 --- a/src/game/g_active.c +++ b/src/game/g_active.c @@ -1427,7 +1427,7 @@ void ClientThink_real( gentity_t *ent ) if( modifier < BOOSTER_REGEN_MOD && boost->s.eType == ET_BUILDABLE && boost->s.modelindex == BA_A_BOOSTER && boost->spawned && - boost->health > 0 && level.overmindPresent ) + boost->health > 0 && boost->powered ) { modifier = BOOSTER_REGEN_MOD; continue; @@ -1512,7 +1512,7 @@ void ClientThink_real( gentity_t *ent ) } //switch jetpack off if no reactor - if( !level.reactorPresent ) + if( !G_Reactor( ) ) BG_DeactivateUpgrade( UP_JETPACK, client->ps.stats ); } diff --git a/src/game/g_buildable.c b/src/game/g_buildable.c index dad88840..11d7ea2a 100644 --- a/src/game/g_buildable.c +++ b/src/game/g_buildable.c @@ -143,17 +143,9 @@ qboolean G_FindPower( gentity_t *self ) // Handle repeaters if( self->s.modelindex == BA_H_REPEATER ) { - if( level.reactorPresent ) - { - G_FindReactor( self ); - self->parentNode = self->reactorNode; - - return qtrue; - } - - self->parentNode = NULL; + self->parentNode = G_Reactor( ); - return qfalse; + return self->parentNode != NULL; } // Reset parent @@ -559,80 +551,46 @@ qboolean G_IsDCCBuilt( void ) /* ================ -G_FindOvermind +G_Reactor +G_Overmind + +Since there's only one of these and we quite often want to find them, cache the +results, but check them for validity each time -Attempt to find an overmind for self +The code here will break if more than one reactor or overmind is allowed, even +if one of them is dead/unspawned ================ */ -qboolean G_FindOvermind( gentity_t *self ) -{ - int i; - gentity_t *ent; +static gentity_t *G_FindBuildable( buildable_t buildable ); - if( self->buildableTeam != TEAM_ALIENS ) - return qfalse; +gentity_t *G_Reactor( void ) +{ + static gentity_t *rc; - //if this already has overmind then stop now - if( self->overmindNode && self->overmindNode->health > 0 ) - return qtrue; + // If cache becomes invalid renew it + if( !rc || rc->s.eType != ET_BUILDABLE || rc->s.modelindex == BA_H_REACTOR ) + rc = G_FindBuildable( BA_H_REACTOR ); - //reset parent - self->overmindNode = NULL; + // If we found it and it's alive, return it + if( rc && rc->spawned && rc->health > 0 ) + return rc; - //iterate through entities - for( i = MAX_CLIENTS, ent = g_entities + i; i < level.num_entities; i++, ent++ ) - { - if( ent->s.eType != ET_BUILDABLE ) - continue; - - //if entity is an overmind calculate the distance to it - if( ent->s.modelindex == BA_A_OVERMIND && ent->spawned && ent->health > 0 ) - { - self->overmindNode = ent; - return qtrue; - } - } - - return qfalse; + return NULL; } -/* -================ -G_FindReactor - -Attempt to find a reactor for self -================ -*/ -qboolean G_FindReactor( gentity_t *self ) +gentity_t *G_Overmind( void ) { - int i; - gentity_t *ent; + static gentity_t *om; - if( self->buildableTeam != TEAM_HUMANS ) - return qfalse; + // If cache becomes invalid renew it + if( !om || om->s.eType != ET_BUILDABLE || om->s.modelindex == BA_A_OVERMIND ) + om = G_FindBuildable( BA_A_OVERMIND ); - // If this already has reactor then stop now - if( self->reactorNode && self->reactorNode->health > 0 ) - return qtrue; - - // Reset parent - self->reactorNode = NULL; - - // Iterate through entities - for( i = MAX_CLIENTS, ent = g_entities + i; i < level.num_entities; i++, ent++ ) - { - if( ent->s.eType != ET_BUILDABLE ) - continue; + // If we found it and it's alive, return it + if( om && om->spawned && om->health > 0 ) + return om; - // If entity is an overmind calculate the distance to it - if( ent->s.modelindex == BA_H_REACTOR && ent->spawned && ent->health > 0 ) - { - self->reactorNode = ent; - return qtrue; - } - } - - return qfalse; + return NULL; } /* @@ -888,7 +846,7 @@ A generic think function for Alien buildables */ void AGeneric_Think( gentity_t *self ) { - self->powered = level.overmindPresent; + self->powered = G_Overmind( ) != NULL; self->nextthink = level.time + BG_Buildable( self->s.modelindex )->nextthink; AGeneric_CreepCheck( self ); } @@ -1210,7 +1168,9 @@ Think function for Alien Barricade void ABarricade_Think( gentity_t *self ) { AGeneric_Think( self ); - ABarricade_Shrink( self, !G_FindOvermind( self ) ); + + // Shrink if unpowered + ABarricade_Shrink( self, !self->powered ); } /* @@ -1260,16 +1220,13 @@ void AAcidTube_Think( gentity_t *self ) int i, num; gentity_t *enemy; - self->powered = level.overmindPresent; - self->nextthink = level.time + BG_Buildable( self->s.modelindex )->nextthink; + AGeneric_Think( self ); VectorAdd( self->s.origin, range, maxs ); VectorSubtract( self->s.origin, range, mins ); - AGeneric_CreepCheck( self ); - // attack nearby humans - if( self->spawned && self->health > 0 && G_FindOvermind( self ) ) + if( self->spawned && self->health > 0 && self->powered ) { num = trap_EntitiesInBox( mins, maxs, entityList, MAX_GENTITIES ); for( i = 0; i < num; i++ ) @@ -1351,17 +1308,14 @@ Think function for Alien Hive */ void AHive_Think( gentity_t *self ) { - self->powered = level.overmindPresent; - self->nextthink = level.time + BG_Buildable( self->s.modelindex )->nextthink; - - AGeneric_CreepCheck( self ); + AGeneric_Think( self ); // Hive missile hasn't returned in HIVE_REPEAT seconds, forget about it if( self->timestamp < level.time ) self->active = qfalse; // Find a target to attack - if( self->spawned && !self->active && G_FindOvermind( self ) ) + if( self->spawned && !self->active && self->powered ) { int i, num, entityList[ MAX_GENTITIES ]; vec3_t mins, maxs, @@ -1499,7 +1453,7 @@ void AHovel_Use( gentity_t *self, gentity_t *other, gentity_t *activator ) { vec3_t hovelOrigin, hovelAngles, inverseNormal; - if( self->spawned && G_FindOvermind( self ) ) + if( self->spawned && self->powered ) { if( self->active ) { @@ -1558,10 +1512,7 @@ Think for alien hovel */ void AHovel_Think( gentity_t *self ) { - self->powered = level.overmindPresent; - self->nextthink = level.time + 200; - - AGeneric_CreepCheck( self ); + AGeneric_Think( self ); if( self->spawned ) { @@ -1631,10 +1582,7 @@ void ABooster_Touch( gentity_t *self, gentity_t *other, trace_t *trace ) { gclient_t *client = other->client; - if( !self->spawned || self->health <= 0 ) - return; - - if( !G_FindOvermind( self ) ) + if( !self->spawned || !self->powered || self->health <= 0 ) return; if( !client ) @@ -1791,12 +1739,9 @@ void ATrapper_Think( gentity_t *self ) int range = BG_Buildable( self->s.modelindex )->turretRange; int firespeed = BG_Buildable( self->s.modelindex )->turretFireSpeed; - self->powered = level.overmindPresent; - self->nextthink = level.time + BG_Buildable( self->s.modelindex )->nextthink; - - AGeneric_CreepCheck( self ); + AGeneric_Think( self ); - if( self->spawned && G_FindOvermind( self ) ) + if( self->spawned && self->powered ) { //if the current target is not valid find a new one if( !ATrapper_CheckTarget( self, self->enemy, range ) ) @@ -3386,7 +3331,7 @@ itemBuildError_t G_CanBuild( gentity_t *ent, buildable_t buildable, int distance // Check there is an Overmind if( buildable != BA_A_OVERMIND ) { - if( !level.overmindPresent ) + if( !G_Overmind( ) ) reason = IBE_NOOVERMIND; } diff --git a/src/game/g_cmds.c b/src/game/g_cmds.c index 35047f86..3bcb1c64 100644 --- a/src/game/g_cmds.c +++ b/src/game/g_cmds.c @@ -1798,7 +1798,7 @@ void Cmd_Class_f( gentity_t *ent ) int cost; //check that we have an overmind - if( !level.overmindPresent ) + if( !G_Overmind( ) ) { G_TriggerMenu( clientNum, MN_A_NOOVMND_EVOLVE ); return; diff --git a/src/game/g_local.h b/src/game/g_local.h index 033b0458..57406735 100644 --- a/src/game/g_local.h +++ b/src/game/g_local.h @@ -199,8 +199,6 @@ struct gentity_s qboolean locked; // used for turret tracking qboolean powered; // for human buildables int builtBy; // clientNum of person that built this - gentity_t *overmindNode; // controlling overmind - gentity_t *reactorNode; // reactor int dcc; // number of controlling dccs qboolean spawned; // whether or not this buildable has finished spawning int shrunkTime; // time when a barricade shrunk or zero @@ -615,8 +613,6 @@ typedef struct int alienKills; int humanKills; - qboolean reactorPresent; - qboolean overmindPresent; qboolean overmindMuted; int humanBaseAttackTimer; @@ -750,8 +746,8 @@ gentity_t *G_CheckSpawnPoint( int spawnNum, vec3_t origin, vec3_t normal buildable_t G_IsPowered( vec3_t origin ); qboolean G_IsDCCBuilt( void ); int G_FindDCC( gentity_t *self ); -qboolean G_FindOvermind( gentity_t *self ); -qboolean G_FindReactor( gentity_t *self ); +gentity_t *G_Reactor( void ); +gentity_t *G_Overmind( void ); qboolean G_FindCreep( gentity_t *self ); void G_BuildableThink( gentity_t *ent, int msec ); diff --git a/src/game/g_main.c b/src/game/g_main.c index eaa7e1e1..bf562a52 100644 --- a/src/game/g_main.c +++ b/src/game/g_main.c @@ -1145,12 +1145,6 @@ void G_CalculateBuildPoints( void ) level.humanBuildPoints = g_humanBuildPoints.integer - level.humanBuildPointQueue; level.alienBuildPoints = g_alienBuildPoints.integer - level.alienBuildPointQueue; - level.reactorPresent = qfalse; - level.overmindPresent = qfalse; - - level.numAlienSpawns = 0; - level.numHumanSpawns = 0; - // Deactivate any unused zones for( i = 0; i < g_humanRepeaterMaxZones.integer; i++ ) { @@ -1217,11 +1211,7 @@ void G_CalculateBuildPoints( void ) { if( ent->spawned && ent->health > 0 ) { - if( buildable == BA_H_REACTOR ) - level.reactorPresent = qtrue; - else if( buildable == BA_A_OVERMIND ) - level.overmindPresent = qtrue; - else if( buildable == BA_H_SPAWN ) + if( buildable == BA_H_SPAWN ) level.numHumanSpawns++; else if( buildable == BA_A_SPAWN ) level.numAlienSpawns++; |