public static int QuadrumInteger(long absTicks, float longitude)
        {
            Quadrum quadrum = GenDate.Quadrum(absTicks, longitude);

            if (quadrum == Quadrum.Aprimay)
            {
                return(1);
            }
            else if (quadrum == Quadrum.Jugust)
            {
                return(2);
            }
            else if (quadrum == Quadrum.Septober)
            {
                return(3);
            }
            else if (quadrum == Quadrum.Decembary)
            {
                return(4);
            }
            else
            {
                return(0);
            }
        }
示例#2
0
        //GenDate
        public static void DateReadoutStringAt_PostFix(long absTicks, Vector2 location, ref string __result)
        {
            var num   = GenDate.DayOfSeason(absTicks, location.x) + 1;
            var value = Find.ActiveLanguageWorker.OrdinalNumber(num, Gender.None);

            __result = "TTA_DateReadout".Translate(value, GenDate.Quadrum(absTicks, location.x).Label(), GenDate.Year(absTicks, location.x), num);
        }
示例#3
0
        public static void PushState(Map map)
        {
            var world = Current.Game != null ? Current.Game.World : null;

            if (world == null)
            {
                RimRPC.prsnc.details = "Main Menu";
            }
            else
            {
                float latitude  = (map == null) ? 0f : Find.WorldGrid.LongLatOf(map.Tile).y;
                float longitude = (map == null) ? 0f : Find.WorldGrid.LongLatOf(map.Tile).x;
                colonyname = GetColonyName();
                days       = GenDate.DaysPassed;
                dayhour    = GenDate.HourOfDay(Find.TickManager.TicksAbs, longitude);
                //Season season = GenDate.Season(Find.TickManager.TicksAbs, latitude, longitude);
                //Quadrum updates seem enough.
                Quadrum quadrum = GenDate.Quadrum(Find.TickManager.TicksAbs, longitude);

                BiomeDef biome = Find.WorldGrid[map.uniqueID].biome;
                RimRPC.prsnc.state          = "Day " + days + " (" + dayhour + "h) | " + quadrum;
                RimRPC.prsnc.details        = colonyname;
                RimRPC.prsnc.largeImageText = "RimWorld";
                RimRPC.prsnc.smallImageKey  = "inmap";
                RimRPC.prsnc.smallImageText = "Playing!";
            }
            DiscordRPC.UpdatePresence(ref RimRPC.prsnc);
            Log.Message("[RichPressence] Pushed presence update to RPC.");
        }
示例#4
0
        public static void PushState(Map map)
        {
            var world = Current.Game != null ? Current.Game.World : null;

            if (world == null)
            {
                RimRPC.prsnc.details = "Main Menu";
            }
            else
            {
                float latitude  = (map == null) ? 0f : Find.WorldGrid.LongLatOf(map.Tile).y;
                float longitude = (map == null) ? 0f : Find.WorldGrid.LongLatOf(map.Tile).x;
                colonyname     = GetColonyName();
                years          = days / 60;
                colonistnumber = (float)PawnsFinder.AllMapsCaravansAndTravelingTransportPods_Alive_FreeColonists.Count <Pawn>();
                days           = GenDate.DaysPassed;
                dayhour        = GenDate.HourOfDay(Find.TickManager.TicksAbs, longitude);
                quadrum        = GenDate.Quadrum(Find.TickManager.TicksAbs, longitude);

                BiomeDef biome = Find.WorldGrid[map.uniqueID].biome;
                RimRPC.prsnc.state          = BuildString("state");
                RimRPC.prsnc.details        = BuildString("details");
                RimRPC.prsnc.largeImageText = "RimWorld";
                RimRPC.prsnc.smallImageKey  = "inmap";
                RimRPC.prsnc.smallImageText = "Playing!";
                if (RWRPCMod.settings.RPC_Time)
                {
                    RimRPC.prsnc.startTimestamp = RimRPC.started;
                }
            }
            DiscordRPC.UpdatePresence(ref RimRPC.prsnc);
        }
        private void UpdateAbsoluteFieldsFromTicks(int ticksToUse)
        {
            var tileCoords = RemindersGameComponent.VectorForTime;

            if (!tileCoords.HasValue)
            {
                return;
            }
            var absTicks = GenDate.TickGameToAbs(ticksToUse);
            var coords   = tileCoords.Value;

            yearValue  = GenDate.Year(absTicks, coords.x);
            yearBuffer = yearValue.ToString();

            quadrumValue = GenDate.Quadrum(absTicks, coords.x);

            dayValue  = GenDate.DayOfQuadrum(absTicks, coords.x) + 1;
            dayBuffer = dayValue.ToString();

            hourValue  = GenDate.HourOfDay(absTicks, coords.x);
            hourBuffer = hourValue.ToString();

            Log.Debug($"Set defaults to {dayBuffer} {quadrumValue}, {yearBuffer} at {hourBuffer}.");
            Log.Debug($"Should have set to {GenDate.DateFullStringWithHourAt(absTicks, coords)}.");
        }
示例#6
0
        private void SetDateInfo()
        {
            //RimWorld.DateReadout.DateOnGUI
            Vector2 location;

            if (WorldRendererUtility.WorldRenderedNow && Find.WorldSelector.selectedTile >= 0)
            {
                location = Find.WorldGrid.LongLatOf(Find.WorldSelector.selectedTile);
            }

            else if (WorldRendererUtility.WorldRenderedNow && Find.WorldSelector.NumSelectedObjects > 0)
            {
                location = Find.WorldGrid.LongLatOf(Find.WorldSelector.FirstSelectedObject.Tile);
            }

            else
            {
                if (Find.VisibleMap == null)
                {
                    return;
                }

                location = Find.WorldGrid.LongLatOf(Find.VisibleMap.Tile);
            }

            int gameTicks = Find.TickManager.gameStartAbsTick == 0 ? Find.TickManager.TicksGame : Find.TickManager.TicksAbs;             //Find.TickManager.TicksAbs errors if gameStartAbsTick is 0

            //RimWorld.GenDate.DateReadoutStringAt
            this.dateDayofSeason = GenDate.DayOfSeason(gameTicks, location.x) + 1;
            this.dateQuadrum     = GenDate.Quadrum(gameTicks, location.x);
            this.dateYear        = GenDate.Year(gameTicks, location.x);
        }
