//----------------------------------------------------- void CThrow::ThrowObject(IEntity* pEntity, IPhysicalEntity* pPE) { bool strengthMode = false; CPlayer *pPlayer = static_cast<CPlayer*>(m_pWeapon->GetOwnerActor()); if (pPlayer) { // Report throw to AI system. if (pPlayer->GetEntity() && pPlayer->GetEntity()->GetAI()) { SAIEVENT AIevent; AIevent.targetId = pEntity->GetId(); pPlayer->GetEntity()->GetAI()->Event(AIEVENT_PLAYER_THROW, &AIevent); } } Vec3 hit = GetProbableHit(WEAPON_HIT_RANGE); Vec3 pos = GetFiringPos(hit); Vec3 dir = ApplySpread(GetFiringDir(hit, pos), GetSpread()); Vec3 vel = GetFiringVelocity(dir); float speed = 12.0f; if(strengthMode) speed *= m_pShared->throwparams.strenght_scale; speed = max(2.0f, speed); pe_params_pos ppos; ppos.pos = pEntity->GetWorldPos(); pPE->SetParams(&ppos); if(CheckForIntersections(pPE,dir)) { Matrix34 newTM = pEntity->GetWorldTM(); newTM.SetTranslation(newTM.GetTranslation()-(dir*0.4f)); pEntity->SetWorldTM(newTM,ENTITY_XFORM_POS); } else { pe_action_set_velocity asv; asv.v = (dir*speed)+vel; AABB box; pEntity->GetWorldBounds(box); Vec3 finalW = -gEnv->pSystem->GetViewCamera().GetMatrix().GetColumn0()*(8.0f/max(0.1f,box.GetRadius())); finalW.x *= Random(0.5f,1.3f); finalW.y *= Random(0.5f,1.3f); finalW.z *= Random(0.5f,1.3f); asv.w = finalW; //asv.w = Vec3(Random(-4.5f,3.5f),Random(-1.75f,2.5f),Random(-1.5f,2.2f)); pPE->Action(&asv); } SEntityEvent entityEvent; entityEvent.event = ENTITY_EVENT_PICKUP; entityEvent.nParam[0] = 0; if (pPlayer) entityEvent.nParam[1] = pPlayer->GetEntityId(); entityEvent.fParam[0] = speed; pEntity->SendEvent( entityEvent ); }
//----------------------------------------------------- void CThrow::ThrowLivingEntity(IEntity* pEntity, IPhysicalEntity* pPE) { Vec3 hit = GetProbableHit(WEAPON_HIT_RANGE); Vec3 pos = GetFiringPos(hit); Vec3 dir = ApplySpread(GetFiringDir(hit, pos), GetSpread()); Vec3 vel = GetFiringVelocity(dir); CPlayer *pPlayer = static_cast<CPlayer*>(m_pWeapon->GetOwnerActor()); if(pPlayer) { float speed = 8.0f; dir.Normalize(); if(CheckForIntersections(pPE,dir)) { Matrix34 newTM = pEntity->GetWorldTM(); newTM.SetTranslation(newTM.GetTranslation()-(dir*0.6f)); pEntity->SetWorldTM(newTM,ENTITY_XFORM_POS); } { pe_action_set_velocity asv; asv.v = (dir*speed)+vel; pPE->Action(&asv); // [anton] use thread safe=1 (immediate) if the character is still a living entity at this stage, // but will be ragdollized during the same frame pe_params_articulated_body pab; pab.bCheckCollisions = 1; // was set to 0 while carrying pPE->SetParams(&pab); } // Report throw to AI system. if (pPlayer->GetEntity() && pPlayer->GetEntity()->GetAI()) { SAIEVENT AIevent; AIevent.targetId = pEntity->GetId(); pPlayer->GetEntity()->GetAI()->Event(AIEVENT_PLAYER_STUNT_THROW_NPC, &AIevent); } } }
//-------------------------------------- void CThrow::DoDrop() { m_pWeapon->HideItem(true); if (m_throwableId) { IEntity *pEntity = gEnv->pEntitySystem->GetEntity(m_throwableId); if (pEntity) { IPhysicalEntity *pPE = pEntity->GetPhysics(); if (pPE && (pPE->GetType() == PE_RIGID || pPE->GetType() == PE_PARTICLE)) { Vec3 hit = GetProbableHit(WEAPON_HIT_RANGE); Vec3 pos = GetFiringPos(hit); CActor *pActor = m_pWeapon->GetOwnerActor(); IMovementController *pMC = pActor ? pActor->GetMovementController() : 0; if (pMC) { SMovementState info; pMC->GetMovementState(info); float speed = 2.5f; CPlayer *pPlayer = static_cast<CPlayer *>(m_pWeapon->GetOwnerActor()); if(info.aimDirection.z < -0.1f) { if(pPlayer) { if(SPlayerStats *pStats = static_cast<SPlayerStats *>(pPlayer->GetActorStats())) { if(pStats->grabbedHeavyEntity) { speed = 4.0f; } } } } if(CheckForIntersections(pPE, info.eyeDirection)) { Matrix34 newTM = pEntity->GetWorldTM(); newTM.SetTranslation(newTM.GetTranslation() - (info.eyeDirection * 0.4f)); pEntity->SetWorldTM(newTM, ENTITY_XFORM_POS); pe_action_set_velocity asv; asv.v = (-info.eyeDirection * speed); pPE->Action(&asv); } else { pe_action_set_velocity asv; asv.v = (info.eyeDirection * speed); pPE->Action(&asv); } SEntityEvent entityEvent; entityEvent.event = ENTITY_EVENT_PICKUP; entityEvent.nParam[0] = 0; if (pPlayer) { entityEvent.nParam[1] = pPlayer->GetEntityId(); } entityEvent.fParam[0] = speed; pEntity->SendEvent( entityEvent ); } } } if (m_throwableAction) { m_throwableAction->execute(m_pWeapon); } } }