Наследование: IPerformanceTest
Пример #1
0
        public void UpdatePath()
        {
            Location goal = TargetPosition;

            if (goal.IsNaN())
            {
                if (TargetEntity == null)
                {
                    Path = null;
                    return;
                }
                goal = TargetEntity.GetPosition();
            }
            Location selfpos = GetPosition();

            if ((goal - selfpos).LengthSquared() > MaxPathFindDistance * MaxPathFindDistance)
            {
                TargetPosition = Location.NaN; // TODO: Configurable "can't find path" result -> giveup vs. teleport
                TargetEntity   = null;
                Path           = null;
                return;
            }
            List <Location> tpath = TheRegion.FindPath(selfpos, goal, MaxPathFindDistance, 1);

            if (tpath == null)
            {
                TargetPosition = Location.NaN; // TODO: Configurable "can't find path" result -> giveup vs. teleport
                TargetEntity   = null;
                Path           = null;
                return;
            }
            Path       = new ListQueue <Location>(tpath);
            PathUpdate = 1; // TODO: Configurable update time
        }
        public static void testListQueue()
        {
            ListQueue<double> queue = new ListQueue<double>(5);

            queue.insertBack(10);
            queue.insertBack(20);
            queue.insertBack(30);
            queue.insertBack(40);

            Console.WriteLine("начало очереди " + queue.peekFront());

            Console.WriteLine("конец очереди " + queue.peekBack());

            queue.removeFront();
            queue.removeFront();
            queue.removeFront();

            queue.insertBack(50);
            queue.insertBack(60);
            queue.insertBack(70);
            queue.insertBack(80);

            Console.WriteLine("начало очереди2 " + queue.peekFront());

            Console.WriteLine("конец очереди2 " + queue.peekBack());

            while (!queue.isEmpty())
            {
                double value = queue.removeFront();
                Console.WriteLine(value);

            }
        }
Пример #3
0
        private async void ButtonStart_Click(object sender, RoutedEventArgs e)
        {
            model.IsBusy    = true;
            model.forceStop = false;

            for (int i = 0; i < model.Queue.Count; i++)
            {
                ListQueue.ScrollIntoView(model.Queue[i]);

                if (!model.Queue[i].IsRemote)
                {
                    await model.SendFile(model.Queue[i]);
                }
                else
                {
                    await model.ReceiveFile(model.Queue[i]);
                }

                if (model.forceStop)
                {
                    break;
                }

                model.Queue.Remove(model.Queue[i]);
                i--;
            }

            model.IsBusy = false;

            model.NavigateLocal(model.LocalPath);
            model.NavigateRemote(model.RemotePath);
        }
Пример #4
0
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     // initialize
     queue = new ListQueue <string>();
     // actualizar representacion grafica de cola
     l_RepCola.Content = string.Concat("Cola: ", queue.ToString());
 }
Пример #5
0
        public static string JosephTask(int N, int M)
        {
            var result  = new StringBuilder(N);
            var victims = new ListQueue <int>();

            for (var i = 0; i < N; i++)
            {
                victims.Enqueue(i);
            }

            var currPosition = 1;

            while (victims.Size > 1)
            {
                if (currPosition % M == 0)
                {
                    var luckyMan = victims.Dequeue();
                    result.Append(luckyMan);
                    result.Append(" ");
                }
                else
                {
                    var unluckyMan = victims.Dequeue();
                    victims.Enqueue(unluckyMan);
                }

                currPosition++;
            }

            var looser = victims.Dequeue();

            result.Append(looser);

            return(result.ToString());
        }
Пример #6
0
 /// <summary>
 /// ActionScheduleを初期化する
 /// </summary>
 /// <param name="schedule">PlayerIDの並びで行動の順番を格納するキュー</param>
 /// <param name="players">Player情報の配列、この配列の順番が行動の順番となる</param>
 private static void ResetActionSchedule(ListQueue <int> schedule, IReadOnlyList <Player> players)
 {
     schedule.Clear();
     for (var i = 0; i < players.Count * 3; i++)
     {
         schedule.Enqueue(players[i % players.Count].PlayerID);
     }
 }
