ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/random_maps/treasure.C
(Generate patch)

Comparing deliantra/server/random_maps/treasure.C (file contents):
Revision 1.20 by root, Thu Jan 18 00:06:56 2007 UTC vs.
Revision 1.23 by root, Sat Jan 27 00:56:48 2007 UTC

74 74
75 /* bail out if treasure isn't wanted. */ 75 /* bail out if treasure isn't wanted. */
76 if (treasure_style) 76 if (treasure_style)
77 if (!strcmp (treasure_style, "none")) 77 if (!strcmp (treasure_style, "none"))
78 return; 78 return;
79
79 if (treasureoptions <= 0) 80 if (treasureoptions <= 0)
80 treasureoptions = RANDOM () % (2 * LAST_OPTION); 81 treasureoptions = RANDOM () % (2 * LAST_OPTION);
81 82
82 /* filter out the mutually exclusive options */ 83 /* filter out the mutually exclusive options */
83 if ((treasureoptions & RICH) && (treasureoptions & SPARSE)) 84 if ((treasureoptions & RICH) && (treasureoptions & SPARSE))
84 { 85 {
85 if (RANDOM () % 2) 86 if (rndm (2))
86 treasureoptions -= 1; 87 treasureoptions -= 1;
87 else 88 else
88 treasureoptions -= 2; 89 treasureoptions -= 2;
89 } 90 }
90 91
101 102
102 /* get the style map */ 103 /* get the style map */
103 sprintf (styledirname, "%s", "/styles/treasurestyles"); 104 sprintf (styledirname, "%s", "/styles/treasurestyles");
104 sprintf (stylefilepath, "%s/%s", styledirname, treasure_style); 105 sprintf (stylefilepath, "%s/%s", styledirname, treasure_style);
105 style_map = find_style (styledirname, treasure_style, -1); 106 style_map = find_style (styledirname, treasure_style, -1);
107
108 if (!style_map)
109 {
110 LOG (llevError, "unable to load style map %s %s.\n", styledirname, treasure_style);
111 return;
112 }
106 113
107 /* all the treasure at one spot in the map. */ 114 /* all the treasure at one spot in the map. */
108 if (treasureoptions & CONCENTRATED) 115 if (treasureoptions & CONCENTRATED)
109 { 116 {
110 117
463 return theMonsterToFind; 470 return theMonsterToFind;
464 } 471 }
465 } 472 }
466 473
467 /* now search all the 8 squares around recursively for a monster,in random order */ 474 /* now search all the 8 squares around recursively for a monster,in random order */
468 for (i = RANDOM () % 8, j = 0; j < 8 && theMonsterToFind == NULL; i++, j++) 475 for (i = rndm (8), j = 0; j < 8 && theMonsterToFind == NULL; i++, j++)
469 { 476 {
470 theMonsterToFind = find_monster_in_room_recursive (layout, map, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], RP); 477 theMonsterToFind = find_monster_in_room_recursive (layout, map, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], RP);
471 if (theMonsterToFind != NULL) 478 if (theMonsterToFind != NULL)
472 return theMonsterToFind; 479 return theMonsterToFind;
473 } 480 }
536 room_free_spots_x[number_of_free_spots_in_room] = x; 543 room_free_spots_x[number_of_free_spots_in_room] = x;
537 room_free_spots_y[number_of_free_spots_in_room] = y; 544 room_free_spots_y[number_of_free_spots_in_room] = y;
538 number_of_free_spots_in_room++; 545 number_of_free_spots_in_room++;
539 546
540 /* now search all the 8 squares around recursively for free spots,in random order */ 547 /* now search all the 8 squares around recursively for free spots,in random order */
541 for (i = RANDOM () % 8, j = 0; j < 8 && theMonsterToFind == NULL; i++, j++) 548 for (i = rndm (8), j = 0; j < 8 && theMonsterToFind == NULL; i++, j++)
542 find_spot_in_room_recursive (layout, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], RP); 549 find_spot_in_room_recursive (layout, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], RP);
543 550
544} 551}
545 552
546/* find a random non-blocked spot in this room to drop a key. */ 553/* find a random non-blocked spot in this room to drop a key. */
660 *cx = -1; 667 *cx = -1;
661 *cy = -1; 668 *cy = -1;
662 } 669 }
663} 670}
664 671
665
666void 672void
667remove_monsters (int x, int y, maptile *map) 673remove_monsters (int x, int y, maptile *map)
668{ 674{
669 object *tmp; 675 object *tmp;
670 676
671 for (tmp = GET_MAP_OB (map, x, y); tmp != NULL; tmp = tmp->above) 677 for (tmp = GET_MAP_OB (map, x, y); tmp; tmp = tmp->above)
672 if (QUERY_FLAG (tmp, FLAG_ALIVE)) 678 if (QUERY_FLAG (tmp, FLAG_ALIVE))
673 { 679 {
674 if (tmp->head) 680 if (tmp->head)
675 tmp = tmp->head; 681 tmp = tmp->head;
676 tmp->remove (); 682 tmp->remove ();
679 if (tmp == NULL) 685 if (tmp == NULL)
680 break; 686 break;
681 }; 687 };
682} 688}
683 689
684
685/* surrounds the point x,y by doors, so as to enclose something, like 690/* surrounds the point x,y by doors, so as to enclose something, like
686 a chest. It only goes as far as the 8 squares surrounding, and 691 a chest. It only goes as far as the 8 squares surrounding, and
687 it'll remove any monsters it finds.*/ 692 it'll remove any monsters it finds.*/
688
689object ** 693object **
690surround_by_doors (maptile *map, char **layout, int x, int y, int opts) 694surround_by_doors (maptile *map, char **layout, int x, int y, int opts)
691{ 695{
692 int i; 696 int i;
693 char *doors[2]; 697 char *doors[2];
710 /* place doors in all the 8 adjacent unblocked squares. */ 714 /* place doors in all the 8 adjacent unblocked squares. */
711 for (i = 1; i < 9; i++) 715 for (i = 1; i < 9; i++)
712 { 716 {
713 int x1 = x + freearr_x[i], y1 = y + freearr_y[i]; 717 int x1 = x + freearr_x[i], y1 = y + freearr_y[i];
714 718
715 if (!wall_blocked (map, x1, y1) || layout[x1][y1] == '>') 719 if (!wall_blocked (map, x1, y1) && layout[x1][y1] == '>')
716 { /* place a door */ 720 { /* place a door */
721 remove_monsters (x1, y1, map);
722
717 object *new_door = get_archetype ((freearr_x[i] == 0) ? doors[1] : doors[0]); 723 object *new_door = get_archetype (freearr_x[i] == 0 ? doors[1] : doors[0]);
718 724 map->insert (new_door, x1, y1);
719 new_door->x = x + freearr_x[i];
720 new_door->y = y + freearr_y[i];
721 remove_monsters (new_door->x, new_door->y, map);
722 insert_ob_in_map (new_door, map, NULL, 0);
723 doorlist[ndoors_made] = new_door; 725 doorlist[ndoors_made] = new_door;
724 ndoors_made++; 726 ndoors_made++;
725 } 727 }
726 } 728 }
729
727 return doorlist; 730 return doorlist;
728} 731}
729 732
730 733
731/* returns the first door in this square, or NULL if there isn't a door. */ 734/* returns the first door in this square, or NULL if there isn't a door. */
775 } 778 }
776 else 779 else
777 { 780 {
778 layout[x][y] = 1; 781 layout[x][y] = 1;
779 /* now search all the 8 squares around recursively for free spots,in random order */ 782 /* now search all the 8 squares around recursively for free spots,in random order */
780 for (i = RANDOM () % 8, j = 0; j < 8 && theMonsterToFind == NULL; i++, j++) 783 for (i = rndm (8), j = 0; j < 8 && theMonsterToFind == NULL; i++, j++)
781 find_doors_in_room_recursive (layout, map, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], doorlist, ndoors, RP); 784 find_doors_in_room_recursive (layout, map, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], doorlist, ndoors, RP);
782 } 785 }
783} 786}
784 787
785/* find a random non-blocked spot in this room to drop a key. */ 788/* find a random non-blocked spot in this room to drop a key. */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines