Exemplo n.º 1
0
 public void Add(ref Vector2d other)
 {
     this.x += other.x;
     this.y += other.y;
 }
Exemplo n.º 2
0
 public long Distance(Vector2d other)
 {
     return(Distance(other.x, other.y));
 }
Exemplo n.º 3
0
 public void Subtract(ref Vector2d other)
 {
     this.x -= other.x;
     this.y -= other.y;
 }
Exemplo n.º 4
0
 public long Dot(Vector2d other)
 {
     return(this.Dot(other.x, other.y));
 }
Exemplo n.º 5
0
 public long Cross(Vector2d vec)
 {
     return(Cross(vec.x, vec.y));
 }
Exemplo n.º 6
0
 public Vector2d Rotated(Vector2d rotation)
 {
     return(Rotated(rotation.x, rotation.y));
 }
Exemplo n.º 7
0
 public void Lerp(Vector2d target, long amount)
 {
     Lerp(target.x, target.y, amount);
 }
Exemplo n.º 8
0
        public void DistributeCircle_Box(LSBody box, LSBody circle)
        {
            xMore = circle._position.x > box._position.x;
            yMore = circle._position.y > box._position.y;

            if (xMore)
            {
                PenetrationX = (circle.XMin - box.XMax);
            }
            else
            {
                PenetrationX = (circle.XMax - box.XMin);
            }
            if (yMore)
            {
                PenetrationY = (circle.YMin - box.YMax);
            }
            else
            {
                PenetrationY = (circle.YMax - box.YMin);
            }

            //PenetrationX = PenetrationX + circle.Velocity.x;
            //PenetrationY = PenetrationY + circle.Velocity.y;
            xAbs = PenetrationX < 0 ? -PenetrationX : PenetrationX;
            yAbs = PenetrationY < 0 ? -PenetrationY : PenetrationY;

            if ((xAbs <= circle.Radius && yAbs <= circle.Radius))
            {
                Vector2d corner;
                corner.x = xMore ? box.Position.x + box.HalfWidth : box.Position.x - box.HalfWidth;
                corner.y = yMore ? box.Position.y + box.HalfHeight : box.Position.y - box.HalfHeight;
                Vector2d dir = circle.Position - corner;
                dir.Normalize();

                circle.Position = corner + dir * circle.Radius;
            }
            else
            {
                if (xAbs > yAbs)
                {
                    PenetrationX = 0;
                    //if (yAbs < circle.Radius) PenetrationY = PenetrationY * yAbs / circle.Radius;
                    if (PenetrationY > 0 == yMore)
                    {
                        PenetrationY = -PenetrationY;
                    }
                }
                else
                {
                    PenetrationY = 0;
                    //if (xAbs < circle.Radius) PenetrationX = PenetrationX * xAbs / circle.Radius;
                    if (PenetrationX > 0 == xMore)
                    {
                        PenetrationX = -PenetrationX;
                    }
                }



                //Resolving
                circle._position.x -= PenetrationX;
                circle._position.y -= PenetrationY;
            }



            circle.PositionChanged = true;
            circle.BuildBounds();
        }
Exemplo n.º 9
0
 public void StartFormalMove(Vector2d position)
 {
     Agent.StopCast(ID);
     IsCasting = true;
     RegisterGroup();
 }
Exemplo n.º 10
0
        protected override void OnSimulate()
        {
            if (!CanMove)
            {
                return;
            }
            if (IsMoving)
            {
                if (CanPathfind)
                {
                    if (DoPathfind)
                    {
                        DoPathfind = false;
                        if (viableDestination)
                        {
                            if (Pathfinder.GetPathNode(cachedBody.Position, out currentNode))
                            {
                                if (currentNode.DoesEqual(this.destinationNode))
                                {
                                    if (this.RepathTries >= 1)
                                    {
                                        this.Arrive();
                                    }
                                }
                                else
                                {
                                    if (straightPath)
                                    {
                                        if (Pathfinder.NeedsPath(currentNode, destinationNode, this.GridSize))
                                        {
                                            if (Pathfinder.FindPath(Destination, currentNode, destinationNode, myPath,
                                                                    GridSize, GetNodeHash(destinationNode)))
                                            {
                                                hasPath   = true;
                                                pathIndex = 0;
                                            }
                                            else
                                            {
                                                if (IsFormationMoving)
                                                {
                                                    StartMove(MyMovementGroup.Destination);
                                                    IsFormationMoving = false;
                                                }
                                            }
                                            straightPath = false;
                                        }
                                        else
                                        {
                                        }
                                    }
                                    else
                                    {
                                        if (Pathfinder.NeedsPath(currentNode, destinationNode, this.GridSize))
                                        {
                                            if (Pathfinder.FindPath(Destination, currentNode, destinationNode, myPath,
                                                                    GridSize, GetNodeHash(destinationNode)))
                                            {
                                                hasPath   = true;
                                                pathIndex = 0;
                                            }
                                            else
                                            {
                                                if (IsFormationMoving)
                                                {
                                                    StartMove(MyMovementGroup.Destination);
                                                    IsFormationMoving = false;
                                                }
                                            }
                                        }
                                        else
                                        {
                                            straightPath = true;
                                        }
                                    }
                                }
                            }
                            else
                            {
                            }
                        }
                        else
                        {
                            hasPath = false;
                            if (IsFormationMoving)
                            {
                                StartMove(MyMovementGroup.Destination);
                                IsFormationMoving = false;
                            }
                        }
                    }
                    else
                    {
                    }

                    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);
                long stuckThreshold   = 0;

                if (distance > closingDistance || movingToWaypoint)
                {
                    desiredVelocity = (movementDirection);

                    if (CanTurn)
                    {
                        CachedTurn.StartTurnDirection(movementDirection);
                    }


                    stuckThreshold = this.timescaledSpeed / 4;
                }
                else
                {
                    if (distance < FixedMath.Mul(closingDistance, StopMultiplier))
                    {
                        Arrive();
                        return;
                    }
                    if (this.SlowArrival)
                    {
                        long closingSpeed = distance.Div(closingDistance);
                        desiredVelocity = movementDirection * (closingSpeed);
                        stuckThreshold  = closingSpeed / 2;
                    }
                    else
                    {
                        desiredVelocity = (movementDirection);
                        stuckThreshold  = this.timescaledSpeed / 2;
                    }
                }
                if (GetFullCanCollisionStop() && (Agent.Body.Position - this.AveragePosition).FastMagnitude() < (stuckThreshold * stuckThreshold))
                {
                    StuckTime += 1;

                    if (StuckTime > StuckTimeThreshold)
                    {
                        if (RepathTries < StuckRepathTries)
                        {
                            DoPathfind = true;
                            RepathTries++;
                        }
                        else
                        {
                            RepathTries = 0;
                            this.Arrive();
                        }
                        StuckTime = 0;
                    }
                }
                else
                {
                    if (StuckTime > 0)
                    {
                        StuckTime -= 1;
                    }

                    RepathTries = 0;
                }

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

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

                cachedBody.VelocityChanged = true;

                TempCanCollisionStop = true;
            }
            else
            {
                if (cachedBody.VelocityFastMagnitude > 0)
                {
                    cachedBody._velocity      -= cachedBody._velocity * timescaledAcceleration;
                    cachedBody.VelocityChanged = true;
                }
                StoppedTime++;
            }
            AveragePosition = AveragePosition.Lerped(Agent.Body.Position, FixedMath.One / 4);
        }