public static Pawn FindKrumpablePawn(Pawn pawn, FightynessCategory CurCategory, Orkoid max = Orkoid.GargantuanSquiggoth) { List <Pawn> collection = pawn.Map.mapPawns.SpawnedPawnsInFaction(pawn.Faction); float maxSize = pawn.BodySize + (pawn.BodySize * (1 * (int)CurCategory)); workingList.Clear(); workingList.AddRange(collection); workingList.Shuffle <Pawn>(); workingList.RemoveAll(x => x == pawn || x.Orkiness() > max); workingList.RemoveAll(x => x.BodySize > maxSize); workingList.RemoveAll(x => !pawn.CanReach(x, PathEndMode.Touch, Danger.Deadly)); if (workingList.NullOrEmpty()) { return(null); } return(workingList.RandomElementByWeight(x => AdeptusMath.Inverse(x.Position.DistanceTo(pawn.Position)))); }
public virtual bool TrySpawnPawns(Pawn harvester = null) { if (this.HarvestableNow) { int squigs = Squigs.Count(); int snots = Snots.Count(); int grots = Grots.Count(); int orks = Orks.Count(); int greenskins = squigs + snots + grots + orks; Rand.PushState(this.thingIDNumber); var spawnRoll = Rand.ValueSeeded(this.thingIDNumber); Rand.PopState(); if (spawnRoll < (SpawnChance * (/*HealthTuning.DeathOnDownedChance_NonColonyHumanlikeFromPopulationIntentCurve.Evaluate(StorytellerUtilityPopulation.PopulationIntent + greenskins) **/ Find.Storyteller.difficulty.enemyDeathOnDownedChanceFactor) * this.Growth)) { PawnKindDef pawnKindDef; bool OrkoidHarvester = harvester == null || harvester.isOrkoid(); if (OrkoidHarvester) { List <PawnGenOption> options = new List <PawnGenOption>() { new PawnGenOption(AdeptusPawnKindDefOf.OG_Squig, SquigChance * (OrkoidFungalUtility.SquigSpawnCurve.Evaluate(squigs))), new PawnGenOption(AdeptusPawnKindDefOf.OG_Snotling, SnotlingChance * (OrkoidFungalUtility.SnotSpawnCurve.Evaluate(snots))), new PawnGenOption(AdeptusPawnKindDefOf.OG_Grot_Wild, GrotChance * ((this.ageInt / this.def.plant.LifespanTicks) + OrkoidFungalUtility.GrotSpawnCurve.Evaluate(grots))), new PawnGenOption(AdeptusPawnKindDefOf.OG_Ork_Wild, OrkChance * ((this.ageInt / this.def.plant.LifespanTicks) + OrkoidFungalUtility.OrkSpawnCurve.Evaluate(orks))) }; pawnKindDef = options.InRandomOrder().RandomElementByWeight(x => x.selectionWeight).kind; Rand.PushState(); if (pawnKindDef == AdeptusPawnKindDefOf.OG_Squig) { Rand.PushState(); pawnKindDef = DefDatabase <PawnKindDef> .AllDefsListForReading.Where(x => x.RaceProps.Animal && x.defName.Contains("OG_") && x.defName.Contains("_Squig")).RandomElementByWeight(x => AdeptusMath.Inverse(x.race.BaseMarketValue)); Rand.PopState(); } Rand.PopState(); StringBuilder builder = new StringBuilder(); builder.Append(pawnKindDef.LabelCap + " Spawned"); builder.AppendLine(); foreach (var item in options) { builder.Append(" " + item.kind.LabelCap + " weighted at " + item.selectionWeight); } if (Prefs.DevMode) { Log.Message(builder.ToString()); } } else { pawnKindDef = AdeptusPawnKindDefOf.OG_Squig; } Faction faction = FungalProps.spawnwild || !OrkoidHarvester ? null : Faction.OfPlayer; PawnGenerationRequest pawnGenerationRequest = new PawnGenerationRequest(pawnKindDef, faction, PawnGenerationContext.NonPlayer, -1, true, true, false, false, true, true, 0f, fixedGender: Gender.None, fixedBiologicalAge: Age, fixedChronologicalAge: Age); Pawn pawn = PawnGenerator.GeneratePawn(pawnGenerationRequest); if (pawnKindDef.RaceProps.Humanlike) { /* * if (pawn.kindDef == OGOrkPawnKindDefOf.OG_Ork_Wild) * { * pawn.story.childhood.identifier = "Ork_Base_Child"; * } * else if (pawn.kindDef == OGOrkPawnKindDefOf.OG_Grot_Wild) * { * pawn.story.childhood.identifier = "Grot_Base_Child"; * } */ if (!FungalProps.spawnwild && (Faction.OfPlayer.def == AdeptusFactionDefOf.OG_Ork_PlayerTribe || Faction.OfPlayer.def == AdeptusFactionDefOf.OG_Ork_PlayerColony)) { PawnKindDef pawnKind; if (Faction.OfPlayer.def == AdeptusFactionDefOf.OG_Ork_PlayerTribe) { pawnKind = pawn.def.defName.Contains("Alien_Grot") ? AdeptusPawnKindDefOf.Tribesperson_OG_Grot : DefDatabase <PawnKindDef> .AllDefsListForReading.Where(x => x.defName.Contains("Tribesperson_OG_Ork")).RandomElementByWeight(x => AdeptusMath.Inverse(x.combatPower)); } else { pawnKind = pawn.def.defName.Contains("Alien_Grot") ? AdeptusPawnKindDefOf.Colonist_OG_Grot : DefDatabase <PawnKindDef> .AllDefsListForReading.Where(x => x.defName.Contains("Colonist_OG_Ork")).RandomElementByWeight(x => AdeptusMath.Inverse(x.combatPower)); } pawn.ChangeKind(pawnKind); } else { pawn.ChangeKind(PawnKindDefOf.WildMan); } pawn.story.bodyType = pawn.story.childhood.BodyTypeFor(pawn.gender); } if (GrowthRateFactor_Fertility < 1f) { foreach (Need need in pawn.needs.AllNeeds) { if (need.def != NeedDefOf.Rest) { need.CurLevel = 0.1f; } } } else { float level = GrowthRateFactor_Fertility - 1f; pawn.needs.food.CurLevel = level; pawn.needs.rest.CurLevel = 1f; if (pawn.RaceProps.Humanlike) { pawn.needs.mood.CurLevel = level; } } Hediff hediff = HediffMaker.MakeHediff(HediffDefOf.Malnutrition, pawn); hediff.Severity = Math.Min(1f - GrowthRateFactor_Fertility, 0.8f); pawn.health.AddHediff(hediff); GenSpawn.Spawn(pawn, this.Position, this.Map, 0); if (harvester != null && harvester.Faction == Faction.OfPlayer) { TaggedString taggedString = TranslatorFormattedStringExtensions.Translate("AdeptusMechanicus.Ork.FungalHarvest_SuccessMessage", harvester.Named("HARVESTER"), pawn.Label); Messages.Message(taggedString, pawn, MessageTypeDefOf.PositiveEvent, true); } return(true); } } return(false); }