Esempio n. 1
0
        public int getDirection(MTRandom MT)
        {
            var visited   = true;
            var direction = 0;

            while (visited)
            {
                direction = (int)MT.GetUInt32() & 3;
                visited   = this.directions[direction] != 0;
            }
            this.directions[direction] = 1;

            return(direction);
        }
Esempio n. 2
0
        public int getDirection(MTRandom MT)
        {
            var visited = true;
            var direction = 0;

            while (visited)
            {
                direction = (int)MT.GetUInt32() & 3;
                visited = this.directions[direction] != 0;
            }
            this.directions[direction] = 1;

            return direction;
        }
Esempio n. 3
0
        public bool generateCriticalPath(MTRandom MT, int CritPathMin, int CritPathMax)
        {
            if (this.isCriticalPathGenerated)
                return true;

            if (CritPathMin > CritPathMax)
            {
                var min = CritPathMin;
                CritPathMin = CritPathMax;
                CritPathMax = min;
            }
            this._CritPathMinResult = 0;
            this._CritPathMaxResult = 0;
            this.isCriticalPathGenerated = this._generateCriticalPathRecursive(0, CritPathMin, CritPathMax, -1, MT);
            return this.isCriticalPathGenerated;
        }
Esempio n. 4
0
        public bool generateCriticalPath(MTRandom MT, int CritPathMin, int CritPathMax)
        {
            if (this.isCriticalPathGenerated)
            {
                return(true);
            }

            if (CritPathMin > CritPathMax)
            {
                var min = CritPathMin;
                CritPathMin = CritPathMax;
                CritPathMax = min;
            }
            this._CritPathMinResult      = 0;
            this._CritPathMaxResult      = 0;
            this.isCriticalPathGenerated = this._generateCriticalPathRecursive(0, CritPathMin, CritPathMax, -1, MT);
            return(this.isCriticalPathGenerated);
        }
Esempio n. 5
0
        int _generateSubPath_random_dir(MTRandom MT, int[] directions)
        {
            for (int i = 0; i < 4; i++)
            {
                if (directions[i] == 0)
                {
                    while (true)
                    {
                        int random_dir = (int)(MT.GetUInt32() & 3);
                        if (directions[random_dir] == 0)
                        {
                            directions[random_dir] = 1;
                            return(random_dir);
                        }
                    }
                }
            }

            return(-1);
        }
Esempio n. 6
0
 public DungeonStructure(string dungeon_class, int instance_id, int item_id, string option, int seed, int floorplan)
 {
     DungeonClass s_dungeon_class = DungeonClass.LoadDungeonClass(dungeon_class);
     this.name = s_dungeon_class.Name;
     this.seed = seed;
     this.floorplan = floorplan;
     this.option = option.ToLower();
     // init random generators
     MT_maze = new MTRandom(s_dungeon_class.BaseSeed + item_id + floorplan);
     MT_puzzle = new MTRandom(seed);
     //init floors
     floors = new List<DungeonFloorStructure>();
     DungeonFloorStructure prev = null;
     for (int i = 0; i < s_dungeon_class.Floors.Count; i++)
     {
         bool last_floor = i == s_dungeon_class.Floors.Count - 1;
         DungeonFloorStructure floor = new DungeonFloorStructure(this, s_dungeon_class.GetFloorDesc(i), last_floor, prev);
         prev = floor;
         floors.Add(floor);
     }
 }
Esempio n. 7
0
        public DungeonStructure(string dungeon_class, int instance_id, int item_id, string option, int seed, int floorplan)
        {
            DungeonClass s_dungeon_class = DungeonClass.LoadDungeonClass(dungeon_class);

            this.name      = s_dungeon_class.Name;
            this.seed      = seed;
            this.floorplan = floorplan;
            this.option    = option.ToLower();
            // init random generators
            MT_maze   = new MTRandom(s_dungeon_class.BaseSeed + item_id + floorplan);
            MT_puzzle = new MTRandom(seed);
            //init floors
            floors = new List <DungeonFloorStructure>();
            DungeonFloorStructure prev = null;

            for (int i = 0; i < s_dungeon_class.Floors.Count; i++)
            {
                bool last_floor             = i == s_dungeon_class.Floors.Count - 1;
                DungeonFloorStructure floor = new DungeonFloorStructure(this, s_dungeon_class.GetFloorDesc(i), last_floor, prev);
                prev = floor;
                floors.Add(floor);
            }
        }
Esempio n. 8
0
 public bool generateSubPath(MTRandom MT, int coverageFactor, int branchProbability)
 {
     if (this.isCriticalPathGenerated)
     {
         if (this.isSubPathGenerated)
         {
             return(true);
         }
         else
         {
             if (coverageFactor > 100)
             {
                 coverageFactor = 100;
             }
             if (branchProbability > 100)
             {
                 branchProbability = 100;
             }
             var free_rooms = 0;
             for (int y = 0; y < this.height; ++y)
             {
                 for (var x = 0; x < this.width; ++x)
                 {
                     if (!this.rooms[x][y].isOccupied())
                     {
                         free_rooms += 1;
                     }
                 }
             }
             var coverage  = (int)(free_rooms * coverageFactor / 100);
             var to_vector = new List <Position>();
             if (this.CriticalPath.Count > 0)
             {
                 foreach (var move in this.CriticalPath)
                 {
                     to_vector.Add(move.pos_to);
                 }
                 to_vector.RemoveAt(to_vector.Count - 1);
             }
             to_vector = this._generateSubPath_sub_1(to_vector);
             var temp_vector = new List <Position>();
             if (coverage > 0)
             {
                 for (int i = 0; i < coverage; ++i)
                 {
                     var  vect = to_vector;
                     bool flag = false;
                     if (temp_vector.Count == 0)
                     {
                         if (to_vector.Count == 0)
                         {
                             break;
                         }
                         flag = true;
                     }
                     else
                     {
                         if (to_vector.Count == 0)
                         {
                             flag = false;
                             vect = temp_vector;
                         }
                         else
                         {
                             var rnd = MT.GetUInt32() % 100;
                             flag = branchProbability >= rnd;
                             if (!flag)
                             {
                                 vect = temp_vector;
                             }
                         }
                     }
                     int rand_idx   = (int)(MT.GetUInt32() % (uint)vect.Count());
                     var pos        = vect[rand_idx];
                     var room       = this.getRoom(pos);
                     var directions = new int[] { 0, 0, 0, 0 };
                     var random_dir = -1;
                     var direction  = 0;
                     while (true)
                     {
                         random_dir = this._generateSubPath_random_dir(MT, directions);
                         if (room.GetPassageType(random_dir) == 0)
                         {
                             if (this.isRoomInDirectionFree(pos, random_dir))
                             {
                                 break;
                             }
                         }
                         direction += 1;
                         if (direction >= 4)
                         {
                             break;
                         }
                     }
                     if (direction >= 4)
                     {
                         temp_vector = this._generateSubPath_sub_3(temp_vector, to_vector);
                         to_vector   = this._generateSubPath_sub_1(to_vector);
                         continue;
                     }
                     var biased_pos = pos.GetBiasedPosition(random_dir);
                     var room2      = this.getRoom(biased_pos);
                     room.directions[random_dir] = 2;
                     room2.directions[Direction.GetOppositeDirection(random_dir)] = 1;
                     this.counter += 1;
                     room2.Visited(this.counter);
                     temp_vector.Add(biased_pos);
                     if (!flag)
                     {
                         temp_vector.RemoveAt(rand_idx);
                         to_vector.Add(pos);
                     }
                     temp_vector = this._generateSubPath_sub_3(temp_vector, to_vector);
                     to_vector   = this._generateSubPath_sub_1(to_vector);
                 }
                 this.isSubPathGenerated = true;
                 //Console.WriteLine("sub");
                 //this.print_maze();
                 return(true);
             }
             else
             {
                 return(true);
             }
         }
     }
     else
     {
         return(false);
     }
 }
Esempio n. 9
0
        bool _generateCriticalPathRecursive(int CritPathPos, int CritPathMin, int CritPathMax, int direction, MTRandom MT)
        {
            int[] directions = new int[4];
            _CritPathMaxResult += 1;

            if (_CritPathMaxResult <= 10 * CritPathMax)
            {
                if (CritPathMin <= CritPathPos && CritPathPos <= CritPathMax && this.isRoomInDirectionFree(this.current_pos, this.start_direction))
                {
                    start_pos = current_pos;
                    foreach (maze_move move in CriticalPath)
                    {
                        int temp = move.pos_from.X;
                        move.pos_from.X = move.pos_to.X;
                        move.pos_to.X   = temp;

                        temp            = move.pos_from.Y;
                        move.pos_from.Y = move.pos_to.Y;
                        move.pos_to.Y   = temp;

                        move.direction = Direction.GetOppositeDirection(move.direction);
                    }

                    CriticalPath.Reverse();
                    //print_maze();
                    return(true);
                }
                else
                {
                    CritPathPos += 1;
                    int count = 0;

                    if (CritPathPos <= CritPathMax)
                    {
                        if (direction != -1)
                        {
                            direction = Direction.GetOppositeDirection(direction);
                        }

                        for (int i = 0; i < 4; i++)
                        {
                            if (i == direction)
                            {
                                directions[i] = 0;
                            }
                            else
                            {
                                Position next_pos = current_pos.GetBiasedPosition(i);
                                directions[i] = _sub(next_pos);
                                count        += directions[i];
                            }
                        }
                        while (count > 0)
                        {
                            var rnd  = MT.GetUInt32() % count + 1;
                            int cnt2 = 0;

                            int i_dir = 0;
                            while (i_dir < 4)
                            {
                                cnt2 += directions[i_dir];
                                if (cnt2 >= rnd)
                                {
                                    break;
                                }
                                i_dir++;
                            }
                            count            -= directions[i_dir];
                            directions[i_dir] = 0;
                            //moves_count = len(self.CriticalPath)
                            if (_make_move(i_dir))
                            {
                                if (_generateCriticalPathRecursive(CritPathPos, CritPathMin, CritPathMax, i_dir, MT))
                                {
                                    return(true);
                                }
                                _undo_move();
                            }
                        }
                    }
                }
            }

            return(false);
        }
Esempio n. 10
0
 public bool generateSubPath(MTRandom MT, int coverageFactor, int branchProbability)
 {
     if (this.isCriticalPathGenerated)
     {
         if (this.isSubPathGenerated)
             return true;
         else
         {
             if (coverageFactor > 100)
                 coverageFactor = 100;
             if (branchProbability > 100)
                 branchProbability = 100;
             var free_rooms = 0;
             for (int y = 0; y < this.height; ++y)
             {
                 for (var x = 0; x < this.width; ++x)
                     if (!this.rooms[x][y].isOccupied())
                         free_rooms += 1;
             }
             var coverage = (int)(free_rooms * coverageFactor / 100);
             var to_vector = new List<Position>();
             if (this.CriticalPath.Count > 0)
             {
                 foreach (var move in this.CriticalPath)
                     to_vector.Add(move.pos_to);
                 to_vector.RemoveAt(to_vector.Count - 1);
             }
             to_vector = this._generateSubPath_sub_1(to_vector);
             var temp_vector = new List<Position>();
             if (coverage > 0)
             {
                 for (int i = 0; i < coverage; ++i)
                 {
                     var vect = to_vector;
                     bool flag = false;
                     if (temp_vector.Count == 0)
                     {
                         if (to_vector.Count == 0)
                             break;
                         flag = true;
                     }
                     else
                     {
                         if (to_vector.Count == 0)
                         {
                             flag = false;
                             vect = temp_vector;
                         }
                         else
                         {
                             var rnd = MT.GetUInt32() % 100;
                             flag = branchProbability >= rnd;
                             if (!flag)
                                 vect = temp_vector;
                         }
                     }
                     int rand_idx = (int)(MT.GetUInt32() % (uint)vect.Count());
                     var pos = vect[rand_idx];
                     var room = this.getRoom(pos);
                     var directions = new int[] { 0, 0, 0, 0 };
                     var random_dir = -1;
                     var direction = 0;
                     while (true)
                     {
                         random_dir = this._generateSubPath_random_dir(MT, directions);
                         if (room.GetPassageType(random_dir) == 0)
                         {
                             if (this.isRoomInDirectionFree(pos, random_dir))
                                 break;
                         }
                         direction += 1;
                         if (direction >= 4)
                             break;
                     }
                     if (direction >= 4)
                     {
                         temp_vector = this._generateSubPath_sub_3(temp_vector, to_vector);
                         to_vector = this._generateSubPath_sub_1(to_vector);
                         continue;
                     }
                     var biased_pos = pos.GetBiasedPosition(random_dir);
                     var room2 = this.getRoom(biased_pos);
                     room.directions[random_dir] = 2;
                     room2.directions[Direction.GetOppositeDirection(random_dir)] = 1;
                     this.counter += 1;
                     room2.Visited(this.counter);
                     temp_vector.Add(biased_pos);
                     if (!flag)
                     {
                         temp_vector.RemoveAt(rand_idx);
                         to_vector.Add(pos);
                     }
                     temp_vector = this._generateSubPath_sub_3(temp_vector, to_vector);
                     to_vector = this._generateSubPath_sub_1(to_vector);
                 }
                 this.isSubPathGenerated = true;
                 //Console.WriteLine("sub");
                 //this.print_maze();
                 return true;
             }
             else
                 return true;
         }
     }
     else
         return false;
 }
Esempio n. 11
0
        int _generateSubPath_random_dir(MTRandom MT, int[] directions)
        {
            for (int i = 0; i < 4; i++)
            {
                if (directions[i] == 0)
                {
                    while (true)
                    {
                        int random_dir = (int)(MT.GetUInt32() & 3);
                        if (directions[random_dir] == 0)
                        {
                            directions[random_dir] = 1;
                            return random_dir;
                        }
                    }
                }
            }

            return -1;
        }
Esempio n. 12
0
        bool _generateCriticalPathRecursive(int CritPathPos, int CritPathMin, int CritPathMax, int direction, MTRandom MT)
        {
            int[] directions = new int[4];
            _CritPathMaxResult += 1;

            if (_CritPathMaxResult <= 10 * CritPathMax)
            {
                if (CritPathMin <= CritPathPos && CritPathPos <= CritPathMax && this.isRoomInDirectionFree(this.current_pos, this.start_direction))
                {
                    start_pos = current_pos;
                    foreach (maze_move move in CriticalPath)
                    {
                        int temp = move.pos_from.X;
                        move.pos_from.X = move.pos_to.X;
                        move.pos_to.X = temp;

                        temp = move.pos_from.Y;
                        move.pos_from.Y = move.pos_to.Y;
                        move.pos_to.Y = temp;

                        move.direction = Direction.GetOppositeDirection(move.direction);
                    }

                    CriticalPath.Reverse();
                    //print_maze();
                    return true;
                }
                else
                {
                    CritPathPos += 1;
                    int count = 0;

                    if (CritPathPos <= CritPathMax)
                    {
                        if (direction != -1)
                            direction = Direction.GetOppositeDirection(direction);

                        for (int i = 0; i < 4; i++)
                        {
                            if (i == direction)
                                directions[i] = 0;
                            else
                            {
                                Position next_pos = current_pos.GetBiasedPosition(i);
                                directions[i] = _sub(next_pos);
                                count += directions[i];
                            }
                        }
                        while (count > 0)
                        {
                            var rnd = MT.GetUInt32() % count + 1;
                            int cnt2 = 0;

                            int i_dir = 0;
                            while (i_dir < 4)
                            {
                                cnt2 += directions[i_dir];
                                if (cnt2 >= rnd)
                                    break;
                                i_dir++;
                            }
                            count -= directions[i_dir];
                            directions[i_dir] = 0;
                            //moves_count = len(self.CriticalPath)
                            if (_make_move(i_dir))
                            {
                                if (_generateCriticalPathRecursive(CritPathPos, CritPathMin, CritPathMax, i_dir, MT))
                                    return true;
                                _undo_move();
                            }
                        }
                    }
                }
            }

            return false;
        }
Esempio n. 13
0
        void _set_random_path_position()
        {
            if (prev_floor_structure != null)
            {
                start_direction = Direction.GetOppositeDirection(prev_floor_structure.start_direction);
            }
            else
            {
                start_direction = Direction.Down;
            }
            maze_generator.setStartDir = start_direction;
            MTRandom mt = dungeon_structure.MT_maze;

            if (HasBossRoom)
            {
                if (dungeon_structure.option.Contains("largebossroom=" + '"' + "true"))                  // <option largebossroom="true" />
                {
                    while (true)
                    {
                        pos.X = (int)(mt.GetUInt32() % (width - 2) + 1);
                        pos.Y = (int)(mt.GetUInt32() % (height - 3) + 1);
                        if (maze_generator.isFree(pos))
                        {
                            if (maze_generator.isFree(new Position(pos.X - 1, pos.Y)))
                            {
                                if (maze_generator.isFree(new Position(pos.X + 1, pos.Y)))
                                {
                                    if (maze_generator.isFree(new Position(pos.X, pos.Y + 1)))
                                    {
                                        if (maze_generator.isFree(new Position(pos.X - 1, pos.Y + 1)))
                                        {
                                            if (maze_generator.isFree(new Position(pos.X + 1, pos.Y + 1)))
                                            {
                                                if (maze_generator.isFree(new Position(pos.X, pos.Y + 2)))
                                                {
                                                    if (maze_generator.isFree(new Position(pos.X - 1, pos.Y + 2)))
                                                    {
                                                        if (maze_generator.isFree(new Position(pos.X + 1, pos.Y + 2)))
                                                        {
                                                            break;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    maze_generator.markReservedPosition(new Position(pos.X - 1, pos.Y));
                    maze_generator.markReservedPosition(new Position(pos.X + 1, pos.Y));
                    maze_generator.markReservedPosition(new Position(pos.X, pos.Y + 1));
                    maze_generator.markReservedPosition(new Position(pos.X - 1, pos.Y + 1));
                    maze_generator.markReservedPosition(new Position(pos.X + 1, pos.Y + 1));
                    maze_generator.markReservedPosition(new Position(pos.X, pos.Y + 2));
                    maze_generator.markReservedPosition(new Position(pos.X - 1, pos.Y + 2));
                    maze_generator.markReservedPosition(new Position(pos.X + 1, pos.Y + 2));
                }

                else
                {
                    while (true)
                    {
                        pos.X = (int)(mt.GetUInt32() % (width - 2) + 1);
                        pos.Y = (int)(mt.GetUInt32() % (height - 3) + 1);
                        if (maze_generator.isFree(pos))
                        {
                            if (maze_generator.isFree(new Position(pos.X - 1, pos.Y)))
                            {
                                if (maze_generator.isFree(new Position(pos.X + 1, pos.Y)))
                                {
                                    if (maze_generator.isFree(new Position(pos.X, pos.Y + 1)))
                                    {
                                        if (maze_generator.isFree(new Position(pos.X - 1, pos.Y + 1)))
                                        {
                                            if (maze_generator.isFree(new Position(pos.X + 1, pos.Y + 1)))
                                            {
                                                if (maze_generator.isFree(new Position(pos.X, pos.Y + 2)))
                                                {
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    maze_generator.markReservedPosition(new Position(pos.X - 1, pos.Y));
                    maze_generator.markReservedPosition(new Position(pos.X + 1, pos.Y));
                    maze_generator.markReservedPosition(new Position(pos.X, pos.Y + 1));
                    maze_generator.markReservedPosition(new Position(pos.X - 1, pos.Y + 1));
                    maze_generator.markReservedPosition(new Position(pos.X + 1, pos.Y + 1));
                    maze_generator.markReservedPosition(new Position(pos.X, pos.Y + 2));
                }
            }
            else
            {
                bool free = false;
                while (!free)
                {
                    pos.X = (int)(mt.GetUInt32() % width);
                    pos.Y = (int)(mt.GetUInt32() % height);
                    free  = maze_generator.isFree(pos);
                }
            }
            if (!IsLastFloor && !HasBossRoom)
            {
                RandomDirection rnd_dir = new RandomDirection();
                while (true)
                {
                    int direction = rnd_dir.getDirection(mt);
                    if (_set_traits(pos, direction, 3100))
                    {
                        start_direction = direction;
                        break;
                    }
                    //			# core::ICommonAPI::stdapi_SetNPCDirection();  // Server stuff?
                }
            }
            maze_generator.setPathPosition(pos);
        }