public bool IsFogged(IntVec3 c) { return(c.InBounds(this.map) && this.fogGrid != null && this.fogGrid[this.map.cellIndices.CellToIndex(c)]); }
private static PlaceSpotQuality PlaceSpotQualityAt(IntVec3 c, Map map, Thing thing, IntVec3 center, bool allowStacking, Predicate <IntVec3> extraValidator = null) { if (!c.InBounds(map) || !c.Walkable(map)) { return(PlaceSpotQuality.Unusable); } if (extraValidator != null && !extraValidator(c)) { return(PlaceSpotQuality.Unusable); } List <Thing> list = map.thingGrid.ThingsListAt(c); for (int i = 0; i < list.Count; i++) { Thing thing2 = list[i]; if (thing.def.saveCompressible && thing2.def.saveCompressible) { return(PlaceSpotQuality.Unusable); } if (thing.def.category == ThingCategory.Item && thing2.def.category == ThingCategory.Item && (!thing2.CanStackWith(thing) || thing2.stackCount >= thing.def.stackLimit)) { return(PlaceSpotQuality.Unusable); } } if (c.GetRoom(map) != center.GetRoom(map)) { if (!map.reachability.CanReach(center, c, PathEndMode.OnCell, TraverseMode.PassDoors, Danger.Deadly)) { return(PlaceSpotQuality.Awful); } return(PlaceSpotQuality.Bad); } if (allowStacking) { for (int j = 0; j < list.Count; j++) { Thing thing3 = list[j]; if (thing3.def.category == ThingCategory.Item && thing3.CanStackWith(thing) && thing3.stackCount < thing.def.stackLimit) { return(PlaceSpotQuality.Perfect); } } } bool flag = (thing as Pawn)?.Downed ?? false; PlaceSpotQuality placeSpotQuality = PlaceSpotQuality.Perfect; for (int k = 0; k < list.Count; k++) { Thing thing4 = list[k]; if (thing4.def.IsDoor) { return(PlaceSpotQuality.Bad); } if (thing4 is Building_WorkTable) { return(PlaceSpotQuality.Bad); } Pawn pawn = thing4 as Pawn; if (pawn != null) { if (pawn.Downed || flag) { return(PlaceSpotQuality.Bad); } if ((int)placeSpotQuality > 3) { placeSpotQuality = PlaceSpotQuality.Okay; } } if (thing4.def.category == ThingCategory.Plant && thing4.def.selectable && (int)placeSpotQuality > 3) { placeSpotQuality = PlaceSpotQuality.Okay; } } return(placeSpotQuality); }
public static void EqualizeTemperaturesThroughBuilding(Building b, float rate, bool twoWay) { int num = 0; float num2 = 0f; if (twoWay) { for (int i = 0; i < 2; i++) { IntVec3 intVec = (i != 0) ? (b.Position - b.Rotation.FacingCell) : (b.Position + b.Rotation.FacingCell); if (intVec.InBounds(b.Map)) { RoomGroup roomGroup = intVec.GetRoomGroup(b.Map); if (roomGroup != null) { num2 += roomGroup.Temperature; GenTemperature.beqRoomGroups[num] = roomGroup; num++; } } } } else { for (int j = 0; j < 4; j++) { IntVec3 intVec2 = b.Position + GenAdj.CardinalDirections[j]; if (intVec2.InBounds(b.Map)) { RoomGroup roomGroup2 = intVec2.GetRoomGroup(b.Map); if (roomGroup2 != null) { num2 += roomGroup2.Temperature; GenTemperature.beqRoomGroups[num] = roomGroup2; num++; } } } } if (num == 0) { return; } float num3 = num2 / (float)num; RoomGroup roomGroup3 = b.GetRoomGroup(); if (roomGroup3 != null) { roomGroup3.Temperature = num3; } if (num == 1) { return; } float num4 = 1f; for (int k = 0; k < num; k++) { if (!GenTemperature.beqRoomGroups[k].UsesOutdoorTemperature) { float temperature = GenTemperature.beqRoomGroups[k].Temperature; float num5 = num3 - temperature; float num6 = num5 * rate; float num7 = num6 / (float)GenTemperature.beqRoomGroups[k].CellCount; float num8 = GenTemperature.beqRoomGroups[k].Temperature + num7; if (num6 > 0f && num8 > num3) { num8 = num3; } else if (num6 < 0f && num8 < num3) { num8 = num3; } float num9 = Mathf.Abs((num8 - temperature) * (float)GenTemperature.beqRoomGroups[k].CellCount / num6); if (num9 < num4) { num4 = num9; } } } for (int l = 0; l < num; l++) { if (!GenTemperature.beqRoomGroups[l].UsesOutdoorTemperature) { float temperature2 = GenTemperature.beqRoomGroups[l].Temperature; float num10 = num3 - temperature2; float num11 = num10 * rate * num4; float num12 = num11 / (float)GenTemperature.beqRoomGroups[l].CellCount; GenTemperature.beqRoomGroups[l].Temperature += num12; } } for (int m = 0; m < GenTemperature.beqRoomGroups.Length; m++) { GenTemperature.beqRoomGroups[m] = null; } }
public void FloodFill(IntVec3 root, Predicate <IntVec3> passCheck, Func <IntVec3, int, bool> processor, int maxCellsToProcess = 2147483647, bool rememberParents = false, IEnumerable <IntVec3> extraRoots = null) { if (this.working) { Log.Error("Nested FloodFill calls are not allowed. This will cause bugs.", false); } this.working = true; this.ClearVisited(); if (rememberParents && this.parentGrid == null) { this.parentGrid = new CellGrid(this.map); } if (root.IsValid && extraRoots == null && !passCheck(root)) { if (rememberParents) { this.parentGrid[root] = IntVec3.Invalid; } this.working = false; return; } int area = this.map.Area; IntVec3[] cardinalDirectionsAround = GenAdj.CardinalDirectionsAround; int num = cardinalDirectionsAround.Length; CellIndices cellIndices = this.map.cellIndices; int num2 = 0; this.openSet.Clear(); if (root.IsValid) { int num3 = cellIndices.CellToIndex(root); this.visited.Add(num3); this.traversalDistance[num3] = 0; this.openSet.Enqueue(root); } if (extraRoots != null) { IList <IntVec3> list = extraRoots as IList <IntVec3>; if (list != null) { for (int i = 0; i < list.Count; i++) { int num4 = cellIndices.CellToIndex(list[i]); this.visited.Add(num4); this.traversalDistance[num4] = 0; this.openSet.Enqueue(list[i]); } } else { foreach (IntVec3 current in extraRoots) { int num5 = cellIndices.CellToIndex(current); this.visited.Add(num5); this.traversalDistance[num5] = 0; this.openSet.Enqueue(current); } } } if (rememberParents) { for (int j = 0; j < this.visited.Count; j++) { IntVec3 intVec = cellIndices.IndexToCell(this.visited[j]); this.parentGrid[this.visited[j]] = ((!passCheck(intVec)) ? IntVec3.Invalid : intVec); } } while (this.openSet.Count > 0) { IntVec3 intVec2 = this.openSet.Dequeue(); int num6 = this.traversalDistance[cellIndices.CellToIndex(intVec2)]; if (processor(intVec2, num6)) { break; } num2++; if (num2 == maxCellsToProcess) { break; } for (int k = 0; k < num; k++) { IntVec3 intVec3 = intVec2 + cardinalDirectionsAround[k]; int num7 = cellIndices.CellToIndex(intVec3); if (intVec3.InBounds(this.map) && this.traversalDistance[num7] == -1 && passCheck(intVec3)) { this.visited.Add(num7); this.openSet.Enqueue(intVec3); this.traversalDistance[num7] = num6 + 1; if (rememberParents) { this.parentGrid[num7] = intVec2; } } } if (this.openSet.Count > area) { Log.Error("Overflow on flood fill (>" + area + " cells). Make sure we're not flooding over the same area after we check it.", false); this.working = false; return; } } this.working = false; }
public static Thing Spawn(Thing newThing, IntVec3 loc, Map map, Rot4 rot, WipeMode wipeMode = WipeMode.Vanish, bool respawningAfterLoad = false) { if (map == null) { Log.Error("Tried to spawn " + newThing.ToStringSafe <Thing>() + " in a null map.", false); return(null); } if (!loc.InBounds(map)) { Log.Error(string.Concat(new object[] { "Tried to spawn ", newThing.ToStringSafe <Thing>(), " out of bounds at ", loc, "." }), false); return(null); } if (newThing.def.randomizeRotationOnSpawn) { rot = Rot4.Random; } CellRect occupiedRect = GenAdj.OccupiedRect(loc, rot, newThing.def.Size); if (!occupiedRect.InBounds(map)) { Log.Error(string.Concat(new object[] { "Tried to spawn ", newThing.ToStringSafe <Thing>(), " out of bounds at ", loc, " (out of bounds because size is ", newThing.def.Size, ")." }), false); return(null); } if (newThing.Spawned) { Log.Error("Tried to spawn " + newThing + " but it's already spawned.", false); return(newThing); } if (wipeMode == WipeMode.Vanish) { GenSpawn.WipeExistingThings(loc, rot, newThing.def, map, DestroyMode.Vanish); } else if (wipeMode == WipeMode.FullRefund) { GenSpawn.WipeAndRefundExistingThings(loc, rot, newThing.def, map); } if (newThing.def.category == ThingCategory.Item) { foreach (IntVec3 intVec in occupiedRect) { foreach (Thing thing in intVec.GetThingList(map).ToList <Thing>()) { if (thing != newThing) { if (thing.def.category == ThingCategory.Item) { thing.DeSpawn(DestroyMode.Vanish); if (!GenPlace.TryPlaceThing(thing, intVec, map, ThingPlaceMode.Near, null, (IntVec3 x) => !occupiedRect.Contains(x))) { thing.Destroy(DestroyMode.Vanish); } } } } } } newThing.Rotation = rot; newThing.Position = loc; if (newThing.holdingOwner != null) { newThing.holdingOwner.Remove(newThing); } newThing.SpawnSetup(map, respawningAfterLoad); if (newThing.Spawned && newThing.stackCount == 0) { Log.Error("Spawned thing with 0 stackCount: " + newThing, false); newThing.Destroy(DestroyMode.Vanish); return(null); } if (newThing.def.passability == Traversability.Impassable) { foreach (IntVec3 c in occupiedRect) { foreach (Thing thing2 in c.GetThingList(map).ToList <Thing>()) { if (thing2 != newThing) { Pawn pawn = thing2 as Pawn; if (pawn != null) { pawn.pather.TryRecoverFromUnwalkablePosition(false); } } } } } return(newThing); }
private void SweepInTwoDirectionsAndTryToCreateLink(Rot4 potentialOtherRegionDir, IntVec3 c) { if (!potentialOtherRegionDir.IsValid) { return; } HashSet <IntVec3> hashSet = linksProcessedAt[potentialOtherRegionDir.AsInt]; if (hashSet.Contains(c)) { return; } IntVec3 c2 = c + potentialOtherRegionDir.FacingCell; if (c2.InBounds(map) && regionGrid.GetRegionAt_NoRebuild_InvalidAllowed(c2) == newReg) { return; } RegionType expectedRegionType = c2.GetExpectedRegionType(map); if (expectedRegionType == RegionType.None) { return; } Rot4 rot = potentialOtherRegionDir; rot.Rotate(RotationDirection.Clockwise); int num = 0; int num2 = 0; hashSet.Add(c); if (!expectedRegionType.IsOneCellRegion()) { while (true) { IntVec3 intVec = c + rot.FacingCell * (num + 1); if (!intVec.InBounds(map) || regionGrid.GetRegionAt_NoRebuild_InvalidAllowed(intVec) != newReg || (intVec + potentialOtherRegionDir.FacingCell).GetExpectedRegionType(map) != expectedRegionType) { break; } if (!hashSet.Add(intVec)) { Log.Error("We've processed the same cell twice."); } num++; } while (true) { IntVec3 intVec2 = c - rot.FacingCell * (num2 + 1); if (!intVec2.InBounds(map) || regionGrid.GetRegionAt_NoRebuild_InvalidAllowed(intVec2) != newReg || (intVec2 + potentialOtherRegionDir.FacingCell).GetExpectedRegionType(map) != expectedRegionType) { break; } if (!hashSet.Add(intVec2)) { Log.Error("We've processed the same cell twice."); } num2++; } } int length = num + num2 + 1; SpanDirection dir; IntVec3 root; if (potentialOtherRegionDir == Rot4.North) { dir = SpanDirection.East; root = c - rot.FacingCell * num2; root.z++; } else if (potentialOtherRegionDir == Rot4.South) { dir = SpanDirection.East; root = c + rot.FacingCell * num; } else if (potentialOtherRegionDir == Rot4.East) { dir = SpanDirection.North; root = c + rot.FacingCell * num; root.x++; } else { dir = SpanDirection.North; root = c - rot.FacingCell * num2; } EdgeSpan span = new EdgeSpan(root, dir, length); RegionLink regionLink = map.regionLinkDatabase.LinkFrom(span); regionLink.Register(newReg); newReg.links.Add(regionLink); }
public bool CanReach(IntVec3 start, LocalTargetInfo dest, PathEndMode peMode, TraverseParms traverseParams) { if (working) { Log.ErrorOnce("Called CanReach() while working. This should never happen. Suppressing further errors.", 7312233); return(false); } if (traverseParams.pawn != null) { if (!traverseParams.pawn.Spawned) { return(false); } if (traverseParams.pawn.Map != map) { Log.Error("Called CanReach() with a pawn spawned not on this map. This means that we can't check his reachability here. Pawn's current map should have been used instead of this one. pawn=" + traverseParams.pawn + " pawn.Map=" + traverseParams.pawn.Map + " map=" + map); return(false); } } if (ReachabilityImmediate.CanReachImmediate(start, dest, map, peMode, traverseParams.pawn)) { return(true); } if (!dest.IsValid) { return(false); } if (dest.HasThing && dest.Thing.Map != map) { return(false); } if (start.InBounds(map) && dest.Cell.InBounds(map)) { if ((peMode == PathEndMode.OnCell || peMode == PathEndMode.Touch || peMode == PathEndMode.ClosestTouch) && traverseParams.mode != TraverseMode.NoPassClosedDoorsOrWater && traverseParams.mode != TraverseMode.PassAllDestroyableThingsNotWater) { Room room = RegionAndRoomQuery.RoomAtFast(start, map); if (room != null && room == RegionAndRoomQuery.RoomAtFast(dest.Cell, map)) { return(true); } } if (traverseParams.mode == TraverseMode.PassAllDestroyableThings) { TraverseParms traverseParams2 = traverseParams; traverseParams2.mode = TraverseMode.PassDoors; if (CanReach(start, dest, peMode, traverseParams2)) { return(true); } } dest = (LocalTargetInfo)GenPath.ResolvePathMode(traverseParams.pawn, dest.ToTargetInfo(map), ref peMode); working = true; try { pathGrid = map.pathGrid; regionGrid = map.regionGrid; reachedIndex++; destRegions.Clear(); switch (peMode) { case PathEndMode.OnCell: { Region region = dest.Cell.GetRegion(map); if (region != null && region.Allows(traverseParams, isDestination: true)) { destRegions.Add(region); } break; } case PathEndMode.Touch: TouchPathEndModeUtility.AddAllowedAdjacentRegions(dest, traverseParams, map, destRegions); break; } if (destRegions.Count == 0 && traverseParams.mode != TraverseMode.PassAllDestroyableThings && traverseParams.mode != TraverseMode.PassAllDestroyableThingsNotWater) { FinalizeCheck(); return(false); } destRegions.RemoveDuplicates(); openQueue.Clear(); numRegionsOpened = 0; DetermineStartRegions(start); if (openQueue.Count == 0 && traverseParams.mode != TraverseMode.PassAllDestroyableThings && traverseParams.mode != TraverseMode.PassAllDestroyableThingsNotWater) { FinalizeCheck(); return(false); } if (startingRegions.Any() && destRegions.Any() && CanUseCache(traverseParams.mode)) { switch (GetCachedResult(traverseParams)) { case BoolUnknown.True: FinalizeCheck(); return(true); case BoolUnknown.False: FinalizeCheck(); return(false); } } if (traverseParams.mode == TraverseMode.PassAllDestroyableThings || traverseParams.mode == TraverseMode.PassAllDestroyableThingsNotWater || traverseParams.mode == TraverseMode.NoPassClosedDoorsOrWater) { bool result = CheckCellBasedReachability(start, dest, peMode, traverseParams); FinalizeCheck(); return(result); } bool result2 = CheckRegionBasedReachability(traverseParams); FinalizeCheck(); return(result2); } finally { working = false; } } return(false); }
private string CurrentDebugString() { StringBuilder stringBuilder = new StringBuilder(); Pawn pawn2; Pawn pawn3; if (!WorldRendererUtility.WorldRenderedNow && Find.VisibleMap != null) { if (DebugViewSettings.writeGameConditions) { stringBuilder.AppendLine("---"); stringBuilder.AppendLine(Find.VisibleMap.gameConditionManager.DebugString()); } if (DebugViewSettings.writePlayingSounds) { stringBuilder.AppendLine("---"); stringBuilder.AppendLine("Sustainers:"); foreach (Sustainer allSustainer in Find.SoundRoot.sustainerManager.AllSustainers) { stringBuilder.AppendLine(allSustainer.DebugString()); } stringBuilder.AppendLine(); stringBuilder.AppendLine("OneShots:"); foreach (SampleOneShot playingOneShot in Find.SoundRoot.oneShotManager.PlayingOneShots) { stringBuilder.AppendLine(playingOneShot.ToString()); } } if (DebugViewSettings.writeSoundEventsRecord) { stringBuilder.AppendLine("---"); stringBuilder.AppendLine("Recent sound events:\n ..."); stringBuilder.AppendLine(DebugSoundEventsLog.EventsListingDebugString); } if (DebugViewSettings.writeGame) { stringBuilder.AppendLine("---"); stringBuilder.AppendLine((Current.Game != null) ? Current.Game.DebugString() : "Current.Game = null"); } if (DebugViewSettings.writeSteamItems) { stringBuilder.AppendLine("---"); stringBuilder.AppendLine(WorkshopItems.DebugOutput()); } if (DebugViewSettings.writeConcepts) { stringBuilder.AppendLine("---"); stringBuilder.AppendLine(LessonAutoActivator.DebugString()); } if (DebugViewSettings.writeMemoryUsage) { stringBuilder.AppendLine("---"); stringBuilder.AppendLine("Total allocated: " + Profiler.GetTotalAllocatedMemoryLong().ToStringBytes("F2")); stringBuilder.AppendLine("Total reserved: " + Profiler.GetTotalReservedMemoryLong().ToStringBytes("F2")); stringBuilder.AppendLine("Total reserved unused: " + Profiler.GetTotalUnusedReservedMemoryLong().ToStringBytes("F2")); stringBuilder.AppendLine("Mono heap size: " + Profiler.GetMonoHeapSizeLong().ToStringBytes("F2")); stringBuilder.AppendLine("Mono used size: " + Profiler.GetMonoUsedSizeLong().ToStringBytes("F2")); } if (Current.ProgramState == ProgramState.Playing) { IntVec3 intVec = UI.MouseCell(); stringBuilder.AppendLine("Tick " + Find.TickManager.TicksGame); stringBuilder.AppendLine("Inspecting " + intVec.ToString()); if (DebugViewSettings.writeCellContents || this.fullMode) { stringBuilder.AppendLine("---"); if (intVec.InBounds(Find.VisibleMap)) { foreach (Designation item in Find.VisibleMap.designationManager.AllDesignationsAt(intVec)) { stringBuilder.AppendLine(item.ToString()); } foreach (Thing item2 in Find.VisibleMap.thingGrid.ThingsAt(intVec)) { if (!this.fullMode) { stringBuilder.AppendLine(item2.LabelCap + " - " + item2.ToString()); } else { stringBuilder.AppendLine(Scribe.saver.DebugOutputFor(item2)); stringBuilder.AppendLine(); } } } } if (DebugViewSettings.debugApparelOptimize) { stringBuilder.AppendLine("---"); foreach (Thing item3 in Find.VisibleMap.thingGrid.ThingsAt(intVec)) { Apparel apparel = item3 as Apparel; if (apparel != null) { stringBuilder.AppendLine(apparel.LabelCap); stringBuilder.AppendLine(" raw: " + JobGiver_OptimizeApparel.ApparelScoreRaw(null, apparel).ToString("F2")); Pawn pawn = Find.Selector.SingleSelectedThing as Pawn; if (pawn != null) { stringBuilder.AppendLine(" Pawn: " + pawn); stringBuilder.AppendLine(" gain: " + JobGiver_OptimizeApparel.ApparelScoreGain(pawn, apparel).ToString("F2")); } } } } if (DebugViewSettings.drawPawnDebug) { stringBuilder.AppendLine("---"); stringBuilder.AppendLine(Find.VisibleMap.reservationManager.DebugString()); } if (DebugViewSettings.writeMoteSaturation) { stringBuilder.AppendLine("---"); stringBuilder.AppendLine("Mote count: " + Find.VisibleMap.moteCounter.MoteCount); stringBuilder.AppendLine("Mote saturation: " + Find.VisibleMap.moteCounter.Saturation); } if (DebugViewSettings.writeSnowDepth) { stringBuilder.AppendLine("---"); stringBuilder.AppendLine("Snow depth: " + Find.VisibleMap.snowGrid.GetDepth(intVec)); } if (DebugViewSettings.drawDeepResources) { stringBuilder.AppendLine("---"); stringBuilder.AppendLine("Deep resource def: " + Find.VisibleMap.deepResourceGrid.ThingDefAt(intVec)); stringBuilder.AppendLine("Deep resource count: " + Find.VisibleMap.deepResourceGrid.CountAt(intVec)); } if (DebugViewSettings.writeEcosystem) { stringBuilder.AppendLine("---"); stringBuilder.AppendLine(Find.VisibleMap.wildSpawner.DebugString()); } if (DebugViewSettings.writeTotalSnowDepth) { stringBuilder.AppendLine("---"); stringBuilder.AppendLine("Total snow depth: " + Find.VisibleMap.snowGrid.TotalDepth); } if (DebugViewSettings.writeCanReachColony) { stringBuilder.AppendLine("---"); stringBuilder.AppendLine("CanReachColony: " + Find.VisibleMap.reachability.CanReachColony(UI.MouseCell())); } if (DebugViewSettings.writeMentalStateCalcs) { stringBuilder.AppendLine("---"); foreach (Pawn item4 in (from t in Find.VisibleMap.thingGrid.ThingsAt(UI.MouseCell()) where t is Pawn select t).Cast <Pawn>()) { stringBuilder.AppendLine(item4.mindState.mentalBreaker.DebugString()); } } if (DebugViewSettings.writeWind) { stringBuilder.AppendLine("---"); stringBuilder.AppendLine(Find.VisibleMap.windManager.DebugString()); } if (DebugViewSettings.writeWorkSettings) { foreach (Pawn item5 in (from t in Find.VisibleMap.thingGrid.ThingsAt(UI.MouseCell()) where t is Pawn select t).Cast <Pawn>()) { if (item5.workSettings != null) { stringBuilder.AppendLine("---"); stringBuilder.AppendLine(item5.workSettings.DebugString()); } } } if (DebugViewSettings.writeApparelScore) { stringBuilder.AppendLine("---"); if (intVec.InBounds(Find.VisibleMap)) { foreach (Thing thing3 in intVec.GetThingList(Find.VisibleMap)) { Apparel apparel2 = thing3 as Apparel; if (apparel2 != null) { stringBuilder.AppendLine(apparel2.Label + ": " + JobGiver_OptimizeApparel.ApparelScoreRaw(null, apparel2).ToString("F2")); } } } } if (DebugViewSettings.writeRecentStrikes) { stringBuilder.AppendLine("---"); stringBuilder.AppendLine(Find.VisibleMap.mineStrikeManager.DebugStrikeRecords()); } if (DebugViewSettings.writeStoryteller) { stringBuilder.AppendLine("---"); stringBuilder.AppendLine(Find.Storyteller.DebugString()); stringBuilder.AppendLine("---"); stringBuilder.AppendLine(Find.StoryWatcher.DebugString()); } if (DebugViewSettings.writeListRepairableBldgs) { stringBuilder.AppendLine("---"); stringBuilder.AppendLine(Find.VisibleMap.listerBuildingsRepairable.DebugString()); } if (DebugViewSettings.writeListFilthInHomeArea) { stringBuilder.AppendLine("---"); stringBuilder.AppendLine(Find.VisibleMap.listerFilthInHomeArea.DebugString()); } if (DebugViewSettings.writeTerrain) { stringBuilder.AppendLine("---"); stringBuilder.AppendLine(Find.VisibleMap.terrainGrid.DebugStringAt(intVec)); } if (DebugViewSettings.writeListHaulables) { stringBuilder.AppendLine("---"); stringBuilder.AppendLine(Find.VisibleMap.listerHaulables.DebugString()); } if (DebugViewSettings.drawLords) { foreach (Lord lord in Find.VisibleMap.lordManager.lords) { stringBuilder.AppendLine("---"); stringBuilder.AppendLine(lord.DebugString()); } } if (DebugViewSettings.writeMusicManagerPlay) { stringBuilder.AppendLine("---"); stringBuilder.AppendLine(Find.MusicManagerPlay.DebugString()); } if (DebugViewSettings.writeAttackTargets) { foreach (Pawn item6 in Find.VisibleMap.thingGrid.ThingsAt(UI.MouseCell()).OfType <Pawn>()) { stringBuilder.AppendLine("---"); stringBuilder.AppendLine("Potential attack targets for " + item6.LabelShort + ":"); List <IAttackTarget> potentialTargetsFor = Find.VisibleMap.attackTargetsCache.GetPotentialTargetsFor(item6); for (int i = 0; i < potentialTargetsFor.Count; i++) { Thing thing = (Thing)potentialTargetsFor[i]; stringBuilder.AppendLine(thing.LabelShort + ", " + thing.Faction + ((!potentialTargetsFor[i].ThreatDisabled()) ? string.Empty : " (threat disabled)")); } } } if (intVec.InBounds(Find.VisibleMap)) { if (DebugViewSettings.drawRegions) { stringBuilder.AppendLine("---"); Region regionAt_NoRebuild_InvalidAllowed = Find.VisibleMap.regionGrid.GetRegionAt_NoRebuild_InvalidAllowed(intVec); stringBuilder.AppendLine("Region:\n" + ((regionAt_NoRebuild_InvalidAllowed == null) ? "null" : regionAt_NoRebuild_InvalidAllowed.DebugString)); } if (DebugViewSettings.drawRooms) { stringBuilder.AppendLine("---"); Room room = intVec.GetRoom(Find.VisibleMap, RegionType.Set_All); if (room != null) { stringBuilder.AppendLine(room.DebugString()); } else { stringBuilder.AppendLine("(no room)"); } } if (DebugViewSettings.drawRoomGroups) { stringBuilder.AppendLine("---"); RoomGroup roomGroup = intVec.GetRoomGroup(Find.VisibleMap); if (roomGroup != null) { stringBuilder.AppendLine(roomGroup.DebugString()); } else { stringBuilder.AppendLine("(no room group)"); } } if (DebugViewSettings.drawGlow) { stringBuilder.AppendLine("---"); stringBuilder.AppendLine("Game glow: " + Find.VisibleMap.glowGrid.GameGlowAt(intVec, false)); stringBuilder.AppendLine("Psych glow: " + Find.VisibleMap.glowGrid.PsychGlowAt(intVec)); stringBuilder.AppendLine("Visual Glow: " + Find.VisibleMap.glowGrid.VisualGlowAt(intVec)); stringBuilder.AppendLine("GlowReport:\n" + ((SectionLayer_LightingOverlay)Find.VisibleMap.mapDrawer.SectionAt(intVec).GetLayer(typeof(SectionLayer_LightingOverlay))).GlowReportAt(intVec)); stringBuilder.AppendLine("SkyManager.CurSkyGlow: " + Find.VisibleMap.skyManager.CurSkyGlow); } if (DebugViewSettings.writePathCosts) { stringBuilder.AppendLine("---"); stringBuilder.AppendLine("Perceived path cost: " + Find.VisibleMap.pathGrid.PerceivedPathCostAt(intVec)); stringBuilder.AppendLine("Real path cost: " + Find.VisibleMap.pathGrid.CalculatedCostAt(intVec, false, IntVec3.Invalid)); } if (DebugViewSettings.writeFertility) { stringBuilder.AppendLine("---"); stringBuilder.AppendLine("\nFertility: " + Find.VisibleMap.fertilityGrid.FertilityAt(intVec).ToString("##0.00")); } if (DebugViewSettings.writeLinkFlags) { stringBuilder.AppendLine("---"); stringBuilder.AppendLine("\nLinkFlags: "); IEnumerator enumerator11 = Enum.GetValues(typeof(LinkFlags)).GetEnumerator(); try { while (enumerator11.MoveNext()) { object current11 = enumerator11.Current; if ((Find.VisibleMap.linkGrid.LinkFlagsAt(intVec) & (LinkFlags)current11) != 0) { stringBuilder.Append(" " + current11); } } } finally { IDisposable disposable; if ((disposable = (enumerator11 as IDisposable)) != null) { disposable.Dispose(); } } } if (DebugViewSettings.writeSkyManager) { stringBuilder.AppendLine("---"); stringBuilder.AppendLine(Find.VisibleMap.skyManager.DebugString()); } if (DebugViewSettings.writeCover) { stringBuilder.AppendLine("---"); stringBuilder.Append("Cover: "); Thing thing2 = Find.VisibleMap.coverGrid[intVec]; if (thing2 == null) { stringBuilder.AppendLine("null"); } else { stringBuilder.AppendLine(thing2.ToString()); } } if (DebugViewSettings.drawPower) { stringBuilder.AppendLine("---"); foreach (Thing item7 in Find.VisibleMap.thingGrid.ThingsAt(intVec)) { ThingWithComps thingWithComps = item7 as ThingWithComps; if (thingWithComps != null && thingWithComps.GetComp <CompPowerTrader>() != null) { stringBuilder.AppendLine(" " + thingWithComps.GetComp <CompPowerTrader>().DebugString); } } PowerNet powerNet = Find.VisibleMap.powerNetGrid.TransmittedPowerNetAt(intVec); if (powerNet != null) { stringBuilder.AppendLine(string.Empty + powerNet.DebugString()); } else { stringBuilder.AppendLine("(no PowerNet here)"); } } if (DebugViewSettings.drawPreyInfo) { pawn2 = (Find.Selector.SingleSelectedThing as Pawn); if (pawn2 != null) { List <Thing> thingList = intVec.GetThingList(Find.VisibleMap); for (int j = 0; j < thingList.Count; j++) { pawn3 = (thingList[j] as Pawn); if (pawn3 != null) { goto IL_107b; } } } } } } goto IL_10de; } stringBuilder.AppendLine("World view"); return(stringBuilder.ToString()); IL_107b: stringBuilder.AppendLine("---"); if (FoodUtility.IsAcceptablePreyFor(pawn2, pawn3)) { stringBuilder.AppendLine("Prey score: " + FoodUtility.GetPreyScoreFor(pawn2, pawn3)); } else { stringBuilder.AppendLine("Prey score: None"); } goto IL_10de; IL_10de: return(stringBuilder.ToString()); }
private void TryGenerateAreaNow(Room room) { if (room.Dereferenced || room.TouchesMapEdge || room.RegionCount > 26 || room.CellCount > 320 || room.RegionType == RegionType.Portal) { return; } bool flag = false; foreach (IntVec3 borderCell in room.BorderCells) { Thing roofHolderOrImpassable = borderCell.GetRoofHolderOrImpassable(map); if (roofHolderOrImpassable != null) { if ((roofHolderOrImpassable.Faction != null && roofHolderOrImpassable.Faction != Faction.OfPlayer) || (roofHolderOrImpassable.def.building != null && !roofHolderOrImpassable.def.building.allowAutoroof)) { return; } if (roofHolderOrImpassable.Faction == Faction.OfPlayer) { flag = true; } } } if (!flag) { return; } innerCells.Clear(); foreach (IntVec3 cell in room.Cells) { if (!innerCells.Contains(cell)) { innerCells.Add(cell); } for (int i = 0; i < 8; i++) { IntVec3 c = cell + GenAdj.AdjacentCells[i]; if (!c.InBounds(map)) { continue; } Thing roofHolderOrImpassable2 = c.GetRoofHolderOrImpassable(map); if (roofHolderOrImpassable2 == null || (roofHolderOrImpassable2.def.size.x <= 1 && roofHolderOrImpassable2.def.size.z <= 1)) { continue; } CellRect cellRect = roofHolderOrImpassable2.OccupiedRect(); cellRect.ClipInsideMap(map); for (int j = cellRect.minZ; j <= cellRect.maxZ; j++) { for (int k = cellRect.minX; k <= cellRect.maxX; k++) { IntVec3 item = new IntVec3(k, 0, j); if (!innerCells.Contains(item)) { innerCells.Add(item); } } } } } cellsToRoof.Clear(); foreach (IntVec3 innerCell in innerCells) { for (int l = 0; l < 9; l++) { IntVec3 intVec = innerCell + GenAdj.AdjacentCellsAndInside[l]; if (intVec.InBounds(map) && (l == 8 || intVec.GetRoofHolderOrImpassable(map) != null) && !cellsToRoof.Contains(intVec)) { cellsToRoof.Add(intVec); } } } justRoofedCells.Clear(); foreach (IntVec3 item2 in cellsToRoof) { if (map.roofGrid.RoofAt(item2) == null && !justRoofedCells.Contains(item2) && !map.areaManager.NoRoof[item2] && RoofCollapseUtility.WithinRangeOfRoofHolder(item2, map, assumeNonNoRoofCellsAreRoofed: true)) { map.areaManager.BuildRoof[item2] = true; justRoofedCells.Add(item2); } } }
private static void TryJumpInternal(IntVec3 cell, Map map) { if (Current.ProgramState == ProgramState.Playing && cell.IsValid && map != null && Find.Maps.Contains(map) && cell.InBounds(map)) { bool flag = TryHideWorld(); if (Find.CurrentMap != map) { Current.Game.CurrentMap = map; if (!flag) { SoundDefOf.MapSelected.PlayOneShotOnCamera(); } } Find.CameraDriver.JumpToCurrentMapLoc(cell); } }
public void MouseoverReadoutOnGUI() { if (Event.current.type == EventType.Repaint && Find.MainTabsRoot.OpenTab == null) { GenUI.DrawTextWinterShadow(new Rect(256f, (float)(UI.screenHeight - 256), -256f, 256f)); Text.Font = GameFont.Small; GUI.color = new Color(1f, 1f, 1f, 0.8f); IntVec3 c = UI.MouseCell(); if (c.InBounds(Find.VisibleMap)) { float num = 0f; Rect rect = default(Rect); if (c.Fogged(Find.VisibleMap)) { Vector2 botLeft = MouseoverReadout.BotLeft; float x = botLeft.x; float num2 = (float)UI.screenHeight; Vector2 botLeft2 = MouseoverReadout.BotLeft; rect = new Rect(x, num2 - botLeft2.y - num, 999f, 999f); Widgets.Label(rect, "Undiscovered".Translate()); GUI.color = Color.white; } else { Vector2 botLeft3 = MouseoverReadout.BotLeft; float x2 = botLeft3.x; float num3 = (float)UI.screenHeight; Vector2 botLeft4 = MouseoverReadout.BotLeft; rect = new Rect(x2, num3 - botLeft4.y - num, 999f, 999f); int num4 = Mathf.RoundToInt((float)(Find.VisibleMap.glowGrid.GameGlowAt(c, false) * 100.0)); Widgets.Label(rect, this.glowStrings[num4]); num = (float)(num + 19.0); Vector2 botLeft5 = MouseoverReadout.BotLeft; float x3 = botLeft5.x; float num5 = (float)UI.screenHeight; Vector2 botLeft6 = MouseoverReadout.BotLeft; rect = new Rect(x3, num5 - botLeft6.y - num, 999f, 999f); TerrainDef terrain = c.GetTerrain(Find.VisibleMap); if (terrain != this.cachedTerrain) { string str = (!((double)terrain.fertility > 0.0001)) ? string.Empty : (" " + "FertShort".Translate() + " " + terrain.fertility.ToStringPercent()); this.cachedTerrainString = terrain.LabelCap + ((terrain.passability == Traversability.Impassable) ? null : (" (" + "WalkSpeed".Translate(this.SpeedPercentString((float)terrain.pathCost)) + str + ")")); this.cachedTerrain = terrain; } Widgets.Label(rect, this.cachedTerrainString); num = (float)(num + 19.0); Zone zone = c.GetZone(Find.VisibleMap); if (zone != null) { Vector2 botLeft7 = MouseoverReadout.BotLeft; float x4 = botLeft7.x; float num6 = (float)UI.screenHeight; Vector2 botLeft8 = MouseoverReadout.BotLeft; rect = new Rect(x4, num6 - botLeft8.y - num, 999f, 999f); string label = zone.label; Widgets.Label(rect, label); num = (float)(num + 19.0); } float depth = Find.VisibleMap.snowGrid.GetDepth(c); if (depth > 0.029999999329447746) { Vector2 botLeft9 = MouseoverReadout.BotLeft; float x5 = botLeft9.x; float num7 = (float)UI.screenHeight; Vector2 botLeft10 = MouseoverReadout.BotLeft; rect = new Rect(x5, num7 - botLeft10.y - num, 999f, 999f); SnowCategory snowCategory = SnowUtility.GetSnowCategory(depth); string label2 = SnowUtility.GetDescription(snowCategory) + " (" + "WalkSpeed".Translate(this.SpeedPercentString((float)SnowUtility.MovementTicksAddOn(snowCategory))) + ")"; Widgets.Label(rect, label2); num = (float)(num + 19.0); } List <Thing> thingList = c.GetThingList(Find.VisibleMap); for (int i = 0; i < thingList.Count; i++) { Thing thing = thingList[i]; if (thing.def.category != ThingCategory.Mote) { Vector2 botLeft11 = MouseoverReadout.BotLeft; float x6 = botLeft11.x; float num8 = (float)UI.screenHeight; Vector2 botLeft12 = MouseoverReadout.BotLeft; rect = new Rect(x6, num8 - botLeft12.y - num, 999f, 999f); string labelMouseover = thing.LabelMouseover; Widgets.Label(rect, labelMouseover); num = (float)(num + 19.0); } } RoofDef roof = c.GetRoof(Find.VisibleMap); if (roof != null) { Vector2 botLeft13 = MouseoverReadout.BotLeft; float x7 = botLeft13.x; float num9 = (float)UI.screenHeight; Vector2 botLeft14 = MouseoverReadout.BotLeft; rect = new Rect(x7, num9 - botLeft14.y - num, 999f, 999f); Widgets.Label(rect, roof.LabelCap); num = (float)(num + 19.0); } GUI.color = Color.white; } } } }
public static Thing Spawn(Thing newThing, IntVec3 loc, Map map, Rot4 rot, WipeMode wipeMode = WipeMode.Vanish, bool respawningAfterLoad = false) { if (map == null) { Log.Error("Tried to spawn " + newThing.ToStringSafe() + " in a null map."); return(null); } if (!loc.InBounds(map)) { Log.Error(string.Concat("Tried to spawn ", newThing.ToStringSafe(), " out of bounds at ", loc, ".")); return(null); } if (newThing.def.randomizeRotationOnSpawn) { rot = Rot4.Random; } CellRect occupiedRect = GenAdj.OccupiedRect(loc, rot, newThing.def.Size); if (!occupiedRect.InBounds(map)) { Log.Error(string.Concat("Tried to spawn ", newThing.ToStringSafe(), " out of bounds at ", loc, " (out of bounds because size is ", newThing.def.Size, ").")); return(null); } if (newThing.Spawned) { Log.Error(string.Concat("Tried to spawn ", newThing, " but it's already spawned.")); return(newThing); } switch (wipeMode) { case WipeMode.Vanish: WipeExistingThings(loc, rot, newThing.def, map, DestroyMode.Vanish); break; case WipeMode.FullRefund: WipeAndRefundExistingThings(loc, rot, newThing.def, map); break; case WipeMode.VanishOrMoveAside: CheckMoveItemsAside(loc, rot, newThing.def, map); WipeExistingThings(loc, rot, newThing.def, map, DestroyMode.Vanish); break; } if (newThing.def.category == ThingCategory.Item) { foreach (IntVec3 item in occupiedRect) { foreach (Thing item2 in item.GetThingList(map).ToList()) { if (item2 != newThing && item2.def.category == ThingCategory.Item) { item2.DeSpawn(); if (!GenPlace.TryPlaceThing(item2, item, map, ThingPlaceMode.Near, null, (IntVec3 x) => !occupiedRect.Contains(x))) { item2.Destroy(); } } } } } newThing.Rotation = rot; newThing.Position = loc; if (newThing.holdingOwner != null) { newThing.holdingOwner.Remove(newThing); } newThing.SpawnSetup(map, respawningAfterLoad); if (newThing.Spawned && newThing.stackCount == 0) { Log.Error("Spawned thing with 0 stackCount: " + newThing); newThing.Destroy(); return(null); } if (newThing.def.passability == Traversability.Impassable) { foreach (IntVec3 item3 in occupiedRect) { foreach (Thing item4 in item3.GetThingList(map).ToList()) { if (item4 != newThing) { (item4 as Pawn)?.pather.TryRecoverFromUnwalkablePosition(error: false); } } } return(newThing); } return(newThing); }
public static IntVec3 FindNoWipeSpawnLocNear(IntVec3 near, Map map, ThingDef thingToSpawn, Rot4 rot, int maxDist = 2, Predicate <IntVec3> extraValidator = null) { int num = GenRadial.NumCellsInRadius((float)maxDist); IntVec3 intVec = IntVec3.Invalid; float num2 = 0f; for (int i = 0; i < num; i++) { IntVec3 intVec2 = near + GenRadial.RadialPattern[i]; if (intVec2.InBounds(map)) { CellRect cellRect = GenAdj.OccupiedRect(intVec2, rot, thingToSpawn.size); if (cellRect.InBounds(map)) { if (GenSight.LineOfSight(near, intVec2, map, true, null, 0, 0)) { if (extraValidator == null || extraValidator(intVec2)) { if (thingToSpawn.category != ThingCategory.Building || GenConstruct.CanBuildOnTerrain(thingToSpawn, intVec2, map, rot, null)) { bool flag = false; bool flag2 = false; CellFinder.tmpUniqueWipedThings.Clear(); CellRect.CellRectIterator iterator = cellRect.GetIterator(); while (!iterator.Done()) { if (iterator.Current.Impassable(map)) { flag2 = true; } List <Thing> thingList = iterator.Current.GetThingList(map); for (int j = 0; j < thingList.Count; j++) { if (thingList[j] is Pawn) { flag = true; } else if (GenSpawn.SpawningWipes(thingToSpawn, thingList[j].def) && !CellFinder.tmpUniqueWipedThings.Contains(thingList[j])) { CellFinder.tmpUniqueWipedThings.Add(thingList[j]); } } iterator.MoveNext(); } if (flag && thingToSpawn.passability == Traversability.Impassable) { CellFinder.tmpUniqueWipedThings.Clear(); } else if (flag2 && thingToSpawn.category == ThingCategory.Item) { CellFinder.tmpUniqueWipedThings.Clear(); } else { float num3 = 0f; for (int k = 0; k < CellFinder.tmpUniqueWipedThings.Count; k++) { if (CellFinder.tmpUniqueWipedThings[k].def.category == ThingCategory.Building && !CellFinder.tmpUniqueWipedThings[k].def.costList.NullOrEmpty <ThingDefCountClass>() && CellFinder.tmpUniqueWipedThings[k].def.costStuffCount == 0) { List <ThingDefCountClass> list = CellFinder.tmpUniqueWipedThings[k].CostListAdjusted(); for (int l = 0; l < list.Count; l++) { num3 += list[l].thingDef.GetStatValueAbstract(StatDefOf.MarketValue, null) * (float)list[l].count * (float)CellFinder.tmpUniqueWipedThings[k].stackCount; } } else { num3 += CellFinder.tmpUniqueWipedThings[k].MarketValue * (float)CellFinder.tmpUniqueWipedThings[k].stackCount; } if (CellFinder.tmpUniqueWipedThings[k].def.category == ThingCategory.Building || CellFinder.tmpUniqueWipedThings[k].def.category == ThingCategory.Item) { num3 = Mathf.Max(num3, 0.001f); } } CellFinder.tmpUniqueWipedThings.Clear(); if (!intVec.IsValid || num3 < num2) { if (num3 == 0f) { return(intVec2); } intVec = intVec2; num2 = num3; } } } } } } } } return((!intVec.IsValid) ? near : intVec); }
public override void Regenerate() { Building[] innerArray = base.Map.edificeGrid.InnerArray; float y = AltitudeLayer.Shadows.AltitudeFor(); CellRect cellRect = new CellRect(this.section.botLeft.x, this.section.botLeft.z, 17, 17); cellRect.ClipInsideMap(base.Map); LayerSubMesh sm = base.GetSubMesh(MatBases.EdgeShadow); sm.Clear(MeshParts.All); sm.verts.Capacity = cellRect.Area * 4; sm.colors.Capacity = cellRect.Area * 4; sm.tris.Capacity = cellRect.Area * 8; bool[] array = new bool[4]; bool[] array2 = new bool[4]; bool[] array3 = new bool[4]; CellIndices cellIndices = base.Map.cellIndices; for (int i = cellRect.minX; i <= cellRect.maxX; i++) { for (int j = cellRect.minZ; j <= cellRect.maxZ; j++) { Thing thing = innerArray[cellIndices.CellToIndex(i, j)]; if (thing != null && thing.def.castEdgeShadows) { sm.verts.Add(new Vector3((float)i, y, (float)j)); sm.verts.Add(new Vector3((float)i, y, (float)(j + 1))); sm.verts.Add(new Vector3((float)(i + 1), y, (float)(j + 1))); sm.verts.Add(new Vector3((float)(i + 1), y, (float)j)); sm.colors.Add(SectionLayer_EdgeShadows.Shadowed); sm.colors.Add(SectionLayer_EdgeShadows.Shadowed); sm.colors.Add(SectionLayer_EdgeShadows.Shadowed); sm.colors.Add(SectionLayer_EdgeShadows.Shadowed); int count = sm.verts.Count; sm.tris.Add(count - 4); sm.tris.Add(count - 3); sm.tris.Add(count - 2); sm.tris.Add(count - 4); sm.tris.Add(count - 2); sm.tris.Add(count - 1); } else { array[0] = false; array[1] = false; array[2] = false; array[3] = false; array2[0] = false; array2[1] = false; array2[2] = false; array2[3] = false; array3[0] = false; array3[1] = false; array3[2] = false; array3[3] = false; IntVec3 a = new IntVec3(i, 0, j); IntVec3[] cardinalDirectionsAround = GenAdj.CardinalDirectionsAround; for (int k = 0; k < 4; k++) { IntVec3 c = a + cardinalDirectionsAround[k]; if (c.InBounds(base.Map)) { thing = innerArray[cellIndices.CellToIndex(c)]; if (thing != null && thing.def.castEdgeShadows) { array2[k] = true; array[(k + 3) % 4] = true; array[k] = true; } } } IntVec3[] diagonalDirectionsAround = GenAdj.DiagonalDirectionsAround; for (int l = 0; l < 4; l++) { if (!array[l]) { IntVec3 c = a + diagonalDirectionsAround[l]; if (c.InBounds(base.Map)) { thing = innerArray[cellIndices.CellToIndex(c)]; if (thing != null && thing.def.castEdgeShadows) { array[l] = true; array3[l] = true; } } } } Action <int> action = delegate(int idx) { sm.tris.Add(sm.verts.Count - 2); sm.tris.Add(idx); sm.tris.Add(sm.verts.Count - 1); sm.tris.Add(sm.verts.Count - 1); sm.tris.Add(idx); sm.tris.Add(idx + 1); }; Action action2 = delegate { sm.colors.Add(SectionLayer_EdgeShadows.Shadowed); sm.colors.Add(SectionLayer_EdgeShadows.Lit); sm.colors.Add(SectionLayer_EdgeShadows.Lit); sm.tris.Add(sm.verts.Count - 3); sm.tris.Add(sm.verts.Count - 2); sm.tris.Add(sm.verts.Count - 1); }; int count2 = sm.verts.Count; if (array[0]) { if (array2[0] || array2[1]) { float num2; float num = num2 = 0f; if (array2[0]) { num = 0.45f; } if (array2[1]) { num2 = 0.45f; } sm.verts.Add(new Vector3((float)i, y, (float)j)); sm.colors.Add(SectionLayer_EdgeShadows.Shadowed); sm.verts.Add(new Vector3((float)i + num2, y, (float)j + num)); sm.colors.Add(SectionLayer_EdgeShadows.Lit); if (array[1] && !array3[1]) { action(sm.verts.Count); } } else { sm.verts.Add(new Vector3((float)i, y, (float)j)); sm.verts.Add(new Vector3((float)i, y, (float)j + 0.45f)); sm.verts.Add(new Vector3((float)i + 0.45f, y, (float)j)); action2(); } } if (array[1]) { if (array2[1] || array2[2]) { float num2; float num = num2 = 0f; if (array2[1]) { num2 = 0.45f; } if (array2[2]) { num = -0.45f; } sm.verts.Add(new Vector3((float)i, y, (float)(j + 1))); sm.colors.Add(SectionLayer_EdgeShadows.Shadowed); sm.verts.Add(new Vector3((float)i + num2, y, (float)(j + 1) + num)); sm.colors.Add(SectionLayer_EdgeShadows.Lit); if (array[2] && !array3[2]) { action(sm.verts.Count); } } else { sm.verts.Add(new Vector3((float)i, y, (float)(j + 1))); sm.verts.Add(new Vector3((float)i + 0.45f, y, (float)(j + 1))); sm.verts.Add(new Vector3((float)i, y, (float)(j + 1) - 0.45f)); action2(); } } if (array[2]) { if (array2[2] || array2[3]) { float num2; float num = num2 = 0f; if (array2[2]) { num = -0.45f; } if (array2[3]) { num2 = -0.45f; } sm.verts.Add(new Vector3((float)(i + 1), y, (float)(j + 1))); sm.colors.Add(SectionLayer_EdgeShadows.Shadowed); sm.verts.Add(new Vector3((float)(i + 1) + num2, y, (float)(j + 1) + num)); sm.colors.Add(SectionLayer_EdgeShadows.Lit); if (array[3] && !array3[3]) { action(sm.verts.Count); } } else { sm.verts.Add(new Vector3((float)(i + 1), y, (float)(j + 1))); sm.verts.Add(new Vector3((float)(i + 1), y, (float)(j + 1) - 0.45f)); sm.verts.Add(new Vector3((float)(i + 1) - 0.45f, y, (float)(j + 1))); action2(); } } if (array[3]) { if (array2[3] || array2[0]) { float num2; float num = num2 = 0f; if (array2[3]) { num2 = -0.45f; } if (array2[0]) { num = 0.45f; } sm.verts.Add(new Vector3((float)(i + 1), y, (float)j)); sm.colors.Add(SectionLayer_EdgeShadows.Shadowed); sm.verts.Add(new Vector3((float)(i + 1) + num2, y, (float)j + num)); sm.colors.Add(SectionLayer_EdgeShadows.Lit); if (array[0] && !array3[0]) { action(count2); } } else { sm.verts.Add(new Vector3((float)(i + 1), y, (float)j)); sm.verts.Add(new Vector3((float)(i + 1) - 0.45f, y, (float)j)); sm.verts.Add(new Vector3((float)(i + 1), y, (float)j + 0.45f)); action2(); } } } } } if (sm.verts.Count > 0) { sm.FinalizeMesh(MeshParts.Verts | MeshParts.Tris | MeshParts.Colors); } }
public void MouseoverReadoutOnGUI() { if (Event.current.type != EventType.Repaint) { return; } if (Find.MainTabsRoot.OpenTab != null) { return; } GenUI.DrawTextWinterShadow(new Rect(256f, (float)(UI.screenHeight - 256), -256f, 256f)); Text.Font = GameFont.Small; GUI.color = new Color(1f, 1f, 1f, 0.8f); IntVec3 c = UI.MouseCell(); if (!c.InBounds(Find.CurrentMap)) { return; } float num = 0f; Rect rect; if (c.Fogged(Find.CurrentMap)) { rect = new Rect(MouseoverReadout.BotLeft.x, (float)UI.screenHeight - MouseoverReadout.BotLeft.y - num, 999f, 999f); Widgets.Label(rect, "Undiscovered".Translate()); GUI.color = Color.white; return; } rect = new Rect(MouseoverReadout.BotLeft.x, (float)UI.screenHeight - MouseoverReadout.BotLeft.y - num, 999f, 999f); int num2 = Mathf.RoundToInt(Find.CurrentMap.glowGrid.GameGlowAt(c, false) * 100f); Widgets.Label(rect, this.glowStrings[num2]); num += 19f; rect = new Rect(MouseoverReadout.BotLeft.x, (float)UI.screenHeight - MouseoverReadout.BotLeft.y - num, 999f, 999f); TerrainDef terrain = c.GetTerrain(Find.CurrentMap); if (terrain != this.cachedTerrain) { string str = ((double)terrain.fertility <= 0.0001) ? string.Empty : (" " + "FertShort".Translate() + " " + terrain.fertility.ToStringPercent()); this.cachedTerrainString = terrain.LabelCap + ((terrain.passability == Traversability.Impassable) ? null : (" (" + "WalkSpeed".Translate(new object[] { this.SpeedPercentString((float)terrain.pathCost) }) + str + ")")); this.cachedTerrain = terrain; } Widgets.Label(rect, this.cachedTerrainString); num += 19f; Zone zone = c.GetZone(Find.CurrentMap); if (zone != null) { rect = new Rect(MouseoverReadout.BotLeft.x, (float)UI.screenHeight - MouseoverReadout.BotLeft.y - num, 999f, 999f); string label = zone.label; Widgets.Label(rect, label); num += 19f; } float depth = Find.CurrentMap.snowGrid.GetDepth(c); if (depth > 0.03f) { rect = new Rect(MouseoverReadout.BotLeft.x, (float)UI.screenHeight - MouseoverReadout.BotLeft.y - num, 999f, 999f); SnowCategory snowCategory = SnowUtility.GetSnowCategory(depth); string label2 = SnowUtility.GetDescription(snowCategory) + " (" + "WalkSpeed".Translate(new object[] { this.SpeedPercentString((float)SnowUtility.MovementTicksAddOn(snowCategory)) }) + ")"; Widgets.Label(rect, label2); num += 19f; } List <Thing> thingList = c.GetThingList(Find.CurrentMap); for (int i = 0; i < thingList.Count; i++) { Thing thing = thingList[i]; if (thing.def.category != ThingCategory.Mote) { rect = new Rect(MouseoverReadout.BotLeft.x, (float)UI.screenHeight - MouseoverReadout.BotLeft.y - num, 999f, 999f); string labelMouseover = thing.LabelMouseover; Widgets.Label(rect, labelMouseover); num += 19f; } } RoofDef roof = c.GetRoof(Find.CurrentMap); if (roof != null) { rect = new Rect(MouseoverReadout.BotLeft.x, (float)UI.screenHeight - MouseoverReadout.BotLeft.y - num, 999f, 999f); Widgets.Label(rect, roof.LabelCap); num += 19f; } GUI.color = Color.white; }
public override void Regenerate() { if (!MatBases.SunShadow.shader.isSupported) { return; } LayerSubMesh subMesh = base.GetSubMesh(MatBases.IndoorMask); subMesh.Clear(MeshParts.All); Building[] innerArray = base.Map.edificeGrid.InnerArray; CellRect cellRect = new CellRect(this.section.botLeft.x, this.section.botLeft.z, 17, 17); cellRect.ClipInsideMap(base.Map); subMesh.verts.Capacity = cellRect.Area * 2; subMesh.tris.Capacity = cellRect.Area * 4; float y = AltitudeLayer.MetaOverlays.AltitudeFor(); CellIndices cellIndices = base.Map.cellIndices; for (int i = cellRect.minX; i <= cellRect.maxX; i++) { int j = cellRect.minZ; while (j <= cellRect.maxZ) { IntVec3 intVec = new IntVec3(i, 0, j); if (this.HideRainPrimary(intVec)) { goto IL_16E; } bool flag = intVec.Roofed(base.Map); bool flag2 = false; if (flag) { for (int k = 0; k < 8; k++) { IntVec3 c = intVec + GenAdj.AdjacentCells[k]; if (c.InBounds(base.Map)) { if (this.HideRainPrimary(c)) { flag2 = true; break; } } } } if (flag && flag2) { goto IL_16E; } IL_29D: j++; continue; IL_16E: Thing thing = innerArray[cellIndices.CellToIndex(i, j)]; float num; if (thing != null && (thing.def.passability == Traversability.Impassable || thing.def.IsDoor)) { num = 0f; } else { num = 0.16f; } subMesh.verts.Add(new Vector3((float)i - num, y, (float)j - num)); subMesh.verts.Add(new Vector3((float)i - num, y, (float)(j + 1) + num)); subMesh.verts.Add(new Vector3((float)(i + 1) + num, y, (float)(j + 1) + num)); subMesh.verts.Add(new Vector3((float)(i + 1) + num, y, (float)j - num)); int count = subMesh.verts.Count; subMesh.tris.Add(count - 4); subMesh.tris.Add(count - 3); subMesh.tris.Add(count - 2); subMesh.tris.Add(count - 4); subMesh.tris.Add(count - 2); subMesh.tris.Add(count - 1); goto IL_29D; } } if (subMesh.verts.Count > 0) { subMesh.FinalizeMesh(MeshParts.Verts | MeshParts.Tris); } }
public static FloodUnfogResult FloodUnfog(IntVec3 root, Map map) { FloodFillerFog.cellsToUnfog.Clear(); FloodUnfogResult result = default(FloodUnfogResult); bool[] fogGridDirect = map.fogGrid.fogGrid; FogGrid fogGrid = map.fogGrid; List <IntVec3> newlyUnfoggedCells = new List <IntVec3>(); int numUnfogged = 0; bool expanding = false; CellRect viewRect = CellRect.ViewRect(map); result.allOnScreen = true; Predicate <IntVec3> predicate = delegate(IntVec3 c) { if (!fogGridDirect[map.cellIndices.CellToIndex(c)]) { return(false); } Thing edifice = c.GetEdifice(map); return((edifice == null || !edifice.def.MakeFog) && (!FloodFillerFog.testMode || expanding || numUnfogged <= 500)); }; Action <IntVec3> processor = delegate(IntVec3 c) { fogGrid.Unfog(c); newlyUnfoggedCells.Add(c); List <Thing> thingList = c.GetThingList(map); for (int l = 0; l < thingList.Count; l++) { Pawn pawn = thingList[l] as Pawn; if (pawn != null) { pawn.mindState.Active = true; if (pawn.def.race.IsMechanoid) { result.mechanoidFound = true; } } } if (!viewRect.Contains(c)) { result.allOnScreen = false; } result.cellsUnfogged++; if (FloodFillerFog.testMode) { numUnfogged++; map.debugDrawer.FlashCell(c, (float)numUnfogged / 200f, numUnfogged.ToStringCached(), 50); } }; map.floodFiller.FloodFill(root, predicate, processor, int.MaxValue, false, null); expanding = true; for (int i = 0; i < newlyUnfoggedCells.Count; i++) { IntVec3 a = newlyUnfoggedCells[i]; for (int j = 0; j < 8; j++) { IntVec3 intVec = a + GenAdj.AdjacentCells[j]; if (intVec.InBounds(map) && fogGrid.IsFogged(intVec)) { if (!predicate(intVec)) { FloodFillerFog.cellsToUnfog.Add(intVec); } } } } for (int k = 0; k < FloodFillerFog.cellsToUnfog.Count; k++) { fogGrid.Unfog(FloodFillerFog.cellsToUnfog[k]); if (FloodFillerFog.testMode) { map.debugDrawer.FlashCell(FloodFillerFog.cellsToUnfog[k], 0.3f, "x", 50); } } FloodFillerFog.cellsToUnfog.Clear(); return(result); }
protected override void TimeInterval(float deltaTime) { base.TimeInterval(deltaTime); if (base.Destroyed) { return; } if (!this.Flying && !this.Skidding) { return; } Vector3 vector = this.NextExactPosition(deltaTime); IntVec3 intVec = new IntVec3(vector); if (intVec != base.Position) { if (!intVec.InBounds(base.Map)) { this.Destroy(DestroyMode.Vanish); return; } if (this.def.mote.collide && intVec.Filled(base.Map)) { this.WallHit(); return; } } base.Position = intVec; this.exactPosition = vector; if (this.def.mote.rotateTowardsMoveDirection && this.velocity != default(Vector3)) { this.exactRotation = this.velocity.AngleFlat(); } else { this.exactRotation += this.rotationRate * deltaTime; } this.velocity += this.def.mote.acceleration * deltaTime; if (this.def.mote.speedPerTime != 0f) { this.Speed = Mathf.Max(this.Speed + this.def.mote.speedPerTime * deltaTime, 0f); } if (this.airTimeLeft > 0f) { this.airTimeLeft -= deltaTime; if (this.airTimeLeft < 0f) { this.airTimeLeft = 0f; } if (this.airTimeLeft <= 0f && !this.def.mote.landSound.NullOrUndefined()) { this.def.mote.landSound.PlayOneShot(new TargetInfo(base.Position, base.Map, false)); } } if (this.Skidding) { this.Speed *= this.skidSpeedMultiplierPerTick; this.rotationRate *= this.skidSpeedMultiplierPerTick; if (this.Speed < 0.02f) { this.Speed = 0f; } } }
private void RegenerateEqualizationData() { thickRoofCoverage = 0f; noRoofCoverage = 0f; equalizeCells.Clear(); if (roomGroup.RoomCount == 0) { return; } Map map = Map; if (roomGroup.UsesOutdoorTemperature) { return; } int num = 0; foreach (IntVec3 cell in roomGroup.Cells) { RoofDef roof = cell.GetRoof(map); if (roof == null) { noRoofCoverage += 1f; } else if (roof.isThickRoof) { thickRoofCoverage += 1f; } num++; } thickRoofCoverage /= num; noRoofCoverage /= num; foreach (IntVec3 cell2 in roomGroup.Cells) { for (int i = 0; i < 4; i++) { IntVec3 intVec = cell2 + GenAdj.CardinalDirections[i]; IntVec3 intVec2 = cell2 + GenAdj.CardinalDirections[i] * 2; if (intVec.InBounds(map)) { Region region = intVec.GetRegion(map); if (region != null) { if (region.type != RegionType.Portal) { continue; } bool flag = false; for (int j = 0; j < region.links.Count; j++) { Region regionA = region.links[j].RegionA; Region regionB = region.links[j].RegionB; if (regionA.Room.Group != roomGroup && !regionA.IsDoorway) { flag = true; break; } if (regionB.Room.Group != roomGroup && !regionB.IsDoorway) { flag = true; break; } } if (flag) { continue; } } } if (!intVec2.InBounds(map) || intVec2.GetRoomGroup(map) == roomGroup) { continue; } bool flag2 = false; for (int k = 0; k < 4; k++) { if ((intVec2 + GenAdj.CardinalDirections[k]).GetRoomGroup(map) == roomGroup) { flag2 = true; break; } } if (!flag2) { equalizeCells.Add(intVec2); } } } equalizeCells.Shuffle(); }