예제 #1
0
        bool CheckRange()
        {
            Vector2d targetDirection = Target.Body._position - cachedBody._position;
            long     fastMag         = targetDirection.FastMagnitude();

            return(fastMag <= fastRangeToTarget);
        }
예제 #2
0
        private void ApplyCone(Vector3d center3d, Vector2d forward, long radius, long angle)
        {
            Vector2d center    = center3d.ToVector2d();
            long     fastRange = radius * radius;

            Scan(center, radius);
            for (int i = 0; i < ScanOutput.Count; i++)
            {
                LSAgent  agent      = ScanOutput[i];
                Vector2d agentPos   = agent.Body._position;
                Vector2d difference = agentPos - center;

                if (difference.FastMagnitude() > fastRange)
                {
                    continue;
                }
                if (forward.Dot(difference) < 0)
                {
                    continue;
                }
                difference.Normalize();

                long cross = forward.Cross(difference).Abs();
                if (cross > angle)
                {
                    continue;
                }
                HitAgent(agent);
            }
        }
예제 #3
0
        public void Simulate()
        {
            if (VelocityChanged)
            {
                VelocityFastMagnitude = _velocity.FastMagnitude();
                VelocityChanged       = false;
            }

            LastPosition = _position;

            if (VelocityFastMagnitude != 0)
            {
                _position.x    += _velocity.x / LockstepManager.FrameRate;
                _position.y    += _velocity.y / LockstepManager.FrameRate;
                PositionChanged = true;
            }

            BuildChangedValues();

            if (PositionChanged || this.PositionChangedBuffer)
            {
                Partition.UpdateObject(this);
            }

            if (SettingVisuals)
            {
                _settingVisualsCounter--;
            }
        }
예제 #4
0
        public void EarlySimulate()
        {
            if (VelocityChanged)
            {
                VelocityFastMagnitude = _velocity.FastMagnitude();
                VelocityChanged       = false;
            }
            if (VelocityFastMagnitude != 0)
            {
                _position.x    += _velocity.x;
                _position.y    += _velocity.y;
                PositionChanged = true;
            }

            if (PositionChanged || this.PositionChangedBuffer)
            {
                Partition.UpdateObject(this);
            }
            if (RotationChanged)
            {
            }
            else
            {
            }
        }
예제 #5
0
 private void HandleContact(LSBody other)
 {
     if (targetReached == true && Agent.IsCasting == false && !(Agent.Body.Immovable || Agent.Body.IsTrigger))
     {
         Vector2d delta = this.Agent.Body._position - this.Agent.Body.LastPosition;
         if (delta.FastMagnitude() > collisionTurnThreshold)
         {
             delta.Normalize();
             this.StartTurnDirection(delta);
         }
     }
 }
예제 #6
0
 void CheckAutoturn()
 {
     if (isColliding)
     {
         isColliding = false;
         //autoturn direction will be culmination of positional changes
         if (targetReached == true && Agent.IsCasting == false && !(Agent.Body.Immovable || Agent.Body.IsTrigger))
         {
             Vector2d delta = this.Agent.Body._position - this.Agent.Body.LastPosition;
             if (delta.FastMagnitude() > collisionTurnThreshold)
             {
                 delta.Normalize();
                 this.StartTurnDirection(delta);
             }
         }
     }
 }
예제 #7
0
        public void Simulate()
        {
            if (VelocityChanged)
            {
                VelocityFastMagnitude = _velocity.FastMagnitude();
                VelocityChanged       = false;
            }
            if (VelocityFastMagnitude != 0)
            {
                _position.x    += _velocity.x;
                _position.y    += _velocity.y;
                PositionChanged = true;
            }

            BuildChangedValues();


            if (PositionChanged || this.PositionChangedBuffer)
            {
                Partition.UpdateObject(this);
            }
        }
