// XML data into verb
        protected virtual void              TryGetProps()
        {
            if (gotProps)
            {
                //Already done, pass
                return;
            }

            var props = verbProps as VerbProperties_Extended;

            if (props == null)
            {
#if DEBUG
                CCL_Log.TraceMod(
                    this.caster.def,
                    Verbosity.Warnings,
                    "Missing VerbProperties_Extended"
                    );
#endif
                pelletCount = 1;
                expMin      = 10;
                expMid      = 50;
                expMax      = 240;
            }
            else
            {
                pelletCount = props.pelletCount;
                expMin      = props.experienceGain.min;
                expMid      = props.experienceGain.mid;
                expMax      = props.experienceGain.max;
            }
            gotProps = true;
        }
        public static bool HasResearchRequirement(this BuildableDef buildableDef)
        {
#if DEBUG
            CCL_Log.TraceMod(
                buildableDef,
                Verbosity.Stack,
                "HasResearchRequirement()"
                );
#endif
            // Can't entirely rely on this one check as it's state may change mid-game
            if (
                (buildableDef.researchPrerequisites != null) &&
                (buildableDef.researchPrerequisites.Any(def => def != null))
                )
            {
                // Easiest check, do it first
                return(true);
            }

            // Check for an advanced research unlock
            return
                (Controller.Data.AdvancedResearchDefs.Any(a => (
                                                              (a.IsBuildingToggle) &&
                                                              (!a.HideDefs) &&
                                                              (a.thingDefs.Contains(buildableDef as ThingDef))
                                                              )));
        }
예제 #3
0
        public bool                         Inject(ModHelperDef def)
        {
            if (def.TraderKinds.NullOrEmpty())
            {
                return(true);
            }

            for (var index = 0; index < def.TraderKinds.Count; index++)
            {
                var injectionSet = def.TraderKinds[index];
                if (
                    (!injectionSet.requiredMod.NullOrEmpty()) &&
                    (Find_Extensions.ModByName(injectionSet.requiredMod) == null)
                    )
                {
                    continue;
                }
                var traderKindDef = DefDatabase <TraderKindDef> .GetNamed(injectionSet.targetDef);

                foreach (var stockGenerator in injectionSet.stockGenerators)
                {
                    traderKindDef.stockGenerators.Add(stockGenerator);
                    stockGenerator.PostLoad();
                    stockGenerator.ResolveReferences(traderKindDef);
                    CCL_Log.TraceMod(
                        def,
                        Verbosity.Injections,
                        string.Format("Injecting {0} into {1}", stockGenerator.GetType().Name, traderKindDef.label),
                        "TraderKinds");
                }
            }

            dictInjected.Add(def, true);
            return(true);
        }
예제 #4
0
        public static List <Def> GetResearchUnlocked(this ResearchProjectDef researchProjectDef)
        {
#if DEBUG
            CCL_Log.TraceMod(
                researchProjectDef,
                Verbosity.Stack,
                "GetResearchUnlocked()"
                );
#endif
            var researchDefs = new List <Def>();

            //Log.Message( "Normal" );
            researchDefs.AddRangeUnique(DefDatabase <ResearchProjectDef> .AllDefsListForReading.Where(rd =>
                                                                                                      (!rd.prerequisites.NullOrEmpty()) &&
                                                                                                      (rd.prerequisites.Contains(researchProjectDef))
                                                                                                      ).ToList().ConvertAll <Def>(def => (Def)def));

            //Log.Message( "Advanced" );
            // same as prerequisites, but with effectedResearchDefs and researchDefs switched.
            var advancedResearchDefs = Controller.Data.AdvancedResearchDefs.Where(a => (
                                                                                      (a.IsResearchToggle) &&
                                                                                      (!a.HideDefs) &&
                                                                                      (a.researchDefs.Contains(researchProjectDef))
                                                                                      )).ToList();

            researchDefs.AddRangeUnique(advancedResearchDefs.SelectMany(ar => ar.effectedResearchDefs).ToList().ConvertAll <Def>(Def => (Def)Def));

            return(researchDefs);
        }
예제 #5
0
        public static List <Def> GetResearchedLockedBy(this ResearchProjectDef researchProjectDef)
        {
#if DEBUG
            CCL_Log.TraceMod(
                researchProjectDef,
                Verbosity.Stack,
                "GetResearchLockedBy()"
                );
#endif
            // Advanced Research that locks it
            var researchDefs = new List <Def>();

            // Look in advanced research
            var advancedResearch = Controller.Data.AdvancedResearchDefs.Where(a => (
                                                                                  (a.IsResearchToggle) &&
                                                                                  (a.HideDefs) &&
                                                                                  (a.effectedResearchDefs.Contains(researchProjectDef))
                                                                                  )).ToList();

            // Aggregate research
            if (!advancedResearch.NullOrEmpty())
            {
                foreach (var a in advancedResearch)
                {
                    researchDefs.AddRangeUnique(a.researchDefs.ConvertAll <Def>(def => (Def)def));
                }
            }

            return(researchDefs);
        }
        public static bool                  IsLockedOut(this BuildableDef buildableDef)
        {
            bool rVal;
            var  foo = buildableDef.GetHashCode();

            if (!isLockedOut.TryGetValue(buildableDef.shortHash, out rVal))
            {
#if DEBUG
                CCL_Log.TraceMod(
                    buildableDef,
                    Verbosity.Stack,
                    "IsLockedOut()"
                    );
#endif

                // Is it a frame or blueprint?
                if (
                    (buildableDef.defName.EndsWith("_Frame")) ||
                    (buildableDef.defName.EndsWith("_Blueprint")) ||
                    (buildableDef.defName.EndsWith("_Blueprint_Install"))
                    )
                {
                    isLockedOut.Add(buildableDef.shortHash, true);
                    return(true);
                }

                //  Logic is faulty ( Thingdefs inherit from buildable defs, checking for existence of blueprint eliminates all non-buildings )
                //  After correcting logic (Valid: blueprint == null [items], or blueprint != null and designation != null/None [buildings]),
                //  the check no longer makes sense, since only defs with a designation category ever get a blueprint assigned. -- Fluffy.
                //
                //// Is the designationCategory locked out?
                //// only applies if it is buildable (has a blueprint def), but no category.
                //if(
                //    buildableDef.blueprintDef != null &&
                //    ( buildableDef.designationCategory.NullOrEmpty()||
                //      buildableDef.designationCategory == "None" )
                //)
                //{
                //    isLockedOut.Add( buildableDef, true );
                //    return true;
                //}

                // If the research locks it's out, check for an ARDef unlock
                if (
                    (buildableDef.researchPrerequisites != null) &&
                    (buildableDef.researchPrerequisites.Any(def => def.IsLockedOut())) &&
                    (!Controller.Data.AdvancedResearchDefs.Any(a => (
                                                                   (a.IsBuildingToggle) &&
                                                                   (!a.HideDefs) &&
                                                                   (a.thingDefs.Contains(buildableDef as ThingDef))
                                                                   ))))
                {
                    rVal = true;
                }

                // Cache the result
                isLockedOut.Add(buildableDef.shortHash, rVal);
            }
            return(rVal);
        }
예제 #7
0
        public static List <RecipeDef> GetRecipesUnlocked(this ThingDef thingDef, ref List <Def> researchDefs)
        {
#if DEBUG
            CCL_Log.TraceMod(
                thingDef,
                Verbosity.Stack,
                "GetRecipesUnlocked()"
                );
#endif
            // Recipes that are unlocked on thing with research
            var recipeDefs = new List <RecipeDef>();
            if (researchDefs != null)
            {
                researchDefs.Clear();
            }

            // Look at recipes
            var recipes = DefDatabase <RecipeDef> .AllDefsListForReading.Where(r => (
                                                                                   (r.researchPrerequisite != null) &&
                                                                                   (
                                                                                       (
                                                                                           (r.recipeUsers != null) &&
                                                                                           (r.recipeUsers.Contains(thingDef))
                                                                                       ) ||
                                                                                       (
                                                                                           (thingDef.recipes != null) &&
                                                                                           (thingDef.recipes.Contains(r))
                                                                                       )
                                                                                   ) &&
                                                                                   (!r.IsLockedOut())
                                                                                   )).ToList();

            // Look in advanced research too
            var advancedResearch = Controller.Data.AdvancedResearchDefs.Where(a => (
                                                                                  (a.IsRecipeToggle) &&
                                                                                  (!a.HideDefs) &&
                                                                                  (a.thingDefs.Contains(thingDef))
                                                                                  )).ToList();

            // Aggregate advanced research
            foreach (var a in advancedResearch)
            {
                recipeDefs.AddRangeUnique(a.recipeDefs);
                if (researchDefs != null)
                {
                    if (a.researchDefs.Count == 1)
                    {
                        // If it's a single research project, add that
                        researchDefs.AddUnique(a.researchDefs[0]);
                    }
                    else
                    {
                        // Add the advanced project instead
                        researchDefs.AddUnique(a);
                    }
                }
            }
            return(recipeDefs);
        }
        public override void                PostSpawnSetup()
        {
            base.PostSpawnSetup();

            // Get the default glower
            CompGlower = parent.TryGetComp <CompGlower>();
#if DEBUG
            if (CompGlower == null)
            {
                CCL_Log.TraceMod(
                    parent.def,
                    Verbosity.FatalErrors,
                    "Missing CompGlower"
                    );
                return;
            }
#endif

            // Get the color properties
            ColorProps = this.CompProperties_ColoredLight();
#if DEBUG
            if (ColorProps == null)
            {
                CCL_Log.TraceMod(
                    parent.def,
                    Verbosity.FatalErrors,
                    "Missing CompProperties_ColoredLight"
                    );
                return;
            }
#endif

            // Set default palette if none is specified
            if (ColorProps.color == null)
            {
                ColorProps.color = Light.Color;
            }

            // Set default
            if ((ColorIndex < 0) ||
                (ColorIndex >= ColorProps.color.Count))
            {
                ColorIndex = ColorProps.Default;
            }

            // Get the glow radius
            lightRadius = CompGlower.Props.glowRadius;

            // Set the light color
            if (ColorProps.useColorPicker)
            {
                ChangeColor(Color, false);
            }
            else
            {
                ChangeColor(ColorIndex);
            }
        }
예제 #9
0
        public static bool                  HasResearchRequirement(this RecipeDef recipeDef)
        {
#if DEBUG
            CCL_Log.TraceMod(
                recipeDef,
                Verbosity.Stack,
                "HasResearchRequirement()"
                );
#endif
            // Can't entirely rely on this one check as it's state may change mid-game
            if (recipeDef.researchPrerequisite != null)
            {
                // Easiest check, do it first
                return(true);
            }

            // Check for an advanced research unlock
            if (Controller.Data.AdvancedResearchDefs.Any(a => (
                                                             (a.IsRecipeToggle) &&
                                                             (!a.HideDefs) &&
                                                             (a.recipeDefs.Contains(recipeDef))
                                                             )))
            {
                return(true);
            }

            // Get list of things referencing
            var thingsOn = DefDatabase <ThingDef> .AllDefsListForReading.Where(t => (
                                                                                   (t.recipes != null) &&
                                                                                   (t.recipes.Contains(recipeDef)) &&
                                                                                   (!t.IsLockedOut())
                                                                                   )).ToList();

            if (thingsOn == null)
            {
                thingsOn = new List <ThingDef>();
            }
            else
            {
                thingsOn.AddRangeUnique(recipeDef.recipeUsers);
            }

            var advancedResearchDefs = Controller.Data.AdvancedResearchDefs.Where(a => (
                                                                                      (a.IsRecipeToggle) &&
                                                                                      (a.recipeDefs.Contains(recipeDef)) &&
                                                                                      (!a.HideDefs)
                                                                                      )).ToList();
            if (!advancedResearchDefs.NullOrEmpty())
            {
                foreach (var a in advancedResearchDefs)
                {
                    thingsOn.AddRangeUnique(a.thingDefs);
                }
            }
            // Now check for an absolute requirement
            return(thingsOn.All(t => t.HasResearchRequirement()));
        }
예제 #10
0
        public void Disable(bool firstTimeRun = false)
        {
            // Don't disable if it's not the first run and not yet enabled
            if (
                (researchState == ResearchEnableMode.Incomplete) &&
                (firstTimeRun == false)
                )
            {
                return;
            }
#if DEBUG
            CCL_Log.TraceMod(
                modHelperDef,
                Verbosity.StateChanges,
                "Disabling '" + defName + "'",
                "AdvancedResearchDef"
                );
#endif
            if (IsRecipeToggle)
            {
                // Recipe toggle
                ToggleRecipes(true);
            }
            if (IsPlantToggle)
            {
                // Plant toggle
                TogglePlants(true);
            }
            if (IsBuildingToggle)
            {
                // Building toggle
                ToggleBuildings(true);
            }
            if (
                (IsResearchToggle) &&
                (researchState != ResearchEnableMode.GodMode)
                )
            {
                // Research toggle
                ToggleResearch(true);
            }
            if (
                (HasCallbacks) &&
                (!firstTimeRun)
                )
            {
                // Cache callbacks
                ToggleCallbacks(true);
            }
            if (HasHelp)
            {
                // Build & toggle help
                ToggleHelp(true);
            }
            // Flag it as disabled
            researchState = ResearchEnableMode.Incomplete;
        }
예제 #11
0
        public static bool InitializeHosts(bool preload = false)
        {
            if (preload)
            {
                Controller.Data.MCMHosts.Clear();
            }

            // Get the mods with config menus
            foreach (var mhd in Controller.Data.ModHelperDefs)
            {
                // Create all the menus for it
                if (!mhd.ModConfigurationMenus.NullOrEmpty())
                {
                    foreach (var mcm in mhd.ModConfigurationMenus)
                    {
                        if ( // Filter out preload during non-preload and non-preload during preload
                            (
                                (preload) &&
                                (mcm.preload)
                            ) ||
                            (
                                (!preload) &&
                                (!mcm.preload)
                            )
                            )
                        {
                            var host = Controller.Data.MCMHosts.Find(m => m.worker.InjectionSet == mcm);
                            if (host != null)
                            {   // MCM already created....?
                                CCL_Log.TraceMod(
                                    mhd,
                                    Verbosity.Warnings,
                                    string.Format("{0} - Tried to create an MCM when an MCM already exists", mcm.mcmClass.ToString())
                                    );
                                continue;
                            }
                            host        = new MCMHost();
                            host.Label  = mcm.label;
                            host.worker = (ModConfigurationMenu)Activator.CreateInstance(mcm.mcmClass);
                            if (host.worker == null)
                            {
                                CCL_Log.Error(string.Format("Unable to create instance of {0}", mcm.mcmClass.ToString()));
                                return(false);
                            }
                            else
                            {   // Initialize, add it to the menu list and then load it's data
                                host.worker.InjectionSet = mcm;
                                host.worker.Initialize();
                                Controller.Data.MCMHosts.Add(host);
                                LoadHostData(host);
                            }
                        }
                    }
                }
            }
            return(true);
        }
예제 #12
0
        public static List <ThingDef> GetThingsUnlocked(this RecipeDef recipeDef, ref List <Def> researchDefs)
        {
#if DEBUG
            CCL_Log.TraceMod(
                recipeDef,
                Verbosity.Stack,
                "GetThingsUnlocked()"
                );
#endif
            // Things it is unlocked on with research
            var thingDefs = new List <ThingDef>();
            if (researchDefs != null)
            {
                researchDefs.Clear();
            }

            if (recipeDef.researchPrerequisite != null)
            {
                thingDefs.AddRangeUnique(recipeDef.recipeUsers);
                if (researchDefs != null)
                {
                    researchDefs.AddUnique(recipeDef.researchPrerequisite);
                }
            }

            // Look in advanced research too
            var advancedResearch = Controller.Data.AdvancedResearchDefs.Where(a => (
                                                                                  (a.IsRecipeToggle) &&
                                                                                  (!a.HideDefs) &&
                                                                                  (a.recipeDefs.Contains(recipeDef))
                                                                                  )).ToList();

            // Aggregate advanced research
            if (!advancedResearch.NullOrEmpty())
            {
                foreach (var a in advancedResearch)
                {
                    thingDefs.AddRangeUnique(a.thingDefs);

                    if (researchDefs != null)
                    {
                        if (a.researchDefs.Count == 1)
                        {
                            // If it's a single research project, add that
                            researchDefs.AddUnique(a.researchDefs[0]);
                        }
                        else
                        {
                            // Add the advanced project instead
                            researchDefs.AddUnique(a);
                        }
                    }
                }
            }

            return(thingDefs);
        }
예제 #13
0
        public static List <string> GetSowTagsUnlocked(this ResearchProjectDef researchProjectDef, ref List <ThingDef> thingDefs)
        {
#if DEBUG
            CCL_Log.TraceMod(
                researchProjectDef,
                Verbosity.Stack,
                "GetSowTagsUnlocked()"
                );
#endif
            var sowTags = new List <string>();
            if (thingDefs != null)
            {
                thingDefs.Clear();
            }

            // Add all plants using this research project
            var researchPlants = DefDatabase <ThingDef> .AllDefsListForReading.Where(d => (
                                                                                         (d.plant != null) &&
                                                                                         (!d.plant.sowResearchPrerequisites.NullOrEmpty()) &&
                                                                                         (d.plant.sowResearchPrerequisites.Contains(researchProjectDef))
                                                                                         )).ToList();

            if (!researchPlants.NullOrEmpty())
            {
                foreach (var plant in researchPlants)
                {
                    sowTags.AddRangeUnique(plant.plant.sowTags);
                }
                if (thingDefs != null)
                {
                    thingDefs.AddRangeUnique(researchPlants);
                }
            }

            // Look in advanced research to add plants and sow tags it unlocks
            var advancedResearch = Controller.Data.AdvancedResearchDefs.Where(a => (
                                                                                  (a.IsPlantToggle) &&
                                                                                  (!a.HideDefs) &&
                                                                                  (a.researchDefs.Count == 1) &&
                                                                                  (a.researchDefs.Contains(researchProjectDef))
                                                                                  )).ToList();

            // Aggregate advanced research
            if (!advancedResearch.NullOrEmpty())
            {
                foreach (var a in advancedResearch)
                {
                    sowTags.AddRangeUnique(a.sowTags);
                    if (thingDefs != null)
                    {
                        thingDefs.AddRangeUnique(a.thingDefs);
                    }
                }
            }

            return(sowTags);
        }
