private void GenerateFactions() { if (regenerate) { RemoveAllFactions(); } for (int i = 0; i < FactionToGenerate; i++) { FactionDef facDef = (from fa in DefDatabase <FactionDef> .AllDefs where fa.canMakeRandomly && !fa.hidden && !fa.isPlayer select fa).RandomElement(); Faction faction = NewGeneratedFaction(facDef); Find.FactionManager.Add(faction); } int num = GenMath.RoundRandom((float)Find.WorldGrid.TilesCount / 100000f * SettlementsPer100kTiles.RandomInRange); num -= Find.WorldObjects.Settlements.Count; for (int k = 0; k < num; k++) { Faction faction3 = (from x in Find.World.factionManager.AllFactionsListForReading where !x.def.isPlayer && !x.def.hidden select x).RandomElementByWeight((Faction x) => x.def.settlementGenerationWeight); Settlement settlement = (Settlement)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.Settlement); settlement.SetFaction(faction3); settlement.Tile = TileFinder.RandomSettlementTileFor(faction3); settlement.Name = SettlementNameGenerator.GenerateSettlementName(settlement); Find.WorldObjects.Add(settlement); } }
public static void GenerateFactionsIntoWorld() { int i = 0; foreach (FactionDef allDef in DefDatabase <FactionDef> .AllDefs) { for (int j = 0; j < allDef.requiredCountAtGameStart; j++) { Faction faction = NewGeneratedFaction(allDef); Find.FactionManager.Add(faction); if (!faction.Hidden) { i++; } } } for (; i < 5; i++) { Faction faction2 = NewGeneratedFaction(DefDatabase <FactionDef> .AllDefs.Where((FactionDef fa) => fa.canMakeRandomly && Find.FactionManager.AllFactions.Count((Faction f) => f.def == fa) < fa.maxCountAtGameStart).RandomElement()); Find.World.factionManager.Add(faction2); } int num = GenMath.RoundRandom((float)Find.WorldGrid.TilesCount / 100000f * SettlementsPer100kTiles.RandomInRange * Find.World.info.overallPopulation.GetScaleFactor()); num -= Find.WorldObjects.Settlements.Count; for (int k = 0; k < num; k++) { Faction faction3 = Find.World.factionManager.AllFactionsListForReading.Where((Faction x) => !x.def.isPlayer && !x.Hidden && !x.temporary).RandomElementByWeight((Faction x) => x.def.settlementGenerationWeight); Settlement settlement = (Settlement)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.Settlement); settlement.SetFaction(faction3); settlement.Tile = TileFinder.RandomSettlementTileFor(faction3); settlement.Name = SettlementNameGenerator.GenerateSettlementName(settlement); Find.WorldObjects.Add(settlement); } }
private static void MakeHomeForSquatters() { IEnumerable <WorldObject> abandoned = Find.WorldObjects.AllWorldObjects .Where(wObject => wObject.def == WorldObjectDefOf.AbandonedSettlement || wObject.def == WorldObjectDefOf.DestroyedSettlement); foreach (WorldObject wObject in abandoned) { if (wObject.Tile - wObject.ID % 10 == 0) { continue; } if (Find.TickManager.TicksGame > wObject.creationGameTicks + GenDate.TicksPerYear * (1 + UnityEngine.Mathf.Clamp01(wObject.ID / 10))) { if (Rand.Chance(0.000175f)) //350 ticks / 0.000175 == 2,000,000 ticks =~ 33 days { Settlement settlement = (Settlement)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.Settlement); settlement.SetFaction(Find.FactionManager.AllFactionsVisible.Where(x => x.def.settlementGenerationWeight > 0f).RandomElement()); settlement.Tile = wObject.Tile; settlement.Name = SettlementNameGenerator.GenerateSettlementName(settlement); Find.WorldObjects.Remove(wObject); Find.WorldObjects.Add(settlement); Find.LetterStack.ReceiveLetter("MFI_LetterLabelSquatters".Translate(), "MFI_LetterSquatters".Translate(settlement.Faction, settlement.Name), LetterDefOf.NeutralEvent, settlement); } } } }
public static Faction NewGeneratedFaction(FactionDef facDef) { Faction faction = new Faction(); faction.def = facDef; faction.loadID = Find.UniqueIDsManager.GetNextFactionID(); faction.colorFromSpectrum = FactionGenerator.NewRandomColorFromSpectrum(faction); if (!facDef.isPlayer) { if (facDef.fixedName != null) { faction.Name = facDef.fixedName; } else { faction.Name = NameGenerator.GenerateName(facDef.factionNameMaker, from fac in Find.FactionManager.AllFactionsVisible select fac.Name, false, null); } } faction.centralMelanin = Rand.Value; foreach (Faction current in Find.FactionManager.AllFactionsListForReading) { faction.TryMakeInitialRelationsWith(current); } if (!facDef.hidden && !facDef.isPlayer) { Settlement settlement = (Settlement)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.Settlement); settlement.SetFaction(faction); settlement.Tile = TileFinder.RandomSettlementTileFor(faction, false, null); settlement.Name = SettlementNameGenerator.GenerateSettlementName(settlement, null); Find.WorldObjects.Add(settlement); } faction.GenerateNewLeader(); return(faction); }
private static void CreateSettlements(Faction faction) { int existingFactions = Find.FactionManager.AllFactionsVisible.Count(); int amount = GenMath.RoundRandom(Find.WorldGrid.TilesCount / 100000f * settlementsPer100KTiles.RandomInRange / existingFactions * Settings.newFactionSettlementFactor); // New factions get less bases amount = Mathf.Max(Settings.minSettlements, amount); int count = 0; for (int k = 0; k < amount; k++) { var tile = TileFinder.RandomSettlementTileFor(faction); if (tile == 0) { continue; } var factionBase = (Settlement)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.Settlement); factionBase.SetFaction(faction); factionBase.Tile = tile; factionBase.Name = SettlementNameGenerator.GenerateSettlementName(factionBase); Find.WorldObjects.Add(factionBase); count++; } Log.Message("Created " + count + " settlements for " + faction.def.LabelCap); }
public override void PreMapGenerate() { Settlement settlement = (Settlement)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.Settlement); settlement.SetFaction(Find.GameInitData.playerFaction); settlement.Tile = Find.GameInitData.startingTile; settlement.Name = SettlementNameGenerator.GenerateSettlementName(settlement, Find.GameInitData.playerFaction.def.playerInitialSettlementNameMaker); Find.WorldObjects.Add(settlement); }
private void GiveRewardsAndSendLetter(bool giveTech, bool newFaction) { string text = "RD_GratefulSurvivors".Translate(); string text2 = "RD_GratefulSurvivorsDesc".Translate(); //"The survivors of the crash are very thankful for your help, and have send some supplies as a gesture of gratitude."; if (giveTech) { ThingDef.Named("Gun_ChargeRifle"); ThingDef thingDef = this.RandomHiTechReward(); ThingDef stuff = null; if (thingDef.MadeFromStuff) { stuff = GenStuff.DefaultStuffFor(thingDef); } this.rewards.TryAdd(ThingMaker.MakeThing(thingDef, stuff), true); text2 = "RD_GratefulSurvivorsAmazedDesc".Translate(); //"The survivors of the crash are amazed by your rapid and professional emergency medical response, thanks to which no-one died. In gratitude, they have included a special system removed form the wreck."; } Find.LetterStack.ReceiveLetter(text, text2, LetterDefOf.PositiveEvent, null); Map map = Find.AnyPlayerHomeMap ?? ((MapParent)this.parent).Map; QuestComp_MedicalEmergency.tmpRewards.AddRange(this.rewards); this.rewards.Clear(); IntVec3 dropCenter = DropCellFinder.TradeDropSpot(map); DropPodUtility.DropThingsNear(dropCenter, map, QuestComp_MedicalEmergency.tmpRewards, 110, false, false, true); QuestComp_MedicalEmergency.tmpRewards.Clear(); if (newFaction) { int tile = this.parent.Tile; this.CloseMapImmediate(); Faction faction = FactionGenerator.NewGeneratedFaction(FactionDefOf.Ancients); map.pawnDestinationReservationManager.GetPawnDestinationSetFor(faction); Find.FactionManager.Add(faction); Settlement settlement = (Settlement)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.Settlement); settlement.SetFaction(faction); settlement.Tile = tile; settlement.Name = SettlementNameGenerator.GenerateSettlementName(settlement, null); Find.WorldObjects.Add(settlement); faction.leader = null; foreach (Pawn pawn in this.injured) { if (!pawn.Dead && pawn.Faction != Faction.OfPlayer) { pawn.SetFactionDirect(faction); if (faction.leader == null) { faction.leader = pawn; } } } faction.TryAffectGoodwillWith(Faction.OfPlayer, 100); string text3 = "RD_NewFaction".Translate(); //New Faction! string text4 = "RD_NewFactionDesc".Translate() + faction.Name; //"The survivors of the crash have decided to make a life for themselves here, and have founded a new faction" Find.LetterStack.ReceiveLetter(text3, text4, LetterDefOf.PositiveEvent, null); } }
public override void WorldComponentTick() { base.WorldComponentTick(); if (Find.TickManager.TicksGame % 350 == 0) { TickLetters(); IEnumerable <WorldObject> abandoned = from wObject in Find.WorldObjects.AllWorldObjects where wObject.def == WorldObjectDefOf.AbandonedSettlement || wObject.def == WorldObjectDefOf.DestroyedSettlement select wObject; foreach (WorldObject wObject in abandoned) { if (wObject.Tile - wObject.ID % 10 == 0) { continue; } if (Find.TickManager.TicksGame > wObject.creationGameTicks + GenDate.TicksPerYear * (1 + UnityEngine.Mathf.Clamp01(wObject.ID / 10))) { if (Rand.Chance(0.000175f)) //350 ticks / 0.000175 == 2,000,000 ticks =~ 33 days { Settlement settlement = (Settlement)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.Settlement); settlement.SetFaction(Find.FactionManager.AllFactionsVisible.Where(x => x.def.settlementGenerationWeight > 0f).RandomElement()); settlement.Tile = wObject.Tile; settlement.Name = SettlementNameGenerator.GenerateSettlementName(settlement); Find.WorldObjects.Remove(wObject); Find.WorldObjects.Add(settlement); Find.LetterStack.ReceiveLetter("MFI_LetterLabelSquatters".Translate(), "MFI_LetterSquatters".Translate(settlement.Faction, settlement.Name), LetterDefOf.NeutralEvent, settlement); } } } //get settlements to upgrade. These shouldn't include temp generated or event maps -- preferably only the outposts this spawned by this mod //ideally I'd add some specific Component to each outpost (as a unique identifier and maybe even as the thing that makes em upgrade), but for the moment that's not needed. IEnumerable <Site> sites = from site in Find.WorldObjects.Sites where site.Faction.HostileTo(other: Faction.OfPlayer) && site.Faction.def.permanentEnemy && !site.Faction.def.hidden && !site.Faction.defeated && (site.HasMap ? site.ShouldRemoveMapNow(out bool alsoRemoveWorldObject) : true) && site.parts.Any(predicate: (SitePart x) => x.Def == SitePartDefOf.Outpost) && !site.GetComponent <TimeoutComp>().Active select site; foreach (Site current in sites) { if (current.creationGameTicks + MoreFactionInteraction_Settings.ticksToUpgrade <= Find.TickManager.TicksGame) { UpgradeSiteToSettlement(current); break; } } } }
private static void UpgradeSiteToSettlement(Site toUpgrade) { Settlement factionBase = (Settlement)WorldObjectMaker.MakeWorldObject(def: WorldObjectDefOf.Settlement); factionBase.SetFaction(newFaction: toUpgrade.Faction); factionBase.Tile = toUpgrade.Tile; factionBase.Name = SettlementNameGenerator.GenerateSettlementName(factionBase: factionBase); Find.WorldObjects.Remove(o: toUpgrade); Find.WorldObjects.Add(o: factionBase); Find.LetterStack.ReceiveLetter(label: "MFI_LetterLabelBanditOutpostUpgraded".Translate(), text: "MFI_LetterBanditOutpostUpgraded".Translate( factionBase.Faction.Name ), textLetterDef: LetterDefOf.NeutralEvent, lookTargets: factionBase, relatedFaction: toUpgrade.Faction); }
private void Ressurect() { if (resurrectSet && !ally.defeated) { Settlement resurrect = (Settlement)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.Settlement); Faction faction = ally; resurrect.SetFaction(faction); resurrect.Tile = parent.Tile; resurrect.creationGameTicks = parent.creationGameTicks; resurrect.Name = SettlementNameGenerator.GenerateSettlementName(resurrect); Find.WorldObjects.AllWorldObjects.Add(resurrect); Utilities.FactionsWar().GetByFaction(resurrect.Faction).resources += FE_WorldComp_FactionsWar.SETTLEMENT_RESOURCE_VALUE; } }
public override void PreMapGenerate() { var defaultSettlement = Find.WorldObjects.MapParentAt(Find.GameInitData.startingTile); Find.WorldObjects.Remove(defaultSettlement); var city = (City)WorldObjectMaker.MakeWorldObject(DefDatabase <WorldObjectDef> .GetNamed(GetObjectDefName())); city.SetFaction(Find.GameInitData.playerFaction); city.inhabitantFaction = GenCity.RandomCityFaction(IsValidFaction); city.Tile = Find.GameInitData.startingTile; city.Name = SettlementNameGenerator.GenerateSettlementName(city, city.inhabitantFaction?.def.factionNameMaker); Find.WorldObjects.Add(city); }
private static void SpawnRandomFactionBase() { if (Find.FactionManager.AllFactions.Where((Faction x) => !x.IsPlayer && !x.def.hidden).TryRandomElement(out Faction result)) { int num = GenWorld.MouseTile(); if (!Find.WorldGrid[num].biome.impassable) { Settlement settlement = (Settlement)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.Settlement); settlement.SetFaction(result); settlement.Tile = num; settlement.Name = SettlementNameGenerator.GenerateSettlementName(settlement); Find.WorldObjects.Add(settlement); } } }
private static void UpgradeSiteToSettlement(Site toUpgrade) { var factionBase = (Settlement)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.Settlement); factionBase.SetFaction(toUpgrade.Faction); factionBase.Tile = toUpgrade.Tile; factionBase.Name = SettlementNameGenerator.GenerateSettlementName(factionBase); Find.WorldObjects.Remove(toUpgrade); Find.WorldObjects.Add(factionBase); Find.LetterStack.ReceiveLetter( "MFI_LetterLabelBanditOutpostUpgraded".Translate(), "MFI_LetterBanditOutpostUpgraded".Translate(factionBase.Faction.Name), LetterDefOf.NeutralEvent, factionBase, toUpgrade.Faction); }
public static void SpawnNewFactionBasesIntoWorld(Faction newFaction, int numOfBases) { if (newFaction == null) { return; } for (int k = 0; k < numOfBases; k++) { Settlement settlement = (Settlement)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.Settlement); settlement.SetFaction(newFaction); settlement.Tile = TileFinder.RandomSettlementTileFor(newFaction); settlement.Name = SettlementNameGenerator.GenerateSettlementName(settlement); Find.WorldObjects.Add(settlement); } }
public static Faction NewGeneratedFaction(FactionDef facDef) { Faction faction = new Faction(); faction.def = facDef; faction.loadID = Find.UniqueIDsManager.GetNextFactionID(); faction.colorFromSpectrum = NewRandomColorFromSpectrum(faction); if (!facDef.isPlayer) { if (facDef.fixedName != null) { faction.Name = facDef.fixedName; } else { string text = ""; for (int i = 0; i < 10; i++) { string text2 = NameGenerator.GenerateName(facDef.factionNameMaker, Find.FactionManager.AllFactionsVisible.Select((Faction fac) => fac.Name)); if (text2.Length <= 20) { text = text2; } } if (text.NullOrEmpty()) { text = NameGenerator.GenerateName(facDef.factionNameMaker, Find.FactionManager.AllFactionsVisible.Select((Faction fac) => fac.Name)); } faction.Name = text; } } faction.centralMelanin = Rand.Value; foreach (Faction item in Find.FactionManager.AllFactionsListForReading) { faction.TryMakeInitialRelationsWith(item); } if (!faction.Hidden && !facDef.isPlayer) { Settlement settlement = (Settlement)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.Settlement); settlement.SetFaction(faction); settlement.Tile = TileFinder.RandomSettlementTileFor(faction); settlement.Name = SettlementNameGenerator.GenerateSettlementName(settlement); Find.WorldObjects.Add(settlement); } faction.TryGenerateNewLeader(); return(faction); }
protected override void DoListingItems() { base.DoListingItems(); #if DEBUG if (!WorldRendererUtility.WorldRenderedNow) { return; } DoGap(); DoLabel("Tools - MFI"); DebugToolWorld_NewTmp("Spawn pirate base", () => { var tile = GenWorld.MouseTile(); if (tile < 0 || Find.World.Impassable(tile)) { Messages.Message("Impassable", MessageTypeDefOf.RejectInput, false); } else { var faction = (from x in Find.FactionManager.AllFactions where !x.def.hidden && !x.defeated && !x.IsPlayer && x.HostileTo(Faction.OfPlayer) && x.def.permanentEnemy select x).First(); var factionBase = (Settlement)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.Settlement); factionBase.SetFaction(faction); factionBase.Tile = tile; factionBase.Name = SettlementNameGenerator.GenerateSettlementName(factionBase); Find.WorldObjects.Add(factionBase); } }, false ); DebugToolWorld_NewTmp("Test annual Expo", new AnnualExpoDialogue(null, null, null, Find.FactionManager.RandomAlliedFaction()) .DebugLogChances, false); #endif }
private static void CreateSettlements(Faction faction, int amount, int minDistance, out int spawned) { spawned = 0; // Try twice as many times as needed, but don't try infinitely, this is pretty slow var tiles = Enumerable.Range(0, amount * 2).Select(_ => TileFinder.RandomSettlementTileFor(faction)).Where(t => t != 0).Distinct().ToArray(); var tilesInDistance = tiles.Where(IsFarEnoughFromPlayer).Take(amount).ToArray(); // Validator bool IsFarEnoughFromPlayer(int tileId) { foreach (var playerSettlement in Find.WorldObjects.SettlementBases) { if (playerSettlement.Faction != Faction.OfPlayer) { continue; } int distance = Find.WorldGrid.TraversalDistanceBetween(tileId, playerSettlement.Tile, false, minDistance); var objects = Find.WorldObjects.ObjectsAt(tileId).ToArray(); if (objects.Length > 0) { if (Prefs.DevMode) { Log.Message($"Tile: {tileId} has {objects.Select(o => o.Label).ToCommaList(true)}."); } } if (distance < minDistance) { return(false); } } return(true); } foreach (var tile in tilesInDistance) { // Spawn base var factionBase = (Settlement)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.Settlement); factionBase.SetFaction(faction); factionBase.Tile = tile; factionBase.Name = SettlementNameGenerator.GenerateSettlementName(factionBase); Find.WorldObjects.Add(factionBase); spawned++; } }
public override void CompTick() { if (!active) { return; } if (loop >= 4) { active = false; Settlement factionBase = (Settlement)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.Settlement); factionBase.SetFaction(parent.Faction); factionBase.Tile = parent.Tile; factionBase.Name = SettlementNameGenerator.GenerateSettlementName(factionBase); Find.WorldObjects.Remove(parent); Find.WorldObjects.Add(factionBase); return; } if (target == null) { loop = 4; return; } if (stopTimer <= Find.TickManager.TicksGame) { loop++; if (!NextTarget(out target)) { loop = 4; } stopTimer = timerTarget.RandomInRange * Global.DayInTicks + Find.TickManager.TicksGame; if (Rand.Chance(0.35f)) { Utilities.FactionsWar().GetByFaction(target.Faction).resources -= FE_WorldComp_FactionsWar.SETTLEMENT_RESOURCE_VALUE; Utilities.FactionsWar().GetByFaction(parent.Faction).resources += FE_WorldComp_FactionsWar.SETTLEMENT_RESOURCE_VALUE / 1.5f; Find.WorldObjects.Remove(target); Messages.Message("MessageFriendlyAttackSuccess".Translate(target, set1, set2), MessageTypeDefOf.PositiveEvent); return; } Messages.Message("MessageFriendlyAttackFail".Translate(target, set1, set2), target, MessageTypeDefOf.NeutralEvent); Utilities.FactionsWar().GetByFaction(parent.Faction).resources -= FE_WorldComp_FactionsWar.MINOR_EVENT_RESOURCE_VALUE; } }
public static bool Prefix(FactionDef facDef, ref Faction __result) { if (Controller.Settings.usingFactionControl.Equals(true)) { return(true); } Faction faction = new Faction(); faction.def = facDef; faction.loadID = Find.UniqueIDsManager.GetNextFactionID(); faction.colorFromSpectrum = FactionGenerator.NewRandomColorFromSpectrum(faction); if (!facDef.isPlayer) { if (facDef.fixedName == null) { faction.Name = NameGenerator.GenerateName(facDef.factionNameMaker, from fac in Find.FactionManager.AllFactionsVisible select fac.Name, false, null); } else { faction.Name = facDef.fixedName; } } faction.centralMelanin = Rand.Value; foreach (Faction allFactionsListForReading in Find.FactionManager.AllFactionsListForReading) { faction.TryMakeInitialRelationsWith(allFactionsListForReading); } faction.GenerateNewLeader(); if (!facDef.hidden && !facDef.isPlayer) { Settlement settlement = (Settlement)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.Settlement); settlement.SetFaction(faction); settlement.Tile = TileFinder.RandomSettlementTileFor(faction, false, null); settlement.Name = SettlementNameGenerator.GenerateSettlementName(settlement, null); Find.WorldObjects.Add(settlement); } __result = faction; return(false); }
private static string DestroyOldOutpostAndCreateNewAtSpot(Settlement someRandomPreferablyNearbySettlement) { if (Rand.ChanceSeeded(chance: 0.5f, specialSeed: someRandomPreferablyNearbySettlement.ID)) { Settlement factionBase = (Settlement)WorldObjectMaker.MakeWorldObject(def: WorldObjectDefOf.Settlement); factionBase.SetFaction(newFaction: someRandomPreferablyNearbySettlement.Faction.EnemyInFactionWar()); factionBase.Tile = someRandomPreferablyNearbySettlement.Tile; factionBase.Name = SettlementNameGenerator.GenerateSettlementName(factionBase: factionBase); Find.WorldObjects.Remove(o: someRandomPreferablyNearbySettlement); Find.WorldObjects.Add(o: factionBase); return("MFI_FactionWarBaseTakenOver".Translate(someRandomPreferablyNearbySettlement.Faction, someRandomPreferablyNearbySettlement.Faction.EnemyInFactionWar())); } DestroyedSettlement destroyedSettlement = (DestroyedSettlement)WorldObjectMaker.MakeWorldObject(def: WorldObjectDefOf.DestroyedSettlement); destroyedSettlement.Tile = someRandomPreferablyNearbySettlement.Tile; Faction loserFaction = someRandomPreferablyNearbySettlement.Faction; Find.WorldObjects.Add(o: destroyedSettlement); Find.WorldObjects.Remove(o: someRandomPreferablyNearbySettlement); return("MFI_FactionWarBaseDestroyed".Translate(loserFaction, loserFaction.EnemyInFactionWar())); }
public void DoRebelResult() { float successChance = 0.45f; if (Rand.Chance(successChance)) { Faction.Notify_LeaderDied(); string playerAffect = ""; if (supress) { Faction.TryAffectGoodwillWith(Faction.OfPlayer, -15); playerAffect = "Quest_SuppressionRebelplayerAffect".Translate(); } else { playerAffect = "Quest_SuppressionRebelNonplayerAffect".Translate(); } Find.LetterStack.ReceiveLetter("Quest_SuppressionRebellionRebelWinTitle".Translate(), "Quest_SuppressionRebellionRebelWinDesc".Translate(RebelSettlement.Name, playerAffect), LetterDefOf.NeutralEvent); } else { Faction faction = DoNewFaction(); Find.LetterStack.ReceiveLetter("Quest_SuppressionRebellionNewFactionTitle".Translate(), "Quest_SuppressionRebellionNewFactionDesc".Translate(RebelSettlement.Name, faction.Name), LetterDefOf.PositiveEvent); int tile = TileFinder.RandomSettlementTileFor(faction); Settlement settlement = (Settlement)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.Settlement); settlement.SetFaction(faction); settlement.Name = SettlementNameGenerator.GenerateSettlementName(settlement); settlement.Tile = tile; Find.WorldObjects.Add(settlement); } Site.EndQuest(null, EndCondition.None); }
public static void GenerateFactionsIntoWorld() { int i = 0; foreach (FactionDef current in DefDatabase <FactionDef> .AllDefs) { for (int j = 0; j < current.requiredCountAtGameStart; j++) { Faction faction = FactionGenerator.NewGeneratedFaction(current); Find.FactionManager.Add(faction); if (!current.hidden) { i++; } } } while (i < 5) { FactionDef facDef = (from fa in DefDatabase <FactionDef> .AllDefs where fa.canMakeRandomly && Find.FactionManager.AllFactions.Count((Faction f) => f.def == fa) < fa.maxCountAtGameStart select fa).RandomElement <FactionDef>(); Faction faction2 = FactionGenerator.NewGeneratedFaction(facDef); Find.World.factionManager.Add(faction2); i++; } int num = GenMath.RoundRandom((float)Find.WorldGrid.TilesCount / 100000f * FactionGenerator.SettlementsPer100kTiles.RandomInRange); num -= Find.WorldObjects.Settlements.Count; for (int k = 0; k < num; k++) { Faction faction3 = (from x in Find.World.factionManager.AllFactionsListForReading where !x.def.isPlayer && !x.def.hidden select x).RandomElementByWeight((Faction x) => x.def.settlementGenerationWeight); Settlement settlement = (Settlement)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.Settlement); settlement.SetFaction(faction3); settlement.Tile = TileFinder.RandomSettlementTileFor(faction3, false, null); settlement.Name = SettlementNameGenerator.GenerateSettlementName(settlement, null); Find.WorldObjects.Add(settlement); } }
protected override bool TryExecuteWorker(IncidentParms parms) { int tile; if (!TileFinder.TryFindNewSiteTile(out tile, minDist, maxDist, false, true, -1)) { return(false); } Faction faction = (from x in Find.World.factionManager.AllFactionsListForReading where !x.def.isPlayer && !x.def.hidden select x).RandomElementByWeight((Faction x) => x.def.settlementGenerationWeight); Settlement settlement = (Settlement)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.Settlement); settlement.SetFaction(faction); settlement.Tile = tile; settlement.Name = SettlementNameGenerator.GenerateSettlementName(settlement, null); Find.WorldObjects.Add(settlement); Find.LetterStack.ReceiveLetter("LetterLabelNewSettlementLGE".Translate(), "LetterNewSettlementLGE".Translate(faction.Name), LetterDefOf.NeutralEvent, settlement, null); return(true); }
void GenerateCities(int per100kTiles, bool abandoned) { int cityCount = GenMath.RoundRandom(Find.WorldGrid.TilesCount / 100000F * per100kTiles); for (int i = 0; i < cityCount; i++) { var city = (City)WorldObjectMaker.MakeWorldObject(DefDatabase <WorldObjectDef> .GetNamed(abandoned ? "City_Abandoned" : "City_Faction")); city.SetFaction(GenCity.RandomCityFaction()); if (!abandoned) { city.inhabitantFaction = city.Faction; } city.Tile = TileFinder.RandomSettlementTileFor(city.Faction); city.Name = SettlementNameGenerator.GenerateSettlementName(city); if (!TileFinder.IsValidTileForNewSettlement(city.Tile)) { // (Faction Control) ensure valid tile for existing saves city.Tile = TileFinder.RandomStartingTile(); } Find.WorldObjects.Add(city); } }
protected override void DoListingItems() { base.DoListingItems(); if (WorldRendererUtility.WorldRenderedNow) { DoGap(); DoLabel("Tools - MFI"); base.DebugToolWorld("Spawn pirate base", delegate { int tile = GenWorld.MouseTile(false); if (tile < 0 || Find.World.Impassable(tile)) { Messages.Message("Impassable", MessageTypeDefOf.RejectInput, false); } else { Faction faction = (from x in Find.FactionManager.AllFactions where !x.def.hidden && !x.defeated && !x.IsPlayer && x.HostileTo(other: Faction.OfPlayer) && x.def.permanentEnemy select x).First(); Settlement factionBase = (Settlement)WorldObjectMaker.MakeWorldObject(def: WorldObjectDefOf.Settlement); factionBase.SetFaction(newFaction: faction); factionBase.Tile = tile; factionBase.Name = SettlementNameGenerator.GenerateSettlementName(factionBase: factionBase); Find.WorldObjects.Add(o: factionBase); } } ); } }
public override void WorldComponentUpdate() { base.WorldComponentUpdate(); if (Find.TickManager.TicksGame % 100 == 0) { //get settlements to upgrade. These shouldn't include temp generated or event maps -- preferably only the outposts this spawned by this mod //ideally I'd add some specific Component to each outpost (as a unique identifier and maybe even as the thing that makes em upgrade), but for the moment that's not needed. IEnumerable <Site> sites = from site in Find.WorldObjects.Sites where site.Faction.HostileTo(other: Faction.OfPlayer) && site.Faction.def.permanentEnemy && !site.Faction.def.hidden && !site.Faction.defeated && site.parts.Any(predicate: (SitePart x) => x.Def == SitePartDefOf.Outpost) && !site.GetComponent <TimeoutComp>().Active select site; Site toUpgrade = null; foreach (Site current in sites) { if (current.creationGameTicks + MoreFactionInteraction_Settings.ticksToUpgrade <= Find.TickManager.TicksGame) { toUpgrade = current; } } if (toUpgrade != null) { Settlement factionBase = (Settlement)WorldObjectMaker.MakeWorldObject(def: WorldObjectDefOf.Settlement); factionBase.SetFaction(newFaction: toUpgrade.Faction); factionBase.Tile = toUpgrade.Tile; factionBase.Name = SettlementNameGenerator.GenerateSettlementName(factionBase: factionBase); Find.WorldObjects.Remove(o: toUpgrade); Find.WorldObjects.Add(o: factionBase); Find.LetterStack.ReceiveLetter(label: "MFI_LetterLabelBanditOutpostUpgraded".Translate(), text: "MFI_LetterBanditOutpostUpgraded".Translate(args: new object[] { factionBase.Faction.Name, }), textLetterDef: LetterDefOf.NeutralEvent, lookTargets: factionBase, relatedFaction: toUpgrade.Faction); } } }
/* * this method manages faction expansion. * Each faction has a timer, when it ends a new settlement is built */ private void NaturalSettlementExpansion() { if (!EndGame_Settings.FactionExpansion) { return; } foreach (LE_FactionInfo info in factionInfo.ToList()) { if (info.faction.defeated) { factionInfo.Remove(info); return; } if (info.expansionCoolddown > Find.TickManager.TicksGame) { return; } info.expansionCoolddown = Find.TickManager.TicksGame + (int)daysToExpansion.Evaluate(Find.WorldObjects.Settlements.Count(s => s.Faction == info.faction)) + ExpansionCooldown.RandomInRange; if (!Find.WorldObjects.Settlements.Where(x => x.Faction == info.faction && Find.WorldGrid.ApproxDistanceInTiles(Find.AnyPlayerHomeMap.Tile, x.Tile) > 45).TryRandomElement(out Settlement origin)) { continue; } Settlement expand = (Settlement)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.Settlement); expand.SetFaction(info.faction); expand.Tile = TileFinder.RandomSettlementTileFor(expand.Faction, false, x => Find.WorldGrid.ApproxDistanceInTiles(Find.AnyPlayerHomeMap.Tile, x) < Find.WorldGrid.ApproxDistanceInTiles(Find.AnyPlayerHomeMap.Tile, origin.Tile) - 20 && Find.WorldGrid.ApproxDistanceInTiles(x, origin.Tile) < 40 && TileFinder.IsValidTileForNewSettlement(x, null)); expand.Name = SettlementNameGenerator.GenerateSettlementName(expand, info.faction.def.settlementNameMaker); Find.WorldObjects.Add(expand); GetByFaction(info.faction).resources -= LARGE_EVENT_Cache_RESOURCE_VALUE; Messages.Message("MessageExpanded".Translate(origin, info.faction, expand), expand, MessageTypeDefOf.NeutralEvent, false); GetByFaction(info.faction).history += "HistoryDate".Translate(5500 + (Find.TickManager.TicksGame / Global.YearInTicks)) + "MessageExpanded".Translate(origin, info.faction, expand) + "\n\n"; } }
/* * Destructive prefix */ public static bool Prefix() { int num = 0; // track actual faction count int actualFactionCount = 0; // track faction centers Controller.factionCenters.Clear(); // Use CustomFaction instead, use Main.CustomFactions instead foreach (CustomFaction cf in Main.CustomFactions) { cf.FactionDef.requiredCountAtGameStart = (int)cf.RequiredCount; if (cf.RequiredCount == 0) { cf.FactionDef.maxCountAtGameStart = 0; } else { cf.FactionDef.maxCountAtGameStart = (int)cf.MaxCountAtStart; } } // Refactor into method // SetFactionCounts() // { foreach (FactionDef def in DefDatabase <FactionDef> .AllDefs) { if (def.isPlayer) { continue; } switch (def.defName) { case "OutlanderCivil": SetFactionCount(def, (int)Controller_FactionOptions.Settings.outlanderCivilMin); break; case "OutlanderRough": SetFactionCount(def, (int)Controller_FactionOptions.Settings.outlanderHostileMin); break; case "TribeCivil": SetFactionCount(def, (int)Controller_FactionOptions.Settings.tribalCivilMin); break; case "TribeRough": SetFactionCount(def, (int)Controller_FactionOptions.Settings.tribalHostileMin); break; case "TribeSavage": SetFactionCount(def, (int)Controller_FactionOptions.Settings.tribalSavageMin); break; case "Empire": SetFactionCount(def, (int)Controller_FactionOptions.Settings.empireMin); break; case "Pirate": SetFactionCount(def, (int)Controller_FactionOptions.Settings.pirateMin); break; } // } actualFactionCount += def.requiredCountAtGameStart; for (int i = 0; i < def.requiredCountAtGameStart; i++) { Faction faction = FactionGenerator.NewGeneratedFaction(def); Find.FactionManager.Add(faction); if (!def.hidden) { num++; } } } if (Controller_FactionOptions.Settings.MinFactionCount == 0 && Main.CustomFactions.Count == 0) { /*Log.Error("Faction Control: No factions were selected. To prevent the game from going into an infinite loop a tribe was added."); * FactionDef def = DefDatabase<FactionDef>.GetNamed("TribeCivil"); * def.requiredCountAtGameStart = 1; * Controller.maxFactionSprawl = 1; * Faction faction = FactionGenerator.NewGeneratedFaction(def); * Find.FactionManager.Add(faction); * actualFactionCount = 1;*/ return(false); } double sqrtTiles = Math.Sqrt(Find.WorldGrid.TilesCount); double sqrtFactionCount = Math.Sqrt(actualFactionCount); Controller.minFactionSeparation = sqrtTiles / (sqrtFactionCount * 2); Controller.maxFactionSprawl = sqrtTiles / (sqrtFactionCount * Controller.Settings.factionGrouping); Controller.pirateSprawl = Controller.maxFactionSprawl; if (Controller.Settings.spreadPirates) { Controller.pirateSprawl = sqrtTiles / (sqrtFactionCount * 0.5f); } while (num < (int)Controller_FactionOptions.Settings.factionCount) { FactionDef facDef = (from fa in DefDatabase <FactionDef> .AllDefs where fa.canMakeRandomly && Find.FactionManager.AllFactions.Count((Faction f) => f.def == fa) < fa.maxCountAtGameStart select fa).RandomElement <FactionDef>(); Faction faction2 = FactionGenerator.NewGeneratedFaction(facDef); Find.World.factionManager.Add(faction2); num++; } float tilesCount = (float)Find.WorldGrid.TilesCount / 100000f; float minBP100K = 75f * Controller.Settings.factionDensity; float maxBP100K = 85f * Controller.Settings.factionDensity; FloatRange factionBasesPer100kTiles = new FloatRange(minBP100K, maxBP100K); int maxCount = 0; int count = GenMath.RoundRandom(tilesCount * factionBasesPer100kTiles.RandomInRange); count -= Find.WorldObjects.SettlementBases.Count; for (int j = 0; j < count && maxCount < 2000; j++) { Faction faction2 = ( from x in Find.World.factionManager.AllFactionsListForReading where !x.def.isPlayer && !x.def.hidden select x).RandomElementByWeight <Faction>((Faction x) => x.def.settlementGenerationWeight); Settlement factionBase = (Settlement)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.Settlement); factionBase.SetFaction(faction2); factionBase.Tile = TileFinder.RandomSettlementTileFor(faction2, false, null); if (factionBase.Tile < 1) { j--; } else { factionBase.Name = SettlementNameGenerator.GenerateSettlementName(factionBase); Find.WorldObjects.Add(factionBase); } ++maxCount; } return(false); }
private bool doConquest() { Settlement AttackerBase = RandomSettlement(); if (AttackerBase == null) { return(false); } Faction AttackerFaction = AttackerBase.Faction; if (AttackerFaction == null) { return(false); } List <Settlement> settlements = Find.WorldObjects.Settlements.ToList <Settlement>(); List <Settlement> prox1 = new List <Settlement>(); List <Settlement> prox2 = new List <Settlement>(); List <Settlement> prox3 = new List <Settlement>(); List <Settlement> prox4 = new List <Settlement>(); List <Settlement> prox5 = new List <Settlement>(); List <Settlement> prox6 = new List <Settlement>(); List <Settlement> prox7 = new List <Settlement>(); double attackerBaseCount = 0; double totalBaseCount = 0; List <Settlement> attackerSettlementList = new List <Settlement>(); for (int i = 0; i < settlements.Count; i++) { Settlement DefenderBase = settlements[i]; if (DefenderBase.Faction == AttackerBase.Faction) { attackerBaseCount++; attackerSettlementList.Add(DefenderBase); } if (DefenderBase.Faction != null && !DefenderBase.Faction.IsPlayer && DefenderBase.Faction.def.settlementGenerationWeight > 0f && !DefenderBase.def.defName.Equals("City_Faction") && !DefenderBase.def.defName.Equals("City_Abandoned") && !DefenderBase.def.defName.Equals("City_Ghost") && !DefenderBase.def.defName.Equals("City_Citadel")) { totalBaseCount++; if (AttackerBase.Faction.HostileTo(DefenderBase.Faction)) { int attackDistance = Find.WorldGrid.TraversalDistanceBetween(AttackerBase.Tile, DefenderBase.Tile, true); if (attackDistance < 30) { prox1.Add(DefenderBase); } else if (attackDistance < 60) { prox2.Add(DefenderBase); } else if (attackDistance < 90) { prox3.Add(DefenderBase); } else if (attackDistance < 120) { prox4.Add(DefenderBase); } else if (attackDistance < 150) { prox5.Add(DefenderBase); } else if (attackDistance < 180) { prox6.Add(DefenderBase); } else if (attackDistance < 210) { prox7.Add(DefenderBase); } } } } // Rebellion code if (attackerBaseCount >= 10 && attackerBaseCount >= (totalBaseCount * 0.1)) { int num = Rand.Range(1, 100); if (num <= (int)(attackerBaseCount / totalBaseCount * 20) || attackerBaseCount >= (totalBaseCount * 0.8)) { List <Faction> allFactionList = (from x in Find.FactionManager.AllFactionsVisible where x.def.settlementGenerationWeight > 0f && !x.def.hidden && !x.IsPlayer && !x.defeated && x != AttackerFaction && x.leader != null && !x.leader.IsPrisoner && !x.leader.Spawned select x).ToList <Faction>(); for (int i = 0; i < allFactionList.Count; i++) { if (!IncidentWorker_NPCConquest.HasAnyOtherBase(allFactionList[i])) { for (int j = 0; j < attackerSettlementList.Count; j++) { int num2 = Rand.Range(1, 100); bool resistancechance = num2 < 41; if (resistancechance) { Settlement rebelSettlement = (Settlement)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.Settlement); rebelSettlement.SetFaction(allFactionList[i]); rebelSettlement.Tile = attackerSettlementList[j].Tile; rebelSettlement.Name = SettlementNameGenerator.GenerateSettlementName(rebelSettlement, null); Find.WorldObjects.Remove(attackerSettlementList[j]); Find.WorldObjects.Add(rebelSettlement); } } FactionRelation factionRelation = allFactionList[i].RelationWith(AttackerBase.Faction, false); factionRelation.kind = FactionRelationKind.Hostile; FactionRelation factionRelation2 = AttackerBase.Faction.RelationWith(allFactionList[i], false); factionRelation2.kind = FactionRelationKind.Hostile; Find.LetterStack.ReceiveLetter("LabelRebellion".Translate(), "DescRebellion".Translate(allFactionList[i], AttackerBase.Faction), LetterDefOf.NeutralEvent, null); return(true); } } if (IncidentWorker_NPCConquest.allowCloneFaction && AttackerFaction != Faction.OfEmpire) { Faction clonefaction = FactionGenerator.NewGeneratedFaction(new FactionGeneratorParms(AttackerFaction.def, default(IdeoGenerationParms), null)); clonefaction.color = Random.ColorHSV(0f, 1f, 1f, 1f, 0.5f, 1f); Find.FactionManager.Add(clonefaction); for (int i = 0; i < attackerSettlementList.Count; i++) { int num3 = Rand.Range(1, 100); bool resistancechance = num3 < 41; if (resistancechance) { Settlement rebelSettlement = (Settlement)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.Settlement); rebelSettlement.SetFaction(clonefaction); rebelSettlement.Tile = attackerSettlementList[i].Tile; rebelSettlement.Name = SettlementNameGenerator.GenerateSettlementName(rebelSettlement, null); Find.WorldObjects.Remove(attackerSettlementList[i]); Find.WorldObjects.Add(rebelSettlement); } } FactionRelation factionRelation = clonefaction.RelationWith(AttackerBase.Faction, false); factionRelation.kind = FactionRelationKind.Hostile; FactionRelation factionRelation2 = AttackerBase.Faction.RelationWith(clonefaction, false); factionRelation2.kind = FactionRelationKind.Hostile; Ideo newIdeo = IdeoGenerator.GenerateIdeo(FactionIdeosTracker.IdeoGenerationParmsForFaction_BackCompatibility(clonefaction.def)); clonefaction.ideos.SetPrimary(newIdeo); Find.IdeoManager.Add(newIdeo); clonefaction.leader.ideo.SetIdeo(newIdeo); Find.LetterStack.ReceiveLetter("LabelRebellion".Translate(), "DescRebellion".Translate(clonefaction, AttackerBase.Faction), LetterDefOf.NeutralEvent, null); return(true); } } } // Conquest code Settlement FinalDefenderBase; if (prox1.Count != 0) { FinalDefenderBase = prox1.RandomElement <Settlement>(); } else if (prox2.Count != 0) { FinalDefenderBase = prox2.RandomElement <Settlement>(); } else if (prox3.Count != 0) { FinalDefenderBase = prox3.RandomElement <Settlement>(); } else if (prox4.Count != 0) { FinalDefenderBase = prox4.RandomElement <Settlement>(); } else if (prox5.Count != 0) { FinalDefenderBase = prox5.RandomElement <Settlement>(); } else if (prox6.Count != 0) { FinalDefenderBase = prox6.RandomElement <Settlement>(); } else if (prox7.Count != 0) { FinalDefenderBase = prox7.RandomElement <Settlement>(); } else { return(false); } if (FinalDefenderBase.HasMap) { Log.Message("attack target has generated map. Event dropped."); return(false); } // Determine whether to raze or take control, distance-based int razeroll = Rand.Range(1, 100); if (razeroll <= IncidentWorker_NPCConquest.razeChance) { if (IncidentWorker_NPCConquest.allowRazeClear) { List <DestroyedSettlement> clearRuinTarget = Find.WorldObjects.DestroyedSettlements; for (int i = 0; i < clearRuinTarget.Count; i++) { Find.WorldObjects.Remove(clearRuinTarget[i]); } } DestroyedSettlement destroyedSettlement = (DestroyedSettlement)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.DestroyedSettlement); destroyedSettlement.Tile = FinalDefenderBase.Tile; Find.WorldObjects.Remove(FinalDefenderBase); Find.WorldObjects.Add(destroyedSettlement); } else { Settlement settlementConquest = (Settlement)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.Settlement); settlementConquest.SetFaction(AttackerBase.Faction); settlementConquest.Tile = FinalDefenderBase.Tile; settlementConquest.Name = SettlementNameGenerator.GenerateSettlementName(settlementConquest, null); Find.WorldObjects.Remove(FinalDefenderBase); Find.WorldObjects.Add(settlementConquest); } // Defeat check for distance conquest if (IncidentWorker_NPCConquest.allowCloneFaction && !HasAnyOtherBase(FinalDefenderBase)) { List <Faction> clonefactioncheck = (from x in Find.FactionManager.AllFactionsVisible where !x.def.hidden && !x.IsPlayer && !x.defeated && x != FinalDefenderBase.Faction && x.def == FinalDefenderBase.Faction.def select x).ToList <Faction>(); if (clonefactioncheck.Count > 0) { FinalDefenderBase.Faction.defeated = true; Find.LetterStack.ReceiveLetter("LetterLabelFactionBaseDefeated".Translate(), "LetterFactionBaseDefeated_FactionDestroyed".Translate(FinalDefenderBase.Faction.Name), LetterDefOf.NeutralEvent, null); } } int defeatroll = Rand.Range(1, 100); if (defeatroll <= IncidentWorker_NPCConquest.defeatChance && !HasAnyOtherBase(FinalDefenderBase)) { FinalDefenderBase.Faction.defeated = true; Find.LetterStack.ReceiveLetter("LetterLabelFactionBaseDefeated".Translate(), "LetterFactionBaseDefeated_FactionDestroyed".Translate(FinalDefenderBase.Faction.Name), LetterDefOf.NeutralEvent, null); } // Alliance code if (IncidentWorker_NPCConquest.allowAlliance && Find.World.GetComponent <DiplomacyWorldComponent>().allianceCooldown <= 0) { List <Faction> alliance = (from x in Find.FactionManager.AllFactionsVisible where x.def.settlementGenerationWeight > 0f && !x.def.hidden && !x.IsPlayer && !x.defeated && x != AttackerFaction && x.leader != null && !x.leader.IsPrisoner && !x.leader.Spawned select x).ToList <Faction>(); List <Faction> finalAlliance = new List <Faction>(); if (alliance.Count >= 2 && attackerBaseCount >= (totalBaseCount * 0.4) && attackerBaseCount <= (totalBaseCount * 0.6) && attackerBaseCount > 9) { for (int i = 0; i < alliance.Count; i++) { int num = Rand.Range(1, 100); bool havemysword = num < 81; if (havemysword) { FactionRelation factionRelation = AttackerFaction.RelationWith(alliance[i], false); factionRelation.kind = FactionRelationKind.Hostile; FactionRelation factionRelation2 = alliance[i].RelationWith(AttackerFaction, false); factionRelation2.kind = FactionRelationKind.Hostile; finalAlliance.Add(alliance[i]); } } StringBuilder allianceList = new StringBuilder(); for (int x = 0; x < finalAlliance.Count; x++) { for (int y = 0; y < finalAlliance.Count; y++) { if (finalAlliance[y] != finalAlliance[x]) { FactionRelation factionRelation3 = finalAlliance[y].RelationWith(finalAlliance[x], false); factionRelation3.kind = FactionRelationKind.Neutral; FactionRelation factionRelation4 = finalAlliance[x].RelationWith(finalAlliance[y], false); factionRelation4.kind = FactionRelationKind.Neutral; } } allianceList.Append(finalAlliance[x].ToString()).Append(", "); } string allianceListString = allianceList.ToString(); allianceListString = allianceListString.Trim().TrimEnd(','); Find.LetterStack.ReceiveLetter("LabelAlliance".Translate(), "DescAlliance".Translate(allianceListString, AttackerBase.Faction), LetterDefOf.NeutralEvent, null); Find.World.GetComponent <DiplomacyWorldComponent>().allianceCooldown = 11; } } if (Find.World.GetComponent <DiplomacyWorldComponent>().allianceCooldown > 0) { Find.World.GetComponent <DiplomacyWorldComponent>().allianceCooldown--; } return(true); }
protected override bool TryExecuteWorker(IncidentParms parms) { if (!enableExpansion) { return(false); } int tile = TileFinder.RandomStartingTile(); if (!TileFinder.IsValidTileForNewSettlement(tile)) { return(false); } List <Settlement> settlements = Find.WorldObjects.Settlements.ToList <Settlement>(); if (settlements.Count > maxExpansionLimit) { Log.Message("current settlememt count of " + settlements.Count.ToString() + " greater than max expansion limit of " + maxExpansionLimit.ToString()); return(false); } List <Settlement> candidateSettlements = new List <Settlement>(); for (int i = 0; i < settlements.Count; i++) { Settlement SettlerCandidateBase = settlements[i]; if (SettlerCandidateBase.Faction.IsPlayer || SettlerCandidateBase.Faction.def.settlementGenerationWeight == 0f) { } else { if (Find.WorldGrid.TraversalDistanceBetween(tile, SettlerCandidateBase.Tile, true) <= expansionRadius) { candidateSettlements.Add(SettlerCandidateBase); } } } Settlement SettlerBase; if (candidateSettlements.Count != 0) { SettlerBase = candidateSettlements.RandomElement <Settlement>(); } else { // fail due to no valid candidate with supply line return(false); } Settlement settlement = (Settlement)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.Settlement); settlement.SetFaction(SettlerBase.Faction); bool flag3 = settlement.Faction == null; if (flag3) { return(false); } else { settlement.Tile = tile; settlement.Name = SettlementNameGenerator.GenerateSettlementName(settlement, null); Find.WorldObjects.Add(settlement); Find.LetterStack.ReceiveLetter("LabelExpansion".Translate(), "DescExpansion".Translate(SettlerBase.Faction.Name, SettlerBase.Name, settlement.Name), LetterDefOf.NeutralEvent, settlement, null, null); ExpandableWorldObjectsUtility.ExpandableWorldObjectsUpdate(); } return(true); }