示例#1
0
        public static bool CanWatchFromBed(Pawn pawn, Building_Bed bed, Thing toWatch)
        {
            if (!WatchBuildingUtility.EverPossibleToWatchFrom(pawn.Position, toWatch.Position, pawn.Map, true))
            {
                return(false);
            }
            if (toWatch.def.rotatable)
            {
                Rot4     rotation = bed.Rotation;
                CellRect cellRect = toWatch.OccupiedRect();
                if (rotation == Rot4.North)
                {
                    int     maxZ     = cellRect.maxZ;
                    IntVec3 position = pawn.Position;
                    if (maxZ < position.z)
                    {
                        return(false);
                    }
                }
                if (rotation == Rot4.South)
                {
                    int     minZ      = cellRect.minZ;
                    IntVec3 position2 = pawn.Position;
                    if (minZ > position2.z)
                    {
                        return(false);
                    }
                }
                if (rotation == Rot4.East)
                {
                    int     maxX      = cellRect.maxX;
                    IntVec3 position3 = pawn.Position;
                    if (maxX < position3.x)
                    {
                        return(false);
                    }
                }
                if (rotation == Rot4.West)
                {
                    int     minX      = cellRect.minX;
                    IntVec3 position4 = pawn.Position;
                    if (minX > position4.x)
                    {
                        return(false);
                    }
                }
            }
            List <int> list = WatchBuildingUtility.CalculateAllowedDirections(toWatch.def, toWatch.Rotation);

            for (int i = 0; i < list.Count; i++)
            {
                if (WatchBuildingUtility.GetWatchCellRect(toWatch.def, toWatch.Position, toWatch.Rotation, list[i]).Contains(pawn.Position))
                {
                    return(true);
                }
            }
            return(false);
        }
示例#2
0
        public static bool TryFindBestWatchCell(Thing toWatch, Pawn pawn, bool desireSit, out IntVec3 result, out Building chair)
        {
            List <int> list   = WatchBuildingUtility.CalculateAllowedDirections(toWatch.def, toWatch.Rotation);
            IntVec3    intVec = IntVec3.Invalid;

            for (int i = 0; i < list.Count; i++)
            {
                CellRect watchCellRect = WatchBuildingUtility.GetWatchCellRect(toWatch.def, toWatch.Position, toWatch.Rotation, list[i]);
                IntVec3  centerCell    = watchCellRect.CenterCell;
                int      num           = watchCellRect.Area * 4;
                for (int j = 0; j < num; j++)
                {
                    IntVec3 intVec2 = centerCell + GenRadial.RadialPattern[j];
                    if (watchCellRect.Contains(intVec2))
                    {
                        bool     flag     = false;
                        Building building = null;
                        if (WatchBuildingUtility.EverPossibleToWatchFrom(intVec2, toWatch.Position, toWatch.Map, false) && !intVec2.IsForbidden(pawn) && pawn.CanReserve(intVec2, 1, -1, null, false) && pawn.Map.pawnDestinationReservationManager.CanReserve(intVec2, pawn))
                        {
                            if (desireSit)
                            {
                                building = intVec2.GetEdifice(pawn.Map);
                                if (building != null && building.def.building.isSittable && pawn.CanReserve(building, 1, -1, null, false))
                                {
                                    flag = true;
                                }
                            }
                            else
                            {
                                flag = true;
                            }
                        }
                        if (flag)
                        {
                            if (!desireSit || !(building.Rotation != new Rot4(list[i]).Opposite))
                            {
                                result = intVec2;
                                chair  = building;
                                return(true);
                            }
                            intVec = intVec2;
                        }
                    }
                }
            }
            if (intVec.IsValid)
            {
                result = intVec;
                chair  = intVec.GetEdifice(pawn.Map);
                return(true);
            }
            result = IntVec3.Invalid;
            chair  = null;
            return(false);
        }
        public static IEnumerable <IntVec3> CalculateWatchCells(ThingDef def, IntVec3 center, Rot4 rot, Map map)
        {
            List <int> allowedDirections = WatchBuildingUtility.CalculateAllowedDirections(def, rot);

            for (int i = 0; i < allowedDirections.Count; i++)
            {
                foreach (IntVec3 c in WatchBuildingUtility.GetWatchCellRect(def, center, rot, allowedDirections[i]))
                {
                    if (WatchBuildingUtility.EverPossibleToWatchFrom(c, center, map, true))
                    {
                        yield return(c);
                    }
                }
            }
        }
        public static bool CanWatchFromBed(Pawn pawn, Building_Bed bed, Thing toWatch)
        {
            bool result;

            if (!WatchBuildingUtility.EverPossibleToWatchFrom(pawn.Position, toWatch.Position, pawn.Map, true))
            {
                result = false;
            }
            else
            {
                if (toWatch.def.rotatable)
                {
                    Rot4     rotation = bed.Rotation;
                    CellRect cellRect = toWatch.OccupiedRect();
                    if (rotation == Rot4.North && cellRect.maxZ < pawn.Position.z)
                    {
                        return(false);
                    }
                    if (rotation == Rot4.South && cellRect.minZ > pawn.Position.z)
                    {
                        return(false);
                    }
                    if (rotation == Rot4.East && cellRect.maxX < pawn.Position.x)
                    {
                        return(false);
                    }
                    if (rotation == Rot4.West && cellRect.minX > pawn.Position.x)
                    {
                        return(false);
                    }
                }
                List <int> list = WatchBuildingUtility.CalculateAllowedDirections(toWatch.def, toWatch.Rotation);
                for (int i = 0; i < list.Count; i++)
                {
                    if (WatchBuildingUtility.GetWatchCellRect(toWatch.def, toWatch.Position, toWatch.Rotation, list[i]).Contains(pawn.Position))
                    {
                        return(true);
                    }
                }
                result = false;
            }
            return(result);
        }
示例#5
0
        public static IEnumerable <IntVec3> CalculateWatchCells(ThingDef def, IntVec3 center, Rot4 rot, Map map)
        {
            List <int> allowedDirections = WatchBuildingUtility.CalculateAllowedDirections(def, rot);

            for (int i = 0; i < allowedDirections.Count; i++)
            {
                foreach (IntVec3 item in WatchBuildingUtility.GetWatchCellRect(def, center, rot, allowedDirections[i]))
                {
                    if (WatchBuildingUtility.EverPossibleToWatchFrom(item, center, map, true))
                    {
                        yield return(item);

                        /*Error: Unable to find new state assignment for yield return*/;
                    }
                }
            }
            yield break;
IL_013d:
            /*Error near IL_013e: Unexpected return in MoveNext()*/;
        }