public static string RandomSeedString() { GrammarRequest request = default(GrammarRequest); request.Includes.Add(RulePackDefOf.SeedGenerator); return(GrammarResolver.Resolve("r_seed", request).ToLower()); }
protected virtual string ToGameStringFromPOV_Worker(Thing pov, bool forceLog) { string rootKeyword = "r_logentry"; GrammarRequest request = this.GenerateGrammarRequest(); return(GrammarResolver.Resolve(rootKeyword, request, null, forceLog)); }
public static string History(Faction subject = null, Faction victim = null, Settlement town = null, Pawn pawn = null, string towndestroyed = null) { GrammarRequest request = new GrammarRequest(); request.Includes.Add(EndGameDefOf.FE_History); if (pawn != null) { request.Rules.AddRange(GrammarUtility.RulesForPawn("Pawn", pawn)); return(GrammarResolver.Resolve("r_history_pawn", request, null, false, null)); } if (town != null) { request.Rules.AddRange(RulesForTown("AffectedTown", town)); return(GrammarResolver.Resolve("r_history_town", request, null, false, null)); } if (subject != null && victim != null) { request.Rules.AddRange(GrammarUtility.RulesForFaction("FACTION1", subject)); request.Rules.AddRange(GrammarUtility.RulesForFaction("FACTION2", victim)); return(GrammarResolver.Resolve("r_history_faction", request, null, false, null)); } if (subject != null) { request.Rules.AddRange(GrammarUtility.RulesForFaction("FACTION1", subject)); request.Rules.AddRange(RulesForString("FACTION2", NameGenerator.GenerateName(subject.def.factionNameMaker, Find.FactionManager.AllFactionsVisible.Select(fac => fac.Name)))); return(GrammarResolver.Resolve("r_history_factiondead", request, null, false, null)); } if (towndestroyed != null) { request.Rules.AddRange(RulesForString("AffectedTown", towndestroyed)); return(GrammarResolver.Resolve("r_history_townDestroyed", request, null, false, null)); } return(GrammarResolver.Resolve("r_history_generic", request, null, false, null)); }
protected override string ToGameStringFromPOV_Worker(Thing pov, bool forceLog) { string result; if (this.initiator == null || this.recipient == null) { Log.ErrorOnce("PlayLogEntry_Interaction has a null pawn reference.", 34422, false); result = "[" + this.intDef.label + " error: null pawn reference]"; } else { Rand.PushState(); Rand.Seed = this.logID; GrammarRequest request = base.GenerateGrammarRequest(); string text; if (pov == this.initiator) { request.IncludesBare.Add(this.intDef.logRulesInitiator); request.Rules.AddRange(GrammarUtility.RulesForPawn("ME", this.initiator, request.Constants)); request.Rules.AddRange(GrammarUtility.RulesForPawn("OTHER", this.recipient, request.Constants)); request.Rules.AddRange(GrammarUtility.RulesForPawn("INITIATOR", this.initiator, request.Constants)); request.Rules.AddRange(GrammarUtility.RulesForPawn("RECIPIENT", this.recipient, request.Constants)); text = GrammarResolver.Resolve("r_logentry", request, "interaction from initiator", forceLog); } else if (pov == this.recipient) { if (this.intDef.logRulesRecipient != null) { request.IncludesBare.Add(this.intDef.logRulesRecipient); } else { request.IncludesBare.Add(this.intDef.logRulesInitiator); } request.Rules.AddRange(GrammarUtility.RulesForPawn("ME", this.recipient, request.Constants)); request.Rules.AddRange(GrammarUtility.RulesForPawn("OTHER", this.initiator, request.Constants)); request.Rules.AddRange(GrammarUtility.RulesForPawn("INITIATOR", this.initiator, request.Constants)); request.Rules.AddRange(GrammarUtility.RulesForPawn("RECIPIENT", this.recipient, request.Constants)); text = GrammarResolver.Resolve("r_logentry", request, "interaction from recipient", forceLog); } else { Log.ErrorOnce("Cannot display PlayLogEntry_Interaction from POV who isn't initiator or recipient.", 51251, false); text = this.ToString(); } if (this.extraSentencePacks != null) { for (int i = 0; i < this.extraSentencePacks.Count; i++) { request.Clear(); request.Includes.Add(this.extraSentencePacks[i]); request.Rules.AddRange(GrammarUtility.RulesForPawn("INITIATOR", this.initiator, request.Constants)); request.Rules.AddRange(GrammarUtility.RulesForPawn("RECIPIENT", this.recipient, request.Constants)); text = text + " " + GrammarResolver.Resolve(this.extraSentencePacks[i].RulesPlusIncludes[0].keyword, request, "extraSentencePack", forceLog); } } Rand.PopState(); result = text; } return result; }
public void TryThrowTaunt(RulePackDef rulePack, Pawn pawn) { if (!AllowThrowTauntNow(pawn)) { return; } string taunt = GrammarResolver.Resolve(rulePack.Rules[0].keyword, rulePack.Rules); if (taunt.NullOrEmpty()) { Log.Warning("CE tried throwing invalid taunt for " + pawn.ToString()); } else { MoteMaker.ThrowText(pawn.Position.ToVector3Shifted(), pawn.Map, taunt); } var curTick = Find.TickManager.TicksGame; if (!tauntTickTracker.ContainsKey(pawn)) { tauntTickTracker.Add(pawn, curTick); } else { tauntTickTracker[pawn] = curTick; } }
public static string WarEvent(Faction raider = null, Faction victim = null, Settlement town = null, bool fail = false) { GrammarRequest request = new GrammarRequest(); if (victim == null && town == null) { request.Includes.Add(EndGameDefOf.FE_WarEvent_ArtifactCache); request.Rules.AddRange(GrammarUtility.RulesForFaction("FACTION1", raider)); return(GrammarResolver.Resolve("FE_ArtifactCache", request, null, false, null)); } if (town == null) { request.Includes.Add(EndGameDefOf.FE_WarEvent_Raid); request.Rules.AddRange(GrammarUtility.RulesForFaction("FACTION1", raider)); request.Rules.AddRange(GrammarUtility.RulesForFaction("FACTION2", victim)); return(GrammarResolver.Resolve("FE_Sabotage", request, null, false, null)); } if (fail) { request.Includes.Add(EndGameDefOf.FE_WarEvent_Raid); request.Rules.AddRange(GrammarUtility.RulesForFaction("FACTION1", raider)); request.Rules.AddRange(GrammarUtility.RulesForFaction("FACTION2", victim)); request.Rules.AddRange(RulesForTown("AffectedTown", town)); return(GrammarResolver.Resolve("FE_RaidFail", request, null, false, null)); } request.Includes.Add(EndGameDefOf.FE_WarEvent_Raid); request.Rules.AddRange(GrammarUtility.RulesForFaction("FACTION1", raider)); request.Rules.AddRange(GrammarUtility.RulesForFaction("FACTION2", victim)); request.Rules.AddRange(RulesForTown("AffectedTown", town)); return(GrammarResolver.Resolve("FE_RaidSuccess", request, null, false, null)); }
public override void Initialize(CompProperties props) { base.Initialize(props); GrammarRequest request = default(GrammarRequest); request.Includes.Add(Props.nameMaker); name = GenText.CapitalizeAsTitle(GrammarResolver.Resolve("r_weapon_name", request)); }
public static string AdjustedFor(this string text, Pawn p, string pawnSymbol = "PAWN") { GrammarRequest request = default(GrammarRequest); request.Includes.Add(RulePackDefOf.DynamicWrapper); request.Rules.Add(new Rule_String("RULE", text)); request.Rules.AddRange(GrammarUtility.RulesForPawn(pawnSymbol, p, null)); return(GrammarResolver.Resolve("r_root", request, null, false, null)); }
public static string RandomSeedString() { return(GrammarResolver.Resolve("r_seed", new GrammarRequest { Includes = { RulePackDefOf.SeedGenerator } }, null, false, null).ToLower()); }
public static string GenerateName(RulePackDef rootPack, Predicate <string> validator = null, bool appendNumberIfNameUsed = false, string rootKeyword = null, string testPawnNameSymbol = null) { GrammarRequest grammarRequest = default(GrammarRequest); grammarRequest.Includes.Add(rootPack); if (testPawnNameSymbol != null) { grammarRequest.Rules.Add(new Rule_String("ANYPAWN_nameDef", testPawnNameSymbol)); grammarRequest.Rules.Add(new Rule_String("ANYPAWN_nameIndef", testPawnNameSymbol)); } string text = (rootKeyword == null) ? rootPack.FirstRuleKeyword : rootKeyword; string text2 = (rootKeyword == null) ? rootPack.FirstUntranslatedRuleKeyword : rootKeyword; if (appendNumberIfNameUsed) { string text3; GrammarRequest request; string text4; for (int i = 0; i < 100; i++) { for (int j = 0; j < 5; j++) { text3 = text; request = grammarRequest; text4 = text2; string text5 = GenText.ToTitleCaseSmart(GrammarResolver.Resolve(text3, request, null, false, text4)); if (i != 0) { text5 = text5 + " " + (i + 1); } if (validator == null || validator(text5)) { return(text5); } } } text4 = text; request = grammarRequest; text3 = text2; return(GenText.ToTitleCaseSmart(GrammarResolver.Resolve(text4, request, null, false, text3))); } for (int k = 0; k < 150; k++) { string text3 = text; GrammarRequest request = grammarRequest; string text4 = text2; string text6 = GenText.ToTitleCaseSmart(GrammarResolver.Resolve(text3, request, null, false, text4)); if (validator == null || validator(text6)) { return(text6); } } Log.Error("Could not get new name (rule pack: " + rootPack + ")", false); return("Errorname"); }
public override string ToGameStringFromPOV(Thing pov) { if (this.initiator == null || this.recipient == null) { Log.ErrorOnce("PlayLogEntry_Interaction has a null pawn reference.", 34422); return("[" + this.intDef.label + " error: null pawn reference]"); } Rand.PushState(); Rand.Seed = this.randSeed; GrammarRequest request = default(GrammarRequest); string text; if (pov == this.initiator) { request.Rules.AddRange(this.intDef.logRulesInitiator.Rules); request.Rules.AddRange(GrammarUtility.RulesForPawn("me", this.initiator, request.Constants)); request.Rules.AddRange(GrammarUtility.RulesForPawn("other", this.recipient, request.Constants)); text = GrammarResolver.Resolve("logentry", request, "interaction from initiator", false); } else if (pov == this.recipient) { if (this.intDef.logRulesRecipient != null) { request.Rules.AddRange(this.intDef.logRulesRecipient.Rules); } else { request.Rules.AddRange(this.intDef.logRulesInitiator.Rules); } request.Rules.AddRange(GrammarUtility.RulesForPawn("me", this.recipient, request.Constants)); request.Rules.AddRange(GrammarUtility.RulesForPawn("other", this.initiator, request.Constants)); text = GrammarResolver.Resolve("logentry", request, "interaction from recipient", false); } else { Log.ErrorOnce("Cannot display PlayLogEntry_Interaction from POV who isn't initiator or recipient.", 51251); text = this.ToString(); } if (this.extraSentencePacks != null) { for (int i = 0; i < this.extraSentencePacks.Count; i++) { request.Clear(); request.Includes.Add(this.extraSentencePacks[i]); request.Rules.AddRange(GrammarUtility.RulesForPawn("initiator", this.initiator, request.Constants)); request.Rules.AddRange(GrammarUtility.RulesForPawn("recipient", this.recipient, request.Constants)); text = text + " " + GrammarResolver.Resolve(this.extraSentencePacks[i].RulesPlusIncludes[0].keyword, request, "extraSentencePack", false); } } Rand.PopState(); return(text); }
protected override string ToGameStringFromPOV_Worker(Thing pov, bool forceLog) { if (initiator == null || recipient == null) { Log.ErrorOnce("PlayLogEntry_Interaction has a null pawn reference.", 34422); return("[" + intDef.label + " error: null pawn reference]"); } Rand.PushState(); Rand.Seed = logID; GrammarRequest request = base.GenerateGrammarRequest(); string text; if (pov == initiator) { request.IncludesBare.Add(intDef.logRulesInitiator); request.Rules.AddRange(GrammarUtility.RulesForPawn("INITIATOR", initiator, request.Constants)); request.Rules.AddRange(GrammarUtility.RulesForPawn("RECIPIENT", recipient, request.Constants)); text = GrammarResolver.Resolve("r_logentry", request, "interaction from initiator", forceLog); } else if (pov == recipient) { if (intDef.logRulesRecipient != null) { request.IncludesBare.Add(intDef.logRulesRecipient); } else { request.IncludesBare.Add(intDef.logRulesInitiator); } request.Rules.AddRange(GrammarUtility.RulesForPawn("INITIATOR", initiator, request.Constants)); request.Rules.AddRange(GrammarUtility.RulesForPawn("RECIPIENT", recipient, request.Constants)); text = GrammarResolver.Resolve("r_logentry", request, "interaction from recipient", forceLog); } else { Log.ErrorOnce("Cannot display PlayLogEntry_Interaction from POV who isn't initiator or recipient.", 51251); text = ToString(); } if (extraSentencePacks != null) { for (int i = 0; i < extraSentencePacks.Count; i++) { request.Clear(); request.Includes.Add(extraSentencePacks[i]); request.Rules.AddRange(GrammarUtility.RulesForPawn("INITIATOR", initiator, request.Constants)); request.Rules.AddRange(GrammarUtility.RulesForPawn("RECIPIENT", recipient, request.Constants)); text = text + " " + GrammarResolver.Resolve(extraSentencePacks[i].FirstRuleKeyword, request, "extraSentencePack", forceLog, extraSentencePacks[i].FirstUntranslatedRuleKeyword); } } Rand.PopState(); return(text); }
public DiaNode AnnualExpoDialogueNode(Pawn pawn, Caravan caravan, EventDef eventDef, Faction host) { GrammarRequest request = default; request.Includes.Add(RulePackDefOf.ArtDescriptionUtility_Global); string flavourText = GrammarResolver.Resolve("artextra_clause", request); DiaNode dialogueGreeting = new DiaNode(text: "MFI_AnnualExpoDialogueIntroduction".Translate(eventDef.theme, FirstCharacterToLower(flavourText))); foreach (DiaOption option in DialogueOptions(pawn: pawn, caravan, eventDef, host)) { dialogueGreeting.options.Add(item: option); } return(dialogueGreeting); }
public static string GenerateName(RulePackDef rootPack, Predicate <string> validator = null, bool appendNumberIfNameUsed = false, string rootKeyword = null, string testPawnNameSymbol = null) { GrammarRequest request = default(GrammarRequest); request.Includes.Add(rootPack); if (testPawnNameSymbol != null) { request.Rules.Add(new Rule_String("ANYPAWN_nameDef", testPawnNameSymbol)); request.Rules.Add(new Rule_String("ANYPAWN_nameIndef", testPawnNameSymbol)); } rootKeyword = ((rootKeyword == null) ? rootPack.RulesPlusIncludes[0].keyword : rootKeyword); string result; if (appendNumberIfNameUsed) { for (int i = 0; i < 100; i++) { for (int j = 0; j < 5; j++) { string text = GenText.ToTitleCaseSmart(GrammarResolver.Resolve(rootKeyword, request, null, false)); if (i != 0) { text = text + " " + (i + 1); } if (validator == null || validator(text)) { return(text); } } } result = GenText.ToTitleCaseSmart(GrammarResolver.Resolve(rootKeyword, request, null, false)); } else { for (int k = 0; k < 150; k++) { string text2 = GenText.ToTitleCaseSmart(GrammarResolver.Resolve(rootKeyword, request, null, false)); if (validator == null || validator(text2)) { return(text2); } } Log.Error("Could not get new name (rule pack: " + rootPack + ")", false); result = "Errorname"; } return(result); }
public override string ToGameStringFromPOV(Thing pov) { Rand.PushState(); Rand.Seed = base.randSeed; GrammarRequest request = default(GrammarRequest); request.Includes.Add(RulePackDefOf.Combat_ExplosionImpact); if (this.initiatorPawn != null) { request.Rules.AddRange(GrammarUtility.RulesForPawn("initiator", this.initiatorPawn, request.Constants)); } else if (this.initiatorThing != null) { request.Rules.AddRange(GrammarUtility.RulesForDef("initiator", this.initiatorThing)); } else { request.Constants["initiator_missing"] = "True"; } if (this.recipientPawn != null) { request.Rules.AddRange(GrammarUtility.RulesForPawn("recipient", this.recipientPawn, request.Constants)); } else if (this.recipientThing != null) { request.Rules.AddRange(GrammarUtility.RulesForDef("recipient", this.recipientThing)); } else { request.Constants["recipient_missing"] = "True"; } request.Rules.AddRange(PlayLogEntryUtility.RulesForOptionalWeapon("weapon", this.weaponDef, this.projectileDef)); if (this.projectileDef != null) { request.Rules.AddRange(GrammarUtility.RulesForDef("projectile", this.projectileDef)); } if (this.damageDef != null && this.damageDef.combatLogRules != null) { request.Includes.Add(this.damageDef.combatLogRules); } request.Rules.AddRange(PlayLogEntryUtility.RulesForDamagedParts("recipient_part", this.damagedParts, this.damagedPartsDestroyed, request.Constants)); string result = GrammarResolver.Resolve("logentry", request, "ranged explosion", false); Rand.PopState(); return(result); }
public static TaggedString GenerateTextFromTale(TextGenerationPurpose purpose, Tale tale, int seed, RulePackDef extraInclude, CompBook compBook) { Rand.PushState(); Rand.Seed = seed; string rootKeyword = null; GrammarRequest request = default(GrammarRequest); request.Includes.Add(extraInclude); switch (purpose) { case TextGenerationPurpose.ArtDescription: rootKeyword = compBook.Props.nameMaker.RulesImmediate .Where(x => x.keyword != null && x.keyword.Length > 0).RandomElement().keyword; //Log.Message("rootKeyword for description: " + rootKeyword); if (tale != null && !Rand.Chance(0.2f)) { request.Includes.Add(RulePackDefOf.ArtDescriptionRoot_HasTale); request.IncludesBare.AddRange(tale.GetTextGenerationIncludes()); request.Rules.AddRange(tale.GetTextGenerationRules()); } else { request.Includes.Add(RulePackDefOf.ArtDescriptionRoot_Taleless); request.Includes.Add(RulePackDefOf.TalelessImages); } request.Includes.Add(RulePackDefOf.ArtDescriptionUtility_Global); break; case TextGenerationPurpose.ArtName: rootKeyword = compBook.Props.descriptionMaker.RulesImmediate .Where(x => x.keyword != null && x.keyword.Length > 0).RandomElement().keyword; //Log.Message("rootKeyword for name: " + rootKeyword); if (tale != null) { request.IncludesBare.AddRange(tale.GetTextGenerationIncludes()); request.Rules.AddRange(tale.GetTextGenerationRules()); } break; } string str = GrammarResolver.Resolve(rootKeyword, request, (tale != null) ? tale.def.defName : "null_tale"); Rand.PopState(); return(str); }
public static string ResolveAbsoluteText(List <Rule> absoluteRules, Dictionary <string, string> absoluteConstants = null, string absoluteRootKeyword = "root", bool capitalizeFirstSentence = true) { GrammarRequest req = default(GrammarRequest); if (absoluteRules != null) { req.Rules.AddRange(absoluteRules); } if (absoluteConstants != null) { foreach (KeyValuePair <string, string> absoluteConstant in absoluteConstants) { req.Constants.Add(absoluteConstant.Key, absoluteConstant.Value); } } AddSlateVars(ref req); return(GrammarResolver.Resolve(absoluteRootKeyword, req, null, forceLog: false, null, null, null, capitalizeFirstSentence)); }
/// <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 }
public static string GenerateName(RulePackDef rootPack, Predicate <string> validator = null, bool appendNumberIfNameUsed = false, string rootKeyword = null) { string text = null; GrammarRequest request = default(GrammarRequest); request.Includes.Add(rootPack); if (appendNumberIfNameUsed) { for (int i = 0; i < 100; i++) { int num = 0; while (num < 5) { text = GenText.ToTitleCaseSmart(GrammarResolver.Resolve((rootKeyword == null) ? rootPack.RulesPlusIncludes[0].keyword : rootKeyword, request, null, false)); if (i != 0) { text = text + " " + (i + 1); } if (validator != null && !validator(text)) { num++; continue; } return(text); } } return(GenText.ToTitleCaseSmart(GrammarResolver.Resolve((rootKeyword == null) ? rootPack.RulesPlusIncludes[0].keyword : rootKeyword, request, null, false))); } int num2 = 0; while (num2 < 150) { text = GenText.ToTitleCaseSmart(GrammarResolver.Resolve((rootKeyword == null) ? rootPack.RulesPlusIncludes[0].keyword : rootKeyword, request, null, false)); if (validator != null && !validator(text)) { num2++; continue; } return(text); } Log.Error("Could not get new name (rule pack: " + rootPack + ")"); return(text); }
public override string ToGameStringFromPOV(Thing pov) { if (this.initiatorPawn == null && this.initiatorThing == null) { Log.ErrorOnce("BattleLogEntry_RangedFire has a null initiator.", 60465709); return("[BattleLogEntry_RangedFire error: null pawn reference]"); } Rand.PushState(); Rand.Seed = base.randSeed; GrammarRequest request = default(GrammarRequest); request.Includes.Add(RulePackDefOf.Combat_RangedFire); if (this.initiatorPawn != null) { request.Rules.AddRange(GrammarUtility.RulesForPawn("initiator", this.initiatorPawn, request.Constants)); } else if (this.initiatorThing != null) { request.Rules.AddRange(GrammarUtility.RulesForDef("initiator", this.initiatorThing)); } else { request.Constants["initiator_missing"] = "True"; } if (this.recipientPawn != null) { request.Rules.AddRange(GrammarUtility.RulesForPawn("recipient", this.recipientPawn, request.Constants)); } else if (this.recipientThing != null) { request.Rules.AddRange(GrammarUtility.RulesForDef("recipient", this.recipientThing)); } else { request.Constants["recipient_missing"] = "True"; } request.Rules.AddRange(PlayLogEntryUtility.RulesForOptionalWeapon("weapon", this.weaponDef, this.projectileDef)); request.Constants["burst"] = this.burst.ToString(); string result = GrammarResolver.Resolve("logentry", request, "ranged fire", false); Rand.PopState(); return(result); }
public override string ToGameStringFromPOV(Thing pov) { if (this.recipientPawn == null) { Log.ErrorOnce("BattleLogEntry_DamageTaken has a null recipient.", 60465709); return("[BattleLogEntry_DamageTaken error: null pawn reference]"); } Rand.PushState(); Rand.Seed = base.randSeed; GrammarRequest request = default(GrammarRequest); request.Includes.Add(this.ruleDef); request.Rules.AddRange(GrammarUtility.RulesForPawn("recipient", this.recipientPawn, request.Constants)); request.Rules.AddRange(PlayLogEntryUtility.RulesForDamagedParts("recipient_part", this.damagedParts, this.damagedPartsDestroyed, request.Constants)); string result = GrammarResolver.Resolve("logentry", request, "damage taken", false); Rand.PopState(); return(result); }
public DiaNode AnnualExpoDialogueNode() { GrammarRequest request = default; request.Includes.Add(RulePackDefOf.ArtDescriptionUtility_Global); var flavourText = GrammarResolver.Resolve("artextra_clause", request); var dialogueGreeting = new DiaNode( "MFI_AnnualExpoDialogueIntroduction".Translate(activity.theme, FirstCharacterToLower(flavourText))); foreach (var option in DialogueOptions(participant)) { dialogueGreeting.options.Add(option); } return(dialogueGreeting); }
public override string ToGameStringFromPOV(Thing pov) { Rand.PushState(); Rand.Seed = base.randSeed; GrammarRequest request = default(GrammarRequest); request.Rules.AddRange(GrammarUtility.RulesForPawn("initiator", this.initiator, request.Constants)); if (this.recipientPawn != null) { request.Rules.AddRange(GrammarUtility.RulesForPawn("recipient", this.recipientPawn, request.Constants)); } else if (this.recipientThing != null) { request.Rules.AddRange(GrammarUtility.RulesForDef("recipient", this.recipientThing)); } request.Includes.Add(this.outcomeRuleDef); request.Includes.Add(this.maneuverRuleDef); if (!this.toolLabel.NullOrEmpty()) { request.Rules.Add(new Rule_String("tool_label", this.toolLabel)); } if (this.implementType != null && !this.implementType.implementOwnerRuleName.NullOrEmpty()) { if (this.ownerEquipmentDef != null) { request.Rules.AddRange(GrammarUtility.RulesForDef(this.implementType.implementOwnerRuleName, this.ownerEquipmentDef)); } else if (this.ownerHediffDef != null) { request.Rules.AddRange(GrammarUtility.RulesForDef(this.implementType.implementOwnerRuleName, this.ownerHediffDef)); } } if (this.implementType != null && !this.implementType.implementOwnerTypeValue.NullOrEmpty()) { request.Constants["implementOwnerType"] = this.implementType.implementOwnerTypeValue; } request.Rules.AddRange(PlayLogEntryUtility.RulesForDamagedParts("recipient_part", this.damagedParts, this.damagedPartsDestroyed, request.Constants)); string result = GrammarResolver.Resolve("logentry", request, "combat interaction", false); Rand.PopState(); return(result); }
public string GetName() { if (this.battleName.NullOrEmpty()) { HashSet <Faction> hashSet = new HashSet <Faction>(from p in this.concerns select p.Faction); GrammarRequest request = default(GrammarRequest); if (this.concerns.Count == 1) { if (hashSet.Count((Faction f) => f != null) < 2) { request.Includes.Add(RulePackDefOf.Battle_Solo); request.Rules.AddRange(GrammarUtility.RulesForPawn("PARTICIPANT1", this.concerns.First <Pawn>(), null)); goto IL_1CC; } } if (this.concerns.Count == 2) { request.Includes.Add(RulePackDefOf.Battle_Duel); request.Rules.AddRange(GrammarUtility.RulesForPawn("PARTICIPANT1", this.concerns.First <Pawn>(), null)); request.Rules.AddRange(GrammarUtility.RulesForPawn("PARTICIPANT2", this.concerns.Last <Pawn>(), null)); } else if (hashSet.Count == 1) { request.Includes.Add(RulePackDefOf.Battle_Internal); request.Rules.AddRange(GrammarUtility.RulesForFaction("FACTION1", hashSet.First <Faction>())); } else if (hashSet.Count == 2) { request.Includes.Add(RulePackDefOf.Battle_War); request.Rules.AddRange(GrammarUtility.RulesForFaction("FACTION1", hashSet.First <Faction>())); request.Rules.AddRange(GrammarUtility.RulesForFaction("FACTION2", hashSet.Last <Faction>())); } else { request.Includes.Add(RulePackDefOf.Battle_Brawl); } IL_1CC: this.battleName = GrammarResolver.Resolve("r_battlename", request, null, false, null); } return(this.battleName); }
public static TaggedString GenerateTextFromTale(TextGenerationPurpose purpose, Tale tale, int seed, RulePackDef extraInclude) { Rand.PushState(); Rand.Seed = seed; string rootKeyword = null; GrammarRequest request = default(GrammarRequest); request.Includes.Add(extraInclude); switch (purpose) { case TextGenerationPurpose.ArtDescription: rootKeyword = "r_art_description"; if (tale != null && !Rand.Chance(0.2f)) { request.Includes.Add(RulePackDefOf.ArtDescriptionRoot_HasTale); request.IncludesBare.AddRange(tale.GetTextGenerationIncludes()); request.Rules.AddRange(tale.GetTextGenerationRules()); } else { request.Includes.Add(RulePackDefOf.ArtDescriptionRoot_Taleless); request.Includes.Add(RulePackDefOf.TalelessImages); } request.Includes.Add(RulePackDefOf.ArtDescriptionUtility_Global); break; case TextGenerationPurpose.ArtName: rootKeyword = "r_art_name"; if (tale != null) { request.IncludesBare.AddRange(tale.GetTextGenerationIncludes()); request.Rules.AddRange(tale.GetTextGenerationRules()); } break; } string str = GrammarResolver.Resolve(rootKeyword, request, (tale != null) ? tale.def.defName : "null_tale"); Rand.PopState(); return(str); }
public static string GenerateTextFromTale(TextGenerationPurpose purpose, Tale tale, int seed, List <Rule> extraRules) { Rand.PushState(); Rand.Seed = seed; string rootKeyword = null; GrammarRequest request = default(GrammarRequest); request.Rules.AddRange(extraRules); switch (purpose) { case TextGenerationPurpose.ArtDescription: rootKeyword = "art_description_root"; if (tale != null && Rand.Value > 0.20000000298023224) { request.Includes.Add(RulePackDefOf.ArtDescriptionRoot_HasTale); request.Rules.AddRange(tale.GetTextGenerationRules()); } else { request.Includes.Add(RulePackDefOf.ArtDescriptionRoot_Taleless); request.Includes.Add(RulePackDefOf.TalelessImages); } request.Includes.Add(RulePackDefOf.ArtDescriptionUtility_Global); break; case TextGenerationPurpose.ArtName: rootKeyword = "art_name"; if (tale != null) { request.Rules.AddRange(tale.GetTextGenerationRules()); } break; } string result = GrammarResolver.Resolve(rootKeyword, request, (tale == null) ? "null_tale" : tale.def.defName, false); Rand.PopState(); return(result); }
public static string GenerateName(GrammarRequest request, Predicate <string> validator = null, bool appendNumberIfNameUsed = false, string rootKeyword = null, string untranslatedRootKeyword = null) { if (untranslatedRootKeyword == null) { untranslatedRootKeyword = rootKeyword; } string text = "ErrorName"; if (appendNumberIfNameUsed) { for (int i = 0; i < 100; i++) { for (int j = 0; j < 5; j++) { text = GenText.CapitalizeAsTitle(GrammarResolver.Resolve(rootKeyword, request, null, forceLog: false, untranslatedRootKeyword)); if (i != 0) { text = text + " " + (i + 1); } if (validator == null || validator(text)) { return(text); } } } return(GenText.CapitalizeAsTitle(GrammarResolver.Resolve(rootKeyword, request, null, forceLog: false, untranslatedRootKeyword))); } for (int k = 0; k < 150; k++) { text = GenText.CapitalizeAsTitle(GrammarResolver.Resolve(rootKeyword, request, null, forceLog: false, untranslatedRootKeyword)); if (validator == null || validator(text)) { return(text); } } Log.Error("Could not get new name (first rule pack: " + request.Includes.FirstOrDefault().ToStringSafe() + ")"); return(text); }
public string GetName() { if (battleName.NullOrEmpty()) { HashSet <Faction> hashSet = new HashSet <Faction>(concerns.Select((Pawn p) => p.Faction)); GrammarRequest request = default(GrammarRequest); if (concerns.Count == 1 && hashSet.Count((Faction f) => f != null) < 2) { request.Includes.Add(RulePackDefOf.Battle_Solo); request.Rules.AddRange(GrammarUtility.RulesForPawn("PARTICIPANT1", concerns.First())); } else if (concerns.Count == 2) { request.Includes.Add(RulePackDefOf.Battle_Duel); request.Rules.AddRange(GrammarUtility.RulesForPawn("PARTICIPANT1", concerns.First())); request.Rules.AddRange(GrammarUtility.RulesForPawn("PARTICIPANT2", concerns.Last())); } else if (hashSet.Count == 1) { request.Includes.Add(RulePackDefOf.Battle_Internal); request.Rules.AddRange(GrammarUtility.RulesForFaction("FACTION1", hashSet.First())); } else if (hashSet.Count == 2) { request.Includes.Add(RulePackDefOf.Battle_War); request.Rules.AddRange(GrammarUtility.RulesForFaction("FACTION1", hashSet.First())); request.Rules.AddRange(GrammarUtility.RulesForFaction("FACTION2", hashSet.Last())); } else { request.Includes.Add(RulePackDefOf.Battle_Brawl); } battleName = GrammarResolver.Resolve("r_battlename", request); } return(battleName); }
public override string ToGameStringFromPOV(Thing pov) { Rand.PushState(); Rand.Seed = base.randSeed; GrammarRequest request = default(GrammarRequest); if (this.subjectPawn != null) { request.Rules.AddRange(GrammarUtility.RulesForPawn("subject", this.subjectPawn, request.Constants)); } else if (this.subjectThing != null) { request.Rules.AddRange(GrammarUtility.RulesForDef("subject", this.subjectThing)); } request.Includes.Add(this.transitionDef); if (this.initiator != null) { request.Rules.AddRange(GrammarUtility.RulesForPawn("initiator", this.initiator, request.Constants)); } if (this.culpritHediffDef != null) { request.Rules.AddRange(GrammarUtility.RulesForDef("culpritHediff", this.culpritHediffDef)); } if (this.culpritHediffTargetDef != null) { request.Rules.AddRange(GrammarUtility.RulesForDef("culpritHediff_target", this.culpritHediffTargetDef)); } if (this.culpritTargetDef != null) { request.Rules.AddRange(GrammarUtility.RulesForDef("culpritHediff_originaltarget", this.culpritTargetDef)); } string result = GrammarResolver.Resolve("logentry", request, "state transition", false); Rand.PopState(); return(result); }
protected virtual string ToGameStringFromPOV_Worker(Thing pov, bool forceLog) { return(GrammarResolver.Resolve("r_logentry", GenerateGrammarRequest(), null, forceLog)); }