public static IntVec3 FindEnd(IntVec3 center, Rot4 rot, IntVec2 size, bool again) { LinkDirections dirA; LinkDirections dirB; IntVec3 adjust; int delta = again ? +1 : -1; if (rot.IsHorizontal) { dirA = LinkDirections.Up; dirB = LinkDirections.Down; adjust = new IntVec3(1, 0, delta); } else { dirA = LinkDirections.Right; dirB = LinkDirections.Left; adjust = new IntVec3(delta, 0, 1); } LinkDirections dir = again ? dirB : dirA; return(GenAdj.CellsAdjacentAlongEdge(center + adjust, rot, size, dir).FirstOrFallback()); }
public override IEnumerable <IntVec3> PotentialWorkCellsGlobal(Pawn pawn) { if (wrappedScanner == null) { CreateWrappedScanner(); } if (wrappedScanner == null) { foreach (var intVec3 in base.PotentialWorkCellsGlobal(pawn)) { yield return(intVec3); } yield break; } //Adapted from latter half of WorkGiver_Grower PotentialWorkCellsGlobal var maxDanger = pawn.NormalMaxDanger(); var wantedPlantDef = wrappedScanner.GetType().GetField("wantedPlantDef" , BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); wantedPlantDef?.SetValue(wrappedScanner, null); if (!(pawn.Map.zoneManager.ZoneAt(pawn.Position) is Zone_Growing growZone)) { //Try edge cells in pawn facing direction next growZone = GenAdj .CellsAdjacentAlongEdge(pawn.Position, pawn.Rotation, new IntVec2(1, 1), Utilities.EdgeFacingRotation(pawn.Rotation)).Select(p => pawn.Map.zoneManager.ZoneAt(p)) .OfType <Zone_Growing>().FirstOrDefault(); if (growZone == default(Zone_Growing)) { yield break; } } if (growZone.cells.Count == 0) { Log.ErrorOnce("Grow zone has 0 cells: " + growZone, -563487); } else if (!growZone.ContainsStaticFire) { //If there is an extraRequirement then check it, otherwise true var extraRequirements = wrappedScanner.GetType().GetMethod("ExtraRequirements" , BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); if ((bool?)extraRequirements?.Invoke(wrappedScanner, new object[] { growZone, pawn }) ?? true) { if (pawn.CanReach(growZone.Cells[0], PathEndMode.OnCell, maxDanger)) { var addCells = true; if (wrappedScanner.ToString().Contains("Sow")) { var plantToSow = growZone.GetPlantDefToGrow(); addCells = plantToSow.plant.sowMinSkill <= pawn.skills.GetSkill(SkillDefOf.Plants).Level; //Log.Message("Pawn: " + pawn.NameShortColored + " GetPlantDefToGrow: " + growZone.GetPlantDefToGrow() + " CanSow: " + addCells); } if (addCells) { foreach (var potentialWorkCellsGlobal in growZone.cells) { yield return(potentialWorkCellsGlobal); } } wantedPlantDef?.SetValue(wrappedScanner, null); } } } wantedPlantDef?.SetValue(wrappedScanner, null); }