/// <summary>
        ///     Adds a new waggon.
        /// </summary>
        public void AddWaggon()
        {
            var waggon = new Waggon();

            this._waggonsView.AddNewItem(waggon);
            this._waggonsView.CommitNew();
            this._waggonsView.MoveCurrentTo(waggon);
        }
Пример #2
0
    public virtual void OnHealthZero()
    {
        PreviousWaggon.NextWaggon = null;
        PreviousWaggon            = null;

        Waggon currentWaggon = this;

        while (currentWaggon != null)
        {
            currentWaggon.OnDisconnectEvent(true);
            currentWaggon = currentWaggon.NextWaggon;
        }
    }
Пример #3
0
    public void AddWaggon(Waggon waggon)
    {
        if (waggon == null)
        {
            Debug.LogError("Every Waggon Prefab needs to contain a Waggon Script! Waggon could not be added!");
            return;
        }


        List <Waggon> waggons = Waggons;

        if (waggon.NextLevelWaggonPrefab != null)
        {
            foreach (Waggon w in waggons)
            {
                if (w.NextLevelWaggonPrefab == waggon.NextLevelWaggonPrefab)
                {
                    // COMBINE THEM
                    Waggon prevWaggon = w.PreviousWaggon;

                    Waggon combinedWaggon = Instantiate(waggon.NextLevelWaggonPrefab.gameObject).GetComponent <Waggon>();
                    prevWaggon.NextWaggon         = combinedWaggon;
                    combinedWaggon.PreviousWaggon = prevWaggon;
                    combinedWaggon.NextWaggon     = w.NextWaggon;

                    if (w.NextWaggon != null)
                    {
                        w.NextWaggon.PreviousWaggon = combinedWaggon;
                    }

                    Destroy(w.gameObject);
                    Destroy(waggon.gameObject);

                    combinedWaggon.OnConnectEvent();
                    return;
                }
            }
        }

        Waggon lastWaggon = waggons[waggons.Count - 1];

        waggon.PreviousWaggon = lastWaggon;
        lastWaggon.NextWaggon = waggon;

        waggon.OnConnectEvent();
    }
Пример #4
0
 private void Awake()
 {
     _waggon        = GetComponent <Waggon>();
     _currentHealth = _maximumHealth;
 }
        private static IEnumerable <KeyValuePair <int, int> > GetWaggonsToSpeedValues(Train train,
                                                                                      int numLocomotives,
                                                                                      Waggon waggon,
                                                                                      int cargoFactor,
                                                                                      int slopePercentage,
                                                                                      Hilliness selectedHilliness,
                                                                                      int tilesBetweenSlopes,
                                                                                      bool useStaticFriction)
        {
            // Create waggon numbers from 1 to 19.
            IEnumerable <int> waggonNumbers = Enumerable.Range(1, 19).ToList();

            // Compute waggon weight based on cargo factor
            int waggonMass = waggon.MassEmpty + (waggon.MassFull - waggon.MassEmpty) * cargoFactor;

            // Compute total tonnages.
            IEnumerable <double> tonnages =
                waggonNumbers.Select(numWaggons => (double)(numWaggons * waggonMass) + (train.Mass * numLocomotives));

            // Compute rolling resistance efforts
            IEnumerable <double> tractiveEfforts =
                tonnages.Select(tonnage => (tonnage * (useStaticFriction ? 27.0 : 17.0)) / 1000.0);

            // Compute slope resistance efforts
            IEnumerable <double> slopeTractiveEfforts = waggonNumbers.Select(
                numWaggons =>
            {
                double numWaggonsOnSlope = 0;

                switch (selectedHilliness)
                {
                case Hilliness.OneSlope:
                    {
                        numWaggonsOnSlope = Math.Min(numWaggons, 1.0 / waggon.Length);
                    }
                    break;

                case Hilliness.MultipleSlopes:
                    {
                        double trainTileLength  = numWaggons * waggon.Length;
                        double tilesWithWaggons = Math.Ceiling(trainTileLength / (tilesBetweenSlopes + 1));

                        numWaggonsOnSlope = Math.Min(numWaggons, tilesWithWaggons / waggon.Length);
                    }
                    break;
                }

                // 1/10 is Short for 9.81 / 100. It just works and is very close to the correct
                // trigonometry based values for small slope percentages.
                double teSlopeResistance = (numWaggonsOnSlope * waggonMass * slopePercentage) / 10.0;

                return(teSlopeResistance);
            });

            // Compute total tractive efforts
            IEnumerable <double> totalTractiveEfforts = tractiveEfforts.Zip(
                slopeTractiveEfforts,
                (resistanceTe, slopeTe) => resistanceTe + slopeTe);

            // Compute the speed for each tonnage.
            IEnumerable <double> speeds =
                totalTractiveEfforts.Select(
                    tractiveEffort => (tractiveEffort > (train.MaxTractiveEffort * numLocomotives)) ? 0 : ((train.Power * numLocomotives) / tractiveEffort));

            // Convert to km/h.
            speeds = speeds.Select(speed => (speed * 3.6));

            // Cap at max speed.
            int maxSpeed = Math.Min(train.MaxSpeed, waggon.MaxSpeed);

            speeds = speeds.Select(speed => Math.Min(maxSpeed, speed));

            // Zip them together.
            IEnumerable <KeyValuePair <int, int> > values = waggonNumbers.Zip(
                speeds,
                (numWaggons, speed) => new KeyValuePair <int, int>(numWaggons, (int)speed));

            return(values);
        }
        private static IEnumerable <KeyValuePair <int, int> > GetSpeedToWaggonsValues(Train train,
                                                                                      int numLocomotives,
                                                                                      Waggon waggon,
                                                                                      int cargoFactor,
                                                                                      int slopePercentage,
                                                                                      Hilliness selectedHilliness,
                                                                                      int tilesBetweenSlopes,
                                                                                      bool useStaticFriction)
        {
            // Create speed values from 0 to 200 km/h in 5 km/h steps.
            IEnumerable <int> speedValues = Enumerable.Range(0, 42).Select(value => value * 5).ToList();

            // Compute waggon weight based on cargo factor
            int waggonMass = waggon.MassEmpty + (waggon.MassFull - waggon.MassEmpty) * cargoFactor;

            // Calculate the tractive effort at each speed step and cap at TE max.
            IEnumerable <int> numWaggonsPerSpeed = speedValues.Select(
                speed =>
            {
                var tractiveEffort = (int)((train.Power * numLocomotives) / (speed / 3.6));
                tractiveEffort     = ((speed > train.MaxSpeed) || (speed > waggon.MaxSpeed)) ? 0 : tractiveEffort;
                tractiveEffort     = Math.Min((train.MaxTractiveEffort * numLocomotives), tractiveEffort);
                tractiveEffort     = (speed == 0 ? (train.MaxTractiveEffort * numLocomotives) : tractiveEffort);

                double tonnage = (tractiveEffort * 1000.0) / (useStaticFriction ? 27.0 : 17.0);
                tonnage        = Math.Max(0.0, tonnage - (train.Mass * numLocomotives));

                var maxNumWaggons = (int)(tonnage / waggonMass);

                IEnumerable <int> numberOfWaggons = Enumerable.Range(0, maxNumWaggons + 1);

                IEnumerable <KeyValuePair <int, double> > numWaggonsToTeValue = numberOfWaggons.Select(
                    numWaggons =>
                {
                    double numWaggonsOnSlope = 0;

                    switch (selectedHilliness)
                    {
                    case Hilliness.OneSlope:
                        {
                            numWaggonsOnSlope = Math.Min(numWaggons, 1.0 / waggon.Length);
                        }
                        break;

                    case Hilliness.MultipleSlopes:
                        {
                            double trainTileLength  = numWaggons * waggon.Length;
                            double tilesWithWaggons = Math.Ceiling(trainTileLength / (tilesBetweenSlopes + 1));

                            numWaggonsOnSlope = Math.Min(numWaggons, tilesWithWaggons / waggon.Length);
                        }
                        break;
                    }

                    // 1/10 is Short for 9.81 / 100. It just works and is very close to the correct
                    // trigonometry based values for small slope percentages.
                    double teSlopeResistance = (numWaggonsOnSlope * waggonMass * slopePercentage) / 10.0;

                    // Compute rolling resistance efforts
                    double trainTonnage = (numWaggons * waggonMass + (train.Mass * numLocomotives));

                    double teRollingRestistance = (trainTonnage * (useStaticFriction ? 27.0 : 17.0)) / 1000.0;

                    double teTotal = (teSlopeResistance + teRollingRestistance);

                    return(new KeyValuePair <int, double>(numWaggons, teTotal));
                });

                int numPossibleWaggons = numWaggonsToTeValue.LastOrDefault(pair => pair.Value <= tractiveEffort).Key;

                return(numPossibleWaggons);
            });

            return(speedValues.Zip(
                       numWaggonsPerSpeed,
                       (speed, numWaggons) => new KeyValuePair <int, int>(speed, numWaggons)));
        }
        /// <summary>
        ///     Adds a new waggon.
        /// </summary>
        public void AddWaggon()
        {
            var waggon = new Waggon();

            this._waggonsView.AddNewItem(waggon);
            this._waggonsView.CommitNew();
            this._waggonsView.MoveCurrentTo(waggon);
        }
