コード例 #1
0
        internal int TryApplyPatch()
        {
            try
            {
                if (foods == null)
                {
                    return(0);
                }

                int loadedElements = 0;

                if (LoadedModManager.RunningMods.Any((ModContentPack arg) => arg.PackageId == requiredMod || arg.Name == requiredMod))
                {
                    loaded = true;
                    foreach (ComptabilityElement current in foods)
                    {
                        if (current.def != null)
                        {
                            var thingDef = ThingDef.Named(current.def);
                            FoodCategoryUtils.RecordFood(thingDef, current.pref);
                            loadedElements++;
                        }
                    }
                    //Log.Message("Loaded compatibility patch \"" + this.defName + "\" for mod " + requiredMod + ". Applied " + loadedElements + " fixes.");
                }

                return(loadedElements);
            }
            catch (Exception ex)
            {
                Log.Error("Exception when loading compatibility Def for mod " + requiredMod + " : " + ex + " " + ex.StackTrace);
            }

            return(0);
        }
コード例 #2
0
        public override void DefsLoaded()
        {
            // ------------------ Basic options -----------------

            //Config.ColonistsPrefPasteOverTasty = Settings.GetHandle<bool>("colonistsPrefPasteOverTasty", "PrefNutrientPasteOverTasty".Translate(), "PrefNutrientPasteOverTasty_desc".Translate(), true);
            //Config.privilegedPrisoners = Settings.GetHandle<bool>("privilegedPrisoners", "PrivilegedPrisoners".Translate(), "PrivilegedPrisoners_desc".Translate(), false);

            //Config.IncapColonistsFeedMode = Settings.GetHandle("incapColonistsFeedMode", "IncapFeedMode".Translate(), "", IncapFeedMode.AnimalsLikeExcludeCorpses, null, "enumSetting_");

            //Config.petsPreferHunt = Settings.GetHandle<bool>("petsPreferHunt", "PetsPreferHunt".Translate(), "PetsPreferHunt_desc".Translate(), true);

            Config.SeparatedNutrientPaste = Settings.GetHandle <bool>("separatedNutrientPaste", "SeparatedNutrientPaste".Translate(), "SeparatedNutrientPaste_desc".Translate(), true);

            Config.PrintPreferencesCommand = Settings.GetHandle <bool>("commandPrintReport", "PrintReportCommand".Translate(), "PrintReportCommand_desc".Translate());
            Config.PrintPreferencesCommand.CustomDrawer = delegate(Rect rect)
            {
                if (Widgets.ButtonText(rect, "commandPrintReportButton".Translate()))
                {
                    var floatOptions = new List <FloatMenuOption>();
                    foreach (var printMode in Enum.GetValues(typeof(ReportMode)))
                    {
                        floatOptions.Add(new FloatMenuOption(("commandPrintReportOption_" + printMode.ToString()).Translate(), () =>
                        {
                            Report.PrintCompatibilityReport((ReportMode)printMode);
                        }));
                    }
                    Find.WindowStack.Add(new FloatMenu(floatOptions));
                }
                return(true);
            };

            Config.NeedsTabUIHeight           = Settings.GetHandle <float>("NeedsTabUIHeight", "NeedsTabUIHeight".Translate(), "NeedsTabUIHeight_desc".Translate(), 140);
            Config.NeedsTabUIHeight.Validator = delegate(string text)
            {
                float value;

                if (!float.TryParse(text, out value))
                {
                    return(false);
                }

                if (value < 100)
                {
                    return(false);
                }

                return(true);
            };
            Config.NeedsTabUIHeight.OnValueChanged = delegate(float value)
            {
                UI.PawnPolicyCard.middleRectHeigth = value;
            };

            Config.controlPets      = Settings.GetHandle <bool>("controlPets", "ControlPets".Translate(), "ControlPets_desc".Translate(), true);
            Config.controlPrisoners = Settings.GetHandle <bool>("controlPrisoners", "ControlPrisoners".Translate(), "ControlPrisoners_desc".Translate(), true);
            Config.controlColonists = Settings.GetHandle <bool>("controlColonists", "ControlColonists".Translate(), "ControlColonists_desc".Translate(), true);
            Config.controlVisitors  = Settings.GetHandle <bool>("controlVisitors", "ControlVisitors".Translate(), "ControlColonists_desc".Translate(), true);

            Config.ShowAdvancedOptions = Settings.GetHandle <bool>("showAdvancedOptions", "ShowAdvancedOptions".Translate(), "ShowAdvancedOptions_desc".Translate(), false);

            // ------------------ Advanced options -----------------
            {
                SettingHandle.ShouldDisplay VisibilityPredicate = (() => Config.ShowAdvancedOptions);

                Config.petsSafeHuntMaxStrengthRatio = Settings.GetHandle <float>("petsSafeHuntMaxStrenghRatio", "PetsSafeHuntMaxStrenghtRatio".Translate(), "PetsSafeHuntMaxStrenghtRatio_desc".Translate(), 0.25f);
                Config.petsSafeHuntMaxStrengthRatio.VisibilityPredicate = VisibilityPredicate;
                Config.petsSafeHuntMaxStrengthRatio.Validator           = delegate(string value)
                {
                    float ratio;

                    if (float.TryParse(value, out ratio) && 0f < ratio && ratio <= 0.5f)
                    {
                        return(true);
                    }

                    Logger.Warning("Wrong option value: " + value + " \nreseting...");

                    return(false);
                };

                Config.useCorpsesForTaming = Settings.GetHandle <bool>("useCorpsesForTaming", "UseCorpsesForTaming".Translate(), "UseCorpsesForTaming_desc".Translate(), false);
                Config.useCorpsesForTaming.VisibilityPredicate = VisibilityPredicate;

                Config.useHumanlikeCorpsesForTaming = Settings.GetHandle <bool>("useHumanlikeCorpsesForTaming", "UseHumanlikeCorpsesForTaming".Translate(), "UseHumanlikeCorpsesForTaming_desc".Translate(), false);
                Config.useHumanlikeCorpsesForTaming.VisibilityPredicate = VisibilityPredicate;

                //Config.extendedFoodOptimality = Settings.GetHandle<bool>("extendedFoodOptimality", "ExtendedFoodOptimality".Translate(), "ExtendedFoodOptimality_desc".Translate(), true);
                //Config.extendedFoodOptimality.VisibilityPredicate = VisibilityPredicate;

                Config.CostFactor = Settings.GetHandle <float>("CostFactor", "CostFactor".Translate(), "CostFactor_desc".Translate(), Config.CONFIG_DEFAULT_COST_FACTOR);
                Config.CostFactor.VisibilityPredicate = VisibilityPredicate;

                Config.FoodSearchMaxItemsCount = Settings.GetHandle <int>("FoodSearchMaxItemsCount", "FoodSearchMaxItemsCount".Translate(), "FoodSearchMaxItemsCount_desc".Translate(), 2000);
                Config.FoodSearchMaxItemsCount.VisibilityPredicate = VisibilityPredicate;

                Config.useMealsForTaming = Settings.GetHandle <bool>("useMealsForTaming", "UseMealsForTaming".Translate(), "UseMealsForTaming_desc".Translate(), false);
                Config.useMealsForTaming.VisibilityPredicate = VisibilityPredicate;

#if DEBUG
                Config.debugNoPawnsRestricted = Settings.GetHandle <bool>("debugNoPawnsRestricted", "debugNoPawnsRestricted", "", false);
                Config.debugFoodPrefConstant  = Settings.GetHandle <bool>("debugFoodPrefConstant", "debugFoodPrefConstant", "", false);
                Config.debugNoWasteFactor     = Settings.GetHandle <bool>("debugNoWasteFactor", "debugNoWasteFactor", "", false);
#endif
            }

            FoodCategoryUtils.ClearAllRecords();
            processDefs();

            // ducktape
            processCannibalMealDef("MealNutrientPaste");
            //processCannibalMealDef("MealSimple");
            //processCannibalMealDef("MealFine");
            //processCannibalMealDef("MealLavish");

            //#if DEBUG
            Report.PrintCompatibilityReport(ReportMode.DefName, true);
            //#endif
        }
