Пример #1
0
        public static List<SectorTween> Res_Sector_GenTweens(Room room)
        {
            var result = new List<SectorTween>();
            for (var h = 0; h < room.SectorsY - 1; h++)
            {
                for (var w = 0; w < room.SectorsX - 1; w++)
                {
                    var room_tween = new SectorTween();

                    // Init X-plane tween [ | ]

                    var current_heightmap = room.Sectors[w * room.SectorsY + h];
                    var next_heightmap = room.Sectors[w * room.SectorsY + h + 1];
                    byte joinedFloors = 0;
                    byte joinedCeilings = 0;

                    // XY corners coordinates must be calculated from native room sector 
                    room_tween.FloorCorners[0][1] = current_heightmap.FloorCorners[0][1];
                    room_tween.FloorCorners[1][1] = room_tween.FloorCorners[0][1];
                    room_tween.FloorCorners[2][1] = room_tween.FloorCorners[0][1];
                    room_tween.FloorCorners[3][1] = room_tween.FloorCorners[0][1];
                    room_tween.FloorCorners[0][0] = current_heightmap.FloorCorners[0][0];
                    room_tween.FloorCorners[1][0] = room_tween.FloorCorners[0][0];
                    room_tween.FloorCorners[2][0] = current_heightmap.FloorCorners[1][0];
                    room_tween.FloorCorners[3][0] = room_tween.FloorCorners[2][0];
                    room_tween.CeilingCorners[0][1] = current_heightmap.CeilingCorners[0][1];
                    room_tween.CeilingCorners[1][1] = room_tween.CeilingCorners[0][1];
                    room_tween.CeilingCorners[2][1] = room_tween.CeilingCorners[0][1];
                    room_tween.CeilingCorners[3][1] = room_tween.CeilingCorners[0][1];
                    room_tween.CeilingCorners[0][0] = current_heightmap.CeilingCorners[0][0];
                    room_tween.CeilingCorners[1][0] = room_tween.CeilingCorners[0][0];
                    room_tween.CeilingCorners[2][0] = current_heightmap.CeilingCorners[1][0];
                    room_tween.CeilingCorners[3][0] = room_tween.CeilingCorners[2][0];

                    if (w > 0)
                    {
                        if (next_heightmap.FloorPenetrationConfig != TR_PENETRATION_CONFIG.Wall ||
                            current_heightmap.FloorPenetrationConfig != TR_PENETRATION_CONFIG.Wall)
                        {
                            if (Res_Sector_IsWall(next_heightmap, current_heightmap))
                            {
                                room_tween.FloorCorners[0][2] = current_heightmap.FloorCorners[0][2];
                                room_tween.FloorCorners[1][2] = current_heightmap.CeilingCorners[0][2];
                                room_tween.FloorCorners[2][2] = current_heightmap.CeilingCorners[1][2];
                                room_tween.FloorCorners[3][2] = current_heightmap.FloorCorners[1][2];
                                Res_Sector_SetTweenFloorConfig(room_tween);
                                room_tween.CeilingTweenType = SectorTweenType.None;
                                joinedFloors = 1;
                                joinedCeilings = 1;
                            }
                            else if (Res_Sector_IsWall(current_heightmap, next_heightmap))
                            {
                                room_tween.FloorCorners[0][2] = next_heightmap.FloorCorners[3][2];
                                room_tween.FloorCorners[1][2] = next_heightmap.CeilingCorners[3][2];
                                room_tween.FloorCorners[2][2] = next_heightmap.CeilingCorners[2][2];
                                room_tween.FloorCorners[3][2] = next_heightmap.FloorCorners[2][2];
                                Res_Sector_SetTweenFloorConfig(room_tween);
                                room_tween.CeilingTweenType = SectorTweenType.None;
                                joinedFloors = 1;
                                joinedCeilings = 1;
                            }
                            else
                            {
                                /************************** SECTION WITH DROPS CALCULATIONS **********************/
                                if (current_heightmap.PortalToRoom < 0 && next_heightmap.PortalToRoom < 0 ||
                                    current_heightmap.IsTwoSidePortal(next_heightmap))
                                {
                                    current_heightmap = current_heightmap.CheckPortalPointer();
                                    next_heightmap = next_heightmap.CheckPortalPointer();
                                    if (current_heightmap.PortalToRoom < 0 && next_heightmap.PortalToRoom < 0 &&
                                        current_heightmap.FloorPenetrationConfig != TR_PENETRATION_CONFIG.Wall &&
                                        next_heightmap.FloorPenetrationConfig != TR_PENETRATION_CONFIG.Wall)
                                    {
                                        if (current_heightmap.FloorPenetrationConfig == TR_PENETRATION_CONFIG.Solid ||
                                            next_heightmap.FloorPenetrationConfig == TR_PENETRATION_CONFIG.Solid)
                                        {
                                            room_tween.FloorCorners[0][2] = current_heightmap.FloorCorners[0][2];
                                            room_tween.FloorCorners[1][2] = next_heightmap.FloorCorners[3][2];
                                            room_tween.FloorCorners[2][2] = next_heightmap.FloorCorners[2][2];
                                            room_tween.FloorCorners[3][2] = current_heightmap.FloorCorners[1][2];
                                            Res_Sector_SetTweenFloorConfig(room_tween);
                                            joinedFloors = 1;
                                        }
                                        if (current_heightmap.CeilingPenetrationConfig == TR_PENETRATION_CONFIG.Solid ||
                                            next_heightmap.CeilingPenetrationConfig == TR_PENETRATION_CONFIG.Solid)
                                        {
                                            room_tween.CeilingCorners[0][2] = current_heightmap.CeilingCorners[0][2];
                                            room_tween.CeilingCorners[1][2] = next_heightmap.CeilingCorners[3][2];
                                            room_tween.CeilingCorners[2][2] = next_heightmap.CeilingCorners[2][2];
                                            room_tween.CeilingCorners[3][2] = current_heightmap.CeilingCorners[1][2];
                                            Res_Sector_SetTweenCeilingConfig(room_tween);
                                            joinedCeilings = 1;
                                        }
                                    }
                                }
                            }
                        }

                        current_heightmap = room.Sectors[w * room.SectorsY + h];
                        next_heightmap = room.Sectors[w * room.SectorsY + h + 1];
                        if (joinedFloors == 0 && (current_heightmap.PortalToRoom < 0 || next_heightmap.PortalToRoom < 0))
                        {
                            byte valid = 0;
                            if (next_heightmap.PortalToRoom >= 0 && current_heightmap.SectorAbove != null &&
                                current_heightmap.FloorPenetrationConfig == TR_PENETRATION_CONFIG.Solid)
                            {
                                next_heightmap = next_heightmap.CheckPortalPointer();
                                if (next_heightmap.OwnerRoom.ID == current_heightmap.SectorAbove.OwnerRoom.ID)
                                {
                                    valid = 1;
                                }
                                if (valid == 0)
                                {
                                    var rs =
                                        current_heightmap.SectorAbove.OwnerRoom.GetSectorRaw(next_heightmap.Position);
                                    if (rs != null && rs.PortalToRoom == next_heightmap.OwnerRoom.ID)
                                    {
                                        valid = 1;
                                    }
                                }
                            }

                            if (current_heightmap.PortalToRoom >= 0 && next_heightmap.SectorAbove != null &&
                                next_heightmap.FloorPenetrationConfig == TR_PENETRATION_CONFIG.Solid)
                            {
                                current_heightmap = current_heightmap.CheckPortalPointer();
                                if (current_heightmap.OwnerRoom.ID == next_heightmap.SectorAbove.OwnerRoom.ID)
                                {
                                    valid = 1;
                                }
                                if (valid == 0)
                                {
                                    var rs =
                                        next_heightmap.SectorAbove.OwnerRoom.GetSectorRaw(current_heightmap.Position);
                                    if (rs != null && rs.PortalToRoom == current_heightmap.OwnerRoom.ID)
                                    {
                                        valid = 1;
                                    }
                                }
                            }

                            if (valid == 1 && current_heightmap.FloorPenetrationConfig != TR_PENETRATION_CONFIG.Wall &&
                                next_heightmap.FloorPenetrationConfig != TR_PENETRATION_CONFIG.Wall)
                            {
                                room_tween.FloorCorners[0][2] = current_heightmap.FloorCorners[0][2];
                                room_tween.FloorCorners[1][2] = next_heightmap.FloorCorners[3][2];
                                room_tween.FloorCorners[2][2] = next_heightmap.FloorCorners[2][2];
                                room_tween.FloorCorners[3][2] = current_heightmap.FloorCorners[1][2];
                                Res_Sector_SetTweenFloorConfig(room_tween);
                            }
                        }

                        current_heightmap = room.Sectors[w * room.SectorsY + h];
                        next_heightmap = room.Sectors[w * room.SectorsY + h + 1];
                        if (joinedCeilings == 0 &&
                            (current_heightmap.PortalToRoom < 0 || next_heightmap.PortalToRoom < 0))
                        {
                            byte valid = 0;
                            if (next_heightmap.PortalToRoom >= 0 && current_heightmap.SectorBelow != null &&
                                current_heightmap.CeilingPenetrationConfig == TR_PENETRATION_CONFIG.Solid)
                            {
                                next_heightmap = next_heightmap.CheckPortalPointer();
                                if (next_heightmap.OwnerRoom.ID == current_heightmap.SectorBelow.OwnerRoom.ID)
                                {
                                    valid = 1;
                                }
                                if (valid == 0)
                                {
                                    var rs =
                                        current_heightmap.SectorBelow.OwnerRoom.GetSectorRaw(next_heightmap.Position);
                                    if (rs != null && rs.PortalToRoom == next_heightmap.OwnerRoom.ID)
                                    {
                                        valid = 1;
                                    }
                                }
                            }

                            if (current_heightmap.PortalToRoom >= 0 && next_heightmap.SectorBelow != null &&
                                next_heightmap.FloorPenetrationConfig == TR_PENETRATION_CONFIG.Solid)
                            {
                                current_heightmap = current_heightmap.CheckPortalPointer();
                                if (current_heightmap.OwnerRoom.ID == next_heightmap.SectorBelow.OwnerRoom.ID)
                                {
                                    valid = 1;
                                }
                                if (valid == 0)
                                {
                                    var rs =
                                        next_heightmap.SectorBelow.OwnerRoom.GetSectorRaw(current_heightmap.Position);
                                    if (rs != null && rs.PortalToRoom == current_heightmap.OwnerRoom.ID)
                                    {
                                        valid = 1;
                                    }
                                }
                            }

                            if (valid == 1 && current_heightmap.FloorPenetrationConfig != TR_PENETRATION_CONFIG.Wall &&
                                next_heightmap.FloorPenetrationConfig != TR_PENETRATION_CONFIG.Wall)
                            {
                                room_tween.CeilingCorners[0][2] = current_heightmap.CeilingCorners[0][2];
                                room_tween.CeilingCorners[1][2] = next_heightmap.CeilingCorners[3][2];
                                room_tween.CeilingCorners[2][2] = next_heightmap.CeilingCorners[2][2];
                                room_tween.CeilingCorners[3][2] = current_heightmap.CeilingCorners[1][2];
                                Res_Sector_SetTweenCeilingConfig(room_tween);
                            }
                        }
                    }

                    result.Add(room_tween);

                    /*****************************************************************************************************
                     ********************************   CENTRE  OF  THE  ALGORITHM   *************************************
                     *****************************************************************************************************/

                    room_tween = new SectorTween();

                    current_heightmap = room.Sectors[w * room.SectorsY + h];
                    next_heightmap = room.Sectors[(w + 1) * room.SectorsY + h];
                    room_tween.FloorCorners[0][0] = current_heightmap.FloorCorners[1][0];
                    room_tween.FloorCorners[1][0] = room_tween.FloorCorners[0][0];
                    room_tween.FloorCorners[2][0] = room_tween.FloorCorners[0][0];
                    room_tween.FloorCorners[3][0] = room_tween.FloorCorners[0][0];
                    room_tween.FloorCorners[0][1] = current_heightmap.FloorCorners[1][1];
                    room_tween.FloorCorners[1][1] = room_tween.FloorCorners[0][1];
                    room_tween.FloorCorners[2][1] = current_heightmap.FloorCorners[2][1];
                    room_tween.FloorCorners[3][1] = room_tween.FloorCorners[2][1];

                    room_tween.CeilingCorners[0][0] = current_heightmap.CeilingCorners[1][0];
                    room_tween.CeilingCorners[1][0] = room_tween.CeilingCorners[0][0];
                    room_tween.CeilingCorners[2][0] = room_tween.CeilingCorners[0][0];
                    room_tween.CeilingCorners[3][0] = room_tween.CeilingCorners[0][0];
                    room_tween.CeilingCorners[0][1] = current_heightmap.CeilingCorners[1][1];
                    room_tween.CeilingCorners[1][1] = room_tween.CeilingCorners[0][1];
                    room_tween.CeilingCorners[2][1] = current_heightmap.CeilingCorners[2][1];
                    room_tween.CeilingCorners[3][1] = room_tween.CeilingCorners[2][1];

                    joinedFloors = 0;
                    joinedCeilings = 0;

                    if (h > 0)
                    {
                        if (next_heightmap.FloorPenetrationConfig != TR_PENETRATION_CONFIG.Wall ||
                            current_heightmap.FloorPenetrationConfig != TR_PENETRATION_CONFIG.Wall)
                        {
                            // Init Y-plane tween  [ - ]
                            if (Res_Sector_IsWall(next_heightmap, current_heightmap))
                            {
                                room_tween.FloorCorners[0][2] = current_heightmap.FloorCorners[1][2];
                                room_tween.FloorCorners[1][2] = current_heightmap.CeilingCorners[1][2];
                                room_tween.FloorCorners[2][2] = current_heightmap.CeilingCorners[2][2];
                                room_tween.FloorCorners[3][2] = current_heightmap.FloorCorners[2][2];
                                Res_Sector_SetTweenFloorConfig(room_tween);
                                room_tween.CeilingTweenType = SectorTweenType.None;
                                joinedFloors = 1;
                                joinedCeilings = 1;
                            }
                            else if (Res_Sector_IsWall(current_heightmap, next_heightmap))
                            {
                                room_tween.FloorCorners[0][2] = next_heightmap.FloorCorners[0][2];
                                room_tween.FloorCorners[1][2] = next_heightmap.CeilingCorners[0][2];
                                room_tween.FloorCorners[2][2] = next_heightmap.CeilingCorners[3][2];
                                room_tween.FloorCorners[3][2] = next_heightmap.FloorCorners[3][2];
                                Res_Sector_SetTweenFloorConfig(room_tween);
                                room_tween.CeilingTweenType = SectorTweenType.None;
                                joinedFloors = 1;
                                joinedCeilings = 1;
                            }
                            else
                            {
                                /************************** BIG SECTION WITH DROPS CALCULATIONS **********************/
                                if (current_heightmap.PortalToRoom < 0 && next_heightmap.PortalToRoom < 0 ||
                                    current_heightmap.IsTwoSidePortal(next_heightmap))
                                {
                                    current_heightmap = current_heightmap.CheckPortalPointer();
                                    next_heightmap = next_heightmap.CheckPortalPointer();
                                    if (current_heightmap.PortalToRoom < 0 && next_heightmap.PortalToRoom < 0 &&
                                        current_heightmap.FloorPenetrationConfig != TR_PENETRATION_CONFIG.Wall &&
                                        next_heightmap.FloorPenetrationConfig != TR_PENETRATION_CONFIG.Wall)
                                    {
                                        if (current_heightmap.FloorPenetrationConfig == TR_PENETRATION_CONFIG.Solid ||
                                            next_heightmap.FloorPenetrationConfig == TR_PENETRATION_CONFIG.Solid)
                                        {
                                            room_tween.FloorCorners[0][2] = current_heightmap.FloorCorners[1][2];
                                            room_tween.FloorCorners[1][2] = next_heightmap.FloorCorners[0][2];
                                            room_tween.FloorCorners[2][2] = next_heightmap.FloorCorners[3][2];
                                            room_tween.FloorCorners[3][2] = current_heightmap.FloorCorners[2][2];
                                            Res_Sector_SetTweenFloorConfig(room_tween);
                                            joinedFloors = 1;
                                        }
                                        if (current_heightmap.CeilingPenetrationConfig == TR_PENETRATION_CONFIG.Solid ||
                                            next_heightmap.CeilingPenetrationConfig == TR_PENETRATION_CONFIG.Solid)
                                        {
                                            room_tween.CeilingCorners[0][2] = current_heightmap.CeilingCorners[1][2];
                                            room_tween.CeilingCorners[1][2] = next_heightmap.CeilingCorners[0][2];
                                            room_tween.CeilingCorners[2][2] = next_heightmap.CeilingCorners[3][2];
                                            room_tween.CeilingCorners[3][2] = current_heightmap.CeilingCorners[2][2];
                                            Res_Sector_SetTweenCeilingConfig(room_tween);
                                            joinedCeilings = 1;
                                        }
                                    }
                                }
                            }
                        }

                        current_heightmap = room.Sectors[w * room.SectorsY + h];

                        next_heightmap = room.Sectors[(w + 1) * room.SectorsY + h];
                        if (joinedFloors == 0 && (current_heightmap.PortalToRoom < 0 || next_heightmap.PortalToRoom < 0))
                        {
                            byte valid = 0;
                            if (next_heightmap.PortalToRoom >= 0 && current_heightmap.SectorAbove != null &&
                                current_heightmap.FloorPenetrationConfig == TR_PENETRATION_CONFIG.Solid)
                            {
                                next_heightmap = next_heightmap.CheckPortalPointer();
                                if (next_heightmap.OwnerRoom.ID == current_heightmap.SectorAbove.OwnerRoom.ID)
                                {
                                    valid = 1;
                                }
                                if (valid == 0)
                                {
                                    var rs =
                                        current_heightmap.SectorAbove.OwnerRoom.GetSectorRaw(next_heightmap.Position);
                                    if (rs != null && rs.PortalToRoom == next_heightmap.OwnerRoom.ID)
                                    {
                                        valid = 1;
                                    }
                                }
                            }

                            if (current_heightmap.PortalToRoom >= 0 && next_heightmap.SectorAbove != null &&
                                next_heightmap.FloorPenetrationConfig == TR_PENETRATION_CONFIG.Solid)
                            {
                                current_heightmap = current_heightmap.CheckPortalPointer();
                                if (current_heightmap.OwnerRoom.ID == next_heightmap.SectorAbove.OwnerRoom.ID)
                                {
                                    valid = 1;
                                }
                                if (valid == 0)
                                {
                                    var rs =
                                        next_heightmap.SectorAbove.OwnerRoom.GetSectorRaw(current_heightmap.Position);
                                    if (rs != null && rs.PortalToRoom == current_heightmap.OwnerRoom.ID)
                                    {
                                        valid = 1;
                                    }
                                }
                            }

                            if (valid == 1 && current_heightmap.FloorPenetrationConfig != TR_PENETRATION_CONFIG.Wall &&
                                next_heightmap.FloorPenetrationConfig != TR_PENETRATION_CONFIG.Wall)
                            {
                                room_tween.FloorCorners[0][2] = current_heightmap.FloorCorners[1][2];
                                room_tween.FloorCorners[1][2] = next_heightmap.FloorCorners[0][2];
                                room_tween.FloorCorners[2][2] = next_heightmap.FloorCorners[3][2];
                                room_tween.FloorCorners[3][2] = current_heightmap.FloorCorners[2][2];
                                Res_Sector_SetTweenFloorConfig(room_tween);
                            }
                        }

                        current_heightmap = room.Sectors[w * room.SectorsY + h];

                        next_heightmap = room.Sectors[(w + 1) * room.SectorsY + h];
                        if (joinedCeilings == 0 &&
                            (current_heightmap.PortalToRoom < 0 || next_heightmap.PortalToRoom < 0))
                        {
                            byte valid = 0;
                            if (next_heightmap.PortalToRoom >= 0 && current_heightmap.SectorBelow != null &&
                                current_heightmap.CeilingPenetrationConfig == TR_PENETRATION_CONFIG.Solid)
                            {
                                next_heightmap = next_heightmap.CheckPortalPointer();
                                if (next_heightmap.OwnerRoom.ID == current_heightmap.SectorBelow.OwnerRoom.ID)
                                {
                                    valid = 1;
                                }
                                if (valid == 0)
                                {
                                    var rs =
                                        current_heightmap.SectorBelow.OwnerRoom.GetSectorRaw(next_heightmap.Position);
                                    if (rs != null && rs.PortalToRoom == next_heightmap.OwnerRoom.ID)
                                    {
                                        valid = 1;
                                    }
                                }
                            }

                            if (current_heightmap.PortalToRoom >= 0 && next_heightmap.SectorBelow != null &&
                                next_heightmap.FloorPenetrationConfig == TR_PENETRATION_CONFIG.Solid)
                            {
                                current_heightmap = current_heightmap.CheckPortalPointer();
                                if (current_heightmap.OwnerRoom.ID == next_heightmap.SectorBelow.OwnerRoom.ID)
                                {
                                    valid = 1;
                                }
                                if (valid == 0)
                                {
                                    var rs =
                                        next_heightmap.SectorBelow.OwnerRoom.GetSectorRaw(current_heightmap.Position);
                                    if (rs != null && rs.PortalToRoom == current_heightmap.OwnerRoom.ID)
                                    {
                                        valid = 1;
                                    }
                                }
                            }

                            if (valid == 1 && current_heightmap.FloorPenetrationConfig != TR_PENETRATION_CONFIG.Wall &&
                                next_heightmap.FloorPenetrationConfig != TR_PENETRATION_CONFIG.Wall)
                            {
                                room_tween.CeilingCorners[0][2] = current_heightmap.CeilingCorners[1][2];
                                room_tween.CeilingCorners[1][2] = next_heightmap.CeilingCorners[0][2];
                                room_tween.CeilingCorners[2][2] = next_heightmap.CeilingCorners[3][2];
                                room_tween.CeilingCorners[3][2] = current_heightmap.CeilingCorners[2][2];
                                Res_Sector_SetTweenCeilingConfig(room_tween);
                            }
                        }
                    }

                    result.Add(room_tween);
                }
            }
            return result;
        }
Пример #2
0
        public static void Res_Sector_SetTweenCeilingConfig(SectorTween tween)
        {
            if (tween.CeilingCorners[0][2] > tween.CeilingCorners[1][2])
            {
                var temp = tween.CeilingCorners[0][2];
                tween.CeilingCorners[0][2] = tween.CeilingCorners[1][2];
                tween.CeilingCorners[1][2] = temp;

                temp = tween.CeilingCorners[2][2];
                tween.CeilingCorners[2][2] = tween.CeilingCorners[3][2];
                tween.CeilingCorners[3][2] = temp;
            }

            if (tween.CeilingCorners[3][2] > tween.CeilingCorners[2][2])
            {
                tween.CeilingTweenType = SectorTweenType.TwoTriangles;
            }
            else if ((tween.CeilingCorners[0][2] != tween.CeilingCorners[1][2]) &&
                     (tween.CeilingCorners[2][2] != tween.CeilingCorners[3][2]))
            {
                tween.CeilingTweenType = SectorTweenType.Quad;
            }
            else if (tween.CeilingCorners[0][2] != tween.CeilingCorners[1][2])
            {
                tween.CeilingTweenType = SectorTweenType.TriangleLeft;
            }
            else if (tween.CeilingCorners[2][2] != tween.CeilingCorners[3][2])
            {
                tween.CeilingTweenType = SectorTweenType.TriangleRight;
            }
            else
            {
                tween.CeilingTweenType = SectorTweenType.None;
            }
        }