private void GenerateRoadEndpoints() { List <int> list = (from wo in Find.WorldObjects.AllWorldObjects where Rand.Value > 0.05f select wo.Tile).ToList(); int num = GenMath.RoundRandom((float)Find.WorldGrid.TilesCount / 100000f * ExtraRoadNodesPer100kTiles.RandomInRange); for (int i = 0; i < num; i++) { list.Add(TileFinder.RandomSettlementTileFor(null)); } List <int> list2 = new List <int>(); for (int j = 0; j < list.Count; j++) { int num2 = Mathf.Max(0, RoadDistanceFromSettlement.RandomInRange); int num3 = list[j]; for (int k = 0; k < num2; k++) { Find.WorldGrid.GetTileNeighbors(num3, list2); num3 = list2.RandomElement(); } if (Find.WorldReachability.CanReach(list[j], num3)) { list[j] = num3; } } list = list.Distinct().ToList(); Find.World.genData.roadNodes = list; }
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); }
public static void Postfix() { if (!WorldGenerator_GenerateFromScribe.IsGeneratingWorld) { return; } // tell tile finder to use our data - this is done before we can re-obtain settlement tiles TileFinder_RandomSettlementTileFor.FirstSettlementLocations = WorldGenerator_GenerateFromScribe.FirstSettlementLocation; TileFinder_IsValidTileForNewSettlement.FirstSettlementLocations = WorldGenerator_GenerateFromScribe.FirstSettlementLocation; TileFinder_IsValidTileForNewSettlement.FDs = WorldGenerator_GenerateFromScribe.FDs; // set 'first' settlements foreach (var s in Find.WorldObjects.Settlements) { if (!WorldGenerator_GenerateFromScribe.AddedSettlements.Contains(s) && s.Faction != null && s.Faction.Name != null && !WorldGenerator_GenerateFromScribe.FirstSettlementLocation.ContainsKey(s.Faction.Name)) { WorldGenerator_GenerateFromScribe.FirstSettlementLocation[s.Faction.Name] = s.Tile; } } // now randomize settlement positions based on mod logic foreach (var s in WorldGenerator_GenerateFromScribe.AddedSettlements) { s.Tile = s.Faction != null?TileFinder.RandomSettlementTileFor(s.Faction) : TileFinder.RandomStartingTile(); } // now we can clear stuff we won't use until a save is loaded the next time WorldGenerator_GenerateFromScribe.AddedSettlements.Clear(); WorldGenerator_GenerateFromScribe.IsGeneratingWorld = false; }
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 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); }
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); } }
private void GenerateAncientSites() { int num = GenMath.RoundRandom((float)Find.WorldGrid.TilesCount / 100000f * ancientSitesPer100kTiles.RandomInRange); for (int i = 0; i < num; i++) { Find.World.genData.ancientSites.Add(TileFinder.RandomSettlementTileFor(null)); } }
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); }
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 static void BeginArenaFight(List <PawnKindDef> lhs, List <PawnKindDef> rhs, Action <ArenaResult> callback) { MapParent mapParent = (MapParent)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.Debug_Arena); mapParent.Tile = TileFinder.RandomSettlementTileFor(Faction.OfPlayer, mustBeAutoChoosable: true, (int tile) => lhs.Concat(rhs).Any((PawnKindDef pawnkind) => Find.World.tileTemperatures.SeasonAndOutdoorTemperatureAcceptableFor(tile, pawnkind.race))); mapParent.SetFaction(Faction.OfPlayer); Find.WorldObjects.Add(mapParent); Map orGenerateMap = GetOrGenerateMapUtility.GetOrGenerateMap(mapParent.Tile, new IntVec3(50, 1, 50), null); MultipleCaravansCellFinder.FindStartingCellsFor2Groups(orGenerateMap, out IntVec3 first, out IntVec3 second); List <Pawn> lhs2 = SpawnPawnSet(orGenerateMap, lhs, first, Faction.OfAncients); List <Pawn> rhs2 = SpawnPawnSet(orGenerateMap, rhs, second, Faction.OfAncientsHostile); DebugArena component = mapParent.GetComponent <DebugArena>(); component.lhs = lhs2; component.rhs = rhs2; component.callback = callback; }
void GenerateCity(WorldObjectDef def, bool abandoned, System.Predicate <Faction> factionFilter = null) { var city = (City)WorldObjectMaker.MakeWorldObject(def); city.SetFaction(GenCity.RandomCityFaction(factionFilter)); if (!abandoned) { city.inhabitantFaction = city.Faction; } city.Tile = TileFinder.RandomSettlementTileFor(city.Faction); city.Name = city.ChooseName(); if (!TileFinder.IsValidTileForNewSettlement(city.Tile)) { // (Faction Control) ensure valid tile for existing saves city.Tile = TileFinder.RandomStartingTile(); } Find.WorldObjects.Add(city); }
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); }
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); } }
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); } }
private static void NightvisionArenaFight ( SkillDef skill, AorB[] sides, GlowTeam lhsTeam, int lhsCount, GlowTeam rhsTeam, int rhsCount, Action <ArenaUtility.ArenaResult> callback ) { var mapParent = (MapParent)WorldObjectMaker.MakeWorldObject(def: WorldObjectDefOf.Debug_Arena); mapParent.Tile = TileFinder.RandomSettlementTileFor( faction: Faction.OfPlayer, mustBeAutoChoosable: true, extraValidator: tile => Find.World.tileTemperatures.SeasonAndOutdoorTemperatureAcceptableFor( tile: tile, animalRace: ThingDef.Named(defName: "Human") ) ); mapParent.SetFaction(newFaction: Faction.OfPlayer); Find.WorldObjects.Add(o: mapParent); Map orGenerateMap = GetOrGenerateMapUtility.GetOrGenerateMap( tile: mapParent.Tile, size: new IntVec3(newX: 50, newY: 1, newZ: 50), suggestedMapParentDef: null ); IntVec3 spot; IntVec3 spot2; MultipleCaravansCellFinder.FindStartingCellsFor2Groups(map: orGenerateMap, first: out spot, second: out spot2); List <Pawn> lhs2 = NVPawnSetSpawner(map: orGenerateMap, skill: skill, team: lhsTeam, count: lhsCount, spot: spot, side: sides[0]); List <Pawn> rhs2 = NVPawnSetSpawner(map: orGenerateMap, skill: skill, team: rhsTeam, count: rhsCount, spot: spot2, side: sides[1]); var component = mapParent.GetComponent <DebugArena>(); component.lhs = lhs2; component.rhs = rhs2; component.callback = callback; }
/* * 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"; } }
public override void GenerateFresh(string seed) { var faction = FactionUtility.DefaultFactionFrom(DefDatabase <FactionDef> .GetNamed("Capital")); Initialize(); // Setup capital center var capitalCenter = WorldObjectMaker.MakeWorldObject(_centerDef); capitalCenter.Tile = TileFinder.RandomSettlementTileFor(null); _capitalWorldObjs.Add(capitalCenter); MapSurroundings(capitalCenter.Tile); GenerateDowntown(); GenerateCapitalCore(); GenerateCapitalOuterRim(); // Place into the world foreach (var worldObj in _capitalWorldObjs) { worldObj.SetFaction(faction); Find.World.worldObjects.Add(worldObj); } }
public static bool Prefix() { if (Controller.Settings.tribalPlanet.Equals(false)) { return(true); } var num = 0; foreach (var allDef in DefDatabase <FactionDef> .AllDefs) { if (allDef.defName == "OutlanderCivil" || allDef.defName == "OutlanderRough" || allDef.defName == "Pirate" || allDef.defName == "Empire") { } else { for (var i = 0; i < allDef.requiredCountAtGameStart; i++) { var faction = FactionGenerator.NewGeneratedFaction(new FactionGeneratorParms(allDef)); Find.FactionManager.Add(faction); if (!allDef.hidden) { num++; } } } } while (num < 5) { var factionDef = ( from fa in DefDatabase <FactionDef> .AllDefs where fa.canMakeRandomly && Find.FactionManager.AllFactions.Count(f => f.def == fa) < fa.maxCountAtGameStart select fa).RandomElement(); if (factionDef.defName == "OutlanderCivil" || factionDef.defName == "OutlanderRough" || factionDef.defName == "Pirate" || factionDef.defName == "Empire") { } else { var faction1 = FactionGenerator.NewGeneratedFaction(new FactionGeneratorParms(factionDef)); Find.World.factionManager.Add(faction1); num++; } } var tilesCount = Find.WorldGrid.TilesCount / 100000f; var settlementsPer100kTiles = new FloatRange(75f, 85f); var count = GenMath.RoundRandom(tilesCount * settlementsPer100kTiles.RandomInRange); count -= Find.WorldObjects.Settlements.Count; for (var j = 0; j < count; j++) { var faction2 = ( from x in Find.World.factionManager.AllFactionsListForReading where !x.def.isPlayer && !x.def.hidden select x).RandomElementByWeight(x => x.def.settlementGenerationWeight); var settlement = (Settlement)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.Settlement); settlement.SetFaction(faction2); settlement.Tile = TileFinder.RandomSettlementTileFor(faction2); settlement.Name = SettlementNameGenerator.GenerateSettlementName(settlement); Find.WorldObjects.Add(settlement); } return(false); }
private bool TryUseResourcesAtPeace(Faction f) { if (f == null) { return(false); } int chance = PeaceEventChance.RandomInRange; // Roads if (!f.def.techLevel.IsNeolithicOrWorse() && chance < 50) { Settlement set1 = new Settlement(), set2 = new Settlement(); foreach (Settlement s in Find.WorldObjects.Settlements.Where(x => x.Faction == f).InRandomOrder()) { if (Find.WorldObjects.Settlements.Where(x => x != s && x.Faction == f && Utilities.Reachable(x, s, 50)).TryRandomElement(out set2)) { set1 = s; break; } } if (set1 == null || set2 == null) { return(false); } List <int> p = new List <int>(); using (WorldPath path = Find.World.pathFinder.FindPath(set1.Tile, set2.Tile, null)) { p = path.NodesReversed; for (int i = 0; i < (p.Count() - 1); i++) { if (Find.WorldGrid[p[i]].potentialRoads == null) { continue; } if (Find.WorldGrid[p[i]].potentialRoads.Any(x => x.road == RoadDefOf.AncientAsphaltHighway) || Find.WorldGrid[p[i]].potentialRoads.Any(x => x.road == RoadDefOf.AncientAsphaltRoad) || Find.WorldGrid[p[i]].potentialRoads.Any(x => x.road == EndGameDefOf.StoneRoad)) { if (Find.WorldGrid[p[i + 1]].potentialRoads != null && (Find.WorldGrid[p[i + 1]].potentialRoads.Any(x => x.road == RoadDefOf.AncientAsphaltHighway) || Find.WorldGrid[p[i + 1]].potentialRoads.Any(x => x.road == RoadDefOf.AncientAsphaltRoad) || Find.WorldGrid[p[i + 1]].potentialRoads.Any(x => x.road == EndGameDefOf.StoneRoad))) { p.Remove(p[i + 1]); } } if (i == (p.Count() - 1)) { return(false); } } if (p.Count() == 0) { return(false); } WorldObject dispute = WorldObjectMaker.MakeWorldObject(EndGameDefOf.Roads_Camp); dispute.GetComponent <WorldComp_DisputeRoads>().StartComp(set1.Tile, set2.Tile, p); dispute.Tile = p.First(); dispute.SetFaction(f); Find.WorldObjects.Add(dispute); Messages.Message("MessageFactionRoads".Translate(set1.Faction, set1, set2), dispute, MessageTypeDefOf.NeutralEvent); GetByFaction(f).resources -= MEDIUM_EVENT_RESOURCE_VALUE; GetByFaction(f).history += "HistoryDate".Translate(5500 + (Find.TickManager.TicksGame / Global.YearInTicks)) + "MessageFactionRoads".Translate(set1.Faction, set1, set2) + "\n\n"; } return(true); } // Goodwill randomizer if (chance < 100) { if (!f.def.CanEverBeNonHostile) { return(false); } if (!Find.FactionManager.AllFactionsListForReading.Where(x => !x.def.isPlayer && x.def.CanEverBeNonHostile).TryRandomElement(out Faction faction)) { return(false); } f.TryAffectGoodwillWith(faction, new IntRange(-10, 10).RandomInRange, false, false); factionInfo.Find(x => x.faction == f).resources -= 200; return(true); } // Settlement Expansion if (chance < 300 && Find.WorldObjects.Settlements.Count(x => x.Faction == f) < 3 && factionInfo.Find(x => x.faction == f).resources > 1000) { if (!Find.WorldObjects.Settlements.Where(x => x.Faction == f).TryRandomElement(out Settlement origin)) { return(false); } Settlement expand = (Settlement)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.Settlement); expand.SetFaction(f); 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, f.def.settlementNameMaker); Find.WorldObjects.Add(expand); Messages.Message("MessageExpanded".Translate(origin, f, expand), expand, MessageTypeDefOf.NeutralEvent, false); GetByFaction(f).history += "HistoryDate".Translate(5500 + (Find.TickManager.TicksGame / Global.YearInTicks)) + "MessageExpanded".Translate(origin, f, expand) + "\n\n"; factionInfo.Find(x => x.faction == f).resources -= LARGE_EVENT_Cache_RESOURCE_VALUE; return(true); } return(false); }
public static bool Prefix() { if (Controller.Settings.tribalPlanet.Equals(false)) { return(true); } else { int num = 0; foreach (FactionDef allDef in DefDatabase <FactionDef> .AllDefs) { if (allDef.defName == "OutlanderCivil" || allDef.defName == "OutlanderRough" || allDef.defName == "Pirate") { } else { for (int i = 0; i < allDef.requiredCountAtGameStart; i++) { Faction faction = FactionGenerator.NewGeneratedFaction(allDef); Find.FactionManager.Add(faction); if (!allDef.hidden) { num++; } } } } while (num < 5) { FactionDef factionDef = ( from fa in DefDatabase <FactionDef> .AllDefs where (!fa.canMakeRandomly ? false : Find.FactionManager.AllFactions.Count <Faction>((Faction f) => f.def == fa) < fa.maxCountAtGameStart) select fa).RandomElement <FactionDef>(); if (factionDef.defName == "OutlanderCivil" || factionDef.defName == "OutlanderRough" || factionDef.defName == "Pirate") { } else { Faction faction1 = FactionGenerator.NewGeneratedFaction(factionDef); Find.World.factionManager.Add(faction1); num++; } } float tilesCount = (float)Find.WorldGrid.TilesCount / 100000f; FloatRange settlementsPer100kTiles = new FloatRange(75f, 85f); int count = GenMath.RoundRandom(tilesCount * settlementsPer100kTiles.RandomInRange); count -= Find.WorldObjects.Settlements.Count; for (int j = 0; j < count; j++) { Faction faction2 = ( from x in Find.World.factionManager.AllFactionsListForReading where (x.def.isPlayer ? false : !x.def.hidden) select x).RandomElementByWeight <Faction>((Faction x) => x.def.settlementGenerationWeight); Settlement settlement = (Settlement)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.Settlement); settlement.SetFaction(faction2); settlement.Tile = TileFinder.RandomSettlementTileFor(faction2, false, null); settlement.Name = SettlementNameGenerator.GenerateSettlementName(settlement, null); Find.WorldObjects.Add(settlement); } return(false); } }
/* * 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); }
protected override bool TryExecuteWorker(IncidentParms parms) { int tile = -1; bool result; Faction faction = Find.FactionManager.RandomEnemyFaction(false, false, true); for (int i = 0; i < 20; i++) { tile = TileFinder.RandomSettlementTileFor(faction, false, null); if (TileFinder.IsValidTileForNewSettlement(tile, null)) { break; } else { tile = -1; } } if (tile != -1) { Site site = (Site)WorldObjectMaker.MakeWorldObject(SiteDefOfReconAndDiscovery.RD_Adventure); site.Tile = tile; site.SetFaction(faction); SitePart starGate = new SitePart(site, SiteDefOfReconAndDiscovery.RD_Stargate, SiteDefOfReconAndDiscovery.RD_Stargate.Worker.GenerateDefaultParams (StorytellerUtility.DefaultSiteThreatPointsNow(), tile, faction)); site.AddPart(starGate); float value = Rand.Value; if ((double)value < 0.25) { SitePart abandonedCastle = new SitePart(site, SiteDefOfReconAndDiscovery.RD_AbandonedCastle, SiteDefOfReconAndDiscovery.RD_AbandonedCastle.Worker.GenerateDefaultParams (StorytellerUtility.DefaultSiteThreatPointsNow(), tile, faction)); abandonedCastle.hidden = true; site.AddPart(abandonedCastle); } else if ((double)value < 0.50) { SitePart abandonedColony = new SitePart(site, SiteDefOfReconAndDiscovery.RD_AbandonedColony, SiteDefOfReconAndDiscovery.RD_AbandonedColony.Worker.GenerateDefaultParams (StorytellerUtility.DefaultSiteThreatPointsNow(), tile, faction)); abandonedColony.hidden = true; site.AddPart(abandonedColony); } else if ((double)value < 0.75) { SitePart preciousLump = new SitePart(site, SitePartDefOf.PreciousLump, SitePartDefOf.PreciousLump.Worker.GenerateDefaultParams (StorytellerUtility.DefaultSiteThreatPointsNow(), tile, faction)); preciousLump.hidden = true; site.AddPart(preciousLump); } else { site = (Site)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.Site); site.Tile = tile; site.SetFaction(faction); SitePart starGate2 = new SitePart(site, SiteDefOfReconAndDiscovery.RD_Stargate, SiteDefOfReconAndDiscovery.RD_Stargate.Worker.GenerateDefaultParams (StorytellerUtility.DefaultSiteThreatPointsNow(), tile, faction)); site.AddPart(starGate2); // TODO: check if this works correctly SitePart outpost = new SitePart(site, SitePartDefOf.Outpost, SitePartDefOf.Outpost.Worker.GenerateDefaultParams (StorytellerUtility.DefaultSiteThreatPointsNow(), tile, faction)); outpost.hidden = true; site.parts.Add(outpost); SitePart turrets = new SitePart(site, SitePartDefOf.Turrets, SitePartDefOf.Turrets.Worker.GenerateDefaultParams (StorytellerUtility.DefaultSiteThreatPointsNow(), tile, faction)); turrets.hidden = true; site.parts.Add(turrets); } if (Rand.Value < 0.2f) { SitePart scatteredManhunters = new SitePart(site, SiteDefOfReconAndDiscovery.RD_ScatteredManhunters, SiteDefOfReconAndDiscovery.RD_ScatteredManhunters.Worker.GenerateDefaultParams (StorytellerUtility.DefaultSiteThreatPointsNow(), tile, faction)); scatteredManhunters.hidden = true; site.parts.Add(scatteredManhunters); } if (Rand.Value < 0.85f) { SitePart scatteredTreasure = new SitePart(site, SiteDefOfReconAndDiscovery.RD_ScatteredTreasure, SiteDefOfReconAndDiscovery.RD_ScatteredTreasure.Worker.GenerateDefaultParams (StorytellerUtility.DefaultSiteThreatPointsNow(), tile, faction)); scatteredTreasure.hidden = true; site.parts.Add(scatteredTreasure); } site.GetComponent <TimeoutComp>().StartTimeout(10 * 60000); base.SendStandardLetter(parms, site); Find.WorldObjects.Add(site); result = true; } else { result = false; } return(result); }