예제 #1
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);
        }