Пример #8
0
 // Start is called before the first frame update
 void Start()
 {
     _waggon = GetComponent <Waggon>();
 }
Пример #9
0
 protected virtual void OnCollectableWaggonHit(Waggon waggon)
 {
 }
Пример #10
0
 protected override void OnCollectableWaggonHit(Waggon waggon)
 {
     _locomotive.AddWaggon(waggon);
 }
        private static IEnumerable<KeyValuePair<int, int>> GetWaggonsToSpeedValues(Train train,
            int numLocomotives,
                                                                                   Waggon waggon,
                                                                                   int cargoFactor,
                                                                                   int slopePercentage,
                                                                                   Hilliness selectedHilliness,
                                                                                   int tilesBetweenSlopes,
                                                                                   bool useStaticFriction)
        {
            // Create waggon numbers from 1 to 19.
            IEnumerable<int> waggonNumbers = Enumerable.Range(1, 19).ToList();

            // Compute waggon weight based on cargo factor
            int waggonMass = waggon.MassEmpty + (waggon.MassFull - waggon.MassEmpty) * cargoFactor;

            // Compute total tonnages.
            IEnumerable<double> tonnages =
                waggonNumbers.Select(numWaggons => (double)(numWaggons * waggonMass) + (train.Mass * numLocomotives));

            // Compute rolling resistance efforts
            IEnumerable<double> tractiveEfforts =
                tonnages.Select(tonnage => (tonnage * (useStaticFriction ? 27.0 : 17.0)) / 1000.0);

            // Compute slope resistance efforts
            IEnumerable<double> slopeTractiveEfforts = waggonNumbers.Select(
                numWaggons =>
                {
                    double numWaggonsOnSlope = 0;

                    switch (selectedHilliness)
                    {
                        case Hilliness.OneSlope:
                        {
                            numWaggonsOnSlope = Math.Min(numWaggons, 1.0 / waggon.Length);
                        }
                            break;

                        case Hilliness.MultipleSlopes:
                        {
                            double trainTileLength = numWaggons * waggon.Length;
                            double tilesWithWaggons = Math.Ceiling(trainTileLength / (tilesBetweenSlopes + 1));

                            numWaggonsOnSlope = Math.Min(numWaggons, tilesWithWaggons / waggon.Length);
                        }
                            break;
                    }

                    // 1/10 is Short for 9.81 / 100. It just works and is very close to the correct
                    // trigonometry based values for small slope percentages.
                    double teSlopeResistance = (numWaggonsOnSlope * waggonMass * slopePercentage) / 10.0;

                    return teSlopeResistance;
                });

            // Compute total tractive efforts
            IEnumerable<double> totalTractiveEfforts = tractiveEfforts.Zip(
                slopeTractiveEfforts,
                (resistanceTe, slopeTe) => resistanceTe + slopeTe);

            // Compute the speed for each tonnage.
            IEnumerable<double> speeds =
                totalTractiveEfforts.Select(
                    tractiveEffort => (tractiveEffort > (train.MaxTractiveEffort * numLocomotives)) ? 0 : ((train.Power * numLocomotives) / tractiveEffort));

            // Convert to km/h.
            speeds = speeds.Select(speed => (speed * 3.6));

            // Cap at max speed.
            int maxSpeed = Math.Min(train.MaxSpeed, waggon.MaxSpeed);

            speeds = speeds.Select(speed => Math.Min(maxSpeed, speed));

            // Zip them together.
            IEnumerable<KeyValuePair<int, int>> values = waggonNumbers.Zip(
                speeds,
                (numWaggons, speed) => new KeyValuePair<int, int>(numWaggons, (int)speed));

            return values;
        }
        private static IEnumerable<KeyValuePair<int, int>> GetSpeedToWaggonsValues(Train train,
            int numLocomotives,
                                                                                   Waggon waggon,
                                                                                   int cargoFactor,
                                                                                   int slopePercentage,
                                                                                   Hilliness selectedHilliness,
                                                                                   int tilesBetweenSlopes,
                                                                                   bool useStaticFriction)
        {
            // Create speed values from 0 to 200 km/h in 5 km/h steps.
            IEnumerable<int> speedValues = Enumerable.Range(0, 42).Select(value => value * 5).ToList();

            // Compute waggon weight based on cargo factor
            int waggonMass = waggon.MassEmpty + (waggon.MassFull - waggon.MassEmpty) * cargoFactor;

            // Calculate the tractive effort at each speed step and cap at TE max.
            IEnumerable<int> numWaggonsPerSpeed = speedValues.Select(
                speed =>
                {
                    var tractiveEffort = (int)((train.Power * numLocomotives) / (speed / 3.6));
                    tractiveEffort = ((speed > train.MaxSpeed) || (speed > waggon.MaxSpeed)) ? 0 : tractiveEffort;
                    tractiveEffort = Math.Min((train.MaxTractiveEffort * numLocomotives), tractiveEffort);
                    tractiveEffort = (speed == 0 ? (train.MaxTractiveEffort * numLocomotives) : tractiveEffort);

                    double tonnage = (tractiveEffort * 1000.0) / (useStaticFriction ? 27.0 : 17.0);
                    tonnage = Math.Max(0.0, tonnage - (train.Mass * numLocomotives));

                    var maxNumWaggons = (int)(tonnage / waggonMass);

                    IEnumerable<int> numberOfWaggons = Enumerable.Range(0, maxNumWaggons + 1);

                    IEnumerable<KeyValuePair<int, double>> numWaggonsToTeValue = numberOfWaggons.Select(
                        numWaggons =>
                        {
                            double numWaggonsOnSlope = 0;

                            switch (selectedHilliness)
                            {
                                case Hilliness.OneSlope:
                                {
                                    numWaggonsOnSlope = Math.Min(numWaggons, 1.0 / waggon.Length);
                                }
                                    break;

                                case Hilliness.MultipleSlopes:
                                {
                                    double trainTileLength = numWaggons * waggon.Length;
                                    double tilesWithWaggons = Math.Ceiling(trainTileLength / (tilesBetweenSlopes + 1));

                                    numWaggonsOnSlope = Math.Min(numWaggons, tilesWithWaggons / waggon.Length);
                                }
                                    break;
                            }

                            // 1/10 is Short for 9.81 / 100. It just works and is very close to the correct
                            // trigonometry based values for small slope percentages.
                            double teSlopeResistance = (numWaggonsOnSlope * waggonMass * slopePercentage) / 10.0;

                            // Compute rolling resistance efforts
                            double trainTonnage = (numWaggons * waggonMass + (train.Mass * numLocomotives));

                            double teRollingRestistance = (trainTonnage * (useStaticFriction ? 27.0 : 17.0)) / 1000.0;

                            double teTotal = (teSlopeResistance + teRollingRestistance);

                            return new KeyValuePair<int, double>(numWaggons, teTotal);
                        });

                    int numPossibleWaggons = numWaggonsToTeValue.LastOrDefault(pair => pair.Value <= tractiveEffort).Key;

                    return numPossibleWaggons;
                });

            return speedValues.Zip(
                numWaggonsPerSpeed,
                (speed, numWaggons) => new KeyValuePair<int, int>(speed, numWaggons));
        }