public static bool OpenRoofCountStopAt(District __instance, ref int __result, int threshold)
 {
     lock (__instance) //added
     {
         if (__instance.cachedOpenRoofCount == -1 && __instance.cachedOpenRoofState == null)
         {
             __instance.cachedOpenRoofCount = 0;
             __instance.cachedOpenRoofState = __instance.Cells.GetEnumerator();
         }
         if (__instance.cachedOpenRoofCount < threshold && __instance.cachedOpenRoofState != null)
         {
             RoofGrid roofGrid = __instance.Map.roofGrid;
             while (__instance.cachedOpenRoofCount < threshold && __instance.cachedOpenRoofState.MoveNext())
             {
                 if (!roofGrid.Roofed(__instance.cachedOpenRoofState.Current))
                 {
                     ++__instance.cachedOpenRoofCount;
                 }
             }
             if (__instance.cachedOpenRoofCount < threshold)
             {
                 __instance.cachedOpenRoofState = null;
             }
         }
         __result = __instance.cachedOpenRoofCount;
     }
     return(false);
 }
Exemple #2
0
        private void initMap()
        {
            if (map != parent.Map)
            {
                if (map != null && lastFaction != null)
                {
                    unseeSeenCells(lastFaction, lastFactionShownCells);
                }
                if (!disabled && mapCompSeenFog != null)
                {
                    mapCompSeenFog.fowWatchers.Remove(this);
                }
                map                   = parent.Map;
                mapCompSeenFog        = map.getMapComponentSeenFog();
                thingGrid             = map.thingGrid;
                glowGrid              = map.glowGrid;
                roofGrid              = map.roofGrid;
                weatherManager        = map.weatherManager;
                lastFactionShownCells = mapCompSeenFog.getFactionShownCells(parent.Faction);

                if (!disabled)
                {
                    mapCompSeenFog.fowWatchers.Add(this);
                }

                mapSizeX = map.Size.x;
                mapSizeZ = map.Size.z;
            }
        }
        public static bool SetRoof(RoofGrid __instance, IntVec3 c, RoofDef def)
        {
            Map map = __instance.map;
            int mcc = map.cellIndices.CellToIndex(c);

            if (__instance.roofGrid[mcc] != def)
            {
                __instance.roofGrid[mcc] = def;
                map.glowGrid.MarkGlowGridDirty(c);
                //Comment the 3 following lines and uncomment the 4th to fix the roof notification -Sernior
                Room room = map.regionGrid.GetValidRegionAt_NoRebuild(c)?.Room;
                if (room != null)
                {
                    room.Notify_RoofChanged();
                }
                //map.regionGrid.GetValidRegionAt_NoRebuild(c)?.District.Notify_RoofChanged(); This fixes the roofs notification instead of the 3 previous lines -Sernior
                if (__instance.drawerInt != null)
                {
                    __instance.drawerInt.SetDirty();
                }

                map.mapDrawer.MapMeshDirty(c, MapMeshFlag.Roofs);
            }
            return(false);
        }
        // Token: 0x0600650C RID: 25868 RVA: 0x00233C80 File Offset: 0x00231E80
        public override void Resolve(ResolveParams rp)
        {
            Faction = rp.faction;
            HiveFactionExtension hiveFaction = Faction.def.GetModExtension <HiveFactionExtension>();

            cells.Clear();
            Map     map        = BaseGen.globalSettings.map;
            IntVec3 CenterCell = rp.rect.CenterCell;
            float   dist       = rp.rect.TopRight.DistanceTo(rp.rect.BottomLeft);

            //	Log.Message(Faction+" hive radius "+ dist);
            cells = map.AllCells.Where(x => x.DistanceTo(CenterCell) <= dist).ToList();
            RoofGrid       roofGrid = BaseGen.globalSettings.map.roofGrid;
            RoofDef        def      = rp.roofDef ?? RoofDefOf.RoofRockThick;
            List <IntVec3> cellst   = cells.Where(x => x.DistanceTo(CenterCell) < dist - 10).ToList();
            List <IntVec3> celle    = cells.Where(x => x.DistanceTo(CenterCell) > dist - 5 && x.DistanceTo(CenterCell) < dist).ToList();

            for (int i = 0; i < dist / 5; i++)
            {
                IntVec3 ce = celle.RandomElement();
                Rand.PushState();
                float size = Rand.Range(5, 10);
                Rand.PopState();
                cells.RemoveAll(x => ce.DistanceTo(x) < size);
            }
            foreach (IntVec3 c in cells)
            {
                roofGrid.SetRoof(c, def);
                map.terrainGrid.SetTerrain(c, TerrainDefOf.Gravel);
                this.TrySpawnWall(c, rp);
            }
        }
        public static void MakeTriangularRoom(Map map, ResolveParams rp)
        {
            if (rp.wallStuff == null)
            {
                Faction faction = Find.FactionManager.RandomNonHostileFaction(false, false, true, TechLevel.Spacer);

                rp.wallStuff = BaseGenUtility.RandomCheapWallStuff(faction, false);
            }
            if (rp.floorDef == null)
            {
                rp.floorDef = BaseGenUtility.CorrespondingTerrainDef(rp.wallStuff, true);
            }
            if (rp.floorDef == null)
            {
                rp.floorDef = BaseGenUtility.RandomBasicFloorDef(Faction.OfMechanoids, false);
            }
            ResolveParams resolveParams = rp;

            resolveParams.rect = new CellRect(rp.rect.minX, rp.rect.minZ, 1, rp.rect.Height);
            BaseGen.symbolStack.Push("edgeWalls", resolveParams, null);
            for (int i = 0; i <= rp.rect.Width; i++)
            {
                int num  = rp.rect.minX + i;
                int num2 = (int)Math.Floor((double)(0.5f * (float)i));
                int num3 = (int)Math.Ceiling((double)(0.5f * (float)i));
                for (int j = rp.rect.minZ + num2; j < rp.rect.minZ + rp.rect.Width - num2; j++)
                {
                    foreach (Thing thing in map.thingGrid.ThingsAt(new IntVec3(num, 1, j)))
                    {
                        thing.TakeDamage(new DamageInfo(DamageDefOf.Blunt, 10000, -1f, -1f, null, null, null, 0));
                    }
                    MapGenUtility.TryToSetFloorTile(new IntVec3(num, 1, j), map, rp.floorDef);
                    if (j == rp.rect.minZ + num2 || j == rp.rect.minZ + num3 || j == rp.rect.minZ + rp.rect.Width - (num2 + 1) || j == rp.rect.minZ + rp.rect.Width - (num3 + 1))
                    {
                        ResolveParams resolveParams2 = rp;
                        resolveParams2.rect = new CellRect(num, j, 1, 1);
                        BaseGen.symbolStack.Push("edgeWalls", resolveParams2, null);
                    }
                }
            }
            map.MapUpdate();
            RoofGrid roofGrid = BaseGen.globalSettings.map.roofGrid;
            RoofDef  def      = rp.roofDef ?? RoofDefOf.RoofConstructed;

            for (int k = 0; k <= rp.rect.Width; k++)
            {
                int newX = rp.rect.minX + k;
                int num4 = (int)Math.Floor((double)(0.5f * (float)k));
                for (int l = rp.rect.minZ + num4; l < rp.rect.minZ + rp.rect.Width - num4; l++)
                {
                    IntVec3 c = new IntVec3(newX, 1, l);
                    if (!roofGrid.Roofed(c))
                    {
                        roofGrid.SetRoof(c, def);
                    }
                }
            }
        }
        public static void SetRoof_postfix(RoofGrid __instance, IntVec3 c, RoofDef def)
        {
            FieldInfo       mapInfo = AccessTools.Field(typeof(RoofGrid), "map");
            Map             map     = (Map)mapInfo.GetValue(__instance);
            MapComp_Windows mapComp = map.GetComponent <MapComp_Windows>();

            if (mapComp != null && mapComp.WindowScanGrid[map.cellIndices.CellToIndex(c)] > 0)
            {
                mapComp.roofUpdateRequest = true;
            }
        }
