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.60 by root, Sat Apr 23 04:56:54 2011 UTC vs.
Revision 1.66 by root, Sat Sep 16 22:17:42 2017 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2001 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2001 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992 Frank Tore Johansen 6 * Copyright (©) 1992 Frank Tore Johansen
7 * 7 *
8 * Deliantra is free software: you can redistribute it and/or modify it under 8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * the terms of the Affero GNU General Public License as published by the 9 * the terms of the Affero GNU General Public License as published by the
10 * Free Software Foundation, either version 3 of the License, or (at your 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version. 11 * 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 Affero GNU General Public License 18 * You should have received a copy of the Affero GNU General Public License
19 * and the GNU General Public License along with this program. If not, see 19 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>. 20 * <http://www.gnu.org/licenses/>.
21 * 21 *
22 * The authors can be reached via e-mail to <support@deliantra.net> 22 * The authors can be reached via e-mail to <support@deliantra.net>
23 */ 23 */
24 24
25/* placing treasure in maps, where appropriate. */ 25/* placing treasure in maps, where appropriate. */
26 26
67 object *key = archetype::get (shstr_key_random_map); 67 object *key = archetype::get (shstr_key_random_map);
68 key->slaying = keycode; 68 key->slaying = keycode;
69 return key; 69 return key;
70} 70}
71 71
72/* places keys in the map, preferably in something alive. 72/* places keys in the map, preferably in something alive.
73 keycode is the key's code, 73 keycode is the key's code,
74 door_flag is either PASS_DOORS or NO_PASS_DOORS. 74 door_flag is either PASS_DOORS or NO_PASS_DOORS.
75 NO_PASS_DOORS won't cross doors or walls to keyplace, PASS_DOORS will. 75 NO_PASS_DOORS won't cross doors or walls to keyplace, PASS_DOORS will.
76 if n_keys is 1, it will place 1 key. if n_keys >1, it will place 2-4 keys: 76 if n_keys is 1, it will place 1 key. if n_keys >1, it will place 2-4 keys:
77 it will place 2-4 keys regardless of what nkeys is provided nkeys > 1. 77 it will place 2-4 keys regardless of what nkeys is provided nkeys > 1.
114 } 114 }
115 115
116 // can freeindex ever be < 0? 116 // can freeindex ever be < 0?
117 if (freeindex >= 0) 117 if (freeindex >= 0)
118 { 118 {
119 kx += freearr_x [freeindex]; 119 kx += DIRX (freeindex);
120 ky += freearr_y [freeindex]; 120 ky += DIRY (freeindex);
121 } 121 }
122 } 122 }
123 } 123 }
124 else 124 else
125 { /* NO_PASS_DOORS --we have to work harder. */ 125 { /* NO_PASS_DOORS --we have to work harder. */
184 184
185 m->at (x, y).update (); 185 m->at (x, y).update ();
186 return GET_MAP_MOVE_BLOCK (m, x, y) & MOVE_WALK; 186 return GET_MAP_MOVE_BLOCK (m, x, y) & MOVE_WALK;
187} 187}
188 188
189/* place treasures in the map, given the 189/* place treasures in the map, given the
190map, (required) 190map, (required)
191maze, (required) 191maze, (required)
192treasure style (may be empty or NULL, or "none" to cause no treasure.) 192treasure style (may be empty or NULL, or "none" to cause no treasure.)
193treasureoptions (may be 0 for random choices or positive) 193treasureoptions (may be 0 for random choices or positive)
194*/ 194*/
341 { 341 {
342 the_chest->destroy (); 342 the_chest->destroy ();
343 return NULL; 343 return NULL;
344 } 344 }
345 345
346 int xl = x + freearr_x[i]; 346 int xl = x + DIRX (i);
347 int yl = y + freearr_y[i]; 347 int yl = y + DIRY (i);
348 348
349 /* if the placement is blocked, return a fail. */ 349 /* if the placement is blocked, return a fail. */
350 if (wall_blocked (map, xl, yl)) 350 if (wall_blocked (map, xl, yl))
351 return 0; 351 return 0;
352 352
425 425
426 for (i = 0; i < SIZEOFFREE; i++) 426 for (i = 0; i < SIZEOFFREE; i++)
427 { 427 {
428 int lx, ly; 428 int lx, ly;
429 429
430 lx = x + freearr_x[i]; 430 lx = x + DIRX (i);
431 ly = y + freearr_y[i]; 431 ly = y + DIRY (i);
432 /* boundscheck */ 432 /* boundscheck */
433 if (lx >= 0 && ly >= 0 && lx < map->width && ly < map->height) 433 if (lx >= 0 && ly >= 0 && lx < map->width && ly < map->height)
434 /* don't bother searching this square unless the map says life exists. */ 434 /* don't bother searching this square unless the map says life exists. */
435 if (GET_MAP_FLAGS (map, lx, ly) & P_IS_ALIVE) 435 if (GET_MAP_FLAGS (map, lx, ly) & P_IS_ALIVE)
436 { 436 {
486 } 486 }
487 487
488 /* now search all the 8 squares around recursively for a monster,in random order */ 488 /* now search all the 8 squares around recursively for a monster,in random order */
489 for (i = rmg_rndm (8), j = 0; j < 8 && !theMonsterToFind; i++, j++) 489 for (i = rmg_rndm (8), j = 0; j < 8 && !theMonsterToFind; i++, j++)
490 { 490 {
491 theMonsterToFind = find_monster_in_room_recursive (maze, map, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1]); 491 theMonsterToFind = find_monster_in_room_recursive (maze, map, x + DIRX (i % 8 + 1), y + DIRY (i % 8 + 1));
492 if (theMonsterToFind) 492 if (theMonsterToFind)
493 return theMonsterToFind; 493 return theMonsterToFind;
494 } 494 }
495 495
496 return theMonsterToFind; 496 return theMonsterToFind;
534 maze[x][y] = 1; 534 maze[x][y] = 1;
535 spots.push (point (x, y)); 535 spots.push (point (x, y));
536 536
537 /* now search all the 8 squares around recursively for free spots,in random order */ 537 /* now search all the 8 squares around recursively for free spots,in random order */
538 for (int i = rmg_rndm (8), j = 0; j < 8 && !theMonsterToFind; i++, j++) 538 for (int i = rmg_rndm (8), j = 0; j < 8 && !theMonsterToFind; i++, j++)
539 find_spot_in_room_recursive (maze, spots, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1]); 539 find_spot_in_room_recursive (maze, spots, x + DIRX (i % 8 + 1), y + DIRY (i % 8 + 1));
540 540
541} 541}
542 542
543/* find a random non-blocked spot in this room to drop a key. */ 543/* find a random non-blocked spot in this room to drop a key. */
544static void 544static void
579 579
580 for (i = 0; i <= SIZEOFFREE1; i++) 580 for (i = 0; i <= SIZEOFFREE1; i++)
581 { 581 {
582 int lx, ly, sindex; 582 int lx, ly, sindex;
583 583
584 lx = x + freearr_x[i]; 584 lx = x + DIRX (i);
585 ly = y + freearr_y[i]; 585 ly = y + DIRY (i);
586 sindex = surround_flag3 (map, lx, ly); 586 sindex = surround_flag3 (map, lx, ly);
587 /* if it's blocked on 3 sides, it's enclosed */ 587 /* if it's blocked on 3 sides, it's enclosed */
588 if (sindex == 7 || sindex == 11 || sindex == 13 || sindex == 14) 588 if (sindex == 7 || sindex == 11 || sindex == 13 || sindex == 14)
589 { 589 {
590 *cx = lx; 590 *cx = lx;
597 spots--try to find someplace which is 2x enclosed. */ 597 spots--try to find someplace which is 2x enclosed. */
598 for (i = 0; i <= SIZEOFFREE1; i++) 598 for (i = 0; i <= SIZEOFFREE1; i++)
599 { 599 {
600 int lx, ly, sindex; 600 int lx, ly, sindex;
601 601
602 lx = x + freearr_x[i]; 602 lx = x + DIRX (i);
603 ly = y + freearr_y[i]; 603 ly = y + DIRY (i);
604 sindex = surround_flag3 (map, lx, ly); 604 sindex = surround_flag3 (map, lx, ly);
605 /* if it's blocked on 3 sides, it's enclosed */ 605 /* if it's blocked on 3 sides, it's enclosed */
606 if (sindex == 3 || sindex == 5 || sindex == 9 || sindex == 6 || sindex == 10 || sindex == 12) 606 if (sindex == 3 || sindex == 5 || sindex == 9 || sindex == 6 || sindex == 10 || sindex == 12)
607 { 607 {
608 *cx = lx; 608 *cx = lx;
614 /* settle for one surround point */ 614 /* settle for one surround point */
615 for (i = 0; i <= SIZEOFFREE1; i++) 615 for (i = 0; i <= SIZEOFFREE1; i++)
616 { 616 {
617 int lx, ly, sindex; 617 int lx, ly, sindex;
618 618
619 lx = x + freearr_x[i]; 619 lx = x + DIRX (i);
620 ly = y + freearr_y[i]; 620 ly = y + DIRY (i);
621 sindex = surround_flag3 (map, lx, ly); 621 sindex = surround_flag3 (map, lx, ly);
622 /* if it's blocked on 3 sides, it's enclosed */ 622 /* if it's blocked on 3 sides, it's enclosed */
623 if (sindex) 623 if (sindex)
624 { 624 {
625 *cx = lx; 625 *cx = lx;
630 /* give up and return the closest free spot. */ 630 /* give up and return the closest free spot. */
631 i = rmg_find_free_spot (archetype::find (shstr_chest), map, x, y, 1, SIZEOFFREE1 + 1); 631 i = rmg_find_free_spot (archetype::find (shstr_chest), map, x, y, 1, SIZEOFFREE1 + 1);
632 632
633 if (i != -1) 633 if (i != -1)
634 { 634 {
635 *cx = x + freearr_x[i]; 635 *cx = x + DIRX (i);
636 *cy = y + freearr_y[i]; 636 *cy = y + DIRY (i);
637 } 637 }
638 else 638 else
639 { 639 {
640 /* indicate failure */ 640 /* indicate failure */
641 *cx = -1; 641 *cx = -1;
682 } 682 }
683 683
684 /* place doors in all the 8 adjacent unblocked squares. */ 684 /* place doors in all the 8 adjacent unblocked squares. */
685 for (i = 1; i < 9; i++) 685 for (i = 1; i < 9; i++)
686 { 686 {
687 int x1 = x + freearr_x[i], y1 = y + freearr_y[i]; 687 int x1 = x + DIRX (i), y1 = y + DIRY (i);
688 688
689 if (!wall_blocked (map, x1, y1) && maze[x1][y1] == '>') 689 if (!wall_blocked (map, x1, y1) && maze[x1][y1] == '>')
690 { /* place a door */ 690 { /* place a door */
691 remove_monsters (x1, y1, map); 691 remove_monsters (x1, y1, map);
692 692
693 object *new_door = get_archetype (freearr_x[i] == 0 ? doors[1] : doors[0]); 693 object *new_door = archetype::get (DIRX (i) == 0 ? doors[1] : doors[0]);
694 map->insert (new_door, x1, y1); 694 map->insert (new_door, x1, y1);
695 doorlist[ndoors_made] = new_door; 695 doorlist[ndoors_made] = new_door;
696 ndoors_made++; 696 ndoors_made++;
697 } 697 }
698 } 698 }
749 maze[x][y] = 1; 749 maze[x][y] = 1;
750 750
751 /* now search all the 8 squares around recursively for free spots,in random order */ 751 /* now search all the 8 squares around recursively for free spots,in random order */
752 for (i = rmg_rndm (8), j = 0; j < 8 && !theMonsterToFind; i++, j++) 752 for (i = rmg_rndm (8), j = 0; j < 8 && !theMonsterToFind; i++, j++)
753 find_doors_in_room_recursive (maze, map, 753 find_doors_in_room_recursive (maze, map,
754 x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], 754 x + DIRX (i % 8 + 1), y + DIRY (i % 8 + 1),
755 doorlist, ndoors); 755 doorlist, ndoors);
756 } 756 }
757} 757}
758 758
759/* find a random non-blocked spot in this room to drop a key. */ 759/* find a random non-blocked spot in this room to drop a key. */
791 791
792 if (opts & DOORED) 792 if (opts & DOORED)
793 { 793 {
794 for (i = 0, door = doorlist[0]; doorlist[i]; i++) 794 for (i = 0, door = doorlist[0]; doorlist[i]; i++)
795 { 795 {
796 object *new_door = get_archetype (shstr_locked_door1); 796 object *new_door = archetype::get (shstr_locked_door1);
797 797
798 door = doorlist[i]; 798 door = doorlist[i];
799 new_door->face = door->face; 799 new_door->face = door->face;
800 new_door->x = door->x; 800 new_door->x = door->x;
801 new_door->y = door->y; 801 new_door->y = door->y;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines