Пример #1
0
        // this needs to be updated to use the cleaner ICreationData interface
        public static string CreateAndReturnRandomFilter(string callingNamespace, IMiniSimDescription actor, List <string> forbiddenCrit, Dictionary <string, string> forbiddenOptions, int[] minMaxCrit, Dictionary <string, int[]> minMaxOptions)
        {
            List <SimSelection.ICriteria> validCriteria = new List <SimSelection.ICriteria>();

            foreach (SimSelection.ICriteria crit in SelectionOption.List)
            {
                if (!forbiddenCrit.Contains(crit.Name))
                {
                    validCriteria.Add(crit);
                }
            }

            if (validCriteria.Count == 0)
            {
                return(string.Empty);
            }

            if (actor == null && PlumbBob.SelectedActor != null)
            {
                actor = PlumbBob.SelectedActor.SimDescription.GetMiniSimDescription();
            }

            List <IMiniSimDescription> picks = new List <IMiniSimDescription>();

            foreach (List <IMiniSimDescription> sims in SimListing.AllSims(actor, false).Values)
            {
                foreach (IMiniSimDescription sim in sims)
                {
                    if (SimSelection.IsSpecial(sim))
                    {
                        continue;
                    }

                    picks.Add(sim);
                }
            }

            if (picks.Count == 0)
            {
                return(string.Empty);
            }

            if (minMaxCrit.Length < 2)
            {
                minMaxCrit[0] = 1;
                minMaxCrit[1] = 2;
            }

            int critpicks = RandomUtil.GetInt(minMaxCrit[0], minMaxCrit[1]);

            Common.Notify("Picking " + critpicks + " from " + validCriteria.Count);

            List <SimSelection.ICriteria> finalPicks = new List <SimSelection.ICriteria>();

            if (validCriteria.Count == critpicks)
            {
                finalPicks = validCriteria;
            }
            else
            {
                while (true)
                {
                    if (validCriteria.Count < critpicks && finalPicks.Count == validCriteria.Count)
                    {
                        break;
                    }

                    if (finalPicks.Count < critpicks)
                    {
                        SimSelection.ICriteria critpick = RandomUtil.GetRandomObjectFromList <SimSelection.ICriteria>(validCriteria);
                        if (!finalPicks.Contains(critpick))
                        {
                            finalPicks.Add(critpick);
                        }
                        continue;
                    }

                    break;
                }
            }

            bool failed = false;

            foreach (SimSelection.ICriteria crit2 in finalPicks)
            {
                Common.Notify("Picked " + crit2.Name);
                List <ICommonOptionItem> finalOpts = new List <ICommonOptionItem>();
                List <ICommonOptionItem> opts      = crit2.GetOptions(actor, finalPicks, picks);

                if (opts != null && opts.Count > 0)
                {
                    Common.Notify("Opts not null");
                    int optpicks = 0;

                    if (minMaxOptions.ContainsKey(crit2.Name) && minMaxOptions[crit2.Name].Length > 1)
                    {
                        optpicks = RandomUtil.GetInt(minMaxOptions[crit2.Name][0], minMaxOptions[crit2.Name][1]);
                    }
                    else
                    {
                        optpicks = 1;
                    }

                    Common.Notify("Picking " + optpicks + " from " + opts.Count);

                    if (opts.Count == optpicks)
                    {
                        finalOpts = opts;
                    }
                    else
                    {
                        while (true)
                        {
                            if (opts.Count < optpicks && finalOpts.Count == opts.Count)
                            {
                                break;
                            }

                            if (finalOpts.Count < optpicks)
                            {
                                ICommonOptionItem opt     = RandomUtil.GetRandomObjectFromList <ICommonOptionItem>(opts);
                                ITestableOption   testOpt = opt as ITestableOption;
                                if (!finalOpts.Contains(opt) && (!forbiddenOptions.ContainsKey(crit2.Name) || (testOpt != null && !forbiddenOptions[crit2.Name].Contains(testOpt.OptionName))))
                                {
                                    // test if this gives me the name, if so we can revert the changes to ITestableOption
                                    Common.Notify("Picked " + opt.Name);
                                    finalOpts.Add(opt);
                                }
                                continue;
                            }
                            break;
                        }
                    }

                    crit2.SetOptions(finalOpts);
                }
                else
                {
                    failed = true;
                    break;
                }
            }

            if (failed)
            {
                Common.Notify("Failed");
                return(string.Empty);
            }

            string filterName;

            while (true)
            {
                filterName = callingNamespace + ".SimAttractionFilter" + RandomGen.NextDouble();

                if (GetFilter(filterName) != null)
                {
                    continue;
                }
                else
                {
                    MasterController.Settings.mFilters.Add(new SavedFilter(filterName, finalPicks));
                    break;
                }
            }

            Common.Notify("Set and returning filter " + filterName);

            return(filterName);
        }
Пример #2
0
        // settled on a seperate interface within attraction profiles to set certain criteria as random which will use the above to pull the options allowing users to allow/disallow criteria. Problems begin with localization of values when handling them as strings. I'll deal with that later.
        public static string CreateFilterWithCriteria(string callingNamespace, IMiniSimDescription actor, List <SimSelection.ICriteriaCreation> creationData)
        {
            if (creationData == null)
            {
                Common.Notify("Creation Data null");
                return(string.Empty);
            }

            if (actor == null && PlumbBob.SelectedActor != null)
            {
                actor = PlumbBob.SelectedActor.SimDescription.GetMiniSimDescription();
            }

            List <IMiniSimDescription> picks = new List <IMiniSimDescription>();

            foreach (List <IMiniSimDescription> sims in SimListing.AllSims(actor, false).Values)
            {
                foreach (IMiniSimDescription sim in sims)
                {
                    if (SimSelection.IsSpecial(sim))
                    {
                        continue;
                    }

                    picks.Add(sim);
                }
            }

            List <SimSelection.ICriteria> finalCriteria = new List <SimSelection.ICriteria>();

            foreach (SimSelection.ICriteriaCreation cData in creationData)
            {
                List <SimSelection.ICriteria> validCriteria = new List <SimSelection.ICriteria>();

                List <string> forbiddenCrit = new List <string>();
                if (cData.RandomCriteria && cData.ForbiddenRandomCriteria != null)
                {
                    forbiddenCrit = cData.ForbiddenRandomCriteria;
                }

                foreach (SimSelection.ICriteria crit in SelectionOption.List)
                {
                    if (crit.Name == cData.CriteriaName)
                    {
                        validCriteria.Add(crit);
                        break;
                    }

                    if (!forbiddenCrit.Contains(crit.Name))
                    {
                        validCriteria.Add(crit);
                    }
                }

                SimSelection.ICriteria pickedCritera = null;
                if (validCriteria.Count == 1)
                {
                    pickedCritera = validCriteria[0];
                }
                else
                {
                    int loop = 0;
                    while (true)
                    {
                        if (loop > 4)
                        {
                            break;
                        }

                        pickedCritera = RandomUtil.GetRandomObjectFromList <SimSelection.ICriteria>(validCriteria);

                        if (finalCriteria.Contains(pickedCritera))
                        {
                            loop++;
                            continue;
                        }
                    }
                }

                if (pickedCritera == null)
                {
                    Common.Notify("pickedCriteria was null");
                    continue;
                }

                List <ICommonOptionItem> criteriaOptions = pickedCritera.GetOptions(actor, new List <SimSelection.ICriteria>(), picks);

                if (criteriaOptions == null || criteriaOptions.Count == 0)
                {
                    Common.Notify("criteriaOptions null or 0");
                    continue;
                }

                List <string> forbiddenOptions = new List <string>();
                if (cData.RandomOptions && cData.ForbiddenRandomOptions != null)
                {
                    forbiddenOptions = cData.ForbiddenRandomOptions;
                }

                List <ICommonOptionItem> finalOptions       = new List <ICommonOptionItem>();
                List <ICommonOptionItem> validRandomOptions = new List <ICommonOptionItem>();

                foreach (ICommonOptionItem opt in criteriaOptions)
                {
                    if (cData.CriteriaOptions != null && cData.CriteriaOptions.Contains(opt.Name) && !finalOptions.Contains(opt))
                    {
                        finalOptions.Add(opt);

                        if (validRandomOptions.Contains(opt))
                        {
                            validRandomOptions.Remove(opt);
                        }

                        continue;
                    }

                    if (cData.RandomOptions && !forbiddenOptions.Contains(opt.Name) && !finalOptions.Contains(opt))
                    {
                        validRandomOptions.Add(opt);
                    }
                }

                if (validRandomOptions.Count > 0)
                {
                    List <ICommonOptionItem> pickedRandomOptions = new List <ICommonOptionItem>();
                    if (cData.MinMaxRandomOptions != null || cData.MinMaxRandomOptions.Length == 2)
                    {
                        int numOpt = RandomUtil.GetInt(cData.MinMaxRandomOptions[0], cData.MinMaxRandomOptions[1]);

                        if (numOpt != 0)
                        {
                            while (true)
                            {
                                if (validRandomOptions.Count == 0 || pickedRandomOptions.Count == numOpt)
                                {
                                    break;
                                }

                                ICommonOptionItem opt = RandomUtil.GetRandomObjectFromList <ICommonOptionItem>(validRandomOptions);

                                if (opt != null)
                                {
                                    pickedRandomOptions.Add(opt);
                                    validRandomOptions.Remove(opt);
                                }
                            }
                        }

                        finalOptions.AddRange(pickedRandomOptions);
                    }
                }

                pickedCritera.SetOptions(finalOptions);

                finalCriteria.Add(pickedCritera);
            }

            if (finalCriteria.Count > 0)
            {
                string filterName;

                while (true)
                {
                    filterName = callingNamespace + ".SimAttractionFilter" + RandomGen.NextDouble();

                    if (GetFilter(filterName) != null)
                    {
                        continue;
                    }
                    else
                    {
                        MasterController.Settings.mFilters.Add(new SavedFilter(filterName, finalCriteria));
                        break;
                    }
                }

                return(filterName);
            }

            return(string.Empty);
        }