public static void PrepareAxisCheck(Vector2d p1, Vector2d p2)
 {
     cacheP1   = p1;
     cacheP2   = p2;
     cacheAxis = p2 - p1;
     cacheAxis.Normalize();
     axisMin       = p1.Dot(cacheAxis.x, cacheAxis.y);
     axisMax       = p2.Dot(cacheAxis.x, cacheAxis.y);
     cacheProjPerp = cacheP1.Cross(cacheAxis.x, cacheAxis.y);
 }
Esempio n. 2
0
        protected override void OnSimulate()
        {
            if (!CanMove)
            {
                return;
            }
            if (IsMoving)
            {
                if (CanPathfind)
                {
                    if (repathCount <= 0)
                    {
                        if (viableDestination)
                        {
                            if (Pathfinder.GetPathNode(cachedBody._position.x, cachedBody._position.y, out currentNode))
                            {
                                if (straightPath)
                                {
                                    if (forcePathfind || Pathfinder.NeedsPath(currentNode, destinationNode, this.GridSize))
                                    {
                                        if (Pathfinder.FindPath(Destination, currentNode, destinationNode, myPath,
                                                                GridSize))
                                        {
                                            hasPath   = true;
                                            pathIndex = 0;
                                        }
                                        else
                                        {
                                            if (IsFormationMoving)
                                            {
                                                StartMove(MyMovementGroup.Destination);
                                                IsFormationMoving = false;
                                            }
                                        }
                                        straightPath = false;
                                        repathCount  = RepathRate;
                                    }
                                    else
                                    {
                                        repathCount = StraightRepathRate;
                                    }
                                }
                                else
                                {
                                    if (forcePathfind || Pathfinder.NeedsPath(currentNode, destinationNode, this.GridSize))
                                    {
                                        if (Pathfinder.FindPath(Destination, currentNode, destinationNode, myPath,
                                                                GridSize))
                                        {
                                            hasPath   = true;
                                            pathIndex = 0;
                                        }
                                        else
                                        {
                                            if (IsFormationMoving)
                                            {
                                                StartMove(MyMovementGroup.Destination);
                                                IsFormationMoving = false;
                                            }
                                        }
                                        repathCount = RepathRate;
                                    }
                                    else
                                    {
                                        straightPath = true;
                                        repathCount  = StraightRepathRate;
                                    }
                                }
                            }
                            else
                            {
                            }
                        }
                        else
                        {
                            hasPath = false;
                            if (IsFormationMoving)
                            {
                                StartMove(MyMovementGroup.Destination);
                                IsFormationMoving = false;
                            }
                        }
                    }
                    else
                    {
                        if (hasPath)
                        {
                            //TODO: fix this shit
                            repathCount--;
                        }
                        else
                        {
                            repathCount--;
                        }
                    }

                    if (straightPath)
                    {
                        targetPos = Destination;
                    }
                    else if (hasPath)
                    {
                        if (pathIndex >= myPath.Count)
                        {
                            targetPos = this.Destination;
                        }
                        else
                        {
                            targetPos = myPath [pathIndex];
                        }
                    }
                    else
                    {
                        targetPos = Destination;
                    }
                }
                else
                {
                    targetPos = Destination;
                }

                movementDirection = targetPos - cachedBody._position;

                movementDirection.Normalize(out distance);
                if (targetPos.x != lastTargetPos.x || targetPos.y != lastTargetPos.y)
                {
                    lastTargetPos   = targetPos;
                    targetDirection = movementDirection;
                }
                bool movingToWaypoint = (this.hasPath && this.pathIndex < myPath.Count - 1);
                if (distance > closingDistance || movingToWaypoint)
                {
                    desiredVelocity = (movementDirection);
                    if (movementDirection.Cross(lastMovementDirection.x, lastMovementDirection.y).AbsMoreThan(FixedMath.Half))
                    {
                        lastMovementDirection = movementDirection;
                        if (CanTurn)
                        {
                            CachedTurn.StartTurnDirection(movementDirection);
                        }
                    }
                }
                else
                {
                    if (distance < FixedMath.Mul(closingDistance, CollisionStopMultiplier))
                    {
                        Arrive();
                        return;
                    }
                    if (this.SlowArrival)
                    {
                        desiredVelocity = (movementDirection * (distance) / (closingDistance));
                    }
                    else
                    {
                        desiredVelocity = (movementDirection);
                    }
                }


                if (movingToWaypoint)
                {
                    if (distance < FixedMath.Mul(closingDistance, FixedMath.One))
                    {
                        this.pathIndex++;
                    }
                }
                desiredVelocity *= timescaledSpeed;

                cachedBody._velocity += (desiredVelocity - cachedBody._velocity) * timescaledAcceleration;

                cachedBody.VelocityChanged = true;
            }
            else
            {
                if (cachedBody.VelocityFastMagnitude > 0)
                {
                    cachedBody._velocity      -= cachedBody._velocity * timescaledAcceleration;
                    cachedBody.VelocityChanged = true;
                }
                stopTime++;
            }
        }
Esempio n. 3
0
        protected override void OnSimulate()
        {
            if (!CanMove)
            {
                return;
            }
            if (IsMoving)
            {
                if (canPathfind)
                {
                    if (repathCount <= 0)
                    {
                        if (viableDestination)
                        {
                            if (Pathfinder.GetPathNode(cachedBody.Position.x, cachedBody.Position.y, out currentNode))
                            {
                                if (straightPath)
                                {
                                    if (forcePathfind || Pathfinder.NeedsPath(currentNode, destinationNode))
                                    {
                                        if (Pathfinder.FindPath(Destination, currentNode, destinationNode, myPath))
                                        {
                                            hasPath   = true;
                                            pathIndex = 0;
                                        }
                                        else
                                        {
                                            if (IsFormationMoving)
                                            {
                                                StartMove(MyMovementGroup.Destination);
                                                IsFormationMoving = false;
                                            }
                                        }
                                        straightPath = false;
                                        repathCount  = RepathRate;
                                    }
                                    else
                                    {
                                        repathCount = StraightRepathRate;
                                    }
                                }
                                else
                                {
                                    if (forcePathfind || Pathfinder.NeedsPath(currentNode, destinationNode))
                                    {
                                        if (Pathfinder.FindPath(Destination, currentNode, destinationNode, myPath))
                                        {
                                            hasPath   = true;
                                            pathIndex = 0;
                                        }
                                        else
                                        {
                                            if (IsFormationMoving)
                                            {
                                                StartMove(MyMovementGroup.Destination);
                                                IsFormationMoving = false;
                                            }
                                        }
                                        repathCount = RepathRate;
                                    }
                                    else
                                    {
                                        straightPath = true;
                                        repathCount  = StraightRepathRate;
                                    }
                                }
                            }
                            else
                            {
                            }
                        }
                        else
                        {
                            hasPath = false;
                            if (IsFormationMoving)
                            {
                                StartMove(MyMovementGroup.Destination);
                                IsFormationMoving = false;
                            }
                        }
                    }
                    else
                    {
                        if (hasPath)
                        {
                            repathCount--;
                        }
                        else
                        {
                            repathCount--;
                        }
                    }

                    if (straightPath)
                    {
                        targetPos = Destination;
                    }
                    else if (hasPath)
                    {
                        if (pathIndex >= myPath.Count)
                        {
                            pathIndex = myPath.Count - 1;
                        }
                        targetPos = myPath[pathIndex];
                    }
                    else
                    {
                        targetPos = Destination;
                    }
                }
                else
                {
                    targetPos = Destination;
                }

                movementDirection = targetPos - cachedBody.Position;
                movementDirection.Normalize(out distance);
                if (targetPos.x != lastTargetPos.x || targetPos.y != lastTargetPos.y)
                {
                    lastTargetPos   = targetPos;
                    targetDirection = movementDirection;
                }

                if (distance > closingDistance)
                {
                    desiredVelocity = (movementDirection);
                    if (movementDirection.Cross(lastMovementDirection.x, lastMovementDirection.y) != 0)
                    {
                        lastMovementDirection = movementDirection;
                        cachedTurn.StartTurnRaw(movementDirection);
                    }
                }
                else
                {
                    if (distance < FixedMath.Mul(closingDistance, CollisionStopMultiplier))
                    {
                        Arrive();
                        return;
                    }
                    desiredVelocity = (movementDirection * (distance) / (closingDistance));
                }

                desiredVelocity *= timescaledSpeed;

                cachedBody._velocity += (desiredVelocity - cachedBody._velocity) * timescaledAcceleration;
                if (distance <= closingDistance)
                {
                    pathIndex++;
                }
                cachedBody.VelocityChanged = true;
                if (collidedWithTrackedAgent)
                {
                    if (collidedCount >= CollisionStopCount)
                    {
                        collidedCount  = 0;
                        collidingAgent = null;
                        Arrive();
                    }
                    else
                    {
                        if (lastPosition.FastDistance(cachedBody.Position.x, cachedBody.Position.y)
                            < collisionStopTreshold)
                        {
                            collidedCount++;
                        }
                        else
                        {
                            lastPosition  = cachedBody.Position;
                            collidedCount = 0;
                        }
                    }
                    collidedWithTrackedAgent = false;
                }
                else
                {
                    collidingAgent = null;
                    collidedCount  = 0;
                }
            }
            else
            {
                if (cachedBody.VelocityFastMagnitude > 0)
                {
                    cachedBody._velocity      -= cachedBody._velocity * timescaledAcceleration;
                    cachedBody.VelocityChanged = true;
                }
                stopTime++;
            }
        }
 private static void ApplyCone(Vector2d center, Vector2d rotation, long radius, long angle, Func<LSAgent, bool> conditional, Action<LSAgent> apply, PlatformType targetPlatform)
 {
     LSProjectile.Scan (center, radius, conditional);
     long num = radius * radius;
     long num2 = angle * angle >> 16;
     for (int i = 0; i < LSProjectile.outputAgents.Count; i++)
     {
         LSAgent lSAgent = LSProjectile.outputAgents [i];
         LSProjectile.agentPos = lSAgent.Body.Position;
         LSProjectile.difference = LSProjectile.agentPos - center;
         long num3 = LSProjectile.difference.FastMagnitude ();
         if (num3 <= num && LSProjectile.difference.Dot (rotation.x, rotation.y) > 0L)
         {
             num3 >>= 16;
             long num4 = rotation.Cross (LSProjectile.difference.x, LSProjectile.difference.y);
             num4 *= num4;
             num4 >>= 16;
             if (num4 < num2 * num3 >> 16)
             {
                 apply (lSAgent);
             }
         }
     }
 }
