Exemplo n.º 1
0
        private static bool HaulablePlaceValidator(Thing haulable, Pawn worker, IntVec3 c)
        {
            bool result;

            if (!worker.CanReserveAndReach(c, PathEndMode.OnCell, worker.NormalMaxDanger(), 1, -1, null, false))
            {
                result = false;
            }
            else if (GenPlace.HaulPlaceBlockerIn(haulable, c, worker.Map, true) != null)
            {
                result = false;
            }
            else if (!c.Standable(worker.Map))
            {
                result = false;
            }
            else if (c == haulable.Position && haulable.Spawned)
            {
                result = false;
            }
            else if (c.ContainsStaticFire(worker.Map))
            {
                result = false;
            }
            else
            {
                if (haulable != null && haulable.def.BlockPlanting)
                {
                    Zone zone = worker.Map.zoneManager.ZoneAt(c);
                    if (zone is Zone_Growing)
                    {
                        return(false);
                    }
                }
                if (haulable.def.passability != Traversability.Standable)
                {
                    for (int i = 0; i < 8; i++)
                    {
                        IntVec3 c2 = c + GenAdj.AdjacentCells[i];
                        if (worker.Map.designationManager.DesignationAt(c2, DesignationDefOf.Mine) != null)
                        {
                            return(false);
                        }
                    }
                }
                Building edifice = c.GetEdifice(worker.Map);
                if (edifice != null)
                {
                    Building_Trap building_Trap = edifice as Building_Trap;
                    if (building_Trap != null)
                    {
                        return(false);
                    }
                }
                result = true;
            }
            return(result);
        }
        private static bool HaulablePlaceValidator(Thing haulable, Pawn worker, IntVec3 c)
        {
            if (!worker.CanReserveAndReach(c, PathEndMode.OnCell, worker.NormalMaxDanger()))
            {
                return(false);
            }
            if (GenPlace.HaulPlaceBlockerIn(haulable, c, worker.Map, checkBlueprintsAndFrames: true) != null)
            {
                return(false);
            }
            if (!c.Standable(worker.Map))
            {
                return(false);
            }
            if (c == haulable.Position && haulable.Spawned)
            {
                return(false);
            }
            if (c.ContainsStaticFire(worker.Map))
            {
                return(false);
            }
            if (haulable != null && haulable.def.BlocksPlanting() && worker.Map.zoneManager.ZoneAt(c) is Zone_Growing)
            {
                return(false);
            }
            if (haulable.def.passability != 0)
            {
                for (int i = 0; i < 8; i++)
                {
                    IntVec3 c2 = c + GenAdj.AdjacentCells[i];
                    if (worker.Map.designationManager.DesignationAt(c2, DesignationDefOf.Mine) != null)
                    {
                        return(false);
                    }
                }
            }
            Building edifice = c.GetEdifice(worker.Map);

            if (edifice != null && edifice is Building_Trap)
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 3
0
        private static bool HaulablePlaceValidator(Thing haulable, Pawn worker, IntVec3 c, out string debugText)
        {
            if (!worker.CanReserveAndReach(c, PathEndMode.OnCell, worker.NormalMaxDanger()))
            {
                debugText = "Could not reserve or reach";
                return(false);
            }
            if (GenPlace.HaulPlaceBlockerIn(haulable, c, worker.Map, true) != null)
            {
                debugText = "Place was blocked";
                return(false);
            }
            var thisIsAPile = c.GetSlotGroup(worker.Map);

            if (thisIsAPile != null)
            {
                if (!thisIsAPile.Settings.AllowedToAccept(haulable))
                {
                    debugText = "Stockpile does not accept";
                    return(false);
                }
            }

            if (!c.Standable(worker.Map))
            {
                debugText = "Cell not standable";
                return(false);
            }
            if (c == haulable.Position && haulable.Spawned)
            {
                debugText = "Current position of thing to be hauled";
                return(false);
            }
            if (c.ContainsStaticFire(worker.Map))
            {
                debugText = "Cell has fire";
                return(false);
            }
            if (haulable != null && haulable.def.BlockPlanting)
            {
                Zone zone = worker.Map.zoneManager.ZoneAt(c);
                if (zone is Zone_Growing)
                {
                    debugText = "Growing zone here";
                    return(false);
                }
            }
            if (haulable.def.passability != Traversability.Standable)
            {
                for (int i = 0; i < 8; i++)
                {
                    IntVec3 adjCell = c + GenAdj.AdjacentCells[i];

                    if (!adjCell.InBounds(worker.Map))
                    {
                        continue;
                    }

                    if (worker.Map.designationManager.DesignationAt(adjCell, DesignationDefOf.Mine) != null)
                    {
                        debugText = "Mining designated nearby";
                        return(false);
                    }
                }
            }

            bool validPositionExists = false;

            var crossGrid = GenAdj.CardinalDirectionsAndInside;

            for (int a = 0; a < crossGrid.CountAllowNull(); a++)
            {
                IntVec3 adjCell = c + crossGrid[a];

                if (!adjCell.InBounds(worker.Map))
                {
                    continue;
                }

                Building restrictedBuildingAdj = adjCell.GetEdifice(worker.Map);
                if (restrictedBuildingAdj != null)
                {
                    if (restrictedBuildingAdj is Building_Door)
                    {
                        break;
                    }
                    if (restrictedBuildingAdj is Building_WorkTable)
                    {
                        thisIsAPile = adjCell.GetSlotGroup(worker.Map);

                        if (thisIsAPile != null)
                        {
                            if (thisIsAPile.Settings.AllowedToAccept(haulable))
                            {
                                validPositionExists = true;
                            }
                        }
                    }
                }
                else
                {
                    validPositionExists = true;
                }
            }

            if (!validPositionExists)
            {
                debugText = "No valid position could be found.";
                return(false);
            }

            Building edifice = c.GetEdifice(worker.Map);

            if (edifice != null)
            {
                if (edifice is Building_Trap)
                {
                    debugText = "It's a trap.";
                    return(false);
                }

                if (edifice is Building_WorkTable)
                {
                    debugText = "Worktable here.";
                    return(false);
                }
            }

            debugText = "OK";
            return(true);
        }
Exemplo n.º 4
0
        // Token: 0x060005DA RID: 1498 RVA: 0x000393CC File Offset: 0x000377CC
        private static bool HaulablePlaceValidator(Thing haulable, Pawn worker, IntVec3 c, IntVec3 center, int radius)
        {
            if (!worker.CanReserveAndReach(c, PathEndMode.OnCell, worker.NormalMaxDanger(), 1, -1, null, false))
            {
                return(false);
            }
            if (GenPlace.HaulPlaceBlockerIn(haulable, c, worker.Map, true) != null)
            {
                return(false);
            }
            if (!c.Standable(worker.Map))
            {
                return(false);
            }
            if (c == haulable.Position && haulable.Spawned)
            {
                return(false);
            }
            if (c.ContainsStaticFire(worker.Map))
            {
                return(false);
            }
            if (XenomorphUtil.DistanceBetween(c, center) <= radius)
            {
                return(false);
            }

            /*
             * if (XenomorphUtil.DistanceBetween(c, center) > radius*2)
             * {
             *  return false;
             * }
             */
            /*
             * if (c.AdjacentTo8Way(center))
             * {
             *  return false;
             * }
             */
            if (haulable != null && haulable.def.BlockPlanting)
            {
                Zone zone = worker.Map.zoneManager.ZoneAt(c);
                if (zone is Zone_Growing)
                {
                    return(false);
                }
            }
            if (haulable.def.passability != Traversability.Standable)
            {
                for (int i = 0; i < 8; i++)
                {
                    IntVec3 c2 = c + GenAdj.AdjacentCells[i];
                    if (worker.Map.designationManager.DesignationAt(c2, DesignationDefOf.Mine) != null)
                    {
                        return(false);
                    }
                }
            }
            Building edifice = c.GetEdifice(worker.Map);

            if (edifice != null)
            {
                Building_Trap building_Trap = edifice as Building_Trap;
                if (building_Trap != null)
                {
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 5
0
        public static IntVec3 SpotToChewStandingNear(Pawn pawn, Thing ingestible)
        {
            IntVec3             root         = pawn.Position;
            Room                rootRoom     = pawn.GetRoom();
            bool                desperate    = false;
            bool                ignoreDanger = false;
            float               maxDist      = 4f;
            Predicate <IntVec3> validator    = delegate(IntVec3 c)
            {
                IntVec3 placeSpot = root - c;
                if ((float)placeSpot.LengthHorizontalSquared > maxDist * maxDist)
                {
                    return(false);
                }
                if (pawn.HostFaction != null && c.GetRoom(pawn.Map) != rootRoom)
                {
                    return(false);
                }
                if (!desperate)
                {
                    if (!c.Standable(pawn.Map))
                    {
                        return(false);
                    }
                    if (GenPlace.HaulPlaceBlockerIn(null, c, pawn.Map, checkBlueprintsAndFrames: false) != null)
                    {
                        return(false);
                    }
                    if (c.GetRegion(pawn.Map).type == RegionType.Portal)
                    {
                        return(false);
                    }
                }
                if (!ignoreDanger && c.GetDangerFor(pawn, pawn.Map) != Danger.None)
                {
                    return(false);
                }
                if (c.ContainsStaticFire(pawn.Map) || c.ContainsTrap(pawn.Map))
                {
                    return(false);
                }
                if (!pawn.Map.pawnDestinationReservationManager.CanReserve(c, pawn))
                {
                    return(false);
                }
                return(Toils_Ingest.TryFindAdjacentIngestionPlaceSpot(c, ingestible.def, pawn, out placeSpot) ? true : false);
            };
            int    maxRegions = 1;
            Region region     = pawn.GetRegion();

            for (int i = 0; i < 30; i++)
            {
                switch (i)
                {
                case 1:
                    desperate = true;
                    break;

                case 2:
                    desperate  = false;
                    maxRegions = 4;
                    break;

                case 6:
                    desperate = true;
                    break;

                case 10:
                    desperate  = false;
                    maxDist    = 8f;
                    maxRegions = 12;
                    break;

                case 15:
                    desperate = true;
                    break;

                case 20:
                    maxDist    = 15f;
                    maxRegions = 16;
                    break;

                case 26:
                    maxDist      = 5f;
                    maxRegions   = 4;
                    ignoreDanger = true;
                    break;

                case 29:
                    maxDist    = 15f;
                    maxRegions = 16;
                    break;
                }
                if (CellFinder.RandomRegionNear(region, maxRegions, TraverseParms.For(pawn)).TryFindRandomCellInRegionUnforbidden(pawn, validator, out IntVec3 result))
                {
                    if (DebugViewSettings.drawDestSearch)
                    {
                        pawn.Map.debugDrawer.FlashCell(result, 0.5f, "go!");
                    }
                    return(result);
                }
                if (DebugViewSettings.drawDestSearch)
                {
                    pawn.Map.debugDrawer.FlashCell(result, 0f, i.ToString());
                }
            }
            return(region.RandomCell);
        }
        public static IntVec3 SpotToChewStandingNear(Pawn pawn, Thing ingestible)
        {
            IntVec3             root         = pawn.Position;
            Room                rootRoom     = pawn.GetRoom(RegionType.Set_Passable);
            bool                desperate    = false;
            bool                ignoreDanger = false;
            float               maxDist      = 4f;
            Predicate <IntVec3> validator    = delegate(IntVec3 c)
            {
                if ((float)(root - c).LengthHorizontalSquared > maxDist * maxDist)
                {
                    return(false);
                }
                if (pawn.HostFaction != null && c.GetRoom(pawn.Map, RegionType.Set_Passable) != rootRoom)
                {
                    return(false);
                }
                if (!desperate)
                {
                    if (!c.Standable(pawn.Map))
                    {
                        return(false);
                    }
                    if (GenPlace.HaulPlaceBlockerIn(null, c, pawn.Map, false) != null)
                    {
                        return(false);
                    }
                    if (c.GetRegion(pawn.Map, RegionType.Set_Passable).type == RegionType.Portal)
                    {
                        return(false);
                    }
                }
                IntVec3 intVec2;
                return((ignoreDanger || c.GetDangerFor(pawn, pawn.Map) == Danger.None) && !c.ContainsStaticFire(pawn.Map) && !c.ContainsTrap(pawn.Map) && pawn.Map.pawnDestinationReservationManager.CanReserve(c, pawn, false) && Toils_Ingest.TryFindAdjacentIngestionPlaceSpot(c, ingestible.def, pawn, out intVec2));
            };
            int    maxRegions = 1;
            Region region     = pawn.GetRegion(RegionType.Set_Passable);

            for (int i = 0; i < 30; i++)
            {
                if (i == 1)
                {
                    desperate = true;
                }
                else if (i == 2)
                {
                    desperate  = false;
                    maxRegions = 4;
                }
                else if (i == 6)
                {
                    desperate = true;
                }
                else if (i == 10)
                {
                    desperate  = false;
                    maxDist    = 8f;
                    maxRegions = 12;
                }
                else if (i == 15)
                {
                    desperate = true;
                }
                else if (i == 20)
                {
                    maxDist    = 15f;
                    maxRegions = 16;
                }
                else if (i == 26)
                {
                    maxDist      = 5f;
                    maxRegions   = 4;
                    ignoreDanger = true;
                }
                else if (i == 29)
                {
                    maxDist    = 15f;
                    maxRegions = 16;
                }
                Region  reg = CellFinder.RandomRegionNear(region, maxRegions, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), null, null, RegionType.Set_Passable);
                IntVec3 intVec;
                if (reg.TryFindRandomCellInRegionUnforbidden(pawn, validator, out intVec))
                {
                    if (DebugViewSettings.drawDestSearch)
                    {
                        pawn.Map.debugDrawer.FlashCell(intVec, 0.5f, "go!", 50);
                    }
                    return(intVec);
                }
                if (DebugViewSettings.drawDestSearch)
                {
                    pawn.Map.debugDrawer.FlashCell(intVec, 0f, i.ToString(), 50);
                }
            }
            return(region.RandomCell);
        }
Exemplo n.º 7
0
        // Token: 0x06000008 RID: 8 RVA: 0x0000233C File Offset: 0x0000053C
        private static bool HaulablePlaceValidator(Thing haulable, Pawn worker, IntVec3 c, out string debugText)
        {
            bool result;

            if (!worker.CanReserveAndReach(c, PathEndMode.OnCell, worker.NormalMaxDanger()))
            {
                debugText = "Could not reserve or reach";
                result    = false;
            }
            else
            {
                if (GenPlace.HaulPlaceBlockerIn(haulable, c, worker.Map, true) != null)
                {
                    debugText = "Place was blocked";
                    result    = false;
                }
                else
                {
                    var slotGroup = c.GetSlotGroup(worker.Map);
                    if (slotGroup != null)
                    {
                        if (!slotGroup.Settings.AllowedToAccept(haulable))
                        {
                            debugText = "Stockpile does not accept";
                            return(false);
                        }
                    }

                    if (!c.Standable(worker.Map))
                    {
                        debugText = "Cell not standable";
                        result    = false;
                    }
                    else
                    {
                        if (c == haulable.Position && haulable.Spawned)
                        {
                            debugText = "Current position of thing to be hauled";
                            result    = false;
                        }
                        else
                        {
                            if (c.ContainsStaticFire(worker.Map))
                            {
                                debugText = "Cell has fire";
                                result    = false;
                            }
                            else
                            {
                                if (haulable.def.BlocksPlanting())
                                {
                                    var zone = worker.Map.zoneManager.ZoneAt(c);
                                    if (zone is Zone_Growing)
                                    {
                                        debugText = "Growing zone here";
                                        return(false);
                                    }
                                }

                                if (haulable.def.passability > Traversability.Standable)
                                {
                                    for (var i = 0; i < 8; i++)
                                    {
                                        var c2 = c + GenAdj.AdjacentCells[i];
                                        if (!c2.InBounds(worker.Map))
                                        {
                                            continue;
                                        }

                                        if (worker.Map.designationManager.DesignationAt(c2,
                                                                                        DesignationDefOf.Mine) == null)
                                        {
                                            continue;
                                        }

                                        debugText = "Mining designated nearby";
                                        return(false);
                                    }
                                }

                                var b = false;
                                var cardinalDirectionsAndInside = GenAdj.CardinalDirectionsAndInside;
                                for (var j = 0; j < cardinalDirectionsAndInside.CountAllowNull(); j++)
                                {
                                    var c3 = c + cardinalDirectionsAndInside[j];
                                    if (!c3.InBounds(worker.Map))
                                    {
                                        continue;
                                    }

                                    var edifice = c3.GetEdifice(worker.Map);
                                    if (edifice != null)
                                    {
                                        if (edifice is Building_Door)
                                        {
                                            break;
                                        }

                                        if (edifice is not Building_WorkTable)
                                        {
                                            continue;
                                        }

                                        slotGroup = c3.GetSlotGroup(worker.Map);
                                        if (slotGroup == null)
                                        {
                                            continue;
                                        }

                                        if (slotGroup.Settings.AllowedToAccept(haulable))
                                        {
                                            b = true;
                                        }
                                    }
                                    else
                                    {
                                        b = true;
                                    }
                                }

                                if (!b)
                                {
                                    debugText = "No valid position could be found.";
                                    result    = false;
                                }
                                else
                                {
                                    var edifice2 = c.GetEdifice(worker.Map);
                                    if (edifice2 != null)
                                    {
                                        if (edifice2 is Building_Trap)
                                        {
                                            debugText = "It's a trap.";
                                            return(false);
                                        }

                                        if (edifice2 is Building_WorkTable)
                                        {
                                            debugText = "It's not a trap, but we still can't put something here.";
                                            return(false);
                                        }
                                    }

                                    debugText = "OK";
                                    result    = true;
                                }
                            }
                        }
                    }
                }
            }

            return(result);
        }