//------------------------------------------------------------------------
void CVehicleMountedWeapon::StartUse(EntityId userId)
{
	IVehicle *pVehicle = gEnv->pGame->GetIGameFramework()->GetIVehicleSystem()->GetVehicle(m_vehicleId);
	if (!IsRippingOff() && pVehicle)
	{ 
		m_pOwnerSeat = pVehicle->GetWeaponParentSeat(GetEntityId());
		m_pSeatUser = pVehicle->GetSeatForPassenger(userId);

		IActor* pOwner = GetOwnerActor();
		if (pOwner && !pOwner->IsPlayer())
		{
			SHUDEvent hudEvent(eHUDEvent_AddEntity);
			hudEvent.AddData((int)pVehicle->GetEntityId());
			CHUDEventDispatcher::CallEvent(hudEvent);
		}

		ClearItemFlags(eIF_InformClientsAboutUse);
 	}

	CHeavyMountedWeapon::StartUse(userId);

	CActor* pActor = GetOwnerActor();
	if (pActor && pActor->IsPlayer())
	{
		static_cast<CPlayer*>(pActor)->RefreshVisibilityState();
	}
}
Beispiel #2
0
void CSmokeManager::CreateNewSmokeInstance(EntityId grenadeId, EntityId grenadeOwnerId, float fMaxRadius)
{
    IEntity * pGrenade = gEnv->pEntitySystem->GetEntity(grenadeId);

    int iNewSmokeInstanceIndex = m_numActiveSmokeInstances;

    //If all of the smoke instances are used up, get the index of the next one to be deleted
    //	and re-use that instance
    if(iNewSmokeInstanceIndex >= MAX_SMOKE_INSTANCES)
        {
            float fLeastLifeLeft = kSmokeLingerTime;

            iNewSmokeInstanceIndex = 0;

            for(int i = 0; i < iNewSmokeInstanceIndex; i++)
                {
                    SSmokeInstance& smokeInstance = m_smokeInstances[i];
                    if(smokeInstance.fTimer < fLeastLifeLeft)
                        {
                            iNewSmokeInstanceIndex = i;
                            fLeastLifeLeft=smokeInstance.fTimer;
                        }
                }
        }
    else
        {
            m_numActiveSmokeInstances++;
        }

    //Fill out the smoke instance with the new data
    SSmokeInstance& newSmokeInstance = m_smokeInstances[iNewSmokeInstanceIndex];
    newSmokeInstance.state					= eSIS_Active_PhysicsAwake;
    newSmokeInstance.vPositon				= pGrenade->GetPos();
    newSmokeInstance.grenadeId			= grenadeId;
    newSmokeInstance.fMaxRadius			= fMaxRadius;
    newSmokeInstance.fCurrentRadius = 0.1f;
    newSmokeInstance.fTimer					= 0.0f;

    if (!gEnv->bMultiplayer)
        {
            CreateSmokeObstructionObject(newSmokeInstance);

            if (gEnv->pAISystem)
                {
                    // Associate event with vehicle if the shooter is in a vehicle (tank cannon shot, etc)
                    EntityId ownerId = grenadeId;
                    IActor* pActor = g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(ownerId);
                    IVehicle* pVehicle = pActor ? pActor->GetLinkedVehicle() : NULL;
                    if (pVehicle)
                        {
                            ownerId = pVehicle->GetEntityId();
                        }

                    SAIStimulus stim(AISTIM_GRENADE, AIGRENADE_SMOKE, ownerId, grenadeId, newSmokeInstance.vPositon, ZERO, kMaxSmokeRadius*1.5f);
                    gEnv->pAISystem->RegisterStimulus(stim);
                }
        }
}
void CVehicleWeaponControlled::StartUse(EntityId userId)
{
  Base::StartUse(userId);
  m_CurrentTime = 0.5f;

  IVehicle *pVehicle = gEnv->pGame->GetIGameFramework()->GetIVehicleSystem()->GetVehicle(m_vehicleId);
  if (pVehicle)
  {
	  SHUDEvent hudEvent(eHUDEvent_AddEntity);
	  hudEvent.AddData((int)pVehicle->GetEntityId());
	  CHUDEventDispatcher::CallEvent(hudEvent);
  }
}
Beispiel #4
0
bool CHUDCrosshair::IsFriendlyEntity(IEntity *pEntity)
{
	IActor *pClientActor = g_pGame->GetIGameFramework()->GetClientActor();
	CGameRules *pGameRules = g_pGame->GetGameRules();

	if(!pEntity || !pClientActor || !pGameRules)
		return false;

	// Less than 2 teams means we are in a FFA based game.
	if(pGameRules->GetTeamCount() < 2)
		return false;

	bool bFriendly = false;

	int iClientTeam = pGameRules->GetTeam(pClientActor->GetEntityId());

	// First, check if entity is a player
	IActor *pActor = g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(pEntity->GetId());
	if(pActor && pActor->IsPlayer())
	{
		if(iClientTeam && (pGameRules->GetTeam(pActor->GetEntityId()) == iClientTeam))
		{
			bFriendly = true;
		}
	}
	else
	{
		// Then, check if entity is a vehicle
		IVehicle *pVehicle = gEnv->pGame->GetIGameFramework()->GetIVehicleSystem()->GetVehicle(pEntity->GetId());
		if(pVehicle && pGameRules->GetTeam(pVehicle->GetEntityId()) == iClientTeam && pVehicle->GetStatus().passengerCount)
		{
			IActor *pDriver = pVehicle->GetDriver();
			/*if(pDriver && pGameRules->GetTeam(pDriver->GetEntityId()) == iClientTeam)
				bFriendly = true;
			else
				bFriendly = false;*/

			bFriendly = true;

			//fix for bad raycast
			if(pDriver && pDriver == pClientActor)
				bFriendly = false;
		}
	}

  return bFriendly;
}
Beispiel #5
0
//------------------------------------------------------------------------
void CGameRules::ClientHit(const HitInfo &hitInfo)
{
	FUNCTION_PROFILER(GetISystem(), PROFILE_GAME);

	IActor *pClientActor = g_pGame->GetIGameFramework()->GetClientActor();
	IEntity *pTarget = m_pEntitySystem->GetEntity(hitInfo.targetId);
	IEntity *pShooter =	m_pEntitySystem->GetEntity(hitInfo.shooterId);
	IVehicle *pVehicle = g_pGame->GetIGameFramework()->GetIVehicleSystem()->GetVehicle(hitInfo.targetId);
	IActor *pActor = g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(hitInfo.targetId);
	bool dead = pActor?(pActor->GetHealth()<=0):false;

	if((pClientActor && pClientActor->GetEntity()==pShooter) && pTarget && (pVehicle || pActor) && !dead)
	{
		SAFE_HUD_FUNC(GetCrosshair()->CrosshairHit());
		SAFE_HUD_FUNC(GetTagNames()->AddEnemyTagName(pActor?pActor->GetEntityId():pVehicle->GetEntityId()));
	}

	if(pActor == pClientActor)
		if (gEnv->pInput) gEnv->pInput->ForceFeedbackEvent( SFFOutputEvent(eDI_XI, eFF_Rumble_Basic, 0.5f * hitInfo.damage * 0.01f, hitInfo.damage * 0.02f, 0.0f));

/*	if (gEnv->pAISystem && !gEnv->bMultiplayer)
	{
		static int htMelee = GetHitTypeId("melee");
		if (pShooter && hitInfo.type != htMelee)
		{
			ISurfaceType *pSurfaceType = GetHitMaterial(hitInfo.material);
			const ISurfaceType::SSurfaceTypeAIParams* pParams = pSurfaceType ? pSurfaceType->GetAIParams() : 0;
			const float radius = pParams ? pParams->fImpactRadius : 5.0f;
			gEnv->pAISystem->BulletHitEvent(hitInfo.pos, radius, pShooter->GetAI());
		}
	}*/

	CreateScriptHitInfo(m_scriptHitInfo, hitInfo);
	CallScript(m_clientStateScript, "OnHit", m_scriptHitInfo);

	bool backface = hitInfo.dir.Dot(hitInfo.normal)>0;
	if (!hitInfo.remote && hitInfo.targetId && !backface)
	{
		if (!gEnv->bServer)
			GetGameObject()->InvokeRMI(SvRequestHit(), hitInfo, eRMI_ToServer);
		else
			ServerHit(hitInfo);
	}
}
Beispiel #6
0
//------------------------------------------------------------------------
tSoundID CItem::PlayAction(const ItemString &actionName, int layer, bool loop, uint32 flags, float speedOverride)
{
	if(!m_enableAnimations || !IsOwnerInGame())
		return (tSoundID)-1;

	TActionMap::iterator it = m_sharedparams->actions.find(CONST_TEMPITEM_STRING(actionName));

	if(it == m_sharedparams->actions.end())
	{
//		GameWarning("Action '%s' not found on item '%s'!", actionName, GetEntity()->GetName());

		for(int i=0; i<eIGS_Last; i++)
		{
			m_animationTime[i]=0;
			m_animationSpeed[i]=1.0f;
			m_animationEnd[i]=0;
		}

		return 0;
	}

	bool fp = m_stats.fp;

	if(m_parentId)
	{
		CItem *pParent=static_cast<CItem *>(m_pItemSystem->GetItem(m_parentId));

		if(pParent)
			fp=pParent->GetStats().fp;
	}

	if(flags&eIPAF_ForceFirstPerson)
		fp = true;

	if(flags&eIPAF_ForceThirdPerson)
		fp = false;

	int sid=fp?eIGS_FirstPerson:eIGS_ThirdPerson;
	SAction &action = it->second;

	tSoundID result = INVALID_SOUNDID;

	if((flags&eIPAF_Sound) && !action.sound[sid].name.empty() && IsSoundEnabled() && g_pGameCVars->i_soundeffects)
	{
		int nSoundFlags = FLAG_SOUND_DEFAULT_3D;
		nSoundFlags |= flags&eIPAF_SoundStartPaused?FLAG_SOUND_START_PAUSED:0;
		IEntitySoundProxy *pSoundProxy = GetSoundProxy(true);

		//GetSound proxy from dualwield master if neccesary
		if(IsDualWieldSlave())
		{
			CItem *pMaster = static_cast<CItem *>(GetDualWieldMaster());

			if(pMaster)
			{
				pSoundProxy = pMaster->GetSoundProxy(true);
			}
		}

		EntityId pSkipEnts[3];
		int nSkipEnts = 0;

		// TODO for Marcio :)
		// check code changes

		// Skip the Item
		pSkipEnts[nSkipEnts] = GetEntity()->GetId();
		++nSkipEnts;

		// Skip the Owner
		if(GetOwner())
		{
			pSkipEnts[nSkipEnts] = GetOwner()->GetId();
			++nSkipEnts;
		}

		if(pSoundProxy)
		{

			TempResourceName name;
			FixResourceName(action.sound[sid].name, name, flags);
			//nSoundFlags = nSoundFlags | (fp?FLAG_SOUND_DEFAULT_3D|FLAG_SOUND_RELATIVE:FLAG_SOUND_DEFAULT_3D);
			Vec3 vOffset(0,0,0);

			if(fp)
				vOffset.x = 0.3f; // offset for first person weapon to the front

			if(!g_pGameCVars->i_staticfiresounds)
			{
				result = pSoundProxy->PlaySoundEx(name, vOffset, FORWARD_DIRECTION, nSoundFlags, 1.0f, 0, 0, eSoundSemantic_Weapon, pSkipEnts, nSkipEnts);
				ISound *pSound = pSoundProxy->GetSound(result);

				if(pSound && action.sound[sid].sphere>0.0f)
					pSound->SetSphereSpec(action.sound[sid].sphere);
			}
			else
			{
				SInstanceAudio *pInstanceAudio=0;

				if(action.sound[sid].isstatic)
				{
					TInstanceActionMap::iterator iit = m_instanceActions.find(CONST_TEMPITEM_STRING(actionName));

					if(iit == m_instanceActions.end())
					{
						std::pair<TInstanceActionMap::iterator, bool> insertion=m_instanceActions.insert(TInstanceActionMap::value_type(actionName, SInstanceAction()));
						pInstanceAudio=&insertion.first->second.sound[sid];
					}
					else
						pInstanceAudio=&iit->second.sound[sid];
				}

				if(pInstanceAudio && (pInstanceAudio->id != INVALID_SOUNDID) && (name != pInstanceAudio->static_name))
					ReleaseStaticSound(pInstanceAudio);

				if(!pInstanceAudio || pInstanceAudio->id == INVALID_SOUNDID)
				{
					result = pSoundProxy->PlaySoundEx(name, vOffset, FORWARD_DIRECTION, nSoundFlags, 1.0f, 0, 0, eSoundSemantic_Weapon, pSkipEnts, nSkipEnts);
					ISound *pSound = pSoundProxy->GetSound(result);

					if(pSound && action.sound[sid].sphere>0.0f)
						pSound->SetSphereSpec(action.sound[sid].sphere);
				}

				if(action.sound[sid].isstatic)
				{
					if(pInstanceAudio->id == INVALID_SOUNDID)
					{
						if(pSoundProxy->SetStaticSound(result, true))
						{
							pInstanceAudio->id = result;
							pInstanceAudio->static_name = name;
							pInstanceAudio->synch = action.sound[sid].issynched;
						}
					}
					else
					{
						ISound *pSound = pSoundProxy->GetSound(pInstanceAudio->id);

						if(pSound)
							pSound->Play(1.0, true, true, pSoundProxy);
					}
				}
			}

			if(gEnv->pAISystem && action.sound[sid].airadius > 0.0f)
			{
				EntityId ownerId = GetOwner() ? GetOwner()->GetId() : 0;

				// associate sound event with vehicle if the shooter is in a vehicle (tank cannon shot, etc)
				if(CActor *pOwnerActor = GetOwnerActor())
				{
					IVehicle *pOwnerVehicle = pOwnerActor->GetLinkedVehicle();

					if(pOwnerVehicle && pOwnerVehicle->GetEntityId())
						ownerId = pOwnerVehicle->GetEntityId();
				}

				SAIStimulus stim(AISTIM_SOUND, AISOUND_WEAPON, ownerId?ownerId:GetEntityId() , 0,
								 GetEntity()->GetWorldPos(), ZERO, action.sound[sid].airadius);

				gEnv->pAISystem->RegisterStimulus(stim);
			}
		}
	}


	if(flags&eIPAF_Animation)
	{
		TempResourceName name;
		// generate random number only once per call to allow animations to
		// match across geometry slots (like first person and third person)
		float randomNumber = Random();

		for(int i=0; i<eIGS_Last; i++)
		{
			if(!(flags&(1<<i)))
				continue;

			int nanimations=action.animation[i].size();

			if(nanimations <= 0)
				continue;

			int anim = int(randomNumber * float(nanimations));

			if(action.animation[i][anim].name.empty())
				continue;

			FixResourceName(action.animation[i][anim].name, name, flags);

			if((i == eIGS_Owner) || (i == eIGS_OwnerLooped))
			{
				if(!action.animation[i][anim].name.empty())
				{
					bool looping=(eIGS_OwnerLooped==i);

					CActor *pOwner = GetOwnerActor();

					if(pOwner)
					{
						if(IsDualWield() && !m_sharedparams->params.dual_wield_pose.empty())
							pOwner->PlayAction(name, m_sharedparams->params.dual_wield_pose.c_str(), looping);
						else
							pOwner->PlayAction(name, m_sharedparams->params.pose.c_str(), looping);
					}
				}

				continue;
			}
			else if(i == eIGS_OffHand)
			{
				if(!action.animation[eIGS_OffHand][anim].name.empty())
				{
					CActor *pOwner = GetOwnerActor();

					if(pOwner)
					{
						CItem *pOffHand = pOwner->GetItemByClass(CItem::sOffHandClass);

						if(pOffHand && pOffHand!=this)
						{
							uint32 ohflags=eIPAF_Default;

							if(action.animation[eIGS_OffHand][anim].blend==0.0f)
								ohflags|=eIPAF_NoBlend;

							pOffHand->PlayAction(action.animation[eIGS_OffHand][anim].name, 0, false, ohflags);
						}
					}
				}

				continue;
			}

			SAnimation &animation=action.animation[i][anim];

			if(!animation.name.empty())
			{
				float blend = animation.blend;

				if(flags&eIPAF_NoBlend)
					blend = 0.0f;

				if(speedOverride > 0.0f)
					PlayAnimationEx(name, i, layer, loop, blend, speedOverride, flags);
				else
					PlayAnimationEx(name, i, layer, loop, blend, animation.speed, flags);
			}

			if((m_stats.fp || m_stats.viewmode&eIVM_FirstPerson) && i==eIGS_FirstPerson && !animation.camera_helper.empty())
			{
				m_camerastats.animating=true;
				m_camerastats.helper=animation.camera_helper;
				m_camerastats.position=animation.camera_pos;
				m_camerastats.rotation=animation.camera_rot;
				m_camerastats.follow=animation.camera_follow;
				m_camerastats.reorient=animation.camera_reorient;
			}
			else if(m_camerastats.animating)
				m_camerastats=SCameraAnimationStats();
		}
	}

	if(flags&eIPAF_Effect && !action.effect[sid].name.empty())
	{
		// change this to attach, if needed
		SpawnEffect(sid, action.effect[sid].name.c_str(), action.effect[sid].helper.c_str());
	}

	if(action.children)
	{
		for(TAccessoryMap::iterator ait=m_accessories.begin(); ait!=m_accessories.end(); ait++)
		{
			EntityId aId=(EntityId)ait->second;
			CItem *pAccessory=static_cast<CItem *>(m_pItemSystem->GetItem(aId));

			if(pAccessory)
				pAccessory->PlayAction(actionName, layer, loop, flags, speedOverride);
		}
	}

	return result;
}