Ejemplo n.º 1
0
        public void OnStreet(int x, int y, int z, Map map)
        {
            if (Active)
            {
                return;
            }
            Active = true;
            X      = x;
            Y      = y;
            Z      = z;
            Map    = map;

            Roads = new Road[0];
            Road road = new Road(X, Y, Z);

            road.Add(new Point3D(X, Y, Z));
            Add(road);
            OnStreet(road, null);
            Active = false;
        }
Ejemplo n.º 2
0
    private bool IsValid()
    {
        int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
        this.PersonCount = inpt[0];
        int hintCount = inpt[1];

        this.PersonPos = new Nullable <long> [this.PersonCount];

        for (int i = 0; i < hintCount; i++)
        {
            inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
            int[] person = inpt.Take(2).Select(a => a - 1).ToArray();
            person.ToList().ForEach(a => {
                if (!Road.ContainsKey(a))
                {
                    Road.Add(a, new Dictionary <int, long>());
                }
            });
            if (Road[person[0]].ContainsKey(person[1]))
            {
                if (Road[person[0]][person[1]] != inpt[2])
                {
                    return(false);
                }
            }
            else
            {
                Road[person[0]][person[1]] = inpt[2];
            }
            if (Road[person[1]].ContainsKey(person[0]))
            {
                if (Road[person[1]][person[0]] != inpt[2] * -1)
                {
                    return(false);
                }
            }
            else
            {
                Road[person[1]][person[0]] = inpt[2] * -1;
            }
        }
        Stack <int> q = new Stack <int>();

        for (int i = PersonCount - 1; i >= 0; i--)
        {
            if (Road.ContainsKey(i))
            {
                q.Push(i);
            }
        }
        if (q.Count == 0)
        {
            return(true);
        }
        PersonPos[q.Peek()] = 0;
        while (q.Count > 0)
        {
            int current = q.Pop();
            if (PersonPos[current] == null)
            {
                PersonPos[current] = 0;
            }
            foreach (int next in Road[current].Keys)
            {
                if (PersonPos[next] == null)
                {
                    PersonPos[next] = PersonPos[current].Value + this.Road[current][next];
                    q.Push(next);
                    continue;
                }
                if (PersonPos[next].Value - PersonPos[current].Value != this.Road[current][next])
                {
                    return(false);
                }
            }
        }
        return(true);
    }
Ejemplo n.º 3
0
    public void Proc()
    {
        int[] inpt      = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
        int   matiCount = inpt[0];
        int   roadCount = inpt[1];
        int   railCount = inpt[2];

        this.RoadMatiList = new TreeNode[matiCount];
        this.RailMatiList = new TreeNode[matiCount];

        for (int i = 0; i < roadCount; i++)
        {
            inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a) - 1).ToArray();
            if (!Road.ContainsKey(inpt[0]))
            {
                Road.Add(inpt[0], new Dictionary <int, bool>());
            }
            if (!this.Road.ContainsKey(inpt[1]))
            {
                this.Road.Add(inpt[1], new Dictionary <int, bool>());
            }
            this.Road[inpt[0]][inpt[1]] = true;
            this.Road[inpt[1]][inpt[0]] = true;
        }
        for (int i = 0; i < railCount; i++)
        {
            inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a) - 1).ToArray();
            if (!this.Rail.ContainsKey(inpt[0]))
            {
                this.Rail.Add(inpt[0], new Dictionary <int, bool>());
            }
            if (!this.Rail.ContainsKey(inpt[1]))
            {
                this.Rail.Add(inpt[1], new Dictionary <int, bool>());
            }
            this.Rail[inpt[0]][inpt[1]] = true;
            this.Rail[inpt[1]][inpt[0]] = true;
        }
        for (int i = 0; i < matiCount; i++)
        {
            if (this.RoadMatiList[i] != null)
            {
                continue;
            }
            this.RoadMatiList[i] = new TreeNode(i);
            Queue <TreeNode> que = new Queue <TreeNode>();
            que.Enqueue(this.RoadMatiList[i]);
            while (que.Count > 0)
            {
                TreeNode curr = que.Dequeue();
                if (!this.Road.ContainsKey(curr.ID))
                {
                    continue;
                }
                foreach (int next in this.Road[curr.ID].Keys)
                {
                    if (curr.Parent != null && curr.Parent.ID == next)
                    {
                        continue;
                    }
                    if (RoadMatiList[next] != null)
                    {
                        continue;
                    }
                    RoadMatiList[next] = curr.AddChild(next);
                    que.Enqueue(RoadMatiList[next]);
                }
            }
        }
        for (int i = 0; i < matiCount; i++)
        {
            if (this.RailMatiList[i] != null)
            {
                continue;
            }
            this.RailMatiList[i] = new TreeNode(i);
            Queue <TreeNode> que = new Queue <TreeNode>();
            que.Enqueue(this.RailMatiList[i]);
            while (que.Count > 0)
            {
                TreeNode curr = que.Dequeue();
                if (!this.Rail.ContainsKey(curr.ID))
                {
                    continue;
                }
                foreach (int next in this.Rail[curr.ID].Keys)
                {
                    if (RailMatiList[next] != null)
                    {
                        continue;
                    }
                    RailMatiList[next] = curr.AddChild(next);
                    que.Enqueue(RailMatiList[next]);
                }
            }
        }

        Dictionary <int, Dictionary <int, int> > groupCount = new Dictionary <int, Dictionary <int, int> >();

        for (int i = 0; i < matiCount; i++)
        {
            int roadGroup = this.RoadMatiList[i].Root.ID;
            int railGroup = this.RailMatiList[i].Root.ID;
            if (!groupCount.ContainsKey(roadGroup))
            {
                groupCount.Add(roadGroup, new Dictionary <int, int>());
            }
            if (groupCount[roadGroup].ContainsKey(railGroup))
            {
                groupCount[roadGroup][railGroup]++;
            }
            else
            {
                groupCount[roadGroup][railGroup] = 1;
            }
        }

        int[] cnt = new int[matiCount];
        for (int i = 0; i < matiCount; i++)
        {
            int roadGroup = this.RoadMatiList[i].Root.ID;
            int railGroup = this.RailMatiList[i].Root.ID;
            cnt[i] = groupCount[roadGroup][railGroup];
        }
        string ans = string.Join(" ", cnt);

        Console.WriteLine(ans);
    }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            // This example program places a few road segments
            // and models at hardcoded locations into an empty map
            // and saves the map into the mod folder.

            // Create an empty map
            var map = new Map("example");

            // Add a road segment:
            // Use the [Item Type].Add method to create a new item
            // and automatically add it to the map.
            var r = Road.Add(map,
                             new Vector3(19, 0, 19.5f), // position of backward (red) node
                             new Vector3(65, 0, 23),    // position of forward (green) node
                             "ger1",                    // unit name of the road
                             80, 80                     // terrain size on the left and right side
                             );

            // Road properties:
            // For roads that don't consist of two seperate roadways,
            // various properties introduced with the template system
            // are set for the right side of the road but apply to both
            // sides, and the values on the left side are ignored.
            r.Right.Look      = "ger_1";
            r.Right.Variant   = "broken_de";
            r.Right.LeftEdge  = "ger_sh_15";
            r.Right.RightEdge = "ger_sh_15";

            // Terrain properties:
            // Define what the terrain will look like.
            // We'll set all of the following properties on the right side only
            // and then clone them to the left side.
            r.Right.Terrain.QuadData.Material = "34";        // "grass_ger_main"
            r.Right.Terrain.Profile           = "profile12"; // "hills2"
            r.Right.Terrain.Noise             = TerrainNoise.Percent0;
            r.Right.Terrain.Coefficient       = 0.5f;

            // Vegetation properties:
            // Let's add some vegetation.
            r.Right.Vegetation[0].Name    = "v2_1ger"; // "ger - mixed forest"
            r.Right.Vegetation[0].Density = 200;
            r.Right.Vegetation[0].From    = 15;
            r.Right.Vegetation[0].To      = 80;

            // Road models:
            // Let's add some reflector posts as well.
            r.Right.Models[0].Name     = "219"; // "reflective post"
            r.Right.Models[0].Distance = 50;
            r.Right.Models[0].Offset   = 6;

            // Copy all of these properties to the right side.
            r.Left = r.Right.Clone();

            // Append some more segments:
            // By default, Append will copy all settings.
            r.Append(new Vector3(98, 0, 43.5f))
            .Append(new Vector3(146.5f, 0, 25))
            .Append(new Vector3(216, 0, 25));

            // Finally, let's place two model items:
            Model.Add(map,
                      new Vector3(103.75f, -0.3f, 31.73f), // position
                      -2.99f,                              // Y rotation in radians
                      "dlc_no_471",                        // unit name of "house_01_sc"
                      "brick",                             // variant
                      "default"                            // look
                      );
            Model.Add(map, new Vector3(159.64f, -0.1f, 36.91f),
                      (float)Math.PI / 2, "378", "default", "default"); // "wood_heap1"

            // Save the map
            var documentsFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            var modFolder       = Path.Combine(documentsFolder, "Euro Truck Simulator 2/mod");
            var modName         = "example";

            map.Save(Path.Combine(modFolder, modName, "map"), true);

            // Remember to hit F8 after loading it in the editor for the first time.
        }