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 item in Find.FactionManager.AllFactionsListForReading) { faction.TryMakeInitialRelationsWith(item); } if (!facDef.hidden && !facDef.isPlayer) { FactionBase factionBase = (FactionBase)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.FactionBase); factionBase.SetFaction(faction); factionBase.Tile = TileFinder.RandomFactionBaseTileFor(faction, false, null); factionBase.Name = FactionBaseNameGenerator.GenerateFactionBaseName(factionBase); Find.WorldObjects.Add(factionBase); } faction.GenerateNewLeader(); return(faction); }
public override void PreMapGenerate() { FactionBase factionBase = (FactionBase)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.FactionBase); factionBase.SetFaction(Find.GameInitData.playerFaction); factionBase.Tile = Find.GameInitData.startingTile; factionBase.Name = FactionBaseNameGenerator.GenerateFactionBaseName(factionBase); Find.WorldObjects.Add(factionBase); }
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.FactionBasesPer100kTiles.RandomInRange); num -= Find.WorldObjects.FactionBases.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.baseSelectionWeight); FactionBase factionBase = (FactionBase)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.FactionBase); factionBase.SetFaction(faction3); factionBase.Tile = TileFinder.RandomFactionBaseTileFor(faction3, false, null); factionBase.Name = FactionBaseNameGenerator.GenerateFactionBaseName(factionBase); Find.WorldObjects.Add(factionBase); } }