private static bool TryFindPlaceSpotNear(IntVec3 center, Map map, Thing thing, bool allowStacking, out IntVec3 bestSpot) { PlaceSpotQuality placeSpotQuality = PlaceSpotQuality.Unusable; bestSpot = center; int num = 0; while (num < 9) { IntVec3 intVec = center + GenRadial.RadialPattern[num]; PlaceSpotQuality placeSpotQuality2 = GenPlace.PlaceSpotQualityAt(intVec, map, thing, center, allowStacking); if ((int)placeSpotQuality2 > (int)placeSpotQuality) { bestSpot = intVec; placeSpotQuality = placeSpotQuality2; } if (placeSpotQuality != PlaceSpotQuality.Perfect) { num++; continue; } break; } if ((int)placeSpotQuality >= 3) { return(true); } int num2 = 0; while (num2 < GenPlace.PlaceNearMiddleRadialCells) { IntVec3 intVec = center + GenRadial.RadialPattern[num2]; PlaceSpotQuality placeSpotQuality2 = GenPlace.PlaceSpotQualityAt(intVec, map, thing, center, allowStacking); if ((int)placeSpotQuality2 > (int)placeSpotQuality) { bestSpot = intVec; placeSpotQuality = placeSpotQuality2; } if (placeSpotQuality != PlaceSpotQuality.Perfect) { num2++; continue; } break; } if ((int)placeSpotQuality >= 3) { return(true); } int num3 = 0; while (num3 < GenPlace.PlaceNearMaxRadialCells) { IntVec3 intVec = center + GenRadial.RadialPattern[num3]; PlaceSpotQuality placeSpotQuality2 = GenPlace.PlaceSpotQualityAt(intVec, map, thing, center, allowStacking); if ((int)placeSpotQuality2 > (int)placeSpotQuality) { bestSpot = intVec; placeSpotQuality = placeSpotQuality2; } if (placeSpotQuality != PlaceSpotQuality.Perfect) { num3++; continue; } break; } if ((int)placeSpotQuality > 0) { return(true); } bestSpot = center; return(false); }
private static PlaceSpotQuality PlaceSpotQualityAt(IntVec3 c, Map map, Thing thing, IntVec3 center, bool allowStacking) { if (c.InBounds(map) && c.Walkable(map)) { List <Thing> list = map.thingGrid.ThingsListAt(c); for (int i = 0; i < list.Count; i++) { Thing thing2 = list[i]; if (thing.def.saveCompressible && thing2.def.saveCompressible) { return(PlaceSpotQuality.Unusable); } if (thing.def.category == ThingCategory.Item && thing2.def.category == ThingCategory.Item && (!thing2.CanStackWith(thing) || thing2.stackCount >= thing.def.stackLimit)) { return(PlaceSpotQuality.Unusable); } } if (c.GetRoom(map, RegionType.Set_Passable) != center.GetRoom(map, RegionType.Set_Passable)) { if (!map.reachability.CanReach(center, c, PathEndMode.OnCell, TraverseMode.PassDoors, Danger.Deadly)) { return(PlaceSpotQuality.Awful); } return(PlaceSpotQuality.Bad); } if (allowStacking) { for (int j = 0; j < list.Count; j++) { Thing thing3 = list[j]; if (thing3.def.category == ThingCategory.Item && thing3.CanStackWith(thing) && thing3.stackCount < thing.def.stackLimit) { return(PlaceSpotQuality.Perfect); } } } Pawn pawn = thing as Pawn; bool flag = pawn != null && pawn.Downed; PlaceSpotQuality placeSpotQuality = PlaceSpotQuality.Perfect; for (int k = 0; k < list.Count; k++) { Thing thing4 = list[k]; if (thing4.def.IsDoor) { return(PlaceSpotQuality.Bad); } if (thing4 is Building_WorkTable) { return(PlaceSpotQuality.Bad); } Pawn pawn2 = thing4 as Pawn; if (pawn2 != null) { if (pawn2.Downed || flag) { return(PlaceSpotQuality.Bad); } if ((int)placeSpotQuality > 3) { placeSpotQuality = PlaceSpotQuality.Okay; } } if (thing4.def.category == ThingCategory.Plant && thing4.def.selectable && (int)placeSpotQuality > 3) { placeSpotQuality = PlaceSpotQuality.Okay; } } return(placeSpotQuality); } return(PlaceSpotQuality.Unusable); }
// overhauled version (vanilla is bugged) public static PlaceSpotQuality PlaceSpotQualityAt(IntVec3 c, Thing thing, IntVec3 center) { if (!c.InBounds() || !c.Walkable()) { return(PlaceSpotQuality.Unusable); } List <Thing> list = Find.ThingGrid.ThingsListAt(c); // if other things on cell int i = 0; while (i < list.Count) { Thing thing2 = list[i]; if (thing.def.saveCompressible && thing2.def.saveCompressible) { return(PlaceSpotQuality.Unusable); } // same thing type if (thing2.def.category == ThingCategory.Item) { // can stack with if (thing2.def == thing.def && thing2.stackCount < thing.def.stackLimit) { // can absorb // Required, because thing reference is changed to the absorber, if absorbed Thing t = thing2; if (thing.TryAbsorbStack(thing2, true)) { // Clean up to prevent haulables lists overflow RemoveHaulableFromLists(t); return(PlaceSpotQuality.Perfect); } // cannot absorb all/anything else { return(PlaceSpotQuality.Unusable); } } return(PlaceSpotQuality.Unusable); } else { i++; } } // if in same room if (c.GetRoom() == center.GetRoom()) { PlaceSpotQuality placeSpotQuality = PlaceSpotQuality.Perfect; for (int j = 0; j < list.Count; j++) { Thing thing3 = list[j]; if (thing3.def.thingClass == typeof(Building_Door)) { return(PlaceSpotQuality.Bad); } Pawn pawn = thing3 as Pawn; if (pawn != null) { if (pawn.Downed) { return(PlaceSpotQuality.Bad); } if (placeSpotQuality > PlaceSpotQuality.Okay) { placeSpotQuality = PlaceSpotQuality.Okay; } } if (thing3.def.category == ThingCategory.Plant && thing3.def.selectable && placeSpotQuality > PlaceSpotQuality.Okay) { placeSpotQuality = PlaceSpotQuality.Okay; } } return(placeSpotQuality); } if (!center.CanReach(c, PathEndMode.OnCell, TraverseMode.PassDoors, Danger.Deadly)) { return(PlaceSpotQuality.Awful); } return(PlaceSpotQuality.Okay); }
// duplicated to make changes public static bool TryFindPlaceSpotNear(IntVec3 center, Thing thing, out IntVec3 bestSpot) { PlaceSpotQuality placeSpotQuality = PlaceSpotQuality.Unusable; bestSpot = center; // try place in 8 adjacent cells for (int i = 0; i < 9; i++) { IntVec3 intVec = center + GenRadial.RadialPattern[i]; // call duplicated cause vanilla is private PlaceSpotQuality placeSpotQuality2 = PlaceSpotQualityAt(intVec, thing, center); if (placeSpotQuality2 > placeSpotQuality) { bestSpot = intVec; placeSpotQuality = placeSpotQuality2; } if (placeSpotQuality == PlaceSpotQuality.Perfect) { break; } } if (placeSpotQuality >= PlaceSpotQuality.Okay) { return(true); } for (int j = 0; j < PlaceNearMiddleRadialCells; j++) { IntVec3 intVec = center + GenRadial.RadialPattern[j]; // call duplicated cause vanilla is private PlaceSpotQuality placeSpotQuality2 = PlaceSpotQualityAt(intVec, thing, center); if (placeSpotQuality2 > placeSpotQuality) { bestSpot = intVec; placeSpotQuality = placeSpotQuality2; } if (placeSpotQuality == PlaceSpotQuality.Perfect) { break; } } if (placeSpotQuality >= PlaceSpotQuality.Okay) { return(true); } for (int k = 0; k < PlaceNearMaxRadialCells; k++) { IntVec3 intVec = center + GenRadial.RadialPattern[k]; // call duplicated cause vanilla is private PlaceSpotQuality placeSpotQuality2 = PlaceSpotQualityAt(intVec, thing, center); if (placeSpotQuality2 > placeSpotQuality) { bestSpot = intVec; placeSpotQuality = placeSpotQuality2; } if (placeSpotQuality == PlaceSpotQuality.Perfect) { break; } } if (placeSpotQuality > PlaceSpotQuality.Unusable) { return(true); } bestSpot = center; return(false); }
private static bool TryFindPlaceSpotNear(IntVec3 center, Rot4 rot, Map map, Thing thing, bool allowStacking, out IntVec3 bestSpot, Predicate <IntVec3> extraValidator = null) { PlaceSpotQuality placeSpotQuality = PlaceSpotQuality.Unusable; bestSpot = center; for (int i = 0; i < 9; i++) { IntVec3 intVec = center + GenRadial.RadialPattern[i]; PlaceSpotQuality placeSpotQuality2 = PlaceSpotQualityAt(intVec, rot, map, thing, center, allowStacking, extraValidator); if ((int)placeSpotQuality2 > (int)placeSpotQuality) { bestSpot = intVec; placeSpotQuality = placeSpotQuality2; } if (placeSpotQuality == PlaceSpotQuality.Perfect) { break; } } if ((int)placeSpotQuality >= 3) { return(true); } for (int j = 0; j < PlaceNearMiddleRadialCells; j++) { IntVec3 intVec = center + GenRadial.RadialPattern[j]; PlaceSpotQuality placeSpotQuality2 = PlaceSpotQualityAt(intVec, rot, map, thing, center, allowStacking, extraValidator); if ((int)placeSpotQuality2 > (int)placeSpotQuality) { bestSpot = intVec; placeSpotQuality = placeSpotQuality2; } if (placeSpotQuality == PlaceSpotQuality.Perfect) { break; } } if ((int)placeSpotQuality >= 3) { return(true); } for (int k = 0; k < PlaceNearMaxRadialCells; k++) { IntVec3 intVec = center + GenRadial.RadialPattern[k]; PlaceSpotQuality placeSpotQuality2 = PlaceSpotQualityAt(intVec, rot, map, thing, center, allowStacking, extraValidator); if ((int)placeSpotQuality2 > (int)placeSpotQuality) { bestSpot = intVec; placeSpotQuality = placeSpotQuality2; } if (placeSpotQuality == PlaceSpotQuality.Perfect) { break; } } if ((int)placeSpotQuality > 0) { return(true); } bestSpot = center; return(false); }
private static PlaceSpotQuality PlaceSpotQualityAt(IntVec3 c, Rot4 rot, Map map, Thing thing, IntVec3 center, bool allowStacking, Predicate <IntVec3> extraValidator = null) { if (!c.InBounds(map) || !c.Walkable(map)) { return(PlaceSpotQuality.Unusable); } if (!GenAdj.OccupiedRect(c, rot, thing.def.Size).InBounds(map)) { return(PlaceSpotQuality.Unusable); } if (extraValidator != null && !extraValidator(c)) { return(PlaceSpotQuality.Unusable); } List <Thing> list = map.thingGrid.ThingsListAt(c); for (int i = 0; i < list.Count; i++) { Thing thing2 = list[i]; if (thing.def.saveCompressible && thing2.def.saveCompressible) { return(PlaceSpotQuality.Unusable); } if (thing.def.category == ThingCategory.Item && thing2.def.category == ThingCategory.Item && (!thing2.CanStackWith(thing) || thing2.stackCount >= thing.def.stackLimit)) { return(PlaceSpotQuality.Unusable); } } if (thing is Building) { foreach (IntVec3 item in GenAdj.OccupiedRect(c, rot, thing.def.size)) { Building edifice = item.GetEdifice(map); if (edifice != null && GenSpawn.SpawningWipes(thing.def, edifice.def)) { return(PlaceSpotQuality.Awful); } } } if (c.GetRoom(map) != center.GetRoom(map)) { if (!map.reachability.CanReach(center, c, PathEndMode.OnCell, TraverseMode.PassDoors, Danger.Deadly)) { return(PlaceSpotQuality.Awful); } return(PlaceSpotQuality.Bad); } if (allowStacking) { for (int j = 0; j < list.Count; j++) { Thing thing3 = list[j]; if (thing3.def.category == ThingCategory.Item && thing3.CanStackWith(thing) && thing3.stackCount < thing.def.stackLimit) { return(PlaceSpotQuality.Perfect); } } } bool flag = (thing as Pawn)?.Downed ?? false; PlaceSpotQuality placeSpotQuality = PlaceSpotQuality.Perfect; for (int k = 0; k < list.Count; k++) { Thing thing4 = list[k]; if (thing4.def.IsDoor) { return(PlaceSpotQuality.Bad); } if (thing4 is Building_WorkTable) { return(PlaceSpotQuality.Bad); } Pawn pawn = thing4 as Pawn; if (pawn != null) { if (pawn.Downed | flag) { return(PlaceSpotQuality.Bad); } if ((int)placeSpotQuality > 3) { placeSpotQuality = PlaceSpotQuality.Okay; } } if (thing4.def.category == ThingCategory.Plant && thing4.def.selectable && (int)placeSpotQuality > 3) { placeSpotQuality = PlaceSpotQuality.Okay; } } return(placeSpotQuality); }