algorithm - Random World Generation -


i'm starting go random world generating, have idea on how random number generating works (actually pseudorandom numbers), don't have idea of how make world "nice", in other words not place blocks based on random x, y gives me, make smooth.

this 1 time generation per world. created @ start.

i thinking of algorithm few moments ago, problem use endless amount of nested if loops, take more necessary time. thinking of following:

  1. choose random location on map , place spawn point in location.
  2. start building street based on spawn location, if spawn location 16 spaces near edge of world build house, otherwise start building street.
  3. based on generated street's place structures around.
  4. place misc.

conceptualizing algorithm isn't of problem, i'm having difficulty starting actual code step 2 , below. based on above algorithm or algorithm think of, how start code? i'm not asking actual code made, idea of how look.

i know question isn't precise , can have multiple answers, i've seen many questions similar 1 having strange approach.

hmm looks planar(or cubic) map filling. point of view firstly need databases

struct _object     {     string name,help,info; // texts later use     int siz[3];            // grid size of object     int pos[3];            // placement pos (center or ever)     // other stuff like: mesh-id,color,hit points,...     };  struct _dependency     {     int objid     list<int> near; // can near objects (can add probability)     list<int> far;  // cannot near objects (can add probability,min distance)     };  list<_object> object;      // dbs of object types list<_dependency> depend;  // dbs of object dependency 

then need initialize dbs ini files or whatever. after need create world map. simplicity let single squared town , single layer(no sub-terrain), size , placement can random.

list<_object> obj;   // dbs of placed objects, lesser derivate of previous _object conserve memory requirements const int n=100; int[n][n] map;       // placement map, containing placed obj id, or -1 empty space 

so need town generating function fills map[n][n]:

void genere()     {     int i,j,x,y,xx,yy,objid,objix;     int _min_complexity=n/10; // can random     int _max_complexity=n;    // can random     // clear map     (i=0;i<n;i++)      (j=0;j<n;j++)       map[i][j]=-1;     int complexity=_min_complexity+random(_max_complexity-_min_complexity);     (i=0;i<complexity;)         {         // random placenet position         x=random(n);         y=random(n);         // random object, should take in mind object[].near , closest objects in map[y][x]         objid=random(object.num);         if (check if map[][] empty enough place object[objid] x,y,z)          if (check if near x,y position not bad type of object object[].far)             {             // add new object list             objix=obj.add(object[objid]);             // add new object map             int *siz=obj[objix].siz             int *pos=obj[objix].pos             x+=pos[0];             y+=pos[1];             (yy=0;yy<siz[1];yy++)              (xx=0;xx<siz[0];xx++)               map[y+yy][x+xx]=objid;             i++;             }         }     } 

also position can double[3] + orientation matrix , map coordinates aligned grid. there many ways tweak code, starting template. hope helps little.

p.s.

list<type> l; l.num - number of items in list l[i]  - item list i=l.add(a) - add new item list , returns index 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -