本文整理汇总了C++中CActor::GetEntity方法的典型用法代码示例。如果您正苦于以下问题:C++ CActor::GetEntity方法的具体用法?C++ CActor::GetEntity怎么用?C++ CActor::GetEntity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CActor
的用法示例。
在下文中一共展示了CActor::GetEntity方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetActorByChannelId
IMPLEMENT_RMI(CGameRules, ClEnteredGame)
{
if(!gEnv->bServer && m_pGameFramework->GetClientActor())
{
CActor* pActor = GetActorByChannelId(m_pGameFramework->GetClientActor()->GetChannelId());
if(pActor)
{
int status[2];
status[0] = GetTeam(pActor->GetEntityId());
status[1] = pActor->GetSpectatorMode();
m_pGameplayRecorder->Event(pActor->GetEntity(), GameplayEvent(eGE_Connected, 0, 0, (void*)status));
}
}
return true;
}
示例2: Fall
//------------------------------------------------------------------------
int CScriptBind_Actor::Fall(IFunctionHandler *pH, Vec3 hitPos)
{
CActor *pActor = GetActor(pH);
if (!pActor)
return pH->EndFunction();
// [Mikko] 11.10.2007 - Moved the check here, since it was causing too much trouble in CActor.Fall().
// The point of this filtering is to mostly mask out self-induced collision damage on friendly NPCs
// which are playing special animations.
if(!g_pGameCVars->g_enableFriendlyFallAndPlay)
{
if (IAnimatedCharacter* pAC = pActor->GetAnimatedCharacter())
{
if ((pAC->GetPhysicalColliderMode() == eColliderMode_NonPushable) ||
(pAC->GetPhysicalColliderMode() == eColliderMode_PushesPlayersOnly))
{
// Only mask for player friendly NPCs.
if (pActor->GetEntity() && pActor->GetEntity()->GetAI())
{
IAIObject* pAI = pActor->GetEntity()->GetAI();
IAIObject* playerAI = 0;
if (IActor* pPlayerActor = m_pGameFW->GetClientActor())
playerAI = pPlayerActor->GetEntity()->GetAI();
if (playerAI
&& gEnv->pAISystem->GetFactionMap().GetReaction(playerAI->GetFactionID(), pAI->GetFactionID()) > IFactionMap::eRT_Hostile)
return pH->EndFunction();
}
}
}
}
pActor->Fall(hitPos);
return pH->EndFunction();
}
示例3: RaiseWeapon
void CFists::RaiseWeapon(bool raise, bool faster /*= false*/)
{
//Only when colliding something while running
if(raise && (GetCurrentAnimState()==eFAS_RUNNING || GetCurrentAnimState()==eFAS_JUMPING) && !IsWeaponRaised())
{
if((m_fm && m_fm->IsFiring())||(m_melee && m_melee->IsFiring()))
return;
PlayAction(g_pItemStrings->raise);
SetDefaultIdleAnimation( eIGS_FirstPerson,g_pItemStrings->idle_relaxed);
SetWeaponRaised(true);
//Also give the player some impulse into the opposite direction
CActor *pPlayer = GetOwnerActor();
Vec3 pos;
if(pPlayer)
{
IPhysicalEntity* playerPhysics = pPlayer->GetEntity()->GetPhysics();
if(playerPhysics)
{
IMovementController *pMC = pPlayer->GetMovementController();
if(pMC)
{
SMovementState state;
pMC->GetMovementState(state);
pe_action_impulse impulse;
impulse.iApplyTime = 1;
impulse.impulse = -state.eyeDirection*600.0f;
playerPhysics->Action(&impulse);
pos = state.eyePosition + state.eyeDirection*0.5f;
}
}
}
GetScheduler()->TimerAction(GetCurrentAnimationTime(eIGS_FirstPerson), CSchedulerAction<EndRaiseWeaponAction>::Create(EndRaiseWeaponAction(this)), true);
//Sound and FX feedback
CollisionFeeback(pos,m_currentAnimState);
}
else if(!raise)
SetWeaponRaised(false);
}
示例4: OnFailedHit
void CMelee::OnFailedHit()
{
const SCollisionTestParams& collisionParams = m_collisionHelper.GetCollisionTestParams();
bool collided = PerformCylinderTest(collisionParams.m_pos, collisionParams.m_dir, collisionParams.m_remote);
CActor* pOwner = m_pWeapon->GetOwnerActor();
if(pOwner && pOwner->IsClient())
{
if(!collided && s_meleeSnapTargetId)
{
Vec3 ownerpos = pOwner->GetEntity()->GetWorldPos();
IEntity* pTarget = gEnv->pEntitySystem->GetEntity(s_meleeSnapTargetId);
if(pTarget && ownerpos.GetSquaredDistance(pTarget->GetWorldPos()) < cry_sqr(GetRange() * m_pMeleeParams->meleeparams.target_range_mult))
{
collided = m_collisionHelper.PerformMeleeOnAutoTarget(s_meleeSnapTargetId);
}
}
s_meleeSnapTargetId = 0;
CHANGED_NETWORK_STATE(pOwner, CPlayer::ASPECT_SNAP_TARGET);
if(g_pGameCVars->pl_melee.mp_melee_system_camera_lock_and_turn)
{
pOwner->GetActorParams().viewLimits.ClearViewLimit(SViewLimitParams::eVLS_Item);
}
}
if(m_pMeleeAction)
{
if(pOwner)
{
m_pMeleeAction->OnHitResult(pOwner, collided);
}
else
{
//Owner has dropped weapon (Likely from being killed) so we can stop and release the action
m_pMeleeAction->ForceFinish();
SAFE_RELEASE(m_pMeleeAction);
}
}
ApplyMeleeEffects(collided);
}
示例5: AttachVulnerabilityEffect
//------------------------------------------------------------------------
int CScriptBind_Actor::AttachVulnerabilityEffect(IFunctionHandler *pH, int characterSlot, int partid, Vec3 hitPos, float radius, const char* effect, const char* attachmentIdentifier)
{
CActor *pActor = GetActor(pH);
if (!pActor)
return pH->EndFunction();
IEntity* pEntity = pActor->GetEntity();
ICharacterInstance* pChar = pEntity->GetCharacter(characterSlot);
if (!pChar || !effect)
return pH->EndFunction();
//fallback: use nearest attachment
float minDiff = radius*radius;
IAttachment* pClosestAtt = 0;
IAttachmentManager* pMan = pChar->GetIAttachmentManager();
for (int i=0; i<pMan->GetAttachmentCount(); ++i)
{
IAttachment* pAtt = pMan->GetInterfaceByIndex(i);
float diff = (hitPos - pAtt->GetAttWorldAbsolute().t).len2();
if (diff < minDiff)
{
// only use specified attachments
if (attachmentIdentifier[0] && !strstr(pAtt->GetName(), attachmentIdentifier))
continue;
minDiff = diff;
pClosestAtt = pAtt;
}
//CryLog("diff: %.2f, att: %s", diff, attName.c_str());
}
if (!pClosestAtt)
return pH->EndFunction();
//CryLog("AttachVulnerabilityEffect: closest att %s, attaching effect %s", pClosestAtt->GetName(), effect);
CEffectAttachment *pEffectAttachment = new CEffectAttachment(effect, Vec3(ZERO), Vec3(0,1,0), 1.f);
pClosestAtt->AddBinding(pEffectAttachment);
pClosestAtt->HideAttachment(0);
return pH->EndFunction(pClosestAtt->GetName());
}
示例6: RegisterCharacterTargetInfo
void CAutoAimManager::RegisterCharacterTargetInfo(const CActor& targetActor, const SAutoaimTargetRegisterParams& registerParams)
{
SAutoaimTarget aimTarget;
aimTarget.entityId = targetActor.GetEntityId();
aimTarget.pActorWeak = targetActor.GetWeakPtr();
aimTarget.fallbackOffset = registerParams.fallbackOffset;
aimTarget.primaryBoneId = registerParams.primaryBoneId;
aimTarget.physicsBoneId = registerParams.physicsBoneId;
aimTarget.secondaryBoneId = registerParams.secondaryBoneId;
aimTarget.innerRadius = registerParams.innerRadius;
aimTarget.outerRadius = registerParams.outerRadius;
aimTarget.snapRadius = registerParams.snapRadius;
aimTarget.snapRadiusTagged = registerParams.snapRadiusTagged;
if (!gEnv->bMultiplayer)
{
IEntity* pTargetEntity = targetActor.GetEntity();
aimTarget.aiFaction = IFactionMap::InvalidFactionID;
//Instance properties, other stuff could be added here easily (grab enemy, sliding hit, etc)
SmartScriptTable props;
SmartScriptTable propsPlayerInteractions;
IScriptTable* pScriptTable = pTargetEntity->GetScriptTable();
if (pScriptTable && pScriptTable->GetValue("Properties", props))
{
if (props->GetValue("PlayerInteractions", propsPlayerInteractions))
{
int stealhKill = 0;
if (propsPlayerInteractions->GetValue("bStealthKill", stealhKill) && (stealhKill != 0))
{
aimTarget.SetFlag(eAATF_StealthKillable);
}
int canBeGrabbed = 0;
if (propsPlayerInteractions->GetValue("bCanBeGrabbed", canBeGrabbed) && (canBeGrabbed != 0))
{
aimTarget.SetFlag(eAATF_CanBeGrabbed);
}
}
}
}
m_autoaimTargets.push_back(aimTarget);
}
示例7: OnShoot
//------------------------------------------------------------------------
void CWeapon::OnShoot(EntityId shooterId, EntityId ammoId, IEntityClass *pAmmoType, const Vec3 &pos, const Vec3 &dir, const Vec3 &vel)
{
BROADCAST_WEAPON_EVENT(OnShoot, (this, shooterId, ammoId, pAmmoType, pos, dir, vel));
//FIXME:quick temporary solution
CActor *pActor = static_cast<CActor *>(g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(shooterId));
if(pActor)
pActor->HandleEvent(SGameObjectEvent(eCGE_OnShoot,eGOEF_ToExtensions));
IActor *pClientActor=m_pGameFramework->GetClientActor();
if(pActor && pActor->GetActorClass() == CPlayer::GetActorClassType() && IsServer())
{
if(pActor == pClientActor)
{
if(IAIObject *pAIObject=pActor->GetEntity()->GetAI())
gEnv->pAISystem->SendSignal(SIGNALFILTER_LEADER, 1, "OnEnableFire", pAIObject, 0);
}
}
if(pClientActor && m_fm && strcmp(m_fm->GetType(), "Thrown"))
{
// inform the HUDRadar about the sound event
Vec3 vPlayerPos=pClientActor->GetEntity()->GetWorldPos();
float fDist2=(vPlayerPos-pos).len2();
if(fDist2<250.0f*250.0f)
{
//if (pClientActor->GetEntityId() != shooterId)
// pHUD->ShowSoundOnRadar(pos);
if(gEnv->bMultiplayer)
{
CGameRules *pGameRules = g_pGame->GetGameRules();
}
if((!IsSilencerAttached()) && fDist2<sqr(SAFE_GAMEAUDIO_BATTLESTATUS_FUNC_RET(GetBattleRange())))
SAFE_GAMEAUDIO_BATTLESTATUS_FUNC(TickBattleStatus(1.0f));
}
}
}
示例8: IsFlying
//------------------------------------------------------------------------
int CScriptBind_Actor::IsFlying(IFunctionHandler *pH)
{
CActor *pActor = GetActor(pH);
if (!pActor)
return pH->EndFunction();
if (pActor)
{
pe_status_living livStat;
IPhysicalEntity *pPhysEnt = pActor->GetEntity()->GetPhysics();
if (!pPhysEnt)
return pH->EndFunction();
if(pPhysEnt->GetStatus(&livStat))
return pH->EndFunction(livStat.bFlying!=0);
}
return pH->EndFunction();
}
示例9: ResetVulnerabilityEffects
//------------------------------------------------------------------------
int CScriptBind_Actor::ResetVulnerabilityEffects(IFunctionHandler *pH, int characterSlot)
{
CActor *pActor = GetActor(pH);
if (!pActor)
return pH->EndFunction();
IEntity* pEntity = pActor->GetEntity();
ICharacterInstance* pChar = pEntity->GetCharacter(characterSlot);
if (pChar)
{
IAttachmentManager* pMan = pChar->GetIAttachmentManager();
for (int i=0; i<pMan->GetAttachmentCount(); ++i)
{
IAttachment* pAtt = pMan->GetInterfaceByIndex(i);
if (strstr(pAtt->GetName(), "vulnerable"))
pAtt->ClearBinding();
}
}
return pH->EndFunction();
}
示例10: Activate
//------------------------------------------------------------------------
void SSleepEffect::Activate(EntityId targetId, EntityId ownerId, EntityId weaponId, const char *effect, const char *defaultEffect)
{
CActor *pActor = (CActor *)gEnv->pGame->GetIGameFramework()->GetIActorSystem()->GetActor(targetId);
if (pActor)
{
IAISystem *pAISystem=gEnv->pAISystem;
if (pAISystem)
{
if(IEntity* pEntity=pActor->GetEntity())
{
if(IAIObject* pAIObj=pEntity->GetAI())
{
IAISignalExtraData *pEData = pAISystem->CreateSignalExtraData(); // no leak - this will be deleted inside SendAnonymousSignal
// try to retrieve the shooter position
if (IEntity* pOwnerEntity = gEnv->pEntitySystem->GetEntity(ownerId))
pEData->point = pOwnerEntity->GetWorldPos();
else
pEData->point = pEntity->GetWorldPos();
IAIActor* pAIActor = pAIObj->CastToIAIActor();
if(pAIActor)
pAIActor->SetSignal(1,"TRANQUILIZED",0,pEData);
}
}
}
pActor->CreateScriptEvent("sleep", 0);
pActor->GetGameObject()->SetPhysicalizationProfile(eAP_Sleep);
// no dropping weapons for AI
if(pActor->IsPlayer())
pActor->DropItem(pActor->GetCurrentItemId(), 1.0f, false);
pActor->SetSleepTimer(12.5f);
}
}
示例11: GetPlantingParameters
// returns true if firing is allowed
bool CPlant::GetPlantingParameters(Vec3& pos, Vec3& dir, Vec3& vel) const
{
CActor *pActor = m_pWeapon->GetOwnerActor();
IMovementController *pMC = pActor?pActor->GetMovementController():0;
SMovementState info;
if (pMC)
pMC->GetMovementState(info);
if (m_pWeapon->GetStats().fp)
pos = m_pWeapon->GetSlotHelperPos( eIGS_FirstPerson, m_plantparams.helper.c_str(), true);
else if (pMC)
pos = info.eyePosition+info.eyeDirection*0.25f;
else
pos = pActor->GetEntity()->GetWorldPos();
if (pMC)
dir = info.eyeDirection;
else
dir = pActor->GetEntity()->GetWorldRotation().GetColumn1();
if (IPhysicalEntity *pPE=pActor->GetEntity()->GetPhysics())
{
pe_status_dynamics sv;
if (pPE->GetStatus(&sv))
{
if (sv.v.len2()>0.01f)
{
float dot=sv.v.GetNormalized().Dot(dir);
if (dot<0.0f)
dot=0.0f;
vel=sv.v*dot;
}
}
}
// if the ammo should be placed (claymore/mine) rather than thrown forward (c4), check if we can do so...
if(m_plantparams.place_on_ground)
{
ray_hit hit;
static const int objTypes = ent_static | ent_terrain;
static const unsigned int flags = rwi_stop_at_pierceable|rwi_colltype_any;
static IPhysicalEntity* pSkipEnts[10];
int nskip = CSingle::GetSkipEntities(m_pWeapon, pSkipEnts, 10);
int res = gEnv->pPhysicalWorld->RayWorldIntersection(pos, 2.0f * dir, objTypes, flags, &hit, 1, pSkipEnts, nskip);
if(!res)
return false;
else
{
// check surface normal - must be close to up
if(hit.n.z < 0.8f)
return false;
// special case to stop stacking of claymores/mines (they are static so are hit by the ray)
if(hit.pCollider && hit.pCollider->GetiForeignData() == PHYS_FOREIGN_ID_ENTITY)
{
IEntity * pEntity = (IEntity*)hit.pCollider->GetForeignData(PHYS_FOREIGN_ID_ENTITY);
if(pEntity)
{
if(!m_pClaymoreClass)
m_pClaymoreClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass("claymoreexplosive");
if(!m_pAVMineClass)
m_pAVMineClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass("avexplosive");
if(pEntity->GetClass() == m_pClaymoreClass || pEntity->GetClass() == m_pAVMineClass)
return false;
}
}
// second check to see if there is another object in the way
float hitDist = hit.dist;
int res = gEnv->pPhysicalWorld->RayWorldIntersection(pos, 2.0f * dir, ent_all, flags, &hit, 1, pSkipEnts, nskip);
if(res && hit.dist < hitDist-0.1f)
{
return false;
}
pos = hit.pt;
}
}
return true;
}
示例12: Hit
//------------------------------------------------------------------------
void CMelee::Hit(const Vec3 &pt, const Vec3 &dir, const Vec3 &normal, IPhysicalEntity *pCollider, int partId, int ipart, int surfaceIdx, float damageScale, bool remote)
{
// generate the damage
IEntity *pTarget = gEnv->pEntitySystem->GetEntityFromPhysics(pCollider);
// Report punch to AI system.
// The AI notification must come before the game rules are
// called so that the death handler in AIsystem understands that the hit
// came from the player.
bool ok = true;
if(pTarget)
{
CActor *pActor = m_pWeapon->GetOwnerActor();
if(!gEnv->bMultiplayer && pActor && pActor->IsPlayer())
{
if (IActor *pAITarget = g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(pTarget->GetId()))
{
if (IAIObject *pAITargetObject = pTarget->GetAI())
{
if (pAITargetObject->IsFriendly(pActor->GetEntity()->GetAI(), false))
{
ok = false;
m_noImpulse = true;
}
}
}
}
if(ok)
{
CGameRules *pGameRules = g_pGame->GetGameRules();
HitInfo info(m_pWeapon->GetOwnerId(), pTarget->GetId(), m_pWeapon->GetEntityId(),
m_pShared->meleeparams.damage * damageScale * m_meleeScale, 0.0f, pGameRules->GetHitMaterialIdFromSurfaceId(surfaceIdx), partId,
pGameRules->GetHitTypeId(m_pShared->meleeparams.hit_type.c_str()), pt, dir, normal);
info.remote = remote;
pGameRules->ClientHit(info);
}
}
// play effects
if(ok)
{
if(IMaterialEffects *pMaterialEffects = gEnv->pGame->GetIGameFramework()->GetIMaterialEffects())
{
TMFXEffectId effectId = pMaterialEffects->GetEffectId("melee", surfaceIdx);
if (effectId != InvalidEffectId)
{
SMFXRunTimeEffectParams params;
params.pos = pt;
params.normal = -dir;
params.playflags = MFX_PLAY_ALL | MFX_DISABLE_DELAY;
params.soundSemantic = eSoundSemantic_Player_Foley;
pMaterialEffects->ExecuteEffect(effectId, params);
}
}
}
ApplyCameraShake(true);
m_pWeapon->PlayAction(m_pShared->meleeactions.hit.c_str());
}
示例13: SvOnHit
//------------------------------------------------------------------------
// returns true if entity is killed, false if it is not
bool CGameRulesMPDamageHandling::SvOnHit( const HitInfo &hitInfo )
{
const HitTypeInfo * pHitTypeInfo = m_pGameRules->GetHitTypeInfo(hitInfo.type);
#if !defined(_RELEASE)
if(!pHitTypeInfo)
CryFatalError("By ::SvOnHit() all hit info should have a hit type that is valid and registered in the GameRules. This isn't true of type %d!", hitInfo.type);
#endif
SDamageHandling damageHandling(&hitInfo, 1.0f);
float damage = hitInfo.damage;
IActorSystem* pActorSystem = g_pGame->GetIGameFramework()->GetIActorSystem();
CActor *pTargetActor = static_cast<CActor*>(pActorSystem->GetActor(hitInfo.targetId));
CActor *pShooterActor = static_cast<CActor*>(pActorSystem->GetActor(hitInfo.shooterId));
CPlayer* pShooterPlayer = (pShooterActor && pShooterActor->IsPlayer()) ? static_cast<CPlayer*>(pShooterActor) : NULL ;
bool isPlayer = pTargetActor != NULL && pTargetActor->IsPlayer();
#ifndef _RELEASE
//--- Fix to allow the damage handling to work for these entity classes in the same way as for Players
static IEntityClass* sDamEntClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass("DamageTestEnt");
isPlayer |= pTargetActor != NULL && pTargetActor->GetEntity()->GetClass() == sDamEntClass;
#endif
CPlayer* pPlayer = isPlayer ? static_cast<CPlayer*>(pTargetActor) : NULL;
const bool isMelee = ((pHitTypeInfo->m_flags & CGameRules::EHitTypeFlag::IsMeleeAttack) != 0);
const bool checkHeadshots = ((pHitTypeInfo->m_flags & CGameRules::EHitTypeFlag::IgnoreHeadshots) == 0);
bool bIsHeadShot = false;
if(pPlayer && hitInfo.partId >= 0 && checkHeadshots)
{
bIsHeadShot = pPlayer->IsHeadShot(hitInfo);
if (!bIsHeadShot && g_pGameCVars->g_mpHeadshotsOnly)
{
damage = 0.f;
}
}
//If the player has died more than kTimeToAllowKillsAfterDeath seconds ago, we disallow any damage they apply, unless the hit type is flagged as allowing it.
static const float kTimeToAllowKillsAfterDeath = 0.05f;
if(pTargetActor && pShooterPlayer && !hitInfo.hitViaProxy
&& ((pHitTypeInfo->m_flags & CGameRules::EHitTypeFlag::AllowPostDeathDamage) == 0) && pShooterActor->IsDead()
&& (gEnv->pTimer->GetFrameStartTime().GetSeconds() - pShooterPlayer->GetDeathTime()) > kTimeToAllowKillsAfterDeath)
{
damage = 0.0f;
}
IGameRulesStateModule *stateModule = m_pGameRules->GetStateModule();
IGameRulesRoundsModule* pRoundsModule = m_pGameRules->GetRoundsModule();
if ( (stateModule != NULL && (stateModule->GetGameState() == IGameRulesStateModule::EGRS_PostGame)) ||
(pRoundsModule!= NULL && !pRoundsModule->IsInProgress() ))
{
// No damage allowed once the game has ended, except in cases where it would cause graphical glitches
if (hitInfo.type != CGameRules::EHitType::PunishFall)
{
damage = 0.0f;
}
}
IEntity *pTarget = gEnv->pEntitySystem->GetEntity(hitInfo.targetId);
#if defined(SERVER_CHECKS)
if(damage != 0.0f)
{
int nNewCheckCounter = m_checkCounter + 1;
if (CItem *pItem = static_cast<CItem *>(g_pGame->GetIGameFramework()->GetIItemSystem()->GetItem(hitInfo.weaponId)))
{
if(CWeapon * pWeapon = static_cast<CWeapon*>(pItem->GetIWeapon()))
{
int nFireModeFromShotId = GetFireModeFromShotId(hitInfo.shotId);
static const int kCheckFreq = 7;
if(pShooterActor && nNewCheckCounter == kCheckFreq)
{
float fDamageAtXMeters = 0.0f;
float fDistance2D, fDistanceMax, fNetLagSeconds;
CServerCheatMonitor::GetHitValidationInfo(*pShooterActor, hitInfo, fDistance2D, fDistanceMax, fNetLagSeconds);
bool bDoDamageValidation = false;
if(isMelee)
{
if(CMelee * pMelee = pWeapon->GetMelee())
{
//This check can't be used for everything because the default firemode returns '0.f' for range and only CMelee extends it
// the horizontal player speed is x 2.0f as the players could have potentially immediately turned and run away from each other
float fMeleeRangeError = fDistance2D - (pMelee->GetRange() + (CServerCheatMonitor::kMaxHorizontalPlayerSpeed * fNetLagSeconds * 2.0f));
if(fMeleeRangeError > 0.1f)
{
g_pGame->GetAntiCheatManager()->FlagActivity(eCT_MeleeRange, pShooterActor->GetChannelId(), fMeleeRangeError);
//.........这里部分代码省略.........
示例14: RecalculateAwareness
void CAIAwarenessToPlayerHelper::RecalculateAwareness()
{
int highestAlertnessInGameRightNow = 0;
float distanceToTheClosestHostileAgentSq = FLT_MAX;
Vec3 playerPosition(ZERO);
const IFactionMap& factionMap = gEnv->pAISystem->GetFactionMap();
uint8 playerFactionID = factionMap.GetFactionID("Players");
IAIObject* playerAiObject = NULL;
CActor* playerActor = static_cast<CActor*>(gEnv->pGame->GetIGameFramework()->GetClientActor());
if (playerActor)
{
if (IEntity* playerEntity = playerActor->GetEntity())
{
playerPosition = playerEntity->GetWorldPos();
playerAiObject = playerEntity->GetAI();
}
}
IF_UNLIKELY ((playerActor == NULL) || (playerAiObject == NULL))
return;
const bool playerIsCloaked = playerActor ? playerActor->IsCloaked() : true;
const bool applyProximityToHostileAgentIncrement = m_actualAwareness < kAIAwarenessToPlayerAware && !playerPosition.IsZero();
// Go through actors
IActorIteratorPtr actorIt = gEnv->pGame->GetIGameFramework()->GetIActorSystem()->CreateActorIterator();
if (actorIt)
{
while (IActor* actor = actorIt->Next())
{
const IAIObject* ai = actor->GetEntity()->GetAI();
const IAIActor* aiActor = ai ? ai->CastToIAIActor() : NULL;
if (aiActor && aiActor->IsActive())
{
const int alertness = GetAlertnessAffectedByVisibility(*aiActor, *playerAiObject, playerIsCloaked);
highestAlertnessInGameRightNow = std::max(alertness, highestAlertnessInGameRightNow);
if (applyProximityToHostileAgentIncrement &&
factionMap.GetReaction(playerFactionID, ai->GetFactionID()) == IFactionMap::Hostile)
{
float distanceSq = playerPosition.GetSquaredDistance(ai->GetPos());
if (distanceToTheClosestHostileAgentSq > distanceSq)
{
distanceToTheClosestHostileAgentSq = distanceSq;
}
}
}
}
}
// Go through non Actors
{
SAwarenessEntitiesVector::iterator it = m_awarenessEntities.begin();
SAwarenessEntitiesVector::iterator end = m_awarenessEntities.end();
for (; it != end; ++it)
{
const IAwarenessEntity* pAwarenessEntity = *it;
const int awareness = pAwarenessEntity->GetAwarenessToActor( playerAiObject, playerActor );
highestAlertnessInGameRightNow = std::max(awareness, highestAlertnessInGameRightNow);
}
}
///
assert(highestAlertnessInGameRightNow >= 0 && highestAlertnessInGameRightNow <= 2);
switch (highestAlertnessInGameRightNow)
{
default:
{
const float thresholdDistanceSq = square(g_pGameCVars->ai_ProximityToHostileAlertnessIncrementThresholdDistance);
if (applyProximityToHostileAgentIncrement && distanceToTheClosestHostileAgentSq < thresholdDistanceSq)
{
m_actualAwareness = kAIAwarenessToPlayerAware * (1 - (distanceToTheClosestHostileAgentSq / thresholdDistanceSq));
}
else
{
m_actualAwareness = 0.0f;
}
}
break;
case 1: m_actualAwareness = kAIAwarenessToPlayerAware; break;
case 2: m_actualAwareness = kAIAwarenessToPlayerAlerted; break;
}
}
示例15: UpdateStowedWeapons
void CHandGrenades::UpdateStowedWeapons()
{
CActor *pOwnerActor = GetOwnerActor();
if (!pOwnerActor)
return;
ICharacterInstance *pOwnerCharacter = pOwnerActor->GetEntity()->GetCharacter(0);
if (!pOwnerCharacter)
return;
IStatObj *pTPObj = GetEntity()->GetStatObj(eIGS_ThirdPerson);
if (!pTPObj)
return;
int ammoCount = m_fm ? pOwnerActor->GetInventory()->GetAmmoCount(m_fm->GetAmmoType()) : 0;
if (IsSelected() && (ammoCount > 0))
{
ammoCount--;
}
if (!pOwnerActor->IsThirdPerson())
{
ammoCount = 0;
}
int numGrenDiff = ammoCount - m_numStowedCopies;
if(numGrenDiff != 0)
{
if (m_stowSlot < 0)
{
m_stowSlot = PickStowSlot(pOwnerCharacter->GetIAttachmentManager(), m_sharedparams->params.bone_attachment_01.c_str(), m_sharedparams->params.bone_attachment_02.c_str());
}
if (m_stowSlot >= 0)
{
bool attach = numGrenDiff > 0;
int tot = abs(numGrenDiff);
IAttachmentManager *pAttachmentManager = pOwnerCharacter->GetIAttachmentManager();
IAttachment *pAttachment = NULL;
for (int i=0; i<tot; i++)
{
//--- Generate the secondary slot from the first by adding one to the attachment name, is all we need at present...
const char *attach1 = (m_stowSlot == 0) ? m_sharedparams->params.bone_attachment_01.c_str() : m_sharedparams->params.bone_attachment_02.c_str();
int lenAttachName = strlen(attach1);
stack_string attach2(attach1, lenAttachName-1);
attach2 += (attach1[lenAttachName-1]+1);
if (attach)
{
pAttachment = pAttachmentManager->GetInterfaceByName(attach1);
if(pAttachment && pAttachment->GetIAttachmentObject())
{
pAttachment = pAttachmentManager->GetInterfaceByName(attach2);
}
if (pAttachment && !pAttachment->GetIAttachmentObject())
{
CCGFAttachment *pCGFAttachment = new CCGFAttachment();
pCGFAttachment->pObj = pTPObj;
pAttachment->AddBinding(pCGFAttachment);
pAttachment->HideAttachment(0);
pAttachment->HideInShadow(0);
m_numStowedCopies++;
}
}
else
{
pAttachment = pAttachmentManager->GetInterfaceByName(attach2);
if(!pAttachment || !pAttachment->GetIAttachmentObject())
{
pAttachment = pAttachmentManager->GetInterfaceByName(attach1);
}
if (pAttachment && pAttachment->GetIAttachmentObject())
{
pAttachment->ClearBinding();
m_numStowedCopies--;
}
}
}
}
}
}