Pixelcraft world generator problem

Non-platform specific questions.

Pixelcraft world generator problem

Postby tzoli » Sun Dec 02, 2012 9:08 pm

Hi.
I have a serious problem and I hope that you can help me. The next version of Pixelcraft could have infinite "worlds" to left and right. The problem is with my generator code. It generates well except trees. There is only one block but there should be more.
Sometimes it doesn't even try to generate a full tree(It doesn't generate anything at all but if it would that would miss some parts. :S
Ok, enough of the boring text. These are the codes that I use for generating trees:
Block->Draw Actor
Code: Select all
if(oldwo != xwo && lefut==0){
 
 
    sprintf(tmpe,"world%i",xwo);

fajl =fopen(tmpe, "r");
 if(fajl != NULL) // file exists
{

 loadVars(tmpe, "save");
 
 

}else{

ogen();
treegen(cloneindex);
genbb();
    if(cloneindex < 104){
 if(fagen[cloneindex]==1){
typek[cloneindex]=17;
        }else if(fagen[cloneindex]==2){
       typek[cloneindex]=24;
                        }

                       }

}
 
  type=typek[cloneindex];
  setelet();
  lefut=1;
CreateTimer("Event Actor", "300", 300);
                }

fagen - stores the data for tree generating(1-log 2-leaves)
setelet() - sets the lifepoints for the block
typek - the saveable data of the blocks
type - the block data that is used by the "game engine"
ogen() - cleans the block datas
treegen() - tree generator code
genbb() - terrain generator code

treegen():
Code: Select all
void treegen(int cli){
    int tempo;
int temoo;

fagen[cli]=0;

      if(cli < 104){
 
                          if(cli > 77){
 
      temoo=rand(10);
      if(temoo==2){

 fagen[cli]=1;


tempo=cli-26;
  fagen[tempo]=1;
tempo=cli-52;
  fagen[tempo]=1;
 tempo=cli-78;
  fagen[tempo]=2;

tempo=cli-27;
  fagen[tempo]=2;
tempo=cli-25;
  fagen[tempo]=2;
tempo=cli-53;
  fagen[tempo]=2;
tempo=cli-51;
  fagen[tempo]=2;

                  }
 
                      }
                         }
              }

It only generates a log-block from the tree and in new "worlds" it doesn't even store the fagen data to generate a tree. :( :?

I hope it's not too confusing. If you have any clue why isn' this working please tell me.
Creepers are capable of climbing ladders, despite lacking arms. (Minecraft wiki)
User avatar
tzoli
 
Posts: 343
Joined: Sat Jun 12, 2010 6:54 pm
Location: Behind you
Score: 15 Give a positive score

Re: Pixelcraft world generator problem

Postby skydereign » Sun Dec 02, 2012 9:36 pm

It would be easier if you posted the ged and data.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Pixelcraft world generator problem

Postby tzoli » Sun Dec 02, 2012 10:00 pm

Well... I don't think so ,but ok.
Here is the link(If you want to reset the world just delete the world* files):
https://dl.dropbox.com/u/87739508/pixelcraft.rar
Creepers are capable of climbing ladders, despite lacking arms. (Minecraft wiki)
User avatar
tzoli
 
Posts: 343
Joined: Sat Jun 12, 2010 6:54 pm
Location: Behind you
Score: 15 Give a positive score

Re: Pixelcraft world generator problem

Postby tzoli » Tue Dec 04, 2012 12:49 pm

Just as I suspected... No one can read anything from my code :)
Anyways, I will try harder to find the problem.
Creepers are capable of climbing ladders, despite lacking arms. (Minecraft wiki)
User avatar
tzoli
 
Posts: 343
Joined: Sat Jun 12, 2010 6:54 pm
Location: Behind you
Score: 15 Give a positive score

Re: Pixelcraft world generator problem

Postby skydereign » Tue Dec 04, 2012 9:12 pm

Well I'll give you that your code is messy (especially due to your odd spacing). But I've only had a couple of minutes to look at it (and it has been only two days). Having the actual game allows me to remove unnecessary parts, and see what is actually working. If the code you posted was the only problem in your code, than you yourself should have no problem finding what is wrong. Anyway, I'll be actually looking at it today.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Pixelcraft world generator problem

Postby tzoli » Tue Dec 04, 2012 9:37 pm

Even I can't find the problem :?
It just basically doesn't want to genrate/doesn't generate any trees(both of it can happen).
Creepers are capable of climbing ladders, despite lacking arms. (Minecraft wiki)
User avatar
tzoli
 
Posts: 343
Joined: Sat Jun 12, 2010 6:54 pm
Location: Behind you
Score: 15 Give a positive score

Re: Pixelcraft world generator problem

Postby skydereign » Wed Dec 05, 2012 3:10 am

There are several problems in your code that make it very hard to fix. The main problem is that the treegen function is only called once (instead of once per tile). This is because you put the function call within the load new level part of the tile's draw actor. On top of that, it only happens when the load file doesn't exist.
Code: Select all
if(oldwo != xwo && lefut==0)
 {
   sprintf(tmpe,"world%i",xwo);

   fajl =fopen(tmpe, "r");
   if(fajl != NULL) // file exists
   {
     loadVars(tmpe, "save");
   }
   else
   { // only run when changing levels and the new file doesn't exist
     ogen();
     treegen(cloneindex);
     genbb();
     if(cloneindex < 104) // you have a lot of these
     { // this limits trees to only certain tile spots
       if(fagen[cloneindex]==1)
       {
    typek[cloneindex]=17;
       }
       else if(fagen[cloneindex]==2)
       {
    typek[cloneindex]=24;
       }
     }
   }

   type=typek[cloneindex];
   setelet();
   lefut=1;
   CreateTimer("Event Actor", "300", 300);
 }

Also in the above code it shows your use of cloneindex to limit where trees can be. You have this code in several locations, which can also get in the way of fixing the overall problem. Now in your treegen function itself you only generate the trees if rand(10) returns a 2. That means a 1/10 chance when the actual function runs, will it setup fagen.

Now if you were to make it so treegen was called for every possible tile, you still run into the problem of treegen resetting fagen for that tile to 0. This is not what you want, as it will prevent the would be extra tree parts from appearing (since fagen for that tile is gone). If you are banking on the tiles to run through their code by cloneindex, than that would work, as trees are set later.

Your game would benefit from some not so minor cleaning up. If nothing else move the loading code outside of the tile actors. You should use a single way of loading a level, so all you need to do is call a single function to do it. Putting it in the tiles means that every single tile runs that code, even if when the time comes, only one tile actually does the load.

There were probably several other things I had to change to get it to work. You have a lot of redundant code, that only serves to make it harder to fix things. The code I saw the most was the if(fagen[cloneindex]==1) block, which was in upwards of four places. Anyway, here is the chopped up version I was using to finally get the tree to grow.
Attachments
pclean.ged
I removed a lot of stuff in this ged. It isn't meant to be swapped out with your current version, as you'll see, a lot of the tile code is missing (and possibly other things).
(756.46 KiB) Downloaded 122 times
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Pixelcraft world generator problem

Postby tzoli » Wed Dec 05, 2012 12:53 pm

Thanks. I will check the the cleanrelines. By the way: Nowit generates treesbut no terrain(I knowthat's not the main thing) :lol:
Really thanks for help :D The + goes :D
Creepers are capable of climbing ladders, despite lacking arms. (Minecraft wiki)
User avatar
tzoli
 
Posts: 343
Joined: Sat Jun 12, 2010 6:54 pm
Location: Behind you
Score: 15 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron