private static void CheckInitDebugDrawGrid() { if (debugDrawGrid == null) { debugDrawGrid = new BoolGrid(Find.CurrentMap); } else if (!debugDrawGrid.MapSizeMatches(Find.CurrentMap)) { debugDrawGrid.ClearAndResizeTo(Find.CurrentMap); } }
public static void DrawFieldEdges(List <IntVec3> cells, Color color) { // swiped from GenDraw.DrawFieldEdges- we need to draw using a different shader to avoid being covered by fog var currentMap = Find.CurrentMap; var material = MaterialPool.MatFrom(new MaterialRequest { shader = ShaderDatabase.MetaOverlay, color = color, BaseTexPath = "UI/Overlays/TargetHighlight_Side" }); material.mainTexture.wrapMode = TextureWrapMode.Clamp; if (fieldGrid == null) { fieldGrid = new BoolGrid(currentMap); } else { fieldGrid.ClearAndResizeTo(currentMap); } int x = currentMap.Size.x; int z = currentMap.Size.z; int count = cells.Count; for (int i = 0; i < count; i++) { if (cells[i].InBounds(currentMap)) { fieldGrid[cells[i].x, cells[i].z] = true; } } for (int j = 0; j < count; j++) { var intVec = cells[j]; if (intVec.InBounds(currentMap)) { rotNeeded[0] = (intVec.z < z - 1 && !fieldGrid[intVec.x, intVec.z + 1]); rotNeeded[1] = (intVec.x < x - 1 && !fieldGrid[intVec.x + 1, intVec.z]); rotNeeded[2] = (intVec.z > 0 && !fieldGrid[intVec.x, intVec.z - 1]); rotNeeded[3] = (intVec.x > 0 && !fieldGrid[intVec.x - 1, intVec.z]); for (int k = 0; k < 4; k++) { if (rotNeeded[k]) { Graphics.DrawMesh(MeshPool.plane10, intVec.ToVector3ShiftedWithAltitude(AltitudeLayer.MetaOverlays), new Rot4(k).AsQuat, material, 0); } } } } }
private void FindAdjacentRooms() { adjacentRooms.Clear(); if (room.UsesOutdoorTemperature) { return; } Map visibleMap = Find.VisibleMap; List <IntVec3> cells = new List <IntVec3>(); foreach (IntVec3 current in room.Cells) { cells.Add(current); } if (fieldGrid == null) { fieldGrid = new BoolGrid(visibleMap); } else { fieldGrid.ClearAndResizeTo(visibleMap); } int x = visibleMap.Size.x; int z = visibleMap.Size.z; int count = cells.Count; for (int i = 0; i < count; i++) { if (cells[i].InBounds(visibleMap)) { fieldGrid[cells[i].x, cells[i].z] = true; } } for (int j = 0; j < count; j++) { IntVec3 c = cells[j]; if (c.InBounds(visibleMap)) { if (c.z < z - 1 && !fieldGrid[c.x, c.z + 1]) { var door = Find.VisibleMap.thingGrid.ThingsAt(new IntVec3(c.x, c.y, c.z + 1)).ToList().Find(s => s.def.defName == "Door"); if (door != null) { adjacentRooms.Add(RegionAndRoomQuery.RoomAt(new IntVec3(c.x, c.y, c.z + 2), Map)); } } if (c.x < x - 1 && !fieldGrid[c.x + 1, c.z]) { var door = Find.VisibleMap.thingGrid.ThingsAt(new IntVec3(c.x + 1, c.y, c.z)).ToList().Find(s => s.def.defName == "Door"); if (door != null) { adjacentRooms.Add(RegionAndRoomQuery.RoomAt(new IntVec3(c.x + 2, c.y, c.z), Map)); } } if (c.z > 0 && !fieldGrid[c.x, c.z - 1]) { var door = Find.VisibleMap.thingGrid.ThingsAt(new IntVec3(c.x, c.y, c.z - 1)).ToList().Find(s => s.def.defName == "Door"); if (door != null) { adjacentRooms.Add(RegionAndRoomQuery.RoomAt(new IntVec3(c.x, c.y, c.z - 2), Map)); } } if (c.z > 0 && !fieldGrid[c.x - 1, c.z]) { var door = Find.VisibleMap.thingGrid.ThingsAt(new IntVec3(c.x - 1, c.y, c.z)).ToList().Find(s => s.def.defName == "Door"); if (door != null) { adjacentRooms.Add(RegionAndRoomQuery.RoomAt(new IntVec3(c.x - 2, c.y, c.z), Map)); } } } } }
//public static void DrawFieldEdges(List<IntVec3> cells, Color color) public static bool Prefix(List <IntVec3> cells, Color color) { if (!Settings.Get().fieldEdgesRedo) { return(true); } Map currentMap = Find.CurrentMap; MaterialRequest req = new MaterialRequest { shader = ShaderDatabase.Transparent, color = color, BaseTexPath = "TargetHighlight_Edge" }; Material materialEdge = MaterialPool.MatFrom(req); materialEdge.GetTexture("_MainTex").wrapMode = TextureWrapMode.Clamp; req.BaseTexPath = "TargetHighlight_Edge2"; Material materialEdge2 = MaterialPool.MatFrom(req); materialEdge2.GetTexture("_MainTex").wrapMode = TextureWrapMode.Clamp; req.BaseTexPath = "TargetHighlight_Edge3"; Material materialEdge3 = MaterialPool.MatFrom(req); materialEdge3.GetTexture("_MainTex").wrapMode = TextureWrapMode.Clamp; req.BaseTexPath = "TargetHighlight_Edge4"; Material materialEdge4 = MaterialPool.MatFrom(req); materialEdge4.GetTexture("_MainTex").wrapMode = TextureWrapMode.Clamp; req.BaseTexPath = "TargetHighlight_Corner"; Material materialCorner = MaterialPool.MatFrom(req); materialCorner.GetTexture("_MainTex").wrapMode = TextureWrapMode.Clamp; if (fieldGrid == null) { fieldGrid = new BoolGrid(currentMap); } else { fieldGrid.ClearAndResizeTo(currentMap); } int x = currentMap.Size.x; int z = currentMap.Size.z; foreach (IntVec3 cell in cells) { if (cell.InBounds(currentMap)) { fieldGrid[cell.x, cell.z] = true; } } foreach (IntVec3 c in cells) { if (c.InBounds(currentMap)) { adjEmpty[0] = (c.z < z - 1 && !fieldGrid[c.x, c.z + 1]); //north adjEmpty[1] = (c.x < x - 1 && !fieldGrid[c.x + 1, c.z]); //east adjEmpty[2] = (c.z > 0 && !fieldGrid[c.x, c.z - 1]); //south adjEmpty[3] = (c.x > 0 && !fieldGrid[c.x - 1, c.z]); //west adjEmpty[4] = (c.x < x - 1 && c.z < z - 1 && !fieldGrid[c.x + 1, c.z + 1]); //northeast adjEmpty[5] = (c.x < x - 1 && c.z > 0 && !fieldGrid[c.x + 1, c.z - 1]); //southeast adjEmpty[6] = (c.x > 0 && c.z > 0 && !fieldGrid[c.x - 1, c.z - 1]); //southwest adjEmpty[7] = (c.x > 0 && c.z < z - 1 && !fieldGrid[c.x - 1, c.z + 1]); //northwest //Count # of edges empty int adjOrthEmpty = 0; for (int i = 0; i < 4; i++) { if (adjEmpty[i]) { adjOrthEmpty++; } } Vector3 cellVector = c.ToVector3ShiftedWithAltitude(AltitudeLayer.MetaOverlays); //Draw edges using texture png based on total # of edges if (adjOrthEmpty == 4) { Graphics.DrawMesh(MeshPool.plane10, cellVector, Quaternion.identity, materialEdge4, 0); } else if (adjOrthEmpty == 3) { for (int i = 0; i < 4; i++) { if (!adjEmpty[i]) { Graphics.DrawMesh(MeshPool.plane10, cellVector, new Rot4(i).AsQuat, materialEdge3, 0); } } } else if (adjOrthEmpty == 2) { bool corner = false; for (int i = 0; i < 4; i++) { if (adjEmpty[i] && adjEmpty[(i + 1) % 4]) { Graphics.DrawMesh(MeshPool.plane10, cellVector, new Rot4(i).AsQuat, materialEdge2, 0); corner = true; } } //Opposite edges : just draw single edge twice if (!corner) { for (int i = 0; i < 4; i++) { if (adjEmpty[i]) { Graphics.DrawMesh(MeshPool.plane10, cellVector, new Rot4(i).AsQuat, materialEdge, 0); } } } } else if (adjOrthEmpty == 1) { for (int i = 0; i < 4; i++) { if (adjEmpty[i]) { Graphics.DrawMesh(MeshPool.plane10, cellVector, new Rot4(i).AsQuat, materialEdge, 0); } } } //Draw corner fill-ins for (int i = 0; i < 4; i++) { if (adjEmpty[i + 4] && !adjEmpty[i] && !adjEmpty[(i + 1) % 4]) { Graphics.DrawMesh(MeshPool.plane10, cellVector, new Rot4(i).AsQuat, materialCorner, 0); } } } } return(false); }
public static void MakeColony(params ColonyMakerFlag[] flags) { bool godMode = DebugSettings.godMode; DebugSettings.godMode = true; Thing.allowDestroyNonDestroyable = true; if (usedCells == null) { usedCells = new BoolGrid(Map); } else { usedCells.ClearAndResizeTo(Map); } IntVec3 center = Map.Center; int minX = center.x - 50; IntVec3 center2 = Map.Center; overRect = new CellRect(minX, center2.z - 50, 100, 100); DeleteAllSpawnedPawns(); GenDebug.ClearArea(overRect, Find.CurrentMap); if (flags.Contains(ColonyMakerFlag.Animals)) { foreach (PawnKindDef item in from k in DefDatabase <PawnKindDef> .AllDefs where k.RaceProps.Animal select k) { if (!TryGetFreeRect(6, 3, out CellRect result)) { return; } result = result.ContractedBy(1); foreach (IntVec3 item2 in result) { Map.terrainGrid.SetTerrain(item2, TerrainDefOf.Concrete); } GenSpawn.Spawn(PawnGenerator.GeneratePawn(item), result.Cells.ElementAt(0), Map); IntVec3 intVec = result.Cells.ElementAt(1); Pawn p = (Pawn)GenSpawn.Spawn(PawnGenerator.GeneratePawn(item), intVec, Map); HealthUtility.DamageUntilDead(p); Corpse thing = (Corpse)intVec.GetThingList(Find.CurrentMap).First((Thing t) => t is Corpse); CompRottable compRottable = thing.TryGetComp <CompRottable>(); if (compRottable != null) { compRottable.RotProgress += 1200000f; } if (item.RaceProps.leatherDef != null) { GenSpawn.Spawn(item.RaceProps.leatherDef, result.Cells.ElementAt(2), Map); } if (item.RaceProps.meatDef != null) { GenSpawn.Spawn(item.RaceProps.meatDef, result.Cells.ElementAt(3), Map); } } } if (flags.Contains(ColonyMakerFlag.ConduitGrid)) { Designator_Build designator_Build = new Designator_Build(ThingDefOf.PowerConduit); for (int i = overRect.minX; i < overRect.maxX; i++) { for (int j = overRect.minZ; j < overRect.maxZ; j += 7) { designator_Build.DesignateSingleCell(new IntVec3(i, 0, j)); } } for (int l = overRect.minZ; l < overRect.maxZ; l++) { for (int m = overRect.minX; m < overRect.maxX; m += 7) { designator_Build.DesignateSingleCell(new IntVec3(m, 0, l)); } } } if (flags.Contains(ColonyMakerFlag.PowerPlants)) { List <ThingDef> list = new List <ThingDef>(); list.Add(ThingDefOf.SolarGenerator); list.Add(ThingDefOf.WindTurbine); List <ThingDef> list2 = list; for (int n = 0; n < 8; n++) { if (TryMakeBuilding(list2[n % list2.Count]) == null) { Log.Message("Could not make solar generator."); break; } } } if (flags.Contains(ColonyMakerFlag.Batteries)) { for (int num = 0; num < 6; num++) { Thing thing2 = TryMakeBuilding(ThingDefOf.Battery); if (thing2 == null) { Log.Message("Could not make battery."); break; } ((Building_Battery)thing2).GetComp <CompPowerBattery>().AddEnergy(999999f); } } if (flags.Contains(ColonyMakerFlag.WorkTables)) { IEnumerable <ThingDef> enumerable = from def in DefDatabase <ThingDef> .AllDefs where typeof(Building_WorkTable).IsAssignableFrom(def.thingClass) select def; foreach (ThingDef item3 in enumerable) { Thing thing3 = TryMakeBuilding(item3); if (thing3 == null) { Log.Message("Could not make worktable: " + item3.defName); break; } Building_WorkTable building_WorkTable = thing3 as Building_WorkTable; if (building_WorkTable != null) { foreach (RecipeDef allRecipe in building_WorkTable.def.AllRecipes) { building_WorkTable.billStack.AddBill(allRecipe.MakeNewBill()); } } } } if (flags.Contains(ColonyMakerFlag.AllBuildings)) { IEnumerable <ThingDef> enumerable2 = from def in DefDatabase <ThingDef> .AllDefs where def.category == ThingCategory.Building && def.BuildableByPlayer select def; foreach (ThingDef item4 in enumerable2) { if (item4 != ThingDefOf.PowerConduit) { Thing thing4 = TryMakeBuilding(item4); if (thing4 == null) { Log.Message("Could not make building: " + item4.defName); break; } } } } if (!TryGetFreeRect(33, 33, out CellRect result2)) { Log.Error("Could not get wallable rect"); } result2 = result2.ContractedBy(1); if (flags.Contains(ColonyMakerFlag.AllItems)) { List <ThingDef> itemDefs = (from def in DefDatabase <ThingDef> .AllDefs where DebugThingPlaceHelper.IsDebugSpawnable(def) && def.category == ThingCategory.Item select def).ToList(); FillWithItems(result2, itemDefs); } else if (flags.Contains(ColonyMakerFlag.ItemsRawFood)) { List <ThingDef> list3 = new List <ThingDef>(); list3.Add(ThingDefOf.RawPotatoes); FillWithItems(result2, list3); } if (flags.Contains(ColonyMakerFlag.Filth)) { foreach (IntVec3 item5 in result2) { GenSpawn.Spawn(ThingDefOf.Filth_Dirt, item5, Map); } } if (flags.Contains(ColonyMakerFlag.ItemsWall)) { CellRect cellRect = result2.ExpandedBy(1); Designator_Build designator_Build2 = new Designator_Build(ThingDefOf.Wall); designator_Build2.SetStuffDef(ThingDefOf.WoodLog); foreach (IntVec3 edgeCell in cellRect.EdgeCells) { designator_Build2.DesignateSingleCell(edgeCell); } } if (flags.Contains(ColonyMakerFlag.ColonistsMany)) { MakeColonists(15, overRect.CenterCell); } else if (flags.Contains(ColonyMakerFlag.ColonistOne)) { MakeColonists(1, overRect.CenterCell); } if (flags.Contains(ColonyMakerFlag.Fire)) { if (!TryGetFreeRect(30, 30, out CellRect result3)) { Log.Error("Could not get free rect for fire."); } ThingDef plant_TreeOak = ThingDefOf.Plant_TreeOak; foreach (IntVec3 item6 in result3) { GenSpawn.Spawn(plant_TreeOak, item6, Map); } foreach (IntVec3 item7 in result3) { IntVec3 current9 = item7; if (current9.x % 7 == 0 && current9.z % 7 == 0) { GenExplosion.DoExplosion(current9, Find.CurrentMap, 3.9f, DamageDefOf.Flame, null); } } } if (flags.Contains(ColonyMakerFlag.ColonistsHungry)) { DoToColonists(0.4f, delegate(Pawn col) { col.needs.food.CurLevel = Mathf.Max(0f, Rand.Range(-0.05f, 0.05f)); }); } if (flags.Contains(ColonyMakerFlag.ColonistsTired)) { DoToColonists(0.4f, delegate(Pawn col) { col.needs.rest.CurLevel = Mathf.Max(0f, Rand.Range(-0.05f, 0.05f)); }); } if (flags.Contains(ColonyMakerFlag.ColonistsInjured)) { DoToColonists(0.4f, delegate(Pawn col) { DamageDef def2 = (from d in DefDatabase <DamageDef> .AllDefs where d.ExternalViolenceFor(null) select d).RandomElement(); col.TakeDamage(new DamageInfo(def2, 10f)); }); } if (flags.Contains(ColonyMakerFlag.ColonistsDiseased)) { foreach (HediffDef item8 in from d in DefDatabase <HediffDef> .AllDefs where d.hediffClass != typeof(Hediff_AddedPart) && (d.HasComp(typeof(HediffComp_Immunizable)) || d.HasComp(typeof(HediffComp_GrowthMode))) select d) { Pawn pawn = PawnGenerator.GeneratePawn(Faction.OfPlayer.def.basicMemberKind, Faction.OfPlayer); TryGetFreeRect(1, 1, out CellRect result4); GenSpawn.Spawn(pawn, result4.CenterCell, Map); pawn.health.AddHediff(item8); } } if (flags.Contains(ColonyMakerFlag.Beds)) { IEnumerable <ThingDef> source = from def in DefDatabase <ThingDef> .AllDefs where def.thingClass == typeof(Building_Bed) select def; int freeColonistsCount = Map.mapPawns.FreeColonistsCount; for (int num2 = 0; num2 < freeColonistsCount; num2++) { if (TryMakeBuilding(source.RandomElement()) == null) { Log.Message("Could not make beds."); break; } } } if (flags.Contains(ColonyMakerFlag.Stockpiles)) { Designator_ZoneAddStockpile_Resources designator_ZoneAddStockpile_Resources = new Designator_ZoneAddStockpile_Resources(); IEnumerator enumerator11 = Enum.GetValues(typeof(StoragePriority)).GetEnumerator(); try { while (enumerator11.MoveNext()) { StoragePriority priority = (StoragePriority)enumerator11.Current; TryGetFreeRect(7, 7, out CellRect result5); result5 = result5.ContractedBy(1); designator_ZoneAddStockpile_Resources.DesignateMultiCell(result5.Cells); Zone_Stockpile zone_Stockpile = (Zone_Stockpile)Map.zoneManager.ZoneAt(result5.CenterCell); zone_Stockpile.settings.Priority = priority; } } finally { IDisposable disposable; if ((disposable = (enumerator11 as IDisposable)) != null) { disposable.Dispose(); } } } if (flags.Contains(ColonyMakerFlag.GrowingZones)) { Zone_Growing dummyZone = new Zone_Growing(Map.zoneManager); Map.zoneManager.RegisterZone(dummyZone); foreach (ThingDef item9 in from d in DefDatabase <ThingDef> .AllDefs where d.plant != null && PlantUtility.CanSowOnGrower(d, dummyZone) select d) { if (!TryGetFreeRect(6, 6, out CellRect result6)) { Log.Error("Could not get growing zone rect."); } result6 = result6.ContractedBy(1); foreach (IntVec3 item10 in result6) { Map.terrainGrid.SetTerrain(item10, TerrainDefOf.Soil); } Designator_ZoneAdd_Growing designator_ZoneAdd_Growing = new Designator_ZoneAdd_Growing(); designator_ZoneAdd_Growing.DesignateMultiCell(result6.Cells); (Map.zoneManager.ZoneAt(result6.CenterCell) as Zone_Growing)?.SetPlantDefToGrow(item9); } dummyZone.Delete(); } ClearAllHomeArea(); FillWithHomeArea(overRect); DebugSettings.godMode = godMode; Thing.allowDestroyNonDestroyable = false; }