本文整理汇总了C++中CActor::GetHealth方法的典型用法代码示例。如果您正苦于以下问题:C++ CActor::GetHealth方法的具体用法?C++ CActor::GetHealth怎么用?C++ CActor::GetHealth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CActor
的用法示例。
在下文中一共展示了CActor::GetHealth方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AdjustPlayerCollisionDamage
//------------------------------------------------------------------------
float CGameRulesMPDamageHandling::AdjustPlayerCollisionDamage(const IEntity *pEntity, const IEntity *pCollider, const CGameRules::SCollisionHitInfo& colHitInfo, float colInfo_damage)
{
float result = colInfo_damage;
if (colHitInfo.target_velocity.len() == 0.f)
{
result = colInfo_damage * 0.2f;
}
CActor *pEntityActor = static_cast<CActor*>(g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(pEntity->GetId()));
if (pEntityActor)
{
float healthThreshold = (float)g_pGameCVars->pl_health.collision_health_threshold;
float currentHealth = pEntityActor->GetHealth();
if (currentHealth <= healthThreshold)
{
result = 0.f;
}
else if ((currentHealth - result) < healthThreshold)
{
result = currentHealth - healthThreshold;
}
}
return result;
}
示例2: GetHealth
//------------------------------------------------------------------------
int CScriptBind_Actor::GetHealth(IFunctionHandler *pH)
{
CActor *pActor = GetActor(pH);
if (!pActor)
return pH->EndFunction();
if (pActor)
return pH->EndFunction(pActor->GetHealth());
return pH->EndFunction();
}
示例3: Drop
//========================================
void CRocketLauncher::Drop(float impulseScale, bool selectNext, bool byDeath)
{
CActor* pOwner = GetOwnerActor();
//Don't let the player drop it if it has not been opened
if(m_stats.first_selection && pOwner && pOwner->IsPlayer() && pOwner->GetHealth()>0 && !byDeath)
return;
if(pOwner && !pOwner->IsPlayer())
{
//In this case goes to the clip, no the inventory
for(TAmmoMap::const_iterator it = m_minDroppedAmmo.begin();it!=m_minDroppedAmmo.end();it++)
m_ammo[it->first] = it->second;
m_minDroppedAmmo.clear();
}
PlayAction(g_pItemStrings->deselect);
GetScheduler()->TimerAction(GetCurrentAnimationTime(eIGS_FirstPerson), CSchedulerAction<EndDropAction>::Create(EndDropAction(this)), true);
}
示例4: ProcessServerHit
//------------------------------------------------------------------------
void CGameRules::ProcessServerHit(const HitInfo &hitInfo)
{
bool ok=true;
// check if shooter is alive
CActor *pShooter = GetActorByEntityId(hitInfo.shooterId);
CActor *pTarget = GetActorByEntityId(hitInfo.targetId);
if (hitInfo.shooterId)
{
if (pShooter && pShooter->GetHealth()<=0)
ok=false;
}
if (hitInfo.targetId)
{
if (pTarget && pTarget->GetSpectatorMode())
ok=false;
}
if (ok)
{
float fTargetHealthBeforeHit = 0.0f;
if(pTarget)
{
fTargetHealthBeforeHit = pTarget->GetHealth();
}
CreateScriptHitInfo(m_scriptHitInfo, hitInfo);
CallScript(m_serverStateScript, "OnHit", m_scriptHitInfo);
if(pTarget && !pTarget->IsDead())
{
const float fCausedDamage = fTargetHealthBeforeHit - pTarget->GetHealth();
ProcessLocalHit(hitInfo, fCausedDamage);
}
// 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]->OnHit(hitInfo);
if (count == m_hitListeners.size())
i++;
else
continue;
}
}
if (pShooter && hitInfo.shooterId!=hitInfo.targetId && hitInfo.weaponId!=hitInfo.shooterId && hitInfo.weaponId!=hitInfo.targetId && hitInfo.damage>=0)
{
EntityId params[2];
params[0] = hitInfo.weaponId;
params[1] = hitInfo.targetId;
m_pGameplayRecorder->Event(pShooter->GetEntity(), GameplayEvent(eGE_WeaponHit, 0, 0, (void *)params));
}
if (pShooter)
m_pGameplayRecorder->Event(pShooter->GetEntity(), GameplayEvent(eGE_Hit, 0, 0, (void *)hitInfo.weaponId));
if (pShooter)
m_pGameplayRecorder->Event(pShooter->GetEntity(), GameplayEvent(eGE_Damage, 0, hitInfo.damage, (void *)hitInfo.weaponId));
}
}
示例5: OnRecordedGameplayEvent
void CGameStateRecorder::OnRecordedGameplayEvent(IEntity *pEntity, const GameplayEvent &event, int currentFrame, bool bRecording)
{
EntityId id;
m_currentFrame = currentFrame;
int demo_forceGameState = 0;
if(!bRecording)
{
ICVar *pVar = gEnv->pConsole->GetCVar( "demo_force_game_state" );
if(pVar)
demo_forceGameState = pVar->GetIVal();
}
if(!pEntity || !(id = pEntity->GetId()))
return;
if(m_IgnoredEvents.size())
if(event.event == m_IgnoredEvents[0])
{
m_IgnoredEvents.erase(m_IgnoredEvents.begin());
return;
}
TGameStates::iterator itActor = m_GameStates.find(id);
if(itActor == m_GameStates.end())
{
m_GameStates.insert(std::make_pair(id,SActorGameState()));
itActor = m_GameStates.find(id);
}
if(itActor == m_GameStates.end())
{
GameWarning("TimeDemo:GameState: actor %s not found in records",pEntity->GetName());
return;
}
SActorGameState& gstate = itActor->second;
switch(event.event)
{
case eGE_HealthChanged:
{
gstate.health = event.value;
if(!m_bRecording)
{
CActor *pActor = (CActor*)(gEnv->pGame->GetIGameFramework()->GetIActorSystem()->GetActor(id));
if(pActor)
{
if(m_bLogWarning)
{
if(CHECK_MISMATCH(pActor->GetHealth(), gstate.health,10))
{
if(!gstate.bHealthDifferent)
{
GameWarning("TimeDemo:GameState: Frame %d - Actor %s - HEALTH mismatch (%d, %d)",m_currentFrame,pEntity->GetName(), static_cast<int>(pActor->GetHealth()), static_cast<int>(gstate.health));
gstate.bHealthDifferent = true;
}
}
else
gstate.bHealthDifferent = false;
}
if( demo_forceGameState)
pActor->SetHealth(gstate.health);
}
}
}
break;
case eGE_WeaponFireModeChanged:
{
TItemName sel = (event.description);
if(sel)
{
TItemContainer& Items = gstate.Items;
TItemContainer::iterator iti = Items.find(sel);
uint8 recFireModeIdx = uint8(event.value);
if(iti != Items.end())
iti->second.fireMode = recFireModeIdx;
CActor *pActor = (CActor*)(gEnv->pGame->GetIGameFramework()->GetIActorSystem()->GetActor(id));
if(pActor && pActor->GetInventory())
{
IItem* pItem = pActor->GetInventory()->GetItemByName(sel);
CWeapon* pWeapon;
if(pItem && (pWeapon = (CWeapon*)(pItem->GetIWeapon())))
{
int fireModeIdx = pWeapon->GetCurrentFireMode();
if(m_bLogWarning)
{
CheckDifference(recFireModeIdx,fireModeIdx,"TimeDemo:GameState: Frame %d - Actor %s - FIRE MODE mismatch for weapon %s (rec:%d, cur:%d)",pEntity,pItem->GetEntity() ? pItem->GetEntity()->GetName() : "(null)");
}
if(demo_forceGameState==2 && fireModeIdx!= recFireModeIdx)
pWeapon->SetCurrentFireMode(recFireModeIdx);
}
}
}
}
//.........这里部分代码省略.........
示例6: RenderInfo
float CGameStateRecorder::RenderInfo(float y, bool bRecording)
{
float retY = 0;
IRenderer *pRenderer = gEnv->pRenderer;
if (bRecording)
{
float fColor[4] = {1,0,0,1};
pRenderer->Draw2dLabel( 1,y+retY, 1.3f, fColor,false," Recording game state");
retY +=15;
}
else
{
const float xp = 300;
const float xr = 400;
const float xri = 600;
float fColor[4] = {0,1,0,1};
float fColorWarning[4] = {1,1,0,1};
const char* actorName = m_demo_actorInfo->GetString();
CActor *pActor = GetActorOfName(actorName);
if(pActor)
{
pRenderer->Draw2dLabel( 1,y+retY, 1.3f, fColor,false," Game state - Actor: %s --------------------------------------------------",pActor->GetEntity()? pActor->GetEntity()->GetName(): "(no entity)");
retY +=15;
if(m_itSingleActorGameState != m_GameStates.end() && pActor->GetEntity() && m_itSingleActorGameState->first == pActor->GetEntity()->GetId())
{
ICVar *pVar = gEnv->pConsole->GetCVar( "demo_force_game_state" );
if(pVar)
{
int demo_forceGameState = pVar->GetIVal();
if(demo_forceGameState)
{
pRenderer->Draw2dLabel( 1,y+retY, 1.3f, fColor,false,demo_forceGameState==1 ?
" Override mode = (health, suit energy)" : " Override mode = (all)");
retY +=15;
}
}
pRenderer->Draw2dLabel( xp,y+retY, 1.3f, fColor,false,"Current");
pRenderer->Draw2dLabel( xr,y+retY, 1.3f, fColor,false,"Recorded");
retY +=15;
SActorGameState& gstate = m_itSingleActorGameState->second;
float recordedHealth = (float)gstate.health;
float health = (float)pActor->GetHealth();
bool bError = CHECK_MISMATCH(health, recordedHealth,10);
pRenderer->Draw2dLabel( 1,y+retY, 1.3f, fColor,false," Health:");
pRenderer->Draw2dLabel( xp,y+retY, 1.3f, bError? fColorWarning : fColor, false,"%d",(int)health);
pRenderer->Draw2dLabel( xr,y+retY, 1.3f, bError? fColorWarning : fColor, false,"%d",(int)recordedHealth);
retY +=15;
// items
pRenderer->Draw2dLabel( 1,y+retY, 1.3f, fColor,false," Inventory ---------------------------------------------------------------------------------------");
retY +=15;
pRenderer->Draw2dLabel( xp,y+retY, 1.3f, fColor,false,"Current");
pRenderer->Draw2dLabel( xri,y+retY, 1.3f, fColor,false,"Recorded");
retY +=15;
CInventory *pInventory = (CInventory*)(pActor->GetInventory());
if(pInventory)
{
int nInvItems = pInventory->GetCount();
TItemContainer& Items = gstate.Items;
int nRecItems = Items.size();
int maxItems = max(nRecItems,nInvItems);
int i=0;
EntityId curSelectedId = pActor->GetCurrentItemId();
TItemName curSelClass = GetItemName(curSelectedId);
bool bSelectedError = !equal_strings(gstate.itemSelected,curSelClass);
for(; i< nInvItems; i++)
{
IItem *pItem = g_pGame->GetIGameFramework()->GetIItemSystem()->GetItem(pInventory->GetItem(i));
if(pItem)
{
TItemName szItemName = GetItemName(pItem->GetEntityId());
TItemContainer::iterator it = Items.find(szItemName);
bError = it==Items.end();
pRenderer->Draw2dLabel( 1,y+retY, 1.3f, fColor,false," %2d)",i+1);
EntityId curId = pItem->GetEntityId();
TItemName curClass = GetItemName(curId);
if(equal_strings(curClass,curSelClass) )
pRenderer->Draw2dLabel( xp-16,y+retY, 1.3f,bSelectedError ? fColorWarning:fColor, false, "[]");
if(equal_strings(szItemName, gstate.itemSelected))
pRenderer->Draw2dLabel( xri-16,y+retY, 1.3f,bSelectedError ? fColorWarning:fColor, false, "[]");
char itemName[32];
const char* originalItemName = pItem->GetEntity() ? pItem->GetEntity()->GetName():"(null)";
int length = strlen(originalItemName);
length = min(length,31);
//.........这里部分代码省略.........
示例7: if
//-----------------------------------------------
//This function is only executed on the server
void CC4Projectile::Stick(EventPhysCollision *pCollision)
{
assert(pCollision);
int trgId = 1;
IPhysicalEntity *pTarget = pCollision->pEntity[trgId];
if(pTarget == GetEntity()->GetPhysics())
{
trgId = 0;
pTarget = pCollision->pEntity[trgId];
}
//Do not stick to breakable glass
if(ISurfaceType *pSurfaceType = gEnv->p3DEngine->GetMaterialManager()->GetSurfaceType(pCollision->idmat[trgId]))
{
if(pSurfaceType->GetBreakability()==1)
{
m_notStick = true;
return;
}
}
IEntity *pTargetEntity = pTarget ? gEnv->pEntitySystem->GetEntityFromPhysics(pTarget) : 0;
if(pTarget && (!pTargetEntity || (pTargetEntity->GetId() != m_ownerId)))
{
//Special cases
if(pTargetEntity)
{
//Stick to actors using a character attachment
CActor *pActor = static_cast<CActor *>(gEnv->pGame->GetIGameFramework()->GetIActorSystem()->GetActor(pTargetEntity->GetId()));
//Not in MP
if(pActor && gEnv->bMultiplayer)
{
m_notStick = true;
return;
}
if(pActor && pActor->GetHealth()>0)
{
if(pActor->GetActorSpecies()!=eGCT_HUMAN)
{
m_notStick = true;
return;
}
if(StickToCharacter(true,pTargetEntity))
{
GetGameObject()->SetAspectProfile(eEA_Physics, ePT_None);
m_stuck = true;
}
m_notStick = true;
return;
}
//Do not stick to small objects...
if(!pActor)
{
pe_params_part pPart;
pPart.ipart = 0;
if(pTarget->GetParams(&pPart) && pPart.pPhysGeom && pPart.pPhysGeom->V<0.15f)
{
m_notStick = true;
return;
}
}
}
else if(pTarget->GetType()==PE_LIVING)
{
m_notStick = true;
return;
}
if(!pTargetEntity)
StickToStaticObject(pCollision,pTarget);
else
{
//Do not attach to items
if(g_pGame->GetIGameFramework()->GetIItemSystem()->GetItem(pTargetEntity->GetId()))
{
m_notStick = true;
return;
}
Matrix34 mat = pTargetEntity->GetWorldTM();
mat.Invert();
Vec3 pos = mat.TransformPoint(pCollision->pt);
mat.SetIdentity();
mat.SetRotation33(Matrix33::CreateOrientation(-pCollision->n,GetEntity()->GetWorldTM().TransformVector(Vec3(0,0,1)),gf_PI));
mat.SetTranslation(pos);
//Dephysicalize and stick
GetGameObject()->SetAspectProfile(eEA_Physics, ePT_None);
//.........这里部分代码省略.........