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.39 by root, Thu May 8 11:39:24 2008 UTC vs.
Revision 1.44 by root, Mon Sep 29 10:32:50 2008 UTC

52 52
53static object * 53static object *
54gen_key (const shstr &keycode) 54gen_key (const shstr &keycode)
55{ 55{
56 /* get a key and set its keycode */ 56 /* get a key and set its keycode */
57 object *key = archetype::get (shstr_key2); 57 object *key = archetype::get (shstr_key_random_map);
58
59 key->slaying = keycode; 58 key->slaying = keycode;
60 key->stats.food = 100;
61 key->speed_left = -1.f;
62 key->flag [FLAG_IS_USED_UP] = true;
63 key->set_speed (1.f / 300.f);
64
65 return key; 59 return key;
66} 60}
67 61
68/* places keys in the map, preferably in something alive. 62/* places keys in the map, preferably in something alive.
69 keycode is the key's code, 63 keycode is the key's code,
79keyplace (maptile *map, int x, int y, const shstr &keycode, int door_flag, int n_keys, random_map_params *RP) 73keyplace (maptile *map, int x, int y, const shstr &keycode, int door_flag, int n_keys, random_map_params *RP)
80{ 74{
81 int i, j; 75 int i, j;
82 int kx = 0, ky = 0; 76 int kx = 0, ky = 0;
83 object *the_keymaster; /* the monster that gets the key. */ 77 object *the_keymaster; /* the monster that gets the key. */
78 object *the_key = gen_key (keycode);
84 79
85 if (door_flag == PASS_DOORS) 80 if (door_flag == PASS_DOORS)
86 { 81 {
87 int tries = 0; 82 int tries = 0;
88 83
103 freeindex = -1; 98 freeindex = -1;
104 for (tries = 0; tries < 15 && freeindex == -1; tries++) 99 for (tries = 0; tries < 15 && freeindex == -1; tries++)
105 { 100 {
106 kx = rmg_rndm (RP->Xsize - 2) + 1; 101 kx = rmg_rndm (RP->Xsize - 2) + 1;
107 ky = rmg_rndm (RP->Ysize - 2) + 1; 102 ky = rmg_rndm (RP->Ysize - 2) + 1;
108 freeindex = find_free_spot (gen_key (keycode), map, kx, ky, 1, SIZEOFFREE1 + 1); 103 freeindex = find_free_spot (the_key, map, kx, ky, 1, SIZEOFFREE1 + 1);
109 } 104 }
110 105
111 // can freeindex ever be < 0? 106 // can freeindex ever be < 0?
112 if (freeindex >= 0) 107 if (freeindex >= 0)
113 { 108 {
121 /* don't try to keyplace if we're sitting on a blocked square and 116 /* don't try to keyplace if we're sitting on a blocked square and
122 NO_PASS_DOORS is set. */ 117 NO_PASS_DOORS is set. */
123 if (n_keys == 1) 118 if (n_keys == 1)
124 { 119 {
125 if (wall_blocked (map, x, y)) 120 if (wall_blocked (map, x, y))
121 {
122 the_key->destroy ();
126 return 0; 123 return 0;
124 }
127 125
128 the_keymaster = find_monster_in_room (map, x, y, RP); 126 the_keymaster = find_monster_in_room (map, x, y, RP);
129 if (!the_keymaster) /* if fail, find a spot to drop the key. */ 127 if (!the_keymaster) /* if fail, find a spot to drop the key. */
130 find_spot_in_room (map, x, y, &kx, &ky, RP); 128 find_spot_in_room (map, x, y, &kx, &ky, RP);
131 } 129 }
145 keyplace (map, x + 1, y - 1, keycode, NO_PASS_DOORS, 1, RP); 143 keyplace (map, x + 1, y - 1, keycode, NO_PASS_DOORS, 1, RP);
146 keyplace (map, x - 1, y + 1, keycode, NO_PASS_DOORS, 1, RP); 144 keyplace (map, x - 1, y + 1, keycode, NO_PASS_DOORS, 1, RP);
147 keyplace (map, x - 1, y - 1, keycode, NO_PASS_DOORS, 1, RP); 145 keyplace (map, x - 1, y - 1, keycode, NO_PASS_DOORS, 1, RP);
148 } 146 }
149 147
148 the_key->destroy ();
150 return 1; 149 return 1;
151 } 150 }
152 } 151 }
153
154 object *the_key = gen_key (keycode);
155 152
156 if (the_keymaster) 153 if (the_keymaster)
157 the_keymaster->head_ ()->insert (the_key); 154 the_keymaster->head_ ()->insert (the_key);
158 else 155 else
159 { 156 {
672} 669}
673 670
674void 671void
675remove_monsters (int x, int y, maptile *map) 672remove_monsters (int x, int y, maptile *map)
676{ 673{
677 object *tmp;
678
679 for (tmp = GET_MAP_OB (map, x, y); tmp; tmp = tmp->above) 674 for (object *tmp = GET_MAP_OB (map, x, y); tmp; )
680 if (QUERY_FLAG (tmp, FLAG_ALIVE))
681 { 675 {
682 if (tmp->head) 676 object *next = tmp->above;
683 tmp = tmp->head; 677
684 tmp->remove (); 678 if (tmp->flag [FLAG_ALIVE])
685 tmp->destroy (); 679 tmp->head_ ()->destroy ();
686 tmp = GET_MAP_OB (map, x, y); 680
687 if (tmp == NULL) 681 tmp = next;
688 break;
689 }; 682 }
690} 683}
691 684
692/* surrounds the point x,y by doors, so as to enclose something, like 685/* surrounds the point x,y by doors, so as to enclose something, like
693 a chest. It only goes as far as the 8 squares surrounding, and 686 a chest. It only goes as far as the 8 squares surrounding, and
694 it'll remove any monsters it finds.*/ 687 it'll remove any monsters it finds.*/
823 816
824 /* lock the doors and hide the keys. */ 817 /* lock the doors and hide the keys. */
825 818
826 if (opts & DOORED) 819 if (opts & DOORED)
827 { 820 {
828 for (i = 0, door = doorlist[0]; doorlist[i] != NULL; i++) 821 for (i = 0, door = doorlist[0]; doorlist[i]; i++)
829 { 822 {
830 object *new_door = get_archetype ("locked_door1"); 823 object *new_door = get_archetype (shstr_locked_door1);
831 824
832 door = doorlist[i]; 825 door = doorlist[i];
833 new_door->face = door->face; 826 new_door->face = door->face;
834 new_door->x = door->x; 827 new_door->x = door->x;
835 new_door->y = door->y; 828 new_door->y = door->y;
836 door->remove ();
837 door->destroy (); 829 door->destroy ();
838 doorlist[i] = new_door; 830 doorlist[i] = new_door;
839 insert_ob_in_map (new_door, map, NULL, 0); 831 insert_ob_in_map (new_door, map, NULL, 0);
840 new_door->slaying = format ("RMG-%d-%d", (int)rmg_rndm (1000000000), (int)rmg_rndm (1000000000)); 832 new_door->slaying = format ("RMG-%d-%d", (int)rmg_rndm (1000000000), (int)rmg_rndm (1000000000));
841 keyplace (map, new_door->x, new_door->y, new_door->slaying, NO_PASS_DOORS, 2, RP); 833 keyplace (map, new_door->x, new_door->y, new_door->slaying, NO_PASS_DOORS, 2, RP);
858 retrofit_joined_wall (map, door->x, door->y - 1, 0, RP); 850 retrofit_joined_wall (map, door->x, door->y - 1, 0, RP);
859 retrofit_joined_wall (map, door->x, door->y + 1, 0, RP); 851 retrofit_joined_wall (map, door->x, door->y + 1, 0, RP);
860 852
861 door->face = wallface->face; 853 door->face = wallface->face;
862 854
863 if (!QUERY_FLAG (wallface, FLAG_REMOVED))
864 wallface->remove ();
865
866 wallface->destroy (); 855 wallface->destroy ();
867 } 856 }
868 } 857 }
869 } 858 }
870} 859}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines