Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //set stage
- terrain = p5_generate_terrain(25,25);
- //*********GENERATE TERRAIN*****************//
- ///p5_generate_terrain(wide,height);
- //generates the desert map
- //wide x height
- var wide = argument0;
- var height = argument1;
- var t = 0; //var for holding the entire terrain information
- //generation
- for(var i = 0;i<height;i++){
- for(var j = 0;j<wide;j++){
- t[i,j] = p5_get_square();
- }
- }
- //fix terrain depending on setting rules
- t = p5_terrain_check(t);
- //generated terrain
- return t;
- //*****************************************//
- //**********RANDOM TERRAIN SELECTION******//
- ///p5_get_square();
- //type of terrain rate
- var normal = 14;
- var dune = 10;
- var cactus = 10;
- var water = 7;
- var shadow = 15;
- var scavenge = 7;
- var abyss = 15;
- var patrol = 10;
- var camp = 5;
- //set scale of success 0-15, 15-25, 25-34...
- dune+=normal;
- cactus+=dune;
- water+=cactus;
- shadow+=water;
- scavenge+=shadow;
- abyss+=scavenge;
- patrol+=abyss;
- camp+=patrol;
- var type = 'normal';
- //random terrain selection
- var square = irandom(camp);//select the higher value for the roll
- //normal
- if(square<normal){
- type = 'normal';
- }else
- //dune
- if(square<dune){
- type = 'dune';
- }else
- //cactus
- if(square<cactus){
- type = 'cactus';
- }else
- //water
- if(square<water){
- type = 'water';
- }else
- //shadow
- if(square<shadow){
- type = 'shadow';
- }else
- //scavenge
- if(square<scavenge){
- type = 'scavenge';
- }else
- //abyss
- if(square<abyss){
- type = 'abyss';
- }else
- //patrol
- if(square<patrol){
- type = 'patrol';
- }else
- //camp
- if(square<camp){
- type = 'camp';
- }
- //return terrain type (string)
- return type;
- //****************************************//
- //**********FIXING THE MAP***************//
- ///p5_terrain_check(terrain);
- var t = argument0;
- var valid = false;
- var h = array_height_2d(t); //height
- var w = array_length_2d(t,0); //width
- //set starting point and goal for player
- switch(irandom(3)){ //4 possible quadrants
- case 0:
- t[floor(w/6),floor(h/6)] = 'start'; //top left - start
- t[floor(w*5/6)-3+irandom(6),floor(h*5/6)-3+irandom(6)] = 'goal'; //bottom right - goal
- break;
- case 1:
- t[floor(w*5/6),floor(h/6)] = 'start'; //top right - start
- t[floor(w/6)-3+irandom(6),floor(h*5/6)-3+irandom(6)] = 'goal'; //bottom left - goal
- break;
- case 2:
- t[floor(w/6),floor(h*5/6)] = 'start'; //bottom left - start
- t[floor(w*5/6)-3+irandom(6),floor(h/6)-3+irandom(6)] = 'goal'; //top right - goal
- break;
- case 3:
- t[floor(w*5/6),floor(h*5/6)] = 'start'; //bottom right - start
- t[floor(w/6)-3+irandom(6),floor(w/6)-3+irandom(6)] = 'goal'; //top left - goal
- break;
- }
- //check if the generated terrain is valid, and if not, fix it.
- for(var i = 0;i<h;i++){
- for(var j = 0;j<w;j++){
- //read square type
- switch(t[i,j]){
- case 'start':
- //WE NEED TO GO DEEPER
- for(var k = i-1;k<=i+1;k++){
- for(var l = j-1;l<=j+1;l++){
- //clear all the surrounding terrain
- //of the starting point.
- //don't apply to self
- if(!(k==i and l==j)) t[k,l] = 'normal';
- }
- }
- break;
- case 'goal':
- //WE NEED TO GO DEEPER
- for(var k = i-1;k<=i+1;k++){
- for(var l = j-1;l<=j+1;l++){
- //count abyss
- var n = 0;
- if(t[k,l] == 'abyss') n++;
- }
- }
- //if there is too much abyss around, re-generate it
- if(n>7){
- for(var k = i-1;k<=i+1;k++){
- for(var l = j-1;l<=j+1;l++){
- t[k,l] = p5_get_square();
- }
- }
- //reset row search
- j=0;
- }
- break;
- case 'cactus':
- case 'water':
- case 'shadow':
- case 'scavenge':
- //WE NEED TO GO DEEPER
- for(var k = i-1;k<=i+1;k++){
- for(var l = j-1;l<=j+1;l++){
- //if the terrain has one of the same type
- //in his 9 grid area, re-generate that square
- if(!(k==i and l==j) and k>0 and l>0 and k<array_height_2d(t) and l<array_length_2d(t,i)){ //don't check self
- if(t[i,j]==t[k,l]){
- t[i,j] = p5_get_square();
- //reset 9 grid search
- k=i-1;
- l=j-1;
- }
- }
- }
- }
- break;
- //don't let be more than 50% abyss in a row
- case 'abyss':
- var n = 0;
- for(var k = 0;k<array_length_2d(t,i);k++) if(t[i,k]=='abyss') n++;
- if(array_length_2d(t,i)/n<2){
- t[i,j] = p5_get_square();
- //reset row search
- k=0;
- }
- break;
- }
- }
- }
- return t;
- //***************************************//
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement