Exemplo n.º 1
0
        public void SpawnDropPod(IntVec3 root, Map map, ref LookTargets targets)
        {
            List <List <Thing> > groups = new List <List <Thing> >();

            SpawnThings(out groups, ref targets);
            DropPodUtility.DropThingGroupsNear(root, map, groups, 140, false, true, true);
        }
        public static void SpawnStartingColonists()
        {
            foreach (Pawn current in MapInitParams.colonists)
            {
                current.psychology.thoughts.GainThought(ThoughtDef.Named("NewColonyOptimism"));
                current.SetFactionDirect(Faction.OfColony);
                current.AddAndRemoveComponentsAsAppropriate();
                PawnInventoryGenerator.GiveAppropriateKeysTo(current);
            }
            EnsureAllWorkTypesAreAssigned();
            bool startedDirectInEditor = MapInitParams.StartedDirectInEditor;
            List <List <Thing> > list  = new List <List <Thing> >();

            foreach (Pawn current2 in MapInitParams.colonists)
            {
                list.Add(new List <Thing>
                {
                    current2
                });
            }
            int num = 0;

            foreach (StartingItemRecord current3 in StartingItems)
            {
                Thing thing = ThingMaker.MakeThing(current3.thingDef);
                thing.SetFactionDirect(Faction.OfColony);
                list[num].Add(thing);
                num++;
                if (num >= list.Count)
                {
                    num = 0;
                }
            }
            bool canInstaDropDuringInit = startedDirectInEditor;

            DropPodUtility.DropThingGroupsNear(MapGenerator.PlayerStartSpot, list, 110, canInstaDropDuringInit, true);
            List <Thing> list2 = new List <Thing>();

            for (int i = 0; i < 16; i++)
            {
                Thing item = ThingMaker.MakeThing(ThingDef.Named("MealSurvivalPack"));
                list2.Add(item);
            }
            List <List <Thing> > list3 = new List <List <Thing> >();

            list3.Add(list2);
            canInstaDropDuringInit = startedDirectInEditor;
            DropPodUtility.DropThingGroupsNear(MapGenerator.PlayerStartSpot + new IntVec3(7, 0, 7), list3, 110, canInstaDropDuringInit, true);
        }
        public static void SpawnStuff()
        {
            foreach (Pawn current in ModdedMapInitParams.colonists)
            {
                current.psychology.thoughts.GainThought(ThoughtDef.Named("NewColonyOptimism"));
                current.SetFactionDirect(Faction.OfColony);
                current.AddAndRemoveComponentsAsAppropriate();
                PawnInventoryGenerator.GiveAppropriateKeysTo(current);
            }
            EnsureAllWorkTypesAreAssigned();
            bool canInstaDropDuringInit = ModdedMapInitParams.StartedDirectInEditor;

            List <List <Thing> > list = new List <List <Thing> >();

            foreach (Pawn current2 in ModdedMapInitParams.colonists)
            {
                list.Add(new List <Thing>
                {
                    current2
                });
            }

            DropPodUtility.DropThingGroupsNear(MapGenerator.PlayerStartSpot, list, 110, canInstaDropDuringInit, false);

            List <Thing> list2 = new List <Thing>();

            for (int i = 0; i < 16; i++)
            {
                Thing item = ThingMaker.MakeThing(ThingDef.Named("MealSurvivalPack"));
                list2.Add(item);
            }

            List <List <Thing> > list3 = new List <List <Thing> >();

            list3.Add(list2);

            try
            {
                DropPodUtility.DropThingGroupsNear(MapGenerator.PlayerStartSpot + new IntVec3(7, 0, 7), list3, 110, canInstaDropDuringInit, true);
            }
            catch (Exception e)
            {
                Log.Message(e.Message);
            }
        }
