/// <summary>
    /// Builds a route based on the given start point.
    /// </summary>
    /// <param name="allRoutes">All routes for a certain traffic participant</param>
    /// <param name="start">Starting point to calculate a route from</param>
    /// <returns>A route using the given starting point</returns>
    public static List <Wp> RouteBuilder(List <List <Wp> > allRoutes, Wp start)
    {
        List <List <Wp> > possibleRoutes = allRoutes.Where(l => l.First() == start).ToList();

        List <Wp> route;

        // Sommige routes delen een begin punt
        if (possibleRoutes.Count > 1)
        {
            int i = Random.Range(0, possibleRoutes.Count);
            route = possibleRoutes[i];
        }
        else
        {
            route = possibleRoutes[0];
        }

        Wp last = route.Last();

        // If the last part of the route is not the end point, find a route that starts at the end point, and glue them together.
        if (last != Wp.END)
        {
            List <Wp> extension = RouteBuilder(allRoutes, last);

            return(route.Concat(extension).Distinct().ToList());
        }
        else
        {
            return(route);
        }
    }
示例#2
0
        // Update is called once per frame
        void Update()
        {
            timer        += Time.deltaTime;
            fanfareTimer += Time.deltaTime;
            busTimer     += Time.deltaTime;

            if (timer >= SpawnInterval)
            {
                RouteMultiplicator(Agent.Car);
                RouteMultiplicator(Agent.Bicycle);

                //RouteMultiplicator(Agent.Pedestrian);

                // spawn a fanfare once in a while
                int dice = Random.Range(1, 10);

                if (!fanfareIsActive && dice == 5)
                {
                    fanfareStart = pedestrianSpawnPoints[Random.Range(0, pedestrianSpawnPoints.Count)];
                    //Debug.Log("spawning fanfare at " + fanfareStart);
                    fanfareRoute    = Waypoint_controller.RouteBuilder(Waypoint_controller.pedestrianRoutes, fanfareStart);
                    fanfareIsActive = true;
                }
                else if (fanfareTimer < FanfareSpawnInterval || !fanfareIsActive)
                {
                    RouteMultiplicator(Agent.Pedestrian);
                }

                timer = 0;
            }

            if (busTimer >= BusSpawnInterval)
            {
                //Debug.Log("Spawning bus");
                busTimer = 0f;
                RouteMultiplicator(Agent.Bus);
            }

            if (timer > 0 && fanfareTimer >= FanfareSpawnInterval && fanfareIsActive)
            {
                if (fanfareIndex < 5)
                {
                    fanfareTimer = 0;
                    RouteMultiplicator(fanfare[fanfareIndex]);
                    //Debug.Log("spawned a " + fanfare[fanfareIndex]);
                    fanfareIndex++;
                }
                else
                {
                    fanfareIsActive = false;
                    fanfareIndex    = 0;
                    //Debug.Log("fanfare complete");
                }
            }
        }
