1 | /* |
1 | /* |
2 | CrossFire, A Multiplayer game for X-windows |
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 (C) 2002 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
5 | Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (©) 1992 Frank Tore Johansen |
6 | |
7 | * |
7 | This program is free software; you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
8 | it under the terms of the GNU General Public License as published by |
9 | * the terms of the Affero GNU General Public License as published by the |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
10 | (at your option) any later version. |
11 | * option) any later version. |
11 | |
12 | * |
12 | 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, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
16 | |
17 | * |
17 | You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the Affero GNU General Public License |
18 | along with this program; if not, write to the Free Software |
19 | * and the GNU General Public License along with this program. If not, see |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * <http://www.gnu.org/licenses/>. |
20 | |
21 | * |
21 | The authors can be reached via e-mail at <crossfire@schmorp.de> |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | */ |
23 | */ |
23 | |
24 | |
24 | #include <global.h> |
25 | #include <global.h> |
|
|
26 | #include <util.h> |
25 | #include <random_map.h> |
27 | #include <random_map.h> |
26 | #include <rproto.h> |
28 | #include <rproto.h> |
27 | |
29 | |
28 | /* Put in the walls and autojoin them. */ |
30 | /* Put in the walls and autojoin them. */ |
29 | |
31 | |
30 | |
|
|
31 | /* given a layout 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 |
32 | are occupied. */ |
33 | are occupied. */ |
33 | |
|
|
34 | int |
34 | int |
35 | surround_flag (char **layout, int i, int j, RMParms * RP) |
35 | surround_flag (const layout &maze, int i, int j) |
36 | { |
36 | { |
37 | /* 1 = wall to left, |
37 | /* 1 = wall to left, |
38 | 2 = wall to right, |
38 | 2 = wall to right, |
39 | 4 = wall above |
39 | 4 = wall above |
40 | 8 = wall below */ |
40 | 8 = wall below */ |
41 | int surround_index = 0; |
41 | int surround_index = 0; |
42 | |
42 | |
43 | if ((i > 0) && layout[i - 1][j] != 0) |
43 | if (i > 0 && maze[i - 1][j] != 0) surround_index |= 1; |
44 | surround_index |= 1; |
44 | if (i < maze.w - 1 && maze[i + 1][j] != 0) surround_index |= 2; |
45 | if ((i < RP->Xsize - 1) && layout[i + 1][j] != 0) |
45 | if (j > 0 && maze[i][j - 1] != 0) surround_index |= 4; |
46 | surround_index |= 2; |
46 | if (j < maze.h - 1 && maze[i][j + 1] != 0) surround_index |= 8; |
47 | if ((j > 0) && layout[i][j - 1] != 0) |
47 | |
48 | surround_index |= 4; |
|
|
49 | if ((j < RP->Ysize - 1) && layout[i][j + 1] != 0) |
|
|
50 | surround_index |= 8; |
|
|
51 | return surround_index; |
48 | return surround_index; |
52 | } |
49 | } |
53 | |
50 | |
54 | |
|
|
55 | /* like surround_flag, but only walls count. |
51 | /* like surround_flag, but only walls count. */ |
56 | */ |
|
|
57 | |
|
|
58 | int |
52 | int |
59 | surround_flag2 (char **layout, int i, int j, RMParms * RP) |
53 | surround_flag2 (const layout &maze, int i, int j) |
60 | { |
54 | { |
61 | /* 1 = wall to left, |
55 | /* 1 = wall to left, |
62 | 2 = wall to right, |
56 | 2 = wall to right, |
63 | 4 = wall above |
57 | 4 = wall above |
64 | 8 = wall below */ |
58 | 8 = wall below */ |
65 | int surround_index = 0; |
59 | int surround_index = 0; |
66 | |
60 | |
67 | if ((i > 0) && layout[i - 1][j] == '#') |
61 | if (i > 0 && maze[i - 1][j] == '#') surround_index |= 1; |
68 | surround_index |= 1; |
62 | if (i < maze.w - 1 && maze[i + 1][j] == '#') surround_index |= 2; |
69 | if ((i < RP->Xsize - 1) && layout[i + 1][j] == '#') |
63 | if (j > 0 && maze[i][j - 1] == '#') surround_index |= 4; |
70 | surround_index |= 2; |
64 | if (j < maze.h - 1 && maze[i][j + 1] == '#') surround_index |= 8; |
71 | if ((j > 0) && layout[i][j - 1] == '#') |
65 | |
72 | surround_index |= 4; |
|
|
73 | if ((j < RP->Ysize - 1) && layout[i][j + 1] == '#') |
|
|
74 | surround_index |= 8; |
|
|
75 | return surround_index; |
66 | return surround_index; |
76 | } |
67 | } |
77 | |
68 | |
78 | |
|
|
79 | /* like surround_flag, except it checks a map, not a layout. |
69 | /* like surround_flag, except it checks a map, not a maze. |
80 | * Since this is part of the random map code, presumption |
70 | * Since this is part of the random map code, presumption |
81 | * is that this is not a tiled map. |
71 | * is that this is not a tiled map. |
82 | * What is considered blocking and not is somewhat hard coded. |
72 | * What is considered blocking and not is somewhat hard coded. |
83 | */ |
73 | */ |
84 | int |
74 | int |
85 | surround_flag3 (maptile *map, sint16 i, sint16 j, RMParms * RP) |
75 | surround_flag3 (maptile *map, int i, int j) |
86 | { |
76 | { |
87 | /* |
77 | /* |
88 | * 1 = blocked to left, |
78 | * 1 = blocked to left, |
89 | * 2 = blocked to right, |
79 | * 2 = blocked to right, |
90 | * 4 = blocked above |
80 | * 4 = blocked above |
91 | * 8 = blocked below |
81 | * 8 = blocked below |
92 | */ |
82 | */ |
93 | |
|
|
94 | int surround_index = 0; |
|
|
95 | |
|
|
96 | if ((i > 0) && (GET_MAP_MOVE_BLOCK (map, i - 1, j) & ~MOVE_BLOCK_DEFAULT)) |
|
|
97 | surround_index |= 1; |
83 | int surround_index = 0; |
98 | if ((i < RP->Xsize - 1) && (GET_MAP_MOVE_BLOCK (map, i + 1, j) & ~MOVE_BLOCK_DEFAULT)) |
84 | |
99 | surround_index |= 2; |
85 | // don't forget to update the mapspace! |
100 | if ((j > 0) && (GET_MAP_MOVE_BLOCK (map, i, j - 1) & ~MOVE_BLOCK_DEFAULT)) |
86 | if (i > 0) map->at (i - 1, j ).update (); |
101 | surround_index |= 4; |
87 | if (i < map->width - 1) map->at (i + 1, j ).update (); |
102 | if ((j < RP->Ysize - 1) && (GET_MAP_MOVE_BLOCK (map, i, j + 1) & ~MOVE_BLOCK_DEFAULT)) |
88 | if (j > 0) map->at (i , j - 1).update (); |
103 | surround_index |= 8; |
89 | if (j < map->height - 1) map->at (i , j + 1).update (); |
|
|
90 | |
|
|
91 | if (i > 0 && (GET_MAP_MOVE_BLOCK (map, i - 1, j) & MOVE_WALK)) surround_index |= 1; |
|
|
92 | if (i < map->width - 1 && (GET_MAP_MOVE_BLOCK (map, i + 1, j) & MOVE_WALK)) surround_index |= 2; |
|
|
93 | if (j > 0 && (GET_MAP_MOVE_BLOCK (map, i, j - 1) & MOVE_WALK)) surround_index |= 4; |
|
|
94 | if (j < map->height - 1 && (GET_MAP_MOVE_BLOCK (map, i, j + 1) & MOVE_WALK)) surround_index |= 8; |
104 | |
95 | |
105 | return surround_index; |
96 | return surround_index; |
106 | } |
97 | } |
107 | |
98 | |
108 | /* like surround_flag2, except it checks a map, not a layout. */ |
99 | /* like surround_flag2, except it checks a map, not a maze. */ |
109 | |
100 | static int |
110 | int |
|
|
111 | surround_flag4 (maptile *map, int i, int j, RMParms * RP) |
101 | surround_flag4 (maptile *map, int i, int j) |
112 | { |
102 | { |
113 | /* 1 = blocked to left, |
103 | /* 1 = blocked to left, |
114 | 2 = blocked to right, |
104 | 2 = blocked to right, |
115 | 4 = blocked above |
105 | 4 = blocked above |
116 | 8 = blocked below */ |
106 | 8 = blocked below */ |
117 | int surround_index = 0; |
107 | int surround_index = 0; |
118 | |
108 | |
119 | if ((i > 0) && wall_blocked (map, i - 1, j)) |
109 | if (i > 0 && wall_blocked (map, i - 1, j)) surround_index |= 1; |
120 | surround_index |= 1; |
110 | if (i < map->width - 1 && wall_blocked (map, i + 1, j)) surround_index |= 2; |
121 | if ((i < RP->Xsize - 1) && wall_blocked (map, i + 1, j)) |
111 | if (j > 0 && wall_blocked (map, i, j - 1)) surround_index |= 4; |
122 | surround_index |= 2; |
112 | if (j < map->height - 1 && wall_blocked (map, i, j + 1)) surround_index |= 8; |
123 | if ((j > 0) && wall_blocked (map, i, j - 1)) |
|
|
124 | surround_index |= 4; |
|
|
125 | if ((j < RP->Ysize - 1) && wall_blocked (map, i, j + 1)) |
|
|
126 | surround_index |= 8; |
|
|
127 | |
113 | |
128 | return surround_index; |
114 | return surround_index; |
129 | } |
115 | } |
130 | |
116 | |
131 | /* takes a map and a layout, and puts walls in the map (picked from |
|
|
132 | w_style) at '#' marks. */ |
|
|
133 | |
|
|
134 | void |
|
|
135 | make_map_walls (maptile *map, char **layout, char *w_style, RMParms * RP) |
|
|
136 | { |
|
|
137 | char styledirname[256]; |
|
|
138 | char stylefilepath[256]; |
|
|
139 | maptile *style_map = 0; |
|
|
140 | object *the_wall; |
|
|
141 | |
|
|
142 | /* get the style map */ |
|
|
143 | if (!strcmp (w_style, "none")) |
|
|
144 | return; |
|
|
145 | sprintf (styledirname, "%s", "/styles/wallstyles"); |
|
|
146 | sprintf (stylefilepath, "%s/%s", styledirname, w_style); |
|
|
147 | style_map = find_style (styledirname, w_style, -1); |
|
|
148 | if (style_map == 0) |
|
|
149 | return; |
|
|
150 | |
|
|
151 | /* fill up the map with the given floor style */ |
|
|
152 | if ((the_wall = pick_random_object (style_map)) != NULL) |
|
|
153 | { |
|
|
154 | int i, j; |
|
|
155 | char *cp; |
|
|
156 | int joinedwalls = 0; |
|
|
157 | object *thiswall; |
|
|
158 | |
|
|
159 | sprintf (RP->wall_name, "%s", &the_wall->arch->name); |
|
|
160 | if ((cp = strchr (RP->wall_name, '_')) != NULL) |
|
|
161 | { |
|
|
162 | *cp = 0; |
|
|
163 | joinedwalls = 1; |
|
|
164 | } |
|
|
165 | |
|
|
166 | for (i = 0; i < RP->Xsize; i++) |
|
|
167 | for (j = 0; j < RP->Ysize; j++) |
|
|
168 | { |
|
|
169 | if (layout[i][j] == '#') |
|
|
170 | { |
|
|
171 | if (joinedwalls) |
|
|
172 | thiswall = pick_joined_wall (the_wall, layout, i, j, RP); |
|
|
173 | else |
|
|
174 | thiswall = arch_to_object (the_wall->arch); |
|
|
175 | thiswall->x = i; |
|
|
176 | thiswall->y = j; |
|
|
177 | thiswall->move_block = MOVE_ALL; |
|
|
178 | insert_ob_in_map (thiswall, map, thiswall, INS_NO_MERGE | INS_NO_WALK_ON); |
|
|
179 | } |
|
|
180 | } |
|
|
181 | } |
|
|
182 | } |
|
|
183 | |
|
|
184 | |
|
|
185 | /* 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, |
186 | and have everything nicely joined. It uses the layout. */ |
118 | and have everything nicely joined. It uses the maze. */ |
187 | |
119 | static object * |
188 | object * |
|
|
189 | pick_joined_wall (object *the_wall, char **layout, int i, int j, RMParms * RP) |
120 | pick_joined_wall (object *the_wall, const layout &maze, int i, int j, random_map_params *RP) |
190 | { |
121 | { |
191 | /* 1 = wall to left, |
122 | /* 1 = wall to left, |
192 | 2 = wall to right, |
123 | 2 = wall to right, |
193 | 4 = wall above |
124 | 4 = wall above |
194 | 8 = wall below */ |
125 | 8 = wall below */ |
195 | int surround_index = 0; |
126 | int surround_index = 0; |
196 | int l; |
127 | int l; |
197 | char wall_name[64]; |
128 | char wall_name[1024]; |
198 | archetype *wall_arch = 0; |
129 | archetype *wall_arch = 0; |
199 | |
130 | |
200 | strcpy (wall_name, the_wall->arch->name); |
131 | assign (wall_name, the_wall->arch->archname); |
201 | |
132 | |
202 | /* conventionally, walls are named like this: |
133 | /* conventionally, walls are named like this: |
203 | wallname_wallcode, where wallcode indicates |
134 | wallname_wallcode, where wallcode indicates |
204 | a joinedness, and wallname is the wall. |
135 | a joinedness, and wallname is the wall. |
205 | this code depends on the convention for |
136 | this code depends on the convention for |
… | |
… | |
213 | wall_name[l] = 0; |
144 | wall_name[l] = 0; |
214 | break; |
145 | break; |
215 | } |
146 | } |
216 | } |
147 | } |
217 | |
148 | |
218 | surround_index = surround_flag2 (layout, i, j, RP); |
|
|
219 | |
|
|
220 | switch (surround_index) |
|
|
221 | { |
|
|
222 | case 0: |
|
|
223 | strcat (wall_name, "_0"); |
149 | strcat (wall_name, "_"); |
224 | break; |
150 | strcat (wall_name, wall_suffix [surround_flag2 (maze, i, j)]); |
225 | case 1: |
151 | |
226 | strcat (wall_name, "_1_3"); |
|
|
227 | break; |
|
|
228 | case 2: |
|
|
229 | strcat (wall_name, "_1_4"); |
|
|
230 | break; |
|
|
231 | case 3: |
|
|
232 | strcat (wall_name, "_2_1_2"); |
|
|
233 | break; |
|
|
234 | case 4: |
|
|
235 | strcat (wall_name, "_1_2"); |
|
|
236 | break; |
|
|
237 | case 5: |
|
|
238 | strcat (wall_name, "_2_2_4"); |
|
|
239 | break; |
|
|
240 | case 6: |
|
|
241 | strcat (wall_name, "_2_2_1"); |
|
|
242 | break; |
|
|
243 | case 7: |
|
|
244 | strcat (wall_name, "_3_1"); |
|
|
245 | break; |
|
|
246 | case 8: |
|
|
247 | strcat (wall_name, "_1_1"); |
|
|
248 | break; |
|
|
249 | case 9: |
|
|
250 | strcat (wall_name, "_2_2_3"); |
|
|
251 | break; |
|
|
252 | case 10: |
|
|
253 | strcat (wall_name, "_2_2_2"); |
|
|
254 | break; |
|
|
255 | case 11: |
|
|
256 | strcat (wall_name, "_3_3"); |
|
|
257 | break; |
|
|
258 | case 12: |
|
|
259 | strcat (wall_name, "_2_1_1"); |
|
|
260 | break; |
|
|
261 | case 13: |
|
|
262 | strcat (wall_name, "_3_4"); |
|
|
263 | break; |
|
|
264 | case 14: |
|
|
265 | strcat (wall_name, "_3_2"); |
|
|
266 | break; |
|
|
267 | case 15: |
|
|
268 | strcat (wall_name, "_4"); |
|
|
269 | break; |
|
|
270 | } |
|
|
271 | wall_arch = archetype::find (wall_name); |
152 | wall_arch = archetype::find (wall_name); |
272 | if (wall_arch) |
153 | |
273 | return arch_to_object (wall_arch); |
154 | return wall_arch ? wall_arch->instance () : the_wall->arch->instance (); |
274 | else |
155 | } |
|
|
156 | |
|
|
157 | // checks whether the layout has a "reachable" space at a given point, i.e. |
|
|
158 | // not a wall that is completely surrounded by walls. |
|
|
159 | static bool inline |
|
|
160 | is_visible (layout &maze, int i, int j) |
|
|
161 | { |
|
|
162 | for (int dx = -1; dx <= 1; ++dx) |
|
|
163 | for (int dy = -1; dy <= 1; ++dy) |
275 | { |
164 | { |
276 | nroferrors--; |
165 | int x = i + dx; |
277 | return arch_to_object (the_wall->arch); |
166 | int y = j + dy; |
|
|
167 | |
|
|
168 | if (IN_RANGE_EXC (x, 0, maze.w) |
|
|
169 | && IN_RANGE_EXC (y, 0, maze.h) |
|
|
170 | && maze [x][y] != '#') |
|
|
171 | return true; |
278 | } |
172 | } |
279 | |
173 | |
280 | |
174 | return false; |
281 | } |
175 | } |
282 | |
176 | |
|
|
177 | /* takes a map and a maze, and puts walls in the map (picked from |
|
|
178 | w_style) at '#' marks. */ |
|
|
179 | void |
|
|
180 | make_map_walls (maptile *map, layout &maze, const char *w_style, const char *m_style, random_map_params *RP) |
|
|
181 | { |
|
|
182 | object *the_wall; |
|
|
183 | |
|
|
184 | /* get the style map */ |
|
|
185 | if (!strcmp (w_style, "none")) |
|
|
186 | return; |
|
|
187 | |
|
|
188 | maptile *style_map = find_style ("/styles/wallstyles", w_style, RP->difficulty); |
|
|
189 | if (!style_map) |
|
|
190 | return; |
|
|
191 | |
|
|
192 | maptile *mining_map = m_style && *m_style |
|
|
193 | ? find_style ("/styles/miningstyles", m_style, RP->difficulty) |
|
|
194 | : 0; |
|
|
195 | |
|
|
196 | if ((the_wall = style_map->pick_random_object (rmg_rndm))) |
|
|
197 | { |
|
|
198 | // first pass, remove all "unreachable" (in-rock) walls |
|
|
199 | // and replace them by "blocked" spaces. |
|
|
200 | |
|
|
201 | layout clean_maze (maze); |
|
|
202 | |
|
|
203 | if (archetype *blocked = archetype::find ("blocked")) |
|
|
204 | for (int x = 0; x < maze.w; ++x) |
|
|
205 | for (int y = 0; y < maze.h; ++y) |
|
|
206 | if (maze [x][y] == '#' && !is_visible (maze, x, y)) |
|
|
207 | { |
|
|
208 | clean_maze [x][y] = 'X'; |
|
|
209 | |
|
|
210 | // erase everything on this space ad replace it by blocked |
|
|
211 | mapspace &ms = map->at (x, y); |
|
|
212 | |
|
|
213 | while (ms.top) |
|
|
214 | ms.top->destroy (); |
|
|
215 | |
|
|
216 | map->insert (blocked->instance (), x, y, 0, INS_NO_MERGE | INS_NO_WALK_ON); |
|
|
217 | } |
|
|
218 | |
|
|
219 | // second pass, add in walls |
|
|
220 | |
|
|
221 | int joinedwalls = 0; |
|
|
222 | |
|
|
223 | assign (RP->wall_name, the_wall->arch->archname); |
|
|
224 | if (char *cp = strchr (RP->wall_name, '_')) |
|
|
225 | { |
|
|
226 | *cp = 0; |
|
|
227 | joinedwalls = 1; |
|
|
228 | } |
|
|
229 | |
|
|
230 | for (int i = 0; i < RP->Xsize; i++) |
|
|
231 | for (int j = 0; j < RP->Ysize; j++) |
|
|
232 | if (clean_maze [i][j] == '#') |
|
|
233 | { |
|
|
234 | object *thiswall = joinedwalls ? pick_joined_wall (the_wall, clean_maze, i, j, RP) |
|
|
235 | : the_wall->arch->instance (); |
|
|
236 | |
|
|
237 | thiswall->move_block = MOVE_ALL; |
|
|
238 | map->insert (thiswall, i, j, thiswall, INS_NO_MERGE | INS_NO_WALK_ON); |
|
|
239 | |
|
|
240 | if (mining_map) |
|
|
241 | if (object *vein = mining_map->at (rmg_rndm (mining_map->width), rmg_rndm (mining_map->height)).bot) |
|
|
242 | map->insert (vein->clone (), i, j, thiswall, INS_NO_MERGE | INS_NO_WALK_ON); |
|
|
243 | } |
|
|
244 | } |
|
|
245 | } |
283 | |
246 | |
284 | /* this takes a map, and changes an existing wall to match what's blocked |
247 | /* this takes a map, and changes an existing wall to match what's blocked |
285 | * around it, counting only doors and walls as blocked. If insert_flag is |
248 | * around it, counting only doors and walls as blocked. If insert_flag is |
286 | * 1, it will go ahead and insert the wall into the map. If not, it |
249 | * 1, it will go ahead and insert the wall into the map. If not, it |
287 | * will only return the wall which would belong there, and doesn't |
250 | * will only return the wall which would belong there, and doesn't |
288 | * remove anything. It depends on the |
251 | * remove anything. It depends on the |
289 | * global, previously-set variable, "wall_name" |
252 | * global, previously-set variable, "wall_name" |
290 | */ |
253 | */ |
291 | |
|
|
292 | object * |
254 | object * |
293 | retrofit_joined_wall (maptile *the_map, int i, int j, int insert_flag, RMParms * RP) |
255 | retrofit_joined_wall (maptile *the_map, int i, int j, int insert_flag, random_map_params *RP) |
294 | { |
256 | { |
295 | /* 1 = wall to left, |
257 | /* 1 = wall to left, |
296 | * 2 = wall to right, |
258 | * 2 = wall to right, |
297 | * 4 = wall above |
259 | * 4 = wall above |
298 | * 8 = wall below |
260 | * 8 = wall below |
… | |
… | |
302 | object *the_wall = 0; |
264 | object *the_wall = 0; |
303 | object *new_wall = 0; |
265 | object *new_wall = 0; |
304 | archetype *wall_arch = 0; |
266 | archetype *wall_arch = 0; |
305 | |
267 | |
306 | /* first find the wall */ |
268 | /* first find the wall */ |
307 | for (the_wall = get_map_ob (the_map, i, j); the_wall != NULL; the_wall = the_wall->above) |
269 | for (the_wall = GET_MAP_OB (the_map, i, j); the_wall; the_wall = the_wall->above) |
308 | if ((the_wall->move_type & MOVE_WALK) && the_wall->type != EXIT && the_wall->type != TELEPORTER) |
270 | if ((the_wall->move_type & MOVE_WALK) && the_wall->type != EXIT && the_wall->type != TELEPORTER) |
309 | break; |
271 | break; |
310 | |
|
|
311 | |
272 | |
312 | /* if what we found is a door, don't remove it, set the_wall to NULL to |
273 | /* if what we found is a door, don't remove it, set the_wall to NULL to |
313 | * signal that later. |
274 | * signal that later. |
314 | */ |
275 | */ |
315 | if (the_wall && (the_wall->type == DOOR || the_wall->type == LOCKED_DOOR)) |
276 | if (the_wall && (the_wall->type == DOOR || the_wall->type == LOCKED_DOOR)) |
… | |
… | |
332 | RP->wall_name[l] = 0; |
293 | RP->wall_name[l] = 0; |
333 | break; |
294 | break; |
334 | } |
295 | } |
335 | } |
296 | } |
336 | |
297 | |
337 | surround_index = surround_flag4 (the_map, i, j, RP); |
|
|
338 | /* This would be a lot cleaner to just us a lookup table, |
|
|
339 | * eg, wall_suffix[surround_index] |
|
|
340 | */ |
|
|
341 | switch (surround_index) |
|
|
342 | { |
|
|
343 | case 0: |
|
|
344 | strcat (RP->wall_name, "_0"); |
298 | strcat (RP->wall_name, "_"); |
345 | break; |
299 | strcat (RP->wall_name, wall_suffix [surround_flag4 (the_map, i, j)]); |
346 | case 1: |
300 | |
347 | strcat (RP->wall_name, "_1_3"); |
|
|
348 | break; |
|
|
349 | case 2: |
|
|
350 | strcat (RP->wall_name, "_1_4"); |
|
|
351 | break; |
|
|
352 | case 3: |
|
|
353 | strcat (RP->wall_name, "_2_1_2"); |
|
|
354 | break; |
|
|
355 | case 4: |
|
|
356 | strcat (RP->wall_name, "_1_2"); |
|
|
357 | break; |
|
|
358 | case 5: |
|
|
359 | strcat (RP->wall_name, "_2_2_4"); |
|
|
360 | break; |
|
|
361 | case 6: |
|
|
362 | strcat (RP->wall_name, "_2_2_1"); |
|
|
363 | break; |
|
|
364 | case 7: |
|
|
365 | strcat (RP->wall_name, "_3_1"); |
|
|
366 | break; |
|
|
367 | case 8: |
|
|
368 | strcat (RP->wall_name, "_1_1"); |
|
|
369 | break; |
|
|
370 | case 9: |
|
|
371 | strcat (RP->wall_name, "_2_2_3"); |
|
|
372 | break; |
|
|
373 | case 10: |
|
|
374 | strcat (RP->wall_name, "_2_2_2"); |
|
|
375 | break; |
|
|
376 | case 11: |
|
|
377 | strcat (RP->wall_name, "_3_3"); |
|
|
378 | break; |
|
|
379 | case 12: |
|
|
380 | strcat (RP->wall_name, "_2_1_1"); |
|
|
381 | break; |
|
|
382 | case 13: |
|
|
383 | strcat (RP->wall_name, "_3_4"); |
|
|
384 | break; |
|
|
385 | case 14: |
|
|
386 | strcat (RP->wall_name, "_3_2"); |
|
|
387 | break; |
|
|
388 | case 15: |
|
|
389 | strcat (RP->wall_name, "_4"); |
|
|
390 | break; |
|
|
391 | } |
|
|
392 | wall_arch = archetype::find (RP->wall_name); |
301 | wall_arch = archetype::find (RP->wall_name); |
|
|
302 | |
393 | if (wall_arch != NULL) |
303 | if (!wall_arch) |
394 | { |
304 | { |
395 | new_wall = arch_to_object (wall_arch); |
305 | new_wall = wall_arch->instance (); |
396 | new_wall->x = i; |
306 | new_wall->x = i; |
397 | new_wall->y = j; |
307 | new_wall->y = j; |
|
|
308 | |
398 | if (the_wall && the_wall->map) |
309 | if (the_wall && the_wall->map) |
399 | { |
310 | the_wall->destroy (); |
400 | remove_ob (the_wall); |
311 | |
401 | free_object (the_wall); |
|
|
402 | } |
|
|
403 | the_wall->move_block = MOVE_ALL; |
312 | the_wall->move_block = MOVE_ALL; |
404 | insert_ob_in_map (new_wall, the_map, new_wall, INS_NO_MERGE | INS_NO_WALK_ON); |
313 | insert_ob_in_map (new_wall, the_map, new_wall, INS_NO_MERGE | INS_NO_WALK_ON); |
405 | } |
314 | } |
406 | else |
315 | |
407 | nroferrors--; /* it's OK not to find an arch. */ |
|
|
408 | return new_wall; |
316 | return new_wall; |
409 | } |
317 | } |