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.5 by root, Thu Jan 18 19:42:10 2007 UTC vs.
Revision 1.12 by root, Thu Jul 1 01:22:44 2010 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines