From d15d03572381c449024f385f4774f1c4bc95e227 Mon Sep 17 00:00:00 2001 From: Petr Pudlak Date: Sat, 20 Sep 2014 16:04:45 +0200 Subject: Add a helper function for suiciding buildables Removes duplicate code when suiciding alien and human structures. --- src/game/g_buildable.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) (limited to 'src/game') 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 @@ -514,6 +514,24 @@ gentity_t *G_InPowerZone( gentity_t *self ) return NULL; } +/* +================ +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 @@ -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; } } -- cgit