--- deliantra/server/random_maps/snake.C 2006/09/10 16:06:37 1.2 +++ deliantra/server/random_maps/snake.C 2012/01/03 11:25:34 1.16 @@ -1,7 +1,28 @@ - +/* + * This file is part of Deliantra, the Roguelike Realtime MMORPG. + * + * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team + * Copyright (©) 1994-2004 Crossfire Development Team (restored, original file without copyright notice) + * + * Deliantra is free software: you can redistribute it and/or modify it under + * the terms of the Affero GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the Affero GNU General Public License + * and the GNU General Public License along with this program. If not, see + * . + * + * The authors can be reached via e-mail to + */ /* peterm@langmuir.eecs.berkeley.edu: this function generates a random -snake-type layout. +snake-type maze. input: xsize, ysize; output: a char** array with # and . for closed and open respectively. @@ -11,43 +32,31 @@ */ - -#include #include -#include - - - +#include +#include "rproto.h" -char ** -make_snake_layout (int xsize, int ysize, int options) +void +make_snake_layout (layout &maze, int options) { int i, j; - /* allocate that array, set it up */ - char **maze = (char **) calloc (sizeof (char *), xsize); + maze.clear (); + maze.border (); - for (i = 0; i < xsize; i++) - { - maze[i] = (char *) calloc (sizeof (char), ysize); - } - - /* write the outer walls */ - for (i = 0; i < xsize; i++) - maze[i][0] = maze[i][ysize - 1] = '#'; - for (j = 0; j < ysize; j++) - maze[0][j] = maze[xsize - 1][j] = '#'; + int xsize = maze.w; + int ysize = maze.h; /* Bail out if the size is too small to make a snake. */ if (xsize < 8 || ysize < 8) - return maze; + return; /* decide snake orientation--vertical or horizontal , and make the walls and place the doors. */ - if (RANDOM () % 2) + if (rmg_rndm (2)) { /* vertical orientation */ - int n_walls = RANDOM () % ((xsize - 5) / 3) + 1; + int n_walls = rmg_rndm (xsize - 5) / 3 + 1; int spacing = xsize / (n_walls + 1); int orientation = 1; @@ -56,25 +65,24 @@ if (orientation) { for (j = 1; j < ysize - 2; j++) - { - maze[i][j] = '#'; - } + maze[i][j] = '#'; + maze[i][j] = 'D'; } else { for (j = 2; j < ysize; j++) - { - maze[i][j] = '#'; - } + maze[i][j] = '#'; + maze[i][1] = 'D'; } + orientation ^= 1; /* toggle the value of orientation */ } } else { /* horizontal orientation */ - int n_walls = RANDOM () % ((ysize - 5) / 3) + 1; + int n_walls = rmg_rndm (ysize - 5) / 3 + 1; int spacing = ysize / (n_walls + 1); int orientation = 1; @@ -83,25 +91,24 @@ if (orientation) { for (j = 1; j < xsize - 2; j++) - { - maze[j][i] = '#'; - } + maze[j][i] = '#'; + maze[j][i] = 'D'; } else { for (j = 2; j < xsize; j++) - { - maze[j][i] = '#'; - } + maze[j][i] = '#'; + maze[1][i] = 'D'; } + orientation ^= 1; /* toggle the value of orientation */ } } /* place the exit up/down */ - if (RANDOM () % 2) + if (rmg_rndm (2)) { maze[1][1] = '<'; maze[xsize - 2][ysize - 2] = '>'; @@ -111,7 +118,5 @@ maze[1][1] = '>'; maze[xsize - 2][ysize - 2] = '<'; } - - - return maze; } +