Exemple #1
0
        public bool Apply(Ets2Node node)
        {
            if (node.NodeUID == PrefabNodeUID)
            {
                PrefabNode = node;
            }

            if (node.NodeUID == StartNodeUID)
            {
                StartNode = node;
                return(true);
            }
            else if (node.NodeUID == EndNodeUID)
            {
                EndNode = node;
                return(true);
            }
            else if (NodesList.ContainsKey(node.NodeUID))
            {
                NodesList[node.NodeUID] = node;
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #2
0
        public void Find(Ets2Node node, ulong item, bool isBackward)
        {
            var req = new Ets2ItemSearchRequest
            {
                ItemUID    = item,
                Node       = node,
                IsBackward = isBackward,
                IsForward  = !isBackward
            };

            ItemSearchRequests.Add(req);
        }
        public Ets2NavigationSegment(IEnumerable<Ets2Item> roadPath, Ets2NavigationSegment prevSeg)
        {
            Type = Ets2NavigationSegmentType.Road;

            Roads = roadPath.ToList();

            // Generate entry/exit noads & road item order
            var firstRoad = Roads.FirstOrDefault();
            var lastRoad = Roads.LastOrDefault();

            if (prevSeg.Prefab.NodesList.ContainsValue(firstRoad.StartNode))
            {
                Entry = firstRoad.StartNode;
                Exit = lastRoad.EndNode;
                ReversedRoadChain = false;
                ReversedRoadElements = false;
            }
            else if (prevSeg.Prefab.NodesList.ContainsValue(firstRoad.EndNode))
            {
                Entry = firstRoad.EndNode;
                Exit = lastRoad.StartNode;
                ReversedRoadChain = false;
                ReversedRoadElements = true;
            }
            else if (prevSeg.Prefab.NodesList.ContainsValue(lastRoad.StartNode))
            {
                Entry = lastRoad.StartNode;
                Exit = firstRoad.EndNode;
                ReversedRoadChain = true;
                ReversedRoadElements = false;
            }
            else if ( prevSeg.Prefab.NodesList.ContainsValue(lastRoad.EndNode))
            {
                Entry = lastRoad.EndNode;
                Exit = firstRoad.StartNode;
                ReversedRoadChain = true;
                ReversedRoadElements = true;
            }
            else
            {

            }
        }
Exemple #4
0
        public void ParseNodes()
        {
            if (Empty)
            {
                return;
            }

            // First determine the number of positions in this file
            var nodesPieces = BitConverter.ToInt32(Stream, 0x10);

            int i = Stream.Length;

            do
            {
                i -= 56; // each block is 56 bytes long

                var node = new Ets2Node(Stream, i);
                if (node.NodeUID == 0)
                {
                    FooterStart = i + 56 - 4;
                    break;
                }
                Nodes.Add(node);

                if (Mapper.Nodes.ContainsKey(node.NodeUID) == false)
                {
                    Mapper.Nodes.TryAdd(node.NodeUID, node);
                }

                var count = BitConverter.ToInt32(Stream, i - 4);
                if (count >= nodesPieces && count == Nodes.Count)
                {
                    FooterStart = i - 4;
                    break;
                }
            } while (i > 60);

            if (FooterStart < 0)
            {
                NoFooterError = true;
                return;
            }
        }
        public Ets2NavigationSegment(IEnumerable <Ets2Item> roadPath, Ets2NavigationSegment prevSeg)
        {
            Type = Ets2NavigationSegmentType.Road;

            Roads = roadPath.ToList();

            // Generate entry/exit noads & road item order
            var firstRoad = Roads.FirstOrDefault();
            var lastRoad  = Roads.LastOrDefault();

            if (prevSeg.Prefab.NodesList.ContainsValue(firstRoad.StartNode))
            {
                Entry                = firstRoad.StartNode;
                Exit                 = lastRoad.EndNode;
                ReversedRoadChain    = false;
                ReversedRoadElements = false;
            }
            else if (prevSeg.Prefab.NodesList.ContainsValue(firstRoad.EndNode))
            {
                Entry                = firstRoad.EndNode;
                Exit                 = lastRoad.StartNode;
                ReversedRoadChain    = false;
                ReversedRoadElements = true;
            }
            else if (prevSeg.Prefab.NodesList.ContainsValue(lastRoad.StartNode))
            {
                Entry                = lastRoad.StartNode;
                Exit                 = firstRoad.EndNode;
                ReversedRoadChain    = true;
                ReversedRoadElements = false;
            }
            else if (prevSeg.Prefab.NodesList.ContainsValue(lastRoad.EndNode))
            {
                Entry                = lastRoad.EndNode;
                Exit                 = firstRoad.StartNode;
                ReversedRoadChain    = true;
                ReversedRoadElements = true;
            }
            else
            {
            }
        }
Exemple #6
0
        public void ParseNodes()
        {
            if (Empty) return;

            // First determine the number of positions in this file
            var nodesPieces = BitConverter.ToInt32(Stream, 0x10);

            int i = Stream.Length;

            do
            {
                i -= 56; // each block is 56 bytes long

                var node = new Ets2Node(Stream, i);
                if (node.NodeUID == 0)
                {
                    FooterStart = i + 56 - 4;
                    break;
                }
                Nodes.Add(node);

                if (Mapper.Nodes.ContainsKey(node.NodeUID) == false)
                    Mapper.Nodes.TryAdd(node.NodeUID, node);

                var count = BitConverter.ToInt32(Stream, i - 4);
                if (count >= nodesPieces && count == Nodes.Count)
                {
                    FooterStart = i - 4;
                    break;
                }

            } while (i > 60);

            if (FooterStart < 0)
            {
                NoFooterError = true;
                return;
            }
        }
Exemple #7
0
        public void FindItems(Ets2Node node, bool postpone)
        {
            if (node.ForwardItemUID > 0)
            {
                Ets2Item itemForward;
                if (Mapper.Items.TryGetValue(node.ForwardItemUID, out itemForward))
                {
                    if (itemForward.Apply(node))
                        node.ForwardItem = itemForward;
                }
                else
                {
                    itemForward = FindItem(node.ForwardItemUID);
                    if (itemForward == null)
                    {
                        if (postpone)
                            Mapper.Find(node, node.ForwardItemUID, false);
                    }
                    else
                    {
                        Items.Add(itemForward);
                        Mapper.Items.TryAdd(node.ForwardItemUID, itemForward);
                        node.ForwardItem = itemForward;

                        if (itemForward.Apply(node))
                            node.ForwardItem = itemForward;
                    }
                }
            }
            if (node.BackwardItemUID > 0)
            {
                Ets2Item itemBackward;
                if (Mapper.Items.TryGetValue(node.BackwardItemUID, out itemBackward))
                {
                    if (itemBackward.Apply(node))
                        node.BackwardItem = itemBackward;
                }
                else
                {
                    itemBackward = FindItem(node.BackwardItemUID);
                    if (itemBackward == null)
                    {
                        if (postpone)
                            Mapper.Find(node, node.BackwardItemUID, true);
                    }
                    else
                    {
                        Items.Add(itemBackward);
                        Mapper.Items.TryAdd(node.BackwardItemUID, itemBackward);
                        node.BackwardItem = itemBackward;

                        if (itemBackward.Apply(node))
                            node.BackwardItem = itemBackward;
                    }
                }
            }
        }
Exemple #8
0
        public void FindItems(Ets2Node node, bool postpone)
        {
            if (node.ForwardItemUID > 0)
            {
                Ets2Item itemForward;
                if (Mapper.Items.TryGetValue(node.ForwardItemUID, out itemForward))
                {
                    if (itemForward.Apply(node))
                    {
                        node.ForwardItem = itemForward;
                    }
                }
                else
                {
                    itemForward = FindItem(node.ForwardItemUID);
                    if (itemForward == null)
                    {
                        if (postpone)
                        {
                            Mapper.Find(node, node.ForwardItemUID, false);
                        }
                    }
                    else
                    {
                        Items.Add(itemForward);
                        Mapper.Items.TryAdd(node.ForwardItemUID, itemForward);
                        node.ForwardItem = itemForward;

                        if (itemForward.Apply(node))
                        {
                            node.ForwardItem = itemForward;
                        }
                    }
                }
            }
            if (node.BackwardItemUID > 0)
            {
                Ets2Item itemBackward;
                if (Mapper.Items.TryGetValue(node.BackwardItemUID, out itemBackward))
                {
                    if (itemBackward.Apply(node))
                    {
                        node.BackwardItem = itemBackward;
                    }
                }
                else
                {
                    itemBackward = FindItem(node.BackwardItemUID);
                    if (itemBackward == null)
                    {
                        if (postpone)
                        {
                            Mapper.Find(node, node.BackwardItemUID, true);
                        }
                    }
                    else
                    {
                        Items.Add(itemBackward);
                        Mapper.Items.TryAdd(node.BackwardItemUID, itemBackward);
                        node.BackwardItem = itemBackward;

                        if (itemBackward.Apply(node))
                        {
                            node.BackwardItem = itemBackward;
                        }
                    }
                }
            }
        }
Exemple #9
0
        public IEnumerable <IEnumerable <Ets2Point> > GeneratePolygonCurves(Ets2Node node, int nodeOr)
        {
            var ks = new List <IEnumerable <Ets2Point> >();

            var steps = 16;

            if (nodeOr >= this.Nodes.Count)
            {
                nodeOr = 0;
            }
            if (Nodes.Any() == false)
            {
                return(ks);
            }

            var xOr = node.X;
            var yOr = node.Z;
            var yaw = node.Yaw - this.Nodes[nodeOr].Yaw + Math.PI / 2;

            foreach (var curve in Curves)
            {
                var ps = new Ets2Point[steps];

                var srx = curve.StartX - this.Nodes[nodeOr].X;
                var erx = curve.EndX - this.Nodes[nodeOr].X;
                var srz = curve.StartZ - this.Nodes[nodeOr].Z;
                var erz = curve.EndZ - this.Nodes[nodeOr].Z;

                var sr = (float)Math.Sqrt(srx * srx + srz * srz);
                var er = (float)Math.Sqrt(erx * erx + erz * erz);

                var ans = yaw - Math.Atan2(srz, srx);
                var ane = yaw - Math.Atan2(erz, erx);

                var sx = xOr - sr * (float)Math.Sin(ans);
                var ex = xOr - er * (float)Math.Sin(ane);
                var sz = yOr - sr * (float)Math.Cos(ans);
                var ez = yOr - er * (float)Math.Cos(ane);
                // TODO: Temporary linear interpolation
                // TODO: Interpolate heading & Y value
                ps    = new Ets2Point[2];
                ps[0] = new Ets2Point(sx, 0, sz, 0);
                ps[1] = new Ets2Point(ex, 0, ez, 0);
                ks.Add(ps);

                /*
                 * var tangentSX = (float)Math.Cos(ans) * curve.Length;
                 * var tangentEX = (float)Math.Cos(ane) * curve.Length;
                 * var tangentSY = (float)Math.Sin(ans) * curve.Length;
                 * var tangentEY = (float)Math.Sin(ane) * curve.Length;
                 *
                 * for (int k = 0; k < steps; k++)
                 * {
                 *  var s = (float)k / (float)steps;
                 *  var x = (float)Ets2CurveHelper.Hermite(s, sx, ex, tangentSX, tangentEX);
                 *  var z = (float)Ets2CurveHelper.Hermite(s, sz, ez, tangentSY, tangentEY);
                 *  ps[k] = new Ets2Point(x, 0, z, 0);
                 * }
                 *
                 * ks.Add(ps);
                 */
            }
            return(ks);
        }
Exemple #10
0
        public IEnumerable <Ets2Point> GeneratePolygonForRoute(Ets2PrefabRoute route, Ets2Node node, int nodeOr)
        {
            List <Ets2Point> p = new List <Ets2Point>();

            if (route == null || route.Route == null)
            {
                return(p);
            }

            /*
             * yaw -= this.Nodes[nodeOr].Yaw;
             * yaw += Math.PI/2;
             */
            var xOr = node.X;
            var yOr = node.Z;
            var yaw = node.Yaw - this.Nodes[nodeOr].Yaw + Math.PI / 2;

            foreach (var curve in route.Route)
            {
                var srx = curve.StartX - this.Nodes[nodeOr].X;
                var erx = curve.EndX - this.Nodes[nodeOr].X;
                var srz = curve.StartZ - this.Nodes[nodeOr].Z;
                var erz = curve.EndZ - this.Nodes[nodeOr].Z;

                var sr = (float)Math.Sqrt(srx * srx + srz * srz);
                var er = (float)Math.Sqrt(erx * erx + erz * erz);

                var ans = yaw - Math.Atan2(srz, srx);
                var ane = yaw - Math.Atan2(erz, erx);

                var sx = xOr - sr * (float)Math.Sin(ans);
                var ex = xOr - er * (float)Math.Sin(ane);
                var sz = yOr - sr * (float)Math.Cos(ans);
                var ez = yOr - er * (float)Math.Cos(ane);

                // TODO: Temporary linear interpolation
                // TODO: Interpolate heading & Y value
                var ps = new Ets2Point[2];
                ps[0] = new Ets2Point(sx, node.Y, sz, (float)ans);
                ps[1] = new Ets2Point(ex, node.Y, ez, (float)ane);

                p.AddRange(ps);
            }

            return(p);
        }
Exemple #11
0
        public void Find(Ets2Node node, ulong item, bool isBackward)
        {
            var req = new Ets2ItemSearchRequest
            {
                ItemUID = item,
                Node = node,
                IsBackward = isBackward,
                IsForward = !isBackward
            };

            ItemSearchRequests.Add(req);
        }
Exemple #12
0
        public IEnumerable<IEnumerable<Ets2Point>> GeneratePolygonCurves(Ets2Node node, int nodeOr)
        {
            var ks = new List<IEnumerable<Ets2Point>>();

            var steps = 16;
            
            if (nodeOr >= this.Nodes.Count)
                nodeOr = 0;
            if (Nodes.Any() == false)
                return ks;

            var xOr = node.X;
            var yOr = node.Z;
            var yaw = node.Yaw - this.Nodes[nodeOr].Yaw + Math.PI/2;

            foreach (var curve in Curves)
            {
                var ps = new Ets2Point[steps];

                var srx = curve.StartX - this.Nodes[nodeOr].X;
                var erx = curve.EndX - this.Nodes[nodeOr].X;
                var srz = curve.StartZ - this.Nodes[nodeOr].Z;
                var erz = curve.EndZ - this.Nodes[nodeOr].Z;

                var sr = (float) Math.Sqrt(srx * srx + srz * srz);
                var er = (float)Math.Sqrt(erx * erx + erz * erz);

                var ans = yaw - Math.Atan2(srz,srx);
                var ane = yaw - Math.Atan2(erz, erx);

                var sx = xOr - sr * (float)Math.Sin(ans);
                var ex = xOr - er * (float)Math.Sin(ane);
                var sz = yOr - sr * (float)Math.Cos(ans);
                var ez = yOr - er * (float)Math.Cos(ane);
                // TODO: Temporary linear interpolation
                // TODO: Interpolate heading & Y value
                ps = new Ets2Point[2];
                ps[0] = new Ets2Point(sx, 0, sz, 0);
                ps[1] = new Ets2Point(ex, 0, ez, 0);
                ks.Add(ps);
                
                /*
                var tangentSX = (float)Math.Cos(ans) * curve.Length;
                var tangentEX = (float)Math.Cos(ane) * curve.Length;
                var tangentSY = (float)Math.Sin(ans) * curve.Length;
                var tangentEY = (float)Math.Sin(ane) * curve.Length;

                for (int k = 0; k < steps; k++)
                {
                    var s = (float)k / (float)steps;
                    var x = (float)Ets2CurveHelper.Hermite(s, sx, ex, tangentSX, tangentEX);
                    var z = (float)Ets2CurveHelper.Hermite(s, sz, ez, tangentSY, tangentEY);
                    ps[k] = new Ets2Point(x, 0, z, 0);
                }

                ks.Add(ps);
                */
            }
            return ks;
        }
Exemple #13
0
        public IEnumerable<Ets2Point> GeneratePolygonForRoute(Ets2PrefabRoute route, Ets2Node node,  int nodeOr)
        {
            List<Ets2Point> p = new List<Ets2Point>();

            if (route == null || route.Route == null)
            return p;

            /*
            yaw -= this.Nodes[nodeOr].Yaw;
            yaw += Math.PI/2;
            */
            var xOr = node.X;
            var yOr = node.Z;
            var yaw = node.Yaw - this.Nodes[nodeOr].Yaw + Math.PI / 2;

            foreach (var curve in route.Route)
            {
                var srx = curve.StartX - this.Nodes[nodeOr].X;
                var erx = curve.EndX - this.Nodes[nodeOr].X;
                var srz = curve.StartZ - this.Nodes[nodeOr].Z;
                var erz = curve.EndZ - this.Nodes[nodeOr].Z;

                var sr = (float) Math.Sqrt(srx*srx + srz*srz);
                var er = (float) Math.Sqrt(erx*erx + erz*erz);

                var ans = yaw - Math.Atan2(srz, srx);
                var ane = yaw - Math.Atan2(erz, erx);

                var sx = xOr - sr*(float) Math.Sin(ans);
                var ex = xOr - er*(float) Math.Sin(ane);
                var sz = yOr - sr*(float) Math.Cos(ans);
                var ez = yOr - er*(float) Math.Cos(ane);

                // TODO: Temporary linear interpolation
                // TODO: Interpolate heading & Y value
                var ps = new Ets2Point[2];
                ps[0] = new Ets2Point(sx, node.Y, sz,(float) ans);
                ps[1] = new Ets2Point(ex, node.Y, ez, (float)ane);

                p.AddRange(ps);
            }

            return p;
        }