Beispiel #1
0
        public static void SpawnTraderShip()
        {
            List <DebugMenuOption> list = new List <DebugMenuOption>();

            list.Add(new DebugMenuOption("Incoming", DebugMenuOptionMode.Tool, delegate()
            {
                Thing thing   = ThingMaker.MakeThing(Globals.TraderShipsShip, null);
                CompShip comp = thing.TryGetComp <CompShip>();
                comp.GenerateInternalTradeShip(Find.CurrentMap);

                GenPlace.TryPlaceThing(SkyfallerMaker.MakeSkyfaller(comp.Props.landAnimation, thing), UI.MouseCell(), Find.CurrentMap, ThingPlaceMode.Near, null, null, default(Rot4));
            }));

            list.Add(new DebugMenuOption("Stationary", DebugMenuOptionMode.Tool, delegate()
            {
                Thing thing = ThingMaker.MakeThing(Globals.TraderShipsShip, null);
                thing.TryGetComp <CompShip>().GenerateInternalTradeShip(Find.CurrentMap);

                GenPlace.TryPlaceThing(thing, UI.MouseCell(), Find.CurrentMap, ThingPlaceMode.Near, null, null, default(Rot4));
            }));


            list.Add(new DebugMenuOption("Crash", DebugMenuOptionMode.Tool, delegate()
            {
                Thing ship    = ThingMaker.MakeThing(Globals.TraderShipsShip, null);
                CompShip comp = ship.TryGetComp <CompShip>();
                comp.GenerateInternalTradeShip(Find.CurrentMap);
                comp.mustCrash = true;
                GenPlace.TryPlaceThing(SkyfallerMaker.MakeSkyfaller(Globals.TraderShipsShipCrashing, ship), UI.MouseCell(), Find.CurrentMap, ThingPlaceMode.Near);
            }));

            List <DebugMenuOption> options = list;

            Find.WindowStack.Add(new Dialog_DebugOptionListLister(options));
        }
Beispiel #2
0
        public static void LandShip(Map map, Thing ship)
        {
            Thing    blockingThing;
            IntVec3  center = IntVec3.Invalid;
            CompShip comp   = ship.TryGetComp <CompShip>();

            Area_LandingZone lz = map.areaManager.LandingZone();

            if (lz != null && !lz.TryFindShipLandingArea(ship.def.size, out center, out blockingThing) && blockingThing != null)
            {
                Messages.Message("TraderShipsLandingZoneBlocked".Translate("TraderShipsBlockedBy".Translate(blockingThing)), blockingThing, MessageTypeDefOf.NeutralEvent, true);
            }

            if (!center.IsValid && ThingDefOf.ShipLandingBeacon != null && !DropCellFinder.TryFindShipLandingArea(map, out center, out blockingThing) && blockingThing != null)
            {
                Messages.Message("TraderShipsLandingZoneBlocked".Translate("TraderShipsBlockedBy".Translate(blockingThing)), blockingThing, MessageTypeDefOf.NeutralEvent, true);
            }

            if (!center.IsValid)
            {
                FindCloseLandingSpot(out center, comp.tradeShip.Faction, map, ship.def.size);
            }

            GenPlace.TryPlaceThing(SkyfallerMaker.MakeSkyfaller(comp.Props.landAnimation, ship), center, map, ThingPlaceMode.Near);
        }
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            var map               = (Map)parms.target;
            int num               = 0;
            int countToSpawn      = this.CountToSpawn;
            var list              = new List <TargetInfo>();
            var shrapnelDirection = Rand.Range(0f, 360f);

            for (int i = 0; i < countToSpawn; i++)
            {
                IntVec3 intVec = default(IntVec3);
                if (!CellFinderLoose.TryFindSkyfallerCell(ThingDefOf.CrashedShipPartIncoming, map, out intVec, 14, default(IntVec3), -1, false, true, true, true, true, false, null))
                {
                    break;
                }
                var building_CrashedShipPart = (Building_CrashedShipPart)ThingMaker.MakeThing(def.shipPart, null);
                building_CrashedShipPart.SetFaction(Faction.OfMechanoids, null);
                building_CrashedShipPart.GetComp <CompSpawnerMechanoidsOnDamaged>().pointsLeft = Mathf.Max(parms.points * ShipPointsFactor, 300f);
                var skyfaller = SkyfallerMaker.MakeSkyfaller(ThingDefOf.CrashedShipPartIncoming, building_CrashedShipPart);
                skyfaller.shrapnelDirection = shrapnelDirection;
                GenSpawn.Spawn(skyfaller, intVec, map, WipeMode.Vanish);
                num++;
                list.Add(new TargetInfo(intVec, map, false));
            }
            if (num > 0)
            {
                SendStandardLetter(list, null);
            }
            return(num > 0);
        }
Beispiel #4
0
        public override void MapLoaded(Map map)
        {
            base.MapLoaded(map);

            CompatabilityAddMissingWaterTags();
            AddDefaultFishableTags();
            AddDefaultWaterAffordances();
            Logger.Message("MapLoaded: Fishable terrain options: " + string.Join(", ", FetchFishingTagged().ConvertAll <string>(t => t.ToString()).ToArray()));

            // Cleanup extra dolphins
            foreach (Thing d in map.GetDirectlyHeldThings().Where((Thing t) => (t as DolphinAway) != null))
            {
                Logger.Message("Caught a lazy dolphin... teleporting off-world");
                d.Destroy();
            }

            IntVec3?launchPoint = RandomFishable(map);

            if (launchPoint.HasValue)
            {
                Logger.Message("Humans are here... so long and thanks for all the fish @ (" + launchPoint + ")");
                DolphinAway dolphin = (DolphinAway)ThingMaker.MakeThing(ThingDef.Named("DolphinAway"), null);
                // Needs his fish before leaving...
                Thing fish = ThingMaker.MakeThing(ThingDef.Named("DeadFish"));
                dolphin.innerContainer.TryAdd(fish);
                this.dolphinLeaving = (DolphinAway)SkyfallerMaker.MakeSkyfaller(ThingDef.Named("DolphinAway"), dolphin);
                GenSpawn.Spawn(this.dolphinLeaving, launchPoint.GetValueOrDefault(), map);
            }
        }
Beispiel #5
0
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            Faction faction = Find.FactionManager.FirstFactionOfDef(FactionDef.Named("PLAHF_faction"));
            Map     map     = (Map)parms.target;
            //List<TargetInfo> list = new List<TargetInfo>();
            float shrapnelDirection = Rand.Range(0f, 360f);
            Thing lookhere;


            IntVec3 intVec;

            if (!CellFinderLoose.TryFindSkyfallerCell(RimWorld.ThingDefOf.DropPodIncoming, map, out intVec, 14, default(IntVec3), -1, false, true, true, true, true, false, null))
            {
                return(false);
            }
            Building_TacticalManaBomb building_tacticalmanabomb = (Building_TacticalManaBomb)ThingMaker.MakeThing(DefDatabase <ThingDef> .GetNamed("Building_TacticalManaBomb", true));

            building_tacticalmanabomb.SetFaction(faction, null);
            building_tacticalmanabomb.spawnpoints = (float)(parms.points * 0.8);
            lookhere = building_tacticalmanabomb;

            Skyfaller skyfaller = SkyfallerMaker.MakeSkyfaller(RimWorld.ThingDefOf.DropPodIncoming, building_tacticalmanabomb);

            skyfaller.shrapnelDirection = shrapnelDirection;
            GenSpawn.Spawn(skyfaller, intVec, map, WipeMode.Vanish);



            Find.LetterStack.ReceiveLetter("LetterLabelPLAHFTMBAttack".Translate(), "LetterPLAHFTMBAttack".Translate(), LetterDefOf.ThreatBig, lookhere, null, null);


            Find.TickManager.slower.SignalForceNormalSpeedShort();
            Find.StoryWatcher.statsRecord.numRaidsEnemy++;
            return(true);
        }
        public static ArtilleryStrikeIncoming SpawnArtilleryStrikeSkyfaller(ThingDef shellDef, Map map, IntVec3 position)
        {
            var artilleryStrikeIncoming = (ArtilleryStrikeIncoming)SkyfallerMaker.MakeSkyfaller(ThingDefOf.VFES_ArtilleryStrikeIncoming);

            artilleryStrikeIncoming.artilleryShellDef = shellDef;
            return((ArtilleryStrikeIncoming)GenSpawn.Spawn(artilleryStrikeIncoming, position, map));
        }
        public override bool TryExecuteWorker(IncidentParms parms)
        {
            Map map                = (Map)parms.target;
            int num                = 0;
            int countToSpawn       = this.CountToSpawn;
            List <TargetInfo> list = new List <TargetInfo>();

            Rand.PushState();
            float shrapnelDirection = Rand.Range(0f, 360f);

            Rand.PopState();
            for (int i = 0; i < countToSpawn; i++)
            {
                IntVec3 intVec;
                if (!CellFinderLoose.TryFindSkyfallerCell(ThingDefOf.CrashedShipPartIncoming, map, out intVec, 14, default(IntVec3), -1, false, true, true, true, true, false, null))
                {
                    break;
                }
                Building building_CrashedShipPart = (Building)ThingMaker.MakeThing(this.def.mechClusterBuilding, null);
                building_CrashedShipPart.SetFaction(OfNecrons, null);
                building_CrashedShipPart.GetComp <CompPawnSpawnerOnDamaged>().pointsLeft = Mathf.Max(parms.points * 0.9f, 300f);
                Skyfaller skyfaller = SkyfallerMaker.MakeSkyfaller(ThingDefOf.CrashedShipPartIncoming, building_CrashedShipPart);
                skyfaller.shrapnelDirection = shrapnelDirection;
                GenSpawn.Spawn(skyfaller, intVec, map, WipeMode.Vanish);
                num++;
                list.Add(new TargetInfo(intVec, map, false));
            }
            if (num > 0)
            {
                base.SendStandardLetter(parms, list, Array.Empty <NamedArgument>());
            }
            return(num > 0);
        }
        public override bool TryExecuteWorker(IncidentParms parms)
        {
            Map map = (Map)parms.target;
            List <TargetInfo> list        = new List <TargetInfo>();
            ThingDef          shipPartDef = def.mechClusterBuilding;
            IntVec3           intVec      = FindDropPodLocation(map, (IntVec3 spot) => CanPlaceAt(spot));

            if (intVec == IntVec3.Invalid)
            {
                return(false);
            }
            float    points = Mathf.Max(parms.points * 0.9f, 300f);
            Thing    thing  = ThingMaker.MakeThing(shipPartDef);
            Building building_CrashedShipPart = (Building)thing;
            CompPawnSpawnerOnDamaged damaged  = building_CrashedShipPart.TryGetCompFast <CompPawnSpawnerOnDamaged>();

            thing.SetFaction(faction, null);
            List <Pawn> list2 = PawnGroupMakerUtility.GeneratePawns(new PawnGroupMakerParms
            {
                groupKind = PawnGroupKindDefOf.Combat,
                tile      = map.Tile,
                faction   = faction,
                points    = points
            }).ToList();

            LordMaker.MakeNewLord(faction, new LordJob_SleepThenMechanoidsDefend(new List <Thing>
            {
                thing
            }, faction, 28f, intVec, canAssaultColony: false, isMechCluster: false), map, list2);
            DropPodUtility.DropThingsNear(intVec, map, list2.Cast <Thing>());
            foreach (Pawn item in list2)
            {
                item.TryGetCompFast <CompCanBeDormant>()?.ToSleep();
            }
            list.AddRange(list2.Select((Pawn p) => new TargetInfo(p)));
            GenSpawn.Spawn(SkyfallerMaker.MakeSkyfaller(ThingDefOf.CrashedShipPartIncoming, thing), intVec, map);
            list.Add(new TargetInfo(intVec, map));
            SendStandardLetter(parms, list);
            return(true);

            bool CanPlaceAt(IntVec3 loc)
            {
                CellRect cellRect = GenAdj.OccupiedRect(loc, Rot4.North, shipPartDef.Size);

                if (loc.Fogged(map) || !cellRect.InBounds(map))
                {
                    return(false);
                }
                foreach (IntVec3 item2 in cellRect)
                {
                    RoofDef roof = item2.GetRoof(map);
                    if (roof != null && roof.isNatural)
                    {
                        return(false);
                    }
                }
                return(GenConstruct.CanBuildOnTerrain(shipPartDef, loc, map, Rot4.North));
            }
        }
        public void TryLaunch(int destinationTile)
        {
            var arrivalAction = CurrentArrivalAction;

            if (arrivalAction != null)
            {
                arrivalAction.source = parent;
            }

            // Play sounds
            var verb = Turret.CurrentEffectiveVerb;

            if (verb.verbProps.soundCast != null)
            {
                verb.verbProps.soundCast.PlayOneShot(new TargetInfo(parent.Position, parent.Map));
            }
            if (verb.verbProps.soundCastTail != null)
            {
                verb.verbProps.soundCastTail.PlayOneShotOnCamera(parent.Map);
            }

            // Make active artillery strike thing
            var activeArtilleryStrike = (ActiveArtilleryStrike)ThingMaker.MakeThing(ThingDefOf.VFES_ActiveArtilleryStrike);

            activeArtilleryStrike.missRadius = ArtilleryStrikeUtility.FinalisedMissRadius(Turret.CurrentEffectiveVerb.verbProps.ForcedMissRadius, Props.maxForcedMissRadiusFactor, parent.Tile, destinationTile, Props.worldTileRange);

            // Simulate an attack
            if (ChangeableProjectile != null)
            {
                activeArtilleryStrike.shellDef   = ChangeableProjectile.Projectile;
                activeArtilleryStrike.shellCount = 1;
                ChangeableProjectile.Notify_ProjectileLaunched();
            }
            else
            {
                activeArtilleryStrike.shellDef = verb.GetProjectile();
                for (int j = 0; j < verb.verbProps.burstShotCount; j++)
                {
                    activeArtilleryStrike.shellCount++;
                    if (verb.verbProps.consumeFuelPerShot > 0 && RefuelableComp != null)
                    {
                        RefuelableComp.ConsumeFuel(verb.verbProps.consumeFuelPerShot);
                    }
                }
            }
            NonPublicMethods.Building_TurretGun_BurstComplete(Turret);

            var artilleryStrikeLeaving = (ArtilleryStrikeLeaving)SkyfallerMaker.MakeSkyfaller(ThingDefOf.VFES_ArtilleryStrikeLeaving, activeArtilleryStrike);

            artilleryStrikeLeaving.startCell       = parent.Position;
            artilleryStrikeLeaving.edgeCell        = FacingEdgeCell;
            artilleryStrikeLeaving.rotation        = CurAngle;
            artilleryStrikeLeaving.destinationTile = destinationTile;
            artilleryStrikeLeaving.arrivalAction   = arrivalAction;
            artilleryStrikeLeaving.groupID         = Find.TickManager.TicksGame;

            GenSpawn.Spawn(artilleryStrikeLeaving, parent.Position, parent.Map);
        }
Beispiel #10
0
        // Token: 0x06000EA8 RID: 3752 RVA: 0x0006C2D0 File Offset: 0x0006A6D0
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            Map map                = (Map)parms.target;
            int num                = 0;
            int countToSpawn       = this.CountToSpawn(parms);
            List <TargetInfo> list = new List <TargetInfo>();

            Rand.PushState();
            float shrapnelDirection = Rand.Range(0f, 360f);

            Rand.PopState();
            Faction faction = null;
            CompProperties_SpawnerOnDamaged props = this.def.mechClusterBuilding?.GetCompProperties <CompProperties_SpawnerOnDamaged>();

            if (props == null)
            {
                return(false);
            }

            /*
             * if (faction == null)
             * {
             *  faction = onDamaged.OfFaction;
             *  if (faction == null)
             *  {
             *      return false;
             *  }
             * }
             */
            for (int i = 0; i < countToSpawn; i++)
            {
                IntVec3              intVec;
                Building             CrashedShipPart = (Building)ThingMaker.MakeThing(this.def.mechClusterBuilding, null);
                CompSpawnerOnDamaged onDamaged       = CrashedShipPart.TryGetComp <CompSpawnerOnDamaged>();
                ThingDef             faller          = onDamaged?.Props.skyFaller ?? ThingDefOf.CrashedShipPartIncoming;
                if (!CellFinderLoose.TryFindSkyfallerCell(faller, map, out intVec, 14, default(IntVec3), -1, false, true, true, true, true, false, null))
                {
                    break;
                }
                //    CrashedShipPart.SetFaction(faction, null);
                if (onDamaged != null)
                {
                    onDamaged.pointsLeft = Mathf.Max(parms.points * 0.9f, 300f);
                }

                Skyfaller skyfaller = SkyfallerMaker.MakeSkyfaller(faller, CrashedShipPart);
                skyfaller.shrapnelDirection = shrapnelDirection;
                Thing thing =
                    GenSpawn.Spawn(skyfaller, intVec, map, WipeMode.Vanish);
                num++;
                list.Add(CrashedShipPart);
            }
            if (num > 0)
            {
                base.SendStandardLetter(parms, list, Array.Empty <NamedArgument>());
            }
            return(num > 0);
        }
        // Token: 0x060047C7 RID: 18375 RVA: 0x00180F4C File Offset: 0x0017F14C
        public override void GenerateIntoMap(Map map)
        {
            method = PlayerPawnsArriveMethod.DropShip;
            if (Find.GameInitData == null)
            {
                return;
            }
            List <List <Thing> > list = new List <List <Thing> >();

            foreach (Pawn item in Find.GameInitData.startingAndOptionalPawns)
            {
                list.Add(new List <Thing>
                {
                    item
                });
            }
            List <Thing> list2 = new List <Thing>();

            foreach (ScenPart scenPart in Find.Scenario.AllParts)
            {
                list2.AddRange(scenPart.PlayerStartingThings());
            }
            int num = 0;

            foreach (Thing thing in list2)
            {
                if (thing.def.CanHaveFaction)
                {
                    thing.SetFactionDirect(Faction.OfPlayer);
                }
                list[num].Add(thing);
                num++;
                if (num >= list.Count)
                {
                    num = 0;
                }
            }
            if ((int)this.method == (int)PlayerPawnsArriveMethod.DropShip)
            {
                Thing        thing    = ThingMaker.MakeThing(dropshipdef, null);
                CompDropship dropship = thing.TryGetComp <CompDropship>();
                foreach (List <Thing> item in list)
                {
                    dropship.Transporter.innerContainer.TryAddRangeOrTransfer(item);
                }
                dropship.autodustoff = true;

                if (DropCellFinder.TryFindDropSpotNear(MapGenerator.PlayerStartSpot, map, out IntVec3 spot, false, false, false, dropshipdef.Size))
                {
                    GenPlace.TryPlaceThing(SkyfallerMaker.MakeSkyfaller(dropship.Props.incomming, thing), spot, map, ThingPlaceMode.Near, null, null, default(Rot4));
                }
                else
                {
                    GenPlace.TryPlaceThing(SkyfallerMaker.MakeSkyfaller(dropship.Props.incomming, thing), MapGenerator.PlayerStartSpot, map, ThingPlaceMode.Near, null, null, default(Rot4));
                }
            }
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            Map     map  = (Map)parms.target;
            Thing   ship = ThingMaker.MakeThing(Globals.TraderShipsShip, null);
            IntVec3 spot = RandomSpot(map);

            CompShip comp = ship.TryGetComp <CompShip>();

            comp.GenerateInternalTradeShip(map);
            comp.mustCrash = true;
            GenPlace.TryPlaceThing(SkyfallerMaker.MakeSkyfaller(Globals.TraderShipsShipCrashing, ship), spot, map, ThingPlaceMode.Near);
            return(true);
        }
Beispiel #13
0
        /// <summary>
        /// Tries to execute the worker.
        /// </summary>
        /// <param name="parms">The parms.</param>
        /// <returns></returns>
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            var      map             = (Map)parms.target;
            var      targetInfoList  = new List <TargetInfo>();
            ThingDef shipPartDef     = def.mechClusterBuilding;
            IntVec3  dropPodLocation = MechClusterUtility.FindDropPodLocation(map, spot =>
            {
                if (!spot.Fogged(map) && GenConstruct.CanBuildOnTerrain(shipPartDef, spot, map, Rot4.North))
                {
                    return(GenConstruct.CanBuildOnTerrain(shipPartDef,
                                                          new IntVec3(spot.x - Mathf.CeilToInt(shipPartDef.size.x / 2f), spot.y,
                                                                      spot.z), map, Rot4.North));
                }
                return(false);
            });

            if (dropPodLocation == IntVec3.Invalid)
            {
                return(false);
            }
            float num       = Mathf.Max(parms.points * 0.9f, 300f);
            var   genParams = new PawnGroupMakerParms
            {
                groupKind = PawnGroupKindDefOf.Combat,
                tile      = map.Tile,
                faction   = Faction.OfMechanoids,
                points    = num
            };
            List <Pawn> list = PawnGroupMakerUtility.GeneratePawns(genParams)
                               .ToList();
            Thing innerThing = ThingMaker.MakeThing(shipPartDef);

            innerThing.SetFaction(Faction.OfMechanoids);
            LordMaker.MakeNewLord(Faction.OfMechanoids, new LordJob_SleepThenMechanoidsDefend(new List <Thing>
            {
                innerThing
            }, Faction.OfMechanoids, 28f, dropPodLocation, false, false), map, list);
            DropPodUtility.DropThingsNear(dropPodLocation, map, list);
            foreach (Thing thing in list)
            {
                thing.TryGetComp <CompCanBeDormant>()?.ToSleep();
            }
            targetInfoList.AddRange(list.Select(p => new TargetInfo(p)));
            GenSpawn.Spawn(SkyfallerMaker.MakeSkyfaller(PMThingDefOf.CrashedMutagenicShipPartIncoming, innerThing), dropPodLocation, map);
            targetInfoList.Add(new TargetInfo(dropPodLocation, map));
            SendStandardLetter(parms, targetInfoList, Array.Empty <NamedArgument>());
            return(true);
        }
        private static void SpawnDropship()
        {
            List <DebugMenuOption> list = new List <DebugMenuOption>();

            list.Add(new DebugMenuOption("Incoming", DebugMenuOptionMode.Tool, delegate()
            {
                GenPlace.TryPlaceThing(SkyfallerMaker.MakeSkyfaller(USCMDefOf.RRY_USCM_DropshipUD4LIncoming, ThingMaker.MakeThing(USCMDefOf.RRY_USCM_DropshipUD4L, null)), UI.MouseCell(), Find.CurrentMap, ThingPlaceMode.Near, null, null, default(Rot4));
            }));
            list.Add(new DebugMenuOption("Stationary", DebugMenuOptionMode.Tool, delegate()
            {
                GenPlace.TryPlaceThing(ThingMaker.MakeThing(USCMDefOf.RRY_USCM_DropshipUD4L, null), UI.MouseCell(), Find.CurrentMap, ThingPlaceMode.Near, null, null, default(Rot4));
            }));
            List <DebugMenuOption> options = list;

            Find.WindowStack.Add(new Dialog_DebugOptionListLister(options));
        }
