public override void DrawGhost( ThingDef def, IntVec3 center, Rot4 rot ) { var vecNorth = center + IntVec3.North.RotatedBy( rot ); var vecSouth = center + IntVec3.South.RotatedBy( rot ); if ( !vecNorth.InBounds() || !vecSouth.InBounds() ) { return; } GenDraw.DrawFieldEdges( new List< IntVec3 > { vecNorth }, new Color( 1f, 0.7f, 0f, 0.5f ) ); GenDraw.DrawFieldEdges( new List< IntVec3 > { vecSouth }, Color.white ); var controlledRoom = vecNorth.GetRoom(); var otherRoom = vecSouth.GetRoom(); if ( controlledRoom == null || otherRoom == null ) { return; } if ( !controlledRoom.UsesOutdoorTemperature ) { GenDraw.DrawFieldEdges( controlledRoom.Cells.ToList(), new Color( 1f, 0.7f, 0f, 0.5f ) ); } }
public static bool GetRandomFreeCardinalZoneAdjacentTo(int zoneAbs, int zoneOrd, out Rot4 cardinal, ZoneProperties[,] zoneMap, int horizontalZonesNumber, int verticalZonesNumber) { // Get the free zones. List<Rot4> cardinalList = new List<Rot4>(); for (int cardinalAsInt = 0; cardinalAsInt < 4; cardinalAsInt++) { int testedZoneAbs = 0; int testedZoneOrd = 0; Rot4 testedCardinal = new Rot4(cardinalAsInt); Zone.GetAdjacentZone(zoneAbs, zoneOrd, testedCardinal, out testedZoneAbs, out testedZoneOrd); if (ZoneIsInArea(testedZoneAbs, testedZoneOrd, horizontalZonesNumber, verticalZonesNumber)) { if (zoneMap[testedZoneOrd, testedZoneAbs].zoneType == ZoneType.NotYetGenerated) { cardinalList.Add(testedCardinal); } } } if (cardinalList.Count == 0) { cardinal = Rot4.North; return false; } else { cardinal = cardinalList.RandomElement<Rot4>(); return true; } }
public static void GenerateSmallRoomWeaponRoom(IntVec3 areaSouthWestOrigin, int zoneAbs, int zoneOrd, Rot4 rotation, ref OG_OutpostData outpostData) { IntVec3 origin = Zone.GetZoneOrigin(areaSouthWestOrigin, zoneAbs, zoneOrd); IntVec3 rotatedOrigin = Zone.GetZoneRotatedOrigin(areaSouthWestOrigin, zoneAbs, zoneOrd, rotation); OG_Common.GenerateEmptyRoomAt(rotatedOrigin + new IntVec3(smallRoomWallOffset, 0, smallRoomWallOffset).RotatedBy(rotation), Genstep_GenerateOutpost.zoneSideSize - 2 * smallRoomWallOffset, Genstep_GenerateOutpost.zoneSideSize - 2 * smallRoomWallOffset, rotation, TerrainDefOf.Concrete, TerrainDef.Named("MetalTile"), ref outpostData); // Spawn weapon racks, weapons and lamps. Building_Storage rack = OG_Common.TrySpawnThingAt(ThingDefOf.EquipmentRack, ThingDefOf.Steel, rotatedOrigin + new IntVec3(smallRoomWallOffset + 1, 0, smallRoomWallOffset + 1).RotatedBy(rotation), true, new Rot4(Rot4.North.AsInt + rotation.AsInt), ref outpostData)as Building_Storage; TrySpawnWeaponOnRack(rack); rack.GetStoreSettings().filter.SetAllow(ThingCategoryDef.Named("WeaponsMelee"), false); rack.GetStoreSettings().Priority = StoragePriority.Critical; rack = OG_Common.TrySpawnThingAt(ThingDefOf.EquipmentRack, ThingDefOf.Steel, rotatedOrigin + new IntVec3(smallRoomWallOffset + 4, 0, smallRoomWallOffset + 1).RotatedBy(rotation), true, new Rot4(Rot4.North.AsInt + rotation.AsInt), ref outpostData) as Building_Storage; TrySpawnWeaponOnRack(rack); rack.GetStoreSettings().filter.SetAllow(ThingCategoryDef.Named("WeaponsMelee"), false); rack.GetStoreSettings().Priority = StoragePriority.Critical; rack = OG_Common.TrySpawnThingAt(ThingDefOf.EquipmentRack, ThingDefOf.Steel, rotatedOrigin + new IntVec3(smallRoomWallOffset + 2, 0, smallRoomWallOffset + 5).RotatedBy(rotation), true, new Rot4(Rot4.South.AsInt + rotation.AsInt), ref outpostData) as Building_Storage; TrySpawnWeaponOnRack(rack); rack.GetStoreSettings().filter.SetAllow(ThingCategoryDef.Named("WeaponsMelee"), false); rack.GetStoreSettings().Priority = StoragePriority.Critical; rack = OG_Common.TrySpawnThingAt(ThingDefOf.EquipmentRack, ThingDefOf.Steel, rotatedOrigin + new IntVec3(smallRoomWallOffset + 5, 0, smallRoomWallOffset + 5).RotatedBy(rotation), true, new Rot4(Rot4.South.AsInt + rotation.AsInt), ref outpostData) as Building_Storage; TrySpawnWeaponOnRack(rack); rack.GetStoreSettings().filter.SetAllow(ThingCategoryDef.Named("WeaponsMelee"), false); rack.GetStoreSettings().Priority = StoragePriority.Critical; OG_Common.TrySpawnLampAt(rotatedOrigin + new IntVec3(smallRoomWallOffset + 1, 0, smallRoomWallOffset + 3).RotatedBy(rotation), Color.white, ref outpostData); OG_Common.TrySpawnLampAt(rotatedOrigin + new IntVec3(smallRoomWallOffset + 5, 0, smallRoomWallOffset + 3).RotatedBy(rotation), Color.white, ref outpostData); // Spawn vertical alley and door. for (int zOffset = smallRoomWallOffset; zOffset <= Genstep_GenerateOutpost.zoneSideSize - smallRoomWallOffset; zOffset++) { Find.TerrainGrid.SetTerrain(rotatedOrigin + new IntVec3(Genstep_GenerateOutpost.zoneSideCenterOffset, 0, zOffset).RotatedBy(rotation), TerrainDef.Named("PavedTile")); } OG_Common.SpawnDoorAt(rotatedOrigin + new IntVec3(Genstep_GenerateOutpost.zoneSideCenterOffset, 0, Genstep_GenerateOutpost.zoneSideSize - smallRoomWallOffset - 1).RotatedBy(rotation), ref outpostData); }
public override AcceptanceReport AllowsPlacing(BuildableDef checkingDef, IntVec3 loc, Rot4 rot) { bool flag = false; List<Thing> list = Find.ThingGrid.ThingsListAt(loc); if (list.Count > 0) { foreach (Thing current in list) { if (current.def.category == ThingCategory.Building) { if (current.def.holdsRoof && current.def.coversFloor && current.def.altitudeLayer == AltitudeLayer.BuildingTall && current.def.passability == Traversability.Impassable) { flag = true; break; } } } } else { flag = false; } AcceptanceReport result; if (flag) { result = true; } else { result = "Need to be placed on a colony wall"; } return result; }
public override AcceptanceReport AllowsPlacing(BuildableDef checkingDef, IntVec3 loc, Rot4 rot, Thing thingToIgnore = null) { IEnumerable<IntVec3> cells = GenAdj.CellsAdjacent8Way(loc, rot, checkingDef.Size).Union<IntVec3>(GenAdj.CellsOccupiedBy(loc, rot, checkingDef.Size)); foreach (IntVec3 cell in cells) { List<Thing> things = Map.thingGrid.ThingsListAt(cell); foreach (Thing thing in things) { if (thing.TryGetComp<CompRTQuantumStockpile>() != null || thing.TryGetComp<CompRTQuantumChunkSilo>() != null) { return "PlaceWorker_RTNoQSOverlap".Translate(); } else if (thing.def.entityDefToBuild != null) { ThingDef thingDef = thing.def.entityDefToBuild as ThingDef; if (null != thingDef && null != thingDef.comps && null != thingDef.comps.Find(x => typeof(CompRTQuantumStockpile) == x.compClass)) { return "PlaceWorker_RTNoQSOverlap".Translate(); } } } } return true; }
public static void GenerateMediumRoomPrison(IntVec3 areaSouthWestOrigin, int zoneAbs, int zoneOrd, Rot4 rotation, ref OG_OutpostData outpostData) { IntVec3 origin = Zone.GetZoneOrigin(areaSouthWestOrigin, zoneAbs, zoneOrd); IntVec3 rotatedOrigin = Zone.GetZoneRotatedOrigin(areaSouthWestOrigin, zoneAbs, zoneOrd, rotation); OG_Common.GenerateEmptyRoomAt(rotatedOrigin + new IntVec3(0, 0, 1).RotatedBy(rotation), 5, 9, rotation, TerrainDefOf.Concrete, null, ref outpostData); OG_Common.GenerateEmptyRoomAt(rotatedOrigin + new IntVec3(4, 0, 1).RotatedBy(rotation), 3, 9, rotation, TerrainDefOf.Concrete, null, ref outpostData); OG_Common.GenerateEmptyRoomAt(rotatedOrigin + new IntVec3(6, 0, 1).RotatedBy(rotation), 5, 9, rotation, TerrainDefOf.Concrete, null, ref outpostData); // Spawn prisoner beds. OG_Common.TrySpawnThingAt(ThingDef.Named("Bed"), ThingDefOf.Steel, rotatedOrigin + new IntVec3(1, 0, 8).RotatedBy(rotation), true, new Rot4(Rot4.South.AsInt + rotation.AsInt), ref outpostData); OG_Common.TrySpawnThingAt(ThingDef.Named("Stool"), ThingDefOf.Steel, rotatedOrigin + new IntVec3(2, 0, 8).RotatedBy(rotation), true, new Rot4(Rot4.South.AsInt + rotation.AsInt), ref outpostData); OG_Common.TrySpawnThingAt(ThingDef.Named("Bed"), ThingDefOf.Steel, rotatedOrigin + new IntVec3(3, 0, 8).RotatedBy(rotation), true, new Rot4(Rot4.South.AsInt + rotation.AsInt), ref outpostData); OG_Common.TrySpawnThingAt(ThingDef.Named("Bed"), ThingDefOf.Steel, rotatedOrigin + new IntVec3(7, 0, 2).RotatedBy(rotation), true, new Rot4(Rot4.North.AsInt + rotation.AsInt), ref outpostData); OG_Common.TrySpawnThingAt(ThingDef.Named("Stool"), ThingDefOf.Steel, rotatedOrigin + new IntVec3(8, 0, 2).RotatedBy(rotation), true, new Rot4(Rot4.North.AsInt + rotation.AsInt), ref outpostData); OG_Common.TrySpawnThingAt(ThingDef.Named("Bed"), ThingDefOf.Steel, rotatedOrigin + new IntVec3(9, 0, 2).RotatedBy(rotation), true, new Rot4(Rot4.North.AsInt + rotation.AsInt), ref outpostData); // Spawn lamps, heaters and coolers. OG_Common.TrySpawnLampAt(rotatedOrigin + new IntVec3(3, 0, 2).RotatedBy(rotation), Color.white, ref outpostData); OG_Common.TrySpawnLampAt(rotatedOrigin + new IntVec3(7, 0, 8).RotatedBy(rotation), Color.white, ref outpostData); OG_Common.TrySpawnHeaterAt(rotatedOrigin + new IntVec3(1, 0, 2).RotatedBy(rotation), ref outpostData); OG_Common.TrySpawnHeaterAt(rotatedOrigin + new IntVec3(9, 0, 8).RotatedBy(rotation), ref outpostData); OG_Common.SpawnCoolerAt(rotatedOrigin + new IntVec3(0, 0, 2).RotatedBy(rotation), new Rot4(Rot4.West.AsInt + rotation.AsInt), ref outpostData); OG_Common.SpawnCoolerAt(rotatedOrigin + new IntVec3(10, 0, 8).RotatedBy(rotation), new Rot4(Rot4.East.AsInt + rotation.AsInt), ref outpostData); // Spawn vertical alley and door. for (int zOffset = 0; zOffset <= 10; zOffset++) { Find.TerrainGrid.SetTerrain(rotatedOrigin + new IntVec3(5, 0, zOffset).RotatedBy(rotation), TerrainDef.Named("PavedTile")); } OG_Common.SpawnDoorAt(rotatedOrigin + new IntVec3(4, 0, 3).RotatedBy(rotation), ref outpostData); OG_Common.SpawnDoorAt(rotatedOrigin + new IntVec3(6, 0, 7).RotatedBy(rotation), ref outpostData); OG_Common.SpawnDoorAt(rotatedOrigin + new IntVec3(5, 0, 1).RotatedBy(rotation), ref outpostData); OG_Common.SpawnDoorAt(rotatedOrigin + new IntVec3(5, 0, 9).RotatedBy(rotation), ref outpostData); }
public override AcceptanceReport AllowsPlacing( BuildableDef checkingDef, IntVec3 loc, Rot4 rot ) { ThingDef def = checkingDef as ThingDef; var Restrictions = def.GetCompProperties( typeof( RestrictedPlacement_Comp ) ) as RestrictedPlacement_Properties; if( Restrictions == null ){ Log.Error( "Could not get restrictions!" ); return (AcceptanceReport)false; } // Override steam-geyser restriction if( ( Restrictions.RestrictedThing.FindIndex( r => r == ThingDefOf.SteamGeyser ) >= 0 )&& ( ThingDefOf.GeothermalGenerator != ( checkingDef as ThingDef ) ) ){ var newGeo = checkingDef as ThingDef; ThingDefOf.GeothermalGenerator = newGeo; } foreach( Thing t in loc.GetThingList() ){ if( ( Restrictions.RestrictedThing.Find( r => r == t.def ) != null )&& ( t.Position == loc ) ) return (AcceptanceReport)true; } return "MessagePlacementNotHere".Translate(); }
/// <summary> /// Checks if a new force field generator can be built at this location. /// - must not be too near from another force field generator (or it would perturb other fields). /// </summary> public override AcceptanceReport AllowsPlacing(BuildableDef checkingDef, IntVec3 loc, Rot4 rot) { // Check if another force field generator is not too close. List<Thing> forceFieldGeneratorList = new List<Thing>(); IEnumerable<Thing> list = Find.ListerThings.ThingsOfDef(ThingDef.Named("ForceFieldGenerator")); foreach (Thing generator in list) { forceFieldGeneratorList.Add(generator); } list = Find.ListerThings.ThingsOfDef(ThingDef.Named("ForceFieldGenerator").blueprintDef); foreach (Thing generator in list) { forceFieldGeneratorList.Add(generator); } list = Find.ListerThings.ThingsOfDef(ThingDef.Named("ForceFieldGenerator").frameDef); foreach (Thing generator in list) { forceFieldGeneratorList.Add(generator); } foreach (Thing generator in forceFieldGeneratorList) { if (generator.Position.InHorDistOf(loc, minDistanceBetweenTwoForceFieldGenerators)) { return new AcceptanceReport("An other force field generator is too close (would generate perturbations)."); } } // Display effect zone. List<IntVec3> coveredCells = Building_ForceFieldGenerator.GetCoveredCells(loc, rot); GenDraw.DrawFieldEdges(coveredCells); return true; }
public override void DrawGhost(ThingDef def, IntVec3 center, Rot4 rot) { GenDraw.DrawFieldEdges( FindUtil.SquareAreaAround(center, Mathf.RoundToInt(def.specialDisplayRadius)) .Where(cell => cell.Walkable() && cell.InBounds()) .ToList()); }
public override AcceptanceReport AllowsPlacing(BuildableDef checkingDef, IntVec3 loc, Rot4 rot) { string reason = ""; bool canBePlacedHere = Building_LaserFencePylon.CanPlaceNewPylonHere(loc, out reason); if (canBePlacedHere == false) { return new AcceptanceReport(reason); } // Display potential placing positions. foreach (Thing pylon in Find.ListerThings.ThingsOfDef(ThingDef.Named("LaserFencePylon").blueprintDef)) { if (pylon.Position.InHorDistOf(loc, 6f)) { Building_LaserFencePylon.DrawPotentialPlacePositions(pylon.Position); } } foreach (Thing pylon in Find.ListerThings.ThingsOfDef(ThingDef.Named("LaserFencePylon").frameDef)) { if (pylon.Position.InHorDistOf(loc, 6f)) { Building_LaserFencePylon.DrawPotentialPlacePositions(pylon.Position); } } foreach (Thing pylon in Find.ListerThings.ThingsOfDef(ThingDef.Named("LaserFencePylon"))) { if (pylon.Position.InHorDistOf(loc, 6f)) { Building_LaserFencePylon.DrawPotentialPlacePositions(pylon.Position); } } return true; }
public override AcceptanceReport AllowsPlacing( BuildableDef checkingDef, IntVec3 loc, Rot4 rot ) { var Restrictions = checkingDef.RestrictedPlacement_Properties(); #if DEBUG if( Restrictions == null ){ CCL_Log.Error( "PlaceWorker_RestrictedCount unable to get properties!", checkingDef.defName ); return AcceptanceReport.WasRejected; } #endif var thingDef = checkingDef as ThingDef; #if DEBUG if( thingDef == null ) { CCL_Log.Error( "PlaceWorker_RestrictedCount unable to get cast BuildableDef to ThingDef!", checkingDef.defName ); return AcceptanceReport.WasRejected; } #endif // Get the current count of instances and blueprints of int count = Find.ListerThings.ThingsOfDef( thingDef ).Count + Find.ListerThings.ThingsOfDef( thingDef.blueprintDef ).Count; return count < Restrictions.MaxCount ? AcceptanceReport.WasAccepted : "MessagePlacementCountRestricted".Translate( Restrictions.MaxCount ); }
public static void GetAdjacentZone(int zoneAbs, int zoneOrd, Rot4 direction, out int adjacentZoneAbs, out int adjacentZoneOrd) { adjacentZoneAbs = 0; adjacentZoneOrd = 0; if (direction == Rot4.North) { adjacentZoneAbs = zoneAbs; adjacentZoneOrd = zoneOrd + 1; } else if (direction == Rot4.East) { adjacentZoneAbs = zoneAbs + 1; adjacentZoneOrd = zoneOrd; } else if (direction == Rot4.South) { adjacentZoneAbs = zoneAbs; adjacentZoneOrd = zoneOrd - 1; } else if (direction == Rot4.West) { adjacentZoneAbs = zoneAbs - 1; adjacentZoneOrd = zoneOrd; } }
/// <summary> /// Display the scan range of built mobile mineral sonar and the max scan range at the tested position. /// Allow placement nearly anywhere. /// </summary> public override AcceptanceReport AllowsPlacing(BuildableDef checkingDef, IntVec3 loc, Rot4 rot) { IEnumerable<Building> mobileMineralSonarList = Find.ListerBuildings.AllBuildingsColonistOfDef(ThingDef.Named("MobileMineralSonar")); if (mobileMineralSonarList != null) { foreach (Building mobileMineralSonar in mobileMineralSonarList) { (mobileMineralSonar as Building_MobileMineralSonar).DrawMaxScanRange(); } } ResearchProjectDef mmsResearch = ResearchProjectDef.Named("ResearchMobileMineralSonarEnhancedScan"); if (Find.ResearchManager.GetProgress(mmsResearch) >= mmsResearch.CostApparent) { Material scanRange30 = MaterialPool.MatFrom("Effects/ScanRange30"); Vector3 scanRangeScale30 = new Vector3(60f, 1f, 60f); Matrix4x4 scanRangeMatrix30 = default(Matrix4x4); // The 10f offset on Y axis is mandatory to be over the fog of war. scanRangeMatrix30.SetTRS(loc.ToVector3Shifted() + new Vector3(0f, 10f, 0f) + Altitudes.AltIncVect, (0f).ToQuat(), scanRangeScale30); Graphics.DrawMesh(MeshPool.plane10, scanRangeMatrix30, scanRange30, 0); } else { Material scanRange50 = MaterialPool.MatFrom("Effects/ScanRange50"); Vector3 scanRangeScale50 = new Vector3(100f, 1f, 100f); Matrix4x4 scanRangeMatrix50 = default(Matrix4x4); // The 10f offset on Y axis is mandatory to be over the fog of war. scanRangeMatrix50.SetTRS(loc.ToVector3Shifted() + new Vector3(0f, 10f, 0f) + Altitudes.AltIncVect, (0f).ToQuat(), scanRangeScale50); Graphics.DrawMesh(MeshPool.plane10, scanRangeMatrix50, scanRange50, 0); } return true; }
/// <summary> /// Draws a target highlight on all connectable Hoppers around target /// </summary> /// <param name="def"></param> /// <param name="center"></param> /// <param name="rot"></param> public override void DrawGhost( ThingDef def, IntVec3 center, Rot4 rot ) { List<CompHopper> hoppers = CompHopperUser.FindHoppers( center, rot, def.Size ); foreach( var hopper in hoppers ) { GenDraw.DrawTargetHighlight( hopper.parent ); } }
public BeltUndergroundComponent() { _processLevel = Level.Underground; _inputLevel = Level.Underground; _outputLevel = Level.Underground; inputDirection = Rot4.Invalid; outputDirection = Rot4.Invalid; }
/// <summary> /// Draws a target highlight on Hopper user /// </summary> /// <param name="def"></param> /// <param name="center"></param> /// <param name="rot"></param> public override void DrawGhost(ThingDef def, IntVec3 center, Rot4 rot) { Thing hopperUser = CompHopper.FindHopperUser( center + rot.FacingCell ); if ( (hopperUser != null) && !hopperUser.OccupiedRect().Cells.Contains( center ) ) { GenDraw.DrawTargetHighlight( hopperUser ); } }
public override AcceptanceReport AllowsPlacing(BuildableDef checkingDef, IntVec3 loc, Rot4 rot) { Fissure thing = (Fissure)Find.ThingGrid.ThingAt(loc, ThingDef.Named("MD2Fissure")); if (thing != null && thing.Position == loc) return true; else return "OnFissureReportString".Translate(); }
public override AcceptanceReport AllowsPlacing( BuildableDef checkingDef, IntVec3 loc, Rot4 rot ) { if( CompHopper.FindHopperUser( loc + rot.FacingCell ) != null ) { return ( AcceptanceReport )true; } return ( AcceptanceReport )( "Must connect to a building that needs a hopper." ); }
/// <summary> /// Check if a new fishing pier can be built at this location. /// - the fishing pier bank cell must be on a bank. /// - the rest of the fishing pier and the fishing spot must be on water. /// - must not be too near from another fishing pier. /// </summary> public override AcceptanceReport AllowsPlacing(BuildableDef checkingDef, IntVec3 loc, Rot4 rot) { // Check fishing pier bank cell is on a "solid" terrain. if (IsAquaticTerrain(loc)) { return new AcceptanceReport("Fishing pier must touch a bank."); } // Check fishing pier middle and river cells are on water. if ((IsAquaticTerrain(loc + new IntVec3(0, 0, 1).RotatedBy(rot)) == false) || (IsAquaticTerrain(loc + new IntVec3(0, 0, 2).RotatedBy(rot)) == false)) { return new AcceptanceReport("Fishing pier must be placed on water."); } // Check fishing zone is on water. for (int xOffset = -1; xOffset <= 1; xOffset++) { for (int yOffset = 3; yOffset <= 5; yOffset++) { if (IsAquaticTerrain(loc + new IntVec3(xOffset, 0, yOffset).RotatedBy(rot)) == false) { return new AcceptanceReport("Fishing zone must be placed on water."); } } } // Check if another fishing pier is not too close (mind the test on "fishing pier" def and "fishing pier spawner" blueprint and frame defs. List<Thing> fishingPierList = Find.ListerThings.ThingsOfDef(Util_FishIndustry.FishingPierDef); List<Thing> fishingPierSpawnerBlueprintList = Find.ListerThings.ThingsOfDef(Util_FishIndustry.FishingPierSpawnerDef.blueprintDef); List<Thing> fishingPierSpawnerFrameList = Find.ListerThings.ThingsOfDef(Util_FishIndustry.FishingPierSpawnerDef.frameDef); if (fishingPierList != null) { IEnumerable<Thing> fishingPierInTheArea = fishingPierList.Where(building => loc.InHorDistOf(building.Position, minDistanceBetweenTwoFishingPiers)); if (fishingPierInTheArea.Count() > 0) { return new AcceptanceReport("An other fishing pier is too close."); } } if (fishingPierSpawnerBlueprintList != null) { IEnumerable<Thing> fishingPierBlueprintInTheArea = fishingPierSpawnerBlueprintList.Where(building => loc.InHorDistOf(building.Position, minDistanceBetweenTwoFishingPiers)); if (fishingPierBlueprintInTheArea.Count() > 0) { return new AcceptanceReport("An other fishing pier blueprint is too close."); } } if (fishingPierSpawnerFrameList != null) { IEnumerable<Thing> fishingPierFrameInTheArea = fishingPierSpawnerFrameList.Where(building => loc.InHorDistOf(building.Position, minDistanceBetweenTwoFishingPiers)); if (fishingPierFrameInTheArea.Count() > 0) { return new AcceptanceReport("An other fishing pier frame is too close."); } } return true; }
public override AcceptanceReport AllowsPlacing( BuildableDef def, IntVec3 center, Rot4 rot ) { var things = Find.Map.thingGrid.ThingsListAt( center ); if ( things.Exists( s => s is IWallAttachable ) ) { return ResourceBank.WallAlreadyOccupied; } return true; }
public override AcceptanceReport AllowsPlacing(BuildableDef checkingDef, IntVec3 loc, Rot4 rot) { var room = loc.GetRoom(); if( room.ContainedBeds.Any( bed => !bed.ForPrisoners ) ) { return (AcceptanceReport) Data.Strings.NoColonistBeds.Translate(); } return (AcceptanceReport) true; }
public override AcceptanceReport AllowsPlacing(BuildableDef checkingDef, IntVec3 loc, Rot4 rot) { TerrainDef mudDef = DefDatabase<TerrainDef>.GetNamed("Mud"); TerrainDef waterDef = DefDatabase<TerrainDef>.GetNamed("WaterShallow"); if (Find.TerrainGrid.TerrainAt(loc) == mudDef || Find.TerrainGrid.TerrainAt(loc) == waterDef) { return true; } return "OnMudOrWaterReportString".Translate(); }
public static void GenerateLandingPadBottom(IntVec3 areaSouthWestOrigin, int zoneAbs, int zoneOrd, Rot4 rotation, ref OG_OutpostData outpostData) { TerrainDef c = TerrainDefOf.Concrete; TerrainDef mt = TerrainDef.Named("MetalTile"); TerrainDef pt = TerrainDef.Named("PavedTile"); TerrainDef[,] landingPadBottomPattern = new TerrainDef[11, 11] { {null, null, null, null, null, null, null, null, null, null, null}, {null, null, c, c, c, c, c, c, c, null, null}, {null, null, c, mt, mt, mt, mt, mt, c, null, null}, {null, c, c, mt, c, c, c, mt, c, c, null}, {null, c, mt, mt, c, c, c, mt, mt, c, null}, {pt, pt, mt, c, c, c, c, c, mt, pt, pt}, {null, c, mt, mt, c, c, c, mt, mt, c, null}, {c, c, mt, c, c, c, c, c, mt, c, c}, {c, mt, mt, c, c, c, c, c, mt, mt, c}, {c, mt, c, c, c, c, c, c, c, mt, c}, {c, mt, c, c, c, c, c, c, c, mt, c} }; IntVec3 rotatedOrigin = Zone.GetZoneRotatedOrigin(areaSouthWestOrigin, zoneAbs, zoneOrd, rotation); // Spawn floor. for (int xOffset = 0; xOffset <= 10; xOffset++) { for (int zOffset = 0; zOffset <= 10; zOffset++) { TerrainDef terrain = landingPadBottomPattern[zOffset, xOffset]; if (terrain != null) { Find.TerrainGrid.SetTerrain(rotatedOrigin + new IntVec3(xOffset, 0, zOffset).RotatedBy(rotation), terrain); } } } // Spawn landing pad beacons. Building_LandingPadBeacon beacon = OG_Common.TrySpawnThingAt(OG_Util.LandingPadBeaconDef, null, rotatedOrigin + new IntVec3(2, 0, 1).RotatedBy(rotation), false, Rot4.Invalid, ref outpostData) as Building_LandingPadBeacon; beacon = OG_Common.TrySpawnThingAt(OG_Util.LandingPadBeaconDef, null, rotatedOrigin + new IntVec3(8, 0, 1).RotatedBy(rotation), false, Rot4.Invalid, ref outpostData) as Building_LandingPadBeacon; beacon = OG_Common.TrySpawnThingAt(OG_Util.LandingPadBeaconDef, null, rotatedOrigin + new IntVec3(1, 0, 4).RotatedBy(rotation), false, Rot4.Invalid, ref outpostData) as Building_LandingPadBeacon; beacon.SetFlashStartOffset(Building_LandingPadBeacon.flashDurationInTicks); beacon = OG_Common.TrySpawnThingAt(OG_Util.LandingPadBeaconDef, null, rotatedOrigin + new IntVec3(9, 0, 4).RotatedBy(rotation), false, Rot4.Invalid, ref outpostData) as Building_LandingPadBeacon; beacon.SetFlashStartOffset(Building_LandingPadBeacon.flashDurationInTicks); beacon = OG_Common.TrySpawnThingAt(OG_Util.LandingPadBeaconDef, null, rotatedOrigin + new IntVec3(1, 0, 7).RotatedBy(rotation), false, Rot4.Invalid, ref outpostData) as Building_LandingPadBeacon; beacon.SetFlashStartOffset(2 * Building_LandingPadBeacon.flashDurationInTicks); beacon = OG_Common.TrySpawnThingAt(OG_Util.LandingPadBeaconDef, null, rotatedOrigin + new IntVec3(9, 0, 7).RotatedBy(rotation), false, Rot4.Invalid, ref outpostData) as Building_LandingPadBeacon; beacon.SetFlashStartOffset(2 * Building_LandingPadBeacon.flashDurationInTicks); beacon = OG_Common.TrySpawnThingAt(OG_Util.LandingPadBeaconDef, null, rotatedOrigin + new IntVec3(1, 0, 10).RotatedBy(rotation), false, Rot4.Invalid, ref outpostData) as Building_LandingPadBeacon; beacon.SetFlashStartOffset(3 * Building_LandingPadBeacon.flashDurationInTicks); beacon = OG_Common.TrySpawnThingAt(OG_Util.LandingPadBeaconDef, null, rotatedOrigin + new IntVec3(9, 0, 10).RotatedBy(rotation), false, Rot4.Invalid, ref outpostData) as Building_LandingPadBeacon; beacon.SetFlashStartOffset(3 * Building_LandingPadBeacon.flashDurationInTicks); outpostData.landingPadCenter = rotatedOrigin + new IntVec3(5, 0, 10).RotatedBy(rotation); outpostData.landingPadRotation = rotation; }
public override void PostSpawnSetup() { base.PostSpawnSetup(); // This component is already correct, set the operation mode inputDirection = parent.Rotation; outputDirection = new Rot4( ( parent.Rotation.AsInt + 2 ) % 4 ); _processLevel = Level.Surface; _inputLevel = Level.Underground; _outputLevel = Level.Surface; }
public override void DrawGhost( ThingDef def, IntVec3 center, Rot4 rot ) { base.DrawGhost( def, center, rot ); var room = center.GetRoom(); if ( room == null || room.UsesOutdoorTemperature ) { return; } GenDraw.DrawFieldEdges( room.Cells.ToList(), GenTemperature.ColorRoomHot ); }
public override AcceptanceReport AllowsPlacing(BuildableDef checkingDef, IntVec3 loc, Rot4 rot) { ThingDef def = checkingDef as ThingDef; int num = Find.ListerBuildings.allBuildingsColonist.Where((Building b)=>b.def==def).Count(); num += Find.ListerThings.ThingsOfDef(def.blueprintDef).Count; if(num==0) { return AcceptanceReport.WasAccepted; } return "MaximumOneReportString".Translate(); }
public override AcceptanceReport AllowsPlacing(BuildableDef checkingDef, IntVec3 loc, Rot4 rot, Thing thingToIgnore = null) { IEnumerable<IntVec3> cells = GenAdj.CellsOccupiedBy(loc, rot, checkingDef.Size); foreach (IntVec3 cell in cells) { if (!cell.Walkable(Map)) { return "PlaceWorker_RTRequireWalkable".Translate(); } } return true; }
public override AcceptanceReport AllowsPlacing( BuildableDef checkingDef, IntVec3 loc, Rot4 rot ) { foreach( Thing curThing in loc.GetThingList() ) { if( curThing.def.surfaceType != SurfaceType.None ) { return AcceptanceReport.WasAccepted; } } return (AcceptanceReport)( "MessagePlacementItemSurface".Translate() ); }
public override AcceptanceReport AllowsPlacing( BuildableDef checkingDef, IntVec3 loc, Rot4 rot ) { AcceptanceReport result; if( Find.RoofGrid.Roofed( loc ) ) { result = true; } else { result = "MessagePlacementMustBeUnderRoof".Translate(); } return result; }
public override AcceptanceReport AllowsPlacing( BuildableDef checkingDef, IntVec3 loc, Rot4 rot ) { IntVec3 c = loc + rot.FacingCell * -1; if( !c.InBounds() ) { return false; } if( c.GetEdifice() == null ) { return "MessagePlacementAgainstSupport".Translate(); } return true; }
private Thing GetPotentiallySupplantedFacility(ThingDef facilityDef, IntVec3 facilityPos, Rot4 facilityRot) { Thing thing = null; int num = 0; for (int i = 0; i < this.linkedFacilities.Count; i++) { if (this.linkedFacilities[i].def == facilityDef) { if (thing == null) { thing = this.linkedFacilities[i]; } num++; } } if (num == 0) { return(null); } CompProperties_Facility compProperties = facilityDef.GetCompProperties <CompProperties_Facility>(); if (num + 1 <= compProperties.maxSimultaneous) { return(null); } Thing thing2 = thing; for (int j = 0; j < this.linkedFacilities.Count; j++) { if (facilityDef == this.linkedFacilities[j].def) { if (this.IsBetter(thing2.def, thing2.Position, thing2.Rotation, this.linkedFacilities[j])) { thing2 = this.linkedFacilities[j]; } } } return(thing2); }
//public static AcceptanceReport CanPlaceBlueprintAt(BuildableDef entDef, IntVec3 center, Rot4 rot, Map map, bool godMode = false, Thing thingToIgnore = null) public static void Postfix(ref AcceptanceReport __result, BuildableDef entDef, IntVec3 center, Rot4 rot, Map map, bool godMode, Thing thingToIgnore) { if (__result.Reason != "IdenticalThingExists".Translate() && __result.Reason != "IdenticalBlueprintExists".Translate()) { return; } if (!entDef.MadeFromStuff) { return; } ThingDef newStuff = DesignatorContext.stuffDef; //It would not be so easy to transpile this part //it doesn't simply change __result to true when a replace frame can be placed, //it also checks if the replace frame is already there and overrides that with false foreach (Thing thing in center.GetThingList(map)) { if (thing.IsNewThingReplacement(out Thing oldThing)) { __result = false; return; } if (thing != thingToIgnore && thing.Position == center && (thing.Rotation == rot || PlacingRotationDoesntMatter(entDef)) && GenConstruct.BuiltDefOf(thing.def) == entDef) { ThingDef oldStuff = thing is Blueprint bp?bp.EntityToBuildStuff() : thing.Stuff; if (thing is ReplaceFrame rf && oldStuff == newStuff) { __result = false; return; } if (newStuff != oldStuff && GenConstruct.CanBuildOnTerrain(entDef, center, map, rot, thing, newStuff)) { __result = true; } } } }
void TransformAtlas(LayerSubMesh mesh, TextureAtlasGroup group) { var offset = Rot4.FromAngleFlat(target); var offseti = offset.AsInt; var vertsc = mesh.verts.Count / 5 * 4; var uvsc = mesh.uvs.Count; var vertsArr = NoAllocHelpers.ExtractArrayFromListT(mesh.verts); var uvsArr = NoAllocHelpers.ExtractArrayFromListT(mesh.uvs); Util.ResizeIfNeeded(ref tempVerts, vertsc); Util.ResizeIfNeeded(ref tempUVs, uvsc); for (int i = 0; i < vertsc; i += 4) { var data = vertsArr[vertsc + i / 4]; if (data.x == PrintPlanePatch.SPECIAL_X) { ExchangeVerts(tempVerts, vertsArr, i, offseti); var rotData = ((int)data.z & 0b1100) >> 2; var flipData = (int)data.z & 0b0011; var relRot = GenMath.PositiveMod(rotData - Rot4.FromAngleFlat(target).AsInt, 4); var flipped = relRot == 1 && ((flipData & 1) == 1) || relRot == 3 && ((flipData & 2) == 2) ? 1 : 0; var rotatedMat = GraphicPrintPatch_SetData.intToGraphic[(int)data.y].mats[(rotData + Rot4.FromAngleFlat(-target).AsInt) % 4]; Graphic.TryGetTextureAtlasReplacementInfo(rotatedMat, group, false, false, out _, out var uvs, out _); FixUVs( tempUVs, uvs, i, flipped ); } else if (data.x != PrintPlanePatch.EMPTY_X) { RotateVerts(tempVerts, vertsArr, i, data, offset); Array.Copy(uvsArr, i, tempUVs, i, 4); } else { Array.Copy(vertsArr, i, tempVerts, i, 4); Array.Copy(uvsArr, i, tempUVs, i, 4); } } mesh.mesh.SetVertices(tempVerts, vertsc); mesh.mesh.SetUVs(tempUVs, uvsc); }
public override AcceptanceReport AllowsPlacing(BuildableDef checkingDef, IntVec3 loc, Rot4 rot) { foreach (Thing curThing in loc.GetThingList()) { if (curThing.def.surfaceType != SurfaceType.None) { return(AcceptanceReport.WasAccepted); } } return((AcceptanceReport)("MessagePlacementItemSurface".Translate())); }
private bool IsPotentiallyValidFacilityForMe(ThingDef facilityDef, IntVec3 facilityPos, Rot4 facilityRot) { if (!CompAffectedByFacilities.IsPotentiallyValidFacilityForMe_Static(facilityDef, facilityPos, facilityRot, this.parent.def, this.parent.Position, this.parent.Rotation, this.parent.Map)) { return(false); } CompProperties_Facility compProperties = facilityDef.GetCompProperties <CompProperties_Facility>(); if (compProperties.canLinkToMedBedsOnly) { Building_Bed building_Bed = this.parent as Building_Bed; if (building_Bed == null || !building_Bed.Medical) { return(false); } } return(true); }
public override AcceptanceReport AllowsPlacing(BuildableDef checkingDef, IntVec3 loc, Rot4 rot, Map map, Thing thingToIgnore = null) { Thing thing = map.thingGrid.ThingAt(loc, ThingDef.Named("Estate_VeinCoal")); if (thing == null || thing.Position != loc) { return("Estate_MustPlaceOnCoalVein".Translate()); } return(true); }
public Option <IntVec3> InputCell(IntVec3 cell, Map map, Rot4 rot) { return(Option(cell + rot.Opposite.FacingCell)); }
private void MakeBlueprintRoom(CellRect mapRect, Map map, MapGeneratorBlueprintDef blueprint, ThingDef stuffDef) { blueprint.buildingData = CleanUpBlueprintData(blueprint.buildingData); blueprint.floorData = CleanUpBlueprintData(blueprint.floorData); blueprint.pawnData = CleanUpBlueprintData(blueprint.pawnData); blueprint.itemData = CleanUpBlueprintData(blueprint.itemData); if (blueprint.buildingData == null && blueprint.floorData == null) { Log.ErrorOnce(string.Format("Misc. MapGenerator -- After cleaning the BlueprintData and FloorData of blueprint {0} -> both are null, nothing will be done!", blueprint.defName), 313001); return; } IntVec3 spawnBaseCell = new IntVec3(mapRect.BottomLeft.x, mapRect.TopRight.y, mapRect.TopRight.z); IntVec3 spawnCell; foreach (IntVec3 cell in mapRect) { // Check all cells and abort if there is something indestructible found if (!CheckCell(cell, map)) { return; } } allSpawnedPawns = null; try { // Work through blueprint. Note: top-left to bottom-right for (int zn = 0; zn < blueprint.size.z; zn++) { for (int x = 0; x < blueprint.size.x; x++) { //// map can be clipped, don't work with the clipped parts //if (x > mapRect.Width - 1 || zn > mapRect.Height - 1) // continue; spawnCell = spawnBaseCell + new IntVec3(x, 0, -zn); int itemPos = x + blueprint.size.x * zn; ThingDef thingDef = TryGetThingDefFromBuildingData(blueprint, itemPos); Rot4 thingRot = TryGetRotationFromBuildingData(blueprint, itemPos); TerrainDef terrainDef = TryGetTerrainDefFromFloorData(blueprint, itemPos); PawnKindDef pawnKindDef = TryGetPawnKindDefFromPawnData(blueprint, itemPos); ThingDef itemDef = TryGetItemDefFromItemData(blueprint, itemPos); List <Thing> list = map.thingGrid.ThingsListAt(spawnCell); for (int i = 0; i < list.Count; i++) { if (list[i].def == thingDef) { continue; } } //Only clear the space, if something will be made here if (thingDef != null || terrainDef != null || pawnKindDef != null || itemDef != null) { ClearCell(spawnCell, map); } if ((blueprint.canHaveHoles || (MapGenerator_ModSettings.createAllNonPawnBPsWithHoles && (blueprint.pawnLegend == null || blueprint.pawnLegend.Count <= 0))) && Rand.Value < MapGenerator_ModSettings.chanceForHoles) { continue; } // If placed on water, increase the hole chance, if no pawns are to be placed! if (spawnCell.GetTerrain(map).defName.ToLower().Contains("water") && (blueprint.pawnLegend == null || blueprint.pawnLegend.Count <= 0) && Rand.Value < MapGenerator_ModSettings.chanceForHolesOnWater) { continue; } TrySetCellAs(spawnCell, map, thingDef, thingRot, stuffDef, terrainDef, pawnKindDef, itemDef, blueprint); } } } catch (Exception ex) { Log.Warning("Misc. MapGenerator -- Error with blueprint '" + blueprint.defName + "'. Placement position at " + mapRect.CenterCell.ToString() + " on a map of the size " + map.Size.ToString() + "\n" + ex.Message + "\n" + ex.StackTrace); } // If pawns are spawned, place ancient shrine trigger if (allSpawnedPawns != null && allSpawnedPawns.Count > 0) { int nextSignalTagID = Find.UniqueIDsManager.GetNextSignalTagID(); string signalTag = "ancientTempleApproached-" + nextSignalTagID; SignalAction_Letter signalAction_Letter = (SignalAction_Letter)ThingMaker.MakeThing(ThingDefOf.SignalAction_Letter, null); signalAction_Letter.signalTag = signalTag; signalAction_Letter.letter = LetterMaker.MakeLetter("LetterLabelAncientShrineWarning".Translate(), "AncientShrineWarning".Translate(), LetterDefOf.NeutralEvent, new TargetInfo(mapRect.CenterCell, map, false)); GenSpawn.Spawn(signalAction_Letter, mapRect.CenterCell, map); RectTrigger rectTrigger = (RectTrigger)ThingMaker.MakeThing(ThingDefOf.RectTrigger, null); rectTrigger.signalTag = signalTag; rectTrigger.Rect = mapRect.ExpandedBy(1).ClipInsideMap(map); rectTrigger.destroyIfUnfogged = true; GenSpawn.Spawn(rectTrigger, mapRect.CenterCell, map); } // also if pawns are spawned make the appropriate LordJob LordJob lordJob; if (allSpawnedPawns != null && allSpawnedPawns.Count > 0) { //Log.Error("Spawned faction: "+ allSpawnedPawns[0].Faction.ToString()); try { if (blueprint.factionSelection == FactionSelection.friendly) { lordJob = new LordJob_AssistColony(allSpawnedPawns[0].Faction, allSpawnedPawns[0].Position); } else { if (Rand.Value < 0.5f) { lordJob = new LordJob_DefendPoint(allSpawnedPawns[0].Position); } else { lordJob = new LordJob_AssaultColony(allSpawnedPawns[0].Faction, false, false, false, false, false); } } LordMaker.MakeNewLord(allSpawnedPawns[0].Faction, lordJob, map, allSpawnedPawns); } catch (Exception ex) { Log.Warning("Misc. MapGenerator -- Error with LordMaker for blueprint '" + blueprint.defName + "'." + "\n" + ex.Message + "\n" + ex.StackTrace); } allSpawnedPawns = null; } }
private static void RenderFacepaint(PawnRenderer instance, bool hideFacepaint, RotDrawMode bodyDrawType, PawnRenderFlags flags, Rot4 headFacing, Vector3 baseDrawPos, Quaternion quaternion) { var pawn = instance.graphics.pawn; if (bodyDrawType != RotDrawMode.Dessicated && !flags.FlagSet(PawnRenderFlags.HeadStump) && pawn.GetComp <CompFacepaint>() is CompFacepaint facepaintComp) { Mesh mesh = instance.graphics.HairMeshSet.MeshAt(headFacing); if (facepaintComp.facepaintGraphicOne != null) { GenDraw.DrawMeshNowOrLater(mesh, baseDrawPos - new Vector3(0, 0.0007f, 0), quaternion, facepaintComp.facepaintGraphicOne.MatAt(headFacing), flags.FlagSet(PawnRenderFlags.DrawNow)); } if (facepaintComp.facepaintGraphicTwo != null) { GenDraw.DrawMeshNowOrLater(mesh, baseDrawPos - new Vector3(0, 0.0005f, 0), quaternion, facepaintComp.facepaintGraphicTwo.MatAt(headFacing), flags.FlagSet(PawnRenderFlags.DrawNow)); } } }
// Fill the cell private void TrySetCellAs(IntVec3 c, Map map, ThingDef thingDef, Rot4 thingRot, ThingDef stuffDef = null, TerrainDef terrainDef = null, PawnKindDef pawnKindDef = null, ThingDef itemDef = null, MapGeneratorBlueprintDef blueprint = null) { //Note: Here is no functionality to clear the cell by design, because it is possible to place items that are larger than 1x1 // Check the cell information if (c == null || !c.InBounds(map)) { Log.Warning("GenStep_CreateBlueprint: Invalid Target-Cell: cell is null or out of bounds."); return; } // only continue to do work if here isn't anything indestructable List <Thing> thingList = c.GetThingList(map); for (int i = 0; i < thingList.Count; i++) { if (!thingList[i].def.destroyable) { return; } } // 1st step - work with the Terrain if (terrainDef != null) { map.terrainGrid.SetTerrain(c, terrainDef); } else if (terrainDef == null && thingDef != null && stuffDef != null) { map.terrainGrid.SetTerrain(c, this.CorrespondingTileDef(stuffDef)); } // 2nd step - work with the Thing (Buildings) if (thingDef != null) { ThingDef stuffDef1 = stuffDef; if (!thingDef.MadeFromStuff) { stuffDef1 = null; } Thing newThing = ThingMaker.MakeThing(thingDef, stuffDef1); if (thingRot == null || thingRot == Rot4.Invalid) { GenSpawn.Spawn(newThing, c, map); } else { GenSpawn.Spawn(newThing, c, map, thingRot); } CompGatherSpot compGathering = newThing.TryGetComp <CompGatherSpot>(); if (compGathering != null) { compGathering.Active = false; } } // The following needs blueprint data to work if (blueprint == null) { return; } // 3rd step - work with the Item //if (itemDef != null) // && blueprint.itemSpawnChance / 100 > Rand.Value) if (itemDef != null && blueprint.itemSpawnChance / 100 > Rand.Value) { ThingDef stuffDef2; if (itemDef.IsApparel) { if (!DefDatabase <ThingDef> .AllDefs.Where <ThingDef>(t => t.IsStuff && t.stuffProps != null && t.stuffProps.categories != null && t.stuffProps.categories.Contains(StuffCategoryDefOf.Fabric)) .TryRandomElement(out stuffDef2)) { stuffDef2 = DefDatabase <ThingDef> .GetNamedSilentFail("Synthread"); } } else { List <string> stuffPossibles = new List <string>() { "Steel", "Steel", "Steel", "Steel", "Silver", "Gold", "Jade", "Plasteel" }; stuffDef2 = DefDatabase <ThingDef> .GetNamedSilentFail(stuffPossibles.RandomElement()); } if (!itemDef.MadeFromStuff) { stuffDef2 = null; } Thing newItem = TryGetTreasure(itemDef, stuffDef2); newItem = GenSpawn.Spawn(newItem, c, map); // Don't forget to set the items to forbidden! if (newItem.TryGetComp <CompForbiddable>() != null) { newItem.SetForbidden(true, false); } // If it is a hive, it needs to be deactivated Hive newHive = newItem as Hive; //if (newHive != null) //{ // newHive..active = false; //} } // 4th step - work with the Pawn if (pawnKindDef != null && blueprint.pawnSpawnChance / 100 > Rand.Value) { if (this.faction == null) { this.faction = Find.FactionManager.FirstFactionOfDef(blueprint.factionDef); } float pointsForRaid = map.IncidentPointsRandomFactorRange.RandomInRange; // still null - find a valid faction. if (this.faction == null) { switch (blueprint.factionSelection) { case FactionSelection.friendly: faction = (from fac in Find.FactionManager.AllFactions where !fac.HostileTo(Faction.OfPlayer) && fac.PlayerGoodwill > 0 && !(fac == Faction.OfPlayer) select fac) .RandomElementByWeight((Faction fac) => 101 - fac.def.RaidCommonalityFromPoints(pointsForRaid)); if (faction == null) { faction = Find.FactionManager.AllFactions.RandomElementByWeight((Faction fac) => fac.def.RaidCommonalityFromPoints(pointsForRaid)); } break; case FactionSelection.hostile: faction = (from fac in Find.FactionManager.AllFactions where fac.HostileTo(Faction.OfPlayer) select fac) .RandomElementByWeight((Faction fac) => 101 - fac.def.RaidCommonalityFromPoints(pointsForRaid)); if (faction == null) { faction = Faction.OfMechanoids; } break; case FactionSelection.none: faction = Find.FactionManager.AllFactions .RandomElementByWeight((Faction fac) => fac.def.RaidCommonalityFromPoints(pointsForRaid)); if (faction == null) { faction = Faction.OfMechanoids; } break; } } Pawn pawn = PawnGenerator.GeneratePawn(pawnKindDef, faction); pawn.mindState.Active = false; pawn = GenSpawn.Spawn(pawn, c, map) as Pawn; if (pawn != null) { if (allSpawnedPawns == null) { allSpawnedPawns = new List <Pawn>(); } allSpawnedPawns.Add(pawn); } } }
public static IntVec3 MiddleEdgeCell(Rot4 dir, Map map, Pawn pawn, Predicate <IntVec3> validator) { List <IntVec3> cellsToCheck = CellRect.WholeMap(map).GetEdgeCells(dir).ToList(); bool riverSpawn = Find.World.CoastDirectionAt(map.Tile) != dir && !Find.WorldGrid[map.Tile].Rivers.NullOrEmpty(); int padding = (pawn.def.size.z / 2) > 4 ? (pawn.def.size.z / 2 + 1) : 4; int startIndex = cellsToCheck.Count / 2; bool riverSpawnValidator(IntVec3 x) => map.terrainGrid.TerrainAt(x) == TerrainDefOf.WaterMovingChestDeep || map.terrainGrid.TerrainAt(x) == TerrainDefOf.WaterMovingShallow; for (int j = 0; j < 10000; j++) { IntVec3 c = pawn.ClampToMap(CellFinder.RandomEdgeCell(dir, map), map, padding); List <IntVec3> occupiedCells = pawn.PawnOccupiedCells(c, dir.Opposite); foreach (IntVec3 cAll in occupiedCells) { if (VehicleHarmony.debug && cAll != c) { GenSpawn.Spawn(ThingDefOf.Beer, cAll, map); } if (!validator(cAll) || (riverSpawn && !riverSpawnValidator(cAll))) { goto Block_Skip; } } Debug.Message("Found: " + c); return(c); Block_Skip :; } Log.Warning("Running secondary spawn cell check for boats"); int i = 0; while (cellsToCheck.Count > 0 && i < cellsToCheck.Count / 2) { if (i > cellsToCheck.Count) { Log.Warning("List of Cells almost went out of bounds. Report to Boats mod author - Smash Phil"); break; } IntVec3 rCell = pawn.ClampToMap(cellsToCheck[startIndex + i], map, padding); Debug.Message("Checking right: " + rCell + " | " + validator(rCell)); List <IntVec3> occupiedCellsRCell = pawn.PawnOccupiedCells(rCell, dir.Opposite); foreach (IntVec3 c in occupiedCellsRCell) { if (!validator(c)) { goto Block_0; } } return(rCell); Block_0 :; IntVec3 lCell = pawn.ClampToMap(cellsToCheck[startIndex - i], map, padding); Debug.Message("Checking left: " + lCell + " | " + validator(lCell)); List <IntVec3> occupiedCellsLCell = pawn.PawnOccupiedCells(lCell, dir.Opposite); foreach (IntVec3 c in occupiedCellsLCell) { if (!validator(c)) { goto Block_1; } } return(lCell); Block_1 :; i++; Debug.Message("=============="); } Log.Error("Could not find valid edge cell to spawn boats on. This could be due to the Boat being too large to spawn on the coast of a Mountainous Map."); return(pawn.ClampToMap(CellFinder.RandomEdgeCell(dir, map), map, padding)); }
/// <summary> /// Checks if a new force field generator can be built at this location. /// - must not be too near from another force field generator (or it would perturb other fields). /// </summary> public override AcceptanceReport AllowsPlacing(BuildableDef checkingDef, IntVec3 loc, Rot4 rot, Thing thingToIgnore = null) { // Check if another force field generator is not too close. List <Thing> forceFieldGeneratorList = new List <Thing>(); IEnumerable <Thing> list = this.Map.listerThings.ThingsOfDef(ThingDef.Named("ForceFieldGenerator")); foreach (Thing generator in list) { forceFieldGeneratorList.Add(generator); } list = this.Map.listerThings.ThingsOfDef(ThingDef.Named("ForceFieldGenerator").blueprintDef); foreach (Thing generator in list) { forceFieldGeneratorList.Add(generator); } list = this.Map.listerThings.ThingsOfDef(ThingDef.Named("ForceFieldGenerator").frameDef); foreach (Thing generator in list) { forceFieldGeneratorList.Add(generator); } foreach (Thing generator in forceFieldGeneratorList) { if (generator.Position.InHorDistOf(loc, minDistanceBetweenTwoForceFieldGenerators)) { return(new AcceptanceReport("An other force field generator is too close (would generate perturbations).")); } } // Display effect zone. List <IntVec3> coveredCells = Building_ForceFieldGenerator.GetCoveredCells(loc, rot); GenDraw.DrawFieldEdges(coveredCells); return(true); }
public IEnumerable <IntVec3> OutputZoneCells(IntVec3 cell, Map map, Rot4 rot) { return(OutputCell(cell, map, rot).Select(c => c.SlotGroupCells(map)).GetOrDefault(EmptyList)); }
public virtual Vector3 EarOffset(Rot4 headFacing) { return(Vector3.zero); }
public Option <IntVec3> OutputCell(IntVec3 cell, Map map, Rot4 rot) { return(Option(cell + rot.FacingCell)); }
public CellRectRot(CellRect newRect, Rot4 newRot) { Rect = newRect; Rot = newRot; }
public Color GetColor(IntVec3 cell, Map map, Rot4 rot, CellPattern cellPattern) { return(cellPattern.ToColor()); }
public void InitializeLandingData(IntVec3 position, Rot4 rotation) { this.landingPadPosition = position; this.landingPadRotation = rotation; }
public virtual void Tick(Rot4 bodyFacing, Rot4 headFacing, PawnGraphicSet graphics) { this.Graphics = graphics; this.BodyFacing = bodyFacing; this.HeadFacing = headFacing; }
public static bool CanPotentiallyLinkTo_Static(Thing facility, ThingDef myDef, IntVec3 myPos, Rot4 myRot) { return(CompAffectedByFacilities.CanPotentiallyLinkTo_Static(facility.def, facility.Position, facility.Rotation, myDef, myPos, myRot) && CompAffectedByFacilities.IsPotentiallyValidFacilityForMe_Static(facility, myDef, myPos, myRot)); }
public static IEnumerable <Thing> PotentialThingsToLinkTo(ThingDef myDef, IntVec3 myPos, Rot4 myRot, Map map) { CompAffectedByFacilities.alreadyReturnedCount.Clear(); CompProperties_AffectedByFacilities myProps = myDef.GetCompProperties <CompProperties_AffectedByFacilities>(); if (myProps.linkableFacilities == null) { yield break; } IEnumerable <Thing> candidates = Enumerable.Empty <Thing>(); for (int i = 0; i < myProps.linkableFacilities.Count; i++) { candidates = candidates.Concat(map.listerThings.ThingsOfDef(myProps.linkableFacilities[i])); } Vector3 myTrueCenter = GenThing.TrueCenter(myPos, myRot, myDef.size, myDef.Altitude); IOrderedEnumerable <Thing> sortedCandidates = from x in candidates orderby Vector3.Distance(myTrueCenter, x.TrueCenter()), x.Position.x, x.Position.z select x; foreach (Thing th in sortedCandidates) { if (CompAffectedByFacilities.CanPotentiallyLinkTo_Static(th, myDef, myPos, myRot)) { CompProperties_Facility facilityProps = th.def.GetCompProperties <CompProperties_Facility>(); if (CompAffectedByFacilities.alreadyReturnedCount.ContainsKey(th.def)) { if (CompAffectedByFacilities.alreadyReturnedCount[th.def] >= facilityProps.maxSimultaneous) { continue; } } else { CompAffectedByFacilities.alreadyReturnedCount.Add(th.def, 0); } Dictionary <ThingDef, int> dictionary; ThingDef def; (dictionary = CompAffectedByFacilities.alreadyReturnedCount)[def = th.def] = dictionary[def] + 1; yield return(th); } } yield break; }
public virtual Quaternion QuatHead(Rot4 rotation) { return(rotation.AsQuat); }
public override AcceptanceReport AllowsPlacing(BuildableDef checkingDef, IntVec3 loc, Rot4 rot, Map map, Thing thingToIgnore = null, Thing thing = null) { for (int i = 0; i < 4; i++) { IntVec3 intVec3 = loc + GenAdj.CardinalDirections[i]; if (intVec3.InBounds(map)) { List <Thing> thingList = intVec3.GetThingList(map); for (int j = 0; j < thingList.Count; j++) { Thing item = thingList[j]; ThingDef thingDef = GenConstruct.BuiltDefOf(item.def) as ThingDef; if (thingDef != null && thingDef.building != null) { if (thingDef.defName == NanoPrinterDef) { return(true); } } } } } return(txtMustPlaceNextToNanoPrinter.Translate()); }
public static void DrawLinesToPotentialThingsToLinkTo(ThingDef myDef, IntVec3 myPos, Rot4 myRot, Map map) { Vector3 a = GenThing.TrueCenter(myPos, myRot, myDef.size, myDef.Altitude); foreach (Thing t in CompAffectedByFacilities.PotentialThingsToLinkTo(myDef, myPos, myRot, map)) { GenDraw.DrawLineBetween(a, t.TrueCenter()); } }
static void RotateVerts(Vector3[] tempVerts, Vector3[] vertsArr, int i, Vector3 c, Rot4 offset) { tempVerts[i] = c + (vertsArr[i] - c).RotatedBy(offset); tempVerts[i + 1] = c + (vertsArr[i + 1] - c).RotatedBy(offset); tempVerts[i + 2] = c + (vertsArr[i + 2] - c).RotatedBy(offset); tempVerts[i + 3] = c + (vertsArr[i + 3] - c).RotatedBy(offset); }
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 result = 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)) { return(true); } } } } } return(result); }
public override AcceptanceReport AllowsPlacing(BuildableDef checkingDef, IntVec3 loc, Rot4 rot, Map map, Thing thingToIgnore = null, Thing thing = null) { List <Thing> thingList = loc.GetThingList(map); for (int i = 0; i < thingList.Count; i++) { if (thingList[i].def.HasComp(typeof(CompPipe)) || thingList[i].def.HasComp(typeof(CompPipeTank)) || thingList[i].def.HasComp(typeof(CompPipeTrader)) || thingList[i].def.HasComp(typeof(CompPipeTransmitter)) || thingList[i].def.HasComp(typeof(CompPipePlant))) { return(false); } if (thingList[i].def.EverTransmitsPower) { return(false); } if (thingList[i].def.entityDefToBuild != null) { ThingDef thingDef = thingList[i].def.entityDefToBuild as ThingDef; if (thingDef != null && thingDef.EverTransmitsPower) { return(false); } } } return(true); }
public void DrawRedLineToPotentiallySupplantedFacility(ThingDef facilityDef, IntVec3 facilityPos, Rot4 facilityRot) { Thing potentiallySupplantedFacility = this.GetPotentiallySupplantedFacility(facilityDef, facilityPos, facilityRot); if (potentiallySupplantedFacility != null) { GenDraw.DrawLineBetween(this.parent.TrueCenter(), potentiallySupplantedFacility.TrueCenter(), CompAffectedByFacilities.InactiveFacilityLineMat); } }
public static bool CanPotentiallyLinkTo_Static(ThingDef facilityDef, IntVec3 facilityPos, Rot4 facilityRot, ThingDef myDef, IntVec3 myPos, Rot4 myRot) { CompProperties_Facility compProperties = facilityDef.GetCompProperties <CompProperties_Facility>(); if (compProperties.mustBePlacedAdjacent) { CellRect rect = GenAdj.OccupiedRect(myPos, myRot, myDef.size); CellRect rect2 = GenAdj.OccupiedRect(facilityPos, facilityRot, facilityDef.size); if (!GenAdj.AdjacentTo8WayOrInside(rect, rect2)) { return(false); } } if (compProperties.mustBePlacedAdjacentCardinalToBedHead) { if (!myDef.IsBed) { return(false); } CellRect other = GenAdj.OccupiedRect(facilityPos, facilityRot, facilityDef.size); bool flag = false; int sleepingSlotsCount = BedUtility.GetSleepingSlotsCount(myDef.size); for (int i = 0; i < sleepingSlotsCount; i++) { IntVec3 sleepingSlotPos = BedUtility.GetSleepingSlotPos(i, myPos, myRot, myDef.size); if (sleepingSlotPos.IsAdjacentToCardinalOrInside(other)) { flag = true; } } if (!flag) { return(false); } } if (!compProperties.mustBePlacedAdjacent && !compProperties.mustBePlacedAdjacentCardinalToBedHead) { Vector3 a = GenThing.TrueCenter(myPos, myRot, myDef.size, myDef.Altitude); Vector3 b = GenThing.TrueCenter(facilityPos, facilityRot, facilityDef.size, facilityDef.Altitude); if (Vector3.Distance(a, b) > compProperties.maxDistance) { return(false); } } return(true); }
private static bool IsPotentiallyValidFacilityForMe_Static(Thing facility, ThingDef myDef, IntVec3 myPos, Rot4 myRot) { return(CompAffectedByFacilities.IsPotentiallyValidFacilityForMe_Static(facility.def, facility.Position, facility.Rotation, myDef, myPos, myRot, facility.Map)); }