Example #1
0
 public void BreadthFirstTraverseWork(Region root, RegionEntryPredicate entryCondition, RegionProcessor regionProcessor, int maxRegions, RegionType traversableRegionTypes)
 {
     if ((root.type & traversableRegionTypes) == RegionType.None)
     {
         return;
     }
     ProfilerThreadCheck.BeginSample("BreadthFirstTraversal");
     this.closedIndex += 1u;
     this.open.Clear();
     this.numRegionsProcessed = 0;
     this.QueueNewOpenRegion(root);
     while (this.open.Count > 0)
     {
         Region region = this.open.Dequeue();
         if (DebugViewSettings.drawRegionTraversal)
         {
             region.Debug_Notify_Traversed();
         }
         ProfilerThreadCheck.BeginSample("regionProcessor");
         if (regionProcessor != null && regionProcessor(region))
         {
             this.FinalizeSearch();
             ProfilerThreadCheck.EndSample();
             ProfilerThreadCheck.EndSample();
             return;
         }
         ProfilerThreadCheck.EndSample();
         this.numRegionsProcessed++;
         if (this.numRegionsProcessed >= maxRegions)
         {
             this.FinalizeSearch();
             ProfilerThreadCheck.EndSample();
             return;
         }
         for (int i = 0; i < region.links.Count; i++)
         {
             RegionLink regionLink = region.links[i];
             for (int j = 0; j < 2; j++)
             {
                 Region region2 = regionLink.regions[j];
                 if (region2 != null && region2.closedIndex[this.closedArrayPos] != this.closedIndex && (region2.type & traversableRegionTypes) != RegionType.None && (entryCondition == null || entryCondition(region, region2)))
                 {
                     this.QueueNewOpenRegion(region2);
                 }
             }
         }
     }
     this.FinalizeSearch();
     ProfilerThreadCheck.EndSample();
 }
Example #2
0
 private static void GenerateGearFor(Pawn pawn, PawnGenerationRequest request)
 {
     ProfilerThreadCheck.BeginSample("GenerateGearFor");
     ProfilerThreadCheck.BeginSample("GenerateStartingApparelFor");
     PawnApparelGenerator.GenerateStartingApparelFor(pawn, request);
     ProfilerThreadCheck.EndSample();
     ProfilerThreadCheck.BeginSample("TryGenerateWeaponFor");
     PawnWeaponGenerator.TryGenerateWeaponFor(pawn);
     ProfilerThreadCheck.EndSample();
     ProfilerThreadCheck.BeginSample("GenerateInventoryFor");
     PawnInventoryGenerator.GenerateInventoryFor(pawn, request);
     ProfilerThreadCheck.EndSample();
     ProfilerThreadCheck.EndSample();
 }
Example #3
0
 public static void CanGetThoughtPostfix(ThoughtDef def, SituationalThoughtHandler __instance, ref bool __result)
 {
     if (__result)
     {
         try
         {
             Need_Soul soul;
             if (HarmonyPatches.HasSoulTraitNullyfyingTraits(def, __instance.pawn, out soul))
             {
                 __result = false;
                 return;
             }
             ThoughtDefCorruption Tdef = def as ThoughtDefCorruption;
             if (Tdef != null)
             {
                 if (IsAutomaton(__instance.pawn))
                 {
                     if (Tdef.IsAutomatonThought)
                     {
                         return;
                     }
                     else
                     {
                         __result = false;
                         return;
                     }
                 }
                 if (!Tdef.requiredSoulTraits.NullOrEmpty())
                 {
                     for (int i = 0; i < soul.SoulTraits.Count; i++)
                     {
                         if (!Tdef.requiredSoulTraits.Contains(soul.SoulTraits[i].SDef))
                         {
                             __result = false;
                         }
                     }
                 }
             }
         }
         finally
         {
             ProfilerThreadCheck.EndSample();
         }
     }
 }
        public bool CanGetThought(ThoughtDef def)
        {
            ProfilerThreadCheck.BeginSample("CanGetThought()");
            try
            {
                if (this.npawn.MentalState != null && this.tpawn.MentalStateDef.blockNormalThoughts && !def.validWhileInMentalState && !def.IsSocial)
                {
                    bool result = false;
                    return(result);
                }

                if (def.nullifyingTraits != null)
                {
                    for (int i = 0; i < def.nullifyingTraits.Count; i++)
                    {
                        if (this.tpawn.story.traits.HasTrait(def.nullifyingTraits[i]))
                        {
                            bool result = false;
                            return(result);
                        }
                    }
                }
                if (def.requiredTraits != null)
                {
                    for (int j = 0; j < def.requiredTraits.Count; j++)
                    {
                        if (!this.tpawn.story.traits.HasTrait(def.requiredTraits[j]))
                        {
                            if (def != null && tpawn != null)
                            {
                                return(HasSoulTraitRequirements(def, tpawn));
                            }
                            else
                            {
                                return(false);
                            }
                        }
                        if (def.RequiresSpecificTraitsDegree && def.requiredTraitsDegree != this.tpawn.story.traits.DegreeOfTrait(def.requiredTraits[j]))
                        {
                            bool result = false;
                            return(result);
                        }
                    }
                }

                if (def.nullifiedIfNotColonist && !this.tpawn.IsColonist)
                {
                    bool result = false;
                    return(result);
                }
                if (ThoughtUtility.IsSituationalThoughtNullifiedByHediffs(def, this.tpawn))
                {
                    bool result = false;
                    return(result);
                }
                if (ThoughtUtility.IsThoughtNullifiedByOwnTales(def, this.tpawn))
                {
                    bool result = false;
                    return(result);
                }
                if (tpawn == null)
                {
                    Log.Message("No tpawn");
                }
                if (def == null)
                {
                    Log.Message("No Def");
                }

                if (HasSoulTraitNullyfyingTraits(def, tpawn))
                {
                    return(false);
                }
            }
            finally
            {
                ProfilerThreadCheck.EndSample();
            }

            if (IsAutomaton(this.tpawn))
            {
                ThoughtDefAutomaton Tdef = new ThoughtDefAutomaton();
                if ((Tdef = def as ThoughtDefAutomaton) != null && Tdef.IsAutomatonThought)
                {
                    return(true);
                }

                return(false);
            }

            return(true);
        }
Example #5
0
        public static void NukeEverything(Game game)
        {
            ProfilerThreadCheck.BeginSample("CarnivaleNuke");

            var facList = game.World.factionManager.AllFactionsListForReading;

            for (int i = facList.Count - 1; i > 0; i--)
            {
                var fac = facList[i];
                if (fac.IsCarnival())
                {
                    foreach (var map in game.Maps)
                    {
                        var lord = map.lordManager.lords.FirstOrDefault(l => l.LordJob is LordJob_EntertainColony);

                        if (lord != null)
                        {
                            map.lordManager.RemoveLord(lord);
                        }

                        foreach (var pawn in map.mapPawns.AllPawns)
                        {
                            if (fac == pawn.Faction || pawn.IsCarny(false))
                            {
                                pawn.DeSpawn();
                                game.World.worldPawns.PassToWorld(pawn, PawnDiscardDecideMode.Discard);
                            }
                            else if (pawn.needs != null && pawn.needs.mood != null)
                            {
                                pawn.needs.mood.thoughts.memories.RemoveMemoriesOfDef(_DefOf.Thought_AttendedShow);
                                pawn.needs.mood.thoughts.memories.RemoveMemoriesOfDef(_DefOf.Thought_MissCarnival);
                            }
                        }

                        foreach (var thing in map.listerThings.AllThings.Where(t => fac == t.Faction))
                        {
                            thing.Destroy();
                        }
                    }

                    fac.RemoveAllRelations();
                    facList.RemoveAt(i);
                }
            }

            List <Pawn> tmpPawnsToRemove = new List <Pawn>();

            foreach (var pawn in game.World.worldPawns.AllPawnsAliveOrDead)
            {
                if (pawn.IsCarny(false))
                {
                    tmpPawnsToRemove.Add(pawn);
                }
                else if (pawn.needs != null && pawn.needs.mood != null)
                {
                    pawn.needs.mood.thoughts.memories.RemoveMemoriesOfDef(_DefOf.Thought_AttendedShow);
                    pawn.needs.mood.thoughts.memories.RemoveMemoriesOfDef(_DefOf.Thought_MissCarnival);
                }
            }

            foreach (var pawn in tmpPawnsToRemove)
            {
                game.World.worldPawns.RemovePawn(pawn);
            }

            foreach (var map in game.Maps)
            {
                var info = map.GetComponent <CarnivalInfo>();

                if (info != null)
                {
                    info.Cleanup();
                    map.components.Remove(info);
                }

                map.pawnDestinationManager = new PawnDestinationManager();
            }

            game.storyteller.incidentQueue.Clear();

            string fileName;

            if (game.Info.permadeathMode)
            {
                fileName = game.Info.permadeathModeUniqueName;
            }
            else
            {
                fileName = game.AnyPlayerHomeMap.info.parent.LabelCap;
            }

            GameDataSaveLoader.SaveGame(fileName + "_Nuked");

            ProfilerThreadCheck.EndSample();
        }
        public static Thing ClosestThingReachable_JT(IntVec3 root, ThingRequest thingReq, PathEndMode peMode, TraverseParms traverseParams, float maxDistance = 9999f, Predicate <Thing> validator = null, IEnumerable <Thing> customGlobalSearchSet = null, int searchRegionsMax = -1, bool forceGlobalSearch = false)
        {
            //customGlobalSearchSet in context of hauling is list of things to be hauled
            //forceGlobalSearch is true when customGlobalSearchSet is not null
            //searchRegionMax is only used for cleaning
            ProfilerThreadCheck.BeginSample("ClosestThingReachable");
            //Guessing if searchRegionsMax is > 0, customGlobalSearchSet is not suppose to be used.
            if (searchRegionsMax > 0 && customGlobalSearchSet != null && !forceGlobalSearch)
            {
                Log.ErrorOnce("searchRegionsMax > 0 && customGlobalSearchSet != null && !forceGlobalSearch. customGlobalSearchSet will never be used.", 634984);
            }
            //There is no null check for thingReq, always not null?
            //if thingReq group == nothing ||
            //if there is thingReq and customGlobalSearchSet is null and there are things matching thingReq
            if (EarlyOutSearch_JT(root, thingReq, customGlobalSearchSet))
            {
                ProfilerThreadCheck.EndSample();
                return(null);
            }
            //Use either searchRegionsMax or customGlobalSearchSet
            //We're interested in thingReq.group == HaulableEver, HaulableAlways, HaulableEverOrMinifiable
            //This means customGlobalSearch has to have something (when there are such items on map) --> correct
            //Actual stuff begins?
            Thing thing = null;

            //IsUndefined == singleDef == null && thingReq group == Undefined
            if (!thingReq.IsUndefined)
            {
                //The debug bellow only resuted in group == Pawn, 7 times with 3 pawns all set only to haul, perhaps dogs loving?
                //Therefore probably ignore this if
                //Log.Message("First if was called. " + thingReq.group.ToString());
                //Hauling: searchRegionsMax should be -1 --> maxRegions = 30
                int maxRegions = (searchRegionsMax <= 0) ? 30 : searchRegionsMax;
                thing = GenClosest.RegionwiseBFSWorker(root, thingReq, peMode, traverseParams, validator, null, 0, maxRegions, maxDistance);
            }
            if (thing == null && (searchRegionsMax < 0 || forceGlobalSearch))
            {
                //validator = (Thing t) => !t.IsForbidden(pawn) && scanner.HasJobOnThing(pawn, t);
                //Debug bellow gives thingReq group to be Undefined, skips first
                //Log.Message("First if resulted in null " + thingReq.group.ToString());
                Predicate <Thing>   validator2 = (Thing t) => root.CanReach(t, peMode, traverseParams) && (validator == null || validator(t));
                IEnumerable <Thing> searchSet  = customGlobalSearchSet ?? Find.ListerThings.ThingsMatching(thingReq);
                //Main start of my code
                List <Thing> degrade   = new List <Thing>();
                List <Thing> undegrade = new List <Thing>();
                //Seperate into degrade or not
                foreach (Thing t in searchSet)
                {
                    if (t.GetStatValue(StatDefOf.DeteriorationRate) > 0)
                    {
                        degrade.Add(t);
                    }
                    else
                    {
                        undegrade.Add(t);
                    }
                }
                //Loop through all haul areas in order
                foreach (Area a in AreaFinder.getHaulAreas())
                {
                    //Check if got degradable item
                    thing = GenClosest.ClosestThing_Global(root, AreaFinder.searcher(a, degrade), maxDistance, validator2);
                    if (thing != null)
                    {
                        break;
                    }

                    //Check if got undegradable item
                    thing = GenClosest.ClosestThing_Global(root, AreaFinder.searcher(a, undegrade), maxDistance, validator2);
                    if (thing != null)
                    {
                        break;
                    }
                }
                if (thing == null)
                {
                    thing = GenClosest.ClosestThing_Global(root, degrade, maxDistance, validator2);
                    if (thing == null)
                    {
                        thing = GenClosest.ClosestThing_Global(root, undegrade, maxDistance, validator2);
                    }
                }

                /* old 50 cell code
                 *              thing = GenClosest.ClosestThing_Global(root, degrade, 50f, validator2); //If there is degradable with 50 cells
                 * if (thing == null)
                 * {
                 *  thing = GenClosest.ClosestThing_Global(root, undegrade, 50f, validator2);//If there is undegradable with 50 cells
                 *  if (thing == null)
                 *  {
                 *      thing = GenClosest.ClosestThing_Global(root, degrade, maxDistance, validator2); //If there is degradable
                 *      if (thing == null)
                 *      {
                 *          thing = GenClosest.ClosestThing_Global(root, undegrade, maxDistance, validator2); //If there is undegradable
                 *      }
                 *  }
                 * }
                 */
                //Main end of my code
            }

            /*
             * if (thing != null)
             * {
             *  Log.Message(thing.def.defName);
             * }
             * else {
             *  Log.Message("Resulted in null");
             * }*/
            ProfilerThreadCheck.EndSample();
            return(thing);
        }