예제 #1
0
        private void TryLaunch(GlobalTargetInfo target, PawnsArriveMode arriveMode, bool attackOnArrival)
        {
            if (!this.parent.Spawned)
            {
                Log.Error("Tried to launch " + this.parent + ", but it's unspawned.");
                return;
            }
            List <CompTransporter> transportersInGroup = this.TransportersInGroup;

            if (transportersInGroup == null)
            {
                Log.Error("Tried to launch " + this.parent + ", but it's not in any group.");
                return;
            }
            if (!this.LoadingInProgressOrReadyToLaunch || !this.AllInGroupConnectedToFuelingPort || !this.AllFuelingPortSourcesInGroupHaveAnyFuel)
            {
                return;
            }
            Map map = this.parent.Map;
            int num = Find.WorldGrid.TraversalDistanceBetween(map.Tile, target.Tile);

            if (num > this.MaxLaunchDistance)
            {
                return;
            }
            this.Transporter.TryRemoveLord(map);
            int   groupID = this.Transporter.groupID;
            float amount  = Mathf.Max(CompLaunchable.FuelNeededToLaunchAtDist((float)num), 1f);

            for (int i = 0; i < transportersInGroup.Count; i++)
            {
                CompTransporter compTransporter   = transportersInGroup[i];
                Building        fuelingPortSource = compTransporter.Launchable.FuelingPortSource;
                if (fuelingPortSource != null)
                {
                    fuelingPortSource.TryGetComp <CompRefuelable>().ConsumeFuel(amount);
                }
                ThingOwner    directlyHeldThings = compTransporter.GetDirectlyHeldThings();
                ActiveDropPod activeDropPod      = (ActiveDropPod)ThingMaker.MakeThing(ThingDefOf.ActiveDropPod, null);
                activeDropPod.Contents = new ActiveDropPodInfo();
                activeDropPod.Contents.innerContainer.TryAddRangeOrTransfer(directlyHeldThings, true, true);
                DropPodLeaving dropPodLeaving = (DropPodLeaving)SkyfallerMaker.MakeSkyfaller(ThingDefOf.DropPodLeaving, activeDropPod);
                dropPodLeaving.groupID         = groupID;
                dropPodLeaving.destinationTile = target.Tile;
                dropPodLeaving.destinationCell = target.Cell;
                dropPodLeaving.arriveMode      = arriveMode;
                dropPodLeaving.attackOnArrival = attackOnArrival;
                compTransporter.CleanUpLoadingVars(map);
                compTransporter.parent.Destroy(DestroyMode.Vanish);
                GenSpawn.Spawn(dropPodLeaving, compTransporter.parent.Position, map);
            }
        }
예제 #2
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();
                }
            }
        }
 public void TryLaunch(int destinationTile, TransportPodsArrivalAction arrivalAction)
 {
     if (!this.parent.Spawned)
     {
         Log.Error("Tried to launch " + this.parent + ", but it's unspawned.", false);
     }
     else
     {
         List <CompTransporter> transportersInGroup = this.TransportersInGroup;
         if (transportersInGroup == null)
         {
             Log.Error("Tried to launch " + this.parent + ", but it's not in any group.", false);
         }
         else if (this.LoadingInProgressOrReadyToLaunch && this.AllInGroupConnectedToFuelingPort && this.AllFuelingPortSourcesInGroupHaveAnyFuel)
         {
             Map map = this.parent.Map;
             int num = Find.WorldGrid.TraversalDistanceBetween(map.Tile, destinationTile, true, int.MaxValue);
             if (num <= this.MaxLaunchDistance)
             {
                 this.Transporter.TryRemoveLord(map);
                 int   groupID = this.Transporter.groupID;
                 float amount  = Mathf.Max(CompLaunchable.FuelNeededToLaunchAtDist((float)num), 1f);
                 for (int i = 0; i < transportersInGroup.Count; i++)
                 {
                     CompTransporter compTransporter   = transportersInGroup[i];
                     Building        fuelingPortSource = compTransporter.Launchable.FuelingPortSource;
                     if (fuelingPortSource != null)
                     {
                         fuelingPortSource.TryGetComp <CompRefuelable>().ConsumeFuel(amount);
                     }
                     ThingOwner    directlyHeldThings = compTransporter.GetDirectlyHeldThings();
                     ActiveDropPod activeDropPod      = (ActiveDropPod)ThingMaker.MakeThing(ThingDefOf.ActiveDropPod, null);
                     activeDropPod.Contents = new ActiveDropPodInfo();
                     activeDropPod.Contents.innerContainer.TryAddRangeOrTransfer(directlyHeldThings, true, true);
                     DropPodLeaving dropPodLeaving = (DropPodLeaving)SkyfallerMaker.MakeSkyfaller(ThingDefOf.DropPodLeaving, activeDropPod);
                     dropPodLeaving.groupID         = groupID;
                     dropPodLeaving.destinationTile = destinationTile;
                     dropPodLeaving.arrivalAction   = arrivalAction;
                     compTransporter.CleanUpLoadingVars(map);
                     compTransporter.parent.Destroy(DestroyMode.Vanish);
                     GenSpawn.Spawn(dropPodLeaving, compTransporter.parent.Position, map, WipeMode.Vanish);
                 }
                 CameraJumper.TryHideWorld();
             }
         }
     }
 }
