private void AttachCustomerToCar(MovingCar car) { gameObject.transform.SetParent(car.transform); gameObject.GetComponent <Animator>().SetBool("IsCatching", true); Destroy(gameObject.GetComponent <Rigidbody2D>()); car.hasPassenger = true; car.transform.position = car.transform.position + new Vector3(0, 0, 1); }
private IEnumerator LoadCar() { _audioPlayer.PlayHaulerLoaded(); IsLoading = true; yield return(DriveIntoGarage()); _maybeLoadedCar = CarSpawner.LoadCar(this); yield return(DriveOutOfGarage()); IsLoading = false; }
private IEnumerator ReturnCarToGarage() { IsLoading = true; yield return(new WaitForSeconds(0.16f)); DestroyImmediate(_maybeLoadedCar.GetComponent <Rigidbody2D>()); DestroyImmediate(_maybeLoadedCar.GetComponent <Collider2D>()); _maybeLoadedCar.transform.parent = transform; yield return(DriveIntoGarage()); _maybeLoadedCar.transform.parent = null; DestroyImmediate(_maybeLoadedCar); _maybeLoadedCar = CarSpawner.LoadCar(this); yield return(DriveOutOfGarage()); IsLoading = false; }
public void GenerateCurrentPositionsList() { List <SwitchMove> switchList = new List <SwitchMove>(); foreach (var station in layout.layoutState.StationStates) { foreach (var car in station.CarsPresent) { SwitchMove move = new SwitchMove(); var movingCar = new MovingCar(); move.CarNumber = car; move.CurrentLocation = station.Name; move.Cargo = "―――"; move.TargetLocation = "―――"; switchList.Add(move); } } GenerateSwitchListFile(switchList); }
public void Return(MovingCar car) { _maybeLoadedCar = car; car.SetReturnHandled(); StartCoroutine(ReturnCarToGarage()); }
private void LaunchCar() { _audioPlayer.PlayCarLaunched(); _maybeLoadedCar.Launch(); _maybeLoadedCar = null; }
public void GenerateNewSwitchlist() { print("STARTING NEW DAY"); List <SwitchMove> switchList = new List <SwitchMove>(); Random.InitState(layout.layoutState.Seed); //Get all the cars on the layout var allCars = new List <MovingCar>(); foreach (var station in layout.layoutState.StationStates) { foreach (var car in station.CarsPresent) { var movingCar = new MovingCar { CarName = car, PreviousStation = station.Name }; allCars.Add(movingCar); } } //Work out which cars are actually moving today List <MovingCar> stayingCars = new List <MovingCar>(); allCars = GetMovingCars(allCars, out stayingCars); //print("Cars moving: " + allCars); //Clear moving cars from their current stations (so they're not counted as present) foreach (var item in allCars) { layout.layoutState.StationStates.FirstOrDefault(b => b.Name == item.PreviousStation).CarsPresent.Remove(item.CarName); } //Send the cars to their new destination foreach (var car in allCars) { print(car.CarName + " is starting move logic."); //Create the switchmove object SwitchMove move = new SwitchMove { CurrentLocation = car.PreviousStation, CarNumber = car.CarName }; var stationRef = layout.layout.Stations.FirstOrDefault(b => b.Name == car.PreviousStation); //Jumble the list of exported cargo System.Random rnd = new System.Random(); string[] randomExportCargo = stationRef.CargoExport.OrderBy(x => rnd.Next()).ToArray(); string cargo = ""; string targetStation = ""; foreach (var rndCargo in randomExportCargo) { print(car.CarName + " is testing export for " + rndCargo); //Check if the car takes this cargo if (GetValidCarTypeCargo(layout.layout.Cars.FirstOrDefault(b => b.Number == car.CarName).Type).Contains(rndCargo)) { //Find a random station that will recieve this cargo targetStation = GetValidStation(rndCargo, true); //if there's no recieving stations, skip to the next cargo if (targetStation == "") { continue; } //Otherwise, we're good to go, so let's proceed with that cargo and station cargo = rndCargo; move.Cargo = rndCargo; print(car.CarName + " selected " + rndCargo); break; } } //If we've failed to find a station that will take valid cargo, find some other station that exports valid cargo for a logistics move if (cargo == "" || targetStation == "") { print(car.CarName + " has no valid export. Starting logistics move search."); //Randomly sort the cargo this car carries string[] validCargo = GetValidCarTypeCargo(layout.layout.Cars.FirstOrDefault(b => b.Number == car.CarName).Type).OrderBy(x => rnd.Next()).ToArray(); //Check the cargo for free stations foreach (var item in validCargo) { print(car.CarName + " is testing logistics move for " + item); targetStation = GetValidStation(item, false); if (targetStation != "" && targetStation != car.PreviousStation) { print(car.CarName + " found logistics move to " + targetStation); move.Cargo = "―――"; break; } else { print(car.CarName + " found no valid station for logistics move that exports " + item); } } } move.TargetLocation = targetStation; if (targetStation == "") { Debug.LogError(car.CarName + " totally failed to find a move and is staying put."); MoveCar(car.CarName, car.PreviousStation); move.Cargo = "―――"; move.TargetLocation = "―――"; switchList.Add(move); continue; } MoveCar(car.CarName, targetStation); Debug.LogWarning($"{move.CarNumber} FROM {move.CurrentLocation} TO {move.TargetLocation} CARGO {move.Cargo}"); switchList.Add(move); } foreach (var car in stayingCars) { SwitchMove move = new SwitchMove { CurrentLocation = car.PreviousStation, CarNumber = car.CarName, Cargo = "―――", TargetLocation = "―――" }; switchList.Add(move); } GenerateSwitchListFile(switchList); layout.layoutState.Seed++; }