Beispiel #1
0
        public static IPlantToGrowSettable GetPlayerSetPlantForCell(IntVec3 cell)
        {
            IPlantToGrowSettable plantToGrowSettable = cell.GetEdifice() as IPlantToGrowSettable;
            if (plantToGrowSettable == null)
                plantToGrowSettable = Find.ZoneManager.ZoneAt(cell) as IPlantToGrowSettable;

            return plantToGrowSettable;
        }
Beispiel #2
0
        private bool IsWaterOrDeck(IntVec3 cell)
        {
            if (terrains.Keys.Contains(cell))
            {
                return(true);
            }
            var def = cell.GetTerrain(map);

            if (def.IsWater)
            {
                var edifice = cell.GetEdifice(map);
                if (edifice == null)
                {
                    return(true);
                }
            }
            return(false);
        }
Beispiel #3
0
        private bool PawnCanOccupy(IntVec3 c)
        {
            if (!c.Walkable(this.pawn.Map))
            {
                return(false);
            }
            Building edifice = c.GetEdifice(this.pawn.Map);

            if (edifice != null)
            {
                Building_Door building_Door = edifice as Building_Door;
                if (building_Door != null && !building_Door.PawnCanOpen(this.pawn) && !building_Door.Open)
                {
                    return(false);
                }
            }
            return(true);
        }
        public bool AlreadyVisibleNearby(IntVec3 center, Map map, ThingDef mineableDef)
        {
            CellRect cellRect = CellRect.CenteredOn(center, 1);

            for (int i = 1; i < MineStrikeManager.RadialVisibleCells; i++)
            {
                IntVec3 c = center + GenRadial.RadialPattern[i];
                if (c.InBounds(map) && !c.Fogged(map) && !cellRect.Contains(c))
                {
                    Building edifice = c.GetEdifice(map);
                    if (edifice != null && edifice.def == mineableDef)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Beispiel #5
0
        public override AcceptanceReport AllowsPlacing(BuildableDef checkingDef, IntVec3 loc, Rot4 rot, Map map, Thing thingToIgnore = null, Thing thing = null)
        {
            Building buil = loc.GetEdifice(map);

            if (!loc.InBounds(map))
            {
                return(false);
            }
            if (!PlaceWorkerUtility.IsWall(buil) || buil.Faction != Faction.OfPlayer)
            {
                return(new AcceptanceReport("D9F_MustBePlacedOnWall".Translate(checkingDef.LabelCap)));
            }
            if (PlaceWorkerUtility.ConflictingThing(checkingDef, loc, rot, map))
            {
                return(new AcceptanceReport("IdenticalThingExists".Translate()));
            }
            return(true);
        }
Beispiel #6
0
        public override AcceptanceReport AllowsPlacing(BuildableDef checkingDef, IntVec3 loc, Rot4 rot, Map map, Thing thingToIgnore = null)
        {
            var def = loc.GetEdifice(map)?.def;

            if (def != null && def.IsSmoothed)
            {
                return(AcceptanceReport.WasAccepted);
            }

            var linkFlags = def?.graphicData?.linkFlags;

            if (linkFlags != null && (linkFlags & LinkFlags.Wall) != 0)
            {
                return(AcceptanceReport.WasAccepted);
            }

            return(ResourceBank.Strings.PlacementMustBeOnWall);
        }
        private Building BuildingToTouchToBeAbleToBuildRoof(IntVec3 c, Pawn pawn)
        {
            if (c.Standable(pawn.Map))
            {
                return(null);
            }
            Building edifice = c.GetEdifice(pawn.Map);

            if (edifice == null)
            {
                return(null);
            }
            if (!pawn.CanReach(edifice, PathEndMode.Touch, pawn.NormalMaxDanger(), false, TraverseMode.ByPawn))
            {
                return(null);
            }
            return(edifice);
        }
 public static bool InGatheringArea(IntVec3 cell, IntVec3 partySpot, Map map)
 {
     if (UseWholeRoomAsGatheringArea(partySpot, map) && cell.GetRoom(map) == partySpot.GetRoom(map))
     {
         return(true);
     }
     if (cell.InHorDistOf(partySpot, 10f))
     {
         Building      edifice        = cell.GetEdifice(map);
         TraverseParms traverseParams = TraverseParms.For(TraverseMode.NoPassClosedDoors, Danger.None);
         if (edifice != null)
         {
             return(map.reachability.CanReach(partySpot, edifice, PathEndMode.ClosestTouch, traverseParams));
         }
         return(map.reachability.CanReach(partySpot, cell, PathEndMode.ClosestTouch, traverseParams));
     }
     return(false);
 }
        private static Building GetCorrectlyRotatedChairAt(IntVec3 x, Map map, CellRect spectateRect)
        {
            if (!x.InBounds(map))
            {
                return(null);
            }
            Building edifice = x.GetEdifice(map);

            if (edifice == null || edifice.def.category != ThingCategory.Building || !edifice.def.building.isSittable)
            {
                return(null);
            }
            if (GenGeo.AngleDifferenceBetween(edifice.Rotation.AsAngle, (spectateRect.ClosestCellTo(x) - edifice.Position).AngleFlat) > 75f)
            {
                return(null);
            }
            return(edifice);
        }
Beispiel #10
0
 public static void Notify_SmoothedByPawn(Thing t, Pawn p)
 {
     for (int i = 0; i < GenAdj.CardinalDirections.Length; i++)
     {
         IntVec3 c = t.Position + GenAdj.CardinalDirections[i];
         if (!c.InBounds(t.Map))
         {
             continue;
         }
         Building edifice = c.GetEdifice(t.Map);
         if (edifice == null || !edifice.def.IsSmoothable)
         {
             continue;
         }
         bool flag = true;
         int  num  = 0;
         for (int j = 0; j < GenAdj.CardinalDirections.Length; j++)
         {
             IntVec3 intVec = edifice.Position + GenAdj.CardinalDirections[j];
             if (!IsBlocked(intVec, t.Map))
             {
                 flag = false;
                 break;
             }
             Building edifice2 = intVec.GetEdifice(t.Map);
             if (edifice2 != null && edifice2.def.IsSmoothed)
             {
                 num++;
             }
         }
         if (!flag || num < 2)
         {
             continue;
         }
         for (int k = 0; k < GenAdj.DiagonalDirections.Length; k++)
         {
             if (!IsBlocked(edifice.Position + GenAdj.DiagonalDirections[k], t.Map))
             {
                 SmoothWall(edifice, p);
                 break;
             }
         }
     }
 }
 public static void Postfix(PathGrid __instance, IntVec3 c, bool perceivedStatic, IntVec3 prevCell, Map ___map, ref int __result)
 {
     if (__result == 10000)
     {
         Building_Window window = c.GetEdifice(___map) as Building_Window;
         if (window != null)
         {
             int cost = 10;
             if (perceivedStatic)
             {
                 for (int j = 0; j < 9; j++)
                 {
                     IntVec3 intVec = GenAdj.AdjacentCellsAndInside[j];
                     IntVec3 c2     = c + intVec;
                     if (c2.InBounds(___map))
                     {
                         Fire         fire = null;
                         List <Thing> list = ___map.thingGrid.ThingsListAtFast(c2);
                         for (int k = 0; k < list.Count; k++)
                         {
                             fire = (list[k] as Fire);
                             if (fire != null)
                             {
                                 break;
                             }
                         }
                         if (fire != null && fire.parent == null)
                         {
                             if (intVec.x == 0 && intVec.z == 0)
                             {
                                 cost += 1000;
                             }
                             else
                             {
                                 cost += 150;
                             }
                         }
                     }
                 }
             }
             __result = cost;
         }
     }
 }
        private Job DeconstructExistingEdificeJob(Pawn pawn, Blueprint blue)
        {
            if (!blue.def.entityDefToBuild.IsEdifice())
            {
                return(null);
            }
            Thing    thing    = null;
            CellRect cellRect = blue.OccupiedRect();

            for (int i = cellRect.minZ; i <= cellRect.maxZ; i++)
            {
                int j = cellRect.minX;
                while (j <= cellRect.maxX)
                {
                    IntVec3 c = new IntVec3(j, 0, i);
                    thing = c.GetEdifice();
                    if (thing != null)
                    {
                        ThingDef thingDef = blue.def.entityDefToBuild as ThingDef;
                        if (thingDef != null && thingDef.building.canPlaceOverWall && thing.def == ThingDefOf.Wall)
                        {
                            return(null);
                        }
                        break;
                    }
                    else
                    {
                        j++;
                    }
                }
                if (thing != null)
                {
                    break;
                }
            }
            if (thing == null || !pawn.CanReserve(thing, 1))
            {
                return(null);
            }
            return(new Job(JobDefOf.Deconstruct, thing)
            {
                ignoreDesignations = true
            });
        }
        public override AcceptanceReport CanDesignateCell(IntVec3 c)
        {
            AcceptanceReport result;

            if (!c.InBounds(Map))
            {
                result = false;
            }
            else if (c.Fogged(Map))
            {
                result = false;
            }
            else if (Map.designationManager.DesignationAt(c, QuarryDefOf.QRY_Designator_ReclaimSoil) != null ||
                     Map.designationManager.DesignationAt(c, DesignationDefOf.SmoothFloor) != null)
            {
                result = false;
            }
            else if (c.InNoBuildEdgeArea(Map))
            {
                result = "TooCloseToMapEdge".Translate();
            }
            else
            {
                Building edifice = c.GetEdifice(Map);
                if (edifice != null && (edifice.def.Fillage == FillCategory.Full || edifice.def.passability == Traversability.Impassable))
                {
                    result = false;
                }
                else
                {
                    TerrainDef terrain = c.GetTerrain(Map);
                    if (terrain != QuarryDefOf.QRY_QuarriedGround)
                    {
                        result = Static.MessageMustDesignateQuarriedGround;
                    }
                    else
                    {
                        result = AcceptanceReport.WasAccepted;
                    }
                }
            }
            return(result);
        }
Beispiel #14
0
        public override void DesignateSingleCell(IntVec3 c)
        {
            Building edifice = c.GetEdifice(base.Map);

            if (edifice != null && edifice.def.IsSmoothable)
            {
                Faction faction = edifice.Faction;
                edifice.Destroy(DestroyMode.WillReplace);
                Thing thing = ThingMaker.MakeThing(edifice.def.building.smoothedThing, edifice.Stuff);
                thing.SetFaction(faction, null);
                GenSpawn.Spawn(thing, edifice.Position, Map, edifice.Rotation, WipeMode.Vanish, false);
                Map.designationManager.TryRemoveDesignation(c, DesignationDefOf.SmoothWall);
            }
            else
            {
                this.Map.terrainGrid.SetTerrain(c, this.Map.terrainGrid.TerrainAt(c).smoothedTerrain);
                Map.designationManager.TryRemoveDesignation(c, DesignationDefOf.SmoothFloor);
            }
        }
        public static bool ValidJumpTarget(Map map, IntVec3 cell)
        {
            if (!cell.IsValid || !cell.InBounds(map))
            {
                return(false);
            }
            if (cell.Impassable(map) || !cell.Walkable(map) || cell.Fogged(map))
            {
                return(false);
            }
            Building      edifice = cell.GetEdifice(map);
            Building_Door building_Door;

            if (edifice != null && (building_Door = (edifice as Building_Door)) != null && !building_Door.Open)
            {
                return(false);
            }
            return(true);
        }
        private bool CanTraverse(IntVec3 c, bool canPathThroughNonStandable)
        {
            Map      map     = BaseGen.globalSettings.map;
            Building edifice = c.GetEdifice(map);

            if (IsWallOrRock(edifice))
            {
                return(true);
            }
            if (!canPathThroughNonStandable && !c.Standable(map))
            {
                return(false);
            }
            if (!c.Impassable(map))
            {
                return(true);
            }
            return(false);
        }
        private static bool IsBlocked(IntVec3 pos, Map map)
        {
            bool result;

            if (!pos.InBounds(map))
            {
                result = false;
            }
            else if (pos.Walkable(map))
            {
                result = false;
            }
            else
            {
                Building edifice = pos.GetEdifice(map);
                result = (edifice != null && (edifice.def.IsSmoothed || edifice.def.building.isNaturalRock));
            }
            return(result);
        }
Beispiel #18
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            if (!pawn.HostileTo(Faction.OfPlayer))
            {
                return(null);
            }
            bool     flag     = pawn.natives.IgniteVerb != null && pawn.HostileTo(Faction.OfPlayer);
            CellRect cellRect = CellRect.CenteredOn(pawn.Position, 5);

            for (int i = 0; i < 35; i++)
            {
                IntVec3 randomCell = cellRect.RandomCell;
                if (randomCell.InBounds(pawn.Map))
                {
                    Building edifice = randomCell.GetEdifice(pawn.Map);
                    if (edifice != null && TrashUtility.ShouldTrashBuilding(pawn, edifice, false) && GenSight.LineOfSight(pawn.Position, randomCell, pawn.Map, false, null, 0, 0))
                    {
                        if (DebugViewSettings.drawDestSearch && Find.VisibleMap == pawn.Map)
                        {
                            Find.VisibleMap.debugDrawer.FlashCell(randomCell, 1f, "trash bld", 50);
                        }
                        return(TrashUtility.TrashJob(pawn, edifice));
                    }
                    if (flag)
                    {
                        Plant plant = randomCell.GetPlant(pawn.Map);
                        if (plant != null && TrashUtility.ShouldTrashPlant(pawn, plant) && GenSight.LineOfSight(pawn.Position, randomCell, pawn.Map, false, null, 0, 0))
                        {
                            if (DebugViewSettings.drawDestSearch && Find.VisibleMap == pawn.Map)
                            {
                                Find.VisibleMap.debugDrawer.FlashCell(randomCell, 0.5f, "trash plant", 50);
                            }
                            return(TrashUtility.TrashJob(pawn, plant));
                        }
                    }
                    if (DebugViewSettings.drawDestSearch && Find.VisibleMap == pawn.Map)
                    {
                        Find.VisibleMap.debugDrawer.FlashCell(randomCell, 0f, "trash no", 50);
                    }
                }
            }
            return(null);
        }
Beispiel #19
0
        // Token: 0x0600295A RID: 10586 RVA: 0x00139AE4 File Offset: 0x00137EE4
        private void ConvertRandomCellInRadius(float radius)
        {
            Map     map = this.parent.Map;
            IntVec3 c   = this.parent.Position + (Rand.InsideUnitCircleVec3 * radius).ToIntVec3();

            if (!c.InBounds(map))
            {
                return;
            }
            TerrainDef terrain = c.GetTerrain(map);
            Thing      thing   = c.GetEdifice(map);
            bool       flith   = c.GetThingList(map).Any((Thing x) => x.def == XenomorphDefOf.RRY_Filth_Slime);
            bool       wall    = thing != null;

            if (flith)
            {
                terrain = TerrainDefOf.WaterShallow;
            }
        }
Beispiel #20
0
        public static void SpawnDoorAt(IntVec3 position, ref OG_OutpostData outpostData)
        {
            ThingDef autodoorDef = OG_Util.FireproofAutodoorDef;
            Building edifice     = position.GetEdifice();

            if ((edifice != null) &&
                (edifice.def == autodoorDef))
            {
                // Avoid spawning another door on the same spot. This creates troubles with region links...
                return;
            }
            Thing           door            = OG_Common.TrySpawnThingAt(autodoorDef, ThingDefOf.Steel, position, false, Rot4.North, ref outpostData, false, true);
            CompForbiddable compForbiddable = door.TryGetComp <CompForbiddable>();

            if (compForbiddable != null)
            {
                compForbiddable.Forbidden = true; // Avoid colonists going into outpost at start-up.
            }
        }
        public static IntVec3 TryFindWatchBuildingPosition(Pawn pawn, Building building, IntRange standDistanceRange, bool desireToSit, out Thing chair)
        {
            chair = null;

            if (standDistanceRange.Equals(IntRange.zero))
            {
                return(building.Position);
            }

            List <IntVec3> foundCells = FindAllWatchBuildingCells(building, standDistanceRange);

            for (int j = 0; j < foundCells.Count; j++)
            {
                IntVec3 intVec = foundCells[j];

                bool flag = false;
                if (desireToSit)
                {
                    chair = intVec.GetEdifice(pawn.Map);
                    if (chair != null && chair.def.building.isSittable && pawn.CanReserve(chair, 1))
                    {
                        flag = true;
                    }
                    else
                    {
                        // Not sittable or reservable => null
                        chair = null;
                    }
                }
                else if (intVec.InBounds(pawn.Map) && intVec.Standable(pawn.Map) && !intVec.IsForbidden(pawn) && pawn.CanReserve(intVec, 1) && pawn.Map.pawnDestinationReservationManager.CanReserve(intVec, pawn))
                {
                    flag = true;
                }

                if (flag && GenSight.LineOfSight(intVec, building.Position, pawn.Map, false))
                {
                    return(intVec);
                }
            }

            return(IntVec3.Invalid);
        }
 public static void Notify_SmoothedByPawn(Thing t, Pawn p)
 {
     for (int i = 0; i < GenAdj.CardinalDirections.Length; i++)
     {
         IntVec3 c = t.Position + GenAdj.CardinalDirections[i];
         if (c.InBounds(t.Map))
         {
             Building edifice = c.GetEdifice(t.Map);
             if (edifice != null && edifice.def.IsSmoothable)
             {
                 bool flag = true;
                 int  num  = 0;
                 for (int j = 0; j < GenAdj.CardinalDirections.Length; j++)
                 {
                     IntVec3 intVec = edifice.Position + GenAdj.CardinalDirections[j];
                     if (!SmoothableWallUtility.IsBlocked(intVec, t.Map))
                     {
                         flag = false;
                         break;
                     }
                     Building edifice2 = intVec.GetEdifice(t.Map);
                     if (edifice2 != null && edifice2.def.IsSmoothed)
                     {
                         num++;
                     }
                 }
                 if (flag && num >= 2)
                 {
                     for (int k = 0; k < GenAdj.DiagonalDirections.Length; k++)
                     {
                         IntVec3 pos = edifice.Position + GenAdj.DiagonalDirections[k];
                         if (!SmoothableWallUtility.IsBlocked(pos, t.Map))
                         {
                             SmoothableWallUtility.SmoothWall(edifice, p);
                             break;
                         }
                     }
                 }
             }
         }
     }
 }
Beispiel #23
0
        // Token: 0x060000DE RID: 222 RVA: 0x00006938 File Offset: 0x00004B38
        public void GetCells()
        {
            this.cellsToAffect.Clear();
            this.damagedThings.Clear();
            SovietNuclearStrike.openCells.Clear();
            SovietNuclearStrike.adjWallCells.Clear();
            Map            map   = base.Map;
            List <IntVec3> cells = CellsAround(this.landPos, this.Map, range);


            foreach (IntVec3 intVec in cells)
            {
                if (!intVec.IsValid)
                {
                    continue;
                }
                if (intVec.InBounds(map) && !intVec.Roofed(map))
                {
                    SovietNuclearStrike.openCells.Add(intVec);
                }
            }
            for (int i = 0; i < SovietNuclearStrike.openCells.Count; i++)
            {
                IntVec3 intVec2 = SovietNuclearStrike.openCells[i];
                if (intVec2.Walkable(map))
                {
                    for (int j = 0; j < 4; j++)
                    {
                        IntVec3 intVec3 = intVec2 + GenAdj.CardinalDirections[j];
                        if (intVec3.InBounds(map) && !intVec3.Standable(map) && intVec3.GetEdifice(map) != null && !SovietNuclearStrike.openCells.Contains(intVec3) && SovietNuclearStrike.adjWallCells.Contains(intVec3))
                        {
                            if (!intVec3.IsValid)
                            {
                                continue;
                            }
                            SovietNuclearStrike.adjWallCells.Add(intVec3);
                        }
                    }
                }
            }
            this.cellsToAffect.AddRange(SovietNuclearStrike.openCells.Concat(SovietNuclearStrike.adjWallCells));
        }
        public override AcceptanceReport AllowsPlacing(BuildableDef checkingDef, IntVec3 loc, Rot4 rot, Map map,
                                                       Thing thingToIgnore = null, Thing thing = null)
        {
            // there's a power plant or battery here.
            var edifice = loc.GetEdifice(map);

            if (edifice?.PowerPlantComp() == null)
            {
                return(I18n.PlaceWorker_PlaceOnPowerPlant);
            }
            if (edifice.FlickableComp() == null)
            {
                return(I18n.PlaceWorker_PlaceOnFlickable);
            }
            if (edifice.OccupiedRect().Any(c => c.GetFirstThing <Building_BackupPowerAttachment>(map) != null))
            {
                return(I18n.PlaceWorker_OnlyOneAttachmentAllowed);
            }
            return(true);
        }
        static List <Thing> GetAllHoppersThings(this RimWorld.Building_NutrientPasteDispenser self)
        {
            var list = new List <Thing>();

            for (int i = 0; i < self.AdjCellsCardinalInBounds().Count; i++)
            {
                IntVec3  c       = self.AdjCellsCardinalInBounds()[i];
                Building edifice = c.GetEdifice(self.Map);
                if (edifice != null && edifice.def == ThingDefOf.Hopper
                    // && eater.CanReach(edifice, PathEndMode.Touch, Danger.Deadly, false, TraverseMode.ByPawn)
                    )
                {
                    List <Thing> thingList = self.AdjCellsCardinalInBounds()[i].GetThingList(self.Map).ToList();

                    list.AddRange(thingList.Where((Thing arg) => Building_NutrientPasteDispenser.IsAcceptableFeedstock(arg.def)));
                }
            }

            return(list);
        }
Beispiel #26
0
        public override bool HasJobOnCell(Pawn pawn, IntVec3 c, bool forced = false)
        {
            if (c.IsForbidden(pawn) || pawn.Map.designationManager.DesignationAt(c, DesignationDefOf.SmoothWall) == null)
            {
                return(false);
            }
            Building edifice = c.GetEdifice(pawn.Map);

            if (edifice == null || !edifice.def.IsSmoothable)
            {
                Log.ErrorOnce("Failed to find valid edifice when trying to smooth a wall", 58988176);
                pawn.Map.designationManager.TryRemoveDesignation(c, DesignationDefOf.SmoothWall);
                return(false);
            }
            if (!pawn.CanReserve(edifice, 1, -1, null, forced) || !pawn.CanReserve(c, 1, -1, null, forced))
            {
                return(false);
            }
            return(true);
        }
Beispiel #27
0
        private void ExpandAvoidGridIntoEdifices()
        {
            int numGridCells = map.cellIndices.NumGridCells;

            for (int i = 0; i < numGridCells; i++)
            {
                if (grid[i] == 0 || map.edificeGrid[i] != null)
                {
                    continue;
                }
                for (int j = 0; j < 8; j++)
                {
                    IntVec3 c = map.cellIndices.IndexToCell(i) + GenAdj.AdjacentCells[j];
                    if (c.InBounds(map) && c.GetEdifice(map) != null)
                    {
                        grid[c] = (byte)Mathf.Min(255, Mathf.Max(grid[c], grid[i]));
                    }
                }
            }
        }
        private static bool IsGoodSnowmanCell(IntVec3 c, Pawn pawn)
        {
            if (pawn.Map.snowGrid.GetDepth(c) < 0.5f)
            {
                return(false);
            }
            if (c.IsForbidden(pawn))
            {
                return(false);
            }
            if (c.GetEdifice(pawn.Map) != null)
            {
                return(false);
            }
            for (int i = 0; i < 9; i++)
            {
                IntVec3 c2 = c + GenAdj.AdjacentCellsAndInside[i];
                if (!c2.InBounds(pawn.Map))
                {
                    return(false);
                }
                if (!c2.Standable(pawn.Map))
                {
                    return(false);
                }
                if (pawn.Map.reservationManager.IsReservedAndRespected(c2, pawn))
                {
                    return(false);
                }
            }
            List <Thing> list = pawn.Map.listerThings.ThingsOfDef(ThingDefOf.Snowman);

            for (int j = 0; j < list.Count; j++)
            {
                if (list[j].Position.InHorDistOf(c, 12f))
                {
                    return(false);
                }
            }
            return(true);
        }
Beispiel #29
0
        private static bool ShouldNotEnterCell(Pawn pawn, Map map, IntVec3 dest)
        {
            bool result;

            if (map.pathGrid.PerceivedPathCostAt(dest) > 30)
            {
                result = true;
            }
            else if (!dest.Walkable(map))
            {
                result = true;
            }
            else
            {
                if (pawn != null)
                {
                    if (dest.IsForbidden(pawn))
                    {
                        return(true);
                    }
                    Building edifice = dest.GetEdifice(map);
                    if (edifice != null)
                    {
                        Building_Door building_Door = edifice as Building_Door;
                        if (building_Door != null)
                        {
                            if (building_Door.IsForbidden(pawn))
                            {
                                return(true);
                            }
                            if (!building_Door.PawnCanOpen(pawn))
                            {
                                return(true);
                            }
                        }
                    }
                }
                result = false;
            }
            return(result);
        }
Beispiel #30
0
        protected bool IsObstacleBlockingAt(IntVec3 position, out ThingDef obstacleDef)
        {
            obstacleDef = null;
            // Look for blocking building.
            Building building = position.GetEdifice(this.Map);

            if (building != null)
            {
                bool doorIsOpen = ((building is Building_Door) &&
                                   (building as Building_Door).Open);
                bool canPassThroughBuilding = ((building.def.fillPercent < 0.7f) ||
                                               doorIsOpen);
                if (!canPassThroughBuilding)
                {
                    obstacleDef = building.def;
                    return(true);
                }
            }
            // Look for blocking plant.
            Plant plant           = position.GetPlant(this.Map);
            bool  plantIsBlocking = ((plant != null) &&
                                     (plant.def.fillPercent >= 0.4f) &&
                                     (plant.Growth >= 0.5f));

            if (plantIsBlocking)
            {
                obstacleDef = plant.def;
                return(true);
            }
            // Look for blocking pawn.
            Pawn pawn           = position.GetFirstPawn(this.Map);
            bool pawnIsBlocking = ((pawn != null) &&
                                   (pawn.BodySize >= 1.5f));

            if (pawnIsBlocking)
            {
                obstacleDef = pawn.def;
                return(true);
            }
            return(false);
        }
Beispiel #31
0
        public static bool HasValidDestination(this Pawn pawn, IntVec3 dest)
        {
            if (dest.InBounds(pawn.Map) == false)
            {
                return(false);
            }
            var door = dest.GetEdifice(pawn.Map) as Building_Door;

            if (door != null)
            {
                if (door.Open == false)
                {
                    return(false);
                }
            }
            if (pawn.Map.pathGrid.WalkableFast(dest) == false)
            {
                return(false);
            }
            return(pawn.Map.terrainGrid.TerrainAt(dest).DoesRepellZombies() == false);
        }
 public Job DeconstructExistingEdificeJob(Pawn pawn, RimWorld.Blueprint blue)
 {
     if (!blue.def.entityDefToBuild.IsEdifice())
     {
         return null;
     }
     Thing thing = null;
     var cellRect = blue.OccupiedRect();
     for (var i = cellRect.minZ; i <= cellRect.maxZ; i++)
     {
         var j = cellRect.minX;
         while (j <= cellRect.maxX)
         {
             var c = new IntVec3(j, 0, i);
             thing = c.GetEdifice();
             if (thing != null)
             {
                 var thingDef = blue.def.entityDefToBuild as ThingDef;
                 if (thingDef != null && thingDef.building.canPlaceOverWall && thing.def == ThingDefOf.Wall)
                 {
                     return null;
                 }
                 break;
             }
             j++;
         }
         if (thing != null)
         {
             break;
         }
     }
     if (thing == null || !pawn.CanReserve(thing))
     {
         return null;
     }
     return new Job(JobDefOf.Deconstruct, thing)
     {
         ignoreDesignations = true
     };
 }
        public void GenerateWarfield(int battleZoneAbs, int battleZoneOrd, OG_OutpostData outpostData)
        {
            // Get a random hostile faction.
            int securityForcesCorpseNumber = Rand.Range(2, 4);
            int hostilesCorpseNumber = 0;
            FactionDef hostileFactionDef = null;
            Faction hostileFaction = null;
            float hostileFactionSelector = Rand.Value;
            if (hostileFactionSelector < 0.25f)
            {
                hostileFactionDef = FactionDefOf.Tribe;
                hostileFaction = Find.FactionManager.FirstFactionOfDef(hostileFactionDef);
                hostilesCorpseNumber = Rand.Range(6, 8);
            }
            else if (hostileFactionSelector < 0.5f)
            {
                hostileFactionDef = FactionDefOf.Pirate;
                hostileFaction = Find.FactionManager.FirstFactionOfDef(hostileFactionDef);
                hostilesCorpseNumber = Rand.Range(3, 5);
            }
            else if (hostileFactionSelector < 0.75f)
            {
                hostileFactionDef = FactionDefOf.SpacerHostile;
                hostileFaction = Find.FactionManager.FirstFactionOfDef(hostileFactionDef);
                hostilesCorpseNumber = Rand.Range(3, 5);
            }
            else
            {
                hostileFactionDef = FactionDefOf.Mechanoid;
                hostileFaction = Find.FactionManager.FirstFactionOfDef(hostileFactionDef);
                hostilesCorpseNumber = Rand.Range(1, 3);
            }
            // Spawn corpses.
            IntVec3 zoneOrigin = Zone.GetZoneOrigin(outpostData.areaSouthWestOrigin, battleZoneAbs, battleZoneOrd);
            for (int corpseIndex = 0; corpseIndex < securityForcesCorpseNumber + hostilesCorpseNumber; corpseIndex++)
            {
                int tries = 3; // Max 3 tries per corpse.
                bool validPositionIsFound = false;
                IntVec3 corpsePosition = new IntVec3();
                for (int tryIndex = 0; tryIndex < tries; tryIndex++)
                {
                    corpsePosition = zoneOrigin + new IntVec3(Rand.Range(1, Genstep_GenerateOutpost.zoneSideSize - 1), 0, Rand.Range(1, Genstep_GenerateOutpost.zoneSideSize - 1));
                    if (corpsePosition.GetEdifice() == null)
                    {
                        validPositionIsFound = true;
                        break;
                    }
                }
                if (validPositionIsFound == false)
                {
                    continue;
                }
                // Generate the corpse according to the faction.
                Pawn corpse = null;
                if (corpseIndex < securityForcesCorpseNumber)
                {
                    corpse = PawnGenerator.GeneratePawn(OG_Util.OutpostScoutDef, OG_Util.FactionOfMiningCo);
                }
                else
                {
                    float pawnKindSelector = Rand.Value;
                    PawnKindDef corpseKindDef = null;
                    if (hostileFactionDef == FactionDefOf.Tribe)
                    {
                        if (pawnKindSelector < 0.4f)
                            corpseKindDef = PawnKindDef.Named("TribalWarrior");
                        else if (pawnKindSelector < 0.8f)
                            corpseKindDef = PawnKindDef.Named("TribalArcher");
                        else
                            corpseKindDef = PawnKindDef.Named("TribalChief");
                    }
                    else if (hostileFactionDef == FactionDefOf.Pirate)
                    {
                        if (pawnKindSelector < 0.25f)
                            corpseKindDef = PawnKindDef.Named("Drifter");
                        else if (pawnKindSelector < 0.50f)
                            corpseKindDef = PawnKindDef.Named("Scavenger");
                        else if (pawnKindSelector < 0.75f)
                            corpseKindDef = PawnKindDef.Named("Thrasher");
                        else
                            corpseKindDef = PawnKindDef.Named("Pirate");
                    }
                    else if (hostileFactionDef == FactionDefOf.SpacerHostile)
                    {
                        if (pawnKindSelector < 0.25f)
                            corpseKindDef = PawnKindDef.Named("SpaceSoldier");
                        else if (pawnKindSelector < 0.50f)
                            corpseKindDef = PawnKindDef.Named("MercenaryGunner");
                        else if (pawnKindSelector < 0.75f)
                            corpseKindDef = PawnKindDef.Named("GrenadierDestructive");
                        else
                            corpseKindDef = PawnKindDef.Named("MercenaryElite");
                    }
                    else if (hostileFactionDef == FactionDefOf.Mechanoid)
                    {
                        if (pawnKindSelector < 0.6f)
                            corpseKindDef = PawnKindDef.Named("Scyther");
                        else
                            corpseKindDef = PawnKindDef.Named("Centipede");
                    }
                    corpse = PawnGenerator.GeneratePawn(corpseKindDef, hostileFaction);
                }
                GenSpawn.Spawn(corpse, corpsePosition);
                // Damage the weapon so the warfield effect is not too exploitable (otherwise, player can get good guns at game start).
                if (corpse.equipment.Primary != null)
                {
                    corpse.equipment.Primary.HitPoints = (int)(Rand.Range(0.05f, 0.30f) * corpse.equipment.Primary.MaxHitPoints);
                }
                // "Kill the corpse".
                HealthUtility.GiveInjuriesToKill(corpse);
                // Make it rotten if outpost is abandonned.
                if (this.outpostData.isInhabited == false)
                {
                    List<Thing> thingsList = corpsePosition.GetThingList();
                    foreach (Thing thing in thingsList)
                    {
                        if (thing.def.defName.Contains("Corpse"))
                        {
                            CompRottable rotComp = thing.TryGetComp<CompRottable>();
                            if (rotComp != null)
                            {
                                rotComp.RotProgress = 20f * GenDate.TicksPerDay; // 20 days so the corpse is dessicated.
                            }
                        }
                    }
                }
            }

            // Destroy some sandbags in the zone.
            List<Thing> sandbagsList = Find.ListerThings.ThingsOfDef(ThingDefOf.Sandbags);
            for (int sandbagIndex = sandbagsList.Count - 1; sandbagIndex >= 0; sandbagIndex--)
            {
                Thing sandbag = sandbagsList[sandbagIndex];
                if (sandbag.Position.InHorDistOf(this.Position, Genstep_GenerateOutpost.zoneSideSize / 2f)
                    && (Rand.Value < 0.1f))
                {
                    // Manually spawn sandbag rubble and use Vanish instead of Kill to avoid spawning ugly metal remains.
                    GenSpawn.Spawn(ThingDef.Named("SandbagRubble"), sandbag.Position);
                    sandbag.Destroy(DestroyMode.Vanish);
                }
            }
        }
Beispiel #34
0
 public static void TrySpawnLampAt(IntVec3 position, Color color, ref OG_OutpostData outpostData)
 {
     if (position.GetEdifice() != null)
     {
         return;
     }
     ThingDef lampDef = null;
     if (color == Color.red)
     {
         lampDef = ThingDef.Named("StandingLamp_Red");
     }
     else if (color == Color.green)
     {
         lampDef = ThingDef.Named("StandingLamp_Green");
     }
     else if (color == Color.blue)
     {
         lampDef = ThingDef.Named("StandingLamp_Blue");
     }
     else
     {
         lampDef = ThingDef.Named("StandingLamp");
     }
     OG_Common.TrySpawnThingAt(lampDef, null, position, false, Rot4.North, ref outpostData, true, false);
     Find.TerrainGrid.SetTerrain(position, TerrainDef.Named("MetalTile"));
 }
        /// <summary>
        /// Check if position is valid to grow a plant. Does not check cluster exclusivity!
        /// </summary>
        public static bool IsValidPositionToGrowPlant(ThingDef_ClusterPlant plantDef, IntVec3 position, bool checkTemperature = true)
        {
            if (position.InBounds() == false)
            {
                return false;
            }
            if (plantDef.isSymbiosisPlant)
            {
                // For symbiosis plant, only check there is a source symbiosis plant.
                if (position.GetFirstThing(plantDef.symbiosisPlantDefSource) != null)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            // Check there is no building or cover.
            if ((position.GetEdifice() != null)
                || (position.GetCover() != null))
            {
                return false;
            }
            // Check terrain condition.
            if (ClusterPlant.CanTerrainSupportPlantAt(plantDef, position) == false)
            {
                return false;
            }
            // Check temperature conditions.
            if (ClusterPlant.IsTemperatureConditionOkAt(plantDef, position) == false)
            {
                return false;
            }
            // Check light conditions.
            if (ClusterPlant.IsLightConditionOkAt(plantDef, position) == false)
            {
                return false;
            }
            // Check there is no other plant.
            if (Find.ThingGrid.ThingAt(position, ThingCategory.Plant) != null)
            {
                return false;
            }
            // Check the cell is not blocked by a plant, an item, a pawn, a rock...
	        List<Thing> thingList = Find.ThingGrid.ThingsListAt(position);
	        for (int thingIndex = 0; thingIndex < thingList.Count; thingIndex++)
	        {
                Thing thing = thingList[thingIndex];
                //Log.Message("checking thing + " + thing.ToString() + " at " + position.ToString());
		        if (thing.def.BlockPlanting)
		        {
			        return false;
		        }
		        if (plantDef.passability == Traversability.Impassable
                    && (thing.def.category == ThingCategory.Pawn
                        || thing.def.category == ThingCategory.Item
                        || thing.def.category == ThingCategory.Building
                        || thing.def.category == ThingCategory.Plant))
		        {
			        return false;
		        }
	        }
            // Check snow level.
            if (GenPlant.SnowAllowsPlanting(position) == false)
            {
                return false;
            }
            return true;
        }
Beispiel #36
0
 public static Thing TrySpawnThingAt(ThingDef thingDef,
     ThingDef stuffDef,
     IntVec3 position,
     bool rotated,
     Rot4 rotation,
     ref OG_OutpostData outpostData,
     bool destroyThings = false,
     bool replaceStructure = false)
 {
     if (destroyThings)
     {
         List<Thing> thingList = position.GetThingList();
         for (int j = thingList.Count - 1; j >= 0; j--)
         {
             thingList[j].Destroy(DestroyMode.Vanish);
         }
     }
     Building building = position.GetEdifice();
     if (building != null)
     {
         if (replaceStructure)
         {
             if (outpostData.outpostThingList.Contains(building))
             {
                 outpostData.outpostThingList.Remove(building);
             }
             building.Destroy(DestroyMode.Vanish);
         }
         else
         {
             return null;
         }
     }
     Thing thing = ThingMaker.MakeThing(thingDef, stuffDef);
     outpostData.outpostThingList.Add(thing);
     thing.SetFaction(OG_Util.FactionOfMiningCo);
     if (rotated && thingDef.rotatable)
     {
         return GenSpawn.Spawn(thing, position, rotation);
     }
     else
     {
         if ((thingDef == ThingDef.Named("TableShort"))
             || (thingDef == ThingDef.Named("MultiAnalyzer")))
         {
             if (rotation == Rot4.East)
             {
                 position += new IntVec3(0, 0, -1);
             }
             else if (rotation == Rot4.South)
             {
                 position += new IntVec3(-1, 0, -1);
             }
             else if (rotation == Rot4.West)
             {
                 position += new IntVec3(-1, 0, 0);
             }
         }
         return GenSpawn.Spawn(thing, position);
     }
 }
Beispiel #37
0
 public static void SpawnResourceAt(ThingDef resourceDef, int quantity, IntVec3 position, bool forceSpawn = false)
 {
     if ((position.GetEdifice() != null)
         && (forceSpawn == false))
     {
         return;
     }
     Thing thing = ThingMaker.MakeThing(resourceDef);
     thing.stackCount = quantity;
     thing.SetForbidden(true);
     GenSpawn.Spawn(thing, position);
 }
Beispiel #38
0
 public static void SpawnDoorAt(IntVec3 position, ref OG_OutpostData outpostData)
 {
     ThingDef autodoorDef = OG_Util.FireproofAutodoorDef;
     Building edifice = position.GetEdifice();
     if ((edifice != null)
         && (edifice.def == autodoorDef))
     {
         // Avoid spawning another door on the same spot. This creates troubles with region links...
         return;
     }
     Thing door = OG_Common.TrySpawnThingAt(autodoorDef, ThingDefOf.Steel, position, false, Rot4.North, ref outpostData, false, true);
     CompForbiddable compForbiddable = door.TryGetComp<CompForbiddable>();
     if (compForbiddable != null)
     {
         compForbiddable.Forbidden = true; // Avoid colonists going into outpost at start-up.
     }
 }