Exemplo n.º 1
0
        private Lord CreateNewLord(Pawn pawn)
        {
            IntVec3 c;
            Thing   thing = GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForDef(XenomorphDefOf.RRY_EggXenomorphFertilized), PathEndMode.OnCell, TraverseParms.For(TraverseMode.NoPassClosedDoors, Danger.Deadly, false), 9999f, null, null, 0, -1, false, RegionType.Set_Passable, false);

            if (thing != null)
            {
                c = RCellFinder.RandomWanderDestFor(pawn, thing.Position, 5f, null, Danger.Some);
            }
            else
            {
                if (InfestationLikeCellFinder.TryFindCell(out c, pawn.Map, false))
                {
                    if (Prefs.DevMode && Find.Selector.SelectedObjects.Contains(pawn))
                    {
                        ThingDef td = XenomorphDefOf.RRY_Filth_Slime;
                        GenSpawn.Spawn(td, c, pawn.Map);
                        Find.LetterStack.ReceiveLetter(string.Format("Lord Created"), string.Format("@: {0} ", c), LetterDefOf.NegativeEvent, c.GetFirstThing(pawn.Map, td), null, null);
                    }
                }
                if (pawn.CanReach(c, PathEndMode.OnCell, Danger.Deadly, true))
                {
                    //    c = RCellFinder.RandomWanderDestFor(pawn, c, 3f, null, Danger.Some);
                }
                else
                {
                    c = RCellFinder.RandomWanderDestFor(pawn, thing.Position, 3f, null, Danger.Some);
                }
            }
            if (pawn.GetLord() != null && pawn.GetLord() is Lord l)
            {
                if (l.ownedPawns.Count > 0)
                {
                    l.ownedPawns.Remove(pawn);
                }
                if (l.ownedPawns.Count == 0)
                {
                    l.lordManager.RemoveLord(l);
                }
            }
            Lord lord = LordMaker.MakeNewLord(parent.Faction, new LordJob_DefendAndExpandHiveLike(false), parent.Map, null);

            lord.AddPawn(pawn);
            return(lord);
        }
        public static bool TryFindGoodHiveLoc(Pawn pawn, out IntVec3 c, Pawn victim = null, bool allowFogged = false, bool allowUnroofed = false, bool allowDigging = false)
        {
            Map map = pawn.Map;
            c = IntVec3.Invalid;
            if (map == null)
            {
                return false;
            }
            if (!pawn.isXenomorph(out Comp_Xenomorph _Xenomorph))
            {
                return false;
            }
            else
            {
                c = _Xenomorph.HiveLoc;
            }
            MapComponent_HiveGrid hiveGrid = pawn.Map.GetComponent<MapComponent_HiveGrid>();
            bool selected = map != null ? Find.Selector.SelectedObjects.Contains(pawn) && (Prefs.DevMode) : false;

            Predicate<IntVec3> validatora = delegate (IntVec3 y)
            {
                if (y.GetTerrain(map).HasTag("Water"))
                {
                    return false;
                }
                bool roofed = (!allowUnroofed && y.Roofed(map)) || allowUnroofed;
                bool score = InfestationLikeCellFinder.GetScoreAt(y, map, allowFogged, allowUnroofed, allowDigging) > 0f;;
                bool filled = y.Filled(map) && !allowDigging;
                bool edifice = y.GetEdifice(map).DestroyedOrNull() || allowDigging;
                bool building = y.GetFirstBuilding(map).DestroyedOrNull() || allowDigging;
                bool thing = y.GetThingList(map).All(x => x.GetType() != typeof(Building_XenomorphCocoon) && x.GetType() != typeof(Building_XenoEgg) && x.GetType() != typeof(HiveLike));
                bool r = score && !filled && edifice && building && thing && roofed;
                return r;
            };
            /*
            if (validatora (_Xenomorph.HiveLoc))
            {

                c = _Xenomorph.HiveLoc;
            }
            else
            if (hiveGrid.Hivelist.NullOrEmpty())
            {
                Log.Warning("no hives present");
                if (!hiveGrid.HiveLoclist.NullOrEmpty())
                {
                //    Log.Message("hivelocs present");
                    c = hiveGrid.HiveLoclist.RandomElement();
                //    return true;
                }
                else
                {
                    Log.Warning("no hivelocs present");
                }
            }
            else
            {
            //    Log.Message("hives present");
                c = hiveGrid.Hivelist.RandomElement().Position;
            //    return true;
            }
            */
            if (c == IntVec3.Invalid || c.x < 1 || c.z < 1 || c == IntVec3.Zero || c.InNoBuildEdgeArea(map) || c.InNoZoneEdgeArea(map) || c.GetTerrain(map).HasTag("Water"))
            {
                if (!InfestationLikeCellFinder.TryFindCell(out c, out IntVec3 lc, map, allowFogged, allowUnroofed, allowDigging))
                {
                //    Log.Message(string.Format("Cant find suitable hive location, defaulting to map edge"));
                    if (!InfestationCellFinder.TryFindCell(out c, map))
                    {
                    //    Log.Message(string.Format("Cant find suitable hive location, defaulting to map edge"));
                        if (!RCellFinder.TryFindBestExitSpot(pawn, out c, TraverseMode.ByPawn))
                        {
                        //    Log.Message(string.Format("Cant find spot near map edge"));
                        }
                        else
                        {
                        //    Log.Message(string.Format("RCellFinder: {0}", c));
                        }
                    }
                    else
                    {
                    //    Log.Message(string.Format("InfestationCellFinder: {0}", c));
                    }
                }
                else
                {
                //    Log.Message(string.Format("InfestationLikeCellFinder: {0}", c));
                }
            }
Exemplo n.º 3
0
        public void XenoLordTick()
        {
            if (map != null)
            {
                IntVec3            c             = IntVec3.Invalid;
                Lord               lord          = null;
                List <Lord>        Hivelords     = new List <Lord>();
                Lord               Hivelord      = null;
                LordJob            Hivejob       = null;
                Pawn               Hivequeen     = null;
                IEnumerable <Lord> lords         = pawn.Map.lordManager.lords.Where(x => x.faction == pawn.Faction);
                bool               isDefendPoint = pawn.GetLord() != null?pawn.GetLord().LordJob is LordJob_DefendPoint : false;

                bool isAssaultColony = pawn.GetLord() != null?pawn.GetLord().LordJob is LordJob_AssaultColony : false;

                bool hostsPresent    = map.mapPawns.AllPawnsSpawned.Any(x => x.isPotentialHost() && !x.isCocooned() && IsAcceptablePreyFor(pawn, x, true));
                bool LordReplaceable = (isDefendPoint || (isAssaultColony && !hostsPresent));
                //   Log.Message(string.Format("LordReplaceable: {0}, isDefendPoint: {1}, isAssaultColony: {2}, hostsPresent: {3}", LordReplaceable, isDefendPoint, isAssaultColony, !hostsPresent));
                if (lords.Count() != 0 && ((pawn.GetLord() != null && LordReplaceable) || pawn.GetLord() == null))
                {
                    foreach (var l in lords)
                    {
                        if (l != null)
                        {
                            if (XenomorphUtil.HivelikesPresent(map))
                            {
                                if (l.LordJob is LordJob_DefendAndExpandHiveLike j)
                                {
                                    Hivelord = l;
                                    Hivejob  = j;
                                    if (l.ownedPawns.Any(x => x.kindDef == QueenDef))
                                    {
                                        Hivequeen = l.ownedPawns.Find(x => x.kindDef == QueenDef);
                                    }
                                    if (pawn.kindDef != XenomorphDefOf.RRY_Xenomorph_Queen || (pawn.kindDef == XenomorphDefOf.RRY_Xenomorph_Queen && Hivequeen != null))
                                    {
                                        Hivelords.Add(l);
                                    }
                                }
                            }
                            else if (XenomorphUtil.HiveSlimePresent(map))
                            {
                                if (l.LordJob is LordJob_DefendHiveLoc j)
                                {
                                    Hivelord = l;
                                    Hivejob  = j;
                                    if (l.ownedPawns.Any(x => x.kindDef == QueenDef))
                                    {
                                        Hivequeen = l.ownedPawns.Find(x => x.kindDef == QueenDef);
                                    }
                                    if (pawn.kindDef != XenomorphDefOf.RRY_Xenomorph_Queen || (pawn.kindDef == XenomorphDefOf.RRY_Xenomorph_Queen && Hivequeen != null))
                                    {
                                        Hivelords.Add(l);
                                    }
                                }
                            }
                        }
                        else
                        {
                            /*
                             * lord = l;
                             * lord.AddPawn(pawn);
                             * pawn.mindState.duty = lord.ownedPawns.FindAll(x => x.mindState.duty != null && x != pawn).RandomElement().mindState.duty;
                             * break;
                             */
                        }
                    }
                }
                if (pawn.GetLord() != null && LordReplaceable)
                {
                    lord = pawn.GetLord();
                    if (lord.ownedPawns.Count == 0)
                    {
                        Log.Message(string.Format("got no pawns, wtf?"));
                    }
                    if (lord.ownedPawns.Count == 1)
                    {
                    }
                    if (c == IntVec3.Invalid && XenomorphUtil.HivelikesPresent(map))
                    {
                        c = !XenomorphUtil.ClosestReachableHivelike(pawn).DestroyedOrNull() ? XenomorphUtil.ClosestReachableHivelike(pawn).Position : IntVec3.Invalid;
                    }
                    if (c == IntVec3.Invalid && XenomorphUtil.EggsPresent(map))
                    {
                        c = !XenomorphUtil.ClosestReachableEgg(pawn).DestroyedOrNull() ? XenomorphUtil.ClosestReachableEgg(pawn).Position : IntVec3.Invalid;
                    }
                    if (c == IntVec3.Invalid && XenomorphUtil.CocoonsPresent(map, XenomorphDefOf.RRY_Xenomorph_Humanoid_Cocoon))
                    {
                        c = !XenomorphUtil.ClosestReachableCocoon(pawn, XenomorphDefOf.RRY_Xenomorph_Humanoid_Cocoon).DestroyedOrNull() ? XenomorphUtil.ClosestReachableCocoon(pawn, XenomorphDefOf.RRY_Xenomorph_Humanoid_Cocoon).Position : IntVec3.Invalid;
                    }
                    if (c == IntVec3.Invalid && XenomorphUtil.CocoonsPresent(map, XenomorphDefOf.RRY_Xenomorph_Animal_Cocoon))
                    {
                        c = !XenomorphUtil.ClosestReachableCocoon(pawn, XenomorphDefOf.RRY_Xenomorph_Animal_Cocoon).DestroyedOrNull() ? XenomorphUtil.ClosestReachableCocoon(pawn, XenomorphDefOf.RRY_Xenomorph_Animal_Cocoon).Position : IntVec3.Invalid;
                    }
                    if (c == IntVec3.Invalid)
                    {
                        if (InfestationLikeCellFinder.TryFindCell(out c, pawn.Map, false))
                        {
                            if (Prefs.DevMode)
                            {
                                ThingDef td = XenomorphDefOf.RRY_Filth_Slime;
                                GenSpawn.Spawn(td, c, pawn.Map);
                                Find.LetterStack.ReceiveLetter(string.Format("Lord Created"), string.Format("@: {0} ", c), LetterDefOf.NegativeEvent, c.GetFirstThing(pawn.Map, td), null, null);
                            }
                        }
                        if (pawn.CanReach(c, PathEndMode.OnCell, Danger.Deadly, true))
                        {
                            c = RCellFinder.RandomWanderDestFor(pawn, c, 3f, null, Danger.Some);
                        }
                        else
                        {
                            c = RCellFinder.RandomWanderDestFor(pawn, pawn.Position, 3f, null, Danger.Some);
                        }
                    }
                    if (c != IntVec3.Invalid)
                    {
                        LordJob newJob;
                        if (XenomorphUtil.HivelikesPresent(map))
                        {
                            newJob = new LordJob_DefendAndExpandHiveLike(false);
                        }
                        else
                        {
                            newJob = new LordJob_DefendHiveLoc(parent.Faction, c);
                        }
                        if (LordReplaceable)
                        {
                            if (!Hivelords.NullOrEmpty())
                            {
                                Hivelord = Hivelords.RandomElement();
                                SwitchToLord(Hivelord);
                                CreateNewLord(pawn, c, newJob);
                            }
                            else
                            {
                                CreateNewLord(pawn, c, newJob);
                            }
                            if (HiveLoc == IntVec3.Invalid)
                            {
                                HiveLoc = c;
                            }
                        }
                    }
                }
                else if (c == IntVec3.Invalid && (pawn.GetLord() != null && pawn.GetLord().LordJob is LordJob LordJob))
                {
                    lord = pawn.GetLord();
                    c    = LordJob.lord.Graph.StartingToil.FlagLoc;
                    if (c == IntVec3.Invalid)
                    {
                        c = LordJob.lord.CurLordToil.FlagLoc;
                    }
                }
                else if (pawn.GetLord() == null)
                {
                    if (!Hivelords.NullOrEmpty())
                    {
                        Hivelord = Hivelords.RandomElement();
                        SwitchToLord(Hivelord);
                    }
                }
                if (pawn.GetLord() != null)
                {
                    List <Pawn> list = pawn.GetLord().ownedPawns.Where(x => x.mindState.duty != null).ToList();
                    if (pawn.GetLord() != null && pawn.mindState.duty == null && !list.NullOrEmpty())
                    {
                        pawn.mindState.duty = list.RandomElement().mindState.duty;
                    }
                }
            }
        }
        public static bool TryFindGoodHiveLoc(Pawn pawn, Pawn victim, out IntVec3 c, bool AllowHiveShip = false)
        {
            Map map = pawn.Map;

            c = IntVec3.Invalid;
            bool selected = map != null?Find.Selector.SelectedObjects.Contains(pawn) && (Prefs.DevMode) : false;

            ThingDef named = victim.RaceProps.Humanlike ? XenomorphDefOf.RRY_Xenomorph_Humanoid_Cocoon : XenomorphDefOf.RRY_Xenomorph_Animal_Cocoon;

            if (AllowHiveShip)
            {
                hiveshippresent          = XenomorphUtil.HiveShipPresent(map);
                hiveshipReachable        = !XenomorphUtil.ClosestReachableHiveShip(pawn).DestroyedOrNull();
                closestreachablehiveship = XenomorphUtil.ClosestReachableHiveShip(pawn);
                if (c == IntVec3.Invalid && hiveshippresent && hiveshipReachable)
                {
                    if (Prefs.DevMode && DebugSettings.godMode)
                    {
                        Log.Message(string.Format("(c == IntVec3.Invalid && hiveshippresent && hiveshipReachable)"));
                    }
                    c = closestreachablehiveship.Position;
                    if (Prefs.DevMode && DebugSettings.godMode)
                    {
                        Log.Message(string.Format("(c == {0})", c));
                    }
                    return(true);
                }
            }

            hivelikesPresent         = XenomorphUtil.HivelikesPresent(map);
            hivelikesReachable       = !XenomorphUtil.ClosestReachableHivelike(pawn).DestroyedOrNull();
            closestReachableHivelike = XenomorphUtil.ClosestReachableHivelike(pawn);
            if ((hivelikesPresent && hivelikesReachable))
            {
                List <ThingDef_HiveLike> hivedefs = DefDatabase <ThingDef_HiveLike> .AllDefsListForReading.FindAll(x => x.Faction == pawn.Faction.def);

                if (XenomorphUtil.TotalSpawnedHivelikeCount(map) > 0)
                {
                    if (XenomorphUtil.TotalSpawnedParentHivelikeCount(map) > 0)
                    {
                        hiveThing = XenomorphUtil.TotalSpawnedParentHivelikeCount(map) > 1 ? XenomorphUtil.SpawnedParentHivelikes(map).RandomElement() : XenomorphUtil.ClosestReachableHivelike(pawn, XenomorphUtil.SpawnedParentHivelikes(map));
                        c         = hiveThing.Position;
                        if (c != IntVec3.Invalid)
                        {
                            return(true);
                        }
                    }

                    /*
                     * if (XenomorphUtil.TotalSpawnedChildHivelikeCount(map) > 0)
                     * {
                     *  hiveThing = XenomorphUtil.TotalSpawnedParentHivelikeCount(map) > 1 ? XenomorphUtil.SpawnedParentHivelikes(map).RandomElement() : XenomorphUtil.ClosestReachableHivelike(pawn, XenomorphUtil.SpawnedParentHivelikes(map));
                     *  c = hiveThing.Position;
                     *  return true;
                     * }
                     */
                }
            }

            hiveslimepresent          = XenomorphUtil.HiveSlimePresent(map);
            hiveslimeReachable        = !XenomorphUtil.ClosestReachableHiveSlime(pawn).DestroyedOrNull();
            closestreachablehiveslime = XenomorphUtil.ClosestReachableHiveSlime(pawn);
            if (c == IntVec3.Invalid && hiveslimepresent && hiveslimeReachable)
            {
                c = closestreachablehiveslime.Position;
                if (c != IntVec3.Invalid)
                {
                    return(true);
                }
            }

            eggsPresent         = XenomorphUtil.EggsPresent(map);
            eggsReachable       = !XenomorphUtil.ClosestReachableEgg(pawn).DestroyedOrNull();
            closestReachableEgg = XenomorphUtil.ClosestReachableEgg(pawn);
            if (c == IntVec3.Invalid && (eggsPresent && eggsReachable && XenomorphUtil.SpawnedEggsNeedHosts(map).Count > 0))
            {
                eggThing = XenomorphUtil.SpawnedEggsNeedHosts(map).Count > 1 ? XenomorphUtil.SpawnedEggsNeedHosts(map).RandomElement() : XenomorphUtil.ClosestReachableEggNeedsHost(pawn);
                c        = eggThing.Position;
                if (c != IntVec3.Invalid)
                {
                    return(true);
                }
            }

            cocoonsPresent         = XenomorphUtil.CocoonsPresent(map, named);
            cocoonsReachable       = !XenomorphUtil.ClosestReachableCocoon(pawn, named).DestroyedOrNull();
            closestReachableCocoon = XenomorphUtil.ClosestReachableCocoon(pawn, named);
            if (c == IntVec3.Invalid && cocoonsPresent && cocoonsReachable)
            {
                c = closestReachableCocoon.Position;
                if (c != IntVec3.Invalid)
                {
                    return(true);
                }
            }

            if (c == IntVec3.Invalid)
            {
                if (!InfestationLikeCellFinder.TryFindCell(out c, map, false))
                {
                    if (!RCellFinder.TryFindBestExitSpot(pawn, out c, TraverseMode.ByPawn))
                    {
                        return(false);
                    }
                    if (c != IntVec3.Invalid)
                    {
                        return(true);
                    }
                }
                else
                {
                    if (pawn.GetLord() != null && pawn.GetLord() is Lord lord)
                    {
                        Log.Message(string.Format("TryFindGoodHiveLoc pawn.GetLord() != null"));
                    }

                    if (pawn.mindState.duty.def != OGHiveLikeDefOf.RRY_DefendAndExpandHiveLike && pawn.mindState.duty.def != OGHiveLikeDefOf.RRY_DefendHiveLikeAggressively)
                    {
                        pawn.mindState.duty = new PawnDuty(OGHiveLikeDefOf.RRY_DefendAndExpandHiveLike, c, 40f);

                        c = RCellFinder.RandomWanderDestFor(pawn, c, 5f, null, Danger.Some);
                        return(true);
                    }
                    else
                    {
                        c = RCellFinder.RandomWanderDestFor(pawn, c, 5f, null, Danger.Some);
                        return(true);
                    }
                }
            }
            return(false);
        }