public static IEnumerable <Command> BuildFacilityCommands(BuildableDef building)
        {
            ThingDef thingDef = building as ThingDef;

            if (thingDef == null)
            {
                yield break;
            }
            CompProperties_AffectedByFacilities affectedByFacilities = thingDef.GetCompProperties <CompProperties_AffectedByFacilities>();

            if (affectedByFacilities == null)
            {
                yield break;
            }
            for (int i = 0; i < affectedByFacilities.linkableFacilities.Count; i++)
            {
                ThingDef         facility = affectedByFacilities.linkableFacilities[i];
                Designator_Build des      = BuildCopyCommandUtility.FindAllowedDesignator(facility, true);
                if (des != null)
                {
                    yield return(des);
                }
            }
            yield break;
        }
        public static IEnumerable <Command> BuildFacilityCommands(BuildableDef building)
        {
            ThingDef thingDef = building as ThingDef;

            if (thingDef != null)
            {
                CompProperties_AffectedByFacilities affectedByFacilities = thingDef.GetCompProperties <CompProperties_AffectedByFacilities>();
                if (affectedByFacilities != null)
                {
                    int i = 0;
                    Designator_Build des;
                    while (true)
                    {
                        if (i >= affectedByFacilities.linkableFacilities.Count)
                        {
                            yield break;
                        }
                        ThingDef facility = affectedByFacilities.linkableFacilities[i];
                        des = BuildCopyCommandUtility.FindAllowedDesignator(facility);
                        if (des != null)
                        {
                            break;
                        }
                        i++;
                    }
                    yield return((Command)des);

                    /*Error: Unable to find new state assignment for yield return*/;
                }
            }
        }
        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 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;
        }
        public static IEnumerable <Thing> PotentialThingsToLinkTo(ThingDef myDef, IntVec3 myPos, Rot4 myRot, Map map)
        {
            alreadyReturnedCount.Clear();
            CompProperties_AffectedByFacilities compProperties = myDef.GetCompProperties <CompProperties_AffectedByFacilities>();

            if (compProperties.linkableFacilities == null)
            {
                yield break;
            }
            IEnumerable <Thing> enumerable = Enumerable.Empty <Thing>();

            for (int i = 0; i < compProperties.linkableFacilities.Count; i++)
            {
                enumerable = enumerable.Concat(map.listerThings.ThingsOfDef(compProperties.linkableFacilities[i]));
            }
            Vector3 myTrueCenter = GenThing.TrueCenter(myPos, myRot, myDef.size, myDef.Altitude);
            IOrderedEnumerable <Thing> orderedEnumerable = from x in enumerable
                                                           orderby Vector3.Distance(myTrueCenter, x.TrueCenter()), x.Position.x, x.Position.z
            select x;

            foreach (Thing item in orderedEnumerable)
            {
                if (!CanPotentiallyLinkTo_Static(item, myDef, myPos, myRot))
                {
                    continue;
                }
                CompProperties_Facility compProperties2 = item.def.GetCompProperties <CompProperties_Facility>();
                if (alreadyReturnedCount.ContainsKey(item.def))
                {
                    if (alreadyReturnedCount[item.def] >= compProperties2.maxSimultaneous)
                    {
                        continue;
                    }
                }
                else
                {
                    alreadyReturnedCount.Add(item.def, 0);
                }
                alreadyReturnedCount[item.def]++;
                yield return(item);
            }
        }
        public override void ResolveReferences(ThingDef parentDef)
        {
            linkableBuildings = new List <ThingDef>();
            List <ThingDef> allDefsListForReading = DefDatabase <ThingDef> .AllDefsListForReading;

            for (int i = 0; i < allDefsListForReading.Count; i++)
            {
                CompProperties_AffectedByFacilities compProperties = allDefsListForReading[i].GetCompProperties <CompProperties_AffectedByFacilities>();
                if (compProperties != null && compProperties.linkableFacilities != null)
                {
                    for (int j = 0; j < compProperties.linkableFacilities.Count; j++)
                    {
                        if (compProperties.linkableFacilities[j] == parentDef)
                        {
                            linkableBuildings.Add(allDefsListForReading[i]);
                            break;
                        }
                    }
                }
            }
        }
        public override void ResolveReferences(ThingDef parentDef)
        {
            this.linkableBuildings = new List <ThingDef>();
            List <ThingDef> allDefsListForReading = DefDatabase <ThingDef> .AllDefsListForReading;

            for (int i = 0; i < allDefsListForReading.Count; i++)
            {
                CompProperties_AffectedByFacilities compProperties = allDefsListForReading[i].GetCompProperties <CompProperties_AffectedByFacilities>();
                if (compProperties != null && compProperties.linkableFacilities != null)
                {
                    int num = 0;
                    while (num < compProperties.linkableFacilities.Count)
                    {
                        if (compProperties.linkableFacilities[num] != parentDef)
                        {
                            num++;
                            continue;
                        }
                        this.linkableBuildings.Add(allDefsListForReading[i]);
                        break;
                    }
                }
            }
        }