示例#1
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);
        }
示例#2
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));
        }
示例#3
0
 private static bool AnyAdjacentGoodDropSpot(IntVec3 c, Map map, bool allowFogged, bool canRoofPunch)
 {
     return(DropCellFinder.IsGoodDropSpot(c + IntVec3.North, map, allowFogged, canRoofPunch) || DropCellFinder.IsGoodDropSpot(c + IntVec3.East, map, allowFogged, canRoofPunch) || DropCellFinder.IsGoodDropSpot(c + IntVec3.South, map, allowFogged, canRoofPunch) || DropCellFinder.IsGoodDropSpot(c + IntVec3.West, map, allowFogged, canRoofPunch));
 }
示例#4
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);
         }
     }
 }
示例#5
0
        public override void TravelingTransportPodsArrived(List <ActiveDropPodInfo> dropPods, Map map)
        {
            IntVec3 near = DropCellFinder.FindRaidDropCenterDistant(map);

            TransportPodsArrivalActionUtility.DropTravelingTransportPods(dropPods, near, map);
        }
 private static bool <ForDropPodsDestination> m__3(TargetInfo x)
 {
     return(DropCellFinder.IsGoodDropSpot(x.Cell, x.Map, false, true));
 }