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 Marc Alexander Lehmann / Robin Redeker / the Deliantra 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 | * 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> |
25 | #include <random_map.h> |
26 | #include <random_map.h> |
26 | #include <rproto.h> |
27 | #include <rproto.h> |
27 | |
28 | |
28 | /* Put in the walls and autojoin them. */ |
29 | /* Put in the walls and autojoin them. */ |
29 | |
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 | |
|
|
34 | int |
33 | int |
35 | surround_flag (char **layout, int i, int j, random_map_params * RP) |
34 | surround_flag (char **layout, int i, int j, random_map_params *RP) |
36 | { |
35 | { |
37 | /* 1 = wall to left, |
36 | /* 1 = wall to left, |
38 | 2 = wall to right, |
37 | 2 = wall to right, |
39 | 4 = wall above |
38 | 4 = wall above |
40 | 8 = wall below */ |
39 | 8 = wall below */ |
… | |
… | |
54 | |
53 | |
55 | /* like surround_flag, but only walls count. |
54 | /* like surround_flag, but only walls count. |
56 | */ |
55 | */ |
57 | |
56 | |
58 | int |
57 | int |
59 | surround_flag2 (char **layout, int i, int j, random_map_params * RP) |
58 | surround_flag2 (char **layout, int i, int j, random_map_params *RP) |
60 | { |
59 | { |
61 | /* 1 = wall to left, |
60 | /* 1 = wall to left, |
62 | 2 = wall to right, |
61 | 2 = wall to right, |
63 | 4 = wall above |
62 | 4 = wall above |
64 | 8 = wall below */ |
63 | 8 = wall below */ |
… | |
… | |
80 | * Since this is part of the random map code, presumption |
79 | * Since this is part of the random map code, presumption |
81 | * is that this is not a tiled map. |
80 | * is that this is not a tiled map. |
82 | * What is considered blocking and not is somewhat hard coded. |
81 | * What is considered blocking and not is somewhat hard coded. |
83 | */ |
82 | */ |
84 | int |
83 | int |
85 | surround_flag3 (maptile *map, sint16 i, sint16 j, random_map_params * RP) |
84 | surround_flag3 (maptile *map, sint16 i, sint16 j, random_map_params *RP) |
86 | { |
85 | { |
87 | /* |
86 | /* |
88 | * 1 = blocked to left, |
87 | * 1 = blocked to left, |
89 | * 2 = blocked to right, |
88 | * 2 = blocked to right, |
90 | * 4 = blocked above |
89 | * 4 = blocked above |
91 | * 8 = blocked below |
90 | * 8 = blocked below |
92 | */ |
91 | */ |
93 | |
92 | |
94 | int surround_index = 0; |
93 | int surround_index = 0; |
95 | |
94 | |
|
|
95 | // don't forget to update the mapspace! |
|
|
96 | if (i > 0) map->at (i - 1, j ).update (); |
|
|
97 | if (i < RP->Xsize - 1) map->at (i + 1, j ).update (); |
|
|
98 | if (j > 0) map->at (i , j - 1).update (); |
|
|
99 | if (j < RP->Ysize - 1) map->at (i , j + 1).update (); |
|
|
100 | |
96 | if ((i > 0) && (GET_MAP_MOVE_BLOCK (map, i - 1, j) & ~MOVE_BLOCK_DEFAULT)) |
101 | if ((i > 0) && (GET_MAP_MOVE_BLOCK (map, i - 1, j) & MOVE_WALK)) |
97 | surround_index |= 1; |
102 | surround_index |= 1; |
98 | if ((i < RP->Xsize - 1) && (GET_MAP_MOVE_BLOCK (map, i + 1, j) & ~MOVE_BLOCK_DEFAULT)) |
103 | if ((i < RP->Xsize - 1) && (GET_MAP_MOVE_BLOCK (map, i + 1, j) & MOVE_WALK)) |
99 | surround_index |= 2; |
104 | surround_index |= 2; |
100 | if ((j > 0) && (GET_MAP_MOVE_BLOCK (map, i, j - 1) & ~MOVE_BLOCK_DEFAULT)) |
105 | if ((j > 0) && (GET_MAP_MOVE_BLOCK (map, i, j - 1) & MOVE_WALK)) |
101 | surround_index |= 4; |
106 | surround_index |= 4; |
102 | if ((j < RP->Ysize - 1) && (GET_MAP_MOVE_BLOCK (map, i, j + 1) & ~MOVE_BLOCK_DEFAULT)) |
107 | if ((j < RP->Ysize - 1) && (GET_MAP_MOVE_BLOCK (map, i, j + 1) & MOVE_WALK)) |
103 | surround_index |= 8; |
108 | surround_index |= 8; |
104 | |
109 | |
105 | return surround_index; |
110 | return surround_index; |
106 | } |
111 | } |
107 | |
112 | |
108 | /* like surround_flag2, except it checks a map, not a layout. */ |
113 | /* like surround_flag2, except it checks a map, not a layout. */ |
109 | |
114 | |
110 | int |
115 | int |
111 | surround_flag4 (maptile *map, int i, int j, random_map_params * RP) |
116 | surround_flag4 (maptile *map, int i, int j, random_map_params *RP) |
112 | { |
117 | { |
113 | /* 1 = blocked to left, |
118 | /* 1 = blocked to left, |
114 | 2 = blocked to right, |
119 | 2 = blocked to right, |
115 | 4 = blocked above |
120 | 4 = blocked above |
116 | 8 = blocked below */ |
121 | 8 = blocked below */ |
… | |
… | |
130 | |
135 | |
131 | /* takes a map and a layout, and puts walls in the map (picked from |
136 | /* takes a map and a layout, and puts walls in the map (picked from |
132 | w_style) at '#' marks. */ |
137 | w_style) at '#' marks. */ |
133 | |
138 | |
134 | void |
139 | void |
135 | make_map_walls (maptile *map, char **layout, char *w_style, random_map_params * RP) |
140 | make_map_walls (maptile *map, char **layout, char *w_style, random_map_params *RP) |
136 | { |
141 | { |
137 | char styledirname[256]; |
142 | char styledirname[1024]; |
138 | char stylefilepath[256]; |
143 | char stylefilepath[1024]; |
139 | maptile *style_map = 0; |
144 | maptile *style_map = 0; |
140 | object *the_wall; |
145 | object *the_wall; |
141 | |
146 | |
142 | /* get the style map */ |
147 | /* get the style map */ |
143 | if (!strcmp (w_style, "none")) |
148 | if (!strcmp (w_style, "none")) |
144 | return; |
149 | return; |
145 | sprintf (styledirname, "%s", "/styles/wallstyles"); |
150 | sprintf (styledirname, "%s", "/styles/wallstyles"); |
146 | sprintf (stylefilepath, "%s/%s", styledirname, w_style); |
151 | sprintf (stylefilepath, "%s/%s", styledirname, w_style); |
147 | style_map = find_style (styledirname, w_style, -1); |
152 | style_map = find_style (styledirname, w_style, -1); |
148 | if (style_map == 0) |
153 | if (!style_map) |
149 | return; |
154 | return; |
150 | |
155 | |
151 | /* fill up the map with the given floor style */ |
156 | /* fill up the map with the given floor style */ |
152 | if ((the_wall = pick_random_object (style_map)) != NULL) |
157 | if ((the_wall = style_map->pick_random_object (rmg_rndm))) |
153 | { |
158 | { |
154 | int i, j; |
159 | int i, j; |
155 | char *cp; |
160 | char *cp; |
156 | int joinedwalls = 0; |
161 | int joinedwalls = 0; |
157 | object *thiswall; |
162 | object *thiswall; |
158 | |
163 | |
159 | sprintf (RP->wall_name, "%s", &the_wall->arch->name); |
164 | sprintf (RP->wall_name, "%s", &the_wall->arch->archname); |
160 | if ((cp = strchr (RP->wall_name, '_')) != NULL) |
165 | if ((cp = strchr (RP->wall_name, '_')) != NULL) |
161 | { |
166 | { |
162 | *cp = 0; |
167 | *cp = 0; |
163 | joinedwalls = 1; |
168 | joinedwalls = 1; |
164 | } |
169 | } |
… | |
… | |
184 | |
189 | |
185 | /* picks the right wall type for this square, to make it look nice, |
190 | /* picks the right wall type for this square, to make it look nice, |
186 | and have everything nicely joined. It uses the layout. */ |
191 | and have everything nicely joined. It uses the layout. */ |
187 | |
192 | |
188 | object * |
193 | object * |
189 | pick_joined_wall (object *the_wall, char **layout, int i, int j, random_map_params * RP) |
194 | pick_joined_wall (object *the_wall, char **layout, int i, int j, random_map_params *RP) |
190 | { |
195 | { |
191 | /* 1 = wall to left, |
196 | /* 1 = wall to left, |
192 | 2 = wall to right, |
197 | 2 = wall to right, |
193 | 4 = wall above |
198 | 4 = wall above |
194 | 8 = wall below */ |
199 | 8 = wall below */ |
195 | int surround_index = 0; |
200 | int surround_index = 0; |
196 | int l; |
201 | int l; |
197 | char wall_name[64]; |
202 | char wall_name[1024]; |
198 | archetype *wall_arch = 0; |
203 | archetype *wall_arch = 0; |
199 | |
204 | |
200 | strcpy (wall_name, the_wall->arch->name); |
205 | assign (wall_name, the_wall->arch->archname); |
201 | |
206 | |
202 | /* conventionally, walls are named like this: |
207 | /* conventionally, walls are named like this: |
203 | wallname_wallcode, where wallcode indicates |
208 | wallname_wallcode, where wallcode indicates |
204 | a joinedness, and wallname is the wall. |
209 | a joinedness, and wallname is the wall. |
205 | this code depends on the convention for |
210 | this code depends on the convention for |
… | |
… | |
217 | |
222 | |
218 | surround_index = surround_flag2 (layout, i, j, RP); |
223 | surround_index = surround_flag2 (layout, i, j, RP); |
219 | |
224 | |
220 | switch (surround_index) |
225 | switch (surround_index) |
221 | { |
226 | { |
222 | case 0: |
227 | case 0: |
223 | strcat (wall_name, "_0"); |
228 | strcat (wall_name, "_0"); |
224 | break; |
229 | break; |
225 | case 1: |
230 | case 1: |
226 | strcat (wall_name, "_1_3"); |
231 | strcat (wall_name, "_1_3"); |
227 | break; |
232 | break; |
228 | case 2: |
233 | case 2: |
229 | strcat (wall_name, "_1_4"); |
234 | strcat (wall_name, "_1_4"); |
230 | break; |
235 | break; |
231 | case 3: |
236 | case 3: |
232 | strcat (wall_name, "_2_1_2"); |
237 | strcat (wall_name, "_2_1_2"); |
233 | break; |
238 | break; |
234 | case 4: |
239 | case 4: |
235 | strcat (wall_name, "_1_2"); |
240 | strcat (wall_name, "_1_2"); |
236 | break; |
241 | break; |
237 | case 5: |
242 | case 5: |
238 | strcat (wall_name, "_2_2_4"); |
243 | strcat (wall_name, "_2_2_4"); |
239 | break; |
244 | break; |
240 | case 6: |
245 | case 6: |
241 | strcat (wall_name, "_2_2_1"); |
246 | strcat (wall_name, "_2_2_1"); |
242 | break; |
247 | break; |
243 | case 7: |
248 | case 7: |
244 | strcat (wall_name, "_3_1"); |
249 | strcat (wall_name, "_3_1"); |
245 | break; |
250 | break; |
246 | case 8: |
251 | case 8: |
247 | strcat (wall_name, "_1_1"); |
252 | strcat (wall_name, "_1_1"); |
248 | break; |
253 | break; |
249 | case 9: |
254 | case 9: |
250 | strcat (wall_name, "_2_2_3"); |
255 | strcat (wall_name, "_2_2_3"); |
251 | break; |
256 | break; |
252 | case 10: |
257 | case 10: |
253 | strcat (wall_name, "_2_2_2"); |
258 | strcat (wall_name, "_2_2_2"); |
254 | break; |
259 | break; |
255 | case 11: |
260 | case 11: |
256 | strcat (wall_name, "_3_3"); |
261 | strcat (wall_name, "_3_3"); |
257 | break; |
262 | break; |
258 | case 12: |
263 | case 12: |
259 | strcat (wall_name, "_2_1_1"); |
264 | strcat (wall_name, "_2_1_1"); |
260 | break; |
265 | break; |
261 | case 13: |
266 | case 13: |
262 | strcat (wall_name, "_3_4"); |
267 | strcat (wall_name, "_3_4"); |
263 | break; |
268 | break; |
264 | case 14: |
269 | case 14: |
265 | strcat (wall_name, "_3_2"); |
270 | strcat (wall_name, "_3_2"); |
266 | break; |
271 | break; |
267 | case 15: |
272 | case 15: |
268 | strcat (wall_name, "_4"); |
273 | strcat (wall_name, "_4"); |
269 | break; |
274 | break; |
270 | } |
275 | } |
271 | wall_arch = archetype::find (wall_name); |
276 | wall_arch = archetype::find (wall_name); |
272 | |
277 | |
273 | return wall_arch |
278 | return wall_arch ? arch_to_object (wall_arch) : arch_to_object (the_wall->arch); |
274 | ? arch_to_object (wall_arch) |
|
|
275 | : arch_to_object (the_wall->arch); |
|
|
276 | } |
279 | } |
277 | |
280 | |
278 | |
281 | |
279 | /* this takes a map, and changes an existing wall to match what's blocked |
282 | /* this takes a map, and changes an existing wall to match what's blocked |
280 | * around it, counting only doors and walls as blocked. If insert_flag is |
283 | * around it, counting only doors and walls as blocked. If insert_flag is |
… | |
… | |
283 | * remove anything. It depends on the |
286 | * remove anything. It depends on the |
284 | * global, previously-set variable, "wall_name" |
287 | * global, previously-set variable, "wall_name" |
285 | */ |
288 | */ |
286 | |
289 | |
287 | object * |
290 | object * |
288 | retrofit_joined_wall (maptile *the_map, int i, int j, int insert_flag, random_map_params * RP) |
291 | retrofit_joined_wall (maptile *the_map, int i, int j, int insert_flag, random_map_params *RP) |
289 | { |
292 | { |
290 | /* 1 = wall to left, |
293 | /* 1 = wall to left, |
291 | * 2 = wall to right, |
294 | * 2 = wall to right, |
292 | * 4 = wall above |
295 | * 4 = wall above |
293 | * 8 = wall below |
296 | * 8 = wall below |
… | |
… | |
333 | /* This would be a lot cleaner to just us a lookup table, |
336 | /* This would be a lot cleaner to just us a lookup table, |
334 | * eg, wall_suffix[surround_index] |
337 | * eg, wall_suffix[surround_index] |
335 | */ |
338 | */ |
336 | switch (surround_index) |
339 | switch (surround_index) |
337 | { |
340 | { |
338 | case 0: |
341 | case 0: |
339 | strcat (RP->wall_name, "_0"); |
342 | strcat (RP->wall_name, "_0"); |
340 | break; |
343 | break; |
341 | case 1: |
344 | case 1: |
342 | strcat (RP->wall_name, "_1_3"); |
345 | strcat (RP->wall_name, "_1_3"); |
343 | break; |
346 | break; |
344 | case 2: |
347 | case 2: |
345 | strcat (RP->wall_name, "_1_4"); |
348 | strcat (RP->wall_name, "_1_4"); |
346 | break; |
349 | break; |
347 | case 3: |
350 | case 3: |
348 | strcat (RP->wall_name, "_2_1_2"); |
351 | strcat (RP->wall_name, "_2_1_2"); |
349 | break; |
352 | break; |
350 | case 4: |
353 | case 4: |
351 | strcat (RP->wall_name, "_1_2"); |
354 | strcat (RP->wall_name, "_1_2"); |
352 | break; |
355 | break; |
353 | case 5: |
356 | case 5: |
354 | strcat (RP->wall_name, "_2_2_4"); |
357 | strcat (RP->wall_name, "_2_2_4"); |
355 | break; |
358 | break; |
356 | case 6: |
359 | case 6: |
357 | strcat (RP->wall_name, "_2_2_1"); |
360 | strcat (RP->wall_name, "_2_2_1"); |
358 | break; |
361 | break; |
359 | case 7: |
362 | case 7: |
360 | strcat (RP->wall_name, "_3_1"); |
363 | strcat (RP->wall_name, "_3_1"); |
361 | break; |
364 | break; |
362 | case 8: |
365 | case 8: |
363 | strcat (RP->wall_name, "_1_1"); |
366 | strcat (RP->wall_name, "_1_1"); |
364 | break; |
367 | break; |
365 | case 9: |
368 | case 9: |
366 | strcat (RP->wall_name, "_2_2_3"); |
369 | strcat (RP->wall_name, "_2_2_3"); |
367 | break; |
370 | break; |
368 | case 10: |
371 | case 10: |
369 | strcat (RP->wall_name, "_2_2_2"); |
372 | strcat (RP->wall_name, "_2_2_2"); |
370 | break; |
373 | break; |
371 | case 11: |
374 | case 11: |
372 | strcat (RP->wall_name, "_3_3"); |
375 | strcat (RP->wall_name, "_3_3"); |
373 | break; |
376 | break; |
374 | case 12: |
377 | case 12: |
375 | strcat (RP->wall_name, "_2_1_1"); |
378 | strcat (RP->wall_name, "_2_1_1"); |
376 | break; |
379 | break; |
377 | case 13: |
380 | case 13: |
378 | strcat (RP->wall_name, "_3_4"); |
381 | strcat (RP->wall_name, "_3_4"); |
379 | break; |
382 | break; |
380 | case 14: |
383 | case 14: |
381 | strcat (RP->wall_name, "_3_2"); |
384 | strcat (RP->wall_name, "_3_2"); |
382 | break; |
385 | break; |
383 | case 15: |
386 | case 15: |
384 | strcat (RP->wall_name, "_4"); |
387 | strcat (RP->wall_name, "_4"); |
385 | break; |
388 | break; |
386 | } |
389 | } |
387 | |
390 | |
388 | wall_arch = archetype::find (RP->wall_name); |
391 | wall_arch = archetype::find (RP->wall_name); |
389 | |
392 | |
390 | if (!wall_arch) |
393 | if (!wall_arch) |
… | |
… | |
392 | new_wall = arch_to_object (wall_arch); |
395 | new_wall = arch_to_object (wall_arch); |
393 | new_wall->x = i; |
396 | new_wall->x = i; |
394 | new_wall->y = j; |
397 | new_wall->y = j; |
395 | |
398 | |
396 | if (the_wall && the_wall->map) |
399 | if (the_wall && the_wall->map) |
397 | { |
|
|
398 | the_wall->remove (); |
|
|
399 | the_wall->destroy (); |
400 | the_wall->destroy (); |
400 | } |
|
|
401 | |
401 | |
402 | the_wall->move_block = MOVE_ALL; |
402 | the_wall->move_block = MOVE_ALL; |
403 | insert_ob_in_map (new_wall, the_map, new_wall, INS_NO_MERGE | INS_NO_WALK_ON); |
403 | insert_ob_in_map (new_wall, the_map, new_wall, INS_NO_MERGE | INS_NO_WALK_ON); |
404 | } |
404 | } |
405 | |
405 | |