Beispiel #15
0
        private KCSG_Skyfaller SpawnSkyfaller(ThingDef skyfaller, Thing innerThing, IntVec3 pos, Map map, Rot4 rot)
        {
            KCSG_Skyfaller faller = (KCSG_Skyfaller)SkyfallerMaker.MakeSkyfaller(skyfaller);

            if (innerThing != null)
            {
                if (!faller.innerContainer.TryAdd(innerThing, true))
                {
                    Log.Error($"Could not add {innerThing.ToStringSafe()} to a KCSG_Skyfaller.");
                    innerThing.Destroy(DestroyMode.Vanish);
                }
            }
            faller.rot = rot;

            return((KCSG_Skyfaller)GenSpawn.Spawn(faller, pos, map, rot, WipeMode.Vanish));
        }
        private static void SpawnShuttle()
        {
            List <DebugMenuOption> options = new List <DebugMenuOption>
            {
                new DebugMenuOption("Incoming", DebugMenuOptionMode.Tool, delegate
                {
                    GenPlace.TryPlaceThing(SkyfallerMaker.MakeSkyfaller(ThingDefOf.ShuttleIncoming, ThingMaker.MakeThing(ThingDefOf.Shuttle)), UI.MouseCell(), Find.CurrentMap, ThingPlaceMode.Near);
                }),
                new DebugMenuOption("Stationary", DebugMenuOptionMode.Tool, delegate
                {
                    GenPlace.TryPlaceThing(ThingMaker.MakeThing(ThingDefOf.Shuttle), UI.MouseCell(), Find.CurrentMap, ThingPlaceMode.Near);
                })
            };

            Find.WindowStack.Add(new Dialog_DebugOptionListLister(options));
        }
        /// <summary>
        ///     Tries to execute the worker.
        /// </summary>
        /// <param name="parms">The parms.</param>
        /// <returns></returns>
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            var      map         = (Map)parms.target;
            var      list        = new List <TargetInfo>();
            ThingDef shipPartDef = def.mechClusterBuilding;
            IntVec3  intVec      = FindDropPodLocation(map, CanPlaceAt);

            if (intVec == IntVec3.Invalid)
            {
                return(false);
            }
            float       points = Mathf.Max(parms.points * 0.9f, 300f);
            List <Pawn> list2  = PawnGroupMakerUtility.GeneratePawns(new PawnGroupMakerParms
            {
                groupKind = PawnGroupKindDefOf.Combat,
                tile      = map.Tile,
                faction   = Faction.OfMechanoids,
                points    = points
            })
                                 .ToList();
            Thing thing = ThingMaker.MakeThing(shipPartDef);

            thing.SetFaction(Faction.OfMechanoids);
            LordMaker.MakeNewLord(Faction.OfMechanoids, new LordJob_SleepThenMechanoidsDefend(new List <Thing>
            {
                thing
            }, Faction.OfMechanoids, 28f, intVec, false, false), map, list2);
            DropPodUtility.DropThingsNear(intVec, map, list2);
            foreach (Pawn item in list2)
            {
                item.TryGetComp <CompCanBeDormant>()?.ToSleep();
            }
            list.AddRange(list2.Select(p => new TargetInfo(p)));
            GenSpawn.Spawn(SkyfallerMaker.MakeSkyfaller(PMThingDefOf.CrashedMutagenicShipPartIncoming, thing), intVec, map);
            list.Add(new TargetInfo(intVec, map));
            SendStandardLetter(parms, list);
            return(true);

            bool CanPlaceAt(IntVec3 loc)
            {
                if (loc.Fogged(map) || !GenAdj.OccupiedRect(loc, Rot4.North, shipPartDef.Size).InBounds(map))
                {
                    return(false);
                }
                return(GenConstruct.CanBuildOnTerrain(shipPartDef, loc, map, Rot4.North));
            }
        }
        public void LaunchLightPod(Thing pod, CompTransporter compTransporter, int destinationTile, IntVec3 destinationCell)
        {
            Map           map                = this.Map;
            int           groupID            = compTransporter.groupID;
            ThingOwner    directlyHeldThings = compTransporter.GetDirectlyHeldThings();
            ActiveDropPod activeDropPod      = (ActiveDropPod)ThingMaker.MakeThing(ThingDefOf.ActiveDropPod);

            activeDropPod.Contents = new ActiveDropPodInfo();
            activeDropPod.Contents.innerContainer.TryAddRangeOrTransfer(directlyHeldThings, canMergeWithExistingStacks: true, destroyLeftover: true);
            WorldTransport.TM_DropPodLeaving obj = (WorldTransport.TM_DropPodLeaving)SkyfallerMaker.MakeSkyfaller(TorannMagicDefOf.TM_LightPodLeaving, activeDropPod);
            obj.groupID         = groupID;
            obj.destinationTile = destinationTile;
            obj.arrivalAction   = null;
            obj.arrivalCell     = destinationCell;
            obj.draftFlag       = this.draftFlag;
            compTransporter.CleanUpLoadingVars(map);
            compTransporter.parent.Destroy();
            GenSpawn.Spawn(obj, compTransporter.parent.Position, map);
        }
        public static Thing DropShuttle_NewTemp(List <ActiveDropPodInfo> pods, Map map, IntVec3 cell, Faction faction = null)
        {
            RemovePawnsFromWorldPawns(pods);
            Thing thing = QuestGen_Shuttle.GenerateShuttle(faction, null, null, acceptColonists: false, onlyAcceptColonists: false, onlyAcceptHealthy: false, 0, dropEverythingIfUnsatisfied: false, leaveImmediatelyWhenSatisfied: false, dropEverythingOnArrival: true);

            thing.TryGetComp <CompShuttle>().hideControls = true;
            CompTransporter compTransporter = thing.TryGetComp <CompTransporter>();

            for (int i = 0; i < pods.Count; i++)
            {
                compTransporter.innerContainer.TryAddRangeOrTransfer(pods[i].innerContainer);
            }
            if (!cell.IsValid)
            {
                cell = DropCellFinder.GetBestShuttleLandingSpot(map, Faction.OfPlayer, out var _);
            }
            GenPlace.TryPlaceThing(SkyfallerMaker.MakeSkyfaller(ThingDefOf.ShuttleIncoming, thing), cell, map, ThingPlaceMode.Near);
            return(thing);
        }
Beispiel #20
0
        public static QuestPart_SpawnThing SpawnSkyfaller(this Quest quest, Map map, ThingDef skyfallerDef, IEnumerable <Thing> innerThings, Faction factionForSafeSpot = null, IntVec3?cell = null, string inSignal = null, bool lookForSafeSpot = false, bool tryLandInShipLandingZone = false, Thing tryLandNearThing = null, Pawn mapParentOfPawn = null)
        {
            Skyfaller            thing = SkyfallerMaker.MakeSkyfaller(skyfallerDef, innerThings);
            QuestPart_SpawnThing questPart_SpawnThing = new QuestPart_SpawnThing();

            questPart_SpawnThing.thing                 = thing;
            questPart_SpawnThing.mapParent             = map?.Parent;
            questPart_SpawnThing.mapParentOfPawn       = mapParentOfPawn;
            questPart_SpawnThing.factionForFindingSpot = factionForSafeSpot;
            if (cell.HasValue)
            {
                questPart_SpawnThing.cell = cell.Value;
            }
            questPart_SpawnThing.inSignal                 = inSignal ?? QuestGen.slate.Get <string>("inSignal");
            questPart_SpawnThing.lookForSafeSpot          = lookForSafeSpot;
            questPart_SpawnThing.tryLandInShipLandingZone = tryLandInShipLandingZone;
            questPart_SpawnThing.tryLandNearThing         = tryLandNearThing;
            quest.AddPart(questPart_SpawnThing);
            return(questPart_SpawnThing);
        }
Beispiel #21
0
        // Token: 0x06000EA8 RID: 3752 RVA: 0x0006C2D0 File Offset: 0x0006A6D0
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            Map map                = (Map)parms.target;
            int num                = 0;
            int countToSpawn       = this.CountToSpawn;
            List <TargetInfo> list = new List <TargetInfo>();
            float             shrapnelDirection = Rand.Range(0f, 360f);
            Faction           faction           = null;
            Building_HiveLike_CrashedShipPart building_CrashedShipPart = null;

            building_CrashedShipPart = (Building_HiveLike_CrashedShipPart)ThingMaker.MakeThing(this.def.shipPart, null);
            if (faction == null)
            {
                faction = building_CrashedShipPart.GetComp <CompPawnSpawnerOnDamaged>().OfFaction;
            }
            for (int i = 0; i < countToSpawn; i++)
            {
                IntVec3 intVec;
                if (!CellFinderLoose.TryFindSkyfallerCell(ThingDefOf.CrashedShipPartIncoming, map, out intVec, 14, default(IntVec3), -1, false, true, true, true, true, false, null))
                {
                    break;
                }
                building_CrashedShipPart.SetFaction(faction, null);
                building_CrashedShipPart.GetComp <CompPawnSpawnerOnDamaged>().pointsLeft = Mathf.Max(parms.points * 0.9f, 300f);

                ThingDef faller = building_CrashedShipPart.GetComp <CompPawnSpawnerOnDamaged>().Props.skyFaller != null?building_CrashedShipPart.GetComp <CompPawnSpawnerOnDamaged>().Props.skyFaller : ThingDefOf.CrashedShipPartIncoming;

                Skyfaller skyfaller = SkyfallerMaker.MakeSkyfaller(faller, building_CrashedShipPart);
                skyfaller.shrapnelDirection = shrapnelDirection;
                GenSpawn.Spawn(skyfaller, intVec, map, WipeMode.Vanish);
                num++;
                list.Add(new TargetInfo(intVec, map, false));
            }
            if (num > 0)
            {
                base.SendStandardLetter(list, null, new string[0]);
            }
            return(num > 0);
        }
Beispiel #22
0
        protected override void RunInt()
        {
            Slate                slate = QuestGen.slate;
            Map                  map   = QuestGen.slate.Get <Map>("map");
            Skyfaller            thing = SkyfallerMaker.MakeSkyfaller(skyfallerDef.GetValue(slate), innerThings.GetValue(slate));
            QuestPart_SpawnThing questPart_SpawnThing = new QuestPart_SpawnThing();

            questPart_SpawnThing.thing     = thing;
            questPart_SpawnThing.mapParent = map.Parent;
            if (factionOfForSafeSpot.GetValue(slate) != null)
            {
                questPart_SpawnThing.factionForFindingSpot = factionOfForSafeSpot.GetValue(slate).Faction;
            }
            if (cell.GetValue(slate).HasValue)
            {
                questPart_SpawnThing.cell = cell.GetValue(slate).Value;
            }
            questPart_SpawnThing.inSignal                 = (QuestGenUtility.HardcodedSignalWithQuestID(inSignal.GetValue(slate)) ?? QuestGen.slate.Get <string>("inSignal"));
            questPart_SpawnThing.lookForSafeSpot          = lookForSafeSpot.GetValue(slate);
            questPart_SpawnThing.tryLandInShipLandingZone = tryLandInShipLandingZone.GetValue(slate);
            QuestGen.quest.AddPart(questPart_SpawnThing);
        }
        public void TryLaunch()
        {
            if (!CanLaunch)
            {
                Messages.Message("D9CTM_PodNotReady".Translate(base.parent.Label), new LookTargets(base.parent), MessageTypeDefOf.NeutralEvent, false);
                return;
            }
            if (FuelingPortSource != null)
            {
                FuelingPortSource.TryGetComp <CompRefuelable>()?.ConsumeFuel(FuelToLaunch);
            }
            Skyfaller skyfaller = SkyfallerMaker.MakeSkyfaller(Props.skyfallerDef);

            GenSpawn.Spawn(skyfaller, parent.Position, Map, WipeMode.Vanish);
            try
            {
                if (ToCreate != null)
                {
                    ThingOwner <Thing> owner = new ThingOwner <Thing>();
                    foreach (ThingDefCountClass td in ToCreate)
                    {
                        Thing t = ThingMaker.MakeThing(td.thingDef, null);
                        owner.TryAdd(t);
                    }
                    do
                    {
                        if (owner.Count <= 0)
                        {
                            return;
                        }
                    }while (owner.TryDrop(owner[0], base.parent.Position, Map, ThingPlaceMode.Near, out Thing last, null, null));
                }
            }
            finally
            {
                parent.Destroy(DestroyMode.Vanish);
            }
        }
        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();
                }
            }
        }
Beispiel #25
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();
        }
        private static void SpawnDropship()
        {
            List <DebugMenuOption> list = new List <DebugMenuOption>();

            foreach (ThingDef localDef2 in from f in DefDatabase <ThingDef> .AllDefs
                     where f.HasComp(typeof(CompDropship))
                     orderby f.defName
                     select f)
            {
                ThingDef localDef = localDef2;
                list.Add(new DebugMenuOption(localDef.defName, DebugMenuOptionMode.Tool, delegate()
                {
                    List <FloatMenuOption> list2 = new List <FloatMenuOption>();
                    IntVec3 cell = UI.MouseCell();

                    ThingDef Incomingdef = DefDatabase <ThingDef> .GetNamedSilentFail(localDef.defName + "_Incoming");
                    if (Incomingdef != null)
                    {
                        list2.Add(new FloatMenuOption("Incoming", delegate()
                        {
                            Thing Dropship            = ThingMaker.MakeThing(localDef, null);
                            CompDropship compDropship = Dropship.TryGetCompFast <CompDropship>();
                            if (compDropship != null)
                            {
                                compDropship.Refuelable.Refuel(compDropship.Refuelable.TargetFuelLevel);
                            }
                            GenPlace.TryPlaceThing(SkyfallerMaker.MakeSkyfaller(Incomingdef, Dropship), cell, Find.CurrentMap, ThingPlaceMode.Near, null, null, default);
                        }, MenuOptionPriority.Default, null, null, 0f, null, null));
                    }
                    ThingDef Crasheddef = DefDatabase <ThingDef> .GetNamedSilentFail(localDef.defName + "_Crashed");
                    if (Crasheddef != null)
                    {
                        ThingDef Crashingdef = DefDatabase <ThingDef> .GetNamedSilentFail(localDef.defName + "_Crashing");
                        if (Crashingdef != null)
                        {
                            list2.Add(new FloatMenuOption("Crashing", delegate()
                            {
                                Thing Dropship            = ThingMaker.MakeThing(Crasheddef, null);
                                CompDropship compDropship = Dropship.TryGetCompFast <CompDropship>();
                                if (compDropship != null)
                                {
                                    compDropship.Refuelable.Refuel(compDropship.Refuelable.TargetFuelLevel);
                                }
                                GenPlace.TryPlaceThing(SkyfallerMaker.MakeSkyfaller(Crashingdef, Dropship), cell, Find.CurrentMap, ThingPlaceMode.Near, null, null, default(Rot4));
                            }, MenuOptionPriority.Default, null, null, 0f, null, null));
                        }
                    }
                    list2.Add(new FloatMenuOption("Stationary", delegate()
                    {
                        Thing Dropship            = ThingMaker.MakeThing(localDef, null);
                        CompDropship compDropship = Dropship.TryGetCompFast <CompDropship>();
                        if (compDropship != null)
                        {
                            compDropship.Refuelable.Refuel(compDropship.Refuelable.TargetFuelLevel);
                        }
                        GenPlace.TryPlaceThing(Dropship, cell, Find.CurrentMap, ThingPlaceMode.Near, null, null, default(Rot4));
                    }, MenuOptionPriority.Default, null, null, 0f, null, null));
                    Find.WindowStack.Add(new FloatMenu(list2));
                }));
            }
            Find.WindowStack.Add(new Dialog_DebugOptionListLister(list));
        }
        public void LaunchLightPod(int destinationTile, IntVec3 destinationCell, TransportPodsArrivalAction arrivalAction)
        {
            Map map = this.CasterPawn.Map;

            CreatePodGroup();
            podTList[0].TryRemoveLord(map);
            int groupID = podTList[0].groupID;

            for (int i = 0; i < podTList.Count; i++)
            {
                ThingOwner    directlyHeldThings = podTList[i].GetDirectlyHeldThings();
                ActiveDropPod activeDropPod      = (ActiveDropPod)ThingMaker.MakeThing(ThingDefOf.ActiveDropPod);
                activeDropPod.Contents = new ActiveDropPodInfo();
                activeDropPod.Contents.innerContainer.TryAddRangeOrTransfer(directlyHeldThings, canMergeWithExistingStacks: true, destroyLeftover: true);
                WorldTransport.TM_DropPodLeaving obj = (WorldTransport.TM_DropPodLeaving)SkyfallerMaker.MakeSkyfaller(TorannMagicDefOf.TM_LightPodLeaving, activeDropPod);
                obj.groupID         = groupID;
                obj.destinationTile = destinationTile;
                obj.arrivalAction   = arrivalAction;
                obj.arrivalCell     = destinationCell;
                obj.draftFlag       = this.draftFlag;
                podTList[i].CleanUpLoadingVars(map);
                podTList[i].parent.Destroy();
                GenSpawn.Spawn(obj, podTList[i].parent.Position, map);
            }
            CameraJumper.TryHideWorld();
            if (!map.mapPawns.AnyColonistSpawned && !map.IsPlayerHome)
            {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.Append("TM_AbandoningMap".Translate(map.Parent.LabelCap));
                Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation(stringBuilder.ToString(), delegate
                {
                    Settlement sm = map.Parent as Settlement;
                    WorldTransport.TM_DelayedDestroyMap ddm = new WorldTransport.TM_DelayedDestroyMap();
                    ddm.parent     = sm;
                    ddm.delayTicks = 120;
                    sm.AllComps.Add(ddm);
                }));
            }
        }