예제 #8
0
        void BehaveWithTarget()
        {
            if (Target.IsActive == false || Target.SpawnVersion != targetVersion ||
                (this.TargetAllegiance & Agent.GetAllegiance(Target)) == 0)
            {
                StopEngage();
                BehaveWithNoTarget();
                return;
            }
            if (IsWindingUp)
            {
                windupCount--;
                if (windupCount < 0)
                {
                    if (this.AgentConditional(Target))
                    {
                        Fire();
                        while (this.attackCount < 0)
                        {
                            this.attackCount += (this.AttackInterval);
                        }
                        this.attackCount -= Windup;
                        IsWindingUp       = false;
                    }
                    else
                    {
                        StopEngage();
                        this.ScanAndEngage();
                    }
                }
            }
            else
            {
                Vector2d targetDirection = Target.Body._position - cachedBody._position;
                long     fastMag         = targetDirection.FastMagnitude();

                if (fastMag <= fastRangeToTarget)
                {
                    if (!inRange)
                    {
                        if (CanMove)
                        {
                            cachedMove.StopMove();
                        }
                    }
                    Agent.SetState(EngagingAnimState);

                    long mag;
                    targetDirection.Normalize(out mag);
                    bool withinTurn = TrackAttackAngle == false ||
                                      (fastMag != 0 &&
                                       cachedBody.Forward.Dot(targetDirection.x, targetDirection.y) > 0 &&
                                       cachedBody.Forward.Cross(targetDirection.x, targetDirection.y).Abs() <= AttackAngle);
                    bool needTurn = mag != 0 && !withinTurn;
                    if (needTurn)
                    {
                        if (CanTurn)
                        {
                            cachedTurn.StartTurnDirection(targetDirection);
                        }
                        else
                        {
                        }
                    }
                    else
                    {
                        if (attackCount <= 0)
                        {
                            StartWindup();
                        }
                    }

                    if (inRange == false)
                    {
                        inRange = true;
                    }
                }
                else
                {
                    if (CanMove)
                    {
                        if (cachedMove.IsMoving == false)
                        {
                            cachedMove.StartMove(Target.Body._position);
                            cachedBody.Priority = basePriority;
                        }
                        else
                        {
                            if (Target.Body.PositionChangedBuffer || inRange)
                            {
                                cachedMove.Destination = Target.Body._position;
                            }
                        }
                    }

                    if (isAttackMoving || isFocused == false)
                    {
                        searchCount -= 1;
                        if (searchCount <= 0)
                        {
                            searchCount = SearchRate;
                            if (ScanAndEngage())
                            {
                            }
                            else
                            {
                            }
                        }
                    }
                    if (inRange == true)
                    {
                        inRange = false;
                    }
                }
            }
        }
예제 #9
0
        void BehaveWithTarget()
        {
            if (Target.IsActive == false || Target.SpawnVersion != targetVersion ||
                (this.TargetAllegiance & Agent.GetAllegiance(Target)) == 0)
            {
                //Target no longer exists
                StopEngage();
                BehaveWithNoTarget();
                return;
            }

            if (!IsWindingUp)
            {
                Vector2d targetDirection = Target.Body._position - cachedBody._position;
                long     fastMag         = targetDirection.FastMagnitude();

                if (CheckRange())
                {
                    if (!inRange)
                    {
                        if (CanMove)
                        {
                            cachedMove.StopMove();
                        }
                        inRange = true;
                    }
                    Agent.SetState(EngagingAnimState);

                    long mag;
                    targetDirection.Normalize(out mag);
                    bool withinTurn = TrackAttackAngle == false ||
                                      (fastMag != 0 &&
                                       cachedBody.Forward.Dot(targetDirection.x, targetDirection.y) > 0 &&
                                       cachedBody.Forward.Cross(targetDirection.x, targetDirection.y).Abs() <= AttackAngle);
                    bool needTurn = mag != 0 && !withinTurn;
                    if (needTurn)
                    {
                        if (CanTurn)
                        {
                            cachedTurn.StartTurnDirection(targetDirection);
                        }
                        else
                        {
                        }
                    }
                    else
                    {
                        if (attackCount <= 0)
                        {
                            StartWindup();
                        }
                    }
                }
                else
                {
                    if (CanMove)
                    {
                        cachedMove.PauseAutoStop();
                        cachedMove.PauseCollisionStop();
                        if (cachedMove.IsMoving == false)
                        {
                            cachedMove.StartMove(Target.Body._position);
                            cachedBody.Priority = basePriority;
                        }
                        else
                        {
                            if (inRange)
                            {
                                cachedMove.Destination = Target.Body.Position;
                            }
                            else
                            {
                                if (repathTimer.AdvanceFrame())
                                {
                                    if (Target.Body.PositionChangedBuffer &&
                                        Target.Body.Position.FastDistance(cachedMove.Destination.x, cachedMove.Destination.y) >= (repathDistance * repathDistance))
                                    {
                                        cachedMove.StartMove(Target.Body._position);
                                        //So units don't sync up and path on the same frame
                                        repathTimer.AdvanceFrames(repathRandom);
                                    }
                                }
                            }
                        }
                    }

                    if (IsAttackMoving || isFocused == false)
                    {
                        searchCount -= 1;
                        if (searchCount <= 0)
                        {
                            searchCount = SearchRate;
                            if (ScanAndEngage())
                            {
                            }
                            else
                            {
                            }
                        }
                    }
                    if (inRange == true)
                    {
                        inRange = false;
                    }
                }
            }

            if (IsWindingUp)
            {
                windupCount -= LockstepManager.DeltaTime;
                if (windupCount < 0)
                {
                    if (this.AgentConditional(Target))
                    {
                        Fire();
                        int counter = 0;
                        while (this.attackCount <= 0)
                        {
                            this.attackCount += (this.AttackInterval);
                            counter++;
                            if (counter > 1)
                            {
                                Debug.Log("asdf" + this.attackCount.ToDouble());
                            }
                        }
                        this.attackCount -= Windup;
                    }
                    else
                    {
                        StopEngage();
                        this.ScanAndEngage();
                    }
                    IsWindingUp = false;
                }
            }

            if (inRange)
            {
                cachedMove.PauseAutoStop();
                cachedMove.PauseCollisionStop();
            }
        }
예제 #10
0
        void BehaveWithTarget()
        {
            if (Target.IsActive == false || Target.SpawnVersion != targetVersion ||
                (this.TargetAllegiance & Agent.GetAllegiance(Target)) == 0)
            {
                //Target's lifecycle has ended
                StopEngage();
                BehaveWithNoTarget();
                return;
            }

            if (!IsWindingUp)
            {
                Vector2d targetDirection = Target.Body._position - cachedBody._position;
                long     fastMag         = targetDirection.FastMagnitude();

                //TODO: Optimize this instead of recalculating magnitude multiple times
                if (CheckRange())
                {
                    if (!inRange)
                    {
                        if (CanMove)
                        {
                            cachedMove.StopMove();
                        }
                        inRange = true;
                    }
                    Agent.SetState(EngagingAnimState);

                    long mag;
                    targetDirection.Normalize(out mag);
                    bool withinTurn = TrackAttackAngle == false ||
                                      (fastMag != 0 &&
                                       cachedBody.Forward.Dot(targetDirection.x, targetDirection.y) > 0 &&
                                       cachedBody.Forward.Cross(targetDirection.x, targetDirection.y).Abs() <= AttackAngle);
                    bool needTurn = mag != 0 && !withinTurn;
                    if (needTurn)
                    {
                        if (CanTurn)
                        {
                            cachedTurn.StartTurnDirection(targetDirection);
                        }
                    }
                    else
                    {
                        if (attackCount >= AttackInterval)
                        {
                            StartWindup();
                        }
                    }
                }
                else
                {
                    if (CanMove)
                    {
                        cachedMove.PauseAutoStop();
                        cachedMove.PauseCollisionStop();
                        if (cachedMove.IsMoving == false)
                        {
                            cachedMove.StartMove(Target.Body._position);
                            cachedBody.Priority = basePriority;
                        }
                        else
                        {
                            if (inRange)
                            {
                                cachedMove.Destination = Target.Body.Position;
                            }
                            else
                            {
                                if (repathTimer.AdvanceFrame())
                                {
                                    if (Target.Body.PositionChangedBuffer &&
                                        Target.Body.Position.FastDistance(cachedMove.Destination.x, cachedMove.Destination.y) >= (repathDistance * repathDistance))
                                    {
                                        cachedMove.StartMove(Target.Body._position);
                                        //So units don't sync up and path on the same frame
                                        repathTimer.AdvanceFrames(repathRandom);
                                    }
                                }
                            }
                        }
                    }

                    if (IsAttackMoving || isFocused == false)
                    {
                        searchCount -= 1;
                        if (searchCount <= 0)
                        {
                            searchCount = SearchRate;
                            if (ScanAndEngage())
                            {
                            }
                            else
                            {
                            }
                        }
                    }
                    if (inRange == true)
                    {
                        inRange = false;
                    }
                }
            }
            if (IsWindingUp)
            {
                //TODO: Do we need AgentConditional checks here?
                windupCount += LockstepManager.DeltaTime;
                if (CanTurn)
                {
                    Vector2d targetVector = Target.Body._position - cachedBody._position;
                    cachedTurn.StartTurnVector(targetVector);
                }
                if (windupCount >= Windup)
                {
                    windupCount = 0;
                    Fire();
                    while (this.attackCount >= AttackInterval)
                    {
                        //resetting back down after attack is fired
                        this.attackCount -= (this.AttackInterval);
                    }
                    this.attackCount += Windup;
                    IsWindingUp       = false;
                }
            }
            else
            {
                windupCount = 0;
            }
            if (inRange)
            {
                cachedMove.PauseAutoStop();
                cachedMove.PauseCollisionStop();
            }
        }
