private List <PawnLayerOption> InitializeAlienAddonOptions(AlienRace race, AlienRaceBodyAddon addon) { if (addon.OptionCount == 0) { return(null); } List <PawnLayerOption> result = new List <PawnLayerOption>(); for (int i = 0; i < addon.OptionCount; i++) { PawnLayerOptionAlienAddon option = new PawnLayerOptionAlienAddon(); option.Label = "EdB.PC.Pawn.PawnLayer.AlienAddonOption".Translate(new object[] { i + 1 }); option.Index = i; result.Add(option); } return(result); }
protected AlienRace InitializeAlienRace(ThingDef raceDef) { try { object alienRaceObject = GetFieldValue(raceDef, raceDef, "alienRace"); if (alienRaceObject == null) { return(null); } object generalSettingsObject = GetFieldValue(raceDef, alienRaceObject, "generalSettings"); if (generalSettingsObject == null) { return(null); } object alienPartGeneratorObject = GetFieldValue(raceDef, generalSettingsObject, "alienPartGenerator"); if (alienPartGeneratorObject == null) { return(null); } System.Collections.ICollection graphicPathsCollection = GetFieldValueAsCollection(raceDef, alienRaceObject, "graphicPaths"); if (graphicPathsCollection == null) { return(null); } /* * Logger.Debug("GraphicsPaths for " + raceDef.defName + ":"); * if (graphicPathsCollection.Count > 0) { * foreach (object o in graphicPathsCollection) { * Logger.Debug(" GraphicsPath"); * Logger.Debug(" .body = " + GetFieldValueAsString(raceDef, o, "body")); * Logger.Debug(" .head = " + GetFieldValueAsString(raceDef, o, "head")); * System.Collections.ICollection lifeStagesCollections = GetFieldValueAsCollection(raceDef, o, "lifeStageDefs"); * } * } */ // We have enough to start putting together the result object, so we instantiate it now. AlienRace result = new AlienRace(); result.ThingDef = raceDef; //Logger.Debug("InitializeAlienRace: " + raceDef.defName); // Get the list of body types. System.Collections.ICollection alienBodyTypesCollection = GetFieldValueAsCollection(raceDef, alienPartGeneratorObject, "alienbodytypes"); if (alienBodyTypesCollection == null) { return(null); } List <BodyTypeDef> bodyTypes = new List <BodyTypeDef>(); //Logger.Debug("Body Types for " + raceDef.defName + ":"); if (alienBodyTypesCollection.Count > 0) { foreach (object o in alienBodyTypesCollection) { if (o.GetType() == typeof(BodyTypeDef)) { BodyTypeDef def = o as BodyTypeDef; //Logger.Debug(" - " + def.defName + ", " + def.LabelCap); bodyTypes.Add((BodyTypeDef)o); } } } else { //Logger.Debug(" none"); } result.BodyTypes = bodyTypes; // Determine if the alien races uses gender-specific heads. bool?useGenderedHeads = GetFieldValueAsBool(raceDef, alienPartGeneratorObject, "useGenderedHeads"); if (useGenderedHeads == null) { return(null); } result.GenderSpecificHeads = useGenderedHeads.Value; // Get the list of crown types. System.Collections.ICollection alienCrownTypesCollection = GetFieldValueAsCollection(raceDef, alienPartGeneratorObject, "aliencrowntypes"); if (alienCrownTypesCollection == null) { return(null); } List <string> crownTypes = new List <string>(); //Logger.Debug("Crown Types for " + raceDef.defName + ":"); if (alienCrownTypesCollection.Count > 0) { foreach (object o in alienCrownTypesCollection) { string crownTypeString = o as string; if (crownTypeString != null) { crownTypes.Add(crownTypeString); //Logger.Debug(" " + crownTypeString); } } } result.CrownTypes = crownTypes; // Go through the graphics paths and find the heads path. // TODO: What is this? string graphicsPathForHeads = null; string graphicsPathForBodyTypes = null; foreach (var graphicsPath in graphicPathsCollection) { System.Collections.ICollection lifeStageCollection = GetFieldValueAsCollection(raceDef, graphicsPath, "lifeStageDefs"); if (lifeStageCollection == null || lifeStageCollection.Count == 0) { string headsPath = GetFieldValueAsString(raceDef, graphicsPath, "head"); string bodyTypesPath = GetFieldValueAsString(raceDef, graphicsPath, "body"); if (headsPath != null) { graphicsPathForHeads = headsPath; } if (bodyTypesPath != null) { graphicsPathForBodyTypes = bodyTypesPath; } } } result.GraphicsPathForHeads = graphicsPathForHeads; result.GraphicsPathForBodyTypes = graphicsPathForBodyTypes; // Figure out colors. ColorGenerator primaryGenerator = FindPrimarySkinColorGenerator(raceDef, alienPartGeneratorObject); ColorGenerator secondaryGenerator = FindSecondarySkinColorGenerator(raceDef, alienPartGeneratorObject); result.UseMelaninLevels = true; result.ChangeableColor = true; result.HasSecondaryColor = false; if (primaryGenerator != null) { if (primaryGenerator.GetType().Name != "ColorGenerator_SkinColorMelanin") { if (primaryGenerator != null) { result.UseMelaninLevels = false; result.PrimaryColors = primaryGenerator.GetColorList(); } else { result.PrimaryColors = new List <Color>(); } if (secondaryGenerator != null) { result.HasSecondaryColor = true; result.SecondaryColors = secondaryGenerator.GetColorList(); } else { result.SecondaryColors = new List <Color>(); } } } // Hair properties. object hairSettingsValue = GetFieldValue(raceDef, alienRaceObject, "hairSettings", true); result.HasHair = true; if (hairSettingsValue != null) { bool?hasHair = GetFieldValueAsBool(raceDef, hairSettingsValue, "hasHair"); if (hasHair != null) { result.HasHair = hasHair.Value; } var hairTagCollection = GetFieldValueAsCollection(raceDef, hairSettingsValue, "hairTags"); if (hairTagCollection != null) { var hairTags = new HashSet <string>(); foreach (var o in hairTagCollection) { string tag = o as string; if (tag != null) { hairTags.Add(tag); } } if (hairTags.Count > 0) { result.HairTags = hairTags; } } } ColorGenerator hairColorGenerator = FindPrimaryColorGenerator(raceDef, alienPartGeneratorObject, "hair"); if (hairColorGenerator != null) { result.HairColors = hairColorGenerator.GetColorList(); } else { result.HairColors = null; } // Apparel properties. object restrictionSettingsValue = GetFieldValue(raceDef, alienRaceObject, "raceRestriction", true); result.RestrictedApparelOnly = false; if (restrictionSettingsValue != null) { bool?restrictedApparelOnly = GetFieldValueAsBool(raceDef, restrictionSettingsValue, "onlyUseRaceRestrictedApparel"); if (restrictedApparelOnly != null) { result.RestrictedApparelOnly = restrictedApparelOnly.Value; } var restrictedApparelCollection = GetFieldValueAsCollection(raceDef, restrictionSettingsValue, "apparelList"); if (restrictedApparelCollection != null) { var apparel = new HashSet <string>(); foreach (var o in restrictedApparelCollection) { string defName = o as string; if (defName != null) { apparel.Add(defName); } } if (apparel.Count > 0) { result.RestrictedApparel = apparel; } } } var bodyAddonsCollection = GetFieldValueAsCollection(raceDef, alienPartGeneratorObject, "bodyAddons"); if (bodyAddonsCollection != null) { var addons = new List <AlienRaceBodyAddon>(); int index = -1; foreach (var o in bodyAddonsCollection) { index++; AlienRaceBodyAddon addon = new AlienRaceBodyAddon(); string path = GetFieldValueAsString(raceDef, o, "path"); if (path == null) { Logger.Warning("Failed to get path for body add-on for alien race: " + raceDef.defName); continue; } addon.Path = path; int?variantCount = GetFieldValueAsInt(raceDef, o, "variantCount"); if (variantCount == null) { Logger.Warning("Failed to get variant count for body add-on for alien race: " + raceDef.defName); continue; } addon.OptionCount = variantCount.Value; string name = ParseAddonName(path); if (name == null) { Logger.Warning("Failed to parse a name from its path for body add-on for alien race: " + raceDef.defName); continue; } addon.Name = name; addon.VariantIndex = index; addons.Add(addon); } result.addons = addons; } return(result); } catch (Exception e) { throw new InitializationException("Failed to initialize an alien race: " + raceDef.defName, e); } }