00001 #include "b_local.h"
00002 #include "g_nav.h"
00003
00004
00005 #define AMMO_POD_HEALTH 1
00006 #define TURN_OFF 0x00000100
00007
00008 #define VELOCITY_DECAY 0.25
00009 #define MAX_DISTANCE 256
00010 #define MAX_DISTANCE_SQR ( MAX_DISTANCE * MAX_DISTANCE )
00011 #define MIN_DISTANCE 24
00012 #define MIN_DISTANCE_SQR ( MIN_DISTANCE * MIN_DISTANCE )
00013
00014 #include "../namespace_begin.h"
00015 extern gitem_t *BG_FindItemForAmmo( ammo_t ammo );
00016 #include "../namespace_end.h"
00017
00018
00019 enum
00020 {
00021 LSTATE_NONE = 0,
00022 LSTATE_DROPPINGDOWN,
00023 LSTATE_DOWN,
00024 LSTATE_RISINGUP,
00025 };
00026
00027 void NPC_Mark2_Precache( void )
00028 {
00029 G_SoundIndex( "sound/chars/mark2/misc/mark2_explo" );
00030 G_SoundIndex( "sound/chars/mark2/misc/mark2_pain" );
00031 G_SoundIndex( "sound/chars/mark2/misc/mark2_fire" );
00032 G_SoundIndex( "sound/chars/mark2/misc/mark2_move_lp" );
00033
00034 G_EffectIndex( "explosions/droidexplosion1" );
00035 G_EffectIndex( "env/med_explode2" );
00036 G_EffectIndex( "blaster/smoke_bolton" );
00037 G_EffectIndex( "bryar/muzzle_flash" );
00038
00039 RegisterItem( BG_FindItemForWeapon( WP_BRYAR_PISTOL ));
00040 RegisterItem( BG_FindItemForAmmo( AMMO_METAL_BOLTS));
00041 RegisterItem( BG_FindItemForAmmo( AMMO_POWERCELL ));
00042 RegisterItem( BG_FindItemForAmmo( AMMO_BLASTER ));
00043 }
00044
00045
00046
00047
00048
00049
00050 void NPC_Mark2_Part_Explode( gentity_t *self, int bolt )
00051 {
00052 if ( bolt >=0 )
00053 {
00054 mdxaBone_t boltMatrix;
00055 vec3_t org, dir;
00056
00057 trap_G2API_GetBoltMatrix( self->ghoul2, 0,
00058 bolt,
00059 &boltMatrix, self->r.currentAngles, self->r.currentOrigin, level.time,
00060 NULL, self->modelScale );
00061
00062 BG_GiveMeVectorFromMatrix( &boltMatrix, ORIGIN, org );
00063 BG_GiveMeVectorFromMatrix( &boltMatrix, NEGATIVE_Y, dir );
00064
00065 G_PlayEffectID( G_EffectIndex("env/med_explode2"), org, dir );
00066 G_PlayEffectID( G_EffectIndex("blaster/smoke_bolton"), org, dir );
00067 }
00068
00069
00070
00071 self->count++;
00072 }
00073
00074
00075
00076
00077
00078
00079
00080 void NPC_Mark2_Pain(gentity_t *self, gentity_t *attacker, int damage)
00081 {
00082 int newBolt,i;
00083 int hitLoc = gPainHitLoc;
00084
00085 NPC_Pain( self, attacker, damage );
00086
00087 for (i=0;i<3;i++)
00088 {
00089 if ((hitLoc==HL_GENERIC1+i) && (self->locationDamage[HL_GENERIC1+i] > AMMO_POD_HEALTH))
00090 {
00091 if (self->locationDamage[hitLoc] >= AMMO_POD_HEALTH)
00092 {
00093 newBolt = trap_G2API_AddBolt( self->ghoul2, 0, va("torso_canister%d",(i+1)) );
00094 if ( newBolt != -1 )
00095 {
00096 NPC_Mark2_Part_Explode(self,newBolt);
00097 }
00098 NPC_SetSurfaceOnOff( self, va("torso_canister%d",(i+1)), TURN_OFF );
00099 break;
00100 }
00101 }
00102 }
00103
00104 G_Sound( self, CHAN_AUTO, G_SoundIndex( "sound/chars/mark2/misc/mark2_pain" ));
00105
00106
00107 if (self->count > 0)
00108 {
00109 G_Damage( self, NULL, NULL, NULL, NULL, self->health, DAMAGE_NO_PROTECTION, MOD_UNKNOWN );
00110 }
00111 }
00112
00113
00114
00115
00116
00117
00118 void Mark2_Hunt(void)
00119 {
00120 if ( NPCInfo->goalEntity == NULL )
00121 {
00122 NPCInfo->goalEntity = NPC->enemy;
00123 }
00124
00125
00126 NPC_FaceEnemy( qtrue );
00127
00128 NPCInfo->combatMove = qtrue;
00129 NPC_MoveToGoal( qtrue );
00130 }
00131
00132
00133
00134
00135
00136
00137 void Mark2_FireBlaster(qboolean advance)
00138 {
00139 vec3_t muzzle1,enemy_org1,delta1,angleToEnemy1;
00140 static vec3_t forward, vright, up;
00141 static vec3_t muzzle;
00142 gentity_t *missile;
00143 mdxaBone_t boltMatrix;
00144 int bolt = trap_G2API_AddBolt(NPC->ghoul2, 0, "*flash");
00145
00146 trap_G2API_GetBoltMatrix( NPC->ghoul2, 0,
00147 bolt,
00148 &boltMatrix, NPC->r.currentAngles, NPC->r.currentOrigin, level.time,
00149 NULL, NPC->modelScale );
00150
00151 BG_GiveMeVectorFromMatrix( &boltMatrix, ORIGIN, muzzle1 );
00152
00153 if (NPC->health)
00154 {
00155 CalcEntitySpot( NPC->enemy, SPOT_HEAD, enemy_org1 );
00156 VectorSubtract (enemy_org1, muzzle1, delta1);
00157 vectoangles ( delta1, angleToEnemy1 );
00158 AngleVectors (angleToEnemy1, forward, vright, up);
00159 }
00160 else
00161 {
00162 AngleVectors (NPC->r.currentAngles, forward, vright, up);
00163 }
00164
00165 G_PlayEffectID( G_EffectIndex("bryar/muzzle_flash"), muzzle1, forward );
00166
00167 G_Sound( NPC, CHAN_AUTO, G_SoundIndex("sound/chars/mark2/misc/mark2_fire"));
00168
00169 missile = CreateMissile( muzzle1, forward, 1600, 10000, NPC, qfalse );
00170
00171 missile->classname = "bryar_proj";
00172 missile->s.weapon = WP_BRYAR_PISTOL;
00173
00174 missile->damage = 1;
00175 missile->dflags = DAMAGE_DEATH_KNOCKBACK;
00176 missile->methodOfDeath = MOD_BRYAR_PISTOL;
00177 missile->clipmask = MASK_SHOT | CONTENTS_LIGHTSABER;
00178
00179 }
00180
00181
00182
00183
00184
00185
00186 void Mark2_BlasterAttack(qboolean advance)
00187 {
00188 if ( TIMER_Done( NPC, "attackDelay" ) )
00189 {
00190 if (NPCInfo->localState == LSTATE_NONE)
00191 {
00192 TIMER_Set( NPC, "attackDelay", Q_irand( 500, 2000) );
00193 }
00194 else
00195 {
00196 TIMER_Set( NPC, "attackDelay", Q_irand( 100, 500) );
00197 }
00198 Mark2_FireBlaster(advance);
00199 return;
00200 }
00201 else if (advance)
00202 {
00203 Mark2_Hunt();
00204 }
00205 }
00206
00207
00208
00209
00210
00211
00212 void Mark2_AttackDecision( void )
00213 {
00214 float distance;
00215 qboolean visible;
00216 qboolean advance;
00217
00218 NPC_FaceEnemy( qtrue );
00219
00220 distance = (int) DistanceHorizontalSquared( NPC->r.currentOrigin, NPC->enemy->r.currentOrigin );
00221 visible = NPC_ClearLOS4( NPC->enemy );
00222 advance = (qboolean)(distance > MIN_DISTANCE_SQR);
00223
00224
00225 if (NPCInfo->localState == LSTATE_RISINGUP)
00226 {
00227 NPC->flags &= ~FL_SHIELDED;
00228 NPC_SetAnim( NPC, SETANIM_BOTH, BOTH_RUN1START, SETANIM_FLAG_HOLD|SETANIM_FLAG_OVERRIDE );
00229 if ((NPC->client->ps.legsTimer<=0) &&
00230 NPC->client->ps.torsoAnim == BOTH_RUN1START )
00231 {
00232 NPCInfo->localState = LSTATE_NONE;
00233 }
00234 return;
00235 }
00236
00237
00238 if ((!visible) || (!NPC_FaceEnemy(qtrue)))
00239 {
00240
00241 if ((NPCInfo->localState == LSTATE_DOWN) || (NPCInfo->localState == LSTATE_DROPPINGDOWN))
00242 {
00243 if ( TIMER_Done( NPC, "downTime" ) )
00244 {
00245 NPCInfo->localState = LSTATE_RISINGUP;
00246 NPC_SetAnim( NPC, SETANIM_BOTH, BOTH_RUN1STOP, SETANIM_FLAG_HOLD|SETANIM_FLAG_OVERRIDE );
00247 TIMER_Set( NPC, "runTime", Q_irand( 3000, 8000) );
00248 }
00249 }
00250 else
00251 {
00252 Mark2_Hunt();
00253 }
00254 return;
00255 }
00256
00257
00258 if ((advance) && (TIMER_Done( NPC, "downTime" )) && (NPCInfo->localState == LSTATE_DOWN))
00259 {
00260 NPCInfo->localState = LSTATE_RISINGUP;
00261 NPC_SetAnim( NPC, SETANIM_BOTH, BOTH_RUN1STOP, SETANIM_FLAG_HOLD|SETANIM_FLAG_OVERRIDE );
00262 TIMER_Set( NPC, "runTime", Q_irand( 3000, 8000) );
00263 }
00264
00265 NPC_FaceEnemy( qtrue );
00266
00267
00268 if (NPCInfo->localState == LSTATE_DROPPINGDOWN)
00269 {
00270 NPC_SetAnim( NPC, SETANIM_BOTH, BOTH_RUN1STOP, SETANIM_FLAG_HOLD|SETANIM_FLAG_OVERRIDE );
00271 TIMER_Set( NPC, "downTime", Q_irand( 3000, 9000) );
00272
00273 if ((NPC->client->ps.legsTimer<=0) && NPC->client->ps.torsoAnim == BOTH_RUN1STOP )
00274 {
00275 NPC->flags |= FL_SHIELDED;
00276 NPCInfo->localState = LSTATE_DOWN;
00277 }
00278 }
00279
00280 else if (NPCInfo->localState == LSTATE_DOWN)
00281 {
00282 NPC->flags |= FL_SHIELDED;
00283
00284 Mark2_BlasterAttack(qfalse);
00285 }
00286 else if (TIMER_Done( NPC, "runTime" ))
00287 {
00288 NPCInfo->localState = LSTATE_DROPPINGDOWN;
00289 }
00290 else if (advance)
00291 {
00292
00293 Mark2_BlasterAttack(advance);
00294 }
00295 }
00296
00297
00298
00299
00300
00301
00302
00303 void Mark2_Patrol( void )
00304 {
00305 if ( NPC_CheckPlayerTeamStealth() )
00306 {
00307
00308 NPC_UpdateAngles( qtrue, qtrue );
00309 return;
00310 }
00311
00312
00313 if (!NPC->enemy)
00314 {
00315 if ( UpdateGoal() )
00316 {
00317 ucmd.buttons |= BUTTON_WALKING;
00318 NPC_MoveToGoal( qtrue );
00319 NPC_UpdateAngles( qtrue, qtrue );
00320 }
00321
00322
00323 if (TIMER_Done(NPC,"patrolNoise"))
00324 {
00325
00326
00327 TIMER_Set( NPC, "patrolNoise", Q_irand( 2000, 4000 ) );
00328 }
00329 }
00330 }
00331
00332
00333
00334
00335
00336
00337 void Mark2_Idle( void )
00338 {
00339 NPC_BSIdle();
00340 }
00341
00342
00343
00344
00345
00346
00347 void NPC_BSMark2_Default( void )
00348 {
00349 if ( NPC->enemy )
00350 {
00351 NPCInfo->goalEntity = NPC->enemy;
00352 Mark2_AttackDecision();
00353 }
00354 else if ( NPCInfo->scriptFlags & SCF_LOOK_FOR_ENEMIES )
00355 {
00356 Mark2_Patrol();
00357 }
00358 else
00359 {
00360 Mark2_Idle();
00361 }
00362 }