protected void InitializeHediffGiverInjuries(OptionsHealth options, HediffGiver giver) { if (giver == null) { Logger.Warning("Could not add injury/health condition because a HediffGiver was null"); return; } if (giver.hediff == null) { Logger.Warning("Could not add injury/health condition because the hediff for " + giver.GetType().FullName + " was null"); return; } InjuryOption option = new InjuryOption(); option.HediffDef = giver.hediff; option.Label = giver.hediff.LabelCap; option.Giver = giver; if (giver.partsToAffect == null) { option.WholeBody = true; } if (giver.canAffectAnyLivePart) { option.WholeBody = false; } if (giver.partsToAffect != null && !giver.canAffectAnyLivePart) { List <BodyPartDef> validParts = new List <BodyPartDef>(); foreach (var def in giver.partsToAffect) { List <UniqueBodyPart> parts = options.FindBodyPartsForDef(def); if (parts != null) { validParts.Add(def); } } if (validParts.Count == 0) { return; } else { option.ValidParts = validParts; } } options.AddInjury(option); }
protected void InitializeHediffGiverInjuries(OptionsHealth options, HediffGiver giver) { InjuryOption option = new InjuryOption(); option.HediffDef = giver.hediff; option.Label = giver.hediff.LabelCap; option.Giver = giver; if (giver.partsToAffect == null) { option.WholeBody = true; } if (giver.canAffectAnyLivePart) { option.WholeBody = false; } if (giver.partsToAffect != null && !giver.canAffectAnyLivePart) { List <BodyPartDef> validParts = new List <BodyPartDef>(); foreach (var def in giver.partsToAffect) { List <UniqueBodyPart> parts = options.FindBodyPartsForDef(def); if (parts != null) { validParts.Add(def); } } if (validParts.Count == 0) { return; } else { option.ValidParts = validParts; } } options.AddInjury(option); }
protected void InitializeInjuryOptions(OptionsHealth options, ThingDef pawnThingDef) { HashSet <HediffDef> addedDefs = new HashSet <HediffDef>(); // Go through all of the hediff giver sets for the pawn's race and intialize injuries from // each giver. if (pawnThingDef.race.hediffGiverSets != null) { foreach (var giverSetDef in pawnThingDef.race.hediffGiverSets) { foreach (var giver in giverSetDef.hediffGivers) { InitializeHediffGiverInjuries(options, giver); } } } // Go through all hediff stages, looking for hediff givers. foreach (var hd in DefDatabase <HediffDef> .AllDefs) { if (hd.stages != null) { foreach (var stage in hd.stages) { if (stage.hediffGivers != null) { foreach (var giver in stage.hediffGivers) { InitializeHediffGiverInjuries(options, giver); } } } } } // Go through all of the chemical defs, looking for hediff givers. foreach (var chemicalDef in DefDatabase <ChemicalDef> .AllDefs) { if (chemicalDef.onGeneratedAddictedEvents != null) { foreach (var giver in chemicalDef.onGeneratedAddictedEvents) { InitializeHediffGiverInjuries(options, giver); } } } // Get all of the hediffs that can be added via the "forced hediff" scenario part and // add them to a hash set so that we can quickly look them up. ScenPart_ForcedHediff scenPart = new ScenPart_ForcedHediff(); IEnumerable <HediffDef> scenPartDefs = Reflection.ScenPart_ForcedHediff.PossibleHediffs(scenPart); HashSet <HediffDef> scenPartDefSet = new HashSet <HediffDef>(scenPartDefs); // Add injury options. foreach (var hd in DefDatabase <HediffDef> .AllDefs) { // TODO: Missing body part seems to be a special case. The hediff giver doesn't itself remove // limbs, so disable it until we can add special-case handling. if (hd.defName == "MissingBodyPart") { continue; } // Filter out defs that were already added via the hediff giver sets. if (addedDefs.Contains(hd)) { continue; } // Filter out implants. if (hd.hediffClass == typeof(Hediff_AddedPart)) { continue; } // If it's an old injury, use the old injury properties to get the label. HediffCompProperties p = hd.CompPropsFor(typeof(HediffComp_GetsPermanent)); HediffCompProperties_GetsPermanent getsPermanentProperties = p as HediffCompProperties_GetsPermanent; String label; if (getsPermanentProperties != null) { if (getsPermanentProperties.permanentLabel != null) { label = getsPermanentProperties.permanentLabel.CapitalizeFirst(); } else { Log.Warning("Prepare Carefully could not find label for old injury: " + hd.defName); continue; } } // If it's not an old injury, make sure it's one of the available hediffs that can // be added via ScenPart_ForcedHediff. If it's not, filter it out. else { if (!scenPartDefSet.Contains(hd)) { continue; } label = hd.LabelCap; } // Add the injury option.. InjuryOption option = new InjuryOption(); option.HediffDef = hd; option.Label = label; if (getsPermanentProperties != null) { option.IsOldInjury = true; } else { option.ValidParts = new List <BodyPartDef>(); } options.AddInjury(option); } // Disambiguate duplicate injury labels. HashSet <string> labels = new HashSet <string>(); HashSet <string> duplicateLabels = new HashSet <string>(); foreach (var option in options.InjuryOptions) { if (labels.Contains(option.Label)) { duplicateLabels.Add(option.Label); } else { labels.Add(option.Label); } } foreach (var option in options.InjuryOptions) { HediffCompProperties p = option.HediffDef.CompPropsFor(typeof(HediffComp_GetsPermanent)); HediffCompProperties_GetsPermanent props = p as HediffCompProperties_GetsPermanent; if (props != null) { if (duplicateLabels.Contains(option.Label)) { string label = "EdB.PC.Dialog.Injury.OldInjury.Label".Translate(props.permanentLabel.CapitalizeFirst(), option.HediffDef.LabelCap); option.Label = label; } } } }