public MapComponentSeenFog(Map map) : base(map) { mapCellLength = map.cellIndices.NumGridCells; mapSizeX = map.Size.x; mapSizeZ = map.Size.z; fogGrid = map.fogGrid; thingGrid = map.thingGrid; mapDrawer = map.mapDrawer; designationManager = this.map.designationManager; maxFactionLoadId = 0; foreach (Faction faction in Find.World.factionManager.AllFactionsListForReading) { maxFactionLoadId = Math.Max(maxFactionLoadId, faction.loadID); } factionsShownCells = new int[maxFactionLoadId + 1][]; knownCells = new bool[mapCellLength]; viewBlockerCells = new bool[mapCellLength]; idxToCellCache = new IntVec3[mapCellLength]; compHideFromPlayerGrid = new List <CompHideFromPlayer> [mapCellLength]; compAffectVisionGrid = new List <CompAffectVision> [mapCellLength]; for (int i = 0; i < mapCellLength; i++) { idxToCellCache[i] = CellIndicesUtility.IndexToCell(i, mapSizeX); compHideFromPlayerGrid[i] = new List <CompHideFromPlayer>(16); compAffectVisionGrid[i] = new List <CompAffectVision>(16); } }
//private void UnfogWorker(IntVec3 c) public static void Postfix(FogGrid __instance, IntVec3 c, Map ___map) { Map map = ___map; if (c.GetThingList(map).FirstOrDefault(t => t.def.IsBlueprint) is Thing blueprint && !blueprint.IsUnderFog()) { if (!GenConstruct.CanPlaceBlueprintAt(blueprint.def.entityDefToBuild, blueprint.Position, blueprint.Rotation, map, false, blueprint).Accepted) { blueprint.Destroy(); } else { blueprint.Notify_ColorChanged(); //does the job, haha. } } }
public override void PreOpen() { base.PreOpen(); //switch to the map view if the world view is active Find.World.renderer.wantedMode = RimWorld.Planet.WorldRenderMode.None; clearState(); FogGrid fogGrid = Find.CurrentMap.fogGrid; List <Thing> allThings = new List <Thing>(); //all items, buildings, animals and structures on the map but not the undiscovered terrain. allThings.AddRange(Find.CurrentMap.listerThings.AllThings.Where(t => /*!t.def.mineable || */ !fogGrid.IsFogged(t.Position))); //all the stuff that the colonists on the map have(not the stuff from prisoners, allies or enemies). foreach (Pawn p in Find.CurrentMap.mapPawns.FreeColonistsSpawned) { if (!p.Dead) { allThings.AddRange(ThingOwnerUtility.GetAllThingsRecursively(p, false)); } } //corpses for dead people foreach (Pawn p in Find.CurrentMap.mapPawns.AllPawnsSpawned) { if (p.Dead) { allThings.Add(p.Corpse); } } //grouping the things based on their archetype(e.g. all cowboy hats regardless of the material used) thingGroups = (from Thing t in allThings group t by t.def into newGroup orderby newGroup.Key.label select newGroup.ToList()).ToList(); //calculating the widest label and sizing the window to fit that label plus a scrollbar. float width = 0; foreach (List <Thing> g in thingGroups) { float x = Text.CalcSize(g.Count() + " " + g[0].def.label).x; if (x > width) { width = x; } } windowRect.width = width + 32; windowRect.height = 270; windowRect.y = (float)(UI.screenHeight - 35) - windowRect.height; }
public static void FogAll(Map map) { FogGrid fogGrid = map.fogGrid; if (fogGrid != null) { CellIndices cellIndices = map.cellIndices; if (fogGrid.fogGrid == null) { fogGrid.fogGrid = new bool[cellIndices.NumGridCells]; } foreach (IntVec3 current in map.AllCells) { fogGrid.fogGrid[cellIndices.CellToIndex(current)] = true; } if (Current.ProgramState == (ProgramState)2) { map.roofGrid.Drawer.SetDirty(); } } }
public static bool Fogged(ref bool __result, Thing t) { __result = false; if (t == null) { return(false); } Map map = t.Map; if (map == null) { return(false); } FogGrid fogGrid = map.fogGrid; if (fogGrid == null) { return(false); } __result = fogGrid.IsFogged(t.Position); return(false); }
static bool Prefix(ref FogGrid __instance, ref Map ___map, IntVec3 c) { if (!(___map.Parent is City)) { return(true); } __instance.Unfog(c); FloodUnfogResult floodUnfogResult = default(FloodUnfogResult); for (int i = 0; i < 4; i++) { IntVec3 intVec = c + GenAdj.CardinalDirections[i]; if (intVec.InBounds(___map) && intVec.Fogged(___map)) { Building edifice = intVec.GetEdifice(___map); if (edifice == null || !edifice.def.MakeFog) { floodUnfogResult = FloodFillerFog.FloodUnfog(intVec, ___map); } else { __instance.Unfog(intVec); } } } for (int j = 0; j < 8; j++) { IntVec3 c2 = c + GenAdj.AdjacentCells[j]; if (c2.InBounds(___map)) { Building edifice2 = c2.GetEdifice(___map); if (edifice2 != null && edifice2.def.MakeFog) { __instance.Unfog(c2); } } } return(false); }
static bool Prefix(ref FogGrid __instance, ref Map ___map, IntVec3 c) { if (___map.Parent is City) { var map = ___map; __instance.Unfog(c); for (var index = 0; index < 4; ++index) { var intVec3 = c + GenAdj.CardinalDirections[index]; if (intVec3.InBounds(map) && intVec3.Fogged(map)) { var edifice = intVec3.GetEdifice(map); if (edifice == null || !edifice.def.MakeFog) { FloodFillerFog.FloodUnfog(intVec3, map); } else { __instance.Unfog(intVec3); } } } for (var index = 0; index < 8; ++index) { var c1 = c + GenAdj.AdjacentCells[index]; if (c1.InBounds(map)) { var edifice = c1.GetEdifice(map); if (edifice != null && edifice.def.MakeFog) { __instance.Unfog(c1); } } } return(false); } return(true); }
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; 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 = true; 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 && !hasPartShownToPlayer()) { compHiddenable.hide(); } else if (!isPawn && !seenByPlayer && !hasPartShownToPlayer()) { compHiddenable.hide(); } else { seenByPlayer = true; compHiddenable.show(); } } else { seenByPlayer = true; compHiddenable.show(); } } else if ((forceUpdate || !seenByPlayer) && hasPartShownToPlayer()) { seenByPlayer = true; compHiddenable.show(); } } } } #if InternalProfile //ProfilingUtils.stopProfiling("CompHideFromPlayer.updateVisibility"); #endif }