Ejemplo n.º 1
0
        public static void Register()
        {
            Registry.Register(RegistryKeys.AllCars, new QueryDataProvider(
                                  "Speed",
                                  () => Main.settings.ShowSpeed,
                                  car => Mathf.Abs(car.GetForwardSpeed()) * 3.6f,
                                  f => $"{f:F1} km/h"));
            Registry.Register(RegistryKeys.AllCars, new QueryDataProvider(
                                  "Grade",
                                  () => Main.settings.ShowGrade,
                                  car => {
                var inclination = car.transform.localEulerAngles.x;
                inclination     = inclination > 180 ? 360f - inclination : -inclination;
                return(Mathf.Tan(inclination * Mathf.PI / 180) * 100);
            },
                                  f => f.ToString(GradeFormat)));
            Registry.Register(RegistryKeys.AllCars, new QueryDataProvider(
                                  "Brake pipe",
                                  () => Main.settings.ShowBrakePipe,
                                  car => car.brakeSystem?.brakePipePressure ?? 0f,
                                  f => $"{f:F2} bar"));
            Registry.Register(RegistryKeys.AllCars, new QueryDataProvider(
                                  "Consist mass",
                                  () => Main.settings.ShowConsistMass,
                                  car => car.trainset.cars.Sum(c => c.totalMass + CargoTypes.GetCargoMass(c.LoadedCargo, c.LoadedCargoAmount)),
                                  f => $"{f / 1000:F0} t"));

            Registry.Register(RegistryKeys.AllCars, new QueryDataProvider(
                                  "Consist length",
                                  () => Main.settings.ShowConsistMass,
                                  car => car.trainset.cars.Sum(c => c.logicCar.length),
                                  f => $"{f:F0} m"));
        }
