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.11 by root, Sat Nov 7 18:30:05 2009 UTC vs.
Revision 1.16 by root, Sun Jul 4 22:12:26 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 */
23
1/* generate a rogue/nethack-like layout */ 24/* generate a rogue/nethack-like maze */
2#include <global.h> 25#include <global.h>
3#include <random_map.h> 26#include <random_map.h>
4#include <rproto.h> 27#include <rproto.h>
5 28
6typedef struct 29typedef struct
15 int rtype; /* circle or rectangular */ 38 int rtype; /* circle or rectangular */
16} Room; 39} Room;
17 40
18static int roguelike_place_room (Room *rooms, int xsize, int ysize, int nrooms); 41static int roguelike_place_room (Room *rooms, int xsize, int ysize, int nrooms);
19static void roguelike_make_rooms (Room *rooms, char **maze, int options); 42static void roguelike_make_rooms (Room *rooms, char **maze, int options);
20static void roguelike_link_rooms (Room *rooms, char **maze, int xsize, int ysize); 43static void roguelike_link_rooms (Room *rooms, layout &maze);
21 44
22int 45int
23surround_check (char **layout, int i, int j, int Xsize, int Ysize) 46surround_check (layout &maze, int i, int j)
24{ 47{
25 /* 1 = wall to left, 48 /* 1 = wall to left,
26 2 = wall to right, 49 2 = wall to right,
27 4 = wall above 50 4 = wall above
28 8 = wall below */ 51 8 = wall below */
29 int surround_index = 0; 52 int surround_index = 0;
30 53
31 if ((i > 0) && (layout[i - 1][j] != 0 && layout[i - 1][j] != '.')) surround_index |= 1; 54 if ((i > 0) && (maze[i - 1][j] != 0 && maze[i - 1][j] != '.')) surround_index |= 1;
32 if ((i < Xsize - 1) && (layout[i + 1][j] != 0 && layout[i + 1][j] != '.')) surround_index |= 2; 55 if ((i < maze.w - 1) && (maze[i + 1][j] != 0 && maze[i + 1][j] != '.')) surround_index |= 2;
33 if ((j > 0) && (layout[i][j - 1] != 0 && layout[i][j - 1] != '.')) surround_index |= 4; 56 if ((j > 0) && (maze[i][j - 1] != 0 && maze[i][j - 1] != '.')) surround_index |= 4;
34 if ((j < Ysize - 1) && (layout[i][j + 1] != 0 && layout[i][j + 1] != '.')) surround_index |= 8; 57 if ((j < maze.h - 1) && (maze[i][j + 1] != 0 && maze[i][j + 1] != '.')) surround_index |= 8;
35 58
36 return surround_index; 59 return surround_index;
37} 60}
38 61
39/* actually make the layout: we work by a reduction process: 62/* actually make the maze: we work by a reduction process:
40 * first we make everything a wall, then we remove areas to make rooms 63 * first we make everything a wall, then we remove areas to make rooms
41 */ 64 */
42void 65void
43roguelike_layout_gen (Layout maze, int options) 66roguelike_layout_gen (layout &maze, int options)
44{ 67{
45 int i, j; 68 int i, j;
46 Room *walk; 69 Room *walk;
47 int nrooms = 0; 70 int nrooms = 0;
48 int tries = 0; 71 int tries = 0;
49 72
50 int xsize = maze->w; 73 int xsize = maze.w;
51 int ysize = maze->h; 74 int ysize = maze.h;
52 75
53 /* minimum room size is basically 5x5: if xsize/ysize is 76 /* minimum room size is basically 5x5: if xsize/ysize is
54 less than 3x that then hollow things out, stick in 77 less than 3x that then hollow things out, stick in
55 a stairsup and stairs down, and exit */ 78 a stairsup and stairs down, and exit */
56 if (xsize < 11 || ysize < 11) 79 if (xsize < 11 || ysize < 11)
57 { 80 {
58 maze->clear (); 81 maze.clear ();
59 maze->border (); 82 maze.border ();
60 83
61 maze[(xsize - 1) / 2][(ysize - 1) / 2 ] = '>'; 84 maze[(xsize - 1) / 2][(ysize - 1) / 2 ] = '>';
62 maze[(xsize - 1) / 2][(ysize - 1) / 2 + 1] = '<'; 85 maze[(xsize - 1) / 2][(ysize - 1) / 2 + 1] = '<';
63 86
64 return; 87 return;
65 } 88 }
66 89
67 maze->clear ('#'); 90 maze.fill ('#');
68 91
69 /* decide on the number of rooms */ 92 /* decide on the number of rooms */
70 nrooms = rmg_rndm (10) + 6; 93 nrooms = rmg_rndm (10) + 6;
71 Room *rooms = salloc0<Room> (nrooms + 1); 94 Room *rooms = salloc0<Room> (nrooms + 1);
72 95
81 i++; 104 i++;
82 } 105 }
83 106
84 if (i == 0) /* no can do! */ 107 if (i == 0) /* no can do! */
85 { 108 {
86 maze->clear (); 109 maze.clear ();
87 maze->border (); 110 maze.border ();
88 111
89 maze [(xsize - 1) / 2][(ysize - 1) / 2 ] = '>'; 112 maze [(xsize - 1) / 2][(ysize - 1) / 2 ] = '>';
90 maze [(xsize - 1) / 2][(ysize - 1) / 2 + 1] = '<'; 113 maze [(xsize - 1) / 2][(ysize - 1) / 2 + 1] = '<';
91 114
92 sfree (rooms, nrooms + 1); 115 sfree (rooms, nrooms + 1);
94 } 117 }
95 118
96 /* erase the areas occupied by the rooms */ 119 /* erase the areas occupied by the rooms */
97 roguelike_make_rooms (rooms, maze, options); 120 roguelike_make_rooms (rooms, maze, options);
98 121
99 roguelike_link_rooms (rooms, maze, xsize, ysize); 122 roguelike_link_rooms (rooms, maze);
100 123
101 /* put in the stairs */ 124 /* put in the stairs */
102 125
103 maze[rooms->x][rooms->y] = '<'; 126 maze[rooms->x][rooms->y] = '<';
104 127
131 if (maze[i][j] == '.') 154 if (maze[i][j] == '.')
132 maze[i][j] = 0; 155 maze[i][j] = 0;
133 156
134 if (maze[i][j] == 'D') 157 if (maze[i][j] == 'D')
135 { /* remove bad door. */ 158 { /* remove bad door. */
136 int si = surround_check (maze, i, j, xsize, ysize); 159 int si = surround_check (maze, i, j);
137 160
138 if (si != 3 && si != 12) 161 if (si != 3 && si != 12)
139 { 162 {
140 maze[i][j] = 0; 163 maze[i][j] = 0;
141 /* back up and recheck any nearby doors */ 164 /* back up and recheck any nearby doors */
251 maze[i][j] = '.'; 274 maze[i][j] = '.';
252 } 275 }
253} 276}
254 277
255static void 278static void
256roguelike_link_rooms (Room *rooms, char **maze, int xsize, int ysize) 279roguelike_link_rooms (Room *rooms, layout &maze)
257{ 280{
258 Room *walk; 281 Room *walk;
259 int i, j; 282 int i, j;
260 283
261 /* link each room to the previous room */ 284 /* link each room to the previous room */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines