Exemplo n.º 1
0
        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));
            }
        }