示例#7
0
        public static void PushState(Map map)
        {
            var world = Current.Game != null ? Current.Game.World : null;

            if (world == null)
            {
                RimRPC.prsnc.details = "Main Menu";
            }
            else
            {
                float latitude  = (map == null) ? 0f : Find.WorldGrid.LongLatOf(map.Tile).y;
                float longitude = (map == null) ? 0f : Find.WorldGrid.LongLatOf(map.Tile).x;
                colonyname     = GetColonyName();
                years          = days / 60;
                days           = GenDate.DaysPassed;
                dayhour        = GenDate.HourOfDay(Find.TickManager.TicksAbs, longitude);
                colonistnumber = (float)PawnsFinder.AllMapsCaravansAndTravelingTransportPods_Alive_FreeColonists.Count <Pawn>();
                //Season season = GenDate.Season(Find.TickManager.TicksAbs, latitude, longitude);
                //Quadrum updates seem enough.
                Quadrum quadrum = GenDate.Quadrum(Find.TickManager.TicksAbs, longitude);

                BiomeDef biome = Find.WorldGrid[map.uniqueID].biome;
                RimRPC.prsnc.state          = "Year " + years + " Day " + days + " (" + dayhour + "h) | " + quadrum;
                RimRPC.prsnc.details        = colonyname + ", " + colonistnumber + " Colonists";
                RimRPC.prsnc.largeImageText = "RimWorld";
                RimRPC.prsnc.smallImageKey  = "inmap";
                RimRPC.prsnc.smallImageText = "Playing!";
            }
            DiscordRPC.UpdatePresence(ref RimRPC.prsnc);
            //Log.Message("[RichPressence] Pushed presence update to RPC."); commented to remove log spam
        }
        // Token: 0x0600001A RID: 26 RVA: 0x00002714 File Offset: 0x00000914
        public override void MapComponentTick()
        {
            base.MapComponentTick();
            if (Find.TickManager.TicksGame % 30000 != 0)
            {
                return;
            }

            if (lastPartyYear == GenDate.YearsPassed)
            {
                //Log.Message(lastPartyYear.ToString());
                return;
            }

            once = true;

            if (!map.listerBuildings.AllBuildingsColonistOfDef(ThingDef.Named("ChristmasTreeBase")).Any() &&
                !map.listerBuildings.AllBuildingsColonistOfDef(ThingDef.Named("ChristmasTreeB")).Any() &&
                !map.listerBuildings.AllBuildingsColonistOfDef(ThingDef.Named("ChristmasTreeC")).Any() &&
                !map.listerBuildings.AllBuildingsColonistOfDef(ThingDef.Named("ChristmasTreeD")).Any())
            {
                //Log.Message("no tree");
                return;
            }

            var season     = GenDate.Season(GenTicks.TicksAbs, Find.WorldGrid.LongLatOf(map.Tile));
            var doTheThing = false;

            if (season == Season.PermanentSummer || season == Season.PermanentWinter)
            {
                //Log.Message("permanent season");
                if (GenDate.Quadrum(GenTicks.TicksAbs, Find.WorldGrid.LongLatOf(map.Tile).x) != Quadrum.Decembary)
                {
                    //Log.Message("not december");
                    return;
                }

                doTheThing = true;
            }

            if (!doTheThing && (season != Season.Winter ||
                                GenDate.DayOfSeason(GenTicks.TicksAbs, Find.WorldGrid.LongLatOf(map.Tile).x) < 2) ||
                !once)
            {
                //Log.Message("not winter");
                return;
            }

            //Log.Message("party");
            once = false;
            ExposeData();
            var incidentParms = StorytellerUtility.DefaultParmsNow(IncidentCategoryDefOf.Misc, map);

            incidentParms.forced = true;
            incidentParms.target = map;
            Find.Storyteller.incidentQueue.Add(XDefOf.PresentDrop, Find.TickManager.TicksGame, incidentParms, 240000);
            TryStartParty();
            lastPartyYear = GenDate.YearsPassed;
        }
示例#9
0
        private void updateBiomeSettings(bool force = false)
        {
            if (this.biomeSettings != null)
            {
                Vector2 location = Find.WorldGrid.LongLatOf(map.Tile);
                Season  season   = GenDate.Season((long)Find.TickManager.TicksAbs, location);
                Quadrum quadrum  = GenDate.Quadrum((long)Find.TickManager.TicksAbs, location.x);

                if (force == true || (biomeSettings.lastChanged != season && biomeSettings.lastChangedQ != quadrum))
                {
//					Log.Warning("Updating seasonal settings");
                    biomeSettings.setWeatherBySeason(map, season, quadrum);
                    biomeSettings.setDiseaseBySeason(season, quadrum);
                    biomeSettings.setIncidentsBySeason(season, quadrum);
                    biomeSettings.lastChanged  = season;
                    biomeSettings.lastChangedQ = quadrum;
                }
            }
        }
示例#10
0
        public static Quadrum CurrentQuadrum()
        {
            Vector2 vector;

            if (WorldRendererUtility.WorldRenderedNow && Find.WorldSelector.selectedTile >= 0)
            {
                vector = Find.WorldGrid.LongLatOf(Find.WorldSelector.selectedTile);
            }
            else if (WorldRendererUtility.WorldRenderedNow && Find.WorldSelector.NumSelectedObjects > 0)
            {
                vector = Find.WorldGrid.LongLatOf(Find.WorldSelector.FirstSelectedObject.Tile);
            }
            else
            {
                if (Find.CurrentMap == null)
                {
                    return(0);
                }
                vector = Find.WorldGrid.LongLatOf(Find.CurrentMap.Tile);
            }
            int num = (Find.TickManager.gameStartAbsTick == 0) ? Find.TickManager.TicksGame : Find.TickManager.TicksAbs;

            return(GenDate.Quadrum((long)num, vector.x));
        }
        public override void DoWindowContents(Rect rect)
        {
            const float scrollRectOffsetTop = ROW_HEIGHT * 2 + ROW_ADD_GAP;

            Text.Font = GameFont.Small;

            // draw event add row
            Rect rectAdd = new Rect(0f, 0f, ROW_ADD_WIDTH, ROW_HEIGHT);

            DrawRowAdd(rectAdd, () =>
            {
                _scrollPosition = new Vector2(0, ROW_HEIGHT * _store.MatteredDays.Count + ROW_HEIGHT * STATIC_ROW_COUNT - (rect.height - scrollRectOffsetTop));
            });

            // draw header
            Rect rectHeader = new Rect(0f, ROW_HEIGHT + ROW_ADD_GAP, rect.width - SCROLLBAR_WIDTH, ROW_HEIGHT);

            DrawHeader(rectHeader);

            // draw list
            if (_store.MatteredDays == null)
            {
                _store.MatteredDays = new List <MatteredDay>();
            }
            List <MatteredDay> list = _store.MatteredDays;

            Rect scrollRect = new Rect(0f, scrollRectOffsetTop, rect.width, rect.height - scrollRectOffsetTop);
            Rect viewRect   = new Rect(0f, 0f, scrollRect.width - SCROLLBAR_WIDTH, ROW_HEIGHT * list.Count + ROW_HEIGHT * STATIC_ROW_COUNT);

            Widgets.BeginScrollView(scrollRect, ref _scrollPosition, viewRect);
            Vector2 cur = Vector2.zero;

            // settlement
            int     startTicks        = Find.TickManager.gameStartAbsTick;
            Quadrum settlementQuadrum = GenDate.Quadrum(startTicks, 0);
            int     settlementDay     = GenDate.DayOfQuadrum(startTicks, 0) + 1;

            DrawRowWithFixedDate(new Rect(0f, cur.y, viewRect.width, ROW_HEIGHT), ref cur, "DM.Tab.BuiltIn.Settlement".Translate(), settlementQuadrum, settlementDay, _store.Settlement, () =>
            {
                FloatMenuUtility.MakeMenu(Enum.GetValues(typeof(Duration)).Cast <Duration>(), duration => duration.Label(), duration => delegate
                {
                    _store.Settlement = duration;
                });
            });

            // birthdays
            DrawRowWithNoDate(new Rect(0f, cur.y, viewRect.width, ROW_HEIGHT), ref cur, "DM.Tab.BuiltIn.ChronologicalBirthday".Translate(), _store.Birthdays, () =>
            {
                FloatMenuUtility.MakeMenu(Enum.GetValues(typeof(Duration)).Cast <Duration>(), duration => duration.Label(), duration => delegate
                {
                    _store.Birthdays = duration;
                });
            }, "DM.Tab.Misc.ShowAll".Translate(), () =>
            {
                Find.WindowStack.Add(new DialogList(DialogList.ListType.Birthdays));
            });

            // lovers anniversaries
            DrawRowWithNoDate(new Rect(0f, cur.y, viewRect.width, ROW_HEIGHT), ref cur, "DM.Tab.BuiltIn.RelationshipAnniversary".Translate(), _store.LoversAnniversaries, () =>
            {
                FloatMenuUtility.MakeMenu(Enum.GetValues(typeof(Duration)).Cast <Duration>(), duration => duration.Label(), duration => delegate
                {
                    _store.LoversAnniversaries = duration;
                });
            }, "DM.Tab.Misc.ShowAll".Translate(), () =>
            {
                Find.WindowStack.Add(new DialogList(DialogList.ListType.Relationships));
            });

            // marriage anniversaries
            DrawRowWithNoDate(new Rect(0f, cur.y, viewRect.width, ROW_HEIGHT), ref cur, "DM.Tab.BuiltIn.MarriageAnniversary".Translate(), _store.MarriageAnniversaries, () =>
            {
                FloatMenuUtility.MakeMenu(Enum.GetValues(typeof(Duration)).Cast <Duration>(), duration => duration.Label(), duration => delegate
                {
                    _store.MarriageAnniversaries = duration;
                });
            }, "DM.Tab.Misc.ShowAll".Translate(), () =>
            {
                Find.WindowStack.Add(new DialogList(DialogList.ListType.Marriages));
            });

            for (int index = 0; index < list.Count; index++)
            {
                if (list.Count <= index)
                {
                    break;
                }

                var row = new Rect(0f, cur.y, viewRect.width, ROW_HEIGHT);

                Widgets.DrawHighlightIfMouseover(row);
                GUI.color = new Color(1f, 1f, 1f, 0.2f);
                Widgets.DrawLineHorizontal(0f, cur.y, viewRect.width);
                GUI.color = Color.white;

                DrawRow(row, list[index], index);

                cur.y += ROW_HEIGHT;
            }
            Widgets.EndScrollView();
        }
