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(); } } }
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; }
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; }
//--------------------------------------- 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); } } }
void ProcessEvent(EFlowEvent event, SActivationInfo *pActInfo) { IWeapon* pWeapon = GetWeapon(pActInfo); if (!pWeapon) return; switch (event) { case eFE_Activate: if (pWeapon) pWeapon->StartChangeFireMode(); break; } }
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)); } } } }
void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo ) { switch (event) { case (eFE_Activate): { if (!IsPortActive(pActInfo, 0)) return; IItemSystem* pItemSys = CCryAction::GetCryAction()->GetIItemSystem(); // get actor IActor* pActor = CCryAction::GetCryAction()->GetClientActor(); if (!pActor) return; IInventory *pInventory = pActor->GetInventory(); if (!pInventory) return; IEntityClass* pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(GetPortString(pActInfo,1)); IItem* pItem = pItemSys->GetItem(pInventory->GetItemByClass(pClass)); if (!pItem || !pItem->GetIWeapon()) { pItem = pActor->GetCurrentItem(); if (!pItem || pItem->GetEntity()->GetClass() != pClass || !pItem->GetIWeapon()) { GameWarning("[flow] CFlowNode_WeaponAmmo: No item/weapon %s!", GetPortString(pActInfo,1).c_str()); return; } } IWeapon *pWeapon = pItem->GetIWeapon(); const string& ammoType = GetPortString(pActInfo,2); IEntityClass* pAmmoClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(ammoType.c_str()); CRY_ASSERT(pAmmoClass); IFireMode* pCurrentFireMode = pWeapon->GetFireMode(pWeapon->GetCurrentFireMode()); if (pCurrentFireMode) { int clipSize = pCurrentFireMode->GetClipSize(); int ammo = pWeapon->GetAmmoCount(pAmmoClass) + GetPortInt(pActInfo,3); ammo = CLAMP(ammo, 0, clipSize); pWeapon->SetAmmoCount(pAmmoClass, ammo); } ActivateOutput(pActInfo, 0, pWeapon->GetAmmoCount(pAmmoClass)); } break; } }
////////////////////////////////////////////////////////////////////////// // IsMountedWeaponUsableWithTarget // A piece of game-code moved from CryAction when scriptbind_AI moved to the AI system ////////////////////////////////////////////////////////////////////////// int CScriptBind_Game::IsMountedWeaponUsableWithTarget(IFunctionHandler *pH) { int paramCount = pH->GetParamCount(); if(paramCount<2) { GameWarning("%s: too few parameters.", __FUNCTION__); return pH->EndFunction(); } GET_ENTITY(1); if(!pEntity) { GameWarning("%s: wrong entity id in parameter 1.", __FUNCTION__); return pH->EndFunction(); } IAIObject* pAI = pEntity->GetAI(); if (!pAI) { GameWarning("%s: Entity '%s' does not have AI.",__FUNCTION__, pEntity->GetName()); return pH->EndFunction(); } EntityId itemEntityId; ScriptHandle hdl2; if(!pH->GetParam(2,hdl2)) { GameWarning("%s: wrong parameter 2 format.", __FUNCTION__); return pH->EndFunction(); } itemEntityId = (EntityId)hdl2.n; if (!itemEntityId) { GameWarning("%s: wrong entity id in parameter 2.", __FUNCTION__); return pH->EndFunction(); } IGameFramework *pGameFramework = gEnv->pGame->GetIGameFramework(); IItem* pItem = pGameFramework->GetIItemSystem()->GetItem(itemEntityId); if (!pItem) { //gEnv->pAISystem->Warning("<CScriptBind> ", "entity in parameter 2 is not an item/weapon"); GameWarning("%s: entity in parameter 2 is not an item/weapon.", __FUNCTION__); return pH->EndFunction(); } float minDist = 7; bool bSkipTargetCheck = false; Vec3 targetPos(ZERO); if(paramCount > 2) { for(int i=3;i <= paramCount ; i++) { if(pH->GetParamType(i) == svtBool) pH->GetParam(i,bSkipTargetCheck); else if(pH->GetParamType(i) == svtNumber) pH->GetParam(i,minDist); else if(pH->GetParamType(i) == svtObject) pH->GetParam(i,targetPos); } } IAIActor* pAIActor = CastToIAIActorSafe(pAI); if (!pAIActor) { GameWarning("%s: entity '%s' in parameter 1 is not an AI actor.", __FUNCTION__, pEntity->GetName()); return pH->EndFunction(); } 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); }
void UIAssetController::updateControls(const float frameTime) { // update build queues map<IAsset*,BuildQueue*>::iterator p; for(p = m_BuildQueues.begin(); p != m_BuildQueues.end(); p++) { if(p->second == m_pCurrentBuildQueue) p->second->update(true); // visible queue, update logic & visual else p->second->update(false); // non-visible queue, update only logic } // @TODO: update build status to buttons if(!m_ButtonsToUpdate.empty()) { IAsset* asset; BasicButton* button; ListNode<BasicButton*>* node = m_ButtonsToUpdate.headNode(); while(node) { button = node->item; asset = (IAsset*)button->getRandomObject(); if(asset && asset->getState() == IAsset::STATE_BEING_BUILT) { int percentage = (int)(asset->getHitpoints() / asset->getHitpointsMax() * 100); button->setLoadingStatus(percentage); node = node->next; } else { button->setEnabled(true); node = m_ButtonsToUpdate.removeGetNext(node); } } } // update nuke button if (m_pCurrentNukeSilo) { int percentage = (int)(m_pCurrentNukeSilo->getWeapon()->getLoadingPercentage() * 100); if (percentage < 1) { m_pNukeButton->setLoadingStatus(100); m_pNukeButton->setEnabled(true); } else { m_pNukeButton->setLoadingStatus(percentage); m_pNukeButton->setEnabled(false); } } bool pickModifier = (!m_KeyPickModifier || KeyboardState::keyDown[m_KeyPickModifier]) ? true : false; bool actionModifier = (!m_KeyActionModifier || KeyboardState::keyDown[m_KeyActionModifier]) ? true : false; switch(m_State) { // ===== case STATE_ASSET_CONTROL: if(pickModifier && MouseState::mouseButton[m_KeyMousePickButton]) onPickButton(frameTime); else if(pickModifier && MouseState::mouseButtonReleased[m_KeyMousePickButton]) onPickRelease(frameTime); else if(MouseState::mouseButtonReleased[m_KeyMouseActionButton]) onActionRelease(frameTime); else if(MouseState::mouseButton[m_KeyMouseActionButton]) onActionButton(frameTime); 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(); } }
void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo ) { IWeapon* pWeapon = GetWeapon(pActInfo); if (!pWeapon) return; switch (event) { case eFE_Initialize: { m_isFiring = false; m_numShots = GetPortInt( pActInfo, IN_NUMBEROFSHOTS ); m_actInfo = *pActInfo; m_numShotsDone = 0; pWeapon->StopFire(); if (pActInfo->pEntity->GetId() != m_weapId) RemoveListener(m_weapId, this); m_weapId = pActInfo->pEntity->GetId(); pWeapon->AddEventListener(this, __FUNCTION__); #ifdef DEBUG_NODEFIREWEAPON pActInfo->pGraph->SetRegularlyUpdated( pActInfo->myID, true ); #endif break; } case eFE_Activate: { m_actInfo = *pActInfo; if (IsPortActive(pActInfo, IN_NUMBEROFSHOTS)) m_numShots = GetPortBool( pActInfo, IN_NUMBEROFSHOTS ); if (IsPortActive(pActInfo, IN_STOPFIRE)) { StopFiring( pActInfo, pWeapon ); } if (IsPortActive(pActInfo, IN_STARTFIRE)) { m_numShotsDone = 0; ReplenishAmmo( pWeapon ); pWeapon->StopFire(); StartFiring( pActInfo, pWeapon ); } break; } case eFE_Update: { // this fixes the problem when the entity is being externally moved/rotated, in the interval of time between when the weapon is aimed an the actual shot happens if (m_isFiring && GetPortBool( pActInfo, IN_ALIGNTOTARGET )) if (pActInfo->pEntity->GetWorldPos()!=m_lastPos || pActInfo->pEntity->GetWorldRotation()!=m_lastRotation) CalcFiringPosition( pActInfo, pWeapon ); #ifdef DEBUG_NODEFIREWEAPON ColorB colorRed( 255,0,0 ); ColorB colorGreen( 0,255,0 ); gEnv->pRenderer->GetIRenderAuxGeom()->DrawLine( posOrig, colorRed, posTarget, colorRed ); gEnv->pRenderer->GetIRenderAuxGeom()->DrawLine( posTarget, colorGreen, posShot, colorGreen ); #endif break; } } }
void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo ) { switch (event) { case eFE_Initialize: { m_actInfo = *pActInfo; Reset(); } break; case eFE_Activate: { IItemSystem* pItemSys = CCryAction::GetCryAction()->GetIItemSystem(); // create listener if (IsPortActive(pActInfo, IN_DISABLE)) { Reset(); } if (IsPortActive(pActInfo, IN_ENABLE)) { Reset(); IItem* pItem = 0; EntityId weaponId = GetPortEntityId(pActInfo, IN_WEAPONID); if (weaponId != 0) { pItem = pItemSys->GetItem(weaponId); } else { IActor* pActor = CCryAction::GetCryAction()->GetClientActor(); if (!pActor) return; IInventory *pInventory = pActor->GetInventory(); if (!pInventory) return; const string& weaponClass = GetPortString(pActInfo, IN_WEAPONCLASS); if (!weaponClass.empty()) { // get actor weapon by class IEntityClass* pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(weaponClass); pItem = pItemSys->GetItem( pInventory->GetItemByClass(pClass) ); } else { // get current actor weapon pItem = pItemSys->GetItem(pInventory->GetCurrentItem()); } } if (!pItem || !pItem->GetIWeapon()) { GameWarning("[flow] CFlowNode_WeaponListener: no item/weapon."); return; } m_weapId = pItem->GetEntity()->GetId(); IWeapon* pWeapon = pItem->GetIWeapon(); // set initial ammo m_ammo = GetPortInt(pActInfo, IN_AMMO); if (m_ammo == 0) m_ammo = -1; // 0 input means infinite // set weapon listener pWeapon->AddEventListener(this, "CFlowNode_WeaponListener"); m_active = true; //CryLog("WeaponListener successfully created on %s", pItem->GetEntity()->GetName()); } break; } } }
//----------------------------------------------------------------------- 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; }
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; IItem * pItem; if(currentSetting=="All") { currentEntityId = pVehicle->GetWeaponId(i+1); } else { currentEntityId = gEnv->pEntitySystem->FindEntityByName(currentSetting)->GetId(); i = pVehicle->GetWeaponCount()-1; } if(!pItemSystem->GetItem(currentEntityId)) return; pItem = pItemSystem->GetItem(currentEntityId); currentWeapon = pItem->GetIWeapon(); loops += 1; // column 1 string pMessageName = string().Format("%s", gEnv->pEntitySystem->GetEntity(currentEntityId)->GetName()); pRenderer->Draw2dLabel(column1,(15*(float(loops+1))*GetPortFloat(pActInfo,IN_SIZE)),GetPortFloat(pActInfo,IN_SIZE),Col_Cyan,false,pMessageName); if (column2<pMessageName.size()*8*GetPortFloat(pActInfo, IN_SIZE)) column2=pMessageName.size()*8*GetPortFloat(pActInfo, IN_SIZE); // column 2 string pMessageValue = string().Format("seat: %s firemode: %i", pVehicle->GetWeaponParentSeat(currentEntityId)->GetSeatName(), currentWeapon->GetCurrentFireMode()).c_str(); pRenderer->Draw2dLabel(column2,(15*(float(loops+1))*GetPortFloat(pActInfo,IN_SIZE)),GetPortFloat(pActInfo,IN_SIZE),Col_Cyan,false,pMessageValue); } } else if(currentParam=="Components") { loops = 0; for(int i=0;i<pVehicle->GetComponentCount();i++) { IVehicleComponent * currentComponent; if(currentSetting=="All") { currentComponent = pVehicle->GetComponent(i); } else { currentComponent = pVehicle->GetComponent(currentSetting); i = pVehicle->GetComponentCount()-1; } loops += 1; ColorF labelColor; labelColor = ColorF(currentComponent->GetDamageRatio(),(1.f-currentComponent->GetDamageRatio()),0.f); // column 1 string pMessageName = string().Format("%s", currentComponent->GetComponentName()).c_str(); pRenderer->Draw2dLabel(column1,(15*(float(loops+1))*GetPortFloat(pActInfo,IN_SIZE)),GetPortFloat(pActInfo,IN_SIZE),labelColor,false,pMessageName); if (column2<pMessageName.size()*8*GetPortFloat(pActInfo, IN_SIZE)) column2=pMessageName.size()*8*GetPortFloat(pActInfo, IN_SIZE); // column 2 string pMessageValue = string().Format("%5.2f (%3.2f)", currentComponent->GetDamageRatio()*currentComponent->GetMaxDamage(), currentComponent->GetDamageRatio()).c_str(); pRenderer->Draw2dLabel(column2,(15*(float(loops+1))*GetPortFloat(pActInfo,IN_SIZE)),GetPortFloat(pActInfo,IN_SIZE),labelColor,false,pMessageValue); } } else { pRenderer->Draw2dLabel(column1,50.f,GetPortFloat(pActInfo,IN_SIZE)+1.f,Col_Red,false,"no component selected!"); } break; } } };
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(); } if(m_animInterActiveIcons.GetVisible()) //if the crosshair is invisible, the use icon should be too { if(!m_bHideUseIconTemp) //hides the icon, when something is already grabbed/being used { m_animInterActiveIcons.GetFlashPlayer()->Advance(fDeltaTime); m_animInterActiveIcons.GetFlashPlayer()->Render(); } } } if(m_animFriendCross.GetVisible()) { m_animFriendCross.GetFlashPlayer()->Advance(fDeltaTime); m_animFriendCross.GetFlashPlayer()->Render(); } if(!g_pGameCVars->hud_iAlternateCrosshairSpread) { m_spread = max(m_spread,-fAlternateIronSight); m_spread = min(m_spread,1.0f); } if (m_smoothSpread != m_spread) { Interpolate(m_smoothSpread, m_spread, 20.0f, fDeltaTime); m_animCrossHair.Invoke("setRecoil", m_smoothSpread); } UpdateCrosshair(); }