Example #1
0
        private GridLayer FindGridLayer(int layerID, bool autoCreate, string mat_path = null)
        {
            for (int index = this.mGridLayers.Count - 1; index >= 0; --index)
            {
                if (this.mGridLayers[index].LayerID == layerID)
                {
                    return(this.mGridLayers[index]);
                }
            }
            if (!autoCreate)
            {
                return((GridLayer)null);
            }
            GridLayer gridLayer = (GridLayer) new GameObject("Grid").AddComponent <GridLayer>();

            ((Component)gridLayer).get_transform().SetParent(((Component)this).get_transform(), false);
            ((MeshFilter)((Component)gridLayer).GetComponent <MeshFilter>()).set_mesh(this.mGridMesh);
            gridLayer.LayerID = layerID;
            ((Component)gridLayer).get_gameObject().SetActive(false);
            Transform transform = ((Component)gridLayer).get_transform();

            transform.set_position(Vector3.op_Addition(transform.get_position(), Vector3.op_Multiply(Vector3.op_Multiply(Vector3.get_up(), (float)layerID), 0.01f)));
            if (!string.IsNullOrEmpty(mat_path))
            {
                gridLayer.ChangeMaterial(mat_path);
            }
            this.mGridLayers.Add(gridLayer);
            return(gridLayer);
        }
Example #2
0
        public XDocument ToXml(GridLayer gridLayer)
        {
            var xDocument = new XDocument(new XDeclaration("1.0", "utf-8", "no"));

            XElement gridNetElement = new NinXElement("RuteNettKart", "",
                                                      new XAttribute(XNamespace.Xmlns + "nin", Config.Settings.Namespace.Nin),
                                                      new XAttribute(XNamespace.Xmlns + "gml", gmlNs),
                                                      new NinXElement("navn", "gridLayer.Name", gridLayer.Name),
                                                      new NinXElement("beskrivelse", "gridLayer.Description", gridLayer.Description),
                                                      new NinXElement("kode", "AddCodeElement('Kode', gridLayer.Code)",
                                                                      AddCodeElement("Kode", gridLayer.Code)),
                                                      XmlSkriver.ContactElement("eier", gridLayer.Owner),
                                                      new NinXElement("etablertDato", "gridLayer.Established", gridLayer.Established),
                                                      new NinXElement("ruteNett", "(int)gridLayer.Type", (int)gridLayer.Type),
                                                      AddMapElements(gridLayer.Cells, gridLayer.Code != null ? gridLayer.Code.Value : string.Empty)
                                                      );

            xDocument.Add(gridNetElement);

            var emptyElements = from element in xDocument.Descendants() where element.IsEmpty select element;

            while (emptyElements.Any())
            {
                emptyElements.Remove();
            }

            return(xDocument);
        }
        public void StoreGridLayerTest()
        {
            var gridLayer = new GridLayer("Kalklag test", RutenettType.SSB010KM)
            {
                Description = "Test av kalklag",
                Code        = new Code {
                    Value = "KA", Registry = "NiN", Version = "2.0"
                },
                Owner = new Contact {
                    Company = "Artsdatabanken"
                },
                Established = DateTime.Now,
                MinValue    = "0.0",
                MaxValue    = "3.0"
            };

            gridLayer.Cells.Add(new GridLayerCell {
                CellId = "22600007060000", Value = "0.0"
            });
            gridLayer.Cells.Add(new GridLayerCell {
                CellId = "22700007060000", Value = "1.0"
            });
            gridLayer.Cells.Add(new GridLayerCell {
                CellId = "22600007070000", Value = "2.0"
            });
            gridLayer.Cells.Add(new GridLayerCell {
                CellId = "22700007070000", Value = "3.0"
            });

            SqlServer.BulkStoreGridLayer(gridLayer);
        }
Example #4
0
 public GridDrawAction(GridLayer gridLayer, Point at, bool setTo)
     : base(gridLayer)
 {
     draw = new List <Point>();
     draw.Add(at);
     this.setTo = setTo;
 }
Example #5
0
    public void Init(int xi, int yi, int Id, Facing f, Type t, Grid g)
    {
        x      = xi;
        y      = yi;
        id     = Id;
        facing = f;
        type   = t;
        grid   = g;

        Prototype p = default(Prototype);

        for (int i = 0; i < prototypes.Count; i++)
        {
            if (prototypes[i].type == type)
            {
                p = prototypes[i];
            }
        }
        if (p.type == Builtins.Uninitialized)
        {
            Logging.Error("Couldn't find type " + type + " in prototypes"); return;
        }
        height = -p.height;
        layer  = p.layer;

        animator.animations = p.animations;

        animator.StartAnimation(animator.animations[0]);
        MatchFacing();

        transform.localPosition = new Vector3(x, y, height);
        grid.cells[x, y, layer] = id;
    }
Example #6
0
 private void btnOption_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
 {
     try
     {
         BackgroundLayer layer                  = m_canvas.Model.BackgroundLayer as BackgroundLayer;
         GridLayer       Grid                   = m_canvas.Model.GridLayer as GridLayer;
         DrawingLayer    Drw                    = m_canvas.Model.ActiveLayer as DrawingLayer;
         Color           nullStorageColor       = m_canvas.Model.NullStorageColor;
         Color           emptyShelfStorageColor = m_canvas.Model.EmptyShelfStorageColor;
         Color           fullShelfStorageColor  = m_canvas.Model.FillShelfStorageColor;
         if (layer != null && Grid != null && Drw != null)
         {
             using (FrmOption frm = new FrmOption(Grid.Enabled, Grid.GridStyle, Grid.Color, layer.Color, Drw.Color, nullStorageColor, emptyShelfStorageColor, fullShelfStorageColor, Drw.Width))
             {
                 if (frm.ShowDialog() == DialogResult.OK)
                 {
                     Grid.Enabled   = frm.GridEnable;
                     Grid.GridStyle = frm.GridStyle;
                     Grid.Color     = frm.GridColor;
                     layer.Color    = frm.BackGroudColor;
                     Drw.Color      = frm.PenColor;
                     Drw.Width      = frm.PenWidth;
                     m_canvas.Model.NullStorageColor       = frm.NullStorageColor;
                     m_canvas.Model.EmptyShelfStorageColor = frm.EmptyShelfStorageColor;
                     m_canvas.Model.FillShelfStorageColor  = frm.FullShelfStorageColor;
                     m_canvas.DoInvalidate(true);
                 }
             }
         }
     }
     catch (Exception ex)
     { MsgBox.ShowError(ex.Message); }
 }
Example #7
0
        public Level(Game game)
        {
            LoadAssets();
            ConfigureEntities();

            UnitBalance  = 1200; // default
            Health       = 100;
            WaveNumber   = 0;
            CurrentState = WaveState.None;

            //_enemyPool = new EntityPool(1000);
            _scanlines = new ScanlineShader(new Vector2u((uint)Game.Size.X, (uint)Game.Size.Y));
            _renderTex = new RenderTexture((uint)Game.Size.X, (uint)Game.Size.Y, true);

            var tileSize = _texTileBasic.Size.X * SpriteScalar;

            _game         = game;
            _overlayInfo  = new InfoOverlay(_game, this);
            _overlayLevel = new LevelOverlay(this, SpriteScalar, tileSize);
            _overlayLevel.SetSelectionState(_texTileRoad, 128);
            Camera = new View(new Vector2f(Game.Size.X / 2, Game.Size.Y / 2), Game.Size);

            _tileMap     = new TileMap(this, _texTileBasic, tilesX, tilesY, tileSize);
            _towerMap    = new GridLayer <TowerEntity>(tilesX, tilesY, tileSize);
            _pathfinding = new AStar <Tile>(HeuristicMethod.Manhatten);
            //Path = _pathfinding.CalculatePath(_tileMap.StartTile, _tileMap.EndTile, _tileMap).ToList<Tile>();
            //game.MouseButtonPressed += (sender, e) => { Camera.Move(new Vector2f(-10f, -10f)); };

            _enemyPool = new EntityPool <EnemyEntity>(1000);

            UpdateInfo();
        }
Example #8
0
    private void TryCreateOnLayer(GridLayer layer, Vector3Int gridPosition)
    {
        gridPosition.y = (int)layer;

        if (_collisionsMatrix.Contains(gridPosition))
        {
            return;
        }
        else
        {
            _collisionsMatrix.Add(gridPosition);
        }

        GridObject template = GetRandomTemplate(layer);

        if (template == null)
        {
            return;
        }

        Vector3 position = GridToWorldPosition(gridPosition);

        GameObject createdObject = Instantiate(template, position, Quaternion.identity, transform).gameObject;

        Destroy(createdObject, _playerSpeed / _cellSize);
    }
Example #9
0
        /// <summary>
        /// This function highlights blocks in a grid that intersects with each other.
        /// </summary>
        /// <param name="firstGrid"></param>
        /// <param name="secondGrid"></param>
        /// <returns></returns>
        public static GridLayer IntersectGrid(GridLayer firstGrid, GridLayer secondGrid, BlockType highlight)
        {
            // Check for their size.
            if (firstGrid.Width != secondGrid.Width || firstGrid.Height != secondGrid.Height)
            {
                throw new InvalidLayerSizeException(secondGrid.Width, secondGrid.Height,
                                                    firstGrid.Width, firstGrid.Height);
            }

            // Create new grid with first grid as reference.
            GridLayer output = new GridLayer(firstGrid.Width, firstGrid.Height);

            // Start comparing them here
            for (int width = 0; width < output.Width; width++)
            {
                for (int height = 0; height < output.Height; height++)
                {
                    if (firstGrid[width, height].Type != BlockType.Empty &&
                        secondGrid[width, height].Type != BlockType.Empty)
                    {
                        output[width, height].Type = highlight;
                    }
                }
            }

            return(output);
        }
Example #10
0
        /// <summary>
        /// This method is used to merge two grids together. It should be noted that the second grid
        /// will overlap stuff on the first grid.
        /// </summary>
        /// <returns></returns>
        public static GridLayer MergeGrid(GridLayer firstGrid, GridLayer secondGrid)
        {
            // Check for their size.
            if (firstGrid.Width != secondGrid.Width || firstGrid.Height != secondGrid.Height)
            {
                throw new InvalidLayerSizeException(secondGrid.Width, secondGrid.Height,
                                                    firstGrid.Width, firstGrid.Height);
            }

            // Create new grid with first grid as reference.
            GridLayer output = firstGrid;

            // Replace everything that's not empty from second grid to first grid.
            for (int width = 0; width < output.Width; width++)
            {
                for (int height = 0; height < output.Height; height++)
                {
                    if (secondGrid[width, height].Type != BlockType.Empty)
                    {
                        output[width, height].Type = secondGrid[width, height].Type;
                    }
                }
            }

            return(output);
        }
Example #11
0
 public GridFloodAction(GridLayer gridLayer, int cellX, int cellY, bool setTo)
     : base(gridLayer)
 {
     CellX = cellX;
     CellY = cellY;
     SetTo = setTo;
 }
Example #12
0
        public void ShowGridLayer(int layerID, GridMap <Color32> grid, bool mask)
        {
            GridLayer gridLayer = this.FindGridLayer(layerID, true, (string)null);

            gridLayer.UpdateGrid(grid);
            gridLayer.SetMask(mask);
            gridLayer.Show();
        }
Example #13
0
        public void ShowGridLayer(int layerID, GridMap <Color32> grid, string mat_path)
        {
            GridLayer gridLayer = this.FindGridLayer(layerID, true, mat_path);

            gridLayer.UpdateGrid(grid);
            gridLayer.SetMask(true);
            gridLayer.Show();
        }
        private void Grid_OnGridLayer(object sender, GridLayerEventArgs e)
        {
            GridLayer layer = e.Layer;

            WriteLine(String.Format("Layer({0}) Bottom: {1} Left: {2} Top: {3} Right: {4}",
                                    layer.ImageID.ToString(), layer.Bottom, layer.Left, layer.Top, layer.Right));
            //string filename = layer.
            //Client.ExecuteCommand("download " + layer.ImageID.ToString() + " " + AssetType.ImageTGA + " " + filename);
        }
Example #15
0
        public GridPasteSelectionAction(GridLayer gridLayer, Rectangle area, bool[,] bits)
            : base(gridLayer)
        {
            newBits   = bits;
            this.area = area;

            this.area.X = Math.Min(area.X, gridLayer.GridCellsX - area.Width);
            this.area.Y = Math.Min(area.Y, gridLayer.GridCellsY - area.Height);
        }
Example #16
0
 public GridRectangleAction(GridLayer gridLayer, int cellX, int cellY, int width, int height, bool setTo)
     : base(gridLayer)
 {
     CellX  = cellX;
     CellY  = cellY;
     Width  = width;
     Height = height;
     SetTo  = setTo;
 }
Example #17
0
        private void toolStripButton6_Click(object sender, EventArgs e)
        {
            double searchRadius = 1;
            int    power        = 1;

            if (map.LayerControl.SelectedLayer != null &&
                map.LayerControl.SelectedLayer is VectorLayer &&
                map.LayerControl.SelectedLayer.Visible)
            {
                VectorLayer  vectorLayer  = (VectorLayer)map.LayerControl.SelectedLayer;
                GridGeometry gridGeometry = null;
                GridInterpolationModalForm interpolationForm = new GridInterpolationModalForm();

                interpolationForm.InitializeForm(map.LayerControl.VectorLayers, ref vectorLayer, ref gridGeometry, ref searchRadius, ref power);
                if (interpolationForm.DialogResult == DialogResult.OK)
                {
                    GridLayer gridLayer = new GridLayer(gridGeometry, map);
                    foreach (var layer in map.Layers)
                    {
                        if (layer.Name == gridLayer.Name)
                        {
                            gridLayer.Name = Interaction.InputBox("Grid для данного слоя уже существует. Введите уникальное название для нового слоя.", "Название слоя", vectorLayer.Name) + ".grd";
                        }
                        else
                        {
                            gridLayer.Name = vectorLayer.Name + ".grd";
                        }
                    }
                    map.AddLayer(gridLayer);
                    List <GeoPoint> points = new List <GeoPoint>();

                    gridLayer.ColorMin = MinStripButton.BackColor;
                    gridLayer.ColorMax = MaxStripButton.BackColor;

                    points = GetPoints(vectorLayer);

                    if (points.Count == 0)
                    {
                        MessageBox.Show("Количество точек равно 0");
                    }
                    else
                    {
                        selectedLayer = gridLayer;
                        gridLayer.DoInterpolation(points, searchRadius, power);
                        ShowColors();
                    }
                }
                else
                {
                }
                map.Refresh();
            }
            else
            {
                MessageBox.Show("Необходимо выбрать векторный слой !");
            }
        }
Example #18
0
    /// <summary>
    /// Set an instance, this will overwrite any existing contents
    /// </summary>
    /// <param name="layer">Layer.</param>
    /// <typeparam name="T">The 1st type parameter.</typeparam>
    public void Set <T>(GridLayer <T> layer)
    {
        if (this.ContainsKey(typeof(T)))
        {
            this[typeof(T)] = layer;
            return;
        }

        this.Add(typeof(T), layer);
    }
Example #19
0
        public void HideGridLayer(int layerID)
        {
            GridLayer gridLayer = this.FindGridLayer(layerID, false, (string)null);

            if (!Object.op_Inequality((Object)gridLayer, (Object)null))
            {
                return;
            }
            gridLayer.Hide();
        }
Example #20
0
        public GridLayer CreateCellWallLayerSimple()
        {
            GridLayer output = new GridLayer(Width, Height);

            // Calculate the required increment
            Point requiredIncrement = (GetLowestPoint() * new Point(-1, -1)) + new Point(2, 2);

            // Get highest point of the block.
            Point highestPoint = GetHighestPoint() + requiredIncrement;

            // Now we get the size of the blocks.
            Point blockSize = new Point(highestPoint.X / Width, highestPoint.Y / Height);

            // After getting the info, we can process the cells.
            foreach (Cell cell in Cells)
            {
                // Each cell has 4 points. We get all those 4 points.
                Point topLeft     = cell.Location + requiredIncrement;
                Point topRight    = new Point(cell.Location.X, cell.Location.Y + cell.Size.Y) + requiredIncrement;
                Point bottomLeft  = new Point(cell.Location.X + cell.Size.X, cell.Location.Y) + requiredIncrement;
                Point bottomRight = cell.Location + cell.Size + requiredIncrement;

                // Get them into a looping list of points that ends with its first iteration
                List <Point> cellPaths = new List <Point>();
                cellPaths.Add(topLeft);
                cellPaths.Add(topRight);
                cellPaths.Add(bottomRight);
                cellPaths.Add(bottomLeft);
                cellPaths.Add(topLeft);

                // Now iterate through the blocks and match them from A to B
                for (int x = 0, xCoord = 0; x < Width && xCoord <= highestPoint.X; x++, xCoord += blockSize.X)
                {
                    for (int y = 0, yCoord = 0; y < Height && yCoord <= highestPoint.Y; y++, yCoord += blockSize.Y)
                    {
                        // Make a temp cell to check for collision.
                        Cell blockCell = new Cell(blockSize, new Point(xCoord, yCoord));

                        // Iterate through the points to see if any of them matches. If so, assign.
                        for (int iter = 0; iter < cellPaths.Count - 1; iter++)
                        {
                            // Check if it intersects with the temp cell.
                            if (blockCell.LineIntersection(cellPaths[iter], cellPaths[iter + 1]))
                            {
                                // If so, assign them.
                                output[x, y].Type = BlockType.RoomWall;
                                break;
                            }
                        }
                    }
                }
            }

            return(output);
        }
Example #21
0
 private void Add_Click(object sender, EventArgs e)
 {
     OpenFileDialog.Filter = "All formats|*.mif;*.txt;*.grd|Layers (*.mif)|*.mif|Grid files (*.grd)|*.grd|Geopoints file (*.txt)|*.txt";
     if (OpenFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
     {
         if (OpenFileDialog.FileName != null)
         {
             try
             {
                 bool isExistName = true;
                 for (int i = 0; i < map.LayersCount; i++)
                 {
                     if (map.Layers[i].Name == System.IO.Path.GetFileNameWithoutExtension(OpenFileDialog.FileName))
                     {
                         isExistName = false;
                     }
                 }
                 if (isExistName)
                 {
                     if (Path.GetExtension(OpenFileDialog.FileName) == ".mif")
                     {
                         VectorLayer MifLayer = new VectorLayer();
                         map.AddLayer(MifLayer);
                         MifLayer.LoadFromFile(OpenFileDialog.FileName);
                     }
                     if (Path.GetExtension(OpenFileDialog.FileName) == ".txt")
                     {
                         VectorLayer vectorLayer = new VectorLayer();
                         map.AddLayer(vectorLayer);
                         vectorLayer.LoadFromFile(OpenFileDialog.FileName);
                     }
                     if (Path.GetExtension(OpenFileDialog.FileName) == ".grd")
                     {
                         GridLayer gridLayer = new GridLayer(new GridGeometry(), map);
                         map.AddLayer(gridLayer);
                         gridLayer.LoadFromFile(OpenFileDialog.FileName);
                     }
                     map.ZoomToAll();
                     map.Refresh();
                     LayerControl.RefreshList();
                 }
                 else
                 {
                     MessageBox.Show("Слой с таким именем уже существует.");
                 }
                 isExistName = true;
             }
             catch (Exception ex)
             {
                 MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
             }
         }
     }
 }
Example #22
0
		public AbstractTrace(IrrlichtDevice device)
		{
			this.device = device;
			device.Grab();

			cubeMaterial.Type = MaterialType.TransparentVertexAlpha;
			cubeMaterial.Lighting = false;

			for (int i = 0; i < layers.Length; i++)
				layers[i] = new GridLayer();
		}
Example #23
0
    //natural resources updating
    void RechargeGroundWaterByRainfall()
    {
        //Loop over all cells.
        //First, each GW layer will be recharged using

        //float adjaceCellsRechargePercentage = 0.5f;     //The percentage of excess rainfall volume (after substracting cell's recharge) that will recharge adjacent cells.
        //TODO make this as a global, game parameters.

        GridLayer <float> potentialRecharge = new GridLayer <float>((uint)Grid.grid.noOfCells.x, (uint)Grid.grid.noOfCells.y);

        //TODO modify the algorithm bellow to update potentialRecharge (without clampting to cell's recharge values), afterwords, append potentialRecharge cell values to
        //GW volume layer (while clamping for its recharge rate).

        for (uint i = 0; i < Grid.grid.noOfCells.x; i++)
        {
            for (uint j = 0; j < Grid.grid.noOfCells.y; j++)
            {
                float cellRainfall = Grid.grid.rainFallLayer.GetCellValue(i, j);
                if (cellRainfall > 0.001f) //no need to do calculations for cells without rainfall..
                {
                    float capacity = Grid.grid.groundWaterCapacityLayer.GetCellValue(i, j);
                    float recharge = Grid.grid.groundWaterRechargeLayer.GetCellValue(i, j);

                    //Assume that, to convert rainfall depth to a volume, we multiply by 1000.0f (including unit adjustements).
                    float rainfallVolume = 1000.0f * cellRainfall / (float)(24 / dateUpdateRateHours);

                    float maxRechargeVolume  = Mathf.Clamp(rainfallVolume / dateUpdateRateHours, 0.0f, recharge) * dateUpdateRateHours;
                    float usedRechargeVolume = Mathf.Clamp(capacity - Grid.grid.groundWaterVolumeLayer.GetCellValue(i, j), 0.0f, maxRechargeVolume);

                    Grid.grid.groundWaterVolumeLayer.GetCellRef(i, j) += usedRechargeVolume;

                    // //(percentage of) excess rainfall volume will recharge adjacent cells
                    // float excessRainfallVolume = adjaceCellsRechargePercentage * (rainfallVolume - usedRechargeVolume) / 4.0f; //divide by number of adjacent cells.

                    // uint lowerX = (uint)Mathf.Max((int)i - 1, 0);
                    // uint lowerY = (uint)Mathf.Max((int)j - 1, 0);
                    // uint upperX = (uint)Mathf.Min(i + 1, Grid.grid.noOfCells.x - 1);
                    // uint upperY = (uint)Mathf.Min(j + 1, Grid.grid.noOfCells.y - 1);
                    // for (uint k = lowerX; k <= upperX; k++)
                    // {
                    //     for (uint l = lowerY; l <= upperY; l++)
                    //     {
                    //         capacity = Grid.grid.groundWaterCapacityLayer.GetCellValue(k, l);
                    //         recharge = Grid.grid.groundWaterRechargeLayer.GetCellValue(k, l);
                    //         maxRechargeVolume = Mathf.Clamp(excessRainfallVolume / dateUpdateRateHours, 0.0f, recharge) * dateUpdateRateHours;
                    //         usedRechargeVolume = Mathf.Clamp(capacity - Grid.grid.groundWaterVolumeLayer.GetCellValue(k, l), 0.0f, maxRechargeVolume);
                    //         Grid.grid.groundWaterVolumeLayer.GetCellRef(k, l) += usedRechargeVolume;
                    //     }
                    // }
                }
            }
        }
    }
Example #24
0
    void TransportPollution(int timeFrame) //happens on a daily basis (24 hours).
    {
        //We need to copy the existing the pollution layer to avoid having changes we made in the loop bellow affect calculation of the next cells in the same loop.
        //The other way is to calculate to the new layer, then add its values to the original layer at the end.
        GridLayer <float> newPollutionLayer = new GridLayer <float>((uint)Grid.grid.noOfCells.x, (uint)Grid.grid.noOfCells.y);

        Grid.grid.pollutionLayer.CopyToLayer(newPollutionLayer);

        for (uint i = 0; i < Grid.grid.noOfCells.x; i++)
        {
            for (uint j = 0; j < Grid.grid.noOfCells.y; j++)
            {
                float pollution = newPollutionLayer.GetCellValue(i, j);
                if (pollution >= 0.01f)
                {
                    uint  windDir   = Grid.grid.windDirectionLayer.GetCellValue(i, j);
                    float windSpeed = Grid.grid.windSpeedLayer.GetCellValue(i, j);

                    float sinDegree = Mathf.Sin(Mathf.Deg2Rad * windDir);
                    float cosDegree = Mathf.Cos(Mathf.Deg2Rad * windDir);

                    long[,] cells = new long[2, 2];
                    cells[0, 0]   = ((long)i + (cosDegree > 0.001f? Mathf.CeilToInt(cosDegree) : Mathf.FloorToInt(cosDegree)));
                    cells[0, 1]   = j;
                    cells[1, 0]   = i;
                    cells[1, 1]   = ((long)j + (sinDegree > 0.001f? Mathf.CeilToInt(sinDegree) : Mathf.FloorToInt(sinDegree)));

                    float[] cellsShare = new float[2];
                    cellsShare[0] = Mathf.Pow(cosDegree, 2.0f);
                    cellsShare[1] = Mathf.Pow(sinDegree, 2.0f);
                    //print ("Transporting from " + i + "," + j + " to " + cells[0,0] + "," + cells[0,1] + " and " + cells[1,0] + "," + cells[1,1]);

                    float transportPercentage = (Mathf.Pow(pollution, pollutionTransportPowerFactor - 1.0f) / Mathf.Pow(pollutionTransportDenominator, pollutionTransportPowerFactor)) / pollution;
                    transportPercentage = transportPercentage * windSpeed / 30.0f; //assuming max windspeed in game is set to 30.0f.
                    transportPercentage = Mathf.Min(transportPercentage, maxTransportPercent);

                    float transportedVolume = transportPercentage * pollution * timeFrame;

                    Grid.grid.pollutionLayer.GetCellRef(i, j) -= transportedVolume;

                    if (cells[0, 0] > 0 && cells[0, 0] < Grid.grid.noOfCells.x && cells[0, 1] > 0 && cells[0, 1] < Grid.grid.noOfCells.y)
                    {
                        Grid.grid.pollutionLayer.GetCellRef((uint)cells[0, 0], (uint)cells[0, 1]) += cellsShare[0] * transportedVolume;
                    }

                    if (cells[1, 0] > 0 && cells[1, 0] < Grid.grid.noOfCells.x && cells[1, 1] > 0 && cells[1, 1] < Grid.grid.noOfCells.y)
                    {
                        Grid.grid.pollutionLayer.GetCellRef((uint)cells[1, 0], (uint)cells[1, 1]) += cellsShare[1] * transportedVolume;
                    }
                }
            }
        }
    }
Example #25
0
        public GridLayer CreateCellLayer()
        {
            GridLayer output = new GridLayer(Width, Height);

            Point requiredIncrement = (GetLowestPoint() * new Point(-1, -1)) + new Point(2, 2);

            // Get highest point of the block.
            Point highestPoint = GetHighestPoint() + requiredIncrement;

            // Now we get the size of the blocks.
            Point blockSize = new Point(highestPoint.X / Width, highestPoint.Y / Height);

            // After getting the info, we can process the cells.
            foreach (Cell cell in Cells)
            {
                // We need to find the top left and bottom right coordinates for the boxes.
                int xTL = 1, yTL = 1;
                int xBR = 1, yBR = 1;
                for (int x = 0, xCoord = 0; x < Width && xCoord <= highestPoint.X; x++, xCoord += blockSize.X)
                {
                    for (int y = 0, yCoord = 0; y < Height && yCoord <= highestPoint.Y; y++, yCoord += blockSize.Y)
                    {
                        // Make temp cell to check for collision.
                        Cell blockCell = new Cell(blockSize, new Point(xCoord, yCoord));

                        // Check if cell point collides with it.
                        if (blockCell.CheckCollision(cell.Location + requiredIncrement))
                        {
                            xTL = x;
                            yTL = y;
                        }

                        if (blockCell.CheckCollision(cell.Location + cell.Size + requiredIncrement))
                        {
                            xBR = x;
                            yBR = y;
                        }
                    }
                }

                // After finding them, fill them in.
                for (int x = xTL; x < xBR; x++)
                {
                    for (int y = yTL; y < yBR; y++)
                    {
                        output[x, y].Type = BlockType.Room;
                    }
                }
            }

            return(output);
        }
Example #26
0
	void Start () {
        //Dependancy "GridManager"
        gridManagerObject = GameObject.FindGameObjectWithTag("GridManager");
        gridManager = gridManagerObject.GetComponent<GridManager>();
        //Dependancy "GridVariables", "PlayerVariables"
        gridVar = GetComponent<GridVariables>();
        playerVar = GetComponent<PlayerVariables>();
        //Dependancy "GridLayer"
        gridLayer = GetComponent<GridLayer>();

        //Set position of object based on current layer
        transform.position = new Vector3(transform.position.x, gridVar.gridLayer * gridManager.tileSize);
	}
Example #27
0
        public AbstractTrace(IrrlichtDevice device)
        {
            this.device = device;
            device.Grab();

            cubeMaterial.Type     = MaterialType.TransparentVertexAlpha;
            cubeMaterial.Lighting = false;

            for (int i = 0; i < layers.Length; i++)
            {
                layers[i] = new GridLayer();
            }
        }
Example #28
0
 protected override void OnMouseMove(UIMouseEventArgs e)
 {
     if (e.IsDragging)
     {
         GridLayer layer   = _gridViewRenderE.GridLayer;
         GridCell  hitCell = layer.GetGridItemByPosition(e.X, e.Y);
         if (_gridSelectionSession != null)
         {
             _gridSelectionSession.SetLatestHit(hitCell);
         }
     }
     base.OnMouseMove(e);
 }
Example #29
0
        public GridClipboardItem(Rectangle area, GridLayer layer)
            : base()
        {
            Area = area;

            Bits = new bool[Area.Width, Area.Height];
            for (int i = 0; i < Area.Width; i++)
            {
                for (int j = 0; j < Area.Height; j++)
                {
                    Bits[i, j] = layer.Grid[i + Area.X, j + Area.Y];
                }
            }
        }
Example #30
0
        /// <summary>
        /// Вычисляет и заполняет список слоёв
        /// по одной оси координат
        /// </summary>
        /// <param name="gridLayerList"></param>
        /// <param name="numLayers"></param>
        /// <param name="coordinate"></param>
        /// <param name="length"></param>
        private void SetGridLayerList(List <GridLayer> gridLayerList,
                                      uint numLayers,
                                      decimal coordinate,
                                      decimal length)
        {
            decimal step = length / (numLayers - 1);

            for (uint index = 0; index < numLayers; index++)
            {
                GridLayer gridLayer = new GridLayer();
                gridLayer.Index      = index;
                gridLayer.Coordinate = coordinate + index * step;
                gridLayerList.Add(gridLayer);
            }
        }
Example #31
0
    private bool TryGetRandomTemplate(GridLayer layer, out GridObject template)
    {
        var variants = _templates.Where(item => item.Layer == layer);

        foreach (GridObject variant in variants)
        {
            if (variant.Chance > Random.Range(0, 100))
            {
                template = variant;
                return(true);
            }
        }

        template = null;
        return(false);
    }
Example #32
0
    public bool CopyToLayer(GridLayer <T> targetLayer)
    {
        if (GridSize() != targetLayer.GridSize())
        {
            return(false);
        }

        for (uint i = 0; i < grid.GetLength(0); i++)
        {
            for (uint j = 0; j < grid.GetLength(1); j++)
            {
                targetLayer.SetCellValue(i, j, grid[i, j]);
            }
        }

        return(true);
    }
Example #33
0
 public void CopyToLayer(GridLayer layer)
 {
     layer.Copy(m_layer);
     layer.Spacing = m_spacing.SizeF;
 }
Example #34
0
 public void CopyFromLayer(GridLayer layer)
 {
     m_layer.Copy(layer);
     m_spacing.SizeF = m_layer.Spacing;
 }