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 (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
6 | * Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * |
7 | * |
8 | * 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 |
9 | * 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 |
10 | * the Free Software Foundation; either version 2 of the License, or |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * (at your 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 GNU General Public License |
18 | * You should have received a copy of the Affero GNU General Public License |
19 | * 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 |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * <http://www.gnu.org/licenses/>. |
21 | * |
21 | * |
22 | * 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> |
23 | */ |
23 | */ |
24 | |
24 | |
25 | #include <global.h> |
25 | #include <global.h> |
|
|
26 | #include <util.h> |
26 | #include <random_map.h> |
27 | #include <random_map.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 | |
|
|
32 | /* 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 |
33 | are occupied. */ |
33 | are occupied. */ |
34 | |
|
|
35 | int |
34 | int |
36 | surround_flag (char **layout, int i, int j, random_map_params *RP) |
35 | surround_flag (const layout &maze, int i, int j) |
37 | { |
36 | { |
38 | /* 1 = wall to left, |
37 | /* 1 = wall to left, |
39 | 2 = wall to right, |
38 | 2 = wall to right, |
40 | 4 = wall above |
39 | 4 = wall above |
41 | 8 = wall below */ |
40 | 8 = wall below */ |
42 | int surround_index = 0; |
41 | int surround_index = 0; |
43 | |
42 | |
44 | if ((i > 0) && layout[i - 1][j] != 0) |
43 | if (i > 0 && maze[i - 1][j] != 0) surround_index |= 1; |
45 | surround_index |= 1; |
44 | if (i < maze.w - 1 && maze[i + 1][j] != 0) surround_index |= 2; |
46 | if ((i < RP->Xsize - 1) && layout[i + 1][j] != 0) |
45 | if (j > 0 && maze[i][j - 1] != 0) surround_index |= 4; |
47 | surround_index |= 2; |
46 | if (j < maze.h - 1 && maze[i][j + 1] != 0) surround_index |= 8; |
48 | if ((j > 0) && layout[i][j - 1] != 0) |
47 | |
49 | surround_index |= 4; |
|
|
50 | if ((j < RP->Ysize - 1) && layout[i][j + 1] != 0) |
|
|
51 | surround_index |= 8; |
|
|
52 | return surround_index; |
48 | return surround_index; |
53 | } |
49 | } |
54 | |
50 | |
55 | |
|
|
56 | /* like surround_flag, but only walls count. |
51 | /* like surround_flag, but only walls count. */ |
57 | */ |
|
|
58 | |
|
|
59 | int |
52 | int |
60 | surround_flag2 (char **layout, int i, int j, random_map_params *RP) |
53 | surround_flag2 (const layout &maze, int i, int j) |
61 | { |
54 | { |
62 | /* 1 = wall to left, |
55 | /* 1 = wall to left, |
63 | 2 = wall to right, |
56 | 2 = wall to right, |
64 | 4 = wall above |
57 | 4 = wall above |
65 | 8 = wall below */ |
58 | 8 = wall below */ |
66 | int surround_index = 0; |
59 | int surround_index = 0; |
67 | |
60 | |
68 | if ((i > 0) && layout[i - 1][j] == '#') |
61 | if (i > 0 && maze[i - 1][j] == '#') surround_index |= 1; |
69 | surround_index |= 1; |
62 | if (i < maze.w - 1 && maze[i + 1][j] == '#') surround_index |= 2; |
70 | if ((i < RP->Xsize - 1) && layout[i + 1][j] == '#') |
63 | if (j > 0 && maze[i][j - 1] == '#') surround_index |= 4; |
71 | surround_index |= 2; |
64 | if (j < maze.h - 1 && maze[i][j + 1] == '#') surround_index |= 8; |
72 | if ((j > 0) && layout[i][j - 1] == '#') |
65 | |
73 | surround_index |= 4; |
|
|
74 | if ((j < RP->Ysize - 1) && layout[i][j + 1] == '#') |
|
|
75 | surround_index |= 8; |
|
|
76 | return surround_index; |
66 | return surround_index; |
77 | } |
67 | } |
78 | |
68 | |
79 | |
|
|
80 | /* like surround_flag, except it checks a map, not a layout. |
69 | /* like surround_flag, except it checks a map, not a maze. |
81 | * Since this is part of the random map code, presumption |
70 | * Since this is part of the random map code, presumption |
82 | * is that this is not a tiled map. |
71 | * is that this is not a tiled map. |
83 | * What is considered blocking and not is somewhat hard coded. |
72 | * What is considered blocking and not is somewhat hard coded. |
84 | */ |
73 | */ |
85 | int |
74 | int |
86 | surround_flag3 (maptile *map, sint16 i, sint16 j, random_map_params *RP) |
75 | surround_flag3 (maptile *map, int i, int j) |
87 | { |
76 | { |
88 | /* |
77 | /* |
89 | * 1 = blocked to left, |
78 | * 1 = blocked to left, |
90 | * 2 = blocked to right, |
79 | * 2 = blocked to right, |
91 | * 4 = blocked above |
80 | * 4 = blocked above |
92 | * 8 = blocked below |
81 | * 8 = blocked below |
93 | */ |
82 | */ |
94 | |
|
|
95 | int surround_index = 0; |
|
|
96 | |
|
|
97 | if ((i > 0) && (GET_MAP_MOVE_BLOCK (map, i - 1, j) & ~MOVE_BLOCK_DEFAULT)) |
|
|
98 | surround_index |= 1; |
83 | int surround_index = 0; |
99 | if ((i < RP->Xsize - 1) && (GET_MAP_MOVE_BLOCK (map, i + 1, j) & ~MOVE_BLOCK_DEFAULT)) |
84 | |
100 | surround_index |= 2; |
85 | // don't forget to update the mapspace! |
101 | if ((j > 0) && (GET_MAP_MOVE_BLOCK (map, i, j - 1) & ~MOVE_BLOCK_DEFAULT)) |
86 | if (i > 0) map->at (i - 1, j ).update (); |
102 | surround_index |= 4; |
87 | if (i < map->width - 1) map->at (i + 1, j ).update (); |
103 | 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 (); |
104 | 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; |
105 | |
95 | |
106 | return surround_index; |
96 | return surround_index; |
107 | } |
97 | } |
108 | |
98 | |
109 | /* like surround_flag2, except it checks a map, not a layout. */ |
99 | /* like surround_flag2, except it checks a map, not a maze. */ |
110 | |
100 | static int |
111 | int |
|
|
112 | surround_flag4 (maptile *map, int i, int j, random_map_params *RP) |
101 | surround_flag4 (maptile *map, int i, int j) |
113 | { |
102 | { |
114 | /* 1 = blocked to left, |
103 | /* 1 = blocked to left, |
115 | 2 = blocked to right, |
104 | 2 = blocked to right, |
116 | 4 = blocked above |
105 | 4 = blocked above |
117 | 8 = blocked below */ |
106 | 8 = blocked below */ |
118 | int surround_index = 0; |
107 | int surround_index = 0; |
119 | |
108 | |
120 | if ((i > 0) && wall_blocked (map, i - 1, j)) |
109 | if (i > 0 && wall_blocked (map, i - 1, j)) surround_index |= 1; |
121 | surround_index |= 1; |
110 | if (i < map->width - 1 && wall_blocked (map, i + 1, j)) surround_index |= 2; |
122 | if ((i < RP->Xsize - 1) && wall_blocked (map, i + 1, j)) |
111 | if (j > 0 && wall_blocked (map, i, j - 1)) surround_index |= 4; |
123 | surround_index |= 2; |
112 | if (j < map->height - 1 && wall_blocked (map, i, j + 1)) surround_index |= 8; |
124 | if ((j > 0) && wall_blocked (map, i, j - 1)) |
|
|
125 | surround_index |= 4; |
|
|
126 | if ((j < RP->Ysize - 1) && wall_blocked (map, i, j + 1)) |
|
|
127 | surround_index |= 8; |
|
|
128 | |
113 | |
129 | return surround_index; |
114 | return surround_index; |
130 | } |
115 | } |
131 | |
116 | |
132 | /* takes a map and a layout, and puts walls in the map (picked from |
|
|
133 | w_style) at '#' marks. */ |
|
|
134 | |
|
|
135 | void |
|
|
136 | make_map_walls (maptile *map, char **layout, char *w_style, random_map_params *RP) |
|
|
137 | { |
|
|
138 | char styledirname[1024]; |
|
|
139 | char stylefilepath[1024]; |
|
|
140 | maptile *style_map = 0; |
|
|
141 | object *the_wall; |
|
|
142 | |
|
|
143 | /* get the style map */ |
|
|
144 | if (!strcmp (w_style, "none")) |
|
|
145 | return; |
|
|
146 | sprintf (styledirname, "%s", "/styles/wallstyles"); |
|
|
147 | sprintf (stylefilepath, "%s/%s", styledirname, w_style); |
|
|
148 | style_map = find_style (styledirname, w_style, -1); |
|
|
149 | if (style_map == 0) |
|
|
150 | return; |
|
|
151 | |
|
|
152 | /* fill up the map with the given floor style */ |
|
|
153 | if ((the_wall = pick_random_object (style_map)) != NULL) |
|
|
154 | { |
|
|
155 | int i, j; |
|
|
156 | char *cp; |
|
|
157 | int joinedwalls = 0; |
|
|
158 | object *thiswall; |
|
|
159 | |
|
|
160 | sprintf (RP->wall_name, "%s", &the_wall->arch->name); |
|
|
161 | if ((cp = strchr (RP->wall_name, '_')) != NULL) |
|
|
162 | { |
|
|
163 | *cp = 0; |
|
|
164 | joinedwalls = 1; |
|
|
165 | } |
|
|
166 | |
|
|
167 | for (i = 0; i < RP->Xsize; i++) |
|
|
168 | for (j = 0; j < RP->Ysize; j++) |
|
|
169 | { |
|
|
170 | if (layout[i][j] == '#') |
|
|
171 | { |
|
|
172 | if (joinedwalls) |
|
|
173 | thiswall = pick_joined_wall (the_wall, layout, i, j, RP); |
|
|
174 | else |
|
|
175 | thiswall = arch_to_object (the_wall->arch); |
|
|
176 | thiswall->x = i; |
|
|
177 | thiswall->y = j; |
|
|
178 | thiswall->move_block = MOVE_ALL; |
|
|
179 | insert_ob_in_map (thiswall, map, thiswall, INS_NO_MERGE | INS_NO_WALK_ON); |
|
|
180 | } |
|
|
181 | } |
|
|
182 | } |
|
|
183 | } |
|
|
184 | |
|
|
185 | |
|
|
186 | /* 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, |
187 | and have everything nicely joined. It uses the layout. */ |
118 | and have everything nicely joined. It uses the maze. */ |
188 | |
119 | static object * |
189 | object * |
|
|
190 | pick_joined_wall (object *the_wall, char **layout, 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) |
191 | { |
121 | { |
192 | /* 1 = wall to left, |
122 | /* 1 = wall to left, |
193 | 2 = wall to right, |
123 | 2 = wall to right, |
194 | 4 = wall above |
124 | 4 = wall above |
195 | 8 = wall below */ |
125 | 8 = wall below */ |
196 | int surround_index = 0; |
126 | int surround_index = 0; |
197 | int l; |
127 | int l; |
198 | char wall_name[1024]; |
128 | char wall_name[1024]; |
199 | archetype *wall_arch = 0; |
129 | archetype *wall_arch = 0; |
200 | |
130 | |
201 | strcpy (wall_name, the_wall->arch->name); |
131 | assign (wall_name, the_wall->arch->archname); |
202 | |
132 | |
203 | /* conventionally, walls are named like this: |
133 | /* conventionally, walls are named like this: |
204 | wallname_wallcode, where wallcode indicates |
134 | wallname_wallcode, where wallcode indicates |
205 | a joinedness, and wallname is the wall. |
135 | a joinedness, and wallname is the wall. |
206 | this code depends on the convention for |
136 | this code depends on the convention for |
… | |
… | |
214 | wall_name[l] = 0; |
144 | wall_name[l] = 0; |
215 | break; |
145 | break; |
216 | } |
146 | } |
217 | } |
147 | } |
218 | |
148 | |
219 | surround_index = surround_flag2 (layout, i, j, RP); |
|
|
220 | |
|
|
221 | switch (surround_index) |
|
|
222 | { |
|
|
223 | case 0: |
|
|
224 | strcat (wall_name, "_0"); |
149 | strcat (wall_name, "_"); |
225 | break; |
150 | strcat (wall_name, wall_suffix [surround_flag2 (maze, i, j)]); |
226 | case 1: |
151 | |
227 | strcat (wall_name, "_1_3"); |
|
|
228 | break; |
|
|
229 | case 2: |
|
|
230 | strcat (wall_name, "_1_4"); |
|
|
231 | break; |
|
|
232 | case 3: |
|
|
233 | strcat (wall_name, "_2_1_2"); |
|
|
234 | break; |
|
|
235 | case 4: |
|
|
236 | strcat (wall_name, "_1_2"); |
|
|
237 | break; |
|
|
238 | case 5: |
|
|
239 | strcat (wall_name, "_2_2_4"); |
|
|
240 | break; |
|
|
241 | case 6: |
|
|
242 | strcat (wall_name, "_2_2_1"); |
|
|
243 | break; |
|
|
244 | case 7: |
|
|
245 | strcat (wall_name, "_3_1"); |
|
|
246 | break; |
|
|
247 | case 8: |
|
|
248 | strcat (wall_name, "_1_1"); |
|
|
249 | break; |
|
|
250 | case 9: |
|
|
251 | strcat (wall_name, "_2_2_3"); |
|
|
252 | break; |
|
|
253 | case 10: |
|
|
254 | strcat (wall_name, "_2_2_2"); |
|
|
255 | break; |
|
|
256 | case 11: |
|
|
257 | strcat (wall_name, "_3_3"); |
|
|
258 | break; |
|
|
259 | case 12: |
|
|
260 | strcat (wall_name, "_2_1_1"); |
|
|
261 | break; |
|
|
262 | case 13: |
|
|
263 | strcat (wall_name, "_3_4"); |
|
|
264 | break; |
|
|
265 | case 14: |
|
|
266 | strcat (wall_name, "_3_2"); |
|
|
267 | break; |
|
|
268 | case 15: |
|
|
269 | strcat (wall_name, "_4"); |
|
|
270 | break; |
|
|
271 | } |
|
|
272 | wall_arch = archetype::find (wall_name); |
152 | wall_arch = archetype::find (wall_name); |
273 | |
153 | |
274 | return wall_arch ? arch_to_object (wall_arch) : arch_to_object (the_wall->arch); |
154 | return wall_arch ? wall_arch->instance () : the_wall->arch->instance (); |
275 | } |
155 | } |
276 | |
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) |
|
|
164 | { |
|
|
165 | int x = i + dx; |
|
|
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; |
|
|
172 | } |
|
|
173 | |
|
|
174 | return false; |
|
|
175 | } |
|
|
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 | } |
277 | |
246 | |
278 | /* 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 |
279 | * 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 |
280 | * 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 |
281 | * 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 |
282 | * remove anything. It depends on the |
251 | * remove anything. It depends on the |
283 | * global, previously-set variable, "wall_name" |
252 | * global, previously-set variable, "wall_name" |
284 | */ |
253 | */ |
285 | |
|
|
286 | object * |
254 | object * |
287 | retrofit_joined_wall (maptile *the_map, int i, int j, int insert_flag, random_map_params *RP) |
255 | retrofit_joined_wall (maptile *the_map, int i, int j, int insert_flag, random_map_params *RP) |
288 | { |
256 | { |
289 | /* 1 = wall to left, |
257 | /* 1 = wall to left, |
290 | * 2 = wall to right, |
258 | * 2 = wall to right, |
… | |
… | |
296 | object *the_wall = 0; |
264 | object *the_wall = 0; |
297 | object *new_wall = 0; |
265 | object *new_wall = 0; |
298 | archetype *wall_arch = 0; |
266 | archetype *wall_arch = 0; |
299 | |
267 | |
300 | /* first find the wall */ |
268 | /* first find the wall */ |
301 | 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) |
302 | 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) |
303 | break; |
271 | break; |
304 | |
|
|
305 | |
272 | |
306 | /* 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 |
307 | * signal that later. |
274 | * signal that later. |
308 | */ |
275 | */ |
309 | 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)) |
… | |
… | |
326 | RP->wall_name[l] = 0; |
293 | RP->wall_name[l] = 0; |
327 | break; |
294 | break; |
328 | } |
295 | } |
329 | } |
296 | } |
330 | |
297 | |
331 | surround_index = surround_flag4 (the_map, i, j, RP); |
|
|
332 | /* This would be a lot cleaner to just us a lookup table, |
|
|
333 | * eg, wall_suffix[surround_index] |
|
|
334 | */ |
|
|
335 | switch (surround_index) |
|
|
336 | { |
|
|
337 | case 0: |
|
|
338 | strcat (RP->wall_name, "_0"); |
298 | strcat (RP->wall_name, "_"); |
339 | break; |
299 | strcat (RP->wall_name, wall_suffix [surround_flag4 (the_map, i, j)]); |
340 | case 1: |
|
|
341 | strcat (RP->wall_name, "_1_3"); |
|
|
342 | break; |
|
|
343 | case 2: |
|
|
344 | strcat (RP->wall_name, "_1_4"); |
|
|
345 | break; |
|
|
346 | case 3: |
|
|
347 | strcat (RP->wall_name, "_2_1_2"); |
|
|
348 | break; |
|
|
349 | case 4: |
|
|
350 | strcat (RP->wall_name, "_1_2"); |
|
|
351 | break; |
|
|
352 | case 5: |
|
|
353 | strcat (RP->wall_name, "_2_2_4"); |
|
|
354 | break; |
|
|
355 | case 6: |
|
|
356 | strcat (RP->wall_name, "_2_2_1"); |
|
|
357 | break; |
|
|
358 | case 7: |
|
|
359 | strcat (RP->wall_name, "_3_1"); |
|
|
360 | break; |
|
|
361 | case 8: |
|
|
362 | strcat (RP->wall_name, "_1_1"); |
|
|
363 | break; |
|
|
364 | case 9: |
|
|
365 | strcat (RP->wall_name, "_2_2_3"); |
|
|
366 | break; |
|
|
367 | case 10: |
|
|
368 | strcat (RP->wall_name, "_2_2_2"); |
|
|
369 | break; |
|
|
370 | case 11: |
|
|
371 | strcat (RP->wall_name, "_3_3"); |
|
|
372 | break; |
|
|
373 | case 12: |
|
|
374 | strcat (RP->wall_name, "_2_1_1"); |
|
|
375 | break; |
|
|
376 | case 13: |
|
|
377 | strcat (RP->wall_name, "_3_4"); |
|
|
378 | break; |
|
|
379 | case 14: |
|
|
380 | strcat (RP->wall_name, "_3_2"); |
|
|
381 | break; |
|
|
382 | case 15: |
|
|
383 | strcat (RP->wall_name, "_4"); |
|
|
384 | break; |
|
|
385 | } |
|
|
386 | |
300 | |
387 | wall_arch = archetype::find (RP->wall_name); |
301 | wall_arch = archetype::find (RP->wall_name); |
388 | |
302 | |
389 | if (!wall_arch) |
303 | if (!wall_arch) |
390 | { |
304 | { |
391 | new_wall = arch_to_object (wall_arch); |
305 | new_wall = wall_arch->instance (); |
392 | new_wall->x = i; |
306 | new_wall->x = i; |
393 | new_wall->y = j; |
307 | new_wall->y = j; |
394 | |
308 | |
395 | if (the_wall && the_wall->map) |
309 | if (the_wall && the_wall->map) |
396 | { |
|
|
397 | the_wall->remove (); |
|
|
398 | the_wall->destroy (); |
310 | the_wall->destroy (); |
399 | } |
|
|
400 | |
311 | |
401 | the_wall->move_block = MOVE_ALL; |
312 | the_wall->move_block = MOVE_ALL; |
402 | 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); |
403 | } |
314 | } |
404 | |
315 | |