public TaleReference GetRandomTaleReferenceForArt(ArtGenerationContext source)
        {
            if (source == ArtGenerationContext.Outsider)
            {
                return(TaleReference.Taleless);
            }
            if (this.tales.Count == 0)
            {
                return(TaleReference.Taleless);
            }
            if (Rand.Value < 0.25)
            {
                return(TaleReference.Taleless);
            }
            Tale tale = default(Tale);

            if (!(from x in this.tales
                  where x.def.usableForArt
                  select x).TryRandomElementByWeight <Tale>((Func <Tale, float>)((Tale ta) => ta.InterestLevel), out tale))
            {
                return(TaleReference.Taleless);
            }
            tale.Notify_NewlyUsed();
            return(new TaleReference(tale));
        }
Beispiel #2
0
        private void CheckCullUnusedTalesWithMaxPerPawnLimit(Tale addedTale)
        {
            if (addedTale.def.maxPerPawn < 0)
            {
                return;
            }
            if (addedTale.DominantPawn == null)
            {
                return;
            }
            int i = 0;

            for (int j = 0; j < this.tales.Count; j++)
            {
                if (this.tales[j].Unused && this.tales[j].def == addedTale.def && this.tales[j].DominantPawn == addedTale.DominantPawn)
                {
                    i++;
                }
            }
            while (i > addedTale.def.maxPerPawn)
            {
                Tale tale = null;
                int  num  = -1;
                for (int k = 0; k < this.tales.Count; k++)
                {
                    if (this.tales[k].Unused && this.tales[k].def == addedTale.def && this.tales[k].DominantPawn == addedTale.DominantPawn && this.tales[k].AgeTicks > num)
                    {
                        tale = this.tales[k];
                        num  = this.tales[k].AgeTicks;
                    }
                }
                this.RemoveTale(tale);
                i--;
            }
        }
Beispiel #3
0
        private void CheckCullUnusedVolatileTales()
        {
            int num = 0;

            for (int i = 0; i < tales.Count; i++)
            {
                if (tales[i].def.type == TaleType.Volatile && tales[i].Unused)
                {
                    num++;
                }
            }
            while (num > 350)
            {
                Tale  tale = null;
                float num2 = float.MaxValue;
                for (int j = 0; j < tales.Count; j++)
                {
                    if (tales[j].def.type == TaleType.Volatile && tales[j].Unused && tales[j].InterestLevel < num2)
                    {
                        tale = tales[j];
                        num2 = tales[j].InterestLevel;
                    }
                }
                RemoveTale(tale);
                num--;
            }
        }
        private void DoGraphPage(Rect rect)
        {
            rect.yMin += 17f;
            GUI.BeginGroup(rect);
            Rect graphRect  = new Rect(0f, 0f, rect.width, 450f);
            Rect legendRect = new Rect(0f, graphRect.yMax, rect.width / 2f, 40f);
            Rect rect2      = new Rect(0f, legendRect.yMax, rect.width, 40f);

            if (this.historyAutoRecorderGroup != null)
            {
                MainTabWindow_History.marks.Clear();
                List <Tale> allTalesListForReading = Find.TaleManager.AllTalesListForReading;
                for (int i = 0; i < allTalesListForReading.Count; i++)
                {
                    Tale tale = allTalesListForReading[i];
                    if (tale.def.type == TaleType.PermanentHistorical)
                    {
                        float x = (float)GenDate.TickAbsToGame(tale.date) / 60000f;
                        MainTabWindow_History.marks.Add(new CurveMark(x, tale.ShortSummary, tale.def.historyGraphColor));
                    }
                }
                this.historyAutoRecorderGroup.DrawGraph(graphRect, legendRect, this.graphSection, MainTabWindow_History.marks);
            }
            Text.Font = GameFont.Small;
            float num = (float)Find.TickManager.TicksGame / 60000f;

            if (Widgets.ButtonText(new Rect(legendRect.xMin + legendRect.width, legendRect.yMin, 110f, 40f), "Last30Days".Translate(), true, false, true))
            {
                this.graphSection = new FloatRange(Mathf.Max(0f, num - 30f), num);
            }
            if (Widgets.ButtonText(new Rect(legendRect.xMin + legendRect.width + 110f + 4f, legendRect.yMin, 110f, 40f), "Last100Days".Translate(), true, false, true))
            {
                this.graphSection = new FloatRange(Mathf.Max(0f, num - 100f), num);
            }
            if (Widgets.ButtonText(new Rect(legendRect.xMin + legendRect.width + 228f, legendRect.yMin, 110f, 40f), "Last300Days".Translate(), true, false, true))
            {
                this.graphSection = new FloatRange(Mathf.Max(0f, num - 300f), num);
            }
            if (Widgets.ButtonText(new Rect(legendRect.xMin + legendRect.width + 342f, legendRect.yMin, 110f, 40f), "AllDays".Translate(), true, false, true))
            {
                this.graphSection = new FloatRange(0f, num);
            }
            if (Widgets.ButtonText(new Rect(rect2.x, rect2.y, 110f, 40f), "SelectGraph".Translate(), true, false, true))
            {
                List <FloatMenuOption>          list  = new List <FloatMenuOption>();
                List <HistoryAutoRecorderGroup> list2 = Find.History.Groups();
                for (int j = 0; j < list2.Count; j++)
                {
                    HistoryAutoRecorderGroup groupLocal = list2[j];
                    list.Add(new FloatMenuOption(groupLocal.def.LabelCap, delegate()
                    {
                        this.historyAutoRecorderGroup = groupLocal;
                    }, MenuOptionPriority.Default, null, null, 0f, null, null));
                }
                FloatMenu window = new FloatMenu(list, "SelectGraph".Translate(), false);
                Find.WindowStack.Add(window);
                PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.HistoryTab, KnowledgeAmount.Total);
            }
            GUI.EndGroup();
        }
