public void DoGlow() { if (this.glower == null) { Log.Message("glower null"); } if (this.glower != null && glower.parent != null && this.Map != null) { //Log.Message("glower not null, glow center " + glowCenter); if (this.glowCenter != default(IntVec3) && this.pawn.Spawned) { this.Map.mapDrawer.MapMeshDirty(glowCenter, MapMeshFlag.Things); GlowGrid gg = this.Map.glowGrid; HashSet <CompGlower> litGlowers = Traverse.Create(root: gg).Field(name: "litGlowers").GetValue <HashSet <CompGlower> >(); litGlowers.Add(glower); Traverse.Create(root: gg).Field(name: "litGlowers").SetValue(litGlowers); gg.MarkGlowGridDirty(glowCenter); if (Current.ProgramState != ProgramState.Playing) { List <IntVec3> locs = Traverse.Create(root: gg).Field(name: "initialGlowerLocs").GetValue <List <IntVec3> >(); locs.Add(glowCenter); Traverse.Create(root: gg).Field(name: "initialGlowerLocs").SetValue(locs); } //this.Map.glowGrid.RegisterGlower(glower); this.glowing = true; } } }
internal static void Prefix(GlowGrid __instance) { var map = __instance.map; if (!TryRegisterMap(map)) { return; } if (Finder.refreshGrid) { tEmptyGrid.CopyTo(__instance.glowGrid, 0); tEmptyGrid.CopyTo(__instance.glowGridNoCavePlants, 0); return; } if (tEmptyGrid == null || tEmptyGrid.Length != __instance.glowGrid.Length) { tEmptyGrid = new Color32[__instance.glowGrid.Length]; tBufferedGrid = new Color32[__instance.glowGrid.Length]; for (int i = 0; i < __instance.glowGrid.Length; i++) { tEmptyGrid[i] = new Color32(0, 0, 0, 0); } } tEmptyGrid.CopyTo(__instance.glowGridNoCavePlants, 0); calculating = true; }
private static void FixRemovedGlowers(GlowGrid instance, GlowerPorperties prop) { if (prop.glower?.parent?.Destroyed ?? true) { calculating = false; instance.MarkGlowGridDirty(prop.position.ToIntVec3()); calculating = true; } var flooder = instance.map.glowFlooder; var mapIndex = instance.map.Index; foreach (var otherGlower in instance.litGlowers) { var other = GlowerPorperties.GetGlowerPorperties(otherGlower); if (other != prop && other.drawen && other.Inersects(prop)) { FloodGlow(other, tBufferedGrid, instance.map, flooder); } } foreach (var index in prop.indices) { instance.glowGrid[index] = tBufferedGrid[index]; #if DEBUG if (Finder.drawGlowerUpdates) { instance.map.debugDrawer.FlashCell( instance.map.cellIndices.IndexToCell(index), 0.05f, "_1_", 50); } #endif } }
internal static void Prefix(GlowGrid __instance, CompGlower oldGlow) { Map map = __instance.map; deregister = true; TryRegisterMap(map); GlowerPorperties prop; if (Finder.debug) { Log.Message(string.Format("ROCKETMAN: Removed {0}", oldGlow)); } if (!props.ContainsKey(oldGlow)) { if (Finder.debug && !removedProps[map.Index].Any(p => p.glower == oldGlow)) { Log.Warning(string.Format("ROCKETMAN: Found an unregisterd {0}:{1}", oldGlow, oldGlow.parent)); } return; } prop = props[oldGlow]; if (Finder.debug) { Log.Message(string.Format("ROCKETMAN: Queued {0} for removal", oldGlow.parent)); } removedProps[map.Index].Add(prop); }
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; } }
private static void FinalizeCleanUp(GlowGrid instance) { var map = instance.map; var mapIndex = map.Index; removedProps[mapIndex].Clear(); changedProps[mapIndex].Clear(); }
public static void InitAvoidGlowGrid( Pawn pawn) { GlowGrid localGlowGrid = pawn?.Map?.glowGrid; if (localGlowGrid == null) { return; } }
private static void FinalizeNewGlowers(GlowGrid instance) { var map = instance.map; var flooder = map.glowFlooder; foreach (var glower in instance.litGlowers) { var prop = GlowerPorperties.GetGlowerPorperties(glower); if (!prop.drawen) { flooder.AddFloodGlowFor(prop.glower, instance.glowGrid); } } }
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; } }
public static void Prefix(GlowGrid __instance, IntVec3 loc) { if (Current.ProgramState == ProgramState.Playing) { var map = __instance.map; var mapIndex = map.Index; if (TryRegisterMap(map)) { if (!loc.IsValid || !loc.InBounds(map)) { return; } if (register || calculating || deregister) { return; } #if DEBUG if (Finder.debug) { Log.Message(string.Format("ROCKETMAN: Map glow grid dirty at {0}", loc)); } #endif var changedPos = loc.ToVector3(); foreach (var glower in __instance.litGlowers) { var prop = GlowerPorperties.GetGlowerPorperties(glower); if (prop.Contains(changedPos)) { changedProps[mapIndex].Add(prop); #if DEBUG if (Finder.debug) { Log.Message(string.Format("ROCKETMAN: Changed and glow grid dirty at {0} for {1}", loc, glower.parent)); } #endif } } } } }
internal static void Prefix(GlowGrid __instance, CompGlower newGlow) { Map map = __instance.map; register = true; TryRegisterMap(map); GlowerPorperties prop = GlowerPorperties.GetGlowerPorperties(newGlow); if (props.ContainsKey(newGlow)) { if (Finder.debug) { Log.Warning(string.Format("ROCKETMAN: Double registering an registered glower {0}:{1}", newGlow, newGlow.parent)); } return; } if (Finder.debug) { Log.Warning(string.Format("ROCKETMAN: Registering an registered glower {0}:{1}", newGlow, newGlow.parent)); } }
internal static void Postfix(GlowGrid __instance) { var map = __instance.map; var mapIndex = map.Index; if (Finder.refreshGrid) { Finder.refreshGrid = false; return; } if (Finder.debug) { Log.Message(string.Format("ROCKETMAN: Recalculationg for removed with {0} queued for removal", removedProps[mapIndex].Count)); } foreach (var prop in removedProps[mapIndex]) { tEmptyGrid.CopyTo(tBufferedGrid, 0); FixRemovedGlowers(__instance, prop); props.Remove(prop.glower); } if (Finder.debug) { Log.Message(string.Format("ROCKETMAN: Recalculationg for changes with {0} queued for changes", changedProps[mapIndex].Count)); } if (changedProps[mapIndex].Count != 0) { tEmptyGrid.CopyTo(tBufferedGrid, 0); FixChanged(__instance); } calculating = false; FinalizeNewGlowers(__instance); FinalizeCleanUp(__instance); }
static void Postfix(GlowGrid __instance) { __instance.litGlowers = new HashSet <CompGlower>(new CompGlowerEquality()); }
private static void FixChanged(GlowGrid instance) { var map = instance.map; var mapIndex = map.Index; var queue = new Queue <GlowerPorperties>(); foreach (var glower in instance.litGlowers) { var prop = GlowerPorperties.GetGlowerPorperties(glower); queue.Enqueue(prop); } while (true) { var count = changedProps[mapIndex].Count; var tqueue = new Queue <GlowerPorperties>(); var changedArray = changedProps[mapIndex].ToArray(); while (queue.Count > 0) { var prop = queue.Dequeue(); if (!prop.drawen || changedProps[mapIndex].Contains(prop)) { continue; } var found = false; foreach (var other in changedArray) { if (other != prop && other.Inersects(prop)) { changedProps[mapIndex].Add(prop); found = true; break; } } if (!found) { tqueue.Enqueue(prop); } } if (count == changedProps[mapIndex].Count) { break; } queue = tqueue; } foreach (var prop in changedProps[mapIndex]) { foreach (var index in prop.indices) { instance.glowGrid[index] = new Color32(0, 0, 0, 0); #if DEBUG if (Finder.drawGlowerUpdates) { map.debugDrawer.FlashCell(map.cellIndices.IndexToCell(index), 0.6f, "000", 10); } #endif } } foreach (var prop in changedProps[mapIndex]) { FloodGlow(prop, tBufferedGrid, map, map.glowFlooder); } foreach (var prop in changedProps[mapIndex]) { foreach (var index in prop.indices) { instance.glowGrid[index] = tBufferedGrid[index]; #if DEBUG if (Finder.drawGlowerUpdates) { map.debugDrawer.FlashCell(map.cellIndices.IndexToCell(index), 0.6f, "1__", 50); } #endif } } }
public void updateVisibility(bool forceCheck, bool forceUpdate = false) { if (!setupDone || Current.ProgramState == ProgramState.MapInitializing) { return; } #if InternalProfile //ProfilingUtils.startProfiling("CompHideFromPlayer.updateVisibility"); #endif Thing thing = base.parent; IntVec3 newPosition = thing.Position; Rot4 newRotation = thing.Rotation; if (thing != null && thing.Spawned && thing.Map != null && newPosition != iv3Invalid && (isOneCell || newRotation != r4Invalid)) { if (map != thing.Map) { map = thing.Map; fogGrid = map.fogGrid; glowGrid = map.glowGrid; mapCompSeenFog = thing.Map.getMapComponentSeenFog(); } else if (mapCompSeenFog == null) { mapCompSeenFog = thing.Map.getMapComponentSeenFog(); } if (mapCompSeenFog == null) { return; } if (forceCheck || !calculated || newPosition != lastPosition || (!isOneCell && newRotation != lastRotation)) { calculated = !isPawn; // always recalculate pawns lastPosition = newPosition; lastRotation = newRotation; bool belongToPlayer = thing.Faction != null && thing.Faction.IsPlayer; if (mapCompSeenFog != null && !fogGrid.IsFogged(lastPosition)) { if (isSaveable && !saveCompressible) { if (!belongToPlayer) { if (isPawn && !canBeSeen(lastPosition, true)) { compHiddenable.hide(); } else if (!isPawn && !seenByPlayer && !canBeSeen(lastPosition, false)) { compHiddenable.hide(); } else { seenByPlayer = true; compHiddenable.show(); } } else { seenByPlayer = true; compHiddenable.show(); } } else if ((forceUpdate || !seenByPlayer) && canBeSeen(lastPosition, false)) { seenByPlayer = true; compHiddenable.show(); } } } } #if InternalProfile //ProfilingUtils.stopProfiling("CompHideFromPlayer.updateVisibility"); #endif }