public static IntVec3 TryFindValidTargetCell(ShipBase ship, IntVec3 targetCell, Map map) { IntVec3 result; TraverseParms traverseParms = TraverseParms.For(TraverseMode.NoPassClosedDoors, Danger.Deadly, false); CellRect occupiedRect = GenAdj.OccupiedRect(targetCell, ship.Rotation, ship.def.Size); Predicate <IntVec3> baseValidator = (IntVec3 x) => x.Standable(map) && !(x.Roofed(map) && x.GetRoof(map).isThickRoof) && GenAdj.OccupiedRect(targetCell, ship.Rotation, ship.def.Size).InBounds(map); if (baseValidator(targetCell)) { return(targetCell); } if (RCellFinder.TryFindRandomCellNearWith(targetCell, baseValidator, map, out result)) { return(result); } Log.Warning("Could not find any valid cell."); return(CellFinder.RandomCell(map)); }
public override void Destroy(DestroyMode mode = DestroyMode.Vanish) { RemoveAllOwners(); foreach (IntVec3 c in GenAdj.CellsOccupiedBy(this)) { // Change the terrain here back to quarried stone, removing the walls Map.terrainGrid.SetTerrain(c, QuarryDefOf.QRY_QuarriedGround); } if (!QuarrySettings.letterSent && !TutorSystem.AdaptiveTrainingEnabled) { Find.LetterStack.ReceiveLetter(Static.LetterLabel, Static.LetterText, QuarryDefOf.CuproLetter, new RimWorld.Planet.GlobalTargetInfo(Position, Map)); QuarrySettings.letterSent = true; } if (TutorSystem.AdaptiveTrainingEnabled) { LessonAutoActivator.TeachOpportunity(QuarryDefOf.QRY_ReclaimingSoil, OpportunityType.GoodToKnow); } base.Destroy(mode); }
public override void PostSpawnSetup() { compPowerTrader = parent.TryGetComp <CompPowerTrader>(); lastTickStagger++; tickStagger = lastTickStagger; cellIndex = tickStagger; cells = GenAdj.CellsAdjacent8Way(parent).ToList(); while (cellIndex > cells.Count) { cellIndex -= cells.Count; } if (quantumWarehouse != null) { compWarehouse = quantumWarehouse.TryGetComp <CompRTQuantumWarehouse>(); } }
// ===================== Main function ===================== public override void Tick() { base.Tick(); this.ticksSinceTakeOff++; if (this.ticksSinceTakeOff <= verticalTrajectoryDurationInTicks) { MoteMaker.ThrowDustPuff(GenAdj.CellsAdjacentCardinal(this.landingPadPosition, this.landingPadRotation, Util_ThingDefOf.LandingPad.Size).RandomElement(), this.Map, 3f * (1f - (float)this.ticksSinceTakeOff / (float)verticalTrajectoryDurationInTicks)); } if (this.ticksSinceTakeOff == 1) { // Taking off sound. FlyingSpaceshipTakingOff.takingOffSound.PlayOneShot(new TargetInfo(this.Position, this.Map)); } if (this.ticksSinceTakeOff >= verticalTrajectoryDurationInTicks + horizontalTrajectoryDurationInTicks) { this.Destroy(); } }
private bool TrySpawnBatteryNear(IntVec3 position, Map map, Faction faction, out Building newBattery) { Predicate <IntVec3> extraValidator = null; if (this.spawnRoofOverNewBatteries) { extraValidator = delegate(IntVec3 x) { CellRect.CellRectIterator iterator = GenAdj.OccupiedRect(x, Rot4.North, ThingDefOf.Battery.size).ExpandedBy(3).GetIterator(); while (!iterator.Done()) { IntVec3 current = iterator.Current; if (current.InBounds(map)) { List <Thing> thingList = current.GetThingList(map); for (int i = 0; i < thingList.Count; i++) { if (thingList[i].def.PlaceWorkers != null) { if (thingList[i].def.PlaceWorkers.Any((PlaceWorker y) => y is PlaceWorker_NotUnderRoof)) { return(false); } } } } iterator.MoveNext(); } return(true); }; } if (this.TrySpawnPowerTransmittingBuildingNear(position, map, faction, ThingDefOf.Battery, out newBattery, extraValidator)) { float randomInRange = this.newBatteriesInitialStoredEnergyPctRange.RandomInRange; newBattery.GetComp <CompPowerBattery>().SetStoredEnergyPct(randomInRange); if (this.spawnRoofOverNewBatteries) { this.SpawnRoofOver(newBattery); } return(true); } return(false); }
private static IEnumerable <CompPower> ContiguousPowerBuildings(Building root) { closedSet.Clear(); openSet.Clear(); currentSet.Clear(); openSet.Add(root); do { foreach (Building item in openSet) { closedSet.Add(item); } HashSet <Building> hashSet = currentSet; currentSet = openSet; openSet = hashSet; openSet.Clear(); foreach (Building item2 in currentSet) { foreach (IntVec3 item3 in GenAdj.CellsAdjacentCardinal(item2)) { if (!item3.InBounds(item2.Map)) { continue; } List <Thing> thingList = item3.GetThingList(item2.Map); for (int i = 0; i < thingList.Count; i++) { Building building = thingList[i] as Building; if (building != null && building.TransmitsPowerNow && !openSet.Contains(building) && !currentSet.Contains(building) && !closedSet.Contains(building)) { openSet.Add(building); break; } } } } }while (openSet.Count > 0); CompPower[] result = closedSet.Select((Building b) => b.PowerComp).ToArray(); closedSet.Clear(); openSet.Clear(); currentSet.Clear(); return(result); }
//public static bool CanBuildOnTerrain(BuildableDef entDef, IntVec3 c, Map map, Rot4 rot, Thing thingToIgnore = null) public static bool Prefix(ref bool __result, BuildableDef entDef, IntVec3 c, Map map, Rot4 rot, Thing thingToIgnore = null) { CellRect cellRect = GenAdj.OccupiedRect(c, rot, entDef.Size); cellRect.ClipInsideMap(map); CellRect.CellRectIterator iterator = cellRect.GetIterator(); while (!iterator.Done()) { if (iterator.Current.SupportsStructureType(map, TerrainDefOf.Bridge.terrainAffordanceNeeded) && TerrainDefOf.Bridge.affordances.Contains(entDef.terrainAffordanceNeeded)) { __result = true; return(false); } iterator.MoveNext(); } return(true); }
public override void DesignateSingleCell(IntVec3 c) { if (TutorSystem.TutorialMode && !TutorSystem.AllowAction(new EventPack(base.TutorTagDesignate, c))) { return; } if (DebugSettings.godMode || this.entDef.GetStatValueAbstract(StatDefOf.WorkToBuild, this.stuffDef) == 0f) { if (this.entDef is TerrainDef) { base.Map.terrainGrid.SetTerrain(c, (TerrainDef)this.entDef); } else { Thing thing = ThingMaker.MakeThing((ThingDef)this.entDef, this.stuffDef); thing.SetFactionDirect(Faction.OfPlayer); GenSpawn.Spawn(thing, c, base.Map, this.placingRot, WipeMode.Vanish, false); } } else { GenSpawn.WipeExistingThings(c, this.placingRot, this.entDef.blueprintDef, base.Map, DestroyMode.Deconstruct); GenConstruct.PlaceBlueprintForBuild(this.entDef, c, base.Map, this.placingRot, Faction.OfPlayer, this.stuffDef); } MoteMaker.ThrowMetaPuffs(GenAdj.OccupiedRect(c, this.placingRot, this.entDef.Size), base.Map); ThingDef thingDef = this.entDef as ThingDef; if (thingDef != null && thingDef.IsOrbitalTradeBeacon) { PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.BuildOrbitalTradeBeacon, KnowledgeAmount.Total); } if (TutorSystem.TutorialMode) { TutorSystem.Notify_Event(new EventPack(base.TutorTagDesignate, c)); } if (this.entDef.PlaceWorkers != null) { for (int i = 0; i < this.entDef.PlaceWorkers.Count; i++) { this.entDef.PlaceWorkers[i].PostPlace(base.Map, this.entDef, c, this.placingRot); } } }
private static IEnumerable <CompPipe> ContiguousPowerBuildings(Building root) { closedSet.Clear(); openSet.Clear(); currentSet.Clear(); openSet.Add(root); do { foreach (Building item in openSet) { closedSet.Add(item); } HashSet <Building> hashSet = currentSet; currentSet = openSet; openSet = hashSet; openSet.Clear(); foreach (Building building in currentSet) { foreach (IntVec3 c in GenAdj.CellsAdjacentCardinal(building)) { if (c.InBounds(building.Map)) { List <Thing> thingList = c.GetThingList(building.Map); for (int i = 0; i < thingList.Count; i++) { Building building2 = thingList[i] as Building; if (building2 != null && !PipeNetMaker.openSet.Contains(building2) && !PipeNetMaker.currentSet.Contains(building2) && !PipeNetMaker.closedSet.Contains(building2)) { PipeNetMaker.openSet.Add(building2); break; } } } } } }while (openSet.Count > 0); CompPipe[] result = (from b in closedSet select b.GetComp <CompPipe>()).ToArray <CompPipe>(); closedSet.Clear(); openSet.Clear(); currentSet.Clear(); return(result); }
// Token: 0x06000027 RID: 39 RVA: 0x00002FDC File Offset: 0x000011DC public void damageBuildings(int amt) { IntVec3 intVec = GenAdj.RandomAdjacentCell8Way(this); bool flag = GenGrid.InBounds(intVec, base.Map); bool flag2 = flag; if (flag2) { Building firstBuilding = GridsUtility.GetFirstBuilding(intVec, base.Map); DamageInfo damageInfo; damageInfo = new DamageInfo(DamageDefOf.Burn, (float)amt, 0f, -1f, null, null, null, 0, null); bool flag3 = firstBuilding != null; bool flag4 = flag3; if (flag4) { firstBuilding.TakeDamage(damageInfo); } } }
public override void CompTick() { this.tickProgress += 1; if (this.tickProgress > Props.ticksConversionRate) { Pawn pawn = this.parent as Pawn; if ((!pawn.Downed) && (pawn.Map != null)) { CellRect rect = GenAdj.OccupiedRect(pawn.Position, pawn.Rotation, IntVec2.One); rect = rect.ExpandedBy(2); foreach (IntVec3 current in rect.Cells) { if (current.InBounds(pawn.Map)) { HashSet <Thing> hashSet = new HashSet <Thing>(current.GetThingList(pawn.Map)); if (hashSet != null) { Thing current2 = hashSet.FirstOrFallback(); if (current2 != null) { if (current2.def.defName == Props.thingToAffect) { Thing thing = GenSpawn.Spawn(ThingDef.Named(Props.thingToTurnTo), current, pawn.Map, WipeMode.Vanish); current2.Destroy(); break; } else if (current2.def.defName == Props.secondaryThingToAffect) { Thing thing = GenSpawn.Spawn(ThingDef.Named(Props.thingToTurnTo), current, pawn.Map, WipeMode.Vanish); current2.Destroy(); break; } } } } } } // FilthMaker.MakeFilth(this.parent.PositionHeld, this.parent.MapHeld, ThingDef.Named("GR_FilthMucus"), 1); this.tickProgress = 0; } }
public static void CheckSpawnBridgeUnder(ThingDef thingDef, IntVec3 c, Rot4 rot) { if (thingDef.category != ThingCategory.Building) { return; } Map map = BaseGen.globalSettings.map; CellRect cellRect = GenAdj.OccupiedRect(c, rot, thingDef.size); BaseGenUtility.bridgeCells.Clear(); CellRect.CellRectIterator iterator = cellRect.GetIterator(); while (!iterator.Done()) { if (!iterator.Current.SupportsStructureType(map, thingDef.terrainAffordanceNeeded) && GenConstruct.CanBuildOnTerrain(TerrainDefOf.Bridge, iterator.Current, map, Rot4.North, null)) { BaseGenUtility.bridgeCells.Add(iterator.Current); } iterator.MoveNext(); } if (!BaseGenUtility.bridgeCells.Any <IntVec3>()) { return; } if (thingDef.size.x != 1 || thingDef.size.z != 1) { for (int i = BaseGenUtility.bridgeCells.Count - 1; i >= 0; i--) { for (int j = 0; j < 8; j++) { IntVec3 intVec = BaseGenUtility.bridgeCells[i] + GenAdj.AdjacentCells[j]; if (!BaseGenUtility.bridgeCells.Contains(intVec) && intVec.InBounds(map) && !intVec.SupportsStructureType(map, thingDef.terrainAffordanceNeeded) && GenConstruct.CanBuildOnTerrain(TerrainDefOf.Bridge, intVec, map, Rot4.North, null)) { BaseGenUtility.bridgeCells.Add(intVec); } } } } for (int k = 0; k < BaseGenUtility.bridgeCells.Count; k++) { map.terrainGrid.SetTerrain(BaseGenUtility.bridgeCells[k], TerrainDefOf.Bridge); } }
private static bool MakeFilth(IntVec3 c, Map map, ThingDef filthDef, IEnumerable <string> sources, bool shouldPropagate) { Filth filth = (Filth)(from t in c.GetThingList(map) where t.def == filthDef select t).FirstOrDefault <Thing>(); if (!c.Walkable(map) || (filth != null && !filth.CanBeThickened)) { if (shouldPropagate) { List <IntVec3> list = GenAdj.AdjacentCells8WayRandomized(); for (int i = 0; i < 8; i++) { IntVec3 c2 = c + list[i]; if (c2.InBounds(map)) { if (FilthMaker.MakeFilth(c2, map, filthDef, sources, false)) { return(true); } } } } if (filth != null) { filth.AddSources(sources); } return(false); } if (filth != null) { filth.ThickenFilth(); filth.AddSources(sources); } else { Filth filth2 = (Filth)ThingMaker.MakeThing(filthDef, null); filth2.AddSources(sources); GenSpawn.Spawn(filth2, c, map); } return(true); }
public override AcceptanceReport AllowsPlacing(BuildableDef checkingDef, IntVec3 loc, Rot4 rot, Map map, Thing thingToIgnore = null, Thing thing = null) { /* * 맵 이내여야함 * 조리대 위치쪽도 맵이내여야함 * */ //GenThing.TrueCenter(loc, rot, checkingDef.Size, checkingDef.Altitude) AcceptanceReport result = false; CellRect cellRect = GenAdj.OccupiedRect(loc, rot, checkingDef.Size); bool needWallFlag = false; bool isInBound = true; foreach (IntVec3 c in cellRect) { IntVec3 addonTarget = c - rot.FacingCell; if (!GenGrid.Impassable(c, map)) { result = Translator.Translate("WallAttachment_WarningNeedWall"); needWallFlag = true; } if (!c.InBounds(map) || !addonTarget.InBounds(map)) { result = "OutOfBounds".Translate(); isInBound = false; } if ((c.InNoBuildEdgeArea(map) || addonTarget.InNoBuildEdgeArea(map)) && !DebugSettings.godMode) { result = "TooCloseToMapEdge".Translate(); isInBound = false; } } if (!needWallFlag && isInBound) { result = true; } return(result); }
private static IEnumerable <CompPower> ContiguousPowerBuildings(Building root) { PowerNetMaker.closedSet.Clear(); PowerNetMaker.currentSet.Clear(); PowerNetMaker.openSet.Add(root); while (true) { foreach (Building item in PowerNetMaker.openSet) { PowerNetMaker.closedSet.Add(item); } HashSet <Building> hashSet = PowerNetMaker.currentSet; PowerNetMaker.currentSet = PowerNetMaker.openSet; PowerNetMaker.openSet = hashSet; PowerNetMaker.openSet.Clear(); foreach (Building item2 in PowerNetMaker.currentSet) { foreach (IntVec3 item3 in GenAdj.CellsAdjacentCardinal(item2)) { if (item3.InBounds(item2.Map)) { List <Thing> thingList = item3.GetThingList(item2.Map); for (int i = 0; i < thingList.Count; i++) { Building building = thingList[i] as Building; if (building != null && building.TransmitsPowerNow && !PowerNetMaker.openSet.Contains(building) && !PowerNetMaker.currentSet.Contains(building) && !PowerNetMaker.closedSet.Contains(building)) { PowerNetMaker.openSet.Add(building); break; } } } } } if (PowerNetMaker.openSet.Count <= 0) { break; } } return(from b in PowerNetMaker.closedSet select b.PowerComp); }
public override AcceptanceReport AllowsPlacing( BuildableDef checkingDef, IntVec3 loc, Rot4 rot, Map map, Thing thingToIgnore = null ) { var overlapsWithSomething = GenAdj.CellsAdjacent8Way(loc, rot, checkingDef.Size). Union(GenAdj.CellsOccupiedBy(loc, rot, checkingDef.Size)). SelectMany(cell => map.thingGrid.ThingsListAt(cell)). Any(thing => { if ( thing.TryGetComp <CompQSRStockpile>() != null || thing.TryGetComp <CompQSRWarehouse>() != null || thing.TryGetComp <CompQSRRelay>() != null ) { return(true); } if ( thing.def.entityDefToBuild != null && thing.def.entityDefToBuild is ThingDef thingDef && thingDef.comps != null && thingDef.comps.Any(comp => Utils.QuantumCompClasses.Contains(comp.compClass)) ) { return(true); } return(false); }); if (overlapsWithSomething) { return("PlaceWorker_QSRNoQSOverlap".Translate()); } return(true); }
// Token: 0x0600001B RID: 27 RVA: 0x000027AC File Offset: 0x000009AC public bool BestClosestPowerSource(Pawn pawn, Thing thing) { CompPower compPower; bool flag = thing.Faction == pawn.Faction && (compPower = thing.TryGetComp <CompPower>()) != null && compPower.PowerNet != null && compPower.PowerNet.CurrentStoredEnergy() > 50f && !thing.IsForbidden(pawn) && pawn.CanReserve(new LocalTargetInfo(thing), 1, -1, null, false) && thing.Position.InAllowedArea(pawn) && pawn.CanReach(new LocalTargetInfo(thing), PathEndMode.OnCell, Danger.Deadly, false, TraverseMode.ByPawn); bool flag2 = !flag; bool result; if (flag2) { result = false; } else { Building t = thing as Building; IntVec3 position = thing.Position; bool flag3 = position.Walkable(pawn.Map) && position.InAllowedArea(pawn) && pawn.CanReserve(new LocalTargetInfo(position), 1, -1, null, false) && pawn.CanReach(position, PathEndMode.OnCell, Danger.Deadly, false, TraverseMode.ByPawn); if (flag3) { result = true; } else { IEnumerable <IntVec3> source = GenAdj.CellsAdjacentCardinal(t); Func <IntVec3, float> < > 9__0; Func <IntVec3, float> keySelector; if ((keySelector = < > 9__0) == null) { keySelector = (< > 9__0 = ((IntVec3 selector) => selector.DistanceTo(pawn.Position))); } foreach (IntVec3 intVec in source.OrderByDescending(keySelector)) { bool flag4 = intVec.Walkable(pawn.Map) && intVec.InAllowedArea(pawn) && pawn.CanReserve(new LocalTargetInfo(intVec), 1, -1, null, false) && pawn.CanReach(intVec, PathEndMode.ClosestTouch, Danger.Deadly, false, TraverseMode.ByPawn); if (flag4) { return(true); } } result = false; } } return(result); }
private void DrawDebugPowerNets() { if (Current.ProgramState != ProgramState.Playing || Find.CurrentMap != map) { return; } int num = 0; foreach (PowerNet allNet in allNets) { foreach (CompPower item in allNet.transmitters.Concat(allNet.connectors)) { foreach (IntVec3 item2 in GenAdj.CellsOccupiedBy(item.parent)) { CellRenderer.RenderCell(item2, (float)num * 0.44f); } } num++; } }
// Token: 0x0600001D RID: 29 RVA: 0x00002B28 File Offset: 0x00000D28 public void damageBuildings(int amt) { IntVec3 intVec = GenAdj.RandomAdjacentCell8Way(this); bool flag = GenGrid.InBounds(intVec, base.Map); bool flag2 = flag; if (flag2) { Building firstBuilding = GridsUtility.GetFirstBuilding(intVec, base.Map); DamageInfo damageInfo; damageInfo = new DamageInfo(XenomorphDefOf.RRY_AcidBurn, (float)amt, 0f, -1f, null, null, null, 0, null); bool flag3 = firstBuilding != null; bool flag4 = flag3; if (flag4) { MoteMaker.ThrowDustPuff(firstBuilding.Position, base.Map, 0.2f); firstBuilding.TakeDamage(damageInfo); } } }
public override AcceptanceReport AllowsPlacing(BuildableDef def, IntVec3 center, Rot4 rot, Map map, Thing thingToIgnore = null, Thing thing = null) { foreach (IntVec3 c in GenAdj.OccupiedRect(center, rot, def.Size).ExpandedBy(1)) { List <Thing> list = map.thingGrid.ThingsListAt(c); for (int i = 0; i < list.Count; i++) { Thing thing2 = list[i]; if (thing2 != thingToIgnore && ((thing2.def.category == ThingCategory.Building && thing2.def.defName == "VFEV_Apiary") || ((thing2.def.IsBlueprint || thing2.def.IsFrame) && thing2.def.entityDefToBuild is ThingDef && ((ThingDef)thing2.def.entityDefToBuild).defName == "VFEV_Apiary"))) { return("APlaceWorker".Translate()); } } } if (center.Roofed(map)) { return("APlaceWorkerNoRoof".Translate()); } return(true); }
public bool IsValidPositionForShipCrashSite(IntVec3 position) { ThingDef chunkDef = ThingDefOf.ShipChunk; if ((position.InBounds() == false) || position.Fogged()) { return(false); } foreach (IntVec3 chckedPosition in GenAdj.CellsOccupiedBy(position, Rot4.North, this.def.shipPart.size)) { if ((chckedPosition.Standable() == false) || chckedPosition.Roofed() || chckedPosition.CanReachColony() == false) { return(false); } } return(true); }
private void DrawDebugPowerNets() { if (Current.ProgramState != ProgramState.Playing) { return; } int num = 0; foreach (ShieldNet current in this.allNets) { foreach (CompShield current2 in current.transmitters.Concat(current.connectors)) { foreach (IntVec3 current3 in GenAdj.CellsOccupiedBy(current2.parent)) { CellRenderer.RenderCell(current3, (float)num * 0.44f); } } num++; } }
public static bool WipeExistingThings(IntVec3 thingPos, Rot4 thingRot, BuildableDef thingDef, Map map, DestroyMode mode) { if (thingDef?.Size != null) { foreach (IntVec3 c in GenAdj.CellsOccupiedBy(thingPos, thingRot, thingDef.Size)) { foreach (Thing thing in map.thingGrid.ThingsAt(c).ToList <Thing>()) { if (thing?.def?.destroyable != null) { if (GenSpawn.SpawningWipes(thingDef, thing.def)) { thing.Destroy(mode); } } } } } return(false); }
public Thing GetSameSpawned(IntVec3 at, Map map) { if (!at.InBounds(map)) { return(null); } List <Thing> thingList = at.GetThingList(map); for (int i = 0; i < thingList.Count; i++) { CellRect lhs = GenAdj.OccupiedRect(at, rot, thingList[i].def.Size); CellRect lhs2 = GenAdj.OccupiedRect(at, rot.Opposite, thingList[i].def.Size); CellRect rhs = thingList[i].OccupiedRect(); if ((lhs == rhs || lhs2 == rhs) && thingList[i].def == def && (stuff == null || thingList[i].Stuff == stuff) && (thingList[i].Rotation == rot || thingList[i].Rotation == rot.Opposite || !def.rotatable)) { return(thingList[i]); } } return(null); }
public override Thing GetSpawnedBlueprintOrFrame(IntVec3 at, Map map) { if (!at.InBounds(map)) { return(null); } List <Thing> thingList = at.GetThingList(map); for (int i = 0; i < thingList.Count; i++) { CellRect lhs = GenAdj.OccupiedRect(at, rot, thingList[i].def.Size); CellRect lhs2 = GenAdj.OccupiedRect(at, rot.Opposite, thingList[i].def.Size); CellRect rhs = thingList[i].OccupiedRect(); if ((lhs == rhs || lhs2 == rhs) && thingList[i].def.entityDefToBuild == def && (stuff == null || ((IConstructible)thingList[i]).EntityToBuildStuff() == stuff) && (thingList[i].Rotation == rot || thingList[i].Rotation == rot.Opposite || !def.rotatable)) { return(thingList[i]); } } return(null); }
public override void PostSpawnSetup() { base.PostSpawnSetup(); lastTickStagger++; tickStagger = lastTickStagger; compFlickable = parent.TryGetComp <CompFlickable>(); if (compFlickable == null) { Log.Error("CompRTPowerSwitch could not get parent's CompFlickable!"); } cellIndex = tickStagger; cells = GenAdj.CellsAdjacentCardinal(parent).ToList(); while (cellIndex > cells.Count) { cellIndex -= cells.Count; } }
public override void Print(SectionLayer layer, Thing thing) { base.Print(layer, thing); // also print on cardinal neighbours if that neighbour transmits gas but is not linked itself // this draws 'connections' underneath gas users. foreach (var cell in GenAdj.CellsAdjacentCardinal(thing) .Where(c => GenGrid.InBounds((IntVec3)c, thing.Map))) { var neighbour = cell.GetThingList(thing.Map) .FirstOrDefault(t => t.TryGetComp <CompGas>(out _) && !t.def.graphicData.Linked); if (neighbour != null) { var mat = LinkedDrawMatFrom(thing, cell); Printer_Plane.PrintPlane(layer, cell.ToVector3ShiftedWithAltitude(thing.def.Altitude), Vector2.one, mat); } } }
public static void DrawBridgeCost(Designator_Build designator, Vector2 drawPos, float curY, ThingDef stuff) { DesignationDragger dragger = Find.DesignatorManager.Dragger; int bridgeCount = 0; IEnumerable <IntVec3> cells = dragger.Dragging ? dragger.DragCells : GenAdj.OccupiedRect(UI.MouseCell(), designator.PlacingRot(), designator.PlacingDef.Size).Cells; foreach (IntVec3 dragPos in cells) { if (PlaceBridges.NeedsBridge(designator.PlacingDef, dragPos, designator.Map, stuff)) { bridgeCount++; } } if (bridgeCount == 0) { return; } //could just say wood here, this is still assuming it costs only one thing. ThingDefCountClass bridgeCost = TerrainDefOf.Bridge.costList.First(); Widgets.ThingIcon(new Rect(drawPos.x, drawPos.y + curY, 27f, 27f), bridgeCost.thingDef); int totalCost = bridgeCost.count * bridgeCount; string label = $"{totalCost} ({TerrainDefOf.Bridge.LabelCap})"; //This doesn't account for normal building cost + under bridge cost, but what can you do if (designator.Map.resourceCounter.GetCount(bridgeCost.thingDef) < totalCost) { GUI.color = Color.red; label = label + " (" + "NotEnoughStoredLower".Translate() + ")"; } Text.Font = GameFont.Small; Text.Anchor = TextAnchor.MiddleLeft; Widgets.Label(new Rect(drawPos.x + 29f, drawPos.y + curY, 999f, 29f), label); Text.Anchor = TextAnchor.UpperLeft; GUI.color = Color.white; }
public override void Resolve(ResolveParams rp) { ThingDef thingDef; if ((thingDef = rp.singleThingDef) == null) { thingDef = (from x in ThingSetMakerUtility.allGeneratableItems where x.IsWeapon || x.IsMedicine || x.IsDrug select x).RandomElement <ThingDef>(); } ThingDef thingDef2 = thingDef; Rot4? thingRot = rp.thingRot; Rot4 rot = (thingRot == null) ? Rot4.North : thingRot.Value; IntVec3 zero = IntVec3.Zero; IntVec2 size = thingDef2.size; int? fillWithThingsPadding = rp.fillWithThingsPadding; int num = (fillWithThingsPadding == null) ? 0 : fillWithThingsPadding.Value; if (num < 0) { num = 0; } GenAdj.AdjustForRotation(ref zero, ref size, rot); if (size.x <= 0 || size.z <= 0) { Log.Error("Thing has 0 size.", false); return; } for (int i = rp.rect.minX; i <= rp.rect.maxX - size.x + 1; i += size.x + num) { for (int j = rp.rect.minZ; j <= rp.rect.maxZ - size.z + 1; j += size.z + num) { ResolveParams resolveParams = rp; resolveParams.rect = new CellRect(i, j, size.x, size.z); resolveParams.singleThingDef = thingDef2; resolveParams.thingRot = new Rot4?(rot); BaseGen.symbolStack.Push("thing", resolveParams); } } BaseGen.symbolStack.Push("clear", rp); }
private void PodImpact() { for (int i = 0; i < 6; i++) { Vector3 spawnLoc = base.Position.ToVector3Shifted() + Gen.RandomHorizontalVector(1f); MoteMaker.ThrowDustPuff(spawnLoc, this.Map, 1.2f); } MoteMaker.ThrowLightningGlow(base.Position.ToVector3Shifted(), this.Map, 2f); MoteMaker.ThrowSmoke(base.Position.ToVector3Shifted(), this.Map, 1f); MeteorIncoming.ExplodeSound.PlayOneShot(new TargetInfo(base.Position, base.Map, false)); foreach (IntVec3 current in GenAdj.CellsAdjacent8Way(this)) { MoteMaker.ThrowAirPuffUp(base.Position.ToVector3Shifted(), this.Map); } GenSpawn.Spawn(this.contents.SingleContainedThing, base.Position, this.Map, base.Rotation); if (this.contents.SingleContainedThing is AlienQueen queen) { queen.health.AddHediff(PurpleIvyDefOf.PI_CrashlandedDowned); queen.health.AddHediff(PurpleIvyDefOf.PI_Regen); queen.recoveryTick = Find.TickManager.TicksGame + new IntRange(80000, 140000).RandomInRange; queen.canGuard = true; } else if (this.contents.SingleContainedThing is Building_Meteorite meteorite) { foreach (var dir in GenRadial.RadialCellsAround(meteorite.Position, 5, true)) { if (GenGrid.InBounds(dir, meteorite.Map)) { Thing thing = ThingMaker.MakeThing(PurpleIvyDefOf.PI_Spores, null); GenSpawn.Spawn(thing, dir, meteorite.Map, 0); var Spores = (PurpleGas)thing; Spores.destroyTick = Find.TickManager.TicksGame + new IntRange(160000, 180000).RandomInRange; Spores.activeDamage = true; meteorite.spores.Add(Spores); } } } GenExplosion.DoExplosion(base.Position, this.Map, 5f, DamageDefOf.Bomb, this); this.Destroy(DestroyMode.Vanish); }