Пример #1
0
        public void build_visible_cells()
        {
            VisibleCells = new Dictionary <uint, EnvCell>();

            foreach (var visibleCellID in VisibleCellIDs)
            {
                var blockCellID = ID & 0xFFFF0000 | visibleCellID;
                if (VisibleCells.ContainsKey(blockCellID))
                {
                    continue;
                }
                var cell = (EnvCell)LScape.get_landcell(blockCellID);
                VisibleCells.Add(visibleCellID, cell);
            }
        }
Пример #2
0
        public static ObjCell GetVisible(uint cellID)
        {
            if (cellID == 0)
            {
                return(null);
            }

            // is this supposed to return a list?

            /*if ((cellID & 0xFFFF) >= 0x100)
             * return EnvCell.get_visible(cellID);
             * else
             *  return LandCell.Get(cellID);*/
            return(LScape.get_landcell(cellID));
        }
Пример #3
0
        /// <summary>
        /// Returns the list of adjacent landblocks
        /// </summary>
        public List <Landblock> get_adjacents()
        {
            if (adjacents != null)
            {
                return(adjacents);
            }

            adjacents = new List <Landblock>();

            // dungeons have no adjacents
            if (IsDungeon)
            {
                return(adjacents);
            }

            var lbx = ID >> 24;
            var lby = ID >> 16 & 0xFF;

            var startX = lbx > 0 ? lbx - 1 : lbx;
            var startY = lby > 0 ? lby - 1 : lby;

            var endX = lbx < 254 ? lbx + 1 : lbx;
            var endY = lby < 254 ? lby + 1 : lby;

            // get adjacents for outdoor landblocks
            for (var curX = startX; curX <= endX; curX++)
            {
                for (var curY = startY; curY <= endY; curY++)
                {
                    // exclude current landblock
                    if (curX == lbx && curY == lby)
                    {
                        continue;
                    }

                    var id        = curX << 24 | curY << 16 | 0xFFFF;
                    var landblock = LScape.get_landblock(id);
                    if (landblock != null)
                    {
                        adjacents.Add(landblock);
                    }
                }
            }
            return(adjacents);
        }
Пример #4
0
        public static void add_cell_block(int min_x, int min_y, int max_x, int max_y, CellArray cellArray)
        {
            for (var i = min_x; i <= max_x; i++)
            {
                for (var j = min_y; j <= max_y; j++)
                {
                    if (i < 0 || j < 0 || i >= LandDefs.LandLength || j >= LandDefs.LandLength)
                    {
                        continue;
                    }

                    var ui = (uint)i;
                    var uj = (uint)j;

                    var cellID = (((uj >> 3) | 32 * (ui & 0xFFFFFFF8)) << 16) | ((uj & 7) + 8 * (ui & 7) + 1);

                    var cell = LScape.get_landcell(cellID);

                    cellArray.add_cell(cellID, cell);
                }
            }
        }
Пример #5
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);
        }
Пример #6
0
        public static ObjCell get_visible(uint cellID)
        {
            var cell = (EnvCell)LScape.get_landcell(cellID);

            return(cell.VisibleCells.Values.First());
        }
Пример #7
0
        public EnvCell GetOtherCell(uint landblockID)
        {
            var blockCellID = landblockID & 0xFFFF0000 | OtherCellId;

            return((EnvCell)LScape.get_landcell(blockCellID));
        }
Пример #8
0
 public new static LandCell Get(uint cellID)
 {
     return((LandCell)LScape.get_landcell(cellID));
 }
Пример #9
0
 static ObjCell()
 {
     ObjMaint  = new ObjectMaint();  // global static?
     Landscape = LScape.GetInstance();
 }
Пример #10
0
        public static void add_all_outside_cells(int numParts, List <PhysicsPart> parts, CellArray cellArray)
        {
            if (cellArray.AddedOutside)
            {
                return;
            }

            cellArray.AddedOutside = true;

            if (numParts == 0)
            {
                return;
            }

            var min_x = 0;
            var min_y = 0;
            var max_x = 0;
            var max_y = 0;

            for (var i = 0; i < numParts; i++)
            {
                var curPart = parts[i];

                var loc = new Position(curPart.Pos);

                var cellID = LandDefs.AdjustToOutside(loc) ? loc.ObjCellID : 0;

                var cell = LScape.get_landcell(cellID);

                if (cell == null)
                {
                    continue;
                }

                var _lcoord = LandDefs.gid_to_lcoord(cellID);

                if (_lcoord == null)
                {
                    continue;
                }

                var lcoord = _lcoord.Value;

                var lx = (int)(((cellID & 0xFFFF) - 1) / 8);
                var ly = (int)(((cellID & 0xFFFF) - 1) % 8);

                for (var j = 0; j < numParts; j++)
                {
                    var otherPart = parts[j];

                    if (otherPart == null)
                    {
                        continue;
                    }

                    // add if missing: otherPart.Always2D, checks degrades.degradeMode != 1

                    var bbox = new BBox();
                    bbox.LocalToGlobal(otherPart.GetBoundingBox(), otherPart.Pos, cell.Pos);

                    var min_cx = (int)Math.Floor(bbox.Min.X / 24.0f);
                    var min_cy = (int)Math.Floor(bbox.Min.Y / 24.0f);

                    var max_cx = (int)Math.Floor(bbox.Max.X / 24.0f);
                    var max_cy = (int)Math.Floor(bbox.Max.Y / 24.0f);

                    min_x = Math.Min(min_cx - lx, min_x);
                    min_y = Math.Min(min_cy - ly, min_y);

                    max_x = Math.Max(max_cx - lx, max_x);
                    max_y = Math.Max(max_cy - ly, max_y);
                }

                add_cell_block(min_x + (int)lcoord.X, min_y + (int)lcoord.Y, max_x + (int)lcoord.X, max_y + (int)lcoord.Y, cellArray);
            }
        }