예제 #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();
                }
            }
        }
예제 #3
0
        protected override void LeaveMap()
        {
            if (this.alreadyLeft)
            {
                base.LeaveMap();
                return;
            }
            if (this.groupID < 0)
            {
                Log.Error("Drop pod left the map, but its group ID is " + this.groupID);
                this.Destroy(DestroyMode.Vanish);
                return;
            }
            if (this.destinationTile < 0)
            {
                Log.Error("Drop pod left the map, but its destination tile is " + this.destinationTile);
                this.Destroy(DestroyMode.Vanish);
                return;
            }
            Lord lord = TransporterUtility.FindLord(this.groupID, base.Map);

            if (lord != null)
            {
                base.Map.lordManager.RemoveLord(lord);
            }
            TravelingTransportPods travelingTransportPods = (TravelingTransportPods)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.TravelingTransportPods);

            travelingTransportPods.Tile = base.Map.Tile;
            travelingTransportPods.SetFaction(Faction.OfPlayer);
            travelingTransportPods.destinationTile = this.destinationTile;
            travelingTransportPods.destinationCell = this.destinationCell;
            travelingTransportPods.arriveMode      = this.arriveMode;
            travelingTransportPods.attackOnArrival = this.attackOnArrival;
            Find.WorldObjects.Add(travelingTransportPods);
            DropPodLeaving.tmpActiveDropPods.Clear();
            DropPodLeaving.tmpActiveDropPods.AddRange(base.Map.listerThings.ThingsInGroup(ThingRequestGroup.ActiveDropPod));
            for (int i = 0; i < DropPodLeaving.tmpActiveDropPods.Count; i++)
            {
                DropPodLeaving dropPodLeaving = DropPodLeaving.tmpActiveDropPods[i] as DropPodLeaving;
                if (dropPodLeaving != null && dropPodLeaving.groupID == this.groupID)
                {
                    dropPodLeaving.alreadyLeft = true;
                    travelingTransportPods.AddPod(dropPodLeaving.Contents, true);
                    dropPodLeaving.Contents = null;
                    dropPodLeaving.Destroy(DestroyMode.Vanish);
                }
            }
        }
 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();
             }
         }
     }
 }
예제 #5
0
        protected override void LeaveMap()
        {
            if (alreadyLeft || !createWorldObject)
            {
                base.LeaveMap();
                return;
            }
            if (groupID < 0)
            {
                Log.Error("Drop pod left the map, but its group ID is " + groupID);
                Destroy();
                return;
            }
            if (destinationTile < 0)
            {
                Log.Error("Drop pod left the map, but its destination tile is " + destinationTile);
                Destroy();
                return;
            }
            Lord lord = TransporterUtility.FindLord(groupID, base.Map);

            if (lord != null)
            {
                base.Map.lordManager.RemoveLord(lord);
            }
            TravelingTransportPods travelingTransportPods = (TravelingTransportPods)WorldObjectMaker.MakeWorldObject(worldObjectDef ?? WorldObjectDefOf.TravelingTransportPods);

            travelingTransportPods.Tile = base.Map.Tile;
            travelingTransportPods.SetFaction(Faction.OfPlayer);
            travelingTransportPods.destinationTile = destinationTile;
            travelingTransportPods.arrivalAction   = arrivalAction;
            Find.WorldObjects.Add(travelingTransportPods);
            tmpActiveDropPods.Clear();
            tmpActiveDropPods.AddRange(base.Map.listerThings.ThingsInGroup(ThingRequestGroup.ActiveDropPod));
            for (int i = 0; i < tmpActiveDropPods.Count; i++)
            {
                DropPodLeaving dropPodLeaving = tmpActiveDropPods[i] as DropPodLeaving;
                if (dropPodLeaving != null && dropPodLeaving.groupID == groupID)
                {
                    dropPodLeaving.alreadyLeft = true;
                    travelingTransportPods.AddPod(dropPodLeaving.Contents, justLeftTheMap: true);
                    dropPodLeaving.Contents = null;
                    dropPodLeaving.Destroy();
                }
            }
        }
예제 #6
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(string.Concat("Tried to send ", parent, ", but it's unspawned."));
             return;
         }
         List <CompTransporter> transportersInGroup = TransportersInGroup;
         if (transportersInGroup == null)
         {
             Log.Error(string.Concat("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 var _);
                             }
                         }
                     }
                 }
             }
             sending = true;
             Map map = parent.Map;
             Transporter.TryRemoveLord(map);
             SendLaunchedSignals(transportersInGroup);
             List <Pawn> list = new List <Pawn>();
             for (int j = 0; j < transportersInGroup.Count; j++)
             {
                 CompTransporter compTransporter = transportersInGroup[j];
                 for (int num2 = transportersInGroup[j].innerContainer.Count - 1; num2 >= 0; num2--)
                 {
                     Pawn pawn2 = transportersInGroup[j].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();
                 DropPodLeaving obj = (DropPodLeaving)ThingMaker.MakeThing(ThingDefOf.ShuttleLeaving);
                 obj.createWorldObject = permitShuttle && compTransporter.innerContainer.Any();
                 obj.worldObjectDef    = WorldObjectDefOf.TravelingShuttle;
                 compTransporter.CleanUpLoadingVars(map);
                 compTransporter.parent.Destroy(DestroyMode.QuestLogic);
                 GenSpawn.Spawn(obj, compTransporter.parent.Position, map);
             }
             if (list.Count != 0)
             {
                 for (int k = 0; k < transportersInGroup.Count; k++)
                 {
                     QuestUtility.SendQuestTargetSignals(transportersInGroup[k].parent.questTags, "SentWithExtraColonists", transportersInGroup[k].parent.Named("SUBJECT"), list.Named("SENTCOLONISTS"));
                 }
             }
             sending = false;
         }
     }
 }