Exemplo n.º 1
0
        /// <summary>
        /// Scan for upcoming stop signs, stop there, and then wait for the intersection to clear before proceeding.
        /// </summary>
        public void HandleStopSign()
        {
            foreach (CityPath p in PathsInView())
            {
                CityNode node = p.e;
                if (node is StopSignNode)
                {
                    StopSignNode n    = node as StopSignNode;
                    double       dist = DistanceToNodeOnPath(n);

                    if (!stopped)
                    {
                        if (dist <= Util.StopDistance(speed, DEACCELERATION) + 25)
                        {
                            limits.RemoveAll(l => l.name == "stop sign");
                            limits.Add(new SpeedLimiter(0, "stop sign"));
                        }
                        if (dist < 26)
                        {
                            if (speed <= 0.1)
                            {
                                stopped = true;
                                n.intersection.VehicleApproach(this);
                            }
                        }
                    }
                    else
                    {
                        if (n.intersection.current == this)
                        {
                            limits.RemoveAll(l => l.name == "stop sign");
                        }
                        else
                        {
                            limits.RemoveAll(l => l.name == "stop sign");
                            limits.Add(new SpeedLimiter(0, "stop sign"));
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public override void Build(City c)
        {
            StopSignIntersection i = new StopSignIntersection();

            CityNode nw1 = wTop = new StopSignNode(x - 40, y - 80, i, "nw1");
            CityNode nl1 = new CityNode(x - 40, y, "nl1");
            CityNode ne1 = eTop = new IntersectionExitNode(x + 40, y - 80, i, "ne1");

            nw1.Connect(nl1, CityPathType.privates);

            CityNode nw2 = wLeft = new StopSignNode(x - 80, y + 40, i, "nw2");
            CityNode nl2 = new CityNode(x, y + 40, "nl2");
            CityNode ne2 = eLeft = new IntersectionExitNode(x - 80, y - 40, i, "ne2");

            nw2.Connect(nl2, CityPathType.privates);

            CityNode nw3 = wBottom = new StopSignNode(x + 40, y + 80, i, "nw3");
            CityNode nl3 = new CityNode(x + 40, y, "nl3");
            CityNode ne3 = eBottom = new IntersectionExitNode(x - 40, y + 80, i, "ne3");

            nw3.Connect(nl3, CityPathType.privates);

            CityNode nw4 = wRight = new StopSignNode(x + 80, y - 40, i, "nw4");
            CityNode nl4 = new CityNode(x, y - 40, "nl4");
            CityNode ne4 = eRight = new IntersectionExitNode(x + 80, y + 40, i, "ne4");

            nw4.Connect(nl4, CityPathType.privates);

            nl1.Connect(ne3, CityPathType.privates);
            nl2.Connect(ne4, CityPathType.privates);
            nl3.Connect(ne1, CityPathType.privates);
            nl4.Connect(ne2, CityPathType.privates);

            nl1.Connect(nl2, CityPathType.privates, 40);
            nl2.Connect(nl3, CityPathType.privates, 40);
            nl3.Connect(nl4, CityPathType.privates, 40);
            nl4.Connect(nl1, CityPathType.privates, 40);

            nw1.Connect(ne2, CityPathType.privates, 40);
            nw2.Connect(ne3, CityPathType.privates, 40);
            nw3.Connect(ne4, CityPathType.privates, 40);
            nw4.Connect(ne1, CityPathType.privates, 40);

            pTopLeft     = new CityNode(x - 100, y - 100);
            pTopRight    = new CityNode(x + 100, y - 100);
            pBottomLeft  = new CityNode(x - 100, y + 100);
            pBottomRight = new CityNode(x + 100, y + 100);

            pTopLeft.Connect(pTopRight, CityPathType.pedestrians);
            pTopLeft.Connect(pBottomLeft, CityPathType.pedestrians);

            pTopRight.Connect(pTopLeft, CityPathType.pedestrians);
            pTopRight.Connect(pBottomRight, CityPathType.pedestrians);

            pBottomLeft.Connect(pBottomRight, CityPathType.pedestrians);
            pBottomLeft.Connect(pTopLeft, CityPathType.pedestrians);

            pBottomRight.Connect(pBottomLeft, CityPathType.pedestrians);
            pBottomRight.Connect(pTopRight, CityPathType.pedestrians);

            c.nodes.Add(pTopLeft);
            c.nodes.Add(pTopRight);
            c.nodes.Add(pBottomLeft);
            c.nodes.Add(pBottomRight);

            c.nodes.Add(nw1);
            c.nodes.Add(nl1);
            c.nodes.Add(ne1);

            c.nodes.Add(nw2);
            c.nodes.Add(nl2);
            c.nodes.Add(ne2);

            c.nodes.Add(nw3);
            c.nodes.Add(nl3);
            c.nodes.Add(ne3);

            c.nodes.Add(nw4);
            c.nodes.Add(nl4);
            c.nodes.Add(ne4);
        }