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.33 by root, Fri Apr 11 21:09:53 2008 UTC vs.
Revision 1.36 by root, Tue Apr 15 03:00:24 2008 UTC

118 } 118 }
119 119
120 /* all the treasure at one spot in the map. */ 120 /* all the treasure at one spot in the map. */
121 if (treasureoptions & CONCENTRATED) 121 if (treasureoptions & CONCENTRATED)
122 { 122 {
123
124 /* map_layout_style global, and is previously set */ 123 /* map_layout_style global, and is previously set */
125 switch (RP->map_layout_style) 124 switch (RP->map_layout_style)
126 { 125 {
127 case LAYOUT_ONION: 126 case LAYOUT_ONION:
128 case LAYOUT_SPIRAL: 127 case LAYOUT_SPIRAL:
140 int tdiv = RP->symmetry_used; 139 int tdiv = RP->symmetry_used;
141 object *chest; 140 object *chest;
142 141
143 if (tdiv == 3) 142 if (tdiv == 3)
144 tdiv = 2; /* this symmetry uses a divisor of 2 */ 143 tdiv = 2; /* this symmetry uses a divisor of 2 */
144
145 /* don't put a chest on an exit. */ 145 /* don't put a chest on an exit. */
146 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 147
148 if (!chest) 148 if (!chest)
149 continue; /* if no chest was placed NEXT */ 149 continue; /* if no chest was placed NEXT */
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;
482 { 486 {
483 theMonsterToFind = find_monster_in_room_recursive (layout, map, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], RP); 487 theMonsterToFind = find_monster_in_room_recursive (layout, map, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], RP);
484 if (theMonsterToFind != NULL) 488 if (theMonsterToFind != NULL)
485 return theMonsterToFind; 489 return theMonsterToFind;
486 } 490 }
491
487 return theMonsterToFind; 492 return theMonsterToFind;
488} 493}
489
490 494
491/* sets up some data structures: the _recursive form does the 495/* sets up some data structures: the _recursive form does the
492 real work. */ 496 real work. */
493
494object * 497object *
495find_monster_in_room (maptile *map, int x, int y, random_map_params *RP) 498find_monster_in_room (maptile *map, int x, int y, random_map_params *RP)
496{ 499{
497 char **layout2; 500 Layout layout2 (RP);
498 int i, j; 501
502 layout2->clear ();
503
504 /* allocate and copy the layout, converting C to 0. */
505 for (int i = 0; i < layout2->w; i++)
506 for (int j = 0; j < layout2->h; j++)
507 if (wall_blocked (map, i, j))
508 layout2[i][j] = '#';
499 509
500 theMonsterToFind = 0; 510 theMonsterToFind = 0;
501 layout2 = (char **) calloc (sizeof (char *), RP->Xsize);
502 /* allocate and copy the layout, converting C to 0. */
503 for (i = 0; i < RP->Xsize; i++)
504 {
505 layout2[i] = (char *) calloc (sizeof (char), RP->Ysize);
506 for (j = 0; j < RP->Ysize; j++)
507 if (wall_blocked (map, i, j))
508 layout2[i][j] = '#';
509 }
510
511 theMonsterToFind = find_monster_in_room_recursive (layout2, map, x, y, RP); 511 theMonsterToFind = find_monster_in_room_recursive (layout2, map, x, y, RP);
512 512
513 /* deallocate the temp. layout */ 513 layout2.free ();
514 for (i = 0; i < RP->Xsize; i++)
515 free (layout2[i]);
516
517 free (layout2);
518 514
519 return theMonsterToFind; 515 return theMonsterToFind;
520} 516}
521 517
522/* a datastructure needed by find_spot_in_room and find_spot_in_room_recursive */ 518/* a datastructure needed by find_spot_in_room and find_spot_in_room_recursive */
797find_doors_in_room (maptile *map, int x, int y, random_map_params *RP) 793find_doors_in_room (maptile *map, int x, int y, random_map_params *RP)
798{ 794{
799 int i, j; 795 int i, j;
800 int ndoors = 0; 796 int ndoors = 0;
801 797
802 object **doorlist = (object **) calloc (sizeof (int), 1024); 798 object **doorlist = (object **)calloc (sizeof (int), 1024);
803 799
804 MazeData layout2 (RP->Xsize, RP->Ysize); 800 LayoutData layout2 (RP->Xsize, RP->Ysize);
801 layout2.clear ();
805 802
806 /* allocate and copy the layout, converting C to 0. */ 803 /* allocate and copy the layout, converting C to 0. */
807 for (i = 0; i < RP->Xsize; i++) 804 for (i = 0; i < RP->Xsize; i++)
808 for (j = 0; j < RP->Ysize; j++) 805 for (j = 0; j < RP->Ysize; j++)
809 if (wall_blocked (map, i, j)) 806 layout2[i][j] = wall_blocked (map, i, j) ? '#' : 0;
810 layout2[i][j] = '#';
811 807
812 /* setup num_free_spots and room_free_spots */ 808 /* setup num_free_spots and room_free_spots */
813 find_doors_in_room_recursive (layout2, map, x, y, doorlist, &ndoors, RP); 809 find_doors_in_room_recursive (layout2, map, x, y, doorlist, &ndoors, RP);
814 810
815 return doorlist; 811 return doorlist;
859 { 855 {
860 retrofit_joined_wall (map, door->x - 1, door->y, 0, RP); 856 retrofit_joined_wall (map, door->x - 1, door->y, 0, RP);
861 retrofit_joined_wall (map, door->x + 1, door->y, 0, RP); 857 retrofit_joined_wall (map, door->x + 1, door->y, 0, RP);
862 retrofit_joined_wall (map, door->x, door->y - 1, 0, RP); 858 retrofit_joined_wall (map, door->x, door->y - 1, 0, RP);
863 retrofit_joined_wall (map, door->x, door->y + 1, 0, RP); 859 retrofit_joined_wall (map, door->x, door->y + 1, 0, RP);
860
864 door->face = wallface->face; 861 door->face = wallface->face;
862
865 if (!QUERY_FLAG (wallface, FLAG_REMOVED)) 863 if (!QUERY_FLAG (wallface, FLAG_REMOVED))
866 wallface->remove (); 864 wallface->remove ();
865
867 wallface->destroy (); 866 wallface->destroy ();
868 } 867 }
869 } 868 }
870 } 869 }
871} 870}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines