Ejemplo 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 }));
            }
        }
Ejemplo n.º 2
0
        public ActionResult NM_PerformAction()
        {
            if (dontCall)
            {
                return(ActionResult.Continue);
            }

            Boat boat = null;

            try
            {
                mRoutingSim.SimRoutingComponent.DisallowBeingPushed = true;

                if (mRoutingSim.HasExitReason((ExitReason)mOriginalRoute.ExitReasonsInterrupt))
                {
                    AddFailureExplanation(FailureExplanation.CancelledByScript);
                    return(ActionResult.Terminate);
                }

                Lot lot = (mOriginalRoute == null) ? mRoutingSim.LotCurrent : LotManager.GetLotAtPoint(mOriginalRoute.GetOriginalStartPoint());
                boat = Sim_GetBoatForGetInBoatRouteAction(mRoutingSim, lot);
                if (boat == null)
                {
                    AddFailureExplanation(FailureExplanation.VehicleSequenceFailure);
                    return(ActionResult.Terminate);
                }

                mLastFoundBoatId = boat.ObjectId;
                Vector3 pt;
                mOriginalRoute.GetSegmentStartPoint(0u, out pt);
                Vector3 dir;
                mOriginalRoute.GetSegmentStartDirection(0u, out dir);

                mBoatAppearingPt = pt;

                mnReplanFrequency = RandomUtil.GetInt(SimRoutingComponent.AvoidanceReplanCheckFrequencyMin, SimRoutingComponent.AvoidanceReplanCheckFrequencyMax);
                mnReplanOffset    = RandomUtil.GetInt(SimRoutingComponent.AvoidanceReplanCheckOffsetMin, SimRoutingComponent.AvoidanceReplanCheckOffsetMax);

                StandAndWaitController standAndWaitController = new StandAndWaitController();
                standAndWaitController.AllowZeroCycle = true;
                standAndWaitController.Duration       = SimRoutingComponent.DefaultStandAndWaitDuration;
                standAndWaitController.OnCycle        = base.StandAndWaitCycleHandler;
                standAndWaitController.Run(mRoutingSim);

                if (mStandAndWaitResult == ActionResult.Terminate)
                {
                    if (mLastFoundObstruction.IsValid && mOriginalRoute.DoRouteFail)
                    {
                        mRoutingSim.SimRoutingComponent.PlayRouteFailureIfAppropriate(mLastFoundObstruction.ObjectFromId <GameObject>());
                    }
                    return(mStandAndWaitResult);
                }

                if (mStandAndWaitResult == ActionResult.ContinueAndFollowPath)
                {
                    return(mStandAndWaitResult);
                }

                ItemComponent itemComp = boat.ItemComp;
                if (itemComp != null && itemComp.InventoryParent != null)
                {
                    itemComp.InventoryParent.RemoveByForce(boat);
                }

                MooringPost mooringPost = boat.Parent as MooringPost;
                if (mooringPost != null)
                {
                    mooringPost.UnReserveSpot(boat);
                }

                boat.PlaceAt(pt, dir, mRoutingSim);

                BoatRoutingComponent boatRoutingComponent = boat.RoutingComponent as BoatRoutingComponent;
                if (boatRoutingComponent != null)
                {
                    boatRoutingComponent.ForceUpdateDynamicFootprint();
                    boatRoutingComponent.EnableDynamicFootprint();
                }

                mRoutingSim.FadeOut(true, 0.5f, null);

                if (!boat.HaveSimWaitBeforeGettingIn(mRoutingSim))
                {
                    mRoutingSim.FadeIn(false, 0f);
                    return(ActionResult.Terminate);
                }

                boat.SimIsGettingIn = true;

                if (boat.Driver == null)
                {
                    boat.PutInDriver(mRoutingSim);
                }
                else
                {
                    boat.PutInPassenger(mRoutingSim);
                }

                boat.SimIsGettingIn = false;

                if (!(boat is BoatTaxi))
                {
                    mRoutingSim.FadeIn(true, 0.5f);
                }

                GameObject objectInRightHand = mRoutingSim.GetObjectInRightHand();
                if (objectInRightHand != null && !(objectInRightHand is Sim))
                {
                    objectInRightHand.SetHiddenFlags(HiddenFlags.Model);
                }

                mRoutingSim.SimRoutingComponent.ClearPush();

                mOriginalRoute.FollowerAgeGenderSpecies = (uint)boat.GetBoatSpecies();
                mOriginalRoute.Follower = boat.Proxy;
                mOriginalRoute.SetOption2(Route.RouteOption2.BeginAsBoat, true);
                mOriginalRoute.SetOption2(Route.RouteOption2.UseFollowerStartOrientation, boat.UsesTurnHelperFootprint());
                mOriginalRoute.SetOption(Route.RouteOption.RouteAsGhost, false);

                return(ActionResult.ContinueAndPopPathAndReplan);
            }
            catch
            {
                if (boat != null && boat.DestroyOnRelease)
                {
                    boat.Destroy();
                }
                throw;
            }
            finally
            {
                mRoutingSim.SimRoutingComponent.DisallowBeingPushed = false;
            }
        }