Example #1
0
        protected override GrammarRequest GenerateGrammarRequest()
        {
            GrammarRequest result = base.GenerateGrammarRequest();

            if (subjectPawn != null)
            {
                result.Rules.AddRange(GrammarUtility.RulesForPawn("SUBJECT", subjectPawn, result.Constants));
            }
            else if (subjectThing != null)
            {
                result.Rules.AddRange(GrammarUtility.RulesForDef("SUBJECT", subjectThing));
            }
            result.Includes.Add(transitionDef);
            if (initiator != null)
            {
                result.Rules.AddRange(GrammarUtility.RulesForPawn("INITIATOR", initiator, result.Constants));
            }
            if (culpritHediffDef != null)
            {
                result.Rules.AddRange(GrammarUtility.RulesForHediffDef("CULPRITHEDIFF", culpritHediffDef, culpritHediffTargetPart));
            }
            if (culpritHediffTargetPart != null)
            {
                result.Rules.AddRange(GrammarUtility.RulesForBodyPartRecord("CULPRITHEDIFF_target", culpritHediffTargetPart));
            }
            if (culpritTargetPart != null)
            {
                result.Rules.AddRange(GrammarUtility.RulesForBodyPartRecord("CULPRITHEDIFF_originaltarget", culpritTargetPart));
            }
            return(result);
        }
        /// <summary>
        /// create the main log text
        /// </summary>
        /// <param name="pov">The pov.</param>
        /// <param name="forceLog">if set to <c>true</c> [force log].</param>
        /// <returns></returns>
        protected override string ToGameStringFromPOV_Worker(Thing pov, bool forceLog)
        {
            Assert(pov == _pawn, "pov == _pawn");

            Rand.PushState(logID); // Does not need a MP-safe seed.
            try
            {
                GrammarRequest grammarRequest = GenerateGrammarRequest();

                RulePackDef mutationRulePack = (_mutationDef as MutationDef)?.mutationLogRulePack;

                if (mutationRulePack != null)
                {
                    grammarRequest.Includes.Add(mutationRulePack);
                }
                else
                {
                    grammarRequest.Includes.Add(PMRulePackDefOf.GetDefaultPackForMutation(_mutationDef));
                    grammarRequest.Rules.Add(new Rule_String("DATE", GenDate.DateFullStringAt(ticksAbs, Vector2.zero)));
                }
                AddCustomRules(grammarRequest.Rules);

                IEnumerable <Rule> pawnR     = GrammarUtility.RulesForPawn(PAWN_IDENTIFIER, _pawn, grammarRequest.Constants);
                BodyPartRecord     partR     = BodyDefOf.Human.AllParts.Where(r => _mutatedRecords.Contains(r.def)).RandomElement();
                IEnumerable <Rule> partRules = GrammarUtility.RulesForBodyPartRecord(PART_LABEL, partR);
                IEnumerable <Rule> mutR      = GrammarUtility.RulesForHediffDef(MUTATION_IDENTIFIER, _mutationDef, partR);

                // Add the rules.
                grammarRequest.Rules.AddRange(pawnR);
                grammarRequest.Rules.AddRange(mutR);
                grammarRequest.Rules.AddRange(partRules);
                return(GrammarResolver.Resolve(RP_ROOT_RULE, grammarRequest, "mutation log", forceLog));
            }
            catch (Exception exception)
            {
                Log.Error($"encountered {exception.GetType().Name} exception while generating string for mutation log\n\t{exception}");
            }
            finally
            {
                Rand.PopState(); // Make sure to always pop rand.
            }

            return(_mutationDef.LabelCap); //TODO generate string
        }