예제 #4
0
 public void Send()
 {
     if (!ModLister.RoyaltyInstalled)
     {
         Log.ErrorOnce("Shuttle is a Royalty-specific game system. If you want to use this code please check ModLister.RoyaltyInstalled before calling it. See rules on the Ludeon forum for more info.", 8811221);
     }
     else
     {
         if (sending)
         {
             return;
         }
         if (!parent.Spawned)
         {
             Log.Error("Tried to send " + parent + ", but it's unspawned.");
             return;
         }
         List <CompTransporter> transportersInGroup = TransportersInGroup;
         if (transportersInGroup == null)
         {
             Log.Error("Tried to send " + parent + ", but it's not in any group.");
         }
         else
         {
             if (!LoadingInProgressOrReadyToLaunch)
             {
                 return;
             }
             if (!AllRequiredThingsLoaded)
             {
                 if (dropEverythingIfUnsatisfied)
                 {
                     Transporter.CancelLoad();
                 }
                 else if (dropNonRequiredIfUnsatisfied)
                 {
                     for (int i = 0; i < transportersInGroup.Count; i++)
                     {
                         for (int num = transportersInGroup[i].innerContainer.Count - 1; num >= 0; num--)
                         {
                             Thing thing = transportersInGroup[i].innerContainer[num];
                             Pawn  pawn;
                             if (!IsRequired(thing) && (requiredColonistCount <= 0 || (pawn = (thing as Pawn)) == null || !pawn.IsColonist))
                             {
                                 transportersInGroup[i].innerContainer.TryDrop(thing, ThingPlaceMode.Near, out Thing _);
                             }
                         }
                     }
                 }
             }
             sending = true;
             bool allRequiredThingsLoaded = AllRequiredThingsLoaded;
             Map  map = parent.Map;
             Transporter.TryRemoveLord(map);
             string signalPart = allRequiredThingsLoaded ? "SentSatisfied" : "SentUnsatisfied";
             for (int j = 0; j < transportersInGroup.Count; j++)
             {
                 QuestUtility.SendQuestTargetSignals(transportersInGroup[j].parent.questTags, signalPart, transportersInGroup[j].parent.Named("SUBJECT"), transportersInGroup[j].innerContainer.ToList().Named("SENT"));
             }
             List <Pawn> list = new List <Pawn>();
             for (int k = 0; k < transportersInGroup.Count; k++)
             {
                 CompTransporter compTransporter = transportersInGroup[k];
                 for (int num2 = transportersInGroup[k].innerContainer.Count - 1; num2 >= 0; num2--)
                 {
                     Pawn pawn2 = transportersInGroup[k].innerContainer[num2] as Pawn;
                     if (pawn2 != null)
                     {
                         if (pawn2.IsColonist && !requiredPawns.Contains(pawn2))
                         {
                             list.Add(pawn2);
                         }
                         pawn2.ExitMap(allowedToJoinOrCreateCaravan: false, Rot4.Invalid);
                     }
                 }
                 compTransporter.innerContainer.ClearAndDestroyContentsOrPassToWorld();
                 Thing newThing = ThingMaker.MakeThing(ThingDefOf.ShuttleLeaving);
                 compTransporter.CleanUpLoadingVars(map);
                 compTransporter.parent.Destroy(DestroyMode.QuestLogic);
                 GenSpawn.Spawn(newThing, compTransporter.parent.Position, map);
             }
             if (list.Count != 0)
             {
                 for (int l = 0; l < transportersInGroup.Count; l++)
                 {
                     QuestUtility.SendQuestTargetSignals(transportersInGroup[l].parent.questTags, "SentWithExtraColonists", transportersInGroup[l].parent.Named("SUBJECT"), list.Named("SENTCOLONISTS"));
                 }
             }
             sending = false;
         }
     }
 }