1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992 Frank Tore Johansen |
6 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
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 |
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 |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * option) any later version. |
11 | * option) any later version. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the Affero GNU General Public License |
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 |
19 | * and the GNU General Public License along with this program. If not, see |
20 | * <http://www.gnu.org/licenses/>. |
20 | * <http://www.gnu.org/licenses/>. |
21 | * |
21 | * |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
23 | */ |
23 | */ |
24 | |
24 | |
25 | #include <global.h> |
25 | #include <global.h> |
|
|
26 | #include <util.h> |
26 | #include <random_map.h> |
27 | #include <rmg.h> |
27 | #include <rproto.h> |
28 | #include <rproto.h> |
28 | |
29 | |
29 | /* Put in the walls and autojoin them. */ |
30 | /* Put in the walls and autojoin them. */ |
30 | |
31 | |
31 | /* given a maze and a coordinate, tell me which squares up/down/right/left |
32 | /* given a maze and a coordinate, tell me which squares up/down/right/left |
… | |
… | |
37 | 2 = wall to right, |
38 | 2 = wall to right, |
38 | 4 = wall above |
39 | 4 = wall above |
39 | 8 = wall below */ |
40 | 8 = wall below */ |
40 | int surround_index = 0; |
41 | int surround_index = 0; |
41 | |
42 | |
42 | if (i > 0 && maze[i - 1][j] != 0) surround_index |= 1; |
43 | if (i > 0 && maze[i - 1][j] != 0) surround_index |= 1; |
43 | if (i < maze.w - 1 && maze[i + 1][j] != 0) surround_index |= 2; |
44 | if (i < maze.w - 1 && maze[i + 1][j] != 0) surround_index |= 2; |
44 | if (j > 0 && maze[i][j - 1] != 0) surround_index |= 4; |
45 | if (j > 0 && maze[i][j - 1] != 0) surround_index |= 4; |
45 | if (j < maze.h - 1 && maze[i][j + 1] != 0) surround_index |= 8; |
46 | if (j < maze.h - 1 && maze[i][j + 1] != 0) surround_index |= 8; |
46 | |
47 | |
47 | return surround_index; |
48 | return surround_index; |
48 | } |
49 | } |
49 | |
50 | |
… | |
… | |
55 | 2 = wall to right, |
56 | 2 = wall to right, |
56 | 4 = wall above |
57 | 4 = wall above |
57 | 8 = wall below */ |
58 | 8 = wall below */ |
58 | int surround_index = 0; |
59 | int surround_index = 0; |
59 | |
60 | |
60 | if (i > 0 && maze[i - 1][j] == '#') surround_index |= 1; |
61 | if (i > 0 && maze[i - 1][j] == '#') surround_index |= 1; |
61 | if (i < maze.w - 1 && maze[i + 1][j] == '#') surround_index |= 2; |
62 | if (i < maze.w - 1 && maze[i + 1][j] == '#') surround_index |= 2; |
62 | if (j > 0 && maze[i][j - 1] == '#') surround_index |= 4; |
63 | if (j > 0 && maze[i][j - 1] == '#') surround_index |= 4; |
63 | if (j < maze.h - 1 && maze[i][j + 1] == '#') surround_index |= 8; |
64 | if (j < maze.h - 1 && maze[i][j + 1] == '#') surround_index |= 8; |
64 | |
65 | |
65 | return surround_index; |
66 | return surround_index; |
66 | } |
67 | } |
67 | |
68 | |
… | |
… | |
116 | /* picks the right wall type for this square, to make it look nice, |
117 | /* picks the right wall type for this square, to make it look nice, |
117 | and have everything nicely joined. It uses the maze. */ |
118 | and have everything nicely joined. It uses the maze. */ |
118 | static object * |
119 | static object * |
119 | pick_joined_wall (object *the_wall, const layout &maze, int i, int j, random_map_params *RP) |
120 | pick_joined_wall (object *the_wall, const layout &maze, int i, int j, random_map_params *RP) |
120 | { |
121 | { |
121 | /* 1 = wall to left, |
|
|
122 | 2 = wall to right, |
|
|
123 | 4 = wall above |
|
|
124 | 8 = wall below */ |
|
|
125 | int surround_index = 0; |
|
|
126 | int l; |
122 | int l; |
127 | char wall_name[1024]; |
123 | char wall_name[1024]; |
128 | archetype *wall_arch = 0; |
124 | archetype *wall_arch = 0; |
129 | |
125 | |
130 | assign (wall_name, the_wall->arch->archname); |
126 | assign (wall_name, the_wall->arch->archname); |
… | |
… | |
151 | wall_arch = archetype::find (wall_name); |
147 | wall_arch = archetype::find (wall_name); |
152 | |
148 | |
153 | return wall_arch ? wall_arch->instance () : the_wall->arch->instance (); |
149 | return wall_arch ? wall_arch->instance () : the_wall->arch->instance (); |
154 | } |
150 | } |
155 | |
151 | |
|
|
152 | // checks whether the layout has a "reachable" space at a given point, i.e. |
|
|
153 | // not a wall that is completely surrounded by walls. |
|
|
154 | static bool inline |
|
|
155 | is_visible (layout &maze, int i, int j) |
|
|
156 | { |
|
|
157 | for (int dx = -1; dx <= 1; ++dx) |
|
|
158 | for (int dy = -1; dy <= 1; ++dy) |
|
|
159 | { |
|
|
160 | int x = i + dx; |
|
|
161 | int y = j + dy; |
|
|
162 | |
|
|
163 | if (IN_RANGE_EXC (x, 0, maze.w) |
|
|
164 | && IN_RANGE_EXC (y, 0, maze.h) |
|
|
165 | && maze [x][y] != '#') |
|
|
166 | return true; |
|
|
167 | } |
|
|
168 | |
|
|
169 | return false; |
|
|
170 | } |
|
|
171 | |
156 | /* takes a map and a maze, and puts walls in the map (picked from |
172 | /* takes a map and a maze, and puts walls in the map (picked from |
157 | w_style) at '#' marks. */ |
173 | w_style) at '#' marks. */ |
158 | void |
174 | void |
159 | make_map_walls (maptile *map, layout &maze, const char *w_style, const char *m_style, random_map_params *RP) |
175 | make_map_walls (maptile *map, layout &maze, const char *w_style, const char *m_style, random_map_params *RP) |
160 | { |
176 | { |
… | |
… | |
172 | ? find_style ("/styles/miningstyles", m_style, RP->difficulty) |
188 | ? find_style ("/styles/miningstyles", m_style, RP->difficulty) |
173 | : 0; |
189 | : 0; |
174 | |
190 | |
175 | if ((the_wall = style_map->pick_random_object (rmg_rndm))) |
191 | if ((the_wall = style_map->pick_random_object (rmg_rndm))) |
176 | { |
192 | { |
177 | int i, j; |
193 | // first pass, remove all "unreachable" (in-rock) walls |
178 | char *cp; |
194 | // and replace them by "blocked" spaces. |
|
|
195 | |
|
|
196 | layout clean_maze (maze); |
|
|
197 | |
|
|
198 | if (archetype *blocked = archetype::find ("blocked")) |
|
|
199 | for (int x = 0; x < maze.w; ++x) |
|
|
200 | for (int y = 0; y < maze.h; ++y) |
|
|
201 | if (maze [x][y] == '#' && !is_visible (maze, x, y)) |
|
|
202 | { |
|
|
203 | clean_maze [x][y] = 'X'; |
|
|
204 | |
|
|
205 | // erase everything on this space ad replace it by blocked |
|
|
206 | mapspace &ms = map->at (x, y); |
|
|
207 | |
|
|
208 | while (ms.top) |
|
|
209 | ms.top->destroy (); |
|
|
210 | |
|
|
211 | map->insert (blocked->instance (), x, y, 0, INS_NO_MERGE | INS_NO_WALK_ON); |
|
|
212 | } |
|
|
213 | |
|
|
214 | // second pass, add in walls |
|
|
215 | |
179 | int joinedwalls = 0; |
216 | int joinedwalls = 0; |
180 | object *thiswall; |
|
|
181 | |
217 | |
182 | sprintf (RP->wall_name, "%s", &the_wall->arch->archname); |
218 | assign (RP->wall_name, the_wall->arch->archname); |
183 | if ((cp = strchr (RP->wall_name, '_')) != NULL) |
219 | if (char *cp = strchr (RP->wall_name, '_')) |
184 | { |
220 | { |
185 | *cp = 0; |
221 | *cp = 0; |
186 | joinedwalls = 1; |
222 | joinedwalls = 1; |
187 | } |
223 | } |
188 | |
224 | |
189 | for (i = 0; i < RP->Xsize; i++) |
225 | for (int i = 0; i < RP->Xsize; i++) |
190 | for (j = 0; j < RP->Ysize; j++) |
226 | for (int j = 0; j < RP->Ysize; j++) |
191 | { |
|
|
192 | if (maze[i][j] == '#') |
227 | if (clean_maze [i][j] == '#') |
193 | { |
228 | { |
194 | if (joinedwalls) |
|
|
195 | thiswall = pick_joined_wall (the_wall, maze, i, j, RP); |
229 | object *thiswall = joinedwalls ? pick_joined_wall (the_wall, clean_maze, i, j, RP) |
196 | else |
230 | : the_wall->arch->instance (); |
197 | thiswall = the_wall->arch->instance (); |
|
|
198 | |
231 | |
199 | thiswall->move_block = MOVE_ALL; |
232 | thiswall->move_block = MOVE_ALL; |
200 | map->insert (thiswall, i, j, thiswall, INS_NO_MERGE | INS_NO_WALK_ON); |
233 | map->insert (thiswall, i, j, thiswall, INS_NO_MERGE | INS_NO_WALK_ON); |
201 | |
234 | |
202 | if (mining_map) |
235 | if (mining_map) |
203 | if (object *vein = mining_map->at (rmg_rndm (mining_map->width), rmg_rndm (mining_map->height)).bot) |
236 | if (object *vein = mining_map->at (rmg_rndm (mining_map->width), rmg_rndm (mining_map->height)).bot) |
204 | map->insert (vein->clone (), i, j, thiswall, INS_NO_MERGE | INS_NO_WALK_ON); |
237 | map->insert (vein->clone (), i, j, thiswall, INS_NO_MERGE | INS_NO_WALK_ON); |
205 | } |
238 | } |
206 | } |
|
|
207 | } |
239 | } |
208 | } |
240 | } |
209 | |
241 | |
210 | /* this takes a map, and changes an existing wall to match what's blocked |
242 | /* this takes a map, and changes an existing wall to match what's blocked |
211 | * around it, counting only doors and walls as blocked. If insert_flag is |
243 | * around it, counting only doors and walls as blocked. If insert_flag is |
… | |
… | |
215 | * global, previously-set variable, "wall_name" |
247 | * global, previously-set variable, "wall_name" |
216 | */ |
248 | */ |
217 | object * |
249 | object * |
218 | retrofit_joined_wall (maptile *the_map, int i, int j, int insert_flag, random_map_params *RP) |
250 | retrofit_joined_wall (maptile *the_map, int i, int j, int insert_flag, random_map_params *RP) |
219 | { |
251 | { |
220 | /* 1 = wall to left, |
|
|
221 | * 2 = wall to right, |
|
|
222 | * 4 = wall above |
|
|
223 | * 8 = wall below |
|
|
224 | */ |
|
|
225 | int surround_index = 0; |
|
|
226 | int l; |
252 | int l; |
227 | object *the_wall = 0; |
253 | object *the_wall = 0; |
228 | object *new_wall = 0; |
254 | object *new_wall = 0; |
229 | archetype *wall_arch = 0; |
255 | archetype *wall_arch = 0; |
230 | |
256 | |
231 | /* first find the wall */ |
257 | /* first find the wall */ |
232 | for (the_wall = GET_MAP_OB (the_map, i, j); the_wall != NULL; the_wall = the_wall->above) |
258 | for (the_wall = GET_MAP_OB (the_map, i, j); the_wall; the_wall = the_wall->above) |
233 | if ((the_wall->move_type & MOVE_WALK) && the_wall->type != EXIT && the_wall->type != TELEPORTER) |
259 | if ((the_wall->move_type & MOVE_WALK) && the_wall->type != EXIT && the_wall->type != TELEPORTER) |
234 | break; |
260 | break; |
235 | |
|
|
236 | |
261 | |
237 | /* if what we found is a door, don't remove it, set the_wall to NULL to |
262 | /* if what we found is a door, don't remove it, set the_wall to NULL to |
238 | * signal that later. |
263 | * signal that later. |
239 | */ |
264 | */ |
240 | if (the_wall && (the_wall->type == DOOR || the_wall->type == LOCKED_DOOR)) |
265 | if (the_wall && (the_wall->type == DOOR || the_wall->type == LOCKED_DOOR)) |
… | |
… | |
268 | { |
293 | { |
269 | new_wall = wall_arch->instance (); |
294 | new_wall = wall_arch->instance (); |
270 | new_wall->x = i; |
295 | new_wall->x = i; |
271 | new_wall->y = j; |
296 | new_wall->y = j; |
272 | |
297 | |
273 | if (the_wall && the_wall->map) |
298 | if (the_wall->map) |
274 | the_wall->destroy (); |
299 | the_wall->destroy (); |
275 | |
300 | |
276 | the_wall->move_block = MOVE_ALL; |
301 | the_wall->move_block = MOVE_ALL; |
277 | insert_ob_in_map (new_wall, the_map, new_wall, INS_NO_MERGE | INS_NO_WALK_ON); |
302 | insert_ob_in_map (new_wall, the_map, new_wall, INS_NO_MERGE | INS_NO_WALK_ON); |
278 | } |
303 | } |