mirror of
				https://github.com/amevarashi/RJW-Sexperience.git
				synced 2024-08-14 23:54:08 +00:00 
			
		
		
		
	Simplified GetAdjacentBuilding methods
This commit is contained in:
		
							parent
							
								
									ab485c677f
								
							
						
					
					
						commit
						cd9647f999
					
				
					 1 changed files with 5 additions and 21 deletions
				
			
		| 
						 | 
					@ -31,38 +31,22 @@ namespace RJWSexperience
 | 
				
			||||||
			return 1.0f;
 | 
								return 1.0f;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		public static T GetAdjacentBuilding<T>(this Pawn pawn) where T : Building
 | 
							public static T GetAdjacentBuilding<T>(this Pawn pawn) where T : Building => GetAdjacentBuildings<T>(pawn).FirstOrFallback();
 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			if (!pawn.Spawned)
 | 
					 | 
				
			||||||
				return null;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			EdificeGrid edifice = pawn.Map.edificeGrid;
 | 
					 | 
				
			||||||
			if (edifice[pawn.Position] is T building)
 | 
					 | 
				
			||||||
				return building;
 | 
					 | 
				
			||||||
			foreach (IntVec3 pos in GenAdjFast.AdjacentCells8Way(pawn.Position))
 | 
					 | 
				
			||||||
			{
 | 
					 | 
				
			||||||
				if (edifice[pos] is T adjBuilding)
 | 
					 | 
				
			||||||
					return adjBuilding;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			return null;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		public static IEnumerable<T> GetAdjacentBuildings<T>(this Pawn pawn) where T : Building
 | 
							public static IEnumerable<T> GetAdjacentBuildings<T>(this Pawn pawn) where T : Building
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			var results = new List<T>();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			if (!pawn.Spawned)
 | 
								if (!pawn.Spawned)
 | 
				
			||||||
				return results;
 | 
									yield break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			EdificeGrid edifice = pawn.Map.edificeGrid;
 | 
								EdificeGrid edifice = pawn.Map.edificeGrid;
 | 
				
			||||||
			if (edifice[pawn.Position] is T building)
 | 
								if (edifice[pawn.Position] is T building)
 | 
				
			||||||
				results.Add(building);
 | 
									yield return building;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			foreach (IntVec3 pos in GenAdjFast.AdjacentCells8Way(pawn.Position))
 | 
								foreach (IntVec3 pos in GenAdjFast.AdjacentCells8Way(pawn.Position))
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				if (pos.InBounds(pawn.Map) && edifice[pos] is T adjBuilding)
 | 
									if (pos.InBounds(pawn.Map) && edifice[pos] is T adjBuilding)
 | 
				
			||||||
					results.Add(adjBuilding);
 | 
										yield return adjBuilding;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			return results;
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		/// <summary>
 | 
							/// <summary>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue