Jump to content

Recommended Posts

Posted

Hello.

 

I'm creating a dungeon dimension. The layout of the dungeon is generated using a simple loop that stops itself after the max amount of rooms has been reached. However, it only ever generates about 4 rooms and then stops itself???

 

Is there a way to generate the layout without it stopping itself whilst still being able to use the seed of the world to generate the layout? Another class perhaps? Maybe chunkprovider isn't the greatest place to do this...

 

Here is a snip of my code:

 

public ChunkProviderDungeon(World worldIn, long seed)
    {
            this.worldObj = worldIn;
            this.rand = new Random(seed);
            this.roomamount = rand.nextInt(25) + 50;
            generateLayout();
    }

    private static void generateLayout() {
        Point start = new Point(1,0);
        pointlist.add(start);
        roomTry(1,0);
    }
    
    private static void roomTry(int x, int z) {
        int connections = rand.nextInt(3);
        for(int i=0; i < connections; i++){
            int direction = rand.nextInt(3);
            if(direction == 0){
                Point point = new Point(x + 1, z);
                if(!pointlist.contains(point)){
                    pointlist.add(point);
                    --roomamount;
                }
                System.out.println(roomamount);
                if(roomamount > 0){
                    roomTry(x + 1, z);
                }
            }else if(direction == 1){
                Point point = new Point(x - 1, z);
                if(!pointlist.contains(point)){
                    pointlist.add(point);
                    --roomamount;
                }
                System.out.println(roomamount);
                if(roomamount > 0){
                    roomTry(x - 1, z);
                }
            }else if(direction == 2){
                Point point = new Point(x, z + 1);
                if(!pointlist.contains(point)){
                    pointlist.add(point);
                    --roomamount;
                }
                System.out.println(roomamount);
                if(roomamount > 0){
                    roomTry(x, z + 1);
                }
            }else if(direction == 3){
                Point point = new Point(x, z - 1);
                if(!pointlist.contains(point)){
                    pointlist.add(point);
                    --roomamount;
                }
                System.out.println(roomamount);
                if(roomamount > 0){
                    roomTry(x, z - 1);
                }
            }else{
                Point point = new Point(x, z - 1);
                if(!pointlist.contains(point)){
                    pointlist.add(point);
                    --roomamount;
                }
                System.out.println(roomamount);
                if(roomamount > 0){
                    roomTry(x, z - 1);
                }
            }
        }
    }

    public static List<Point> getPoints(){
        return pointlist;
        
    }

 

 

The list of points is then used to generate the dungeon.

 

When I run the code I get print outs of 56, 55, 54, 53, 52 and then no more. It just stops itself. Any reason why?

 

Thanks in advance.

Posted

OMG DERP. It was possible for a room to have 0 connections making the entire loop stop. Sometimes I question my intelligence. Can a mod just remove this entire thread ?? Sorry for the pointless post.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.