예제 #11
0
        void BehaveWithTarget()
        {
            if (Target.IsActive == false || Target.SpawnVersion != targetVersion)
            {
                StopEngage();
                BehaveWithNoTarget();
                return;
            }
            Vector2d targetDirection = Target.Body.Position - cachedBody.Position;
            long     fastMag         = targetDirection.FastMagnitude();

            if (fastMag <= fastRangeToTarget)
            {
                if (!inRange)
                {
                    if (CanMove)
                    {
                        cachedMove.StopMove();
                    }
                }
                Agent.SetState(AnimState.Engaging);
                long mag = FixedMath.Sqrt(fastMag >> FixedMath.SHIFT_AMOUNT);
                //cachedTurn.StartTurn(targetDirection / mag);
                bool withinTurn = TrackAttackAngle == false ||
                                  (fastMag != 0 &&
                                   cachedBody.Rotation.Dot(targetDirection.x, targetDirection.y) > 0 &&
                                   cachedBody.Rotation.Cross(targetDirection.x, targetDirection.y).Abs() <= AttackAngle);
                bool needTurn = mag != 0 && !withinTurn;
                if (needTurn)
                {
                    if (CanTurn)
                    {
                        targetDirection /= mag;
                        cachedTurn.StartTurn(targetDirection);
                    }
                }
                else
                {
                    if (attackCount <= 0)
                    {
                        attackCount = attackFrameCount;
                        Fire();
                    }
                }

                if (inRange == false)
                {
                    inRange = true;
                }
            }
            else
            {
                if (CanMove)
                {
                    if (cachedMove.IsMoving == false)
                    {
                        cachedMove.StartMove(Target.Body.Position);
                        cachedBody.Priority = basePriority;
                    }
                    else
                    {
                        if (Target.Body.PositionChanged || inRange)
                        {
                            cachedMove.Destination = Target.Body.Position;
                        }
                    }
                }

                if (isAttackMoving || isFocused == false)
                {
                    searchCount -= 1;
                    if (searchCount <= 0)
                    {
                        searchCount = SearchRate;
                        if (ScanAndEngage())
                        {
                        }
                        else
                        {
                        }
                    }
                }
                if (inRange == true)
                {
                    inRange = false;
                }
            }
        }