예제 #1
0
        private static bool PrepareToIngestToilsPrefix(JobDriver __instance, Toil chewToil, ref IEnumerable <Toil> __result) //TODO figure out how to turn this into a transpiler patch
        {
            Thing thing = __instance.job.targetA.Thing;

            if (RaceGenerator.TryGetMorphOfRace(__instance.pawn.def, out MorphDef def))
            {
                if (thing.def.ingestible == null)
                {
                    return(true);
                }

                FoodTypeFlags flg = thing.def.ingestible.foodType & (FoodTypeFlags.Tree | FoodTypeFlags.Plant);
                if (flg != 0)
                {
                    __result = new[]
                    {
                        ReserveFoodIfWillIngestWholeStack(__instance),
                        Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch)
                    };

                    return(false);
                }
            }
            else if (__instance.pawn.IsSapientFormerHuman())
            {
                if (thing.def.ingestible == null)
                {
                    return(true);
                }
            }

            return(true);
        }
            /// <summary>Gets the total weight.</summary>
            /// the higher the weight the more likely this interaction is going to be picked
            /// <param name="pawn">The pawn.</param>
            /// <returns></returns>
            public float GetTotalWeight(Pawn pawn)
            {
                IEnumerable <HediffDef> hediffs = pawn.health.hediffSet.hediffs.Select(h => h.def);

                float total       = 0;
                var   hasMutation = false;

                foreach (HediffDef hediffDef in hediffs)
                {
                    if (mutationWeights.TryGetValue(hediffDef, out float v))
                    {
                        hasMutation = true;
                        total      += v;
                    }
                }

                bool isMorph = RaceGenerator.TryGetMorphOfRace(pawn.def, out MorphDef morph);

                if (isMorph)
                {
                    isMorph = morphWeights.TryGetValue(morph, out float w);
                    total  += w;
                }

                if (requiresBoth && !isMorph && !hasMutation)
                {
                    total = 0;
                }

                return(total);
            }
예제 #3
0
        private void FisExplicitRaceGraphics()
        {
            //work around for the portraits of explicit hybrid races not updating correctly after load for some reason
            //should be removed when that is fixed

            MorphDef morph;

            if (RaceGenerator.TryGetMorphOfRace(Pawn.def, out morph))
            {
                if (Pawn.def == morph.ExplicitHybridRace)
                {
                    Pawn.RefreshGraphics();
                }
            }
        }
예제 #4
0
        private static void ApplyMorphFoodThoughts(Pawn ingester, Thing foodSource, List <ThoughtDef> foodThoughts)
        {
            if (RaceGenerator.TryGetMorphOfRace(ingester.def, out MorphDef morphDef))
            {
                AteThought cannibalThought = morphDef.raceSettings?.thoughtSettings?.ateAnimalThought;
                if (cannibalThought == null)
                {
                    return;
                }
                if (ingester?.story?.traits == null)
                {
                    return;
                }
                bool cannibal = ingester.story.traits.HasTrait(TraitDefOf.Cannibal);

                if (foodSource.def == morphDef.race.race.meatDef && !cannibal)
                {
                    foodThoughts.Add(cannibalThought.thought);
                    return;
                }

                ThingDef comp = foodSource.TryGetComp <CompIngredients>()
                                ?.ingredients?.FirstOrDefault(def => def == morphDef.race.race.meatDef);
                if (comp != null && !cannibal)
                {
                    foodThoughts.Add(cannibalThought.ingredientThought);
                }
            }
            else
            {
                var fHStatus = ingester.GetQuantizedSapienceLevel();
                if (fHStatus == null || fHStatus == SapienceLevel.PermanentlyFeral)
                {
                    return;
                }

                ThoughtDef thought = GetCannibalThought(ingester, foodSource);
                if (thought != null)
                {
                    foodThoughts.Add(thought);
                }
            }
        }
예제 #5
0
        static void Main(string[] args)
        {
            bool showHelp  = false;
            int  numRacers = 0;
            int  numLanes  = 0;
            bool verbose   = false;

            var p = new OptionSet()
            {
                { "r=|racers=", "The number of racers.", (int r) => numRacers = r },
                { "l=|lanes=", "The number of lanes.", (int l) => numLanes = l },
                { "v|verbose", "If present, outputs details of every step as lane assignments are made.",
                  v => verbose = v != null },
                { "h|help", "Show this message and exit", h => showHelp = h != null }
            };

            List <string> extra;

            try
            {
                extra = p.Parse(args);
            }
            catch (OptionException ex)
            {
                Console.Write("ChaoticRotation: ");
                Console.WriteLine(ex.Message);
                Console.WriteLine("Try 'ChaoticRotation --help' for more information.");
                return;
            }

            if (numRacers <= 0)
            {
                Console.WriteLine("Number of racers must be a positive integer.");
                showHelp = true;
            }

            if (numLanes <= 0)
            {
                Console.WriteLine("Number of lanes must be a positive integer.");
                showHelp = true;
            }

            if (showHelp)
            {
                Console.WriteLine();
                ShowHelp(p);
                return;
            }

            EventLogger logger = null;

            if (verbose)
            {
                logger = new EventLogger();
                logger.LogMessageGenerated += Logger_LogMessageGenerated;
            }
            RaceGenerator rg = new RaceGenerator(logger);

            //try
            //{
            int[,] races = rg.Solve(numRacers, numLanes);
            int numRaces = rg.GetNumRaces(numRacers, numLanes);

            Console.WriteLine();
            Console.WriteLine("Minimum number of steps possible: {0}", rg.MinSteps);
            Console.WriteLine("Number of steps actually taken:   {0}", rg.ActualSteps);
            Console.WriteLine("Number of backtracks:             {0}", rg.Backtracks);
            Console.WriteLine();

            PrintRaces(races, numRaces, numLanes);
            Console.WriteLine();
            PrintRacers(races, numRaces, numLanes, numRacers);
            //}
            //catch (Exception ex)
            //{
            //    Console.WriteLine("Exception Caught: {0}", ex.Message);
            //}
        }