Esempio n. 5
0
        protected override void OnSimulate()
        {
            if (!CanMove) {
                return;
            }
            if (IsMoving) {
                if (canPathfind) {
                    if (repathCount <= 0) {
                        if (viableDestination) {
                            if (Pathfinder.GetPathNode(cachedBody.Position.x, cachedBody.Position.y, out currentNode)) {
                                if (straightPath) {
                                    if (forcePathfind || Pathfinder.NeedsPath(currentNode, destinationNode)) {
                                        if (Pathfinder.FindPath(Destination, currentNode, destinationNode, myPath)) {
                                            hasPath = true;
                                            pathIndex = 0;
                                        } else {
                                            if (IsFormationMoving) {
                                                StartMove(MyMovementGroup.Destination);
                                                IsFormationMoving = false;
                                            }
                                        }
                                        straightPath = false;
                                        repathCount = RepathRate;
                                    } else {
                                        repathCount = StraightRepathRate;
                                    }
                                } else {
                                    if (forcePathfind || Pathfinder.NeedsPath(currentNode, destinationNode)) {
                                        if (Pathfinder.FindPath(Destination, currentNode, destinationNode, myPath)) {
                                            hasPath = true;
                                            pathIndex = 0;
                                        } else {
                                            if (IsFormationMoving) {
                                                StartMove(MyMovementGroup.Destination);
                                                IsFormationMoving = false;
                                            }
                                        }
                                        repathCount = RepathRate;
                                    } else {
                                        straightPath = true;
                                        repathCount = StraightRepathRate;
                                    }
                                }
                            } else {}
                        } else {
                            hasPath = false;
                            if (IsFormationMoving) {
                                StartMove(MyMovementGroup.Destination);
                                IsFormationMoving = false;
                            }
                        }
                    } else {
                        if (hasPath) {
                            repathCount--;
                        } else {
                            repathCount--;
                        }
                    }

                    if (straightPath) {
                        targetPos = Destination;
                    } else if (hasPath) {
                        if (pathIndex >= myPath.Count) {
                            pathIndex = myPath.Count - 1;
                        }
                        targetPos = myPath[pathIndex];
                    } else {
                        targetPos = Destination;
                    }
                } else {
                    targetPos = Destination;
                }

                movementDirection = targetPos - cachedBody.Position;
                movementDirection.Normalize(out distance);
                if (targetPos.x != lastTargetPos.x || targetPos.y != lastTargetPos.y) {
                    lastTargetPos = targetPos;
                    targetDirection = movementDirection;
                }

                if (distance > closingDistance) {
                    desiredVelocity = (movementDirection);
                    if (movementDirection.Cross (lastMovementDirection.x, lastMovementDirection.y) != 0)
                    {
                        lastMovementDirection = movementDirection;
                        cachedTurn.StartTurnRaw (movementDirection);
                    }
                } else {
                    if (distance < FixedMath.Mul (closingDistance, CollisionStopMultiplier)) {
                        Arrive();
                        return;
                    }
                    desiredVelocity = (movementDirection * (distance) / (closingDistance));
                }

                desiredVelocity *= timescaledSpeed;

                cachedBody._velocity += (desiredVelocity - cachedBody._velocity) * timescaledAcceleration;
                if (distance <= closingDistance) {
                    pathIndex++;
                }
                cachedBody.VelocityChanged = true;
                if (collidedWithTrackedAgent) {
                    if (collidedCount >= CollisionStopCount) {
                        collidedCount = 0;
                        collidingAgent = null;
                        Arrive ();
                    }
                    else {
                        if (lastPosition.FastDistance (cachedBody.Position.x, cachedBody.Position.y)
                            < collisionStopTreshold) {
                            collidedCount++;
                        }
                        else {
                            lastPosition = cachedBody.Position;
                            collidedCount = 0;
                        }
                    }
                    collidedWithTrackedAgent = false;
                }
                else {
                    collidingAgent = null;
                    collidedCount = 0;
                }
            } else {
                if (cachedBody.VelocityFastMagnitude > 0) {
                    cachedBody._velocity -= cachedBody._velocity * timescaledAcceleration;
                    cachedBody.VelocityChanged = true;
                }
                stopTime++;
            }
        }