private ThoughtState CalculateAlienBP([NotNull] Pawn pawn, [NotNull] MutationTracker tracker, [NotNull] RaceMutationSettingsExtension raceExt) { float inf = tracker.TotalInfluence; foreach (Hediff_AddedMutation mutation in tracker.AllMutations) { var isNatural = false; foreach (IRaceMutationRetriever retriever in raceExt.mutationRetrievers) { if (retriever.CanGenerate(mutation.Def)) { isNatural = true; break; } } if (isNatural) { inf -= 1; } } float nInf = Mathf.Max(inf, 0) / MorphUtilities.GetMaxInfluenceOfRace(pawn.def); int n = Mathf.FloorToInt(nInf * def.stages.Count); n = Mathf.Clamp(n, 0, def.stages.Count - 1); return(ThoughtState.ActiveAtStage(n)); }
/// <summary> /// return the thought state for the given pawn /// </summary> /// <param name="p"></param> /// <returns></returns> protected override ThoughtState CurrentStateInternal(Pawn p) { if (!def.IsValidFor(p)) { return(false); } MutationTracker mutTracker = p.GetMutationTracker(); if (mutTracker == null) { return(false); } if (!mutTracker.AllMutations.Any()) { return(false); } var morph = p.def.GetMorphOfRace(); var influence = morph == null ? MorphUtilities.GetMaxInfluenceOfRace(p.def) : morph.GetMaxInfluenceForBody(p.RaceProps.body); var nInfluence = mutTracker.TotalInfluence / influence; var idx = Mathf.Clamp(nInfluence * def.stages.Count, 0, def.stages.Count - 1); return(ThoughtState.ActiveAtStage(Mathf.FloorToInt(idx))); }
private static void GetPawnsNewInfluence() { var wDict = new Dictionary <AnimalClassBase, float>(); var mutations = new List <Hediff_AddedMutation>(); var strings = new List <string>(); foreach (Pawn pawn in PawnsFinder.AllMaps_FreeColonists) { mutations.Clear(); mutations.AddRange(pawn.health.hediffSet.hediffs.OfType <Hediff_AddedMutation>()); float maxInf = MorphUtilities.GetMaxInfluenceOfRace(pawn.def); AnimalClassUtilities.FillInfluenceDict(mutations, wDict); if (wDict.Count == 0) { continue; } //now build the log message entry var builder = new StringBuilder(); builder.AppendLine($"{pawn.Name}:"); foreach (KeyValuePair <AnimalClassBase, float> kvp in wDict) { var def = (Def)kvp.Key; builder.AppendLine($"\t{def.label}:{(kvp.Value / maxInf).ToStringPercent()}"); } strings.Add(builder.ToString()); } string msg = strings.Join(delimiter: "\n----------------------------\n"); Log.Message(msg); }
static void GetRaceMaxInfluence() { StringBuilder builder = new StringBuilder(); foreach (ThingDef thingDef in DefDatabase <ThingDef> .AllDefs.Where(t => t.race?.body != null)) { builder.AppendLine($"{thingDef.defName}/{thingDef.label}={MorphUtilities.GetMaxInfluenceOfRace(thingDef)}"); } Log.Message(builder.ToString()); }
static void GetMissingSlotsPerMorph() { var allPossibleSites = DefDatabase <MutationDef> .AllDefs.SelectMany(m => m.GetAllMutationSites(BodyDefOf.Human)) .Distinct() .ToList(); List <MutationSite> scratchList = new List <MutationSite>(); List <MutationSite> missingScratch = new List <MutationSite>(); StringBuilder builder = new StringBuilder(); foreach (MorphDef morphDef in MorphDef.AllDefs) { var allMorphSites = morphDef.AllAssociatedMutations.SelectMany(m => m.GetAllMutationSites(BodyDefOf.Human)) .Distinct(); scratchList.Clear(); scratchList.AddRange(allMorphSites); missingScratch.Clear(); var missing = allPossibleSites.Where(m => !scratchList.Contains(m)); missingScratch.AddRange(missing); if (missingScratch.Count == 0) { builder.AppendLine($"{morphDef.defName} has all possible mutations"); } else { float maxInfluence = ((float)scratchList.Count) / MorphUtilities.GetMaxInfluenceOfRace(ThingDefOf.Human); builder.AppendLine($"{morphDef.defName}: {nameof(maxInfluence)}={maxInfluence.ToStringByStyle(ToStringStyle.PercentOne)}"); var grouping = missingScratch.GroupBy(g => g.Layer, g => g.Record); foreach (var group in grouping) { builder.AppendLine($"-\t{group.Key}: [{group.Select(s => s.def).Distinct().Join(s => s?.defName ?? "NULL")}]"); } } } Log.Message(builder.ToString()); }
private static void MaximumMutationPointsForHumans() { Log.Message(MorphUtilities.GetMaxInfluenceOfRace(ThingDefOf.Human).ToString()); }
void GetMutationInfo(Pawn pawn) { var tracker = pawn?.GetMutationTracker(); if (tracker == null) { Log.Message($"no tracker on {pawn?.Name?.ToStringFull ?? "NULL"}"); return; } StringBuilder builder = new StringBuilder(); builder.AppendLine($"---{pawn.Name}---"); builder.AppendLine("---Raw Influence---"); foreach (KeyValuePair <AnimalClassBase, float> kvp in tracker) { builder.AppendLine($"{kvp.Key.Label}:{kvp.Value}"); } builder.AppendLine($"---Total={tracker.TotalInfluence} N:{tracker.TotalNormalizedInfluence} NN:{tracker.TotalInfluence/MorphUtilities.GetMaxInfluenceOfRace(pawn.def)}---"); builder.AppendLine($"---HighestInfluence={tracker.HighestInfluence?.Label ?? "NULL"}---"); Log.Message(builder.ToString()); }