本文整理汇总了C++中IWeapon类的典型用法代码示例。如果您正苦于以下问题:C++ IWeapon类的具体用法?C++ IWeapon怎么用?C++ IWeapon使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IWeapon类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Serialize
void Serialize(SActivationInfo* pActInfo, TSerialize ser)
{
ser.Value("active", m_active);
ser.Value("ammo", m_ammo);
ser.Value("weaponId", m_weapId);
if (ser.IsReading())
{
if (m_active && m_weapId != 0)
{
IItemSystem* pItemSys = CCryAction::GetCryAction()->GetIItemSystem();
IItem* pItem = pItemSys->GetItem(m_weapId);
if (!pItem || !pItem->GetIWeapon())
{
GameWarning("[flow] CFlowNode_WeaponListener: Serialize no item/weapon.");
return;
}
IWeapon* pWeapon = pItem->GetIWeapon();
// set weapon listener
pWeapon->AddEventListener(this, "CFlowNode_WeaponListener");
// CryLog("[flow] CFlowNode_WeaponListener::Serialize() successfully created on '%s'", pItem->GetEntity()->GetName());
}
else
{
Reset();
}
}
}
示例2: BulletNode
IWeapon* MySceneManager::addBulletSceneNode( const std::wstring& textureFileName, int velocity /*= 1000*/, u32 interval /*= 100 */ )
{
IWeapon* bullet = new BulletNode( smgr );
bullet->setMaterialTexture( 0, driver->getTexture( textureFileName.c_str() ) );
bullet->SetVelocity( (f32)velocity );
bullet->SetInterval( interval );
return bullet;
}
示例3: assert
bool CBitmapUi::CanDrawCrosshair() const
{
assert( m_pGameFramework != NULL );
if ( ! g_pGameCVars->g_show_crosshair )
{
return false;
}
IActor* pPlayer = m_pGameFramework->GetClientActor();
if ( pPlayer == NULL )
{
return false;
}
bool isPlayerDead = pPlayer->IsDead();
if ( isPlayerDead )
{
return false;
}
bool thirdPersonMode = pPlayer->IsThirdPerson();
bool crosshairEnabledInThirdPerson = ( g_pGameCVars->g_show_crosshair_tp != 0 );
if ( thirdPersonMode && ! crosshairEnabledInThirdPerson )
{
return false;
}
IItem* pItem = pPlayer->GetCurrentItem();
if ( pItem == NULL )
{
return false;
}
IWeapon* pWeapon = pItem->GetIWeapon();
if ( pWeapon == NULL )
{
return false;
}
bool carryingMeleeWeapon = pWeapon->CanMeleeAttack();
if ( carryingMeleeWeapon )
{
return false;
}
bool isWeaponZoomed = pWeapon->IsZoomed();
bool usingWeaponSightForAiming = ( ! thirdPersonMode && isWeaponZoomed );
if ( usingWeaponSightForAiming )
{
return false;
}
return true;
}
示例4: DbgLog
//---------------------------------------
void CMiscAnnouncer::RemoveWeaponListener(EntityId weaponId)
{
DbgLog("CMiscAnnouncer::RemoveWeaponListener() weapon=%s", g_pGame->GetGameRules()->GetEntityName(weaponId));
IItem* pItem = gEnv->pGame->GetIGameFramework()->GetIItemSystem()->GetItem(weaponId);
if(pItem)
{
IWeapon *pWeapon = pItem->GetIWeapon();
if(pWeapon)
{
pWeapon->RemoveEventListener(this);
}
}
}
示例5: ProcessEvent
void ProcessEvent(EFlowEvent event, SActivationInfo *pActInfo)
{
IWeapon* pWeapon = GetWeapon(pActInfo);
if (!pWeapon)
return;
switch (event)
{
case eFE_Activate:
if (pWeapon)
pWeapon->StartChangeFireMode();
break;
}
}
示例6: ProcessEvent
void ProcessEvent(EFlowEvent event, SActivationInfo* pActInfo)
{
if (event == eFE_Activate && (IsPortActive(pActInfo, IN_GET) || IsPortActive(pActInfo, IN_SET)))
{
IActor* pActor = GetInputActor(pActInfo);
if (!pActor)
return;
IInventory *pInventory = pActor->GetInventory();
if (pInventory)
{
const string& ammoType = GetPortString(pActInfo, IN_AMMOTYPE);
IEntityClass* pAmmoClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(ammoType.c_str());
if (pAmmoClass)
{
if (IsPortActive(pActInfo, IN_SET))
{
const bool bAdd = GetPortBool(pActInfo, IN_ADD);
const int ammoAmount = GetPortInt(pActInfo, IN_AMMOCOUNT);
pInventory->SetAmmoCount(pAmmoClass, bAdd ? (ammoAmount + pInventory->GetAmmoCount(pAmmoClass)) : (ammoAmount));
}
int magazineAmmo = 0;
int inventoryAmmo = pInventory->GetAmmoCount(pAmmoClass);
if (IItem* pItem = pActor->GetCurrentItem())
{
IWeapon* pCurrentWeapon = GetWeapon(pItem->GetEntityId());
if (pCurrentWeapon)
{
magazineAmmo = pCurrentWeapon->GetAmmoCount(pAmmoClass);
}
}
ActivateOutput(pActInfo, OUT_MAGAZINE, magazineAmmo);
ActivateOutput(pActInfo, OUT_INVENTORY, inventoryAmmo);
ActivateOutput(pActInfo, OUT_TOTAL, (magazineAmmo + inventoryAmmo));
}
}
}
}
示例7: GameWarning
//.........这里部分代码省略.........
}
IEntity* pItemEntity = pItem->GetEntity();
if(!pItemEntity)
return pH->EndFunction();
if(!pItem->GetOwnerId())
{
// weapon is not used, check if it is on a vehicle
IEntity* pParentEntity = pItemEntity->GetParent();
if(pParentEntity)
{
IAIObject* pParentAI = pParentEntity->GetAI();
if(pParentAI && pParentAI->GetAIType()==AIOBJECT_VEHICLE)
{
// (MATT) Feature was cut and code was tricky, hence ignore weapons in vehicles {2008/02/15:11:08:51}
return pH->EndFunction();
}
}
}
else if( pItem->GetOwnerId()!= pEntity->GetId()) // item is used by someone else?
return pH->EndFunction(false);
// check target
if(bSkipTargetCheck)
return pH->EndFunction(true);
IAIObject* pTarget = pAIActor->GetAttentionTarget();
if(targetPos.IsZero())
{
if(!pTarget)
return pH->EndFunction();
targetPos = pTarget->GetPos();
}
Vec3 targetDir(targetPos - pItemEntity->GetWorldPos());
Vec3 targetDirXY(targetDir.x, targetDir.y, 0);
float length2D = targetDirXY.GetLength();
if(length2D < minDist || length2D<=0)
return pH->EndFunction();
targetDirXY /= length2D;//normalize
IWeapon* pWeapon = pItem->GetIWeapon();
bool vehicleGun = pWeapon && pWeapon->GetHostId();
if (!vehicleGun)
{
Vec3 mountedAngleLimits(pItem->GetMountedAngleLimits());
float yawRange = DEG2RAD(mountedAngleLimits.z);
if(yawRange > 0 && yawRange < gf_PI)
{
float deltaYaw = pItem->GetMountedDir().Dot(targetDirXY);
if(deltaYaw < cosf(yawRange))
return pH->EndFunction(false);
}
float minPitch = DEG2RAD(mountedAngleLimits.x);
float maxPitch = DEG2RAD(mountedAngleLimits.y);
//maxPitch = (maxPitch - minPitch)/2;
//minPitch = -maxPitch;
float pitch = atanf(targetDir.z / length2D);
if ( pitch < minPitch || pitch > maxPitch )
return pH->EndFunction(false);
}
if(pTarget)
{
IEntity* pTargetEntity = pTarget->GetEntity();
if(pTargetEntity)
{
// check target distance and where he's going
IPhysicalEntity *phys = pTargetEntity->GetPhysics();
if(phys)
{
pe_status_dynamics dyn;
phys->GetStatus(&dyn);
Vec3 velocity ( dyn.v);
velocity.z = 0;
float speed = velocity.GetLength2D();
if(speed>0)
{
//velocity /= speed;
if(length2D< minDist * 0.75f && velocity.Dot(targetDirXY)<=0)
return pH->EndFunction(false);
}
}
}
}
return pH->EndFunction(true);
}
示例8: while
//.........这里部分代码省略.........
if(KeyboardState::keyReleased[m_KeyFirstPersonCamera])
{
toggleFirstPersonCamera();
}
break;
// =====
case STATE_NUKE:
case STATE_BUILDING_PLACEMENT:
// sanity check
if(m_State == STATE_BUILDING_PLACEMENT && (!m_pCurrentBuildButton || !m_pCurrentBuildAssetDef)) {
changeState(STATE_ASSET_CONTROL);
break;
}
// update selector
D3DXMATRIX matProj, matView;
D3DXVECTOR3 rayOrigin, rayDir;
m_pDevice->GetTransform(D3DTS_PROJECTION, &matProj);
m_pDevice->GetTransform(D3DTS_VIEW, &matView);
MouseState::transformTo3D(matView, matProj, rayOrigin, rayDir);
D3DXVECTOR3* hitSquare = TerrainIntersection::pickTerrain(rayOrigin, rayDir);
if(hitSquare)
{
m_pSelector->setPoint(D3DXVECTOR2(hitSquare->x, hitSquare->y));
delete hitSquare;
}
// mouse actions
if(MouseState::mouseButtonReleased[MouseState::mouseSecondButton]) {
// return the preserved ore
if(m_CurrentBuildOreTaken) {
m_pCurrentPlayer->modifyOre(m_CurrentBuildOreTaken);
}
// cancel build state with secondary mouse button
changeState(STATE_ASSET_CONTROL);
setNukeSilo(NULL);
break;
} else if(MouseState::mouseButtonReleased[MouseState::mouseFirstButton] && m_State == STATE_BUILDING_PLACEMENT) {
// placement made
if(m_pSelector->isBuildable()) {
D3DXVECTOR2 bpos = m_pSelector->getBuildingPoint();
// @TODO: assetfactory->create
IAsset* newAsset = AssetFactory::createAsset(m_pCurrentPlayer, m_pCurrentBuildAssetDef->tag, (short)bpos.x, (short)bpos.y);
if(newAsset) {
m_pCurrentBuildButton->setEnabled(false);
m_pCurrentBuildButton->setRandomObject(newAsset);
m_ButtonsToUpdate.pushHead(m_pCurrentBuildButton);
}
// problem, new asset not created, return ore to player
else {
if(m_CurrentBuildOreTaken)
m_pCurrentPlayer->modifyOre(m_CurrentBuildOreTaken);
}
changeState(STATE_ASSET_CONTROL);
break;
}
// @TODO ??
} else if(MouseState::mouseButtonReleased[MouseState::mouseFirstButton] && m_State == STATE_NUKE) {
if (m_pCurrentNukeSilo != NULL)
{
IWeapon* pWeapon = m_pCurrentNukeSilo->getWeapon();
pWeapon->setTarget(new Target((unsigned short)m_pSelector->getNukePoint().x, (unsigned short)m_pSelector->getNukePoint().y));
}
changeState(STATE_ASSET_CONTROL);
setNukeSilo(NULL);
break;
}
break;
} // switch
// if mouse idles over asset, display tooltip showing it's name
if(!MouseState::mouseMoved && (MouseState::mouseIdle > m_TooltipTreshold))
{
if(!m_TooltipShown)
{
D3DXMATRIX matProj, matView;
D3DXVECTOR3 rayOrigin, rayDir;
m_pDevice->GetTransform(D3DTS_PROJECTION, &matProj);
m_pDevice->GetTransform(D3DTS_VIEW, &matView);
MouseState::transformTo3D(matView, matProj, rayOrigin, rayDir);
UIAsset* pUIAsset = UI3DObjectManager::pickAsset(rayOrigin, rayDir);
if(pUIAsset)
{
string assetName = pUIAsset->getAsset()->getDef()->name;
Cursor::getInstance()->setTooltip(assetName.c_str(), m_TooltipLifetime);
m_TooltipShown = true;
}
}
}
else if(m_TooltipShown)
{
m_TooltipShown = false;
Cursor::getInstance()->clearTooltip();
}
}
示例9: FUNCTION_PROFILER
//-----------------------------------------------------------------------
bool CSpectacularKill::StartOnTarget(CActor* pTargetActor)
{
FUNCTION_PROFILER(gEnv->pSystem, PROFILE_GAME);
CRY_ASSERT(pTargetActor);
CRY_ASSERT_MESSAGE(!IsBusy(), "spectacular kill should not be initiated while a spectacular kill is already in progress");
SSpectacularKillAnimation anim;
if (!IsBusy() && pTargetActor && GetValidAnim(pTargetActor, anim) && CanExecuteOnTarget(pTargetActor, anim))
{
// Disable AI
if (!pTargetActor->IsPlayer() && pTargetActor->GetEntity()->GetAI())
pTargetActor->GetEntity()->GetAI()->Event(AIEVENT_DISABLE, 0);
if (!m_pOwner->IsPlayer() && m_pOwner->GetEntity()->GetAI())
m_pOwner->GetEntity()->GetAI()->Event(AIEVENT_DISABLE, 0);
// make sure they aren't firing when the anim starts
{
IItem* pItem = pTargetActor->GetCurrentItem();
IWeapon* pWeapon = pItem ? pItem->GetIWeapon() : NULL;
if (pWeapon)
pWeapon->StopFire();
}
{
IItem* pItem = m_pOwner->GetCurrentItem();
IWeapon* pWeapon = pItem ? pItem->GetIWeapon() : NULL;
if (pWeapon)
pWeapon->StopFire();
}
SActorStats* pStats = m_pOwner->GetActorStats();
if(pStats)
{
pStats->spectacularKillPartner = pTargetActor->GetEntityId();
}
SActorStats* pTargetStats = pTargetActor->GetActorStats();
if(pTargetStats)
{
pTargetStats->spectacularKillPartner = m_pOwner->GetEntityId();
}
const float slideTime = 0.2f;
const char* pKillerAnim = anim.killerAnimation.c_str();
const char* pVictimAnim = anim.victimAnimation.c_str();
SCharacterParams killerParams(m_pOwner->GetAnimatedCharacter(), pKillerAnim, /*allowHPhysics*/false, slideTime);
SCharacterParams targetParams(pTargetActor->GetAnimatedCharacter(), pVictimAnim, /*allowHPhysics*/false, slideTime);
SCooperativeAnimParams animParams(/*forceStart*/true, /*looping*/ false, /*alignment*/ /*eAF_FirstActorNoRot*/eAF_FirstActor);
animParams.bIgnoreCharacterDeath = true;
animParams.bPreventFallingThroughTerrain = false;
animParams.bNoCollisionsBetweenFirstActorAndRest = true;
ICooperativeAnimationManager* pCooperativeAnimationManager = gEnv->pGame->GetIGameFramework()->GetICooperativeAnimationManager();
bool bStarted = pCooperativeAnimationManager->StartNewCooperativeAnimation(killerParams, targetParams, animParams);
if (bStarted)
{
m_targetId = pTargetActor->GetEntityId();
m_isBusy = true;
// Register the killing
s_lastKillInfo.killerAnim = pKillerAnim;
s_lastKillInfo.timeStamp = gEnv->pTimer->GetFrameStartTime().GetSeconds();
#ifndef _RELEASE
// Clean persistant debug information
IPersistantDebug* pPersistantDebug = BeginPersistantDebug();
// Send telemetry event
CStatsRecordingMgr* pRecordingMgr = g_pGame->GetStatsRecorder();
IStatsTracker* pTracker = pRecordingMgr ? pRecordingMgr->GetStatsTracker(m_pOwner) : NULL;
if (pTracker)
{
EGameStatisticEvent eventType = eGSE_SpectacularKill;
if(pRecordingMgr->ShouldRecordEvent(eventType, m_pOwner))
{
pTracker->Event(eventType, (anim.killerAnimation + " -> " + anim.victimAnimation).c_str());
}
}
#endif
return true;
}
}
return false;
}
示例10: ProcessEvent
virtual void ProcessEvent( EFlowEvent event,SActivationInfo *pActInfo )
{
IVehicleSystem * pVehicleSystem = NULL;
IVehicle * pVehicle = NULL;
switch(event)
{
case eFE_Initialize:
{
pActInfo->pGraph->SetRegularlyUpdated(pActInfo->myID, false);
break;
}
case eFE_Activate:
{
if (!pActInfo->pEntity)
return;
pVehicleSystem = gEnv->pGame->GetIGameFramework()->GetIVehicleSystem();
pVehicle = pVehicleSystem->GetVehicle(pActInfo->pEntity->GetId());
if (!pVehicleSystem || !pVehicle)
return;
string givenString = GetPortString(pActInfo, IN_PARTS);
currentParam = givenString.substr(0,givenString.find_first_of(":"));
currentSetting = givenString.substr(givenString.find_first_of(":")+1,(givenString.length()-givenString.find_first_of(":")));
column1 = 10.f;
column2 = 100.f;
if (IsPortActive(pActInfo,IN_SHOW))
pActInfo->pGraph->SetRegularlyUpdated(pActInfo->myID, true);
break;
}
case eFE_Update:
{
IRenderer * pRenderer = gEnv->pRenderer;
pVehicleSystem = gEnv->pGame->GetIGameFramework()->GetIVehicleSystem();
pVehicle = pVehicleSystem->GetVehicle(pActInfo->pEntity->GetId());
if(!pVehicleSystem || !pActInfo->pEntity || !pVehicle)
return;
pRenderer->Draw2dLabel(column1,10,GetPortFloat(pActInfo,IN_SIZE)+2.f,Col_Cyan,false,pActInfo->pEntity->GetName());
if(currentParam=="Seats")
{
loops = 0;
for(uint32 i=0;i<pVehicle->GetSeatCount();i++)
{
IVehicleSeat * currentSeat;
if(currentSetting=="All")
{
currentSeat = pVehicle->GetSeatById(i+1);
}
else
{
currentSeat = pVehicle->GetSeatById(pVehicle->GetSeatId(currentSetting));
i = pVehicle->GetSeatCount()-1;
}
loops += 1;
// column 1
string pMessage = ("%s:", currentSeat->GetSeatName());
if (column2<pMessage.size()*8*GetPortFloat(pActInfo, IN_SIZE))
column2=pMessage.size()*8*GetPortFloat(pActInfo, IN_SIZE);
pRenderer->Draw2dLabel(column1,(15*(float(loops+1))*GetPortFloat(pActInfo,IN_SIZE)),GetPortFloat(pActInfo,IN_SIZE),Col_Cyan,false,pMessage);
// column 2
if(currentSeat->GetPassenger(true))
{
pMessage = ("- %s", gEnv->pEntitySystem->GetEntity(currentSeat->GetPassenger(true))->GetName());
pRenderer->Draw2dLabel(column2,(15*(float(loops+1))*GetPortFloat(pActInfo,IN_SIZE)),GetPortFloat(pActInfo,IN_SIZE),Col_Cyan,false,pMessage);
}
}
}
else if(currentParam=="Wheels")
{
pRenderer->Draw2dLabel(column1,50.f,GetPortFloat(pActInfo,IN_SIZE)+1.f,Col_Red,false,"!");
}
else if(currentParam=="Weapons")
{
loops = 0;
for(int i=0;i<pVehicle->GetWeaponCount();i++)
{
IItemSystem * pItemSystem = gEnv->pGame->GetIGameFramework()->GetIItemSystem();
IWeapon * currentWeapon;
EntityId currentEntityId;
//.........这里部分代码省略.........
示例11: if
void CHUDCrosshair::Update(float fDeltaTime)
{
if(m_bBroken)
return;
IActor *pClientActor = g_pGame->GetIGameFramework()->GetClientActor();
IItemSystem *pItemSystem = g_pGame->GetIGameFramework()->GetIItemSystem();
if(!pClientActor || !pItemSystem)
return;
IInventory *pInventory = pClientActor->GetInventory();
if(!pInventory)
return;
IItem *pItem = pItemSystem->GetItem(pInventory->GetCurrentItem());
IWeapon *pWeapon = NULL;
IWeapon *pSlaveWeapon = NULL;
const float fAlternateIronSight = 0.03f;
if(pItem)
{
pWeapon = pItem->GetIWeapon();
if(pItem->IsDualWieldMaster())
{
if(IItem *pSlave=pItem->GetDualWieldSlave())
pSlaveWeapon = pSlave->GetIWeapon();
}
}
else if(IVehicle *pVehicle=pClientActor->GetLinkedVehicle())
{
pItem = pItemSystem->GetItem(pVehicle->GetCurrentWeaponId(pClientActor->GetEntityId()));
if(pItem)
pWeapon = pItem->GetIWeapon();
}
if(pWeapon)
{
float fMinSpread = 0.0f;
float fMaxSpread = 0.0f;
m_spread = 0.0f;
if(IFireMode *pFireMode=pWeapon->GetFireMode(pWeapon->GetCurrentFireMode()))
{
fMinSpread = pFireMode->GetMinSpread();
fMaxSpread = pFireMode->GetMaxSpread();
m_spread = pFireMode->GetSpread();
}
if(pSlaveWeapon)
{
if(IFireMode *pSlaveFireMode=pSlaveWeapon->GetFireMode(pSlaveWeapon->GetCurrentFireMode()))
{
fMinSpread += pSlaveFireMode->GetMinSpread();
fMaxSpread += pSlaveFireMode->GetMaxSpread();
m_spread += pSlaveFireMode->GetSpread();
}
}
CPlayer *pPlayer = static_cast<CPlayer*>(pClientActor);
if(pPlayer && pPlayer->GetNanoSuit() && pPlayer->GetNanoSuit()->GetMode() == NANOMODE_STRENGTH)
m_spread *=0.5;
if(g_pGameCVars->hud_iAlternateCrosshairSpread)
{
if(m_spread < fMinSpread)
m_spread = min(m_spread,g_pGameCVars->hud_fAlternateCrosshairSpreadCrouch) / g_pGameCVars->hud_fAlternateCrosshairSpreadCrouch;
else
m_spread = min(m_spread,g_pGameCVars->hud_fAlternateCrosshairSpreadNeutral) / g_pGameCVars->hud_fAlternateCrosshairSpreadNeutral;
}
else
{
m_spread = min((m_spread-fMinSpread),15.0f) / 15.0f;
IZoomMode *pZoomMode = pWeapon->GetZoomMode(pWeapon->GetCurrentZoomMode());
if(pZoomMode && !pZoomMode->IsToggle() && (pZoomMode->IsZoomed() || pZoomMode->IsZooming()))
{
m_spread -= fAlternateIronSight;
}
else
{
m_spread = min(m_spread,1.0f);
m_spread = max(m_spread,0.0f);
}
}
}
if(m_animCrossHair.GetVisible() && !g_pHUD->InSpectatorMode())
{
//also disables the damage indicator
if(/*g_pGameCVars->hud_crosshair>0 && m_iCrosshair > 0 &&*/ (g_pGameCVars->g_difficultyLevel<4 || gEnv->bMultiplayer))
{
m_animCrossHair.GetFlashPlayer()->Advance(fDeltaTime);
m_animCrossHair.GetFlashPlayer()->Render();
}
//.........这里部分代码省略.........