Пример #7
0
 /// <summary>
 /// デフォルトコンストラクタ
 /// </summary>
 private MatchCore()
 {
     MatchInfo      = new MatchInfo();
     Field          = new Field();
     Players        = new Dictionary <int, Player>();
     ActionSchedule = new ListQueue <int>();
     Rand           = new Random();
 }
    public static void Main(string[] args)
    {
        IQueue <int> q1 = new ArrayQueue <int>( );
        IQueue <int> q2 = new ListQueue <int>( );

        queueOps("ArrayQueue", q1);
        queueOps("ListQueue", q2);
    }
Пример #9
0
        protected override string PrintElement(ListQueue <MapElement> elements)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendFormat(@"spawn(""{0}"",{1},{2},{3},{4},""{5}""){6}", type, x, y, (int)orientation, h, uniqueID, '\n');
            sb.AppendFormat(@"{0}.button:setDisableSelf({1}){2}", uniqueID, DisableSelf ? "true" : "false", '\n');

            return(sb.ToString());
        }
Пример #10
0
        protected override string PrintElement(ListQueue <MapElement> elements)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendFormat(@"spawn(""{0}"",{1},{2},{3},{4},""{5}""){6}", "torch_holder", x, y, (int)orientation, h, uniqueID, '\n');
            sb.AppendFormat(@"{0}.controller:setHasTorch({1}){2}", uniqueID, HasTorch ? "true" : "false", '\n');

            return(sb.ToString());
        }
Пример #11
0
 protected override string PrintElement(ListQueue <MapElement> elements)
 {
     /*StringBuilder sb = new StringBuilder();
      *
      * sb.AppendLine(String.Format(@"spawn(""{0}"",{1},{2},{3},{4},""{5}"")", monsterType, x, y, (int)orientation, h, uniqueID));
      *
      * return sb.ToString();*/
     return(String.Format(@"spawn(""{0}"",{1},{2},{3},{4},""{5}""){6}", type, x, y, (int)orientation, h, uniqueID, '\n'));
 }
Пример #12
0
        protected override string PrintElement(ListQueue <MapElement> elements)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendFormat(@"spawn(""{0}"",{1},{2},{3},{4},""{5}""){6}", textType, x, y, (int)orientation, h, uniqueID, '\n');
            sb.AppendFormat(@"{0}.walltext:setWallText(""{1}""){2}", uniqueID, TextWritten, '\n');

            return(sb.ToString());
        }
Пример #13
0
        protected override string PrintElement(ListQueue <MapElement> elements)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendFormat(@"spawn(""{0}"",{1},{2},{3},{4},""{5}""){6}", ElementType, x, y, (int)orientation, h, uniqueID, '\n');
            sb.AppendFormat(@"{0}.lock:setOpenedBy(""{1}""){2}", uniqueID, OpenedBy, '\n');

            return(sb.ToString());
        }
Пример #14
0
        protected override string PrintElement(ListQueue <MapElement> elements)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendFormat(@"spawn(""{0}"",{1},{2},{3},{4},""{5}""){6}", type, x, y, (int)orientation, h, uniqueID, '\n');
            sb.AppendFormat(@"{0}.pit:setState(""{1}""){2}", uniqueID, Open ? "open" : "closed", '\n');
            if (Disable)
            {
                sb.AppendFormat(@"{0}.platform:disable(){1}", uniqueID, '\n');
            }
            return(sb.ToString());
        }
Пример #15
0
        /// <summary>
        /// Returns a LUA representation of this object
        /// </summary>
        /// <returns></returns>
        protected override string PrintElement(ListQueue <MapElement> elements)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendFormat(@"spawn(""{0}"",{1},{2},{3},{4},""{5}""){6}", type, x, y, (int)orientation, h, uniqueID, '\n');
            if (Open)
            {
                sb.AppendFormat(@"{0}.door:setDoorState(""{1}""){2}", uniqueID, "open", '\n');
            }
            sb.AppendFormat(@"{0}.door:setPullChain({1}){2}", uniqueID, PullChain ? "true" : "false", '\n');
            return(sb.ToString());
        }
 /// <summary>
 /// デフォルトコンストラクタ
 /// </summary>
 /// <param name="textureHandle">テクスチャの識別子</param>
 /// <param name="x">テクスチャの左上のX座標</param>
 /// <param name="y">テクスチャの左上のy座標</param>
 /// <param name="width">テクスチャの幅</param>
 /// <param name="height">テクスチャの高さ</param>
 public AnimationTexture(int textureHandle, double x, double y, double width, double height)
 {
     TextureHandle       = textureHandle;
     X                   = x;
     Y                   = y;
     Width               = width;
     Height              = height;
     IsProcessingEvent   = false;
     IsStopped           = true;
     AnimationSchedule   = new ListQueue <SugorokuAnimation>();
     ProcessingAnimation = new SugorokuAnimation(0, x, y, width, height, 0, 0, 0, 0, 0);
 }
Пример #17
0
        protected override string PrintElement(ListQueue <MapElement> elements)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendFormat(@"spawn(""{0}"",{1},{2},{3},{4},""{5}""){6}", type, x, y, (int)orientation, h, uniqueID, '\n');
            sb.AppendFormat(@"{0}.floortrigger:setTriggeredByParty({1}){2}", uniqueID, TriggeredByParty ? "true" : "false", '\n');
            sb.AppendFormat(@"{0}.floortrigger:setTriggeredByMonster({1}){2}", uniqueID, TriggeredByMonster ? "true" : "false", '\n');
            sb.AppendFormat(@"{0}.floortrigger:setTriggeredByItem({1}){2}", uniqueID, TriggeredByItem ? "true" : "false", '\n');
            sb.AppendFormat(@"{0}.floortrigger:setTriggeredByDigging({1}){2}", uniqueID, TriggeredByDigging ? "true" : "false", '\n');
            sb.AppendFormat(@"{0}.floortrigger:setDisableSelf({1}){2}", uniqueID, DisableSelf ? "true" : "false", '\n');

            return(sb.ToString());
        }
Пример #18
0
        public string Print(ListQueue <MapElement> elements)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(PrintElement(elements));

            foreach (Connector c in connectors)
            {
                sb.Append(String.Format(@"{0}.{1}:addConnector(""{2}"", ""{3}"", ""{4}""){5}", uniqueID, ConnectorName, c.Trigger, c.Target, c.Action, '\n'));
            }

            return(sb.ToString());
        }
Пример #19
0
        protected override string PrintElement(ListQueue <MapElement> elements)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendFormat(@"spawn(""{0}"",{1},{2},{3},{4},""{5}""){6}", type, x, y, (int)orientation, h, uniqueID, '\n');
            foreach (string item in itemsId)
            {
                int        index   = elements.FindIndex(x => x.uniqueID.Equals(item));
                MapElement element = elements[index];
                elements.RemoveAt(index);

                sb.Append(element.Print(elements));
                sb.AppendFormat(@"{0}.surface:addItem({1}.item){2}", uniqueID, item, '\n');//FIXME: tem de estar feito o spawn do item.
            }
            return(sb.ToString());
        }
Пример #20
0
    public void breadthFirstSearch()
    {
        SceneManager.LoadScene("Maze");
        Node current;

        //for each u E V - {s}
        foreach (Node n in Nodes)
        {
            //u.d = infinite
            n.setDistance(int.MaxValue);
        }
        //s.d = 0
        maze.getEnter().setDistance(0);
        //Q = empty set
        ListQueue queue = new ListQueue();

        //EnQueue(Q,s)
        queue.enqueue(maze.getEnter());
        //While Q != empty set
        while (!queue.isEmpty())
        {
            //u = Dequeue(Q)
            current = (Node)queue.dequeue();
            Debug.Log("(" + current.getX() + "," + current.getY() + ")");
            current.setExplored(true);
            current.setKnown(false);
            if (current == maze.getExit().getPrevious())
            {
                Debug.Log("Breadth First Search Complete");
                break;
            }

            //foreach v E G.Adj[u]
            foreach (Node n in current.getPaths())
            {
                //if v.d == infinite
                if (n.getDistance() == int.MaxValue)
                {
                    //v.d = u.d + 1
                    n.setDistance(current.getDistance() + 1);
                    //EnQueue(Q,v)
                    n.setKnown(true);
                    queue.enqueue(n);
                }
            }
        }
    }
Пример #21
0
        public void CheckClearQueue()
        {
            MyQueue <int> queueArray = new ArrayQueue <int>();
            MyQueue <int> queueList  = new ListQueue <int>();

            for (int i = 1; i < 11; i++)
            {
                queueArray.Enqueue(i);
                queueList.Enqueue(i);
            }

            queueArray.Clear();
            queueList.Clear();

            Assert.Equal(0, queueArray.Count());
            Assert.Equal(0, queueList.Count());
        }
Пример #22
0
        public void CheckPeekQueue()
        {
            MyQueue <int> queueArray = new ArrayQueue <int>();
            MyQueue <int> queueList  = new ListQueue <int>();

            for (int i = 1; i < 11; i++)
            {
                queueArray.Enqueue(i);
                queueList.Enqueue(i);
            }

            var resultArray = queueArray.Peek();
            var resultList  = queueList.Peek();

            Assert.Equal(1, resultArray);
            Assert.Equal(1, resultList);
        }
Пример #23
0
        public void CheckDequeueQueue()
        {
            MyQueue <int> queueArray = new ArrayQueue <int>();
            MyQueue <int> queueList  = new ListQueue <int>();

            for (int i = 1; i < 11; i++)
            {
                queueArray.Enqueue(i);
                queueList.Enqueue(i);
            }

            queueArray.Dequeue();
            queueList.Dequeue();

            Assert.Equal(2, queueArray.Peek());
            Assert.Equal(2, queueList.Peek());
        }
Пример #24
0
        public void CheckCountQueue()
        {
            MyQueue <int> queueArray = new ArrayQueue <int>();
            MyQueue <int> queueList  = new ListQueue <int>();

            for (int i = 1; i < 11; i++)
            {
                queueArray.Enqueue(i);
                queueList.Enqueue(i);
            }

            var countArray = queueArray.Count();
            var countList  = queueList.Count();

            Assert.Equal(10, countArray);
            Assert.Equal(10, countList);
        }
Пример #25
0
        public void CheckContainsQueue()
        {
            MyQueue <int> queueArray = new ArrayQueue <int>();
            MyQueue <int> queueList  = new ListQueue <int>();

            for (int i = 1; i < 6; i++)
            {
                queueArray.Enqueue(i);
                queueList.Enqueue(i);
            }

            var resultArray = queueArray.Contains(1);
            var resultList  = queueList.Contains(1);

            Assert.True(resultArray);
            Assert.True(resultList);
        }
Пример #26
0
    public void depthFirstSearch()
    {
        Node current = new Node();

        SceneManager.LoadScene("Maze");
        //for each u E G.V
        foreach (Node n in Nodes)
        {
            //u.color = white
            n.setColor("WHITE");
        }
        //time = 0
        time = 0;
        //for each u E G.V
        ListQueue queue = new ListQueue();

        //EnQueue(Q,s)
        queue.enqueue(maze.getEnter());
        //While Q != empty set
        while (!queue.isEmpty())
        {
            current = (Node)queue.dequeue();
            Debug.Log("(" + current.getX() + "," + current.getY() + ")");
            current.setExplored(true);
            current.setKnown(false);
            if (current == maze.getExit().getPrevious())
            {
                Debug.Log("depth First Search Complete");
                break;
            }

            foreach (Node n in current.getPaths())
            {
                //if u.color == white
                if (n.getColor() == "WHITE")
                {
                    //DFS-VISIT(G,u)
                    Debug.Log("(" + n.getX() + "," + n.getY() + ")");
                    depthFirstSearchVisit(n);
                }
            }
        }
    }
            static void Main()
            {
                ListQueue <int> queue = new ListQueue <int>();

                foreach (int i in Enumerable.Range(1, 8))
                {
                    queue.EnQueue(i);
                }
                foreach (var item in queue)
                {
                    Console.WriteLine(item);
                }
                foreach (int i in Enumerable.Range(1, 9))
                {
                    queue.DeQueue();
                }
                foreach (var item in queue)
                {
                    Console.WriteLine(item);
                }
                Console.ReadKey();
            }
Пример #28
0
    static void Main(string[] args)
    {
        ListQueue <string> queue = new ListQueue <string>();

        Console.WriteLine("Item count in ListQueue: {0}", queue.Count);
        Console.WriteLine();
        for (int i = 1; i <= 10; i++)
        {
            var text = String.Format("Test{0}", i);
            queue.Enqueue(text);
            Console.WriteLine("Just enqueued: {0}", text);
        }
        Console.WriteLine();
        Console.WriteLine("Item count in ListQueue: {0}", queue.Count);
        Console.WriteLine();
        var peekText = queue.Peek();

        Console.WriteLine("Just peeked at: {0}", peekText);
        Console.WriteLine();
        var textToRemove = "Test5";

        queue.Remove(textToRemove);
        Console.WriteLine("Just removed: {0}", textToRemove);
        Console.WriteLine();
        var queueCount = queue.Count;

        for (int i = 0; i < queueCount; i++)
        {
            var text = queue.Dequeue();
            Console.WriteLine("Just dequeued: {0}", text);
        }
        Console.WriteLine();
        Console.WriteLine("Item count in ListQueue: {0}", queue.Count);
        Console.WriteLine();
        Console.WriteLine("Now try to ADD an item...should cause an exception.");
        queue.Add("shouldFail");
    }
Пример #29
0
        /// <summary>
        /// Returns the LUA representation of this Lever object
        /// </summary>
        /// <returns></returns>
        protected override string PrintElement(ListQueue <MapElement> elements)
        {
            //throw new NotImplementedException();

            StringBuilder sb = new StringBuilder();

            sb.AppendFormat(@"spawn(""{0}"",{1},{2},{3},{4},""{5}""){6}", _type, x, y, (int)orientation, h, uniqueID, '\n');
            switch (_state)
            {
            case 0:
                sb.AppendFormat(@"{0}.lever:setState({1}){2}", uniqueID, _state.ToString().ToLower(), '\n');
                break;
            }
            sb.AppendFormat(@"{0}.lever:setDisableSelf({1}){2}", uniqueID, DisableSelf.ToString().ToLower(), '\n');
            if (_connectedTo != null)
            {
                sb.AppendFormat(@"{0}.lever:addConnector(""{1}"", ""{2}"", ""{3}""){4}", uniqueID, _action, _connectedTo, _reaction, '\n');
            }

            return(sb.ToString());
            //spawn("beach_lever",16,14,0,0,"beach_lever_1")
            //beach_lever_1.lever:setDisableSelf(false) //so funciona 1x
            //beach_lever_1.lever:addConnector("onToggle", "beach_door_portcullis_1", "toggle")
        }
Пример #30
0
 protected override string PrintElement(ListQueue <MapElement> elements)
 {
     return(String.Format(@"spawn(""{0}"",{1},{2},{3},{4},""{5}""){6}", ElementType, x, y, (int)orientation, h, uniqueID, '\n'));
 }
