Пример #1
0
//------------------------------------------------------------------------
void CVehicleWeapon::StartUse(EntityId userId)
{
	if (m_ownerId && userId != m_ownerId)
		return; 

  if (GetEntity()->GetParent())
  { 
    m_pVehicle = gEnv->pGame->GetIGameFramework()->GetIVehicleSystem()->GetVehicle(GetEntity()->GetParent()->GetId());
    assert(m_pVehicle && "Using VehicleWeapons on non-vehicles may lead to unexpected behavior.");

    if (m_pVehicle)
    {   
      m_pPart = m_pVehicle->GetWeaponParentPart(GetEntityId()); 
      m_pOwnerSeat = m_pVehicle->GetWeaponParentSeat(GetEntityId());
      m_pSeatUser = m_pVehicle->GetSeatForPassenger(userId);
    }
  }
  
	SetOwnerId(userId);
  Select(true);	
	m_stats.used = true;

	EnableUpdate(true, eIUS_General);
	RequireUpdate(eIUS_General);

  if (OutOfAmmo(false))
    Reload(false);

  UseManualBlending(true);

	LowerWeapon(false);

	SendMusicLogicEvent(eMUSICLOGICEVENT_WEAPON_MOUNT);

}
Пример #2
0
//------------------------------------------------------------------------
void CVehicleWeapon::StopUse(EntityId userId)
{
	if (m_ownerId && userId != m_ownerId)
		return;

	SendMusicLogicEvent(eMUSICLOGICEVENT_WEAPON_UNMOUNT);
 
  Select(false);  	
  m_stats.used = false;	

  UseManualBlending(false);

  SetOwnerId(0);

  EnableUpdate(false);

	if(IsZoomed() || IsZoomingInOrOut())
	{
		ExitZoom();
	}

	LowerWeapon(false);

}
Пример #3
0
//---------------------------------------------------------------------------
void CVehicleWeapon::CheckForFriendlyAI(float frameTime)
{
	if (m_pVehicle)
	{
		if (CActor* pOwnerActor = GetOwnerActor())
		{
			if (pOwnerActor->IsPlayer() && !gEnv->bMultiplayer)
			{
				m_timeToUpdate -= frameTime;
				if (m_timeToUpdate > 0.f)
					return;

				m_timeToUpdate = 0.15f;

				if (IMovementController* pMC = pOwnerActor->GetMovementController())
				{
					SMovementState info;
					pMC->GetMovementState(info);

					LowerWeapon(false);

					// Try ray hit
					ray_hit rayhit;
					IPhysicalEntity* pSkipEnts[10];
					int nSkip = CSingle::GetSkipEntities(this, pSkipEnts, 10);	

					int intersect = gEnv->pPhysicalWorld->RayWorldIntersection(info.weaponPosition, info.aimDirection * 150.f, ent_all,
						rwi_stop_at_pierceable | rwi_colltype_any, &rayhit, 1, pSkipEnts, nSkip);

					if (intersect && rayhit.pCollider)
					{
						if (IEntity* pLookAtEntity = m_pEntitySystem->GetEntityFromPhysics(rayhit.pCollider))
						{
							if (EntityId lookAtEntityId = pLookAtEntity->GetId())
							{
								IAIObject* pLookAtAIObject = pLookAtEntity->GetAI();
								IEntity* pOwnerEntity = pOwnerActor->GetEntity();

								if (pOwnerEntity && pLookAtAIObject && (lookAtEntityId != GetEntityId()))
								{
									if (IVehicle* pVehicle = gEnv->pGame->GetIGameFramework()->GetIVehicleSystem()->GetVehicle(lookAtEntityId))
									{
										if (pVehicle->HasFriendlyPassenger(pOwnerEntity))
										{
											LowerWeapon(true);
											StopFire();	// Just in case
										}
									}
									else 
									{
										if (pLookAtAIObject->IsFriendly(pOwnerEntity->GetAI(), false))
										{
											LowerWeapon(true);
											StopFire();	// Just in case
										}
									}
								}
								else
								{
									// Special case (Animated objects), check for script table value "bNoFriendlyFire"
									if (IScriptTable* pScriptTable = pLookAtEntity->GetScriptTable())
									{
										SmartScriptTable props;
										if (pScriptTable->GetValue("Properties", props))
										{
											int isFriendly;
											if (props->GetValue("bNoFriendlyFire", isFriendly) && (isFriendly != 0))
											{
												LowerWeapon(true);
												StopFire();	// Just in case
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
}
Пример #4
0
//---------------------------------------------------------------------------
void CVehicleWeapon::CheckForFriendlyAI(float frameTime)
{
	CActor* pOwner = GetOwnerActor();

	if(pOwner && m_pVehicle && pOwner->IsPlayer() && !gEnv->bMultiplayer)
	{
		m_timeToUpdate-=frameTime;
		if(m_timeToUpdate>0.0f)
			return;

		m_timeToUpdate = 0.15f;


		if(IMovementController* pMC = pOwner->GetMovementController())
		{
			SMovementState info;
			pMC->GetMovementState(info);

			LowerWeapon(false);

			//Try with boxes first
			bool success = false;			
			
			//Try ray hit
			if(!success)
			{
				ray_hit rayhit;
				IPhysicalEntity* pSkipEnts[10];
				int nSkip = CSingle::GetSkipEntities(this, pSkipEnts, 10);	

				int intersect = gEnv->pPhysicalWorld->RayWorldIntersection(info.weaponPosition, info.aimDirection * 150.0f, ent_all,
					rwi_stop_at_pierceable|rwi_colltype_any, &rayhit, 1, pSkipEnts, nSkip);

				IEntity* pLookAtEntity = NULL;

				if(intersect && rayhit.pCollider)
					pLookAtEntity = m_pEntitySystem->GetEntityFromPhysics(rayhit.pCollider);

				if(pLookAtEntity && pLookAtEntity->GetAI() && pOwner->GetEntity() && pLookAtEntity->GetId()!=GetEntityId())
				{
					bool bFriendlyVehicle = false;
					if( pLookAtEntity && pLookAtEntity->GetId() )
					{
						IVehicle *pVehicle = gEnv->pGame->GetIGameFramework()->GetIVehicleSystem()->GetVehicle(pLookAtEntity->GetId());
						if ( pVehicle )
						{
							if ( pOwner->GetEntity() && pVehicle->HasFriendlyPassenger( pOwner->GetEntity() ) )
								bFriendlyVehicle = true;
						}				
					}

					if(bFriendlyVehicle||!pLookAtEntity->GetAI()->IsHostile(pOwner->GetEntity()->GetAI(),false))
					{
						LowerWeapon(true);
						StopFire();//Just in case

						success = true;
						m_pLookAtEnemy = NULL;
					}	
				}
				else if(pLookAtEntity)
				{
					//Special case (Animated objects), check for script table value "bFriendly"
					SmartScriptTable props;
					IScriptTable* pScriptTable = pLookAtEntity->GetScriptTable();
					if(!pScriptTable || !pScriptTable->GetValue("Properties", props))
						return;

					int isFriendly = 0;
					if(props->GetValue("bNoFriendlyFire", isFriendly) && isFriendly!=0)
					{
						LowerWeapon(true);
						StopFire();//Just in case

						success = true;
						m_pLookAtEnemy = NULL;
					}
					
				}
				else if(!pLookAtEntity)
					m_pLookAtEnemy = NULL;
			}

		}
	}		
}