CSkeleton::ESkeletonStates CSkeleton::Manuver() { XMFLOAT3 tVector(0.0f, m_f3Velocity.y, 0.0f); // Update the timer ResetManuverVector(m_nChance, tVector); m_fExitTimer -= DELTA_TIME(); if (m_fExitTimer < 0.0f) { m_nManuverCount++; m_fExitTimer = 1.5f; if (m_nManuverCount == m_nManuverCount) return MOVING_IN; } Steering().Seek(*GetPlayer()->GetPosition()); if (m_bIsGrounded) { Steering().Update(false, m_fScale); SetWorldVelocity(tVector); } else SetWorldVelocity({ knockBackVelocity.x, m_f3Velocity.y, knockBackVelocity.z }); return MANUVERING; }
static Action_SkBuff steering_field(arguments_t args, SkBuff b) { uint32_t offset = get_arg_0(uint32_t, args); uint32_t size = get_arg_1(uint32_t, args); uint32_t data, *ptr; uint32_t mask; if (size > (sizeof(data)*8)) { /* size is number of bits */ if (printk_ratelimit()) { printk(KERN_INFO "[PFQ] steering_field: bit-size too big (max. 32)!\n"); return Drop(b); } } ptr = skb_header_pointer(b.skb, offset, sizeof(uint32_t), &data); if (ptr == NULL) return Drop(b); mask = (1ULL << size) - 1; return Steering(b, *ptr & mask); }
static Action_SkBuff steering_vlan_id(arguments_t args, SkBuff b) { if (b.skb->vlan_tci & VLAN_VID_MASK) return Steering(b, b.skb->vlan_tci & VLAN_VID_MASK); else return Drop(b); }
static Action_SkBuff steering_link(arguments_t args, SkBuff b) { uint32_t * w; w = (uint32_t *)eth_hdr(b.skb); return Steering(b, w[0] ^ w[1] ^ w[2]); // 3 * sizeof(uint32_t) = 12 bytes. }
static Action_SkBuff steering_ip(arguments_t args, SkBuff b) { if (eth_hdr(b.skb)->h_proto == __constant_htons(ETH_P_IP)) { struct iphdr _iph; const struct iphdr *ip; __be32 hash; ip = skb_header_pointer(b.skb, b.skb->mac_len, sizeof(_iph), &_iph); if (ip == NULL) return Drop(b); hash = ip->saddr ^ ip->daddr; return Steering(b, *(uint32_t *)&hash); } return Drop(b); }
void Projectile::TurnToTarget( float _dt ) { // Calculate the vector from this token to the Target's position D3DXVECTOR2 vToTarget(0,0); D3DXVECTOR2 tDefault(0,-1); D3DXVECTOR2 pos = ((BaseEntity*)m_Target)->GetPos() + ((BaseEntity*)m_Target)->GetImgCenter(); vToTarget.x = pos.x - (this->GetPos().x + this->GetImgCenter().x); vToTarget.y = pos.y - (this->GetPos().y + this->GetImgCenter().y); // Calculate forward vector D3DXVECTOR2 forward = Rotate2D( tDefault, this->GetRot() ); // calculate the angle between the vectors float angle = AngleBetweenVectors( vToTarget, forward ); if(Steering(forward, vToTarget) < 0.0f) this->SetRot(this->GetRot() - 3.0f*_dt); else this->SetRot(this->GetRot() + 3.0f*_dt); forward = Rotate2D( tDefault, this->GetRot() ); D3DXVec2Normalize(&forward,&forward); this->SetDir(forward); }
void CGuard::ComputeMovement(float fElapsedTime) { tVector2D myvec; myvec.fX = this->GetLook().fX; myvec.fY = this->GetLook().fY; tVector2D playervec; playervec.fX = pPlayer->GetPosX() - this->GetPosX(); playervec.fY = pPlayer->GetPosY() - this->GetPosY(); tVector2D rightvec = Vector2DRotate(myvec,1.57f); float dot = DotProduct(rightvec,playervec); if(Steering(myvec,playervec) > 0) // clockwise { /*myvec = Vector2DRotate(myvec,3.14*fElapsedTime); this->SetRotation(this->GetRotation() + 3.14*fElapsedTime); this->SetLook(myvec);*/ myvec = Vector2DRotate(myvec,0.9f*fElapsedTime); this->SetRotation(this->GetRotation() + 0.9f*fElapsedTime); this->SetLook(myvec); } else { /*myvec = Vector2DRotate(myvec,-3.14*fElapsedTime); this->SetRotation(this->GetRotation() - 3.14*fElapsedTime); this->SetLook(myvec);*/ myvec = Vector2DRotate(myvec,(-0.9f)*fElapsedTime); this->SetRotation(this->GetRotation() + (-0.9f)*fElapsedTime); this->SetLook(myvec); } }
CSkeleton::ESkeletonStates CSkeleton::Follow() { if (NearlyEqual(GetCurrAnimation()->GetCurrTime(), 0.05f)) { AudioSystemWwise::Get()->PostEvent(AK::EVENTS::PLAYERFOOTSTEP, *GetPosition()); } if (NearlyEqual(GetCurrAnimation()->GetCurrTime(), 0.5f)) { AudioSystemWwise::Get()->PostEvent(AK::EVENTS::PLAYERFOOTSTEP, *GetPosition()); } if (m_bIsGrounded) SetWorldVelocity({ 0, m_f3Velocity.y, 0 }); else SetWorldVelocity({ knockBackVelocity.x, m_f3Velocity.y, knockBackVelocity.z }); // Get the current path vector<XMFLOAT3>& vPath = GetPath(); // path here from group // Get the current velocity //XMVECTOR currentVelocity; XMLoadFloat3(&m_f3vel); if (DistanceToPlayer() < 500.0f) { return MOVING_IN; } // Node that I'm on along the path int nCurrentNode = GetCurNodeOnPath(); if (nCurrentNode < 0 || vPath.empty()) { BuildPathToPlayer(); vPath = GetPath(); if (vPath.size() < 2) { return FOLLOW; } } nCurrentNode = GetCurNodeOnPath(); // Get the current positions XMFLOAT3 curPos = *GetPosition(); XMFLOAT3 targetPos = vPath[nCurrentNode]; // Convert them for math XMVECTOR mathPos = XMLoadFloat3(&curPos); XMVECTOR mathTarget = XMLoadFloat3(&targetPos); // Find the vector between the two points XMVECTOR mathToVec = XMVectorSubtract(mathTarget, mathPos); //XMFLOAT3 toVec; XMStoreFloat3(&toVec, mathToVec); // Normalize the toVector to get the direction XMVECTOR mathVelocity = XMVector3Normalize(mathToVec); // Add the separation factor // mathVelocity += GetParentGroup()->CalculateSeparation(this); mathVelocity *= MOVE_SPEED; XMFLOAT3 realVelocity; XMStoreFloat3(&realVelocity, mathVelocity); realVelocity.y = m_f3Velocity.y; // Get the distance to target - ANY XYZ HOLDS THE LENGTH XMVECTOR mathDistToTarget = XMVector3Length(mathToVec); XMFLOAT3 distToTarget; XMStoreFloat3(&distToTarget, mathDistToTarget); // Offset the current node float nNextNodeDistance = 300.0f; // If i reached the node, move on the next one if (distToTarget.x < nNextNodeDistance && nCurrentNode >= 0) { nCurrentNode--; } Steering().Seek(targetPos); if (m_bIsGrounded) { Steering().Update(false, m_fScale); SetWorldVelocity(realVelocity); } SetNodeOnPath(nCurrentNode); return FOLLOW; }
CSkeleton::ESkeletonStates CSkeleton::Retreating() { if (NearlyEqual(GetCurrAnimation()->GetCurrTime(), 0.05f)) AudioSystemWwise::Get()->PostEvent(AK::EVENTS::PLAYERFOOTSTEP, *GetPosition()); if (NearlyEqual(GetCurrAnimation()->GetCurrTime(), 0.5f)) AudioSystemWwise::Get()->PostEvent(AK::EVENTS::PLAYERFOOTSTEP, *GetPosition()); if (m_bIsGrounded) SetWorldVelocity({ 0, m_f3Velocity.y, 0 }); else SetWorldVelocity({ knockBackVelocity.x, m_f3Velocity.y, knockBackVelocity.z }); // Get the current path vector<XMFLOAT3>& vPath = GetPath(); // path here from group // Node that I'm on along the path int nCurrentNode = GetCurNodeOnPath(); // Clamp CurNode to 0 and max if (nCurrentNode < 0) return DEATH; // If no path was generated, then return if (vPath.size() <= 0) { nCurrentNode = -1; return DEATH; } // Get the current positions XMFLOAT3 curPos = *GetPosition(); XMFLOAT3 targetPos = vPath[nCurrentNode]; // Convert them for math XMVECTOR mathPos = XMLoadFloat3(&curPos); XMVECTOR mathTarget = XMLoadFloat3(&targetPos); // Find the vector between the two points XMVECTOR mathToVec = XMVectorSubtract(mathTarget, mathPos); // Normalize the toVector to get the direction XMVECTOR mathVelocity = XMVector3Normalize(mathToVec); // Add the separation factor //mathVelocity += GetParentGroup()->CalculateSeparation(this); //mathVelocity += GetParentGroup()->CalculateAlignment(); mathVelocity *= MOVE_SPEED; XMFLOAT3 realVelocity; XMStoreFloat3(&realVelocity, mathVelocity); realVelocity.y = m_f3Velocity.y; // Get the distance to target - ANY XYZ HOLDS THE LENGTH XMVECTOR mathDistToTarget = XMVector3Length(mathToVec); XMFLOAT3 distToTarget; XMStoreFloat3(&distToTarget, mathDistToTarget); float nNextNodeDistance = 125.0f; Steering().Seek(targetPos); // If i reached the node, move on the next one if (distToTarget.x < nNextNodeDistance && nCurrentNode >= 0) nCurrentNode--; if (m_bIsGrounded) { Steering().Update(false, m_fScale); SetWorldVelocity(realVelocity); } else SetWorldVelocity({ knockBackVelocity.x, m_f3Velocity.y, knockBackVelocity.z }); SetNodeOnPath(nCurrentNode); return RETREAT; }
CSkeleton::ESkeletonStates CSkeleton::Move(bool _forward) { XMVECTOR vPlayer = XMLoadFloat3(GetPlayer()->GetPosition()); XMVECTOR vSkeleton = XMLoadFloat3(GetPosition()); XMVECTOR vVelocity; XMFLOAT3 fVelocity3(0.0f, m_f3Velocity.y, 0.0f); m_fExitTimer -= DELTA_TIME(); if (_forward) vVelocity = vPlayer - vSkeleton; else vVelocity = vSkeleton - vPlayer; XMVECTOR vDistance = XMVector3Length(vVelocity); float fDistance = vDistance.m128_f32[0]; vVelocity = XMVector3Normalize(vVelocity); vVelocity *= 350.0f; XMStoreFloat3(&fVelocity3, vVelocity); fVelocity3.y = m_f3Velocity.y; if (m_eCurrState == BACKING_OUT) { if (fDistance > 500.0f) return MANUVERING; } if (m_eCurrState == MOVING_IN) { CPlayer* player = reinterpret_cast<CPlayer*>(GetPlayer()); /*if (player->IsAttacking() && fDistance < 200.0f && fDistance > 125.0f) { unsigned int blockChance = (rand() % 100) + 1; if (blockChance < GetBlockChance()) m_eNewState = BLOCKING; } */ if (fDistance <= 125.0f) { if (m_bIsGrounded) SetWorldVelocity({ 0.0f, m_f3Velocity.y, 0.0f }); return SWINGING; } } if (fDistance > 3000.0f) { m_eNewState = RETREAT; } if (fDistance > 1250.0f) { return FOLLOW; } //if (m_fExitTimer < 0.0f) //return MANUVERING; Steering().Seek(*GetPlayer()->GetPosition()); if (m_bIsGrounded) { Steering().Update(false, m_fScale); SetWorldVelocity(fVelocity3); } else SetWorldVelocity({ knockBackVelocity.x, m_f3Velocity.y, knockBackVelocity.z }); if (_forward) return MOVING_IN; return BACKING_OUT; }
bool PlayerBase::AtTarget() const { return (Vec2DDistanceSq(Pos(), Steering()->Target()) < 3.0); }