diff options
author | Petr Pudlak <petr.mvd@gmail.com> | 2014-09-20 16:04:45 +0200 |
---|---|---|
committer | Petr Pudlak <petr.mvd@gmail.com> | 2014-09-20 16:04:45 +0200 |
commit | d15d03572381c449024f385f4774f1c4bc95e227 (patch) | |
tree | b9cb204a700461b96d6d3fdeb8be5ac9fc0791ac /src/game/g_buildable.c | |
parent | c9ee8af98ce89fe2ffbe4389345a58899f3b3534 (diff) |
Add a helper function for suiciding buildables
Removes duplicate code when suiciding alien and human structures.
Diffstat (limited to 'src/game/g_buildable.c')
-rw-r--r-- | src/game/g_buildable.c | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/src/game/g_buildable.c b/src/game/g_buildable.c index 61a3460..856db29 100644 --- a/src/game/g_buildable.c +++ b/src/game/g_buildable.c @@ -516,6 +516,24 @@ gentity_t *G_InPowerZone( gentity_t *self ) /* ================ +G_Suicide + +let the given buildable suicide +================ +*/ +void G_Suicide( gentity_t *self ) +{ + const gentity_t *parent = self->parentNode; + + if( parent ) + G_Damage( self, NULL, g_entities + parent->killedBy, NULL, NULL, + self->health, 0, MOD_NOCREEP ); + else + G_Damage( self, NULL, NULL, NULL, NULL, self->health, 0, MOD_NOCREEP ); +} + +/* +================ G_FindDCC attempt to find a controlling DCC for self, return number found @@ -952,16 +970,9 @@ Tests for creep and kills the buildable if there is none */ void AGeneric_CreepCheck( gentity_t *self ) { - gentity_t *spawn; - - spawn = self->parentNode; if( !G_FindCreep( self ) ) { - if( spawn ) - G_Damage( self, NULL, g_entities + spawn->killedBy, NULL, NULL, - self->health, 0, MOD_NOCREEP ); - else - G_Damage( self, NULL, NULL, NULL, NULL, self->health, 0, MOD_NOCREEP ); + G_Suicide( self ); return; } G_CreepSlow( self ); @@ -2314,11 +2325,7 @@ static qboolean G_SuicideIfNoPower( gentity_t *self ) self->count = level.time; else if( ( level.time - self->count ) >= HUMAN_BUILDABLE_INACTIVE_TIME ) { - if( self->parentNode ) - G_Damage( self, NULL, g_entities + self->parentNode->killedBy, - NULL, NULL, self->health, 0, MOD_NOCREEP ); - else - G_Damage( self, NULL, NULL, NULL, NULL, self->health, 0, MOD_NOCREEP ); + G_Suicide( self ); return qtrue; } } |