//------------------------------------------------------------------------ int CInventory::GetCountOfUniqueId(uint8 uniqueId) const { //Skip uniqueId 0 if(!uniqueId) return 0; IItemSystem *pItemSystem = gEnv->pGame->GetIGameFramework()->GetIItemSystem(); int count = 0; TInventoryCIt end = m_stats.slots.end(); for (TInventoryCIt it = m_stats.slots.begin(); it != end; ++it) { IItem *pItem = pItemSystem->GetItem(*it); if (pItem) { uint8 id = pItemSystem->GetItemUniqueId(pItem->GetEntity()->GetClass()->GetName()); if (id==uniqueId) count++; } } TInventoryVectorEx::const_iterator endEx = m_stats.accessorySlots.end(); for (TInventoryVectorEx::const_iterator cit = m_stats.accessorySlots.begin(); cit!=endEx; ++cit) { uint8 id = pItemSystem->GetItemUniqueId((*cit)->GetName()); if (id==uniqueId) count++; } return count; }
// RMI receiver in the server to remove all items from the inventory. changes are automatically propagated to the clients IMPLEMENT_RMI(CInventory, SvReq_RemoveAllItems) { IItemSystem* pItemSystem = CCryAction::GetCryAction()->GetIItemSystem(); IItem* pItem = pItemSystem->GetItem( GetCurrentItem() ); if (pItem) { pItem->Select(false); pItemSystem->SetActorItem( GetActor(), (EntityId)0, false ); } Destroy(); if (gEnv->bMultiplayer) { TRMIInventory_Dummy Info; GetGameObject()->InvokeRMI( Cl_RemoveAllAmmo(), Info, eRMI_ToAllClients); } else { ResetAmmo(); } return true; }
BOOL KHeroPackage::GetBinaryDataForClient(uint16_t* pItemLen, BYTE* pbyData, size_t uMaxBufferSize) { BOOL bResult = false; BOOL bRetCode = false; size_t uItemSize = 0; const KItemProperty* pcItemProperty = NULL; for (int i = eipEquipBegin; i < eipTotal; ++i) { pItemLen[i] = 0; IItem* pItem = GetItem(i); if (pItem == NULL) continue; bRetCode = pItem->GetBinaryDataForClient(&uItemSize, pbyData, uMaxBufferSize); KGLOG_PROCESS_ERROR(bRetCode); pItemLen[i] = (uint16_t)uItemSize; uMaxBufferSize -= uItemSize; pbyData += uItemSize; } bResult = true; Exit0: return bResult; }
bool CHeavyMountedWeapon::CanUse(EntityId userId) const { EntityId ownerId = m_owner.GetId(); if (m_rippedOff) { CActor* pActor = GetActor(userId); if (pActor && pActor->IsSwimming()) return false; if (ownerId == 0 || ownerId == userId) return true; } else if(IActor* pActor = gEnv->pGame->GetIGameFramework()->GetIActorSystem()->GetActor(userId)) { IItem* pItem = pActor->GetCurrentItem(false); if(pItem) { if(pItem->IsBusy()) { return false; } if(IWeapon* pWeapon = pItem->GetIWeapon()) { if(pWeapon->IsReloading()) { return false; } } } } return BaseClass::CanUse(userId); }
//------------------------------------------------------------------------ int CInventory::GetCountOfCategory(const char *categoryName) const { IItemSystem *pItemSystem = gEnv->pGame->GetIGameFramework()->GetIItemSystem(); int count = 0; TInventoryCIt end = m_stats.slots.end(); for (TInventoryCIt it = m_stats.slots.begin(); it != end; ++it) { IItem *pItem = pItemSystem->GetItem(*it); if (pItem) { const char *cat = pItemSystem->GetItemCategory(pItem->GetEntity()->GetClass()->GetName()); if (!strcmp(cat, categoryName)) count++; } } TInventoryVectorEx::const_iterator endEx = m_stats.accessorySlots.end(); for (TInventoryVectorEx::const_iterator cit = m_stats.accessorySlots.begin(); cit!=endEx; ++cit) { const char *cat = pItemSystem->GetItemCategory((*cit)->GetName()); if (!strcmp(cat,categoryName)) count++; } return count; }
void CInventory::PostSerialize() { for( int i=0; i<IInventory::eInventorySlot_Last; ++i ) { const int itemIndex = FindItem( m_stats.slotsInfo[i].lastSelected ); // For whatever reason we don't have this last item in the inventory, // so find a suitable item in the same slot. if( itemIndex == -1 ) { const EntityId entityId = GetAnyEntityInSlot( i ); SetLastSelectedInSlot(entityId); } } // Benito - This is last minute workaround to solve a strange bug: // If the game is saved while you had equipped a 'heavy weapon' (dynamic one, not present in the level) but this ones is holstered at the moment of save // when the game is loaded, the item is not restored properly, because the entity does not get a serialize call. // This code ensures that weapon goes back to the hands of the player, adding as many checks here as possible before doing the final call const bool ownerActorIsClientNotInVehicle = (m_pActor != NULL) && m_pActor->IsClient() && (m_pActor->GetLinkedVehicle() == NULL); if(ownerActorIsClientNotInVehicle) { IItem* pCurrentItem = gEnv->pGame->GetIGameFramework()->GetIItemSystem()->GetItem(m_stats.currentItemId); if((pCurrentItem != NULL) && (pCurrentItem->GetOwnerId() == 0)) { if(pCurrentItem->CanUse(m_pActor->GetEntityId())) { m_stats.currentItemId = 0; //Reset and use it again pCurrentItem->Use(m_pActor->GetEntityId()); } } } }
void CAICorpse::AboutToBeRemoved() { IItemSystem* pItemSystem = g_pGame->GetIGameFramework()->GetIItemSystem(); ICharacterInstance* pCharacter = GetEntity()->GetCharacter(0); IAttachmentManager* pAttachmentManager = (pCharacter != NULL) ? pCharacter->GetIAttachmentManager() : NULL; for (uint32 i = 0; i < (uint32)m_attachedItemsInfo.size(); ++i) { AttachedItem& attachedItem = m_attachedItemsInfo[i]; IItem* pItem = pItemSystem->GetItem( attachedItem.id ); if((pItem != NULL) && ShouldDropOnCorpseRemoval( pItem->GetEntity()->GetClass() )) { IAttachment* pAttachment = (pAttachmentManager != NULL) ? pAttachmentManager->GetInterfaceByName( attachedItem.attachmentName.c_str() ) : NULL; if(pAttachment != NULL) { pAttachment->ClearBinding(); } pItem->Drop( 1.0f, false, true ); pItem->GetEntity()->SetFlags( pItem->GetEntity()->GetFlags() & ~ENTITY_FLAG_NO_SAVE ); attachedItem.id = 0; } } }
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(); } } }
//------------------------------------------------------------------------ void CGunTurret::OnTargetLocked(IEntity *pTarget) { if(pTarget) PlayAction(g_pItemStrings->lock); if(IsServer()) { // if this turret has others linked, notify them about acquired target for(IEntityLink *pLink = GetEntity()->GetEntityLinks(); pLink; pLink = pLink->next) { if(0 != strcmp(pLink->name, "TargetInfo")) continue; IItem *pItem = g_pGame->GetIGameFramework()->GetIItemSystem()->GetItem(pLink->entityId); if(pItem) { SGameObjectEvent event(pTarget?eCGE_Turret_LockedTarget:eCGE_Turret_LostTarget, eGOEF_ToExtensions); event.ptr = pTarget; pItem->GetGameObject()->SendEvent(event); } } } if(IsClient()) { m_pGameFramework->GetMusicLogic()->SetEvent(eMUSICLOGICEVENT_PLAYER_TURRET_ATTACK); } }
EntityId CAICorpse::CloneAttachedItem( const CAICorpse::AttachedItem& attachedItem, IAttachment* pAttachment ) { stack_string clonedItemName; clonedItemName.Format("%s_%s", GetEntity()->GetName(), attachedItem.pClass->GetName() ); SEntitySpawnParams params; params.sName = clonedItemName.c_str(); params.pClass = attachedItem.pClass; // Flag as 'No Save' they will be recreated during serialization if needed params.nFlags |= (ENTITY_FLAG_NO_SAVE); IEntity *pClonedItemEntity = gEnv->pEntitySystem->SpawnEntity(params); assert (pClonedItemEntity != NULL); IItem* pClonedItem = g_pGame->GetIGameFramework()->GetIItemSystem()->GetItem(pClonedItemEntity->GetId()); assert(pClonedItem != NULL); pClonedItem->Physicalize(false, false); pClonedItem->SetOwnerId( GetEntityId() ); // Set properties table to null, since they'll not be used IScriptTable* pClonedItemEntityScript = pClonedItemEntity->GetScriptTable(); if (pClonedItemEntityScript != NULL) { pClonedItemEntity->GetScriptTable()->SetToNull("Properties"); } // Swap attachments CEntityAttachment* pEntityAttachement = new CEntityAttachment(); pEntityAttachement->SetEntityId( pClonedItemEntity->GetId() ); pAttachment->AddBinding( pEntityAttachement ); return pClonedItemEntity->GetId(); }
//------------------------------------------------------------------------ void CInventory::HolsterItem(bool holster) { //CryLogAlways("%s::HolsterItem(%s)", GetEntity()->GetName(), holster?"true":"false"); if (!holster) { if (m_stats.holsteredItemId) { IItem* pItem = m_pGameFrameWork->GetIItemSystem()->GetItem(m_stats.holsteredItemId); if(pItem && pItem->CanSelect()) { m_pGameFrameWork->GetIItemSystem()->SetActorItem(GetActor(), m_stats.holsteredItemId, false); } else { m_pGameFrameWork->GetIItemSystem()->SetActorItem(GetActor(), GetLastItem(), false); } } m_stats.holsteredItemId = 0; } else if (m_stats.currentItemId && (!m_stats.holsteredItemId || m_stats.holsteredItemId == m_stats.currentItemId)) { m_stats.holsteredItemId = m_stats.currentItemId; m_pGameFrameWork->GetIItemSystem()->SetActorItem(GetActor(), (EntityId)0, false); } }
//--------------------------------------------- CWeapon* CLaser::GetWeapon() const { IItem* pParentItem = m_pItemSystem->GetItem(GetParentId()); if(pParentItem == NULL) return 0; CWeapon* pParentWeapon = static_cast<CWeapon*>(pParentItem->GetIWeapon()); return pParentWeapon; }
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 CPlayerEntityInteraction::ReleaseHeavyWeapon(CPlayer* pPlayer) { IItem* pCurrentItem = pPlayer->GetCurrentItem(); if (pCurrentItem && PlayerCanInteract(pPlayer)) { EntityId heavyWeaponEntity = pCurrentItem->GetEntityId(); CallEntityScriptMethod( heavyWeaponEntity, "OnUsed", pPlayer, 0); } }
CWeapon* CFlashLight::GetWeapon() const { IItem* pParentItem = m_pItemSystem->GetItem(GetParentId()); if (pParentItem == NULL) { return 0; } CWeapon* pParentWeapon = static_cast<CWeapon*>(pParentItem->GetIWeapon()); return pParentWeapon; }
CWeapon* CCinematicInput::GetWeapon(const CCinematicInput::Weapon& weaponClass) const { assert( (weaponClass >= 0) && (weaponClass < eWeapon_ClassCount) ); if (m_weapons[weaponClass].m_weaponId != 0) { IItem* pItem = g_pGame->GetIGameFramework()->GetIItemSystem()->GetItem(m_weapons[weaponClass].m_weaponId); return (pItem != NULL) ? static_cast<CWeapon*>(pItem->GetIWeapon()) : NULL; } return NULL; }
void CFlowItemAction::Update(SActivationInfo* pActInfo) { m_timerCountDown -= gEnv->pTimer->GetFrameTime(); if (m_timerCountDown > 0.0f) return; IItem* pItem = GetItem(pActInfo); if (pItem) pItem->SetBusy(false); pActInfo->pGraph->SetRegularlyUpdated(pActInfo->myID, false); ActivateOutput(pActInfo, IAO_Done, 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 ) { 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; } }
//------------------------------------------------------------------------ void CItem::ResetDualWield() { if (m_dualWieldSlaveId) { IItem *pSlave = GetDualWieldSlave(); if (pSlave) pSlave->ResetDualWield(); } SetActionSuffix(""); EnableSelect(true); m_dualWieldSlaveId = 0; m_dualWieldMasterId = 0; }
QVariant ButtonsDefinitionExtension::data(const QModelIndex& index, int role) const { ItemRole::Id roleId; if (!decodeRole(role, roleId)) { return QVariant(); } TF_ASSERT(index.isValid()); IItem* item = reinterpret_cast<IItem*>(index.internalPointer()); if (item == nullptr || roleId != buttonsDefinitionRole::roleId_) { return QVariant(); } return get<IQtHelpers>()->toQVariant(item->getData(index.column(), roleId), nullptr); }
//------------------------------------------------------------------------ CWeapon *CScriptBind_Weapon::GetWeapon(IFunctionHandler *pH) { void *pThis = pH->GetThis(); if (pThis) { IItem *pItem = m_pGameFW->GetIItemSystem()->GetItem((EntityId)(UINT_PTR)pThis); if (pItem) { IWeapon *pWeapon=pItem->GetIWeapon(); if (pWeapon) return static_cast<CWeapon *>(pWeapon); } } return 0; }
//---------------------------------------------- void CC4Detonator::SelectC4() { if (CActor *pOwner = GetOwnerActor()) { EntityId c4Id = pOwner->GetInventory()->GetItemByClass(CItem::sC4Class); if (c4Id) { //Do not reselect C4 is there's no ammo IItem *pItem = m_pItemSystem->GetItem(c4Id); CWeapon *pWep = pItem ? static_cast<CWeapon *>(pItem->GetIWeapon()) : NULL; if(pWep && pWep->OutOfAmmo(false)) { return; } pOwner->SelectItemByName("C4", false); } } }
// RMI receiver in the server to remove an item from the inventory. change is automatically propagated to the clients IMPLEMENT_RMI(CInventory, SvReq_RemoveItem) { TRMIInventory_Item Info(params); IItemSystem* pItemSystem = CCryAction::GetCryAction()->GetIItemSystem(); IEntityClass* pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass( Info.m_ItemClass.c_str()); if (pClass) { IItem* pItem = pItemSystem->GetItem( GetItemByClass( pClass ) ); if (pItem && pItem->GetEntityId()==GetCurrentItem()) { pItem->Select(false); pItemSystem->SetActorItem( GetActor(), (EntityId)0, false ); } if (pItem) gEnv->pEntitySystem->RemoveEntity( pItem->GetEntityId() ); } return true; }
//------------------------------------------------------------------------ void CInventory::Destroy() { // //CryLog("%s::CInventory::Destroy()",GetEntity()->GetName()); // if(!GetISystem()->IsSerializingFile()) { IEntitySystem *pEntitySystem = gEnv->pEntitySystem; IItemSystem *pItemSystem = gEnv->pGame->GetIGameFramework()->GetIItemSystem(); TInventoryVector deleteList = m_stats.slots; for (TInventoryIt it = deleteList.begin(); it != deleteList.end(); ++it) { EntityId entityId = *it; IItem *pItem = pItemSystem->GetItem(entityId); if (pItem) { RemoveItemFromCategorySlot(pItem->GetEntityId()); pItem->RemoveOwnerAttachedAccessories(); pItem->AttachToHand(false); pItem->AttachToBack(false); pItem->SetOwnerId(0); } pEntitySystem->RemoveEntity(entityId); } } Clear(); }
void PlayerUnit::collideJudge(){ std::pair<ObjectMap::iterator, ObjectMap::iterator> itPair = ObjectMng.getRange(ENEMY); while(itPair.first != itPair.second){ IEnemy* ptr = dynamic_cast<IEnemy*>(itPair.first->second); if(ptr && ptr->isCollision() && Collision::collision(this, ptr)){ hitAction(ptr); } ++itPair.first; } itPair = ObjectMng.getRange(ENEMY_BULLET); while(itPair.first != itPair.second){ IEnemyBullet* ptr = dynamic_cast<IEnemyBullet*>(itPair.first->second); if(ptr && ptr->isCollision() && Collision::collision(this, ptr)){ hitAction(ptr); ptr->hitAction(this); } ++itPair.first; } itPair = ObjectMng.getRange(ITEM); while(itPair.first != itPair.second){ IItem* ptr = dynamic_cast<IItem*>(itPair.first->second); if(ptr && ptr->isCollision() && Collision::collision(this, ptr)){ ptr->hitAction(this); } ++itPair.first; } }
BOOL KHeroPackage::UnApplyEquip(KHero* pHero) { BOOL bResult = false; BOOL bRetCode = false; const KItemProperty* pcItemProperty = NULL; for (int i = eipEquipBegin; i < eipTotal; ++i) { IItem* pItem = GetItem(i); if (pItem == NULL) continue; pcItemProperty = pItem->GetProperty(); KGLOG_PROCESS_ERROR(pcItemProperty); pHero->UnApplyAttribute(pcItemProperty->pBaseAttr); pHero->UnApplyAttribute(pcItemProperty->pExtAttr); } bResult = true; Exit0: return bResult; }
//------------------------------------------------------ void CWeapon::ForcePendingActions(uint8 blockedActions) { CItem::ForcePendingActions(blockedActions); CActor* pOwner = GetOwnerActor(); if(!pOwner || !pOwner->IsClient()) return; //Force start firing, if needed and possible if(m_requestedFire) { if(!IsDualWield() && !IsWeaponRaised()) { m_requestedFire = false; OnAction(GetOwnerId(),"attack1",eAAM_OnPress,0.0f); } else if(IsDualWield() && IsDualWieldMaster()) { IItem *slave = GetDualWieldSlave(); if(!IsWeaponRaised()) { m_requestedFire = false; OnAction(GetOwnerId(),"attack1",eAAM_OnPress,0.0f); } else if(slave && slave->GetIWeapon()) { CWeapon* dualwield = static_cast<CWeapon*>(slave); if(!dualwield->IsWeaponRaised()) { m_requestedFire = false; OnAction(GetOwnerId(),"attack1",eAAM_OnPress,0.0f); } } } } }
void CFlowItemAction::Activate(SActivationInfo* pActInfo) { IItem* pItem = GetItem(pActInfo); if (!pItem) return; CItem* pItemImpl = static_cast<CItem*>(pItem); bool busy = GetPortBool(pActInfo, IAI_Busy); bool loop = GetPortBool(pActInfo, IAI_Loop); const string& actionName = GetPortString(pActInfo, IAI_Action); FragmentID fragID = pItemImpl->GetFragmentID(actionName); pItemImpl->PlayAction(fragID, 0, loop); if (busy) { pItem->SetBusy(true); } if (busy || !loop) { uint ownerAnimationtime = pItemImpl->GetCurrentAnimationTime(eIGS_Owner); StartDoneCountDown(pActInfo, ownerAnimationtime / (float)1000.0f); } }
////////////////////////////////////////////////////////////////////////// // 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); }