Exemplo n.º 4
0
 public override void PostMapGenerate(Map map)
 {
     if (Find.GameInitData == null)
     {
         return;
     }
     if (spawnInCoffins)
     {
         bool usingDropPods        = Find.Scenario.AllParts.Any(x => x is ScenPart_PlayerPawnsArriveMethod s && (PlayerPawnsArriveMethod)AccessTools.Field(typeof(ScenPart_PlayerPawnsArriveMethod), "method").GetValue(s) == PlayerPawnsArriveMethod.DropPods);
         List <List <Thing> > list = new List <List <Thing> >();
         foreach (Pawn current in Find.GameInitData.startingPawns)
         {
             if (current.RaceProps.Humanlike && current?.health?.hediffSet?.hediffs.FirstOrDefault(y => y.def.defName.Contains("Vampirism")) != null)
             {
                 IntVec3         loc    = current.PositionHeld;
                 Building_Casket casket = (Building_Casket)ThingMaker.MakeThing(VampDefOf.ROMV_RoyalCoffin, ThingDefOf.WoodLog);
                 casket.SetFaction(Faction.OfPlayer);
                 if (current.Spawned)
                 {
                     current.DeSpawn();
                 }
                 if (current.holdingOwner != null)
                 {
                     current.holdingOwner.Take(current);
                 }
                 if (!usingDropPods)
                 {
                     GenPlace.TryPlaceThing(casket, loc, map, ThingPlaceMode.Near);
                 }
                 casket.GetDirectlyHeldThings().TryAdd(current);
                 if (usingDropPods)
                 {
                     list.Add(new List <Thing> {
                         casket
                     });
                 }
             }
         }
         bool instaDrop = Find.GameInitData.QuickStarted;
         if (usingDropPods)
         {
             DropPodUtility.DropThingGroupsNear(MapGenerator.PlayerStartSpot, map, list, 110, instaDrop, true);
         }
     }
 }
Exemplo n.º 5
0
        public override void GenerateIntoMap(Map map)
        {
            if (Find.GameInitData == null)
            {
                return;
            }
            RCellFinder.TryFindRandomPawnEntryCell(out this.location, map, 1f, false, null);
            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;
                }
            }
            DropPodUtility.DropThingGroupsNear(this.location, map, list, 110, Find.GameInitData.QuickStarted || this.method != PlayerPawnsArriveMethod.DropPods, true, true, true, false);
        }
Exemplo n.º 6
0
        public override void Init()
        {
            base.Init();

            var customParams = CustomParams;

            Data.baseRadius = Mathf.InverseLerp(BaseRadiusMin, BaseRadiusMax, (float)lord.ownedPawns.Count / 50);
            Data.baseRadius = Mathf.Clamp(Data.baseRadius, BaseRadiusMin, BaseRadiusMax);
            List <Thing> list             = new List <Thing>();
            var          placedBlueprints = CustomSiegeUtility.PlaceBlueprints(Data, base.Map, lord.faction).ToList();

            for (int i = 0; i < placedBlueprints.Count; i++)
            {
                var blueprint_Build = placedBlueprints[i];
                Data.blueprints.Add(blueprint_Build);
                using (List <ThingDefCountClass> .Enumerator enumerator2 = blueprint_Build.MaterialsNeeded().GetEnumerator())
                {
                    while (enumerator2.MoveNext())
                    {
                        ThingDefCountClass cost = enumerator2.Current;
                        Thing thing             = list.FirstOrDefault((Thing t) => t.def == cost.thingDef);
                        if (thing != null)
                        {
                            thing.stackCount += cost.count;
                        }
                        else
                        {
                            Thing thing2 = ThingMaker.MakeThing(cost.thingDef, null);
                            thing2.stackCount = cost.count;
                            list.Add(thing2);
                        }
                    }
                }
                ThingDef thingDef = blueprint_Build.def.entityDefToBuild as ThingDef;
                if (thingDef != null)
                {
                    ThingDef  turret    = thingDef;
                    bool      allowEMP  = false;
                    TechLevel techLevel = lord.faction.def.techLevel;
                    ThingDef  thingDef2 = TurretGunUtility.TryFindRandomShellDef(turret, allowEMP, true, techLevel, false, 250f);
                    if (thingDef2 != null)
                    {
                        Thing thing3 = ThingMaker.MakeThing(thingDef2, null);
                        thing3.stackCount = InitalShellsPerCannon;
                        list.Add(thing3);
                    }
                }
            }
            for (int i = 0; i < list.Count; i++)
            {
                list[i].stackCount = Mathf.CeilToInt((float)list[i].stackCount * Rand.Range(1f, 1.2f));
            }
            List <List <Thing> > list2 = new List <List <Thing> >();

            for (int j = 0; j < list.Count; j++)
            {
                while (list[j].stackCount > list[j].def.stackLimit)
                {
                    int   num    = Mathf.CeilToInt((float)list[j].def.stackLimit * Rand.Range(0.9f, 0.999f));
                    Thing thing4 = ThingMaker.MakeThing(list[j].def, null);
                    thing4.stackCount   = num;
                    list[j].stackCount -= num;
                    list.Add(thing4);
                }
            }
            List <Thing> list3 = new List <Thing>();

            for (int k = 0; k < list.Count; k++)
            {
                list3.Add(list[k]);
                if (k % 2 == 1 || k == list.Count - 1)
                {
                    list2.Add(list3);
                    list3 = new List <Thing>();
                }
            }
            List <Thing> list4 = new List <Thing>();
            int          num2  = Mathf.RoundToInt(NutritionRangePerRaider.RandomInRange / customParams.mealDef.GetStatValueAbstract(StatDefOf.Nutrition) * lord.ownedPawns.Count);

            for (int l = 0; l < num2; l++)
            {
                Thing item = ThingMaker.MakeThing(customParams.mealDef, null);
                list4.Add(item);
            }
            list2.Add(list4);
            if (lord.faction.def.techLevel >= TechLevel.Industrial)
            {
                DropPodUtility.DropThingGroupsNear(Data.siegeCenter, Map, list2, 110);
            }
            else
            {
                for (int i = 0; i < list2.Count; i++)
                {
                    var group = list2[i];
                    if (DropCellFinder.TryFindDropSpotNear(Data.siegeCenter, Map, out IntVec3 pos, false, false))
                    {
                        for (int j = 0; j < group.Count; j++)
                        {
                            var thing = group[j];
                            thing.SetForbidden(true, false);
                            GenPlace.TryPlaceThing(thing, pos, Map, ThingPlaceMode.Near);
                        }
                    }
                }
            }
            Data.desiredBuilderFraction = BuilderCountFraction.RandomInRange;
        }
Exemplo n.º 7
0
        private void TryExecute(Map map, IncidentParms parms, ObjectiveDef def, IncidentCondition?condition)
        {
            LookTargets targets = new LookTargets();
            string      label   = "";
            string      message = "";

            if (type == IncidentType.Research)
            {
                StringBuilder sb = new StringBuilder();
                foreach (ResearchProjectDef project in researchUnlocks)
                {
                    sb.Append("   - " + project.LabelCap);
                    Find.ResearchManager.FinishProject(project);
                }
                label   = "ResearchIncident_SMO".Translate();
                message = "ResearchIncidentDesc_SMO".Translate(sb.ToString());
            }
            if (type == IncidentType.Reward)
            {
                SpawnMode mode = spawnSettings.mode;
                if (mode == SpawnMode.Target)
                {
                    SpawnAround(parms.spawnCenter, map, ref targets, out bool p);
                }
                if (mode == SpawnMode.Stockpile)
                {
                    List <Thing>   things = SpawnThings(out List <List <Thing> > list, ref targets);
                    List <IntVec3> cells  = new List <IntVec3>();
                    List <Zone>    zones  = map.zoneManager.AllZones;
                    for (int i = 0; i < zones.Count; i++)
                    {
                        Zone zone = zones[i];
                        if (zone is Zone_Stockpile)
                        {
                            cells.AddRange(zone.Cells.Where(c => c.GetFirstItem(map) == null));
                        }
                    }
                    if (cells.Count < things.Count)
                    {
                        IntVec3 cell = IntVec3.Invalid;
                        if (map.areaManager.Home?.ActiveCells.Count() > 0)
                        {
                            PositionFilter filter = new PositionFilter();
                            filter.homeArea = AreaCheck.Prefer;
                            filter.roofs    = AreaCheck.Avoid;
                            cell            = filter.FindCell(map, spawnSettings.spawnList);
                        }
                        cell = cell.IsValid ? cell : parms.spawnCenter;
                        DropPodUtility.DropThingGroupsNear(cell, map, list, 140, false, true, true);
                    }
                    else
                    {
                        foreach (Thing thing in things)
                        {
                            IntVec3 cell = cells.RandomElement();
                            cells.Remove(cell);
                            targets.targets.Add(GenSpawn.Spawn(thing, cells.RandomElement(), map));
                        }
                    }
                }
                if (mode == SpawnMode.DropPod)
                {
                    SpawnDropPod(parms.spawnCenter, map, ref targets);
                }
                if (condition.Value == IncidentCondition.Started)
                {
                    label   = "StartingItems_SMO".Translate();
                    message = "StartingItemsDesc_SMO".Translate("'" + def.LabelCap + "'");
                }
                if (condition.Value == IncidentCondition.Finished || condition == null)
                {
                    label = "Reward_SMO".Translate();
                    if (def != null)
                    {
                        message = "RewardDesc_SMO".Translate("'" + def.LabelCap + "'");
                    }
                }
            }
            if (type == IncidentType.Appear)
            {
                SpawnAround(parms.spawnCenter, map, ref targets, out bool p);
                label   = p ? "AppearPlural_SMO".Translate() : "Appear_SMO".Translate();
                message = p ? "AppearDescPlural_SMO".Translate() : "AppearDesc_SMO".Translate(targets);
            }
            if (type == IncidentType.Skyfaller)
            {
                int count = 0;
                foreach (ThingSkyfaller skyfaller in spawnSettings.skyfallers)
                {
                    if (Rand.Chance(skyfaller.chance))
                    {
                        count++;
                        targets.targets.Add(SkyfallerMaker.SpawnSkyfaller(skyfaller.skyfaller, skyfaller.def, parms.spawnCenter, map));
                    }
                }
                bool plural = count > 1;
                label   = plural ? "Skyfaller_SMO".Translate() : "SkyfallerPlural_SMO".Translate();
                message = plural ? "SkyfallerDesc_SMO".Translate() : "SkyfallerDescPlural_SMO".Translate();
            }
            if (type == IncidentType.Raid)
            {
                List <Pawn> raiders = new List <Pawn>();
                foreach (ThingValue tv in spawnSettings.spawnList)
                {
                    if (Rand.Chance(tv.chance))
                    {
                        for (int i = 0; i < tv.value; i++)
                        {
                            Pawn pawn = PawnGenerator.GeneratePawn(tv.PawnKindDef, parms.faction);
                            raiders.Add(pawn);
                            targets.targets.Add(pawn);
                        }
                    }
                }
                parms.raidArrivalMode.Worker.Arrive(raiders, parms);
                parms.raidStrategy.Worker.MakeLords(parms, raiders);
                Find.StoryWatcher.statsRecord.numRaidsEnemy++;
                label   = "Raid_SMO".Translate();
                message = "RaidDesc_SMO".Translate(PawnKinds);
            }
            Find.LetterStack.ReceiveLetter(letterLabel ?? label, letterDesc ?? message, letterDef, targets, type == IncidentType.Raid ? Faction : null, null);
        }
