/// <summary>
        /// To be called when this vehicle shall be removed from the current NodeConnection
        /// </summary>
        /// <param name="logConnectionStatistics">Flag, whether NodeConnection statistics shall be logged</param>
        /// <param name="nextConnection">NodeConnection where to respawn vehicle - set to null if vehicle shall not respawn</param>
        /// <param name="nextArcPosition">arc position on nextConnection where vehicle shall respawn</param>
        private void RemoveFromCurrentNodeConnection(bool logConnectionStatistics, NodeConnection nextConnection, double nextArcPosition)
        {
            _state.UnsetLineChangeVehicleInteraction();

            if (logConnectionStatistics)
                {
                OnVehicleLeftNodeConnection(new VehicleLeftNodeConnectionEventArgs(new Interval<double>(statistics.arcPositionOfStartOnNodeConnection, currentPosition), new Interval<double>(statistics.startTimeOnNodeConnection, GlobalTime.Instance.currentTime)));
                }
            currentNodeConnection.RemoveVehicle(this);

            if (nextConnection != null)
                {
                double pos = Math.Min(nextConnection.lineSegment.length, nextArcPosition);
                if (pos < nextArcPosition)
                    {
                    // FIXME: this sometimes happens, even if it should not!
                    }

                lastLineChangeCheck.Right -= currentNodeConnection.lineSegment.length;

                // update statistics
                _statistics.totalMilage += currentPosition - statistics.arcPositionOfStartOnNodeConnection;
                _statistics.numNodeConnections++;
                _statistics.arcPositionOfStartOnNodeConnection = pos;
                _statistics.startTimeOnNodeConnection = GlobalTime.Instance.currentTime;

                // set new state
                _state = new State(nextConnection, pos);

                // add vehicle to new node connection
                nextConnection.AddVehicleAt(this, pos);
                }
            else
                {
                // evoke VehicleDied event
                OnVehicleDied(new VehicleDiedEventArgs(_statistics, targetNodes.Contains(currentNodeConnection.endNode)));
                }
        }
Example #2
0
        /// <summary>
        /// Lässt ein Auto am startNode losfahren
        /// </summary>
        /// <returns>true, if Vehicle was successfully created - otherwise false</returns>
        private bool CreateVehicle()
        {
            IVehicle.Physics p = new IVehicle.Physics(m_wunschgeschwindigkeit, m_wunschgeschwindigkeit, 0);

            IVehicle v = null;
            switch (m_vehicleType)
                {
                case IVehicle.VehicleTypes.CAR:
                    if (GlobalRandom.Instance.Next(100) < truckRatio)
                        {
                        v = new Truck(p);
                        }
                    else
                        {
                        v = new Car(p);
                        }
                    break;
                case IVehicle.VehicleTypes.TRAM:
                    v = new Tram(p);
                    break;
                case IVehicle.VehicleTypes.BUS:
                    v = new Bus(p);
                    break;
                }

            // Neue Linie zum Weiterfahren bestimmen
            LineNode start = startNodes[GlobalRandom.Instance.Next(startNodes.Count)];

            if (start.nextConnections.Count > 0)
                {
                int foo = GlobalRandom.Instance.Next(start.nextConnections.Count);

                IVehicle.State state = new IVehicle.State(start.nextConnections[foo], 0);
                v.state = state;
                v.targetNodes = endNodes;
                return start.nextConnections[foo].AddVehicle(v);
                }

            return false;
        }