public override void CompTick() { //Since it's a laggy class, allow options to toggle it if (AnimalBehaviours_Settings.flagAnimalParticles) { this.gasProgress++; //Increasing gasTickMax reduces lag, but it will also look like ass if (this.gasProgress > gasTickMax) { Pawn pawn = this.parent as Pawn; if (pawn.Map != null) { if (!Props.generateIfDowned || (Props.generateIfDowned && !pawn.Downed && !pawn.Dead)) { CellRect rect = GenAdj.OccupiedRect(pawn.Position, pawn.Rotation, IntVec2.One); rect = rect.ExpandedBy(Props.radius); foreach (IntVec3 current in rect.Cells) { if (current.InBounds(pawn.Map) && rand.NextDouble() < Props.rate) { Thing thing = ThingMaker.MakeThing(ThingDef.Named(Props.gasType), null); thing.Rotation = Rot4.North; thing.Position = current; //Directly using SpawnSetup instead of GenSpawn.Spawn to further reduce lag thing.SpawnSetup(pawn.Map, false); } } } this.gasProgress = 0; } } } }
public static bool CanBuildOnTerrain(BuildableDef entDef, IntVec3 c, Map map, Rot4 rot, Thing thingToIgnore = null, ThingDef stuffDef = null) { TerrainAffordanceDef terrainAffordanceNeed = entDef.GetTerrainAffordanceNeed(stuffDef); if (terrainAffordanceNeed != null) { CellRect cellRect = GenAdj.OccupiedRect(c, rot, entDef.Size); cellRect.ClipInsideMap(map); foreach (IntVec3 item in cellRect) { if (!map.terrainGrid.TerrainAt(item).affordances.Contains(terrainAffordanceNeed)) { return(false); } List <Thing> thingList = item.GetThingList(map); for (int i = 0; i < thingList.Count; i++) { if (thingList[i] != thingToIgnore) { TerrainDef terrainDef = thingList[i].def.entityDefToBuild as TerrainDef; if (terrainDef != null && !terrainDef.affordances.Contains(terrainAffordanceNeed)) { return(false); } } } } } return(true); }
public override void Resolve(ResolveParams rp) { Map map = BaseGen.globalSettings.map; ThingDef thingDef = (rp.singleThingDef != null) ? rp.singleThingDef : ((rp.faction == null || (int)rp.faction.def.techLevel < 3) ? Rand.Element(ThingDefOf.Bed, ThingDefOf.Bedroll, ThingDefOf.SleepingSpot) : ThingDefOf.Bed); ThingDef singleThingStuff = (rp.singleThingStuff == null || !rp.singleThingStuff.stuffProps.CanMake(thingDef)) ? GenStuff.RandomStuffInexpensiveFor(thingDef, rp.faction) : rp.singleThingStuff; bool @bool = Rand.Bool; foreach (IntVec3 item in rp.rect) { if (@bool) { if (item.x % 3 != 0 || item.z % 2 != 0) { continue; } } else if (item.x % 2 != 0 || item.z % 3 != 0) { continue; } Rot4 rot = @bool ? Rot4.West : Rot4.North; if (!GenSpawn.WouldWipeAnythingWith(item, rot, thingDef, map, (Thing x) => x.def.category == ThingCategory.Building) && !BaseGenUtility.AnyDoorAdjacentCardinalTo(GenAdj.OccupiedRect(item, rot, thingDef.Size), map)) { ResolveParams resolveParams = rp; resolveParams.rect = GenAdj.OccupiedRect(item, rot, thingDef.size); resolveParams.singleThingDef = thingDef; resolveParams.singleThingStuff = singleThingStuff; resolveParams.thingRot = rot; BaseGen.symbolStack.Push("bed", resolveParams); } } }
public void SendThingsByFarcast() { CellRect rect = GenAdj.OccupiedRect(this.Position, this.Rotation, this.def.size); rect = rect.ExpandedBy(4); soundDef.PlayOneShotOnCamera(null); foreach (IntVec3 current in rect.Cells) { Building edifice = current.GetEdifice(this.Map); if (edifice != null && ((edifice.def.defName == "GU_FarcasterPad") || (edifice.def.defName == "GU_AncientFarcasterPad"))) { foreach (IntVec3 current2 in edifice.OccupiedRect().Cells) { List <Thing> thingList = current2.GetThingList(this.Map); for (int i = 0; i < thingList.Count; i++) { if (thingList[i] is Pawn || (thingList[i] is ThingWithComps && !(thingList[i] is Building))) { Thing thingToSend = thingList[i]; thingToSend.DeSpawn(); GenSpawn.Spawn(thingToSend, locationHome - GenAdj.CardinalDirections[0] * 4, mapHome); } } } } } }
/// <summary> /// Check if <paramref name="thing"/> blocks any interaction cell of others if placed at <paramref name="pos"/> with rotation <paramref name="rot"/>. /// </summary> /// <param name="thing"> Thing to place. </param> /// <param name="pos"> Position at which <paramref name="thing"/> would be placed. </param> /// <param name="rot"> Would be rotation of <paramref name="thing"/>. </param> /// <returns> First Thing which interaction cell is blocked by <paramref name="thing"/>. </returns> public static Thing BlockAdjacentInteractionCell(this Thing thing, IntVec3 pos, Rot4 rot) { CellRect cellRect = GenAdj.OccupiedRect(pos, rot, thing.def.size); foreach (IntVec3 cell in GenAdj.CellsAdjacentCardinal(pos, rot, thing.def.Size)) { if (cell.InBounds(thing.MapHeld)) { List <Thing> things = cell.GetThingList(thing.MapHeld); foreach (Thing neighbour in things) { if (neighbour.def.hasInteractionCell && (thing.def.passability == Traversability.Impassable || thing.def == neighbour.def) && cellRect.Contains( Verse.ThingUtility.InteractionCellWhenAt( neighbour.def, neighbour.Position, neighbour.Rotation, neighbour.Map))) { return(neighbour); } } } } return(null); }
private bool TrySpawnPowerTransmittingBuildingNear(IntVec3 position, Map map, Faction faction, ThingDef def, out Building newBuilding, Predicate <IntVec3> extraValidator = null) { TraverseParms traverseParams = TraverseParms.For(TraverseMode.PassAllDestroyableThings, Danger.Deadly, false); IntVec3 loc; if (RCellFinder.TryFindRandomCellNearWith(position, delegate(IntVec3 x) { if (!x.Standable(map) || x.Roofed(map) || !this.EverPossibleToTransmitPowerAt(x, map)) { return(false); } if (!map.reachability.CanReach(position, x, PathEndMode.OnCell, traverseParams)) { return(false); } CellRect.CellRectIterator iterator = GenAdj.OccupiedRect(x, Rot4.North, def.size).GetIterator(); while (!iterator.Done()) { IntVec3 c = iterator.Current; if (!c.InBounds(map) || c.Roofed(map) || c.GetEdifice(map) != null || c.GetFirstItem(map) != null || c.GetTransmitter(map) != null) { return(false); } iterator.MoveNext(); } return(extraValidator == null || extraValidator(x)); }, map, out loc, 8, 2147483647)) { newBuilding = (Building)GenSpawn.Spawn(ThingMaker.MakeThing(def, null), loc, map, Rot4.North, WipeMode.Vanish, false); newBuilding.SetFaction(faction, null); return(true); } newBuilding = null; return(false); }
public static bool CanPossiblyFallOnColonist(ThingDef skyfaller, IntVec3 c, Map map) { CellRect cellRect = GenAdj.OccupiedRect(c, Rot4.North, skyfaller.size); int dist = Mathf.Max(Mathf.CeilToInt(skyfaller.skyfaller.explosionRadius) + 7, 14); CellRect.CellRectIterator iterator = cellRect.ExpandedBy(dist).GetIterator(); while (!iterator.Done()) { IntVec3 c2 = iterator.Current; if (c2.InBounds(map)) { List <Thing> thingList = c2.GetThingList(map); for (int i = 0; i < thingList.Count; i++) { Pawn pawn = thingList[i] as Pawn; if (pawn != null && pawn.IsColonist) { return(true); } } } iterator.MoveNext(); } return(false); }
public bool WouldCollide(ThingDef def, IntVec3 pos, Rot4 rot) { CellRect cellRect = GenAdj.OccupiedRect(pos, rot, def.size); if (def.terrainAffordanceNeeded != null) { foreach (IntVec3 item in cellRect) { TerrainDef terrainDef = TerrainAt(item); if (terrainDef != null && !terrainDef.affordances.Contains(def.terrainAffordanceNeeded)) { return(true); } } } for (int i = 0; i < cachedThings.Count; i++) { if (!cellRect.Overlaps(cachedThings[i].OccupiedRect)) { continue; } if (def.race != null) { if (cachedThings[i].def.passability == Traversability.Impassable) { return(true); } } else if (!GenConstruct.CanPlaceBlueprintOver(def, cachedThings[i].def)) { return(true); } } return(false); }
public void WipeColliding(ThingDef def, IntVec3 pos, Rot4 rot) { if (!WouldCollide(def, pos, rot)) { return; } CellRect cellRect = GenAdj.OccupiedRect(pos, rot, def.size); if (def.terrainAffordanceNeeded != null) { foreach (IntVec3 item in cellRect) { TerrainDef terrainDef = TerrainAt(item); if (terrainDef != null && !terrainDef.affordances.Contains(def.terrainAffordanceNeeded)) { RemoveTerrain(item); } } } for (int num = cachedThings.Count - 1; num >= 0; num--) { if (cellRect.Overlaps(cachedThings[num].OccupiedRect) && !GenConstruct.CanPlaceBlueprintOver(def, cachedThings[num].def)) { Remove(cachedThings[num]); } } }
public override void DrawGhost(ThingDef def, IntVec3 center, Rot4 rot) { CellRect cellRect = GenAdj.OccupiedRect(center, rot, def.size); cellRect = cellRect.ExpandedBy(1); GenDraw.DrawFieldEdges(cellRect.Cells.ToList(), Color.white); }
public override AcceptanceReport AllowsPlacing(BuildableDef def, IntVec3 center, Rot4 rot, Map map, Thing thingToIgnore = null, Thing thing) { return(!GenAdj.OccupiedRect(center, rot, def.Size).Cells.Any(cell => map.thingGrid.ThingsAt(cell) .Where(t => t != thingToIgnore) .Any(t => t.def.passability == Traversability.Impassable))); }
public static IntVec3 GetSleepingSlotPos(int index, IntVec3 bedCenter, Rot4 bedRot, IntVec2 bedSize) { int sleepingSlotsCount = GetSleepingSlotsCount(bedSize); if (index < 0 || index >= sleepingSlotsCount) { Log.Error("Tried to get sleeping slot pos with index " + index + ", but there are only " + sleepingSlotsCount + " sleeping slots available."); return(bedCenter); } CellRect cellRect = GenAdj.OccupiedRect(bedCenter, bedRot, bedSize); if (bedRot == Rot4.North) { return(new IntVec3(cellRect.minX + index, bedCenter.y, cellRect.minZ)); } if (bedRot == Rot4.East) { return(new IntVec3(cellRect.minX, bedCenter.y, cellRect.maxZ - index)); } if (bedRot == Rot4.South) { return(new IntVec3(cellRect.minX + index, bedCenter.y, cellRect.maxZ)); } return(new IntVec3(cellRect.maxX, bedCenter.y, cellRect.maxZ - index)); }
public override void Resolve(ResolveParams rp) { Map map = BaseGen.globalSettings.map; bool @bool = Rand.Bool; ThingDef thingDef = rp.singleThingDef ?? Rand.Element(ThingDefOf.Bed, ThingDefOf.Bedroll, ThingDefOf.SleepingSpot); ThingDef singleThingStuff = rp.singleThingStuff ?? GenStuff.RandomStuffByCommonalityFor(thingDef, (rp.faction != null) ? rp.faction.def.techLevel : TechLevel.Undefined); foreach (IntVec3 item in rp.rect) { IntVec3 current = item; if (@bool) { if (current.x % 3 == 0 && current.z % 2 == 0) { goto IL_00d5; } } else if (current.x % 2 == 0 && current.z % 3 == 0) { goto IL_00d5; } continue; IL_00d5: Rot4 rot = (!@bool) ? Rot4.North : Rot4.West; if (!GenSpawn.WouldWipeAnythingWith(current, rot, thingDef, map, (Thing x) => x.def.category == ThingCategory.Building) && !BaseGenUtility.AnyDoorAdjacentCardinalTo(GenAdj.OccupiedRect(current, rot, thingDef.Size), map)) { ResolveParams resolveParams = rp; resolveParams.rect = GenAdj.OccupiedRect(current, rot, thingDef.size); resolveParams.singleThingDef = thingDef; resolveParams.singleThingStuff = singleThingStuff; resolveParams.thingRot = rot; BaseGen.symbolStack.Push("bed", resolveParams); } } }
public override bool IsSpawningBlockedPermanently(IntVec3 at, Map map, Thing thingToIgnore = null, bool wipeIfCollides = false) { if (!at.InBounds(map)) { return(true); } if (!CanBuildOnTerrain(at, map)) { return(true); } foreach (IntVec3 item in GenAdj.OccupiedRect(at, rot, def.Size)) { if (!item.InBounds(map)) { return(true); } List <Thing> thingList = item.GetThingList(map); for (int i = 0; i < thingList.Count; i++) { if (!thingList[i].def.destroyable && !GenConstruct.CanPlaceBlueprintOver(def, thingList[i].def)) { return(true); } } } return(false); }
public override void CompTick() { if (!AlphaAnimalsEvents_Settings.removeAnimalParticles) { this.gasProgress += 1; if (this.gasProgress > gasTickMax) { Pawn pawn = this.parent as Pawn; if (pawn.Map != null) { CellRect rect = GenAdj.OccupiedRect(pawn.Position, pawn.Rotation, IntVec2.One); rect = rect.ExpandedBy(Props.radius); foreach (IntVec3 current in rect.Cells) { if (current.InBounds(pawn.Map) && rand.NextDouble() < Props.rate) { Thing thing = ThingMaker.MakeThing(ThingDef.Named(Props.gasType), null); thing.Rotation = Rot4.North; thing.Position = current; thing.SpawnSetup(pawn.Map, false); //GenSpawn.Spawn(thing, current, pawn.Map); } } // FilthMaker.MakeFilth(this.parent.PositionHeld, this.parent.MapHeld, ThingDef.Named("GR_FilthMucus"), 1); this.gasProgress = 0; } } } }
// Token: 0x060024EE RID: 9454 RVA: 0x00119A04 File Offset: 0x00117E04 public static IntVec3 GetSleepingSlotPos(int index, IntVec3 bedCenter, Rot4 bedRot, IntVec2 bedSize) { int sleepingSlotsCount = XenomorphCocoonUtility.GetSleepingSlotsCount(bedSize); if (index < 0 || index >= sleepingSlotsCount) { Log.Error(string.Concat(new object[] { "Tried to get sleeping slot pos with index ", index, ", but there are only ", sleepingSlotsCount, " sleeping slots available." }), false); return(bedCenter); } CellRect cellRect = GenAdj.OccupiedRect(bedCenter, bedRot, bedSize); if (bedRot == Rot4.North) { return(new IntVec3(cellRect.minX + index, bedCenter.y, cellRect.maxZ)); } if (bedRot == Rot4.East) { return(new IntVec3(cellRect.maxX, bedCenter.y, cellRect.maxZ - index)); } if (bedRot == Rot4.South) { return(new IntVec3(cellRect.minX + index, bedCenter.y, cellRect.maxZ)); } return(new IntVec3(cellRect.maxX, bedCenter.y, cellRect.minZ - index)); }
public override void PostDeSpawn(Map map) { base.PostDeSpawn(map); if (mapCompSeenFog != null && (compHideFromPlayer != null || compAffectVision != null)) { if (isOneCell) { mapCompSeenFog.deregisterCompHideFromPlayerPosition(compHideFromPlayer, lastPosition.x, lastPosition.z); mapCompSeenFog.deregisterCompAffectVisionPosition(compAffectVision, lastPosition.x, lastPosition.z); } else if (lastPosition != iv3Invalid && lastRotation != r4Invalid) { int z; int x; CellRect cellRect = GenAdj.OccupiedRect(lastPosition, lastRotation, size); for (z = cellRect.minZ; z <= cellRect.maxZ; z++) { for (x = cellRect.minX; x <= cellRect.maxX; x++) { if (compHideFromPlayer != null) { mapCompSeenFog.deregisterCompHideFromPlayerPosition(compHideFromPlayer, x, z); } if (compAffectVision != null) { mapCompSeenFog.deregisterCompAffectVisionPosition(compAffectVision, x, z); } } } } } }
public static CellRect RangeArea(ThingDef def, IntVec3 center, Rot4 rot) { int range = -def.interactionCellOffset.z; IntVec2 area = new IntVec2(def.Size.x, range - def.size.z); return(GenAdj.OccupiedRect(FindRangeCenter(center, rot, range), rot, area)); }
public static bool SkyfallerCanLandAt(IntVec3 c, Map map, IntVec2 size, Faction faction = null) { if (!IsSafeDropSpot(c, map, faction, size, 5)) { return(false); } foreach (IntVec3 item in GenAdj.OccupiedRect(c, Rot4.North, size)) { List <Thing> thingList = item.GetThingList(map); for (int i = 0; i < thingList.Count; i++) { Thing thing = thingList[i]; if (thing is IActiveDropPod || thing is Skyfaller) { return(false); } PlantProperties plant = thing.def.plant; if (plant != null && plant.IsTree) { return(false); } if (thing.def.preventSkyfallersLandingOn) { return(false); } if (thing.def.category == ThingCategory.Item || thing.def.category == ThingCategory.Building) { return(false); } } } return(true); }
public static bool CanBuildOnTerrain(BuildableDef entDef, IntVec3 c, Map map, Rot4 rot, Thing thingToIgnore = null) { TerrainDef terrainDef = entDef as TerrainDef; if (terrainDef != null && !c.GetTerrain(map).changeable) { return(false); } CellRect cellRect = GenAdj.OccupiedRect(c, rot, entDef.Size); cellRect.ClipInsideMap(map); CellRect.CellRectIterator iterator = cellRect.GetIterator(); while (!iterator.Done()) { TerrainDef terrainDef2 = map.terrainGrid.TerrainAt(iterator.Current); if (entDef.terrainAffordanceNeeded != null && !terrainDef2.affordances.Contains(entDef.terrainAffordanceNeeded)) { return(false); } List <Thing> thingList = iterator.Current.GetThingList(map); for (int i = 0; i < thingList.Count; i++) { if (thingList[i] != thingToIgnore) { TerrainDef terrainDef3 = thingList[i].def.entityDefToBuild as TerrainDef; if (terrainDef3 != null && !terrainDef3.affordances.Contains(entDef.terrainAffordanceNeeded)) { return(false); } } } iterator.MoveNext(); } return(true); }
protected override bool TryExecuteWorker(IncidentParms parms) { Map map = (Map)parms.target; List <TargetInfo> list = new List <TargetInfo>(); ThingDef shipPartDef = def.mechClusterBuilding; IntVec3 intVec = FindDropPodLocation(map, (IntVec3 spot) => CanPlaceAt(spot)); if (intVec == IntVec3.Invalid) { return(false); } float points = Mathf.Max(parms.points * 0.9f, 300f); List <Pawn> list2 = PawnGroupMakerUtility.GeneratePawns(new PawnGroupMakerParms { groupKind = PawnGroupKindDefOf.Combat, tile = map.Tile, faction = Faction.OfMechanoids, points = points }).ToList(); Thing thing = ThingMaker.MakeThing(shipPartDef); thing.SetFaction(Faction.OfMechanoids); LordMaker.MakeNewLord(Faction.OfMechanoids, new LordJob_SleepThenMechanoidsDefend(new List <Thing> { thing }, Faction.OfMechanoids, 28f, intVec, canAssaultColony: false, isMechCluster: false), map, list2); DropPodUtility.DropThingsNear(intVec, map, list2.Cast <Thing>()); foreach (Pawn item in list2) { item.TryGetComp <CompCanBeDormant>()?.ToSleep(); } list.AddRange(list2.Select((Pawn p) => new TargetInfo(p))); GenSpawn.Spawn(SkyfallerMaker.MakeSkyfaller(ThingDefOf.CrashedShipPartIncoming, thing), intVec, map); list.Add(new TargetInfo(intVec, map)); SendStandardLetter(parms, list); return(true); bool CanPlaceAt(IntVec3 loc) { CellRect cellRect = GenAdj.OccupiedRect(loc, Rot4.North, shipPartDef.Size); if (loc.Fogged(map) || !cellRect.InBounds(map)) { return(false); } if (!DropCellFinder.SkyfallerCanLandAt(loc, map, shipPartDef.Size)) { return(false); } foreach (IntVec3 item2 in cellRect) { RoofDef roof = item2.GetRoof(map); if (roof != null && roof.isNatural) { return(false); } } return(GenConstruct.CanBuildOnTerrain(shipPartDef, loc, map, Rot4.North)); } }
public override void CompTick() { this.gasProgress += 1; //Increasing gasTickMax reduces lag, but it will also look like ass if (this.gasProgress > gasTickMax) { Pawn pawn = this.parent as Pawn; if (pawn.Map != null) { CellRect rect = GenAdj.OccupiedRect(pawn.Position, pawn.Rotation, IntVec2.One); rect = rect.ExpandedBy(Props.radius); foreach (IntVec3 current in rect.Cells) { if (current.InBounds(pawn.Map) && rand.NextDouble() < Props.rate) { Thing thing = ThingMaker.MakeThing(ThingDef.Named(Props.gasType), null); thing.Rotation = Rot4.North; thing.Position = current; //Directly using SpawnSetup instead of GenSpawn.Spawn to further reduce lag thing.SpawnSetup(pawn.Map, false); } } this.gasProgress = 0; } } }
public override AcceptanceReport AllowsPlacing(BuildableDef checkingDef, IntVec3 loc, Rot4 rot, Thing thingToIgnore = null) { var rect = GenAdj.OccupiedRect(loc, rot, checkingDef.Size); foreach (var innerCell in rect.ContractedBy(1)) { // Interior only excludes other carn buildings if (innerCell.GetThingList(base.Map) .Any(t => t is Blueprint_StuffHacked || t is Frame_StuffHacked || t is Building_Carn)) { return(new AcceptanceReport("CarnTentInvalidInterior".Translate(checkingDef.label))); } } foreach (var wallCell in rect.EdgeCells.Concat(rect.ExpandedBy(1).EdgeCells)) { // Edge cells are more exclusive if (wallCell.GetThingList(base.Map) .Any(t => t is Blueprint || t is Frame || t is Building)) { return(new AcceptanceReport("CarnTentInvalidWalls".Translate(checkingDef.label))); } } return(base.AllowsPlacing(checkingDef, loc, rot, thingToIgnore)); }
private bool TryFindMortarSpawnCell(CellRect rect, Rot4 rot, ThingDef mortarDef, out IntVec3 cell) { Map map = BaseGen.globalSettings.map; Predicate <CellRect> edgeTouchCheck; if (rot == Rot4.North) { edgeTouchCheck = ((CellRect x) => x.Cells.Any((IntVec3 y) => y.z == rect.maxZ)); } else if (rot == Rot4.South) { edgeTouchCheck = ((CellRect x) => x.Cells.Any((IntVec3 y) => y.z == rect.minZ)); } else if (rot == Rot4.West) { edgeTouchCheck = ((CellRect x) => x.Cells.Any((IntVec3 y) => y.x == rect.minX)); } else { edgeTouchCheck = ((CellRect x) => x.Cells.Any((IntVec3 y) => y.x == rect.maxX)); } return(CellFinder.TryFindRandomCellInsideWith(rect, delegate(IntVec3 x) { CellRect obj = GenAdj.OccupiedRect(x, rot, mortarDef.size); return ThingUtility.InteractionCellWhenAt(mortarDef, x, rot, map).Standable(map) && obj.FullyContainedWithin(rect) && edgeTouchCheck(obj); }, out cell)); }
private static bool IsPotentiallyValidFacilityForMe_Static(ThingDef facilityDef, IntVec3 facilityPos, Rot4 facilityRot, ThingDef myDef, IntVec3 myPos, Rot4 myRot, Map map) { CellRect startRect = GenAdj.OccupiedRect(myPos, myRot, myDef.size); CellRect endRect = GenAdj.OccupiedRect(facilityPos, facilityRot, facilityDef.size); bool flag = false; for (int i = startRect.minZ; i <= startRect.maxZ; i++) { for (int j = startRect.minX; j <= startRect.maxX; j++) { for (int k = endRect.minZ; k <= endRect.maxZ; k++) { for (int l = endRect.minX; l <= endRect.maxX; l++) { IntVec3 start = new IntVec3(j, 0, i); IntVec3 end = new IntVec3(l, 0, k); if (GenSight.LineOfSight(start, end, map, startRect, endRect, null)) { goto IL_0081; } } } } continue; IL_0081: flag = true; break; } if (!flag) { return(false); } return(true); }
private bool hasPartShownToPlayer() { Faction playerFaction = Faction.OfPlayer; if (isOneCell) { return(mapCompSeenFog.isShown(playerFaction, lastPosition.x, lastPosition.z)); } else { CellRect occupiedRect = GenAdj.OccupiedRect(lastPosition, lastRotation, size); for (int x = occupiedRect.minX; x <= occupiedRect.maxX; x++) { for (int z = occupiedRect.minZ; z <= occupiedRect.maxZ; z++) { if (mapCompSeenFog.isShown(playerFaction, x, z)) { return(true); } } } } return(false); }
public IEnumerable <IntVec3> CellsForWater(ThingDef def, IntVec3 center, Rot4 rot) { var rightRot = rot; rightRot.Rotate(RotationDirection.Clockwise); var elOne = 1; var elTwo = 3; if (rot == Rot4.West) { elOne = 3; elTwo = 2; } else if (rot == Rot4.South) { elOne = 0; elTwo = 2; } else if (rot == Rot4.East) { elOne = 0; elTwo = 1; } var cellAbove = GenAdj.OccupiedRect(center, rot, def.size).Corners.ElementAt(elOne) + rightRot.FacingCell; var cellAdj = GenAdj.OccupiedRect(center, rot, def.size).Corners.ElementAt(elTwo) + rightRot.FacingCell; return(new List <IntVec3> { cellAbove, cellAdj }); }
/* * public static bool Spawn(ref Thing __result, * 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); * __result = (Thing)null; * return false; * } * if (!loc.InBounds(map)) * { * Log.Error("Tried to spawn " + newThing.ToStringSafe<Thing>() + " out of bounds at " + (object)loc + ".", false); * __result = (Thing)null; * return false; * } * //added null check * if (null != newThing) * { * //added null check * if (null != newThing.def) * { * if (newThing.def.randomizeRotationOnSpawn) * rot = Rot4.Random; * CellRect occupiedRect = GenAdj.OccupiedRect(loc, rot, newThing.def.Size); * if (!occupiedRect.InBounds(map)) * { * Log.Error("Tried to spawn " + newThing.ToStringSafe<Thing>() + " out of bounds at " + (object)loc + " (out of bounds because size is " + (object)newThing.def.Size + ").", false); * __result = (Thing)null; * return false; * } * if (newThing.Spawned) * { * Log.Error("Tried to spawn " + (object)newThing + " but it's already spawned.", false); * __result = newThing; * return false; * } * switch (wipeMode) * { * case WipeMode.Vanish: * GenSpawn.WipeExistingThings(loc, rot, (BuildableDef)newThing.def, map, DestroyMode.Vanish); * break; * case WipeMode.FullRefund: * GenSpawn.WipeAndRefundExistingThings(loc, rot, (BuildableDef)newThing.def, map); * break; * case WipeMode.VanishOrMoveAside: * GenSpawn.CheckMoveItemsAside(loc, rot, newThing.def, map); * GenSpawn.WipeExistingThings(loc, rot, (BuildableDef)newThing.def, map, DestroyMode.Vanish); * break; * } * if (newThing.def.category == ThingCategory.Item) * { * foreach (IntVec3 intVec3 in occupiedRect) * { * foreach (Thing thing in intVec3.GetThingList(map).ToList<Thing>()) * { * if (thing != newThing && thing.def.category == ThingCategory.Item) * { * thing.DeSpawn(DestroyMode.Vanish); * if (!GenPlace.TryPlaceThing(thing, intVec3, map, ThingPlaceMode.Near, (Action<Thing, int>)null, (Predicate<IntVec3>)(x => !occupiedRect.Contains(x)), new Rot4())) * 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: " + (object)newThing, false); * newThing.Destroy(DestroyMode.Vanish); * __result = (Thing)null; * return false; * } * if (newThing.def.passability == Traversability.Impassable) * { * foreach (IntVec3 c in occupiedRect) * { * foreach (Thing thing in c.GetThingList(map).ToList<Thing>()) * { * if (thing != newThing && thing is Pawn pawn) * pawn.pather.TryRecoverFromUnwalkablePosition(false); * } * } * __result = newThing; * return false; * } * } * } * __result = newThing; * return false; * } */ public static bool CheckMoveItemsAside( IntVec3 thingPos, Rot4 thingRot, ThingDef thingDef, Map map) { if (thingDef.surfaceType != SurfaceType.None || thingDef.passability == Traversability.Standable) { return(false); } CellRect occupiedRect = GenAdj.OccupiedRect(thingPos, thingRot, thingDef.Size); foreach (IntVec3 intVec3 in occupiedRect) { //if (intVec3.InBounds(map)) //{ //CellIndices cellIndices = map.cellIndices; //List<Thing> list = intVec3.GetThingList(map).ToList<Thing>(); // map.thingGrid [cellIndices.CellToIndex(intVec3)]; foreach (Thing thing in map.thingGrid.ThingsAt(intVec3)) { if (thing.def.category == ThingCategory.Item) { thing.DeSpawn(DestroyMode.Vanish); if (!GenPlace.TryPlaceThing(thing, intVec3, map, ThingPlaceMode.Near, null, (x => !occupiedRect.Contains(x)), new Rot4())) { thing.Destroy(DestroyMode.Vanish); } } } //} } return(false); }
// Verse.Verb // Token: 0x060022E2 RID: 8930 RVA: 0x000D4A4C File Offset: 0x000D2C4C public new bool TryFindShootLineFromTo(IntVec3 root, LocalTargetInfo targ, out ShootLine resultingLine) { if (targ.HasThing && targ.Thing.Map != this.Caster.Map) { resultingLine = default(ShootLine); return(false); } if (this.verbProps.IsMeleeAttack || this.EffectiveRange <= 1.42f) { resultingLine = new ShootLine(root, targ.Cell); return(ReachabilityImmediate.CanReachImmediate(root, targ, this.Caster.Map, PathEndMode.Touch, null)); } CellRect cellRect = targ.HasThing ? targ.Thing.OccupiedRect() : CellRect.SingleCell(targ.Cell); float num = this.verbProps.EffectiveMinRange(targ, this.Caster); float num2 = cellRect.ClosestDistSquaredTo(root); if (num2 > this.EffectiveRange * this.EffectiveRange || num2 < num * num) { resultingLine = new ShootLine(root, targ.Cell); return(false); } if (!this.verbProps.requireLineOfSight) { resultingLine = new ShootLine(root, targ.Cell); return(true); } if (this.CasterIsPawn) { if (this.CanHitFromCellIgnoringRange(root, targ, out IntVec3 dest)) { resultingLine = new ShootLine(root, dest); return(true); } ShootLeanUtility.LeanShootingSourcesFromTo(root, cellRect.ClosestCellTo(root), this.Caster.Map, Verb_ShootCompMountedCE.tempLeanShootSources); for (int i = 0; i < Verb_ShootCompMountedCE.tempLeanShootSources.Count; i++) { IntVec3 intVec = Verb_ShootCompMountedCE.tempLeanShootSources[i]; if (this.CanHitFromCellIgnoringRange(intVec, targ, out dest)) { resultingLine = new ShootLine(intVec, dest); return(true); } } } else { IntVec2 size = new IntVec2(Caster.def.size.x + 1, Caster.def.size.z + 1); foreach (IntVec3 intVec2 in GenAdj.OccupiedRect(Caster.Position, Caster.Rotation, size)) { if (this.CanHitFromCellIgnoringRange(intVec2, targ, out IntVec3 dest)) { resultingLine = new ShootLine(intVec2, dest); return(true); } } } resultingLine = new ShootLine(root, targ.Cell); return(false); }
private void SetScanLines() { scanLines.Clear(); foreach (IntVec3 c in GenAdj.OccupiedRect(Position, Rotation, def.size)) { scanLines.Add(new ScanLine(this, c)); } }