public static IntVec3 RandomAdjacentCell8Way(this Thing t) { CellRect cellRect = t.OccupiedRect(); CellRect cellRect2 = cellRect.ExpandedBy(1); IntVec3 randomCell; do { randomCell = cellRect2.RandomCell; }while (cellRect.Contains(randomCell)); return(randomCell); }
public void Notify_BuildingDespawned(Thing b) { CellRect cellRect = b.OccupiedRect(); for (int i = this.allDesignations.Count - 1; i >= 0; i--) { Designation designation = this.allDesignations[i]; if (cellRect.Contains(designation.target.Cell) && designation.def.removeIfBuildingDespawned) { this.RemoveDesignation(designation); } } }
public void Notify_BuildingDespawned(Thing b) { CellRect cellRect = b.OccupiedRect(); for (int num = allDesignations.Count - 1; num >= 0; num--) { Designation designation = allDesignations[num]; if (cellRect.Contains(designation.target.Cell) && designation.def.removeIfBuildingDespawned) { RemoveDesignation(designation); } } }
public static bool ThingFromRegionListerReachable(Thing thing, Region region, PathEndMode peMode, Pawn traveler) { Map map = region.Map; if (peMode == PathEndMode.ClosestTouch) { peMode = GenPath.ResolveClosestTouchPathMode(traveler, map, thing.Position); } switch (peMode) { case PathEndMode.None: return(false); case PathEndMode.Touch: return(true); case PathEndMode.OnCell: if (thing.def.size.x == 1 && thing.def.size.z == 1) { if (thing.Position.GetRegion(map) == region) { return(true); } } else { CellRect.CellRectIterator iterator = thing.OccupiedRect().GetIterator(); while (!iterator.Done()) { if (iterator.Current.GetRegion(map) == region) { return(true); } iterator.MoveNext(); } } return(false); case PathEndMode.InteractionCell: if (thing.InteractionCell.GetRegion(map) == region) { return(true); } return(false); default: Log.Error("Unsupported PathEndMode: " + peMode); return(false); } }
public static bool LineOfSightToThing(IntVec3 start, Thing t, Map map, bool skipFirstCell = false, Func <IntVec3, bool> validator = null) { if (t.def.size == IntVec2.One) { return(LineOfSight(start, t.Position, map)); } foreach (IntVec3 item in t.OccupiedRect()) { if (LineOfSight(start, item, map, skipFirstCell, validator)) { return(true); } } return(false); }
public void DeRegister(Thing t) { if (t.def.Fillage != 0) { CellRect cellRect = t.OccupiedRect(); for (int i = cellRect.minZ; i <= cellRect.maxZ; i++) { for (int j = cellRect.minX; j <= cellRect.maxX; j++) { IntVec3 c = new IntVec3(j, 0, i); RecalculateCell(c, t); } } } }
public void Register(Thing t) { if (t.def.Fillage != FillCategory.None) { CellRect cellRect = t.OccupiedRect(); for (int i = cellRect.minZ; i <= cellRect.maxZ; i++) { for (int j = cellRect.minX; j <= cellRect.maxX; j++) { IntVec3 c = new IntVec3(j, 0, i); this.RecalculateCell(c, null); } } } }
public static bool IsAnyCellUnderRoof(Thing thing) { CellRect cellRect = thing.OccupiedRect(); bool result = false; RoofGrid roofGrid = thing.Map.roofGrid; foreach (IntVec3 item in cellRect) { if (roofGrid.Roofed(item)) { return(true); } } return(result); }
public static IntVec3 RandomAdjacentCell8Way(this Thing t) { CellRect cellRect = t.OccupiedRect(); CellRect cellRect2 = cellRect.ExpandedBy(1); IntVec3 randomCell; while (true) { randomCell = cellRect2.RandomCell; if (!cellRect.Contains(randomCell)) { break; } } return(randomCell); }
public void Unfog(IntVec3 c) { UnfogWorker(c); List <Thing> thingList = c.GetThingList(map); for (int i = 0; i < thingList.Count; i++) { Thing thing = thingList[i]; if (thing.def.Fillage == FillCategory.Full) { foreach (IntVec3 cell in thing.OccupiedRect().Cells) { UnfogWorker(cell); } } } }
public void Register(Thing t) { if (t.def.size.x == 1 && t.def.size.z == 1) { RegisterInCell(t, t.Position); return; } CellRect cellRect = t.OccupiedRect(); for (int i = cellRect.minZ; i <= cellRect.maxZ; i++) { for (int j = cellRect.minX; j <= cellRect.maxX; j++) { RegisterInCell(t, new IntVec3(j, 0, i)); } } }
internal void Notify_ThingAffectingRegionsSpawned(Thing b) { regionsToDirty.Clear(); foreach (IntVec3 item in b.OccupiedRect().ExpandedBy(1).ClipInsideMap(b.Map)) { Region validRegionAt_NoRebuild = b.Map.regionGrid.GetValidRegionAt_NoRebuild(item); if (validRegionAt_NoRebuild != null) { b.Map.temperatureCache.TryCacheRegionTempInfo(item, validRegionAt_NoRebuild); regionsToDirty.Add(validRegionAt_NoRebuild); } } for (int i = 0; i < regionsToDirty.Count; i++) { SetRegionDirty(regionsToDirty[i]); } regionsToDirty.Clear(); }
public void Notify_LinkerCreatedOrDestroyed(Thing linker) { CellIndices cellIndices = map.cellIndices; foreach (IntVec3 item in linker.OccupiedRect()) { LinkFlags linkFlags = LinkFlags.None; List <Thing> list = map.thingGrid.ThingsListAt(item); for (int i = 0; i < list.Count; i++) { if (list[i].def.graphicData != null) { linkFlags |= list[i].def.graphicData.linkFlags; } } linkGrid[cellIndices.CellToIndex(item)] = linkFlags; } }
internal void Notify_NoZoneOverlapThingSpawned(Thing thing) { CellRect cellRect = thing.OccupiedRect(); for (int i = cellRect.minZ; i <= cellRect.maxZ; i++) { for (int j = cellRect.minX; j <= cellRect.maxX; j++) { IntVec3 c = new IntVec3(j, 0, i); Zone zone = this.ZoneAt(c); if (zone != null) { zone.RemoveCell(c); zone.CheckContiguous(); } } } }
internal void Notify_ThingAffectingRegionsDespawned(Thing b) { this.regionsToDirty.Clear(); Region validRegionAt_NoRebuild = this.map.regionGrid.GetValidRegionAt_NoRebuild(b.Position); if (validRegionAt_NoRebuild != null) { this.map.temperatureCache.TryCacheRegionTempInfo(b.Position, validRegionAt_NoRebuild); this.regionsToDirty.Add(validRegionAt_NoRebuild); } foreach (IntVec3 item2 in GenAdj.CellsAdjacent8Way(b)) { if (item2.InBounds(this.map)) { Region validRegionAt_NoRebuild2 = this.map.regionGrid.GetValidRegionAt_NoRebuild(item2); if (validRegionAt_NoRebuild2 != null) { this.map.temperatureCache.TryCacheRegionTempInfo(item2, validRegionAt_NoRebuild2); this.regionsToDirty.Add(validRegionAt_NoRebuild2); } } } for (int i = 0; i < this.regionsToDirty.Count; i++) { this.SetRegionDirty(this.regionsToDirty[i], true); } this.regionsToDirty.Clear(); if (b.def.size.x == 1 && b.def.size.z == 1) { this.dirtyCells.Add(b.Position); } else { CellRect cellRect = b.OccupiedRect(); 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); this.dirtyCells.Add(item); } } } }
public void Deregister(Thing t, bool doEvenIfDespawned = false) { if (!t.Spawned && !doEvenIfDespawned) { return; } if (t.def.size.x == 1 && t.def.size.z == 1) { DeregisterInCell(t, t.Position); return; } CellRect cellRect = t.OccupiedRect(); for (int i = cellRect.minZ; i <= cellRect.maxZ; i++) { for (int j = cellRect.minX; j <= cellRect.maxX; j++) { DeregisterInCell(t, new IntVec3(j, 0, i)); } } }
public void Notify_LinkerCreatedOrDestroyed(Thing linker) { CellIndices cellIndices = map.cellIndices; CellRect.CellRectIterator iterator = linker.OccupiedRect().GetIterator(); while (!iterator.Done()) { IntVec3 current = iterator.Current; LinkFlags linkFlags = LinkFlags.None; List <Thing> list = map.thingGrid.ThingsListAt(current); for (int i = 0; i < list.Count; i++) { if (list[i].def.graphicData != null) { linkFlags |= list[i].def.graphicData.linkFlags; } } linkGrid[cellIndices.CellToIndex(current)] = linkFlags; iterator.MoveNext(); } }
internal void Notify_ThingAffectingRegionsSpawned(Thing b) { this.regionsToDirty.Clear(); CellRect.CellRectIterator iterator = b.OccupiedRect().ExpandedBy(1).ClipInsideMap(b.Map).GetIterator(); while (!iterator.Done()) { IntVec3 current = iterator.Current; Region validRegionAt_NoRebuild = b.Map.regionGrid.GetValidRegionAt_NoRebuild(current); if (validRegionAt_NoRebuild != null) { b.Map.temperatureCache.TryCacheRegionTempInfo(current, validRegionAt_NoRebuild); this.regionsToDirty.Add(validRegionAt_NoRebuild); } iterator.MoveNext(); } for (int i = 0; i < this.regionsToDirty.Count; i++) { this.SetRegionDirty(this.regionsToDirty[i], true); } this.regionsToDirty.Clear(); }
public static void Refund(Thing thing, Map map, CellRect avoidThisRect) { bool flag = false; if (thing.def.Minifiable) { MinifiedThing minifiedThing = thing.MakeMinified(); if (GenPlace.TryPlaceThing(minifiedThing, thing.Position, map, ThingPlaceMode.Near, null, (IntVec3 x) => !avoidThisRect.Contains(x))) { flag = true; } else { minifiedThing.GetDirectlyHeldThings().Clear(); minifiedThing.Destroy(DestroyMode.Vanish); } } if (!flag) { GenLeaving.DoLeavingsFor(thing, map, DestroyMode.Refund, thing.OccupiedRect(), (IntVec3 x) => !avoidThisRect.Contains(x)); thing.Destroy(DestroyMode.Vanish); } }
public static bool AdjacentTo8WayOrInside(this Thing a, Thing b) { return(GenAdj.AdjacentTo8WayOrInside(a.OccupiedRect(), b.OccupiedRect())); }
protected bool CanHit(Thing thing) { bool result; if (!thing.Spawned) { result = false; } else if (thing == this.launcher) { result = false; } else { bool flag = false; CellRect.CellRectIterator iterator = thing.OccupiedRect().GetIterator(); while (!iterator.Done()) { List <Thing> thingList = iterator.Current.GetThingList(base.Map); bool flag2 = false; for (int i = 0; i < thingList.Count; i++) { if (thingList[i] != thing && thingList[i].def.Fillage == FillCategory.Full && thingList[i].def.Altitude >= thing.def.Altitude) { flag2 = true; break; } } if (!flag2) { flag = true; break; } iterator.MoveNext(); } if (!flag) { result = false; } else { ProjectileHitFlags hitFlags = this.HitFlags; if (thing == this.intendedTarget && (hitFlags & ProjectileHitFlags.IntendedTarget) != ProjectileHitFlags.None) { result = true; } else { if (thing != this.intendedTarget) { if (thing is Pawn) { if ((hitFlags & ProjectileHitFlags.NonTargetPawns) != ProjectileHitFlags.None) { return(true); } } else if ((hitFlags & ProjectileHitFlags.NonTargetWorld) != ProjectileHitFlags.None) { return(true); } } result = (thing == this.intendedTarget && thing.def.Fillage == FillCategory.Full); } } } return(result); }
private void TryGenerateAreaNow(Room room) { if (room.Dereferenced || room.TouchesMapEdge) { return; } if (room.RegionCount > 26 || room.CellCount > 320) { return; } if (room.RegionType == RegionType.Portal) { return; } bool flag = false; foreach (IntVec3 c in room.BorderCells) { Thing roofHolderOrImpassable = c.GetRoofHolderOrImpassable(this.map); if (roofHolderOrImpassable != null) { if (roofHolderOrImpassable.Faction != null && roofHolderOrImpassable.Faction != Faction.OfPlayer) { return; } if (roofHolderOrImpassable.def.building != null && !roofHolderOrImpassable.def.building.allowAutoroof) { return; } if (roofHolderOrImpassable.Faction == Faction.OfPlayer) { flag = true; } } } if (!flag) { return; } this.innerCells.Clear(); foreach (IntVec3 intVec in room.Cells) { if (!this.innerCells.Contains(intVec)) { this.innerCells.Add(intVec); } for (int i = 0; i < 8; i++) { IntVec3 c2 = intVec + GenAdj.AdjacentCells[i]; if (c2.InBounds(this.map)) { Thing roofHolderOrImpassable2 = c2.GetRoofHolderOrImpassable(this.map); if (roofHolderOrImpassable2 != null && (roofHolderOrImpassable2.def.size.x > 1 || roofHolderOrImpassable2.def.size.z > 1)) { CellRect cellRect = roofHolderOrImpassable2.OccupiedRect(); cellRect.ClipInsideMap(this.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 (!this.innerCells.Contains(item)) { this.innerCells.Add(item); } } } } } } } this.cellsToRoof.Clear(); foreach (IntVec3 a in this.innerCells) { for (int l = 0; l < 9; l++) { IntVec3 intVec2 = a + GenAdj.AdjacentCellsAndInside[l]; if (intVec2.InBounds(this.map) && (l == 8 || intVec2.GetRoofHolderOrImpassable(this.map) != null) && !this.cellsToRoof.Contains(intVec2)) { this.cellsToRoof.Add(intVec2); } } } this.justRoofedCells.Clear(); foreach (IntVec3 intVec3 in this.cellsToRoof) { if (this.map.roofGrid.RoofAt(intVec3) == null && !this.justRoofedCells.Contains(intVec3)) { if (!this.map.areaManager.NoRoof[intVec3] && RoofCollapseUtility.WithinRangeOfRoofHolder(intVec3, this.map, true)) { this.map.areaManager.BuildRoof[intVec3] = true; this.justRoofedCells.Add(intVec3); } } } }
public void FaceTarget(LocalTargetInfo target) { if (target.IsValid) { if (target.HasThing) { Thing thing = (!target.Thing.Spawned) ? ThingOwnerUtility.GetFirstSpawnedParentThing(target.Thing) : target.Thing; if (thing != null && thing.Spawned) { bool flag = false; IntVec3 c = default(IntVec3); CellRect cellRect = thing.OccupiedRect(); for (int i = cellRect.minZ; i <= cellRect.maxZ; i++) { for (int j = cellRect.minX; j <= cellRect.maxX; j++) { if (pawn.Position == new IntVec3(j, 0, i)) { Face(thing.DrawPos); return; } } } for (int k = cellRect.minZ; k <= cellRect.maxZ; k++) { for (int l = cellRect.minX; l <= cellRect.maxX; l++) { IntVec3 intVec = new IntVec3(l, 0, k); if (intVec.AdjacentToCardinal(pawn.Position)) { FaceAdjacentCell(intVec); return; } if (intVec.AdjacentTo8Way(pawn.Position)) { flag = true; c = intVec; } } } if (flag) { if (DebugViewSettings.drawPawnRotatorTarget) { pawn.Map.debugDrawer.FlashCell(pawn.Position, 0.6f, "jbthing"); GenDraw.DrawLineBetween(pawn.Position.ToVector3Shifted(), c.ToVector3Shifted()); } FaceAdjacentCell(c); } else { Face(thing.DrawPos); } } } else if (pawn.Position.AdjacentTo8Way(target.Cell)) { if (DebugViewSettings.drawPawnRotatorTarget) { pawn.Map.debugDrawer.FlashCell(pawn.Position, 0.2f, "jbloc"); GenDraw.DrawLineBetween(pawn.Position.ToVector3Shifted(), target.Cell.ToVector3Shifted()); } FaceAdjacentCell(target.Cell); } else if (target.Cell.IsValid && target.Cell != pawn.Position) { Face(target.Cell.ToVector3()); } } }
private void TryGenerateAreaNow(Room room) { if (!room.Dereferenced && !room.TouchesMapEdge && room.RegionCount <= 26 && room.CellCount <= 320 && room.RegionType != RegionType.Portal) { 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) { 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)) { Thing roofHolderOrImpassable2 = c.GetRoofHolderOrImpassable(map); if (roofHolderOrImpassable2 != null && (roofHolderOrImpassable2.def.size.x > 1 || roofHolderOrImpassable2.def.size.z > 1)) { 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) { RoofDef roofDef = map.roofGrid.RoofAt(item2); if (roofDef == null && !justRoofedCells.Contains(item2) && !map.areaManager.NoRoof[item2] && RoofCollapseUtility.WithinRangeOfRoofHolder(item2, map, assumeNonNoRoofCellsAreRoofed: true)) { map.areaManager.BuildRoof[item2] = true; justRoofedCells.Add(item2); } } } } }
public static bool IsAdjacentToCardinalOrInside(this Thing t1, Thing t2) { return(GenAdj.IsAdjacentToCardinalOrInside(t1.OccupiedRect(), t2.OccupiedRect())); }
public bool TryFindShootLineFromTo(IntVec3 root, LocalTargetInfo targ, out ShootLine resultingLine) { if (targ.HasThing && targ.Thing.Map != caster.Map) { resultingLine = default(ShootLine); return(false); } if (verbProps.IsMeleeAttack || verbProps.range <= 1.42f) { resultingLine = new ShootLine(root, targ.Cell); return(ReachabilityImmediate.CanReachImmediate(root, targ, caster.Map, PathEndMode.Touch, null)); } CellRect cellRect = (!targ.HasThing) ? CellRect.SingleCell(targ.Cell) : targ.Thing.OccupiedRect(); float num = verbProps.EffectiveMinRange(targ, caster); float num2 = cellRect.ClosestDistSquaredTo(root); if (num2 > verbProps.range * verbProps.range || num2 < num * num) { resultingLine = new ShootLine(root, targ.Cell); return(false); } if (!verbProps.requireLineOfSight) { resultingLine = new ShootLine(root, targ.Cell); return(true); } IntVec3 goodDest; if (CasterIsPawn) { if (CanHitFromCellIgnoringRange(root, targ, out goodDest)) { resultingLine = new ShootLine(root, goodDest); return(true); } ShootLeanUtility.LeanShootingSourcesFromTo(root, cellRect.ClosestCellTo(root), caster.Map, tempLeanShootSources); for (int i = 0; i < tempLeanShootSources.Count; i++) { IntVec3 intVec = tempLeanShootSources[i]; if (CanHitFromCellIgnoringRange(intVec, targ, out goodDest)) { resultingLine = new ShootLine(intVec, goodDest); return(true); } } } else { CellRect.CellRectIterator iterator = caster.OccupiedRect().GetIterator(); while (!iterator.Done()) { IntVec3 current = iterator.Current; if (CanHitFromCellIgnoringRange(current, targ, out goodDest)) { resultingLine = new ShootLine(current, goodDest); return(true); } iterator.MoveNext(); } } resultingLine = new ShootLine(root, targ.Cell); return(false); }