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);
                    }
                }
            }
        }
        protected override Job TryGivePlayJob(Pawn pawn, Thing t)
        {
            IntVec3  c;
            Building t2;
            Job      result;

            if (!WatchBuildingUtility.TryFindBestWatchCell(t, pawn, this.def.desireSit, out c, out t2))
            {
                result = null;
            }
            else
            {
                result = new Job(this.def.jobDef, t, c, t2);
            }
            return(result);
        }
        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);
        }
        protected override bool CanInteractWith(Pawn pawn, Thing t, bool inBed)
        {
            bool result;

            if (!base.CanInteractWith(pawn, t, inBed))
            {
                result = false;
            }
            else if (inBed)
            {
                Building_Bed bed = pawn.CurrentBed();
                result = WatchBuildingUtility.CanWatchFromBed(pawn, bed, t);
            }
            else
            {
                result = true;
            }
            return(result);
        }
Ejemplo n.º 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()*/;
        }
        public override void DrawGhost(ThingDef def, IntVec3 center, Rot4 rot, Color ghostCol)
        {
            Map currentMap = Find.CurrentMap;

            GenDraw.DrawFieldEdges(WatchBuildingUtility.CalculateWatchCells(def, center, rot, currentMap).ToList <IntVec3>());
        }
        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, false))
                        {
                            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)
                            {
                                Rot4 arg_15E_0 = building.Rotation;
                                Rot4 rot       = new Rot4(list[i]);
                                if (arg_15E_0 != rot.Opposite)
                                {
                                    intVec = intVec2;
                                    goto IL_17F;
                                }
                            }
                            result = intVec2;
                            chair  = building;
                            return(true);
                        }
                    }
                    IL_17F :;
                }
            }
            if (intVec.IsValid)
            {
                result = intVec;
                chair  = intVec.GetEdifice(pawn.Map);
                return(true);
            }
            result = IntVec3.Invalid;
            chair  = null;
            return(false);
        }
        public override void DrawGhost(ThingDef def, IntVec3 center, Rot4 rot)
        {
            Map visibleMap = Find.VisibleMap;

            GenDraw.DrawFieldEdges(WatchBuildingUtility.CalculateWatchCells(def, center, rot, visibleMap).ToList());
        }