示例#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 CGunTurret::PostInit(IGameObject *pGameObject)
{
	CItem::PostInit(pGameObject);

	if(gEnv->bServer)
		UpdateEntityProperties();

	SetOwnerId(GetEntityId());

	if(!gEnv->bServer)
		for(int i=0; i<4; i++)
			pGameObject->SetUpdateSlotEnableCondition(this, i, eUEC_InRange);
}
示例#3
0
//------------------------------------------------------------------------
void CVehicleWeapon::StartUse(EntityId userId)
{
	if (m_owner.GetId() && userId != m_owner.GetId())
		return; 

  if (GetEntity()->GetParent())
  { 
		const EntityId vehicleId = GetEntity()->GetParent()->GetId();
		m_vehicleId = vehicleId;
    IVehicle* pVehicle = gEnv->pGame->GetIGameFramework()->GetIVehicleSystem()->GetVehicle(vehicleId);
    assert(pVehicle && "Using VehicleWeapons on non-vehicles may lead to unexpected behavior.");

    if (pVehicle)
    {
      IVehicleSeat* pOwnerSeat = pVehicle->GetWeaponParentSeat(GetEntityId());
      IVehicleSeat* pSeatUser = pVehicle->GetSeatForPassenger(userId);
			m_bOwnerInSeat = (pOwnerSeat == pSeatUser);

			if(userId == g_pGame->GetIGameFramework()->GetClientActorId())
			{
				pVehicle->RegisterVehicleEventListener(this, "CVehicleWeapon");
			}
    }
  }
  
	SetOwnerId(userId);
  Select(true);	
	m_stats.used = true;

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

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

  m_shootCounter = 0;
	
	if(userId == g_pGame->GetIGameFramework()->GetClientActorId())
	{
		SHUDEvent	event;

		event.eventType			= eHUDEvent_OnItemSelected;
		event.eventIntData	= CItem::GetEntityId();

		CHUDEventDispatcher::CallEvent(event);

		SHUDEventWrapper::FireModeChanged(this, m_firemode);
	}
}
void CVehicleWeaponControlled::StopUse(EntityId userId)
{
   EntityId id = GetOwnerId();

   Base::StopUse(userId);

   SetOwnerId(id);
   m_CurrentTime = 0.5f;

   IVehicle *pVehicle = gEnv->pGame->GetIGameFramework()->GetIVehicleSystem()->GetVehicle(m_vehicleId);
   if (pVehicle)
   {
	   SHUDEvent hudEvent(eHUDEvent_RemoveEntity);
	   hudEvent.AddData((int)pVehicle->GetEntityId());
	   CHUDEventDispatcher::CallEvent(hudEvent);
   }
}
示例#5
0
//------------------------------------------------------------------------
void CVehicleWeapon::StopUse(EntityId userId)
{
	if (m_owner.GetId() && userId != m_owner.GetId())
		return;

	if(userId == g_pGame->GetIGameFramework()->GetClientActorId())
	{
		IVehicle* pVehicle = GetVehicle();
		if(pVehicle)
		{
			pVehicle->UnregisterVehicleEventListener(this);
		}
		AudioCache(true, true);	//change cache to third person if it's not available
	}
 
  Select(false);  	
  m_stats.used = false;	

  SetOwnerId(0);

  EnableUpdate(false);

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

	 m_shootCounter = 0;

	 if (userId == g_pGame->GetIGameFramework()->GetClientActorId())
	 {
		 SHUDEvent event;
		 event.eventType = eHUDEvent_OnItemSelected;
		 event.eventIntData = 0;

		 CHUDEventDispatcher::CallEvent(event);
	 }
}
示例#6
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);

}
示例#7
0
void CAIGrenade::Reset()
{
	CWeapon::Reset();

	SetOwnerId(0);
}
示例#8
0
//------------------------------------------------------------------------
void CAmmoPickup::PickUp(EntityId pickerId, bool sound, bool select, bool keepHistory)
{
	if(!CheckAmmoRestrictions(pickerId))
		return;

	SetOwnerId(pickerId);

	CActor *pActor=GetActor(pickerId);

	if (!pActor)
		return;

	IInventory *pInventory = GetActorInventory(pActor);
	if (!pInventory)
		return;

	if (IsServer())
	{
		// bonus ammo is always put in the actor's inv
		if (!m_bonusammo.empty())
		{
			for (TAmmoMap::iterator it=m_bonusammo.begin(); it!=m_bonusammo.end(); ++it)
			{
				int count=it->second;

				SetInventoryAmmoCount(it->first, GetInventoryAmmoCount(it->first)+count);

				if(pActor->IsPlayer())
				{
					ShouldSwitchGrenade(it->first);
					OnIncendiaryAmmoPickedUp(it->first,count);
				}
			}

			m_bonusammo.clear();
		}

		for (TAmmoMap::iterator it=m_ammo.begin(); it!=m_ammo.end(); ++it)
		{
			int count=it->second;

			SetInventoryAmmoCount(it->first, GetInventoryAmmoCount(it->first)+count);

			if(pActor->IsPlayer())
			{
				ShouldSwitchGrenade(it->first);
				OnIncendiaryAmmoPickedUp(it->first,count);
			}
		}

		if (!m_ammoName.empty() && m_ammoCount)
		{
			IEntityClass* pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(m_ammoName.c_str());
			SetInventoryAmmoCount(pClass, GetInventoryAmmoCount(pClass)+m_ammoCount);

			if(pActor->IsPlayer())
			{
				ShouldSwitchGrenade(pClass);
				OnIncendiaryAmmoPickedUp(pClass,m_ammoCount);
			}
		}

		TriggerRespawn();
	}

	//Play sound
	if(!m_pickup_sound.empty())
	{
		IEntity *pPicker = m_pEntitySystem->GetEntity(pickerId);
		if(pPicker)
		{
			IEntitySoundProxy* pSoundProxy = (IEntitySoundProxy*)pPicker->GetProxy(ENTITY_PROXY_SOUND);

			if(pSoundProxy)
			{
				//Execute sound at picker position
				pSoundProxy->PlaySound(m_pickup_sound, pPicker->GetWorldPos(),FORWARD_DIRECTION, FLAG_SOUND_DEFAULT_3D, eSoundSemantic_Weapon);
			}
		}
	}

	RemoveEntity();
}
示例#9
0
void CAccessory::PickUp(EntityId pickerId, bool sound, bool select/* =true */, bool keepHistory/* =true */, const char *setup /*= NULL*/)
{
    CActor *pActor=GetActor(pickerId);
    if (!pActor)
        return;

    TriggerRespawn();

    GetEntity()->EnablePhysics(false);
    Physicalize(false, false);

    bool soundEnabled = IsSoundEnabled();
    EnableSound(sound);

    SetViewMode(0);
    SetOwnerId(pickerId);

    CopyRenderFlags(GetOwner());

    Hide(true);
    m_stats.dropped = false;
    m_stats.detached = false;
    m_stats.brandnew = false;


    IInventory *pInventory = pActor->GetInventory();
    if (!pInventory)
        {
            GameWarning("Actor '%s' has no inventory, when trying to pickup '%s'!",pActor->GetEntity()->GetName(),GetEntity()->GetName());
            return;
        }

    if (!pActor->IsPlayer() || pActor->IsClient() || gEnv->bMultiplayer)
        {
            bool hasAccessory = pInventory->HasAccessory(GetEntity()->GetClass());
            bool hasAccessoryForThisWeapon = pInventory->HasAccessory(GetEntity()->GetClass());

            if (!hasAccessoryForThisWeapon)
                pInventory->AddAccessory(GetEntity()->GetClass());
            if (!hasAccessory)
                ProcessAccessoryAmmoCapacities(pInventory, true);
            if (!hasAccessoryForThisWeapon)
                ProcessAccessoryAmmo(pInventory);
        }

    OnPickedUp(pickerId, m_sharedparams->params.unique);

    if (select)
        {
            PlayAction(GetFragmentIds().pickedup);
        }

    EnableSound(soundEnabled);

    bool isLocalEntity = GetEntity()->GetFlags()&(ENTITY_FLAG_CLIENT_ONLY|ENTITY_FLAG_SERVER_ONLY) ? true : false;

    if (IsServer() && !IsDemoPlayback())
        {
            if(!gEnv->bMultiplayer || isLocalEntity)
                RemoveEntity();
            else if(g_pGame->GetGameRules())
                g_pGame->GetGameRules()->ScheduleEntityRemoval(GetEntityId(),10.0f,false); //Give some time to the clients to pick the msg
        }

    if (IsServer())
        {
            GetGameObject()->SetNetworkParent(pickerId);
            if (!isLocalEntity)
                {
                    pActor->GetGameObject()->InvokeRMIWithDependentObject(CActor::ClPickUp(), CActor::PickItemParams(GetEntityId(), m_stats.selected, sound), eRMI_ToAllClients|eRMI_NoLocalCalls, GetEntityId());
                }
        }
}
示例#10
0
void CAccessory::PickUp(EntityId pickerId, bool sound, bool select, bool keepHistory, const char *setup)
{
	CActor *pActor=GetActor(pickerId);
	if (!pActor)
		return;

	if(!CheckAmmoRestrictions(pickerId))
	{
		if (IsServer())
			g_pGame->GetGameRules()->SendTextMessage(eTextMessageCenter, "@ammo_maxed_out", eRMI_ToClientChannel, pActor->GetChannelId(), (string("@")+GetEntity()->GetClass()->GetName()).c_str());
		return;
	}

	TriggerRespawn();

	GetEntity()->EnablePhysics(false);
	Physicalize(false, false);

	bool soundEnabled = IsSoundEnabled();
	EnableSound(sound);

	SetViewMode(0);		
	SetOwnerId(pickerId);

	CopyRenderFlags(GetOwner());

	Hide(true);
	m_stats.dropped = false;
	m_stats.brandnew = false;


	IInventory *pInventory = pActor->GetInventory();
	if (!pInventory)
	{
		GameWarning("Actor '%s' has no inventory, when trying to pickup '%s'!",pActor->GetEntity()->GetName(),GetEntity()->GetName());
		return;
	}

	if(!pInventory->HasAccessory(GetEntity()->GetClass()))
	{
		pInventory->AddAccessory(GetEntity()->GetClass());
	}

	OnPickedUp(pickerId, m_sharedparams->params.unique);	

	PlayAction(g_pItemStrings->pickedup);

	EnableSound(soundEnabled);

	if (IsServer() && !IsDemoPlayback())
	{
		if(!gEnv->bMultiplayer)
			RemoveEntity();
		else if(g_pGame->GetGameRules())
			g_pGame->GetGameRules()->ScheduleEntityRemoval(GetEntityId(),10.0f,false); //Give some time to the clients to pick the msg
	}

	if (IsServer())
	{
		GetGameObject()->SetNetworkParent(pickerId);
		if ((GetEntity()->GetFlags()&(ENTITY_FLAG_CLIENT_ONLY|ENTITY_FLAG_SERVER_ONLY)) == 0)
		{
			pActor->GetGameObject()->InvokeRMIWithDependentObject(CActor::ClPickUp(), CActor::PickItemParams(GetEntityId(), m_stats.selected, sound), eRMI_ToAllClients|eRMI_NoLocalCalls, GetEntityId());

			const char *displayName=GetDisplayName();
}
	}
}
void CVehicleWeaponControlled::Update(SEntityUpdateContext& ctx, int update)
{
	IVehicle *pVehicle = m_vehicleId ? gEnv->pGame->GetIGameFramework()->GetIVehicleSystem()->GetVehicle(m_vehicleId) : NULL; 
  if (!m_vehicleId && GetEntity()->GetParent())
  {
    IEntity *entity = GetEntity();
    
    if (entity)
    {
      IEntity *parent = entity->GetParent();
      if (parent)
      {
				m_vehicleId = parent->GetId();
        pVehicle = gEnv->pGame->GetIGameFramework()->GetIVehicleSystem()->GetVehicle(parent->GetId());
      }
    }
  }



  if (pVehicle)
  {
		IVehiclePart *pPart = pVehicle->GetWeaponParentPart(GetEntityId());
		if(pPart)
		{
			if(IVehiclePart *pParentPart = pPart->GetParent())
			{
				CRY_ASSERT(pVehicle->GetEntity());

				if(ICharacterInstance *characterInst = pVehicle->GetEntity()->GetCharacter(pParentPart->GetSlot()))
				{
					if(ISkeletonPose* pose = characterInst->GetISkeletonPose())
					{
						IDefaultSkeleton& rIDefaultSkeleton = characterInst->GetIDefaultSkeleton();
						int16 joint = rIDefaultSkeleton.GetJointIDByName(pPart->GetName());
						const QuatT &jQuat = pose->GetAbsJointByID(joint);

						Matrix34 localT(jQuat);
						localT.SetTranslation(jQuat.t/* - Vec3(0.0f, 0.75f, 0.0f)*/);

						Matrix34 vehicleWorldTm = pVehicle->GetEntity()->GetWorldTM();
						Matrix34 mat = vehicleWorldTm * localT;
						Vec3 vehicleSide2 = pPart->GetParent()->GetLocalTM(true, true).GetTranslation();

						CPlayer *pl = this->GetOwnerPlayer();

						Matrix33 mat2;
						if (!m_destination.IsEquivalent(ZERO))
						{
							Vec3 diff = GetDestination() - mat.GetTranslation(); //pPart->GetWorldTM().GetTranslation();
							diff.Normalize();

							Matrix33 loc(mat);
							loc.Invert();

							Vec3 diffLocal = loc.TransformVector(diff);

							Matrix33 desMat;
							desMat.SetRotationVDir(diffLocal, 0.0f);

							Vec3 test = GetEntity()->GetLocalTM().GetColumn0();

							Ang3 testTM(desMat);

							float za = testTM.x - m_Angles.x;
							za = (za < 0.0f) ? -gf_PI : gf_PI;
							za *= 0.05f * ctx.fFrameTime;

							m_Angles.x += za;
							Limit(m_Angles.x, -gf_PI * 0.33f, gf_PI * 0.33f);

							if (testTM.z > m_Angles.z + 0.05f)
							{
								m_Angles.z += gf_PI * factor1 * ctx.fFrameTime;        
							}
							else if (testTM.z < m_Angles.z - 0.05f)
							{
								m_Angles.z -= gf_PI * factor1 * ctx.fFrameTime;        
							}
							else
							{
								m_Angles.z = testTM.z;
							}

							Limit(m_Angles.z, -gf_PI * 0.33f, gf_PI * 0.33f);
							mat2.SetRotationXYZ(m_Angles);
						}
						else
						{
							if (!m_FireBlocked)
							{
								m_Angles.x = m_Angles.x - ctx.fFrameTime * factor2 * m_Angles.x;
								m_Angles.z = m_Angles.z - ctx.fFrameTime * factor2 * m_Angles.z;
							}
							mat2.SetRotationXYZ(m_Angles);
						}

						mat = mat * mat2; 


						GetEntity()->SetWorldTM(mat);


						if (pl)
						{
							Matrix34 worldGunMat = vehicleWorldTm * localT;

							if (!pl->IsDead())
							{

								Vec3 trans = worldGunMat.GetTranslation() - worldGunMat.GetColumn2() * 0.7f;
								worldGunMat.SetTranslation(trans);

								pl->GetEntity()->SetWorldTM(worldGunMat);


								float dot = mat.GetColumn1().dot(worldGunMat.GetColumn0());
								Update3PAnim(pl, 0.5f - dot * 0.5f, ctx.fFrameTime, mat);
							}
							else
							{

								ICharacterInstance* pCharacter = pl->GetEntity()->GetCharacter(0);
								int boneId = pCharacter ? pCharacter->GetIDefaultSkeleton().GetJointIDByName("Spine03") : 7;

								pl->LinkToMountedWeapon(0);
								if (IVehicleSeat* seat = pVehicle->GetSeatForPassenger(pl->GetEntityId()))
								{
									seat->Exit(false, true);
								}

								Matrix33 rot(worldGunMat);
								Vec3 offset(0.0f, 0.0f, 0.70f);
								Vec3 transformedOff = rot.TransformVector(offset);
								Vec3 trans = worldGunMat.GetTranslation();
								trans -= transformedOff;
								worldGunMat.SetTranslation(trans);
								pl->GetEntity()->SetWorldTM(worldGunMat);
								pl->GetEntity()->SetPos(worldGunMat.GetTranslation()); //worldGunMat.GetTranslation());
								pl->RagDollize(true);

								if (boneId > -1)
								{
									IPhysicalEntity *physEnt = pl->GetEntity()->GetPhysics();
									if (physEnt)
									{
										pe_simulation_params simulationParams;
										physEnt->GetParams(&simulationParams);

										pe_params_pos pos;
										pos.pos = GetEntity()->GetPos();
										physEnt->SetParams(&pos);

										pe_action_impulse impulse;
										impulse.ipart = boneId;
										impulse.angImpulse = Vec3(0.0f, 0.0f, 1.0f);
										impulse.impulse = worldGunMat.GetColumn1() * -1.5f * simulationParams.mass;
										physEnt->Action(&impulse);
									}
								}

								StopUse(GetOwnerId());

								SetOwnerId(0);
								StopFire();

								m_FireBlocked = true;
							} // IsDead
						} // pl
					} // pose
				} // characterInst
			} // pParentPart
		} // pPart
	} // pVehicle

  Base::Update(ctx, update);
  RequireUpdate(eIUS_General);
}
示例#12
0
void CHeavyWeapon::StartUse(EntityId userId)
{
    // holster user item here
    SetOwnerId(userId);

    CActor* pOwner = GetOwnerActor();
    if (!pOwner)
        return;

    HighlightWeapon(false);
    Physicalize(false, false);

    if(gEnv->bMultiplayer)
        {
            m_properties.usable &= strlen(g_pGameCVars->g_forceHeavyWeapon->GetString()) == 0;

            CHANGED_NETWORK_STATE(pOwner, CPlayer::ASPECT_CURRENT_ITEM);
        }

    if(IItem* pCurrentItem = pOwner->GetCurrentItem())
        {
            //Don't keep history if we're switching from Pick & Throw otherwsie we'll switch back to it when we're done with the heavy weapon
            static IEntityClass* pPickAndThrowWeaponClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass("PickAndThrowWeapon");
            m_pItemSystem->SetActorItem(pOwner, GetEntityId(), pCurrentItem->GetEntity()->GetClass() != pPickAndThrowWeaponClass);
        }
    else
        {
            m_pItemSystem->SetActorItem(pOwner, GetEntityId(), true);
        }

    TriggerRespawn();

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

    RegisterAsUser();

    HandleHeavyWeaponPro(*pOwner);

    m_stats.brandnew = false;
    m_stats.used = true;
    m_stats.detached = false;

    if(IsClient() && gEnv->pGame->GetIGameFramework()->GetClientActorId()==userId)
        {
            if(IEntity* pEntity = GetEntity())
                {
                    const char* collectibleId = pEntity->GetClass()->GetName();
                    CPersistantStats* pStats = g_pGame->GetPersistantStats();
                    if(pStats && pStats->GetStat(collectibleId, EMPS_SPWeaponByName) == 0)
                        {
                            pStats->SetMapStat(EMPS_SPWeaponByName, collectibleId, eDatabaseStatValueFlag_Available);

                            if(!gEnv->bMultiplayer)
                                {
                                    // Show hud unlock msg
                                    SHUDEventWrapper::DisplayWeaponUnlockMsg(collectibleId);
                                }
                        }
                }
        }

    if (IsServer())
        {
            pOwner->GetGameObject()->InvokeRMIWithDependentObject(CActor::ClStartUse(), CActor::ItemIdParam(GetEntityId()), eRMI_ToAllClients|eRMI_NoLocalCalls, GetEntityId());
            g_pGame->GetGameRules()->AbortEntityRemoval(GetEntityId());
        }

    OnStartUsing();
}