1 | |
|
|
2 | /* |
|
|
3 | * static char *rcsid_exit_c = |
|
|
4 | * "$Id: exit.C,v 1.4 2006/09/10 16:06:37 root Exp $"; |
|
|
5 | */ |
|
|
6 | |
|
|
7 | /* |
1 | /* |
8 | CrossFire, A Multiplayer game for X-windows |
2 | CrossFire, A Multiplayer game for X-windows |
9 | |
3 | |
10 | Copyright (C) 2001 Mark Wedel & Crossfire Development Team |
4 | Copyright (C) 2001 Mark Wedel & Crossfire Development Team |
11 | Copyright (C) 1992 Frank Tore Johansen |
5 | Copyright (C) 1992 Frank Tore Johansen |
… | |
… | |
22 | |
16 | |
23 | You should have received a copy of the GNU General Public License |
17 | You should have received a copy of the GNU General Public License |
24 | along with this program; if not, write to the Free Software |
18 | along with this program; if not, write to the Free Software |
25 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
26 | |
20 | |
27 | The authors can be reached via e-mail at crossfire-devel@real-time.com |
21 | The authors can be reached via e-mail at <crossfire@schmorp.de> |
28 | */ |
22 | */ |
29 | |
23 | |
30 | #include <global.h> |
24 | #include <global.h> |
31 | #include <random_map.h> |
25 | #include <random_map.h> |
32 | #include <sproto.h> |
26 | #include <sproto.h> |
… | |
… | |
112 | break; |
106 | break; |
113 | } |
107 | } |
114 | } |
108 | } |
115 | } |
109 | } |
116 | |
110 | |
117 | |
|
|
118 | |
|
|
119 | |
|
|
120 | |
|
|
121 | |
|
|
122 | /* orientation: 0 means random, |
111 | /* orientation: 0 means random, |
123 | 1 means descending dungeon |
112 | 1 means descending dungeon |
124 | 2 means ascending dungeon |
113 | 2 means ascending dungeon |
125 | 3 means rightward |
114 | 3 means rightward |
126 | 4 means leftward |
115 | 4 means leftward |
127 | 5 means northward |
116 | 5 means northward |
128 | 6 means southward |
117 | 6 means southward |
129 | */ |
118 | */ |
130 | |
|
|
131 | void |
119 | void |
132 | place_exits (mapstruct *map, char **maze, char *exitstyle, int orientation, RMParms * RP) |
120 | place_exits (maptile *map, char **maze, char *exitstyle, int orientation, RMParms *RP) |
133 | { |
121 | { |
134 | char styledirname[256]; |
122 | char styledirname[256]; |
135 | mapstruct *style_map_down = 0; /* harder maze */ |
123 | maptile *style_map_down = 0; /* harder maze */ |
136 | mapstruct *style_map_up = 0; /* easier maze */ |
124 | maptile *style_map_up = 0; /* easier maze */ |
137 | object *the_exit_down; /* harder maze */ |
125 | object *the_exit_down; /* harder maze */ |
138 | object *the_exit_up; /* easier maze */ |
126 | object *the_exit_up; /* easier maze */ |
139 | object *random_sign; /* magic mouth saying this is a random map. */ |
127 | object *random_sign; /* magic mouth saying this is a random map. */ |
140 | char buf[512]; |
128 | char buf[512]; |
141 | int cx = -1, cy = -1; /* location of a map center */ |
129 | int cx = -1, cy = -1; /* location of a map center */ |
… | |
… | |
177 | style_map_down = style_map_up; |
165 | style_map_down = style_map_up; |
178 | break; |
166 | break; |
179 | } |
167 | } |
180 | } |
168 | } |
181 | if (style_map_up == 0) |
169 | if (style_map_up == 0) |
182 | the_exit_up = arch_to_object (find_archetype ("exit")); |
170 | the_exit_up = arch_to_object (archetype::find ("exit")); |
183 | else |
171 | else |
184 | { |
172 | { |
185 | object *tmp; |
173 | object *tmp; |
186 | |
174 | |
187 | tmp = pick_random_object (style_map_up); |
175 | tmp = pick_random_object (style_map_up); |
… | |
… | |
189 | } |
177 | } |
190 | |
178 | |
191 | /* we need a down exit only if we're recursing. */ |
179 | /* we need a down exit only if we're recursing. */ |
192 | if (RP->dungeon_level < RP->dungeon_depth || RP->final_map[0] != 0) |
180 | if (RP->dungeon_level < RP->dungeon_depth || RP->final_map[0] != 0) |
193 | if (style_map_down == 0) |
181 | if (style_map_down == 0) |
194 | the_exit_down = arch_to_object (find_archetype ("exit")); |
182 | the_exit_down = arch_to_object (archetype::find ("exit")); |
195 | else |
183 | else |
196 | { |
184 | { |
197 | object *tmp; |
185 | object *tmp; |
198 | |
186 | |
199 | tmp = pick_random_object (style_map_down); |
187 | tmp = pick_random_object (style_map_down); |
… | |
… | |
268 | |
256 | |
269 | insert_ob_in_map (the_exit_up, map, NULL, 0); |
257 | insert_ob_in_map (the_exit_up, map, NULL, 0); |
270 | maze[the_exit_up->x][the_exit_up->y] = '<'; |
258 | maze[the_exit_up->x][the_exit_up->y] = '<'; |
271 | |
259 | |
272 | /* set the starting x,y for this map */ |
260 | /* set the starting x,y for this map */ |
273 | MAP_ENTER_X (map) = the_exit_up->x; |
261 | map->enter_x = the_exit_up->x; |
274 | MAP_ENTER_Y (map) = the_exit_up->y; |
262 | map->enter_y = the_exit_up->y; |
275 | |
263 | |
276 | /* first, look for a '>' character */ |
264 | /* first, look for a '>' character */ |
277 | find_in_layout (0, '>', &downx, &downy, maze, RP); |
265 | find_in_layout (0, '>', &downx, &downy, maze, RP); |
278 | /* if no > is found use C */ |
266 | /* if no > is found use C */ |
279 | if (downx == -1) |
267 | if (downx == -1) |
… | |
… | |
320 | write_map_parameters_to_string (buf, RP); |
308 | write_map_parameters_to_string (buf, RP); |
321 | the_exit_down->msg = buf; |
309 | the_exit_down->msg = buf; |
322 | /* the identifier for making a random map. */ |
310 | /* the identifier for making a random map. */ |
323 | if (RP->dungeon_level >= RP->dungeon_depth && RP->final_map[0] != 0) |
311 | if (RP->dungeon_level >= RP->dungeon_depth && RP->final_map[0] != 0) |
324 | { |
312 | { |
325 | mapstruct *new_map; |
313 | maptile *new_map; |
326 | object *the_exit_back = arch_to_object (the_exit_up->arch), *tmp; |
314 | object *the_exit_back = arch_to_object (the_exit_up->arch), *tmp; |
327 | |
315 | |
328 | #if 0 |
316 | #if 0 |
329 | /* I'm not sure if there was any reason to change the path to the |
317 | /* I'm not sure if there was any reason to change the path to the |
330 | * map other than to maybe make it more descriptive in the 'maps' |
318 | * map other than to maybe make it more descriptive in the 'maps' |
… | |
… | |
337 | /* give the final map a name */ |
325 | /* give the final map a name */ |
338 | sprintf (new_map_name, "%sfinal_map", RP->final_map); |
326 | sprintf (new_map_name, "%sfinal_map", RP->final_map); |
339 | /* set the exit down. */ |
327 | /* set the exit down. */ |
340 | #endif |
328 | #endif |
341 | /* load it */ |
329 | /* load it */ |
342 | if ((new_map = ready_map_name (RP->final_map, 0)) == NULL) |
330 | if (!(new_map = maptile::find_map (RP->final_map, 0))) |
343 | return; |
331 | return; |
344 | |
332 | |
|
|
333 | new_map->load (); |
|
|
334 | |
345 | the_exit_down->slaying = RP->final_map; |
335 | the_exit_down->slaying = RP->final_map; |
346 | strcpy (new_map->path, RP->final_map); |
|
|
347 | |
336 | |
348 | for (tmp = GET_MAP_OB (new_map, MAP_ENTER_X (new_map), MAP_ENTER_Y (new_map)); tmp; tmp = tmp->above) |
337 | for (tmp = new_map->at (new_map->enter_x, new_map->enter_y).bot; tmp; tmp = tmp->above) |
349 | /* Remove exit back to previous random map. There should only be one |
338 | /* Remove exit back to previous random map. There should only be one |
350 | * which is why we break out. To try to process more than one |
339 | * which is why we break out. To try to process more than one |
351 | * would require keeping a 'next' pointer, ad free_object kills tmp, which |
340 | * would require keeping a 'next' pointer, ad free_object kills tmp, which |
352 | * breaks the for loop. |
341 | * breaks the for loop. |
353 | */ |
342 | */ |
354 | if (tmp->type == EXIT && EXIT_PATH (tmp) && !strncmp (EXIT_PATH (tmp), "/random/", 8)) |
343 | if (tmp->type == EXIT && EXIT_PATH (tmp) && !strncmp (EXIT_PATH (tmp), "/random/", 8)) |
355 | { |
344 | { |
356 | remove_ob (tmp); |
345 | tmp->destroy (); |
357 | free_object (tmp); |
|
|
358 | break; |
346 | break; |
359 | } |
347 | } |
360 | |
348 | |
361 | if (final_map_exit == 1) |
349 | if (final_map_exit == 1) |
362 | { |
350 | { |
363 | /* setup the exit back */ |
351 | /* setup the exit back */ |
364 | the_exit_back->slaying = map->path; |
352 | the_exit_back->slaying = map->path; |
365 | the_exit_back->stats.hp = the_exit_down->x; |
353 | the_exit_back->stats.hp = the_exit_down->x; |
366 | the_exit_back->stats.sp = the_exit_down->y; |
354 | the_exit_back->stats.sp = the_exit_down->y; |
367 | the_exit_back->x = MAP_ENTER_X (new_map); |
355 | the_exit_back->x = new_map->enter_x; |
368 | the_exit_back->y = MAP_ENTER_Y (new_map); |
356 | the_exit_back->y = new_map->enter_y; |
369 | |
357 | |
370 | insert_ob_in_map (the_exit_back, new_map, NULL, 0); |
358 | insert_ob_in_map (the_exit_back, new_map, NULL, 0); |
371 | } |
359 | } |
372 | |
360 | |
373 | set_map_timeout (new_map); /* So it gets swapped out */ |
361 | set_map_timeout (new_map); /* So it gets swapped out */ |
… | |
… | |
382 | } |
370 | } |
383 | } |
371 | } |
384 | |
372 | |
385 | } |
373 | } |
386 | |
374 | |
387 | |
|
|
388 | |
|
|
389 | /* this function unblocks the exits. We blocked them to |
375 | /* this function unblocks the exits. We blocked them to |
390 | keep things from being dumped on them during the other |
376 | keep things from being dumped on them during the other |
391 | phases of random map generation. */ |
377 | phases of random map generation. */ |
392 | void |
378 | void |
393 | unblock_exits (mapstruct *map, char **maze, RMParms * RP) |
379 | unblock_exits (maptile *map, char **maze, RMParms * RP) |
394 | { |
380 | { |
395 | int i = 0, j = 0; |
381 | int i = 0, j = 0; |
396 | object *walk; |
382 | object *walk; |
397 | |
383 | |
398 | for (i = 0; i < RP->Xsize; i++) |
384 | for (i = 0; i < RP->Xsize; i++) |
399 | for (j = 0; j < RP->Ysize; j++) |
385 | for (j = 0; j < RP->Ysize; j++) |
400 | if (maze[i][j] == '>' || maze[i][j] == '<') |
386 | if (maze[i][j] == '>' || maze[i][j] == '<') |
401 | { |
387 | { |
402 | for (walk = get_map_ob (map, i, j); walk != NULL; walk = walk->above) |
388 | for (walk = GET_MAP_OB (map, i, j); walk != NULL; walk = walk->above) |
403 | { |
389 | { |
404 | if (walk->move_block == MOVE_ALL && walk->type != LOCKED_DOOR) |
390 | if (walk->move_block == MOVE_ALL && walk->type != LOCKED_DOOR) |
405 | { |
391 | { |
406 | walk->move_block = MOVE_BLOCK_DEFAULT; |
392 | walk->move_block = MOVE_BLOCK_DEFAULT; |
407 | update_object (walk, UP_OBJ_CHANGE); |
393 | update_object (walk, UP_OBJ_CHANGE); |