예제 #14
0
        public static List <RecipeDef> GetRecipesCurrent(this ThingDef thingDef)
        {
#if DEBUG
            CCL_Log.TraceMod(
                thingDef,
                Verbosity.Stack,
                "GetRecipesCurrent()"
                );
#endif
            return(thingDef.AllRecipes);
        }
        // The list of things are all the growers we want to change
        void                                GroupPlantChange(List <Thing> things)
        {
            var thisGrower = Building_PlantGrower;

#if DEBUG
            if (thisGrower == null)
            {
                CCL_Log.TraceMod(
                    parent.def,
                    Verbosity.NonFatalErrors,
                    "Unable to resolve ThingClass to base Building_PlantGrower"
                    );
                return;
            }
#endif
            // Get plant to grow
            var plantDef = thisGrower.GetPlantDefToGrow();
            if (GenList.NullOrEmpty(plantDef?.plant?.sowTags))
            {
                // "Plant" doesn't contain the required information
                CCL_Log.TraceMod(
                    parent.def,
                    Verbosity.Warnings,
                    "Unable to resolve plant def to grow"
                    );
                return;
            }

            // Now set their plant
            foreach (Thing g in things)
            {
                // Should be a Building_PlantGrower
                var grower = g as Building_PlantGrower;
#if DEBUG
                if (string.IsNullOrEmpty(grower?.def?.building.sowTag))
                {
                    CCL_Log.TraceMod(
                        parent.def,
                        Verbosity.Warnings,
                        "Unable to resolve other things ThingClass to base Building_PlantGrower"
                        );
                    return;
                }
#endif
                // Only set if the sow tags match
                if (plantDef.plant.sowTags.Contains(grower.def.building.sowTag))
                {
                    grower.SetPlantDefToGrow(plantDef);
                }
            }
        }
예제 #16
0
        public static bool                  IsLockedOut(this RecipeDef recipeDef)
        {
            bool rVal = false;

            if (!isLockedOut.TryGetValue(recipeDef.shortHash, out rVal))
            {
#if DEBUG
                CCL_Log.TraceMod(
                    recipeDef,
                    Verbosity.Stack,
                    "IsLockedOut()"
                    );
#endif
                // Advanced research unlocking it?
                if (Controller.Data.AdvancedResearchDefs.Any(a => (
                                                                 (a.IsRecipeToggle) &&
                                                                 (!a.HideDefs) &&
                                                                 (a.recipeDefs.Contains(recipeDef))
                                                                 )))
                {
                    isLockedOut.Add(recipeDef.shortHash, false);
                    return(false);
                }

                // Is the research parent locked out?
                if (
                    (recipeDef.researchPrerequisite != null) &&
                    (recipeDef.researchPrerequisite.IsLockedOut())
                    )
                {
                    isLockedOut.Add(recipeDef.shortHash, true);
                    return(true);
                }

                // Is everything using it locked?
                if (!DefDatabase <ThingDef> .AllDefsListForReading.Any(t => (
                                                                           (t.AllRecipes != null) &&
                                                                           (t.AllRecipes.Contains(recipeDef)) &&
                                                                           (!t.IsLockedOut())
                                                                           )))
                {
                    rVal = true;
                }
                isLockedOut.Add(recipeDef.shortHash, rVal);
            }
            return(rVal);
        }
예제 #17
0
        public static List <RecipeDef> GetRecipesLocked(this ThingDef thingDef, ref List <Def> researchDefs)
        {
#if DEBUG
            CCL_Log.TraceMod(
                thingDef,
                Verbosity.Stack,
                "GetRecipesLocked()"
                );
#endif
            // Things it is locked on with research
            var recipeDefs = new List <RecipeDef>();
            if (researchDefs != null)
            {
                researchDefs.Clear();
            }

            // Look in advanced research
            var advancedResearch = Controller.Data.AdvancedResearchDefs.Where(a => (
                                                                                  (a.IsRecipeToggle) &&
                                                                                  (a.HideDefs) &&
                                                                                  (a.thingDefs.Contains(thingDef))
                                                                                  )).ToList();

            // Aggregate advanced research
            foreach (var a in advancedResearch)
            {
                recipeDefs.AddRangeUnique(a.recipeDefs);

                if (researchDefs != null)
                {
                    if (a.researchDefs.Count == 1)
                    {
                        // If it's a single research project, add that
                        researchDefs.AddUnique(a.researchDefs[0]);
                    }
                    else if (a.ResearchConsolidator != null)
                    {
                        // Add the advanced project instead
                        researchDefs.AddUnique(a.ResearchConsolidator);
                    }
                }
            }

            return(recipeDefs);
        }
예제 #18
0
        public static List <RecipeDef> GetRecipesAll(this ThingDef thingDef)
        {
#if DEBUG
            CCL_Log.TraceMod(
                thingDef,
                Verbosity.Stack,
                "GetRecipesAll()"
                );
#endif
            // Things it is locked on with research
            var recipeDefs = new List <RecipeDef>();

            recipeDefs.AddRangeUnique(thingDef.GetRecipesCurrent());
            recipeDefs.AddRangeUnique(thingDef.GetRecipesUnlocked(ref nullDefs));
            recipeDefs.AddRangeUnique(thingDef.GetRecipesLocked(ref nullDefs));

            return(recipeDefs);
        }
예제 #19
0
        internal static bool _IsLockedOut(this ResearchProjectDef researchProjectDef, ResearchProjectDef initialDef)
        {
            bool rVal = false;

            if (!isLockedOut.TryGetValue(researchProjectDef.shortHash, out rVal))
            {
#if DEBUG
                CCL_Log.TraceMod(
                    researchProjectDef,
                    Verbosity.Stack,
                    "IsLockedOut()"
                    );
#endif
                // Check for possible unlock
                if (!researchProjectDef.prerequisites.NullOrEmpty())
                {
                    // Check each prerequisite
                    foreach (var p in researchProjectDef.prerequisites)
                    {
                        if (
                            (p.defName == researchProjectDef.defName) ||
                            (p.defName == initialDef.defName) ||
                            (p._IsLockedOut(initialDef))
                            )
                        {
                            // Cyclical-prerequisite or parent locked means potential lock-out

                            // Check for possible unlock
                            if (!Controller.Data.AdvancedResearchDefs.Any(a => (
                                                                              (a.IsResearchToggle) &&
                                                                              (!a.HideDefs) &&
                                                                              (a.effectedResearchDefs.Contains(researchProjectDef))
                                                                              )))
                            {
                                // No unlockers, always locked out
                                rVal = true;
                            }
                        }
                    }
                }
                isLockedOut.Add(researchProjectDef.shortHash, rVal);
            }
            return(rVal);
        }
        public override void                PostLoad()
        {
            base.PostLoad();

            // Validate place workers
            if (!placeWorkers.NullOrEmpty())
            {
                // Terrain with comps only supports a small set of place workers
                foreach (var placeWorker in placeWorkers)
                {
                    if (!IsValidPlaceWorker(placeWorker))
                    {
                        CCL_Log.TraceMod(
                            this,
                            Verbosity.FatalErrors,
                            "Unsupported placeworker :: " + placeWorker.GetType().ToString()
                            );
                    }
                }
            }

            // Validate comps
            if (!comps.NullOrEmpty())
            {
                // Terrain with comps only supports a small set of comps
                for (int i = 0; i < comps.Count; ++i)
                {
                    var comp      = comps[i];
                    var compClass = comp.compClass;
                    if (
                        (compClass != typeof(CompRestrictedPlacement)) &&
                        (!compClass.IsSubclassOf(typeof(CompRestrictedPlacement)))
                        )
                    {
                        CCL_Log.TraceMod(
                            this,
                            Verbosity.FatalErrors,
                            "Unsupported ThingComp :: " + compClass.ToString()
                            );
                    }
                }
            }
        }
예제 #21
0
        public static List <ThingDef> GetThingsUnlocked(this ResearchProjectDef researchProjectDef)
        {
#if DEBUG
            CCL_Log.TraceMod(
                researchProjectDef,
                Verbosity.Stack,
                "GetThingsUnlocked()"
                );
#endif
            // Buildings it unlocks
            var thingsOn       = new List <ThingDef>();
            var researchThings = DefDatabase <ThingDef> .AllDefsListForReading.Where(t => (
                                                                                         (!t.IsLockedOut()) &&
                                                                                         (t.GetResearchRequirements() != null) &&
                                                                                         (t.GetResearchRequirements().Contains(researchProjectDef))
                                                                                         )).ToList();

            if (!researchThings.NullOrEmpty())
            {
                thingsOn.AddRangeUnique(researchThings);
            }

            // Look in advanced research too
            var advancedResearch = Controller.Data.AdvancedResearchDefs.Where(a => (
                                                                                  (a.IsBuildingToggle) &&
                                                                                  (!a.HideDefs) &&
                                                                                  (a.researchDefs.Count == 1) &&
                                                                                  (a.researchDefs.Contains(researchProjectDef))
                                                                                  )).ToList();

            // Aggregate research
            if (!advancedResearch.NullOrEmpty())
            {
                foreach (var a in advancedResearch)
                {
                    thingsOn.AddRangeUnique(a.thingDefs);
                }
            }

            return(thingsOn);
        }
예제 #22
0
        public static List <ThingDef> GetRecipeUsers(this RecipeDef recipeDef)
        {
#if DEBUG
            CCL_Log.TraceMod(
                recipeDef,
                Verbosity.Stack,
                "GetRecipeUsers()"
                );
#endif

            var thingDefs = DefDatabase <ThingDef> .AllDefsListForReading.Where(t =>
                                                                                !t.AllRecipes.NullOrEmpty() &&
                                                                                t.AllRecipes.Contains( recipeDef ) &&
                                                                                !t.IsLockedOut()).ToList();

            if (!thingDefs.NullOrEmpty())
            {
                return(thingDefs);
            }
            return(new List <ThingDef>());
        }
예제 #23
0
        public bool                         Inject(ModHelperDef def)
        {
            if (def.ThingComps.NullOrEmpty())
            {
                return(true);
            }

            foreach (var compSet in def.ThingComps)
            {
                bool processThis = true;
                if (!compSet.requiredMod.NullOrEmpty())
                {
                    processThis = Find_Extensions.ModByName(compSet.requiredMod) != null;
                }
                if (processThis)
                {
                    foreach (var targetName in compSet.targetDefs)
                    {
                        // TODO:  Make a full copy using the comp in this def as a template
                        // Currently adds the comp in this def so all target use the same def
                        var targetDef = DefDatabase <ThingDef> .GetNamed(targetName);

                        if (targetDef.HasComp(compSet.compProps.compClass))
                        {
                            CCL_Log.TraceMod(
                                def,
                                Verbosity.Warnings,
                                string.Format("Trying to inject ThingComp '{0}' into '{1}' when it already exists (another mod may have already injected).", compSet.compProps.compClass.ToString(), targetName),
                                "ThingComp Injector");
                        }
                        else
                        {
                            targetDef.comps.Add(compSet.compProps);
                        }
                    }
                }
            }

            return(true);
        }
예제 #24
0
        public override void                PostSpawnSetup()
        {
            base.PostSpawnSetup();

            // Check power comp
#if DEBUG
            if (CompPowerTrader == null)
            {
                CCL_Log.TraceMod(
                    parent.def,
                    Verbosity.FatalErrors,
                    "Missing CompPowerTrader"
                    );
                return;
            }
#endif

            if (remainingTicks < 0)
            {
                remainingTicks = CompLifeSpan.Props.lifespanTicks;
            }
        }
        public override void                SpawnSetup()
        {
            //Log.Message( string.Format( "{0}.SpawnSetup()", this.ThingID ) );
            base.SpawnSetup();
#if DEBUG
            if (CompAutomatedFactory == null)
            {
                CCL_Log.TraceMod(
                    this.def,
                    Verbosity.FatalErrors,
                    "Building_AutomatedFactory requires CompAutomatedFactory");
                return;
            }
            if (CompAutomatedFactory.Properties == null)
            {
                CCL_Log.TraceMod(
                    this.def,
                    Verbosity.FatalErrors,
                    "CompAutomatedFactory requires CompProperties_AutomatedFactory");
                return;
            }
            if (CompAutomatedFactory.Properties.outputVector == FactoryOutputVector.Invalid)
            {
                CCL_Log.TraceMod(
                    this.def,
                    Verbosity.FatalErrors,
                    "CompAutomatedFactory.outputVector is invalid");
                return;
            }
            if (CompAutomatedFactory.Properties.productionMode == FactoryProductionMode.None)
            {
                CCL_Log.TraceMod(
                    this.def,
                    Verbosity.FatalErrors,
                    "CompAutomatedFactory.productionMode is invalid");
                return;
            }
#endif
        }