コード例 #3
0
        //TODO: fix diet list
        internal static void PrintCompatibilityReport(ReportMode mode, bool silent = false)
        {
            string text = "";

            text = "\n========================== Complete food categories list ==========================\n\n";

            var completeSortedList = (from entry in FoodCategoryUtils.FoodRecords
                                      //where entry.Key.GetMod() != null
                                      group entry by entry.Value.category);

            foreach (var current in completeSortedList)
            {
                var completeSortedList2 = (from entry in current
                                           group entry by entry.Key.GetMod());

                if (completeSortedList2.Any())
                {
                    text += string.Format("+-- Foods of category {0} {1}: --------- \n", current.Key, (current.Key == FoodCategory.Null) ? "(undetermined)" : "");

                    foreach (var modDefs in completeSortedList2)
                    {
                        text += string.Format("| [Mod : {0}]", modDefs.Key.Name);

                        text += " " + String.Join(" ; ", modDefs.Select((arg) => arg.Key.ToReportString(mode) + (arg.Value.costFactor != 1f ? "(cost: " + arg.Value.costFactor.ToString("F2") + ")" : "") + (arg.Key.HasForcedFoodPref() ? " (forced)" : "")).ToArray()) + "\n";
                    }
                    text += "|\n";
                }
            }

            text += "\n========================== Complete diets list ==========================\n\n";

            foreach (var policy in Policies.AllVisiblePolicies)
            {
                var allDietsSorted = (from entry in policy.PerRacesDiet
                                      where entry.Key.GetMod() != null
                                      group entry by entry.Key.GetMod());

                var masks = string.Join(" ; ", policy.pawnMasks.Select((arg) => arg.ToString()).ToArray());
                text += string.Format("+-- [Policy : {0}] {1} --------------- \n", policy.label, masks);

                foreach (var mod in allDietsSorted)
                {
                    text += string.Format("|\t[Mod : {0}]\n", mod.Key.Name);
                    foreach (var diet in mod)
                    {
                        var detailledDiet = new List <string>();

                        if (policy.unrestricted)
                        {
                            detailledDiet.Add("* Does not ever care *");
                        }
                        else
                        {
                            foreach (FoodCategory current in diet.Value.elements.Select((arg) => arg.foodCategory))
                            {
                                var foodsWithPrefForRace = DefDatabaseHelper.AllDefsIngestibleNAnimals.Where((arg) => arg.ingestible != null && arg.DetermineFoodCategory(true) == current && diet.Key.race.CanEverEat(arg));
                                var foodsWithPref        = FoodCategoryUtils.GetAllFoodsWithPref(current);
                                int foodsWithPrefCount   = foodsWithPref.Count();

                                string foodsList = "";

                                int gap = foodsWithPrefCount - foodsWithPrefForRace.Count();

                                if (foodsWithPrefCount == foodsWithPrefForRace.Count() && foodsWithPrefCount > 3)
                                {
                                    foodsList = "*all*";
                                }
                                else if (4 >= gap && gap >= 1)
                                {
                                    var excludeList = foodsWithPref.Where((arg) => !foodsWithPrefForRace.Contains(arg)).Select((arg) => arg.ToReportString(mode));
                                    foodsList = string.Format("*all except* {0}", string.Join(";", excludeList.ToArray()));
                                }
                                else
                                {
                                    foodsList = string.Join("=", foodsWithPrefForRace.Select((arg) => arg.ToReportString(mode)).ToArray());
                                }


                                detailledDiet.Add(string.Format("[{0} ({1})]", current, foodsList));
                            }
                        }

                        text += string.Format("|\t\t{0} :\t\t{1}\n", diet.Key.ToReportString(mode), string.Join(" > ", detailledDiet.ToArray()));
                    }
                }
            }

            Log.Message(string.Format("Compatibility report ({0} lines) :\n{1}", text.Count((arg) => arg == '\n'), text));

            if (!silent)
            {
                Messages.Message("ReportPrintedInLogMessage".Translate(), MessageTypeDefOf.NeutralEvent);
            }
        }