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 |
… | |
… | |
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 | |
156 | // checks whether the layout has a "reachable" wall at a givne point, i.e. |
152 | // checks whether the layout has a "reachable" space at a given point, i.e. |
157 | // a wall that is not completely surrounded by walls. |
153 | // not a wall that is completely surrounded by walls. |
158 | static bool inline |
154 | static bool inline |
159 | is_visible (layout &maze, int i, int j) |
155 | is_visible (layout &maze, int i, int j) |
160 | { |
156 | { |
161 | int cnt = 0; |
|
|
162 | |
|
|
163 | for (int dx = -1; dx <= 1; ++dx) |
157 | for (int dx = -1; dx <= 1; ++dx) |
164 | for (int dy = -1; dy <= 1; ++dy) |
158 | for (int dy = -1; dy <= 1; ++dy) |
165 | { |
159 | { |
166 | int x = i + dx; |
160 | int x = i + dx; |
167 | int y = j + dy; |
161 | int y = j + dy; |
168 | |
162 | |
169 | cnt += x < 0 || x >= maze.w |
163 | if (IN_RANGE_EXC (x, 0, maze.w) |
170 | || y < 0 || y >= maze.h |
164 | && IN_RANGE_EXC (y, 0, maze.h) |
171 | || maze [x][y] == '#'; |
165 | && maze [x][y] != '#') |
|
|
166 | return true; |
172 | } |
167 | } |
173 | |
168 | |
174 | return cnt != 9; |
169 | return false; |
175 | } |
170 | } |
176 | |
171 | |
177 | /* 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 |
178 | w_style) at '#' marks. */ |
173 | w_style) at '#' marks. */ |
179 | void |
174 | void |
… | |
… | |
252 | * global, previously-set variable, "wall_name" |
247 | * global, previously-set variable, "wall_name" |
253 | */ |
248 | */ |
254 | object * |
249 | object * |
255 | 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) |
256 | { |
251 | { |
257 | /* 1 = wall to left, |
|
|
258 | * 2 = wall to right, |
|
|
259 | * 4 = wall above |
|
|
260 | * 8 = wall below |
|
|
261 | */ |
|
|
262 | int surround_index = 0; |
|
|
263 | int l; |
252 | int l; |
264 | object *the_wall = 0; |
253 | object *the_wall = 0; |
265 | object *new_wall = 0; |
254 | object *new_wall = 0; |
266 | archetype *wall_arch = 0; |
255 | archetype *wall_arch = 0; |
267 | |
256 | |
… | |
… | |
304 | { |
293 | { |
305 | new_wall = wall_arch->instance (); |
294 | new_wall = wall_arch->instance (); |
306 | new_wall->x = i; |
295 | new_wall->x = i; |
307 | new_wall->y = j; |
296 | new_wall->y = j; |
308 | |
297 | |
309 | if (the_wall && the_wall->map) |
298 | if (the_wall->map) |
310 | the_wall->destroy (); |
299 | the_wall->destroy (); |
311 | |
300 | |
312 | the_wall->move_block = MOVE_ALL; |
301 | the_wall->move_block = MOVE_ALL; |
313 | 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); |
314 | } |
303 | } |