Пример #1
0
        public void InitPlaces()
        {
            List <RandomPlaceDef> allPlaces = DefDatabase <RandomPlaceDef> .AllDefsListForReading;

            Triggers.Clear();

            for (int i = 0; i < allPlaces.Count; i++)
            {
                RandomPlaceDef randomPlaceDef = allPlaces[i];

                int spawnedCount = 0;
                int minToStart   = randomPlaceDef.MinStartScale == null ? randomPlaceDef.MinAtStart : (int)randomPlaceDef.MinStartScale.Evaluate(Find.World.PlanetCoverage);
                int maxSpawn     = randomPlaceDef.MaxSpawnScale == null ? randomPlaceDef.MaxSpawn : (int)randomPlaceDef.MaxSpawnScale.Evaluate(Find.World.PlanetCoverage);

                for (int i3 = 0; i3 < minToStart; i3++)
                {
                    int tile = TileFinder.RandomStartingTile();

                    if (Triggers.ContainsKey(tile))
                    {
                        continue;
                    }

                    if (randomPlaceDef.Worker == null || randomPlaceDef.Worker.CanPlace(tile))
                    {
                        TryGetFaction(randomPlaceDef.FactionType, out Faction faction);
                        Triggers.Add(tile, MakeTrigger(tile, randomPlaceDef, faction));
                        spawnedCount++;
                    }
                }

                if (spawnedCount >= maxSpawn)
                {
                    continue;
                }

                for (int i4 = 0; i4 < maxSpawn - spawnedCount; i4++)
                {
                    if (Rand.Chance(randomPlaceDef.Commonality))
                    {
                        int tile = TileFinder.RandomStartingTile();

                        if (Triggers.ContainsKey(tile))
                        {
                            continue;
                        }

                        if (randomPlaceDef.Worker == null || randomPlaceDef.Worker.CanPlace(tile))
                        {
                            TryGetFaction(randomPlaceDef.FactionType, out Faction faction);
                            Triggers.Add(tile, MakeTrigger(tile, randomPlaceDef, faction));
                        }
                    }
                }
            }

            if (Prefs.DevMode)
            {
                Log.Message($"TOTAL: {Triggers.Count}");
            }
        }
Пример #2
0
        public WorldTrigger MakeTrigger(int tile, RandomPlaceDef def, Faction faction)
        {
            WorldTrigger trigger = new WorldTrigger(tile, def, faction);

            return(trigger);
        }
Пример #3
0
 public WorldTrigger(int tile, RandomPlaceDef def, Faction faction)
 {
     Tile           = tile;
     RandomPlaceDef = def;
     Faction        = faction;
 }