Ejemplo n.º 2
0
        public static float GetLoadedConsistMass(List <Car> cars)
        {
            float cargoMass = CargoTypes.GetCargoUnitMass(CargoType.Passengers);
            float totalMass = cars.Sum(c => c.carOnlyMass);

            totalMass += cars.Sum(c => c.capacity * cargoMass);
            return(totalMass);
        }
        public ActionResult DeleteConfirmed(Guid id)
        {
            CargoTypes cargoTypes = db.CargoTypes.Find(id);

            db.CargoTypes.Remove(cargoTypes);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        // GET: CargoTypes/Edit/5
        public ActionResult Edit(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CargoTypes cargoTypes = db.CargoTypes.Find(id);

            if (cargoTypes == null)
            {
                return(HttpNotFound());
            }
            return(View(cargoTypes));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Метод возвращает экземпляр класса <see cref="CargoType"/> или, если в таблице нет такой записи, создаёт её
        /// </summary>
        /// <param name="type">Тип груза</param>
        /// <returns>Экземпляр класса <see cref="CargoType"/></returns>
        public CargoType GetCargoType(string type)
        {
            var cargoType = CargoTypes.FirstOrDefault(t => t.Type.Equals(type));

            if (cargoType == null)
            {
                cargoType = new CargoType {
                    Type = type
                };
                CargoTypes.Add(cargoType);
                SaveChanges();
            }

            return(cargoType);
        }
        public ActionResult Edit([Bind(Include = "CargoID,Name,Description")] CargoTypesViewModel CargoTypesViewModel)
        {
            if (ModelState.IsValid)
            {
                CargoTypes model = db.CargoTypes.Find(CargoTypesViewModel.CargoID);

                model.Name        = CargoTypesViewModel.Name;
                model.Description = CargoTypesViewModel.Description;

                model.DateModified = DateTime.Now;
                model.ModifiedBy   = Guid.Parse(User.Identity.GetUserId());

                db.Entry(model).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(CargoTypesViewModel));
        }
        public ActionResult Create([Bind(Include = "Name,Description")] CargoTypes cargoTypes)
        {
            if (ModelState.IsValid)
            {
                cargoTypes.CargoID = Guid.NewGuid();

                cargoTypes.DateCreated  = DateTime.Now;
                cargoTypes.DateModified = cargoTypes.DateCreated;

                cargoTypes.CreatedBy  = Guid.Parse(User.Identity.GetUserId());
                cargoTypes.ModifiedBy = cargoTypes.CreatedBy;

                db.CargoTypes.Add(cargoTypes);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(cargoTypes));
        }
            ) GenerateBaseCargoTrainData(
            int minCountCars,
            int maxCountCars,
            List <CargoGroup> availableCargoGroups,
            System.Random rng)
        {
            List <CarTypesPerCargoType> carTypesPerCargoTypes = new List <CarTypesPerCargoType>();
            List <TrainCarType>         allCarTypes           = new List <TrainCarType>();
            int              countCarsInTrain = rng.Next(minCountCars, maxCountCars + 1);
            CargoGroup       pickedCargoGroup = GetRandomFromEnumerable <CargoGroup>(availableCargoGroups, rng);
            List <CargoType> pickedCargoTypes = pickedCargoGroup.cargoTypes;

            pickedCargoTypes = GetMultipleRandomsFromList <CargoType>(
                pickedCargoTypes,
                Math.Min(countCarsInTrain, rng.Next(1, pickedCargoTypes.Count + 1)),
                rng
                );
            int countCargoTypes             = pickedCargoTypes.Count;
            int countCarsPerCargoType       = countCarsInTrain / countCargoTypes;
            int countCargoTypesWithExtraCar = countCarsInTrain % countCargoTypes;

            for (int i = 0; i < countCargoTypes; i++)
            {
                int countCars = i < countCargoTypesWithExtraCar ? countCarsPerCargoType + 1 : countCarsPerCargoType;
                List <CargoContainerType> cargoContainerTypesThatSupportCargoType
                    = CargoTypes.GetCarContainerTypesThatSupportCargoType(pickedCargoTypes[i]);
                List <TrainCarType> trainCarTypesThatAreSpecificContainerType
                    = CargoTypes.GetTrainCarTypesThatAreSpecificContainerType(
                          GetRandomFromEnumerable <CargoContainerType>(cargoContainerTypesThatSupportCargoType, rng)
                          );
                List <TrainCarType> trainCarTypes = new List <TrainCarType>();
                for (int j = 0; j < countCars; j++)
                {
                    trainCarTypes.Add(
                        GetRandomFromEnumerable <TrainCarType>(trainCarTypesThatAreSpecificContainerType, rng));
                }
                carTypesPerCargoTypes
                .Add(new CarTypesPerCargoType(trainCarTypes, pickedCargoTypes[i], (float)trainCarTypes.Count));
                allCarTypes.AddRange(trainCarTypes);
            }
            return(carTypesPerCargoTypes, allCarTypes, pickedCargoGroup);
        }
Ejemplo n.º 9
0
        public override void Parse(string[] data)
        {
            int index = 1;

            this.Id = data[index++];
            int.TryParse(data[index++], out this.SourceId);
            this.Time = DateTime.Parse(data[index++]);
            double x = 0;

            double.TryParse(data[index++], out x);
            double y = 0;

            double.TryParse(data[index++], out y);
            this.Shape = new GeoPointShape(x, y);
            double.TryParse(data[index++], out this.SOG);
            double.TryParse(data[index++], out this.COG);
            bool.TryParse(data[index++], out this.Lost);
            int.TryParse(data[index++], out this.RateOfTurn);
            double.TryParse(data[index++], out this.Orientation);
            double.TryParse(data[index++], out this.Length);
            double.TryParse(data[index++], out this.Breadth);
            double.TryParse(data[index++], out this.Altitude);
            this.NavStatus     = (NavStatuses)Enum.Parse(typeof(NavStatuses), data[index++]);
            this.UpdSensorType = (UpdSensor)Enum.Parse(typeof(UpdSensor), data[index++]);
            bool.TryParse(data[index++], out this.ATONOffPos);
            this.StaticId   = data[index++];
            this.SourceName = data[index++];
            this.Source     = (SourceTypes)Enum.Parse(typeof(SourceTypes), data[index++]);
            //this.Callsign = data[index++];
            this.Callsign = EncodeStr.Decode(data[index++]);
            //this.ShipName = data[index++];
            this.ShipName   = EncodeStr.Decode(data[index++]);
            this.ObjectType = (ObjectTypes)Enum.Parse(typeof(ObjectTypes), data[index++]);
            this.ShipType   = (ShipTypes)Enum.Parse(typeof(ShipTypes), data[index++]);
            int.TryParse(data[index++], out this.IMO);
            int.TryParse(data[index++], out this.MMSI);
            this.ATONType = (ATONTypes)Enum.Parse(typeof(ATONTypes), data[index++]);
            this.ATONName = data[index++];
            int.TryParse(data[index++], out this.AntPosDistFromFront);
            int.TryParse(data[index++], out this.AntPosDistFromLeft);
            this.NatLangShipName = data[index++];
            this.PortOfRegistry  = data[index++];
            this.CountryFlag     = data[index++];
            double.TryParse(data[index++], out this.MaxAirDraught);
            double.TryParse(data[index++], out this.MaxDraught);
            bool.TryParse(data[index++], out this.DeepWaterVesselind);
            this.VoyageId  = data[index++];
            this.CargoType = (CargoTypes)Enum.Parse(typeof(CargoTypes), data[index++]);
            //this.Destination = data[index++];
            this.Destination = EncodeStr.Decode(data[index++]);
            DateTime.TryParse(data[index++], out this.ETA);
            DateTime.TryParse(data[index++], out this.ATA);
            double.TryParse(data[index++], out this.AirDraught);
            double.TryParse(data[index++], out this.Draught);
            if (index < data.Length)
            {
                this.GID = data[index++];
            }
            if (index < data.Length)
            {
                this.FID = data[index++];
            }
        }
Ejemplo n.º 10
0
 private void ShowTrainInfo()
 {
     if (Module.ActiveRoute.IsSet)
     {
         var carsCount   = Module.ActiveRoute.RouteTracker.Trainset.cars.Count;
         var trainLength = Module.ActiveRoute.RouteTracker.Trainset.cars.Sum(c => c.logicCar.length);
         var trainWeight = Module.ActiveRoute.RouteTracker.Trainset.cars.Sum(c => c.logicCar.carOnlyMass + c.logicCar.LoadedCargoAmount * CargoTypes.GetCargoUnitMass(c.logicCar.CurrentCargoTypeInCar));
         CallMessageSubPage($"Cars: {carsCount}\nTrain length: {trainLength:0} m\nTrain weight: {trainWeight * 0.001f:0} t", "Back");
     }
 }
Ejemplo n.º 11
0
 public static float TotalMass(this Trainset trainset) => trainset.cars.Sum(c => c.totalMass + CargoTypes.GetCargoMass(c.LoadedCargo, c.LoadedCargoAmount));
Ejemplo n.º 12
0
        public static JobChainControllerWithEmptyHaulGeneration GenerateShuntingUnloadJobWithCarSpawning(
            StationController destinationStation,
            bool forceLicenseReqs,
            System.Random rng)
        {
            Debug.Log("[PersistentJobs] unload: generating with car spawning");
            YardTracksOrganizer yto = YardTracksOrganizer.Instance;
            List <CargoGroup>   availableCargoGroups = destinationStation.proceduralJobsRuleset.inputCargoGroups;
            int countTrainCars = rng.Next(
                destinationStation.proceduralJobsRuleset.minCarsPerJob,
                destinationStation.proceduralJobsRuleset.maxCarsPerJob);

            if (forceLicenseReqs)
            {
                Debug.Log("[PersistentJobs] unload: forcing license requirements");
                if (!LicenseManager.IsJobLicenseAcquired(JobLicenses.Shunting))
                {
                    Debug.LogError("[PersistentJobs] unload: Trying to generate a ShuntingUnload job with " +
                                   "forceLicenseReqs=true should never happen if player doesn't have Shunting license!");
                    return(null);
                }
                availableCargoGroups
                    = (from cg in availableCargoGroups
                       where LicenseManager.IsLicensedForJob(cg.CargoRequiredLicenses)
                       select cg).ToList();
                countTrainCars
                    = Math.Min(countTrainCars, LicenseManager.GetMaxNumberOfCarsPerJobWithAcquiredJobLicenses());
            }
            if (availableCargoGroups.Count == 0)
            {
                Debug.LogWarning("[PersistentJobs] unload: no available cargo groups");
                return(null);
            }

            CargoGroup chosenCargoGroup = Utilities.GetRandomFromEnumerable(availableCargoGroups, rng);

            // choose cargo & trainCar types
            Debug.Log("[PersistentJobs] unload: choosing cargo & trainCar types");
            List <CargoType>    availableCargoTypes  = chosenCargoGroup.cargoTypes;
            List <CargoType>    orderedCargoTypes    = new List <CargoType>();
            List <TrainCarType> orderedTrainCarTypes = new List <TrainCarType>();

            for (int i = 0; i < countTrainCars; i++)
            {
                CargoType chosenCargoType = Utilities.GetRandomFromEnumerable(availableCargoTypes, rng);
                List <CargoContainerType> availableContainers
                    = CargoTypes.GetCarContainerTypesThatSupportCargoType(chosenCargoType);
                CargoContainerType  chosenContainerType = Utilities.GetRandomFromEnumerable(availableContainers, rng);
                List <TrainCarType> availableTrainCarTypes
                    = CargoTypes.GetTrainCarTypesThatAreSpecificContainerType(chosenContainerType);
                TrainCarType chosenTrainCarType = Utilities.GetRandomFromEnumerable(availableTrainCarTypes, rng);
                orderedCargoTypes.Add(chosenCargoType);
                orderedTrainCarTypes.Add(chosenTrainCarType);
            }
            float approxTrainLength = yto.GetTotalCarTypesLength(orderedTrainCarTypes)
                                      + yto.GetSeparationLengthBetweenCars(countTrainCars);

            // choose starting track
            Debug.Log("[PersistentJobs] unload: choosing starting track");
            Track startingTrack
                = Utilities.GetTrackThatHasEnoughFreeSpace(yto, destinationStation.logicStation.yard.TransferInTracks, approxTrainLength);

            if (startingTrack == null)
            {
                Debug.LogWarning("[PersistentJobs] unload: Couldn't find startingTrack with enough free space for train!");
                return(null);
            }

            // choose random starting station
            // no need to ensure it has has free space; this is just a back story
            Debug.Log("[PersistentJobs] unload: choosing origin (inconsequential)");
            List <StationController> availableOrigins = new List <StationController>(chosenCargoGroup.stations);
            StationController        startingStation  = Utilities.GetRandomFromEnumerable(availableOrigins, rng);

            // spawn trainCars
            Debug.Log("[PersistentJobs] unload: spawning trainCars");
            RailTrack       railTrack        = SingletonBehaviour <LogicController> .Instance.LogicToRailTrack[startingTrack];
            List <TrainCar> orderedTrainCars = CarSpawner.SpawnCarTypesOnTrack(
                orderedTrainCarTypes,
                railTrack,
                true,
                0.0,
                false,
                true);

            if (orderedTrainCars == null)
            {
                Debug.LogWarning("[PersistentJobs] unload: Failed to spawn trainCars!");
                return(null);
            }

            JobChainControllerWithEmptyHaulGeneration jcc = GenerateShuntingUnloadJobWithExistingCars(
                startingStation,
                startingTrack,
                destinationStation,
                orderedTrainCars,
                orderedCargoTypes,
                rng,
                true);

            if (jcc == null)
            {
                Debug.LogWarning("[PersistentJobs] unload: Couldn't generate job chain. Deleting spawned trainCars!");
                SingletonBehaviour <CarSpawner> .Instance.DeleteTrainCars(orderedTrainCars, true);

                return(null);
            }

            return(jcc);
        }
        public static JobChainControllerWithEmptyHaulGeneration GenerateShuntingLoadJobWithCarSpawning(
            StationController startingStation,
            bool forceLicenseReqs,
            System.Random rng)
        {
            Debug.Log("[PersistentJobs] load: generating with car spawning");
            YardTracksOrganizer yto = YardTracksOrganizer.Instance;
            List <CargoGroup>   availableCargoGroups = startingStation.proceduralJobsRuleset.outputCargoGroups;
            int countTrainCars = rng.Next(
                startingStation.proceduralJobsRuleset.minCarsPerJob,
                startingStation.proceduralJobsRuleset.maxCarsPerJob);

            if (forceLicenseReqs)
            {
                Debug.Log("[PersistentJobs] load: forcing license requirements");
                if (!LicenseManager.IsJobLicenseAcquired(JobLicenses.Shunting))
                {
                    Debug.LogError("Trying to generate a ShuntingLoad job with forceLicenseReqs=true should " +
                                   "never happen if player doesn't have Shunting license!");
                    return(null);
                }
                availableCargoGroups
                    = (from cg in availableCargoGroups
                       where LicenseManager.IsLicensedForJob(cg.CargoRequiredLicenses)
                       select cg).ToList();
                countTrainCars = Math.Min(countTrainCars, LicenseManager.GetMaxNumberOfCarsPerJobWithAcquiredJobLicenses());
            }
            if (availableCargoGroups.Count == 0)
            {
                Debug.LogWarning("[PersistentJobs] load: no available cargo groups");
                return(null);
            }

            CargoGroup chosenCargoGroup = Utilities.GetRandomFromEnumerable(availableCargoGroups, rng);

            // choose cargo & trainCar types
            Debug.Log("[PersistentJobs] load: choosing cargo & trainCar types");
            List <CargoType>    availableCargoTypes  = chosenCargoGroup.cargoTypes;
            List <CargoType>    orderedCargoTypes    = new List <CargoType>();
            List <TrainCarType> orderedTrainCarTypes = new List <TrainCarType>();

            for (int i = 0; i < countTrainCars; i++)
            {
                CargoType chosenCargoType = Utilities.GetRandomFromEnumerable(availableCargoTypes, rng);
                List <CargoContainerType> availableContainers
                    = CargoTypes.GetCarContainerTypesThatSupportCargoType(chosenCargoType);
                CargoContainerType  chosenContainerType = Utilities.GetRandomFromEnumerable(availableContainers, rng);
                List <TrainCarType> availableTrainCarTypes
                    = CargoTypes.GetTrainCarTypesThatAreSpecificContainerType(chosenContainerType);
                TrainCarType chosenTrainCarType = Utilities.GetRandomFromEnumerable(availableTrainCarTypes, rng);
                orderedCargoTypes.Add(chosenCargoType);
                orderedTrainCarTypes.Add(chosenTrainCarType);
            }

            // choose starting tracks
            int maxCountTracks = startingStation.proceduralJobsRuleset.maxShuntingStorageTracks;
            int countTracks    = rng.Next(1, maxCountTracks + 1);

            // bias toward less than max number of tracks for shorter trains
            if (orderedTrainCarTypes.Count < 2 * maxCountTracks)
            {
                countTracks = rng.Next(0, Mathf.FloorToInt(1.5f * maxCountTracks)) % maxCountTracks + 1;
            }
            Debug.Log(string.Format("[PersistentJobs] load: choosing {0} starting tracks", countTracks));
            int          countCarsPerTrainset       = countTrainCars / countTracks;
            int          countTrainsetsWithExtraCar = countTrainCars % countTracks;
            List <Track> tracks = new List <Track>();

            do
            {
                tracks.Clear();
                for (int i = 0; i < countTracks; i++)
                {
                    int rangeStart = i * countCarsPerTrainset + Math.Min(i, countTrainsetsWithExtraCar);
                    int rangeCount = i < countTrainsetsWithExtraCar ? countCarsPerTrainset + 1 : countCarsPerTrainset;
                    List <TrainCarType> trainCarTypesPerTrack = orderedTrainCarTypes.GetRange(rangeStart, rangeCount);
                    float approxTrainLengthPerTrack           = yto.GetTotalCarTypesLength(trainCarTypesPerTrack)
                                                                + yto.GetSeparationLengthBetweenCars(trainCarTypesPerTrack.Count);
                    Track track = Utilities.GetTrackThatHasEnoughFreeSpace(
                        yto,
                        startingStation.logicStation.yard.StorageTracks.Except(tracks).ToList(),
                        approxTrainLengthPerTrack / (float)countTracks);
                    if (track == null)
                    {
                        break;
                    }
                    tracks.Add(track);
                }
            } while (tracks.Count < countTracks--);
            if (tracks.Count == 0)
            {
                Debug.LogWarning("[PersistentJobs] load: Couldn't find startingTrack with enough free space for train!");
                return(null);
            }

            // choose random destination station that has at least 1 available track
            Debug.Log("[PersistentJobs] load: choosing destination");
            float approxTrainLength = yto.GetTotalCarTypesLength(orderedTrainCarTypes)
                                      + yto.GetSeparationLengthBetweenCars(countTrainCars);
            List <StationController> availableDestinations = new List <StationController>(chosenCargoGroup.stations);
            StationController        destStation           = null;
            Track destinationTrack = null;

            while (availableDestinations.Count > 0 && destinationTrack == null)
            {
                destStation = Utilities.GetRandomFromEnumerable(availableDestinations, rng);
                availableDestinations.Remove(destStation);
                destinationTrack = Utilities.GetTrackThatHasEnoughFreeSpace(
                    yto,
                    yto.FilterOutOccupiedTracks(destStation.logicStation.yard.TransferInTracks),
                    approxTrainLength);
            }
            if (destinationTrack == null)
            {
                Debug.LogWarning("Couldn't find a station with enough free space for train!");
                return(null);
            }

            // spawn trainCars & form carsPerStartingTrack
            Debug.Log("[PersistentJobs] load: spawning trainCars");
            List <TrainCar>     orderedTrainCars     = new List <TrainCar>();
            List <CarsPerTrack> carsPerStartingTrack = new List <CarsPerTrack>();

            for (int i = 0; i < tracks.Count; i++)
            {
                int rangeStart = i * countCarsPerTrainset + Math.Min(i, countTrainsetsWithExtraCar);
                int rangeCount = i < countTrainsetsWithExtraCar ? countCarsPerTrainset + 1 : countCarsPerTrainset;
                Debug.Log(string.Format(
                              "[PersistentJobs] load: spawning cars in range [{0}-{1}) from total range [0-{2})",
                              rangeStart,
                              rangeStart + rangeCount,
                              orderedTrainCarTypes.Count));
                Track           startingTrack = tracks[i];
                RailTrack       railTrack     = SingletonBehaviour <LogicController> .Instance.LogicToRailTrack[startingTrack];
                List <TrainCar> spawnedCars   = CarSpawner.SpawnCarTypesOnTrack(
                    orderedTrainCarTypes.GetRange(rangeStart, rangeCount),
                    railTrack,
                    true,
                    0.0,
                    false,
                    true);
                if (spawnedCars == null)
                {
                    Debug.LogWarning("[PersistentJobs] load: Failed to spawn some trainCars!");
                    SingletonBehaviour <CarSpawner> .Instance.DeleteTrainCars(orderedTrainCars, true);

                    return(null);
                }
                orderedTrainCars.AddRange(spawnedCars);
                carsPerStartingTrack.Add(
                    new CarsPerTrack(startingTrack, (from car in spawnedCars select car.logicCar).ToList()));
            }

            JobChainControllerWithEmptyHaulGeneration jcc = GenerateShuntingLoadJobWithExistingCars(
                startingStation,
                carsPerStartingTrack,
                destStation,
                orderedTrainCars,
                orderedCargoTypes,
                rng,
                true);

            if (jcc == null)
            {
                Debug.LogWarning("[PersistentJobs] load: Couldn't generate job chain. Deleting spawned trainCars!");
                SingletonBehaviour <CarSpawner> .Instance.DeleteTrainCars(orderedTrainCars, true);

                return(null);
            }

            return(jcc);
        }