Esempio n. 1
0
        public static void Postfix(Caravan __instance, ref IEnumerable <Gizmo> __result)
        {
            float masss = 0.0f;

            foreach (Pawn pawn in __instance.pawns.InnerListForReading)
            {
                for (int index = 0; index < pawn.inventory.innerContainer.Count; ++index)
                {
                    if (pawn.inventory.innerContainer[index].def.defName != "Building_Helicopter")
                    {
                        masss += pawn.inventory.innerContainer[index].def.BaseMass * (float)pawn.inventory.innerContainer[index].stackCount;
                    }
                }
            }
            foreach (Pawn pawn in __instance.pawns.InnerListForReading)
            {
                Pawn_InventoryTracker pinv = pawn.inventory;
                for (int i = 0; i < pinv.innerContainer.Count; i++)
                {
                    if (pinv.innerContainer[i].def.defName == "Building_Helicopter")
                    {
                        Command_Action commandAction1 = new Command_Action();
                        commandAction1.defaultLabel = "CommandLaunchGroup".Translate();
                        commandAction1.defaultDesc  = "CommandLaunchGroupDesc".Translate();
                        commandAction1.icon         = ContentFinder <Texture2D> .Get("UI/Commands/LaunchShip", true);

                        commandAction1.alsoClickIfOtherInGroupClicked = false;
                        commandAction1.action = (Action)(() =>
                        {
                            float massCapacity = pinv.innerContainer[i].TryGetComp <CompTransporter>().Props.massCapacity;
                            if ((double)masss <= (double)massCapacity)
                            {
                                pinv.innerContainer[i].TryGetComp <CompLaunchableHelicopter>().WorldStartChoosingDestination(__instance);
                            }
                            else
                            {
                                Messages.Message("TooBigTransportersMassUsage".Translate() + "(" + (object)(float)((double)massCapacity - (double)masss) + "KG)", MessageTypeDefOf.RejectInput, false);
                            }
                        });
                        List <Gizmo> list = __result.ToList <Gizmo>();
                        list.Add((Gizmo)commandAction1);
                        Command_Action commandAction2 = new Command_Action();
                        commandAction2.defaultLabel = "CommandAddFuel".Translate();
                        commandAction2.defaultDesc  = "CommandAddFuelDesc".Translate();
                        commandAction2.icon         = ContentFinder <Texture2D> .Get("Things/Item/Resource/Chemfuel", true);

                        commandAction2.alsoClickIfOtherInGroupClicked = false;
                        commandAction2.action = (Action)(() =>
                        {
                            bool flag = false;
                            int count = 0;
                            CompRefuelable comp = pinv.innerContainer[i].TryGetComp <CompRefuelable>();
                            List <Thing> thingList = CaravanInventoryUtility.AllInventoryItems(__instance);
                            for (int index = 0; index < thingList.Count; ++index)
                            {
                                if (thingList[index].def == ThingDefOf.Chemfuel)
                                {
                                    count = thingList[index].stackCount;
                                    Pawn ownerOf = CaravanInventoryUtility.GetOwnerOf(__instance, thingList[index]);
                                    float num = comp.Props.fuelCapacity - comp.Fuel;
                                    if ((double)num < 1.0 && (double)num > 0.0)
                                    {
                                        count = 1;
                                    }
                                    if ((double)count * 1.0 >= (double)num)
                                    {
                                        count = (int)num;
                                    }
                                    if ((double)thingList[index].stackCount * 1.0 <= (double)count)
                                    {
                                        thingList[index].stackCount -= count;
                                        Thing thing = thingList[index];
                                        ownerOf.inventory.innerContainer.Remove(thing);
                                        thing.Destroy(DestroyMode.Vanish);
                                    }
                                    else if ((uint)count > 0U)
                                    {
                                        thingList[index].SplitOff(count).Destroy(DestroyMode.Vanish);
                                    }
                                    comp.GetType().GetField("fuel", BindingFlags.Instance | BindingFlags.NonPublic).SetValue((object)comp, (object)(float)((double)comp.Fuel + (double)count));
                                    flag = true;
                                    break;
                                }
                            }
                            if (flag)
                            {
                                Messages.Message("AddFuelDoneMsg".Translate((object)count, (object)comp.Fuel), MessageTypeDefOf.PositiveEvent, false);
                            }
                            else
                            {
                                Messages.Message("NonOilMsg".Translate(), MessageTypeDefOf.RejectInput, false);
                            }
                        });
                        list.Add((Gizmo)commandAction2);
                        Gizmo_MapRefuelableFuelStatus refuelableFuelStatus = new Gizmo_MapRefuelableFuelStatus()
                        {
                            nowFuel   = pinv.innerContainer[i].TryGetComp <CompRefuelable>().Fuel,
                            maxFuel   = pinv.innerContainer[i].TryGetComp <CompRefuelable>().Props.fuelCapacity,
                            compLabel = pinv.innerContainer[i].TryGetComp <CompRefuelable>().Props.FuelGizmoLabel
                        };
                        list.Add((Gizmo)refuelableFuelStatus);
                        __result = (IEnumerable <Gizmo>)list;
                        return;
                    }
                }
            }
        }
        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(CompLaunchableSRTS.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();

                    // Neceros Edit
                    Thing thing = ThingMaker.MakeThing(ThingDef.Named(parent.def.defName), (ThingDef)null);
                    thing.SetFactionDirect(Faction.OfPlayer);
                    thing.Rotation = this.FuelingPortSource.Rotation;
                    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);

                    // Neceros Edit
                    ActiveDropPod activeDropPod = (ActiveDropPod)ThingMaker.MakeThing(ThingDef.Named(parent.def.defName + "_Active"), null);
                    activeDropPod.Contents = new ActiveDropPodInfo();
                    activeDropPod.Contents.innerContainer.TryAddRangeOrTransfer((IEnumerable <Thing>)directlyHeldThings, true, true);

                    // Neceros Edit
                    SRTSLeaving srtsLeaving = (SRTSLeaving)SkyfallerMaker.MakeSkyfaller(ThingDef.Named(parent.def.defName + "_Leaving"), (Thing)activeDropPod);
                    srtsLeaving.rotation        = this.FuelingPortSource.Rotation;
                    srtsLeaving.groupID         = groupId;
                    srtsLeaving.destinationTile = destinationTile;
                    srtsLeaving.arrivalAction   = arrivalAction;
                    comp1.CleanUpLoadingVars(map);
                    IntVec3 position = fuelingPortSource.Position;
                    SRTSStatic.SRTSDestroy((Thing)fuelingPortSource, DestroyMode.Vanish);
                    GenSpawn.Spawn((Thing)srtsLeaving, 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(CompLaunchableSRTS.FuelNeededToLaunchAtDist((float)num), 1f);
                    if (this.FuelingPortSource != null)
                    {
                        this.FuelingPortSource.TryGetComp <CompRefuelable>().ConsumeFuel(amount);
                    }
                    ThingOwner <Pawn> directlyHeldThings = (ThingOwner <Pawn>)cafr.GetDirectlyHeldThings();
                    Thing             thing = null;
                    foreach (Pawn pawn in directlyHeldThings.InnerListForReading)
                    {
                        Pawn_InventoryTracker inventory = pawn.inventory;
                        for (int index = 0; index < inventory.innerContainer.Count; ++index)
                        {
                            // Neceros Edit
                            if (inventory.innerContainer[index].TryGetComp <CompLaunchableSRTS>() != null)
                            {
                                thing = inventory.innerContainer[index];
                                inventory.innerContainer[index].holdingOwner.Remove(inventory.innerContainer[index]);
                                break;
                            }
                        }
                    }
                    /*Add caravan items to SRTS - SmashPhil */
                    foreach (Pawn p in directlyHeldThings.InnerListForReading)
                    {
                        p.inventory.innerContainer.InnerListForReading.ForEach(x => AddThingsToSRTS(x));
                        p.inventory.innerContainer.Clear();
                    }

                    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);
                    }

                    // Neceros Edit
                    ActiveDropPod activeDropPod = (ActiveDropPod)ThingMaker.MakeThing(ThingDef.Named(parent.def.defName + "_Active"), (ThingDef)null);
                    activeDropPod.Contents = new ActiveDropPodInfo();
                    activeDropPod.Contents.innerContainer.TryAddRangeOrTransfer((IEnumerable <Thing>)thingOwner, true, true);
                    activeDropPod.Contents.innerContainer.TryAddRangeOrTransfer((IEnumerable <Thing>)thingsInsideShip, true, true);
                    thingsInsideShip.Clear();

                    cafr.RemoveAllPawns();
                    if (cafr.Spawned)
                    {
                        Find.WorldObjects.Remove((WorldObject)cafr);
                    }
                    TravelingTransportPods travelingTransportPods = (TravelingTransportPods)WorldObjectMaker.MakeWorldObject(DefDatabase <WorldObjectDef> .GetNamed("TravelingSRTS", 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();
                }
            }
        }
        public static void Postfix(Caravan __instance, ref IEnumerable <Gizmo> __result)
        {
            float masss = 0;

            foreach (Pawn pawn in __instance.pawns.InnerListForReading)
            {
                for (int j = 0; j < pawn.inventory.innerContainer.Count; j++)
                {
                    if (pawn.inventory.innerContainer[j].def != USCMDefOf.RRY_USCM_DropshipUD4L)
                    {
                        masss += (pawn.inventory.innerContainer[j].def.BaseMass * pawn.inventory.innerContainer[j].stackCount);
                    }
                }
            }

            foreach (Pawn pawn in __instance.pawns.InnerListForReading)
            {
                Pawn_InventoryTracker pinv = pawn.inventory;
                for (int i = 0; i < pinv.innerContainer.Count; i++)
                {
                    if (pinv.innerContainer[i].def == USCMDefOf.RRY_USCM_DropshipUD4L)
                    {
                        Command_Action launch = new Command_Action();
                        launch.defaultLabel = "CommandSendShuttle".Translate();
                        launch.defaultDesc  = "CommandSendShuttleDesc".Translate();
                        launch.icon         = ContentFinder <Texture2D> .Get("UI/Commands/LaunchShip", true);

                        launch.alsoClickIfOtherInGroupClicked = false;
                        launch.action = delegate
                        {
                            float maxmass = pinv.innerContainer[i].TryGetComp <CompTransporter>().Props.massCapacity;
                            if (masss <= maxmass)
                            {
                                pinv.innerContainer[i].TryGetComp <CompUSCMDropship>().WorldStartChoosingDestination(__instance);
                            }
                            else
                            {
                                Messages.Message("TooBigTransportersMassUsage".Translate() + "(" + (maxmass - masss) + "KG)", MessageTypeDefOf.RejectInput, false);
                            }
                        };

                        List <Gizmo> newr = __result.ToList();
                        newr.Add(launch);

                        Command_Action addFuel = new Command_Action();
                        addFuel.defaultLabel = "USCM_Dropship_CommandAddFuel".Translate();
                        addFuel.defaultDesc  = "USCM_Dropship_CommandAddFuelDesc".Translate();
                        addFuel.icon         = ContentFinder <Texture2D> .Get("Things/Item/Resource/Chemfuel", true);

                        addFuel.alsoClickIfOtherInGroupClicked = false;
                        addFuel.action = delegate
                        {
                            bool           hasAddFuel = false;
                            int            fcont      = 0;
                            CompRefuelable comprf     = pinv.innerContainer[i].TryGetComp <CompRefuelable>();
                            List <Thing>   list       = CaravanInventoryUtility.AllInventoryItems(__instance);
                            //pinv.innerContainer.Count
                            for (int j = 0; j < list.Count; j++)
                            {
                                if (list[j].def == ThingDefOf.Chemfuel)
                                {
                                    fcont = list[j].stackCount;
                                    Pawn  ownerOf = CaravanInventoryUtility.GetOwnerOf(__instance, list[j]);
                                    float need    = comprf.Props.fuelCapacity - comprf.Fuel;

                                    if (need < 1f && need > 0)
                                    {
                                        fcont = 1;
                                    }
                                    if (fcont * 1f >= need)
                                    {
                                        fcont = (int)need;
                                    }



                                    // Log.Warning("f&n is "+fcont+"/"+need);
                                    if (list[j].stackCount * 1f <= fcont)
                                    {
                                        list[j].stackCount -= fcont;
                                        Thing thing = list[j];
                                        ownerOf.inventory.innerContainer.Remove(thing);
                                        thing.Destroy(DestroyMode.Vanish);
                                    }
                                    else
                                    {
                                        if (fcont != 0)
                                        {
                                            list[j].SplitOff(fcont).Destroy(DestroyMode.Vanish);
                                        }
                                    }


                                    Type      crtype = comprf.GetType();
                                    FieldInfo finfo  = crtype.GetField("fuel", BindingFlags.NonPublic | BindingFlags.Instance);
                                    finfo.SetValue(comprf, comprf.Fuel + fcont);
                                    hasAddFuel = true;
                                    break;
                                }
                            }
                            if (hasAddFuel)
                            {
                                Messages.Message("USCM_Dropship_AddFuelDoneMsg".Translate(fcont, comprf.Fuel), MessageTypeDefOf.PositiveEvent, false);
                            }
                            else
                            {
                                Messages.Message("USCM_Dropship_NoFuelMsg".Translate(), MessageTypeDefOf.RejectInput, false);
                            }
                        };

                        newr.Add(addFuel);

                        Gizmo_MapRefuelableFuelStatus fuelStat = new Gizmo_MapRefuelableFuelStatus
                        {
                            nowFuel   = pinv.innerContainer[i].TryGetComp <CompRefuelable>().Fuel,
                            maxFuel   = pinv.innerContainer[i].TryGetComp <CompRefuelable>().Props.fuelCapacity,
                            compLabel = pinv.innerContainer[i].TryGetComp <CompRefuelable>().Props.FuelGizmoLabel
                        };


                        newr.Add(fuelStat);

                        __result = newr;
                        return;
                    }
                }
            }
        }
