public static void GenerateLandingPadNearby(CellRect rect, Map map, Faction faction, out CellRect usedRect) { ResolveParams resolveParams = default(ResolveParams); MapGenerator.TryGetVar <List <CellRect> >("UsedRects", out var usedRects); tmpCandidates.Clear(); int size = 9; tmpCandidates.Add(new IntVec3(rect.maxX + 1, 0, rect.CenterCell.z)); tmpCandidates.Add(new IntVec3(rect.minX - size, 0, rect.CenterCell.z)); tmpCandidates.Add(new IntVec3(rect.CenterCell.x, 0, rect.maxZ + 1)); tmpCandidates.Add(new IntVec3(rect.CenterCell.x, 0, rect.minZ - size)); if (!tmpCandidates.Where(delegate(IntVec3 x) { CellRect r = new CellRect(x.x, x.z, size, size); return(r.InBounds(map) && (usedRects == null || !usedRects.Any((CellRect y) => y.Overlaps(r)))); }).TryRandomElement(out var result)) { usedRect = CellRect.Empty; return; } resolveParams.rect = new CellRect(result.x, result.z, size, size); resolveParams.faction = faction; RimWorld.BaseGen.BaseGen.globalSettings.map = map; RimWorld.BaseGen.BaseGen.symbolStack.Push("landingPad", resolveParams); RimWorld.BaseGen.BaseGen.Generate(); usedRect = resolveParams.rect; }
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 AcceptanceReport AllowsPlacing(BuildableDef checkingDef, IntVec3 loc, Rot4 rot, Map map, Thing thingToIgnore = null, Thing thing = null) { if (thing is NCS_Tent tent) { bool existingFloor = tent.CanSafelySpawnFloor(loc, map); foreach (SketchEntity entity in tent.sketch.Entities) { CellRect cellRect = entity.OccupiedRect.MovedBy(loc); if (!cellRect.InBounds(map)) { return((AcceptanceReport)false); } if (cellRect.InNoBuildEdgeArea(map)) { return((AcceptanceReport)"TooCloseToMapEdge".Translate()); } if (!entity.CanBuildOnTerrain(entity.pos + loc, map) && !(entity is SketchTerrain && existingFloor)) // ignore floors if they're going to get skipped on spawn { if (entity is SketchBuildable sb) { return((AcceptanceReport)"TerrainCannotSupport_TerrainAffordance".Translate(sb.Buildable, sb.Buildable.GetTerrainAffordanceNeed(sb.Stuff))); } return((AcceptanceReport)"TerrainCannotSupport".Translate(tent)); } } } return((AcceptanceReport)true); }
public static void DoMapSpawns(Map map) { int spawnCounter = 0; foreach (ObjectSpawnsDef element in DefDatabase <ObjectSpawnsDef> .AllDefs.Where(element => element.allowedBiomes.Contains(map.Biome))) { if (element.spawnOnlyInPlayerMaps && !map.IsPlayerHome) { continue; } IEnumerable <IntVec3> tmpTerrain = map.AllCells.InRandomOrder(); if (spawnCounter == 0) { spawnCounter = element.numberToSpawn.RandomInRange; } foreach (IntVec3 c in tmpTerrain) { bool canSpawn = CanSpawnAt(c, map, element); if (canSpawn) { Thing thing = (Thing)ThingMaker.MakeThing(element.thingDef, null); CellRect occupiedRect = GenAdj.OccupiedRect(c, thing.Rotation, thing.def.Size); if (occupiedRect.InBounds(map)) { canSpawn = true; foreach (IntVec3 c2 in occupiedRect) { if (!CanSpawnAt(c2, map, element)) { canSpawn = false; break; } } if (canSpawn) { if (element.randomRotation) { GenPlace.TryPlaceThing(thing, c, map, ThingPlaceMode.Direct, null, null, Rot4.Random); } else { GenSpawn.Spawn(thing, c, map); } spawnCounter--; } } } if (canSpawn && spawnCounter <= 0) { spawnCounter = 0; break; } } } }
public void DoMapSpawns() { foreach (ObjectSpawnsDef element in DefDatabase <ObjectSpawnsDef> .AllDefs.Where(element => element.allowedBiome == map.Biome.defName)) { IEnumerable <IntVec3> tmpTerrain = map.AllCells.InRandomOrder(); int extraGeneration = 0; foreach (string biome in element.biomesWithExtraGeneration) { if (map.Biome.defName == biome) { extraGeneration = element.extraGeneration; } } if (spawnCounter == 0) { spawnCounter = Rand.RangeInclusive(element.numberToSpawn.min, element.numberToSpawn.max) + extraGeneration; } foreach (IntVec3 c in tmpTerrain) { bool canSpawn = CanSpawnAt(c, element); if (canSpawn) { Thing thing = (Thing)ThingMaker.MakeThing(element.thingDef, null); CellRect occupiedRect = GenAdj.OccupiedRect(c, thing.Rotation, thing.def.Size); if (occupiedRect.InBounds(map)) { canSpawn = true; foreach (IntVec3 c2 in occupiedRect) { if (!CanSpawnAt(c2, element)) { canSpawn = false; break; } } if (canSpawn) { GenSpawn.Spawn(thing, c, map); spawnCounter--; } } } if (canSpawn && spawnCounter <= 0) { spawnCounter = 0; break; } } } this.verifyFirstTime = false; }
public static IEnumerable <IntVec3> GetRandomCellSampleAround(Thing t, int numberOfSamples, int distance) { IntVec3 center = t.Position; CellRect area = new CellRect(center.x - distance, center.z - distance, distance * 2, distance * 2); if (!area.InBounds(t.Map)) { area = area.ClipInsideMap(t.Map); } for (int i = 0; i < numberOfSamples; i++) { yield return(area.RandomCell); } }
public override AcceptanceReport AllowsPlacing(BuildableDef checkingDef, IntVec3 loc, Rot4 rot, Map map, Thing thingToIgnore = null, Thing thing = null) { MonumentMarker monumentMarker = thing as MonumentMarker; if (monumentMarker != null) { CellRect rect = monumentMarker.sketch.OccupiedRect.MovedBy(loc); Blueprint_Install thingToIgnore2 = monumentMarker.FindMyBlueprint(rect, map); foreach (SketchEntity entity in monumentMarker.sketch.Entities) { CellRect cellRect = entity.OccupiedRect.MovedBy(loc); if (!cellRect.InBounds(map)) { return(false); } if (cellRect.InNoBuildEdgeArea(map)) { return("TooCloseToMapEdge".Translate()); } foreach (IntVec3 item in cellRect) { if (!entity.CanBuildOnTerrain(item, map)) { TerrainDef terrain = item.GetTerrain(map); return("CannotPlaceMonumentOnTerrain".Translate(terrain.LabelCap)); } } } tmpMonumentThings.Clear(); foreach (SketchBuildable buildable in monumentMarker.sketch.Buildables) { Thing spawnedBlueprintOrFrame = buildable.GetSpawnedBlueprintOrFrame(loc + buildable.pos, map); SketchThing sketchThing; if (spawnedBlueprintOrFrame != null) { tmpMonumentThings.Add(spawnedBlueprintOrFrame); } else if ((sketchThing = buildable as SketchThing) != null) { Thing sameSpawned = sketchThing.GetSameSpawned(loc + sketchThing.pos, map); if (sameSpawned != null) { tmpMonumentThings.Add(sameSpawned); } } } foreach (SketchEntity entity2 in monumentMarker.sketch.Entities) { if (entity2.IsSameSpawnedOrBlueprintOrFrame(loc + entity2.pos, map)) { continue; } foreach (IntVec3 item2 in entity2.OccupiedRect.MovedBy(loc)) { if (item2.InBounds(map)) { Building firstBuilding = item2.GetFirstBuilding(map); if (firstBuilding != null && !tmpMonumentThings.Contains(firstBuilding)) { tmpMonumentThings.Clear(); return("CannotPlaceMonumentOver".Translate(firstBuilding.LabelCap)); } } } SketchBuildable sketchBuildable; if ((sketchBuildable = entity2 as SketchBuildable) != null) { Thing thing2 = sketchBuildable.FirstPermanentBlockerAt(loc + entity2.pos, map); if (thing2 != null && !tmpMonumentThings.Contains(thing2)) { tmpMonumentThings.Clear(); return("CannotPlaceMonumentOver".Translate(thing2.LabelCap)); } } } foreach (SketchEntity entity3 in monumentMarker.sketch.Entities) { Building firstAdjacentBuilding = MonumentMarkerUtility.GetFirstAdjacentBuilding(entity3, loc, tmpMonumentThings, map); if (firstAdjacentBuilding != null) { return("MonumentAdjacentToBuilding".Translate(firstAdjacentBuilding.LabelCap)); } if (entity3.IsSpawningBlockedPermanently(loc + entity3.pos, map, thingToIgnore2)) { tmpMonumentThings.Clear(); return("MonumentBlockedPermanently".Translate()); } } tmpMonumentThings.Clear(); } return(true); }
public void doMapSpawns() { if (map.Biome.defName.Contains("MA_")) { foreach (MechanoidAssimilationSpawnsDef element in DefDatabase <MechanoidAssimilationSpawnsDef> .AllDefs.Where(element => element.allowedBiome == map.Biome.defName)) { IEnumerable <IntVec3> tmpTerrain = map.AllCells.InRandomOrder(); int extraGeneration = 0; foreach (string biome in element.biomesWithExtraGeneration) { if (map.Biome.defName == biome) { extraGeneration = element.extraGeneration; } } bool canSpawn = true; if (spawnCounter == 0) { spawnCounter = Rand.RangeInclusive(element.numberToSpawn.min, element.numberToSpawn.max) + extraGeneration; //Log.Message(spawnCounter.ToString()); } foreach (IntVec3 c in tmpTerrain) { TerrainDef terrain = c.GetTerrain(map); bool flagAllowed = true; foreach (string allowed in element.terrainValidationAllowed) { if (terrain.defName == allowed) { break; } else { flagAllowed = false; } } bool flagDisallowed = true; foreach (string notAllowed in element.terrainValidationDisallowed) { if (terrain.HasTag(notAllowed)) { flagDisallowed = false; break; } } bool flagWater = true; if (!element.allowOnWater && terrain.IsWater) { flagWater = false; } bool flagCenter = true; if (element.findCellsOutsideColony) { if (!OutOfCenter(c, map, 60)) { flagCenter = false; } } canSpawn = flagAllowed & flagDisallowed & flagWater & flagCenter; if (canSpawn) { // Log.Message("Sucesful c was " + c.ToString()); Thing thing = (Thing)ThingMaker.MakeThing(element.thingDef, null); CellRect occupiedRect = GenAdj.OccupiedRect(c, thing.Rotation, thing.def.Size); if (occupiedRect.InBounds(map)) { // Log.Message("Prior to " + element.defName + " .Spawncounter was " + spawnCounter); GenSpawn.Spawn(thing, c, map); spawnCounter--; // Log.Message("Spawning " + element.defName + " .Spawncounter was " + spawnCounter); } } if (canSpawn && spawnCounter <= 0) { //Log.Message("Spawn counter is " + spawnCounter + " So I'm getting out"); spawnCounter = 0; break; } } } } this.verifyFirstTime = false; }
public void doMapSpawns() { IEnumerable <IntVec3> tmpTerrain = map.AllCells.InRandomOrder(); foreach (SpecialPowerSpawnsDef element in DefDatabase <SpecialPowerSpawnsDef> .AllDefs.Where(element => element.disallowedBiome != map.Biome.defName)) { int extraGeneration = 0; foreach (string biome in element.biomesWithExtraGeneration) { if (map.Biome.defName == biome) { extraGeneration = element.extraGeneration; } } bool canSpawn = true; if (spawnCounter == 0) { spawnCounter = Rand.RangeInclusive(element.numberToSpawn.min, element.numberToSpawn.max) + extraGeneration; //Log.Message(spawnCounter.ToString()); } foreach (IntVec3 c in tmpTerrain) { if (!c.CloseToEdge(map, 15)) { TerrainDef terrain = c.GetTerrain(map); foreach (string allowed in element.terrainValidationAllowed) { if (terrain.defName == allowed) { canSpawn = true; break; } canSpawn = false; } foreach (string notAllowed in element.terrainValidationDisallowed) { if (terrain.defName == notAllowed) { canSpawn = false; break; } } if (canSpawn) { Thing thing = (Thing)ThingMaker.MakeThing(element.thingDef, null); CellRect occupiedRect = GenAdj.OccupiedRect(c, thing.Rotation, thing.def.Size); if (occupiedRect.InBounds(map)) { GenSpawn.Spawn(thing, c, map); spawnCounter--; } } if (canSpawn && spawnCounter <= 0) { spawnCounter = 0; break; } } } } this.verifyFirstTime = false; }
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); } if (null != newThing) { 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); }
public override AcceptanceReport AllowsPlacing(BuildableDef checkingDef, IntVec3 loc, Rot4 rot, Map map, Thing thingToIgnore = null, Thing thing = null) { MonumentMarker monumentMarker = thing as MonumentMarker; if (monumentMarker != null) { CellRect rect = monumentMarker.sketch.OccupiedRect.MovedBy(loc); Blueprint_Install thingToIgnore2 = monumentMarker.FindMyBlueprint(rect, map); foreach (SketchEntity entity in monumentMarker.sketch.Entities) { CellRect cellRect = entity.OccupiedRect.MovedBy(loc); if (!cellRect.InBounds(map)) { return(false); } if (cellRect.InNoBuildEdgeArea(map)) { return("TooCloseToMapEdge".Translate()); } foreach (IntVec3 item in cellRect) { if (!entity.CanBuildOnTerrain(item, map)) { return("MonumentBadTerrain".Translate()); } } if (entity.IsSpawningBlockedPermanently(loc + entity.pos, map, thingToIgnore2)) { return("MonumentBlockedPermanently".Translate()); } } tmpMonumentThings.Clear(); foreach (SketchBuildable buildable in monumentMarker.sketch.Buildables) { Thing spawnedBlueprintOrFrame = buildable.GetSpawnedBlueprintOrFrame(loc + buildable.pos, map); SketchThing sketchThing; if (spawnedBlueprintOrFrame != null) { tmpMonumentThings.Add(spawnedBlueprintOrFrame); } else if ((sketchThing = (buildable as SketchThing)) != null) { Thing sameSpawned = sketchThing.GetSameSpawned(loc + sketchThing.pos, map); if (sameSpawned != null) { tmpMonumentThings.Add(sameSpawned); } } } foreach (SketchEntity entity2 in monumentMarker.sketch.Entities) { if (!entity2.IsSameSpawnedOrBlueprintOrFrame(loc + entity2.pos, map)) { foreach (IntVec3 item2 in entity2.OccupiedRect.MovedBy(loc)) { if (item2.InBounds(map)) { Building firstBuilding = item2.GetFirstBuilding(map); if (firstBuilding != null && !tmpMonumentThings.Contains(firstBuilding)) { tmpMonumentThings.Clear(); return("MonumentOverlapsBuilding".Translate()); } } } } } foreach (SketchEntity entity3 in monumentMarker.sketch.Entities) { if (!entity3.IsSameSpawnedOrBlueprintOrFrame(loc + entity3.pos, map)) { foreach (IntVec3 edgeCell in entity3.OccupiedRect.MovedBy(loc).ExpandedBy(1).EdgeCells) { if (edgeCell.InBounds(map)) { Building firstBuilding2 = edgeCell.GetFirstBuilding(map); if (firstBuilding2 != null && !tmpMonumentThings.Contains(firstBuilding2) && (firstBuilding2.Faction == null || firstBuilding2.Faction == Faction.OfPlayer)) { tmpMonumentThings.Clear(); return("MonumentAdjacentToBuilding".Translate()); } } } } } tmpMonumentThings.Clear(); } return(true); }