Beispiel #1
0
        public void TryLaunch(int destinationTile, TransportPodsArrivalAction arrivalAction)
        {
            if (!parent.Spawned)
            {
                Log.Error(string.Concat("Tried to launch ", parent, ", but it's unspawned."));
                return;
            }
            List <CompTransporter> transportersInGroup = TransportersInGroup;

            if (transportersInGroup == null)
            {
                Log.Error(string.Concat("Tried to launch ", parent, ", but it's not in any group."));
            }
            else
            {
                if (!LoadingInProgressOrReadyToLaunch || !AllInGroupConnectedToFuelingPort || !AllFuelingPortSourcesInGroupHaveAnyFuel)
                {
                    return;
                }
                Map         map         = parent.Map;
                int         num         = Find.WorldGrid.TraversalDistanceBetween(map.Tile, destinationTile);
                CompShuttle compShuttle = parent.TryGetComp <CompShuttle>();
                if (num <= MaxLaunchDistance || (compShuttle != null && compShuttle.IsMissionShuttle))
                {
                    Transporter.TryRemoveLord(map);
                    int   groupID = Transporter.groupID;
                    float amount  = Mathf.Max(FuelNeededToLaunchAtDist(num), 1f);
                    compShuttle?.SendLaunchedSignals(transportersInGroup);
                    for (int i = 0; i < transportersInGroup.Count; i++)
                    {
                        CompTransporter compTransporter = transportersInGroup[i];
                        compTransporter.Launchable.FuelingPortSource?.TryGetComp <CompRefuelable>().ConsumeFuel(amount);
                        ThingOwner    directlyHeldThings = compTransporter.GetDirectlyHeldThings();
                        ActiveDropPod activeDropPod      = (ActiveDropPod)ThingMaker.MakeThing(ThingDefOf.ActiveDropPod);
                        activeDropPod.Contents = new ActiveDropPodInfo();
                        activeDropPod.Contents.innerContainer.TryAddRangeOrTransfer(directlyHeldThings, canMergeWithExistingStacks: true, destroyLeftover: true);
                        DropPodLeaving obj = (DropPodLeaving)SkyfallerMaker.MakeSkyfaller(Props.skyfallerLeaving ?? ThingDefOf.DropPodLeaving, activeDropPod);
                        obj.groupID         = groupID;
                        obj.destinationTile = destinationTile;
                        obj.arrivalAction   = arrivalAction;
                        obj.worldObjectDef  = ((compShuttle != null) ? WorldObjectDefOf.TravelingShuttle : WorldObjectDefOf.TravelingTransportPods);
                        compTransporter.CleanUpLoadingVars(map);
                        compTransporter.parent.Destroy();
                        GenSpawn.Spawn(obj, compTransporter.parent.Position, map);
                    }
                    CameraJumper.TryHideWorld();
                }
            }
        }