ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/random_maps/snake.C
(Generate patch)

Comparing deliantra/server/random_maps/snake.C (file contents):
Revision 1.7 by root, Fri Apr 11 21:09:53 2008 UTC vs.
Revision 1.18 by root, Wed Nov 16 23:42:02 2016 UTC

1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 *
4 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 1994-2004 Crossfire Development Team (restored, original file without copyright notice)
6 *
7 * Deliantra is free software: you can redistribute it and/or modify it under
8 * the terms of the Affero GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the Affero GNU General Public License
18 * and the GNU General Public License along with this program. If not, see
19 * <http://www.gnu.org/licenses/>.
20 *
21 * The authors can be reached via e-mail to <support@deliantra.net>
22 */
1 23
2/* peterm@langmuir.eecs.berkeley.edu: this function generates a random 24/* peterm@langmuir.eecs.berkeley.edu: this function generates a random
3snake-type layout. 25snake-type maze.
4 26
5input: xsize, ysize; 27input: xsize, ysize;
6output: a char** array with # and . for closed and open respectively. 28output: a char** array with # and . for closed and open respectively.
7 29
8a char value of 0 represents a blank space: a '#' is 30a char value of 0 represents a blank space: a '#' is
9a wall. 31a wall.
10 32
11*/ 33*/
12 34
13#include <global.h> 35#include <global.h>
14#include "random_map.h" 36#include <rmg.h>
15#include "rproto.h" 37#include "rproto.h"
16 38
17Maze 39void
18make_snake_layout (int xsize, int ysize, int options) 40make_snake_layout (layout &maze, int options)
19{ 41{
20 int i, j; 42 int i, j;
21 43
22 Maze maze (xsize, ysize); 44 maze.clear ();
45 maze.border ();
23 46
24 /* write the outer walls */ 47 int xsize = maze.w;
25 for (i = 0; i < xsize; i++) maze[i][0] = maze[i][ysize - 1] = '#'; 48 int ysize = maze.h;
26 for (j = 0; j < ysize; j++) maze[0][j] = maze[xsize - 1][j] = '#';
27 49
28 /* Bail out if the size is too small to make a snake. */ 50 /* Bail out if the size is too small to make a snake. */
29 if (xsize < 8 || ysize < 8) 51 if (xsize < 8 || ysize < 8)
30 return maze; 52 return;
31 53
32 /* decide snake orientation--vertical or horizontal , and 54 /* decide snake orientation--vertical or horizontal , and
33 make the walls and place the doors. */ 55 make the walls and place the doors. */
34 56
35 if (rndm (2)) 57 if (rmg_rndm (2))
36 { /* vertical orientation */ 58 { /* vertical orientation */
37 int n_walls = rndm (xsize - 5) / 3 + 1; 59 int n_walls = rmg_rndm (xsize - 5) / 3 + 1;
38 int spacing = xsize / (n_walls + 1); 60 int spacing = xsize / (n_walls + 1);
39 int orientation = 1; 61 int orientation = 1;
40 62
41 for (i = spacing; i < xsize - 3; i += spacing) 63 for (i = spacing; i < xsize - 3; i += spacing)
42 { 64 {
58 orientation ^= 1; /* toggle the value of orientation */ 80 orientation ^= 1; /* toggle the value of orientation */
59 } 81 }
60 } 82 }
61 else 83 else
62 { /* horizontal orientation */ 84 { /* horizontal orientation */
63 int n_walls = rndm (ysize - 5) / 3 + 1; 85 int n_walls = rmg_rndm (ysize - 5) / 3 + 1;
64 int spacing = ysize / (n_walls + 1); 86 int spacing = ysize / (n_walls + 1);
65 int orientation = 1; 87 int orientation = 1;
66 88
67 for (i = spacing; i < ysize - 3; i += spacing) 89 for (i = spacing; i < ysize - 3; i += spacing)
68 { 90 {
84 orientation ^= 1; /* toggle the value of orientation */ 106 orientation ^= 1; /* toggle the value of orientation */
85 } 107 }
86 } 108 }
87 109
88 /* place the exit up/down */ 110 /* place the exit up/down */
89 if (rndm (2)) 111 if (rmg_rndm (2))
90 { 112 {
91 maze[1][1] = '<'; 113 maze[1][1] = '<';
92 maze[xsize - 2][ysize - 2] = '>'; 114 maze[xsize - 2][ysize - 2] = '>';
93 } 115 }
94 else 116 else
95 { 117 {
96 maze[1][1] = '>'; 118 maze[1][1] = '>';
97 maze[xsize - 2][ysize - 2] = '<'; 119 maze[xsize - 2][ysize - 2] = '<';
98 } 120 }
99
100 return maze;
101} 121}
102 122

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines