コード例 #1
0
        /// <summary>
        /// Find defined things in the room and within distance and return an IEnumerable.
        /// </summary>
        /// <param name="position">The source position.</param>
        /// <param name="distance">The max. distance from the position.</param>
        /// <param name="category">The EntityCategory to search for.</param>
        /// <returns></returns>
        private IEnumerable <Thing> FindItemsInRoomAndWithinDistance(IntVec3 position, float distance, EntityCategory category)
        {
            // Find the room at the position
            Room room = position.GetRoom();

            if (room == null)
            {
                IEnumerable <IntVec3> posList = position.AdjacentSquares8WayAndInside();
                foreach (IntVec3 pos in posList)
                {
                    if (pos.GetRoom() == null)
                    {
                        continue;
                    }

                    room = pos.GetRoom();
                    break;
                }
            }


            // LINQ => Compare: room // distance // category
            return(Find.ListerThings.AllThings.Where(t => t.def.category == category &&
                                                     room == t.Position.GetRoom() &&
                                                     t.Position.WithinHorizontalDistanceOf(position, distance)));
        }