Ejemplo n.º 1
0
        public static WaterSquare[][] RiversToWaterSquares(int width, int height, List<List<RiverCoord>> rivers)
        {
            var output = new WaterSquare[width][];
            for (var i = 0; i < width; i++)
                output[i] = new WaterSquare[height];

            for (var i = 0; i < rivers.Count; i++)
            {
                var currRiver = rivers[i];
                for (var j = 0; j < currRiver.Count; j++)
                {
                    var riverCord = currRiver[j];
                    if (output[riverCord.PointX][riverCord.PointY] == null)
                    {
                        output[riverCord.PointX][riverCord.PointY] = new WaterSquare(riverCord.PointX, riverCord.PointY,
                                                                                     null, null, null, null);
                    }

                    var currWaterSquare = output[riverCord.PointX][riverCord.PointY];
                    var addedOne = false;
                    if (j - 1 >= 0)
                    {
                        addedOne = true;
                        var prevRiverCord = currRiver[j - 1];
                        if (prevRiverCord.PointY == riverCord.PointY - 1)
                            currWaterSquare.North = new WaterSource(false, prevRiverCord.RiverSize);
                        if (prevRiverCord.PointY == riverCord.PointY + 1)
                            currWaterSquare.South = new WaterSource(false, prevRiverCord.RiverSize);
                        if (prevRiverCord.PointX == riverCord.PointX - 1)
                            currWaterSquare.West = new WaterSource(false, prevRiverCord.RiverSize);
                        if (prevRiverCord.PointX == riverCord.PointX + 1)
                            currWaterSquare.East = new WaterSource(false, prevRiverCord.RiverSize);
                    }

                    if (j + 1 < currRiver.Count)
                    {
                        addedOne = true;
                        var nextRiverCord = currRiver[j + 1];
                        if (nextRiverCord.PointY == riverCord.PointY - 1)
                            currWaterSquare.North = new WaterSource(true, riverCord.RiverSize);
                        if (nextRiverCord.PointY == riverCord.PointY + 1)
                            currWaterSquare.South = new WaterSource(true, riverCord.RiverSize);
                        if (nextRiverCord.PointX == riverCord.PointX - 1)
                            currWaterSquare.West = new WaterSource(true, riverCord.RiverSize);
                        if (nextRiverCord.PointX == riverCord.PointX + 1)
                            currWaterSquare.East = new WaterSource(true, riverCord.RiverSize);
                    }
                    if (!addedOne)
                        currWaterSquare.HighestSize = currWaterSquare.LowestSize = riverCord.RiverSize;
                }
            }
            return output;
        }
Ejemplo n.º 2
0
        //private BackgroundWorker bw = new BackgroundWorker();
        private void WaterTexture(WaterSquare[][] waterSquare)
        {
            for (var i = 0; i < MainGame.MapWidth; i++)
            {
                for (var j = 0; j < MainGame.MapHeight; j++)
                {
                    if (waterSquare[i][j] == null) continue;
                    var r = new Rectangle(i, j, 1, 1);
                    var color = new Color[1];
                    color[0] = new Color(0, 0, waterSquare[i][j].HighestSize);

                    _renderTexture.SetData(0, r, color, 0, 1);
                }
            }
        }
Ejemplo n.º 3
0
        private byte[,] GetTestWater(WaterSquare[][] masterWaterData, int x, int y, Random rand)
        {
            var s = Environment.TickCount;
            var data = new byte[PlayScreen.SectorTileSize,PlayScreen.SectorTileSize];

            if (masterWaterData[x][y] != null)
                NoiseGen.GetRiverSquare(ref data, masterWaterData[x][y], 3, rand);
            System.Diagnostics.Debug.WriteLine("time output:{0}", Environment.TickCount - s);
            return data;
        }
Ejemplo n.º 4
0
        public static void GetRiverSquare(ref byte[,] output, WaterSquare area, byte val, Random rand)
        {
            var size = output.GetLength(0);

            var mainSource = (area.North != null && area.North.IsFlowDirection) ? area.North : null;
            mainSource = (mainSource == null && area.South != null && area.South.IsFlowDirection)
                             ? area.South
                             : mainSource;
            mainSource = (mainSource == null && area.West != null && area.West.IsFlowDirection) ? area.West : mainSource;
            mainSource = (mainSource == null && area.East != null && area.East.IsFlowDirection) ? area.East : mainSource;

            byte tempVal = 5;
            var count = 0;
            if (area.North != null)
                count++;
            if (area.South != null)
                count++;
            if (area.West != null)
                count++;
            if (area.East != null)
                count++;

            if (mainSource == null && count > 0)
            {
                var goNorth = area.North != null;
                var goSouth = area.South != null;
                var goWest = area.West != null;
                var goEast = area.East != null;

                var hasFlow = goNorth && area.North.IsFlowDirection;
                hasFlow = (goSouth && area.South.IsFlowDirection) || hasFlow;
                hasFlow = (goWest && area.West.IsFlowDirection) || hasFlow;
                hasFlow = (goEast && area.East.IsFlowDirection) || hasFlow;

                var outThickness = goNorth ? area.North.Thickness : byte.MaxValue;
                outThickness = goSouth && area.South.Thickness < outThickness ? area.South.Thickness : outThickness;
                outThickness = goWest && area.West.Thickness < outThickness ? area.West.Thickness : outThickness;
                outThickness = goEast && area.East.Thickness < outThickness ? area.East.Thickness : outThickness;
                if (!hasFlow)
                {
                    if (_newRiver == null)
                        _newRiver = new byte[size,size];
                    else
                        Array.Clear(_newRiver, 0, _newRiver.Length);

                    if (_newerRiver == null)
                        _newerRiver = new byte[size,size];
                    else
                        Array.Clear(_newRiver, 0, _newRiver.Length);

                    const bool createLake = true;
                    if (goNorth)
                    {
                        CreateRiverBezier(ref _newerRiver, area.North.Thickness, tempVal, true, false, false,
                                          false, createLake, rand);
                        tempVal++;
                        MergeData(ref _newRiver, _newerRiver);
                    }
                    if (goSouth)
                    {
                        CreateRiverBezier(ref _newerRiver, area.South.Thickness, tempVal, false, true, false,
                                          false, createLake, rand);
                        tempVal++;
                        MergeData(ref _newRiver, _newerRiver);
                    }
                    if (goWest)
                    {
                        CreateRiverBezier(ref _newerRiver, area.West.Thickness, tempVal, false, false, true,
                                          false, createLake, rand);
                        tempVal++;
                        MergeData(ref _newRiver, _newerRiver);
                    }
                    if (goEast)
                    {
                        CreateRiverBezier(ref _newerRiver, area.East.Thickness, tempVal, false, false, false,
                                          true, createLake, rand);
                        tempVal++;
                        MergeData(ref _newRiver, _newerRiver);
                    }
                }
                else
                {
                    CreateRiverBezier(ref _newRiver, outThickness, tempVal, goNorth, goSouth, goWest, goEast, true, rand);
                    tempVal++;
                }

                ChangeVals(ref _newRiver, tempVal);
                tempVal++;
                MergeData(ref output, _newRiver);
            }

            if (mainSource == null)
            {
                GetLake(ref output, area.LowestSize, rand);
                return;
            }

            if (count == 1)
            {
                Array.Clear(_newRiver, 0, _newRiver.Length);

                CreateRiverBezier(ref _newRiver, mainSource.Thickness, tempVal, area.North == mainSource,
                                  area.South == mainSource, area.West == mainSource,
                                  area.East == mainSource,
                                  true, rand);
                MergeData(ref output, _newRiver);
            }
            else
            {
                Array.Clear(_newRiver, 0, _newRiver.Length);

                for (var i = 0; i < 4; i++)
                {
                    WaterSource currentTester;
                    switch (i)
                    {
                        case 0:
                            currentTester = area.North;
                            break;
                        case 1:
                            currentTester = area.South;
                            break;
                        case 2:
                            currentTester = area.West;
                            break;
                        default:
                            currentTester = area.East;
                            break;
                    }

                    if (currentTester == null)
                        continue;

                    if (currentTester == mainSource)
                        continue;

                    var goNorth = currentTester == area.North || mainSource == area.North;
                    var goSouth = currentTester == area.South || mainSource == area.South;
                    var goWest = currentTester == area.West || mainSource == area.West;
                    var goEast = currentTester == area.East || mainSource == area.East;

                    var outThickness = goNorth ? area.North.Thickness : Byte.MaxValue;
                    outThickness = goSouth && area.South.Thickness < outThickness
                                       ? area.South.Thickness
                                       : outThickness;
                    outThickness = goWest && area.West.Thickness < outThickness
                                       ? area.West.Thickness
                                       : outThickness;
                    outThickness = goEast && area.East.Thickness < outThickness
                                       ? area.East.Thickness
                                       : outThickness;

                    CreateRiverBezier(ref _newRiver, outThickness, tempVal, goNorth, goSouth, goWest, goEast, false,
                                      rand);
                    tempVal++;
                    MergeData(ref output, _newRiver);
                }
            }
            //for (var y = 0; y < size; y++)
            //{
            //    for (var x = 0; x < size; x++)
            //    {
            //            System.Diagnostics.Debug.Write(output[x,y] + ",");
            //    }
            //    System.Diagnostics.Debug.WriteLine("");
            //}
            ChangeVals(ref output, val);
        }