Exemplo n.º 1
0
        protected override void PrivatePerformAction(bool prompt)
        {
            Overwatch.Log(Name);

            Dictionary <IGameObject, bool> outOfWorldObjects = new Dictionary <IGameObject, bool>();

            Dictionary <ObjectGuid, bool> reservedObjects = new Dictionary <ObjectGuid, bool>();

            foreach (ParkingSpace space in Sims3.Gameplay.Queries.GetObjects <ParkingSpace>())
            {
                Vehicle vehicle = space.GetContainedVehicle();
                if (vehicle == null && space.ReservedVehicle != null)
                {
                    space.mReservedVehicle = null;
                }

                if (vehicle == null)
                {
                    continue;
                }

                if (!RetainOnLot(space))
                {
                    continue;
                }

                reservedObjects[vehicle.ObjectId] = true;
            }

            foreach (MooringPost post in Sims3.Gameplay.Queries.GetObjects <MooringPost>())
            {
                Vehicle vehicle = post.GetContainedVehicle();
                if (vehicle == null)
                {
                    continue;
                }

                if (!RetainOnLot(post))
                {
                    continue;
                }

                reservedObjects[vehicle.ObjectId] = true;
            }

            foreach (BikeRack rack in Sims3.Gameplay.Queries.GetObjects <BikeRack>())
            {
                if (!RetainOnLot(rack))
                {
                    continue;
                }

                foreach (Bicycle bike in rack.GetContainedBikes())
                {
                    reservedObjects[bike.ObjectId] = true;
                }
            }

            foreach (SimDescription sim in SimListing.GetResidents(false).Values)
            {
                if (sim.BoardingSchool != null)
                {
                    AddOutOfWorldObjects(outOfWorldObjects, sim.BoardingSchool.mInventoryItems);
                }

                if (sim.mInventoryItemsWhileInPassport != null)
                {
                    AddOutOfWorldObjects(outOfWorldObjects, sim.mInventoryItemsWhileInPassport);
                }

                Sim createdSim = sim.CreatedSim;
                if (createdSim != null)
                {
                    PoliceStation.GoToJail interaction = createdSim.CurrentInteraction as PoliceStation.GoToJail;
                    if ((interaction != null) && (interaction.mInmatesObjects != null))
                    {
                        foreach (IGameObject obj in interaction.mInmatesObjects)
                        {
                            outOfWorldObjects[obj] = true;
                        }
                    }

                    Vehicle reserved = createdSim.GetReservedVehicle();
                    if (reserved != null)
                    {
                        reservedObjects[reserved.ObjectId] = true;
                    }
                }

                ObjectGuid preferred = sim.mPreferredVehicleGuid;
                if (preferred != ObjectGuid.InvalidObjectGuid)
                {
                    reservedObjects[preferred] = true;
                }
            }

            if (ParentsLeavingTownSituation.sAdultsInventories != null)
            {
                foreach (List <InventoryItem> list in ParentsLeavingTownSituation.sAdultsInventories.Values)
                {
                    AddOutOfWorldObjects(outOfWorldObjects, list);
                }
            }

            int count = 0;

            foreach (Vehicle vehicle in Sims3.Gameplay.Queries.GetObjects <Vehicle>())
            {
                if (outOfWorldObjects.ContainsKey(vehicle))
                {
                    continue;
                }

                if (vehicle.HasFlags(GameObject.FlagField.IsStolen))
                {
                    continue;
                }

                if (reservedObjects.ContainsKey(vehicle.ObjectId))
                {
                    continue;
                }

                if ((!vehicle.InInventory) && (vehicle.Driver != null) && (!vehicle.Driver.HasBeenDestroyed))
                {
                    if (vehicle.Driver.LotCurrent == vehicle.LotCurrent)
                    {
                        continue;
                    }

                    if (vehicle.Driver.IsPerformingAService)
                    {
                        continue;
                    }
                }

                // Temporary until further review can be done
                if (vehicle is CarUFO)
                {
                    continue;
                }

                if (vehicle is WindSurfboard)
                {
                    // These vehicles can be placed on the ground, so don't require a parent
                    continue;
                }

                if (vehicle is MagicBroom)
                {
                    if (vehicle.InInventory)
                    {
                        continue;
                    }

                    if (vehicle.Parent is BroomStand)
                    {
                        continue;
                    }
                }
                else
                {
                    IOwnableVehicle ownableVehicle = vehicle as IOwnableVehicle;
                    if (ownableVehicle != null)
                    {
                        if (ownableVehicle.PendingUse)
                        {
                            continue;
                        }

                        CarOwnable carOwnable = vehicle as CarOwnable;
                        if (carOwnable != null)
                        {
                            if (!carOwnable.GeneratedOwnableForNpc)
                            {
                                continue;
                            }
                        }
                        else
                        {
                            BoatOwnable boatOwnable = vehicle as BoatOwnable;
                            if (boatOwnable != null)
                            {
                                if (!boatOwnable.GeneratedOwnableForNpc)
                                {
                                    continue;
                                }
                            }
                            else
                            {
                                if (ownableVehicle.InInventory)
                                {
                                    continue;
                                }
                            }
                        }
                    }

                    if ((vehicle is FoodTruckBase) || (vehicle is CarService))
                    {
                        if (vehicle.InWorld)
                        {
                            continue;
                        }
                    }
                }

                if ((vehicle.InWorld) && (vehicle.InUse))
                {
                    bool found = false;

                    foreach (Sim sim in vehicle.ActorsUsingMe)
                    {
                        if (!sim.HasBeenDestroyed)
                        {
                            found = true;
                            break;
                        }
                    }

                    if (found)
                    {
                        continue;
                    }
                }

                string parentSpace = null;
                if (vehicle.Parent != null)
                {
                    parentSpace = vehicle.Parent.GetType().ToString();
                    if (parentSpace.Contains("GalleryShopParkingSpace") || parentSpace.Contains("StoreSetParkingSpace"))
                    {
                        continue;
                    }
                }

                {
                    string catalogName = vehicle.CatalogName;

                    bool inInventory = vehicle.InInventory;

                    vehicle.UnParent();

                    IUsesParkingSpace parker = vehicle as IUsesParkingSpace;

                    if (parker != null)
                    {
                        ParkingSpace space = vehicle.Parent as ParkingSpace;
                        if (space != null)
                        {
                            space.UnReserveSpot(parker);
                        }
                        else
                        {
                            MooringPost post = vehicle.Parent as MooringPost;
                            if (post != null)
                            {
                                post.UnReserveSpot(parker as Boat);
                            }
                        }
                    }

                    vehicle.Destroy();

                    if (!(vehicle is LightweightTaxi))
                    {
                        count++;
                        Overwatch.Log("Towed " + catalogName);

                        if (inInventory)
                        {
                            Overwatch.Log(" Was InInventory");
                        }

                        if (!string.IsNullOrEmpty(parentSpace))
                        {
                            Overwatch.Log(" Space: " + parentSpace);
                        }
                    }
                }
            }

            if ((count > 0) || (prompt))
            {
                Overwatch.AlarmNotify(Common.Localize("CleanupVehicles:Complete", false, new object[] { count }));
            }
        }
Exemplo n.º 2
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;
        }