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.22 by root, Fri Jan 19 21:49:58 2007 UTC vs.
Revision 1.29 by root, Mon Jun 4 13:04:00 2007 UTC

41#define LAST_OPTION 64 /* set this to the last real option, for random */ 41#define LAST_OPTION 64 /* set this to the last real option, for random */
42 42
43#define NO_PASS_DOORS 0 43#define NO_PASS_DOORS 0
44#define PASS_DOORS 1 44#define PASS_DOORS 1
45 45
46/* a macro to get a strongly centered random distribution,
47 from 0 to x, centered at x/2 */
48static int
49bc_random (int x)
50{
51 return (rndm (x) + rndm (x) + rndm (x)) / 3;
52}
46 53
47/* returns true if square x,y has P_NO_PASS set, which is true for walls 54/* returns true if square x,y has P_NO_PASS set, which is true for walls
48 * and doors but not monsters. 55 * and doors but not monsters.
49 * This function is not map tile aware. 56 * This function is not map tile aware.
50 */ 57 */
52wall_blocked (maptile *m, int x, int y) 59wall_blocked (maptile *m, int x, int y)
53{ 60{
54 if (OUT_OF_REAL_MAP (m, x, y)) 61 if (OUT_OF_REAL_MAP (m, x, y))
55 return 1; 62 return 1;
56 63
64 m->at (x, y).update ();
57 int r = GET_MAP_MOVE_BLOCK (m, x, y) & ~MOVE_BLOCK_DEFAULT; 65 return GET_MAP_MOVE_BLOCK (m, x, y) & MOVE_WALK;
58 return r;
59} 66}
60 67
61/* place treasures in the map, given the 68/* place treasures in the map, given the
62map, (required) 69map, (required)
63layout, (required) 70layout, (required)
76 if (treasure_style) 83 if (treasure_style)
77 if (!strcmp (treasure_style, "none")) 84 if (!strcmp (treasure_style, "none"))
78 return; 85 return;
79 86
80 if (treasureoptions <= 0) 87 if (treasureoptions <= 0)
81 treasureoptions = RANDOM () % (2 * LAST_OPTION); 88 treasureoptions = rndm (2 * LAST_OPTION);
82 89
83 /* filter out the mutually exclusive options */ 90 /* filter out the mutually exclusive options */
84 if ((treasureoptions & RICH) && (treasureoptions & SPARSE)) 91 if ((treasureoptions & RICH) && (treasureoptions & SPARSE))
85 { 92 {
86 if (rndm (2)) 93 if (rndm (2))
89 treasureoptions -= 2; 96 treasureoptions -= 2;
90 } 97 }
91 98
92 /* pick the number of treasures */ 99 /* pick the number of treasures */
93 if (treasureoptions & SPARSE) 100 if (treasureoptions & SPARSE)
94 num_treasures = BC_RANDOM (RP->total_map_hp / 600 + RP->difficulty / 2 + 1); 101 num_treasures = bc_random (RP->total_map_hp / 600 + RP->difficulty / 2 + 1);
95 else if (treasureoptions & RICH) 102 else if (treasureoptions & RICH)
96 num_treasures = BC_RANDOM (RP->total_map_hp / 150 + 2 * RP->difficulty + 1); 103 num_treasures = bc_random (RP->total_map_hp / 150 + 2 * RP->difficulty + 1);
97 else 104 else
98 num_treasures = BC_RANDOM (RP->total_map_hp / 300 + RP->difficulty + 1); 105 num_treasures = bc_random (RP->total_map_hp / 300 + RP->difficulty + 1);
99 106
100 if (num_treasures <= 0) 107 if (num_treasures <= 0)
101 return; 108 return;
102 109
103 /* get the style map */ 110 /* get the style map */
104 sprintf (styledirname, "%s", "/styles/treasurestyles"); 111 sprintf (styledirname, "%s", "/styles/treasurestyles");
105 sprintf (stylefilepath, "%s/%s", styledirname, treasure_style); 112 sprintf (stylefilepath, "%s/%s", styledirname, treasure_style);
106 style_map = find_style (styledirname, treasure_style, -1); 113 style_map = find_style (styledirname, treasure_style, -1);
114
115 if (!style_map)
116 {
117 LOG (llevError, "unable to load style map %s %s.\n", styledirname, treasure_style);
118 return;
119 }
107 120
108 /* all the treasure at one spot in the map. */ 121 /* all the treasure at one spot in the map. */
109 if (treasureoptions & CONCENTRATED) 122 if (treasureoptions & CONCENTRATED)
110 { 123 {
111 124
154 167
155 i = j = -1; 168 i = j = -1;
156 tries = 0; 169 tries = 0;
157 while (i == -1 && tries < 100) 170 while (i == -1 && tries < 100)
158 { 171 {
159 i = RANDOM () % (RP->Xsize - 2) + 1; 172 i = rndm (RP->Xsize - 2) + 1;
160 j = RANDOM () % (RP->Ysize - 2) + 1; 173 j = rndm (RP->Ysize - 2) + 1;
161 find_enclosed_spot (map, &i, &j, RP); 174 find_enclosed_spot (map, &i, &j, RP);
162 if (wall_blocked (map, i, j)) 175 if (wall_blocked (map, i, j))
163 i = -1; 176 i = -1;
164 tries++; 177 tries++;
165 } 178 }
181 { /* DIFFUSE treasure layout */ 194 { /* DIFFUSE treasure layout */
182 int ti, i, j; 195 int ti, i, j;
183 196
184 for (ti = 0; ti < num_treasures; ti++) 197 for (ti = 0; ti < num_treasures; ti++)
185 { 198 {
186 i = RANDOM () % (RP->Xsize - 2) + 1; 199 i = rndm (RP->Xsize - 2) + 1;
187 j = RANDOM () % (RP->Ysize - 2) + 1; 200 j = rndm (RP->Ysize - 2) + 1;
188 place_chest (treasureoptions, i, j, map, style_map, 1, RP); 201 place_chest (treasureoptions, i, j, map, style_map, 1, RP);
189 } 202 }
190 } 203 }
191} 204}
192 205
226 treasurelist *tlist = find_treasurelist (RP->treasurestyle); 239 treasurelist *tlist = find_treasurelist (RP->treasurestyle);
227 240
228 if (tlist != NULL) 241 if (tlist != NULL)
229 for (ti = 0; ti < n_treasures; ti++) 242 for (ti = 0; ti < n_treasures; ti++)
230 { /* use the treasure list */ 243 { /* use the treasure list */
231 object *new_treasure = pick_random_object (style_map); 244 object *new_treasure = style_map->pick_random_object ();
232 245
233 insert_ob_in_ob (arch_to_object (new_treasure->arch), the_chest); 246 insert_ob_in_ob (arch_to_object (new_treasure->arch), the_chest);
234 } 247 }
235 else 248 else
236 { /* use the style map */ 249 { /* use the style map */
237 the_chest->randomitems = tlist; 250 the_chest->randomitems = tlist;
238 the_chest->stats.hp = n_treasures; 251 the_chest->stats.hp = n_treasures;
239 } 252 }
240#endif 253#endif
241 { /* neither style_map no treasure list given */ 254 { /* neither style_map no treasure list given */
242 treasurelist *tlist = find_treasurelist ("chest"); 255 treasurelist *tlist = treasurelist::find ("chest");
243 256
244 the_chest->randomitems = tlist; 257 the_chest->randomitems = tlist;
245 the_chest->stats.hp = n_treasures; 258 the_chest->stats.hp = n_treasures;
246 } 259 }
247 260
251 maptile *trap_map = find_style ("/styles/trapstyles", "traps", -1); 264 maptile *trap_map = find_style ("/styles/trapstyles", "traps", -1);
252 object *the_trap; 265 object *the_trap;
253 266
254 if (trap_map) 267 if (trap_map)
255 { 268 {
256 the_trap = pick_random_object (trap_map); 269 the_trap = trap_map->pick_random_object ();
257 the_trap->stats.Cha = 10 + RP->difficulty; 270 the_trap->stats.Cha = 10 + RP->difficulty;
258 the_trap->level = BC_RANDOM ((3 * RP->difficulty) / 2); 271 the_trap->level = bc_random ((3 * RP->difficulty) / 2);
259 if (the_trap) 272 if (the_trap)
260 { 273 {
261 object *new_trap; 274 object *new_trap;
262 275
263 new_trap = arch_to_object (the_trap->arch); 276 new_trap = arch_to_object (the_trap->arch);
270 } 283 }
271 284
272 /* set the chest lock code, and call the keyplacer routine with 285 /* set the chest lock code, and call the keyplacer routine with
273 the lockcode. It's not worth bothering to lock the chest if 286 the lockcode. It's not worth bothering to lock the chest if
274 there's only 1 treasure.... */ 287 there's only 1 treasure.... */
275
276 if ((treasureoptions & KEYREQUIRED) && n_treasures > 1) 288 if ((treasureoptions & KEYREQUIRED) && n_treasures > 1)
277 { 289 {
278 char keybuf[1024]; 290 char keybuf[1024];
279 291
280 sprintf (keybuf, "%d", (int) RANDOM ()); 292 sprintf (keybuf, "%d", rndm (1000000000));
281 the_chest->slaying = keybuf; 293 the_chest->slaying = keybuf;
282 keyplace (map, x, y, keybuf, PASS_DOORS, 1, RP); 294 keyplace (map, x, y, keybuf, PASS_DOORS, 1, RP);
283 } 295 }
284 296
285 /* actually place the chest. */ 297 /* actually place the chest. */
347 int tries = 0; 359 int tries = 0;
348 360
349 the_keymaster = 0; 361 the_keymaster = 0;
350 while (tries < 15 && !the_keymaster) 362 while (tries < 15 && !the_keymaster)
351 { 363 {
352 i = (RANDOM () % (RP->Xsize - 2)) + 1; 364 i = rndm (RP->Xsize - 2) + 1;
353 j = (RANDOM () % (RP->Ysize - 2)) + 1; 365 j = rndm (RP->Ysize - 2) + 1;
354 tries++; 366 tries++;
355 the_keymaster = find_closest_monster (map, i, j, RP); 367 the_keymaster = find_closest_monster (map, i, j, RP);
356 } 368 }
357 369
358 /* if we don't find a good keymaster, drop the key on the ground. */ 370 /* if we don't find a good keymaster, drop the key on the ground. */
361 int freeindex; 373 int freeindex;
362 374
363 freeindex = -1; 375 freeindex = -1;
364 for (tries = 0; tries < 15 && freeindex == -1; tries++) 376 for (tries = 0; tries < 15 && freeindex == -1; tries++)
365 { 377 {
366 kx = (RANDOM () % (RP->Xsize - 2)) + 1; 378 kx = rndm (RP->Xsize - 2) + 1;
367 ky = (RANDOM () % (RP->Ysize - 2)) + 1; 379 ky = rndm (RP->Ysize - 2) + 1;
368 freeindex = find_free_spot (the_key, map, kx, ky, 1, SIZEOFFREE1 + 1); 380 freeindex = find_free_spot (the_key, map, kx, ky, 1, SIZEOFFREE1 + 1);
369 } 381 }
370 382
371 // can freeindex ever be < 0? 383 // can freeindex ever be < 0?
372 if (freeindex >= 0) 384 if (freeindex >= 0)
568 /* setup num_free_spots and room_free_spots */ 580 /* setup num_free_spots and room_free_spots */
569 find_spot_in_room_recursive (layout2, x, y, RP); 581 find_spot_in_room_recursive (layout2, x, y, RP);
570 582
571 if (number_of_free_spots_in_room > 0) 583 if (number_of_free_spots_in_room > 0)
572 { 584 {
573 i = RANDOM () % number_of_free_spots_in_room; 585 i = rndm (number_of_free_spots_in_room);
574 *kx = room_free_spots_x[i]; 586 *kx = room_free_spots_x[i];
575 *ky = room_free_spots_y[i]; 587 *ky = room_free_spots_y[i];
576 } 588 }
577 589
578 /* deallocate the temp. layout */ 590 /* deallocate the temp. layout */
646 *cy = ly; 658 *cy = ly;
647 return; 659 return;
648 } 660 }
649 } 661 }
650 /* give up and return the closest free spot. */ 662 /* give up and return the closest free spot. */
651 i = find_free_spot (&archetype::find ("chest")->clone, map, x, y, 1, SIZEOFFREE1 + 1); 663 i = find_free_spot (archetype::find ("chest"), map, x, y, 1, SIZEOFFREE1 + 1);
652 664
653 if (i != -1) 665 if (i != -1)
654 { 666 {
655 *cx = x + freearr_x[i]; 667 *cx = x + freearr_x[i];
656 *cy = y + freearr_y[i]; 668 *cy = y + freearr_y[i];
686 it'll remove any monsters it finds.*/ 698 it'll remove any monsters it finds.*/
687object ** 699object **
688surround_by_doors (maptile *map, char **layout, int x, int y, int opts) 700surround_by_doors (maptile *map, char **layout, int x, int y, int opts)
689{ 701{
690 int i; 702 int i;
691 char *doors[2]; 703 const char *doors[2];
692 object **doorlist; 704 object **doorlist;
693 int ndoors_made = 0; 705 int ndoors_made = 0;
694 doorlist = (object **) calloc (9, sizeof (object *)); /* 9 doors so we can hold termination null */ 706 doorlist = (object **) calloc (9, sizeof (object *)); /* 9 doors so we can hold termination null */
695 707
696 /* this is a list we pick from, for horizontal and vertical doors */ 708 /* this is a list we pick from, for horizontal and vertical doors */
771 } 783 }
772 } 784 }
773 else 785 else
774 { 786 {
775 layout[x][y] = 1; 787 layout[x][y] = 1;
788
776 /* now search all the 8 squares around recursively for free spots,in random order */ 789 /* now search all the 8 squares around recursively for free spots,in random order */
777 for (i = rndm (8), j = 0; j < 8 && theMonsterToFind == NULL; i++, j++) 790 for (i = rndm (8), j = 0; j < 8 && !theMonsterToFind; i++, j++)
778 find_doors_in_room_recursive (layout, map, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], doorlist, ndoors, RP); 791 find_doors_in_room_recursive (layout, map,
792 x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1],
793 doorlist, ndoors, RP);
779 } 794 }
780} 795}
781 796
782/* find a random non-blocked spot in this room to drop a key. */ 797/* find a random non-blocked spot in this room to drop a key. */
783object ** 798object **
839 new_door->y = door->y; 854 new_door->y = door->y;
840 door->remove (); 855 door->remove ();
841 door->destroy (); 856 door->destroy ();
842 doorlist[i] = new_door; 857 doorlist[i] = new_door;
843 insert_ob_in_map (new_door, map, NULL, 0); 858 insert_ob_in_map (new_door, map, NULL, 0);
844 sprintf (keybuf, "%d", (int) RANDOM ()); 859 sprintf (keybuf, "%d", rndm (1000000000));
845 new_door->slaying = keybuf; 860 new_door->slaying = keybuf;
846 keyplace (map, new_door->x, new_door->y, keybuf, NO_PASS_DOORS, 2, RP); 861 keyplace (map, new_door->x, new_door->y, keybuf, NO_PASS_DOORS, 2, RP);
847 } 862 }
848 } 863 }
849 864

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines