//----------------------------------------------------------------------------- // Purpose: Gets event from anim stream and throws the object // Input : // Output : //----------------------------------------------------------------------------- void CWeaponMolotov::Operator_HandleAnimEvent( animevent_t *pEvent, CBaseCombatCharacter *pOperator ) { switch( pEvent->event ) { case EVENT_WEAPON_THROW: { CAI_BaseNPC *pNPC = GetOwner()->MyNPCPointer(); if (!pNPC) { return; } CBaseEntity *pEnemy = pNPC->GetEnemy(); if (!pEnemy) { return; } Vector vec_target = pNPC->GetEnemyLKP(); // ----------------------------------------------------- // Get position of throw // ----------------------------------------------------- // If owner has a hand, set position to the hand bone position Vector launchPos; int iBIndex = pNPC->LookupBone("Bip01 R Hand"); if (iBIndex != -1) { Vector origin; QAngle angles; pNPC->GetBonePosition( iBIndex, launchPos, angles); } // Otherwise just set to in front of the owner else { Vector vFacingDir = pNPC->BodyDirection2D( ); vFacingDir = vFacingDir * 60.0; launchPos = pNPC->GetAbsOrigin()+vFacingDir; } //Vector vecVelocity = VecCheckToss( pNPC, launchPos, vec_target, 1.0 ); ThrowMolotov( launchPos, m_vecTossVelocity); // Drop the weapon and remove as no more ammo pNPC->Weapon_Drop( this ); UTIL_Remove( this ); } break; default: BaseClass::Operator_HandleAnimEvent( pEvent, pOperator ); break; } }
//----------------------------------------------------------------------------- // Purpose: // Input : flDot - // flDist - // Output : int //----------------------------------------------------------------------------- int CWeaponSMG1::WeaponRangeAttack2Condition( float flDot, float flDist ) { CAI_BaseNPC *npcOwner = GetOwner()->MyNPCPointer(); return COND_NONE; /* // -------------------------------------------------------- // Assume things haven't changed too much since last time // -------------------------------------------------------- if (gpGlobals->curtime < m_flNextGrenadeCheck ) return m_lastGrenadeCondition; */ // ----------------------- // If moving, don't check. // ----------------------- if ( npcOwner->IsMoving()) return COND_NONE; CBaseEntity *pEnemy = npcOwner->GetEnemy(); if (!pEnemy) return COND_NONE; Vector vecEnemyLKP = npcOwner->GetEnemyLKP(); if ( !( pEnemy->GetFlags() & FL_ONGROUND ) && pEnemy->GetWaterLevel() == 0 && vecEnemyLKP.z > (GetAbsOrigin().z + WorldAlignMaxs().z) ) { //!!!BUGBUG - we should make this check movetype and make sure it isn't FLY? Players who jump a lot are unlikely to // be grenaded. // don't throw grenades at anything that isn't on the ground! return COND_NONE; } // -------------------------------------- // Get target vector // -------------------------------------- Vector vecTarget; if (random->RandomInt(0,1)) { // magically know where they are vecTarget = pEnemy->WorldSpaceCenter(); } else { // toss it to where you last saw them vecTarget = vecEnemyLKP; } // vecTarget = m_vecEnemyLKP + (pEnemy->BodyTarget( GetLocalOrigin() ) - pEnemy->GetLocalOrigin()); // estimate position // vecTarget = vecTarget + pEnemy->m_vecVelocity * 2; if ( ( vecTarget - npcOwner->GetLocalOrigin() ).Length2D() <= COMBINE_MIN_GRENADE_CLEAR_DIST ) { // crap, I don't want to blow myself up m_flNextGrenadeCheck = gpGlobals->curtime + 1; // one full second. return (COND_NONE); } // --------------------------------------------------------------------- // Are any friendlies near the intended grenade impact area? // --------------------------------------------------------------------- CBaseEntity *pTarget = NULL; while ( ( pTarget = gEntList.FindEntityInSphere( pTarget, vecTarget, COMBINE_MIN_GRENADE_CLEAR_DIST ) ) != NULL ) { //Check to see if the default relationship is hatred, and if so intensify that if ( npcOwner->IRelationType( pTarget ) == D_LI ) { // crap, I might blow my own guy up. Don't throw a grenade and don't check again for a while. m_flNextGrenadeCheck = gpGlobals->curtime + 1; // one full second. return (COND_WEAPON_BLOCKED_BY_FRIEND); } } // --------------------------------------------------------------------- // Check that throw is legal and clear // --------------------------------------------------------------------- // FIXME: speed is based on difficulty... Vector vecToss = VecCheckThrow( this, npcOwner->GetLocalOrigin() + Vector(0,0,60), vecTarget, 600.0, 0.5 ); if ( vecToss != vec3_origin ) { m_vecTossVelocity = vecToss; // don't check again for a while. // JAY: HL1 keeps checking - test? //m_flNextGrenadeCheck = gpGlobals->curtime; m_flNextGrenadeCheck = gpGlobals->curtime + 0.3; // 1/3 second. return COND_CAN_RANGE_ATTACK2; } else { // don't check again for a while. m_flNextGrenadeCheck = gpGlobals->curtime + 1; // one full second. return COND_WEAPON_SIGHT_OCCLUDED; } }
void CAI_MoveAndShootOverlay::RunShootWhileMove() { if ( m_flNextMoveShootTime == FLT_MAX ) return; CAI_BaseNPC *pOuter = GetOuter(); // keep enemy if dead but try to look for a new one if (!pOuter->GetEnemy() || !pOuter->GetEnemy()->IsAlive()) { CBaseEntity *pNewEnemy = pOuter->BestEnemy(); if( pNewEnemy != NULL ) { //New enemy! Clear the timers and set conditions. pOuter->SetCondition( COND_NEW_ENEMY ); pOuter->SetEnemy( pNewEnemy ); pOuter->SetState( NPC_STATE_COMBAT ); } else { pOuter->ClearAttackConditions(); } // SetEnemy( NULL ); } if ( GetEnemy() == NULL || !pOuter->GetNavigator()->IsGoalActive() ) return; bool bMoveAimAtEnemy = CanAimAtEnemy(); UpdateMoveShootActivity( bMoveAimAtEnemy ); if (bMoveAimAtEnemy) { Assert( pOuter->GetActiveWeapon() ); // This should have been caught at task start // time to fire? if ( pOuter->HasCondition( COND_CAN_RANGE_ATTACK1 ) && gpGlobals->curtime >= m_flNextMoveShootTime ) { if ( m_bMovingAndShooting || GetOuter()->OnBeginMoveAndShoot() ) { m_bMovingAndShooting = true; Activity activity = pOuter->TranslateActivity( ACT_GESTURE_RANGE_ATTACK1 ); Assert( activity != ACT_INVALID ); if (--m_nMoveShots > 0) { pOuter->SetLastAttackTime( gpGlobals->curtime ); pOuter->AddGesture( activity ); // FIXME: this seems a bit wacked pOuter->Weapon_SetActivity( pOuter->Weapon_TranslateActivity( ACT_RANGE_ATTACK1 ), 0 ); m_flNextMoveShootTime = gpGlobals->curtime + pOuter->GetActiveWeapon()->GetFireRate() - 0.1; } else { m_nMoveShots = random->RandomInt( m_minBurst, m_maxBurst ); m_flNextMoveShootTime = gpGlobals->curtime + random->RandomFloat( m_minPause, m_maxPause ); m_bMovingAndShooting = false; GetOuter()->OnEndMoveAndShoot(); } } } // try to keep facing towards the last known position of the enemy Vector vecEnemyLKP = pOuter->GetEnemyLKP(); pOuter->AddFacingTarget( pOuter->GetEnemy(), vecEnemyLKP, 1.0, 0.8 ); } else { if ( m_bMovingAndShooting ) { m_bMovingAndShooting = false; GetOuter()->OnEndMoveAndShoot(); } } }
void CAI_MoveAndShootOverlay::RunShootWhileMove() { if ( m_bNoShootWhileMove ) return; if ( gpGlobals->curtime < m_flSuspendUntilTime ) return; m_flSuspendUntilTime = MOVESHOOT_DO_NOT_SUSPEND; CAI_BaseNPC *pOuter = GetOuter(); // keep enemy if dead but try to look for a new one if (!pOuter->GetEnemy() || !pOuter->GetEnemy()->IsAlive()) { CBaseEntity *pNewEnemy = pOuter->BestEnemy(); if( pNewEnemy != NULL ) { //New enemy! Clear the timers and set conditions. pOuter->SetEnemy( pNewEnemy ); pOuter->SetState( NPC_STATE_COMBAT ); } else { pOuter->ClearAttackConditions(); } // SetEnemy( NULL ); } /*if( !pOuter->GetNavigator()->IsGoalActive() ) return;*/ if ( GetEnemy() == NULL ) { if ( pOuter->GetAlternateMoveShootTarget() ) { // Aim at this other thing if I can't aim at my enemy. pOuter->AddFacingTarget( pOuter->GetAlternateMoveShootTarget(), pOuter->GetAlternateMoveShootTarget()->GetAbsOrigin(), 1.0, 0.2 ); } return; } bool bMoveAimAtEnemy = CanAimAtEnemy(); UpdateMoveShootActivity( bMoveAimAtEnemy ); if ( !bMoveAimAtEnemy ) { EndShootWhileMove(); return; } Assert( HasAvailableRangeAttack() ); // This should have been caught at task start Activity activity; bool bIsReloading = false; if ( ( activity = pOuter->TranslateActivity( ACT_GESTURE_RELOAD ) ) != ACT_INVALID ) { bIsReloading = pOuter->IsPlayingGesture( activity ); } if ( !bIsReloading && HasAvailableRangeAttack() ) { // time to fire? if ( pOuter->HasCondition( COND_CAN_RANGE_ATTACK1, false ) ) { if ( pOuter->GetShotRegulator()->IsInRestInterval() ) { EndShootWhileMove(); } else if ( pOuter->GetShotRegulator()->ShouldShoot() ) { if ( m_bMovingAndShooting || pOuter->OnBeginMoveAndShoot() ) { m_bMovingAndShooting = true; pOuter->OnRangeAttack1(); activity = pOuter->TranslateActivity( ACT_GESTURE_RANGE_ATTACK1 ); Assert( activity != ACT_INVALID ); pOuter->RestartGesture( activity ); // FIXME: this seems a bit wacked pOuter->Weapon_SetActivity( pOuter->Weapon_TranslateActivity( ACT_RANGE_ATTACK1 ), 0 ); } } } } // try to keep facing towards the last known position of the enemy Vector vecEnemyLKP = pOuter->GetEnemyLKP(); pOuter->AddFacingTarget( pOuter->GetEnemy(), vecEnemyLKP, 1.0, 0.8 ); }