//------------------------------------------------------------------------ void CProjectile::SetParams(EntityId ownerId, EntityId hostId, EntityId weaponId, int fmId, int damage, int hitTypeId) { m_ownerId = ownerId; m_weaponId = weaponId; m_fmId = fmId; m_hostId = hostId; m_damage = damage; m_hitTypeId = hitTypeId; if (m_hostId || m_ownerId) { IEntity* pSelfEntity = GetEntity(); if (pSelfEntity) pSelfEntity->AddEntityLink("Shooter", m_ownerId); IEntity *pEntity = gEnv->pEntitySystem->GetEntity(m_hostId?m_hostId:m_ownerId); if (pEntity) { if (pSelfEntity) { //need to set AI species to the shooter - not to be scared of it's own rockets IAIActor* pAIActor = CastToIAIActorSafe(pSelfEntity->GetAI()); IAIActor* pShooterAIActor = CastToIAIActorSafe(pEntity->GetAI()); if (pAIActor && pShooterAIActor) { AgentParameters ap = pAIActor->GetParameters(); ap.m_nSpecies = pShooterAIActor->GetParameters().m_nSpecies; pAIActor->SetParameters(ap); } } if (m_pPhysicalEntity && m_pPhysicalEntity->GetType()==PE_PARTICLE) { pe_params_particle pparams; pparams.pColliderToIgnore = pEntity->GetPhysics(); m_pPhysicalEntity->SetParams(&pparams); } } } }
void CAIInput::GetState( SSerializedPlayerInput& input ) { SMovementState movementState; m_pPlayer->GetMovementController()->GetMovementState( movementState ); Quat worldRot = m_pPlayer->GetBaseQuat(); input.stance = movementState.stance; input.bodystate = 0; IAIActor* pAIActor = CastToIAIActorSafe(m_pPlayer->GetEntity()->GetAI()); if (pAIActor) { input.bodystate=pAIActor->GetState().bodystate; input.allowStrafing = pAIActor->GetState().allowStrafing; } float maxSpeed = m_pPlayer->GetStanceMaxSpeed(m_pPlayer->GetStance()); if(maxSpeed == 0.0f) maxSpeed = 1.0f; input.deltaMovement = movementState.movementDirection.GetNormalizedSafe()*movementState.desiredSpeed / maxSpeed;; input.lookDirection = movementState.eyeDirection; // PLAYERPREDICTION input.bodyDirection = movementState.entityDirection; // ~PLAYERPREDICTION input.sprint = false; input.leanl = false; input.leanr = false; IAnimationGraphState *pState=0; if (m_pPlayer->GetAnimatedCharacter()) pState=m_pPlayer->GetAnimatedCharacter()->GetAnimationGraphState(); if (pState) { input.aiming = pState->GetInputAsFloat(m_pPlayer->m_inputAiming)!=0.0f; input.usinglookik = pState->GetInputAsFloat(m_pPlayer->m_inputUsingLookIK)!=0.0f; input.pseudoSpeed=pState->GetInputAsFloat(pState->GetInputId("PseudoSpeed")); } }
////////////////////////////////////////////////////////////////////////// // 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 CNetPlayerInput::DoSetState(const SSerializedPlayerInput& input ) { // PLAYERPREDICTION m_newInterpolation |= (input.position != m_curInput.position) || (input.deltaMovement != m_curInput.deltaMovement); m_curInput = input; CHANGED_NETWORK_STATE(m_pPlayer, IPlayerInput::INPUT_ASPECT ); // not having these set seems to stop a remote avatars rotation being reflected m_curInput.aiming = true; m_curInput.allowStrafing = true; m_curInput.usinglookik = true; // ~PLAYERPREDICTION IAIActor* pAIActor = CastToIAIActorSafe(m_pPlayer->GetEntity()->GetAI()); if (pAIActor) pAIActor->GetState().bodystate=input.bodystate; CMovementRequest moveRequest; moveRequest.SetStance( (EStance)m_curInput.stance ); if(IsDemoPlayback()) { Vec3 localVDir(m_pPlayer->GetViewQuatFinal().GetInverted() * m_curInput.lookDirection); Ang3 deltaAngles(asinf(localVDir.z),0,cry_atan2f(-localVDir.x,localVDir.y)); moveRequest.AddDeltaRotation(deltaAngles*gEnv->pTimer->GetFrameTime()); } { if (m_curInput.usinglookik) moveRequest.SetLookTarget( m_pPlayer->GetEntity()->GetWorldPos() + 10.0f * m_curInput.lookDirection ); else moveRequest.ClearLookTarget(); if (m_curInput.aiming) moveRequest.SetAimTarget(moveRequest.GetLookTarget()); else moveRequest.ClearAimTarget(); } /* float pseudoSpeed = 0.0f; if (m_curInput.deltaMovement.len2() > 0.0f) { pseudoSpeed = m_pPlayer->CalculatePseudoSpeed(m_curInput.sprint); } */ // PLAYERPREDICTION moveRequest.SetPseudoSpeed(CalculatePseudoSpeed()); // ~PLAYERPREDICTION moveRequest.SetAllowStrafing(input.allowStrafing); float lean=0.0f; if (m_curInput.leanl) lean-=1.0f; if (m_curInput.leanr) lean+=1.0f; moveRequest.SetLean(lean); m_pPlayer->GetMovementController()->RequestMovement(moveRequest); IAnimationGraphState *pState=0; if (m_pPlayer->GetAnimatedCharacter()) pState=m_pPlayer->GetAnimatedCharacter()->GetAnimationGraphState(); // PLAYERPREDICTION if (pState) { pState->SetInput(m_pPlayer->m_inputAiming, m_curInput.aiming); pState->SetInput(m_pPlayer->m_inputUsingLookIK, m_curInput.usinglookik); } #if !defined(_RELEASE) // debug.. if (g_pGameCVars->g_debugNetPlayerInput & 1) { IPersistantDebug * pPD = gEnv->pGame->GetIGameFramework()->GetIPersistantDebug(); pPD->Begin( string("net_player_input_") + m_pPlayer->GetEntity()->GetName(), true ); pPD->AddSphere( moveRequest.GetLookTarget(), 0.5f, ColorF(1,0,1,1), 1.0f ); // pPD->AddSphere( moveRequest.GetMoveTarget(), 0.5f, ColorF(1,1,0,1), 1.0f ); Vec3 wp(m_pPlayer->GetEntity()->GetWorldPos() + Vec3(0,0,2)); pPD->AddDirection( wp, 1.5f, m_curInput.deltaMovement, ColorF(1,0,0,1), 1.0f ); pPD->AddDirection( wp, 1.5f, m_curInput.lookDirection, ColorF(0,1,0,1), 1.0f ); } #endif // ~PLAYERPREDICTION }