Exemplo n.º 1
0
        protected void OneShotRouteToLot()
        {
            mTruck.RoutingComponent.ClearQueuedActions();

            bool flag = false;

            if (mTruck.mDestinationLot == null)
            {
                flag = true;
                List <Lot> randomList      = new List <Lot>();
                Lot        lotHome         = null;
                Household  activeHousehold = Household.ActiveHousehold;
                if (activeHousehold != null)
                {
                    lotHome = activeHousehold.LotHome;
                }

                Lot activeLot = LotManager.ActiveLot;
                foreach (Lot lot3 in LotManager.AllLots)
                {
                    if (((lot3.LotId != ulong.MaxValue) && (lot3 != activeLot)) && (lot3 != lotHome))
                    {
                        randomList.Add(lot3);
                    }
                }

                if (randomList.Count > 0x0)
                {
                    mTruck.mDestinationLot = RandomUtil.GetRandomObjectFromList <Lot>(randomList);
                }

                if (mTruck.mDestinationLot == null)
                {
                    mTruck.FadeOut(false, true);
                    mTruck.mRouteToLot = null;
                    return;
                }
            }

            ParkingSpace parent = mTruck.Parent as ParkingSpace;

            if (parent != null)
            {
                Matrix44 matrix = new Matrix44();
                mTruck.LotCurrent.StreetParking.GetParkingSpotForCar(mTruck, ref matrix);
                mTruck.PlaceAt(matrix.pos.V3, matrix.at.V3, null);
                mTruck.TruckOnRoad();
                parent.LotCurrent.StreetParking.FreeParkingSpotForCar(mTruck);
            }

            Matrix44 mat = new Matrix44();

            mTruck.mDestinationLot.StreetParking.GetParkingSpotForCar(mTruck, ref mat);
            Vector3 position = mTruck.Position;
            Route   r        = mTruck.CarRoutingComponent.CreateRoute();

            r.PlanToMatrixFromPoint(ref position, ref mat);
            if (!mTruck.DoRoute(r))
            {
                if (parent != null)
                {
                    parent.ParkVehicle(mTruck);
                }
                else
                {
                    flag = true;
                }
            }
            else if (parent != null)
            {
                parent.UnReserveSpot(mTruck);
            }

            mTruck.mDestinationLot.StreetParking.FreeParkingSpotForCar(mTruck);
            if (!flag)
            {
                ParkingSpace closestUnreservedParkingSpace = Vehicle.GetClosestUnreservedParkingSpace(mTruck.mDestinationLot.GetObjects <WideParkingSpace>(), mTruck);
                if (closestUnreservedParkingSpace != null)
                {
                    closestUnreservedParkingSpace.ParkVehicle(mTruck);
                    mTruck.TruckParked();
                }
                else if (Traffic.Settings.mRequireFoodParkingSpace)
                {
                    mTruck.FadeOut(false, true);
                }
                else
                {
                    mTruck.TruckParked();
                    mTruck.SetGeometryState("openWithLights");
                }
            }
            else if (Traffic.Settings.mRequireFoodParkingSpace)
            {
                mTruck.FadeOut(false, true);
            }
            else
            {
                mTruck.TruckParked();
                mTruck.SetGeometryState("openWithLights");
            }

            AddMapTags(mTruck);

            mTruck.mDestinationLot = null;
            mTruck.mRouteToLot     = null;
        }