Пример #1
0
        private bool IsAnyTrainAtPlatform(bool loading)
        {
            if (!(CurrentTasksField?.GetValue(LogicMachine) is List <WarehouseTask> currentTasks))
            {
                return(false);
            }

            WarehouseTaskType taskType = loading ? WarehouseTaskType.Loading : WarehouseTaskType.Unloading;

            foreach (WarehouseTask warehouseTask in currentTasks)
            {
                if (warehouseTask.readyForMachine && (warehouseTask.warehouseTaskType == taskType) && AreCarsStoppedAtPlatform(warehouseTask.cars))
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #2
0
        private System.Collections.IEnumerator DelayedLoadUnload(bool isLoading)
        {
            WaitForSeconds carDelay = WaitFor.Seconds(LOAD_DELAY);

            WarehouseTaskType taskType = isLoading ? WarehouseTaskType.Loading : WarehouseTaskType.Unloading;
            var currentLoadData        = LogicMachine.GetCurrentLoadUnloadData(taskType);

            if (currentLoadData.Count == 0)
            {
                DelayedLoadUnloadRoutine = null;
                loading   = false;
                unloading = false;
                yield break;
            }

            if (isLoading)
            {
                loading   = true;
                unloading = false;
            }
            else
            {
                loading   = false;
                unloading = true;
            }

            bool completedTransfer = false;

            foreach (var data in currentLoadData)
            {
                yield return(carDelay);

                if (data.state == WMDataState.FullLoadUnloadPossible)
                {
                    // all cars ready to load
                    foreach (WarehouseTask task in data.tasksAvailableToProcess)
                    {
                        // make double sure that the cars are able to be loaded
                        bool allCarsStopped = AreCarsStoppedAtPlatform(task.cars);
                        if (!allCarsStopped)
                        {
                            // this kills the passengers
                            continue;
                        }

                        // display the current transferring train
                        string message;
                        if (task.warehouseTaskType == WarehouseTaskType.Loading)
                        {
                            message = $"Now Boarding\n{task.Job.ID} to {task.Job.chainData.chainDestinationYardId}";
                        }
                        else
                        {
                            message = $"Now Boarding\n{task.Job.ID} from {task.Job.chainData.chainOriginYardId}";
                        }
                        ApplyOverrideText(message);

                        // now that we verified that the cars are okay, actually transfer the passengers to/from the cars
                        for (int nToProcess = task.cars.Count; nToProcess > 0; nToProcess--)
                        {
                            Car result = (isLoading) ?
                                         LogicMachine.LoadOneCarOfTask(task) :
                                         LogicMachine.UnloadOneCarOfTask(task);

                            if (result == null)
                            {
                                PassengerJobs.ModEntry.Logger.Error("Tried to (un)load a car that wasn't there :(");

                                // fail into safe state by completing task
                                task.state = TaskState.Done;
                                foreach (Car car in task.cars)
                                {
                                    if (isLoading)
                                    {
                                        car.LoadCargo(car.capacity, CargoType.Passengers);
                                    }
                                    else
                                    {
                                        car.DumpCargo();
                                    }
                                }
                                LogicMachine.RemoveWarehouseTask(task);

                                break;
                            }

                            yield return(carDelay);
                        }
                    }

                    ClearOverrideText();
                    completedTransfer = true;
                }
            }
            // all jobs processed

            if (completedTransfer && (LoadCompletedSound != null))
            {
                Transform playerTform = PlayerManager.PlayerCamera.transform;
                LoadCompletedSound.Play(playerTform.position, parent: playerTform);
            }

            loading = unloading = false;
            DelayedLoadUnloadRoutine = null;
        }