Пример #1
0
        public static void PushSectorType(this HexRegion region, SectorType type)
        {
            var possibleSectors = region.ChildSectors.Where(x => x.Type == SectorType.Unassigned).ToList();
            var index           = Random.Range(0, possibleSectors.Count);

            possibleSectors[index].Type = type;
        }
Пример #2
0
        public HexSector(int x, int y, HexRegion parentRegion)
        {
            ParentRegion = parentRegion;
            X            = x;
            Y            = y;
            IsEven       = (X % 2 == 0);
            ChildTiles   = new List <HexTile>();

            foreach (var coord in GetTileMapping)
            {
                var tileXCord = X * 7 + (int)coord.x;
                var tileYCord = Y * 7 + (int)coord.y;

                var tileXPos = X * 5.7f + coord.x * 0.815f;
                var tileYPos = Y * 7f + coord.y;

                if (IsEven)
                {
                    tileYPos  += 3.5f;
                    tileYCord += 3;
                }
                else if (coord.x % 2 == 0)
                {
                    tileYCord--;
                }

                GameObject hexObject;

                if (coord.x % 2 == 0)
                {
                    hexObject = Object.Instantiate(HexPrefab, new Vector3(tileXPos, tileYPos, 0), Quaternion.identity) as GameObject;
                }
                else
                {
                    hexObject = Object.Instantiate(HexPrefab, new Vector3(tileXPos, tileYPos + 0.5f, 0), Quaternion.identity) as GameObject;
                }
                if (hexObject == null)
                {
                    continue;
                }
                var tile = hexObject.GetComponent <HexTile>();

                GameState.Me.HexMap.TileList.Add(tile);
                ChildTiles.Add(tile);
                tile.ParentSector = this;
                tile.X            = tileXCord;
                tile.Y            = tileYCord;
                tile.Resource     = new Resource(0, 0, 0, 0);
                tile.SetId();
                hexObject.name             = (tile.X + ", " + tile.Y);
                hexObject.transform.parent = MapGen.Map.transform;
                GameState.Me.AllTiles.Add(tile.Id, tile);
                if (coord.x == 4 && coord.y == 4)
                {
                    CenterTile = tile;
                }
            }
        }
Пример #3
0
        public static bool NeighbourIsType(this HexRegion region, HexRegion[,] map, RegionType type)
        {
            var neighbourList = new List <HexRegion>();
            var x             = region.X;
            var y             = region.Y;

            //UL
            if (x > 0 && y < map.GetLength(1))
            {
                if (map[x - 1, y + 1] != null)
                {
                    neighbourList.Add(map[x - 1, y + 1]);
                }
            }
            //LL
            if (x > 0)
            {
                if (map[x - 1, y] != null)
                {
                    neighbourList.Add(map[x - 1, y]);
                }
            }
            //UR
            if (y < map.GetLength(1))
            {
                if (map[x, y + 1] != null)
                {
                    neighbourList.Add(map[x, y + 1]);
                }
            }
            //DL
            if (y > 0)
            {
                if (map[x, y - 1] != null)
                {
                    neighbourList.Add(map[x, y - 1]);
                }
            }
            //RR
            if (x < map.GetLength(1))
            {
                if (map[x + 1, y] != null)
                {
                    neighbourList.Add(map[x + 1, y]);
                }
            }
            //DR
            if (x < map.GetLength(1) && y > 0)
            {
                if (map[x + 1, y - 1] != null)
                {
                    neighbourList.Add(map[x + 1, y - 1]);
                }
            }

            return(neighbourList.Any(r => r.Type == type));
        }
Пример #4
0
 static void AssignSneakySectors(this HexRegion region)
 {
     region.PushSectorType(Random.value >= 0.20f ? SectorType.Planet : SectorType.Clouds);
     region.PushSectorType(Random.value >= 0.20f ? SectorType.Deadspace : SectorType.Clouds);
     region.PushSectorType(SectorType.Clouds);
     region.PushSectorType(SectorType.Clouds);
     region.PushSectorType(SectorType.Clouds);
     region.PushSectorType(SectorType.Blend);
     region.PushSectorType(SectorType.Asteroids);
 }
Пример #5
0
 static void AssignDeadSectors(this HexRegion region)
 {
     region.CenterSector.Type = Random.value >= 0.20f ? SectorType.Anomaly : SectorType.Deadspace;
     region.PushSectorType(Random.value >= 0.50f ? SectorType.Asteroids : SectorType.Clouds);
     region.PushSectorType(Random.value >= 0.40f ? SectorType.Clouds : SectorType.Deadspace);
     region.PushSectorType(SectorType.Deadspace);
     region.PushSectorType(SectorType.Deadspace);
     region.PushSectorType(SectorType.Deadspace);
     region.PushSectorType(SectorType.Deadspace);
 }
Пример #6
0
 static void AssignRichesSectors(this HexRegion region)
 {
     region.CenterSector.Type = Random.value >= 0.33f ? SectorType.Anomaly : SectorType.Asteroids;
     region.PushSectorType(Random.value >= 0.50f ? SectorType.Planet : SectorType.Clouds);
     region.PushSectorType(Random.value >= 0.45f ? SectorType.Deadspace : SectorType.Blend);
     region.PushSectorType(SectorType.Clouds);
     region.PushSectorType(SectorType.Blend);
     region.PushSectorType(SectorType.Asteroids);
     region.PushSectorType(SectorType.Blend);
 }
Пример #7
0
 static void AssignSolarSystemSectors(this HexRegion region)
 {
     region.CenterSector.Type = SectorType.SystemCenter;
     region.PushSectorType(SectorType.Planet);
     region.PushSectorType(SectorType.Planet);
     region.PushSectorType(SectorType.Asteroids);
     region.PushSectorType(SectorType.Clouds);
     region.PushSectorType(SectorType.Blend);
     region.PushSectorType(SectorType.Blend);
 }
Пример #8
0
        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;
                }
            }
        }
Пример #9
0
        //Hardcoded method to make sure each starting area has a bare minimum of resources.
        static void DistributeSystemResources(this HexRegion region, ResourceType type, Dictionary <HexSector, int> scoreTracking)
        {
            var allSectors   = region.ChildSectors.ToDictionary(sector => sector, sector => 0);
            var targetSector =
                allSectors.Keys.Where(x => ResourceSpawnTypes[type].Contains(x.Type))
                .OrderBy(x => allSectors[x])
                .First();

            //Find a nice empty tile to populate.
            var possibleTiles = targetSector.ChildTiles.Where(x => x.Resource.Type == ResourceType.Nothing).ToList();

            possibleTiles[Random.Range(0, possibleTiles.Count)].Resource = new Resource(type);

            scoreTracking[targetSector] += ResourceCost[type];
        }