Пример #31
0
 public void UpdatePath()
 {
     Location goal = TargetPosition;
     if (goal.IsNaN())
     {
         if (TargetEntity == null)
         {
             Path = null;
             return;
         }
         goal = TargetEntity.GetPosition();
     }
     Location selfpos = GetPosition();
     if ((goal - selfpos).LengthSquared() > MaxPathFindDistance * MaxPathFindDistance)
     {
         TargetPosition = Location.NaN; // TODO: Configurable "can't find path" result -> giveup vs. teleport
         TargetEntity = null;
         Path = null;
         return;
     }
     List<Location> tpath = TheRegion.FindPath(selfpos, goal, MaxPathFindDistance, 1);
     if (tpath == null)
     {
         TargetPosition = Location.NaN; // TODO: Configurable "can't find path" result -> giveup vs. teleport
         TargetEntity = null;
         Path = null;
         return;
     }
     Path = new ListQueue<Location>(tpath);
     PathUpdate = 1; // TODO: Configurable update time
 }
Пример #32
0
 public override void Tick()
 {
     if (TheRegion.Delta <= 0)
     {
         return;
     }
     if (!IsSpawned)
     {
         return;
     }
     PathUpdate -= TheRegion.Delta;
     if (PathUpdate <= 0)
     {
         UpdatePath();
     }
     if (Path != null)
     {
         PathMovement = true;
         Location spos = GetPosition();
         while (Path.Length > 0 && ((Path.Peek() - spos).LengthSquared() < PathFindCloseEnough || (Path.Peek() - spos + new Location(0, 0, -1.5)).LengthSquared() < PathFindCloseEnough))
         {
             Path.Pop();
         }
         if (Path.Length <= 0)
         {
             Path = null;
         }
         else
         {
             Location targetdir = (Path.Peek() - spos).Normalize();
             Location movegoal = Utilities.RotateVector(targetdir, (270 + Direction.Yaw) * Utilities.PI180);
             Vector2 movegoal2 = new Vector2((double)movegoal.X, (double)movegoal.Y);
             if (movegoal2.LengthSquared() > 0)
             {
                 movegoal2.Normalize();
             }
             XMove = movegoal2.X;
             YMove = movegoal2.Y;
             if (movegoal.Z > 0.4)
             {
                 CBody.Jump();
             }
         }
     }
     if (Path == null && PathMovement)
     {
         XMove = 0;
         YMove = 0;
         PathMovement = false;
     }
     while (Direction.Yaw < 0)
     {
         Direction.Yaw += 360;
     }
     while (Direction.Yaw > 360)
     {
         Direction.Yaw -= 360;
     }
     if (Direction.Pitch > 89.9f)
     {
         Direction.Pitch = 89.9f;
     }
     if (Direction.Pitch < -89.9f)
     {
         Direction.Pitch = -89.9f;
     }
     CBody.ViewDirection = Utilities.ForwardVector_Deg(Direction.Yaw, Direction.Pitch).ToBVector();
     if (Upward && !IsFlying && !pup && CBody.SupportFinder.HasSupport)
     {
         CBody.Jump();
         pup = true;
     }
     else if (!Upward)
     {
         pup = false;
     }
     double speedmod = new Vector2(XMove, YMove).Length() * 2;
     speedmod *= (1f + SprintOrWalk * 0.5f);
     if (ItemDoSpeedMod)
     {
         speedmod *= ItemSpeedMod;
     }
     Material mat = TheRegion.GetBlockMaterial(GetPosition() + new Location(0, 0, -0.05f));
     speedmod *= mat.GetSpeedMod();
     CBody.StandingSpeed = CBStandSpeed * speedmod;
     CBody.CrouchingSpeed = CBCrouchSpeed * speedmod;
     double frictionmod = 1f;
     frictionmod *= mat.GetFrictionMod();
     CBody.SlidingForce = CBSlideForce * frictionmod * Mass;
     CBody.AirForce = CBAirForce * frictionmod * Mass;
     CBody.TractionForce = CBTractionForce * frictionmod * Mass;
     CBody.VerticalMotionConstraint.MaximumGlueForce = CBGlueForce * Mass;
     if (CurrentSeat == null)
     {
         Vector3 movement = new Vector3(XMove, YMove, 0);
         if (Upward && IsFlying)
         {
             movement.Z = 1;
         }
         else if (Downward && IsFlying)
         {
             movement.Z = -1;
         }
         if (movement.LengthSquared() > 0)
         {
             movement.Normalize();
         }
         if (Downward)
         {
             CBody.StanceManager.DesiredStance = Stance.Crouching;
         }
         else
         {
             CBody.StanceManager.DesiredStance = DesiredStance;
         }
         CBody.HorizontalMotionConstraint.MovementDirection = new Vector2(movement.X, movement.Y);
         if (IsFlying)
         {
             Location forw = Utilities.RotateVector(new Location(-movement.Y, movement.X, movement.Z), Direction.Yaw * Utilities.PI180, Direction.Pitch * Utilities.PI180);
             SetPosition(GetPosition() + forw * TheRegion.Delta * CBStandSpeed * 2 * speedmod);
             CBody.HorizontalMotionConstraint.MovementDirection = Vector2.Zero;
             Body.LinearVelocity = new Vector3(0, 0, 0);
         }
     }
     else
     {
         CurrentSeat.HandleInput(this);
     }
     base.Tick();
     RigidTransform transf = new RigidTransform(Vector3.Zero, Body.Orientation);
     BoundingBox box;
     Body.CollisionInformation.Shape.GetBoundingBox(ref transf, out box);
     MinZ = box.Min.Z;
 }
