public override void Generate(Map map, GenStepParams parms) { CellRect around; IntVec3 near; if (!SiteGenStepUtility.TryFindRootToSpawnAroundRectOfInterest(out around, out near, map)) { return; } List <Pawn> list = new List <Pawn>(); foreach (Pawn current in this.GeneratePawns(parms, map)) { IntVec3 loc; if (!SiteGenStepUtility.TryFindSpawnCellAroundOrNear(around, near, map, out loc)) { Find.WorldPawns.PassToWorld(current, PawnDiscardDecideMode.Decide); break; } GenSpawn.Spawn(current, loc, map, WipeMode.Vanish); list.Add(current); } if (!list.Any <Pawn>()) { return; } LordMaker.MakeNewLord(Faction.OfMechanoids, new LordJob_AssaultColony(Faction.OfMechanoids, Rand.Bool), map, list); for (int i = 0; i < list.Count; i++) { list[i].jobs.EndCurrentJob(JobCondition.InterruptForced, true); } }
public override void Generate(Map map, GenStepParams parms) { if (this.forcedfaction != null) { parms.sitePart.site.SetFaction(forcedfaction); } int h = 10, w = 10; List <Pawn> list = new List <Pawn>(); foreach (Pawn pawn in this.GeneratePawns(map, parms)) { IntVec3 loc; if (this.spawnOnEdge) { if (!CellFinder.TryFindRandomEdgeCellWith((IntVec3 x) => x.Standable(map) && !x.Fogged(map) && map.reachability.CanReachColony(x), map, CellFinder.EdgeRoadChance_Ignore, out loc)) { Find.WorldPawns.PassToWorld(pawn, PawnDiscardDecideMode.Decide); break; } } else if (!SiteGenStepUtility.TryFindSpawnCellAroundOrNear(CellRect.CenteredOn(map.Center, w, h), map.Center, map, out loc)) { Find.WorldPawns.PassToWorld(pawn, PawnDiscardDecideMode.Decide); break; } GenSpawn.Spawn(pawn, loc, map, WipeMode.Vanish); if (!this.spawnOnEdge) { for (int i = 0; i < 10; i++) { MoteMaker.ThrowAirPuffUp(pawn.DrawPos, map); } } list.Add(pawn); } if (!list.Any <Pawn>()) { return; } Faction faction = list[0].Faction; LordMaker.MakeNewLord(faction, new LordJob_DefendBase(faction, map.Center), map, list); if (!this.spawnOnEdge) { for (int k = 0; k < list.Count; k++) { list[k].jobs.StartJob(JobMaker.MakeJob(JobDefOf.Wait, 120, false), JobCondition.None, null, false, true, null, null, false, false); list[k].Rotation = Rot4.Random; } } }
public override void Generate(Map map, GenStepParams parms) { int cycle = 0; while (1 == 1) { cycle += 1; if (cycle > 20) { return; } if (!TryFindFightingFactions(out enemyFaction, out friendlyFaction)) { continue; } // Check result for valid pawnGroupMakers --> This should normally not be invalid as it is checked in the faction finder, but someone still got invalid factions.. if (enemyFaction == null || enemyFaction.def.pawnGroupMakers.NullOrEmpty() || friendlyFaction == null || friendlyFaction.def.pawnGroupMakers.NullOrEmpty()) { continue; } break; } float defaultPoints = defaultPointsRange.RandomInRange; if ((parms.sitePart != null) && parms.sitePart.parms.threatPoints < defaultPoints) { parms.sitePart.parms.threatPoints = defaultPoints; } GenStepParams parmsEnemy = parms; GenStepParams parmsFriendly = parms; float randomForMechanoids = Rand.Value; if (randomForMechanoids < chanceForMechanoids && parms.sitePart != null) { // 50% chance that the fighting faction against the mechanoid is an enemy of the colony if (Rand.Value > 0.5f) { friendlyFaction = enemyFaction; } // define mechanoid side enemyFaction = Faction.OfMechanoids; parmsEnemy.sitePart.parms.threatPoints = parmsEnemy.sitePart.parms.threatPoints * multiMechFight_Mechanoids; // define human side if (friendlyFaction.def.techLevel > TechLevel.Medieval) { parmsFriendly.sitePart.parms.threatPoints = parmsFriendly.sitePart.parms.threatPoints * multiMechFight_Industrial; } else { parmsFriendly.sitePart.parms.threatPoints = parmsFriendly.sitePart.parms.threatPoints * multiMechFight_Medieval; } } else // --> not Mechanoid fighting { // Friendlies are a bit weaker! if (parmsFriendly.sitePart != null) { parmsFriendly.sitePart.parms.threatPoints = parmsFriendly.sitePart.parms.threatPoints * multiNormalFight_Friendlies; } // 20% chance that friendlies are NOT the attacker but the defender // This is a bit more dangerous for the watching colonists as they might spawn directly next to you.. if (Rand.Value < 0.20f) { Faction tmpFaction = friendlyFaction; friendlyFaction = enemyFaction; enemyFaction = tmpFaction; GenStepParams parmsTmp = parmsFriendly; parmsFriendly = parmsEnemy; parmsEnemy = parmsTmp; } } // Spawn side 1 (defending) CellRect rectToDefend1; IntVec3 singleCellToSpawnNear1; if (SiteGenStepUtility.TryFindRootToSpawnAroundRectOfInterest(out rectToDefend1, out singleCellToSpawnNear1, map)) { if (rectToDefend1 == null || !rectToDefend1.InBounds(map) || !map.AllCells.Contains(rectToDefend1.CenterCell) || rectToDefend1.Cells.Count() == 0) { rectToDefend1 = CellRect.CenteredOn(map.Center, 10); } List <Pawn> list = new List <Pawn>(); foreach (Pawn item in this.GeneratePawns(parmsEnemy, map, this.enemyFaction)) { IntVec3 spawnCell; if (!SiteGenStepUtility.TryFindSpawnCellAroundOrNear(rectToDefend1, singleCellToSpawnNear1, map, out spawnCell)) { Find.WorldPawns.PassToWorld(item, PawnDiscardDecideMode.Decide); break; } GenSpawn.Spawn(item, spawnCell, map, WipeMode.Vanish); list.Add(item); } if (list.Any()) { if (this.enemyFaction == Faction.OfMechanoids) { //LordMaker.MakeNewLord(Faction.OfMechanoids, new LordJob_SleepThenAssaultColony(Faction.OfMechanoids), map, list); LordMaker.MakeNewLord(Faction.OfMechanoids, new LordJob_DefendAndExpandHive(), map, list); } else { LordMaker.MakeNewLord(this.enemyFaction, new LordJob_DefendBase(this.enemyFaction, rectToDefend1.Cells.RandomElement()), map, list); } for (int i = 0; i < list.Count; i++) { list[i].jobs.EndCurrentJob(JobCondition.InterruptForced, true); } } } // Spawn side 2 (attacking) //CellRect rectToDefend2; //IntVec3 singleCellToSpawnNear2; IntVec3 spawnCellPawns; //if (SiteGenStepUtility.TryFindRootToSpawnAroundRectOfInterest(out rectToDefend2, out singleCellToSpawnNear2, map) && // RCellFinder.TryFindRandomPawnEntryCell(out spawnCellPawns, map, 0.5f)) if (RCellFinder.TryFindRandomPawnEntryCell(out spawnCellPawns, map, 0.5f)) { List <Pawn> list2 = new List <Pawn>(); foreach (Pawn item in this.GeneratePawns(parmsFriendly, map, this.friendlyFaction)) { IntVec3 spawnCell; //if (!SiteGenStepUtility.TryFindSpawnCellAroundOrNear(rectToDefend2, singleCellToSpawnNear2, map, out spawnCell)) if (!SiteGenStepUtility.TryFindSpawnCellAroundOrNear(rectToDefend1, spawnCellPawns, map, out spawnCell)) { Find.WorldPawns.PassToWorld(item, PawnDiscardDecideMode.Decide); break; } GenSpawn.Spawn(item, spawnCell, map, WipeMode.Vanish); list2.Add(item); } if (list2.Any()) { LordMaker.MakeNewLord(this.friendlyFaction, new LordJob_AssistColony(this.friendlyFaction, rectToDefend1.Cells.RandomElement()), map, list2); for (int i = 0; i < list2.Count; i++) { list2[i].jobs.EndCurrentJob(JobCondition.InterruptForced, true); } } } }
static bool Prefix(ref SignalAction_Ambush __instance, SignalArgs args) { Map map = __instance.Map; if (__instance.points <= 0f) { return(false); } List <Pawn> list = new List <Pawn>(); foreach (Pawn item in (IEnumerable <Pawn>)GenerateAmbushPawnsInfo.Invoke(__instance, new object[] { })) { // Skip out if the pawn isn't suitable for the map if (!map.PawnKindCanEnter(item.kindDef)) { Find.WorldPawns.PassToWorld(item); break; } IntVec3 result; if (__instance.spawnPawnsOnEdge) { // Changed to CellFinderExtended if (!CellFinderExtended.TryFindRandomEdgeCellWith((IntVec3 x) => x.Standable(map) && !x.Fogged(map) && map.reachability.CanReachColony(x), map, item.kindDef, CellFinder.EdgeRoadChance_Ignore, out result)) { Find.WorldPawns.PassToWorld(item); break; } } // TODO: PawnKind aware find cell around else if (!SiteGenStepUtility.TryFindSpawnCellAroundOrNear(__instance.spawnAround, __instance.spawnNear, map, out result)) { Find.WorldPawns.PassToWorld(item); break; } GenSpawn.Spawn(item, result, map); if (!__instance.spawnPawnsOnEdge) { for (int i = 0; i < 10; i++) { MoteMaker.ThrowAirPuffUp(item.DrawPos, map); } } list.Add(item); } if (!list.Any()) { return(false); } if (__instance.ambushType == SignalActionAmbushType.Manhunters) { for (int j = 0; j < list.Count; j++) { list[j].mindState.mentalStateHandler.TryStartMentalState(MentalStateDefOf.ManhunterPermanent); } } else { Faction faction = list[0].Faction; LordMaker.MakeNewLord(faction, new LordJob_AssaultColony(faction), map, list); } if (!__instance.spawnPawnsOnEdge) { for (int k = 0; k < list.Count; k++) { list[k].jobs.StartJob(JobMaker.MakeJob(JobDefOf.Wait, 120)); list[k].Rotation = Rot4.Random; } } Find.LetterStack.ReceiveLetter("LetterLabelAmbushInExistingMap".Translate(), "LetterAmbushInExistingMap".Translate(Faction.OfPlayer.def.pawnsPlural).CapitalizeFirst(), LetterDefOf.ThreatBig, list[0]); return(false); }