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.2 by root, Sun Sep 10 16:06:37 2006 UTC vs.
Revision 1.15 by root, Sat Apr 23 04:56:53 2011 UTC

1 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 *
4 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011 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 */
2 23
3/* peterm@langmuir.eecs.berkeley.edu: this function generates a random 24/* peterm@langmuir.eecs.berkeley.edu: this function generates a random
4snake-type layout. 25snake-type maze.
5 26
6input: xsize, ysize; 27input: xsize, ysize;
7output: a char** array with # and . for closed and open respectively. 28output: a char** array with # and . for closed and open respectively.
8 29
9a char value of 0 represents a blank space: a '#' is 30a char value of 0 represents a blank space: a '#' is
10a wall. 31a wall.
11 32
12*/ 33*/
13 34
35#include <global.h>
36#include <rmg.h>
37#include "rproto.h"
14 38
15#include <stdio.h> 39void
16#include <global.h> 40make_snake_layout (layout &maze, int options)
17#include <time.h>
18
19
20
21
22char **
23make_snake_layout (int xsize, int ysize, int options)
24{ 41{
25 int i, j; 42 int i, j;
26 43
27 /* allocate that array, set it up */ 44 maze.clear ();
28 char **maze = (char **) calloc (sizeof (char *), xsize); 45 maze.border ();
29 46
30 for (i = 0; i < xsize; i++) 47 int xsize = maze.w;
31 { 48 int ysize = maze.h;
32 maze[i] = (char *) calloc (sizeof (char), ysize);
33 }
34
35 /* write the outer walls */
36 for (i = 0; i < xsize; i++)
37 maze[i][0] = maze[i][ysize - 1] = '#';
38 for (j = 0; j < ysize; j++)
39 maze[0][j] = maze[xsize - 1][j] = '#';
40 49
41 /* 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. */
42 if (xsize < 8 || ysize < 8) 51 if (xsize < 8 || ysize < 8)
43 return maze; 52 return;
44 53
45 /* decide snake orientation--vertical or horizontal , and 54 /* decide snake orientation--vertical or horizontal , and
46 make the walls and place the doors. */ 55 make the walls and place the doors. */
47 56
48 if (RANDOM () % 2) 57 if (rmg_rndm (2))
49 { /* vertical orientation */ 58 { /* vertical orientation */
50 int n_walls = RANDOM () % ((xsize - 5) / 3) + 1; 59 int n_walls = rmg_rndm (xsize - 5) / 3 + 1;
51 int spacing = xsize / (n_walls + 1); 60 int spacing = xsize / (n_walls + 1);
52 int orientation = 1; 61 int orientation = 1;
53 62
54 for (i = spacing; i < xsize - 3; i += spacing) 63 for (i = spacing; i < xsize - 3; i += spacing)
55 { 64 {
56 if (orientation) 65 if (orientation)
57 { 66 {
58 for (j = 1; j < ysize - 2; j++) 67 for (j = 1; j < ysize - 2; j++)
59 {
60 maze[i][j] = '#'; 68 maze[i][j] = '#';
61 } 69
62 maze[i][j] = 'D'; 70 maze[i][j] = 'D';
63 } 71 }
64 else 72 else
65 { 73 {
66 for (j = 2; j < ysize; j++) 74 for (j = 2; j < ysize; j++)
67 {
68 maze[i][j] = '#'; 75 maze[i][j] = '#';
69 } 76
70 maze[i][1] = 'D'; 77 maze[i][1] = 'D';
71 } 78 }
79
72 orientation ^= 1; /* toggle the value of orientation */ 80 orientation ^= 1; /* toggle the value of orientation */
73 } 81 }
74 } 82 }
75 else 83 else
76 { /* horizontal orientation */ 84 { /* horizontal orientation */
77 int n_walls = RANDOM () % ((ysize - 5) / 3) + 1; 85 int n_walls = rmg_rndm (ysize - 5) / 3 + 1;
78 int spacing = ysize / (n_walls + 1); 86 int spacing = ysize / (n_walls + 1);
79 int orientation = 1; 87 int orientation = 1;
80 88
81 for (i = spacing; i < ysize - 3; i += spacing) 89 for (i = spacing; i < ysize - 3; i += spacing)
82 { 90 {
83 if (orientation) 91 if (orientation)
84 { 92 {
85 for (j = 1; j < xsize - 2; j++) 93 for (j = 1; j < xsize - 2; j++)
86 {
87 maze[j][i] = '#'; 94 maze[j][i] = '#';
88 } 95
89 maze[j][i] = 'D'; 96 maze[j][i] = 'D';
90 } 97 }
91 else 98 else
92 { 99 {
93 for (j = 2; j < xsize; j++) 100 for (j = 2; j < xsize; j++)
94 {
95 maze[j][i] = '#'; 101 maze[j][i] = '#';
96 } 102
97 maze[1][i] = 'D'; 103 maze[1][i] = 'D';
98 } 104 }
105
99 orientation ^= 1; /* toggle the value of orientation */ 106 orientation ^= 1; /* toggle the value of orientation */
100 } 107 }
101 } 108 }
102 109
103 /* place the exit up/down */ 110 /* place the exit up/down */
104 if (RANDOM () % 2) 111 if (rmg_rndm (2))
105 { 112 {
106 maze[1][1] = '<'; 113 maze[1][1] = '<';
107 maze[xsize - 2][ysize - 2] = '>'; 114 maze[xsize - 2][ysize - 2] = '>';
108 } 115 }
109 else 116 else
110 { 117 {
111 maze[1][1] = '>'; 118 maze[1][1] = '>';
112 maze[xsize - 2][ysize - 2] = '<'; 119 maze[xsize - 2][ysize - 2] = '<';
113 } 120 }
121}
114 122
115
116 return maze;
117}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines