private void init() { // Reveal the starting position if home map and no pawns (landing). if (map.IsPlayerHome && map.mapPawns.ColonistsSpawnedCount == 0) { IntVec3 playerStartSpot = MapGenerator.PlayerStartSpot; ShadowCaster.computeFieldOfViewWithShadowCasting(playerStartSpot.x, playerStartSpot.z, Mathf.RoundToInt(CompFieldOfViewWatcher.NON_MECH_DEFAULT_RANGE), viewBlockerCells, map.Size.x, map.Size.z, false, null, null, null, // Directly updating known cells. No need to call incrementSeen. knownCells, 0, 0, mapSizeX, null, 0, 0, 0, 0, 0); for (int i = 0; i < mapCellLength; i++) { if (knownCells[i]) { IntVec3 cell = CellIndicesUtility.IndexToCell(i, mapSizeX); foreach (Thing t in map.thingGrid.ThingsListAtFast(cell)) { CompMainComponent compMain = (CompMainComponent)t.TryGetComp(CompMainComponent.COMP_DEF); if (compMain != null && compMain.compHideFromPlayer != null) { compMain.compHideFromPlayer.forceSeen(); } } } } } // Update all thing FoV and visibility. foreach (Thing thing in map.listerThings.AllThings) { if (thing.Spawned) { CompMainComponent compMain = (CompMainComponent)thing.TryGetComp(CompMainComponent.COMP_DEF); if (compMain != null) { if (compMain.compComponentsPositionTracker != null) { compMain.compComponentsPositionTracker.updatePosition(); } if (compMain.compFieldOfViewWatcher != null) { compMain.compFieldOfViewWatcher.updateFoV(); } if (compMain.compHideFromPlayer != null) { compMain.compHideFromPlayer.updateVisibility(true); } } } } // Redraw everything. mapDrawer.RegenerateEverythingNow(); }
public static CompHiddenable TryGetCompHiddenable(this Thing _this) { CompMainComponent mainComp = (CompMainComponent)_this.TryGetComp(CompMainComponent.COMP_DEF); if (mainComp != null) { return(mainComp.compHiddenable); } return(null); }
private void updateViewBlockerCells(bool blockView) { bool[] viewBlockerCells = mapCompSeenFog.viewBlockerCells; int mapSizeZ = map.Size.z; int mapSizeX = map.Size.x; CellRect occupiedRect = parent.OccupiedRect(); for (int x = occupiedRect.minX; x <= occupiedRect.maxX; x++) { for (int z = occupiedRect.minZ; z <= occupiedRect.maxZ; z++) { if (x >= 0 && z >= 0 && x <= mapSizeX && z <= mapSizeZ) { viewBlockerCells[(z * mapSizeZ) + x] = blockView; } } } if (Current.ProgramState == ProgramState.Playing) { if (map != null) { List <Thing> things = map.listerThings.AllThings; for (int i = 0; i < things.Count; i++) { ThingWithComps thing = things[i] as ThingWithComps; if (thing != null) { CompMainComponent compMain = (CompMainComponent)thing.TryGetComp(CompMainComponent.COMP_DEF); if (compMain != null) { CompFieldOfViewWatcher cmpFov = compMain.compFieldOfViewWatcher; if (cmpFov != null && parent.Position.InHorDistOf(thing.Position, cmpFov.sightRange)) { cmpFov.updateFoV(true); } } } } } } }
private void init() { // Retrieve map sections and store in a linear array. Section[,] mapDrawerSections = (Section[, ])Traverse.Create(mapDrawer).Field("sections").GetValue(); sectionsSizeX = mapDrawerSections.GetLength(0); sectionsSizeY = mapDrawerSections.GetLength(1); sections = new Section[sectionsSizeX * sectionsSizeY]; for (int y = 0; y < sectionsSizeY; y++) { for (int x = 0; x < sectionsSizeX; x++) { sections[y * sectionsSizeX + x] = mapDrawerSections[x, y]; } } // Initialize mining designators (add notifications intercepted by detours aren't fired on load). List <Designation> designations = map.designationManager.allDesignations; for (int i = 0; i < designations.Count; i++) { Designation des = designations[i]; if (des.def == DesignationDefOf.Mine && !des.target.HasThing) { registerMineDesignation(des); } } // Reveal the starting position if home map and no pawns (landing). if (map.IsPlayerHome && map.mapPawns.ColonistsSpawnedCount == 0) { IntVec3 playerStartSpot = MapGenerator.PlayerStartSpot; ShadowCaster.computeFieldOfViewWithShadowCasting(playerStartSpot.x, playerStartSpot.z, Mathf.RoundToInt(CompFieldOfViewWatcher.NON_MECH_DEFAULT_RANGE), viewBlockerCells, map.Size.x, map.Size.z, false, null, null, null, // Directly updating known cells. No need to call incrementSeen. knownCells, 0, 0, mapSizeX, null, 0, 0, 0, 0, 0); for (int i = 0; i < mapCellLength; i++) { if (knownCells[i]) { IntVec3 cell = CellIndicesUtility.IndexToCell(i, mapSizeX); foreach (Thing t in map.thingGrid.ThingsListAtFast(cell)) { CompMainComponent compMain = (CompMainComponent)t.TryGetComp(CompMainComponent.COMP_DEF); if (compMain != null && compMain.compHideFromPlayer != null) { compMain.compHideFromPlayer.forceSeen(); } } } } } // Update all thing FoV and visibility. foreach (Thing thing in map.listerThings.AllThings) { if (thing.Spawned) { CompMainComponent compMain = (CompMainComponent)thing.TryGetComp(CompMainComponent.COMP_DEF); if (compMain != null) { if (compMain.compComponentsPositionTracker != null) { compMain.compComponentsPositionTracker.updatePosition(); } if (compMain.compFieldOfViewWatcher != null) { compMain.compFieldOfViewWatcher.updateFoV(); } if (compMain.compHideFromPlayer != null) { compMain.compHideFromPlayer.updateVisibility(true); } } } } // Redraw everything. mapDrawer.RegenerateEverythingNow(); }
private static bool fovLineOfSight(IntVec3 sourceSq, IntVec3 targetLoc, Thing thing) { // If the thing is mannable, then use the manning pawn to perform the calculation. CompMannable compMannable = thing.TryGetComp <CompMannable>(); if (compMannable != null) { thing = compMannable.ManningPawn; // Apply interaction cell offset. sourceSq += (thing.Position - thing.InteractionCell); } // If not a pawn, then doesn't need a fov calculation. if (!(thing is Pawn)) { return(true); } MapComponentSeenFog seenFog = thing.Map.getMapComponentSeenFog(); CompMainComponent compMain = (CompMainComponent)thing.TryGetComp(CompMainComponent.COMP_DEF); CompFieldOfViewWatcher compFoV = compMain.compFieldOfViewWatcher; // If requires moving, calculate only the base sight. int sightRange = Mathf.RoundToInt(compFoV.calcPawnSightRange(sourceSq, true, !thing.Position.AdjacentToCardinal(sourceSq))); if (!sourceSq.InHorDistOf(targetLoc, sightRange)) { // If out of sightRange. return(false); } // Limit to needed octant. IntVec3 dir = targetLoc - sourceSq; byte octant; if (dir.x >= 0) { if (dir.z >= 0) { if (dir.x >= dir.z) { octant = 0; } else { octant = 1; } } else { if (dir.x >= -dir.z) { octant = 7; } else { octant = 6; } } } else { if (dir.z >= 0) { if (-dir.x >= dir.z) { octant = 3; } else { octant = 2; } } else { if (-dir.x >= -dir.z) { octant = 4; } else { octant = 5; } } } Map map = thing.Map; bool[] targetFound = new bool[1]; ShadowCaster.computeFieldOfViewWithShadowCasting(sourceSq.x, sourceSq.z, sightRange, seenFog.viewBlockerCells, map.Size.x, map.Size.z, false, null, null, null, targetFound, 0, 0, 0, null, 0, 0, 0, 0, 0, octant, targetLoc.x, targetLoc.z); return(targetFound[0]); }