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.19 by root, Wed Jan 17 12:36:31 2007 UTC vs.
Revision 1.23 by root, Sat Jan 27 00:56:48 2007 UTC

1/* 1/*
2<<<<<<< treasure.C
3 * CrossFire, A Multiplayer game 2 * CrossFire, A Multiplayer game
4 * 3 *
5 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team 4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
6 * Copyright (C) 2001 Mark Wedel & Crossfire Development Team 5 * Copyright (C) 2001 Mark Wedel & Crossfire Development Team
7 * Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (C) 1992 Frank Tore Johansen
20 * along with this program; if not, write to the Free Software 19 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 * 21 *
23 * The authors can be reached via e-mail at <crossfire@schmorp.de> 22 * The authors can be reached via e-mail at <crossfire@schmorp.de>
24 */ 23 */
25=======
26 * CrossFire, A Multiplayer game for X-windows
27 *
28 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
29 * Copyright (C) 2001 Mark Wedel & Crossfire Development Team
30 * Copyright (C) 1992 Frank Tore Johansen
31 *
32 * This program is free software; you can redistribute it and/or modify
33 * it under the terms of the GNU General Public License as published by
34 * the Free Software Foundation; either version 2 of the License, or
35 * (at your option) any later version.
36 *
37 * This program is distributed in the hope that it will be useful,
38 * but WITHOUT ANY WARRANTY; without even the implied warranty of
39 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
40 * GNU General Public License for more details.
41 *
42 * You should have received a copy of the GNU General Public License
43 * along with this program; if not, write to the Free Software
44 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
45 *
46 * The authors can be reached via e-mail at <crossfire@schmorp.de>
47 */
48>>>>>>> 1.18
49 24
50/* placing treasure in maps, where appropriate. */ 25/* placing treasure in maps, where appropriate. */
51 26
52#include <global.h> 27#include <global.h>
53#include <random_map.h> 28#include <random_map.h>
99 74
100 /* bail out if treasure isn't wanted. */ 75 /* bail out if treasure isn't wanted. */
101 if (treasure_style) 76 if (treasure_style)
102 if (!strcmp (treasure_style, "none")) 77 if (!strcmp (treasure_style, "none"))
103 return; 78 return;
79
104 if (treasureoptions <= 0) 80 if (treasureoptions <= 0)
105 treasureoptions = RANDOM () % (2 * LAST_OPTION); 81 treasureoptions = RANDOM () % (2 * LAST_OPTION);
106 82
107 /* filter out the mutually exclusive options */ 83 /* filter out the mutually exclusive options */
108 if ((treasureoptions & RICH) && (treasureoptions & SPARSE)) 84 if ((treasureoptions & RICH) && (treasureoptions & SPARSE))
109 { 85 {
110 if (RANDOM () % 2) 86 if (rndm (2))
111 treasureoptions -= 1; 87 treasureoptions -= 1;
112 else 88 else
113 treasureoptions -= 2; 89 treasureoptions -= 2;
114 } 90 }
115 91
126 102
127 /* get the style map */ 103 /* get the style map */
128 sprintf (styledirname, "%s", "/styles/treasurestyles"); 104 sprintf (styledirname, "%s", "/styles/treasurestyles");
129 sprintf (stylefilepath, "%s/%s", styledirname, treasure_style); 105 sprintf (stylefilepath, "%s/%s", styledirname, treasure_style);
130 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 }
131 113
132 /* all the treasure at one spot in the map. */ 114 /* all the treasure at one spot in the map. */
133 if (treasureoptions & CONCENTRATED) 115 if (treasureoptions & CONCENTRATED)
134 { 116 {
135 117
488 return theMonsterToFind; 470 return theMonsterToFind;
489 } 471 }
490 } 472 }
491 473
492 /* 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 */
493 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++)
494 { 476 {
495 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);
496 if (theMonsterToFind != NULL) 478 if (theMonsterToFind != NULL)
497 return theMonsterToFind; 479 return theMonsterToFind;
498 } 480 }
561 room_free_spots_x[number_of_free_spots_in_room] = x; 543 room_free_spots_x[number_of_free_spots_in_room] = x;
562 room_free_spots_y[number_of_free_spots_in_room] = y; 544 room_free_spots_y[number_of_free_spots_in_room] = y;
563 number_of_free_spots_in_room++; 545 number_of_free_spots_in_room++;
564 546
565 /* 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 */
566 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++)
567 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);
568 550
569} 551}
570 552
571/* 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. */
685 *cx = -1; 667 *cx = -1;
686 *cy = -1; 668 *cy = -1;
687 } 669 }
688} 670}
689 671
690
691void 672void
692remove_monsters (int x, int y, maptile *map) 673remove_monsters (int x, int y, maptile *map)
693{ 674{
694 object *tmp; 675 object *tmp;
695 676
696 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)
697 if (QUERY_FLAG (tmp, FLAG_ALIVE)) 678 if (QUERY_FLAG (tmp, FLAG_ALIVE))
698 { 679 {
699 if (tmp->head) 680 if (tmp->head)
700 tmp = tmp->head; 681 tmp = tmp->head;
701 tmp->remove (); 682 tmp->remove ();
704 if (tmp == NULL) 685 if (tmp == NULL)
705 break; 686 break;
706 }; 687 };
707} 688}
708 689
709
710/* 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
711 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
712 it'll remove any monsters it finds.*/ 692 it'll remove any monsters it finds.*/
713
714object ** 693object **
715surround_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)
716{ 695{
717 int i; 696 int i;
718 char *doors[2]; 697 char *doors[2];
735 /* place doors in all the 8 adjacent unblocked squares. */ 714 /* place doors in all the 8 adjacent unblocked squares. */
736 for (i = 1; i < 9; i++) 715 for (i = 1; i < 9; i++)
737 { 716 {
738 int x1 = x + freearr_x[i], y1 = y + freearr_y[i]; 717 int x1 = x + freearr_x[i], y1 = y + freearr_y[i];
739 718
740 if (!wall_blocked (map, x1, y1) || layout[x1][y1] == '>') 719 if (!wall_blocked (map, x1, y1) && layout[x1][y1] == '>')
741 { /* place a door */ 720 { /* place a door */
721 remove_monsters (x1, y1, map);
722
742 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]);
743 724 map->insert (new_door, x1, y1);
744 new_door->x = x + freearr_x[i];
745 new_door->y = y + freearr_y[i];
746 remove_monsters (new_door->x, new_door->y, map);
747 insert_ob_in_map (new_door, map, NULL, 0);
748 doorlist[ndoors_made] = new_door; 725 doorlist[ndoors_made] = new_door;
749 ndoors_made++; 726 ndoors_made++;
750 } 727 }
751 } 728 }
729
752 return doorlist; 730 return doorlist;
753} 731}
754 732
755 733
756/* 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. */
800 } 778 }
801 else 779 else
802 { 780 {
803 layout[x][y] = 1; 781 layout[x][y] = 1;
804 /* 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 */
805 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++)
806 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);
807 } 785 }
808} 786}
809 787
810/* 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