Example #1
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");
                }
            }
        }
Example #2
0
        /// <summary>
        /// Creates a new traffic participant based on the given type on a random location with a random route.
        /// </summary>
        /// <param name="type"></param>
        private void RouteMultiplicator(Agent type)
        {
            Wp waypoint;

            switch (type)
            {
            case Agent.Car:
                waypoint = carSpawnPoints.Random();
                break;

            case Agent.Bicycle:
                waypoint = cycleSpawnPoints.Random();
                break;

            case Agent.Fanfare_horn:
            case Agent.Fanfare_vert:
            case Agent.Fanfare_trombone:
            case Agent.Fanfare_hort:
            case Agent.Fanfare_ping:
            case Agent.Pedestrian:
                waypoint = pedestrianSpawnPoints.Random();
                break;

            case Agent.Bus:
                waypoint = Wp.D1;
                break;

            // experimental purposes
            case Agent.Test:
                waypoint = test.Random();
                break;

            default:
                // Compiler edge case. Shouldn't ever happen.
                return;
            }

            List <Wp> route = new List <Wp>();
            Dictionary <Wp, string> waits = new Dictionary <Wp, string>();

            float speed = 0;

            switch (type)
            {
            case Agent.Car:
                route = Waypoint_controller.RouteBuilder(Waypoint_controller.carRoutes, waypoint);
                if (Random.Range(0, 15) == 7)
                {
                    traffic_object = Instantiate(bus);
                }
                else
                {
                    traffic_object = Instantiate(f150);
                }
                waits = Dictionaries.CarWaitpoints;
                speed = 7f;
                break;

            case Agent.Bicycle:
                route          = Waypoint_controller.RouteBuilder(Waypoint_controller.cycleRoutes, waypoint);
                traffic_object = Instantiate(bicycle);
                waits          = Dictionaries.CycleWaitpoints;
                speed          = 3f;
                break;

            case Agent.Pedestrian:
                route          = Waypoint_controller.RouteBuilder(Waypoint_controller.pedestrianRoutes, waypoint);
                traffic_object = Instantiate(pedestrian);
                waits          = Dictionaries.PedestrianWaitpoints;
                speed          = 1f;
                break;

            case Agent.Fanfare_horn:
                route          = fanfareRoute;
                traffic_object = Instantiate(horn);
                waits          = Dictionaries.PedestrianWaitpoints;
                speed          = 1f;
                break;

            case Agent.Fanfare_vert:
                route          = fanfareRoute;
                traffic_object = Instantiate(vertical_drum);
                waits          = Dictionaries.PedestrianWaitpoints;
                speed          = 1f;
                break;

            case Agent.Fanfare_trombone:
                route          = fanfareRoute;
                traffic_object = Instantiate(trombone);
                waits          = Dictionaries.PedestrianWaitpoints;
                speed          = 1f;
                break;

            case Agent.Fanfare_hort:
                route          = fanfareRoute;
                traffic_object = Instantiate(horizontal_drum);
                waits          = Dictionaries.PedestrianWaitpoints;
                speed          = 1f;
                break;

            case Agent.Fanfare_ping:
                route          = fanfareRoute;
                traffic_object = Instantiate(pingping);
                waits          = Dictionaries.PedestrianWaitpoints;
                speed          = 1f;
                break;

            case Agent.Bus:
                route          = Waypoint_controller.busRoutes[0];
                traffic_object = Instantiate(bus);
                waits          = Dictionaries.BusWaitpoints;
                speed          = 6f;
                break;

            // experimental purposes
            case Agent.Test:
                route          = Waypoint_controller.RouteBuilder(Waypoint_controller.pedestrianRoutes, waypoint);
                traffic_object = Instantiate(pedestrian);
                waits          = Dictionaries.PedestrianWaitpoints;
                speed          = 6f;
                //Debug.Log("traffic object instantiated");
                break;
            }

            traffic_object.SetActive(true);

            Moving trafficUser = traffic_object.AddComponent <Moving>();

            trafficUser.MovingSpeed            = speed;
            trafficUser.TypeSpecificWaitPoints = waits;

            foreach (Wp wp in route)
            {
                trafficUser.Waypoints.Enqueue(GameObject.Find(wp.ToString()));
            }
        }