public override void Notify_GeneratedByQuestGen(SitePart part, Slate slate, List <Rule> outExtraDescriptionRules, Dictionary <string, string> outExtraDescriptionConstants) { base.Notify_GeneratedByQuestGen(part, slate, outExtraDescriptionRules, outExtraDescriptionConstants); WeatherDef weather = part.conditionCauser.TryGetComp <CompCauseGameCondition_ForceWeather>().weather; outExtraDescriptionRules.AddRange(GrammarUtility.RulesForDef("weather", weather)); }
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); }
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)); }
protected override GrammarRequest GenerateGrammarRequest() { GrammarRequest result = base.GenerateGrammarRequest(); result.Rules.AddRange(GrammarUtility.RulesForDef("ITEM", itemUsed)); return(result); }
protected override GrammarRequest GenerateGrammarRequest() { GrammarRequest result = base.GenerateGrammarRequest(); if (this.recipientPawn != null || this.recipientThing != null) { result.Includes.Add((!this.deflected) ? RulePackDefOf.Combat_RangedDamage : RulePackDefOf.Combat_RangedDeflect); } else { result.Includes.Add(RulePackDefOf.Combat_RangedMiss); } if (this.initiatorPawn != null) { result.Rules.AddRange(GrammarUtility.RulesForPawn("INITIATOR", this.initiatorPawn, result.Constants)); } else if (this.initiatorThing != null) { result.Rules.AddRange(GrammarUtility.RulesForDef("INITIATOR", this.initiatorThing)); } else { result.Constants["INITIATOR_missing"] = "True"; } if (this.recipientPawn != null) { result.Rules.AddRange(GrammarUtility.RulesForPawn("RECIPIENT", this.recipientPawn, result.Constants)); } else if (this.recipientThing != null) { result.Rules.AddRange(GrammarUtility.RulesForDef("RECIPIENT", this.recipientThing)); } else { result.Constants["RECIPIENT_missing"] = "True"; } if (this.originalTargetPawn != this.recipientPawn || this.originalTargetThing != this.recipientThing) { if (this.originalTargetPawn != null) { result.Rules.AddRange(GrammarUtility.RulesForPawn("ORIGINALTARGET", this.originalTargetPawn, result.Constants)); result.Constants["ORIGINALTARGET_mobile"] = this.originalTargetMobile.ToString(); } else if (this.originalTargetThing != null) { result.Rules.AddRange(GrammarUtility.RulesForDef("ORIGINALTARGET", this.originalTargetThing)); } else { result.Constants["ORIGINALTARGET_missing"] = "True"; } } result.Rules.AddRange(PlayLogEntryUtility.RulesForOptionalWeapon("WEAPON", this.weaponDef, this.projectileDef)); result.Constants["COVER_missing"] = ((this.coverDef == null) ? "True" : "False"); if (this.coverDef != null) { result.Rules.AddRange(GrammarUtility.RulesForDef("COVER", this.coverDef)); } return(result); }
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 GrammarRequest GenerateGrammarRequest() { GrammarRequest result = base.GenerateGrammarRequest(); result.Rules.AddRange(GrammarUtility.RulesForPawn("INITIATOR", this.initiator, result.Constants)); if (this.recipientPawn != null) { result.Rules.AddRange(GrammarUtility.RulesForPawn("RECIPIENT", this.recipientPawn, result.Constants)); } else if (this.recipientThing != null) { result.Rules.AddRange(GrammarUtility.RulesForDef("RECIPIENT", this.recipientThing)); } result.Includes.Add(this.ruleDef); if (!this.toolLabel.NullOrEmpty()) { result.Rules.Add(new Rule_String("TOOL_label", this.toolLabel)); } if (this.implementType != null && !this.implementType.implementOwnerRuleName.NullOrEmpty()) { if (this.ownerEquipmentDef != null) { result.Rules.AddRange(GrammarUtility.RulesForDef(this.implementType.implementOwnerRuleName, this.ownerEquipmentDef)); } else if (this.ownerHediffDef != null) { result.Rules.AddRange(GrammarUtility.RulesForDef(this.implementType.implementOwnerRuleName, this.ownerHediffDef)); } } if (this.implementType != null && !this.implementType.implementOwnerTypeValue.NullOrEmpty()) { result.Constants["IMPLEMENTOWNER_type"] = this.implementType.implementOwnerTypeValue; } return(result); }
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 static IEnumerable <Rule> RulesForOptionalWeapon(string prefix, ThingDef weaponDef, ThingDef projectileDef) { if (weaponDef == null) { yield break; } foreach (Rule item in GrammarUtility.RulesForDef(prefix, weaponDef)) { yield return(item); } ThingDef thingDef = projectileDef; if (thingDef == null && !weaponDef.Verbs.NullOrEmpty()) { thingDef = weaponDef.Verbs[0].defaultProjectile; } if (thingDef == null) { yield break; } foreach (Rule item2 in GrammarUtility.RulesForDef(prefix + "_projectile", thingDef)) { yield return(item2); } }
public override void Notify_GeneratedByQuestGen(SitePart part, Slate slate, List <Rule> outExtraDescriptionRules, Dictionary <string, string> outExtraDescriptionConstants) { // Duplicate code so modularize in Util Util.SitePartWorker_Base_Notify_GeneratedByQuestGen(part, outExtraDescriptionRules, outExtraDescriptionConstants); // Replaces PrisonerWillingToJoinQuestUtility.GeneratePrisoner Pawn pawn = GameComponent.GetRandomAllyForSpawning(); pawn.guest.SetGuestStatus(part.site.Faction, true); Util.DressPawnIfCold(pawn, part.site.Tile); part.things = new ThingOwner <Pawn>(part, true, LookMode.Deep); part.things.TryAdd(pawn, true); string text; PawnRelationUtility.Notify_PawnsSeenByPlayer(Gen.YieldSingle <Pawn>(pawn), out text, true, false); outExtraDescriptionRules.AddRange(GrammarUtility.RulesForPawn("prisoner", pawn, outExtraDescriptionConstants, true, true)); string output; if (!text.NullOrEmpty()) { output = "\n\n" + "PawnHasTheseRelationshipsWithColonists".Translate(pawn.LabelShort, pawn) + "\n\n" + text; } else { output = ""; } outExtraDescriptionRules.Add(new Rule_String("prisonerFullRelationInfo", output)); }
public void CreateGrammarFromListSuccess() { List <String> testListValues = new List <String> { "Test Item One", "Test Item Two", "Test Item Three", }; XmlDocument doc = new XmlDocument(); doc.Load(formattedFileName); XmlGrammar baseGrammar = new XmlGrammar(doc); XmlGrammar grammar = GrammarUtility.CreateGrammarFromList(formattedFileName, "testList", testListValues); Assert.AreEqual(5, grammar.Rules.Count()); for (int i = 0; i < baseGrammar.Rules.Count() - 1; i++) { Assert.AreEqual(baseGrammar.Rules.ElementAt(i).InnerXml, grammar.Rules.ElementAt(i).InnerXml); } XmlElement elem = grammar.Rules.Last(); Assert.AreEqual("testList", elem.Attributes["id"].Value); XmlElement oneOfElem = elem.FirstChild as XmlElement; Assert.AreEqual(3, oneOfElem.ChildNodes.Count); Assert.AreEqual(testListValues[0], oneOfElem.ChildNodes[0].FirstChild.Value.Trim()); Assert.AreEqual(testListValues[1], oneOfElem.ChildNodes[1].FirstChild.Value.Trim()); Assert.AreEqual(testListValues[2], oneOfElem.ChildNodes[2].FirstChild.Value.Trim()); }
public override void RandomizeSettings(float points, Map map, List <Rule> outExtraDescriptionRules, Dictionary <string, string> outExtraDescriptionConstants) { base.RandomizeSettings(points, map, outExtraDescriptionRules, outExtraDescriptionConstants); weather = DefDatabase <WeatherDef> .AllDefsListForReading.Where((WeatherDef def) => def.isBad).RandomElement(); outExtraDescriptionRules.AddRange(GrammarUtility.RulesForDef("forcedWeather", weather)); }
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 override void Initialize(IConfigurationManager configManager) { base.Initialize(configManager); if (ConfigManager.FindAllComponentsOfType <ITVRemote>().Any()) { XmlGrammar grammar = GrammarUtility.CreateGrammarFromList(ConfigManager.GetPathForFile("RemoteGrammar.grxml", GetType()), "ChannelName", ConfigManager.FindAllComponentsOfType <ITVRemote>().SelectMany(r => r.GetChannels()).ToList()); Provider = new GrammarProvider(grammar); } }
public override void Initialize(IConfigurationManager configManager) { base.Initialize(configManager); if (IsValid) { List <String> podcastNames = Podcasts.Select(info => info.Name).ToList(); XmlGrammar grammar = GrammarUtility.CreateGrammarFromList(ConfigManager.GetPathForFile("PodcastGrammar.grxml", GetType()), "PodcastName", podcastNames); Provider = new GrammarProvider(grammar); } }
public override void Initialize(IConfigurationManager configManager) { base.Initialize(configManager); if (ConfigManager.FindAllComponentsOfType <IPowerController>().Any()) { IEnumerable <String> locations = ConfigManager.FindAllComponentsOfType <IPowerController>().Select(s => s.Name); XmlGrammar grammar = GrammarUtility.CreateGrammarFromList(ConfigManager.GetPathForFile("PowerGrammar.grxml", GetType()), "SwitchName", locations.ToList()); Provider = new GrammarProvider(grammar); } }
protected override GrammarRequest GenerateGrammarRequest() { GrammarRequest result = base.GenerateGrammarRequest(); result.Rules.AddRange(GrammarUtility.RulesForDef("ABILITY", abilityUsed)); if (subjectPawn == null && subjectThing == null) { result.Rules.Add(new Rule_String("SUBJECT_definite", "AreaLower".Translate())); } return(result); }
protected override GrammarRequest GenerateGrammarRequest() { GrammarRequest result = base.GenerateGrammarRequest(); if (recipientPawn == null) { Log.ErrorOnce("BattleLogEntry_DamageTaken has a null recipient.", 60465709); } result.Includes.Add(ruleDef); result.Rules.AddRange(GrammarUtility.RulesForPawn("RECIPIENT", recipientPawn, result.Constants)); return(result); }
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 GrammarRequest GenerateGrammarRequest() { GrammarRequest result = base.GenerateGrammarRequest(); if (initiatorPawn == null && initiatorThing == null) { Log.ErrorOnce("BattleLogEntry_RangedFire has a null initiator.", 60465709); } if (weaponDef != null && weaponDef.Verbs[0].rangedFireRulepack != null) { result.Includes.Add(weaponDef.Verbs[0].rangedFireRulepack); } else { result.Includes.Add(RulePackDefOf.Combat_RangedFire); } if (initiatorPawn != null) { result.Rules.AddRange(GrammarUtility.RulesForPawn("INITIATOR", initiatorPawn, result.Constants)); } else if (initiatorThing != null) { result.Rules.AddRange(GrammarUtility.RulesForDef("INITIATOR", initiatorThing)); } else { result.Constants["INITIATOR_missing"] = "True"; } if (recipientPawn != null) { result.Rules.AddRange(GrammarUtility.RulesForPawn("RECIPIENT", recipientPawn, result.Constants)); } else if (recipientThing != null) { result.Rules.AddRange(GrammarUtility.RulesForDef("RECIPIENT", recipientThing)); } else { result.Constants["RECIPIENT_missing"] = "True"; } result.Rules.AddRange(PlayLogEntryUtility.RulesForOptionalWeapon("WEAPON", weaponDef, projectileDef)); if (initiatorPawn != null && initiatorPawn.skills != null) { result.Constants["INITIATOR_skill"] = initiatorPawn.skills.GetSkill(SkillDefOf.Shooting).Level.ToStringCached(); } if (recipientPawn != null && recipientPawn.skills != null) { result.Constants["RECIPIENT_skill"] = recipientPawn.skills.GetSkill(SkillDefOf.Shooting).Level.ToStringCached(); } result.Constants["BURST"] = burst.ToString(); return(result); }
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); }
internal XmlGrammar GetMainGrammar() { if (ConfigManager != null && ConfigManager.FindAllComponentsOfType <IMovieSensor>().Any()) { List <Showtime> showTimes = ConfigManager.FindAllComponentsOfType <IMovieSensor>().SelectMany(s => s.GetMovieShowtimes(new SamiDateTime(DateTimeRange.AnyTime))).ToList(); List <String> movieNames = showTimes.Select(showtime => showtime.MovieTitle).Distinct().ToList(); if (movieNames.Count == 0) { // If the movie list is empty, the grammar file becomes invalid. // Therefore, I will add a nonsensical string that will never be detect // to prevent the grammar from erroring. // A better solution should be found for this, but it's not too important // right now. movieNames.Add("XYZ123"); } List <String> theaterNames = showTimes.Select(showtime => showtime.Theater).Distinct().ToList(); if (theaterNames.Count == 0) { // If the movie list is empty, the grammar file becomes invalid. // Therefore, I will add a nonsensical string that will never be detect // to prevent the grammar from erroring. // A better solution should be found for this, but it's not too important // right now. theaterNames.Add("XYZ123"); } XmlDocument doc = new XmlDocument(); doc.Load(ConfigManager.GetPathForFile("MovieGrammar.grxml", GetType())); XmlElement oneof = GrammarUtility.CreateListOfPossibleStrings(doc, movieNames); XmlElement rule = GrammarUtility.CreateElement(doc, "rule", new Dictionary <string, string> { { "id", "MovieName" }, { "scope", "public" }, }); rule.AppendChild(oneof); doc.LastChild.AppendChild(rule); oneof = GrammarUtility.CreateListOfPossibleStrings(doc, theaterNames); rule = GrammarUtility.CreateElement(doc, "rule", new Dictionary <string, string> { { "id", "TheaterName" }, { "scope", "public" }, }); rule.AppendChild(oneof); doc.LastChild.AppendChild(rule); return(new XmlGrammar(doc)); } return(null); }
public override void Initialize(IConfigurationManager configManager) { base.Initialize(configManager); if (ConfigManager.FindAllComponentsOfType <IBartenderController>().Any() && AvailableDrinks.Any()) { List <String> drinkNames = AvailableDrinks.Select(d => d.Name).ToList(); XmlGrammar grammar = GrammarUtility.CreateGrammarFromList(ConfigManager.GetPathForFile("BartenderGrammar.grxml", GetType()), "DrinkName", drinkNames); Provider = new GrammarProvider(grammar, GrammarUtility.GetGenericTrueFalseGrammar(ConfirmationRuleName, CommandName, new List <String> { "o k" }, new List <String> { "cancel" })); } }
public override void Initialize(IConfigurationManager configManager) { base.Initialize(configManager); if (!Children.OfType <IOInterfaceReference>().Any()) { foreach (IVolumeController controller in ConfigManager.FindAllComponentsOfType <IVolumeController>()) { AddChild(new IOInterfaceReference("", controller.Name, ConfigManager)); } } IEnumerable <String> references = Children.OfType <IOInterfaceReference>().Select(s => s.Name); XmlGrammar grammar = GrammarUtility.CreateGrammarFromList(ConfigManager.GetPathForFile("VolumeGrammar.grxml", GetType()), "Source", references.ToList()); Provider = new GrammarProvider(grammar, new XmlGrammar(ConfigManager, VolumeGrammarName, "AdjustmentGrammar.grxml", GetType())); }
public static IEnumerable <Rule> PlayLogEntryUtility_RulesForOptionalWeapon_Postfix(IEnumerable <Rule> __result, string prefix, ThingDef weaponDef, ThingDef projectileDef) { foreach (var rule in __result) { yield return(rule); } if (weaponDef != null || projectileDef == null) { yield break; } foreach (var rule in GrammarUtility.RulesForDef(prefix + "_projectile", projectileDef)) { yield return(rule); } }
internal XmlGrammar GetMainGrammar() { if (ConfigManager.FindAllComponentsOfType <IMusicController>().Any()) { List <String> playlists = ConfigManager.FindAllComponentsOfType <IMusicController>().SelectMany(s => s.GetPlaylists()).ToList(); if (playlists.Any()) { return(GrammarUtility.CreateGrammarFromList(ConfigManager.GetPathForFile("MusicGrammar.xml", GetType()), "PlaylistName", playlists)); } else { _playlistsFound = false; } } return(null); }
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); }
protected override GrammarRequest GenerateGrammarRequest() { GrammarRequest result = base.GenerateGrammarRequest(); result.Rules.AddRange(GrammarUtility.RulesForPawn("INITIATOR", initiator, result.Constants)); if (recipientPawn != null) { result.Rules.AddRange(GrammarUtility.RulesForPawn("RECIPIENT", recipientPawn, result.Constants)); } else if (recipientThing != null) { result.Rules.AddRange(GrammarUtility.RulesForDef("RECIPIENT", recipientThing)); } result.Includes.Add(ruleDef); if (!toolLabel.NullOrEmpty()) { result.Rules.Add(new Rule_String("TOOL_label", toolLabel)); result.Rules.Add(new Rule_String("TOOL_definite", Find.ActiveLanguageWorker.WithDefiniteArticle(toolLabel))); result.Rules.Add(new Rule_String("TOOL_indefinite", Find.ActiveLanguageWorker.WithIndefiniteArticle(toolLabel))); result.Constants["TOOL_gender"] = LanguageDatabase.activeLanguage.ResolveGender(toolLabel).ToString(); } if (implementType != null && !implementType.implementOwnerRuleName.NullOrEmpty()) { if (ownerEquipmentDef != null) { result.Rules.AddRange(GrammarUtility.RulesForDef(implementType.implementOwnerRuleName, ownerEquipmentDef)); } else if (ownerHediffDef != null) { result.Rules.AddRange(GrammarUtility.RulesForDef(implementType.implementOwnerRuleName, ownerHediffDef)); } } if (initiator != null && initiator.skills != null) { result.Constants["INITIATOR_skill"] = initiator.skills.GetSkill(SkillDefOf.Melee).Level.ToStringCached(); } if (recipientPawn != null && recipientPawn.skills != null) { result.Constants["RECIPIENT_skill"] = recipientPawn.skills.GetSkill(SkillDefOf.Melee).Level.ToStringCached(); } if (implementType != null && !implementType.implementOwnerTypeValue.NullOrEmpty()) { result.Constants["IMPLEMENTOWNER_type"] = implementType.implementOwnerTypeValue; } return(result); }
protected override GrammarRequest GenerateGrammarRequest() { GrammarRequest result = base.GenerateGrammarRequest(); if (this.initiatorPawn == null && this.initiatorThing == null) { Log.ErrorOnce("BattleLogEntry_RangedFire has a null initiator.", 60465709, false); } if (this.weaponDef != null && this.weaponDef.Verbs[0].rangedFireRulepack != null) { result.Includes.Add(this.weaponDef.Verbs[0].rangedFireRulepack); } else { result.Includes.Add(RulePackDefOf.Combat_RangedFire); } if (this.initiatorPawn != null) { result.Rules.AddRange(GrammarUtility.RulesForPawn("INITIATOR", this.initiatorPawn, result.Constants)); } else if (this.initiatorThing != null) { result.Rules.AddRange(GrammarUtility.RulesForDef("INITIATOR", this.initiatorThing)); } else { result.Constants["INITIATOR_missing"] = "True"; } if (this.recipientPawn != null) { result.Rules.AddRange(GrammarUtility.RulesForPawn("RECIPIENT", this.recipientPawn, result.Constants)); } else if (this.recipientThing != null) { result.Rules.AddRange(GrammarUtility.RulesForDef("RECIPIENT", this.recipientThing)); } else { result.Constants["RECIPIENT_missing"] = "True"; } result.Rules.AddRange(PlayLogEntryUtility.RulesForOptionalWeapon("WEAPON", this.weaponDef, this.projectileDef)); result.Constants["BURST"] = this.burst.ToString(); 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 }