예제 #26
0
        public static List <RecipeDef> GetRecipesLocked(this ResearchProjectDef researchProjectDef, ref List <ThingDef> thingDefs)
        {
#if DEBUG
            CCL_Log.TraceMod(
                researchProjectDef,
                Verbosity.Stack,
                "GetRecipesLocked()"
                );
#endif
            // Recipes on buildings it locks
            var recipes = new List <RecipeDef>();
            if (thingDefs != null)
            {
                thingDefs.Clear();
            }

            // Look in advanced research
            var advancedResearch = Controller.Data.AdvancedResearchDefs.Where(a => (
                                                                                  (a.IsRecipeToggle) &&
                                                                                  (a.HideDefs) &&
                                                                                  (a.researchDefs.Count == 1) &&
                                                                                  (a.researchDefs.Contains(researchProjectDef))
                                                                                  )).ToList();

            // Aggregate research
            if (!advancedResearch.NullOrEmpty())
            {
                foreach (var a in advancedResearch)
                {
                    recipes.AddRangeUnique(a.recipeDefs);
                    if (thingDefs != null)
                    {
                        thingDefs.AddRangeUnique(a.thingDefs);
                    }
                }
            }

            return(recipes);
        }
 public override void                PostSpawnSetup()
 {
     if (this.RequiresProperties)
     {
         var properties = this.RestrictedPlacement_Properties();
         if (properties == null)
         {
             CCL_Log.TraceMod(
                 parent.def,
                 Verbosity.FatalErrors,
                 "Missing RestrictedPlacement_Properties"
                 );
             return;
         }
         if (
             (IsTerrainRestriction) &&
             (properties.RestrictedTerrain.NullOrEmpty())
             )
         {
             CCL_Log.TraceMod(
                 parent.def,
                 Verbosity.FatalErrors,
                 "Missing terrainDefs"
                 );
         }
         if (
             (IsThingRestriction) &&
             (properties.RestrictedThing.NullOrEmpty())
             )
         {
             CCL_Log.TraceMod(
                 parent.def,
                 Verbosity.FatalErrors,
                 "Missing thingDefs"
                 );
         }
     }
 }
예제 #28
0
        public override void        PostLoad()
        {
            base.PostLoad();

            if (
                (string.IsNullOrEmpty(labelKey)) &&
                (string.IsNullOrEmpty(label))
                )
            {
                CCL_Log.TraceMod(
                    this,
                    Verbosity.NonFatalErrors,
                    "Def must have a valid label or labelKey for translation"
                    );
                label = defName;
            }

            if (!menuClass.IsSubclassOf(typeof(MainMenu)))
            {
                CCL_Log.TraceMod(
                    this,
                    Verbosity.FatalErrors,
                    string.Format("{0} is not a valid main menu class, does not inherit from MainMenu", menuClass.ToString())
                    );
            }
            else
            {
                menuWorker = (MainMenu)Activator.CreateInstance(menuClass);
                if (menuWorker == null)
                {
                    CCL_Log.TraceMod(
                        this,
                        Verbosity.FatalErrors,
                        string.Format("Unable to create instance of {0}", menuClass.ToString()),
                        "MainMenuDef");
                }
            }
        }
예제 #29
0
        public static List <Def> GetResearchRequirements(this ResearchProjectDef researchProjectDef)
        {
#if DEBUG
            CCL_Log.TraceMod(
                researchProjectDef,
                Verbosity.Stack,
                "GetResearchRequirements()"
                );
#endif
            var researchDefs = new List <Def>();

            if (researchProjectDef.prerequisites != null)
            {
                if (!researchProjectDef.prerequisites.Contains(Research.Locker))
                {
                    researchDefs.AddRangeUnique(researchProjectDef.prerequisites.ConvertAll <Def>(def => (Def)def));
                }
                else
                {
                    var advancedResearchDefs = Controller.Data.AdvancedResearchDefs.Where(a => (
                                                                                              (a.IsResearchToggle) &&
                                                                                              (!a.HideDefs) &&
                                                                                              (a.effectedResearchDefs.Contains(researchProjectDef))
                                                                                              )).ToList();

                    if (!advancedResearchDefs.NullOrEmpty())
                    {
                        foreach (var advancedResearchDef in advancedResearchDefs)
                        {
                            researchDefs.AddRangeUnique(advancedResearchDef.researchDefs.ConvertAll <Def>(def => (Def)def));
                        }
                    }
                }
            }

            // Return the list of research required
            return(researchDefs);
        }
예제 #30
0
        public static List <string> GetSowTagsLocked(this ResearchProjectDef researchProjectDef, ref List <ThingDef> thingDefs)
        {
#if DEBUG
            CCL_Log.TraceMod(
                researchProjectDef,
                Verbosity.Stack,
                "GetSowTagsLocked()"
                );
#endif
            var sowTags = new List <string>();
            if (thingDefs != null)
            {
                thingDefs.Clear();
            }

            // Look in advanced research to add plants and sow tags it unlocks
            var advancedResearch = Controller.Data.AdvancedResearchDefs.Where(a => (
                                                                                  (a.IsPlantToggle) &&
                                                                                  (a.HideDefs) &&
                                                                                  (a.researchDefs.Count == 1) &&
                                                                                  (a.researchDefs.Contains(researchProjectDef))
                                                                                  )).ToList();

            // Aggregate advanced research
            if (!advancedResearch.NullOrEmpty())
            {
                foreach (var a in advancedResearch)
                {
                    sowTags.AddRangeUnique(a.sowTags);
                    if (thingDefs != null)
                    {
                        thingDefs.AddRangeUnique(a.thingDefs);
                    }
                }
            }

            return(sowTags);
        }