Beispiel #28
0
        //private bool ChoseWorldTarget(GlobalTargetInfo target)
        //{
        //    Utility.DebugReport("ChooseWorldTarget Called");
        //    if (!LoadingInProgressOrReadyToLaunch)
        //    {
        //        return true;
        //    }

        //    if (!target.IsValid)
        //    {
        //        Messages.Message("MessageTransportPodsDestinationIsInvalid".Translate(), MessageTypeDefOf.RejectInput);
        //        return false;
        //    }

        //    var num = Find.WorldGrid.TraversalDistanceBetween(parent.Map.Tile, target.Tile);
        //    if (num > MaxLaunchDistance)
        //    {
        //        //Messages.Message("MessageTransportPodsDestinationIsTooFar".Translate(new object[]
        //        //{
        //        //    CompLaunchable.FuelNeededToLaunchAtDist((float)num).ToString("0.#")
        //        //}), MessageTypeDefOf.RejectInput);
        //        return false;
        //    }

        //    if (target.WorldObject is MapParent {HasMap: true} mapParent)
        //    {
        //        var myMap = parent.Map;
        //        var map = mapParent.Map;
        //        Current.Game.CurrentMap = map;
        //        var arg_139_0 = Find.Targeter;

        //        void ActionWhenFinished()
        //        {
        //            if (Find.Maps.Contains(myMap))
        //            {
        //                Current.Game.CurrentMap = myMap;
        //            }
        //        }

        //        arg_139_0.BeginTargeting(TargetingParameters.ForDropPodsDestination(), delegate(LocalTargetInfo x)
        //        {
        //            if (!LoadingInProgressOrReadyToLaunch)
        //            {
        //                Utility.DebugReport("ChooseTarget Exited - LoadingInProgressOrReadyToLaunch");
        //                return;
        //            }

        //            TryLaunch(x.ToGlobalTargetInfo(map), PawnsArrivalModeDefOf.EdgeDrop, false);
        //        }, null, ActionWhenFinished, TargeterMouseAttachment);
        //        return true;
        //    }

        //    if (target.WorldObject is Settlement && target.WorldObject.Faction != Faction.OfPlayer)
        //    {
        //        Find.WorldTargeter.closeWorldTabWhenFinished = false;
        //        var list = new List<FloatMenuOption>();
        //        if (!target.WorldObject.Faction.HostileTo(Faction.OfPlayer))
        //        {
        //            list.Add(new FloatMenuOption("VisitFactionBase".Translate(
        //                target.WorldObject.Label
        //            ), delegate
        //            {
        //                if (!LoadingInProgressOrReadyToLaunch)
        //                {
        //                    return;
        //                }

        //                TryLaunch(target, PawnsArrivalModeDefOf.EdgeDrop, false);
        //                CameraJumper.TryHideWorld();
        //            }));
        //        }

        //        list.Add(new FloatMenuOption("DropAtEdge".Translate(), delegate
        //        {
        //            if (!LoadingInProgressOrReadyToLaunch)
        //            {
        //                return;
        //            }

        //            TryLaunch(target, PawnsArrivalModeDefOf.EdgeDrop, true);
        //            CameraJumper.TryHideWorld();
        //        }));
        //        list.Add(new FloatMenuOption("DropInCenter".Translate(), delegate
        //        {
        //            if (!LoadingInProgressOrReadyToLaunch)
        //            {
        //                return;
        //            }

        //            TryLaunch(target, PawnsArrivalModeDefOf.CenterDrop, true);
        //            CameraJumper.TryHideWorld();
        //        }));
        //        Find.WindowStack.Add(new FloatMenu(list));
        //        return true;
        //    }
        //    Messages.Message("MessageTransportPodsDestinationIsInvalid".Translate(), MessageTypeDefOf.RejectInput);
        //    return false;
        //    //this.TryLaunch(target, PawnsArrivalModeDefOf.Undecided, false);
        //    //return true;
        //}

        public void TryLaunch(int destinationTile, TransportPodsArrivalAction arrivalAction)
        {
            Utility.DebugReport("TryLaunch Called");
            if (!parent.Spawned)
            {
                Log.Error("Tried to launch " + parent + ", but it's unspawned.");
                return;
            }

            var transportersInGroup = TransportersInGroup;

            if (transportersInGroup == null)
            {
                Log.Error("Tried to launch " + parent + ", but it's not in any group.");
                return;
            }

            if (!LoadingInProgressOrReadyToLaunch)
            {
                Utility.DebugReport("TryLaunch Failed");
                return;
            }

            var map = parent.Map;
            var num = Find.WorldGrid.TraversalDistanceBetween(map.Tile, destinationTile);

            if (num > MaxLaunchDistance)
            {
                Utility.DebugReport("TryLaunch Failed #2");
                return;
            }

            Transporter.TryRemoveLord(map);
            var groupID = Transporter.groupID;

            foreach (var compTransporterPawn in transportersInGroup)
            {
                var compTransporter = compTransporterPawn;
                var originalPawn    = (Pawn)compTransporter.parent;
                var oldPosition     = compTransporter.parent.Position;


                ActiveDropPod activeDropPod = (ActiveDropPod)ThingMaker.MakeThing(ThingDefOf.ActiveDropPod, null);
                activeDropPod.Contents = new ActiveDropPodInfo();
                activeDropPod.Contents.innerContainer.TryAddRangeOrTransfer(compTransporter.GetDirectlyHeldThings(), true, true);
                FlyShipLeaving flyShipLeaving = (FlyShipLeaving)SkyfallerMaker.MakeSkyfaller(PawnFlyerDef.leavingDef ?? ThingDefOf.DropPodLeaving, activeDropPod);
                flyShipLeaving.groupID         = groupID;
                flyShipLeaving.destinationTile = destinationTile;
                flyShipLeaving.arrivalAction   = arrivalAction;
                flyShipLeaving.worldObjectDef  = PawnFlyerDef.travelingDef;
                //flyShipLeaving.worldObjectDef = WorldObjectDefOf.TravelingTransportPods;
                compTransporter.CleanUpLoadingVars(map);
                //compTransporter.parent.Destroy(DestroyMode.Vanish);
                compTransporterPawn.parent.DeSpawn();
                flyShipLeaving.Contents.innerContainer.TryAddOrTransfer(originalPawn);
                GenSpawn.Spawn(flyShipLeaving, oldPosition, map, WipeMode.Vanish);

                //Utility.DebugReport("Transporter Outspawn Attempt");
                //var compTransporter = compTransporterPawn;
                //Utility.DebugReport("Transporter Outspawn " + compTransporter.parent.Label);
                //var pawnFlyerLeaving = (Skyfaller) ThingMaker.MakeThing(PawnFlyerDef.leavingDef);
                //pawnFlyerLeaving.groupID = groupID;
                //pawnFlyerLeaving.pawnFlyer = parent as PawnFlyer;
                //pawnFlyerLeaving.destinationTile = target.Tile;
                //pawnFlyerLeaving.destinationCell = target.Cell;
                //pawnFlyerLeaving.arriveMode = arriveMode;
                //pawnFlyerLeaving.attackOnArrival = attackOnArrival;
                //var innerContainer = compTransporter.GetDirectlyHeldThings();
                //pawnFlyerLeaving.Contents = new ActiveDropPodInfo();
                //innerContainer.TryTransferAllToContainer(pawnFlyerLeaving.Contents.innerContainer);
                ////pawnFlyerLeaving.Contents.innerContainer. //TryAddMany(innerContainer);
                //innerContainer.Clear();
                //compTransporter.CleanUpLoadingVars(map);
                //compTransporter.parent.DeSpawn();
                //pawnFlyerLeaving.Contents.innerContainer.TryAdd(compTransporter.parent);
                //GenSpawn.Spawn(pawnFlyerLeaving, compTransporter.parent.Position, map);
            }
            CameraJumper.TryHideWorld();
        }
Beispiel #29
0
        public override void GenerateIntoMap(Map map)
        {
            if (Find.GameInitData == null)
            {
                return;
            }
            List <List <Thing> > list = new List <List <Thing> >();

            foreach (Pawn item in Find.GameInitData.startingAndOptionalPawns)
            {
                list.Add(new List <Thing>
                {
                    item
                });
            }
            List <Thing> list2 = new List <Thing>();

            foreach (ScenPart scenPart in Find.Scenario.AllParts)
            {
                list2.AddRange(scenPart.PlayerStartingThings());
            }
            int num = 0;

            for (int i = 0; i < list2.Count; i++)
            {
                Thing thing = list2[i];
                if (thing.def.CanHaveFaction)
                {
                    thing.SetFactionDirect(Faction.OfPlayer);
                }
                list[num].Add(thing);
                num++;
                if (num >= list.Count)
                {
                    num = 0;
                }
            }
            PlayerPawnsArriveMethod method = (PlayerPawnsArriveMethod)AccessTools.Field(typeof(ScenPart_PlayerPawnsArriveMethod), "method").GetValue(this);

            //     Log.Message("method = " + method.ToStringHuman() + " dropship: "+ (DropshipDef != null));
            if (DropshipDef != null && method == PlayerPawnsArriveMethod.DropPods)
            {
                Thing        ship     = ThingMaker.MakeThing(this.DropshipDef);
                CompDropship dropship = ship.TryGetCompFast <CompDropship>();
                if (dropship != null)
                {
                    foreach (List <Thing> item in list)
                    {
                        if (item.Contains(ship))
                        {
                            item.Remove(ship);
                        }
                        dropship.Transporter.innerContainer.TryAddRangeOrTransfer(item);
                    }
                    dropship.autodustoff = AutoDustoff;
                    if (DropCellFinder.TryFindDropSpotNear(MapGenerator.PlayerStartSpot, map, out IntVec3 spot, false, false, false, ship.def.Size))
                    {
                        GenPlace.TryPlaceThing(SkyfallerMaker.MakeSkyfaller(ThingDef.Named(ship.def.defName + "_Incoming"), ship), spot, map, ThingPlaceMode.Near, null, null, default(Rot4));
                    }
                    else
                    {
                        GenPlace.TryPlaceThing(SkyfallerMaker.MakeSkyfaller(ThingDef.Named(ship.def.defName + "_Incoming"), ship), MapGenerator.PlayerStartSpot, map, ThingPlaceMode.Near, null, null, default(Rot4));
                    }
                    return;
                }
            }
        // 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();
            }
        }