Esempio n. 1
0
    public void GetAdjacentCellsIds(int cellId)
    {
        MediumCell cell = _mediumCells[cellId];

        GetSideTiles(cell);
        GetTopBotCells(cell);
    }
Esempio n. 2
0
    void TransferContent(int cellId, int dir, float motionAxisValue)
    {
        MediumCell adjacentCell = _mediumCells[_adjacentId[dir]];

        for (int c = 0; c < 5; c++)
        {
            if (c == 4)
            {
                _horzTransfer = motionAxisValue / adjacentCell.Content[c] * HeatTransferRatio;

                _tempCells[cellId].Content[c]           += _horzTransfer;
                _tempCells[_adjacentId[dir]].Content[c] -= _horzTransfer;
            }
            else
            {
                _horzTransfer = (motionAxisValue * ContentTransferRatio) * adjacentCell.Content[c];

                if (_horzTransfer < adjacentCell.Content[c] * 4)
                {
                    _tempCells[cellId].Content[c]           += _horzTransfer;
                    _tempCells[_adjacentId[dir]].Content[c] -= _horzTransfer;
                }
            }
        }
    }
Esempio n. 3
0
    public void Burning()
    {
        Owner.Amount -= 0.5f * Time.deltaTime;

        _cellPosition = new Vector2Int((int)Math.Round(this.transform.position.x), (int)Math.Round(this.transform.position.y));

        MediumCell cell = _airMedium.GetCellByPosition(_cellPosition);

        for (int i = 0; i < IOElements.Length; i++)
        {
            if (i != 2)
            {
                cell.Content[i] += IOElements[i] * Time.deltaTime;
            }
            else // Oxygen
            {
                if (cell.Content[i] > 0)
                {
                    cell.Content[i] -= IOElements[i] * Time.deltaTime;
                }
                else //if no Oxygen Fire dies
                {
                    _burning = false;
                    Destroy(_fire.gameObject);
                }
            }
        }
    }
Esempio n. 4
0
 void InitializeTempCells()
 {
     // Initiate Temp MediumCells
     _tempCells = new MediumCell[_airMedium.Cells.Length];
     for (int i = 0; i < _airMedium.Cells.Length; i++)
     {
         _tempCells[i] = new MediumCell(i, _airMedium.Cells[i].GridPosition);
     }
     ClealCells(0);
 }
Esempio n. 5
0
    void Produce()
    {
        _position = new Vector2Int((int)Math.Round(this.transform.position.x), (int)Math.Round(this.transform.position.y));

        MediumCell cell = _airMedium.GetCellByPosition(_position);

        if (ProducerType.ProduceElements)
        {
            for (int i = 0; i < ElementsOutput.Length; i++)
            {
                cell.Content[i] += ElementsOutput[i] * Time.deltaTime;
            }
        }
    }
Esempio n. 6
0
    void GetTopBotCells(MediumCell cell)
    {
        int cellId = cell.CellId;

        if (cell.GridPosition.y == -_mapSize.y / 2)              // if tile is on the Buttom edge
        {
            _adjacentId[0] = cellId + _mapSize.x;                //Top Cell ID
            _adjacentId[2] = _dummyId;                           // Buttom Cell ID = Dummy Cell
        }
        else if (cell.GridPosition.y == (_mapSize.y / 2) - 1)    // if tile is on the Top edge
        {
            _adjacentId[0] = _dummyId;                           // Top Cell ID = Dummy Cell
            _adjacentId[2] = cellId - _mapSize.x;                // Buttom Cell ID
        }
        else                                                     // else
        {
            _adjacentId[0] = cellId + _mapSize.x;                // Top Cell ID
            _adjacentId[2] = cellId - _mapSize.x;                // Buttom Cell ID
        }
    }
Esempio n. 7
0
    void GetSideTiles(MediumCell cell)
    {
        int cellId = cell.CellId;

        if (cell.GridPosition.x == -_mapSize.x / 2)                 // if tile is on the Left edge
        {
            _adjacentId[1] = cellId + 1;                            // Right Cell ID
            _adjacentId[3] = cellId + _mapSize.x - 1;               // Left Cell ID
        }
        else if (cell.GridPosition.x == (_mapSize.x / 2) - 1)       // if tile is on the Right edge
        {
            _adjacentId[1] = cellId - (_mapSize.x - 1);             // Right Cell ID
            _adjacentId[3] = cellId - 1;                            // Left Cell ID
        }
        else                                                        // else
        {
            _adjacentId[1] = cellId + 1;                            // Right Cell ID
            _adjacentId[3] = cellId - 1;                            // Left Cell ID
        }
    }
Esempio n. 8
0
    void TransferContent(int cellId, int dir, float motionAxisValue)
    {
        MediumCell adjacentCell = MediumCells[AdjacentId[dir]];

        for (int c = 0; c < 5; c++)
        {
            if (c == 4)
            {
                // transfer heat
                HorzTransfer = motionAxisValue / adjacentCell.Content[c] * HeatTransferRatio;

                TempCells[cellId].Content[c]          += HorzTransfer;
                TempCells[AdjacentId[dir]].Content[c] -= HorzTransfer;

                // job return
                var tmpCell = TempCellsReturn[cellId];
                var adjCell = TempCellsReturn[AdjacentId[dir]];

                tmpCell.Content4 = TempCells[cellId].Content[c];
                adjCell.Content4 = TempCells[AdjacentId[dir]].Content[c];

                TempCellsReturn[cellId]          = tmpCell;
                TempCellsReturn[AdjacentId[dir]] = adjCell;
            }
            else
            {
                // transfer content
                HorzTransfer = (motionAxisValue * ContentTransferRatio) * adjacentCell.Content[c];

                if (HorzTransfer < adjacentCell.Content[c] * 4)
                {
                    TempCells[cellId].Content[c]          += HorzTransfer;
                    TempCells[AdjacentId[dir]].Content[c] -= HorzTransfer;

                    // job return
                    var tmpCell = TempCellsReturn[cellId];
                    var adjCell = TempCellsReturn[AdjacentId[dir]];

                    if (c == 0)
                    {
                        tmpCell.Content0 = TempCells[cellId].Content[c];
                        adjCell.Content0 = TempCells[AdjacentId[dir]].Content[c];
                    }
                    else if (c == 1)
                    {
                        tmpCell.Content1 = TempCells[cellId].Content[c];
                        adjCell.Content1 = TempCells[AdjacentId[dir]].Content[c];
                    }
                    else if (c == 2)
                    {
                        tmpCell.Content2 = TempCells[cellId].Content[c];
                        adjCell.Content2 = TempCells[AdjacentId[dir]].Content[c];
                    }
                    else if (c == 3)
                    {
                        tmpCell.Content3 = TempCells[cellId].Content[c];
                        adjCell.Content3 = TempCells[AdjacentId[dir]].Content[c];
                    }

                    TempCellsReturn[cellId]          = tmpCell;
                    TempCellsReturn[AdjacentId[dir]] = adjCell;
                }
            }
        }
    }