1 | /* |
1 | /* |
2 | CrossFire, A Multiplayer game for X-windows |
2 | * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. |
3 | |
3 | * |
|
|
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team |
4 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
5 | Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | |
7 | * |
7 | This program is free software; you can redistribute it and/or modify |
8 | * Crossfire TRT is free software: you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by |
9 | * it under the terms of the GNU General Public License as published by |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | * the Free Software Foundation, either version 3 of the License, or |
10 | (at your option) any later version. |
11 | * (at your 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 GNU General Public License |
18 | along with this program; if not, write to the Free Software |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * |
20 | |
|
|
21 | The authors can be reached via e-mail at <crossfire@schmorp.de> |
21 | * The authors can be reached via e-mail to <crossfire@schmorp.de> |
22 | */ |
22 | */ |
23 | |
23 | |
24 | #include <global.h> |
24 | #include <global.h> |
25 | #include <random_map.h> |
25 | #include <random_map.h> |
26 | #include <rproto.h> |
26 | #include <rproto.h> |
27 | |
27 | |
… | |
… | |
30 | |
30 | |
31 | /* given a layout and a coordinate, tell me which squares up/down/right/left |
31 | /* given a layout and a coordinate, tell me which squares up/down/right/left |
32 | are occupied. */ |
32 | are occupied. */ |
33 | |
33 | |
34 | int |
34 | int |
35 | surround_flag (char **layout, int i, int j, RMParms * RP) |
35 | surround_flag (char **layout, int i, int j, random_map_params *RP) |
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 */ |
… | |
… | |
54 | |
54 | |
55 | /* like surround_flag, but only walls count. |
55 | /* like surround_flag, but only walls count. |
56 | */ |
56 | */ |
57 | |
57 | |
58 | int |
58 | int |
59 | surround_flag2 (char **layout, int i, int j, RMParms * RP) |
59 | surround_flag2 (char **layout, int i, int j, random_map_params *RP) |
60 | { |
60 | { |
61 | /* 1 = wall to left, |
61 | /* 1 = wall to left, |
62 | 2 = wall to right, |
62 | 2 = wall to right, |
63 | 4 = wall above |
63 | 4 = wall above |
64 | 8 = wall below */ |
64 | 8 = wall below */ |
… | |
… | |
80 | * Since this is part of the random map code, presumption |
80 | * Since this is part of the random map code, presumption |
81 | * is that this is not a tiled map. |
81 | * is that this is not a tiled map. |
82 | * What is considered blocking and not is somewhat hard coded. |
82 | * What is considered blocking and not is somewhat hard coded. |
83 | */ |
83 | */ |
84 | int |
84 | int |
85 | surround_flag3 (maptile *map, sint16 i, sint16 j, RMParms * RP) |
85 | surround_flag3 (maptile *map, sint16 i, sint16 j, random_map_params *RP) |
86 | { |
86 | { |
87 | /* |
87 | /* |
88 | * 1 = blocked to left, |
88 | * 1 = blocked to left, |
89 | * 2 = blocked to right, |
89 | * 2 = blocked to right, |
90 | * 4 = blocked above |
90 | * 4 = blocked above |
91 | * 8 = blocked below |
91 | * 8 = blocked below |
92 | */ |
92 | */ |
93 | |
93 | |
94 | int surround_index = 0; |
94 | int surround_index = 0; |
95 | |
95 | |
|
|
96 | // don't forget to update the mapspace! |
|
|
97 | if (i > 0) map->at (i - 1, j ).update (); |
|
|
98 | if (i < RP->Xsize - 1) map->at (i + 1, j ).update (); |
|
|
99 | if (j > 0) map->at (i , j - 1).update (); |
|
|
100 | if (j < RP->Ysize - 1) map->at (i , j + 1).update (); |
|
|
101 | |
96 | if ((i > 0) && (GET_MAP_MOVE_BLOCK (map, i - 1, j) & ~MOVE_BLOCK_DEFAULT)) |
102 | if ((i > 0) && (GET_MAP_MOVE_BLOCK (map, i - 1, j) & MOVE_WALK)) |
97 | surround_index |= 1; |
103 | surround_index |= 1; |
98 | if ((i < RP->Xsize - 1) && (GET_MAP_MOVE_BLOCK (map, i + 1, j) & ~MOVE_BLOCK_DEFAULT)) |
104 | if ((i < RP->Xsize - 1) && (GET_MAP_MOVE_BLOCK (map, i + 1, j) & MOVE_WALK)) |
99 | surround_index |= 2; |
105 | surround_index |= 2; |
100 | if ((j > 0) && (GET_MAP_MOVE_BLOCK (map, i, j - 1) & ~MOVE_BLOCK_DEFAULT)) |
106 | if ((j > 0) && (GET_MAP_MOVE_BLOCK (map, i, j - 1) & MOVE_WALK)) |
101 | surround_index |= 4; |
107 | surround_index |= 4; |
102 | if ((j < RP->Ysize - 1) && (GET_MAP_MOVE_BLOCK (map, i, j + 1) & ~MOVE_BLOCK_DEFAULT)) |
108 | if ((j < RP->Ysize - 1) && (GET_MAP_MOVE_BLOCK (map, i, j + 1) & MOVE_WALK)) |
103 | surround_index |= 8; |
109 | surround_index |= 8; |
104 | |
110 | |
105 | return surround_index; |
111 | return surround_index; |
106 | } |
112 | } |
107 | |
113 | |
108 | /* like surround_flag2, except it checks a map, not a layout. */ |
114 | /* like surround_flag2, except it checks a map, not a layout. */ |
109 | |
115 | |
110 | int |
116 | int |
111 | surround_flag4 (maptile *map, int i, int j, RMParms * RP) |
117 | surround_flag4 (maptile *map, int i, int j, random_map_params *RP) |
112 | { |
118 | { |
113 | /* 1 = blocked to left, |
119 | /* 1 = blocked to left, |
114 | 2 = blocked to right, |
120 | 2 = blocked to right, |
115 | 4 = blocked above |
121 | 4 = blocked above |
116 | 8 = blocked below */ |
122 | 8 = blocked below */ |
… | |
… | |
130 | |
136 | |
131 | /* takes a map and a layout, and puts walls in the map (picked from |
137 | /* takes a map and a layout, and puts walls in the map (picked from |
132 | w_style) at '#' marks. */ |
138 | w_style) at '#' marks. */ |
133 | |
139 | |
134 | void |
140 | void |
135 | make_map_walls (maptile *map, char **layout, char *w_style, RMParms * RP) |
141 | make_map_walls (maptile *map, char **layout, char *w_style, random_map_params *RP) |
136 | { |
142 | { |
137 | char styledirname[256]; |
143 | char styledirname[1024]; |
138 | char stylefilepath[256]; |
144 | char stylefilepath[1024]; |
139 | maptile *style_map = 0; |
145 | maptile *style_map = 0; |
140 | object *the_wall; |
146 | object *the_wall; |
141 | |
147 | |
142 | /* get the style map */ |
148 | /* get the style map */ |
143 | if (!strcmp (w_style, "none")) |
149 | if (!strcmp (w_style, "none")) |
144 | return; |
150 | return; |
145 | sprintf (styledirname, "%s", "/styles/wallstyles"); |
151 | sprintf (styledirname, "%s", "/styles/wallstyles"); |
146 | sprintf (stylefilepath, "%s/%s", styledirname, w_style); |
152 | sprintf (stylefilepath, "%s/%s", styledirname, w_style); |
147 | style_map = find_style (styledirname, w_style, -1); |
153 | style_map = find_style (styledirname, w_style, -1); |
148 | if (style_map == 0) |
154 | if (!style_map) |
149 | return; |
155 | return; |
150 | |
156 | |
151 | /* fill up the map with the given floor style */ |
157 | /* fill up the map with the given floor style */ |
152 | if ((the_wall = pick_random_object (style_map)) != NULL) |
158 | if ((the_wall = style_map->pick_random_object ())) |
153 | { |
159 | { |
154 | int i, j; |
160 | int i, j; |
155 | char *cp; |
161 | char *cp; |
156 | int joinedwalls = 0; |
162 | int joinedwalls = 0; |
157 | object *thiswall; |
163 | object *thiswall; |
158 | |
164 | |
159 | sprintf (RP->wall_name, "%s", &the_wall->arch->name); |
165 | sprintf (RP->wall_name, "%s", &the_wall->arch->archname); |
160 | if ((cp = strchr (RP->wall_name, '_')) != NULL) |
166 | if ((cp = strchr (RP->wall_name, '_')) != NULL) |
161 | { |
167 | { |
162 | *cp = 0; |
168 | *cp = 0; |
163 | joinedwalls = 1; |
169 | joinedwalls = 1; |
164 | } |
170 | } |
… | |
… | |
184 | |
190 | |
185 | /* picks the right wall type for this square, to make it look nice, |
191 | /* picks the right wall type for this square, to make it look nice, |
186 | and have everything nicely joined. It uses the layout. */ |
192 | and have everything nicely joined. It uses the layout. */ |
187 | |
193 | |
188 | object * |
194 | object * |
189 | pick_joined_wall (object *the_wall, char **layout, int i, int j, RMParms * RP) |
195 | pick_joined_wall (object *the_wall, char **layout, int i, int j, random_map_params *RP) |
190 | { |
196 | { |
191 | /* 1 = wall to left, |
197 | /* 1 = wall to left, |
192 | 2 = wall to right, |
198 | 2 = wall to right, |
193 | 4 = wall above |
199 | 4 = wall above |
194 | 8 = wall below */ |
200 | 8 = wall below */ |
195 | int surround_index = 0; |
201 | int surround_index = 0; |
196 | int l; |
202 | int l; |
197 | char wall_name[64]; |
203 | char wall_name[1024]; |
198 | archetype *wall_arch = 0; |
204 | archetype *wall_arch = 0; |
199 | |
205 | |
200 | strcpy (wall_name, the_wall->arch->name); |
206 | assign (wall_name, the_wall->arch->archname); |
201 | |
207 | |
202 | /* conventionally, walls are named like this: |
208 | /* conventionally, walls are named like this: |
203 | wallname_wallcode, where wallcode indicates |
209 | wallname_wallcode, where wallcode indicates |
204 | a joinedness, and wallname is the wall. |
210 | a joinedness, and wallname is the wall. |
205 | this code depends on the convention for |
211 | this code depends on the convention for |
… | |
… | |
217 | |
223 | |
218 | surround_index = surround_flag2 (layout, i, j, RP); |
224 | surround_index = surround_flag2 (layout, i, j, RP); |
219 | |
225 | |
220 | switch (surround_index) |
226 | switch (surround_index) |
221 | { |
227 | { |
222 | case 0: |
228 | case 0: |
223 | strcat (wall_name, "_0"); |
229 | strcat (wall_name, "_0"); |
224 | break; |
230 | break; |
225 | case 1: |
231 | case 1: |
226 | strcat (wall_name, "_1_3"); |
232 | strcat (wall_name, "_1_3"); |
227 | break; |
233 | break; |
228 | case 2: |
234 | case 2: |
229 | strcat (wall_name, "_1_4"); |
235 | strcat (wall_name, "_1_4"); |
230 | break; |
236 | break; |
231 | case 3: |
237 | case 3: |
232 | strcat (wall_name, "_2_1_2"); |
238 | strcat (wall_name, "_2_1_2"); |
233 | break; |
239 | break; |
234 | case 4: |
240 | case 4: |
235 | strcat (wall_name, "_1_2"); |
241 | strcat (wall_name, "_1_2"); |
236 | break; |
242 | break; |
237 | case 5: |
243 | case 5: |
238 | strcat (wall_name, "_2_2_4"); |
244 | strcat (wall_name, "_2_2_4"); |
239 | break; |
245 | break; |
240 | case 6: |
246 | case 6: |
241 | strcat (wall_name, "_2_2_1"); |
247 | strcat (wall_name, "_2_2_1"); |
242 | break; |
248 | break; |
243 | case 7: |
249 | case 7: |
244 | strcat (wall_name, "_3_1"); |
250 | strcat (wall_name, "_3_1"); |
245 | break; |
251 | break; |
246 | case 8: |
252 | case 8: |
247 | strcat (wall_name, "_1_1"); |
253 | strcat (wall_name, "_1_1"); |
248 | break; |
254 | break; |
249 | case 9: |
255 | case 9: |
250 | strcat (wall_name, "_2_2_3"); |
256 | strcat (wall_name, "_2_2_3"); |
251 | break; |
257 | break; |
252 | case 10: |
258 | case 10: |
253 | strcat (wall_name, "_2_2_2"); |
259 | strcat (wall_name, "_2_2_2"); |
254 | break; |
260 | break; |
255 | case 11: |
261 | case 11: |
256 | strcat (wall_name, "_3_3"); |
262 | strcat (wall_name, "_3_3"); |
257 | break; |
263 | break; |
258 | case 12: |
264 | case 12: |
259 | strcat (wall_name, "_2_1_1"); |
265 | strcat (wall_name, "_2_1_1"); |
260 | break; |
266 | break; |
261 | case 13: |
267 | case 13: |
262 | strcat (wall_name, "_3_4"); |
268 | strcat (wall_name, "_3_4"); |
263 | break; |
269 | break; |
264 | case 14: |
270 | case 14: |
265 | strcat (wall_name, "_3_2"); |
271 | strcat (wall_name, "_3_2"); |
266 | break; |
272 | break; |
267 | case 15: |
273 | case 15: |
268 | strcat (wall_name, "_4"); |
274 | strcat (wall_name, "_4"); |
269 | break; |
275 | break; |
270 | } |
276 | } |
271 | wall_arch = archetype::find (wall_name); |
277 | wall_arch = archetype::find (wall_name); |
272 | if (wall_arch) |
|
|
273 | return arch_to_object (wall_arch); |
|
|
274 | else |
|
|
275 | { |
|
|
276 | nroferrors--; |
|
|
277 | return arch_to_object (the_wall->arch); |
|
|
278 | } |
|
|
279 | |
278 | |
280 | |
279 | return wall_arch ? arch_to_object (wall_arch) : arch_to_object (the_wall->arch); |
281 | } |
280 | } |
282 | |
281 | |
283 | |
282 | |
284 | /* this takes a map, and changes an existing wall to match what's blocked |
283 | /* 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 |
284 | * around it, counting only doors and walls as blocked. If insert_flag is |
… | |
… | |
288 | * remove anything. It depends on the |
287 | * remove anything. It depends on the |
289 | * global, previously-set variable, "wall_name" |
288 | * global, previously-set variable, "wall_name" |
290 | */ |
289 | */ |
291 | |
290 | |
292 | object * |
291 | object * |
293 | retrofit_joined_wall (maptile *the_map, int i, int j, int insert_flag, RMParms * RP) |
292 | retrofit_joined_wall (maptile *the_map, int i, int j, int insert_flag, random_map_params *RP) |
294 | { |
293 | { |
295 | /* 1 = wall to left, |
294 | /* 1 = wall to left, |
296 | * 2 = wall to right, |
295 | * 2 = wall to right, |
297 | * 4 = wall above |
296 | * 4 = wall above |
298 | * 8 = wall below |
297 | * 8 = wall below |
… | |
… | |
302 | object *the_wall = 0; |
301 | object *the_wall = 0; |
303 | object *new_wall = 0; |
302 | object *new_wall = 0; |
304 | archetype *wall_arch = 0; |
303 | archetype *wall_arch = 0; |
305 | |
304 | |
306 | /* first find the wall */ |
305 | /* first find the wall */ |
307 | for (the_wall = get_map_ob (the_map, i, j); the_wall != NULL; the_wall = the_wall->above) |
306 | for (the_wall = GET_MAP_OB (the_map, i, j); the_wall != NULL; the_wall = the_wall->above) |
308 | if ((the_wall->move_type & MOVE_WALK) && the_wall->type != EXIT && the_wall->type != TELEPORTER) |
307 | if ((the_wall->move_type & MOVE_WALK) && the_wall->type != EXIT && the_wall->type != TELEPORTER) |
309 | break; |
308 | break; |
310 | |
309 | |
311 | |
310 | |
312 | /* if what we found is a door, don't remove it, set the_wall to NULL to |
311 | /* if what we found is a door, don't remove it, set the_wall to NULL to |
… | |
… | |
338 | /* This would be a lot cleaner to just us a lookup table, |
337 | /* This would be a lot cleaner to just us a lookup table, |
339 | * eg, wall_suffix[surround_index] |
338 | * eg, wall_suffix[surround_index] |
340 | */ |
339 | */ |
341 | switch (surround_index) |
340 | switch (surround_index) |
342 | { |
341 | { |
343 | case 0: |
342 | case 0: |
344 | strcat (RP->wall_name, "_0"); |
343 | strcat (RP->wall_name, "_0"); |
345 | break; |
344 | break; |
346 | case 1: |
345 | case 1: |
347 | strcat (RP->wall_name, "_1_3"); |
346 | strcat (RP->wall_name, "_1_3"); |
348 | break; |
347 | break; |
349 | case 2: |
348 | case 2: |
350 | strcat (RP->wall_name, "_1_4"); |
349 | strcat (RP->wall_name, "_1_4"); |
351 | break; |
350 | break; |
352 | case 3: |
351 | case 3: |
353 | strcat (RP->wall_name, "_2_1_2"); |
352 | strcat (RP->wall_name, "_2_1_2"); |
354 | break; |
353 | break; |
355 | case 4: |
354 | case 4: |
356 | strcat (RP->wall_name, "_1_2"); |
355 | strcat (RP->wall_name, "_1_2"); |
357 | break; |
356 | break; |
358 | case 5: |
357 | case 5: |
359 | strcat (RP->wall_name, "_2_2_4"); |
358 | strcat (RP->wall_name, "_2_2_4"); |
360 | break; |
359 | break; |
361 | case 6: |
360 | case 6: |
362 | strcat (RP->wall_name, "_2_2_1"); |
361 | strcat (RP->wall_name, "_2_2_1"); |
363 | break; |
362 | break; |
364 | case 7: |
363 | case 7: |
365 | strcat (RP->wall_name, "_3_1"); |
364 | strcat (RP->wall_name, "_3_1"); |
366 | break; |
365 | break; |
367 | case 8: |
366 | case 8: |
368 | strcat (RP->wall_name, "_1_1"); |
367 | strcat (RP->wall_name, "_1_1"); |
369 | break; |
368 | break; |
370 | case 9: |
369 | case 9: |
371 | strcat (RP->wall_name, "_2_2_3"); |
370 | strcat (RP->wall_name, "_2_2_3"); |
372 | break; |
371 | break; |
373 | case 10: |
372 | case 10: |
374 | strcat (RP->wall_name, "_2_2_2"); |
373 | strcat (RP->wall_name, "_2_2_2"); |
375 | break; |
374 | break; |
376 | case 11: |
375 | case 11: |
377 | strcat (RP->wall_name, "_3_3"); |
376 | strcat (RP->wall_name, "_3_3"); |
378 | break; |
377 | break; |
379 | case 12: |
378 | case 12: |
380 | strcat (RP->wall_name, "_2_1_1"); |
379 | strcat (RP->wall_name, "_2_1_1"); |
381 | break; |
380 | break; |
382 | case 13: |
381 | case 13: |
383 | strcat (RP->wall_name, "_3_4"); |
382 | strcat (RP->wall_name, "_3_4"); |
384 | break; |
383 | break; |
385 | case 14: |
384 | case 14: |
386 | strcat (RP->wall_name, "_3_2"); |
385 | strcat (RP->wall_name, "_3_2"); |
387 | break; |
386 | break; |
388 | case 15: |
387 | case 15: |
389 | strcat (RP->wall_name, "_4"); |
388 | strcat (RP->wall_name, "_4"); |
390 | break; |
389 | break; |
391 | } |
390 | } |
|
|
391 | |
392 | wall_arch = archetype::find (RP->wall_name); |
392 | wall_arch = archetype::find (RP->wall_name); |
|
|
393 | |
393 | if (wall_arch != NULL) |
394 | if (!wall_arch) |
394 | { |
395 | { |
395 | new_wall = arch_to_object (wall_arch); |
396 | new_wall = arch_to_object (wall_arch); |
396 | new_wall->x = i; |
397 | new_wall->x = i; |
397 | new_wall->y = j; |
398 | new_wall->y = j; |
|
|
399 | |
398 | if (the_wall && the_wall->map) |
400 | if (the_wall && the_wall->map) |
399 | { |
401 | { |
400 | remove_ob (the_wall); |
402 | the_wall->remove (); |
401 | free_object (the_wall); |
403 | the_wall->destroy (); |
402 | } |
404 | } |
|
|
405 | |
403 | the_wall->move_block = MOVE_ALL; |
406 | the_wall->move_block = MOVE_ALL; |
404 | insert_ob_in_map (new_wall, the_map, new_wall, INS_NO_MERGE | INS_NO_WALK_ON); |
407 | insert_ob_in_map (new_wall, the_map, new_wall, INS_NO_MERGE | INS_NO_WALK_ON); |
405 | } |
408 | } |
406 | else |
409 | |
407 | nroferrors--; /* it's OK not to find an arch. */ |
|
|
408 | return new_wall; |
410 | return new_wall; |
409 | } |
411 | } |