public void UpdatePacks() { IEnumerable <Pawn> pawnsOnMap = RimValiUtility.AllPawnsOfRaceOnMap(AvaliDefs.RimVali, map).Where(x => (RimValiUtility.GetPackSize(x, x.TryGetComp <PackComp>().Props.relation) < maxSize) & racesInPacks.Contains(x.def)); foreach (Pawn pawn in pawnsOnMap) { PackComp comp = pawn.TryGetComp <PackComp>(); if (!(comp == null)) { //Pull the comp info from the pawn PawnRelationDef relationDef = comp.Props.relation; SimpleCurve ageCurve = comp.Props.packGenChanceOverAge; if (RimValiUtility.GetPackSize(pawn, relationDef) == 1) { //Tells us that this pawn has had a pack if (enableDebug) { Log.Message("Attempting to make pack.. [Base pack]"); } //Makes the pack. RimValiUtility.KeoBuildMakePack(pawn, relationDef, racesInPacks, maxSize); } } } }
public void UpdatePacks() { if (enableDebug && multiThreaded) { //Log.Message("Thread started."); } IEnumerable <Pawn> pawnsOnMap = RimValiUtility.AllPawnsOfRaceInWorld(AvaliDefs.RimVali).Where <Pawn>(x => RimValiUtility.GetPackSize(x) < maxSize); foreach (Pawn pawn in pawnsOnMap) { //Log.Message(pawn.Faction.Name); //Log.Message(pawn.Name.ToString() + " updatePacks()"); PackComp comp = pawn.TryGetComp <PackComp>(); if (!(comp == null)) { //Pull the comp info from the pawn SimpleCurve ageCurve = comp.Props.packGenChanceOverAge; //Tells us that this pawn has had a pack if (enableDebug) { //Log.Message("Attempting to make pack.. [Base pack]"); } //Makes the pack. //Log.Message("EiPackHandlerFromPackDriverMapComp started."); packs = RimValiUtility.EiPackHandler(packs, pawn, racesInPacks, maxSize); } } }
protected override ThoughtState CurrentStateInternal(Pawn pawn) { AvaliThoughtDriver avaliThoughtDriver = pawn.TryGetComp <AvaliThoughtDriver>(); PackComp packComp = pawn.TryGetComp <PackComp>(); if (!(avaliThoughtDriver == null)) { if (pawn.Awake()) { if (pawn.CheckIfPackmatesInRoom()) { return(ThoughtState.ActiveDefault); } else { return(ThoughtState.Inactive); } } else { return(ThoughtState.Inactive); } } else { return(ThoughtState.Inactive); } }
public void UpdatePawns(Map map) { IEnumerable <Pawn> pawns = RimValiUtility.CheckAllPawnsInMapAndFaction(map, Faction.OfPlayer).Where(x => x.def == AvaliDefs.RimVali); foreach (Pawn pawn in pawns) { AvaliThoughtDriver avaliThoughtDriver = pawn.TryGetComp <AvaliThoughtDriver>(); PackComp packComp = pawn.TryGetComp <PackComp>(); if (!(avaliThoughtDriver == null)) { if (pawn.def == AvaliDefs.RimVali) { if (RimValiUtility.GetPackSize(pawn, avaliThoughtDriver.Props.relationDef) > 1) { PawnRelationDef relationDef = avaliThoughtDriver.Props.relationDef; UpdateSharedRoomThought(pawn, relationDef, avaliThoughtDriver.Props.inSameRoomThought); UpdateBedRoomThought(pawn, relationDef, avaliThoughtDriver.Props.sharedBedroomThought, avaliThoughtDriver.Props.sleptApartThought); } } } if (!(packComp == null)) { if (packComp.Props.canHaveAloneThought) { UpdateThought(pawn, packComp.Props.relation, packComp.Props.aloneThought); } } } }
public override void PawnDied(Corpse corpse) { if (enableDebug) { Log.Message("Death detected"); } if (corpse.InnerPawn.def.race == AvaliDefs.RimVali.race) { if (!(AvaliPackDriver.packs == null) && AvaliPackDriver.packs.Count > 0) { if (enableDebug) { Log.Message("I got here, packs exist."); } Pawn pawn = corpse.InnerPawn; foreach (AvaliPack pack in AvaliPackDriver.packs) { if (pack.pawns.Contains(pawn)) { if (enableDebug) { Log.Message("The pawn had a pack"); } DeathDate deathDate = new DeathDate(); Log.Message(GenDate.DayOfYear(1, Find.WorldGrid.LongLatOf(corpse.Map.Tile).x).ToString()); deathDate.day = GenDate.DayOfYear(1, Find.WorldGrid.LongLatOf(corpse.Map.Tile).x); if (corpse.InnerPawn != null && enableDebug) { Log.Message("Pawn is not null"); } deathDate.deadPawn = pawn; if (enableDebug) { Log.Message("I got the deathdate"); Log.Message(deathDate.day.ToString()); } pack.deathDates.Add(deathDate); pack.size--; if (enableDebug) { Log.Message(pack.size.ToString()); } foreach (Pawn packmate in pack.pawns) { if (!(pawn == packmate) && !pawn.Dead) { PackComp comp = packmate.TryGetComp <PackComp>(); if (comp.Props.deathThought != null) { packmate.needs.mood.thoughts.memories.TryGainMemory(comp.Props.deathThought); } } } break; } } } } }
public void UpdatePackLoss(Pawn pawn) { AvaliThoughtDriver thoughtComp = pawn.TryGetComp <AvaliThoughtDriver>(); PackComp packComp = pawn.TryGetComp <PackComp>(); if (packComp.ticksSinceLastInpack == 0 && (RimValiUtility.GetPackWithoutSelf(pawn) == null || RimValiUtility.GetPackWithoutSelf(pawn).size < 2)) { packComp.ticksSinceLastInpack = Find.TickManager.TicksGame; } else if (RimValiUtility.GetPackWithoutSelf(pawn) != null && RimValiUtility.GetPackWithoutSelf(pawn).size > 1) { packComp.ticksSinceLastInpack = 0; } }
public void UpdatePawns(Map map) { AvaliPackDriver AvaliPackDriver = Current.Game.GetComponent <AvaliPackDriver>(); IEnumerable <Pawn> pawns = RimValiUtility.CheckAllPawnsInMapAndFaction(map, Faction.OfPlayer).Where(x => AvaliPackDriver.racesInPacks.Contains(x.def)); IEnumerable <AvaliPack> packs = AvaliPackDriver.packs; foreach (Pawn pawn in pawns) { AvaliThoughtDriver avaliThoughtDriver = pawn.TryGetComp <AvaliThoughtDriver>(); PackComp packComp = pawn.TryGetComp <PackComp>(); if (!(avaliThoughtDriver == null)) { //Log.Message("Pawn has pack comp, moving to next step..."); if (AvaliPackDriver.packs == null || AvaliPackDriver.packs.Count == 0) { //Log.Message("How did we get here? [Pack list was 0 or null]"); return; } AvaliPack pawnPack = null; //This errors out when pawns dont have a pack, in rare cases. That is bad. This stops it from doing that. try { pawnPack = pawn.GetPack(); } catch { return; } //Log.Message("Tried to get packs pack, worked."); if (pawnPack == null) { //Log.Message("How did we get here? [Pack was null.]"); break; } foreach (Pawn packmate in pawnPack.pawns) { Thought_Memory thought_Memory2 = (Thought_Memory)ThoughtMaker.MakeThought(packComp.Props.togetherThought); if (!(packmate == pawn) && packmate != null && pawn != null) { bool bubble; if (!thought_Memory2.TryMergeWithExistingMemory(out bubble)) { //Log.Message("Adding thought to pawn."); pawn.needs.mood.thoughts.memories.TryGainMemory(thought_Memory2, packmate); } } } } } }
protected override ThoughtState CurrentStateInternal(Pawn p) { PackComp packComp = p.TryGetComp <PackComp>(); AvaliThoughtDriver thoughtComp = p.TryGetComp <AvaliThoughtDriver>(); if (thoughtComp == null) { return(ThoughtState.Inactive); } foreach (Hediff hediff in p.health.hediffSet.hediffs) { if (thoughtComp.Props.packLossPreventers.Contains(hediff.def)) { return(ThoughtState.Inactive); } } if (!LoadedModManager.GetMod <RimValiMod>().GetSettings <RimValiModSettings>().packLossEnabled) { return(ThoughtState.Inactive); } if (packComp == null) { return(ThoughtState.Inactive); } UpdatePackLoss(p); int timeAlone = Find.TickManager.TicksGame - packComp.ticksSinceLastInpack; if (timeAlone == Find.TickManager.TicksGame) { return(ThoughtState.Inactive); } if (timeAlone >= 240000) { return(ThoughtState.ActiveAtStage(2)); } if (timeAlone > 120000) { return(ThoughtState.ActiveAtStage(1)); } if (timeAlone > 60000) { return(ThoughtState.ActiveAtStage(0)); } return(ThoughtState.ActiveAtStage(3)); }
public void MakeNewPacks() { if (enableDebug && multiThreaded) { Log.Message("Thread started."); } IEnumerable <Pawn> pawnsOnMap = RimValiUtility.AllPawnsOfRaceOnMap(AvaliDefs.RimVali, map).Where <Pawn>(x => RimValiUtility.GetPackSize(x, x.TryGetComp <PackComp>().Props.relation) < maxSize); foreach (Pawn pawn in pawnsOnMap) { PackComp comp = pawn.TryGetComp <PackComp>(); if (!(comp == null)) { //Pull the comp info from the pawn PawnRelationDef relationDef = comp.Props.relation; SimpleCurve ageCurve = comp.Props.packGenChanceOverAge; //Tells us that this pawn has had a pack if (enableDebug) { Log.Message("Attempting to make pack.. [New/added pack]"); } //Makes the pack. foreach (Pawn packmate in pawnsOnMap) { //RimValiUtility.KeoBuildMakeBasePack(pawn, relationDef, racesInPacks, maxSize); RimValiUtility.EiBuildMakeBasePack(pawn, relationDef, racesInPacks, maxSize, packs); if (RimValiUtility.GetPackSize(pawn, relationDef) <= 0) { RimValiUtility.EiBuildMakeBasePack(pawn, relationDef, racesInPacks, maxSize, packs); } else { RimValiUtility.EiBuildMakeBasePack(pawn, relationDef, racesInPacks, maxSize, packs); } if (RimValiUtility.GetPackSize(pawn, relationDef) == maxSize) { break; } } } } }