Exemplo n.º 8
0
        // Copy of ScenPart_PlayerPawnsArriveMethod.GenerateIntoMap(), but with changes to spawn custom
        // equipment.
        public void SpawnColonistsWithEquipment(Map map, ScenPart_PlayerPawnsArriveMethod arriveMethodPart)
        {
            List <List <Thing> > list = new List <List <Thing> >();

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

            foreach (ScenPart current2 in Find.Scenario.AllParts)
            {
                ScenPart_StartingThing_Defined startingThings = current2 as ScenPart_StartingThing_Defined;
                ScenPart_StartingAnimal        animal         = current2 as ScenPart_StartingAnimal;
                if (startingThings == null && animal == null)
                {
                    list2.AddRange(current2.PlayerStartingThings());
                }
            }

            int num = 0;

            foreach (Thing current3 in list2)
            {
                if (current3.def.CanHaveFaction)
                {
                    current3.SetFactionDirect(Faction.OfPlayer);
                }
                list[num].Add(current3);
                num++;
                if (num >= list.Count)
                {
                    num = 0;
                }
            }


            // Spawn custom equipment
            List <Thing> weapons = new List <Thing>();
            List <Thing> food    = new List <Thing>();
            List <Thing> apparel = new List <Thing>();
            List <Thing> animals = new List <Thing>();
            List <Thing> other   = new List <Thing>();

            int maxStack = 50;

            foreach (var e in PrepareCarefully.Instance.Equipment)
            {
                EquipmentDatabaseEntry entry = PrepareCarefully.Instance.EquipmentEntries[e.EquipmentKey];
                if (entry == null)
                {
                    string thing = e.def != null ? e.def.defName : "null";
                    string stuff = e.stuffDef != null ? e.stuffDef.defName : "null";
                    Log.Warning(string.Format("Unrecognized resource/equipment.  This may be caused by an invalid thing/stuff combination. (thing = {0}, stuff={1})", thing, stuff));
                    continue;
                }
                if (entry.gear)
                {
                    int count           = e.Count;
                    int idealStackCount = count / list.Count;
                    while (count > 0)
                    {
                        int stackCount = idealStackCount;
                        if (stackCount < 1)
                        {
                            stackCount = 1;
                        }
                        if (stackCount > entry.def.stackLimit)
                        {
                            stackCount = entry.def.stackLimit;
                        }
                        if (stackCount > maxStack)
                        {
                            stackCount = maxStack;
                        }
                        if (stackCount > count)
                        {
                            stackCount = count;
                        }

                        Thing thing = null;
                        if (entry.def.MadeFromStuff && entry.stuffDef == null)
                        {
                            ThingDef defaultStuffDef = null;
                            if (entry.def.apparel != null)
                            {
                                defaultStuffDef = ThingDef.Named("Synthread");
                            }
                            if (thing == null)
                            {
                                Log.Warning("Item " + entry.def.defName + " is \"made from stuff\" but no material was specified. This may be caused by a misconfigured modded item or scenario.");
                                Log.Warning("The item will be spawned into the map and assigned a default material, if possible, but you will see an error if you are in Development Mode.");
                            }
                            thing = ThingMaker.MakeThing(entry.def, defaultStuffDef);
                        }
                        else
                        {
                            thing = ThingMaker.MakeThing(entry.def, entry.stuffDef);
                        }

                        if (thing != null)
                        {
                            thing.stackCount = stackCount;
                            if (entry.def.weaponTags != null && entry.def.weaponTags.Count > 0)
                            {
                                weapons.Add(thing);
                            }
                            else if (entry.def.apparel != null)
                            {
                                apparel.Add(thing);
                            }
                            else if (entry.def.ingestible != null)
                            {
                                food.Add(thing);
                            }
                            else
                            {
                                other.Add(thing);
                            }
                        }

                        // Decrement the count whether we were able to add a valid thing or not.  If we don't decrement,
                        // we'll be stuck in an infinite while loop.
                        count -= stackCount;
                    }
                }
                else if (entry.animal)
                {
                    int count = e.Count;
                    for (int i = 0; i < count; i++)
                    {
                        Thing animal = CreateAnimal(entry);
                        if (animal != null)
                        {
                            animals.Add(animal);
                        }
                    }
                }
            }

            List <Thing> combined = new List <Thing>();

            combined.AddRange(weapons);
            combined.AddRange(food);
            combined.AddRange(apparel);
            combined.AddRange(animals);
            combined.AddRange(other);

            num = 0;
            foreach (Thing thing in combined)
            {
                if (thing.def.CanHaveFaction)
                {
                    thing.SetFactionDirect(Faction.OfPlayer);
                }
                list[num].Add(thing);
                num++;
                if (num >= list.Count)
                {
                    num = 0;
                }
            }

            // Get the arrive method from the scenario part.
            PlayerPawnsArriveMethod arriveMethod = PlayerPawnsArriveMethod.DropPods;

            if (arriveMethodPart != null)
            {
                arriveMethod = (PlayerPawnsArriveMethod)typeof(ScenPart_PlayerPawnsArriveMethod).GetField("method",
                                                                                                          BindingFlags.NonPublic | BindingFlags.Instance).GetValue(arriveMethodPart);
            }

            bool instaDrop = Find.GameInitData.QuickStarted || arriveMethod != PlayerPawnsArriveMethod.DropPods;

            DropPodUtility.DropThingGroupsNear(MapGenerator.PlayerStartSpot, map, list, 110, instaDrop, true, true);
        }
 public void SpawnDropPod(IntVec3 root, Map map, List <List <Thing> > groups)
 {
     DropPodUtility.DropThingGroupsNear(root, map, groups, 140, false, true, true);
 }