Exemple #7
0
        static void Postfix(int index, ref RoofGrid __instance, ref Color __result)
        {
            if (BiomesCoreDefOf.BMT_RockRoofStable != null && __instance.RoofAt(index) == BiomesCoreDefOf.BMT_RockRoofStable)
            {
                //__result = Color.black;

                // light grey
                //__result = new Color(0.75f, 0.75f, 0.75f, 1f);

                // dark grey
                __result = new Color(0.25f, 0.25f, 0.25f, 1f);
            }
        }
 public override void Resolve(ResolveParams rp)
 {
     if (!rp.noRoof.HasValue || !rp.noRoof.Value)
     {
         RoofGrid roofGrid = BaseGen.globalSettings.map.roofGrid;
         RoofDef  def      = rp.roofDef ?? RoofDefOf.RoofConstructed;
         foreach (IntVec3 item in rp.rect)
         {
             if (!roofGrid.Roofed(item))
             {
                 roofGrid.SetRoof(item, def);
             }
         }
     }
 }
        public static void Postfix(RoofGrid __instance, IntVec3 c, RoofDef def, RoofDef __state)
        {
            if (Scribe.mode == LoadSaveMode.LoadingVars)
            {
                return;
            }
            bool    removing  = def == null;
            RoofDef defToPass = HarmonyPatcher.TransparentRoofs ? (removing ? __state : def) : def;
            var     info      = new MapUpdateWatcher.MapUpdateInfo()
            {
                center  = c,
                removed = removing,
                roofDef = defToPass,
                map     = (Map)MapInfo.GetValue(__instance)
            };

            MapUpdateWatcher.OnMapUpdate(__instance, info);
        }
 public override void Resolve(ResolveParams rp)
 {
     if (rp.noRoof == null || !rp.noRoof.Value)
     {
         RoofGrid roofGrid = BaseGen.globalSettings.map.roofGrid;
         RoofDef  def      = rp.roofDef ?? RoofDefOf.RoofConstructed;
         CellRect.CellRectIterator iterator = rp.rect.GetIterator();
         while (!iterator.Done())
         {
             IntVec3 c = iterator.Current;
             if (!roofGrid.Roofed(c))
             {
                 roofGrid.SetRoof(c, def);
             }
             iterator.MoveNext();
         }
     }
 }
        //public void SetRoof(IntVec3 c, RoofDef def)
        public static void Postfix(RoofGrid __instance, IntVec3 c, RoofDef def, Map ___map)
        {
            if (def == null)
            {
                return;
            }

            Map map = ___map;

            if (map == null || map.thingGrid == null || !map.regionAndRoomUpdater.Enabled)
            {
                return;
            }

            foreach (Thing t in map.thingGrid.ThingsAt(c))
            {
                RestoreHPToSafeItem.Restore(t, map);
            }
        }
