Exemplo n.º 1
0
        public void Inject()
        {
            Type bed = typeof(Building_Bed);
            Dictionary <string, ThingDef> bedDefs = DefDatabase <ThingDef> .AllDefsListForReading
                                                    .Where(d => !d.defName.StartsWith("Ogre_NanoTech") && bed.IsAssignableFrom(d.thingClass))
                                                    .ToDictionary(x => x.defName, y => y);

            HashSet <string> modSupport = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            List <ThingDef> linkableBuildings         = ThingDef.Named("Ogre_NanoTech_Bed").GetCompProperties <CompProperties_AffectedByFacilities>().linkableFacilities;
            List <CompProperties_Facility> facilities = linkableBuildings
                                                        .Select(x => x.GetCompProperties <CompProperties_Facility>())
                                                        .Where(x => x != null)
                                                        .ToList();

            List <ThingDef> linkableHospitalOnly = ThingDef.Named("Ogre_NanoTech_HospitalBed").GetCompProperties <CompProperties_AffectedByFacilities>().linkableFacilities;
            List <CompProperties_Facility> hospitalOnlyFacilities = linkableHospitalOnly
                                                                    .Select(x => x.GetCompProperties <CompProperties_Facility>())
                                                                    .Where(x => x != null)
                                                                    .ToList();

            ThingCategoryDef buildingCategory = DefDatabase <ThingCategoryDef> .AllDefsListForReading.Find(x => x.defName == "BuildingsFurniture");

            foreach (SupportedBed b in _BEDS_TO_SUPPORT)
            {
                if (bedDefs.ContainsKey(b.DefName))
                {
                    ThingDef nanoBed = NanoUtil.CreateNanoBedDefFromSupportedBed(
                        bed: bedDefs[b.DefName],
                        fnAdditionalProcessing: b.FnPostProcess,
                        linkableBuildings: b.UseHospitalLinkablesOnly ? linkableHospitalOnly : linkableBuildings,
                        facilities: b.UseHospitalLinkablesOnly ? hospitalOnlyFacilities : facilities
                        );

                    DefDatabase <ThingDef> .Add(nanoBed);

                    buildingCategory.childThingDefs.Add(nanoBed);                     // so beds are in stockpile filters
                    modSupport.Add(b.ModName);
                }
            }

            Verse.Log.Message("Nano Repair Tech Added Support: [ " + string.Join(", ", modSupport.OrderBy(x => x).ToArray()) + " ]");

            // defs show up where they are
            // supposed to in the game menus?
            DefDatabase <DesignationCategoryDef> .AllDefsListForReading.Find(x => x.defName == "Ogre_NanoRepairTech_DesignationCategory").ResolveReferences();

            // pawns will not auto seek out
            // the beds unless the
            // RestUtilty is reset
            RestUtility.Reset();
        }
Exemplo n.º 2
0
        public void Inject()
        {
            Type bed = typeof(Building_Bed);
            Dictionary <string, ThingDef> bedDefs = DefDatabase <ThingDef> .AllDefsListForReading
                                                    .Where(d => !d.defName.StartsWith("Ogre_NanoTech") && bed.IsAssignableFrom(d.thingClass))
                                                    .ToDictionary(x => x.defName, y => y);

            HashSet <string> modSupport = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            List <ThingDef> linkableBuildings         = ThingDef.Named("Ogre_NanoTech_Bed").GetCompProperties <CompProperties_AffectedByFacilities>().linkableFacilities;
            List <CompProperties_Facility> facilities = linkableBuildings
                                                        .Select(x => x.GetCompProperties <CompProperties_Facility>())
                                                        .Where(x => x != null)
                                                        .ToList();

            List <ThingDef> linkableHospitalOnly = ThingDef.Named("Ogre_NanoTech_HospitalBed").GetCompProperties <CompProperties_AffectedByFacilities>().linkableFacilities;
            List <CompProperties_Facility> hospitalOnlyFacilities = linkableHospitalOnly
                                                                    .Select(x => x.GetCompProperties <CompProperties_Facility>())
                                                                    .Where(x => x != null)
                                                                    .ToList();

            ThingCategoryDef buildingCategory = DefDatabase <ThingCategoryDef> .AllDefsListForReading.Find(x => x.defName == "BuildingsFurniture");

            List <MemeDef> memesRef = new List <MemeDef>();

            Dictionary <string, List <MemeDef> > designatorViaMeme = new Dictionary <string, List <MemeDef> >();

            if (ModsConfig.IdeologyActive)
            {
                // build a lookup of all memes
                // that have unlockable buildables
                // ex pain in virtue ( slab beds )
                List <MemeDef> memes = new List <MemeDef>(DefDatabase <MemeDef> .AllDefsListForReading);
                foreach (MemeDef m in memes)
                {
                    if (m.addDesignators != null)
                    {
                        foreach (BuildableDef d in m.addDesignators)
                        {
                            if (d != null && !string.IsNullOrWhiteSpace(d.defName))
                            {
                                List <MemeDef> o;
                                if (!designatorViaMeme.TryGetValue(d.defName, out o))
                                {
                                    o = new List <MemeDef>();
                                    designatorViaMeme.Add(d.defName, o);
                                }
                                o.Add(m);
                            }
                        }
                    }
                }
            }

            foreach (SupportedBed b in _BEDS_TO_SUPPORT)
            {
                if (bedDefs.ContainsKey(b.DefName))
                {
                    ThingDef nanoBed = NanoUtil.CreateNanoBedDefFromSupportedBed(
                        bed: bedDefs[b.DefName],
                        fnAdditionalProcessing: b.FnPostProcess,
                        linkableBuildings: b.UseHospitalLinkablesOnly ? linkableHospitalOnly : linkableBuildings,
                        facilities: b.UseHospitalLinkablesOnly ? hospitalOnlyFacilities : facilities
                        );

                    DefDatabase <ThingDef> .Add(nanoBed);

                    buildingCategory.childThingDefs.Add(nanoBed);                     // so beds are in stockpile filters
                    modSupport.Add(b.ModName);

                    if (ModsConfig.IdeologyActive)
                    {
                        // check if this bed is listed as an
                        // unlockable building via a memedef
                        if (!nanoBed.canGenerateDefaultDesignator)
                        {
                            if (designatorViaMeme.ContainsKey(b.DefName))
                            {
                                foreach (MemeDef m in designatorViaMeme[b.DefName])
                                {
                                    m.addDesignators.Add(nanoBed);
                                }
                            }
                        }
                    }
                }
            }

            Verse.Log.Message("Nano Repair Tech Added Support: [ " + string.Join(", ", modSupport.OrderBy(x => x).ToArray()) + " ]");

            // defs show up where they are
            // supposed to in the game menus?
            DefDatabase <DesignationCategoryDef> .AllDefsListForReading.Find(x => x.defName == "Ogre_NanoRepairTech_DesignationCategory").ResolveReferences();

            // pawns will not auto seek out
            // the beds unless the
            // RestUtilty is reset
            RestUtility.Reset();
        }