Exemplo n.º 1
0
        public static List <Vehicle> GetLotVehicles(Lot lot)
        {
            List <Vehicle> results = new List <Vehicle>();

            if (lot != null)
            {
                if (lot.IsResidentialLot)
                {
                    List <IOwnableVehicle> vehicles = new List <IOwnableVehicle>(lot.GetObjects <IOwnableVehicle>());
                    foreach (IOwnableVehicle vehicle in vehicles)
                    {
                        CarOwnable ownable = vehicle as CarOwnable;
                        if (ownable != null)
                        {
                            if (ownable.LotHome != lot)
                            {
                                continue;
                            }

                            results.Add(ownable);
                        }
                        else
                        {
                            Bicycle bicycle = vehicle as Bicycle;
                            if (bicycle != null)
                            {
                                if (bicycle.LotHome != lot)
                                {
                                    continue;
                                }

                                results.Add(bicycle);
                            }
                        }
                    }
                }
                else
                {
                    foreach (ParkingSpace space in lot.GetObjects <ParkingSpace>())
                    {
                        CarOwnable ownable = space.ReservedVehicle as CarOwnable;
                        if (ownable == null)
                        {
                            continue;
                        }

                        if (ownable.GeneratedOwnableForNpc)
                        {
                            continue;
                        }

                        results.Add(ownable);
                    }
                }
            }

            return(results);
        }
        protected static bool OnTestVehicle(IGameObject obj, object customData)
        {
            CarOwnable car = obj as CarOwnable;

            if ((car != null) && (car.GeneratedOwnableForNpc))
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 3
0
        protected static void OnLotChanged(Event e)
        {
            Sim sim    = e.Actor as Sim;
            Lot oldLot = e.TargetObject as Lot;

            if ((oldLot != null) && (!oldLot.IsResidentialLot))
            {
                foreach (ParkingSpace space in oldLot.GetObjects <ParkingSpace>())
                {
                    CarOwnable ownable = space.ReservedVehicle as CarOwnable;
                    if (ownable == null)
                    {
                        continue;
                    }

                    if (ownable.GeneratedOwnableForNpc)
                    {
                        continue;
                    }

                    if ((ownable == sim.GetReservedVehicle()) || (ownable == sim.GetPreferredVehicle()) || (ownable.Driver == sim))
                    {
                        Inventories.TryToMove(ownable, sim);
                        space.UnReserveSpot(ownable);
                    }
                }

                foreach (MooringPost post in oldLot.GetObjects <MooringPost>())
                {
                    BoatOwnable ownable = post.ReservedVehicle as BoatOwnable;
                    if (ownable == null)
                    {
                        continue;
                    }

                    if (ownable.GeneratedOwnableForNpc)
                    {
                        continue;
                    }

                    if ((ownable == sim.GetReservedVehicle()) || (ownable == sim.GetPreferredVehicle()) || (ownable.Driver == sim))
                    {
                        Inventories.TryToMove(ownable, sim);
                        post.UnReserveSpot(ownable);
                    }
                }
            }
        }
Exemplo n.º 4
0
        protected override List <GameObject> GetInventory(SimDescription sim)
        {
            List <GameObject> results = new List <GameObject>();

            foreach (GameObject obj in Inventories.InventoryFindAll <GameObject>(sim))
            {
                if (obj.Value == 0)
                {
                    continue;
                }

                if (obj is Vehicle)
                {
                    CarOwnable ownable = obj as CarOwnable;
                    if (ownable != null)
                    {
                        if (ownable.GeneratedOwnableForNpc)
                        {
                            continue;
                        }

                        if (ownable is CarMotiveMobile)
                        {
                            continue;
                        }

                        if (ownable is SirenEnabledVehicle)
                        {
                            continue;
                        }
                    }

                    NameComponent name = obj.GetComponent <NameComponent>();
                    if ((name == null) || (string.IsNullOrEmpty(name.Name)))
                    {
                        results.Add(obj);
                    }
                }
            }

            return(results);
        }
Exemplo n.º 5
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.º 6
0
        protected override bool Allow(SimDescription sim)
        {
            if (!base.Allow(sim))
            {
                return(false);
            }

            if ((sim.CreatedSim.LotCurrent == null) || (sim.CreatedSim.LotCurrent.IsWorldLot))
            {
                IncStat("In Transit");
                return(false);
            }
            else if (!Households.AllowGuardian(sim))
            {
                IncStat("Too Young");
                return(false);
            }
            else if (sim.GetPreferredVehicle() != null)
            {
                IncStat("Preferred");
                return(false);
            }
            else
            {
                bool found = false;
                List <IOwnableVehicle> vehicles = Inventories.InventoryDuoFindAll <IOwnableVehicle, Vehicle>(sim);

                IOwnableVehicle choice = sim.CreatedSim.GetOwnedAndUsableVehicle(sim.CreatedSim.LotCurrent) as IOwnableVehicle;
                if (choice != null)
                {
                    vehicles.Add(choice);
                }

                IOwnableVehicle reserved = sim.CreatedSim.GetReservedVehicle() as IOwnableVehicle;
                if (reserved != null)
                {
                    if (!vehicles.Contains(reserved))
                    {
                        vehicles.Add(reserved);
                    }
                }

                IOwnableVehicle preferred = sim.CreatedSim.GetPreferredVehicle();
                if (preferred != null)
                {
                    if (!vehicles.Contains(preferred))
                    {
                        vehicles.Add(preferred);
                    }
                }

                AddStat("Vehicles", vehicles.Count);

                foreach (IOwnableVehicle existing in vehicles)
                {
                    CarOwnable car = existing as CarOwnable;
                    if ((car != null) && (car.GeneratedOwnableForNpc))
                    {
                        continue;
                    }

                    T vehicle = existing as T;
                    if ((vehicle != null) && (!Test(vehicle)))
                    {
                        IncStat("Has Other Type");
                        return(false);
                    }

                    found = true;
                }

                if (found)
                {
                    if (AddScoring("ReplaceVehicle", sim) <= 0)
                    {
                        IncStat("Replace Score Fail");
                        return(false);
                    }
                }
            }

            return(true);
        }
Exemplo n.º 7
0
        protected override bool PrivateUpdate(ScenarioFrame frame)
        {
            List <IOwnableVehicle> existing = new List <IOwnableVehicle>();

            foreach (IOwnableVehicle obj in Inventories.InventoryDuoFindAll <IOwnableVehicle, Vehicle>(Sim))
            {
                CarOwnable car = obj as CarOwnable;
                if ((car != null) && (car.GeneratedOwnableForNpc))
                {
                    continue;
                }

                Vehicle vehicle = obj as Vehicle;
                if (vehicle == null)
                {
                    continue;
                }

                NameComponent name = vehicle.GetComponent <NameComponent>();
                if ((name == null) || (string.IsNullOrEmpty(name.Name)))
                {
                    existing.Add(obj);
                }
            }

            mExtraFunds = 0;
            mMinimum    = 0;

            foreach (IOwnableVehicle vehicle in existing)
            {
                GameObject obj = vehicle as GameObject;

                mExtraFunds += obj.Value;

                if (mMinimum < obj.Value)
                {
                    mMinimum = obj.Value;
                }
            }

            AddStat("Extra", mExtraFunds);

            if (existing.Count > 0)
            {
                mMinimum += 2500;
            }

            if (!base.PrivateUpdate(frame))
            {
                return(false);
            }

            if (Object != null)
            {
                Sim.SetPreferredVehicle(Object);
            }

            foreach (IOwnableVehicle vehicle in existing)
            {
                Money.Sell(Sim, vehicle as GameObject);
            }

            return(true);
        }
Exemplo n.º 8
0
        public static Vehicle Sim_GetVehicle(Sim ths, Lot lot, bool allowUFO)
        {
            if (ths.IsPet)
            {
                return(null);
            }

            var vehicleForCurrentInteraction = ths.GetVehicleForCurrentInteraction();

            if (vehicleForCurrentInteraction != null && !(vehicleForCurrentInteraction is Boat))
            {
                return(vehicleForCurrentInteraction);
            }

            bool child    = ths.Posture == null || !ths.Posture.Satisfies(CommodityKind.CarryingChild, null);
            bool canDrive = ths.CanDriveOrCallTaxi();

            if (canDrive &&
                !Vehicle.WorldHasSpecialCarRules(GameUtils.GetCurrentWorld())

                && (!(ths.SimRoutingComponent != null && ths.SimRoutingComponent.AllowBikes)

                    || (ths.Autonomy != null &&
                        ths.Autonomy.SituationComponent != null &&
                        ths.Autonomy.SituationComponent.InSituationOfType(typeof(GoHereWithSituation)))

                    || ths.CurrentInteraction is TravelUtil.SitInCarToTriggerTravel ||
                    ths.CurrentInteraction is TravelUtil.SitInCarToReturnHomeWithinHomeWorld))
            {
                child = false;
            }

            Vehicle vehicle = null;

            vehicle = ths.GetOwnedAndUsableVehicle(lot, true, child && !ths.IsHoldingAnything(), !GameUtils.IsInstalled(ProductVersion.EP4), allowUFO);

            if (vehicle == null || vehicle.HasBeenDestroyed)
            {
                if (canDrive)
                {
                    if (ths.SimDescription == null)
                    {
                        return(null);
                    }

                    if (child)
                    {
                        vehicle = Vehicle_CreateTaxiBicycle(ths.SimDescription.Child);
                    }
                    else if (ths.SimDescription.CanDrive && ths.IsHoldingAnything())
                    {
                        IGameObject gameObject = (!GameUtils.IsInstalled(ProductVersion.EP11) ||
                                                  GameUtils.GetCurrentWorld() != WorldName.FutureWorld) ?
                                                 GlobalFunctions.CreateObjectOutOfWorld(RandomUtil.CoinFlip() ?
                                                                                        "CarUsed2" : "CarSedan", ProductVersion.BaseGame, null, null)
                            : GlobalFunctions.CreateObjectOutOfWorld(RandomUtil.CoinFlip() ? "HoverCarUsed"
                            : "HoverCarExpensive", ProductVersion.EP11, null, null);

                        CarOwnable carOwnable = gameObject as CarOwnable;
                        if (carOwnable != null)
                        {
                            Lot       lotHome   = ths.LotHome;
                            Household household = ths.Household;

                            if (lotHome != null && household != null && !household.IsServiceNpcHousehold)
                            {
                                int cost = carOwnable.Cost;
                                if (ths.FamilyFunds >= cost)
                                {
                                    ths.ModifyFunds(-cost);
                                }
                                else
                                {
                                    household.UnpaidBills += cost;
                                }
                            }

                            carOwnable.GeneratedOwnableForNpc = (lotHome == null);
                            carOwnable.DestroyOnRelease       = (lotHome == null);
                            carOwnable.LotHome = lotHome;

                            vehicle = carOwnable;
                        }
                        else if (gameObject != null)
                        {
                            gameObject.Destroy();
                            vehicle = null;
                        }
                    }
                    else
                    {
                        try
                        {
                            if (CarNpcManager.Singleton == null)
                            {
                                throw new NullReferenceException("CarNpcManager.Singleton == null");
                            }
                            vehicle = CarNpcManager.Singleton.CreateNpcCar(CarNpcManager.NpcCars.Taxi);
                        }
                        catch (ResetException)
                        {
                            throw;
                        }
                        catch (Exception) { }
                    }
                }
                else
                {
                    if (ths.IsHoldingAnything())
                    {
                        return(null);
                    }
                    vehicle = Vehicle_CreateTaxiBicycle(ths.SimDescription.Child);
                }
            }

            if (vehicle == null || vehicle.HasBeenDestroyed)
            {
                if (child && !ths.IsHoldingAnything() && ths.SimDescription != null)
                {
                    vehicle = Vehicle_CreateTaxiBicycle(ths.SimDescription.Child);
                }
                else if (CarNpcManager.Singleton != null)
                {
                    vehicle = CarNpcManager.Singleton.CreateNpcCar(CarNpcManager.NpcCars.Taxi);
                }
            }
            return(vehicle);
        }
Exemplo n.º 9
0
        public ActionResult NM_PerformAction()
        {
            if (dontCall)
            {
                return(ActionResult.Continue);
            }

            Vehicle vehicle = null;

            try
            {
                var simRoutingComponentx = mRoutingSim.SimRoutingComponent;

                mRoutingSim.PopHoverboardPostureIfNecessary();

                simRoutingComponentx.DisallowBeingPushed = true;
                simRoutingComponentx.TriggerOnCarSequenceStartedEvent();

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

                Lot lot = (mOriginalRoute == null) ? mRoutingSim.LotCurrent : LotManager.GetLotAtPoint(mOriginalRoute.GetOriginalStartPoint());
                vehicle = Sim_GetVehicle(mRoutingSim, lot, GameUtils.IsInstalled(ProductVersion.EP8));
                if (vehicle == null || vehicle.HasBeenDestroyed)
                {
                    AddFailureExplanation(FailureExplanation.VehicleSequenceFailure);
                    return(ActionResult.Terminate);
                }


                mOriginalRoute.SetOption(Route.RouteOption.EnableUFOPlanning, vehicle is CarUFO);
                Household household = mRoutingSim.Household;
                if (household != null)
                {
                    CarOwnable carOwnable = vehicle as CarOwnable;
                    if (carOwnable != null && carOwnable.GeneratedOwnableForNpc)
                    {
                        Lot lotHome = household.LotHome;
                        if (lotHome != null)
                        {
                            int cost = carOwnable.Cost;
                            if (household.FamilyFunds >= cost)
                            {
                                household.ModifyFamilyFunds(-cost);
                            }
                            else
                            {
                                household.UnpaidBills += cost;
                            }
                            carOwnable.GeneratedOwnableForNpc = (lotHome == null);
                            carOwnable.DestroyOnRelease       = (lotHome == null);
                            carOwnable.LotHome = lotHome;
                        }
                    }
                }


                Vector3 pt;
                mOriginalRoute.GetSegmentStartPoint(0u, out pt);
                Vector3 dir;
                mOriginalRoute.GetSegmentStartDirection(0u, out dir);

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

                vehicle.PlaceAt(pt, dir, mRoutingSim);

                if (vehicle is Bicycle && mRoutingSim.Posture.Satisfies(CommodityKind.CarryingObject, null))
                {
                    InteractionInstance standingTransition = mRoutingSim.Posture.GetStandingTransition();
                    if (standingTransition != null)
                    {
                        standingTransition.RunInteraction();
                    }
                }

                if (GameUtils.IsInstalled(ProductVersion.EP9))
                {
                    mRoutingSim.PopBackpackPostureIfNecessary();
                    if (mRoutingSim.SimDescription.IsPlantSim)
                    {
                        (mRoutingSim.RoutingComponent as SimRoutingComponent).StopPlantSimRoutingVFX();
                    }
                }

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

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

                mRoutingSim.FadeIn(true, 0.5f);

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

                simRoutingComponentx.ClearPush();

                var followSubPathRouteAction = new VehicleFollowSubPathRouteAction(vehicle, mOriginalRoute);
                followSubPathRouteAction.AssociatedSim = mRoutingSim;

                mRoutingSim.RoutingComponent.InsertRouteActionAfter(this, followSubPathRouteAction);

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