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

Comparing deliantra/server/random_maps/rogue_layout.C (file contents):
Revision 1.7 by root, Fri Apr 11 21:09:53 2008 UTC vs.
Revision 1.9 by root, Tue Apr 15 03:00:24 2008 UTC

29 8 = wall below */ 29 8 = wall below */
30 int surround_index = 0; 30 int surround_index = 0;
31 31
32 if ((i > 0) && (layout[i - 1][j] != 0 && layout[i - 1][j] != '.')) 32 if ((i > 0) && (layout[i - 1][j] != 0 && layout[i - 1][j] != '.'))
33 surround_index += 1; 33 surround_index += 1;
34
34 if ((i < Xsize - 1) && (layout[i + 1][j] != 0 && layout[i + 1][j] != '.')) 35 if ((i < Xsize - 1) && (layout[i + 1][j] != 0 && layout[i + 1][j] != '.'))
35 surround_index += 2; 36 surround_index += 2;
37
36 if ((j > 0) && (layout[i][j - 1] != 0 && layout[i][j - 1] != '.')) 38 if ((j > 0) && (layout[i][j - 1] != 0 && layout[i][j - 1] != '.'))
37 surround_index += 4; 39 surround_index += 4;
40
38 if ((j < Ysize - 1) && (layout[i][j + 1] != 0 && layout[i][j + 1] != '.')) 41 if ((j < Ysize - 1) && (layout[i][j + 1] != 0 && layout[i][j + 1] != '.'))
39 surround_index += 8; 42 surround_index += 8;
43
40 return surround_index; 44 return surround_index;
41} 45}
42 46
43/* actually make the layout: we work by a reduction process: 47/* actually make the layout: we work by a reduction process:
44 * first we make everything a wall, then we remove areas to make rooms 48 * first we make everything a wall, then we remove areas to make rooms
45 */ 49 */
46Maze 50void
47roguelike_layout_gen (int xsize, int ysize, int options) 51roguelike_layout_gen (Layout maze, int options)
48{ 52{
49 int i, j; 53 int i, j;
50 Room *walk; 54 Room *walk;
51 int nrooms = 0; 55 int nrooms = 0;
52 int tries = 0; 56 int tries = 0;
53 57
54 Maze maze (xsize, ysize); 58 int xsize = maze->w;
55 59 int ysize = maze->h;
56 for (i = 0; i < xsize; i++)
57 for (j = 0; j < ysize; j++)
58 maze[i][j] = '#';
59 60
60 /* minimum room size is basically 5x5: if xsize/ysize is 61 /* minimum room size is basically 5x5: if xsize/ysize is
61 less than 3x that then hollow things out, stick in 62 less than 3x that then hollow things out, stick in
62 a stairsup and stairs down, and exit */ 63 a stairsup and stairs down, and exit */
63
64 if (xsize < 11 || ysize < 11) 64 if (xsize < 11 || ysize < 11)
65 { 65 {
66 for (i = 1; i < xsize - 1; i++) 66 maze->clear ();
67 for (j = 1; j < ysize - 1; j++) 67 maze->border ();
68 maze[i][j] = 0;
69 68
70 maze[(xsize - 1) / 2][(ysize - 1) / 2 ] = '>'; 69 maze[(xsize - 1) / 2][(ysize - 1) / 2 ] = '>';
71 maze[(xsize - 1) / 2][(ysize - 1) / 2 + 1] = '<'; 70 maze[(xsize - 1) / 2][(ysize - 1) / 2 + 1] = '<';
72 71
73 return maze; 72 return;
74 } 73 }
74
75 maze->clear ('#');
75 76
76 /* decide on the number of rooms */ 77 /* decide on the number of rooms */
77 nrooms = rndm (10) + 6; 78 nrooms = rndm (10) + 6;
78 Room *rooms = salloc0<Room> (nrooms + 1); 79 Room *rooms = salloc0<Room> (nrooms + 1);
79 80
86 tries++; 87 tries++;
87 else 88 else
88 i++; 89 i++;
89 } 90 }
90 91
91 if (i == 0) 92 if (i == 0) /* no can do! */
92 { /* no can do! */ 93 {
93 for (i = 1; i < xsize - 1; i++) 94 maze->clear ();
94 for (j = 1; j < ysize - 1; j++) 95 maze->border ();
95 maze[i][j] = 0;
96 96
97 maze [(xsize - 1) / 2][(ysize - 1) / 2 ] = '>'; 97 maze [(xsize - 1) / 2][(ysize - 1) / 2 ] = '>';
98 maze [(xsize - 1) / 2][(ysize - 1) / 2 + 1] = '<'; 98 maze [(xsize - 1) / 2][(ysize - 1) / 2 + 1] = '<';
99 99
100 sfree (rooms, nrooms + 1); 100 sfree (rooms, nrooms + 1);
101 return maze; 101 return;
102 } 102 }
103
104 103
105 /* erase the areas occupied by the rooms */ 104 /* erase the areas occupied by the rooms */
106 roguelike_make_rooms (rooms, maze, options); 105 roguelike_make_rooms (rooms, maze, options);
107 106
108 roguelike_link_rooms (rooms, maze, xsize, ysize); 107 roguelike_link_rooms (rooms, maze, xsize, ysize);
153 } 152 }
154 } 153 }
155 } 154 }
156 155
157 sfree (rooms, nrooms + 1); 156 sfree (rooms, nrooms + 1);
158 return maze;
159} 157}
160 158
161static int 159static int
162roguelike_place_room (Room *rooms, int xsize, int ysize, int nrooms) 160roguelike_place_room (Room *rooms, int xsize, int ysize, int nrooms)
163{ 161{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines