public override void Generate(Map map, GenStepParams parms)
        {
            TraverseParms traverseParams = TraverseParms.For(TraverseMode.NoPassClosedDoors);

            if (RCellFinder.TryFindRandomCellNearTheCenterOfTheMapWith((IntVec3 x) => x.Standable(map) && !x.Fogged(map) && map.reachability.CanReachMapEdge(x, traverseParams) && x.GetRoom(map).CellCount >= MinRoomCells, map, out var result))
            {
                float       points = ((parms.sitePart != null) ? parms.sitePart.parms.threatPoints : defaultPointsRange.RandomInRange);
                PawnKindDef animalKind;
                if (parms.sitePart != null && parms.sitePart.parms.animalKind != null)
                {
                    animalKind = parms.sitePart.parms.animalKind;
                }
                else if (!ManhunterPackGenStepUtility.TryGetAnimalsKind(points, map.Tile, out animalKind))
                {
                    return;
                }
                List <Pawn> list = ManhunterPackIncidentUtility.GenerateAnimals_NewTmp(animalKind, map.Tile, points);
                for (int i = 0; i < list.Count; i++)
                {
                    IntVec3 loc = CellFinder.RandomSpawnCellForPawnNear(result, map, 10);
                    GenSpawn.Spawn(list[i], loc, map, Rot4.Random);
                    list[i].health.AddHediff(HediffDefOf.Scaria);
                    list[i].mindState.mentalStateHandler.TryStartMentalState(MentalStateDefOf.ManhunterPermanent);
                }
            }
        }
示例#2
0
        public override void Generate(Map map, GenStepParams parms)
        {
            TraverseParms traverseParams = TraverseParms.For(TraverseMode.NoPassClosedDoors, Danger.Deadly, false);
            IntVec3       root;

            if (RCellFinder.TryFindRandomCellNearTheCenterOfTheMapWith((IntVec3 x) => x.Standable(map) && !x.Fogged(map) && map.reachability.CanReachMapEdge(x, traverseParams) && x.GetRoom(map, RegionType.Set_Passable).CellCount >= this.MinRoomCells, map, out root))
            {
                float       points = (parms.siteCoreOrPart == null) ? this.defaultPointsRange.RandomInRange : parms.siteCoreOrPart.parms.threatPoints;
                PawnKindDef animalKind;
                if (parms.siteCoreOrPart != null && parms.siteCoreOrPart.parms.animalKind != null)
                {
                    animalKind = parms.siteCoreOrPart.parms.animalKind;
                }
                else if (!ManhunterPackGenStepUtility.TryGetAnimalsKind(points, map.Tile, out animalKind))
                {
                    return;
                }
                List <Pawn> list = ManhunterPackIncidentUtility.GenerateAnimals(animalKind, map.Tile, points);
                for (int i = 0; i < list.Count; i++)
                {
                    IntVec3 loc = CellFinder.RandomSpawnCellForPawnNear(root, map, 10);
                    GenSpawn.Spawn(list[i], loc, map, Rot4.Random, WipeMode.Vanish, false);
                    list[i].mindState.mentalStateHandler.TryStartMentalState(MentalStateDefOf.ManhunterPermanent, null, false, false, null, false);
                }
            }
        }
示例#3
0
        public static bool TryFindRaidDropCenterClose(out IntVec3 spot, Map map, bool canRoofPunch = true, bool allowIndoors = true, bool closeWalk = true, int maxRadius = -1)
        {
            Faction parentFaction = map.ParentFaction;

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

            do
            {
                IntVec3 result = IntVec3.Invalid;
                if (map.mapPawns.FreeHumanlikesSpawnedOfFaction(parentFaction).Count() > 0)
                {
                    result = map.mapPawns.FreeHumanlikesSpawnedOfFaction(parentFaction).RandomElement().Position;
                }
                else
                {
                    if (parentFaction == Faction.OfPlayer)
                    {
                        List <Building> allBuildingsColonist = map.listerBuildings.allBuildingsColonist;
                        for (int i = 0; i < allBuildingsColonist.Count && !TryFindDropSpotNear(allBuildingsColonist[i].Position, map, out result, allowFogged: true, canRoofPunch, allowIndoors); i++)
                        {
                        }
                    }
                    else
                    {
                        List <Thing> list = map.listerThings.ThingsInGroup(ThingRequestGroup.BuildingArtificial);
                        for (int j = 0; j < list.Count && (list[j].Faction != parentFaction || !TryFindDropSpotNear(list[j].Position, map, out result, allowFogged: true, canRoofPunch, allowIndoors)); j++)
                        {
                        }
                    }
                    if (!result.IsValid)
                    {
                        RCellFinder.TryFindRandomCellNearTheCenterOfTheMapWith((IntVec3 x) => CanPhysicallyDropInto(x, map, canRoofPunch, allowIndoors) && !x.Fogged(map) && x.Standable(map), map, out result);
                    }
                }
                int num2 = ((maxRadius >= 0) ? maxRadius : 10);
                if (!closeWalk)
                {
                    CellFinder.TryFindRandomCellNear(result, map, num2 * num2, null, out spot, 50);
                }
                else
                {
                    spot = CellFinder.RandomClosewalkCellNear(result, map, num2);
                }
                if (CanPhysicallyDropInto(spot, map, canRoofPunch, allowIndoors) && !spot.Fogged(map))
                {
                    return(true);
                }
                num++;
            }while (num <= 300);
            spot = CellFinderLoose.RandomCellWith((IntVec3 c) => CanPhysicallyDropInto(c, map, canRoofPunch, allowIndoors), map);
            return(false);
        }