Beispiel #5
0
        private void CheckCullUnusedTalesWithMaxPerPawnLimit(Tale addedTale)
        {
            if (addedTale.def.maxPerPawn < 0 || addedTale.DominantPawn == null)
            {
                return;
            }
            int num = 0;

            for (int i = 0; i < tales.Count; i++)
            {
                if (tales[i].Unused && tales[i].def == addedTale.def && tales[i].DominantPawn == addedTale.DominantPawn)
                {
                    num++;
                }
            }
            while (num > addedTale.def.maxPerPawn)
            {
                Tale tale = null;
                int  num2 = -1;
                for (int j = 0; j < tales.Count; j++)
                {
                    if (tales[j].Unused && tales[j].def == addedTale.def && tales[j].DominantPawn == addedTale.DominantPawn && tales[j].AgeTicks > num2)
                    {
                        tale = tales[j];
                        num2 = tales[j].AgeTicks;
                    }
                }
                RemoveTale(tale);
                num--;
            }
        }
        public static void RecordTale(TaleDef def, params object[] args)
        {
            bool flag = Rand.Value < def.ignoreChance;

            if (Rand.Value >= def.ignoreChance || DebugViewSettings.logTaleRecording)
            {
                if (def.colonistOnly)
                {
                    bool flag2 = false;
                    bool flag3 = false;
                    for (int i = 0; i < args.Length; i++)
                    {
                        Pawn pawn = args[i] as Pawn;
                        if (pawn != null)
                        {
                            flag2 = true;
                            if (pawn.Faction == Faction.OfPlayer)
                            {
                                flag3 = true;
                            }
                        }
                    }
                    if (flag2 && !flag3)
                    {
                        return;
                    }
                }
                Tale tale = TaleFactory.MakeRawTale(def, args);
                if (tale != null)
                {
                    if (DebugViewSettings.logTaleRecording)
                    {
                        string   format = "Tale {0} from {1}, targets {2}:\n{3}";
                        object[] array  = new object[4];
                        array[0] = ((!flag) ? "recorded" : "ignored");
                        array[1] = def;
                        array[2] = (from arg in args
                                    select arg.ToStringSafe <object>()).ToCommaList(false);
                        array[3] = TaleTextGenerator.GenerateTextFromTale(TextGenerationPurpose.ArtDescription, tale, Rand.Int, RulePackDefOf.ArtDescription_Sculpture);
                        Log.Message(string.Format(format, array), false);
                    }
                    if (!flag)
                    {
                        Find.TaleManager.Add(tale);
                        for (int j = 0; j < args.Length; j++)
                        {
                            Pawn pawn2 = args[j] as Pawn;
                            if (pawn2 != null)
                            {
                                if (!pawn2.Dead && pawn2.needs.mood != null)
                                {
                                    pawn2.needs.mood.thoughts.situational.Notify_SituationalThoughtsDirty();
                                }
                                pawn2.records.AccumulateStoryEvent(StoryEventDefOf.TaleCreated);
                            }
                        }
                    }
                }
            }
        }
Beispiel #7
0
        private void CheckCullUnusedVolatileTales()
        {
            int i = 0;

            for (int j = 0; j < this.tales.Count; j++)
            {
                if (this.tales[j].def.type == TaleType.Volatile && this.tales[j].Unused)
                {
                    i++;
                }
            }
            while (i > 350)
            {
                Tale  tale = null;
                float num  = float.MaxValue;
                for (int k = 0; k < this.tales.Count; k++)
                {
                    if (this.tales[k].def.type == TaleType.Volatile && this.tales[k].Unused && this.tales[k].InterestLevel < num)
                    {
                        tale = this.tales[k];
                        num  = this.tales[k].InterestLevel;
                    }
                }
                this.RemoveTale(tale);
                i--;
            }
        }
 public void ReferenceDestroyed()
 {
     if (this.tale != null)
     {
         this.tale.Notify_ReferenceDestroyed();
         this.tale = null;
     }
 }
        public static Tale RecordTale(TaleDef def, params object[] args)
        {
            bool flag = Rand.Value < def.ignoreChance;

            if (Rand.Value < def.ignoreChance && !DebugViewSettings.logTaleRecording)
            {
                return(null);
            }
            if (def.colonistOnly)
            {
                bool flag2 = false;
                bool flag3 = false;
                for (int i = 0; i < args.Length; i++)
                {
                    Pawn pawn = args[i] as Pawn;
                    if (pawn != null)
                    {
                        flag2 = true;
                        if (pawn.Faction == Faction.OfPlayer)
                        {
                            flag3 = true;
                        }
                    }
                }
                if (flag2 && !flag3)
                {
                    return(null);
                }
            }
            Tale tale = TaleFactory.MakeRawTale(def, args);

            if (tale == null)
            {
                return(null);
            }
            if (DebugViewSettings.logTaleRecording)
            {
                Log.Message(string.Format("Tale {0} from {1}, targets {2}:\n{3}", flag ? "ignored" : "recorded", def, args.Select((object arg) => arg.ToStringSafe()).ToCommaList(), TaleTextGenerator.GenerateTextFromTale(TextGenerationPurpose.ArtDescription, tale, Rand.Int, RulePackDefOf.ArtDescription_Sculpture)));
            }
            if (flag)
            {
                return(null);
            }
            Find.TaleManager.Add(tale);
            for (int j = 0; j < args.Length; j++)
            {
                Pawn pawn2 = args[j] as Pawn;
                if (pawn2 != null)
                {
                    if (!pawn2.Dead && pawn2.needs.mood != null)
                    {
                        pawn2.needs.mood.thoughts.situational.Notify_SituationalThoughtsDirty();
                    }
                    pawn2.records.AccumulateStoryEvent(StoryEventDefOf.TaleCreated);
                }
            }
            return(tale);
        }
Beispiel #10
0
 private void RemoveTale(Tale tale)
 {
     if (!tale.Unused)
     {
         Log.Warning("Tried to remove used tale " + tale, false);
         return;
     }
     this.tales.Remove(tale);
 }
Beispiel #11
0
        public static Tale MakeRandomTestTale(TaleDef def = null)
        {
            if (def == null)
            {
                def = DefDatabase <TaleDef> .AllDefs.Where((TaleDef d) => d.usableForArt).RandomElement();
            }
            Tale tale = MakeRawTale(def);

            tale.GenerateTestData();
            return(tale);
        }
Beispiel #12
0
 private void RemoveTale(Tale tale)
 {
     if (!tale.Unused)
     {
         Log.Warning("Tried to remove used tale " + tale);
     }
     else
     {
         tales.Remove(tale);
     }
 }
        public static Tale MakeRandomTestTale(TaleDef def = null)
        {
            if (def == null)
            {
                def = (from d in DefDatabase <TaleDef> .AllDefs
                       where d.usableForArt
                       select d).RandomElement <TaleDef>();
            }
            Tale tale = TaleFactory.MakeRawTale(def, new object[0]);

            tale.GenerateTestData();
            return(tale);
        }
Beispiel #14
0
        public Tale GetLatestTale(TaleDef def, Pawn pawn)
        {
            Tale tale = null;
            int  num  = 0;

            for (int i = 0; i < this.tales.Count; i++)
            {
                if (this.tales[i].def == def && this.tales[i].DominantPawn == pawn && (tale == null || this.tales[i].AgeTicks < num))
                {
                    tale = this.tales[i];
                    num  = this.tales[i].AgeTicks;
                }
            }
            return(tale);
        }
 public static Tale MakeRawTale(TaleDef def, params object[] args)
 {
     try
     {
         Tale tale = (Tale)Activator.CreateInstance(def.taleClass, args);
         tale.def  = def;
         tale.id   = Find.UniqueIDsManager.GetNextTaleID();
         tale.date = Find.TickManager.TicksAbs;
         return(tale);
     }
     catch (Exception arg)
     {
         Log.Error(string.Format("Failed to create tale object {0} with parameters {1}: {2}", def, GenText.ToCommaList(args.Select(Gen.ToStringSafe <object>), true), arg));
         return(null);
     }
 }
Beispiel #16
0
 public static Tale MakeRawTale(TaleDef def, params object[] args)
 {
     try
     {
         Tale obj = (Tale)Activator.CreateInstance(def.taleClass, args);
         obj.def  = def;
         obj.id   = Find.UniqueIDsManager.GetNextTaleID();
         obj.date = Find.TickManager.TicksAbs;
         return(obj);
     }
     catch (Exception arg2)
     {
         Log.Error($"Failed to create tale object {def} with parameters {args.Select((object arg) => arg.ToStringSafe()).ToCommaList()}: {arg2}");
         return(null);
     }
 }
Beispiel #17
0
        public override float OpinionOffset()
        {
            Tale latestTale = Find.TaleManager.GetLatestTale(this.def.taleDef, this.otherPawn);

            if (latestTale != null)
            {
                float num = 1f;
                if (latestTale.def.type == TaleType.Expirable)
                {
                    float value = (float)latestTale.AgeTicks / (latestTale.def.expireDays * 60000f);
                    num = Mathf.InverseLerp(1f, this.def.lerpOpinionToZeroAfterDurationPct, value);
                }
                return(base.CurStage.baseOpinionOffset * num);
            }
            return(0f);
        }
        public TaleReference GetRandomTaleReferenceForArtConcerning(Thing th)
        {
            if (this.tales.Count == 0)
            {
                return(TaleReference.Taleless);
            }
            Tale tale = default(Tale);

            if (!(from x in this.tales
                  where x.def.usableForArt && x.Concerns(th)
                  select x).TryRandomElementByWeight <Tale>((Func <Tale, float>)((Tale x) => x.InterestLevel), out tale))
            {
                return(TaleReference.Taleless);
            }
            tale.Notify_NewlyUsed();
            return(new TaleReference(tale));
        }
Beispiel #19
0
        public float GetMaxHistoricalTaleDay()
        {
            float num = 0f;

            for (int i = 0; i < this.tales.Count; i++)
            {
                Tale tale = this.tales[i];
                if (tale.def.type == TaleType.PermanentHistorical)
                {
                    float num2 = (float)GenDate.TickAbsToGame(tale.date) / 60000f;
                    if (num2 > num)
                    {
                        num = num2;
                    }
                }
            }
            return(num);
        }
Beispiel #20
0
        public static Tale MakeRawTale(TaleDef def, params object[] args)
        {
            Tale result;

            try
            {
                Tale tale = (Tale)Activator.CreateInstance(def.taleClass, args);
                tale.def  = def;
                tale.id   = Find.UniqueIDsManager.GetNextTaleID();
                tale.date = Find.TickManager.TicksAbs;
                result    = tale;
            }
            catch (Exception arg)
            {
                Log.Error(string.Format("Failed to create tale object {0} with parameters {1}: {2}", def, args.Select(new Func <object, string>(Gen.ToStringSafe <object>)).ToCommaList(false), arg), false);
                result = null;
            }
            return(result);
        }
        public bool TryExecute(IncidentParms parms)
        {
            Map map;

            if ((map = parms.target as Map) != null && def.requireColonistsPresent && map.mapPawns.FreeColonistsSpawnedCount == 0)
            {
                return(true);
            }
            bool flag = TryExecuteWorker(parms);

            if (flag)
            {
                if (def.tale != null)
                {
                    Pawn pawn = null;
                    if (parms.target is Caravan)
                    {
                        pawn = ((Caravan)parms.target).RandomOwner();
                    }
                    else if (parms.target is Map)
                    {
                        pawn = ((Map)parms.target).mapPawns.FreeColonistsSpawned.RandomElementWithFallback();
                    }
                    else if (parms.target is World)
                    {
                        pawn = PawnsFinder.AllMapsCaravansAndTravelingTransportPods_Alive_FreeColonists_NoCryptosleep.RandomElementWithFallback();
                    }
                    if (pawn != null)
                    {
                        TaleRecorder.RecordTale(def.tale, pawn);
                    }
                }
                if (def.category.tale != null)
                {
                    Tale tale = TaleRecorder.RecordTale(def.category.tale);
                    if (tale != null)
                    {
                        tale.customLabel = def.label;
                    }
                }
            }
            return(flag);
        }
Beispiel #22
0
        public static string 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 result = GrammarResolver.Resolve(rootKeyword, request, (tale == null) ? "null_tale" : tale.def.defName);

            Rand.PopState();
            return(result);
        }
        public bool TryExecute(IncidentParms parms)
        {
            bool flag = this.TryExecuteWorker(parms);

            if (flag)
            {
                if (this.def.tale != null)
                {
                    Pawn pawn = null;
                    if (parms.target is Caravan)
                    {
                        pawn = ((Caravan)parms.target).RandomOwner();
                    }
                    else if (parms.target is Map)
                    {
                        pawn = ((Map)parms.target).mapPawns.FreeColonistsSpawned.RandomElementWithFallback(null);
                    }
                    else if (parms.target is World)
                    {
                        pawn = PawnsFinder.AllMapsCaravansAndTravelingTransportPods_Alive_FreeColonists_NoCryptosleep.RandomElementWithFallback(null);
                    }
                    if (pawn != null)
                    {
                        TaleRecorder.RecordTale(this.def.tale, new object[]
                        {
                            pawn
                        });
                    }
                }
                if (this.def.category.tale != null)
                {
                    Tale tale = TaleRecorder.RecordTale(this.def.category.tale, new object[0]);
                    if (tale != null)
                    {
                        tale.customLabel = this.def.label;
                    }
                }
            }
            return(flag);
        }
        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);
            if (purpose == TextGenerationPurpose.ArtDescription)
            {
                rootKeyword = "art_description_root";
                if (tale != null && Rand.Value > 0.2f)
                {
                    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);
            }
            else if (purpose == TextGenerationPurpose.ArtName)
            {
                rootKeyword = "art_name";
                if (tale != null)
                {
                    request.Rules.AddRange(tale.GetTextGenerationRules());
                }
            }
            string result = GrammarResolver.Resolve(rootKeyword, request, (tale == null) ? "null_tale" : tale.def.defName, false);

            Rand.PopState();
            return(result);
        }
Beispiel #25
0
 private void CheckCullTales(Tale addedTale)
 {
     this.CheckCullUnusedVolatileTales();
     this.CheckCullUnusedTalesWithMaxPerPawnLimit(addedTale);
 }
Beispiel #26
0
 public void Add(Tale tale)
 {
     this.tales.Add(tale);
     this.CheckCullTales(tale);
 }
Beispiel #27
0
 internal bool <> m__0(Tale x)
 {
     return(x.def.usableForArt && x.Concerns(this.th));
 }
Beispiel #28
0
 private static float <LogTaleInterestSummary> m__8(Tale t)
 {
     return(t.InterestLevel);
 }
Beispiel #29
0
 private static bool <LogTaleInterestSummary> m__7(Tale t)
 {
     return(t.def.usableForArt);
 }
Beispiel #30
0
 private static bool <LogTales> m__6(Tale x)
 {
     return(x.def.type == TaleType.Expirable && x.Unused);
 }