示例#3
0
        public void LoadIntellisenseResults(List <Diagnostic> hc)
        {
            lock (s_obs)
            {
                if (ef == null)
                {
                    return;
                }

                ScriptControl.ScriptControl scr = null;

                VSSolution vs = null;

                string filename = "";

                if (ef != null)
                {
                    if (ef.scr != null)
                    {
                        scr = ef.scr;
                    }
                }

                ToolStripComboBox b = toolStripComboBox1;

                int i = b.SelectedIndex;

                vs = ef.GetVSSolution();

                VSProject vp = null;
                //if (vs != null)
                //    vp = vs.MainVSProject;

                //dg.SuspendLayout();

                //LI = new ArrayList();

                //if (vp != null)
                //    if (i == 2)
                //    {
                //        foreach (IntErrors e in DD)
                //        {
                //            if (vp != null)
                //                if (e.vp != vp)
                //                    continue;

                //            int rowId = dg.Rows.Add();
                //            DataGridViewRow row = dg.Rows[rowId];

                //            row.Cells[0].Value = "";
                //            row.Cells[1].Value = ve_resource.Breakall_6323;
                //            row.Cells[2].Value = "e.Code";
                //            row.Cells[3].Value = e.e.Message;
                //            row.Cells[4].Value = Path.GetFileNameWithoutExtension(e.vp.FileName);
                //            row.Cells[5].Value = Path.GetFileName(e.file);
                //            row.Cells[6].Value = e.e.Region.BeginLine.ToString();
                //            row.Cells[7].Value = "project";

                //            string message = e.e.Message;

                //            //if (message.StartsWith("UnknownIdentifier") == true)
                //            //    MessageBox.Show("Unknown identifier");

                //            //v.Checked = true;

                //            row.Tag = e;

                //            //lv.Items.Add(v);
                //        }
                //        dg.ResumeLayout();
                //        return;
                //    }

                //if (i == 3 || i == 0)
                {
                    if (hc != null)
                    {
                    }

                    //filename = d.FileName;

                    foreach (/*IntErrors e in DD*/ Diagnostic hs in hc)
                    {
                        //if (filename != "")
                        //    if (e.file != filename)
                        //        continue;

                        Diagnostic dc = hs;// hc[hs];

                        filename = dc.Location.SourceTree.FilePath;

                        AvalonDocument d = scr.FileOpened(filename, false);

                        int hash = dc.GetMessage().GetHashCode();

                        if (hcd.ContainsKey(hash))
                        {
                            continue;
                        }

                        int    line = 0;
                        string file = "";
                        if (dc.Location != Microsoft.CodeAnalysis.Location.None)
                        {
                            if (dc.Location.SourceTree != null)
                            {
                                file = dc.Location.SourceTree.FilePath;// syntaxTree.FilePath;
                                FileLinePositionSpan c = dc.Location.GetLineSpan();
                                line = c.StartLinePosition.Line;
                            }
                        }

                        int             rowId = dg.Rows.Add();
                        DataGridViewRow row   = dg.Rows[rowId];
                        row.InheritedStyle.BackColor = Color.FromKnownColor(KnownColor.Control);
                        //dg.Rows.Remove(row);
                        //dg.Rows.Insert(0, row);
                        row.Cells[0].Value = dc.Descriptor.Category;
                        if (dc.Severity.ToString() == "Error")
                        {
                            row.Cells[1].Value = new Bitmap(ve_resource.Breakall_6323, 15, 15);
                            Ep.Add(row);
                        }
                        else if (dc.Severity.ToString() == "Warning")
                        {
                            row.Cells[1].Value = new Bitmap(ve_resource.StatusWarning_16x, 15, 15);
                            Wp.Add(row);
                        }
                        else
                        {
                            row.Cells[1].Value = new Bitmap(ve_resource.StatusHelp_256x, 15, 15);
                            Mp.Add(row);
                        }

                        row.Cells[2].Value = dc.Descriptor.Id;
                        row.Cells[3].Value = dc.GetMessage();

                        if (dc.Location != Microsoft.CodeAnalysis.Location.None)
                        {
                            if (vp != null)
                            {
                                row.Cells[4].Value = Path.GetFileNameWithoutExtension(vp.FileName);
                            }
                            else if (dc.Location != Microsoft.CodeAnalysis.Location.None)
                            {
                                if (dc.Location.SourceTree != null)
                                {
                                    row.Cells[4].Value = Path.GetFileNameWithoutExtension(dc.Location.SourceTree.FilePath);
                                }
                            }
                        }
                        row.Cells[5].Value = Path.GetFileName(file);
                        if (line > 0)
                        {
                            row.Cells[6].Value = d.GetLineExtended(line) + 1;
                        }
                        row.Cells[7].Value = "project";

                        //row.Cells[0].Value = "";
                        //row.Cells[1].Value = ve_resource.Errors;
                        //row.Cells[2].Value = "e.Code";
                        //row.Cells[3].Value = e.e.Message;
                        //row.Cells[4].Value = Path.GetFileNameWithoutExtension(e.vp.FileName);
                        //row.Cells[5].Value = Path.GetFileName(e.file);
                        //row.Cells[6].Value = e.e.Region.BeginLine.ToString();
                        //row.Cells[7].Value = "project";

                        //ListViewItem v = new ListViewItem();
                        //v.Text = "";
                        //v.SubItems.Add("");
                        //v.SubItems.Add("e.Code");
                        //v.SubItems.Add(e.e.Message);
                        //v.SubItems.Add(Path.GetFileNameWithoutExtension(e.vp.FileName));
                        //v.SubItems.Add(Path.GetFileName(e.c.FileName));
                        //v.SubItems.Add(e.e.Region.BeginLine.ToString());
                        //v.SubItems.Add("project");

                        //v.Checked = true;

                        row.Tag = dc;

                        dg.Rows.Remove(row);
                        dg.Rows.Insert(0, row);

                        hcd.Add(hash, row);

                        //lv.Items.Add(v);
                    }

                    dg.ResumeLayout();

                    //ef.scr.FocusActiveDocument();
                    return;
                }

                //ArrayList F = ef.scr.GetOpenFiles();

                /*
                 * foreach (IntErrors e in DD)
                 * {
                 *  //ListViewItem v = new ListViewItem();
                 *  //v.Text = "";
                 *  //v.SubItems.Add("");
                 *  //v.SubItems.Add("e.Code");
                 *  //v.SubItems.Add(e.e.Message);
                 *  //v.SubItems.Add(Path.GetFileNameWithoutExtension(e.c.FileName));
                 *  //v.SubItems.Add(Path.GetFileName(e.c.FileName));
                 *  //v.SubItems.Add(e.e.Region.BeginLine.ToString());
                 *  //v.SubItems.Add("project");
                 *
                 *  //v.Checked = true;
                 *
                 *  int rowId = dg.Rows.Add();
                 *  DataGridViewRow row = dg.Rows[rowId];
                 *  row.InheritedStyle.BackColor = Color.FromKnownColor(KnownColor.Control);
                 *
                 *  row.Cells[0].Value = "";
                 *  row.Cells[1].Value = ve_resource.Errors;
                 *  row.Cells[2].Value = "e.Code";
                 *  row.Cells[3].Value = e.e.Message;
                 *  row.Cells[4].Value = Path.GetFileNameWithoutExtension(e.vp.FileName);
                 *  row.Cells[5].Value = Path.GetFileName(e.file);
                 *  row.Cells[6].Value = e.e.Region.BeginLine.ToString();
                 *  row.Cells[7].Value = "project";
                 *
                 *  //string message = e.e.Message;
                 *
                 *  //if (message.StartsWith("UnknownIdentifier") == true)
                 *  //{
                 *  //    // MessageBox.Show("Unknown identifier");
                 *
                 *  //    string[] cc = e.e.Message.Split(" ".ToCharArray());
                 *
                 *  //    Document d = ef.scr.FileOpened(e.c.FileName);
                 *
                 *  //    //foreach (Row r in d.Editor.Document)
                 *  //    //    foreach (Word w in r)
                 *  //    //        w.HasError = false;
                 *
                 *  //    if (d != null)
                 *  //    {
                 *  //        // MessageBox.Show("File has been found");
                 *
                 *  //        if (e.e.Region.BeginLine < 0)
                 *  //            continue;
                 *
                 *  //        d.SuspendLayout();
                 *
                 *  //        Row r = d.Editor.Document[e.e.Region.BeginLine];
                 *
                 *  //        foreach (Word w in r)
                 *  //        {
                 *  //            string[] bb = w.Text.Split(";".ToCharArray());
                 *
                 *  //            foreach (string dd in bb)
                 *
                 *  //                if (dd == cc[1])
                 *  //                {
                 *  //                    // MessageBox.Show("Identifier found");
                 *
                 *  //                    w.HasError = true;
                 *
                 *  //                    //d.Refresh();
                 *  //                }
                 *  //        }
                 *
                 *  //        d.ResumeLayout();
                 *  //    }
                 *
                 *  //}
                 *
                 *  row.Tag = e;
                 * }
                 *
                 * ef.scr.LoadErrors(DD);
                 *
                 * dg.ResumeLayout();
                 */
            }
        }
