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.27 by elmex, Sun Apr 15 14:15:14 2007 UTC vs.
Revision 1.35 by root, Mon Apr 14 22:41:17 2008 UTC

1/* 1/*
2 * CrossFire, A Multiplayer game 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team 4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (C) 2001 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version. 11 * (at your option) any later version.
12 * 12 *
13 * 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,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * 20 *
22 * The authors can be reached via e-mail at <crossfire@schmorp.de> 21 * The authors can be reached via e-mail to <support@deliantra.net>
23 */ 22 */
24 23
25/* placing treasure in maps, where appropriate. */ 24/* placing treasure in maps, where appropriate. */
26 25
27#include <global.h> 26#include <global.h>
119 } 118 }
120 119
121 /* all the treasure at one spot in the map. */ 120 /* all the treasure at one spot in the map. */
122 if (treasureoptions & CONCENTRATED) 121 if (treasureoptions & CONCENTRATED)
123 { 122 {
124
125 /* map_layout_style global, and is previously set */ 123 /* map_layout_style global, and is previously set */
126 switch (RP->map_layout_style) 124 switch (RP->map_layout_style)
127 { 125 {
128 case LAYOUT_ONION: 126 case LAYOUT_ONION:
129 case LAYOUT_SPIRAL: 127 case LAYOUT_SPIRAL:
137 for (j = 0; j < RP->Ysize; j++) 135 for (j = 0; j < RP->Ysize; j++)
138 { 136 {
139 if (layout[i][j] == 'C' || layout[i][j] == '>') 137 if (layout[i][j] == 'C' || layout[i][j] == '>')
140 { 138 {
141 int tdiv = RP->symmetry_used; 139 int tdiv = RP->symmetry_used;
142 object **doorlist;
143 object *chest; 140 object *chest;
144 141
145 if (tdiv == 3) 142 if (tdiv == 3)
146 tdiv = 2; /* this symmetry uses a divisor of 2 */ 143 tdiv = 2; /* this symmetry uses a divisor of 2 */
144
147 /* don't put a chest on an exit. */ 145 /* don't put a chest on an exit. */
148 chest = place_chest (treasureoptions, i, j, map, style_map, num_treasures / tdiv, RP); 146 chest = place_chest (treasureoptions, i, j, map, style_map, num_treasures / tdiv, RP);
147
149 if (!chest) 148 if (!chest)
150 continue; /* if no chest was placed NEXT */ 149 continue; /* if no chest was placed NEXT */
150
151 if (treasureoptions & (DOORED | HIDDEN)) 151 if (treasureoptions & (DOORED | HIDDEN))
152 { 152 {
153 doorlist = find_doors_in_room (map, i, j, RP); 153 object **doorlist = find_doors_in_room (map, i, j, RP);
154 lock_and_hide_doors (doorlist, map, treasureoptions, RP); 154 lock_and_hide_doors (doorlist, map, treasureoptions, RP);
155 free (doorlist); 155 free (doorlist);
156 } 156 }
157 } 157 }
158 } 158 }
170 while (i == -1 && tries < 100) 170 while (i == -1 && tries < 100)
171 { 171 {
172 i = rndm (RP->Xsize - 2) + 1; 172 i = rndm (RP->Xsize - 2) + 1;
173 j = rndm (RP->Ysize - 2) + 1; 173 j = rndm (RP->Ysize - 2) + 1;
174 find_enclosed_spot (map, &i, &j, RP); 174 find_enclosed_spot (map, &i, &j, RP);
175
175 if (wall_blocked (map, i, j)) 176 if (wall_blocked (map, i, j))
176 i = -1; 177 i = -1;
178
177 tries++; 179 tries++;
178 } 180 }
181
179 chest = place_chest (treasureoptions, i, j, map, style_map, num_treasures, RP); 182 chest = place_chest (treasureoptions, i, j, map, style_map, num_treasures, RP);
183
180 if (!chest) 184 if (!chest)
181 return; 185 return;
186
182 i = chest->x; 187 i = chest->x;
183 j = chest->y; 188 j = chest->y;
184 if (treasureoptions & (DOORED | HIDDEN)) 189 if (treasureoptions & (DOORED | HIDDEN))
185 { 190 {
186 doorlist = surround_by_doors (map, layout, i, j, treasureoptions); 191 doorlist = surround_by_doors (map, layout, i, j, treasureoptions);
204} 209}
205 210
206/* put a chest into the map, near x and y, with the treasure style 211/* put a chest into the map, near x and y, with the treasure style
207 determined (may be null, or may be a treasure list from lib/treasures, 212 determined (may be null, or may be a treasure list from lib/treasures,
208 if the global variable "treasurestyle" is set to that treasure list's name */ 213 if the global variable "treasurestyle" is set to that treasure list's name */
209
210object * 214object *
211place_chest (int treasureoptions, int x, int y, maptile *map, maptile *style_map, int n_treasures, random_map_params *RP) 215place_chest (int treasureoptions, int x, int y, maptile *map, maptile *style_map, int n_treasures, random_map_params *RP)
212{ 216{
213 object *the_chest; 217 object *the_chest;
214 int i, xl, yl; 218 int i, xl, yl;
250 the_chest->randomitems = tlist; 254 the_chest->randomitems = tlist;
251 the_chest->stats.hp = n_treasures; 255 the_chest->stats.hp = n_treasures;
252 } 256 }
253#endif 257#endif
254 { /* neither style_map no treasure list given */ 258 { /* neither style_map no treasure list given */
255 treasurelist *tlist = find_treasurelist ("chest"); 259 treasurelist *tlist = treasurelist::find ("chest");
256 260
257 the_chest->randomitems = tlist; 261 the_chest->randomitems = tlist;
258 the_chest->stats.hp = n_treasures; 262 the_chest->stats.hp = n_treasures;
259 } 263 }
260 264
429 the_key->y = ky; 433 the_key->y = ky;
430 insert_ob_in_map (the_key, map, NULL, 0); 434 insert_ob_in_map (the_key, map, NULL, 0);
431 return 1; 435 return 1;
432 } 436 }
433 437
434 insert_ob_in_ob (the_key, the_keymaster); 438 insert_ob_in_ob (the_key, the_keymaster->head_ ());
435 return 1; 439 return 1;
436} 440}
437 441
438 442
439 443
502 /* allocate and copy the layout, converting C to 0. */ 506 /* allocate and copy the layout, converting C to 0. */
503 for (i = 0; i < RP->Xsize; i++) 507 for (i = 0; i < RP->Xsize; i++)
504 { 508 {
505 layout2[i] = (char *) calloc (sizeof (char), RP->Ysize); 509 layout2[i] = (char *) calloc (sizeof (char), RP->Ysize);
506 for (j = 0; j < RP->Ysize; j++) 510 for (j = 0; j < RP->Ysize; j++)
507 {
508 if (wall_blocked (map, i, j)) 511 if (wall_blocked (map, i, j))
509 layout2[i][j] = '#'; 512 layout2[i][j] = '#';
510 }
511 } 513 }
514
512 theMonsterToFind = find_monster_in_room_recursive (layout2, map, x, y, RP); 515 theMonsterToFind = find_monster_in_room_recursive (layout2, map, x, y, RP);
513 516
514 /* deallocate the temp. layout */ 517 /* deallocate the temp. layout */
515 for (i = 0; i < RP->Xsize; i++) 518 for (i = 0; i < RP->Xsize; i++)
516 {
517 free (layout2[i]); 519 free (layout2[i]);
518 } 520
519 free (layout2); 521 free (layout2);
520 522
521 return theMonsterToFind; 523 return theMonsterToFind;
522} 524}
523 525
658 *cy = ly; 660 *cy = ly;
659 return; 661 return;
660 } 662 }
661 } 663 }
662 /* give up and return the closest free spot. */ 664 /* give up and return the closest free spot. */
663 i = find_free_spot (&archetype::find ("chest")->clone, map, x, y, 1, SIZEOFFREE1 + 1); 665 i = find_free_spot (archetype::find ("chest"), map, x, y, 1, SIZEOFFREE1 + 1);
664 666
665 if (i != -1) 667 if (i != -1)
666 { 668 {
667 *cx = x + freearr_x[i]; 669 *cx = x + freearr_x[i];
668 *cy = y + freearr_y[i]; 670 *cy = y + freearr_y[i];
747 if (tmp->type == DOOR || tmp->type == LOCKED_DOOR) 749 if (tmp->type == DOOR || tmp->type == LOCKED_DOOR)
748 return tmp; 750 return tmp;
749 return NULL; 751 return NULL;
750} 752}
751 753
752
753/* the workhorse routine, which finds the doors in a room */ 754/* the workhorse routine, which finds the doors in a room */
754void 755void
755find_doors_in_room_recursive (char **layout, maptile *map, int x, int y, object **doorlist, int *ndoors, random_map_params *RP) 756find_doors_in_room_recursive (char **layout, maptile *map, int x, int y, object **doorlist, int *ndoors, random_map_params *RP)
756{ 757{
757 int i, j; 758 int i, j;
771 layout[x][y] = 1; 772 layout[x][y] = 1;
772 door = door_in_square (map, x, y); 773 door = door_in_square (map, x, y);
773 if (door) 774 if (door)
774 { 775 {
775 doorlist[*ndoors] = door; 776 doorlist[*ndoors] = door;
777
776 if (*ndoors > 1022) /* eek! out of memory */ 778 if (*ndoors > 1022) /* eek! out of memory */
777 { 779 {
778 LOG (llevError, "find_doors_in_room_recursive:Too many doors for memory allocated!\n"); 780 LOG (llevError, "find_doors_in_room_recursive:Too many doors for memory allocated!\n");
779 return; 781 return;
780 } 782 }
796 798
797/* find a random non-blocked spot in this room to drop a key. */ 799/* find a random non-blocked spot in this room to drop a key. */
798object ** 800object **
799find_doors_in_room (maptile *map, int x, int y, random_map_params *RP) 801find_doors_in_room (maptile *map, int x, int y, random_map_params *RP)
800{ 802{
801 char **layout2;
802 object **doorlist;
803 int i, j; 803 int i, j;
804 int ndoors = 0; 804 int ndoors = 0;
805 805
806 doorlist = (object **) calloc (sizeof (int), 1024); 806 object **doorlist = (object **)calloc (sizeof (int), 1024);
807 807
808 layout2 = (char **) calloc (sizeof (char *), RP->Xsize); 808 MazeData layout2 (RP->Xsize, RP->Ysize);
809
809 /* allocate and copy the layout, converting C to 0. */ 810 /* allocate and copy the layout, converting C to 0. */
810 for (i = 0; i < RP->Xsize; i++) 811 for (i = 0; i < RP->Xsize; i++)
811 {
812 layout2[i] = (char *) calloc (sizeof (char), RP->Ysize);
813 for (j = 0; j < RP->Ysize; j++) 812 for (j = 0; j < RP->Ysize; j++)
814 {
815 if (wall_blocked (map, i, j)) 813 if (wall_blocked (map, i, j))
816 layout2[i][j] = '#'; 814 layout2[i][j] = '#';
817 }
818 }
819 815
820 /* setup num_free_spots and room_free_spots */ 816 /* setup num_free_spots and room_free_spots */
821 find_doors_in_room_recursive (layout2, map, x, y, doorlist, &ndoors, RP); 817 find_doors_in_room_recursive (layout2, map, x, y, doorlist, &ndoors, RP);
822 818
823 /* deallocate the temp. layout */
824 for (i = 0; i < RP->Xsize; i++)
825 free (layout2[i]);
826
827 free (layout2);
828 return doorlist; 819 return doorlist;
829} 820}
830
831
832 821
833/* locks and/or hides all the doors in doorlist, or does nothing if 822/* locks and/or hides all the doors in doorlist, or does nothing if
834 opts doesn't say to lock/hide doors. */ 823 opts doesn't say to lock/hide doors. */
835
836void 824void
837lock_and_hide_doors (object **doorlist, maptile *map, int opts, random_map_params *RP) 825lock_and_hide_doors (object **doorlist, maptile *map, int opts, random_map_params *RP)
838{ 826{
839 object *door; 827 object *door;
840 int i; 828 int i;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines