1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
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 (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2001 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2001 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992 Frank Tore Johansen |
6 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * the terms of the Affero GNU General Public License as published by the |
9 | * the terms of the Affero GNU General Public License as published by the |
… | |
… | |
109 | freeindex = -1; |
109 | freeindex = -1; |
110 | for (tries = 0; tries < 15 && freeindex == -1; tries++) |
110 | for (tries = 0; tries < 15 && freeindex == -1; tries++) |
111 | { |
111 | { |
112 | kx = rmg_rndm (RP->Xsize - 2) + 1; |
112 | kx = rmg_rndm (RP->Xsize - 2) + 1; |
113 | ky = rmg_rndm (RP->Ysize - 2) + 1; |
113 | ky = rmg_rndm (RP->Ysize - 2) + 1; |
114 | freeindex = find_free_spot (the_key, map, kx, ky, 1, SIZEOFFREE1 + 1); |
114 | freeindex = rmg_find_free_spot (the_key, map, kx, ky, 1, SIZEOFFREE1 + 1); |
115 | } |
115 | } |
116 | |
116 | |
117 | // can freeindex ever be < 0? |
117 | // can freeindex ever be < 0? |
118 | if (freeindex >= 0) |
118 | if (freeindex >= 0) |
119 | { |
119 | { |
… | |
… | |
192 | layout, (required) |
192 | layout, (required) |
193 | treasure style (may be empty or NULL, or "none" to cause no treasure.) |
193 | treasure style (may be empty or NULL, or "none" to cause no treasure.) |
194 | treasureoptions (may be 0 for random choices or positive) |
194 | treasureoptions (may be 0 for random choices or positive) |
195 | */ |
195 | */ |
196 | void |
196 | void |
197 | place_treasure (maptile *map, char **layout, char *treasure_style, int treasureoptions, random_map_params *RP) |
197 | place_treasure (maptile *map, char **layout, const char *treasure_style, int treasureoptions, random_map_params *RP) |
198 | { |
198 | { |
199 | char styledirname[1024]; |
|
|
200 | char stylefilepath[1024]; |
|
|
201 | maptile *style_map = 0; |
|
|
202 | int num_treasures; |
199 | int num_treasures; |
203 | |
200 | |
204 | /* bail out if treasure isn't wanted. */ |
201 | /* bail out if treasure isn't wanted. */ |
205 | if (treasure_style) |
202 | if (treasure_style) |
206 | if (!strcmp (treasure_style, "none")) |
203 | if (!strcmp (treasure_style, "none")) |
… | |
… | |
228 | |
225 | |
229 | if (num_treasures <= 0) |
226 | if (num_treasures <= 0) |
230 | return; |
227 | return; |
231 | |
228 | |
232 | /* get the style map */ |
229 | /* get the style map */ |
233 | sprintf (styledirname, "%s", "/styles/treasurestyles"); |
230 | maptile *style_map = find_style ("/styles/treasurestyles", treasure_style, RP->difficulty); |
234 | sprintf (stylefilepath, "%s/%s", styledirname, treasure_style); |
|
|
235 | style_map = find_style (styledirname, treasure_style, -1); |
|
|
236 | |
231 | |
237 | if (!style_map) |
232 | if (!style_map) |
238 | { |
233 | { |
239 | LOG (llevError, "unable to load style map %s %s.\n", styledirname, treasure_style); |
234 | LOG (llevError, "unable to load style map %s %s.\n", "/styles/treasurestyles", treasure_style); |
240 | return; |
235 | return; |
241 | } |
236 | } |
242 | |
237 | |
243 | /* all the treasure at one spot in the map. */ |
238 | /* all the treasure at one spot in the map. */ |
244 | if (treasureoptions & CONCENTRATED) |
239 | if (treasureoptions & CONCENTRATED) |
… | |
… | |
384 | } |
379 | } |
385 | |
380 | |
386 | /* stick a trap in the chest if required */ |
381 | /* stick a trap in the chest if required */ |
387 | if (treasureoptions & TRAPPED) |
382 | if (treasureoptions & TRAPPED) |
388 | { |
383 | { |
389 | maptile *trap_map = find_style ("/styles/trapstyles", "traps", -1); |
384 | maptile *trap_map = find_style ("/styles/trapstyles", "traps", RP->difficulty); |
390 | |
385 | |
391 | if (trap_map) |
386 | if (trap_map) |
392 | { |
387 | { |
393 | object *the_trap = trap_map->pick_random_object (rmg_rndm); |
388 | object *the_trap = trap_map->pick_random_object (rmg_rndm); |
394 | |
389 | |
… | |
… | |
439 | /* don't bother searching this square unless the map says life exists. */ |
434 | /* don't bother searching this square unless the map says life exists. */ |
440 | if (GET_MAP_FLAGS (map, lx, ly) & P_IS_ALIVE) |
435 | if (GET_MAP_FLAGS (map, lx, ly) & P_IS_ALIVE) |
441 | { |
436 | { |
442 | object *the_monster = GET_MAP_OB (map, lx, ly); |
437 | object *the_monster = GET_MAP_OB (map, lx, ly); |
443 | |
438 | |
444 | for (; the_monster != NULL && (!QUERY_FLAG (the_monster, FLAG_MONSTER)); the_monster = the_monster->above); |
439 | for (; the_monster != NULL && (!the_monster->flag [FLAG_MONSTER]); the_monster = the_monster->above); |
445 | if (the_monster && QUERY_FLAG (the_monster, FLAG_MONSTER)) |
440 | if (the_monster && the_monster->flag [FLAG_MONSTER]) |
446 | return the_monster; |
441 | return the_monster; |
447 | } |
442 | } |
448 | } |
443 | } |
449 | return NULL; |
444 | return NULL; |
450 | } |
445 | } |
… | |
… | |
478 | if (GET_MAP_FLAGS (map, x, y) & P_IS_ALIVE) |
473 | if (GET_MAP_FLAGS (map, x, y) & P_IS_ALIVE) |
479 | { |
474 | { |
480 | object *the_monster = GET_MAP_OB (map, x, y); |
475 | object *the_monster = GET_MAP_OB (map, x, y); |
481 | |
476 | |
482 | /* check off this point */ |
477 | /* check off this point */ |
483 | for (; the_monster != NULL && (!QUERY_FLAG (the_monster, FLAG_ALIVE)); the_monster = the_monster->above); |
478 | for (; the_monster != NULL && (!the_monster->flag [FLAG_ALIVE]); the_monster = the_monster->above); |
484 | if (the_monster && QUERY_FLAG (the_monster, FLAG_ALIVE)) |
479 | if (the_monster && the_monster->flag [FLAG_ALIVE]) |
485 | { |
480 | { |
486 | theMonsterToFind = the_monster; |
481 | theMonsterToFind = the_monster; |
487 | return theMonsterToFind; |
482 | return theMonsterToFind; |
488 | } |
483 | } |
489 | } |
484 | } |
… | |
… | |
502 | /* sets up some data structures: the _recursive form does the |
497 | /* sets up some data structures: the _recursive form does the |
503 | real work. */ |
498 | real work. */ |
504 | static object * |
499 | static object * |
505 | find_monster_in_room (maptile *map, int x, int y, random_map_params *RP) |
500 | find_monster_in_room (maptile *map, int x, int y, random_map_params *RP) |
506 | { |
501 | { |
507 | Layout layout2 (RP); |
502 | Layout layout2 (map->width, map->height); |
508 | |
503 | |
509 | layout2->clear (); |
504 | // find walls |
510 | |
|
|
511 | /* allocate and copy the layout, converting C to 0. */ |
|
|
512 | for (int i = 0; i < layout2->w; i++) |
505 | for (int i = 0; i < layout2.w; i++) |
513 | for (int j = 0; j < layout2->h; j++) |
506 | for (int j = 0; j < layout2.h; j++) |
514 | if (wall_blocked (map, i, j)) |
507 | layout2[i][j] = wall_blocked (map, i, j) ? '#' : 0; |
515 | layout2[i][j] = '#'; |
|
|
516 | |
508 | |
517 | theMonsterToFind = 0; |
509 | theMonsterToFind = 0; |
518 | theMonsterToFind = find_monster_in_room_recursive (layout2, map, x, y, RP); |
510 | theMonsterToFind = find_monster_in_room_recursive (layout2, map, x, y, RP); |
519 | |
|
|
520 | layout2.free (); |
|
|
521 | |
511 | |
522 | return theMonsterToFind; |
512 | return theMonsterToFind; |
523 | } |
513 | } |
524 | |
514 | |
525 | /* a datastructure needed by find_spot_in_room and find_spot_in_room_recursive */ |
515 | /* a datastructure needed by find_spot_in_room and find_spot_in_room_recursive */ |
… | |
… | |
614 | { |
604 | { |
615 | int lx, ly, sindex; |
605 | int lx, ly, sindex; |
616 | |
606 | |
617 | lx = x + freearr_x[i]; |
607 | lx = x + freearr_x[i]; |
618 | ly = y + freearr_y[i]; |
608 | ly = y + freearr_y[i]; |
619 | sindex = surround_flag3 (map, lx, ly, RP); |
609 | sindex = surround_flag3 (map, lx, ly); |
620 | /* if it's blocked on 3 sides, it's enclosed */ |
610 | /* if it's blocked on 3 sides, it's enclosed */ |
621 | if (sindex == 7 || sindex == 11 || sindex == 13 || sindex == 14) |
611 | if (sindex == 7 || sindex == 11 || sindex == 13 || sindex == 14) |
622 | { |
612 | { |
623 | *cx = lx; |
613 | *cx = lx; |
624 | *cy = ly; |
614 | *cy = ly; |
… | |
… | |
632 | { |
622 | { |
633 | int lx, ly, sindex; |
623 | int lx, ly, sindex; |
634 | |
624 | |
635 | lx = x + freearr_x[i]; |
625 | lx = x + freearr_x[i]; |
636 | ly = y + freearr_y[i]; |
626 | ly = y + freearr_y[i]; |
637 | sindex = surround_flag3 (map, lx, ly, RP); |
627 | sindex = surround_flag3 (map, lx, ly); |
638 | /* if it's blocked on 3 sides, it's enclosed */ |
628 | /* if it's blocked on 3 sides, it's enclosed */ |
639 | if (sindex == 3 || sindex == 5 || sindex == 9 || sindex == 6 || sindex == 10 || sindex == 12) |
629 | if (sindex == 3 || sindex == 5 || sindex == 9 || sindex == 6 || sindex == 10 || sindex == 12) |
640 | { |
630 | { |
641 | *cx = lx; |
631 | *cx = lx; |
642 | *cy = ly; |
632 | *cy = ly; |
… | |
… | |
649 | { |
639 | { |
650 | int lx, ly, sindex; |
640 | int lx, ly, sindex; |
651 | |
641 | |
652 | lx = x + freearr_x[i]; |
642 | lx = x + freearr_x[i]; |
653 | ly = y + freearr_y[i]; |
643 | ly = y + freearr_y[i]; |
654 | sindex = surround_flag3 (map, lx, ly, RP); |
644 | sindex = surround_flag3 (map, lx, ly); |
655 | /* if it's blocked on 3 sides, it's enclosed */ |
645 | /* if it's blocked on 3 sides, it's enclosed */ |
656 | if (sindex) |
646 | if (sindex) |
657 | { |
647 | { |
658 | *cx = lx; |
648 | *cx = lx; |
659 | *cy = ly; |
649 | *cy = ly; |
660 | return; |
650 | return; |
661 | } |
651 | } |
662 | } |
652 | } |
663 | /* give up and return the closest free spot. */ |
653 | /* give up and return the closest free spot. */ |
664 | i = find_free_spot (archetype::find (shstr_chest), map, x, y, 1, SIZEOFFREE1 + 1); |
654 | i = rmg_find_free_spot (archetype::find (shstr_chest), map, x, y, 1, SIZEOFFREE1 + 1); |
665 | |
655 | |
666 | if (i != -1) |
656 | if (i != -1) |
667 | { |
657 | { |
668 | *cx = x + freearr_x[i]; |
658 | *cx = x + freearr_x[i]; |
669 | *cy = y + freearr_y[i]; |
659 | *cy = y + freearr_y[i]; |
… | |
… | |
796 | int i, j; |
786 | int i, j; |
797 | int ndoors = 0; |
787 | int ndoors = 0; |
798 | |
788 | |
799 | object **doorlist = (object **)calloc (sizeof (int), 1024); |
789 | object **doorlist = (object **)calloc (sizeof (int), 1024); |
800 | |
790 | |
801 | LayoutData layout2 (RP->Xsize, RP->Ysize); |
791 | Layout layout2 (RP->Xsize, RP->Ysize); |
802 | layout2.clear (); |
792 | layout2.clear (); |
803 | |
793 | |
804 | /* allocate and copy the layout, converting C to 0. */ |
794 | /* allocate and copy the layout, converting C to 0. */ |
805 | for (i = 0; i < RP->Xsize; i++) |
795 | for (i = 0; i < RP->Xsize; i++) |
806 | for (j = 0; j < RP->Ysize; j++) |
796 | for (j = 0; j < RP->Ysize; j++) |