Terrarium.Game.WorldState.FillCells C# (CSharp) Method

FillCells() public method

Fills in the appropriate grid cells in our CellIndex given the organism state.
public FillCells ( OrganismBase.OrganismState state, int cellX, int cellY, int cellRadius, System.Boolean clear ) : void
state OrganismBase.OrganismState The state of the organism being added.
cellX int The location of the organism in cells.
cellY int The location of the organism in cells.
cellRadius int The radius in cells of the organism.
clear System.Boolean Determines if cells should be cleared or set.
return void
        public void FillCells(OrganismState state, int cellX, int cellY, int cellRadius, Boolean clear)
        {
            Debug.Assert(cellX - cellRadius >= 0 && cellY - cellRadius + 1 >= 0);

            for (var x = cellX - cellRadius; x <= cellX + cellRadius; x++)
            {
                for (var y = cellY - cellRadius; y <= cellY + cellRadius; y++)
                {
                    if (clear)
                    {
                        // Make sure we are only clearing ourselves, the value may be null because clearindex
                        // may have been called
                        if (!(_cellOrganisms[x, y] == null || _cellOrganisms[x, y].ID == state.ID))
                        {
                            Debug.Assert(_cellOrganisms[x, y] == null || _cellOrganisms[x, y].ID == state.ID);
                        }
                        _cellOrganisms[x, y] = null;
                    }
                    else
                    {
                        // Make sure there was no one else here
                        if (!(_cellOrganisms[x, y] == null))
                        {
                            Debug.Assert(_cellOrganisms[x, y] == null);
                        }
                        _cellOrganisms[x, y] = state;
                    }
                }
            }
        }