本文整理汇总了C++中CGameRules::GetTeamCount方法的典型用法代码示例。如果您正苦于以下问题:C++ CGameRules::GetTeamCount方法的具体用法?C++ CGameRules::GetTeamCount怎么用?C++ CGameRules::GetTeamCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CGameRules
的用法示例。
在下文中一共展示了CGameRules::GetTeamCount方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CalculateFriendlyFireRatio
float CGameRulesMPDamageHandling::CalculateFriendlyFireRatio(EntityId entityId1, EntityId entityId2)
{
CGameRules *pGameRules = m_pGameRules;
if (entityId1 != entityId2 && pGameRules->GetTeamCount() > 1)
{
int team1 = pGameRules->GetTeam(entityId1);
if( team1 == pGameRules->GetTeam(entityId2) )
{
return pGameRules->GetFriendlyFireRatio();
}
}
//Not on same team so full damage
return 1.f;
}
示例2: IsFriendlyEntity
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;
}
示例3: IsFriendlyToClient
bool CHUDTagNames::IsFriendlyToClient(EntityId uiEntityId)
{
IActor *client = g_pGame->GetIGameFramework()->GetClientActor();
CGameRules *pGameRules = g_pGame->GetGameRules();
if(!client || !pGameRules)
return false;
int playerTeam = pGameRules->GetTeam(client->GetEntityId());
// if this actor is spectating, use the team of the player they are spectating instead...
if(static_cast<CActor*>(client)->GetSpectatorMode() == CActor::eASM_Follow)
{
playerTeam = pGameRules->GetTeam(static_cast<CActor*>(client)->GetSpectatorTarget());
}
// Less than 2 teams means we are in a FFA based game.
if(pGameRules->GetTeam(uiEntityId) == playerTeam && pGameRules->GetTeamCount() > 1)
return true;
return false;
}
示例4: Update
void CClaymore::Update(SEntityUpdateContext &ctx, int updateSlot)
{
CProjectile::Update(ctx, updateSlot);
bool debug = (g_pGameCVars->g_debugMines != 0);
if(gEnv->bServer)
{
if(m_armed)
{
CGameRules* pGR = g_pGame->GetGameRules();
if(pGR)
{
for(std::list<EntityId>::iterator it = m_targetList.begin(); it != m_targetList.end(); ++it)
{
IEntity* pEntity = gEnv->pEntitySystem->GetEntity(*it);
if(!pEntity) continue;
// if this is a team game, claymores aren't set off by their own team...
if(pGR->GetTeamCount() > 0 && (m_teamId != 0 && pGR->GetTeam(pEntity->GetId()) == m_teamId))
continue;
// otherwise, not set off by the player who dropped them.
if(pGR->GetTeamCount() == 0 && m_ownerId == pEntity->GetId())
continue;
IPhysicalEntity *pPhysics = pEntity->GetPhysics();
if(pPhysics)
{
pe_status_dynamics physStatus;
if(0 != pPhysics->GetStatus(&physStatus) && physStatus.v.GetLengthSquared() > 0.01f)
{
// now check angle between this claymore and approaching object
// to see if it is within the angular range m_triggerAngle.
// If it is, then check distance is less than m_triggerRange,
// and also check line-of-sight between the two entities.
IRenderAuxGeom * pRAG = gEnv->pRenderer->GetIRenderAuxGeom();
pRAG->SetRenderFlags( e_Mode3D | e_AlphaBlended | e_DrawInFrontOff | e_FillModeSolid | e_CullModeNone );
AABB entityBBox;
pEntity->GetWorldBounds(entityBBox);
if(debug)
{
pRAG->DrawAABB( entityBBox, true, ColorF(1,0,0,0.4f), eBBD_Faceted );
}
Vec3 enemyDir = entityBBox.GetCenter() - GetEntity()->GetPos();
Vec3 checkDir = enemyDir;
checkDir.z = 0;
float distanceSq = enemyDir.GetLengthSquared();
// for players a simple distance check is fine, but for vehicles use a better intersection check
// so any corner of the vehicle going inside the zone sets off the claymore.
static float playerRadius = 2.5f;
bool inside = false;
if(entityBBox.GetRadius() < playerRadius)
{
inside = (distanceSq < (m_triggerRadius * m_triggerRadius));
}
else
{
static ray_hit hit;
if(gEnv->pPhysicalWorld->CollideEntityWithBeam(pEntity->GetPhysics(), GetEntity()->GetWorldPos(), enemyDir, m_triggerRadius, &hit))
{
inside = true;
enemyDir = hit.pt - GetEntity()->GetWorldPos();
}
}
if(inside)
{
enemyDir.NormalizeSafe();
checkDir.NormalizeSafe();
float dotProd = checkDir.Dot(m_triggerDirection);
if(debug)
{
pRAG->DrawLine(GetEntity()->GetPos(), ColorF(1,0,0,1), GetEntity()->GetPos() + Matrix33::CreateRotationZ(m_triggerAngle/2.0f)*m_triggerDirection*m_triggerRadius, ColorF(1,0,0,1), 5.0f);
pRAG->DrawLine(GetEntity()->GetPos(), ColorF(1,0,0,1), GetEntity()->GetPos() + Matrix33::CreateRotationZ(-m_triggerAngle/2.0f)*m_triggerDirection*m_triggerRadius, ColorF(1,0,0,1), 5.0f);
ColorF clr;
clr.a = 0.3f;
clr.b = 0.4f;
clr.g = 0.1f;
clr.r = 1.0f;
pRAG->DrawLine(GetEntity()->GetPos(), clr, GetEntity()->GetPos() + (enemyDir * m_triggerRadius), clr, 5.0f);
}
if(dotProd > cry_cosf(m_triggerAngle/2.0f))
{
static const int objTypes = ent_all&(~ent_terrain);
static const unsigned int flags = rwi_stop_at_pierceable|rwi_colltype_any;
ray_hit hit;
int col = gEnv->pPhysicalWorld->RayWorldIntersection(GetEntity()->GetPos(), (enemyDir * m_triggerRadius * 1.5f), objTypes, flags, &hit, 1, GetEntity()->GetPhysics());
bool bang = false;
if (!col)
bang = true;
else if (entityBBox.IsContainPoint(hit.pt))
//.........这里部分代码省略.........
示例5: 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);
}
CPlayer *pPlayer=static_cast<CPlayer *>(pActor);
CNanoSuit *pSuit=pPlayer->GetNanoSuit();
if(m_fm && strcmp(m_fm->GetType(), "Repair"))
{
if(pSuit)
{
if (pSuit->GetMode() == NANOMODE_STRENGTH && !IsMounted())
pSuit->SetSuitEnergy(pSuit->GetSuitEnergy()-g_pGameCVars->g_suitRecoilEnergyCost);
else if(pSuit->GetMode() == NANOMODE_CLOAK)
pSuit->SetSuitEnergy(0.0f);
}
}
if (gEnv->bServer && pSuit && pSuit->IsInvulnerable())
pSuit->SetInvulnerability(false);
}
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(pGameRules->GetTeamCount() < 2 || (pGameRules->GetTeam(shooterId) != pGameRules->GetTeam(pClientActor->GetEntityId())))
{
//Small workaround for patch2...
IFireMode* pFM = GetFireMode(GetCurrentFireMode());
bool grenade = pFM?(pFM->GetAmmoType()==CItem::sScarGrenadeClass):false;
//~...
if (!IsSilencerAttached() || grenade)
{
SAFE_HUD_FUNC(GetRadar()->AddEntityTemporarily(shooterId, 5.0f));
}
else if(fDist2<5.0f*5.0f)
{
//Silencer attached
SAFE_HUD_FUNC(GetRadar()->AddEntityTemporarily(shooterId, 5.0f));
}
}
}
if ((!IsSilencerAttached()) && fDist2<sqr(SAFE_HUD_FUNC_RET(GetBattleRange())))
SAFE_HUD_FUNC(TickBattleStatus(1.0f));
}
}
}
示例6: SvOnCollision
//.........这里部分代码省略.........
if (timeSinceKick < lowestTime)
{
// We found the kicker and the kicked
kickerId = pActor->GetEntityId();
lowestTime = timeSinceKick;
}
}
pActor = pActorIterator->Next();
}
damage = ProcessActorKickedVehicle(victimActor, victimID, kickerId, offenderID, damage, collisionHitInfo);
useDefaultCalculation = false;
}
if (useDefaultCalculation)
{
fEnergy = GetCollisionEnergy(pVictimEntity, collisionHitInfo);
if (victimVehicle || offenderIsBig)
{
damage = 0.0005f * fEnergy;
}
else
{
damage = 0.0025f * fEnergy;
}
// Apply damage multipliers
damage *= GetCollisionDamageMult(pVictimEntity, pOffenderEntity, collisionHitInfo);
if (victimActor)
{
const bool victimIsPlayer = victimActor->IsPlayer();
if (victimIsPlayer)
{
damage = AdjustPlayerCollisionDamage(pVictimEntity, pOffenderEntity, collisionHitInfo, damage);
}
}
}
if (damage >= DAMAGE_THRESHOLD_COLLISIONS)
{
HitInfo hit;
hit.damage = damage;
hit.pos = collisionHitInfo.pos;
if (collisionHitInfo.target_velocity.GetLengthSquared() > 1e-6)
hit.dir = collisionHitInfo.target_velocity.GetNormalized();
hit.radius = 0.0f;
hit.partId = collisionHitInfo.partId;
hit.targetId = victimID;
hit.weaponId = offenderID;
hit.shooterId = kickerId != 0 ? kickerId : offenderID;
hit.material = 0;
hit.type = CGameRules::EHitType::Collision;
hit.explosion = false;
CGameRules *pGameRules = g_pGame->GetGameRules();
if (pGameRules->GetTeamCount() > 1)
{
int shooterTeamId = pGameRules->GetTeam(hit.shooterId);
int targetTeamId = pGameRules->GetTeam(hit.targetId);
if (shooterTeamId && (shooterTeamId == targetTeamId))
{
damage = GetFriendlyFireDamage(damage, hit, victimActor);
}
}
if (damage >= DAMAGE_THRESHOLD_COLLISIONS)
{
IScriptTable* pVictimScript = pVictimEntity ? pVictimEntity->GetScriptTable() : NULL;
IScriptTable* pOffenderScript = pOffenderEntity ? pOffenderEntity->GetScriptTable() : NULL;
if (!pOffenderEntity && pVictimEntity)
{
pOffenderEntity = pVictimEntity;
offenderID = victimID;
}
m_entityCollisionRecords[victimID] = EntityCollisionRecord(offenderID, currentTime);
if(victimVehicle)
{
victimVehicle->OnHit(hit);
}
else if (pVictimScript)
{
FRAME_PROFILER("Call to OnHit", gEnv->pSystem, PROFILE_GAME);
if (!IsDead(victimActor, pVictimScript))
{
if (IActor* offenderDriver = offenderVehicle ? offenderVehicle->GetDriver() : NULL)
hit.shooterId = offenderDriver->GetEntityId();
DelegateServerHit(pVictimScript, hit, victimActor);
}
}
}
}
}
}
示例7: ProcessActorKickedVehicle
float CGameRulesMPDamageHandling::ProcessActorKickedVehicle(IActor* victimActor, EntityId victimId, EntityId kickerId, EntityId vehicleId, float damage, const CGameRules::SCollisionHitInfo& collisionHitInfo)
{
float angSpeedSq = 0.f;
const IEntity* pVehicleEntity = gEnv->pEntitySystem->GetEntity(vehicleId);
if (pVehicleEntity)
{
IPhysicalEntity* pent = pVehicleEntity->GetPhysics();
if (pent)
{
pe_status_dynamics psd;
if (pent->GetStatus(&psd))
{
angSpeedSq = psd.w.GetLengthSquared();
}
}
}
const Vec3& actorVelocity = collisionHitInfo.velocity;
const Vec3& vehicleVelocity = collisionHitInfo.target_velocity;
const float vehicleSpeedSq = vehicleVelocity.GetLengthSquared() + angSpeedSq;
if (vehicleSpeedSq < 1.5f)
return 0.f;
float damageScale = 1.f;
if (g_pGameCVars->g_mpKickableCars)
{
if (kickerId==victimId || FindKickableCarRecord(vehicleId, victimId))
return 0.f;
CGameRules *pGameRules = g_pGame->GetGameRules();
if (pGameRules->GetTeamCount() > 1)
{
int kickerTeamId = pGameRules->GetTeam(kickerId);
int victimTeamId = pGameRules->GetTeam(victimId);
if (kickerTeamId==victimTeamId) // Friendly fire
{
float friendlyFireRatio = pGameRules->GetFriendlyFireRatio();
if (friendlyFireRatio>0.f)
{
damageScale = friendlyFireRatio;
}
else
{
return 0.f;
}
}
}
InsertKickableCarRecord(vehicleId, victimId);
}
// Damage, for now, is based purely on vehicle speed
const float vehicleKillSpeed = m_vehicleDamageSettings.killSpeed;
const float invVehicleKillSpeed = 1.f/(vehicleKillSpeed+0.01f);
const float maxActorHealth = victimActor->GetMaxHealth();
damage = 0.1f + sqrtf(vehicleSpeedSq+0.04f) * invVehicleKillSpeed;
damage = min(damage, 1.f) * maxActorHealth * damageScale;
return damage;
}
示例8: TargetAimAssistance
void CPlayerRotation::TargetAimAssistance(CWeapon* pWeapon, float& followH, float& followV, float& scale, float& _fZoomAmount, const Vec3 playerView[4])
{
FUNCTION_PROFILER(GetISystem(), PROFILE_GAME);
CRY_ASSERT(m_player.IsClient());
followH = 0.0f;
followV = 0.0f;
scale = 1.0f;
float bestScale = 1.0f;
const Vec3 playerFwd = playerView[1];
const Vec3 playerRgt = playerView[0];
const Vec3 playerUp = playerView[2];
const Vec3 playerPos = playerView[3];
Vec3 follow_target_pos(ZERO);
float follow_vote_leader = 0.0f;
float snap_vote_leader = 0.0f;
Vec3 follow_target_dir(ZERO);
Vec3 snap_target_dir(ZERO);
EntityId follow_target_id = 0;
EntityId snap_target_id = 0;
CGameRules * pGameRules = g_pGame->GetGameRules();
float distance_follow_threshold_near = max(0.0f, g_pGameCVars->aim_assistMinDistance);
float distance_follow_threshold_far = max(20.0f, g_pGameCVars->aim_assistMaxDistance);
int playerTeam = pGameRules->GetTeam(m_player.GetEntity()->GetId());
float cloakedPlayerMultiplier = g_pGameCVars->pl_aim_cloaked_multiplier;
const bool multipleTeams = pGameRules->GetTeamCount() > 0;
const float fFollowFalloffDist = g_pGameCVars->aim_assistFalloffDistance + FLT_EPSILON*g_pGameCVars->aim_assistFalloffDistance;
const bool playerIsScoped = m_player.GetActorStats()->isScoped;
float minTurnScale, fAimAssistStrength, fMaxDistMult;
if(pWeapon)
{
const float fZoomAmount = pWeapon->GetZoomTransition();
_fZoomAmount = fZoomAmount;
const float fStrength = g_pGameCVars->aim_assistStrength;
const float fStrengthIronSight = playerIsScoped ? g_pGameCVars->aim_assistStrength_SniperScope : g_pGameCVars->aim_assistStrength_IronSight;
const float fDiff = fStrengthIronSight - fStrength;
fAimAssistStrength = fStrength + (fZoomAmount * fDiff);
const float fMinTurn = g_pGameCVars->aim_assistMinTurnScale;
const float fMinTurnIronSight = playerIsScoped ? g_pGameCVars->aim_assistMinTurnScale_SniperScope : g_pGameCVars->aim_assistMinTurnScale_IronSight;
const float fMinTurnDiff = fMinTurnIronSight - fMinTurn;
minTurnScale = fMinTurn + (fZoomAmount * fMinTurnDiff);
const float fMaxAssistDist = g_pGameCVars->aim_assistMaxDistance;
const float fMaxAssistDist_Iron = playerIsScoped ? g_pGameCVars->aim_assistMaxDistance_SniperScope : g_pGameCVars->aim_assistMaxDistance_IronSight;
const float fMaxAssistDistDiff = (fMaxAssistDist_Iron - fMaxAssistDist) * fZoomAmount;
fMaxDistMult = (fMaxAssistDist + fMaxAssistDistDiff) * __fres(fMaxAssistDist);
}
else
{
_fZoomAmount = 0.0f;
fMaxDistMult = 1.0f;
fAimAssistStrength = g_pGameCVars->aim_assistStrength;
minTurnScale = g_pGameCVars->aim_assistMinTurnScale;
}
const float falloffStartDistance = g_pGameCVars->aim_assistSlowFalloffStartDistance;
const float falloffPerMeter = 1.0f / (g_pGameCVars->aim_assistSlowDisableDistance - falloffStartDistance);
const TAutoaimTargets& aaTargets = g_pGame->GetAutoAimManager().GetAutoAimTargets();
const int targetCount = aaTargets.size();
float fBestTargetDistance = FLT_MAX;
#if DBG_AUTO_AIM
SAuxGeomRenderFlags oldFlags = gEnv->pRenderer->GetIRenderAuxGeom()->GetRenderFlags();
SAuxGeomRenderFlags newFlags = e_Def3DPublicRenderflags;
newFlags.SetAlphaBlendMode(e_AlphaBlended);
newFlags.SetDepthTestFlag(e_DepthTestOff);
newFlags.SetCullMode(e_CullModeNone);
gEnv->pRenderer->GetIRenderAuxGeom()->SetRenderFlags(newFlags);
#endif
for (int i = 0; i < targetCount; ++i)
{
const SAutoaimTarget& target = aaTargets[i];
CRY_ASSERT(target.entityId != m_player.GetEntityId());
//Skip friendly ai
if(gEnv->bMultiplayer)
{
if(multipleTeams && (pGameRules->GetTeam(target.entityId) == playerTeam))
{
continue;
}
}
else
{
if (target.HasFlagSet(eAATF_AIHostile) == false)
continue;
distance_follow_threshold_far = fMaxDistMult * (target.HasFlagSet(eAATF_AIRadarTagged) ? g_pGameCVars->aim_assistMaxDistanceTagged : g_pGameCVars->aim_assistMaxDistance);
//.........这里部分代码省略.........
示例9: GetTalosInput
static void GetTalosInput(CPlayerRotation * pPlayerRotation, const CPlayer& rPlayer, float& x, float& z, const Vec3 playerView[4], float fFrameTime)
{
//Do I need to reproject the view to actually get the positioning correct? Shouldn't be.
const Vec3 playerFwd = playerView[1];
const Vec3 playerRgt = playerView[0];
const Vec3 playerUp = playerView[2];
const Vec3 playerViewPos = playerView[3];
Vec3 playerPos = playerViewPos;
IPhysicalEntity * pPhysicalEntity = rPlayer.GetEntity()->GetPhysics();
if(pPhysicalEntity)
{
pe_status_dynamics dyn_status;
pPhysicalEntity->GetStatus(&dyn_status);
playerPos = playerViewPos + (dyn_status.v * fFrameTime * 2.0f);
}
Vec3 follow_target_dir(ZERO);
EntityId follow_target_id = 0;
static EntityId s_follow_target_id = 0;
CGameRules * pGameRules = g_pGame->GetGameRules();
int playerTeam = pGameRules->GetTeam(rPlayer.GetEntity()->GetId());
float cloakedPlayerMultiplier = g_pGameCVars->pl_aim_cloaked_multiplier;
const bool multipleTeams = pGameRules->GetTeamCount() > 0;
const TAutoaimTargets& aaTargets = g_pGame->GetAutoAimManager().GetAutoAimTargets();
const int targetCount = aaTargets.size();
float fBestTargetDistance = FLT_MAX;
for (int i = 0; i < targetCount; ++i)
{
const SAutoaimTarget& target = aaTargets[i];
if(multipleTeams && (pGameRules->GetTeam(target.entityId) == playerTeam))
{
continue;
}
Vec3 targetPos = target.secondaryAimPosition;
IEntity * pEntity = gEnv->pEntitySystem->GetEntity(target.entityId);
if(pEntity)
{
IPhysicalEntity * pPhysicalEntity2 = pEntity->GetPhysics();
if(pPhysicalEntity2)
{
pe_status_dynamics dyn_status;
pPhysicalEntity2->GetStatus(&dyn_status);
targetPos = targetPos + (dyn_status.v * fFrameTime);
}
}
Vec3 targetDistVec = (targetPos - playerPos);
float distance = targetDistVec.GetLength();
if (distance <= 0.01f)
continue;
Vec3 dirToTarget = targetDistVec / distance;
// fast reject everything behind player, too far away or too near from line of view
// sort rest by angle to crosshair and distance from player
const int kAutoaimVisibilityLatency = 1;
if (!g_pGame->GetPlayerVisTable()->CanLocalPlayerSee(target.entityId, kAutoaimVisibilityLatency))
{
// Since both player and target entities are ignored, and the ray still intersected something, there's something in the way.
// Need to profile this and see if it's faster to do the below checks before doing the linetest. It's fairly expensive but
// linetests generally are as well... - Richard
continue;
}
const float angleDot = dirToTarget.dot(-playerRgt);
const float angle = (RAD2DEG(acos_tpl(angleDot)) - 90.f);
const float absAngle = fabsf(angle);
const float angleDotV = playerUp.dot(dirToTarget);
const float angleToTargetV = (RAD2DEG(acos_tpl(angleDotV)) - 90.f);
const float absAngleV = fabsf(angleToTargetV);
if ( s_follow_target_id == target.entityId )
{
follow_target_id = target.entityId;
follow_target_dir = dirToTarget;
break;
}
else if(distance < fBestTargetDistance)
{
fBestTargetDistance = distance;
follow_target_id = target.entityId;
follow_target_dir = dirToTarget;
}
}
if(follow_target_id != 0)
{
//.........这里部分代码省略.........
示例10: Update
//-------------------------------------------------------------------------
void CGameRulesStandardState::Update( float frameTime )
{
if (gEnv->bServer)
{
if(m_state == EGRS_Intro)
{
// We assume there is an intro, if we reach this point and an intro hasnt been registered, we know there isn't one. Onwards and upwards.
if(!m_pGameRules->IsIntroSequenceRegistered())
{
ChangeState(EGRS_PreGame);
}
}
if (m_state == EGRS_PreGame)
{
if (m_isStarting)
{
const float remainingTime = m_pGameRules->GetRemainingStartTimer();
if (remainingTime <= 0.f)
{
CryLog("CGameRulesStandardState::Update(), starting game");
ChangeState(EGRS_InGame);
}
}
else
{
bool bOk = true;
CGameLobby* pGameLobby = g_pGame->GetGameLobby();
const int numPlayers = m_pGameRules->GetPlayerCount(true);
if (pGameLobby)
{
if (m_isWaitingForOverrideTimer)
{
//-- test override timer
m_startTimerOverrideWait -= frameTime;
bOk = (m_startTimerOverrideWait <= 0.0f);
if (!bOk)
{
bOk = true;
//-- testing min player count doesn't apply to private games
const bool publicGame = !pGameLobby->IsPrivateGame();
const bool onlineGame = pGameLobby->IsOnlineGame();
if (publicGame && onlineGame)
{
// Start only when we have enough players
if (m_pGameRules->GetTeamCount() > 1)
{
//-- team game, insist at least 1 player per team
const int numPlayersPerTeamMin = g_pGameCVars->g_gameRules_startTimerMinPlayersPerTeam;
const int numPlayersTeam1 = m_pGameRules->GetTeamPlayerCount(1, true);
const int numPlayersTeam2 = m_pGameRules->GetTeamPlayerCount(2, true);
bOk = ((numPlayersTeam1 >= numPlayersPerTeamMin) && (numPlayersTeam2 >= numPlayersPerTeamMin));
}
else
{
//-- not a team game, so just insist on minimum 2 players
const int numPlayersMin = g_pGameCVars->g_gameRules_startTimerMinPlayers;
bOk = (numPlayers >= numPlayersMin);
}
const int numPlayersInLobby = pGameLobby->GetSessionNames().Size();
bOk |= (numPlayersInLobby == numPlayers);
}
if (bOk)
{
//-- Enforce a percentage of lobby players in game before starting countdown
bOk = (!gEnv->IsClient() || (g_pGame->GetClientActorId() != 0)) && CheckInitialChannelPlayers();
}
}
}
else
{
bOk = false;
if (numPlayers)
{
//-- Start the override timer.
m_startTimerOverrideWait = g_pGameCVars->g_gameRules_startTimerOverrideWait;
m_isWaitingForOverrideTimer = true;
}
}
}
if (bOk)
{
CryLog("CGameRulesStandardState::Update(), we have %i players, starting the game", numPlayers);
float startTimeLength =
#if !defined(_RELEASE)
g_pGameCVars->g_gameRules_skipStartTimer ? 0.0f :
#endif
g_pGameCVars->g_gameRules_startTimerLength;
#if USE_PC_PREMATCH
bool bDoPCPrematch = false;
//.........这里部分代码省略.........
示例11: ProcessEvent
void CAVMine::ProcessEvent(SEntityEvent &event)
{
if (m_frozen)
return;
switch(event.event)
{
case ENTITY_EVENT_ENTERAREA:
{
IEntity * pEntity = gEnv->pEntitySystem->GetEntity(event.nParam[0]);
CGameRules* pGR = g_pGame->GetGameRules();
if(pEntity && pGR)
{
// if this is a team game, mines aren't set off by their own team
if(pGR->GetTeamCount() > 0 && (m_teamId != 0 && pGR->GetTeam(pEntity->GetId()) == m_teamId))
break;
// otherwise, not set off by the player who dropped them.
if(pGR->GetTeamCount() == 0 && m_ownerId == pEntity->GetId())
break;
// or a vehicle that player might happen to be in
IVehicle* pVehicle = g_pGame->GetIGameFramework()->GetIVehicleSystem()->GetVehicle(event.nParam[0]);
if(pVehicle && pVehicle->GetSeatForPassenger(m_ownerId))
break;
IPhysicalEntity *pPhysics = pEntity->GetPhysics();
if(pPhysics)
{
pe_status_dynamics physStatus;
if(0 != pPhysics->GetStatus(&physStatus))
{
// only count moving objects
if(physStatus.v.GetLengthSquared() > 0.1f)
m_currentWeight += physStatus.mass;
if (m_currentWeight > m_triggerWeight)
Explode(true);
}
}
}
break;
}
case ENTITY_EVENT_LEAVEAREA:
{
IEntity * pEntity = gEnv->pEntitySystem->GetEntity(event.nParam[0]);
if(pEntity)
{
IPhysicalEntity *pPhysics = pEntity->GetPhysics();
if(pPhysics)
{
pe_status_dynamics physStatus;
if(0 != pPhysics->GetStatus(&physStatus))
{
m_currentWeight -= physStatus.mass;
if(m_currentWeight < 0)
m_currentWeight = 0;
}
}
}
break;
}
default:
break;
}
return CProjectile::ProcessEvent(event);
}
示例12: ProcessEvent
void CAVMine::ProcessEvent(SEntityEvent &event)
{
if (m_frozen)
return;
switch(event.event)
{
case ENTITY_EVENT_ENTERAREA:
{
IEntity * pEntity = gEnv->pEntitySystem->GetEntity((EntityId)event.nParam[0]);
CGameRules* pGR = g_pGame->GetGameRules();
if(pEntity && pGR)
{
// if this is a team game, mines aren't set off by their own team
if(pGR->GetTeamCount() > 0 && (m_teamId != 0 && pGR->GetTeam(pEntity->GetId()) == m_teamId))
break;
IPhysicalEntity *pPhysics = pEntity->GetPhysics();
if(pPhysics)
{
pe_status_dynamics physStatus;
if(0 != pPhysics->GetStatus(&physStatus))
{
// only count moving objects
if(physStatus.v.GetLengthSquared() > 0.1f)
m_currentWeight += physStatus.mass;
if (m_currentWeight > m_triggerWeight)
Explode(true);
}
}
}
break;
}
case ENTITY_EVENT_LEAVEAREA:
{
IEntity * pEntity = gEnv->pEntitySystem->GetEntity((EntityId)event.nParam[0]);
if(pEntity)
{
IPhysicalEntity *pPhysics = pEntity->GetPhysics();
if(pPhysics)
{
pe_status_dynamics physStatus;
if(0 != pPhysics->GetStatus(&physStatus))
{
m_currentWeight -= physStatus.mass;
if(m_currentWeight < 0)
m_currentWeight = 0;
}
}
}
break;
}
default:
break;
}
return CProjectile::ProcessEvent(event);
}
示例13: Update
void CHUDTagNames::Update()
{
CActor *pClientActor = static_cast<CActor *>(g_pGame->GetIGameFramework()->GetClientActor());
CGameRules *pGameRules = g_pGame->GetGameRules();
if(!pClientActor || !pGameRules || !gEnv->bMultiplayer)
return;
int iClientTeam = pGameRules->GetTeam(pClientActor->GetEntityId());
// Skip enemies, they need to be added only when shot
// (except in spectator mode when we display everyone)
for(int iTeam = 0; iTeam < pGameRules->GetTeamCount() + 1; ++iTeam)
{
if((iTeam == iClientTeam) || (pClientActor->GetSpectatorMode() != CActor::eASM_None))
{
int iTeamPlayerCount = pGameRules->GetTeamPlayerCount(iTeam);
for(int iPlayer=0; iPlayer<iTeamPlayerCount; iPlayer++)
{
IActor *pActor = g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(pGameRules->GetTeamPlayer(iTeam,iPlayer));
if(!pActor)
continue;
// Never display the local player
if(pActor == pClientActor)
continue;
// never display other spectators
if(static_cast<CActor*>(pActor)->GetSpectatorMode() != CActor::eASM_None)
continue;
// never display the name of the player we're spectating (it's shown separately with their current health)
if(pClientActor->GetSpectatorMode() == CActor::eASM_Follow && pClientActor->GetSpectatorTarget() == pActor->GetEntityId())
continue;
DrawTagName(pActor);
}
}
}
IVehicleSystem *pVehicleSystem = gEnv->pGame->GetIGameFramework()->GetIVehicleSystem();
if(!pVehicleSystem)
return;
IVehicleIteratorPtr pVehicleIter = pVehicleSystem->CreateVehicleIterator();
while(IVehicle *pVehicle=pVehicleIter->Next())
{
SVehicleStatus rVehicleStatus = pVehicle->GetStatus();
if(0 == rVehicleStatus.passengerCount)
continue;
// Skip enemy vehicles, they need to be added only when shot (except in spectator mode...)
bool bEnemyVehicle = true;
for(int iSeatId=1; iSeatId<=pVehicle->GetLastSeatId(); iSeatId++)
{
IVehicleSeat *pVehicleSeat = pVehicle->GetSeatById(iSeatId);
if(!pVehicleSeat)
continue;
EntityId uiEntityId = pVehicleSeat->GetPassenger();
if(0 == iClientTeam)
{
if(uiEntityId && IsFriendlyToClient(uiEntityId))
{
bEnemyVehicle = false;
}
}
else if(uiEntityId && pGameRules->GetTeam(uiEntityId) == iClientTeam)
{
bEnemyVehicle = false;
}
}
if(bEnemyVehicle && (pClientActor->GetSpectatorMode() == CActor::eASM_None)) // again, draw enemies in spectator mode
continue;
DrawTagName(pVehicle);
}
// don't need to do any of this if we're in spectator mode - all player names will have been drawn above.
if(pClientActor->GetSpectatorMode() == CActor::eASM_None)
{
for(TEnemyTagNamesList::iterator iter=m_enemyTagNamesList.begin(); iter!=m_enemyTagNamesList.end(); ++iter)
{
SEnemyTagName *pEnemyTagName = &(*iter);
if(gEnv->pTimer->GetAsyncTime().GetSeconds() >= pEnemyTagName->fSpawnTime+((float) g_pGameCVars->hud_mpNamesDuration))
{
// Note: iter=my_list.erase(iter) may not be standard/safe
TEnemyTagNamesList::iterator iterNext = iter;
++iterNext;
m_enemyTagNamesList.erase(iter);
iter = iterNext;
}
else
{
IActor *pActor = g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(pEnemyTagName->uiEntityId);
if(pActor)
DrawTagName(pActor);
IVehicle *pVehicle = gEnv->pGame->GetIGameFramework()->GetIVehicleSystem()->GetVehicle(pEnemyTagName->uiEntityId);
//.........这里部分代码省略.........