本文整理汇总了C++中CActor类的典型用法代码示例。如果您正苦于以下问题:C++ CActor类的具体用法?C++ CActor怎么用?C++ CActor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CActor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
CHitDeathReactionsPtr CCustomReactionFunctions::GetActorHitDeathReactions(CActor& actor) const
{
CRY_ASSERT(actor.GetActorClass() == CPlayer::GetActorClassType());
CPlayer& player = static_cast<CPlayer&>(actor);
return player.GetHitDeathReactions();
}
示例2: GetActorByEntityId
//------------------------------------------------------------------------
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));
}
}
示例3: Vec3
//------------------------------------------------------------------------
void CGameRules::ServerSimpleHit(const SimpleHitInfo &simpleHitInfo)
{
if (my->CallHook(
"OnEntityDamage",
oohh::GetEntityFromId(simpleHitInfo.targetId),
oohh::GetEntityFromId(simpleHitInfo.weaponId),
oohh::GetEntityFromId(simpleHitInfo.shooterId),
simpleHitInfo.value,
Vec3(0,0,0),
Vec3(0,0,0)
))
{
if (true)
return;
}
switch (simpleHitInfo.type)
{
case 0: // tag
{
if (!simpleHitInfo.targetId)
return;
// tagged entities are temporary in MP, not in SP.
bool temp = gEnv->bMultiplayer;
AddTaggedEntity(simpleHitInfo.shooterId, simpleHitInfo.targetId, temp);
}
break;
case 1: // tac
{
if (!simpleHitInfo.targetId)
return;
CActor *pActor = (CActor *)gEnv->pGame->GetIGameFramework()->GetIActorSystem()->GetActor(simpleHitInfo.targetId);
if (pActor && pActor->CanSleep())
pActor->Fall(Vec3(0.0f,0.0f,0.0f),simpleHitInfo.value);
}
break;
case 0xe: // freeze
{
if (!simpleHitInfo.targetId)
return;
// call OnFreeze
bool allow=true;
if (m_serverStateScript.GetPtr() && m_serverStateScript->GetValueType("OnFreeze")==svtFunction)
{
HSCRIPTFUNCTION func=0;
m_serverStateScript->GetValue("OnFreeze", func);
Script::CallReturn(m_serverStateScript->GetScriptSystem(), func, m_script, ScriptHandle(simpleHitInfo.targetId), ScriptHandle(simpleHitInfo.shooterId), ScriptHandle(simpleHitInfo.weaponId), simpleHitInfo.value, allow);
gEnv->pScriptSystem->ReleaseFunc(func);
}
if (!allow)
return;
if (IEntity *pEntity=gEnv->pEntitySystem->GetEntity(simpleHitInfo.targetId))
{
IScriptTable *pScriptTable=pEntity->GetScriptTable();
// call OnFrost
if (pScriptTable && pScriptTable->GetValueType("OnFrost")==svtFunction)
{
HSCRIPTFUNCTION func=0;
pScriptTable->GetValue("OnFrost", func);
Script::Call(pScriptTable->GetScriptSystem(), func, pScriptTable, ScriptHandle(simpleHitInfo.shooterId), ScriptHandle(simpleHitInfo.weaponId), simpleHitInfo.value);
gEnv->pScriptSystem->ReleaseFunc(func);
}
FreezeEntity(simpleHitInfo.targetId, true, true, simpleHitInfo.value>0.999f);
}
}
break;
default:
assert(!"Unknown Simple Hit type!");
}
}
示例4: ProcessClientExplosionScreenFX
//-------------------------------------------
void CGameRules::ProcessClientExplosionScreenFX(const ExplosionInfo &explosionInfo)
{
IActor *pClientActor = g_pGame->GetIGameFramework()->GetClientActor();
if (pClientActor)
{
//Distance
float dist = (pClientActor->GetEntity()->GetWorldPos() - explosionInfo.pos).len();
//Is the explosion in Player's FOV (let's suppose the FOV a bit higher, like 80)
CActor *pActor = (CActor *)pClientActor;
SMovementState state;
if (IMovementController *pMV = pActor->GetMovementController())
{
pMV->GetMovementState(state);
}
Vec3 eyeToExplosion = explosionInfo.pos - state.eyePosition;
eyeToExplosion.Normalize();
bool inFOV = (state.eyeDirection.Dot(eyeToExplosion) > 0.68f);
//All explosions have radial blur (default 30m radius, to make Sean happy =))
float maxBlurDistance = (explosionInfo.maxblurdistance > 0.0f) ? explosionInfo.maxblurdistance : 30.0f;
if (maxBlurDistance > 0.0f && g_pGameCVars->g_radialBlur > 0.0f && m_explosionScreenFX && explosionInfo.radius > 0.5f)
{
if (inFOV && dist < maxBlurDistance)
{
ray_hit hit;
int col = gEnv->pPhysicalWorld->RayWorldIntersection(explosionInfo.pos , -eyeToExplosion * dist, ent_static | ent_terrain, rwi_stop_at_pierceable | rwi_colltype_any, &hit, 1);
//If there was no obstacle between flashbang grenade and player
if(!col)
{
float distAmp = 1.0f - (dist / maxBlurDistance);
if (gEnv->pInput)
{
gEnv->pInput->ForceFeedbackEvent( SFFOutputEvent(eDI_XI, eFF_Rumble_Basic, 0.5f, distAmp * 3.0f, 0.0f));
}
}
}
}
//Flashbang effect
if(dist < explosionInfo.radius && inFOV &&
(!strcmp(explosionInfo.effect_class, "flashbang") || !strcmp(explosionInfo.effect_class, "FlashbangAI")))
{
ray_hit hit;
int col = gEnv->pPhysicalWorld->RayWorldIntersection(explosionInfo.pos , -eyeToExplosion * dist, ent_static | ent_terrain, rwi_stop_at_pierceable | rwi_colltype_any, &hit, 1);
//If there was no obstacle between flashbang grenade and player
if(!col)
{
float power = explosionInfo.flashbangScale;
power *= max(0.0f, 1 - (dist / explosionInfo.radius));
float lookingAt = (eyeToExplosion.Dot(state.eyeDirection.normalize()) + 1) * 0.5f;
power *= lookingAt;
gEnv->p3DEngine->SetPostEffectParam("Flashbang_Time", 1.0f + (power * 4));
gEnv->p3DEngine->SetPostEffectParam("FlashBang_BlindAmount", explosionInfo.blindAmount);
gEnv->p3DEngine->SetPostEffectParam("Flashbang_DifractionAmount", (power * 2));
gEnv->p3DEngine->SetPostEffectParam("Flashbang_Active", 1);
}
}
else if(inFOV && (dist < explosionInfo.radius))
{
if (explosionInfo.damage > 10.0f || explosionInfo.pressure > 100.0f)
{
//Add some angular impulse to the client actor depending on distance, direction...
float dt = (1.0f - dist / explosionInfo.radius);
dt = dt * dt;
float angleZ = gf_PI * 0.15f * dt;
float angleX = gf_PI * 0.15f * dt;
pActor->AddAngularImpulse(Ang3(Random(-angleX * 0.5f, angleX), 0.0f, Random(-angleZ, angleZ)), 0.0f, dt * 2.0f);
}
}
}
}
示例5: timeServer
void CLevel::ProcessGameEvents ()
{
// Game events
{
NET_Packet P;
u32 svT = timeServer()-NET_Latency;
/*
if (!game_events->queue.empty())
Msg("- d[%d],ts[%d] -- E[svT=%d],[evT=%d]",Device.dwTimeGlobal,timeServer(),svT,game_events->queue.begin()->timestamp);
*/
#ifdef SPAWN_ANTIFREEZE
while (spawn_events->available(svT))
{
u16 ID, dest, type;
spawn_events->get(ID, dest, type, P);
game_events->insert(P);
}
u32 avail_time = 5;
u32 elps = Device.frame_elapsed();
if (elps < 30) avail_time = 33 - elps;
u32 work_limit = elps + avail_time;
#endif
while (game_events->available(svT))
{
u16 ID,dest,type;
game_events->get (ID,dest,type,P);
#ifdef SPAWN_ANTIFREEZE
// не отправлять события не заспавненным объектам
if (g_bootComplete && M_EVENT == ID && PostponedSpawn(dest))
{
spawn_events->insert(P);
continue;
}
if (g_bootComplete && M_SPAWN == ID && Device.frame_elapsed() > work_limit) // alpet: позволит плавнее выводить объекты в онлайн, без заметных фризов
{
u16 parent_id;
GetSpawnInfo(P, parent_id);
//-------------------------------------------------
if (parent_id < 0xffff) // откладывать спавн только объектов в контейнеры
{
//if (!spawn_events->available(svT))
//Msg("* ProcessGameEvents, spawn event postponed. Events rest = %d", game_events->queue.size());
spawn_events->insert(P);
continue;
}
}
#endif
switch (ID)
{
case M_SPAWN:
{
u16 dummy16;
P.r_begin(dummy16);
cl_Process_Spawn(P);
}break;
case M_EVENT:
{
cl_Process_Event(dest, type, P);
}break;
case M_MOVE_PLAYERS:
{
u8 Count = P.r_u8();
for (u8 i=0; i<Count; i++)
{
u16 ID = P.r_u16();
Fvector NewPos, NewDir;
P.r_vec3(NewPos);
P.r_vec3(NewDir);
CActor* OActor = smart_cast<CActor*>(Objects.net_Find (ID));
if (0 == OActor) break;
OActor->MoveActor(NewPos, NewDir);
};
NET_Packet PRespond;
PRespond.w_begin(M_MOVE_PLAYERS_RESPOND);
Send(PRespond, net_flags(TRUE, TRUE));
}break;
case M_STATISTIC_UPDATE:
{
if (GameID() != eGameIDSingle)
Game().m_WeaponUsageStatistic->OnUpdateRequest(&P);
}break;
case M_FILE_TRANSFER:
{
if (m_file_transfer) //in case of net_Stop
m_file_transfer->on_message(&P);
}break;
case M_GAMEMESSAGE:
{
Game().OnGameMessage(P);
}break;
default:
{
VERIFY(0);
}break;
//.........这里部分代码省略.........
示例6: HandleEvent
void CTacBullet::HandleEvent(const SGameObjectEvent &event)
{
if (m_destroying)
return;
CProjectile::HandleEvent(event);
if (event.event == eGFE_OnCollision)
{
EventPhysCollision *pCollision = reinterpret_cast<EventPhysCollision *>(event.ptr);
if (!pCollision)
return;
IEntity *pTarget = pCollision->iForeignData[1]==PHYS_FOREIGN_ID_ENTITY ? (IEntity*)pCollision->pForeignData[1]:0;
if (pTarget)
{
CGameRules *pGameRules = g_pGame->GetGameRules();
EntityId targetId = pTarget->GetId();
CActor *pActor = (CActor *)gEnv->pGame->GetIGameFramework()->GetIActorSystem()->GetActor(targetId);
if(pActor && pActor->CanSleep())
{
if(pActor->GetLinkedVehicle() && !gEnv->bMultiplayer)
{
SleepTargetInVehicle(m_ownerId,pActor);
}
else if(IEntity* pOwnerEntity = gEnv->pEntitySystem->GetEntity(m_ownerId))
{
if (pTarget->GetAI() && !pTarget->GetAI()->IsFriendly(pOwnerEntity->GetAI(), false))
{
float sleepTime = 30.0f;
if(m_pAmmoParams)
sleepTime = m_pAmmoParams->sleepTime;
SimpleHitInfo info(m_ownerId, targetId, m_weaponId, 1, sleepTime); // 0=tag,1=tac
info.remote=IsRemote();
pGameRules->ClientSimpleHit(info);
}
}
}
else
{
Vec3 dir(0, 0, 0);
if (pCollision->vloc[0].GetLengthSquared() > 1e-6f)
dir = pCollision->vloc[0].GetNormalized();
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);
}
}
else if (pCollision->pEntity[0]->GetType() == PE_PARTICLE)
{
float bouncy, friction;
uint32 pierceabilityMat;
gEnv->pPhysicalWorld->GetSurfaceParameters(pCollision->idmat[1], bouncy, friction, pierceabilityMat);
pierceabilityMat&=sf_pierceable_mask;
pe_params_particle params;
if(pCollision->pEntity[0]->GetParams(¶ms)==0)
SetDefaultParticleParams(¶ms);
if (pierceabilityMat>params.iPierceability && pCollision->idCollider!=-1)
return;
}
Destroy();
}
}
示例7: GameWarning
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);
}
}
}
}
//.........这里部分代码省略.........
示例8: Action
bool CInventory::Action(u16 cmd, u32 flags)
{
CActor *pActor = smart_cast<CActor*>(m_pOwner);
if (pActor)
{
switch(cmd)
{
case kWPN_FIRE:
{
pActor->SetShotRndSeed();
}break;
case kWPN_ZOOM :
{
pActor->SetZoomRndSeed();
}break;
};
};
if (g_pGameLevel && OnClient() && pActor)
{
switch(cmd)
{
case kUSE: break;
case kDROP:
{
if ((flags & CMD_STOP) && !IsGameTypeSingle())
{
PIItem tmp_item = ActiveItem();
if (tmp_item)
{
tmp_item->DenyTrade();
}
}
SendActionEvent (cmd, flags);
return true;
}break;
case kWPN_NEXT:
case kWPN_RELOAD:
case kWPN_FIRE:
case kWPN_FUNC:
case kWPN_FIREMODE_NEXT:
case kWPN_FIREMODE_PREV:
case kWPN_ZOOM :
case kTORCH:
case kNIGHT_VISION:
{
SendActionEvent(cmd, flags);
}break;
}
}
if ( ActiveItem() &&
ActiveItem()->Action(cmd, flags))
return true;
bool b_send_event = false;
switch(cmd)
{
case kWPN_1:
case kWPN_2:
case kWPN_3:
case kWPN_4:
case kWPN_5:
case kWPN_6:
{
b_send_event = true;
if (cmd == kWPN_6 && !IsGameTypeSingle()) return false;
u16 slot = u16(cmd - kWPN_1 + 1);
if ( flags & CMD_START )
{
ActiveWeapon( slot );
}
}break;
case kARTEFACT:
{
b_send_event = true;
if(flags&CMD_START)
{
if(GetActiveSlot() == ARTEFACT_SLOT &&
ActiveItem() /*&& IsGameTypeSingle()*/)
{
Activate(NO_ACTIVE_SLOT);
}else {
Activate(ARTEFACT_SLOT);
}
}
}break;
}
if(b_send_event && g_pGameLevel && OnClient() && pActor)
SendActionEvent(cmd, flags);
return false;
}
示例9: GetProbableHit
//--------------------------------------
void CThrow::DoDrop()
{
m_pWeapon->HideItem(true);
if (m_throwableId)
{
IEntity *pEntity = gEnv->pEntitySystem->GetEntity(m_throwableId);
if (pEntity)
{
IPhysicalEntity *pPE = pEntity->GetPhysics();
if (pPE && (pPE->GetType() == PE_RIGID || pPE->GetType() == PE_PARTICLE))
{
Vec3 hit = GetProbableHit(WEAPON_HIT_RANGE);
Vec3 pos = GetFiringPos(hit);
CActor *pActor = m_pWeapon->GetOwnerActor();
IMovementController *pMC = pActor ? pActor->GetMovementController() : 0;
if (pMC)
{
SMovementState info;
pMC->GetMovementState(info);
float speed = 2.5f;
CPlayer *pPlayer = static_cast<CPlayer *>(m_pWeapon->GetOwnerActor());
if(info.aimDirection.z < -0.1f)
{
if(pPlayer)
{
if(SPlayerStats *pStats = static_cast<SPlayerStats *>(pPlayer->GetActorStats()))
{
if(pStats->grabbedHeavyEntity)
{
speed = 4.0f;
}
}
}
}
if(CheckForIntersections(pPE, info.eyeDirection))
{
Matrix34 newTM = pEntity->GetWorldTM();
newTM.SetTranslation(newTM.GetTranslation() - (info.eyeDirection * 0.4f));
pEntity->SetWorldTM(newTM, ENTITY_XFORM_POS);
pe_action_set_velocity asv;
asv.v = (-info.eyeDirection * speed);
pPE->Action(&asv);
}
else
{
pe_action_set_velocity asv;
asv.v = (info.eyeDirection * speed);
pPE->Action(&asv);
}
SEntityEvent entityEvent;
entityEvent.event = ENTITY_EVENT_PICKUP;
entityEvent.nParam[0] = 0;
if (pPlayer)
{
entityEvent.nParam[1] = pPlayer->GetEntityId();
}
entityEvent.fParam[0] = speed;
pEntity->SendEvent( entityEvent );
}
}
}
if (m_throwableAction)
{
m_throwableAction->execute(m_pWeapon);
}
}
}
示例10: 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;
}
示例11: switch
bool CInventory::DropItem(CGameObject *pObj, bool just_before_destroy, bool dont_create_shell)
{
CInventoryItem *pIItem = smart_cast<CInventoryItem*>(pObj);
VERIFY (pIItem);
VERIFY (pIItem->m_pInventory);
VERIFY (pIItem->m_pInventory==this);
VERIFY (pIItem->m_ItemCurrPlace.type!=eItemPlaceUndefined);
pIItem->object().processing_activate();
switch(pIItem->CurrPlace())
{
case eItemPlaceBelt:{
VERIFY(InBelt(pIItem));
TIItemContainer::iterator temp_iter = std::find(m_belt.begin(), m_belt.end(), pIItem);
if (temp_iter != m_belt.end())
{
m_belt.erase(temp_iter);
} else
{
Msg("! ERROR: CInventory::Drop item not found in belt...");
}
pIItem->object().processing_deactivate();
}break;
case eItemPlaceRuck:{
VERIFY(InRuck(pIItem));
TIItemContainer::iterator temp_iter = std::find(m_ruck.begin(), m_ruck.end(), pIItem);
if (temp_iter != m_ruck.end())
{
m_ruck.erase(temp_iter);
} else
{
Msg("! ERROR: CInventory::Drop item not found in ruck...");
}
}break;
case eItemPlaceSlot:{
VERIFY (InSlot(pIItem));
if(m_iActiveSlot == pIItem->CurrSlot())
{
CActor* pActor = smart_cast<CActor*>(m_pOwner);
if (!pActor || pActor->g_Alive())
{
if (just_before_destroy)
{
#ifdef DEBUG
Msg("---DropItem activating slot [-1], forced, Frame[%d]", Device.dwFrame);
#endif // #ifdef DEBUG
Activate (NO_ACTIVE_SLOT, true);
} else
{
#ifdef DEBUG
Msg("---DropItem activating slot [-1], Frame[%d]", Device.dwFrame);
#endif // #ifdef DEBUG
Activate (NO_ACTIVE_SLOT);
}
}
}
m_slots[pIItem->CurrSlot()].m_pIItem = NULL;
pIItem->object().processing_deactivate();
}break;
default:
NODEFAULT;
};
TIItemContainer::iterator it = std::find(m_all.begin(), m_all.end(), pIItem);
if(it!=m_all.end())
m_all.erase(std::find(m_all.begin(), m_all.end(), pIItem));
else
Msg("! CInventory::Drop item not found in inventory!!!");
pIItem->m_pInventory = NULL;
m_pOwner->OnItemDrop (smart_cast<CInventoryItem*>(pObj), just_before_destroy);
CalcTotalWeight ();
InvalidateState ();
m_drop_last_frame = true;
if( CurrentGameUI() )
{
CObject* pActor_owner = smart_cast<CObject*>(m_pOwner);
if (Level().CurrentViewEntity() == pActor_owner)
CurrentGameUI()->OnInventoryAction(pIItem, GE_OWNERSHIP_REJECT);
};
pObj->H_SetParent(0, dont_create_shell);
return true;
}
示例12: if
void CGameRulesMPActorAction::OnActorAction(IActor *pActor, const ActionId& actionId, int activationMode, float value)
{
CActor *pActorImpl = static_cast<CActor *>(pActor);
if (pActorImpl)
{
EntityId pid = pActor->GetEntityId(); // player id
CGameRules *pGameRules = g_pGame->GetGameRules();
IGameRulesSpectatorModule *specmod = pGameRules->GetSpectatorModule();
if (!specmod || (pActorImpl->GetSpectatorMode() <= 0))
{
// Not in spectator mode
if (pActorImpl->IsDead())
{
// if dead
CRecordingSystem *crs = g_pGame->GetRecordingSystem();
if (crs != NULL && crs->IsPlayingBack())
{
// Recording system playing back
if (actionId == g_pGame->Actions().spectate_gen_skipdeathcam && g_pGameCVars->kc_canSkip )
crs->StopPlayback();
}
else if ((actionId == g_pGame->Actions().spectate_gen_spawn || actionId == g_pGame->Actions().hud_mouseclick) && activationMode == eAAM_OnPress && pActorImpl->GetSpectatorState() != CActor::eASS_SpectatorMode)
{
// Revive requested.
// This may happen immediately or not at all.
if (IGameRulesSpawningModule* pSpawningModule=pGameRules->GetSpawningModule())
{
IGameRulesStateModule* stateModule = pGameRules->GetStateModule();
if (!stateModule || (stateModule->GetGameState() != IGameRulesStateModule::EGRS_PostGame))
{
CryLog("CGameRulesMPActorAction::OnActorAction() Requesting revive");
pSpawningModule->ClRequestRevive(pActor->GetEntityId());
}
}
}
else if ((specmod != NULL && specmod->CanChangeSpectatorMode(pid)) && (((actionId == g_pGame->Actions().spectate_gen_nextmode) || (actionId == g_pGame->Actions().spectate_gen_prevmode)) && (activationMode == eAAM_OnPress)))
{
// get into spectate mode
if (!crs || !crs->IsPlayingOrQueued())
{
specmod->ChangeSpectatorModeBestAvailable(pActor, false);
}
}
}
}
else
{
// is spectating
int curspecmode = pActorImpl->GetSpectatorMode();
int curspecstate = pActorImpl->GetSpectatorState();
const CRecordingSystem* pRecordingSystem = g_pGame->GetRecordingSystem();
// actions general across almost all spectator modes
if( (curspecmode == CActor::eASM_Killer && !g_pGameCVars->g_killercam_canSkip) || (pRecordingSystem && pRecordingSystem->IsPlayingBack()) )
{
// Can't change mode or respawn-request, when in KillerCam mode or watching Killcam.
}
else if ((actionId == g_pGame->Actions().spectate_gen_spawn) && (activationMode == eAAM_OnPress) && pActorImpl->GetSpectatorState() != CActor::eASS_SpectatorMode)
{
IGameRulesSpawningModule *pSpawningModule = pGameRules->GetSpawningModule();
if (pSpawningModule)
{
IGameRulesStateModule* stateModule = pGameRules->GetStateModule();
if (!stateModule || (stateModule->GetGameState() != IGameRulesStateModule::EGRS_PostGame))
{
CryLog("CGameRulesMPActorAction::OnActorAction() Spectating, received spectate_gen_spawn action, requesting revive");
pSpawningModule->ClRequestRevive(pActor->GetEntityId());
}
}
}
else if (((actionId == g_pGame->Actions().spectate_gen_nextmode) || (actionId == g_pGame->Actions().spectate_gen_prevmode)) && (activationMode == eAAM_OnPress))
{
CryLog("[tlh] > changemode button pressed");
if (specmod->CanChangeSpectatorMode(pid))
{
CryLog("[tlh] > can change");
int mode;
EntityId othEntId;
mode = specmod->GetNextMode(pid, ((actionId == g_pGame->Actions().spectate_gen_nextmode) ? 1 : -1), &othEntId);
if (mode != curspecmode)
{
CryLog("[tlh] > changing to mode %d with othEnt %d",mode,othEntId);
specmod->ChangeSpectatorMode(pActor, mode, othEntId, false);
}
}
}
else
{
// actions specific to individual spectator modes
if (specmod->CanChangeSpectatorMode(pid)) // "CanChangeSpectatorMode?" is essentially "CanInteractWithSpectatorMode?" - ie. we don't want to be able to do any of this on the Join Game screen
{
if (curspecmode == CActor::eASM_Fixed)
//.........这里部分代码省略.........
示例13: get_binded_action
//.........这里部分代码省略.........
bool bOk = false;
u32 i=0, j, n=Objects.o_count();
if (pCurrentEntity)
for ( ; i<n; ++i)
if (Objects.o_get_by_iterator(i) == pCurrentEntity)
break;
if (i < n) {
j = i;
bOk = false;
for (++i; i <n; ++i) {
CEntityAlive* tpEntityAlive = smart_cast<CEntityAlive*>(Objects.o_get_by_iterator(i));
if (tpEntityAlive) {
bOk = true;
break;
}
}
if (!bOk)
for (i = 0; i <j; ++i) {
CEntityAlive* tpEntityAlive = smart_cast<CEntityAlive*>(Objects.o_get_by_iterator(i));
if (tpEntityAlive) {
bOk = true;
break;
}
}
if (bOk) {
CObject *tpObject = CurrentEntity();
CObject *__I = Objects.o_get_by_iterator(i);
CObject **I = &__I;
SetEntity(*I);
if (tpObject != *I)
{
CActor* pActor = smart_cast<CActor*> (tpObject);
if (pActor)
pActor->inventory().Items_SetCurrentEntityHud(false);
}
if (tpObject)
{
Engine.Sheduler.Unregister (tpObject);
Engine.Sheduler.Register (tpObject, TRUE);
};
Engine.Sheduler.Unregister (*I);
Engine.Sheduler.Register (*I, TRUE);
CActor* pActor = smart_cast<CActor*> (*I);
if (pActor)
{
pActor->inventory().Items_SetCurrentEntityHud(true);
CHudItem* pHudItem = smart_cast<CHudItem*>(pActor->inventory().ActiveItem());
if (pHudItem)
{
pHudItem->OnStateSwitch(pHudItem->GetState());
}
}
}
}
return;
}
// Lain: added
case DIK_F5:
{
if ( CBaseMonster* pBM = smart_cast<CBaseMonster*>(CurrentEntity()))
{
DBG().log_debug_info();
示例14: FallAndPlay_Reaction
void CCustomReactionFunctions::FallAndPlay_Reaction(CActor& actor, const SReactionParams& reactionParams, const HitInfo& hitInfo)
{
actor.Fall();
DeathImpulse_Reaction(actor, reactionParams, hitInfo);
}
示例15: NetShootEx
void CLTagSingle::NetShootEx(const Vec3 &pos, const Vec3 &dir, const Vec3 &vel, const Vec3 &hit, float extra, int predictionHandle)
{
IEntityClass* ammo = m_fireParams->fireparams.ammo_type_class;
int weaponAmmoCount = m_pWeapon->GetAmmoCount(ammo);
int ammoCount = weaponAmmoCount;
CActor* pOwnerActor = m_pWeapon->GetOwnerActor();
bool playerIsShooter = pOwnerActor ? pOwnerActor->IsPlayer() : false;
if (IsProceduralRecoilEnabled() && pOwnerActor)
{
pOwnerActor->ProceduralRecoil(m_fireParams->proceduralRecoilParams.duration, m_fireParams->proceduralRecoilParams.strength, m_fireParams->proceduralRecoilParams.kickIn, m_fireParams->proceduralRecoilParams.arms);
}
m_pWeapon->PlayAction(GetFragmentIds().fire, 0, false, CItem::eIPAF_Default);
CProjectile *pAmmo = m_pWeapon->SpawnAmmo(m_fireParams->fireparams.spawn_ammo_class, true);
CLTAGGrenade* pGrenade = static_cast<CLTAGGrenade*>(pAmmo);
if (pGrenade)
{
CRY_ASSERT_MESSAGE(m_fireParams->fireparams.hitTypeId, string().Format("Invalid hit type '%s' in fire params for '%s'", m_fireParams->fireparams.hit_type.c_str(), m_pWeapon->GetEntity()->GetName()));
CRY_ASSERT_MESSAGE(m_fireParams->fireparams.hitTypeId == g_pGame->GetGameRules()->GetHitTypeId(m_fireParams->fireparams.hit_type.c_str()), "Sanity Check Failed: Stored hit type id does not match the type string, possibly CacheResources wasn't called on this weapon type");
pGrenade->SetParams(CProjectile::SProjectileDesc(
m_pWeapon->GetOwnerId(), m_pWeapon->GetHostId(), m_pWeapon->GetEntityId(),
m_fireParams->fireparams.damage, 0.f, 0.f, 0.f, m_fireParams->fireparams.hitTypeId,
m_fireParams->fireparams.bullet_pierceability_modifier, m_pWeapon->IsZoomed()));
// this must be done after owner is set
pGrenade->InitWithAI();
pGrenade->SetDestination(m_pWeapon->GetDestination());
pGrenade->SetGrenadeType(m_grenadeType);
pGrenade->Launch(pos, dir, vel, m_speed_scale);
m_projectileId = pGrenade->GetEntity()->GetId();
}
if (m_pWeapon->IsServer())
{
const char *ammoName = ammo != NULL ? ammo->GetName() : NULL;
g_pGame->GetIGameFramework()->GetIGameplayRecorder()->Event(m_pWeapon->GetOwner(), GameplayEvent(eGE_WeaponShot, ammoName, 1, (void *)(EXPAND_PTR)m_pWeapon->GetEntityId()));
#ifdef SERVER_CHECKS
if (pOwnerActor && m_pWeapon->IsServerSpawn(ammo))
{
int inventoryAmmoCount = m_pWeapon->GetInventoryAmmoCount(ammo);
int totalAmmoCount=weaponAmmoCount+inventoryAmmoCount; // this needed seeing as how this seems to use weaponAmmo or inventoryAmmo but NOT both?
if (totalAmmoCount <= 0)
{
g_pGame->GetAntiCheatManager()->FlagActivity(eCT_ServerSpawnedAmmoUsed, pOwnerActor->GetChannelId());
}
}
#endif
}
m_muzzleEffect.Shoot(this, hit, m_barrelId);
RecoilImpulse(pos, dir);
m_fired = true;
m_next_shot = 0.0f;
ammoCount--;
if(ammoCount<0)
ammoCount = 0;
if (m_pWeapon->IsServer())
{
int clipSize = GetClipSize();
if (clipSize != -1)
{
if (clipSize != 0)
m_pWeapon->SetAmmoCount(ammo, ammoCount);
else
m_pWeapon->SetInventoryAmmoCount(ammo, ammoCount);
}
}
OnShoot(m_pWeapon->GetOwnerId(), pAmmo?pAmmo->GetEntity()->GetId():0, ammo, pos, dir, vel);
if(playerIsShooter)
{
const SThermalVisionParams& thermalParams = m_fireParams->thermalVisionParams;
m_pWeapon->AddShootHeatPulse(pOwnerActor, thermalParams.weapon_shootHeatPulse, thermalParams.weapon_shootHeatPulseTime,
thermalParams.owner_shootHeatPulse, thermalParams.owner_shootHeatPulseTime);
}
if (OutOfAmmo())
m_pWeapon->OnOutOfAmmo(ammo);
if (pAmmo && predictionHandle && pOwnerActor)
{
pAmmo->GetGameObject()->RegisterAsValidated(pOwnerActor->GetGameObject(), predictionHandle);
pAmmo->GetGameObject()->BindToNetwork();
}
else if (pAmmo && pAmmo->IsPredicted() && gEnv->IsClient() && gEnv->bServer && pOwnerActor && pOwnerActor->IsClient())
{
pAmmo->GetGameObject()->BindToNetwork();
}
//.........这里部分代码省略.........