Exemple #1
0
        public Landblock(CellLandblock landblock)
            : base(landblock)
        {
            Init();

            ID = landblock.Id;
            BlockInfoExists = landblock.HasObjects;
            if (BlockInfoExists)
            {
                Info = (LandblockInfo)DBObj.Get(new QualifiedDataID(2, ID - 1));
            }
            BlockCoord = LandDefs.blockid_to_lcoord(landblock.Id).Value;
            _landblock = landblock;
            get_land_limits();
        }
        public void GetCellRotation(uint landblockID, uint x, uint y, ref bool singleTextureCell, ref uint surfNum, ref LandDefs.Rotation rotation)
        {
            var lcoord = LandDefs.blockid_to_lcoord(landblockID);

            var globalCellX = (int)(lcoord.Value.X + x);
            var globalCellY = (int)(lcoord.Value.Y + y);

            // no palette shift

            // SW / SE / NE / NW
            var i        = (int)(LandDefs.VertexDim * x + y);
            var terrain  = Terrain[i];
            var t1       = (terrain & 0x7F) >> 2;
            var r1       = terrain & 3;
            var j        = (int)(LandDefs.VertexDim * (x + 1) + y);
            var terrain2 = Terrain[j];
            var t2       = (terrain2 & 0x7F) >> 2;
            var r2       = terrain2 & 3;
            var terrain3 = Terrain[j + 1];
            var t3       = (terrain3 & 0x7F) >> 2;
            var r3       = terrain3 & 3;
            var terrain4 = Terrain[i + 1];
            var t4       = (terrain4 & 0x7F) >> 2;
            var r4       = terrain4 & 3;

            /*Console.WriteLine($"LandblockStruct.GetCellRotation({landblockID:X8}, x:{x}, y:{y})");
             * Console.WriteLine($"I1: {i}, I2: {j}, I3: {j+1}, I4: {i+1}");
             * if (r1 != 0 || r2 != 0 || r3 != 0 || r4 != 0)
             *  Console.WriteLine($"R1: {r1}, R2: {r2}, R3: {r3}, R4: {r4}");
             * Console.WriteLine($"T1: {(LandDefs.TerrainType)t1}, T2: {(LandDefs.TerrainType)t2}, T3: {(LandDefs.TerrainType)t3}, T4: {(LandDefs.TerrainType)t4}");*/

            var palCodes = new List <uint>();

            palCodes.Add(GetPalCode(r1, r2, r3, r4, t1, t2, t3, t4));   // 0
            //palCodes.Add(GetPalCode(r2, r3, r4, r1, t2, t3, t4, t1));   // 270
            //palCodes.Add(GetPalCode(r3, r4, r1, r2, t3, t4, t1, t2));   // 180
            //palCodes.Add(GetPalCode(r4, r1, r2, r3, t4, t1, t2, t3));   // 90

            var singleRoadCell = r1 == r2 && r1 == r3 && r1 == r4;
            var singleTypeCell = t1 == t2 && t1 == t3 && t1 == t4;

            singleTextureCell = r1 != 0 ? singleRoadCell : singleRoadCell && singleTypeCell;

            var regionDesc  = DatManager.PortalDat.RegionDesc;
            var minimizePal = true;

            LandSurf.Instance.SelectTerrain(globalCellX, globalCellY, ref surfNum, ref rotation, palCodes, 1, minimizePal);
        }
Exemple #3
0
        public Landblock(CellLandblock landblock)
            : base(landblock)
        {
            Init();

            ID = landblock.Id;
            //Console.WriteLine("Loading landblock " + ID.ToString("X8"));
            BlockInfoExists = landblock.HasObjects;
            if (BlockInfoExists)
            {
                Info = DBObj.GetLandblockInfo(ID - 1);
            }
            BlockCoord = LandDefs.blockid_to_lcoord(landblock.Id).Value;
            _landblock = landblock;
            get_land_limits();
        }
        public void ConstructPolygons(uint landblockID)
        {
            var lcoord = LandDefs.blockid_to_lcoord(landblockID).Value;

            var polyNum   = 1;
            var seedA     = (uint)((int)lcoord.X * LandDefs.VertexPerCell * 214614067);
            var seedB     = (uint)((int)lcoord.X * LandDefs.VertexPerCell * 1109124029);
            var vertexCnt = 0;

            for (var x = 0; x < SideCellCount; x++)
            {
                var lcoordX      = lcoord.X + x;
                var originY      = 1;
                var colVertexCnt = 0;
                var originX      = polyNum;

                for (var y = 0; y < SideCellCount; y++)
                {
                    var lcoordY = (int)lcoord.Y + y;
                    var magicB  = seedB;
                    var magicA  = seedA + 1813693831;

                    for (var i = 0; i < LandDefs.VertexPerCell; i++)
                    {
                        var idxI = vertexCnt + i;
                        var idxJ = colVertexCnt;

                        for (var j = 0; j < LandDefs.VertexPerCell; j++)
                        {
                            var splitDir = (uint)(((int)lcoord.Y * LandDefs.VertexPerCell + idxJ) * magicA - magicB - 1369149221);
                            var polyIdx  = (LandDefs.VertexPerCell * i + j) * 2;

                            var cellIdx     = x * SideCellCount + y;
                            var vertIdx     = idxI * SideVertexCount + idxJ;
                            var firstVertex = (idxI * SidePolyCount + idxJ) * 2;
                            var nextVertIdx = (idxI + 1) * SideVertexCount + idxJ;

                            var lcell = (LandCell)LandCells[cellIdx];

                            if (splitDir * 2.3283064e-10 < 0.5f)
                            {
                                //  2    1---0
                                //  | \   \  |
                                //  |  \   \ |
                                //  0---1    2

                                SWtoNEcut[cellIdx] = false;

                                lcell.Polygons[polyIdx]     = AddPolygon(firstVertex, vertIdx, nextVertIdx, vertIdx + 1);
                                lcell.Polygons[polyIdx + 1] = AddPolygon(firstVertex + 1, nextVertIdx + 1, vertIdx + 1, nextVertIdx);
                            }
                            else
                            {
                                //     2   2---1
                                //    / |  |  /
                                //   /  |  | /
                                //  0---1  0

                                SWtoNEcut[cellIdx] = true;

                                lcell.Polygons[polyIdx]     = AddPolygon(firstVertex, vertIdx, nextVertIdx, nextVertIdx + 1);
                                lcell.Polygons[polyIdx + 1] = AddPolygon(firstVertex + 1, vertIdx, nextVertIdx + 1, vertIdx + 1);
                            }
                            idxJ++;
                        }
                        magicA += 214614067;
                        magicB += 1109124029;
                    }

                    var cellID   = (uint)LandDefs.lcoord_to_gid(lcoordX, lcoordY);
                    var landCell = LandCells[x * SideCellCount + y];
                    landCell.ID                 = cellID;
                    landCell.Pos.ObjCellID      = cellID;
                    landCell.Pos.Frame.Origin.X = originX * LandDefs.HalfSquareLength;
                    landCell.Pos.Frame.Origin.Y = originY * LandDefs.HalfSquareLength;

                    originY      += 2;
                    colVertexCnt += LandDefs.VertexPerCell;
                }
                vertexCnt += LandDefs.VertexPerCell;
                seedB     += 1109124029 * (uint)LandDefs.VertexPerCell;
                seedA     += 214614067 * (uint)LandDefs.VertexPerCell;
                polyNum   += 2;
            }
        }