public static void AssignAllRegions(this List <HexRegion> regions, MapSetting setting)
        {
            //Create a map/array of all regions.
            var xMin      = regions.Select(r => r.X).Min();
            var yMin      = regions.Select(r => r.Y).Min();
            var xRange    = regions.Select(r => r.X).Max() - xMin;
            var yRange    = regions.Select(r => r.Y).Max() - yMin;
            var regionMap = new HexRegion[xRange + 2, yRange + 2];

            foreach (var region in regions)
            {
                region.X -= xMin;
                region.Y -= yMin;
                regionMap[region.X, region.Y] = region;
                region.Type = RegionType.Unassigned;
            }

            //For each player, find a region with no neighbouring players.
            while (PushNonAdjacentRegion(regions, regionMap, RegionType.SolarSystem, setting.PlayerCount))
            {
            }

            //Push one dead and one rich zone per 7 regions.
            var richRatio = regions.Count / 7;

            for (var x = 0; x < richRatio; x++)
            {
                regions.PushRegionType(RegionType.Dead);
                regions.PushRegionType(RegionType.Riches);
            }

            //Fill in remaining slots with random choices, based off setting.
            var asteroidChance = (float)setting.AsteroidScore / (setting.AsteroidScore + setting.IonScore + setting.MixedScore);
            var ionChance      = (float)setting.IonScore / (setting.AsteroidScore + setting.IonScore + setting.MixedScore);

            foreach (var region in regions.Where(x => x.Type == RegionType.Unassigned))
            {
                var rand = Random.value;
                if (rand <= asteroidChance)
                {
                    region.Type = RegionType.Asteroids;
                }
                else if (rand >= 1 - ionChance)
                {
                    region.Type = RegionType.Sneaky;
                }
                else
                {
                    region.Type = RegionType.Mixed;
                }
            }
        }
Beispiel #2
0
        public void SpawnTiles(MapSetting setting)
        {
            Map = new GameObject {
                name = "Map"
            };
            GameState.Me.HexMap = new HexMap();
            var zoneCoords = new List <Vector2>();

            if (setting.Spiral)
            {
                zoneCoords.Add(new Vector2(1, 0));
                zoneCoords.Add(new Vector2(2, 0));
                zoneCoords.Add(new Vector2(0, 1));
                zoneCoords.Add(new Vector2(0, 2));
                zoneCoords.Add(new Vector2(1, 1));
                zoneCoords.Add(new Vector2(2, 1));
                zoneCoords.Add(new Vector2(1, 2));


                zoneCoords.Add(new Vector2(3, 1));
                zoneCoords.Add(new Vector2(4, 1));
                zoneCoords.Add(new Vector2(2, 2));
                zoneCoords.Add(new Vector2(2, 3));
                zoneCoords.Add(new Vector2(3, 2));
                zoneCoords.Add(new Vector2(4, 2));
                zoneCoords.Add(new Vector2(3, 3));

                zoneCoords.Add(new Vector2(0, 3));
                zoneCoords.Add(new Vector2(1, 3));
                zoneCoords.Add(new Vector2(-1, 4));
                zoneCoords.Add(new Vector2(-1, 5));
                zoneCoords.Add(new Vector2(0, 4));
                zoneCoords.Add(new Vector2(1, 4));
                zoneCoords.Add(new Vector2(0, 5));
            }
            else
            {
                for (var x = 0; x < setting.XZones; x++)
                {
                    for (var y = 0; y < setting.YZones; y++)
                    {
                        zoneCoords.Add(new Vector2(x, y));
                    }
                }
            }
            //Normalize the coordinates to be based off 0.
            var xMin = zoneCoords.Select(r => r.x).Min();
            var yMin = zoneCoords.Select(r => r.y).Min();

            //Actually spawn all our tiles (regions spawn sectors, sectors spawn tiles).
            RegionList = zoneCoords.Select(coord => new HexRegion((int)(coord.x - xMin), (int)(coord.y - yMin))).ToList();
        }
Beispiel #3
0
        IEnumerator <WaitForSeconds> GenerateMap(MapSetting setting, Action callback)
        {
            SpawnTiles(setting);
            Debug.Log("From the formless void, she wrought the expanse of space.");
            yield return(new WaitForSeconds(0.05f));

            MapTiles();
            Debug.Log("And into this expanse she whispered Order.");
            yield return(new WaitForSeconds(0.05f));

            AssignRegions(setting);
            Debug.Log("And each place was given a Name.");
            yield return(new WaitForSeconds(0.05f));

            AssignSectors();
            Debug.Log("And from one thing sprung many things, all of them with Names of their own.");
            yield return(new WaitForSeconds(0.05f));

            AssignTiles();
            Debug.Log("And to Name a thing is to shape it, and the world heaved into shape.");
            AssignResources(setting);
            Debug.Log("And into this shape, she Divided herself.");
            callback();
        }
Beispiel #4
0
 public void Launch(MapSetting setting, Action callback)
 {
     Singleton <MonoBehaviour> .Instance.StartCoroutine(GenerateMap(setting, callback));
 }
Beispiel #5
0
 public void AssignResources(MapSetting setting)
 {
     RegionList.AssignResources(setting);
 }
Beispiel #6
0
 public void AssignRegions(MapSetting setting)
 {
     RegionList.AssignAllRegions(setting);
 }
        //Main entry point into this entire mess.
        public static void AssignResources(this List <HexRegion> inputRegions, MapSetting setting)
        {
            var allSectors = new Dictionary <HexSector, int>();

            foreach (var sector in inputRegions.SelectMany(region => region.ChildSectors))
            {
                int richness;
                switch (sector.Type)
                {
                case SectorType.Anomaly:
                    richness = -10;
                    break;

                case SectorType.Deadspace:
                    richness = -10;
                    break;

                case SectorType.SystemCenter:
                    richness = 0;
                    break;

                case SectorType.Asteroids:
                    richness = -5;
                    break;

                case SectorType.Clouds:
                    richness = -5;
                    break;

                case SectorType.Blend:
                    richness = -3;
                    break;

                case SectorType.Planet:
                    richness = -4;
                    break;

                case SectorType.Unassigned:
                    richness = 0;
                    break;

                default:
                    richness = 0;
                    break;
                }
                //Liiiiiittle bonus for rich regions.
                if (sector.ParentRegion.Type == RegionType.Riches && richness != 0)
                {
                    richness -= 2;
                }
                allSectors.Add(sector, richness);
            }

            //First, put in a baseline quantity of resources in player solar systems.
            foreach (var region in inputRegions.Where(x => x.Type == RegionType.SolarSystem))
            {
                region.DistributeSystemResources(ResourceType.Aluminum, allSectors);
                region.DistributeSystemResources(ResourceType.Water, allSectors);
                region.DistributeSystemResources(Random.value < 0.5f ? ResourceType.NuclearMaterial : ResourceType.HeavyGas, allSectors);
            }

            // Now, pachinko bonus resources all around the galaxy until you run out of points to assign.
            // We have a minimum totalRichness to ensure at least a scrap of dark matter and neutron mass appear.
            var totalRichness = setting.RichnessScore * setting.PlayerCount * 35;

            if (totalRichness < 30)
            {
                totalRichness = 30;
            }

            var orderIndex = 0;
            var order      = ResourceOrder;

            while (totalRichness >= 0)
            {
                var typeToAssign = order[orderIndex];
                totalRichness -= EvenlyDistributeResource(allSectors, typeToAssign);
                orderIndex++;
            }
        }