protected override bool Allow(MiniSimDescription me, IMiniSimDescription actor) { if (mFilter == null) { return(false); } foreach (SimSelection.ICriteria item in mFilter.mElements) { if (item.CanBeRandomCriteria && RandomUtil.CoinFlip()) { continue; } ITestableOption testable = item as ITestableOption; if (testable == null) { continue; } if (!testable.Test(me, false, actor)) { return(false); } } return(true); }
// use mc to define criteria layout, no hard set filter matching as with go here. // seperate menu to define score hit or miss values. Hit/miss can be negative or pos // way to prevent scores from getting out of hand or user overwhelment by providing general "matters a bit", "matters a lot" values that // hard set generic values (which can be customized) // fiter update by testing if sim matches values and apply the hit miss public static string GetLocalizedFilterCriteria(List <string> filters) { string result = string.Empty; foreach (string filter in filters) { SavedFilter filter2 = GetFilter(filter); if (filter2 != null) { foreach (SimSelection.ICriteria crit in filter2.Elements) { ITestableOption option = crit as ITestableOption; result += crit.Name + Common.NewLine; if (option != null) { // this is returning all because OptionName is a loop of the options internally result += option.OptionName + Common.NewLine; } } } } return(result); }
// 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); }