示例#4
0
 public static bool TryFindRootToSpawnAroundRectOfInterest(out CellRect rectToDefend, out IntVec3 singleCellToSpawnNear, Map map)
 {
     singleCellToSpawnNear = IntVec3.Invalid;
     if (!MapGenerator.TryGetVar("RectOfInterest", out rectToDefend))
     {
         rectToDefend = CellRect.Empty;
         if (!RCellFinder.TryFindRandomCellNearTheCenterOfTheMapWith((IntVec3 x) => x.Standable(map) && !x.Fogged(map) && x.GetRoom(map).CellCount >= 225, map, out singleCellToSpawnNear))
         {
             return(false);
         }
     }
     return(true);
 }
示例#5
0
        public static Thing SpawnTunnels(int hiveCount, Map map, bool spawnAnywhereIfNoGoodCell = false, bool ignoreRoofedRequirement = false, string questTag = null)
        {
            if (!InfestationCellFinder.TryFindCell(out var cell, map))
            {
                if (!spawnAnywhereIfNoGoodCell)
                {
                    return(null);
                }
                if (!RCellFinder.TryFindRandomCellNearTheCenterOfTheMapWith(delegate(IntVec3 x)
                {
                    if (!x.Standable(map) || x.Fogged(map))
                    {
                        return(false);
                    }
                    bool flag = false;
                    int num = GenRadial.NumCellsInRadius(3f);
                    for (int j = 0; j < num; j++)
                    {
                        IntVec3 c = x + GenRadial.RadialPattern[j];
                        if (c.InBounds(map))
                        {
                            RoofDef roof = c.GetRoof(map);
                            if (roof != null && roof.isThickRoof)
                            {
                                flag = true;
                                break;
                            }
                        }
                    }
                    return(flag ? true : false);
                }, map, out cell))
                {
                    return(null);
                }
            }
            Thing thing = GenSpawn.Spawn(ThingMaker.MakeThing(ThingDefOf.TunnelHiveSpawner), cell, map, WipeMode.FullRefund);

            QuestUtility.AddQuestTag(thing, questTag);
            for (int i = 0; i < hiveCount - 1; i++)
            {
                cell = CompSpawnerHives.FindChildHiveLocation(thing.Position, map, ThingDefOf.Hive, ThingDefOf.Hive.GetCompProperties <CompProperties_SpawnerHives>(), ignoreRoofedRequirement, allowUnreachable: true);
                if (cell.IsValid)
                {
                    thing = GenSpawn.Spawn(ThingMaker.MakeThing(ThingDefOf.TunnelHiveSpawner), cell, map, WipeMode.FullRefund);
                    QuestUtility.AddQuestTag(thing, questTag);
                }
            }
            return(thing);
        }
        private CellRect FindRandomRectToDefend(Map map)
        {
            int           rectRadius     = Mathf.Max(Mathf.RoundToInt((float)Mathf.Min(map.Size.x, map.Size.z) * 0.07f), 1);
            TraverseParms traverseParams = TraverseParms.For(TraverseMode.PassDoors, Danger.Deadly, false);
            IntVec3       center;
            CellRect      result;

            if (RCellFinder.TryFindRandomCellNearTheCenterOfTheMapWith(delegate(IntVec3 x)
            {
                bool result2;
                if (!map.reachability.CanReachMapEdge(x, traverseParams))
                {
                    result2 = false;
                }
                else
                {
                    CellRect cellRect = CellRect.CenteredOn(x, rectRadius);
                    int num = 0;
                    CellRect.CellRectIterator iterator = cellRect.GetIterator();
                    while (!iterator.Done())
                    {
                        if (!iterator.Current.InBounds(map))
                        {
                            return(false);
                        }
                        if (iterator.Current.Standable(map) || iterator.Current.GetPlant(map) != null)
                        {
                            num++;
                        }
                        iterator.MoveNext();
                    }
                    result2 = ((float)num / (float)cellRect.Area >= 0.6f);
                }
                return(result2);
            }, map, out center))
            {
                result = CellRect.CenteredOn(center, rectRadius);
            }
            else if (RCellFinder.TryFindRandomCellNearTheCenterOfTheMapWith((IntVec3 x) => x.Standable(map), map, out center))
            {
                result = CellRect.CenteredOn(center, rectRadius);
            }
            else
            {
                result = CellRect.CenteredOn(CellFinder.RandomCell(map), rectRadius).ClipInsideMap(map);
            }
            return(result);
        }
示例#7
0
        private CellRect FindRandomRectToDefend(Map map)
        {
            if (!MapGenerator.TryGetVar("UsedRects", out List <CellRect> usedRects))
            {
                usedRects = null;
            }
            int           rectRadius     = Mathf.Max(Mathf.RoundToInt((float)Mathf.Min(map.Size.x, map.Size.z) * 0.07f), 1);
            TraverseParms traverseParams = TraverseParms.For(TraverseMode.PassDoors);

            if (RCellFinder.TryFindRandomCellNearTheCenterOfTheMapWith(delegate(IntVec3 x)
            {
                if (!map.reachability.CanReachMapEdge(x, traverseParams))
                {
                    return(false);
                }
                CellRect cellRect = CellRect.CenteredOn(x, rectRadius);
                int num = 0;
                foreach (IntVec3 c in cellRect)
                {
                    if (!c.InBounds(map))
                    {
                        return(false);
                    }
                    if (usedRects != null && cellRect.IsOnEdge(c) && usedRects.Any((CellRect y) => y.Contains(c)))
                    {
                        return(false);
                    }
                    if (c.Standable(map) || c.GetPlant(map) != null)
                    {
                        num++;
                    }
                }
                return((float)num / (float)cellRect.Area >= 0.6f);
            }, map, out IntVec3 result))
            {
                return(CellRect.CenteredOn(result, rectRadius));
            }
            if (RCellFinder.TryFindRandomCellNearTheCenterOfTheMapWith((IntVec3 x) => x.Standable(map), map, out result))
            {
                return(CellRect.CenteredOn(result, rectRadius));
            }
            return(CellRect.CenteredOn(CellFinder.RandomCell(map), rectRadius).ClipInsideMap(map));
        }
        private CellRect FindRandomRectToDefend(Map map)
        {
            IntVec3       size           = map.Size;
            int           x2             = size.x;
            IntVec3       size2          = map.Size;
            int           rectRadius     = Mathf.Max(Mathf.RoundToInt((float)((float)Mathf.Min(x2, size2.z) * 0.070000000298023224)), 1);
            TraverseParms traverseParams = TraverseParms.For(TraverseMode.PassDoors, Danger.Deadly, false);
            IntVec3       center         = default(IntVec3);

            if (RCellFinder.TryFindRandomCellNearTheCenterOfTheMapWith((Predicate <IntVec3>) delegate(IntVec3 x)
            {
                if (!map.reachability.CanReachMapEdge(x, traverseParams))
                {
                    return(false);
                }
                CellRect cellRect = CellRect.CenteredOn(x, rectRadius);
                int num = 0;
                CellRect.CellRectIterator iterator = cellRect.GetIterator();
                while (!iterator.Done())
                {
                    if (!iterator.Current.InBounds(map))
                    {
                        return(false);
                    }
                    if (iterator.Current.Standable(map) || iterator.Current.GetPlant(map) != null)
                    {
                        num++;
                    }
                    iterator.MoveNext();
                }
                return((float)num / (float)cellRect.Area >= 0.60000002384185791);
            }, map, out center))
            {
                return(CellRect.CenteredOn(center, rectRadius));
            }
            if (RCellFinder.TryFindRandomCellNearTheCenterOfTheMapWith((Predicate <IntVec3>)((IntVec3 x) => x.Standable(map)), map, out center))
            {
                return(CellRect.CenteredOn(center, rectRadius));
            }
            return(CellRect.CenteredOn(CellFinder.RandomCell(map), rectRadius).ClipInsideMap(map));
        }
        public override void Generate(Map map)
        {
            TraverseParms traverseParams = TraverseParms.For(TraverseMode.NoPassClosedDoors, Danger.Deadly, false);
            IntVec3       root;

            if (RCellFinder.TryFindRandomCellNearTheCenterOfTheMapWith((IntVec3 x) => x.Standable(map) && !x.Fogged(map) && map.reachability.CanReachMapEdge(x, traverseParams) && x.GetRoom(map, RegionType.Set_Passable).CellCount >= this.MinRoomCells, map, out root))
            {
                float       randomInRange = this.pointsRange.RandomInRange;
                PawnKindDef animalKind;
                if (!ManhunterPackIncidentUtility.TryFindManhunterAnimalKind(randomInRange, map.Tile, out animalKind) && !ManhunterPackIncidentUtility.TryFindManhunterAnimalKind(randomInRange, -1, out animalKind))
                {
                    return;
                }
                List <Pawn> list = ManhunterPackIncidentUtility.GenerateAnimals(animalKind, map.Tile, randomInRange);
                for (int i = 0; i < list.Count; i++)
                {
                    IntVec3 loc = CellFinder.RandomSpawnCellForPawnNear(root, map, 10);
                    GenSpawn.Spawn(list[i], loc, map, Rot4.Random, false);
                    list[i].mindState.mentalStateHandler.TryStartMentalState(MentalStateDefOf.ManhunterPermanent, null, false, false, null);
                }
            }
        }
示例#10
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);
        }