Esempio n. 4
0
        private void TryLaunchBombRun(int destTile, Pair <IntVec3, IntVec3> targetPoints, IEnumerable <IntVec3> bombCells, MapParent mapParent)
        {
            if (!this.parent.Spawned)
            {
                Log.Error("Tried to launch " + this.parent + ", but it's unspawned.");
                return;
            }

            if (!CompLauncher.LoadingInProgressOrReadyToLaunch || !CompLauncher.AllInGroupConnectedToFuelingPort || !CompLauncher.AllFuelingPortSourcesInGroupHaveAnyFuel)
            {
                return;
            }

            Map map = this.parent.Map;
            int num = Find.WorldGrid.TraversalDistanceBetween(map.Tile, destTile);

            if (num > CompLauncher.MaxLaunchDistance)
            {
                return;
            }
            CompLauncher.Transporter.TryRemoveLord(map);
            int             groupID        = CompLauncher.Transporter.groupID;
            float           amount         = Mathf.Max(CompLaunchableSRTS.FuelNeededToLaunchAtDist((float)num, this.parent.GetComp <CompLaunchableSRTS>().BaseFuelPerTile), 1f);
            CompTransporter comp1          = CompLauncher.FuelingPortSource.TryGetComp <CompTransporter>();
            Building        fuelPortSource = CompLauncher.FuelingPortSource;

            if (fuelPortSource != null)
            {
                fuelPortSource.TryGetComp <CompRefuelable>().ConsumeFuel(amount);
            }
            ThingOwner directlyHeldThings = comp1.GetDirectlyHeldThings();

            Thing thing = ThingMaker.MakeThing(ThingDef.Named(parent.def.defName), null);

            thing.SetFactionDirect(Faction.OfPlayer);
            thing.Rotation = CompLauncher.FuelingPortSource.Rotation;
            CompRefuelable comp2 = thing.TryGetComp <CompRefuelable>();

            comp2.GetType().GetField("fuel", BindingFlags.Instance | BindingFlags.NonPublic).SetValue((object)comp2, (object)fuelPortSource.TryGetComp <CompRefuelable>().Fuel);
            comp2.TargetFuelLevel = fuelPortSource.TryGetComp <CompRefuelable>().TargetFuelLevel;
            thing.stackCount      = 1;
            directlyHeldThings.TryAddOrTransfer(thing, true);

            ActiveDropPod activeDropPod = (ActiveDropPod)ThingMaker.MakeThing(ThingDef.Named(parent.def.defName + "_Active"), null);

            activeDropPod.Contents = new ActiveDropPodInfo();
            activeDropPod.Contents.innerContainer.TryAddRangeOrTransfer((IEnumerable <Thing>)directlyHeldThings, true, true);

            SRTSLeaving srtsLeaving = (SRTSLeaving)SkyfallerMaker.MakeSkyfaller(ThingDef.Named(parent.def.defName + "_Leaving"), (Thing)activeDropPod);

            srtsLeaving.rotation        = CompLauncher.FuelingPortSource.Rotation;
            srtsLeaving.groupID         = groupID;
            srtsLeaving.destinationTile = destTile;
            srtsLeaving.arrivalAction   = new SRTSArrivalActionBombRun(mapParent, targetPoints, bombCells, this.bombType, map, CompLauncher.FuelingPortSource.Position);

            comp1.CleanUpLoadingVars(map);
            IntVec3 position = fuelPortSource.Position;

            SRTSStatic.SRTSDestroy((Thing)fuelPortSource, DestroyMode.Vanish);
            GenSpawn.Spawn((Thing)srtsLeaving, position, map, WipeMode.Vanish);
            CameraJumper.TryHideWorld();
        }
        // 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();
            }
        }