Exemplo n.º 1
0
 public static void DropThingGroupsNear(IntVec3 dropCenter, Map map, List <List <Thing> > thingsGroups, int openDelay = 110, bool instaDrop = false, bool leaveSlag = false, bool canRoofPunch = true, bool explode = false)
 {
     foreach (List <Thing> current in thingsGroups)
     {
         IntVec3 intVec;
         if (!DropCellFinder.TryFindDropSpotNear(dropCenter, map, out intVec, true, canRoofPunch))
         {
             Log.Warning(string.Concat(new object[]
             {
                 "DropThingsNear failed to find a place to drop ",
                 current.FirstOrDefault <Thing>(),
                 " near ",
                 dropCenter,
                 ". Dropping on random square instead."
             }));
             intVec = CellFinderLoose.RandomCellWith((IntVec3 c) => c.Walkable(map), map, 1000);
         }
         for (int i = 0; i < current.Count; i++)
         {
             current[i].SetForbidden(true, false);
         }
         if (instaDrop)
         {
             foreach (Thing current2 in current)
             {
                 GenPlace.TryPlaceThing(current2, intVec, map, ThingPlaceMode.Near, null);
             }
         }
         else
         {
             ActiveDropPodInfo activeDropPodInfo = new ActiveDropPodInfo();
             foreach (Thing current3 in current)
             {
                 activeDropPodInfo.innerContainer.TryAdd(current3, true);
             }
             activeDropPodInfo.openDelay = openDelay;
             activeDropPodInfo.leaveSlag = leaveSlag;
             DropPodUtility.MakeDropPodAt(intVec, map, activeDropPodInfo, explode);
         }
     }
 }
Exemplo n.º 2
0
 public static void DropThingGroupsNear_NewTmp(IntVec3 dropCenter, Map map, List <List <Thing> > thingsGroups, int openDelay = 110, bool instaDrop = false, bool leaveSlag = false, bool canRoofPunch = true, bool forbid = true, bool allowFogged = true)
 {
     foreach (List <Thing> thingsGroup in thingsGroups)
     {
         if (!DropCellFinder.TryFindDropSpotNear(dropCenter, map, out IntVec3 result, allowFogged, canRoofPunch) && (canRoofPunch || !DropCellFinder.TryFindDropSpotNear(dropCenter, map, out result, allowFogged, canRoofPunch: true)))
         {
             Log.Warning("DropThingsNear failed to find a place to drop " + thingsGroup.FirstOrDefault() + " near " + dropCenter + ". Dropping on random square instead.");
             result = CellFinderLoose.RandomCellWith((IntVec3 c) => c.Walkable(map), map);
         }
         if (forbid)
         {
             for (int i = 0; i < thingsGroup.Count; i++)
             {
                 thingsGroup[i].SetForbidden(value: true, warnOnFail: false);
             }
         }
         if (instaDrop)
         {
             foreach (Thing item in thingsGroup)
             {
                 GenPlace.TryPlaceThing(item, result, map, ThingPlaceMode.Near);
             }
         }
         else
         {
             ActiveDropPodInfo activeDropPodInfo = new ActiveDropPodInfo();
             foreach (Thing item2 in thingsGroup)
             {
                 activeDropPodInfo.innerContainer.TryAdd(item2);
             }
             activeDropPodInfo.openDelay = openDelay;
             activeDropPodInfo.leaveSlag = leaveSlag;
             MakeDropPodAt(result, map, activeDropPodInfo);
         }
     }
 }
Exemplo n.º 3
0
        public static IntVec3 TradeDropSpot(Map map)
        {
            IEnumerable <Building> collection = from b in map.listerBuildings.allBuildingsColonist
                                                where b.def.IsCommsConsole
                                                select b;
            IEnumerable <Building> enumerable = from b in map.listerBuildings.allBuildingsColonist
                                                where b.def.IsOrbitalTradeBeacon
                                                select b;
            Building building = enumerable.FirstOrDefault((Building b) => !map.roofGrid.Roofed(b.Position) && DropCellFinder.AnyAdjacentGoodDropSpot(b.Position, map, false, false));
            IntVec3  position;

            if (building != null)
            {
                position = building.Position;
                IntVec3 result;
                if (!DropCellFinder.TryFindDropSpotNear(position, map, out result, false, false))
                {
                    Log.Error("Could find no good TradeDropSpot near dropCenter " + position + ". Using a random standable unfogged cell.", false);
                    result = CellFinderLoose.RandomCellWith((IntVec3 c) => c.Standable(map) && !c.Fogged(map), map, 1000);
                }
                return(result);
            }
            List <Building> list = new List <Building>();

            list.AddRange(enumerable);
            list.AddRange(collection);
            list.RemoveAll(delegate(Building b)
            {
                CompPowerTrader compPowerTrader = b.TryGetComp <CompPowerTrader>();
                return(compPowerTrader != null && !compPowerTrader.PowerOn);
            });
            Predicate <IntVec3> validator = (IntVec3 c) => DropCellFinder.IsGoodDropSpot(c, map, false, false);

            if (!list.Any <Building>())
            {
                list.AddRange(map.listerBuildings.allBuildingsColonist);
                list.Shuffle <Building>();
                if (!list.Any <Building>())
                {
                    return(CellFinderLoose.RandomCellWith(validator, map, 1000));
                }
            }
            int num = 8;

            while (true)
            {
                for (int i = 0; i < list.Count; i++)
                {
                    IntVec3 position2 = list[i].Position;
                    if (CellFinder.TryFindRandomCellNear(position2, map, num, validator, out position, -1))
                    {
                        return(position);
                    }
                }
                num = Mathf.RoundToInt((float)num * 1.1f);
                if (num > map.Size.x)
                {
                    goto Block_9;
                }
            }
            return(position);

Block_9:
            Log.Error("Failed to generate trade drop center. Giving random.", false);
            return(CellFinderLoose.RandomCellWith(validator, map, 1000));
        }
Exemplo n.º 4
0
        public static bool TryFindRaidDropCenterClose(out IntVec3 spot, Map map)
        {
            Faction faction = map.ParentFaction ?? Faction.OfPlayer;
            int     num     = 0;

            while (true)
            {
                IntVec3 root = IntVec3.Invalid;
                if (map.mapPawns.FreeHumanlikesSpawnedOfFaction(faction).Count() > 0)
                {
                    root = map.mapPawns.FreeHumanlikesSpawnedOfFaction(faction).RandomElement().Position;
                }
                else
                {
                    if (faction == Faction.OfPlayer)
                    {
                        List <Building> allBuildingsColonist = map.listerBuildings.allBuildingsColonist;
                        int             num2 = 0;
                        while (num2 < allBuildingsColonist.Count && !DropCellFinder.TryFindDropSpotNear(allBuildingsColonist[num2].Position, map, out root, true, true))
                        {
                            num2++;
                        }
                    }
                    else
                    {
                        List <Thing> list = map.listerThings.ThingsInGroup(ThingRequestGroup.BuildingArtificial);
                        int          num3 = 0;
                        while (num3 < list.Count && (list[num3].Faction != faction || !DropCellFinder.TryFindDropSpotNear(list[num3].Position, map, out root, true, true)))
                        {
                            num3++;
                        }
                    }
                    if (!root.IsValid)
                    {
                        root = DropCellFinder.RandomDropSpot(map);
                    }
                }
                spot = CellFinder.RandomClosewalkCellNear(root, map, 10, null);
                if (DropCellFinder.CanPhysicallyDropInto(spot, map, true))
                {
                    return(true);
                }
                num++;
                if (num > 300)
                {
                    break;
                }
            }
            spot = CellFinderLoose.RandomCellWith((IntVec3 c) => DropCellFinder.CanPhysicallyDropInto(c, map, true), map, 1000);
            return(false);
        }
Exemplo n.º 5
0
        public List <Thing> ApplyRewardsForTitle(Faction faction, RoyalTitleDef currentTitle, RoyalTitleDef newTitle, bool onlyForNewestTitle = false)
        {
            List <Thing>      list  = new List <Thing>();
            List <ThingCount> list2 = new List <ThingCount>();

            if (newTitle != null && newTitle.Awardable && pawn.IsColonist && NewHighestTitle(faction, newTitle))
            {
                int num  = ((currentTitle != null) ? faction.def.RoyalTitlesAwardableInSeniorityOrderForReading.IndexOf(currentTitle) : 0) + 1;
                int num2 = faction.def.RoyalTitlesAwardableInSeniorityOrderForReading.IndexOf(newTitle);
                if (onlyForNewestTitle)
                {
                    num = num2;
                }
                IntVec3 result  = IntVec3.Invalid;
                Map     mapHeld = pawn.MapHeld;
                if (mapHeld != null)
                {
                    if (mapHeld.IsPlayerHome)
                    {
                        result = DropCellFinder.TradeDropSpot(mapHeld);
                    }
                    else if (!DropCellFinder.TryFindDropSpotNear(pawn.Position, mapHeld, out result, allowFogged: false, canRoofPunch: false))
                    {
                        result = DropCellFinder.RandomDropSpot(mapHeld);
                    }
                }
                for (int i = num; i <= num2; i++)
                {
                    RoyalTitleDef royalTitleDef = faction.def.RoyalTitlesAwardableInSeniorityOrderForReading[i];
                    if (royalTitleDef.rewards == null)
                    {
                        continue;
                    }
                    List <Thing> list3 = royalTitleDef.rewards.Select(delegate(ThingDefCountClass r)
                    {
                        Thing thing      = ThingMaker.MakeThing(r.thingDef);
                        thing.stackCount = r.count;
                        return(thing);
                    }).ToList();
                    for (int j = 0; j < list3.Count; j++)
                    {
                        if (list3[j].def == ThingDefOf.PsychicAmplifier)
                        {
                            Find.History.Notify_PsylinkAvailable();
                            break;
                        }
                    }
                    if (pawn.Spawned)
                    {
                        DropPodUtility.DropThingsNear(result, mapHeld, list3, 110, canInstaDropDuringInit: false, leaveSlag: false, canRoofPunch: false, forbid: false);
                    }
                    else
                    {
                        foreach (Thing item in list3)
                        {
                            pawn.inventory.TryAddItemNotForSale(item);
                        }
                    }
                    for (int k = 0; k < list3.Count; k++)
                    {
                        list2.Add(new ThingCount(list3[k], list3[k].stackCount));
                    }
                    list.AddRange(list3);
                }
                if (list.Count > 0)
                {
                    TaggedString text = "LetterRewardsForNewTitle".Translate(pawn.Named("PAWN"), faction.Named("FACTION"), newTitle.GetLabelCapFor(pawn).Named("TITLE")) + "\n\n" + GenLabel.ThingsLabel(list2, "  - ", ignoreStackLimit: true) + "\n\n" + (pawn.Spawned ? "LetterRewardsForNewTitleDeliveryBase" : "LetterRewardsForNewTitleDeliveryDirect").Translate(pawn.Named("PAWN"));
                    Find.LetterStack.ReceiveLetter("LetterLabelRewardsForNewTitle".Translate(), text, LetterDefOf.PositiveEvent, list);
                }
            }
            return(list);
        }
Exemplo n.º 6
0
        public static bool TryFindRaidDropCenterClose(out IntVec3 spot, Map map)
        {
            Faction parentFaction = map.ParentFaction;

            if (parentFaction == null)
            {
                return(RCellFinder.TryFindRandomCellNearTheCenterOfTheMapWith((IntVec3 x) => DropCellFinder.CanPhysicallyDropInto(x, map, true) && !x.Fogged(map) && x.Standable(map), map, out spot));
            }
            int num = 0;

            while (true)
            {
                IntVec3 root = IntVec3.Invalid;
                if (map.mapPawns.FreeHumanlikesSpawnedOfFaction(parentFaction).Count <Pawn>() > 0)
                {
                    root = map.mapPawns.FreeHumanlikesSpawnedOfFaction(parentFaction).RandomElement <Pawn>().Position;
                }
                else
                {
                    if (parentFaction == Faction.OfPlayer)
                    {
                        List <Building> allBuildingsColonist = map.listerBuildings.allBuildingsColonist;
                        for (int i = 0; i < allBuildingsColonist.Count; i++)
                        {
                            if (DropCellFinder.TryFindDropSpotNear(allBuildingsColonist[i].Position, map, out root, true, true))
                            {
                                break;
                            }
                        }
                    }
                    else
                    {
                        List <Thing> list = map.listerThings.ThingsInGroup(ThingRequestGroup.BuildingArtificial);
                        for (int j = 0; j < list.Count; j++)
                        {
                            if (list[j].Faction == parentFaction && DropCellFinder.TryFindDropSpotNear(list[j].Position, map, out root, true, true))
                            {
                                break;
                            }
                        }
                    }
                    if (!root.IsValid)
                    {
                        RCellFinder.TryFindRandomCellNearTheCenterOfTheMapWith((IntVec3 x) => DropCellFinder.CanPhysicallyDropInto(x, map, true) && !x.Fogged(map) && x.Standable(map), map, out root);
                    }
                }
                spot = CellFinder.RandomClosewalkCellNear(root, map, 10, null);
                if (DropCellFinder.CanPhysicallyDropInto(spot, map, true) && !spot.Fogged(map))
                {
                    break;
                }
                num++;
                if (num > 300)
                {
                    goto Block_10;
                }
            }
            return(true);

Block_10:
            spot = CellFinderLoose.RandomCellWith((IntVec3 c) => DropCellFinder.CanPhysicallyDropInto(c, map, true), map, 1000);
            return(false);
        }