Beispiel #1
0
        public void WholeMapChanged(MapMeshFlag change)
        {
            int num = 0;

            while (true)
            {
                int     num2         = num;
                IntVec2 sectionCount = SectionCount;
                if (num2 >= sectionCount.x)
                {
                    break;
                }
                int num3 = 0;
                while (true)
                {
                    int     num4          = num3;
                    IntVec2 sectionCount2 = SectionCount;
                    if (num4 >= sectionCount2.z)
                    {
                        break;
                    }
                    sections[num, num3].dirtyFlags |= change;
                    num3++;
                }
                num++;
            }
        }
        public void MapMeshDirty(IntVec3 loc, MapMeshFlag dirtyFlags)
        {
            bool regenAdjacentCells    = (dirtyFlags & (MapMeshFlag.FogOfWar | MapMeshFlag.Buildings)) != MapMeshFlag.None;
            bool regenAdjacentSections = (dirtyFlags & MapMeshFlag.GroundGlow) != MapMeshFlag.None;

            this.MapMeshDirty(loc, dirtyFlags, regenAdjacentCells, regenAdjacentSections);
        }
 public void MapMeshDirty(IntVec3 loc, MapMeshFlag dirtyFlags, bool regenAdjacentCells, bool regenAdjacentSections)
 {
     if (Current.ProgramState == ProgramState.Playing)
     {
         Section section = this.SectionAt(loc);
         section.dirtyFlags |= dirtyFlags;
         if (regenAdjacentCells)
         {
             for (int i = 0; i < 8; i++)
             {
                 IntVec3 intVec = loc + GenAdj.AdjacentCells[i];
                 if (intVec.InBounds(this.map))
                 {
                     this.SectionAt(intVec).dirtyFlags |= dirtyFlags;
                 }
             }
         }
         if (regenAdjacentSections)
         {
             IntVec2 a = this.SectionCoordsAt(loc);
             for (int j = 0; j < 8; j++)
             {
                 IntVec3 intVec2      = GenAdj.AdjacentCells[j];
                 IntVec2 intVec3      = a + new IntVec2(intVec2.x, intVec2.z);
                 IntVec2 sectionCount = this.SectionCount;
                 if (intVec3.x >= 0 && intVec3.z >= 0 && intVec3.x <= sectionCount.x - 1 && intVec3.z <= sectionCount.z - 1)
                 {
                     Section section2 = this.sections[intVec3.x, intVec3.z];
                     section2.dirtyFlags |= dirtyFlags;
                 }
             }
         }
     }
 }
        static MapMeshFlagUtility()
        {
            IEnumerator enumerator = Enum.GetValues(typeof(MapMeshFlag)).GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    object      obj         = enumerator.Current;
                    MapMeshFlag mapMeshFlag = (MapMeshFlag)obj;
                    if (mapMeshFlag != MapMeshFlag.None)
                    {
                        MapMeshFlagUtility.allFlags.Add(mapMeshFlag);
                    }
                }
            }
            finally
            {
                IDisposable disposable;
                if ((disposable = (enumerator as IDisposable)) != null)
                {
                    disposable.Dispose();
                }
            }
        }
Beispiel #5
0
        public void WholeMapChanged(MapMeshFlag change)
        {
            int num = 0;

            while (true)
            {
                int     num2         = num;
                IntVec2 sectionCount = this.SectionCount;
                if (num2 < sectionCount.x)
                {
                    int num3 = 0;
                    while (true)
                    {
                        int     num4          = num3;
                        IntVec2 sectionCount2 = this.SectionCount;
                        if (num4 < sectionCount2.z)
                        {
                            this.sections[num, num3].dirtyFlags |= change;
                            num3++;
                            continue;
                        }
                        break;
                    }
                    num++;
                    continue;
                }
                break;
            }
        }
        public static bool Prefix(MethodBase __originalMethod, Section __instance, MapMeshFlag changeType)
        {
            if (p.Active)
            {
                for (int i = 0; i < __instance.layers.Count; i++)
                {
                    SectionLayer sectionLayer = __instance.layers[i];
                    if ((sectionLayer.relevantChangeTypes & changeType) != MapMeshFlag.None)
                    {
                        try
                        {
                            var prof = p.Start(__instance.layers[i].GetType().FullName, __originalMethod);
                            sectionLayer.Regenerate();
                            prof.Stop();
                        }
                        catch (Exception ex)
                        {
                            Log.Error(string.Concat(new object[]
                            {
                                "Could not regenerate layer ",
                                sectionLayer.ToStringSafe <SectionLayer>(),
                                ": ",
                                ex
                            }), false);
                        }
                    }
                }

                return(false);
            }

            return(true);
        }
Beispiel #7
0
        static MapMeshFlagUtility()
        {
            MapMeshFlagUtility.allFlags = new List <MapMeshFlag>();
            IEnumerator enumerator = Enum.GetValues(typeof(MapMeshFlag)).GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    MapMeshFlag mapMeshFlag = (MapMeshFlag)enumerator.Current;
                    if (mapMeshFlag != 0)
                    {
                        MapMeshFlagUtility.allFlags.Add(mapMeshFlag);
                    }
                }
            }
            finally
            {
                IDisposable disposable;
                if ((disposable = (enumerator as IDisposable)) != null)
                {
                    disposable.Dispose();
                }
            }
        }
Beispiel #8
0
 public void RegenerateLayers(MapMeshFlag changeType)
 {
     for (int i = 0; i < this.layers.Count; i++)
     {
         SectionLayer sectionLayer = this.layers[i];
         if ((sectionLayer.relevantChangeTypes & changeType) != MapMeshFlag.None)
         {
             Profiler.BeginSample(string.Concat(new object[]
             {
                 "Regen ",
                 sectionLayer.GetType().Name,
                 " ",
                 this.botLeft
             }));
             try
             {
                 sectionLayer.Regenerate();
             }
             catch (Exception ex)
             {
                 Log.Error(string.Concat(new object[]
                 {
                     "Could not regenerate layer ",
                     sectionLayer.ToStringSafe <SectionLayer>(),
                     ": ",
                     ex
                 }), false);
             }
             Profiler.EndSample();
         }
     }
 }
 public void WholeMapChanged(MapMeshFlag change)
 {
     for (int i = 0; i < this.SectionCount.x; i++)
     {
         for (int j = 0; j < this.SectionCount.z; j++)
         {
             this.sections[i, j].dirtyFlags |= change;
         }
     }
 }
Beispiel #10
0
 public void RegenerateLayers(MapMeshFlag changeType)
 {
     for (int i = 0; i < this.layers.Count; i++)
     {
         SectionLayer sectionLayer = this.layers[i];
         if ((sectionLayer.relevantChangeTypes & changeType) != MapMeshFlag.None)
         {
             sectionLayer.Regenerate();
         }
     }
 }
 private bool TryUpdateSection(Section sect)
 {
     if (sect.dirtyFlags == MapMeshFlag.None)
     {
         return(false);
     }
     for (int i = 0; i < MapMeshFlagUtility.allFlags.Count; i++)
     {
         MapMeshFlag mapMeshFlag = MapMeshFlagUtility.allFlags[i];
         if ((sect.dirtyFlags & mapMeshFlag) != MapMeshFlag.None)
         {
             sect.RegenerateLayers(mapMeshFlag);
         }
     }
     sect.dirtyFlags = MapMeshFlag.None;
     return(true);
 }
 public void RegenerateLayers(MapMeshFlag changeType)
 {
     for (int i = 0; i < layers.Count; i++)
     {
         SectionLayer sectionLayer = layers[i];
         if ((sectionLayer.relevantChangeTypes & changeType) != 0)
         {
             try
             {
                 sectionLayer.Regenerate();
             }
             catch (Exception ex)
             {
                 Log.Error("Could not regenerate layer " + sectionLayer.ToStringSafe() + ": " + ex);
             }
         }
     }
 }
Beispiel #13
0
        private void updateMeshes()
        {
            if (map != parent.Map)
            {
                map     = parent.Map;
                mapComp = map.getMapComponentSeenFog();
            }

            // Update meshes only if the map has been already initialized (sometime this is called when the map drawer isn't initialized yet).
            if (mapComp != null && mapComp.initialized)
            {
                MapMeshFlag allFlags = MapMeshFlag.Buildings | MapMeshFlag.BuildingsDamage | MapMeshFlag.GroundGlow | MapMeshFlag.PowerGrid | MapMeshFlag.Roofs | MapMeshFlag.Snow | MapMeshFlag.Terrain | MapMeshFlag.Things | MapMeshFlag.Zone;
                foreach (IntVec3 cell in parent.OccupiedRect().Cells)
                {
                    if (cell.InBounds(map))
                    {
                        map.mapDrawer.MapMeshDirty(cell, allFlags, false, false);
                    }
                }
            }
        }
        static SectionLayer_FoVLayer()
        {
            // Probably not needed... check just in case the static constructor is executed more than one time (extensions, etc)...
            if (mapMeshFlag == MapMeshFlag.None)
            {
                // Inject new flag.
                List <MapMeshFlag> allFlags       = (List <MapMeshFlag>) typeof(MapDrawer).Assembly.GetType("Verse.MapMeshFlagUtility").GetField("allFlags", GenGeneric.BindingFlagsAll).GetValue(null);
                MapMeshFlag        maxMapMeshFlag = MapMeshFlag.None;
                foreach (MapMeshFlag mapMeshFlag in allFlags)
                {
                    if (mapMeshFlag > maxMapMeshFlag)
                    {
                        maxMapMeshFlag = mapMeshFlag;
                    }
                }
                SectionLayer_FoVLayer.mapMeshFlag = (MapMeshFlag)(((int)maxMapMeshFlag) * 2);
                allFlags.Add(SectionLayer_FoVLayer.mapMeshFlag);

                Log.Message("Injected new mapMeshFlag: " + SectionLayer_FoVLayer.mapMeshFlag);
            }
        }
Beispiel #15
0
        static SectionLayer_FoVLayer()
        {
            // Probably not needed... check just in case the static constructor is executed more than one time (extensions, etc)...
            if (mapMeshFlag == MapMeshFlag.None)
            {
                // Inject new flag.
                List <MapMeshFlag> allFlags       = MapMeshFlagUtility.allFlags;
                MapMeshFlag        maxMapMeshFlag = MapMeshFlag.None;
                foreach (MapMeshFlag mapMeshFlag in allFlags)
                {
                    if (mapMeshFlag > maxMapMeshFlag)
                    {
                        maxMapMeshFlag = mapMeshFlag;
                    }
                }
                SectionLayer_FoVLayer.mapMeshFlag = (MapMeshFlag)(((int)maxMapMeshFlag) << 1);
                allFlags.Add(SectionLayer_FoVLayer.mapMeshFlag);

                Log.Message("Injected new mapMeshFlag: " + SectionLayer_FoVLayer.mapMeshFlag);
            }
        }
Beispiel #16
0
 public void RegenerateLayers(MapMeshFlag changeType)
 {
     for (int i = 0; i < this.layers.Count; i++)
     {
         SectionLayer sectionLayer = this.layers[i];
         if ((sectionLayer.relevantChangeTypes & changeType) != MapMeshFlag.None)
         {
             try
             {
                 sectionLayer.Regenerate();
             }
             catch (Exception ex)
             {
                 Log.Error(string.Concat(new object[]
                 {
                     "Could not regenerate layer ",
                     sectionLayer.ToStringSafe <SectionLayer>(),
                     ": ",
                     ex
                 }), false);
             }
         }
     }
 }
Beispiel #17
0
        public override void DeSpawn()
        {
            Map map = base.Map;

            base.DeSpawn();
            if (this.def.IsEdifice())
            {
                map.edificeGrid.DeRegister(this);
            }
            if (this.def.MakeFog)
            {
                map.fogGrid.Notify_FogBlockerRemoved(base.Position);
            }
            if (this.def.holdsRoof)
            {
                RoofCollapseCellsFinder.Notify_RoofHolderDespawned(this, map);
            }
            if (this.sustainerAmbient != null)
            {
                this.sustainerAmbient.End();
            }
            CellRect cellRect = this.OccupiedRect();

            for (int i = cellRect.minZ; i <= cellRect.maxZ; i++)
            {
                for (int j = cellRect.minX; j <= cellRect.maxX; j++)
                {
                    IntVec3     loc         = new IntVec3(j, 0, i);
                    MapMeshFlag mapMeshFlag = MapMeshFlag.Buildings;
                    if (this.def.coversFloor)
                    {
                        mapMeshFlag |= MapMeshFlag.Terrain;
                    }
                    if (this.def.Fillage == FillCategory.Full)
                    {
                        mapMeshFlag |= MapMeshFlag.Roofs;
                        mapMeshFlag |= MapMeshFlag.Snow;
                    }
                    map.mapDrawer.MapMeshDirty(loc, mapMeshFlag);
                    map.glowGrid.MarkGlowGridDirty(loc);
                }
            }
            map.listerBuildings.Remove(this);
            map.listerBuildingsRepairable.Notify_BuildingDeSpawned(this);
            if (this.def.leaveTerrain != null && Current.ProgramState == ProgramState.Playing)
            {
                CellRect.CellRectIterator iterator = this.OccupiedRect().GetIterator();
                while (!iterator.Done())
                {
                    map.terrainGrid.SetTerrain(iterator.Current, this.def.leaveTerrain);
                    iterator.MoveNext();
                }
            }
            map.designationManager.Notify_BuildingDespawned(this);
            if (!this.CanBeSeenOver())
            {
                map.exitMapGrid.Notify_LOSBlockerDespawned();
            }
            if (this.def.building.hasFuelingPort)
            {
                IntVec3        fuelingPortCell = FuelingPortUtility.GetFuelingPortCell(base.Position, base.Rotation);
                CompLaunchable compLaunchable  = FuelingPortUtility.LaunchableAt(fuelingPortCell, map);
                if (compLaunchable != null)
                {
                    compLaunchable.Notify_FuelingPortSourceDeSpawned();
                }
            }
            if (this.def.building.ai_combatDangerous)
            {
                AvoidGridMaker.Notify_CombatDangerousBuildingDespawned(this, map);
            }
        }
Beispiel #18
0
        public override void DeSpawn(DestroyMode mode = DestroyMode.Vanish)
        {
            var map = Map;     // before DeSpawn!

            base.DeSpawn(mode);

            if (def.IsEdifice())
            {
                map.edificeGrid.DeRegister(this);
            }

            if (mode != DestroyMode.WillReplace)
            {
                if (def.MakeFog)
                {
                    map.fogGrid.Notify_FogBlockerRemoved(Position);
                }

                if (def.holdsRoof)
                {
                    RoofCollapseCellsFinder.Notify_RoofHolderDespawned(this, map);
                }

                if (def.IsSmoothable)
                {
                    SmoothSurfaceDesignatorUtility.Notify_BuildingDespawned(this, map);
                }
            }

            if (sustainerAmbient != null)
            {
                sustainerAmbient.End();
            }

            CellRect occRect = GenAdj.OccupiedRect(this);

            for (int z = occRect.minZ; z <= occRect.maxZ; z++)
            {
                for (int x = occRect.minX; x <= occRect.maxX; x++)
                {
                    IntVec3 c = new IntVec3(x, 0, z);

                    MapMeshFlag changeType = MapMeshFlag.Buildings;

                    if (def.coversFloor)
                    {
                        changeType |= MapMeshFlag.Terrain;
                    }

                    if (def.Fillage == FillCategory.Full)
                    {
                        changeType |= MapMeshFlag.Roofs;
                        changeType |= MapMeshFlag.Snow;
                    }

                    map.mapDrawer.MapMeshDirty(c, changeType);

                    map.glowGrid.MarkGlowGridDirty(c);
                }
            }

            map.listerBuildings.Remove(this);
            map.listerBuildingsRepairable.Notify_BuildingDeSpawned(this);

            if (def.building.leaveTerrain != null && Current.ProgramState == ProgramState.Playing && canChangeTerrainOnDestroyed)
            {
                for (var cri = GenAdj.OccupiedRect(this).GetIterator(); !cri.Done(); cri.MoveNext())
                {
                    map.terrainGrid.SetTerrain(cri.Current, def.building.leaveTerrain);
                }
            }

            //Mining, planning, etc
            map.designationManager.Notify_BuildingDespawned(this);

            if (!this.CanBeSeenOver())
            {
                map.exitMapGrid.Notify_LOSBlockerDespawned();
            }

            if (def.building.hasFuelingPort)
            {
                var fuelingPortCell = FuelingPortUtility.GetFuelingPortCell(Position, Rotation);
                var launchable      = FuelingPortUtility.LaunchableAt(fuelingPortCell, map);

                if (launchable != null)
                {
                    launchable.Notify_FuelingPortSourceDeSpawned();
                }
            }

            //Must go after removing from buildings list
            map.avoidGrid.Notify_BuildingDespawned(this);
        }
Beispiel #19
0
        public override void DeSpawn(DestroyMode mode = DestroyMode.Vanish)
        {
            Map map = base.Map;

            base.DeSpawn(mode);
            if (def.IsEdifice())
            {
                map.edificeGrid.DeRegister(this);
                if (def.Fillage == FillCategory.Full)
                {
                    map.terrainGrid.Drawer.SetDirty();
                }
                if (def.AffectsFertility)
                {
                    map.fertilityGrid.Drawer.SetDirty();
                }
            }
            if (mode != DestroyMode.WillReplace)
            {
                if (def.MakeFog)
                {
                    map.fogGrid.Notify_FogBlockerRemoved(base.Position);
                }
                if (def.holdsRoof)
                {
                    RoofCollapseCellsFinder.Notify_RoofHolderDespawned(this, map);
                }
                if (def.IsSmoothable)
                {
                    SmoothSurfaceDesignatorUtility.Notify_BuildingDespawned(this, map);
                }
            }
            if (sustainerAmbient != null)
            {
                sustainerAmbient.End();
            }
            CellRect cellRect = this.OccupiedRect();

            for (int i = cellRect.minZ; i <= cellRect.maxZ; i++)
            {
                for (int j = cellRect.minX; j <= cellRect.maxX; j++)
                {
                    IntVec3     loc         = new IntVec3(j, 0, i);
                    MapMeshFlag mapMeshFlag = MapMeshFlag.Buildings;
                    if (def.coversFloor)
                    {
                        mapMeshFlag |= MapMeshFlag.Terrain;
                    }
                    if (def.Fillage == FillCategory.Full)
                    {
                        mapMeshFlag |= MapMeshFlag.Roofs;
                        mapMeshFlag |= MapMeshFlag.Snow;
                    }
                    map.mapDrawer.MapMeshDirty(loc, mapMeshFlag);
                    map.glowGrid.MarkGlowGridDirty(loc);
                }
            }
            map.listerBuildings.Remove(this);
            map.listerBuildingsRepairable.Notify_BuildingDeSpawned(this);
            map.listerArtificialBuildingsForMeditation.Notify_BuildingDeSpawned(this);
            if (def.building.leaveTerrain != null && Current.ProgramState == ProgramState.Playing && canChangeTerrainOnDestroyed)
            {
                foreach (IntVec3 item in this.OccupiedRect())
                {
                    map.terrainGrid.SetTerrain(item, def.building.leaveTerrain);
                }
            }
            map.designationManager.Notify_BuildingDespawned(this);
            if (!this.CanBeSeenOver())
            {
                map.exitMapGrid.Notify_LOSBlockerDespawned();
            }
            if (def.building.hasFuelingPort)
            {
                FuelingPortUtility.LaunchableAt(FuelingPortUtility.GetFuelingPortCell(base.Position, base.Rotation), map)?.Notify_FuelingPortSourceDeSpawned();
            }
            map.avoidGrid.Notify_BuildingDespawned(this);
        }