Пример #33
0
        public override void Tick()
        {
            if (TheRegion.Delta <= 0)
            {
                return;
            }
            if (!IsSpawned)
            {
                return;
            }
            PathUpdate -= TheRegion.Delta;
            if (PathUpdate <= 0)
            {
                UpdatePath();
            }
            if (Path != null)
            {
                PathMovement = true;
                Location spos = GetPosition();
                while (Path.Length > 0 && ((Path.Peek() - spos).LengthSquared() < PathFindCloseEnough || (Path.Peek() - spos + new Location(0, 0, -1.5)).LengthSquared() < PathFindCloseEnough))
                {
                    Path.Pop();
                }
                if (Path.Length <= 0)
                {
                    Path = null;
                }
                else
                {
                    Location targetdir = (Path.Peek() - spos).Normalize();
                    Location movegoal  = Utilities.RotateVector(targetdir, (270 + Direction.Yaw) * Utilities.PI180);
                    Vector2  movegoal2 = new Vector2((double)movegoal.X, (double)movegoal.Y);
                    if (movegoal2.LengthSquared() > 0)
                    {
                        movegoal2.Normalize();
                    }
                    XMove = movegoal2.X;
                    YMove = movegoal2.Y;
                    if (movegoal.Z > 0.4)
                    {
                        CBody.Jump();
                    }
                }
            }
            if (Path == null && PathMovement)
            {
                XMove        = 0;
                YMove        = 0;
                PathMovement = false;
            }
            while (Direction.Yaw < 0)
            {
                Direction.Yaw += 360;
            }
            while (Direction.Yaw > 360)
            {
                Direction.Yaw -= 360;
            }
            if (Direction.Pitch > 89.9f)
            {
                Direction.Pitch = 89.9f;
            }
            if (Direction.Pitch < -89.9f)
            {
                Direction.Pitch = -89.9f;
            }
            CBody.ViewDirection = Utilities.ForwardVector_Deg(Direction.Yaw, Direction.Pitch).ToBVector();
            if (Upward && !IsFlying && !pup && CBody.SupportFinder.HasSupport)
            {
                CBody.Jump();
                pup = true;
            }
            else if (!Upward)
            {
                pup = false;
            }
            double speedmod = new Vector2(XMove, YMove).Length() * 1.25;

            speedmod *= (1f + SprintOrWalk * 0.5f);
            if (ItemDoSpeedMod)
            {
                speedmod *= ItemSpeedMod;
            }
            Material mat = TheRegion.GetBlockMaterial(GetPosition() + new Location(0, 0, -0.05f));

            speedmod            *= mat.GetSpeedMod();
            CBody.StandingSpeed  = CBStandSpeed * speedmod;
            CBody.CrouchingSpeed = CBCrouchSpeed * speedmod;
            double frictionmod = 1f;

            frictionmod        *= mat.GetFrictionMod();
            CBody.SlidingForce  = CBSlideForce * frictionmod * Mass;
            CBody.AirForce      = CBAirForce * frictionmod * Mass;
            CBody.TractionForce = CBTractionForce * frictionmod * Mass;
            CBody.VerticalMotionConstraint.MaximumGlueForce = CBGlueForce * Mass;
            if (CurrentSeat == null)
            {
                Vector3 movement = new Vector3(XMove, YMove, 0);
                if (Upward && IsFlying)
                {
                    movement.Z = 1;
                }
                else if (Downward && IsFlying)
                {
                    movement.Z = -1;
                }
                if (movement.LengthSquared() > 0)
                {
                    movement.Normalize();
                }
                if (Downward)
                {
                    CBody.StanceManager.DesiredStance = Stance.Crouching;
                }
                else
                {
                    CBody.StanceManager.DesiredStance = DesiredStance;
                }
                CBody.HorizontalMotionConstraint.MovementDirection = new Vector2(movement.X, movement.Y);
                Location pos     = GetPosition();
                Location rad     = new Location(CBody.BodyRadius, CBody.BodyRadius, 0);
                double   halfeye = CBHHeight * (CBody.StanceManager.CurrentStance == Stance.Standing ? 1.8 : 1.5) * 0.5;
                bool     uw1     = TheRegion.InWater(pos - rad, pos + rad + new Location(0, 0, halfeye));
                bool     uw2     = TheRegion.InWater(pos - rad + new Location(0, 0, halfeye), pos + rad + new Location(0, 0, halfeye * 2));
                if (uw1 || uw2)
                {
                    double mult = uw1 ? (uw2 ? 0.6 : 0.3) : 0.3;
                    SetForSwim(mult, Body.Space.ForceUpdater.Gravity * (1.0 - mult));
                }
                else
                {
                    SetForGround();
                }
                if (IsFlying)
                {
                    Location forw = Utilities.RotateVector(new Location(-movement.Y, movement.X, movement.Z), Direction.Yaw * Utilities.PI180, Direction.Pitch * Utilities.PI180);
                    SetPosition(GetPosition() + forw * TheRegion.Delta * CBStandSpeed * 2 * speedmod);
                    CBody.HorizontalMotionConstraint.MovementDirection = Vector2.Zero;
                    Body.LinearVelocity = new Vector3(0, 0, 0);
                }
                else if (IsSwimlogic)
                {
                    Location forw = Utilities.RotateVector(new Location(movement.X, movement.Y, 0), Direction.Yaw * Utilities.PI180, Direction.Pitch * Utilities.PI180);
                    if (Upward)
                    {
                        forw.Z = 1;
                    }
                    else if (Downward)
                    {
                        forw.Z = -1;
                    }
                    SwimForce(forw.ToBVector());
                }
            }
            else
            {
                CurrentSeat.HandleInput(this);
            }
            base.Tick();
            RigidTransform transf = new RigidTransform(Vector3.Zero, Body.Orientation);

            Body.CollisionInformation.Shape.GetBoundingBox(ref transf, out BoundingBox box);
            MinZ = box.Min.Z;
        }
Пример #34
0
 /// <summary>
 /// Constructs a new CommandQueue - generally kept to the Frenetic internals.
 /// TODO: IList _commands -> ListQueue?
 /// </summary>
 public CommandQueue(CommandScript _script, IList<CommandEntry> _commands, Commands _system)
 {
     Script = _script;
     CommandList = new ListQueue<CommandEntry>(_commands);
     CommandSystem = _system;
     Variables = new Dictionary<string, TemplateObject>();
     Debug = DebugMode.FULL;
 }