Esempio n. 1
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();
            }
        }
Esempio n. 2
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;
                    }
                }
            }
        }
Esempio n. 3
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();
            }
        }