virtual void OnShoot(IWeapon *pWeapon, EntityId shooterId, EntityId ammoId, IEntityClass* pAmmoType, const Vec3 &pos, const Vec3 &dir, const Vec3 &vel) { ++m_numShotsDone; if (m_numShots!=0 && m_numShotsDone>=m_numShots) StopFiring( &m_actInfo, pWeapon ); else { CalcFiringPosition( &m_actInfo, pWeapon ); } }
void AAgent::CheckLoS() { AAgentController* Controller = Cast<AAgentController>(GetController()); if (Controller != NULL) { // Get the location of the agent FVector AgentLocation = GetActorLocation(); // Get the direction the agent is facing FVector Direction = GetActorForwardVector(); // Default trace params FCollisionQueryParams TraceParams(TEXT("LineOfSight_Trace"), false, this); TraceParams.bTraceAsyncScene = true; //=====Draw line trace from agent to player=====// FHitResult Hit(ForceInit); UWorld* World = GetWorld(); World->LineTraceSingleByChannel(Hit, AgentLocation + Direction, Controller->GetFocalPoint(), ECollisionChannel::ECC_Visibility, TraceParams, FCollisionResponseParams::DefaultResponseParam); //DrawDebugLine(World, AgentLocation + Direction, Controller->GetFocalPoint(), FColor::Yellow, false, -1, 0, 2.0f); //==============================================// AActor* HitActor = Hit.GetActor(); if (HitActor != NULL && HitActor->ActorHasTag("Player")) { } /* Otherwise we can assume the actor intersecting the line trace is blocking the line of sight from the agent to the player */ else if (HitActor != NULL) { /* The focal point is currently on the player actor. Set the PlayerLocation blackboard key to the location of this focal point, so that when the agent moves into the Search behaviour it will move to the actual location of the player when the agent lost LoS as opposed to the last location it sensed the player at. */ Controller->SetPlayerLocation(Controller->GetFocalPoint()); // LoS to player is blocked bPlayerSeen = false; // Reset the player has seen blackboard key so that the Agent can begin searching. Controller->SetPlayerFound(bPlayerSeen); // Clear the focus on the player Controller->ClearFocus(EAIFocusPriority::Gameplay); bCanSearch = true; Controller->SetCanSearch(bCanSearch); // Stop firing if still firing if (isFiring) StopFiring(); } } }
void CASW_Sentry_Top_Flamer::CheckFiring() { bool bShouldFire = false; if ( HasAmmo() && m_hEnemy.IsValid() && m_hEnemy.Get()) { float flDist = fabs(m_fGoalYaw - m_fCurrentYaw); if (flDist > 180) flDist = 360 - flDist; // use some hysteresis if (flDist < (IsFiring() ? ASW_SENTRY_FIRE_ANGLE_THRESHOLD * 1.1f : ASW_SENTRY_FIRE_ANGLE_THRESHOLD) ) { bShouldFire = true; } } if ( bShouldFire ) { m_flFireHysteresisTime = gpGlobals->curtime + 0.5f; } else { bShouldFire = gpGlobals->curtime < m_flFireHysteresisTime ; } // turn firing on or off as appropriate if ( IsFiring() != bShouldFire ) { if ( bShouldFire ) StartFiring(); else StopFiring(); } Assert( IsFiring() == bShouldFire ); if ( bShouldFire ) { Fire(); } }
void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo ) { IWeapon* pWeapon = GetWeapon(pActInfo); if (!pWeapon) return; switch (event) { case eFE_Initialize: { m_isFiring = false; m_numShots = GetPortInt( pActInfo, IN_NUMBEROFSHOTS ); m_actInfo = *pActInfo; m_numShotsDone = 0; pWeapon->StopFire(); if (pActInfo->pEntity->GetId() != m_weapId) RemoveListener(m_weapId, this); m_weapId = pActInfo->pEntity->GetId(); pWeapon->AddEventListener(this, __FUNCTION__); #ifdef DEBUG_NODEFIREWEAPON pActInfo->pGraph->SetRegularlyUpdated( pActInfo->myID, true ); #endif break; } case eFE_Activate: { m_actInfo = *pActInfo; if (IsPortActive(pActInfo, IN_NUMBEROFSHOTS)) m_numShots = GetPortBool( pActInfo, IN_NUMBEROFSHOTS ); if (IsPortActive(pActInfo, IN_STOPFIRE)) { StopFiring( pActInfo, pWeapon ); } if (IsPortActive(pActInfo, IN_STARTFIRE)) { m_numShotsDone = 0; ReplenishAmmo( pWeapon ); pWeapon->StopFire(); StartFiring( pActInfo, pWeapon ); } break; } case eFE_Update: { // this fixes the problem when the entity is being externally moved/rotated, in the interval of time between when the weapon is aimed an the actual shot happens if (m_isFiring && GetPortBool( pActInfo, IN_ALIGNTOTARGET )) if (pActInfo->pEntity->GetWorldPos()!=m_lastPos || pActInfo->pEntity->GetWorldRotation()!=m_lastRotation) CalcFiringPosition( pActInfo, pWeapon ); #ifdef DEBUG_NODEFIREWEAPON ColorB colorRed( 255,0,0 ); ColorB colorGreen( 0,255,0 ); gEnv->pRenderer->GetIRenderAuxGeom()->DrawLine( posOrig, colorRed, posTarget, colorRed ); gEnv->pRenderer->GetIRenderAuxGeom()->DrawLine( posTarget, colorGreen, posShot, colorGreen ); #endif break; } } }