示例#4
0
        // Update is called once per frame
        void Update()
        {
            // if there are no more waypoint targets to visit destroy the game object
            if (target == null)
            {
                Destroy(gameObject);
                return;
            }

            float distanceToWaypoint = Vector3.Distance(transform.position, target.transform.position);

            // if the queue of waypoints is empty destroy the game object
            if (Waypoints.Count == 0 && distanceToWaypoint < 0.2f)
            {
                target = null;
                return;
            }

            waitForTrafficLight = false;

            // only check for potential red light within a small range of that traffic light stop point
            if (distanceToWaypoint < 0.2f)
            {
                Wp wayPoint = Utilities.Parse <Wp>(target.name);

                // check if an agent is waiting for a traffic light specificly for this type
                if (this.TypeSpecificWaitPoints.ContainsKey(wayPoint))
                {
                    string     trafficLight = this.TypeSpecificWaitPoints[wayPoint];
                    LightColor c            = Utilities.GetTrafficLightColor(trafficLight);
                    // If light is orange and within less than 0.1f of the way point, make the target stop.
                    // if object approaches target that is linked to a red / orange traffic light
                    if (c == LightColor.Red || c == LightColor.Orange && distanceToWaypoint < 0.1f)
                    {
                        waitForTrafficLight = true;
                        // Don't queue the A series, these have a different trigger point.
                        if (trafficLight[0] != 'A')
                        {
                            TrafficWaitStore.Instance.Queue(trafficLight);
                        }
                    }
                }

                // also check if an agent is waiting for a train crossing
                if (Dictionaries.TrainWaitpoints.ContainsKey(wayPoint))
                {
                    string     trafficLight = Dictionaries.TrainWaitpoints[wayPoint];
                    LightColor c            = Utilities.GetTrafficLightColor(trafficLight);
                    // If light is orange and within less than 0.1f of the way point, make the target stop.
                    if (c == LightColor.Red || c == LightColor.Orange && distanceToWaypoint < 0.1f)
                    {
                        waitForTrafficLight = true;
                    }
                }
            }

            // prevend unintended waits by measuring the time how long an agent is idle
            // if the agent is idle for too long without a legitimate reason, let the agent explode to prevend a deadlock
            if (IsInIdleAnimation)
            {
                explodeTimer += Time.deltaTime;
                if (explodeTimer > 3)
                {
                    RaiseToHeaven();
                }
                // check every second if the agent is waiting behind a traffic light (legitimate wait, no need to destroy)
                else if (explodeTimer > 1)
                {
                    Wp wayPoint = Utilities.Parse <Wp>(target.name);
                    if (this.TypeSpecificWaitPoints.ContainsKey(wayPoint) || Dictionaries.TrainWaitpoints.ContainsKey(wayPoint))
                    {
                        //Debug.Log("explosion cancelled because legitimate wait");
                        explodeTimer = 0;
                        IsColliding  = false;
                        goto Spoker;
                    }
                }
            }
            //cancel explosion as the agent can move again within the 3 seconds
            else if (explodeTimer > 0 && !IsInIdleAnimation)
            {
                explodeTimer = 0;
            }

            if (waitForTrafficLight || IsColliding)
            {
                if (!IsInIdleAnimation)
                {
                    AnimateIdle();
                    IsInIdleAnimation = true;
                }
                return;
            }

            // move logic
Spoker:

            if (IsInIdleAnimation)
            {
                AnimateMoving();
                IsInIdleAnimation = false;
            }

            DoRotation();

            transform.position = Vector3.MoveTowards(transform.position, target.transform.position, MovingSpeed * Time.deltaTime);

            if (distanceToWaypoint < 0.2f && Waypoints.Count > 0)
            {
                target = Waypoints.Dequeue();
            }
        }