示例#1
0
        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 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);
            }
        }
示例#3
0
        public static void GenerateFactionsIntoWorld()
        {
            int i = 0;

            foreach (FactionDef allDef in DefDatabase <FactionDef> .AllDefs)
            {
                for (int j = 0; j < allDef.requiredCountAtGameStart; j++)
                {
                    Faction faction = FactionGenerator.NewGeneratedFaction(allDef);
                    Find.FactionManager.Add(faction);
                    if (!allDef.hidden)
                    {
                        i++;
                    }
                }
            }
            for (; i < 5; i++)
            {
                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();
                Faction faction2 = FactionGenerator.NewGeneratedFaction(facDef);
                Find.World.factionManager.Add(faction2);
            }
            int num = GenMath.RoundRandom((float)((float)Find.WorldGrid.TilesCount / 100000.0 * 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);
            }
        }
示例#4
0
 public override void PostWorldGenerate()
 {
     Find.GameInitData.playerFaction = FactionGenerator.NewGeneratedFaction(factionDef);
     Find.FactionManager.Add(Find.GameInitData.playerFaction);
     FactionGenerator.EnsureRequiredEnemies(Find.GameInitData.playerFaction);
 }
示例#5
0
 public static Faction NewGeneratedFaction()
 {
     return(FactionGenerator.NewGeneratedFaction(DefDatabase <FactionDef> .GetRandom()));
 }