Exemplo n.º 1
0
        public static void Island(ref HexMap map)
        {
            map.Fill("_");

            int     ci     = map.MapWidth / 2;
            int     cj     = map.MapHeight / 2;
            Vector2 center = new Vector2(ci, cj);

            List <Vector2> used = new List <Vector2>();
            List <Vector2> next = new List <Vector2>();

            for (int i = 0; i < 4; i++)
            {
                int di = ci + rng.Next(-map.MapWidth / 2, map.MapWidth / 2);
                int dj = cj + rng.Next(-map.MapHeight / 2, map.MapHeight / 2);

                foreach (var n in map.EmptyNeighbors(di, dj))
                {
                    var chanceToFail = HexMap.Distance(n, center) * 4;

                    if (rng.Next(0, 100) > 20)
                    {
                        map.Put(n, "town");
                    }
                    else
                    {
                        next.Add(n);
                    }

                    if (rng.Next(0, 100) > chanceToFail)
                    {
                        next.AddRange(map.EmptyNeighbors(n));
                    }
                }

                map.Put(di, dj, "city");
            }

            Shuffle(next);

            Queue <Vector2> nextUp = new Queue <Vector2>(next);

            while (nextUp.Count > 0)
            {
                Vector2 f = nextUp.Dequeue();
                if (map[f].biome != null)
                {
                    continue;
                }

                var bs     = map.BiomesInNeighbors(f);
                var viable = bs[rng.Next(0, bs.Count)];
                var v      = map.RandomBiomeAround(viable);
                map.Put(f, v);
                used.Add(f);

                var neighbors = map.EmptyNeighbors(f);
                foreach (var n in neighbors)
                {
                    var chanceToFail = HexMap.Distance(n, center) * 8;
                    if (rng.Next(0, 100) > chanceToFail)
                    {
                        nextUp.Enqueue(n);
                    }
                }
            }

            // moors and waters

            foreach (var field in used)
            {
                var mf = map[field];
                if ((mf.biome == "water") &&
                    map.BiomesInNeighbors(field).Contains("valley"))
                {
                    if (rng.Next(0, 100) > 50)
                    {
                        map.Put(field, "moors");
                    }
                }
            }

            foreach (var field in used)
            {
                foreach (var n in map.Neighbors(field))
                {
                    if (map[n].biome == null)
                    {
                        var prob = rng.Next(0, 10);
                        if (prob < 5)
                        {
                            map.Put(n, "water");
                        }
                    }
                }
            }

            // cities

            char sym = '@';

            foreach (var t in map.Towns)
            {
                map[t].symbol = ++sym;
            }

            var processing = true;

            while (processing)
            {
                processing = false;
                foreach (var t in map.Towns)
                {
                    var tf = map[t];

                    foreach (var n in map.Neighbors(t))
                    {
                        var nf = map[n];
                        if (nf.biome == "town" || nf.biome == "city")
                        {
                            if (tf.symbol < nf.symbol)
                            {
                                nf.symbol  = tf.symbol;
                                processing = true;
                            }
                        }
                    }
                }
            }

            foreach (var t in map.Towns)
            {
                var tf = map[t];
                if (!map.TownFields.ContainsKey(tf.symbol))
                {
                    map.TownFields.Add(tf.symbol, new List <Vector2>());
                }

                map.TownFields[tf.symbol].Add(t);
            }

            Dictionary <char, List <Vector2> > tmpMap = new Dictionary <char, List <Vector2> >();

            {
                char i = '@';
                foreach (var p in map.TownFields)
                {
                    i++;
                    if (!tmpMap.ContainsKey(i))
                    {
                        tmpMap.Add(i, new List <Vector2>());
                    }

                    foreach (var f in p.Value)
                    {
                        tmpMap[i].Add(f);
                        map[f].symbol = i;
                    }
                }

                map.TownFields = tmpMap;
            }

            TownNames.Shuffle();

            foreach (var p in map.TownFields)
            {
                var    index      = p.Key - 65;
                HexMap m          = map;
                var    c          = p.Value.FindAll(t => m[t].biome == "city");
                var    realCenter = c.Count > 0 ? c[0] : rng.FromArray(p.Value);

                Vector2 cent = p.Value.Aggregate(Vector2.Zero, (acc, x) => acc + m.XY(x));
                cent /= p.Value.Count;

                map.TownTitles[cent] = new KeyValuePair <Vector2, string>(realCenter, TownNames[index]);
            }
        }
Exemplo n.º 2
0
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            font = Content.Load <SpriteFont>("Samble");

            camera = new Camera(graphics.GraphicsDevice.Viewport);

            map = new HexMap(20, 20);
            map.Dimensions(80, 0, 160, 140);
            map.Blank("tile_ocean_plain_dark_");
            map.DefineBiomes("town", "city", "forest", "hills", "moors", "mountains", "valley", "water");

            map.TieBiomes("city", "town", 4);
            map.TieBiomes("city", "forest", 5);
            map.TieBiomes("city", "valley", 5);

            map.TieBiomes("moors", "moors", 5);
            map.TieBiomes("moors", "water", 5);

            map.TieBiomes("town", "valley", 3);
            map.TieBiomes("town", "town", 2);
            map.TieBiomes("town", "hills", 3);
            map.TieBiomes("town", "water", 2);
            map.TieBiomes("town", "forest", 3);

            map.TieBiomes("forest", "town", 2);
            map.TieBiomes("forest", "forest", 3);
            map.TieBiomes("forest", "hills", 3);
            map.TieBiomes("forest", "mountains", 3);
            map.TieBiomes("forest", "valley", 1);

            map.TieBiomes("hills", "valley", 5);
            map.TieBiomes("hills", "forest", 2);
            map.TieBiomes("hills", "mountains", 2);
            map.TieBiomes("hills", "town", 1);

            map.TieBiomes("mountains", "hills", 5);
            map.TieBiomes("mountains", "forest", 5);

            map.TieBiomes("valley", "valley", 2);
            map.TieBiomes("valley", "hills", 2);
            map.TieBiomes("valley", "mountains", 2);
            map.TieBiomes("valley", "forest", 4);
            map.TieBiomes("valley", "town", 2);

            map.TieBiomes("water", "water", 5);
            map.TieBiomes("water", "mountains", 4);
            map.TieBiomes("water", "valley", 1);

            map.Add("city_clear", "town", "tile_city_clear_green_", 0, 9);
            map.Add("city_covered", "city", "tile_city_covered_green_", 0, 9);
            map.Add("forest_conifer_dense_clear", "forest", "tile_forest_conifer_dense_clear_green_", 0, 9);
            map.Add("forest_conifer_dense_covered", "forest", "tile_forest_conifer_dense_covered_green_", 0, 9);
            map.Add("forest_conifer_sparse_clear", "forest", "tile_forest_conifer_sparse_clear_green_", 0, 9);
            map.Add("forest_conifer_sparse_covered", "forest", "tile_forest_conifer_sparse_covered_green_", 0, 9);
            map.Add("forest_deciduous_dense_clear", "forest", "tile_forest_deciduous_dense_clear_green_", 0, 9);
            map.Add("forest_deciduous_dense_covered", "forest", "tile_forest_deciduous_dense_covered_green_", 0, 9);
            map.Add("forest_deciduous_sparse_clear", "forest", "tile_forest_deciduous_sparse_clear_green_", 0, 9);
            map.Add("forest_deciduous_sparse_covered", "forest", "tile_forest_deciduous_sparse_covered_green_", 0, 9);
            map.Add("hills_dense_clear", "hills", "tile_hills_dense_clear_green_", 0, 9);
            map.Add("hills_sparse_covered", "hills", "tile_hills_sparse_covered_green_", 0, 9);
            map.Add("mountain_peak_forest_conifer", "mountains", "tile_mountain_peak_forest_conifer_green_", 0, 9);
            map.Add("mountain_peak_forest_deciduous", "mountains", "tile_mountain_peak_forest_deciduous_green_", 0, 9);
            map.Add("mountain_peak_grassland_green", "mountains", "tile_mountain_peak_grassland_green_", 0, 9);
            map.Add("valley_dense_clear", "valley", "tile_valley_dense_clear_green_", 0, 9);
            map.Add("valley_sparse_clear", "valley", "tile_valley_sparse_clear_green_", 0, 9);
            map.Add("ocean_waves_small_dark", "water", "tile_ocean_waves_small_dark_", 0, 9);
            map.Add("ocean_waves_big_dark", "water", "tile_ocean_waves_big_dark_", 0, 9);
            map.Add("moor_sparse_covered", "moors", "tile_moor_sparse_covered_blue_", 0, 9);
            map.Add("moor_dense_clear", "moors", "tile_moor_dense_clear_blue_", 0, 9);

            map.AddLocations("overlay_location_framed_uncut_standard", "battlefield", "bridge", "camp", "campfire", "castle", "cave", "church", "city", "city_house", "dungeon",
                             "farm", "graveyard", "house", "inn", "lighthouse", "military", "mine", "nest", "outpost", "quarry", "ruin", "sanctuary", "ship", "shipwreck", "spring", "tent",
                             "tower", "village", "windmill", "witch_hut");

            map.AddCharacters("strategy_figure_180x180_framed_standard", "adventurer", "adventurer_with_horse", "archer", "armored_horse", "balloon", "bandit", "bandits", "barbarian",
                              "bat", "bear", "boar", "bull", "carriage", "cart", "cat", "chicken", "cow", "crow", "cyclops", "dog", "donkey", "dragon", "druid", "elder", "farmer", "fen_fire", "frog",
                              "ghost", "goblin", "goblins", "hero", "hero_with_horse", "horse", "knight", "knight_with_horse", "kraken", "livestock", "mage", "miner", "mummy", "orc", "orcs", "paladin",
                              "paladin_with_horse", "party", "people", "pig", "pikeman", "priest", "rabbit", "rat", "rogue", "saddled_donkey", "saddled_horse", "sheep", "skeleton", "skeleton_archer",
                              "skeleton_warrior", "skeletons", "slime", "snake", "soldiers", "spider", "stag", "trader", "trader_with_donkey", "trader_with_wagon", "troll", "turkey", "villager", "wagon",
                              "warrior", "werewolf", "witch", "wolf", "worker", "workers", "yeti", "zombie", "zombies");

            map.player = new Character(Content);
            map.Load(Content);

            Creator.Island(ref map);

            center.X = 1600;
            center.Y = 1400;
        }