示例#12
0
        public static bool Prefix(Rect dateRect)
        {
            //--------------------------------------------
            if (GetClocks(Find.VisibleMap).Count() == 0)
            {
                return(true);                                         //use original method
            }
            if (clockAccuracy < 0)
            {
                Log.Warning("Found clock but clockAccuracy not set. Setting to Analog.");
                clockAccuracy = 0;
            }
            //

            //Vector2 location;
            //In event of transpiler just get local variable at end
            if (WorldRendererUtility.WorldRenderedNow && Find.WorldSelector.selectedTile >= 0)
            {
                location = Find.WorldGrid.LongLatOf(Find.WorldSelector.selectedTile);
            }
            else if (WorldRendererUtility.WorldRenderedNow && Find.WorldSelector.NumSelectedObjects > 0)
            {
                location = Find.WorldGrid.LongLatOf(Find.WorldSelector.FirstSelectedObject.Tile);
            }
            else
            {
                if (Find.VisibleMap == null)
                {
                    return(false);
                }
                location = Find.WorldGrid.LongLatOf(Find.VisibleMap.Tile);
            }
            index = GenDate.HourInteger(Find.TickManager.TicksAbs, location.x);
            int     num     = GenDate.DayOfTwelfth(Find.TickManager.TicksAbs, location.x);
            Season  season  = GenDate.Season(Find.TickManager.TicksAbs, location);
            Quadrum quadrum = GenDate.Quadrum(Find.TickManager.TicksAbs, location.x);
            int     num2    = GenDate.Year(Find.TickManager.TicksAbs, location.x);

            if (num != dateStringDay || season != dateStringSeason || quadrum != dateStringQuadrum || num2 != dateStringYear)
            {
                dateString        = GenDate.DateReadoutStringAt(Find.TickManager.TicksAbs, location);
                dateStringDay     = num;
                dateStringSeason  = season;
                dateStringQuadrum = quadrum;
                dateStringYear    = num2;
            }
            Text.Font = GameFont.Small;
            float num3 = Mathf.Max(Text.CalcSize(fastHourStrings[index]).x, Text.CalcSize(dateString).x + 7f);

            dateRect.xMin = dateRect.xMax - num3;
            if (Mouse.IsOver(dateRect))
            {
                Widgets.DrawHighlight(dateRect);
            }
            GUI.BeginGroup(dateRect);
            Text.Font   = GameFont.Small;
            Text.Anchor = TextAnchor.UpperRight;
            Rect rect = dateRect.AtZero();

            rect.xMax -= 7f;
            //-----------------------------------------------------
            hrtime = (index < 12) ? "amannotation".Translate(fastHourStrings[index].ToString() + currentMin) : "pmannotation".Translate(fastHourStrings[index].ToString() + currentMin);
            Widgets.Label(rect, hrtime);
            //
            //Widgets.Label(rect, fastHourStrings[index]); REPLACED
            rect.yMin += 26f;
            Widgets.Label(rect, dateString);
            Text.Anchor = TextAnchor.UpperLeft;
            GUI.EndGroup();
            //Remember - this delegate in itself is its own local method (m_XXX)
            //IL code: ldftn instance string RimWorld.DateReadout/'<DateOnGUI>c__AnonStorey449'::'<>m__64B'()
            TooltipHandler.TipRegion(dateRect, new TipSignal(delegate
            {
                StringBuilder stringBuilder = new StringBuilder();
                for (int i = 0; i < 4; i++)
                {
                    Quadrum quadrum2 = (Quadrum)i;
                    stringBuilder.AppendLine(quadrum2.Label() + " - " + quadrum2.GetSeason(location.y).LabelCap());
                }
                return("DateReadoutTip".Translate(new object[]
                {
                    GenDate.DaysPassed,
                    15,
                    season.LabelCap(),
                    15,
                    GenDate.Quadrum((long)GenTicks.TicksAbs, location.x).Label(),
                    stringBuilder.ToString()
                })
                       //-------------------------------------------
                       + (clockAccuracy > 0 ? "TicksAbsOnGUI".Translate(Find.TickManager.TicksGame) : string.Empty)
                       //
                       );
            }, 86423));
            return(false);
        }
示例#13
0
        public override void Tick(int currentTick)
        {
            base.Tick(currentTick);

            int ticks = Find.TickManager.TicksAbs;

            if (ticks % GenDate.TicksPerHour != 0 || Find.CurrentMap == null || _store == null)
            {
                return;
            }

            Vector2 location     = Find.WorldGrid.LongLatOf(Find.CurrentMap.Tile);
            Quadrum quadrum      = GenDate.Quadrum(ticks, location.x);
            int     dayOfQuadrum = GenDate.DayOfQuadrum(ticks, location.x); // zero based
            int     hour         = GenDate.HourOfDay(ticks, location.x);

            // check settlement
            int     startTicks        = Find.TickManager.gameStartAbsTick;
            Quadrum settlementQuadrum = GenDate.Quadrum(startTicks, 0);
            int     settlementDay     = GenDate.DayOfQuadrum(startTicks, 0); // zero based
            int     settlementYears   = Mathf.RoundToInt(GenDate.YearsPassedFloat);

            if ((hour == 0 || _store.Settlement.Start() == hour) && settlementQuadrum == quadrum && settlementDay == dayOfQuadrum)
            {
                if (hour == 0)
                {
                    Messages.Message("DM.Message.TodaySettlement".Translate(settlementYears), MessageTypeDefOf.PositiveEvent);
                }
                else
                {
                    StartParty("DM.Letter.SettlementParty".Translate(), new List <Pawn>(), _store.Settlement == Duration.AllDay);
                }
            }

            // check built in days
            if (hour == 0 || _store.Birthdays.Start() == hour || _store.MarriageAnniversaries.Start() == hour || _store.LoversAnniversaries.Start() == hour)
            {
                Dictionary <Pawn, DirectPawnRelation> handledRelations = new Dictionary <Pawn, DirectPawnRelation>();

                var colonists = Find.CurrentMap.mapPawns.PawnsInFaction(Faction.OfPlayer);
                foreach (var colonist in colonists)
                {
                    if (colonist.Dead || !colonist.RaceProps.Humanlike)
                    {
                        continue;
                    }

                    // check marriage
                    List <DirectPawnRelation> marriageRelations = colonist.relations.DirectRelations.FindAll(x => x.def == PawnRelationDefOf.Spouse);
                    foreach (DirectPawnRelation relation in marriageRelations)
                    {
                        if (handledRelations.ContainsKey(colonist) || handledRelations.ContainsKey(relation.otherPawn))
                        {
                            continue;
                        }
                        handledRelations.Add(colonist, relation);
                        int     startTick    = relation.startTicks + startTicks;
                        int     startDay     = GenDate.DayOfQuadrum(startTick, location.x);
                        Quadrum startQuadrum = GenDate.Quadrum(startTick, location.x);
                        if (startDay == dayOfQuadrum && startQuadrum == quadrum)
                        {
                            if (hour == 0)
                            {
                                Messages.Message("DM.Message.TodayMarriageAnniversary".Translate(colonist.Name.ToStringShort, relation.otherPawn.Name.ToStringShort), MessageTypeDefOf.PositiveEvent);
                            }
                            else if (_store.MarriageAnniversaries.Start() == hour)
                            {
                                StartParty("DM.Letter.MarriageAnniversaryParty".Translate(colonist.Name.ToStringShort, relation.otherPawn.Name.ToStringShort), new List <Pawn> {
                                    colonist, relation.otherPawn
                                }, _store.MarriageAnniversaries == Duration.AllDay, colonist);
                            }
                        }
                    }

                    // check relationship
                    List <DirectPawnRelation> loverRelations = colonist.relations.DirectRelations.FindAll(x => x.def == PawnRelationDefOf.Lover);
                    foreach (DirectPawnRelation relation in loverRelations)
                    {
                        if (handledRelations.ContainsKey(colonist) || handledRelations.ContainsKey(relation.otherPawn))
                        {
                            continue;
                        }
                        handledRelations.Add(colonist, relation);
                        int     startTick    = relation.startTicks + startTicks;
                        int     startDay     = GenDate.DayOfQuadrum(startTick, location.x);
                        Quadrum startQuadrum = GenDate.Quadrum(startTick, location.x);
                        if (startDay == dayOfQuadrum && startQuadrum == quadrum)
                        {
                            if (hour == 0)
                            {
                                Messages.Message("DM.Message.TodayRelationshipAnniversary".Translate(colonist.Name.ToStringShort, relation.otherPawn.Name.ToStringShort), MessageTypeDefOf.PositiveEvent);
                            }
                            else if (_store.LoversAnniversaries.Start() == hour)
                            {
                                StartParty("DM.Letter.RelationshipAnniversaryParty".Translate(colonist.Name.ToStringShort, relation.otherPawn.Name.ToStringShort), new List <Pawn> {
                                    colonist, relation.otherPawn
                                }, _store.LoversAnniversaries == Duration.AllDay, colonist);
                            }
                        }
                    }

                    // check birthday
                    long    birthdayTick = colonist.ageTracker.BirthAbsTicks;
                    int     birthDate    = GenDate.DayOfQuadrum(birthdayTick, location.x); // zero based
                    Quadrum birthQuadrum = GenDate.Quadrum(birthdayTick, location.x);
                    int     colonistAge  = Mathf.RoundToInt(colonist.ageTracker.AgeChronologicalYearsFloat);
                    if (birthDate == dayOfQuadrum && birthQuadrum == quadrum)
                    {
                        if (hour == 0)
                        {
                            Messages.Message("DM.Message.TodayBirthday".Translate(colonist.Name.ToStringShort, colonistAge), MessageTypeDefOf.PositiveEvent);
                        }
                        else if (_store.Birthdays.Start() == hour)
                        {
                            StartParty("DM.Letter.BirthdayParty".Translate(colonist.Name.ToStringShort), new List <Pawn>(), _store.Birthdays == Duration.AllDay);
                        }
                    }
                }
            }

            // check custom days
            var matchedEvents = _store.MatteredDays.FindAll(x => x.DayOfQuadrum - 1 == dayOfQuadrum && x.Quadrum == quadrum);

            if (matchedEvents.Count == 0)
            {
                return;
            }

            foreach (MatteredDay day in matchedEvents)
            {
                if (hour == 0)
                {
                    Messages.Message("DM.Message.TodayCustomDay".Translate(day.Name), MessageTypeDefOf.PositiveEvent);
                }
                else if (day.Duration.Start() == hour)
                {
                    StartParty("DM.Letter.CustomDayParty".Translate(day.Name), new List <Pawn>(), day.Duration == Duration.AllDay);
                }
            }
        }
示例#14
0
 public override void Tick(int currentTick)
 {
     //Performance reporting tick
     if (EnablePerformanceTesting() && currentTick % GenDate.TicksPerDay == 0 && PerformanceSetup.performanceTotals.Keys.Count > 0)
     {
         Dictionary <string, float> averages = PerformanceSetup.performanceTotals.ToDictionary(x => x.Key, x => (float)x.Value / (float)PerformanceSetup.performanceCalls[x.Key]);
         int topAmt = Math.Min(10, averages.Count);
         List <KeyValuePair <string, float> > avgTicks = (from avg in averages orderby avg.Value descending select avg).Take(topAmt).ToList();
         List <KeyValuePair <string, float> > topTicks = (from avg in averages orderby avg.Value * PerformanceSetup.performanceCalls[avg.Key] descending select avg).Take(topAmt).ToList();
         StringBuilder avgString = new StringBuilder();
         foreach (KeyValuePair <string, float> t in avgTicks)
         {
             avgString.AppendLine(t.Key + " (" + t.Value + ")");
         }
         StringBuilder topString = new StringBuilder();
         foreach (KeyValuePair <string, float> t in topTicks)
         {
             topString.AppendLine(t.Key + " (" + avgTicks.Find(x => x.Key == t.Key).Value + ")");
         }
         Log.Message("Psychology :: Performance Report :: Top " + topAmt + " average tick consumers:\n" + avgString.ToString() + "\nTop " + topAmt + " weighted tick consumers: " + topString.ToString());
     }
     //Constituent tick
     if (currentTick % GenDate.TicksPerHour * 2 == 0)
     {
         Map playerFactionMap            = Find.WorldObjects.SettlementBases.Find(b => b.Faction.IsPlayer).Map;
         IEnumerable <Pawn> constituents = (from p in playerFactionMap.mapPawns.FreeColonistsSpawned
                                            where !p.health.hediffSet.HasHediff(HediffDefOfPsychology.Mayor) && p.GetLord() == null && p.GetTimeAssignment() != TimeAssignmentDefOf.Work && p.Awake()
                                            select p);
         if (constituents.Count() > 0)
         {
             Pawn potentialConstituent       = constituents.RandomElementByWeight(p => 0.0001f + Mathf.Pow(Mathf.Abs(0.7f - p.needs.mood.CurLevel), 2));
             IEnumerable <Pawn> activeMayors = (from m in playerFactionMap.mapPawns.FreeColonistsSpawned
                                                where !m.Dead && m.health.hediffSet.HasHediff(HediffDefOfPsychology.Mayor) && ((Hediff_Mayor)m.health.hediffSet.GetFirstHediffOfDef(HediffDefOfPsychology.Mayor)).worldTileElectedOn == potentialConstituent.Map.Tile &&
                                                m.GetTimeAssignment() != TimeAssignmentDefOf.Work && m.GetTimeAssignment() != TimeAssignmentDefOf.Sleep && m.GetLord() == null && m.Awake() && m.GetLord() == null
                                                select m);
             if (potentialConstituent != null && !potentialConstituent.Downed && !potentialConstituent.Drafted && potentialConstituent.health.summaryHealth.SummaryHealthPercent >= 1f && potentialConstituent.GetTimeAssignment() != TimeAssignmentDefOf.Work && activeMayors.Count() > 0)
             {
                 Pawn    mayor  = activeMayors.RandomElement(); //There should only be one.
                 IntVec3 gather = default(IntVec3);
                 String  found  = null;
                 if (mayor.Map.GetComponent <OfficeTableMapComponent>().officeTable != null)
                 {
                     gather = mayor.Map.GetComponent <OfficeTableMapComponent>().officeTable.parent.Position;
                     found  = "office";
                 }
                 else if (mayor.ownership != null && mayor.ownership.OwnedBed != null)
                 {
                     gather = mayor.ownership.OwnedBed.Position;
                     found  = "bed";
                 }
                 if (PsycheHelper.PsychologyEnabled(potentialConstituent) && Rand.Chance((1f - PsycheHelper.Comp(potentialConstituent).Psyche.GetPersonalityRating(PersonalityNodeDefOf.Independent)) / 5f) && (found != null || RCellFinder.TryFindPartySpot(mayor, out gather)) &&
                     (!mayor.Drafted && !mayor.Downed && mayor.health.summaryHealth.SummaryHealthPercent >= 1f && mayor.GetTimeAssignment() != TimeAssignmentDefOf.Work && (mayor.CurJob == null || mayor.CurJob.def != JobDefOf.TendPatient)))
                 {
                     List <Pawn> pawns = new List <Pawn>();
                     pawns.Add(mayor);
                     pawns.Add(potentialConstituent);
                     Lord meeting = LordMaker.MakeNewLord(mayor.Faction, new LordJob_VisitMayor(gather, potentialConstituent, mayor, (potentialConstituent.needs.mood.CurLevel < (potentialConstituent.mindState.mentalBreaker.BreakThresholdMinor * 1.25f))), mayor.Map, pawns);
                     mayor.jobs.EndCurrentJob(Verse.AI.JobCondition.InterruptForced);
                     potentialConstituent.jobs.EndCurrentJob(Verse.AI.JobCondition.InterruptForced);
                     if (found == "bed")
                     {
                         mayor.needs.mood.thoughts.memories.TryGainMemory(ThoughtDefOfPsychology.MayorNoOffice);
                     }
                     else if (found == null)
                     {
                         mayor.needs.mood.thoughts.memories.TryGainMemory(ThoughtDefOfPsychology.MayorNoBedroom);
                     }
                 }
             }
         }
     }
     //Election tick
     if (currentTick % (GenDate.TicksPerDay / 4f) == 0)
     {
         foreach (Settlement settlement in Find.WorldObjects.Settlements)
         {
             //Self-explanatory.
             if (!PsychologyBase.ActivateElections())
             {
                 continue;
             }
             //If the base isn't owned or named by the player, no election can be held.
             if (!settlement.Faction.IsPlayer || !settlement.namedByPlayer)
             {
                 continue;
             }
             //If the base is not at least a year old, no election will be held.
             if ((Find.TickManager.TicksGame - settlement.creationGameTicks) / GenDate.TicksPerYear < 1)
             {
                 continue;
             }
             //A base must have at least 7 people in it to hold an election.
             if (settlement.Map.mapPawns.FreeColonistsSpawnedCount < 7)
             {
                 continue;
             }
             //If an election is already being held, don't start a new one.
             if (settlement.Map.gameConditionManager.ConditionIsActive(GameConditionDefOfPsychology.Election) || settlement.Map.lordManager.lords.Find(l => l.LordJob is LordJob_Joinable_Election) != null)
             {
                 continue;
             }
             //Elections are held in Septober (because I guess some maps don't have fall?) and during the day.
             if (GenDate.Quadrum(Find.TickManager.TicksAbs, Find.WorldGrid.LongLatOf(settlement.Tile).x) != Quadrum.Septober || (GenLocalDate.HourOfDay(settlement.Map) < 7 || GenLocalDate.HourOfDay(settlement.Map) > 20))
             {
                 continue;
             }
             //If an election has already been completed this year, don't start a new one.
             IEnumerable <Pawn> activeMayors = (from m in settlement.Map.mapPawns.FreeColonistsSpawned
                                                where !m.Dead && m.health.hediffSet.HasHediff(HediffDefOfPsychology.Mayor) && ((Hediff_Mayor)m.health.hediffSet.GetFirstHediffOfDef(HediffDefOfPsychology.Mayor)).worldTileElectedOn == settlement.Map.Tile && ((Hediff_Mayor)m.health.hediffSet.GetFirstHediffOfDef(HediffDefOfPsychology.Mayor)).yearElected == GenLocalDate.Year(settlement.Map.Tile)
                                                select m);
             if (activeMayors.Count() > 0)
             {
                 continue;
             }
             //Try to space out the elections so they don't all proc at once.
             if (Rand.RangeInclusive(1, 15 - GenLocalDate.DayOfQuadrum(settlement.Map.Tile)) > 1)
             {
                 continue;
             }
             IncidentParms parms = new IncidentParms();
             parms.target  = settlement.Map;
             parms.faction = settlement.Faction;
             FiringIncident fi = new FiringIncident(IncidentDefOfPsychology.Election, null, parms);
             Find.Storyteller.TryFire(fi);
         }
     }
 }
示例#15
0
        public static bool Prefix(
            Rect dateRect,
            ref List <string> ___seasonsCached,
            ref int ___dateStringDay,
            ref Season ___dateStringSeason,
            ref Quadrum ___dateStringQuadrum,
            ref int ___dateStringYear,
            ref string ___dateString
            )
        {
            Vector2 vector2;

            if (WorldRendererUtility.WorldRenderedNow && Find.WorldSelector.selectedTile >= 0)
            {
                vector2 = Find.WorldGrid.LongLatOf(Find.WorldSelector.selectedTile);
            }
            else if (WorldRendererUtility.WorldRenderedNow && Find.WorldSelector.NumSelectedObjects > 0)
            {
                vector2 = Find.WorldGrid.LongLatOf(Find.WorldSelector.FirstSelectedObject.Tile);
            }
            else
            {
                if (Find.CurrentMap == null)
                {
                    return(false);
                }
                vector2 = Find.WorldGrid.LongLatOf(Find.CurrentMap.Tile);
            }

            var num1     = GenDate.DayOfTwelfth(Find.TickManager.TicksAbs, vector2.x);
            var season   = GenDate.Season(Find.TickManager.TicksAbs, vector2);
            var quadrum1 = GenDate.Quadrum(Find.TickManager.TicksAbs, vector2.x);
            var num2     = GenDate.Year(Find.TickManager.TicksAbs, vector2.x);
            var str      = true ? ___seasonsCached[(int)season] : "";

            if (num1 != ___dateStringDay || season != ___dateStringSeason || quadrum1 != ___dateStringQuadrum || num2 != ___dateStringYear)
            {
                ___dateString        = GenDate.DateReadoutStringAt(Find.TickManager.TicksAbs, vector2);
                ___dateStringDay     = num1;
                ___dateStringSeason  = season;
                ___dateStringQuadrum = quadrum1;
                ___dateStringYear    = num2;
            }

            var userTime = "";

            if (!BetterTimeFormatMod.UpdateTime)
            {
                userTime = BetterTimeFormatMod.settings.timeFormat;
                var dayPercent = GenLocalDate.DayPercent(Find.CurrentMap);

                if (BetterTimeFormatMod.UpdateHours)
                {
                    var hours = Math.Floor(dayPercent * 24);
                    if (BetterTimeFormatMod.settings.twelveHourFormat)
                    {
                        hours = dayPercent < 0.6 ? hours : hours - 12;
                    }

                    userTime = userTime.ReplaceFirst("HH", $"{hours,0:00}");
                    userTime = userTime.ReplaceFirst("H", $"{hours,0}");
                }

                if (BetterTimeFormatMod.UpdateMinutes)
                {
                    var minutes = Math.Floor(dayPercent * 24 % 1 * 60);
                    userTime = userTime.ReplaceFirst("MM", $"{minutes,0:00}");
                    userTime = userTime.ReplaceFirst("M", $"{minutes,0:0}");
                }

                if (BetterTimeFormatMod.UpdateSeconds)
                {
                    var seconds = Math.Floor(dayPercent * 24 % 1 * 60 % 1 * 60);
                    userTime = userTime.ReplaceFirst("SS", $"{seconds,0:00}");
                    userTime = userTime.ReplaceFirst("S", $"{seconds,0:0}");
                }

                if (BetterTimeFormatMod.settings.twelveHourFormat)
                {
                    var notation = dayPercent < 0.5 ? BetterTimeFormatMod.settings.amString : BetterTimeFormatMod.settings.pmString;
                    userTime = userTime.ReplaceFirst("N", notation);
                }
            }

            Text.Font = GameFont.Small;
            var num3 =
                Mathf.Max(Mathf.Max(Text.CalcSize(userTime).x, Text.CalcSize(___dateString).x), Text.CalcSize(str).x) + 7f;

            dateRect.xMin = dateRect.xMax - num3;
            if (Mouse.IsOver(dateRect))
            {
                Widgets.DrawHighlight(dateRect);
            }
            GUI.BeginGroup(dateRect);
            Text.Font   = GameFont.Small;
            Text.Anchor = TextAnchor.UpperRight;
            var rect = dateRect.AtZero();

            rect.xMax -= 7f;
            Widgets.Label(rect, userTime);
            rect.yMin += 26f;
            Widgets.Label(rect, ___dateString);
            rect.yMin += 26f;
            if (!str.NullOrEmpty())
            {
                Widgets.Label(rect, str);
            }
            Text.Anchor = TextAnchor.UpperLeft;
            GUI.EndGroup();
            if (!Mouse.IsOver(dateRect))
            {
                return(false);
            }
            var stringBuilder = new StringBuilder();

            for (var index2 = 0; index2 < 4; ++index2)
            {
                var quadrum2 = (Quadrum)index2;
                stringBuilder.AppendLine(quadrum2.Label() + " - " + quadrum2.GetSeason(vector2.y).LabelCap());
            }

            var taggedString = "DateReadoutTip".Translate(GenDate.DaysPassed, 15, (NamedArgument)season.LabelCap(), 15,
                                                          (NamedArgument)GenDate.Quadrum(GenTicks.TicksAbs, vector2.x).Label(), (NamedArgument)stringBuilder.ToString());

            TooltipHandler.TipRegion(dateRect, new TipSignal(taggedString, 86423));

            return(false);
        }
示例#16
0
        protected override string GetIconTip(Pawn pawn)
        {
            Tenant tenantComp = pawn.GetTenantComponent();

            if (tenantComp != null && !tenantComp.IsTenant)
            {
                return(string.Empty);
            }
            string value = "FullDate".Translate(Find.ActiveLanguageWorker.OrdinalNumber(GenDate.DayOfSeason(tenantComp.ContractEndDate, 0f)), QuadrumUtility.Label(GenDate.Quadrum(tenantComp.ContractEndDate, 0f)), GenDate.Year(tenantComp.ContractEndDate, 0f));
            string a     = "ContractEndDate".Translate(value);
            string b     = "ContractPayment".Translate(tenantComp.Payment * tenantComp.ContractLength / 60000);
            string c     = "ContractLength".Translate(tenantComp.ContractLength / 60000);
            string d     = "ContractDaily".Translate(tenantComp.Payment);

            return(a + " \n " + b + " \n " + c + " \n " + d);
        }
示例#17
0
        public DialogList(ListType type)
        {
            forcePause = true;
            doCloseX   = true;
            // closeOnEscapeKey = true;
            closeOnClickedOutside   = true;
            absorbInputAroundWindow = true;

            int gameStartTick = Find.TickManager.gameStartAbsTick;
            var colonists     = Find.CurrentMap.mapPawns.PawnsInFaction(Faction.OfPlayer);

            switch (type)
            {
            case ListType.Birthdays:
                foreach (var colonist in colonists)
                {
                    if (colonist.Dead || colonist.NonHumanlikeOrWildMan())
                    {
                        continue;
                    }

                    long    birthdayTick = colonist.ageTracker.BirthAbsTicks;
                    int     birthDate    = GenDate.DayOfQuadrum(birthdayTick, 0); // zero based
                    Quadrum birthQuadrum = GenDate.Quadrum(birthdayTick, 0);
                    _list.Add(new QuadrumDayPair("DM.Letter.BirthdayParty".Translate(colonist.Name.ToStringShort), birthQuadrum, birthDate + 1));
                }
                break;

            case ListType.Relationships:
                Dictionary <Pawn, DirectPawnRelation> loverRelations = new Dictionary <Pawn, DirectPawnRelation>();
                foreach (var colonist in colonists)
                {
                    if (colonist.Dead || colonist.NonHumanlikeOrWildMan())
                    {
                        continue;
                    }

                    List <DirectPawnRelation> relations = colonist.relations.DirectRelations.FindAll(x => x.def == PawnRelationDefOf.Lover);
                    foreach (DirectPawnRelation relation in relations)
                    {
                        if (loverRelations.ContainsKey(colonist) || loverRelations.ContainsKey(relation.otherPawn))
                        {
                            continue;
                        }
                        loverRelations.Add(colonist, relation);
                        int     startTick    = relation.startTicks + gameStartTick;
                        int     startDay     = GenDate.DayOfQuadrum(startTick, 0);
                        Quadrum startQuadrum = GenDate.Quadrum(startTick, 0);
                        _list.Add(new QuadrumDayPair("DM.Letter.RelationshipAnniversaryParty".Translate(colonist.Name.ToStringShort, relation.otherPawn.Name.ToStringShort), startQuadrum, startDay + 1));
                    }
                }
                break;

            case ListType.Marriages:
                Dictionary <Pawn, DirectPawnRelation> marriageRelations = new Dictionary <Pawn, DirectPawnRelation>();
                foreach (var colonist in colonists)
                {
                    if (colonist.Dead || colonist.NonHumanlikeOrWildMan())
                    {
                        continue;
                    }

                    List <DirectPawnRelation> relations = colonist.relations.DirectRelations.FindAll(x => x.def == PawnRelationDefOf.Spouse);
                    foreach (DirectPawnRelation relation in relations)
                    {
                        if (marriageRelations.ContainsKey(colonist) || marriageRelations.ContainsKey(relation.otherPawn))
                        {
                            continue;
                        }
                        marriageRelations.Add(colonist, relation);
                        int     startTick    = relation.startTicks + gameStartTick;
                        int     startDay     = GenDate.DayOfQuadrum(startTick, 0);
                        Quadrum startQuadrum = GenDate.Quadrum(startTick, 0);
                        _list.Add(new QuadrumDayPair("DM.Letter.MarriageAnniversaryParty".Translate(colonist.Name.ToStringShort, relation.otherPawn.Name.ToStringShort), startQuadrum, startDay + 1));
                    }
                }
                break;

            default:
                break;
            }
        }
示例#18
0
        public static Date CurrentDate()
        {
            Vector2 vector;

            if (WorldRendererUtility.WorldRenderedNow && Find.WorldSelector.selectedTile >= 0)
            {
                vector = Find.WorldGrid.LongLatOf(Find.WorldSelector.selectedTile);
            }
            else if (WorldRendererUtility.WorldRenderedNow && Find.WorldSelector.NumSelectedObjects > 0)
            {
                vector = Find.WorldGrid.LongLatOf(Find.WorldSelector.FirstSelectedObject.Tile);
            }
            else
            {
                if (Find.CurrentMap == null)
                {
                    return(null);
                }
                vector = Find.WorldGrid.LongLatOf(Find.CurrentMap.Tile);
            }
            int num = (Find.TickManager.gameStartAbsTick == 0) ? Find.TickManager.TicksGame : Find.TickManager.TicksAbs;
            int day = GenDate.DayOfSeason((long)num, vector.x) + 1;


            if (WorldRendererUtility.WorldRenderedNow && Find.WorldSelector.selectedTile >= 0)
            {
                vector = Find.WorldGrid.LongLatOf(Find.WorldSelector.selectedTile);
            }
            else if (WorldRendererUtility.WorldRenderedNow && Find.WorldSelector.NumSelectedObjects > 0)
            {
                vector = Find.WorldGrid.LongLatOf(Find.WorldSelector.FirstSelectedObject.Tile);
            }
            else
            {
                if (Find.CurrentMap == null)
                {
                    return(null);
                }
                vector = Find.WorldGrid.LongLatOf(Find.CurrentMap.Tile);
            }
            int     num2    = (Find.TickManager.gameStartAbsTick == 0) ? Find.TickManager.TicksGame : Find.TickManager.TicksAbs;
            Quadrum quadrum = GenDate.Quadrum((long)num2, vector.x);

            if (WorldRendererUtility.WorldRenderedNow && Find.WorldSelector.selectedTile >= 0)
            {
                vector = Find.WorldGrid.LongLatOf(Find.WorldSelector.selectedTile);
            }
            else if (WorldRendererUtility.WorldRenderedNow && Find.WorldSelector.NumSelectedObjects > 0)
            {
                vector = Find.WorldGrid.LongLatOf(Find.WorldSelector.FirstSelectedObject.Tile);
            }
            else
            {
                if (Find.CurrentMap == null)
                {
                    return(null);
                }
                vector = Find.WorldGrid.LongLatOf(Find.CurrentMap.Tile);
            }
            int num3 = (Find.TickManager.gameStartAbsTick == 0) ? Find.TickManager.TicksGame : Find.TickManager.TicksAbs;

            int year = GenDate.Year((long)num3, vector.x);


            return(new Date(day, quadrum, year));
        }