예제 #1
0
    //Try to get a free station
    IEnumerator PollForStation(PowerStationRoad p)
    {
        while (p.GetEmptyPoweredStation() == null)
        {
            yield return(new WaitForSeconds(0.1f));
        }
        PowerStation station = p.GetEmptyPoweredStation();

        station.Occupy();
        chargingAt = station;
        controlledCar.GoToState(Car.CarState.driving);
    }
예제 #2
0
    void EndActiveTrip()
    {
        ActiveTrip.completed = true;
        TripInProgress       = false;
        controlledCar.GoToState(Car.CarState.waiting);

        switch (ActiveTrip.type)
        {
        case Trip.TripType.Park: {
            ParkingSpace s = ((ParkingSpotRoad)ActiveTrip.end).GetEmptySpace();
            //Reserve the parking space
            s.Occupy();
            parkedAt = s;
            state    = State.parked;

            controlledCar.Park(s);
            break;
        }

        case Trip.TripType.Charge: {
            PowerStationRoad s = world.FindNearestPoweredPowerstation(controlledCar.transform.position.ToVector2());
            if (s == null)
            {
                Debug.LogError("No power stations! Handle that.");
            }
            PowerStation ps = s.GetEmptyPoweredStation();
            //no empty station available
            //this is actually obsolete.
            if (ps == null)
            {
                Debug.LogError("All stations full (handled in coroutine.)!");
            }
            else
            {
                chargingAt = ps;
                ps.Occupy();
            }

            charging = true;
            state    = State.charging;

            controlledCar.Recharge(chargingAt);
            return;
        }

        case Trip.TripType.Cruise: {
            state = State.enRoute;
            break;
        }
        }

        //Create next journey
        CreateJourney();
        if (ActiveTrip == null)
        {
            Finished = true;
            Game.Instance.OnCarFinished(controlledCar);
            return;
        }
        SetWakeUp(ActiveTrip.departure);
    }