public override void TickRare() { if (destroyedFlag) // Do nothing further, when destroyed (just a safety) { return; } if (!this.Spawned) { return; } // Don't forget the base work base.TickRare(); if (this.currentState != State.lesson) { if (seasonSchedule[GenLocalDate.DayOfSeason(this.Map)] != 0 && seasonSchedule[GenLocalDate.DayOfSeason(this.Map)] != 4) { if (GenLocalDate.HourOfDay(this.Map) == this.lessonHour) { TryTimedLesson(); } } } else { for (int i = 0; i < 2; i++) { if (teachers[i] != null) { bool flag = false; if (!isLeader(teachers[i])) { flag = true; } if (!teachers[i].IsColonistPlayerControlled) { flag = true; } if (teachers[i].Dead) { flag = true; } if (flag) { teachers[i] = null; } ; } } } LessonRareTick(); }
public bool AnyShouldDoNow() { if (GenLocalDate.DayOfSeason(Find.CurrentMap) == dayNumber) { return(tasks.Any(x => x.ShouldDoNow())); } return(false); }
public static bool DayOfSeasonWithin(this Pawn p, List <IntRange> parameters) { if (p.Map == null) { return(false); } int val = GenLocalDate.DayOfSeason(p); return(parameters.Any(ir => ir.min >= val && ir.max <= val)); }
public bool ShouldDoNow(ActivityTask task) { if (tasks.Contains(task)) { if (GenLocalDate.DayOfSeason(Find.CurrentMap) == dayNumber && task.ShouldDoNow()) { return(true); } } return(false); }
private void TryTimedLesson() { int teacherInt = seasonSchedule[GenLocalDate.DayOfSeason(this.Map)]; if (teacherInt >= 3) { tempTeacher = TeachingUtility.DetermineTeacher(this.Map); } else { tempTeacher = teachers[teacherInt - 1]; } TryLesson(); }
protected override bool CanFireNowSub(IncidentParms parms) { if (!settings.Active) { return(false); } Map map = (Map)parms.target; Season season = GenLocalDate.Season(map); if (season != Season.Summer) { return(false); } int day = GenLocalDate.DayOfSeason(map); if (day > 8 || day < 7) { return(false); } return(true); }
public override void TickRare() { base.TickRare(); if (Utility.isDemocracy) { if (allowedDays.Contains(GenLocalDate.DayOfSeason(Map))) { if (allowElection && (Find.TickManager.TicksGame > lastElectionTick + GenDate.TicksPerDay) && Rand.MTBEventOccurs(0.03f, 60000f, 150f) && AcceptableMapConditionsToStartElection(Map)) { List <Pawn> leaders = getLeaders(); List <Pawn> pawnCount = new List <Pawn>(); bool flag = false; pawnCount.AddRange(IncidentWorker_LeaderElection.getAllColonists()); if (leaders.NullOrEmpty()) { flag = true; } if (leaders.Count <= 1 && pawnCount.Count >= 5) { flag = true; } List <Pawn> canBeVoted = new List <Pawn>(); canBeVoted.AddRange(IncidentWorker_LeaderElection.getAllColonists()); List <Pawn> tpawns2 = new List <Pawn>(); foreach (Pawn current in canBeVoted) { Hediff h1 = current.health.hediffSet.GetFirstHediffOfDef(HediffDef.Named("leader1")); Hediff h2 = current.health.hediffSet.GetFirstHediffOfDef(HediffDef.Named("leader2")); Hediff h3 = current.health.hediffSet.GetFirstHediffOfDef(HediffDef.Named("leader3")); Hediff h4 = current.health.hediffSet.GetFirstHediffOfDef(HediffDef.Named("leader4")); Hediff h5 = current.health.hediffSet.GetFirstHediffOfDef(HediffDef.Named("leaderExpired")); if (h1 != null || h2 != null || h3 != null || h4 != null || h5 != null) { tpawns2.Add(current); } if (current.story.WorkTagIsDisabled(WorkTags.Social)) { tpawns2.Add(current); } } foreach (Pawn current in tpawns2) { canBeVoted.Remove(current); } if (canBeVoted.NullOrEmpty()) { Messages.Message("ElectionFail_NoAbleLeader".Translate(), MessageSound.Negative); } else { if (flag) { TryStartGathering(Map); } } } } } }
public override void Tick(int currentTick) { //Constituent tick if (currentTick % GenDate.TicksPerHour * 2 == 0) { Map playerFactionMap = Find.WorldObjects.FactionBases.Find(b => b.Faction.IsPlayer).Map; IEnumerable <Pawn> constituents = (from p in playerFactionMap.mapPawns.FreeColonistsSpawned where !p.health.hediffSet.HasHediff(HediffDefOfPsychology.Mayor) && 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() select m); if (potentialConstituent != null && activeMayors.Count() > 0) { Pawn mayor = activeMayors.RandomElement(); //There should only be one. PsychologyPawn psychologyConstituent = potentialConstituent as PsychologyPawn; IntVec3 gather = default(IntVec3); bool foundBed = false; if (mayor.ownership != null && mayor.ownership.OwnedBed != null) { gather = mayor.ownership.OwnedBed.Position; foundBed = true; } if ((psychologyConstituent == null || Rand.Value < (1f - psychologyConstituent.psyche.GetPersonalityRating(PersonalityNodeDefOf.Independent)) / 5f) && (foundBed || RCellFinder.TryFindPartySpot(mayor, out gather))) { 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 < 0.4f)), mayor.Map, pawns); if (!foundBed) { mayor.needs.mood.thoughts.memories.TryGainMemory(ThoughtDefOfPsychology.MayorNoBedroom); } } } } } //Election tick if (currentTick % (GenDate.TicksPerDay / 4f) == 0) { foreach (FactionBase factionBase in Find.WorldObjects.FactionBases) { //If the base isn't owned or named by the player, no election can be held. if (!factionBase.Faction.IsPlayer || !factionBase.namedByPlayer) { continue; } //Self-explanatory. if (!PsychologyBase.ActivateElections()) { continue; } //If the base is not at least a year old, no election will be held. if ((Find.TickManager.TicksGame - factionBase.creationGameTicks) / GenDate.TicksPerYear < 1) { continue; } //A base must have at least 7 people in it to hold an election. if (factionBase.Map.mapPawns.FreeColonistsSpawnedCount < 7) { continue; } //If an election is already being held, don't start a new one. if (factionBase.Map.gameConditionManager.ConditionIsActive(GameConditionDefOfPsychology.Election) || factionBase.Map.lordManager.lords.Find(l => l.LordJob is LordJob_Joinable_Election) != null) { continue; } //Elections are held in the fall and during the day. if (GenLocalDate.Season(factionBase.Map) != Season.Fall || (GenLocalDate.HourOfDay(factionBase.Map) < 7 || GenLocalDate.HourOfDay(factionBase.Map) > 20)) { continue; } //If an election has already been completed this year, don't start a new one. IEnumerable <Pawn> activeMayors = (from m in factionBase.Map.mapPawns.FreeColonistsSpawned where !m.Dead && m.health.hediffSet.HasHediff(HediffDefOfPsychology.Mayor) && ((Hediff_Mayor)m.health.hediffSet.GetFirstHediffOfDef(HediffDefOfPsychology.Mayor)).worldTileElectedOn == factionBase.Map.Tile && ((Hediff_Mayor)m.health.hediffSet.GetFirstHediffOfDef(HediffDefOfPsychology.Mayor)).yearElected == GenLocalDate.Year(factionBase.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.DayOfSeason(factionBase.Map.Tile)) > 1) { continue; } IncidentParms parms = new IncidentParms(); parms.target = factionBase.Map; parms.faction = factionBase.Faction; FiringIncident fi = new FiringIncident(IncidentDefOfPsychology.Election, null, parms); Find.Storyteller.TryFire(fi); } } }