public bool CanPotentiallyLinkTo(ThingDef facilityDef, IntVec3 facilityPos, Rot4 facilityRot) { if (!CompAffectedByFacilities.CanPotentiallyLinkTo_Static(facilityDef, facilityPos, facilityRot, this.parent.def, this.parent.Position, this.parent.Rotation)) { return(false); } if (!this.IsPotentiallyValidFacilityForMe(facilityDef, facilityPos, facilityRot)) { return(false); } int num = 0; bool flag = false; for (int i = 0; i < this.linkedFacilities.Count; i++) { if (this.linkedFacilities[i].def == facilityDef) { num++; if (this.IsBetter(facilityDef, facilityPos, facilityRot, this.linkedFacilities[i])) { flag = true; break; } } } if (flag) { return(true); } CompProperties_Facility compProperties = facilityDef.GetCompProperties <CompProperties_Facility>(); return(num + 1 <= compProperties.maxSimultaneous); }
public static IEnumerable <Thing> PotentialThingsToLinkTo(ThingDef myDef, IntVec3 myPos, Rot4 myRot, Map map) { _003CPotentialThingsToLinkTo_003Ec__Iterator1 _003CPotentialThingsToLinkTo_003Ec__Iterator = (_003CPotentialThingsToLinkTo_003Ec__Iterator1) /*Error near IL_0034: stateMachine*/; CompAffectedByFacilities.alreadyReturnedCount.Clear(); CompProperties_AffectedByFacilities myProps = myDef.GetCompProperties <CompProperties_AffectedByFacilities>(); if (myProps.linkableFacilities != null) { IEnumerable <Thing> candidates = Enumerable.Empty <Thing>(); for (int i = 0; i < myProps.linkableFacilities.Count; i++) { candidates = candidates.Concat(map.listerThings.ThingsOfDef(myProps.linkableFacilities[i])); } Vector3 myTrueCenter = Gen.TrueCenter(myPos, myRot, myDef.size, myDef.Altitude); IOrderedEnumerable <Thing> sortedCandidates = (from x in candidates orderby Vector3.Distance(myTrueCenter, x.TrueCenter()) select x).ThenBy(delegate(Thing x) { IntVec3 position2 = x.Position; return(position2.x); }).ThenBy(delegate(Thing x) { IntVec3 position = x.Position; return(position.z); }); foreach (Thing item in sortedCandidates) { if (CompAffectedByFacilities.CanPotentiallyLinkTo_Static(item, myDef, myPos, myRot)) { CompProperties_Facility facilityProps = item.def.GetCompProperties <CompProperties_Facility>(); if (CompAffectedByFacilities.alreadyReturnedCount.ContainsKey(item.def)) { if (CompAffectedByFacilities.alreadyReturnedCount[item.def] < facilityProps.maxSimultaneous) { goto IL_0232; } continue; } CompAffectedByFacilities.alreadyReturnedCount.Add(item.def, 0); goto IL_0232; } continue; IL_0232: Dictionary <ThingDef, int> dictionary; ThingDef def; (dictionary = CompAffectedByFacilities.alreadyReturnedCount)[def = item.def] = dictionary[def] + 1; yield return(item); /*Error: Unable to find new state assignment for yield return*/; } } yield break; IL_02b1: /*Error near IL_02b2: Unexpected return in MoveNext()*/; }
public static bool CanPotentiallyLinkTo_Static(Thing facility, ThingDef myDef, IntVec3 myPos, Rot4 myRot) { if (!CompAffectedByFacilities.CanPotentiallyLinkTo_Static(facility.def, facility.Position, facility.Rotation, myDef, myPos, myRot)) { return(false); } if (!CompAffectedByFacilities.IsPotentiallyValidFacilityForMe_Static(facility, myDef, myPos, myRot)) { return(false); } return(true); }
public static IEnumerable <Thing> PotentialThingsToLinkTo(ThingDef myDef, IntVec3 myPos, Rot4 myRot, Map map) { CompAffectedByFacilities.alreadyReturnedCount.Clear(); CompProperties_AffectedByFacilities myProps = myDef.GetCompProperties <CompProperties_AffectedByFacilities>(); if (myProps.linkableFacilities == null) { yield break; } IEnumerable <Thing> candidates = Enumerable.Empty <Thing>(); for (int i = 0; i < myProps.linkableFacilities.Count; i++) { candidates = candidates.Concat(map.listerThings.ThingsOfDef(myProps.linkableFacilities[i])); } Vector3 myTrueCenter = GenThing.TrueCenter(myPos, myRot, myDef.size, myDef.Altitude); IOrderedEnumerable <Thing> sortedCandidates = from x in candidates orderby Vector3.Distance(myTrueCenter, x.TrueCenter()), x.Position.x, x.Position.z select x; foreach (Thing th in sortedCandidates) { if (CompAffectedByFacilities.CanPotentiallyLinkTo_Static(th, myDef, myPos, myRot)) { CompProperties_Facility facilityProps = th.def.GetCompProperties <CompProperties_Facility>(); if (CompAffectedByFacilities.alreadyReturnedCount.ContainsKey(th.def)) { if (CompAffectedByFacilities.alreadyReturnedCount[th.def] >= facilityProps.maxSimultaneous) { continue; } } else { CompAffectedByFacilities.alreadyReturnedCount.Add(th.def, 0); } Dictionary <ThingDef, int> dictionary; ThingDef def; (dictionary = CompAffectedByFacilities.alreadyReturnedCount)[def = th.def] = dictionary[def] + 1; yield return(th); } } yield break; }