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.33 by root, Fri Apr 11 21:09:53 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>
137 for (j = 0; j < RP->Ysize; j++) 136 for (j = 0; j < RP->Ysize; j++)
138 { 137 {
139 if (layout[i][j] == 'C' || layout[i][j] == '>') 138 if (layout[i][j] == 'C' || layout[i][j] == '>')
140 { 139 {
141 int tdiv = RP->symmetry_used; 140 int tdiv = RP->symmetry_used;
142 object **doorlist;
143 object *chest; 141 object *chest;
144 142
145 if (tdiv == 3) 143 if (tdiv == 3)
146 tdiv = 2; /* this symmetry uses a divisor of 2 */ 144 tdiv = 2; /* this symmetry uses a divisor of 2 */
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 }
250 the_chest->randomitems = tlist; 250 the_chest->randomitems = tlist;
251 the_chest->stats.hp = n_treasures; 251 the_chest->stats.hp = n_treasures;
252 } 252 }
253#endif 253#endif
254 { /* neither style_map no treasure list given */ 254 { /* neither style_map no treasure list given */
255 treasurelist *tlist = find_treasurelist ("chest"); 255 treasurelist *tlist = treasurelist::find ("chest");
256 256
257 the_chest->randomitems = tlist; 257 the_chest->randomitems = tlist;
258 the_chest->stats.hp = n_treasures; 258 the_chest->stats.hp = n_treasures;
259 } 259 }
260 260
429 the_key->y = ky; 429 the_key->y = ky;
430 insert_ob_in_map (the_key, map, NULL, 0); 430 insert_ob_in_map (the_key, map, NULL, 0);
431 return 1; 431 return 1;
432 } 432 }
433 433
434 insert_ob_in_ob (the_key, the_keymaster); 434 insert_ob_in_ob (the_key, the_keymaster->head_ ());
435 return 1; 435 return 1;
436} 436}
437 437
438 438
439 439
502 /* allocate and copy the layout, converting C to 0. */ 502 /* allocate and copy the layout, converting C to 0. */
503 for (i = 0; i < RP->Xsize; i++) 503 for (i = 0; i < RP->Xsize; i++)
504 { 504 {
505 layout2[i] = (char *) calloc (sizeof (char), RP->Ysize); 505 layout2[i] = (char *) calloc (sizeof (char), RP->Ysize);
506 for (j = 0; j < RP->Ysize; j++) 506 for (j = 0; j < RP->Ysize; j++)
507 {
508 if (wall_blocked (map, i, j)) 507 if (wall_blocked (map, i, j))
509 layout2[i][j] = '#'; 508 layout2[i][j] = '#';
510 }
511 } 509 }
510
512 theMonsterToFind = find_monster_in_room_recursive (layout2, map, x, y, RP); 511 theMonsterToFind = find_monster_in_room_recursive (layout2, map, x, y, RP);
513 512
514 /* deallocate the temp. layout */ 513 /* deallocate the temp. layout */
515 for (i = 0; i < RP->Xsize; i++) 514 for (i = 0; i < RP->Xsize; i++)
516 {
517 free (layout2[i]); 515 free (layout2[i]);
518 } 516
519 free (layout2); 517 free (layout2);
520 518
521 return theMonsterToFind; 519 return theMonsterToFind;
522} 520}
523 521
658 *cy = ly; 656 *cy = ly;
659 return; 657 return;
660 } 658 }
661 } 659 }
662 /* give up and return the closest free spot. */ 660 /* give up and return the closest free spot. */
663 i = find_free_spot (&archetype::find ("chest")->clone, map, x, y, 1, SIZEOFFREE1 + 1); 661 i = find_free_spot (archetype::find ("chest"), map, x, y, 1, SIZEOFFREE1 + 1);
664 662
665 if (i != -1) 663 if (i != -1)
666 { 664 {
667 *cx = x + freearr_x[i]; 665 *cx = x + freearr_x[i];
668 *cy = y + freearr_y[i]; 666 *cy = y + freearr_y[i];
747 if (tmp->type == DOOR || tmp->type == LOCKED_DOOR) 745 if (tmp->type == DOOR || tmp->type == LOCKED_DOOR)
748 return tmp; 746 return tmp;
749 return NULL; 747 return NULL;
750} 748}
751 749
752
753/* the workhorse routine, which finds the doors in a room */ 750/* the workhorse routine, which finds the doors in a room */
754void 751void
755find_doors_in_room_recursive (char **layout, maptile *map, int x, int y, object **doorlist, int *ndoors, random_map_params *RP) 752find_doors_in_room_recursive (char **layout, maptile *map, int x, int y, object **doorlist, int *ndoors, random_map_params *RP)
756{ 753{
757 int i, j; 754 int i, j;
771 layout[x][y] = 1; 768 layout[x][y] = 1;
772 door = door_in_square (map, x, y); 769 door = door_in_square (map, x, y);
773 if (door) 770 if (door)
774 { 771 {
775 doorlist[*ndoors] = door; 772 doorlist[*ndoors] = door;
773
776 if (*ndoors > 1022) /* eek! out of memory */ 774 if (*ndoors > 1022) /* eek! out of memory */
777 { 775 {
778 LOG (llevError, "find_doors_in_room_recursive:Too many doors for memory allocated!\n"); 776 LOG (llevError, "find_doors_in_room_recursive:Too many doors for memory allocated!\n");
779 return; 777 return;
780 } 778 }
796 794
797/* find a random non-blocked spot in this room to drop a key. */ 795/* find a random non-blocked spot in this room to drop a key. */
798object ** 796object **
799find_doors_in_room (maptile *map, int x, int y, random_map_params *RP) 797find_doors_in_room (maptile *map, int x, int y, random_map_params *RP)
800{ 798{
801 char **layout2;
802 object **doorlist;
803 int i, j; 799 int i, j;
804 int ndoors = 0; 800 int ndoors = 0;
805 801
806 doorlist = (object **) calloc (sizeof (int), 1024); 802 object **doorlist = (object **) calloc (sizeof (int), 1024);
807 803
808 layout2 = (char **) calloc (sizeof (char *), RP->Xsize); 804 MazeData layout2 (RP->Xsize, RP->Ysize);
805
809 /* allocate and copy the layout, converting C to 0. */ 806 /* allocate and copy the layout, converting C to 0. */
810 for (i = 0; i < RP->Xsize; i++) 807 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++) 808 for (j = 0; j < RP->Ysize; j++)
814 {
815 if (wall_blocked (map, i, j)) 809 if (wall_blocked (map, i, j))
816 layout2[i][j] = '#'; 810 layout2[i][j] = '#';
817 }
818 }
819 811
820 /* setup num_free_spots and room_free_spots */ 812 /* setup num_free_spots and room_free_spots */
821 find_doors_in_room_recursive (layout2, map, x, y, doorlist, &ndoors, RP); 813 find_doors_in_room_recursive (layout2, map, x, y, doorlist, &ndoors, RP);
822 814
823 /* deallocate the temp. layout */
824 for (i = 0; i < RP->Xsize; i++)
825 free (layout2[i]);
826
827 free (layout2);
828 return doorlist; 815 return doorlist;
829} 816}
830
831
832 817
833/* locks and/or hides all the doors in doorlist, or does nothing if 818/* locks and/or hides all the doors in doorlist, or does nothing if
834 opts doesn't say to lock/hide doors. */ 819 opts doesn't say to lock/hide doors. */
835
836void 820void
837lock_and_hide_doors (object **doorlist, maptile *map, int opts, random_map_params *RP) 821lock_and_hide_doors (object **doorlist, maptile *map, int opts, random_map_params *RP)
838{ 822{
839 object *door; 823 object *door;
840 int i; 824 int i;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines