Esempio n. 1
0
 public RoomSubsection(RoomNode room)
 {
     parentRoom  = room;
     doorWays    = new List <PathNode>();
     connections = new List <SubroomConnection>();
 }
Esempio n. 2
0
        public PathCreatorOld(ref byte[] romReference, byte hall, byte level, ref string[] file, int fileOffset)
        {
            Hall  = hall;
            Level = level;

            path = new List <PathNode>();

            // Get the start of the level header
            int doorTableLocation = LevelIndexLocation + hall * 24 + level * 4;

            // Use level offset index to find door array pointer, and use that pointer
            doorTableLocation = Program.GetPointer(DoorTableLocation + romReference[doorTableLocation] * 4);

            int         romIndex;
            int         index        = 0;
            byte        roomMax      = 0;
            List <byte> roomDoorIsIn = new List <byte>();
            PathType    type         = PathType.Door;

            // Door type, room, (size) Left, right, top, bottom, door to link to, offsetX, offsetY, ???, ???, ???

            // Reading rom for doorways/pipes
            while (romReference[doorTableLocation + index] != 0x00)
            {
                romIndex = doorTableLocation + index;

                if (romReference[romIndex] == 0x01 && romReference[romIndex + 6] == 0x00) // Ignore portal
                {
                    index += 12;
                    continue;
                }

                roomMax = Math.Max(roomMax, romReference[romIndex + 1]); // Get the room count, based on the largest room number
                roomDoorIsIn.Add(romReference[romIndex + 1]);            // Add room index for door for future reference

                switch (romReference[romIndex])
                {
                case 0x01:
                    type = PathType.Door;
                    break;

                case 0x02:
                    byte x = romReference[romIndex + 7], y = romReference[romIndex + 8];     // Get x/y offset to detect type of door

                    if (y == 0 && x != 0)
                    {
                        type = x > 128 ? PathType.HallRight : PathType.HallLeft;
                    }
                    else
                    {
                        type = y > 128 ? PathType.Ceiling : PathType.Pit;
                    }

                    break;

                case 0x03:
                    type = PathType.PipeBottom;
                    break;
                }

                path.Add(new PathNode(romIndex, type, romReference[romIndex + 6] - 1));

                if (path[path.Count - 1].connectedNodeIndex == -1)
                {
                    path[path.Count - 1].blockType = PathBlockType.Impassable;
                }

                index += 12;
            }

            rooms = new RoomNode[roomMax + 1];
            string[]        substring;
            List <PathNode> toRemove = new List <PathNode>();

            for (int i = 0; i <= roomMax; i++) // Foreach room
            {
                RoomNode roomNew = new RoomNode();
                roomNew.subrooms = new List <RoomSubsection>(new RoomSubsection[] { new RoomSubsection(roomNew) });

                List <PathNode> fullnodeList = new List <PathNode>();

                while (file[fileOffset][0] == '-' || file[fileOffset][0] == '/') // Hide commments
                {
                    fileOffset++;
                }

                substring = file[fileOffset++].Split(',');

                index = 0;
                // Take all the doors in the room and add them to their proper place
                for (int j = 0; j < roomDoorIsIn.Count; j++)
                {
                    if (roomDoorIsIn[j] == i)
                    {
                        string[] selections = substring[index++].Split('-');
                        int      subroom    = int.Parse(selections[0]); // Get the subroom door needs to be contained in

                        if (subroom >= 0)                               // Less than zero is ignored (for doors that shouldn't be messed with)
                        {
                            while (subroom >= roomNew.subrooms.Count)   // Make sure that the subroom the door is contained in exists
                            {
                                roomNew.subrooms.Add(new RoomSubsection(roomNew));
                            }

                            roomNew.subrooms[subroom].doorWays.Add(path[j]); // Add door to subroom
                            path[j].subroom = roomNew.subrooms[subroom];

                            //Set path and block types
                            if (selections.Length > 1)
                            {
                                for (int sel = 1; i < selections.Length; sel++)
                                {
                                    switch (selections[sel][0])
                                    {
                                    case 'P':
                                        path[j].pathType = (PathType)int.Parse(selections[sel].Substring(2));
                                        break;

                                    case 'B':
                                        path[j].blockType = (PathBlockType)int.Parse(selections[sel].Substring(2));
                                        break;
                                    }
                                }
                            }
                        }
                        else
                        {
                            toRemove.Add(path[j]); // Add to list of nodes to remove
                        }
                    }
                }

                rooms[i] = roomNew;
            }

            foreach (PathNode node in toRemove) // Remove unwanted doorways
            {
                path.Remove(node);
            }

            //DC915908
            //fileOffset += roomMax + 1;

            List <int> remove = new List <int>();

            while (file[fileOffset] != "")
            {
                if (file[fileOffset][0] != '/' && file[fileOffset][0] != '-')
                {
                    substring = file[fileOffset].Split(',');

                    if (substring[0] == "C")
                    {
                        path[int.Parse(substring[1])].pathType = (PathType)(int.Parse(substring[2]));
                    }
                    else if (substring[0] == "B")
                    {
                        path[int.Parse(substring[1])].blockType = (PathBlockType)(int.Parse(substring[2]));
                    }
                    //else if (substring[0] == "K")
                    //{
                    //    path[int.Parse(substring[1])].Exclude = true;
                    //}
                    //else if (substring[0] == "R")
                    //{
                    //    rooms[int.Parse(substring[1])].Exclude = true;
                    //}
                    else if (substring[0] == "S")
                    {
                        //            [1]                [2] [3]            [4]
                        // Select the room, then the two subrooms, and a connection of the type of the last value
                        rooms[int.Parse(substring[1])].subrooms[int.Parse(substring[2])].connections.Add(new SubroomConnection((PathBlockType)int.Parse(substring[4]), rooms[int.Parse(substring[1])].subrooms[int.Parse(substring[3])]));
                    }
                }
                fileOffset++;
            }

            //if (hall == 1 && level == 0)
            //{
            //    bool stop = false;
            //    for (int i = 0; i < path.Count; i++)
            //    {
            //        if (path[i].Exclude)
            //        {
            //            foreach (RoomNode main in rooms)
            //            {
            //                foreach (RoomSubsection sub in main.subrooms)
            //                {
            //                    sub.doorWays.Remove(path[i]);
            //                }
            //            }
            //        }
            //    }
            //}

            //roomExclusive = new List<RoomNode>(rooms);
            //for (int i = 0; i < rooms.Length; i++)
            //{
            //    if (path[i].Exclude)
            //    {
            //        roomExclusive.Remove(rooms[i]);
            //    }
            //}

            rooms[0].subrooms[0].itemsContained |= ItemFound.Portal;
        }