Esempio n. 1
0
        private bool Extend()
        {
            RiverSegment lastSeg = _river.LastSeg;
            Coords       lastLoc = lastSeg.Location;

            // Try to get downhill hexes first, if possible
            var adj = _world.Map.GetFilteredAdjacency(lastLoc, (x => !DoublesBack(x) && IsLowerOrWater(lastLoc, x)));

            // Nothing lower; need to do a lateral move
            if (adj.Count == 0)
            {
                adj = _world.Map.GetFilteredAdjacency(lastLoc, (x => !DoublesBack(x) && IsLateral(lastLoc, x)));
            }

            // Nowhere to go, can't extend
            if (adj.Count == 0)
            {
                return(false);
            }

            var adjList   = adj.ToList();
            var candidate = adjList[_rand.GenerateInt(adjList.Count)];


            if (_world.Map.IsWaterAt(candidate.Value))
            {
                _river.Terminate(candidate.Key);
                return(false);
            }

            _river.Extend(candidate.Key, candidate.Value);
            _allCoords.Add(candidate.Value);
            return(true);
        }
Esempio n. 2
0
        private void DrawHexMap(HexMap map, Func <Coords, Color> colorMethod, Double scale = DEFAULT_SCALE)
        {
            Point offset = GetHexagonOffsets();

            double x = 0.0;
            double y = 0.0;

            for (int i = 0; i < map.Width; i++)
            {
                x += scale + offset.X;
                y  = (i % 2 != 0) ? offset.Y : 0.0;
                for (int j = 0; j < map.Height; j++)
                {
                    y += (offset.Y * 2);
                    Coords     currCoords = new Coords(i, j);
                    MapHexagon newMapHex  = CreateHexagon(x, y, colorMethod(currCoords), currCoords);
                    newMapHex.ChangeColor(map.BaseColorAt(currCoords));
                    MapHexagons.Add(newMapHex);
                    if (map.IsRiverAt(currCoords))
                    {
                        RiverSegment seg   = map.GetMainRiverSegmentAt(currCoords);
                        Hex.Side?    entry = seg.EntrySide;
                        Hex.Side?    exit  = seg.ExitSide;
                        //DrawRiver(x, y, entry, exit, scale);
                        DrawRivers();
                    }
                }
            }
        }
Esempio n. 3
0
        public void Commit()
        {
            // iterate through the river and actually place the river segments where they belong
            RiverSegment seg = _river.FirstSeg;

            do
            {
                _world.Map.AddMainRiverAt(seg.Location, seg);
                seg = seg.NextSegment;
            }while (seg.NextSegment != null);
        }
Esempio n. 4
0
        /**
         * <summary>
         * Adds a main RiverSegment to the Hex at given Coords. This is a tile-sized chunk of the
         * primary river that moves through this Hex.
         * </summary>
         * <param name="coords">The Coords of the Hex to update.</param>
         * <param name="riverSegment">The RiverSegment to make the primary river at this Hex.</param>
         * <returns>True if the Hex was updated. False only if the Coords were invalid.</returns>
         */
        public bool AddMainRiverAt(Coords coords, RiverSegment riverSegment)
        {
            if (coords.invalid)
            {
                return(false);
            }
            Hex hex = GetHexAt(coords);

            hex.MainRiverSegment = riverSegment;
            return(true);
        }
Esempio n. 5
0
        private void DrawRivers(Double scale = DEFAULT_SCALE)
        {
            foreach (var river in _world.Rivers)
            {
                RiverSegment seg = river.FirstSeg;
                MapRiver     mr  = new MapRiver();

                mr.Points.Add(CenterPointFromCoords(seg.Location));

                while ((seg.NextSegment != null))
                {
                    if (CoordsWrap(seg.Location, seg.NextSegment.Location))
                    {
                        Point loc       = PointFromCoords(seg.Location);
                        Point exitPoint = GetCoordsOfSideMidpoint(loc.X, loc.Y, (Hex.Side)seg.ExitSide);
                        mr.Points.Add(exitPoint);
                        MapRivers.Add(mr);
                        mr  = new MapRiver();
                        loc = PointFromCoords(seg.NextSegment.Location);
                        Point entryPoint = GetCoordsOfSideMidpoint(loc.X, loc.Y, (Hex.Side)seg.NextSegment.EntrySide);
                        mr.Points.Add(entryPoint);
                    }
                    seg = seg.NextSegment;
                    mr.Points.Add(CenterPointFromCoords(seg.Location));
                }

                if (river.LastSeg.ExitSide != null)
                {
                    Hex.Side exitSide     = (Hex.Side)river.LastSeg.ExitSide;
                    Point    loc          = PointFromCoords(river.LastSeg.Location);
                    Point    sideMidpoint = GetCoordsOfSideMidpoint(loc.X, loc.Y, exitSide);
                    mr.Points.Add(sideMidpoint);
                }

                MapRivers.Add(mr);
            }
        }