private void GenerateCarriers(PawnGroupMakerParms parms, PawnGroupMaker groupMaker, Pawn trader, List <Thing> wares, List <Pawn> outPawns) { List <Thing> list = wares.Where((Thing x) => !(x is Pawn)).ToList(); int i = 0; int num = Mathf.CeilToInt((float)list.Count / 8f); PawnKindDef kind = groupMaker.carriers.Where((PawnGenOption x) => parms.tile == -1 || Find.WorldGrid[parms.tile].biome.IsPackAnimalAllowed(x.kind.race)).RandomElementByWeight((PawnGenOption x) => x.selectionWeight).kind; List <Pawn> list2 = new List <Pawn>(); for (int j = 0; j < num; j++) { Pawn pawn = PawnGenerator.GeneratePawn(new PawnGenerationRequest(kind, parms.faction, PawnGenerationContext.NonPlayer, parms.tile, forceGenerateNewPawn: false, newborn: false, allowDead: false, allowDowned: false, canGeneratePawnRelations: true, mustBeCapableOfViolence: false, 1f, forceAddFreeWarmLayerIfNeeded: false, allowGay: true, allowFood: true, allowAddictions: true, parms.inhabitants)); if (i < list.Count) { pawn.inventory.innerContainer.TryAdd(list[i]); i++; } list2.Add(pawn); outPawns.Add(pawn); } for (; i < list.Count; i++) { list2.RandomElement().inventory.innerContainer.TryAdd(list[i]); } }
private IEnumerable <Pawn> GenerateAmbushPawns() { if (ambushType == SignalActionAmbushType.Manhunters) { if (!ManhunterPackIncidentUtility.TryFindManhunterAnimalKind(points, base.Map.Tile, out PawnKindDef animalKind) && !ManhunterPackIncidentUtility.TryFindManhunterAnimalKind(points, -1, out animalKind)) { return(Enumerable.Empty <Pawn>()); } return(ManhunterPackIncidentUtility.GenerateAnimals(animalKind, base.Map.Tile, points)); } Faction faction = (ambushType != SignalActionAmbushType.Mechanoids) ? (base.Map.ParentFaction ?? Find.FactionManager.RandomEnemyFaction(allowHidden: false, allowDefeated: false, allowNonHumanlike: false)) : Faction.OfMechanoids; if (faction == null) { return(Enumerable.Empty <Pawn>()); } PawnGroupMakerParms pawnGroupMakerParms = new PawnGroupMakerParms(); pawnGroupMakerParms.groupKind = PawnGroupKindDefOf.Combat; pawnGroupMakerParms.tile = base.Map.Tile; pawnGroupMakerParms.faction = faction; pawnGroupMakerParms.points = Mathf.Max(points, faction.def.MinPointsToGeneratePawnGroup(PawnGroupKindDefOf.Combat)); return(PawnGroupMakerUtility.GeneratePawns(pawnGroupMakerParms)); }
public List <Pawn> GeneratePawns(PawnGroupMakerParms parms, PawnGroupMaker groupMaker, bool errorOnZeroResults = true) { List <Pawn> list = new List <Pawn>(); PawnGroupKindWorker.pawnsBeingGeneratedNow.Add(list); try { this.GeneratePawns(parms, groupMaker, list, errorOnZeroResults); } catch (Exception arg) { Log.Error("Exception while generating pawn group: " + arg, false); for (int i = 0; i < list.Count; i++) { list[i].Destroy(DestroyMode.Vanish); } list.Clear(); } finally { PawnGroupKindWorker.pawnsBeingGeneratedNow.Remove(list); } return(list); }
public override bool CanGenerateFrom(PawnGroupMakerParms parms, PawnGroupMaker groupMaker) { return(base.CanGenerateFrom(parms, groupMaker) && PawnGroupMakerUtility.ChoosePawnGenOptionsByPoints(parms.points, groupMaker.options, parms).Any <PawnGenOption>()); }
protected override bool TryExecuteWorker(IncidentParms parms) { Map map = (Map)parms.target; this.ResolveRaidPoints(parms); if (!this.TryResolveRaidFaction(parms)) { return(false); } this.ResolveRaidStrategy(parms); this.ResolveRaidArriveMode(parms); if (!this.ResolveRaidSpawnCenter(parms)) { return(false); } IncidentParmsUtility.AdjustPointsForGroupArrivalParams(parms); PawnGroupMakerParms defaultPawnGroupMakerParms = IncidentParmsUtility.GetDefaultPawnGroupMakerParms(parms, false); List <Pawn> list = PawnGroupMakerUtility.GeneratePawns(PawnGroupKindDefOf.Normal, defaultPawnGroupMakerParms, true).ToList(); if (list.Count == 0) { Log.Error("Got no pawns spawning raid from parms " + parms); return(false); } TargetInfo target = TargetInfo.Invalid; if (parms.raidArrivalMode == PawnsArriveMode.CenterDrop || parms.raidArrivalMode == PawnsArriveMode.EdgeDrop) { DropPodUtility.DropThingsNear(parms.spawnCenter, map, list.Cast <Thing>(), parms.raidPodOpenDelay, false, true, true, false); target = new TargetInfo(parms.spawnCenter, map, false); } else { foreach (Pawn item in list) { IntVec3 loc = CellFinder.RandomClosewalkCellNear(parms.spawnCenter, map, 8, null); GenSpawn.Spawn(item, loc, map, parms.spawnRotation, false); target = item; } } StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine("Points = " + parms.points.ToString("F0")); foreach (Pawn item2 in list) { string str = (item2.equipment == null || item2.equipment.Primary == null) ? "unarmed" : item2.equipment.Primary.LabelCap; stringBuilder.AppendLine(item2.KindLabel + " - " + str); } string letterLabel = this.GetLetterLabel(parms); string letterText = this.GetLetterText(parms, list); PawnRelationUtility.Notify_PawnsSeenByPlayer_Letter(list, ref letterLabel, ref letterText, this.GetRelatedPawnsInfoLetterText(parms), true, true); Find.LetterStack.ReceiveLetter(letterLabel, letterText, this.GetLetterDef(), target, stringBuilder.ToString()); if (this.GetLetterDef() == LetterDefOf.ThreatBig) { TaleRecorder.RecordTale(TaleDefOf.RaidArrived); } Lord lord = LordMaker.MakeNewLord(parms.faction, parms.raidStrategy.Worker.MakeLordJob(parms, map), map, list); AvoidGridMaker.RegenerateAvoidGridsFor(parms.faction, map); LessonAutoActivator.TeachOpportunity(ConceptDefOf.EquippingWeapons, OpportunityType.Critical); if (!PlayerKnowledgeDatabase.IsComplete(ConceptDefOf.ShieldBelts)) { for (int i = 0; i < list.Count; i++) { Pawn pawn = list[i]; if (pawn.apparel.WornApparel.Any((Apparel ap) => ap is ShieldBelt)) { LessonAutoActivator.TeachOpportunity(ConceptDefOf.ShieldBelts, OpportunityType.Critical); break; } } } if (DebugViewSettings.drawStealDebug && parms.faction.HostileTo(Faction.OfPlayer)) { Log.Message("Market value threshold to start stealing: " + StealAIUtility.StartStealingMarketValueThreshold(lord) + " (colony wealth = " + map.wealthWatcher.WealthTotal + ")"); } return(true); }
protected override void GeneratePawns(PawnGroupMakerParms parms, PawnGroupMaker groupMaker, List <Pawn> outPawns, bool errorOnZeroResults = true) { if (!this.CanGenerateFrom(parms, groupMaker)) { if (errorOnZeroResults) { Log.Error("Cannot generate trader caravan for " + parms.faction + "."); } return; } if (!parms.faction.def.caravanTraderKinds.Any <TraderKindDef>()) { Log.Error("Cannot generate trader caravan for " + parms.faction + " because it has no trader kinds."); return; } PawnGenOption pawnGenOption = groupMaker.traders.FirstOrDefault((PawnGenOption x) => !x.kind.trader); if (pawnGenOption != null) { Log.Error(string.Concat(new object[] { "Cannot generate arriving trader caravan for ", parms.faction, " because there is a pawn kind (", pawnGenOption.kind.LabelCap, ") who is not a trader but is in a traders list." })); return; } PawnGenOption pawnGenOption2 = groupMaker.carriers.FirstOrDefault((PawnGenOption x) => !x.kind.RaceProps.packAnimal); if (pawnGenOption2 != null) { Log.Error(string.Concat(new object[] { "Cannot generate arriving trader caravan for ", parms.faction, " because there is a pawn kind (", pawnGenOption2.kind.LabelCap, ") who is not a carrier but is in a carriers list." })); return; } TraderKindDef arg_18A_0; if (parms.traderKind != null) { arg_18A_0 = parms.traderKind; } else { arg_18A_0 = parms.faction.def.caravanTraderKinds.RandomElementByWeight((TraderKindDef traderDef) => traderDef.commonality); } TraderKindDef traderKindDef = arg_18A_0; Pawn pawn = this.GenerateTrader(parms, groupMaker, traderKindDef); outPawns.Add(pawn); ItemCollectionGeneratorParams parms2 = default(ItemCollectionGeneratorParams); parms2.traderDef = traderKindDef; parms2.tile = new int?(parms.tile); parms2.traderFaction = parms.faction; List <Thing> wares = ItemCollectionGeneratorDefOf.TraderStock.Worker.Generate(parms2).InRandomOrder(null).ToList <Thing>(); foreach (Pawn current in this.GetSlavesAndAnimalsFromWares(parms, pawn, wares)) { outPawns.Add(current); } this.GenerateCarriers(parms, groupMaker, pawn, wares, outPawns); this.GenerateGuards(parms, groupMaker, pawn, wares, outPawns); }
public override bool CanGenerateFrom(PawnGroupMakerParms parms, PawnGroupMaker groupMaker) { return(base.CanGenerateFrom(parms, groupMaker) && groupMaker.traders.Any <PawnGenOption>() && (parms.tile == -1 || groupMaker.carriers.Any((PawnGenOption x) => Find.WorldGrid[parms.tile].biome.IsPackAnimalAllowed(x.kind.race)))); }
public abstract IEnumerable <PawnKindDef> GeneratePawnKindsExample(PawnGroupMakerParms parms, PawnGroupMaker groupMaker);
protected abstract void GeneratePawns(PawnGroupMakerParms parms, PawnGroupMaker groupMaker, List <Pawn> outPawns, bool errorOnZeroResults = true);
protected override bool TryExecuteWorker(IncidentParms parms) { Map map = (Map)parms.target; IntVec3 spawnSpot; if (!this.TryFindSpawnSpot(map, out spawnSpot)) { return(false); } Faction faction; if (!this.TryFindEnemyFaction(out faction)) { return(false); } int @int = Rand.Int; IncidentParms raidParms = StorytellerUtility.DefaultParmsNow(IncidentCategoryDefOf.ThreatBig, map); raidParms.forced = true; raidParms.faction = faction; raidParms.raidStrategy = RaidStrategyDefOf.ImmediateAttack; raidParms.raidArrivalMode = PawnsArrivalModeDefOf.EdgeWalkIn; raidParms.spawnCenter = spawnSpot; raidParms.points = Mathf.Max(raidParms.points * IncidentWorker_RefugeeChased.RaidPointsFactorRange.RandomInRange, faction.def.MinPointsToGeneratePawnGroup(PawnGroupKindDefOf.Combat)); raidParms.pawnGroupMakerSeed = new int?(@int); PawnGroupMakerParms defaultPawnGroupMakerParms = IncidentParmsUtility.GetDefaultPawnGroupMakerParms(PawnGroupKindDefOf.Combat, raidParms, false); defaultPawnGroupMakerParms.points = IncidentWorker_Raid.AdjustedRaidPoints(defaultPawnGroupMakerParms.points, raidParms.raidArrivalMode, raidParms.raidStrategy, defaultPawnGroupMakerParms.faction, PawnGroupKindDefOf.Combat); IEnumerable <PawnKindDef> pawnKinds = PawnGroupMakerUtility.GeneratePawnKindsExample(defaultPawnGroupMakerParms); PawnGenerationRequest request = new PawnGenerationRequest(PawnKindDefOf.SpaceRefugee, null, PawnGenerationContext.NonPlayer, -1, false, false, false, false, true, false, 20f, false, true, true, false, false, false, false, null, null, null, null, null, null, null, null); Pawn refugee = PawnGenerator.GeneratePawn(request); refugee.relations.everSeenByPlayer = true; string text = "RefugeeChasedInitial".Translate(refugee.Name.ToStringFull, refugee.story.Title, faction.def.pawnsPlural, faction.Name, refugee.ageTracker.AgeBiologicalYears, PawnUtility.PawnKindsToCommaList(pawnKinds, true), refugee.Named("PAWN")); text = text.AdjustedFor(refugee, "PAWN"); PawnRelationUtility.TryAppendRelationsWithColonistsInfo(ref text, refugee); DiaNode diaNode = new DiaNode(text); DiaOption diaOption = new DiaOption("RefugeeChasedInitial_Accept".Translate()); diaOption.action = delegate { GenSpawn.Spawn(refugee, spawnSpot, map, WipeMode.Vanish); refugee.SetFaction(Faction.OfPlayer, null); CameraJumper.TryJump(refugee); QueuedIncident qi = new QueuedIncident(new FiringIncident(IncidentDefOf.RaidEnemy, null, raidParms), Find.TickManager.TicksGame + IncidentWorker_RefugeeChased.RaidDelay.RandomInRange, 0); Find.Storyteller.incidentQueue.Add(qi); }; diaOption.resolveTree = true; diaNode.options.Add(diaOption); string text2 = "RefugeeChasedRejected".Translate(refugee.LabelShort, refugee); DiaNode diaNode2 = new DiaNode(text2); DiaOption diaOption2 = new DiaOption("OK".Translate()); diaOption2.resolveTree = true; diaNode2.options.Add(diaOption2); DiaOption diaOption3 = new DiaOption("RefugeeChasedInitial_Reject".Translate()); diaOption3.action = delegate { Find.WorldPawns.PassToWorld(refugee, PawnDiscardDecideMode.Decide); }; diaOption3.link = diaNode2; diaNode.options.Add(diaOption3); string title = "RefugeeChasedTitle".Translate(map.Parent.Label); Find.WindowStack.Add(new Dialog_NodeTreeWithFactionInfo(diaNode, faction, true, true, title)); Find.Archive.Add(new ArchivedDialog(diaNode.text, title, faction)); return(true); }
public static IEnumerable <PawnGenOption> ChoosePawnGenOptionsByPoints(float points, List <PawnGenOption> options, PawnGroupMakerParms parms) { float num = PawnGroupMakerUtility.MaxAllowedPawnGenOptionCost(parms.faction, points, parms.raidStrategy); List <PawnGenOption> list = new List <PawnGenOption>(); List <PawnGenOption> list2 = new List <PawnGenOption>(); float num2 = points; bool flag = false; while (true) { list.Clear(); for (int i = 0; i < options.Count; i++) { PawnGenOption pawnGenOption = options[i]; if (!(pawnGenOption.Cost > num2) && !(pawnGenOption.Cost > num) && (!parms.generateFightersOnly || pawnGenOption.kind.isFighter) && (parms.raidStrategy == null || parms.raidStrategy.Worker.CanUsePawnGenOption(pawnGenOption, list2)) && (!flag || !pawnGenOption.kind.factionLeader)) { list.Add(pawnGenOption); } } if (list.Count != 0) { float desireToSuppressCount = PawnGroupMakerUtility.DesireToSuppressCountPerRaidPointsCurve.Evaluate(points); Func <PawnGenOption, float> weightSelector = delegate(PawnGenOption gr) { float num3 = gr.selectionWeight; if (desireToSuppressCount > 0.0) { float b = (float)(num3 * (gr.Cost / 100.0)); num3 = Mathf.Lerp(num3, b, desireToSuppressCount); } return(num3); }; PawnGenOption pawnGenOption2 = list.RandomElementByWeight(weightSelector); list2.Add(pawnGenOption2); num2 -= pawnGenOption2.Cost; if (pawnGenOption2.kind.factionLeader) { flag = true; } continue; } break; } if (list2.Count == 1 && num2 > points / 2.0) { Log.Warning("Used only " + (points - num2) + " / " + points + " points generating for " + parms.faction); } return(list2); }
public bool CanGenerateFrom(PawnGroupMakerParms parms) { return(parms.points <= this.maxTotalPoints && (this.disallowedStrategies == null || !this.disallowedStrategies.Contains(parms.raidStrategy)) && this.kindDef.Worker.CanGenerateFrom(parms, this)); }
public IEnumerable <PawnKindDef> GeneratePawnKindsExample(PawnGroupMakerParms parms) { return(this.kindDef.Worker.GeneratePawnKindsExample(parms, this)); }
public IEnumerable <Pawn> GeneratePawns(PawnGroupMakerParms parms, bool errorOnZeroResults = true) { return(this.kindDef.Worker.GeneratePawns(parms, this, errorOnZeroResults)); }
public static IEnumerable <PawnGenOption> ChoosePawnGenOptionsByPoints(float pointsTotal, List <PawnGenOption> options, PawnGroupMakerParms groupParms) { if (groupParms.seed != null) { Rand.PushState(groupParms.seed.Value); } float num = PawnGroupMakerUtility.MaxPawnCost(groupParms.faction, pointsTotal, groupParms.raidStrategy, groupParms.groupKind); List <PawnGenOption> list = new List <PawnGenOption>(); List <PawnGenOption> list2 = new List <PawnGenOption>(); float num2 = pointsTotal; bool flag = false; float highestCost = -1f; for (;;) { list.Clear(); for (int i = 0; i < options.Count; i++) { PawnGenOption pawnGenOption = options[i]; if (pawnGenOption.Cost <= num2) { if (pawnGenOption.Cost <= num) { if (!groupParms.generateFightersOnly || pawnGenOption.kind.isFighter) { if (groupParms.raidStrategy == null || groupParms.raidStrategy.Worker.CanUsePawnGenOption(pawnGenOption, list2)) { if (!groupParms.dontUseSingleUseRocketLaunchers || pawnGenOption.kind.weaponTags == null || !pawnGenOption.kind.weaponTags.Contains("GunHeavy")) { if (!flag || !pawnGenOption.kind.factionLeader) { if (pawnGenOption.Cost > highestCost) { highestCost = pawnGenOption.Cost; } list.Add(pawnGenOption); } } } } } } } if (list.Count == 0) { break; } Func <PawnGenOption, float> weightSelector = delegate(PawnGenOption gr) { float selectionWeight = gr.selectionWeight; return(selectionWeight * PawnGroupMakerUtility.PawnWeightFactorByMostExpensivePawnCostFractionCurve.Evaluate(gr.Cost / highestCost)); }; PawnGenOption pawnGenOption2 = list.RandomElementByWeight(weightSelector); list2.Add(pawnGenOption2); num2 -= pawnGenOption2.Cost; if (pawnGenOption2.kind.factionLeader) { flag = true; } } if (list2.Count == 1 && num2 > pointsTotal / 2f) { Log.Warning(string.Concat(new object[] { "Used only ", pointsTotal - num2, " / ", pointsTotal, " points generating for ", groupParms.faction }), false); } if (groupParms.seed != null) { Rand.PopState(); } return(list2); }
private static void <PawnGroupsMade> m__3(Faction fac) { StringBuilder sb = new StringBuilder(); sb.AppendLine(string.Concat(new object[] { "FACTION: ", fac.Name, " (", fac.def.defName, ") min=", fac.def.MinPointsToGeneratePawnGroup(PawnGroupKindDefOf.Combat) })); Action <float> action = delegate(float points) { if (points < fac.def.MinPointsToGeneratePawnGroup(PawnGroupKindDefOf.Combat)) { return; } PawnGroupMakerParms pawnGroupMakerParms = new PawnGroupMakerParms(); pawnGroupMakerParms.groupKind = PawnGroupKindDefOf.Combat; pawnGroupMakerParms.tile = Find.CurrentMap.Tile; pawnGroupMakerParms.points = points; pawnGroupMakerParms.faction = fac; sb.AppendLine(string.Concat(new object[] { "Group with ", pawnGroupMakerParms.points, " points (max option cost: ", PawnGroupMakerUtility.MaxPawnCost(fac, points, RaidStrategyDefOf.ImmediateAttack, PawnGroupKindDefOf.Combat), ")" })); float num2 = 0f; foreach (Pawn pawn in from pa in PawnGroupMakerUtility.GeneratePawns(pawnGroupMakerParms, false) orderby pa.kindDef.combatPower select pa) { string text; if (pawn.equipment.Primary != null) { text = pawn.equipment.Primary.Label; } else { text = "no-equipment"; } Apparel apparel = pawn.apparel.FirstApparelOnBodyPartGroup(BodyPartGroupDefOf.Torso); string text2; if (apparel != null) { text2 = apparel.LabelCap; } else { text2 = "shirtless"; } sb.AppendLine(string.Concat(new string[] { " ", pawn.kindDef.combatPower.ToString("F0").PadRight(6), pawn.kindDef.defName, ", ", text, ", ", text2 })); num2 += pawn.kindDef.combatPower; } sb.AppendLine(" totalCost " + num2); sb.AppendLine(); }; foreach (float num in Dialog_DebugActionsMenu.PointsOptions(false)) { float obj = num; action(obj); } Log.Message(sb.ToString(), false); }
public static void PawnGroupsMade() { Dialog_DebugOptionListLister.ShowSimpleDebugMenu <Faction>(from fac in Find.FactionManager.AllFactions where !fac.def.pawnGroupMakers.NullOrEmpty <PawnGroupMaker>() select fac, (Faction fac) => fac.Name + " (" + fac.def.defName + ")", delegate(Faction fac) { StringBuilder sb = new StringBuilder(); sb.AppendLine(string.Concat(new object[] { "FACTION: ", fac.Name, " (", fac.def.defName, ") min=", fac.def.MinPointsToGeneratePawnGroup(PawnGroupKindDefOf.Combat) })); Action <float> action = delegate(float points) { if (points < fac.def.MinPointsToGeneratePawnGroup(PawnGroupKindDefOf.Combat)) { return; } PawnGroupMakerParms pawnGroupMakerParms = new PawnGroupMakerParms(); pawnGroupMakerParms.groupKind = PawnGroupKindDefOf.Combat; pawnGroupMakerParms.tile = Find.CurrentMap.Tile; pawnGroupMakerParms.points = points; pawnGroupMakerParms.faction = fac; sb.AppendLine(string.Concat(new object[] { "Group with ", pawnGroupMakerParms.points, " points (max option cost: ", PawnGroupMakerUtility.MaxPawnCost(fac, points, RaidStrategyDefOf.ImmediateAttack, PawnGroupKindDefOf.Combat), ")" })); float num = 0f; foreach (Pawn current in PawnGroupMakerUtility.GeneratePawns(pawnGroupMakerParms, false).OrderBy((Pawn pa) => pa.kindDef.combatPower)) { string text; if (current.equipment.Primary != null) { text = current.equipment.Primary.Label; } else { text = "no-equipment"; } Apparel apparel = current.apparel.FirstApparelOnBodyPartGroup(BodyPartGroupDefOf.Torso); string text2; if (apparel != null) { text2 = apparel.LabelCap; } else { text2 = "shirtless"; } sb.AppendLine(string.Concat(new string[] { " ", current.kindDef.combatPower.ToString("F0").PadRight(6), current.kindDef.defName, ", ", text, ", ", text2 })); num += current.kindDef.combatPower; } sb.AppendLine(" totalCost " + num); sb.AppendLine(); }; foreach (float obj in Dialog_DebugActionsMenu.PointsOptions(false)) { action(obj); } Log.Message(sb.ToString(), false); }); }
protected override bool TryExecuteWorker(IncidentParms parms) { parms.points *= IncidentWorker_CaravanDemand.IncidentPointsFactorRange.RandomInRange; Caravan caravan = (Caravan)parms.target; if (!PawnGroupMakerUtility.TryGetRandomFactionForCombatPawnGroup(parms.points, out parms.faction, null, false, false, false, true)) { return(false); } List <ThingCount> demands = this.GenerateDemands(caravan); if (demands.NullOrEmpty <ThingCount>()) { return(false); } PawnGroupMakerParms defaultPawnGroupMakerParms = IncidentParmsUtility.GetDefaultPawnGroupMakerParms(PawnGroupKindDefOf.Combat, parms, false); defaultPawnGroupMakerParms.generateFightersOnly = true; defaultPawnGroupMakerParms.dontUseSingleUseRocketLaunchers = true; List <Pawn> attackers = PawnGroupMakerUtility.GeneratePawns(defaultPawnGroupMakerParms, true).ToList <Pawn>(); if (attackers.Count == 0) { Log.Error(string.Concat(new object[] { "Caravan demand incident couldn't generate any enemies even though min points have been checked. faction=", defaultPawnGroupMakerParms.faction, "(", (defaultPawnGroupMakerParms.faction == null) ? "null" : defaultPawnGroupMakerParms.faction.def.ToString(), ") parms=", parms }), false); return(false); } CameraJumper.TryJumpAndSelect(caravan); DiaNode diaNode = new DiaNode(this.GenerateMessageText(parms.faction, attackers.Count, demands, caravan)); DiaOption diaOption = new DiaOption("CaravanDemand_Give".Translate()); diaOption.action = delegate() { this.ActionGive(caravan, demands, attackers); }; diaOption.resolveTree = true; diaNode.options.Add(diaOption); DiaOption diaOption2 = new DiaOption("CaravanDemand_Fight".Translate()); diaOption2.action = delegate() { this.ActionFight(caravan, attackers); }; diaOption2.resolveTree = true; diaNode.options.Add(diaOption2); string text = "CaravanDemandTitle".Translate(new object[] { parms.faction.Name }); WindowStack windowStack = Find.WindowStack; DiaNode nodeRoot = diaNode; Faction faction = parms.faction; bool delayInteractivity = true; string title = text; windowStack.Add(new Dialog_NodeTreeWithFactionInfo(nodeRoot, faction, delayInteractivity, false, title)); Find.Archive.Add(new ArchivedDialog(diaNode.text, text, parms.faction)); return(true); }
// Token: 0x06000E1C RID: 3612 RVA: 0x00069B78 File Offset: 0x00067F78 protected override bool TryExecuteWorker(IncidentParms parms) { /* * GameConditionManager gameConditionManager = parms.target.GameConditionManager; * int duration = Mathf.RoundToInt(this.def.durationDays.RandomInRange * 60000f); * GameCondition cond = GameConditionMaker.MakeCondition(this.def.gameCondition, duration, 0); * gameConditionManager.RegisterCondition(cond); */ Map map = (Map)parms.target; IntVec3 spawnSpot; if (!this.TryFindSpawnSpot(map, out spawnSpot)) { return(false); } Faction faction = Find.FactionManager.FirstFactionOfDef(XenomorphDefOf.RRY_Xenomorph); if (faction == null) { return(false); } int @int = Rand.Int; IncidentParms raidParms = StorytellerUtility.DefaultParmsNow(IncidentCategoryDefOf.ThreatBig, map); raidParms.forced = true; raidParms.faction = faction; raidParms.raidStrategy = RaidStrategyDefOf.ImmediateAttack; raidParms.raidArrivalMode = PawnsArrivalModeDefOf.EdgeWalkIn; raidParms.spawnCenter = spawnSpot; raidParms.generateFightersOnly = true; raidParms.points = Mathf.Max(raidParms.points * IncidentWorker_PowerCutV2.RaidPointsFactorRange.RandomInRange, faction.def.MinPointsToGeneratePawnGroup(PawnGroupKindDefOf.Combat)); raidParms.pawnGroupMakerSeed = new int?(@int); PawnGroupMakerParms defaultPawnGroupMakerParms = IncidentParmsUtility.GetDefaultPawnGroupMakerParms(PawnGroupKindDefOf.Combat, raidParms, false); defaultPawnGroupMakerParms.points = IncidentWorker_Raid.AdjustedRaidPoints(defaultPawnGroupMakerParms.points, raidParms.raidArrivalMode, raidParms.raidStrategy, defaultPawnGroupMakerParms.faction, PawnGroupKindDefOf.Combat); IEnumerable <PawnKindDef> pawnKinds = PawnGroupMakerUtility.GeneratePawnKindsExample(defaultPawnGroupMakerParms); base.SendStandardLetter(); QueuedIncident qi = new QueuedIncident(new FiringIncident(IncidentDefOf.RaidEnemy, null, raidParms), 0, 0); Find.Storyteller.incidentQueue.Add(qi); @int = Rand.Int; if (!this.TryFindSpawnSpot(map, out spawnSpot)) { return(false); } raidParms = StorytellerUtility.DefaultParmsNow(IncidentCategoryDefOf.ThreatBig, map); raidParms.forced = true; raidParms.faction = faction; raidParms.raidStrategy = RaidStrategyDefOf.ImmediateAttack; raidParms.raidArrivalMode = PawnsArrivalModeDefOf.EdgeWalkIn; raidParms.spawnCenter = spawnSpot; raidParms.generateFightersOnly = true; raidParms.points = Mathf.Max(raidParms.points * IncidentWorker_PowerCutV2.RaidPointsFactorRange.RandomInRange, faction.def.MinPointsToGeneratePawnGroup(PawnGroupKindDefOf.Combat)); raidParms.pawnGroupMakerSeed = new int?(@int); defaultPawnGroupMakerParms = IncidentParmsUtility.GetDefaultPawnGroupMakerParms(PawnGroupKindDefOf.Combat, raidParms, false); defaultPawnGroupMakerParms.points = IncidentWorker_Raid.AdjustedRaidPoints(defaultPawnGroupMakerParms.points, raidParms.raidArrivalMode, raidParms.raidStrategy, defaultPawnGroupMakerParms.faction, PawnGroupKindDefOf.Combat); pawnKinds = PawnGroupMakerUtility.GeneratePawnKindsExample(defaultPawnGroupMakerParms); base.SendStandardLetter(); /* * qi = new QueuedIncident(new FiringIncident(IncidentDefOf.RaidEnemy, null, raidParms), Find.TickManager.TicksGame + IncidentWorker_PowerCutV2.RaidDelay.RandomInRange, 0); * Find.Storyteller.incidentQueue.Add(qi); */ List <Building> list = map.listerBuildings.allBuildingsColonist.FindAll(x => x.TryGetComp <CompPowerPlant>() != null); float chance = 1f; foreach (var item in list.OrderBy(x => x.TryGetComp <CompPowerPlant>().EnergyOutputPerTick)) { CompPowerPlant powerPlant = item.TryGetComp <CompPowerPlant>(); if (powerPlant != null) { CompBreakdownable breakdownable = item.TryGetComp <CompBreakdownable>(); if (Rand.ChanceSeeded(chance, AvPConstants.AvPSeed)) { if (breakdownable != null) { breakdownable.DoBreakdown(); chance -= 0.00001f * powerPlant.PowerOutput; } else { } chance -= 0.05f; } } } /* * DiaNode diaNode = new DiaNode(text); * DiaOption diaOption = new DiaOption("RefugeeChasedInitial_Accept".Translate()); * diaOption.action = delegate () * { * QueuedIncident qi = new QueuedIncident(new FiringIncident(IncidentDefOf.RaidEnemy, null, raidParms), Find.TickManager.TicksGame + IncidentWorker_PowerCut.RaidDelay.RandomInRange, 0); * Find.Storyteller.incidentQueue.Add(qi); * }; * diaOption.resolveTree = true; * diaNode.options.Add(diaOption); * string text2 = "RefugeeChasedRejected".Translate(refugee.LabelShort, refugee); * DiaNode diaNode2 = new DiaNode(text2); * DiaOption diaOption2 = new DiaOption("OK".Translate()); * diaOption2.resolveTree = true; * diaNode2.options.Add(diaOption2); * DiaOption diaOption3 = new DiaOption("RefugeeChasedInitial_Reject".Translate()); * diaOption3.action = delegate () * { * Find.WorldPawns.PassToWorld(refugee, PawnDiscardDecideMode.Decide); * }; * diaOption3.link = diaNode2; * diaNode.options.Add(diaOption3); * string title = "RefugeeChasedTitle".Translate(map.Parent.Label); * Find.WindowStack.Add(new Dialog_NodeTreeWithFactionInfo(diaNode, faction, true, true, title)); * Find.Archive.Add(new ArchivedDialog(diaNode.text, title, faction)); */ return(true); }
public virtual bool CanGenerateFrom(PawnGroupMakerParms parms, PawnGroupMaker groupMaker) { return(true); }
public static IEnumerable <PawnGenOption> ChoosePawnGenOptionsByPoints(float pointsTotal, List <PawnGenOption> options, PawnGroupMakerParms groupParms) { if (groupParms.seed.HasValue) { Rand.PushState(groupParms.seed.Value); } float num = MaxPawnCost(groupParms.faction, pointsTotal, groupParms.raidStrategy, groupParms.groupKind); List <PawnGenOption> list = new List <PawnGenOption>(); List <PawnGenOption> list2 = new List <PawnGenOption>(); float num2 = pointsTotal; bool flag = false; float highestCost = -1f; while (true) { list.Clear(); for (int i = 0; i < options.Count; i++) { PawnGenOption pawnGenOption = options[i]; if (!(pawnGenOption.Cost > num2) && !(pawnGenOption.Cost > num) && (!groupParms.generateFightersOnly || pawnGenOption.kind.isFighter) && (groupParms.raidStrategy == null || groupParms.raidStrategy.Worker.CanUsePawnGenOption(pawnGenOption, list2)) && (!groupParms.dontUseSingleUseRocketLaunchers || pawnGenOption.kind.weaponTags == null || !pawnGenOption.kind.weaponTags.Contains("GunSingleUse")) && (!flag || !pawnGenOption.kind.factionLeader)) { if (pawnGenOption.Cost > highestCost) { highestCost = pawnGenOption.Cost; } list.Add(pawnGenOption); } } if (list.Count == 0) { break; } Func <PawnGenOption, float> weightSelector = (PawnGenOption gr) => gr.selectionWeight * PawnWeightFactorByMostExpensivePawnCostFractionCurve.Evaluate(gr.Cost / highestCost); PawnGenOption pawnGenOption2 = list.RandomElementByWeight(weightSelector); list2.Add(pawnGenOption2); num2 -= pawnGenOption2.Cost; if (pawnGenOption2.kind.factionLeader) { flag = true; } } if (list2.Count == 1 && num2 > pointsTotal / 2f) { Log.Warning("Used only " + (pointsTotal - num2) + " / " + pointsTotal + " points generating for " + groupParms.faction); } if (groupParms.seed.HasValue) { Rand.PopState(); } return(list2); }
public override IEnumerable <PawnKindDef> GeneratePawnKindsExample(PawnGroupMakerParms parms, PawnGroupMaker groupMaker) { throw new NotImplementedException(); }
protected override bool TryExecuteWorker(IncidentParms parms) { Map map = (Map)parms.target; this.ResolveRaidPoints(parms); if (!this.TryResolveRaidFaction(parms)) { return(false); } PawnGroupKindDef combat = PawnGroupKindDefOf.Combat; this.ResolveRaidStrategy(parms, combat); this.ResolveRaidArriveMode(parms); if (!parms.raidArrivalMode.Worker.TryResolveRaidSpawnCenter(parms)) { return(false); } parms.points = IncidentWorker_Raid.AdjustedRaidPoints(parms.points, parms.raidArrivalMode, parms.raidStrategy, parms.faction, combat); PawnGroupMakerParms defaultPawnGroupMakerParms = IncidentParmsUtility.GetDefaultPawnGroupMakerParms(combat, parms, false); List <Pawn> list = PawnGroupMakerUtility.GeneratePawns(defaultPawnGroupMakerParms, true).ToList <Pawn>(); if (list.Count == 0) { Log.Error("Got no pawns spawning raid from parms " + parms, false); return(false); } parms.raidArrivalMode.Worker.Arrive(list, parms); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine("Points = " + parms.points.ToString("F0")); foreach (Pawn pawn in list) { string str = (pawn.equipment == null || pawn.equipment.Primary == null) ? "unarmed" : pawn.equipment.Primary.LabelCap; stringBuilder.AppendLine(pawn.KindLabel + " - " + str); } string letterLabel = this.GetLetterLabel(parms); string letterText = this.GetLetterText(parms, list); PawnRelationUtility.Notify_PawnsSeenByPlayer_Letter(list, ref letterLabel, ref letterText, this.GetRelatedPawnsInfoLetterText(parms), true, true); List <TargetInfo> list2 = new List <TargetInfo>(); if (parms.pawnGroups != null) { List <List <Pawn> > list3 = IncidentParmsUtility.SplitIntoGroups(list, parms.pawnGroups); List <Pawn> list4 = list3.MaxBy((List <Pawn> x) => x.Count); if (list4.Any <Pawn>()) { list2.Add(list4[0]); } for (int i = 0; i < list3.Count; i++) { if (list3[i] != list4) { if (list3[i].Any <Pawn>()) { list2.Add(list3[i][0]); } } } } else if (list.Any <Pawn>()) { list2.Add(list[0]); } Find.LetterStack.ReceiveLetter(letterLabel, letterText, this.GetLetterDef(), list2, parms.faction, stringBuilder.ToString()); parms.raidStrategy.Worker.MakeLords(parms, list); AvoidGridMaker.RegenerateAvoidGridsFor(parms.faction, map); LessonAutoActivator.TeachOpportunity(ConceptDefOf.EquippingWeapons, OpportunityType.Critical); if (!PlayerKnowledgeDatabase.IsComplete(ConceptDefOf.ShieldBelts)) { for (int j = 0; j < list.Count; j++) { Pawn pawn2 = list[j]; if (pawn2.apparel.WornApparel.Any((Apparel ap) => ap is ShieldBelt)) { LessonAutoActivator.TeachOpportunity(ConceptDefOf.ShieldBelts, OpportunityType.Critical); break; } } } return(true); }
protected override void GeneratePawns(PawnGroupMakerParms parms, PawnGroupMaker groupMaker, List <Pawn> outPawns, bool errorOnZeroResults = true) { if (!this.CanGenerateFrom(parms, groupMaker)) { if (errorOnZeroResults) { Log.Error("Cannot generate trader caravan for " + parms.faction + ".", false); } } else if (!parms.faction.def.caravanTraderKinds.Any <TraderKindDef>()) { Log.Error("Cannot generate trader caravan for " + parms.faction + " because it has no trader kinds.", false); } else { PawnGenOption pawnGenOption = groupMaker.traders.FirstOrDefault((PawnGenOption x) => !x.kind.trader); if (pawnGenOption != null) { Log.Error(string.Concat(new object[] { "Cannot generate arriving trader caravan for ", parms.faction, " because there is a pawn kind (", pawnGenOption.kind.LabelCap, ") who is not a trader but is in a traders list." }), false); } else { PawnGenOption pawnGenOption2 = groupMaker.carriers.FirstOrDefault((PawnGenOption x) => !x.kind.RaceProps.packAnimal); if (pawnGenOption2 != null) { Log.Error(string.Concat(new object[] { "Cannot generate arriving trader caravan for ", parms.faction, " because there is a pawn kind (", pawnGenOption2.kind.LabelCap, ") who is not a carrier but is in a carriers list." }), false); } else { if (parms.seed != null) { Log.Warning("Deterministic seed not implemented for this pawn group kind worker. The result will be random anyway.", false); } TraderKindDef traderKindDef; if (parms.traderKind != null) { traderKindDef = parms.traderKind; } else { traderKindDef = parms.faction.def.caravanTraderKinds.RandomElementByWeight((TraderKindDef traderDef) => traderDef.CalculatedCommonality); } TraderKindDef traderKindDef2 = traderKindDef; Pawn pawn = this.GenerateTrader(parms, groupMaker, traderKindDef2); outPawns.Add(pawn); ThingSetMakerParams parms2 = default(ThingSetMakerParams); parms2.traderDef = traderKindDef2; parms2.tile = new int?(parms.tile); parms2.traderFaction = parms.faction; List <Thing> wares = ThingSetMakerDefOf.TraderStock.root.Generate(parms2).InRandomOrder(null).ToList <Thing>(); foreach (Pawn item in this.GetSlavesAndAnimalsFromWares(parms, pawn, wares)) { outPawns.Add(item); } this.GenerateCarriers(parms, groupMaker, pawn, wares, outPawns); this.GenerateGuards(parms, groupMaker, pawn, wares, outPawns); } } } }
// Token: 0x06000E1C RID: 3612 RVA: 0x00069B78 File Offset: 0x00067F78 protected override bool TryExecuteWorker(IncidentParms parms) { GameConditionManager gameConditionManager = parms.target.GameConditionManager; int duration = Mathf.RoundToInt(this.def.durationDays.RandomInRange * 60000f); GameCondition cond = GameConditionMaker.MakeCondition(this.def.gameCondition, duration, 0); gameConditionManager.RegisterCondition(cond); Map map = (Map)parms.target; IntVec3 spawnSpot; if (!this.TryFindSpawnSpot(map, out spawnSpot)) { return(false); } Faction faction = Find.FactionManager.FirstFactionOfDef(XenomorphDefOf.RRY_Xenomorph); if (faction == null) { return(false); } int @int = Rand.Int; IncidentParms raidParms = StorytellerUtility.DefaultParmsNow(IncidentCategoryDefOf.ThreatBig, map); raidParms.forced = true; raidParms.faction = faction; raidParms.raidStrategy = RaidStrategyDefOf.ImmediateAttack; raidParms.raidArrivalMode = PawnsArrivalModeDefOf.EdgeWalkIn; raidParms.spawnCenter = spawnSpot; raidParms.generateFightersOnly = true; raidParms.points = Mathf.Max(raidParms.points * IncidentWorker_PowerCut.RaidPointsFactorRange.RandomInRange, faction.def.MinPointsToGeneratePawnGroup(PawnGroupKindDefOf.Combat)); raidParms.pawnGroupMakerSeed = new int?(@int); PawnGroupMakerParms defaultPawnGroupMakerParms = IncidentParmsUtility.GetDefaultPawnGroupMakerParms(PawnGroupKindDefOf.Combat, raidParms, false); defaultPawnGroupMakerParms.points = IncidentWorker_Raid.AdjustedRaidPoints(defaultPawnGroupMakerParms.points, raidParms.raidArrivalMode, raidParms.raidStrategy, defaultPawnGroupMakerParms.faction, PawnGroupKindDefOf.Combat); IEnumerable <PawnKindDef> pawnKinds = PawnGroupMakerUtility.GeneratePawnKindsExample(defaultPawnGroupMakerParms); base.SendStandardLetter(); QueuedIncident qi = new QueuedIncident(new FiringIncident(IncidentDefOf.RaidEnemy, null, raidParms), Find.TickManager.TicksGame + IncidentWorker_PowerCut.RaidDelay.RandomInRange, 0); Find.Storyteller.incidentQueue.Add(qi); /* * DiaNode diaNode = new DiaNode(text); * DiaOption diaOption = new DiaOption("RefugeeChasedInitial_Accept".Translate()); * diaOption.action = delegate () * { * QueuedIncident qi = new QueuedIncident(new FiringIncident(IncidentDefOf.RaidEnemy, null, raidParms), Find.TickManager.TicksGame + IncidentWorker_PowerCut.RaidDelay.RandomInRange, 0); * Find.Storyteller.incidentQueue.Add(qi); * }; * diaOption.resolveTree = true; * diaNode.options.Add(diaOption); * string text2 = "RefugeeChasedRejected".Translate(refugee.LabelShort, refugee); * DiaNode diaNode2 = new DiaNode(text2); * DiaOption diaOption2 = new DiaOption("OK".Translate()); * diaOption2.resolveTree = true; * diaNode2.options.Add(diaOption2); * DiaOption diaOption3 = new DiaOption("RefugeeChasedInitial_Reject".Translate()); * diaOption3.action = delegate () * { * Find.WorldPawns.PassToWorld(refugee, PawnDiscardDecideMode.Decide); * }; * diaOption3.link = diaNode2; * diaNode.options.Add(diaOption3); * string title = "RefugeeChasedTitle".Translate(map.Parent.Label); * Find.WindowStack.Add(new Dialog_NodeTreeWithFactionInfo(diaNode, faction, true, true, title)); * Find.Archive.Add(new ArchivedDialog(diaNode.text, title, faction)); */ return(true); }