public static IEnumerable <FloatMenuOption> GetSettle(
            SettlementBase bs,
            IEnumerable <IThingHolder> pods,
            CompLaunchableHelicopter representative,
            Caravan car)
        {
            foreach (FloatMenuOption floatMenuOption in HelicopterStatic.GetMapParent((MapParent)bs, pods, representative, car))
            {
                FloatMenuOption o = floatMenuOption;
                yield return(o);

                o = (FloatMenuOption)null;
            }
            foreach (FloatMenuOption visitFloatMenuOption in HelicoptersArrivalActionUtility.GetVisitFloatMenuOptions(representative, pods, bs, car))
            {
                FloatMenuOption f = visitFloatMenuOption;
                yield return(f);

                f = (FloatMenuOption)null;
            }
            foreach (FloatMenuOption giftFloatMenuOption in HelicoptersArrivalActionUtility.GetGIFTFloatMenuOptions(representative, pods, bs, car))
            {
                FloatMenuOption f2 = giftFloatMenuOption;
                yield return(f2);

                f2 = (FloatMenuOption)null;
            }
            foreach (FloatMenuOption atkFloatMenuOption in HelicoptersArrivalActionUtility.GetATKFloatMenuOptions(representative, pods, bs, car))
            {
                FloatMenuOption f3 = atkFloatMenuOption;
                yield return(f3);

                f3 = (FloatMenuOption)null;
            }
        }
        public IEnumerable <FloatMenuOption> GetTransportPodsFloatMenuOptionsAt(
            int tile,
            Caravan car = null)
        {
            bool anything = false;
            IEnumerable <IThingHolder> pods = this.TransportersInGroup.Cast <IThingHolder>();

            if (car != null)
            {
                List <Caravan> rliss = new List <Caravan>();
                rliss.Add(car);
                pods  = rliss.Cast <IThingHolder>();
                rliss = (List <Caravan>)null;
            }
            if (car == null)
            {
                if (TransportPodsArrivalAction_FormCaravan.CanFormCaravanAt(pods, tile) && !Find.WorldObjects.AnySettlementBaseAt(tile) && !Find.WorldObjects.AnySiteAt(tile))
                {
                    anything = true;
                    yield return(new FloatMenuOption("FormCaravanHere".Translate(), (Action)(() => this.TryLaunch(tile, (TransportPodsArrivalAction) new TransportPodsArrivalAction_FormCaravan(), car)), MenuOptionPriority.Default, (Action)null, (Thing)null, 0.0f, (Func <Rect, bool>)null, (WorldObject)null));
                }
            }
            else if (!Find.WorldObjects.AnySettlementBaseAt(tile) && !Find.WorldObjects.AnySiteAt(tile) && !Find.World.Impassable(tile))
            {
                anything = true;
                yield return(new FloatMenuOption("FormCaravanHere".Translate(), (Action)(() => this.TryLaunch(tile, (TransportPodsArrivalAction) new TransportPodsArrivalAction_FormCaravan(), car)), MenuOptionPriority.Default, (Action)null, (Thing)null, 0.0f, (Func <Rect, bool>)null, (WorldObject)null));
            }
            List <WorldObject> worldObjects = Find.WorldObjects.AllWorldObjects;

            for (int i = 0; i < worldObjects.Count; ++i)
            {
                if (worldObjects[i].Tile == tile)
                {
                    IEnumerable <FloatMenuOption> nowre = HelicopterStatic.getFM(worldObjects[i], pods, this, car);
                    if (nowre.ToList <FloatMenuOption>().Count < 1)
                    {
                        yield return(new FloatMenuOption("FormCaravanHere".Translate(), (Action)(() => this.TryLaunch(tile, (TransportPodsArrivalAction) new TransportPodsArrivalAction_FormCaravan(), car)), MenuOptionPriority.Default, (Action)null, (Thing)null, 0.0f, (Func <Rect, bool>)null, (WorldObject)null));
                    }
                    else
                    {
                        foreach (FloatMenuOption floatMenuOption in nowre)
                        {
                            FloatMenuOption o = floatMenuOption;
                            anything = true;
                            yield return(o);

                            o = (FloatMenuOption)null;
                        }
                    }
                    nowre = (IEnumerable <FloatMenuOption>)null;
                }
            }
            if (!anything && !Find.World.Impassable(tile))
            {
                yield return(new FloatMenuOption("TransportPodsContentsWillBeLost".Translate(), (Action)(() => this.TryLaunch(tile, (TransportPodsArrivalAction)null, (Caravan)null)), MenuOptionPriority.Default, (Action)null, (Thing)null, 0.0f, (Func <Rect, bool>)null, (WorldObject)null));
            }
        }
        public static IEnumerable <FloatMenuOption> GetSite(
            Site site,
            IEnumerable <IThingHolder> pods,
            CompLaunchableHelicopter representative,
            Caravan car)
        {
            foreach (FloatMenuOption floatMenuOption in HelicopterStatic.GetMapParent((MapParent)site, pods, representative, car))
            {
                FloatMenuOption o = floatMenuOption;
                yield return(o);

                o = (FloatMenuOption)null;
            }
            foreach (FloatMenuOption floatMenuOption in HelicopterStatic.GetVisitSite(representative, pods, site, car))
            {
                FloatMenuOption o2 = floatMenuOption;
                yield return(o2);

                o2 = (FloatMenuOption)null;
            }
        }
 public static IEnumerable <FloatMenuOption> getFM(
     WorldObject wobj,
     IEnumerable <IThingHolder> ih,
     CompLaunchableHelicopter comp,
     Caravan car)
 {
     if (wobj is Caravan)
     {
         return(Enumerable.Empty <FloatMenuOption>());
     }
     if (wobj is Site)
     {
         return(HelicopterStatic.GetSite(wobj as Site, ih, comp, car));
     }
     if (wobj is SettlementBase)
     {
         return(HelicopterStatic.GetSettle(wobj as SettlementBase, ih, comp, car));
     }
     if (wobj is MapParent)
     {
         return(HelicopterStatic.GetMapParent(wobj as MapParent, ih, comp, car));
     }
     return(Enumerable.Empty <FloatMenuOption>());
 }
        // Token: 0x060028DE RID: 10462 RVA: 0x001354FC File Offset: 0x001338FC
        public IEnumerable <FloatMenuOption> GetTransportPodsFloatMenuOptionsAt(int tile, Caravan car = null)
        {
            bool anything = false;
            IEnumerable <IThingHolder> pods = this.TransportersInGroup.Cast <IThingHolder>();

            if (car != null)
            {
                List <Caravan> rliss = new List <Caravan>();
                rliss.Add(car);
                pods = rliss.Cast <IThingHolder>();
            }

            if (car == null)
            {
                if (TransportPodsArrivalAction_FormCaravan.CanFormCaravanAt(pods, tile) && !Find.WorldObjects.AnySettlementBaseAt(tile) && !Find.WorldObjects.AnySiteAt(tile))
                {
                    anything = true;
                    yield return(new FloatMenuOption("FormCaravanHere".Translate(), delegate
                    {
                        this.TryLaunch(tile, new TransportPodsArrivalAction_FormCaravan(), car);
                    }, MenuOptionPriority.Default, null, null, 0f, null, null));
                }
            }
            else
            {
                if (!Find.WorldObjects.AnySettlementBaseAt(tile) && !Find.WorldObjects.AnySiteAt(tile) && !Find.World.Impassable(tile))
                {
                    anything = true;
                    yield return(new FloatMenuOption("FormCaravanHere".Translate(), delegate
                    {
                        this.TryLaunch(tile, new TransportPodsArrivalAction_FormCaravan(), car);
                    }, MenuOptionPriority.Default, null, null, 0f, null, null));
                }
            }

            List <WorldObject> worldObjects = Find.WorldObjects.AllWorldObjects;

            for (int i = 0; i < worldObjects.Count; i++)
            {
                if (worldObjects[i].Tile == tile)
                {
                    IEnumerable <FloatMenuOption> nowre = HelicopterStatic.getFM(worldObjects[i], pods, this, car);
                    if (nowre.ToList().Count < 1)
                    {
                        yield return(new FloatMenuOption("FormCaravanHere".Translate(), delegate
                        {
                            this.TryLaunch(tile, new TransportPodsArrivalAction_FormCaravan(), car);
                        }, MenuOptionPriority.Default, null, null, 0f, null, null));
                    }
                    else
                    {
                        foreach (FloatMenuOption o in nowre)//worldObjects[i].GetTransportPodsFloatMenuOptions(this.TransportersInGroup.Cast<IThingHolder>(), this))
                        {
                            anything = true;
                            yield return(o);
                        }
                    }
                }
            }


            if (!anything && !Find.World.Impassable(tile))
            {
                yield return(new FloatMenuOption("TransportPodsContentsWillBeLost".Translate(), delegate
                {
                    this.TryLaunch(tile, null);
                }, MenuOptionPriority.Default, null, null, 0f, null, null));
            }

            yield break;
        }
        // Token: 0x060028DA RID: 10458 RVA: 0x001352F0 File Offset: 0x001336F0
        public void TryLaunch(int destinationTile, TransportPodsArrivalAction arrivalAction, Caravan cafr = null)
        {
            //Log.Warning("CARR:" + this.carr+"/"+cafr);
            if (cafr == null)
            {
                if (!this.parent.Spawned)
                {
                    Log.Error("Tried to launch " + this.parent + ", but it's unspawned.", false);
                    return;
                }
            }

            /*
             * List<CompTransporter> transportersInGroup = this.TransportersInGroup;
             * if (transportersInGroup == null)
             * {
             *  Log.Error("Tried to launch " + this.parent + ", but it's not in any group.", false);
             *  return;
             * }
             */
            if (this.parent.Spawned)
            {
                if (!this.LoadingInProgressOrReadyToLaunch)
                {
                    return;
                }
            }
            if (!this.AllInGroupConnectedToFuelingPort || !this.AllFuelingPortSourcesInGroupHaveAnyFuel)
            {
                return;
            }
            if (cafr == null)
            {
                Map map = this.parent.Map;
                int num = Find.WorldGrid.TraversalDistanceBetween(map.Tile, destinationTile, true, int.MaxValue);
                if (num > this.MaxLaunchDistance)
                {
                    return;
                }
                this.Transporter.TryRemoveLord(map);
                int   groupID = this.Transporter.groupID;
                float amount  = Mathf.Max(CompLaunchableHelicopter.FuelNeededToLaunchAtDist((float)num), 1f);
                //for (int i = 0; i < transportersInGroup.Count; i++)

                CompTransporter compTransporter   = this.FuelingPortSource.TryGetComp <CompTransporter>(); //transportersInGroup[i];
                Building        fuelingPortSource = this.FuelingPortSource;                                //compTransporter.Launchable.FuelingPortSource;
                if (fuelingPortSource != null)
                {
                    fuelingPortSource.TryGetComp <CompRefuelable>().ConsumeFuel(amount);
                }
                ThingOwner directlyHeldThings = compTransporter.GetDirectlyHeldThings();

                Thing helicopter = ThingMaker.MakeThing(ThingDef.Named("Building_Helicopter"));
                helicopter.SetFactionDirect(Faction.OfPlayer);

                CompRefuelable compr  = helicopter.TryGetComp <CompRefuelable>();
                Type           tcr    = compr.GetType();
                FieldInfo      finfos = tcr.GetField("fuel", BindingFlags.NonPublic | BindingFlags.Instance);
                finfos.SetValue(compr, fuelingPortSource.TryGetComp <CompRefuelable>().Fuel);

                compr.TargetFuelLevel = fuelingPortSource.TryGetComp <CompRefuelable>().TargetFuelLevel;

                helicopter.stackCount = 1;
                directlyHeldThings.TryAddOrTransfer(helicopter);

                ActiveDropPod activeDropPod = (ActiveDropPod)ThingMaker.MakeThing(ThingDef.Named("ActiveHelicopter"), null);
                activeDropPod.Contents = new ActiveDropPodInfo();
                activeDropPod.Contents.innerContainer.TryAddRangeOrTransfer(directlyHeldThings, true, true);
                HelicopterLeaving dropPodLeaving = (HelicopterLeaving)SkyfallerMaker.MakeSkyfaller(ThingDef.Named("HelicopterLeaving"), activeDropPod);
                dropPodLeaving.groupID         = groupID;
                dropPodLeaving.destinationTile = destinationTile;
                dropPodLeaving.arrivalAction   = arrivalAction;
                compTransporter.CleanUpLoadingVars(map);
                //compTransporter.parent
                IntVec3 poc = fuelingPortSource.Position;
                // fuelingPortSource.Destroy(DestroyMode.Vanish);
                HelicopterStatic.HelicopterDestroy(fuelingPortSource, DestroyMode.Vanish);
                GenSpawn.Spawn(dropPodLeaving, poc, map, WipeMode.Vanish);

                CameraJumper.TryHideWorld();
            }
            else
            {
                int num = Find.WorldGrid.TraversalDistanceBetween(carr.Tile, destinationTile, true, int.MaxValue);
                if (num > this.MaxLaunchDistance)
                {
                    return;
                }
                float amount = Mathf.Max(CompLaunchableHelicopter.FuelNeededToLaunchAtDist((float)num), 1f);
                if (FuelingPortSource != null)
                {
                    FuelingPortSource.TryGetComp <CompRefuelable>().ConsumeFuel(amount);
                }


                ThingOwner <Pawn> directlyHeldThings = (ThingOwner <Pawn>)cafr.GetDirectlyHeldThings();
                Thing             helicopter         = null;
                foreach (Pawn pawn in directlyHeldThings.InnerListForReading)
                {
                    Pawn_InventoryTracker pinv = pawn.inventory;
                    for (int i = 0; i < pinv.innerContainer.Count; i++)
                    {
                        if (pinv.innerContainer[i].def.defName == ("Building_Helicopter"))
                        {
                            helicopter = pinv.innerContainer[i];
                            pinv.innerContainer[i].holdingOwner.Remove(pinv.innerContainer[i]);

                            break;
                        }
                    }
                }

                ThingOwner <Thing> finalto = new ThingOwner <Thing>();
                List <Pawn>        lpto    = directlyHeldThings.AsEnumerable <Pawn>().ToList();
                foreach (Pawn p in lpto)
                {
                    finalto.TryAddOrTransfer(p);
                }


                if (helicopter != null)
                {
                    // Log.Warning("TRY ADD"+helicopter);
                    if (helicopter.holdingOwner == null)
                    {
                        //Log.Warning("NULL");
                        //directlyHeldThings.
                        finalto.TryAddOrTransfer(helicopter, false);
                    }
                }


                ActiveDropPod activeDropPod = (ActiveDropPod)ThingMaker.MakeThing(ThingDef.Named("ActiveHelicopter"), null);
                activeDropPod.Contents = new ActiveDropPodInfo();
                activeDropPod.Contents.innerContainer.TryAddRangeOrTransfer(
                    //directlyHeldThings
                    finalto, true, true);

                cafr.RemoveAllPawns();
                if (cafr.Spawned)
                {
                    Find.WorldObjects.Remove(cafr);
                }

                TravelingTransportPods travelingTransportPods = (TravelingTransportPods)WorldObjectMaker.MakeWorldObject(DefDatabase <WorldObjectDef> .GetNamed("TravelingHelicopters", true));
                travelingTransportPods.Tile = cafr.Tile;
                travelingTransportPods.SetFaction(Faction.OfPlayer);
                travelingTransportPods.destinationTile = destinationTile;
                travelingTransportPods.arrivalAction   = arrivalAction;
                Find.WorldObjects.Add(travelingTransportPods);
                travelingTransportPods.AddPod(activeDropPod.Contents, true);
                activeDropPod.Contents = null;
                activeDropPod.Destroy(DestroyMode.Vanish);
                // CameraJumper.TryHideWorld();
                Find.WorldTargeter.StopTargeting();
            }
        }
 public void TryLaunch(
     int destinationTile,
     TransportPodsArrivalAction arrivalAction,
     Caravan cafr = null)
 {
     if (cafr == null && !this.parent.Spawned)
     {
         Log.Error("Tried to launch " + (object)this.parent + ", but it's unspawned.", false);
     }
     else
     {
         if (this.parent.Spawned && !this.LoadingInProgressOrReadyToLaunch || (!this.AllInGroupConnectedToFuelingPort || !this.AllFuelingPortSourcesInGroupHaveAnyFuel))
         {
             return;
         }
         if (cafr == null)
         {
             Map map = this.parent.Map;
             int num = Find.WorldGrid.TraversalDistanceBetween(map.Tile, destinationTile, true, int.MaxValue);
             if (num > this.MaxLaunchDistance)
             {
                 return;
             }
             this.Transporter.TryRemoveLord(map);
             int             groupId           = this.Transporter.groupID;
             float           amount            = Mathf.Max(CompLaunchableHelicopter.FuelNeededToLaunchAtDist((float)num), 1f);
             CompTransporter comp1             = this.FuelingPortSource.TryGetComp <CompTransporter>();
             Building        fuelingPortSource = this.FuelingPortSource;
             if (fuelingPortSource != null)
             {
                 fuelingPortSource.TryGetComp <CompRefuelable>().ConsumeFuel(amount);
             }
             ThingOwner directlyHeldThings = comp1.GetDirectlyHeldThings();
             Thing      thing = ThingMaker.MakeThing(ThingDef.Named("Building_Helicopter"), (ThingDef)null);
             thing.SetFactionDirect(Faction.OfPlayer);
             CompRefuelable comp2 = thing.TryGetComp <CompRefuelable>();
             comp2.GetType().GetField("fuel", BindingFlags.Instance | BindingFlags.NonPublic).SetValue((object)comp2, (object)fuelingPortSource.TryGetComp <CompRefuelable>().Fuel);
             comp2.TargetFuelLevel = fuelingPortSource.TryGetComp <CompRefuelable>().TargetFuelLevel;
             thing.stackCount      = 1;
             directlyHeldThings.TryAddOrTransfer(thing, true);
             ActiveDropPod activeDropPod = (ActiveDropPod)ThingMaker.MakeThing(ThingDef.Named("ActiveHelicopter"), (ThingDef)null);
             activeDropPod.Contents = new ActiveDropPodInfo();
             activeDropPod.Contents.innerContainer.TryAddRangeOrTransfer((IEnumerable <Thing>)directlyHeldThings, true, true);
             HelicopterLeaving helicopterLeaving = (HelicopterLeaving)SkyfallerMaker.MakeSkyfaller(ThingDef.Named("HelicopterLeaving"), (Thing)activeDropPod);
             helicopterLeaving.groupID         = groupId;
             helicopterLeaving.destinationTile = destinationTile;
             helicopterLeaving.arrivalAction   = arrivalAction;
             comp1.CleanUpLoadingVars(map);
             IntVec3 position = fuelingPortSource.Position;
             HelicopterStatic.HelicopterDestroy((Thing)fuelingPortSource, DestroyMode.Vanish);
             GenSpawn.Spawn((Thing)helicopterLeaving, position, map, WipeMode.Vanish);
             CameraJumper.TryHideWorld();
         }
         else
         {
             int num = Find.WorldGrid.TraversalDistanceBetween(this.carr.Tile, destinationTile, true, int.MaxValue);
             if (num > this.MaxLaunchDistance)
             {
                 return;
             }
             float amount = Mathf.Max(CompLaunchableHelicopter.FuelNeededToLaunchAtDist((float)num), 1f);
             if (this.FuelingPortSource != null)
             {
                 this.FuelingPortSource.TryGetComp <CompRefuelable>().ConsumeFuel(amount);
             }
             ThingOwner <Pawn> directlyHeldThings = (ThingOwner <Pawn>)cafr.GetDirectlyHeldThings();
             Thing             thing = (Thing)null;
             foreach (Pawn pawn in directlyHeldThings.InnerListForReading)
             {
                 Pawn_InventoryTracker inventory = pawn.inventory;
                 for (int index = 0; index < inventory.innerContainer.Count; ++index)
                 {
                     if (inventory.innerContainer[index].def.defName == "Building_Helicopter")
                     {
                         thing = inventory.innerContainer[index];
                         inventory.innerContainer[index].holdingOwner.Remove(inventory.innerContainer[index]);
                         break;
                     }
                 }
             }
             ThingOwner <Thing> thingOwner = new ThingOwner <Thing>();
             foreach (Pawn pawn in directlyHeldThings.AsEnumerable <Pawn>().ToList <Pawn>())
             {
                 thingOwner.TryAddOrTransfer((Thing)pawn, true);
             }
             if (thing != null && thing.holdingOwner == null)
             {
                 thingOwner.TryAddOrTransfer(thing, false);
             }
             ActiveDropPod activeDropPod = (ActiveDropPod)ThingMaker.MakeThing(ThingDef.Named("ActiveHelicopter"), (ThingDef)null);
             activeDropPod.Contents = new ActiveDropPodInfo();
             activeDropPod.Contents.innerContainer.TryAddRangeOrTransfer((IEnumerable <Thing>)thingOwner, true, true);
             cafr.RemoveAllPawns();
             if (cafr.Spawned)
             {
                 Find.WorldObjects.Remove((WorldObject)cafr);
             }
             TravelingTransportPods travelingTransportPods = (TravelingTransportPods)WorldObjectMaker.MakeWorldObject(DefDatabase <WorldObjectDef> .GetNamed("TravelingHelicopters", true));
             travelingTransportPods.Tile = cafr.Tile;
             travelingTransportPods.SetFaction(Faction.OfPlayer);
             travelingTransportPods.destinationTile = destinationTile;
             travelingTransportPods.arrivalAction   = arrivalAction;
             Find.WorldObjects.Add((WorldObject)travelingTransportPods);
             travelingTransportPods.AddPod(activeDropPod.Contents, true);
             activeDropPod.Contents = (ActiveDropPodInfo)null;
             activeDropPod.Destroy(DestroyMode.Vanish);
             Find.WorldTargeter.StopTargeting();
         }
     }
 }