本文整理汇总了C++中IActor::GetLinkedVehicle方法的典型用法代码示例。如果您正苦于以下问题:C++ IActor::GetLinkedVehicle方法的具体用法?C++ IActor::GetLinkedVehicle怎么用?C++ IActor::GetLinkedVehicle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IActor
的用法示例。
在下文中一共展示了IActor::GetLinkedVehicle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FlashbangEffect
void CProjectile::FlashbangEffect(const SFlashbangParams *flashbang)
{
if(!flashbang)
return;
const float radius = flashbang->maxRadius;
if(!gEnv->pAISystem)
return;
// Associate event with vehicle if the shooter is in a vehicle (tank cannon shot, etc)
EntityId ownerId = m_ownerId;
IActor *pActor = g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(ownerId);
if(pActor && pActor->GetLinkedVehicle() && pActor->GetLinkedVehicle()->GetEntityId())
ownerId = pActor->GetLinkedVehicle()->GetEntityId();
SAIStimulus stim(AISTIM_GRENADE, AIGRENADE_FLASH_BANG, ownerId, GetEntityId(),
GetEntity()->GetWorldPos(), ZERO, radius);
gEnv->pAISystem->RegisterStimulus(stim);
SAIStimulus stimSound(AISTIM_SOUND, AISOUND_WEAPON, ownerId, 0,
GetEntity()->GetWorldPos(), ZERO, radius * 3.0f);
gEnv->pAISystem->RegisterStimulus(stimSound);
}
示例2: CreateNewSmokeInstance
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);
}
}
}
示例3: ProcessEvent
void CClaymore::ProcessEvent(SEntityEvent &event)
{
if (m_frozen)
return;
switch(event.event)
{
case ENTITY_EVENT_ENTERAREA:
{
IEntity * pEntity = gEnv->pEntitySystem->GetEntity(event.nParam[0]);
IVehicle* pVehicle = NULL;
IActor* pActor = g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(event.nParam[0]); // only detonate for actors...
if(!pActor)
pVehicle = g_pGame->GetIGameFramework()->GetIVehicleSystem()->GetVehicle(event.nParam[0]); // ...or vehicles
// ignore actors in vehicles (we detect the vehicle instead)
if(pActor && pActor->GetLinkedVehicle())
pActor = NULL;
// ignore spectators
if(pActor && static_cast<CActor*>(pActor)->GetSpectatorMode() != CActor::eASM_None)
pActor = NULL;
if(pEntity && (pActor || pVehicle))
{
if(g_pGameCVars->g_debugMines != 0)
CryLog("Claymore detected entity: %d, type %s", pEntity->GetId(), pActor == NULL ? "Vehicle" : "Actor");
m_targetList.push_back(pEntity->GetId());
}
break;
}
case ENTITY_EVENT_LEAVEAREA:
{
IEntity * pEntity = gEnv->pEntitySystem->GetEntity(event.nParam[0]);
if(pEntity)
{
std::list<EntityId>::iterator it = std::find(m_targetList.begin(), m_targetList.end(), pEntity->GetId());
if(it != m_targetList.end())
m_targetList.erase(it);
}
break;
}
default:
break;
}
return CProjectile::ProcessEvent(event);
}
示例4: ProcessEvent
//------------------------------------------------------------------------
void CFlowVehiclePassenger::ProcessEvent(EFlowEvent flowEvent, SActivationInfo* pActivationInfo)
{
CFlowVehicleBase::ProcessEvent(flowEvent, pActivationInfo);
if (flowEvent == eFE_Activate)
{
m_actorId = GetPortEntityId(pActivationInfo, IN_ACTORID);
m_seatId = GetPortInt(pActivationInfo, IN_SEATID);
if (IVehicle* pVehicle = GetVehicle())
{
if (IsPortActive(pActivationInfo, IN_TRIGGERPASSENGERIN))
{
if (m_actorId && m_seatId > 0)
{
IActor* pActor = gEnv->pGame->GetIGameFramework()->GetIActorSystem()->GetActor(m_actorId);
if (pActor)
{
IVehicle* pCurrent = pActor->GetLinkedVehicle();
if (pCurrent && pCurrent != pVehicle)
{
if (IVehicleSeat* pSeat = pCurrent->GetSeatForPassenger(m_actorId))
pSeat->Exit(false, true);
}
if (pCurrent == pVehicle && pCurrent->GetSeatForPassenger(m_actorId))
{
((CVehicle*)pVehicle)->ChangeSeat(m_actorId, 0, m_seatId);
}
else
{
if (IVehicleSeat* pSeat = pVehicle->GetSeatById(m_seatId))
pSeat->Enter(m_actorId);
}
}
}
}
if (IsPortActive(pActivationInfo, IN_TRIGGERPASSENGEROUT))
{
if (m_actorId)
{
if (IVehicleSeat* pSeat = pVehicle->GetSeatForPassenger(m_actorId))
pSeat->Exit(true);
}
}
}
}
}
示例5: UpdateLight
//-----------------------------------------------------------------------
void CVehiclePartLight::UpdateLight(const float frameTime)
{
if (m_slot == -1)
return;
// move to vehicle event change view?
if (m_diffuseMult[0] != m_diffuseMult[1])
{
SEntitySlotInfo info;
if (m_pVehicle->GetEntity()->GetSlotInfo(m_slot, info) && info.pLight)
{
CDLight& light = info.pLight->GetLightProperties();
IActor* pActor = CCryAction::GetCryAction()->GetClientActor();
bool localPlayer = (pActor != NULL) && (pActor->GetLinkedVehicle() == m_pVehicle);
IVehicleSeat* pSeat = pActor ? m_pVehicle->GetSeatForPassenger(pActor->GetEntityId()) : NULL;
IVehicleView* pView = pSeat? pSeat->GetView(pSeat->GetCurrentView()) : NULL;
bool isThirdPersonView = pView? pView->IsThirdPerson() : true;
if (localPlayer && !isThirdPersonView)
light.SetLightColor(ColorF(m_diffuseCol * m_diffuseMult[0], 1.f));
else
light.SetLightColor(ColorF(m_diffuseCol * m_diffuseMult[1], 1.f));
}
}
if (m_pHelper)
{
const static Matrix33 rot(Matrix33::CreateRotationXYZ(Ang3(0.f, 0.f, DEG2RAD(90.f))));
Matrix34 helperTM;
m_pHelper->GetVehicleTM(helperTM);
Matrix34 localTM = Matrix33(helperTM) * rot;
localTM.SetTranslation(helperTM.GetTranslation());
GetEntity()->SetSlotLocalTM(m_slot, localTM);
}
}
示例6: GetView
//----------------------------------------------------------------------
IView* GetView( SActivationInfo* pActInfo )
{
SInputParams inputParams;
ReadCurrentInputParams( pActInfo, inputParams );
IGameFramework* pGF = gEnv->pGame->GetIGameFramework();
IView* pView = 0;
IView* pActiveView = pGF->GetIViewSystem()->GetActiveView();
eViewType viewType = inputParams.view;
if (viewType == VT_FirstPerson) // use player's view
{
IActor* pActor = pGF->GetClientActor();
if (pActor == 0)
return NULL;
eRestriction restriction = inputParams.restriction;
if (restriction != ER_None)
{
IVehicle* pVehicle = pActor->GetLinkedVehicle();
if (restriction == ER_InVehicle && pVehicle == 0)
return NULL;
if (restriction == ER_NoVehicle && pVehicle != 0 /* && pVehicle->GetSeatForPassenger(entityId) != 0 */)
return NULL;
}
EntityId entityId = pActor->GetEntityId();
pView = pGF->GetIViewSystem()->GetViewByEntityId(entityId);
}
else // active view
{
pView = pActiveView;
}
if (pView != pActiveView)
return NULL;
return pView;
}
示例7: Launch
//------------------------------------------------------------------------
void CProjectile::Launch(const Vec3 &pos, const Vec3 &dir, const Vec3 &velocity, float speedScale)
{
m_destroying = false;
GetGameObject()->EnablePhysicsEvent(true, eEPE_OnCollisionLogged);
// Only for bullets
m_hitPoints = m_pAmmoParams->hitPoints;
m_hitListener = false;
if(m_hitPoints>0)
{
//Only projectiles with hit points are hit listeners
g_pGame->GetGameRules()->AddHitListener(this);
m_hitListener = true;
m_noBulletHits = m_pAmmoParams->noBulletHits;
}
Matrix34 worldTM=Matrix34(Matrix33::CreateRotationVDir(dir.GetNormalizedSafe()));
worldTM.SetTranslation(pos);
GetEntity()->SetWorldTM(worldTM);
//Must set velocity after position, if not velocity could be reseted for PE_RIGID
SetVelocity(pos, dir, velocity, speedScale);
m_initial_pos = pos;
m_initial_dir = dir;
m_initial_vel = velocity;
m_last = pos;
// Attach effect when fired (not first update)
if(m_trailEffectId<0)
TrailEffect(true);
IAIObject *pAI = 0;
if((pAI = GetEntity()->GetAI()) != NULL && pAI->GetAIType() == AIOBJECT_GRENADE)
{
IEntity *pOwnerEntity = gEnv->pEntitySystem->GetEntity(m_ownerId);
pe_status_dynamics dyn;
pe_status_dynamics dynProj;
if(pOwnerEntity->GetPhysics()
&& pOwnerEntity->GetPhysics()->GetStatus(&dyn)
&& GetEntity()->GetPhysics()->GetStatus(&dynProj))
{
// Vec3 ownerVel(dyn.v);
Vec3 grenadeDir(dynProj.v.GetNormalizedSafe());
// Trigger the signal at the predicted landing position.
Vec3 predictedPos = pos;
float dummySpeed;
if(GetWeapon())
GetWeapon()->PredictProjectileHit(pOwnerEntity->GetPhysics(), pos, dir, velocity, speedScale * m_pAmmoParams->speed, predictedPos, dummySpeed);
// Associate event with vehicle if the shooter is in a vehicle (tank cannon shot, etc)
EntityId ownerId = pOwnerEntity->GetId();
IActor *pActor = g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(ownerId);
if(pActor && pActor->GetLinkedVehicle() && pActor->GetLinkedVehicle()->GetEntityId())
ownerId = pActor->GetLinkedVehicle()->GetEntityId();
SAIStimulus stim(AISTIM_GRENADE, AIGRENADE_THROWN, ownerId, GetEntityId(),
predictedPos, ZERO, 20.0f);
gEnv->pAISystem->RegisterStimulus(stim);
}
}
}
示例8: HandleEvent
//------------------------------------------------------------------------
void CProjectile::HandleEvent(const SGameObjectEvent &event)
{
if(m_destroying)
return;
FUNCTION_PROFILER(GetISystem(), PROFILE_GAME);
if(event.event == eGFE_OnCollision)
{
EventPhysCollision *pCollision = (EventPhysCollision *)event.ptr;
if(pCollision == NULL)
return;
const SCollisionParams *pCollisionParams = m_pAmmoParams->pCollision;
if(pCollisionParams)
{
if(pCollisionParams->pParticleEffect)
pCollisionParams->pParticleEffect->Spawn(true, IParticleEffect::ParticleLoc(pCollision->pt, pCollision->n, pCollisionParams->scale));
if(pCollisionParams->sound)
{
_smart_ptr<ISound> pSound = gEnv->pSoundSystem->CreateSound(pCollisionParams->sound, FLAG_SOUND_DEFAULT_3D);
if(pSound)
{
pSound->SetSemantic(eSoundSemantic_Projectile);
pSound->SetPosition(pCollision->pt);
pSound->Play();
}
}
}
// add battledust for bulletimpact
if(gEnv->bServer && g_pGame->GetGameRules())
{
if(CBattleDust *pBD = g_pGame->GetGameRules()->GetBattleDust())
{
pBD->RecordEvent(eBDET_ShotImpact, pCollision->pt, GetEntity()->GetClass());
}
}
Ricochet(pCollision);
//Update damage
if((m_damageDropPerMeter>0.0001f)&&
(((pCollision->pt-m_initial_pos).len2()>m_damageDropMinDisSqr)||m_firstDropApplied))
{
if(!m_firstDropApplied)
{
m_firstDropApplied = true;
m_initial_pos = m_initial_pos + (m_initial_dir*(sqrt_fast_tpl(m_damageDropMinDisSqr)));
}
Vec3 vDiff = pCollision->pt - m_initial_pos;
float dis = vDiff.len();
m_damage -= (int)(floor_tpl(m_damageDropPerMeter * dis));
//Check m_damage is positive
if(m_damage<MIN_DAMAGE)
m_damage=MIN_DAMAGE;
//Also modify initial position (the projectile could not be destroyed, cause of pirceability)
m_initial_pos = pCollision->pt;
}
// Notify AI system about grenades.
if(gEnv->pAISystem)
{
IAIObject *pAI = 0;
if((pAI = GetEntity()->GetAI()) != NULL && pAI->GetAIType() == AIOBJECT_GRENADE)
{
// Associate event with vehicle if the shooter is in a vehicle (tank cannon shot, etc)
EntityId ownerId = m_ownerId;
IActor *pActor = g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(ownerId);
if(pActor && pActor->GetLinkedVehicle() && pActor->GetLinkedVehicle()->GetEntityId())
ownerId = pActor->GetLinkedVehicle()->GetEntityId();
SAIStimulus stim(AISTIM_GRENADE, AIGRENADE_COLLISION, ownerId, GetEntityId(),
GetEntity()->GetWorldPos(), ZERO, 12.0f);
gEnv->pAISystem->RegisterStimulus(stim);
}
}
}
}
示例9: ScaledEffect
//------------------------------------------------------------------------
void CProjectile::ScaledEffect(const SScaledEffectParams *pScaledEffect)
{
if(!pScaledEffect)
return;
float lifetime = m_pAmmoParams->lifetime;
IActor *local = gEnv->pGame->GetIGameFramework()->GetClientActor();
if(local)
{
float dist = (GetEntity()->GetWorldPos() - local->GetEntity()->GetWorldPos()).len();
if(m_totalLifetime < pScaledEffect->delay || pScaledEffect->radius == 0.0f)
return;
float fadeInAmt = 1.0f;
float fadeOutAmt = 1.0f;
if(pScaledEffect->fadeInTime > 0.0f)
{
fadeInAmt = (m_totalLifetime - pScaledEffect->delay) / pScaledEffect->fadeInTime;
fadeInAmt = min(fadeInAmt, 1.0f);
fadeOutAmt = 1.0f - (m_totalLifetime - (lifetime - pScaledEffect->fadeOutTime)) / pScaledEffect->fadeOutTime;
fadeOutAmt = max(fadeOutAmt, 0.0f);
}
if(!m_obstructObject && pScaledEffect->aiObstructionRadius != 0.0f)
{
pe_params_pos pos;
pos.scale = 0.1f;
pos.pos = GetEntity()->GetWorldPos() + Vec3(0,0,pScaledEffect->aiObstructionRadius/4 * pos.scale);
m_obstructObject = gEnv->pPhysicalWorld->CreatePhysicalEntity(PE_STATIC, &pos);
if(m_obstructObject)
{
primitives::sphere sphere;
sphere.center = Vec3(0,0,0);
sphere.r = pScaledEffect->aiObstructionRadius;
int obstructID = gEnv->p3DEngine->GetMaterialManager()->GetSurfaceTypeIdByName("mat_obstruct");
IGeometry *pGeom = gEnv->pPhysicalWorld->GetGeomManager()->CreatePrimitive(primitives::sphere::type, &sphere);
phys_geometry *geometry = gEnv->pPhysicalWorld->GetGeomManager()->RegisterGeometry(pGeom, obstructID);
pe_geomparams params;
params.flags = geom_colltype14;
geometry->nRefCount = 0; // automatically delete geometry
m_obstructObject->AddGeometry(geometry, ¶ms);
}
}
else
{
pe_params_pos pos;
pos.scale = 0.1f + min(fadeInAmt, fadeOutAmt) * 0.9f;
pos.pos = GetEntity()->GetWorldPos() + Vec3(0,0, pScaledEffect->aiObstructionRadius/4.0f * pos.scale);
m_obstructObject->SetParams(&pos);
// Signal the AI
if(gEnv->pAISystem && !m_scaledEffectSignaled && m_totalLifetime > (pScaledEffect->delay + pScaledEffect->fadeInTime))
{
m_scaledEffectSignaled = true;
// Associate event with vehicle if the shooter is in a vehicle (tank cannon shot, etc)
EntityId ownerId = m_ownerId;
IActor *pActor = g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(ownerId);
if(pActor && pActor->GetLinkedVehicle() && pActor->GetLinkedVehicle()->GetEntityId())
ownerId = pActor->GetLinkedVehicle()->GetEntityId();
SAIStimulus stim(AISTIM_GRENADE, AIGRENADE_SMOKE, ownerId, GetEntityId(),
pos.pos, ZERO, pScaledEffect->aiObstructionRadius*1.5f);
gEnv->pAISystem->RegisterStimulus(stim);
}
}
if(dist > pScaledEffect->radius)
{
gEnv->p3DEngine->SetPostEffectParam(pScaledEffect->ppname, 0.0f);
return;
}
float effectAmt = 1.0f - (dist / pScaledEffect->radius);
effectAmt = max(effectAmt, 0.0f);
float effectVal = effectAmt * pScaledEffect->maxValue;
effectVal *= fadeInAmt;
m_scaledEffectval = effectVal;
gEnv->p3DEngine->SetPostEffectParam(pScaledEffect->ppname, effectVal);
}
}
示例10: stim
//------------------------------------------
void CC4Projectile::HandleEvent(const SGameObjectEvent &event)
{
if (CheckAnyProjectileFlags(ePFlag_destroying))
return;
CProjectile::HandleEvent(event);
if (event.event == eGFE_OnCollision)
{
EventPhysCollision *pCollision = (EventPhysCollision *)event.ptr;
if(pCollision && pCollision->pEntity[0]->GetType()==PE_PARTICLE)
{
float bouncy, friction;
uint32 pierceabilityMat;
gEnv->pPhysicalWorld->GetSurfaceParameters(pCollision->idmat[1], bouncy, friction, pierceabilityMat);
pierceabilityMat &= sf_pierceable_mask;
uint32 pierceabilityProj = GetAmmoParams().pParticleParams ? GetAmmoParams().pParticleParams->iPierceability : 13;
if (pierceabilityMat > pierceabilityProj)
return;
if(gEnv->bMultiplayer)
{
// Don't stick to weapons.
if(pCollision->iForeignData[1]==PHYS_FOREIGN_ID_ENTITY)
{
if(IEntity* pEntity = (IEntity*)pCollision->pForeignData[1])
{
if(IItem* pItem = g_pGame->GetIGameFramework()->GetIItemSystem()->GetItem(pEntity->GetId()))
{
if(pItem->GetIWeapon())
{
return;
}
}
}
}
}
// Notify AI system about the C4.
if (gEnv->pAISystem)
{
// Associate event with vehicle if the shooter is in a vehicle (tank cannon shot, etc)
EntityId ownerId = m_ownerId;
IActor* pActor = g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(ownerId);
if (pActor && pActor->GetLinkedVehicle() && pActor->GetLinkedVehicle()->GetEntityId())
ownerId = pActor->GetLinkedVehicle()->GetEntityId();
SAIStimulus stim(AISTIM_EXPLOSION, 0, ownerId, GetEntityId(),
GetEntity()->GetWorldPos(), ZERO, 12.0f, AISTIMPROC_ONLY_IF_VISIBLE);
gEnv->pAISystem->RegisterStimulus(stim);
SAIStimulus soundStim(AISTIM_SOUND, AISOUND_COLLISION, ownerId, GetEntityId(),
GetEntity()->GetWorldPos(), ZERO, 8.0f);
gEnv->pAISystem->RegisterStimulus(soundStim);
}
}
if (gEnv->bServer && !m_stickyProjectile.IsStuck())
m_stickyProjectile.Stick(
CStickyProjectile::SStickParams(this, pCollision, CStickyProjectile::eO_AlignToSurface));
}
}
示例11: UpdateCrosshair
void CHUDCrosshair::UpdateCrosshair()
{
IActor *pClientActor = g_pGame->GetIGameFramework()->GetClientActor();
if(!pClientActor)
return;
int iNewFriendly = 0;
if(pClientActor->GetLinkedVehicle())
{
// JanM/MichaelR:
// Get status from the VehicleWeapon, which raycasts considering the necessary SkipEntities (in contrast to WorldQuery)
// Julien: this is now done in MP as well
iNewFriendly = g_pHUD->GetVehicleInterface()->GetFriendlyFire();
}
else
{
if(!gEnv->bMultiplayer)
{
CWeapon *pWeapon = g_pHUD->GetCurrentWeapon();
if(pWeapon)
{
iNewFriendly = pWeapon->IsWeaponLowered() && pWeapon->IsPendingFireRequest();
if(iNewFriendly && pWeapon->GetEntity()->GetClass() == CItem::sTACGunFleetClass)
iNewFriendly = 0;
}
else{
//Two handed pickups need the red X as well
CPlayer *pPlayer= static_cast<CPlayer*>(pClientActor);
if(CWeapon *pOffHand = static_cast<CWeapon*>(pPlayer->GetItemByClass(CItem::sOffHandClass)))
iNewFriendly = pOffHand->IsWeaponLowered();
}
}
else
{
EntityId uiCenterId = pClientActor->GetGameObject()->GetWorldQuery()->GetLookAtEntityId();
if(uiCenterId)
{
iNewFriendly = IsFriendlyEntity(gEnv->pEntitySystem->GetEntity(uiCenterId));
}
}
}
// SNH: if player is carrying a claymore or mine, ask the weapon whether it is possible to place it currently
// (takes into account player speed / stance / aim direction).
// So 'friendly' is a bit of a misnomer here, but we want the "don't/can't fire" crosshair...
if(iNewFriendly != 1 && g_pHUD)
{
CWeapon *pWeapon = g_pHUD->GetCurrentWeapon();
if(pWeapon)
{
static IEntityClass* pClaymoreClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass("Claymore");
static IEntityClass* pAVMineClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass("AVMine");
IEntityClass* pClass = pWeapon->GetEntity()->GetClass();
if(pClass == pClaymoreClass || pClass == pAVMineClass)
{
if(IFireMode* pfm = pWeapon->GetFireMode(pWeapon->GetCurrentFireMode()))
{
if(!pfm->IsFiring())
iNewFriendly = pWeapon->CanFire() ? 0 : 1;
}
}
}
}
if(iNewFriendly != m_iFriendlyTarget)
{
m_iFriendlyTarget = iNewFriendly;
//m_animCrossHair.Invoke("setFriendly", m_iFriendlyTarget);
if(iNewFriendly)
m_animFriendCross.SetVisible(true);
else
m_animFriendCross.SetVisible(false);
}
if(m_animInterActiveIcons.GetVisible())
{
m_bHideUseIconTemp = false;
CItem *pItem = static_cast<CItem*>(pClientActor->GetCurrentItem());
if(pItem)
{
IWeapon *pWeapon = pItem->GetIWeapon();
if(pWeapon)
{
CItem::SStats stats = pItem->GetStats();
if(stats.mounted && stats.used)
m_bHideUseIconTemp = true;
}
}
if(!m_bHideUseIconTemp)
{
EntityId offHandId = pClientActor->GetInventory()->GetItemByClass(CItem::sOffHandClass);
IItem *pOffHandItem = g_pGame->GetIGameFramework()->GetIItemSystem()->GetItem(offHandId);
if(pOffHandItem)
{
COffHand *pOffHand = static_cast<COffHand*>(pOffHandItem);
uint32 offHandState = pOffHand->GetOffHandState();
if(offHandState == eOHS_HOLDING_OBJECT || offHandState == eOHS_THROWING_OBJECT ||
offHandState == eOHS_HOLDING_NPC || offHandState == eOHS_THROWING_NPC)
m_bHideUseIconTemp = true;
//.........这里部分代码省略.........
示例12: ClientExplosion
//.........这里部分代码省略.........
explosion.rmin = explosionInfo.minPhysRadius;
explosion.rmax = explosionInfo.physRadius;
if (explosion.rmax==0)
explosion.rmax=0.0001f;
explosion.r = explosion.rmin;
explosion.holeSize = explosionInfo.hole_size;
if (explosion.nOccRes>0)
explosion.nOccRes = -1; // makes second call re-use occlusion info
gEnv->pPhysicalWorld->SimulateExplosion( &explosion, 0, 0, ent_rigid|ent_sleeping_rigid|ent_independent|ent_static | ent_delayed_deformations);
UpdateAffectedEntitiesSet(affectedEntities, &explosion);
CommitAffectedEntitiesSet(m_scriptExplosionInfo, affectedEntities);
float fSuitEnergyBeforeExplosion = 0.0f;
float fHealthBeforeExplosion = 0.0f;
IActor *pClientActor = g_pGame->GetIGameFramework()->GetClientActor();
if(pClientActor)
{
fHealthBeforeExplosion = (float)pClientActor->GetHealth();
}
CallScript(m_serverStateScript, "OnExplosion", m_scriptExplosionInfo);
if(pClientActor)
{
float fDeltaHealth = fHealthBeforeExplosion - static_cast<CPlayer *>(pClientActor)->GetHealth();
if(fDeltaHealth >= 20.0f)
{
SAFE_GAMEAUDIO_SOUNDMOODS_FUNC(AddSoundMood(SOUNDMOOD_EXPLOSION, MIN(fDeltaHealth, 100.0f) ));
}
}
// call hit listeners if any
if (m_hitListeners.empty() == false)
{
for (size_t i = 0; i < m_hitListeners.size(); )
{
size_t count = m_hitListeners.size();
m_hitListeners[i]->OnServerExplosion(explosionInfo);
if (count == m_hitListeners.size())
i++;
else
continue;
}
}
}
if (gEnv->IsClient())
{
if (explosionInfo.pParticleEffect)
explosionInfo.pParticleEffect->Spawn(true, IParticleEffect::ParticleLoc(explosionInfo.pos, explosionInfo.dir, explosionInfo.effect_scale));
if (!gEnv->bServer)
{
CreateScriptExplosionInfo(m_scriptExplosionInfo, explosionInfo);
}
else
{
affectedEntities.clear();
CommitAffectedEntitiesSet(m_scriptExplosionInfo, affectedEntities);
}
CallScript(m_clientStateScript, "OnExplosion", m_scriptExplosionInfo);
// call hit listeners if any
if (m_hitListeners.empty() == false)
{
THitListenerVec::iterator iter = m_hitListeners.begin();
while (iter != m_hitListeners.end())
{
(*iter)->OnExplosion(explosionInfo);
++iter;
}
}
}
ProcessClientExplosionScreenFX(explosionInfo);
ProcessExplosionMaterialFX(explosionInfo);
if (gEnv->pAISystem && !gEnv->bMultiplayer)
{
// Associate event with vehicle if the shooter is in a vehicle (tank cannon shot, etc)
EntityId ownerId = explosionInfo.shooterId;
IActor* pActor = g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(ownerId);
if (pActor && pActor->GetLinkedVehicle() && pActor->GetLinkedVehicle()->GetEntityId())
ownerId = pActor->GetLinkedVehicle()->GetEntityId();
if (ownerId != 0)
{
SAIStimulus stim(AISTIM_EXPLOSION, 0, ownerId, 0,
explosionInfo.pos, ZERO, explosionInfo.radius);
gEnv->pAISystem->RegisterStimulus(stim);
SAIStimulus stimSound(AISTIM_SOUND, AISOUND_EXPLOSION, ownerId, 0,
explosionInfo.pos, ZERO, explosionInfo.radius * 3.0f, AISTIMPROC_FILTER_LINK_WITH_PREVIOUS);
gEnv->pAISystem->RegisterStimulus(stimSound);
}
}
}
示例13: HandleEvent
//------------------------------------------------------------------------
void CBullet::HandleEvent(const SGameObjectEvent &event)
{
FUNCTION_PROFILER(GetISystem(), PROFILE_GAME);
CProjectile::HandleEvent(event);
if (event.event == eGFE_OnCollision)
{
if (m_destroying)
return;
EventPhysCollision *pCollision = reinterpret_cast<EventPhysCollision *>(event.ptr);
if (!pCollision)
return;
IEntity *pTarget = pCollision->iForeignData[1]==PHYS_FOREIGN_ID_ENTITY ? (IEntity*)pCollision->pForeignData[1]:0;
//Only process hits that have a target
if(pTarget)
{
Vec3 dir(0, 0, 0);
if (pCollision->vloc[0].GetLengthSquared() > 1e-6f)
dir = pCollision->vloc[0].GetNormalized();
CGameRules *pGameRules = g_pGame->GetGameRules();
IActor* pActor = g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(m_ownerId);
bool ok = true;
if(!gEnv->bMultiplayer && pActor && pActor->IsPlayer())
{
IActor* pAITarget = g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(pTarget->GetId());
if(pAITarget && pTarget->GetAI() && pTarget->GetAI()->IsFriendly(pActor->GetEntity()->GetAI(), false))
{
pGameRules->SetEntityToIgnore(pTarget->GetId());
ok = false;
}
}
if(ok)
{
HitInfo hitInfo(m_ownerId, pTarget->GetId(), m_weaponId,
(float)m_damage, 0.0f, pGameRules->GetHitMaterialIdFromSurfaceId(pCollision->idmat[1]), pCollision->partid[1],
m_hitTypeId, pCollision->pt, dir, pCollision->n);
hitInfo.remote = IsRemote();
hitInfo.projectileId = GetEntityId();
hitInfo.bulletType = m_pAmmoParams->bulletType;
pGameRules->ClientHit(hitInfo);
// Notify AI
if (gEnv->pAISystem && !gEnv->bMultiplayer)
{
static int htMelee = pGameRules->GetHitTypeId("melee");
if (m_ownerId && m_hitTypeId != htMelee)
{
ISurfaceType *pSurfaceType = pGameRules->GetHitMaterial(hitInfo.material);
const ISurfaceType::SSurfaceTypeAIParams* pParams = pSurfaceType ? pSurfaceType->GetAIParams() : 0;
const float radius = pParams ? pParams->fImpactRadius : 2.5f;
const float soundRadius = pParams ? pParams->fImpactSoundRadius : 20.0f;
// Associate event with vehicle if the shooter is in a vehicle (tank cannon shot, etc)
EntityId ownerId = m_ownerId;
if (pActor && pActor->GetLinkedVehicle() && pActor->GetLinkedVehicle()->GetEntityId())
ownerId = pActor->GetLinkedVehicle()->GetEntityId();
SAIStimulus stim(AISTIM_BULLET_HIT, 0, ownerId, 0, pCollision->pt, ZERO, radius);
gEnv->pAISystem->RegisterStimulus(stim);
SAIStimulus stimSound(AISTIM_SOUND, AISOUND_COLLISION_LOUD, ownerId, 0, pCollision->pt, ZERO, soundRadius, AISTIMPROC_FILTER_LINK_WITH_PREVIOUS);
gEnv->pAISystem->RegisterStimulus(stimSound);
}
}
}
}
else
{
// Notify AI
// The above case only catches entity vs. entity hits, the AI is interested in all hits.
if (gEnv->pAISystem && !gEnv->bMultiplayer)
{
CGameRules *pGameRules = g_pGame->GetGameRules();
static int htMelee = pGameRules->GetHitTypeId("melee");
if (m_ownerId && m_hitTypeId != htMelee)
{
int material = pGameRules->GetHitMaterialIdFromSurfaceId(pCollision->idmat[1]);
ISurfaceType *pSurfaceType = pGameRules->GetHitMaterial(material);
const ISurfaceType::SSurfaceTypeAIParams* pParams = pSurfaceType ? pSurfaceType->GetAIParams() : 0;
const float radius = pParams ? pParams->fImpactRadius : 2.5f;
const float soundRadius = pParams ? pParams->fImpactSoundRadius : 20.0f;
// Associate event with vehicle if the shooter is in a vehicle (tank cannon shot, etc)
EntityId ownerId = m_ownerId;
IActor* pActor = g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(m_ownerId);
if (pActor && pActor->GetLinkedVehicle() && pActor->GetLinkedVehicle()->GetEntityId())
//.........这里部分代码省略.........
示例14: HandleSequenceEvent
void CFlowNode_AISequenceAction_VehicleRotateTurret::HandleSequenceEvent(AIActionSequence::SequenceEvent sequenceEvent)
{
switch(sequenceEvent)
{
case AIActionSequence::StartAction:
{
if (!m_actInfo.pEntity)
{
// the entity has gone for some reason, at least make sure the action gets finished properly and the FG continues
CancelSequenceAndActivateOutputPort(OutputPort_Done);
return;
}
assert(gEnv && gEnv->pGame && gEnv->pGame->GetIGameFramework() && gEnv->pGame->GetIGameFramework()->GetIActorSystem());
IActor* pActor = gEnv->pGame->GetIGameFramework()->GetIActorSystem()->GetActor(m_actInfo.pEntity->GetId());
// ensure the FG entity is an IActor
if (!pActor)
{
CRY_ASSERT_MESSAGE(0, "no compatible entity was provided");
CryWarning(VALIDATOR_MODULE_AI, VALIDATOR_WARNING, "Actor %s failed to enter vehicle (no compatible entity was provided)", m_actInfo.pEntity->GetName());
CancelSequenceAndActivateOutputPort(OutputPort_Done);
return;
}
// get the vehicle the actor is linked to
IVehicle* pVehicle = pActor->GetLinkedVehicle();
if (!pVehicle)
{
CRY_ASSERT_MESSAGE(0, "agent is not linked to a vehicle");
CryWarning(VALIDATOR_MODULE_AI, VALIDATOR_WARNING, "Actor %s is not linked to a vehicle", m_actInfo.pEntity->GetName());
CancelSequenceAndActivateOutputPort(OutputPort_Done);
return;
}
// get the seat the actor is sitting on
CVehicleSeat* pSeat = static_cast<CVehicleSeat*>(pVehicle->GetSeatForPassenger(m_actInfo.pEntity->GetId()));
if (!pSeat)
{
CRY_ASSERT_MESSAGE(0, "agent is not sitting in the vehicle it is linked to");
CryWarning(VALIDATOR_MODULE_AI, VALIDATOR_WARNING, "Actor %s is not sitting in the vehicle it is linked to", m_actInfo.pEntity->GetName());
CancelSequenceAndActivateOutputPort(OutputPort_Done);
return;
}
// scan for the seat-action that allows rotating the turret
TVehicleSeatActionVector& seatActions = pSeat->GetSeatActions();
for (TVehicleSeatActionVector::iterator it = seatActions.begin(); it != seatActions.end(); ++it)
{
IVehicleSeatAction* pSeatAction = it->pSeatAction;
if ((m_pActionRotateTurret = CAST_VEHICLEOBJECT(CVehicleSeatActionRotateTurret, pSeatAction)))
{
break;
}
}
// ensure the vehicle-seat provided the correct action
if (!m_pActionRotateTurret)
{
CRY_ASSERT_MESSAGE(0, "a CVehicleSeatActionRotateTurret is not provided by the vehicle or someone else in the vehicle has reserved that action already.");
CryWarning(VALIDATOR_MODULE_AI, VALIDATOR_WARNING, "Actor %s could not find a CVehicleSeatActionRotateTurret or that action is already reserved by someone else", m_actInfo.pEntity->GetName());
CancelSequenceAndActivateOutputPort(OutputPort_Done);
return;
}
m_pitchThreshold = GetPortFloat(&m_actInfo, InputPort_ThresholdPitch);
m_yawThreshold = GetPortFloat(&m_actInfo, InputPort_ThresholdYaw);
Vec3 aimPos = GetPortVec3(&m_actInfo, InputPort_AimPos);
m_pActionRotateTurret->SetAimGoal(aimPos);
}
break;
case AIActionSequence::SequenceStopped:
{
if (m_pActionRotateTurret)
{
// cancel the rotation action
m_pActionRotateTurret->SetAimGoal(Vec3Constants<float>::fVec3_Zero);
m_pActionRotateTurret = NULL;
}
}
break;
}
}
示例15: ProcessEvent
virtual void ProcessEvent( EFlowEvent event,SActivationInfo* pActInfo )
{
if (event != eFE_Activate)
return;
if (!InputEntityIsLocalPlayer( pActInfo ))
return;
const bool bTriggered = IsPortActive(pActInfo, EIP_Trigger);
const bool bFreqTriggered = IsPortActive(pActInfo, EIP_Frequency);
if (bTriggered == false && bFreqTriggered == false)
return;
IGameFramework* pGF = gEnv->pGame->GetIGameFramework();
IView* pView = 0;
IView* pActiveView = pGF->GetIViewSystem()->GetActiveView();
int viewType = GetPortInt(pActInfo, EIP_ViewType);
if (viewType == VT_FirstPerson) // use player's view
{
IActor* pActor = pGF->GetClientActor();
if (pActor == 0)
return;
const int restriction = GetPortInt(pActInfo, EIP_Restriction);
if (restriction != ER_None)
{
IVehicle* pVehicle = pActor->GetLinkedVehicle();
if (restriction == ER_InVehicle && pVehicle == 0)
return;
if (restriction == ER_NoVehicle && pVehicle != 0 /* && pVehicle->GetSeatForPassenger(entityId) != 0 */)
return;
}
EntityId entityId = pActor->GetEntityId();
pView = pGF->GetIViewSystem()->GetViewByEntityId(entityId);
}
else // active view
{
pView = pActiveView;
}
if (pView == 0 || pView != pActiveView)
return;
const bool bGroundOnly = GetPortBool(pActInfo, EIP_GroundOnly);
Ang3 angles = Ang3(DEG2RAD(GetPortVec3(pActInfo, EIP_Angle)));
Vec3 shift = GetPortVec3(pActInfo, EIP_Shift);
const float duration = GetPortFloat(pActInfo, EIP_Duration);
float freq = GetPortFloat(pActInfo, EIP_Frequency);
if (iszero(freq) == false)
freq = 1.0f / freq;
const float randomness = GetPortFloat(pActInfo, EIP_Randomness);
static const bool bFlip = true; // GetPortBool(pActInfo, EIP_Flip);
const bool bUpdateOnly = !bTriggered && bFreqTriggered; // it's an update if and only if Frequency has been changed
const float distance = GetPortFloat(pActInfo, EIP_Distance);
const float rangeMin = GetPortFloat(pActInfo, EIP_RangeMin);
const float rangeMax = GetPortFloat(pActInfo, EIP_RangeMax);
float amount = min(1.f, max(0.f, (rangeMax - distance) / (rangeMax - rangeMin)));
angles *= amount;
shift *= amount;
pView->SetViewShake(angles, shift, duration, freq, randomness, FLOWGRAPH_SHAKE_ID, bFlip, bUpdateOnly, bGroundOnly);
}