Exemple #1
0
        /// <summary>
        /// Returns a list of outdoor cells within visible range of player
        /// </summary>
        public List <ObjCell> GetOutdoorCells(ObjCell cell)
        {
            // get cell x/y global offset
            var lcoord = LandDefs.get_outside_lcoord(cell.ID, PhysicsObj.Position.Frame.Origin.X, PhysicsObj.Position.Frame.Origin.Y).Value;

            // includes the origin cell
            var blockLength = (int)CellRadiusOutside * 2 + 1;
            var cells       = new List <ObjCell>(/*blockLength * blockLength*/);

            var start = new Vector2(lcoord.X - CellRadiusOutside, lcoord.Y - CellRadiusOutside);
            var end   = new Vector2(lcoord.X + CellRadiusOutside, lcoord.Y + CellRadiusOutside);

            for (var cellX = start.X; cellX <= end.X; cellX++)
            {
                for (var cellY = start.Y; cellY <= end.Y; cellY++)
                {
                    var blockCellID = LandDefs.lcoord_to_gid(cellX, cellY);
                    var _cell       = LScape.get_landcell((uint)blockCellID);
                    if (_cell == null)
                    {
                        continue;
                    }
                    cells.Add(_cell);

                    // does this outdoor cell contain a building?
                    // if so, add all of its cells
                    var landCell = _cell as LandCell;
                    if (landCell.has_building())
                    {
                        //Console.WriteLine($"Found building in cell {landCell.ID:X8}");
                        var buildingCells = landCell.Building.get_building_cells();
                        //Console.WriteLine("# cells: " + buildingCells.Count);
                        cells.AddRange(buildingCells);
                    }
                }
            }
            return(cells);
        }