Ejemplo n.º 1
0
        /// <summary>
        /// Find all doors
        /// </summary>
        private void AnalyseDoors()
        {
            // List of 3x3 map, of which the middle cell is a door if all other positions match
            Hint basicHorz = new Hint("Basic Door Horz", HintsRule.Convert(new string[] {"?F?", "WFW", "?F?"}));
            Hint basicVert = new Hint("Basic Door Vert", HintsRule.Convert(new string[] {"?W?", "FFF", "?W?"}));

            Hint diag1 = new Hint("Diag Door 1", HintsRule.Convert(new string[] { "?FW", "?F?", "WF?" }));
            Hint diag2 = new Hint("Diag Door 2", GeneralHelper.Rotate(diag1.HintArray));
            Hint diag3 = new Hint("Diag Door 3", GeneralHelper.Rotate(diag2.HintArray));
            Hint diag4 = new Hint("Diag Door 4", GeneralHelper.Rotate(diag3.HintArray));

            Hint half1 = new Hint("Half Door 1", HintsRule.Convert(new string[] {"?FW", "WF?", "?F?"}));
            Hint half2 = new Hint("Half Door 2", GeneralHelper.Rotate(half1.HintArray));
            Hint half3 = new Hint("Half Door 3", GeneralHelper.Rotate(half2.HintArray));
            Hint half4 = new Hint("Half Door 4", GeneralHelper.Rotate(half3.HintArray));

            List<Hint> doorHints = new List<Hint>();
            doorHints.Add(basicVert);
            doorHints.Add(basicHorz);
            doorHints.Add(diag1);
            doorHints.Add(diag2);
            doorHints.Add(diag3);
            doorHints.Add(diag4);
            doorHints.Add(half1);
            doorHints.Add(half2);
            doorHints.Add(half3);
            doorHints.Add(half4);

            // Find Matches
            foreach (Hint hint in doorHints)
            {
                hint.PreProcess(controller.StaticAnalysis);
            }

            // Process matches
            int doorIDCounter = 0;
            foreach (Hint hint in doorHints)
            {
                if (hint.HasPreProcessedMatches)
                {
                    foreach (VectorInt checkLocation in hint.CheckLocations)
                    {
                        if (FindDoor(checkLocation) == null)
                        {
                            // Add new door
                            Door newDoor = new Door();
                            newDoor.Position = checkLocation.Add(1, 1); // Center of the hint is the door
                            doorBitmap[newDoor.Position] = true;
                            newDoor.DoorID = "D" + doorIDCounter.ToString();
                            newDoor.SourceHint = hint;

                            doorIDCounter++;

                            if (hint == basicHorz) newDoor.Type = Door.Types.Basic;
                            else if (hint == basicVert) newDoor.Type = Door.Types.Basic;
                            else if (hint == half1) newDoor.Type = Door.Types.Offset;
                            else if (hint == half2) newDoor.Type = Door.Types.Offset;
                            else if (hint == half3) newDoor.Type = Door.Types.Offset;
                            else if (hint == half4) newDoor.Type = Door.Types.Offset;
                            else if (hint == diag1) newDoor.Type = Door.Types.Diagonal;
                            else if (hint == diag2) newDoor.Type = Door.Types.Diagonal;
                            else if (hint == diag3) newDoor.Type = Door.Types.Diagonal;
                            else if (hint == diag4) newDoor.Type = Door.Types.Diagonal;

                            // Find door sides
                            VectorInt exit = newDoor.Position.Offset(Direction.Up);
                            if (controller.StaticAnalysis.FloorMap[exit]) newDoor.Exits.Add(exit);
                            exit = newDoor.Position.Offset(Direction.Down);
                            if (controller.StaticAnalysis.FloorMap[exit]) newDoor.Exits.Add(exit);
                            exit = newDoor.Position.Offset(Direction.Left);
                            if (controller.StaticAnalysis.FloorMap[exit]) newDoor.Exits.Add(exit);
                            exit = newDoor.Position.Offset(Direction.Right);
                            if (controller.StaticAnalysis.FloorMap[exit]) newDoor.Exits.Add(exit);

                            controller.DebugReport.Append("Found door {0} of type {1} at {2}, with exits at {3} exits", newDoor.DoorID, newDoor.Type, newDoor.Position, StringHelper.Join<VectorInt>(newDoor.Exits, null, ", "));

                            doors.Add(newDoor);
                        }
                    }
                }
            }

            controller.DebugReport.AppendHeading(2, "Final Door Map:");
            controller.DebugReport.Append(doorBitmap.ToString());
            controller.DebugReport.CompleteSection();
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Get the direction used to enter the room from a door
 /// </summary>
 /// <param name="door"></param>
 /// <returns></returns>
 public Direction GetRoomDirection(Door door)
 {
     foreach (VectorInt exit in door.Exits)
     {
         if (this[exit])
         {
             return VectorInt.GetDirection(door.Position, exit);
         }
     }
     throw new InvalidOperationException();
 }