protected override bool TryExecuteWorker(IncidentParms parms) { Map map = (Map)parms.target; if (!TryFindSpawnSpot(map, out IntVec3 spawnSpot)) { return(false); } if (!TryFindEnemyFaction(out Faction enemyFac)) { return(false); } int @int = Rand.Int; IncidentParms raidParms = StorytellerUtility.DefaultParmsNow(IncidentCategoryDefOf.ThreatBig, map); raidParms.forced = true; raidParms.faction = enemyFac; raidParms.raidStrategy = RaidStrategyDefOf.ImmediateAttack; raidParms.raidArrivalMode = PawnsArrivalModeDefOf.EdgeWalkIn; raidParms.spawnCenter = spawnSpot; raidParms.points = Mathf.Max(raidParms.points * RaidPointsFactorRange.RandomInRange, enemyFac.def.MinPointsToGeneratePawnGroup(PawnGroupKindDefOf.Combat)); raidParms.pawnGroupMakerSeed = @int; PawnGroupMakerParms defaultPawnGroupMakerParms = IncidentParmsUtility.GetDefaultPawnGroupMakerParms(PawnGroupKindDefOf.Combat, raidParms); 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, forceGenerateNewPawn: false, newborn: false, allowDead: false, allowDowned: false, canGeneratePawnRelations: true, mustBeCapableOfViolence: false, colonistRelationChanceFactor: 20f); Pawn refugee = PawnGenerator.GeneratePawn(request); refugee.relations.everSeenByPlayer = true; string text = "RefugeeChasedInitial".Translate(refugee.Name.ToStringFull, refugee.story.Title, enemyFac.def.pawnsPlural, enemyFac.Name, refugee.ageTracker.AgeBiologicalYears, PawnUtility.PawnKindsToCommaList(pawnKinds, useAnd: true), refugee.Named("PAWN")); text = text.AdjustedFor(refugee); TaggedString temp = new TaggedString(text); PawnRelationUtility.TryAppendRelationsWithColonistsInfo(ref temp, refugee); DiaNode diaNode = new DiaNode(text); DiaOption diaOption = new DiaOption("RefugeeChasedInitial_Accept".Translate()); diaOption.action = delegate { GenSpawn.Spawn(refugee, spawnSpot, map); refugee.SetFaction(Faction.OfPlayer); CameraJumper.TryJump(refugee); QueuedIncident qi = new QueuedIncident(new FiringIncident(IncidentDefOf.RaidEnemy, null, raidParms), Find.TickManager.TicksGame + RaidDelay.RandomInRange); 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); }; diaOption3.link = diaNode2; diaNode.options.Add(diaOption3); string title = "RefugeeChasedTitle".Translate(map.Parent.Label); Find.WindowStack.Add(new Dialog_NodeTreeWithFactionInfo(diaNode, enemyFac, delayInteractivity: true, radioMode: true, title: title)); Find.Archive.Add(new ArchivedDialog(diaNode.text, title, enemyFac)); return(true); }
public static void PawnGroupGenSampled() { List <DebugMenuOption> list = new List <DebugMenuOption>(); foreach (Faction current in Find.FactionManager.AllFactions) { if (current.def.pawnGroupMakers != null) { if (current.def.pawnGroupMakers.Any((PawnGroupMaker x) => x.kindDef == PawnGroupKindDefOf.Combat)) { Faction localFac = current; list.Add(new DebugMenuOption(localFac.Name + " (" + localFac.def.defName + ")", DebugMenuOptionMode.Action, delegate { List <DebugMenuOption> list2 = new List <DebugMenuOption>(); foreach (float localP2 in Dialog_DebugActionsMenu.PointsOptions(true)) { float localP = localP2; float maxPawnCost = PawnGroupMakerUtility.MaxPawnCost(localFac, localP, null, PawnGroupKindDefOf.Combat); string defName = (from op in localFac.def.pawnGroupMakers.SelectMany((PawnGroupMaker gm) => gm.options) where op.Cost <= maxPawnCost select op).MaxBy((PawnGenOption op) => op.Cost).kind.defName; string label = string.Concat(new string[] { localP.ToString(), ", max ", maxPawnCost.ToString("F0"), " ", defName }); list2.Add(new DebugMenuOption(label, DebugMenuOptionMode.Action, delegate { Dictionary <ThingDef, int>[] weaponsCount = new Dictionary <ThingDef, int> [20]; string[] pawnKinds = new string[20]; for (int i = 0; i < 20; i++) { weaponsCount[i] = new Dictionary <ThingDef, int>(); List <Pawn> list3 = PawnGroupMakerUtility.GeneratePawns(new PawnGroupMakerParms { groupKind = PawnGroupKindDefOf.Combat, tile = Find.CurrentMap.Tile, points = localP, faction = localFac }, false).ToList <Pawn>(); pawnKinds[i] = PawnUtility.PawnKindsToCommaList(list3, true); foreach (Pawn current2 in list3) { if (current2.equipment.Primary != null) { if (!weaponsCount[i].ContainsKey(current2.equipment.Primary.def)) { weaponsCount[i].Add(current2.equipment.Primary.def, 0); } Dictionary <ThingDef, int> dictionary; ThingDef def; (dictionary = weaponsCount[i])[def = current2.equipment.Primary.def] = dictionary[def] + 1; } current2.Destroy(DestroyMode.Vanish); } } int totalPawns = weaponsCount.Sum((Dictionary <ThingDef, int> x) => x.Sum((KeyValuePair <ThingDef, int> y) => y.Value)); List <TableDataGetter <int> > list4 = new List <TableDataGetter <int> >(); list4.Add(new TableDataGetter <int>(string.Empty, (int x) => (x != 20) ? (x + 1).ToString() : "avg")); list4.Add(new TableDataGetter <int>("pawns", delegate(int x) { string arg_64_0 = " "; string arg_64_1; if (x == 20) { arg_64_1 = ((float)totalPawns / 20f).ToString("0.#"); } else { arg_64_1 = weaponsCount[x].Sum((KeyValuePair <ThingDef, int> y) => y.Value).ToString(); } return(arg_64_0 + arg_64_1); })); list4.Add(new TableDataGetter <int>("kinds", (int x) => (x != 20) ? pawnKinds[x] : string.Empty)); list4.AddRange(from x in DefDatabase <ThingDef> .AllDefs where x.IsWeapon && !x.weaponTags.NullOrEmpty <string>() && weaponsCount.Any((Dictionary <ThingDef, int> wc) => wc.ContainsKey(x)) orderby x.IsMeleeWeapon descending, x.techLevel, x.BaseMarketValue select new TableDataGetter <int>(x.label.Shorten(), delegate(int y) { if (y == 20) { return(" " + ((float)weaponsCount.Sum((Dictionary <ThingDef, int> z) => (!z.ContainsKey(x)) ? 0 : z[x]) / 20f).ToString("0.#")); } string arg_104_0; if (weaponsCount[y].ContainsKey(x)) { object[] expr_66 = new object[5]; expr_66[0] = " "; expr_66[1] = weaponsCount[y][x]; expr_66[2] = " ("; expr_66[3] = ((float)weaponsCount[y][x] / (float)weaponsCount[y].Sum((KeyValuePair <ThingDef, int> z) => z.Value)).ToStringPercent("F0"); expr_66[4] = ")"; arg_104_0 = string.Concat(expr_66); } else { arg_104_0 = string.Empty; } return(arg_104_0); })); DebugTables.MakeTablesDialog <int>(Enumerable.Range(0, 21), list4.ToArray()); })); } Find.WindowStack.Add(new Dialog_DebugOptionListLister(list2)); })); } } } Find.WindowStack.Add(new Dialog_DebugOptionListLister(list)); }
public static void PawnGroupGenSampled() { List <DebugMenuOption> list = new List <DebugMenuOption>(); foreach (Faction allFaction in Find.FactionManager.AllFactions) { if (allFaction.def.pawnGroupMakers != null && allFaction.def.pawnGroupMakers.Any((PawnGroupMaker x) => x.kindDef == PawnGroupKindDefOf.Combat)) { Faction localFac = allFaction; float localP = default(float); float maxPawnCost = default(float); list.Add(new DebugMenuOption(localFac.Name + " (" + localFac.def.defName + ")", DebugMenuOptionMode.Action, delegate { List <DebugMenuOption> list2 = new List <DebugMenuOption>(); foreach (float item in DebugActionsUtility.PointsOptions(extended: true)) { localP = item; maxPawnCost = PawnGroupMakerUtility.MaxPawnCost(localFac, localP, null, PawnGroupKindDefOf.Combat); string defName = (from op in localFac.def.pawnGroupMakers.SelectMany((PawnGroupMaker gm) => gm.options) where op.Cost <= maxPawnCost select op).MaxBy((PawnGenOption op) => op.Cost).kind.defName; string label = localP.ToString() + ", max " + maxPawnCost.ToString("F0") + " " + defName; list2.Add(new DebugMenuOption(label, DebugMenuOptionMode.Action, delegate { Dictionary <ThingDef, int>[] weaponsCount = new Dictionary <ThingDef, int> [20]; string[] pawnKinds = new string[20]; for (int i = 0; i < 20; i++) { weaponsCount[i] = new Dictionary <ThingDef, int>(); List <Pawn> list3 = PawnGroupMakerUtility.GeneratePawns(new PawnGroupMakerParms { groupKind = PawnGroupKindDefOf.Combat, tile = Find.CurrentMap.Tile, points = localP, faction = localFac }, warnOnZeroResults: false).ToList(); pawnKinds[i] = PawnUtility.PawnKindsToCommaList(list3, useAnd: true); foreach (Pawn item2 in list3) { if (item2.equipment.Primary != null) { if (!weaponsCount[i].ContainsKey(item2.equipment.Primary.def)) { weaponsCount[i].Add(item2.equipment.Primary.def, 0); } weaponsCount[i][item2.equipment.Primary.def]++; } item2.Destroy(); } } int totalPawns = weaponsCount.Sum((Dictionary <ThingDef, int> x) => x.Sum((KeyValuePair <ThingDef, int> y) => y.Value)); List <TableDataGetter <int> > list4 = new List <TableDataGetter <int> >(); list4.Add(new TableDataGetter <int>("", (int x) => (x != 20) ? (x + 1).ToString() : "avg")); list4.Add(new TableDataGetter <int>("pawns", (int x) => " " + ((x == 20) ? ((float)totalPawns / 20f).ToString("0.#") : weaponsCount[x].Sum((KeyValuePair <ThingDef, int> y) => y.Value).ToString()))); list4.Add(new TableDataGetter <int>("kinds", (int x) => (x != 20) ? pawnKinds[x] : "")); list4.AddRange(from x in DefDatabase <ThingDef> .AllDefs where x.IsWeapon && !x.weaponTags.NullOrEmpty() && weaponsCount.Any((Dictionary <ThingDef, int> wc) => wc.ContainsKey(x)) orderby x.IsMeleeWeapon descending, x.techLevel, x.BaseMarketValue select new TableDataGetter <int>(x.label.Shorten(), delegate(int y) { if (y == 20) { return(" " + ((float)weaponsCount.Sum((Dictionary <ThingDef, int> z) => z.ContainsKey(x) ? z[x] : 0) / 20f).ToString("0.#")); } return((!weaponsCount[y].ContainsKey(x)) ? "" : (" " + weaponsCount[y][x] + " (" + ((float)weaponsCount[y][x] / (float)weaponsCount[y].Sum((KeyValuePair <ThingDef, int> z) => z.Value)).ToStringPercent("F0") + ")")); })); DebugTables.MakeTablesDialog(Enumerable.Range(0, 21), list4.ToArray()); })); } Find.WindowStack.Add(new Dialog_DebugOptionListLister(list2)); })); } } Find.WindowStack.Add(new Dialog_DebugOptionListLister(list)); }
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"); if (Quote != null) { text += "\n\n"; text += Quote; } 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); }