summaryrefslogtreecommitdiff
path: root/src/game/g_buildable.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/g_buildable.c')
-rw-r--r--src/game/g_buildable.c53
1 files changed, 51 insertions, 2 deletions
diff --git a/src/game/g_buildable.c b/src/game/g_buildable.c
index 4e87681..81d303c 100644
--- a/src/game/g_buildable.c
+++ b/src/game/g_buildable.c
@@ -163,6 +163,42 @@ static int G_NumberOfDependants( gentity_t *self )
/*
================
+G_CheckSelfDestruct
+
+check to see whether we should self destruct a human buildable
+the g_humanBuildableNoCreepMode cvar controls this, with the following modes:
+ 0 - disabled
+ 1 - any unpowered human building dies after g_humanBuildableNoCreepTime seconds
+ 2 - any unpowered human building except the spawns die after g_humanBuildableNoCreepTime seconds
+
+both cvars must be set for this to to be enabled
+================
+*/
+
+static void G_CheckSelfDestruct( gentity_t *self )
+{
+ // make sure the level.time is above 1s else the buildings die if the map is restarted
+ if( g_humanBuildableNoCreepMode.integer <= 0 || g_humanBuildableNoCreepTime.integer <= 0 || level.time < 1000 )
+ return;
+
+ // check for blacklisted buildables
+ if( self->s.modelindex == BA_H_REPEATER || // don't kill repeaters, ever.
+ ( g_humanBuildableNoCreepMode.integer == 2 && self->s.modelindex == BA_H_SPAWN ) ) // mode 2 = ignore the spawns
+ return;
+
+ // only continue if the building has been unpowered for longer than g_humanBuildableNoCreepTime.
+ if( ( level.time - self->poweredAt ) / 1000 < g_humanBuildableNoCreepTime.integer )
+ return;
+
+ // building begone
+ G_LogPrintf("Unpowered human buildable %s, killed at at %is, which last received power at %is (game time)\n",
+ BG_FindNameForBuildable( self->s.modelindex ), level.time / 1000, self->poweredAt / 1000 );
+
+ G_Damage( self, NULL, NULL, NULL, NULL, 10000, 0, MOD_SUICIDE );
+}
+
+/*
+================
G_FindPower
attempt to find power for self, return qtrue if successful
@@ -182,11 +218,18 @@ static qboolean G_FindPower( gentity_t *self )
//reactor is always powered
if( self->s.modelindex == BA_H_REACTOR )
+ {
+ self->poweredAt = level.time;
return qtrue;
-
+ }
//if this already has power then stop now
if( self->parentNode && self->parentNode->powered )
+ {
+ self->poweredAt = level.time;
return qtrue;
+ }
+ if( self->poweredAt == 0 )
+ self->poweredAt = level.time; // set this now just in case
//reset parent
self->parentNode = NULL;
@@ -219,10 +262,14 @@ static qboolean G_FindPower( gentity_t *self )
//if there were no power items nearby give up
if( closestPower ) {
self->parentNode = closestPower;
+ self->poweredAt = level.time;
return qtrue;
}
else
+ {
+ G_CheckSelfDestruct( self );
return qfalse;
+ }
}
/*
@@ -2769,7 +2816,7 @@ void HSpawn_Think( gentity_t *self )
gentity_t *ent;
// spawns work without power
- self->powered = qtrue;
+ // self->powered = qtrue; // NOT ANY MORE THEY DON'T
if( self->spawned )
{
@@ -2838,6 +2885,8 @@ void HSpawn_Think( gentity_t *self )
}
self->nextthink = level.time + BG_FindNextThinkForBuildable( self->s.modelindex );
+
+ self->powered = G_FindPower( self );
}