Exemple #12
0
 private static void Prefix(RoofGrid __instance, ref IntVec3 c, ref RoofDef def)
 {
     try
     {
         if (def != null && !def.isNatural)
         {
             Map map      = Traverse.Create(__instance).Field("map").GetValue <Map>();
             var ZTracker = Current.Game.GetComponent <ZLevelsManager>();
             var upperMap = ZTracker.GetUpperLevel(map.Tile, map);
             if (upperMap != null && upperMap.terrainGrid.TerrainAt(c) == ZLevelsDefOf.ZL_OutsideTerrain)
             {
                 upperMap.terrainGrid.SetTerrain(c, ZLevelsDefOf.ZL_RoofTerrain);
             }
         }
         else if (def == null)
         {
             Map map = Traverse.Create(__instance).Field("map").GetValue <Map>();
             if (c.GetRoof(map) == RoofDefOf.RoofConstructed)
             {
                 var ZTracker = Current.Game.GetComponent <ZLevelsManager>();
                 Map upperMap = ZTracker.GetUpperLevel(map.Tile, map);
                 if (upperMap != null)
                 {
                     upperMap.terrainGrid.SetTerrain(c, ZLevelsDefOf.ZL_OutsideTerrain);
                     var thingList = c.GetThingList(upperMap);
                     for (int i = thingList.Count - 1; i >= 0; i--)
                     {
                         if (!(thingList[i] is Mineable || thingList[i] is Blueprint || thingList[i] is Frame))
                         {
                             //Log.Message(thingList[i] + " going down 3");
                             ZTracker.SimpleTeleportThing(thingList[i], c, map, false, 10);
                         }
                     }
                     ZLogger.Message("Removing roof " + c.GetRoof(map), true);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         //Log.Error("Error in Patch_SetRoof: " + ex);
     };
 }
        public static bool SetRoof(RoofGrid __instance, IntVec3 c, RoofDef def)
        {
            if (roofGrid(__instance)[map(__instance).cellIndices.CellToIndex(c)] != def)
            {
                roofGrid(__instance)[map(__instance).cellIndices.CellToIndex(c)] = def;
                map(__instance).glowGrid.MarkGlowGridDirty(c);
                Region validRegionAt_NoRebuild = map(__instance).regionGrid.GetValidRegionAt_NoRebuild(c);
                if (validRegionAt_NoRebuild != null && validRegionAt_NoRebuild.Room != null)
                {
                    validRegionAt_NoRebuild.Room.Notify_RoofChanged();
                }
                if (drawerInt(__instance) != null)
                {
                    drawerInt(__instance).SetDirty();
                }

                map(__instance).mapDrawer.MapMeshDirty(c, MapMeshFlag.Roofs);
            }
            return(false);
        }
        private void initMap()
        {
            if (map != parent.Map)
            {
                if (map != null && lastFaction != null)
                {
                    unseeSeenCells(lastFaction, lastFactionShownCells);
                }
                map                   = parent.Map;
                mapCompSeenFog        = map.getMapComponentSeenFog();
                thingGrid             = map.thingGrid;
                glowGrid              = map.glowGrid;
                roofGrid              = map.roofGrid;
                weatherManager        = map.weatherManager;
                lastFactionShownCells = mapCompSeenFog.getFactionShownCells(parent.Faction);

                mapSizeX = map.Size.x;
                mapSizeZ = map.Size.z;
            }
        }
Exemple #15
0
 private static void Prefix(RoofGrid __instance, ref IntVec3 c, ref RoofDef def, Map ___map)
 {
     try
     {
         if (def != null && !def.isNatural)
         {
             var ZTracker = ZUtils.ZTracker;
             var upperMap = ZTracker.GetUpperLevel(___map.Tile, ___map);
             if (upperMap != null && upperMap.terrainGrid.TerrainAt(c) == ZLevelsDefOf.ZL_OutsideTerrain)
             {
                 upperMap.terrainGrid.SetTerrain(c, ZLevelsDefOf.ZL_RoofTerrain);
             }
         }
         else if (def == null)
         {
             if (c.GetRoof(___map) == RoofDefOf.RoofConstructed)
             {
                 var ZTracker = ZUtils.ZTracker;
                 Map upperMap = ZTracker.GetUpperLevel(___map.Tile, ___map);
                 if (upperMap != null)
                 {
                     upperMap.terrainGrid.SetTerrain(c, ZLevelsDefOf.ZL_OutsideTerrain);
                     var thingList = c.GetThingList(upperMap);
                     for (int i = thingList.Count - 1; i >= 0; i--)
                     {
                         if (thingList[i].IsAllowedToSpawnBelow())
                         {
                             ZTracker.TeleportThing(thingList[i], c, ___map, false, 10);
                         }
                     }
                     ZLogger.Message("Removing roof " + c.GetRoof(___map));
                 }
             }
         }
     }
     catch (Exception ex)
     {
         //Log.Error("Error in Patch_SetRoof: " + ex);
     };
 }
Exemple #16
0
 public static bool OpenRoofCountStopAt(Room __instance, ref int __result, int threshold)
 {
     //IEnumerator<IntVec3> cachedOpenRoofState2 = __instance.Cells.GetEnumerator();
     //int cachedOpenRoofCount2 = -1;
     lock (__instance)
     {
         if (cachedOpenRoofCount(__instance) == -1 && cachedOpenRoofState(__instance) == null)
         {
             cachedOpenRoofCount(__instance) = 0;
             cachedOpenRoofState(__instance) = __instance.Cells.GetEnumerator();
         }
         if (cachedOpenRoofCount(__instance) < threshold && cachedOpenRoofState(__instance) != null)
         {
             RoofGrid roofGrid = __instance.Map.roofGrid;
             if (null != roofGrid)
             {
                 while (cachedOpenRoofCount(__instance) < threshold && cachedOpenRoofState(__instance).MoveNext())
                 {
                     IntVec3 currentRoofState = cachedOpenRoofState(__instance).Current;
                     if (null != currentRoofState)
                     {
                         if (!roofGrid.Roofed(currentRoofState))
                         {
                             cachedOpenRoofCount(__instance)++;
                         }
                     }
                 }
                 if (cachedOpenRoofCount(__instance) < threshold)
                 {
                     cachedOpenRoofState(__instance) = null;
                 }
             }
         }
         __result = cachedOpenRoofCount(__instance);
     }
     return(false);
 }
Exemple #17
0
 public static bool UnbreachableRoofed(this RoofGrid grid, int index)
 {
     return(grid.UnbreachableRoofed(grid.RoofAt(index)));
 }
Exemple #18
0
 public static bool UnbreachableRoofed(this RoofGrid grid, RoofDef roof)
 {
     return(roof != null && roof.UnbreachableRoofed());
 }
        public override void Generate(Map map, GenStepParams parms)
        {
            MapParent_PocketDimension mapParent = map.Parent as MapParent_PocketDimension;
            List <IntVec3>            list      = new List <IntVec3>();
            TerrainGrid terrainGrid             = map.terrainGrid;
            RoofGrid    roofGrid = map.roofGrid;

            string   terrainDefName = "CM_PocketDimensionFloor";
            ThingDef boxStuffDef    = null;

            // Build terrain defname
            Building_PocketDimensionBox box = PocketDimensionUtility.GetBox(mapParent.dimensionSeed);

            if (box != null && box.Stuff != null)
            {
                boxStuffDef = box.Stuff;
                if (boxStuffDef.stuffProps.categories.Contains(StuffCategoryDefOf.Metallic))
                {
                    terrainDefName += "Metal";
                }
                else if (boxStuffDef.stuffProps.categories.Contains(StuffCategoryDefOf.Stony))
                {
                    terrainDefName += "Stone";
                }
                else if (boxStuffDef.stuffProps.categories.Contains(StuffCategoryDefOf.Woody))
                {
                    terrainDefName += "Wood";
                }

                terrainDefName += "_" + boxStuffDef.defName;
            }

            // If that terrain was not found, use default metal terrain
            TerrainDef terrainDef = DefDatabase <TerrainDef> .GetNamedSilentFail(terrainDefName);

            if (terrainDef == null)
            {
                terrainDef = PocketDimensionDefOf.CM_PocketDimensionFloorMetal;
            }

            foreach (IntVec3 current in map.AllCells)
            {
                terrainGrid.SetTerrain(current, terrainDef);

                if (current.OnEdge(map))
                {
                    Thing wall = ThingMaker.MakeThing(PocketDimensionDefOf.CM_PocketDimensionWall, boxStuffDef);
                    wall.SetFaction(Faction.OfPlayer);
                    GenSpawn.Spawn(wall, current, map);
                }

                roofGrid.SetRoof(current, PocketDimensionDefOf.CM_PocketDimensionRoof);
            }
            MapGenFloatGrid elevation = MapGenerator.Elevation;

            foreach (IntVec3 allCell in map.AllCells)
            {
                elevation[allCell] = 0.0f;
            }
            MapGenFloatGrid fertility = MapGenerator.Fertility;

            foreach (IntVec3 allCell2 in map.AllCells)
            {
                fertility[allCell2] = 0.0f;
            }
        }
Exemple #20
0
 public static bool UnbreachableRoofed(this RoofGrid grid, IntVec3 c)
 {
     return(grid.UnbreachableRoofed(grid.RoofAt(c)));
 }
Exemple #21
0
 public static bool UnbreachableRoofed(this RoofGrid grid, int x, int z)
 {
     return(grid.UnbreachableRoofed(grid.RoofAt(x, z)));
 }
 public static void Prefix(RoofGrid __instance, IntVec3 c, out RoofDef __state)
 {
     __state = HarmonyPatcher.TransparentRoofs ? __instance.RoofAt(c) : null;
 }