public void init_static_objs()
        {
            if (SideCellCount != 8)
            {
                return;
            }
            if (StaticObjects.Count > 0)
            {
                adjust_scene_obj_height();
                foreach (var obj in StaticObjects)
                {
                    if (!obj.is_completely_visible())
                    {
                        obj.calc_cross_cells_static();
                    }
                }
            }
            else if (Info != null)
            {
                foreach (var info in Info.Objects)
                {
                    var obj = PhysicsObj.makeObject(info.Id, 0, false);
                    obj.DatObject = true;
                    var position = new Position(ID, new AFrame(info.Frame));
                    var outside  = LandDefs.AdjustToOutside(position);
                    var cell     = get_landcell(position.ObjCellID);
                    if (cell == null)
                    {
                        //Console.WriteLine($"Landblock {ID:X8} - failed to spawn static object {info.Id:X8}");
                        obj.DestroyObject();
                        continue;
                    }
                    obj.add_obj_to_cell(cell, position.Frame);
                    add_static_object(obj);
                }

                if (Info.RestrictionTables != null)
                {
                    foreach (var kvp in Info.RestrictionTables)
                    {
                        var lcoord = LandDefs.gid_to_lcoord(kvp.Key);

                        if (lcoord == null)
                        {
                            continue;
                        }

                        var idx = ((int)lcoord.Value.Y & 7) + ((int)lcoord.Value.X & 7) * SideCellCount;

                        LandCells[idx].RestrictionObj = kvp.Value;
                    }
                }
            }
            if (UseSceneFiles)
            {
                get_land_scenes();
            }
        }
示例#2
0
        /// <summary>s
        /// Gets the landcell from a landblock. If the cell is an indoor cell and hasn't been loaded, it will be loaded.<para />
        /// This function is thread safe
        /// </summary>
        public static ObjCell get_landcell(ulong iBlockCellID)
        {
            /*if ((iBlockCellID | 0xFFFF) == 0x1D9FFFF)
             * {
             *  Console.WriteLine(System.Environment.StackTrace);
             *  var debug = true;
             * }*/

            //Console.WriteLine($"get_landcell({blockCellID:X8}");

            var landblock = get_landblock(iBlockCellID);

            if (landblock == null)
            {
                return(null);
            }

            var     cellID = iBlockCellID & 0xFFFF;
            ObjCell cell   = null;

            // outdoor cells
            if (cellID < 0x100)
            {
                var lcoord = LandDefs.gid_to_lcoord((uint)iBlockCellID, false);
                if (lcoord == null)
                {
                    return(null);
                }
                var landCellIdx = ((int)lcoord.Value.Y % 8) + ((int)lcoord.Value.X % 8) * landblock.SideCellCount;
                landblock.LandCells.TryGetValue(landCellIdx, out cell);
            }
            // indoor cells
            else
            {
                if (landblock.LandCells.TryGetValue((int)cellID, out cell))
                {
                    return(cell);
                }

                lock (landblock.LandCellMutex)
                {
                    if (landblock.LandCells.TryGetValue((int)cellID, out cell))
                    {
                        return(cell);
                    }

                    cell = DBObj.GetEnvCell((uint)iBlockCellID);
                    cell.CurLandblock = landblock;

                    landblock.LandCells.TryAdd((int)cellID, cell);
                    var envCell = (EnvCell)cell;
                    envCell.PostInit();
                }
            }
            return(cell);
        }
示例#3
0
文件: LScape.cs 项目: PyrealMote/ACE
        public LandCell get_landcell(uint cellID)
        {
            var landblock = get_landblock(cellID);

            if (landblock == null)
            {
                return(null);
            }

            var lcoord      = LandDefs.gid_to_lcoord(cellID);
            var landCellIdx = ((int)lcoord.Value.Y % 8) + ((int)lcoord.Value.X % 8) * landblock.SideCellCount;

            return(landblock.LandCells[landCellIdx]);
        }
示例#4
0
        public LandCell get_landcell(uint cellID)
        {
            var lcoord = LandDefs.gid_to_lcoord(cellID).Value;

            var idx = ((int)lcoord.Y & 7) + ((int)lcoord.X & 7) * SideCellCount;

            if (LandCells[idx].ID == cellID)
            {
                return((LandCell)LandCells[idx]);
            }
            else
            {
                return(null);
            }
        }
示例#5
0
        /// <summary>
        /// Gets the landcell from a landblock. If the cell is an indoor cell and hasn't been loaded, it will be loaded.<para />
        /// This function is thread safe
        /// </summary>
        public static ObjCell get_landcell(uint blockCellID)
        {
            //Console.WriteLine($"get_landcell({blockCellID:X8}");

            var landblock = get_landblock(blockCellID);

            if (landblock == null)
            {
                return(null);
            }

            var     cellID = blockCellID & 0xFFFF;
            ObjCell cell   = null;

            // outdoor cells
            if (cellID < 0x100)
            {
                var lcoord = LandDefs.gid_to_lcoord(blockCellID, false);
                if (lcoord == null)
                {
                    return(null);
                }
                var landCellIdx = ((int)lcoord.Value.Y % 8) + ((int)lcoord.Value.X % 8) * landblock.SideCellCount;
                landblock.LandCells.TryGetValue(landCellIdx, out cell);
            }
            // indoor cells
            else
            {
                if (landblock.LandCells.TryGetValue((int)cellID, out cell))
                {
                    return(cell);
                }

                lock (landblock.LandCellMutex)
                {
                    if (landblock.LandCells.TryGetValue((int)cellID, out cell))
                    {
                        return(cell);
                    }

                    cell = DBObj.GetEnvCell(blockCellID);
                    landblock.LandCells.TryAdd((int)cellID, cell);
                    var envCell = (EnvCell)cell;
                    envCell.PostInit();
                }
            }
            return(cell);
        }
示例#6
0
        public static void add_all_outside_cells(Position position, int numSphere, List <Sphere> spheres, CellArray cellArray)
        {
            if (cellArray.AddedOutside)
            {
                return;
            }

            if (numSphere != 0)
            {
                foreach (var sphere in spheres)
                {
                    var cellPoint = position.ObjCellID;
                    var center    = sphere.Center;

                    if (!LandDefs.AdjustToOutside(ref cellPoint, ref center))
                    {
                        break;
                    }

                    var point = new Vector2();
                    point.X = center.X - (float)Math.Floor(center.X / 24.0f) * 24.0f;
                    point.Y = center.Y - (float)Math.Floor(center.Y / 24.0f) * 24.0f;
                    var minRad = sphere.Radius;
                    var maxRad = 24.0f - minRad;

                    var lcoord = LandDefs.gid_to_lcoord(cellPoint);
                    if (lcoord != null)
                    {
                        add_outside_cell(cellArray, lcoord.Value);
                        check_add_cell_boundary(cellArray, point, lcoord.Value, minRad, maxRad);
                    }
                }
            }
            else
            {
                if (!LandDefs.AdjustToOutside(position))
                {
                    return;
                }

                var lcoord = LandDefs.gid_to_lcoord(position.ObjCellID);
                if (lcoord != null)
                {
                    add_outside_cell(cellArray, lcoord.Value);
                }
            }
        }
示例#7
0
        public static ObjCell get_landcell(uint blockCellID)
        {
            var landblock = get_landblock(blockCellID);

            if (landblock == null)
            {
                return(null);
            }

            var     cellID = blockCellID & 0xFFFF;
            ObjCell cell   = null;

            // outdoor cells
            if (cellID < 0x100)
            {
                var lcoord = LandDefs.gid_to_lcoord(blockCellID, false);
                if (lcoord == null)
                {
                    return(null);
                }
                var landCellIdx = ((int)lcoord.Value.Y % 8) + ((int)lcoord.Value.X % 8) * landblock.SideCellCount;
                landblock.LandCells.TryGetValue(landCellIdx, out cell);
            }
            // indoor cells
            else
            {
                landblock.LandCells.TryGetValue((int)cellID, out cell);
                if (cell != null)
                {
                    return(cell);
                }
                cell = (EnvCell)DBObj.Get(new QualifiedDataID(3, blockCellID));
                landblock.LandCells.Add((int)cellID, cell);
                ((EnvCell)cell).build_visible_cells();
            }
            return(cell);
        }
示例#8
0
        public uint get_terrain(uint cellID, Vector3 point)
        {
            var lcoord = LandDefs.gid_to_lcoord(cellID).Value;

            return(Terrain[(int)lcoord.X * 255 * 9 + (int)lcoord.Y]);
        }
示例#9
0
        public static void add_all_outside_cells(int numParts, List <PhysicsPart> parts, CellArray cellArray, uint id)
        {
            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);

                if (!LandDefs.AdjustToOutside(loc))
                {
                    continue;
                }

                var _lcoord = LandDefs.gid_to_lcoord(loc.ObjCellID);

                if (_lcoord == null)
                {
                    continue;
                }

                var lcoord = _lcoord.Value;

                var lx = (int)(((loc.ObjCellID & 0xFFFF) - 1) / 8);
                var ly = (int)(((loc.ObjCellID & 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, loc);

                    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, id);
            }
        }