public Lot FindLot(IScoringGenerator stats, ICollection <SimDescription> sims, int maximumLoan, FindLotFlags flags, LotPriceCheck inPriceRange) { stats.IncStat("FindLot"); Dictionary <SimDescription, bool> lookup = new Dictionary <SimDescription, bool> (); Dictionary <Household, bool> homes = new Dictionary <Household, bool>(); Dictionary <ulong, int> castes = new Dictionary <ulong, int>(); int simCount = 0; bool allowRentable = true; if (sims != null) { foreach (SimDescription sim in sims) { if (lookup.ContainsKey(sim)) { continue; } lookup.Add(sim, true); if (!Money.AllowRent(stats, sim)) { allowRentable = false; } simCount++; foreach (CasteOptions caste in GetData(sim).Castes) { int count; if (castes.TryGetValue(caste.ID, out count)) { castes[caste.ID] = count + 1; } else { castes[caste.ID] = 1; } } if (SimTypes.IsSpecial(sim)) { continue; } if (sim.Household == null) { continue; } homes[sim.Household] = true; } } int currentLotCost = 0; int availableFunds = maximumLoan; foreach (Household home in homes.Keys) { bool allMoving = true; foreach (SimDescription sim in home.AllSimDescriptions) { if (!lookup.ContainsKey(sim)) { allMoving = false; break; } } if (allMoving) { if (home.LotHome == null) { availableFunds += home.NetWorth(); } else if (GetValue <IsAncestralOption, bool>(home)) { stats.IncStat("FindLot: Ancestral Fail"); return(null); } else { currentLotCost += GetLotCost(home.LotHome); availableFunds += home.FamilyFunds + GetLotCost(home.LotHome); availableFunds -= CalculateVehicleCost(home.LotHome); } } else { availableFunds += home.FamilyFunds; } } flags |= FindLotFlags.InspectCareerItems; stats.AddStat("Available Funds", availableFunds); List <Lot> choices = new List <Lot>(); foreach (Lot lot in LotManager.AllLots) { string reason = HouseholdsEx.IsValidResidentialLot(lot); if (!string.IsNullOrEmpty(reason)) { stats.IncStat("Find Lot: " + reason); } else if (!Allow(stats, lot, sims, flags, allowRentable)) { continue; } else { stats.AddStat("Lot Cost", GetLotCost(lot)); if ((inPriceRange == null) || (inPriceRange(stats, lot, currentLotCost, availableFunds) != CheckResult.Failure)) { choices.Add(lot); } } } if (choices.Count == 0) { stats.IncStat("Find Lot: Failure"); return(null); } else if ((flags & FindLotFlags.CheapestHome) == FindLotFlags.CheapestHome) { choices.Sort(new Comparison <Lot>(HouseholdsEx.SortByCost)); return(choices[0]); } else { return(RandomUtil.GetRandomObjectFromList(choices)); } }
protected bool PassesHomeInspection(Common.IStatGenerator stats, Lot lot, ICollection <HomeInspection.Reason> existingResults, IEnumerable <HomeInspection.Result> results, FindLotFlags flags) { if (lot == null) { return(false); } Lot.LotMetrics metrics = new Lot.LotMetrics(); lot.GetLotMetrics(ref metrics); if (metrics.FridgeCount == 0) { stats.IncStat("Home Inspection: No Fridge"); return(false); } if (((flags & FindLotFlags.Inspect) == FindLotFlags.Inspect) && (GetValue <RigorousNewHomeOption, bool> ())) { bool failure = false; foreach (HomeInspection.Result result in results) { switch (result.mReason) { case HomeInspection.Reason.NoDouble: continue; case HomeInspection.Reason.TooFewDouble: if (!GetValue <DoubleBedInspectionOption, bool>()) { stats.IncStat("Home Inspection: " + result.mReason + " Disabled"); continue; } break; case HomeInspection.Reason.TooFewCribs: if ((!GetValue <CribInspectionOption, bool>())) { stats.IncStat("Home Inspection: " + result.mReason + " Disabled"); continue; } else if (existingResults.Contains(HomeInspection.Reason.TooFewCribs)) { stats.IncStat("Home Inspection: " + result.mReason + " Existing Infraction"); continue; } break; case HomeInspection.Reason.TooFewBeds: if (GetValue <DoubleBedInspectionOption, bool>()) { stats.IncStat("Home Inspection: " + result.mReason + " Disabled"); continue; } break; case HomeInspection.Reason.TooFewStalls: if (result.mExisting > 0) { stats.IncStat("Home Inspection: " + result.mReason + " At Least One"); continue; } // Never move horses to a lot that has no stalls break; case HomeInspection.Reason.TooFewPetBeds: if (((flags & FindLotFlags.InspectPets) != FindLotFlags.InspectPets)) { stats.IncStat("Home Inspection: " + result.mReason + " Not Checking"); continue; } else if (!GetValue <PetInspectionOption, bool>()) { stats.IncStat("Home Inspection: " + result.mReason + " Disabled"); continue; } else if (existingResults.Contains(HomeInspection.Reason.TooFewPetBeds)) { stats.IncStat("Home Inspection: " + result.mReason + " Existing Infraction"); continue; } break; } stats.AddStat("Home Inspection: " + result.mReason + " Existing", result.mExisting); stats.AddStat("Home Inspection: " + result.mReason + " Required", result.mRequired); failure = true; } if (failure) { return(false); } } return(true); }
public bool PassesHomeInspection(Common.IStatGenerator stats, Lot lot, ICollection <SimDescription> newMembers, ICollection <SimDescription> existing, FindLotFlags flags) { if (lot == null) { return(false); } List <SimDescription> members = new List <SimDescription> (); members.AddRange(newMembers); members.AddRange(existing); return(PassesHomeInspection(stats, lot, members, flags)); }
public bool PassesHomeInspection(Common.IStatGenerator stats, Lot lot, ICollection <SimDescription> sims, FindLotFlags flags) { if (lot == null) { return(false); } Dictionary <HomeInspection.Reason, bool> existingResults = new Dictionary <HomeInspection.Reason, bool>(); if (sims != null) { Dictionary <Household, bool> houses = new Dictionary <Household, bool>(); foreach (SimDescription sim in sims) { if ((sim.Household != null) && (!houses.ContainsKey(sim.Household))) { houses.Add(sim.Household, true); if (sim.LotHome != null) { foreach (HomeInspection.Result result in new HomeInspection(sim.LotHome).Satisfies(HouseholdsEx.All(sim.Household))) { existingResults[result.mReason] = true; } } } if (sim.Occupation != null) { if (((flags & FindLotFlags.InspectCareerItems) == FindLotFlags.InspectCareerItems) && (GetValue <CareerObjectInspectionOption, bool>())) { DreamJob job = ManagerCareer.GetDreamJob(sim.Occupation.Guid); if (job != null) { if (!job.Satisfies(Careers, sim, lot, true)) { stats.IncStat("Career Inspection Fail"); return(false); } } } } } } return(PassesHomeInspection(stats, lot, existingResults.Keys, new HomeInspection(lot).Satisfies(sims), flags)); }
public bool Allow(Common.IStatGenerator stats, Lot lot, ICollection <SimDescription> sims, FindLotFlags flags, bool allowRentable) { LotOptions lotData = Options.GetLotOptions(lot); if (UnchartedIslandMarker.IsUnchartedIsland(lot)) { stats.IncStat("Find Lot: Uncharted"); return(false); } else if (!lotData.GetValue <AllowLotUseOption, bool>()) { stats.IncStat("Find Lot: Lot Allow Denied"); return(false); } else if (!PassesHomeInspection(stats, lot, sims, flags)) { stats.IncStat("Find Lot: Home Inspection"); return(false); } if (!allowRentable) { if (Money.GetDeedOwner(lot) != null) { return(false); } } return(lotData.AllowCastes(stats, sims)); }