   Random content
  HiAre there any general ways of creating game content randomly (Like random maps in rts games), or is it all just some cunning use of srand() and rand()?Thanks Emil   
  It's all just some cunning use of rand() and srand(). :-)I think that random RTS map generation should be possible through clever use of Perlin noise, and then checking that no areas are cut off from other areas.A lot of roguelike games use random maps, but that's just a matter of placing a few rectangular rooms and adding tunnels between them.   ;Quote:Original post by Beer HunterIt's all just some cunning use of rand() and srand(). :-)I think that random RTS map generation should be possible through clever use of Perlin noise, and then checking that no areas are cut off from other areas.A lot of roguelike games use random maps, but that's just a matter of placing a few rectangular rooms and adding tunnels between them.A well known rougelike is diablo, which generated its maps the same way. By randomly generating random seeds on first use and storing them, the levels get recreatable later. This saves space in the save file, since the game has to save only the differences made during the game and not the whole level.Another tick is to use a random map for level editing and add units by hand. This is what dune 2 used. The terrain was stored as a random seed and then the list of units, buildings and waypoints.Viktor   ;  Have a search around using the term proceedural content generation.  You may also be interested in reading these | three | entries in JTippetts' journal.But yes, it is basically all clever use of random number generation, although srand()/rand() may not neccesarily be the method employed.Since you've expressed an interest in maps in particular, maze generation may be a good place for you to start.   ;  JTippets is more or less GDNet's resident master of random dungeon creation.   ;  Procedural content generation begins with random numbers, but if that's the majority of it you won't have something terribly fun (unless the player get the "lucky numbers")What you want to think about is:- What makes this game fun?- What do I want the player to experience?- What kinds of things harm the experience?- How can I randomly generate maps that use the first two questions and avoid the third?Often, you can come up with an algorithm that is "good but not great" using the above, but it can be tuned to "great" using genetics (create a set of dungeons from random seeds, pick the best few to breed, and keep going until it's "great").   ;  Thanks for the tips everybody. Now i know what im looking for. As an exercise i programmed a random mace generator in MATLAB script. It turned out alright. Here is the code if anyone is intressted:----Main Script-----tw = 50;   %width (tiles)th = 50;   %height (tiles)seed = 373;rand('state',seed);A = zeros(th+1,tw+1,2);A(1,1:tw,2) = 1;A(th+1,1:tw,2) = 1;A(1:th,1,1) = 1;A(1:th,tw+1,1) = 1;for ix = 1:tw+1for iy = 1:th+1   [nx,ny,dx,dy] = getnextfree(A,ix,iy);    if nx == -1 & ny == -1 break; end   while 1   %build wall from nx,ny in dx,dy direction    if dx == 1   A(ny,nx,2) = 1;    end    if dx == -1   A(ny,nx-1,2) = 1;    end    if dy == 1   A(ny,nx,1) = 1;    end    if dy == -1   A(ny-1,nx,1) = 1;    end   nx = nx + dx;    ny = ny + dy;   [dx,dy] = getfreeadjnode(A,nx,ny);   if dx == 0 & dy == 0 break; end   endendenddisplay('Generating done... Drawing');drawmap(A,1,1);----Functions------function [dx, dy] = getfreeadjnode(A, nx, ny)tw = length(A(1,:,1)) - 1;th = length(A(:,1,1)) - 1;pos = [0,0,0,0]; %[right,up,left,down]%Attempt left wallif nx > 1 & A(ny,nx-1,1) == 0 & A(ny,nx-1,2) == 0 if ~(nx > 2 & A(ny,nx-2,2) == 1)   if ~(ny > 1 & A(ny-1,nx-1,1) == 1)  pos(3) = 1;   end    endend%Attempt right wallif nx <= tw & A(ny,nx+1,1) == 0 & A(ny,nx+1,2) == 0 if ~(ny > 1 & A(ny-1,nx+1,1) == 1)   pos(1) = 1;    endend%Attempt up wallif ny > 1 & A(ny-1,nx,1) == 0 & A(ny-1,nx,2) == 0    if ~(nx > 2 & A(ny-1,nx-1,2) == 1)   if ~(ny > 2 & A(ny-2,nx,1) == 1)  pos(2) = 1;   end    endend%Attempt down wallif ny <= th & A(ny+1,nx,1) == 0 & A(ny+1,nx,2) == 0    if ~(nx > 1 & A(ny+1,nx-1,2) == 1)   pos(4) = 1;   endendelms = sum(pos);if elms == 0    dx = 0; dy = 0;    return;endelm = round(rand*(elms-1))+1;h = 0;for i = 1:4    if pos(i) == 1   h = h + 1;    end    if h == elm   if i == 1 dx = 1; dy = 0; return; end   if i == 2 dx = 0; dy = -1; return; end   if i == 3 dx = -1; dy = 0; return; end   if i == 4 dx = 0; dy = 1; return; end    endend----------------function [nx,ny,dx,dy] = getnextfree(A, lx, ly)tw = length(A(1,:,1)) - 1;th = length(A(:,1,1)) - 1;for ny = ly:th+1;for nx = 1:tw+1;    if (nx <= lx) & (ny == ly) continue; end   if A(ny,nx,1) == 1 | A(ny,nx,2) == 1   [dx,dy] = getfreeadjnode(A,nx,ny);   if (dx ~= 0) | (dy ~= 0) return; end    end    endendnx = -1; ny = -1;-------------function drawmap(A,xs,ys)nw = length(A(1,:,1));nh = length(A(:,1,1));ys = ys*-1;for ix = 1:nwfor iy = 1:nh   hold on;    if A(iy,ix,1) == 1  %Down   plot([ix*xs,ix*xs], [iy*ys, (iy+1)*ys])    end    if A(iy,ix,2) == 1  %Right   plot([ix*xs,(ix+1)*xs], [iy*ys, iy*ys])    end    endend   //Emil   