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.4 by root, Sun Dec 31 19:02:24 2006 UTC vs.
Revision 1.19 by root, Sat Nov 17 23:40:02 2018 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines