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.c101
1 files changed, 96 insertions, 5 deletions
diff --git a/src/game/g_buildable.c b/src/game/g_buildable.c
index ee3a02a2..1c3c0a22 100644
--- a/src/game/g_buildable.c
+++ b/src/game/g_buildable.c
@@ -1734,6 +1734,27 @@ static void G_SuicideIfNoPower( gentity_t *self )
}
}
+/*
+================
+G_IdlePowerState
+
+Set buildable idle animation to match power state
+================
+*/
+static void G_IdlePowerState( gentity_t *self )
+{
+ if( self->powered )
+ {
+ if( self->s.torsoAnim == BANIM_IDLE3 )
+ G_SetIdleBuildableAnim( self, BG_Buildable( self->s.modelindex )->idleAnim );
+ }
+ else
+ {
+ if( self->s.torsoAnim != BANIM_IDLE3 )
+ G_SetIdleBuildableAnim( self, BANIM_IDLE3 );
+ }
+}
+
@@ -1950,6 +1971,8 @@ void HRepeater_Think( gentity_t *self )
self->powered = reactor;
+ G_IdlePowerState( self );
+
// Initialise the zone once the repeater has spawned
if( self->spawned && ( !self->usesBuildPointZone || !level.buildPointZones[ self->buildPointZone ].active ) )
{
@@ -2178,19 +2201,19 @@ void HMedistat_Think( gentity_t *self )
self->nextthink = level.time + BG_Buildable( self->s.modelindex )->nextthink;
+ self->powered = G_FindPower( self );
G_SuicideIfNoPower( self );
+ G_IdlePowerState( self );
//clear target's healing flag
if( self->enemy && self->enemy->client )
self->enemy->client->ps.stats[ STAT_STATE ] &= ~SS_HEALING_ACTIVE;
//make sure we have power
- if( !( self->powered = G_FindPower( self ) ) )
+ if( !self->powered )
{
if( self->active )
{
- G_SetBuildableAnim( self, BANIM_CONSTRUCT2, qtrue );
- G_SetIdleBuildableAnim( self, BANIM_IDLE1 );
self->active = qfalse;
self->enemy = NULL;
}
@@ -2429,6 +2452,62 @@ void HMGTurret_FindEnemy( gentity_t *self )
}
}
+/*
+================
+HMGTurret_State
+
+Raise or lower MG turret towards desired state
+================
+*/
+enum {
+ MGT_STATE_INACTIVE,
+ MGT_STATE_DROP,
+ MGT_STATE_RISE,
+ MGT_STATE_ACTIVE
+};
+
+static qboolean HMGTurret_State( gentity_t *self, int state )
+{
+ float angle;
+
+ if( self->waterlevel == state )
+ return qfalse;
+
+ angle = AngleNormalize180( self->s.angles2[ PITCH ] );
+
+ if( state == MGT_STATE_INACTIVE )
+ {
+ if( angle < MGTURRET_VERTICALCAP )
+ {
+ if( self->waterlevel != MGT_STATE_DROP )
+ {
+ self->speed = 0.25f;
+ self->waterlevel = MGT_STATE_DROP;
+ }
+ else
+ self->speed *= 1.25f;
+
+ self->s.angles2[ PITCH ] =
+ MIN( MGTURRET_VERTICALCAP, angle + self->speed );
+ return qtrue;
+ }
+ else
+ self->waterlevel = MGT_STATE_INACTIVE;
+ }
+ else if( state == MGT_STATE_ACTIVE )
+ {
+ if( !self->enemy && angle > 0.0f )
+ {
+ self->waterlevel = MGT_STATE_RISE;
+ self->s.angles2[ PITCH ] =
+ MAX( 0.0f, angle - MGTURRET_ANGULARSPEED * 0.5f );
+ }
+ else
+ self->waterlevel = MGT_STATE_ACTIVE;
+ }
+
+ return qfalse;
+}
/*
================
@@ -2445,11 +2524,18 @@ void HMGTurret_Think( gentity_t *self )
// Turn off client side muzzle flashes
self->s.eFlags &= ~EF_FIRING;
+ self->powered = G_FindPower( self );
G_SuicideIfNoPower( self );
+ G_IdlePowerState( self );
// If not powered or spawned don't do anything
- if( !( self->powered = G_FindPower( self ) ) )
+ if( !self->powered )
{
+ // if power loss drop turret
+ if( self->spawned &&
+ HMGTurret_State( self, MGT_STATE_INACTIVE ) );
+ return;
+
self->nextthink = level.time + POWER_REFRESH_TIME;
return;
}
@@ -2463,6 +2549,8 @@ void HMGTurret_Think( gentity_t *self )
self->turretSpinupTime = -1;
HMGTurret_FindEnemy( self );
}
+ // if newly powered raise turret
+ HMGTurret_State( self, MGT_STATE_ACTIVE );
if( !self->enemy )
return;
@@ -2517,10 +2605,12 @@ void HTeslaGen_Think( gentity_t *self )
{
self->nextthink = level.time + BG_Buildable( self->s.modelindex )->nextthink;
+ self->powered = G_FindPower( self );
G_SuicideIfNoPower( self );
+ G_IdlePowerState( self );
//if not powered don't do anything and check again for power next think
- if( !( self->powered = G_FindPower( self ) ) )
+ if( !self->powered )
{
self->s.eFlags &= ~EF_FIRING;
self->nextthink = level.time + POWER_REFRESH_TIME;
@@ -3691,6 +3781,7 @@ static gentity_t *G_Build( gentity_t *builder, buildable_t buildable, vec3_t ori
VectorCopy( angles, built->s.angles );
built->s.angles[ PITCH ] = 0.0f;
built->s.angles2[ YAW ] = angles[ YAW ];
+ built->s.angles2[ PITCH ] = MGTURRET_VERTICALCAP;
built->s.pos.trType = BG_Buildable( buildable )->traj;
built->s.pos.trTime = level.time;
built->physicsBounce = BG_Buildable( buildable )->bounce;