1 | /* |
1 | /* |
2 | * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Crossfire TRT 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 3 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, |
… | |
… | |
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, see <http://www.gnu.org/licenses/>. |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 | * |
20 | * |
21 | * The authors can be reached via e-mail to <crossfire@schmorp.de> |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | */ |
22 | */ |
23 | |
23 | |
24 | /* placing treasure in maps, where appropriate. */ |
24 | /* placing treasure in maps, where appropriate. */ |
25 | |
25 | |
26 | #include <global.h> |
26 | #include <global.h> |
… | |
… | |
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: |
… | |
… | |
136 | for (j = 0; j < RP->Ysize; j++) |
135 | for (j = 0; j < RP->Ysize; j++) |
137 | { |
136 | { |
138 | if (layout[i][j] == 'C' || layout[i][j] == '>') |
137 | if (layout[i][j] == 'C' || layout[i][j] == '>') |
139 | { |
138 | { |
140 | int tdiv = RP->symmetry_used; |
139 | int tdiv = RP->symmetry_used; |
141 | object **doorlist; |
|
|
142 | object *chest; |
140 | object *chest; |
143 | |
141 | |
144 | if (tdiv == 3) |
142 | if (tdiv == 3) |
145 | tdiv = 2; /* this symmetry uses a divisor of 2 */ |
143 | tdiv = 2; /* this symmetry uses a divisor of 2 */ |
|
|
144 | |
146 | /* don't put a chest on an exit. */ |
145 | /* don't put a chest on an exit. */ |
147 | 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 | |
148 | if (!chest) |
148 | if (!chest) |
149 | continue; /* if no chest was placed NEXT */ |
149 | continue; /* if no chest was placed NEXT */ |
|
|
150 | |
150 | if (treasureoptions & (DOORED | HIDDEN)) |
151 | if (treasureoptions & (DOORED | HIDDEN)) |
151 | { |
152 | { |
152 | doorlist = find_doors_in_room (map, i, j, RP); |
153 | object **doorlist = find_doors_in_room (map, i, j, RP); |
153 | lock_and_hide_doors (doorlist, map, treasureoptions, RP); |
154 | lock_and_hide_doors (doorlist, map, treasureoptions, RP); |
154 | free (doorlist); |
155 | free (doorlist); |
155 | } |
156 | } |
156 | } |
157 | } |
157 | } |
158 | } |
… | |
… | |
169 | while (i == -1 && tries < 100) |
170 | while (i == -1 && tries < 100) |
170 | { |
171 | { |
171 | i = rndm (RP->Xsize - 2) + 1; |
172 | i = rndm (RP->Xsize - 2) + 1; |
172 | j = rndm (RP->Ysize - 2) + 1; |
173 | j = rndm (RP->Ysize - 2) + 1; |
173 | find_enclosed_spot (map, &i, &j, RP); |
174 | find_enclosed_spot (map, &i, &j, RP); |
|
|
175 | |
174 | if (wall_blocked (map, i, j)) |
176 | if (wall_blocked (map, i, j)) |
175 | i = -1; |
177 | i = -1; |
|
|
178 | |
176 | tries++; |
179 | tries++; |
177 | } |
180 | } |
|
|
181 | |
178 | 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 | |
179 | if (!chest) |
184 | if (!chest) |
180 | return; |
185 | return; |
|
|
186 | |
181 | i = chest->x; |
187 | i = chest->x; |
182 | j = chest->y; |
188 | j = chest->y; |
183 | if (treasureoptions & (DOORED | HIDDEN)) |
189 | if (treasureoptions & (DOORED | HIDDEN)) |
184 | { |
190 | { |
185 | doorlist = surround_by_doors (map, layout, i, j, treasureoptions); |
191 | doorlist = surround_by_doors (map, layout, i, j, treasureoptions); |
… | |
… | |
203 | } |
209 | } |
204 | |
210 | |
205 | /* 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 |
206 | 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, |
207 | 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 */ |
208 | |
|
|
209 | object * |
214 | object * |
210 | place_chest (int treasureoptions, int x, int y, maptile *map, maptile *style_map, int n_treasures, random_map_params *RP) |
215 | place_chest (int treasureoptions, int x, int y, maptile *map, maptile *style_map, int n_treasures, random_map_params *RP) |
211 | { |
216 | { |
212 | object *the_chest; |
217 | object *the_chest; |
213 | int i, xl, yl; |
218 | int i, xl, yl; |
… | |
… | |
428 | the_key->y = ky; |
433 | the_key->y = ky; |
429 | insert_ob_in_map (the_key, map, NULL, 0); |
434 | insert_ob_in_map (the_key, map, NULL, 0); |
430 | return 1; |
435 | return 1; |
431 | } |
436 | } |
432 | |
437 | |
433 | insert_ob_in_ob (the_key, the_keymaster); |
438 | insert_ob_in_ob (the_key, the_keymaster->head_ ()); |
434 | return 1; |
439 | return 1; |
435 | } |
440 | } |
436 | |
441 | |
437 | |
442 | |
438 | |
443 | |
… | |
… | |
501 | /* allocate and copy the layout, converting C to 0. */ |
506 | /* allocate and copy the layout, converting C to 0. */ |
502 | for (i = 0; i < RP->Xsize; i++) |
507 | for (i = 0; i < RP->Xsize; i++) |
503 | { |
508 | { |
504 | layout2[i] = (char *) calloc (sizeof (char), RP->Ysize); |
509 | layout2[i] = (char *) calloc (sizeof (char), RP->Ysize); |
505 | for (j = 0; j < RP->Ysize; j++) |
510 | for (j = 0; j < RP->Ysize; j++) |
506 | { |
|
|
507 | if (wall_blocked (map, i, j)) |
511 | if (wall_blocked (map, i, j)) |
508 | layout2[i][j] = '#'; |
512 | layout2[i][j] = '#'; |
509 | } |
|
|
510 | } |
513 | } |
|
|
514 | |
511 | theMonsterToFind = find_monster_in_room_recursive (layout2, map, x, y, RP); |
515 | theMonsterToFind = find_monster_in_room_recursive (layout2, map, x, y, RP); |
512 | |
516 | |
513 | /* deallocate the temp. layout */ |
517 | /* deallocate the temp. layout */ |
514 | for (i = 0; i < RP->Xsize; i++) |
518 | for (i = 0; i < RP->Xsize; i++) |
515 | { |
|
|
516 | free (layout2[i]); |
519 | free (layout2[i]); |
517 | } |
520 | |
518 | free (layout2); |
521 | free (layout2); |
519 | |
522 | |
520 | return theMonsterToFind; |
523 | return theMonsterToFind; |
521 | } |
524 | } |
522 | |
525 | |
… | |
… | |
746 | if (tmp->type == DOOR || tmp->type == LOCKED_DOOR) |
749 | if (tmp->type == DOOR || tmp->type == LOCKED_DOOR) |
747 | return tmp; |
750 | return tmp; |
748 | return NULL; |
751 | return NULL; |
749 | } |
752 | } |
750 | |
753 | |
751 | |
|
|
752 | /* the workhorse routine, which finds the doors in a room */ |
754 | /* the workhorse routine, which finds the doors in a room */ |
753 | void |
755 | void |
754 | find_doors_in_room_recursive (char **layout, maptile *map, int x, int y, object **doorlist, int *ndoors, random_map_params *RP) |
756 | find_doors_in_room_recursive (char **layout, maptile *map, int x, int y, object **doorlist, int *ndoors, random_map_params *RP) |
755 | { |
757 | { |
756 | int i, j; |
758 | int i, j; |
… | |
… | |
770 | layout[x][y] = 1; |
772 | layout[x][y] = 1; |
771 | door = door_in_square (map, x, y); |
773 | door = door_in_square (map, x, y); |
772 | if (door) |
774 | if (door) |
773 | { |
775 | { |
774 | doorlist[*ndoors] = door; |
776 | doorlist[*ndoors] = door; |
|
|
777 | |
775 | if (*ndoors > 1022) /* eek! out of memory */ |
778 | if (*ndoors > 1022) /* eek! out of memory */ |
776 | { |
779 | { |
777 | LOG (llevError, "find_doors_in_room_recursive:Too many doors for memory allocated!\n"); |
780 | LOG (llevError, "find_doors_in_room_recursive:Too many doors for memory allocated!\n"); |
778 | return; |
781 | return; |
779 | } |
782 | } |
… | |
… | |
795 | |
798 | |
796 | /* find a random non-blocked spot in this room to drop a key. */ |
799 | /* find a random non-blocked spot in this room to drop a key. */ |
797 | object ** |
800 | object ** |
798 | find_doors_in_room (maptile *map, int x, int y, random_map_params *RP) |
801 | find_doors_in_room (maptile *map, int x, int y, random_map_params *RP) |
799 | { |
802 | { |
800 | char **layout2; |
|
|
801 | object **doorlist; |
|
|
802 | int i, j; |
803 | int i, j; |
803 | int ndoors = 0; |
804 | int ndoors = 0; |
804 | |
805 | |
805 | doorlist = (object **) calloc (sizeof (int), 1024); |
806 | object **doorlist = (object **)calloc (sizeof (int), 1024); |
806 | |
807 | |
807 | layout2 = (char **) calloc (sizeof (char *), RP->Xsize); |
808 | MazeData layout2 (RP->Xsize, RP->Ysize); |
|
|
809 | |
808 | /* allocate and copy the layout, converting C to 0. */ |
810 | /* allocate and copy the layout, converting C to 0. */ |
809 | for (i = 0; i < RP->Xsize; i++) |
811 | for (i = 0; i < RP->Xsize; i++) |
810 | { |
|
|
811 | layout2[i] = (char *) calloc (sizeof (char), RP->Ysize); |
|
|
812 | for (j = 0; j < RP->Ysize; j++) |
812 | for (j = 0; j < RP->Ysize; j++) |
813 | { |
|
|
814 | if (wall_blocked (map, i, j)) |
813 | if (wall_blocked (map, i, j)) |
815 | layout2[i][j] = '#'; |
814 | layout2[i][j] = '#'; |
816 | } |
|
|
817 | } |
|
|
818 | |
815 | |
819 | /* setup num_free_spots and room_free_spots */ |
816 | /* setup num_free_spots and room_free_spots */ |
820 | find_doors_in_room_recursive (layout2, map, x, y, doorlist, &ndoors, RP); |
817 | find_doors_in_room_recursive (layout2, map, x, y, doorlist, &ndoors, RP); |
821 | |
818 | |
822 | /* deallocate the temp. layout */ |
|
|
823 | for (i = 0; i < RP->Xsize; i++) |
|
|
824 | free (layout2[i]); |
|
|
825 | |
|
|
826 | free (layout2); |
|
|
827 | return doorlist; |
819 | return doorlist; |
828 | } |
820 | } |
829 | |
|
|
830 | |
|
|
831 | |
821 | |
832 | /* locks and/or hides all the doors in doorlist, or does nothing if |
822 | /* locks and/or hides all the doors in doorlist, or does nothing if |
833 | opts doesn't say to lock/hide doors. */ |
823 | opts doesn't say to lock/hide doors. */ |
834 | |
|
|
835 | void |
824 | void |
836 | lock_and_hide_doors (object **doorlist, maptile *map, int opts, random_map_params *RP) |
825 | lock_and_hide_doors (object **doorlist, maptile *map, int opts, random_map_params *RP) |
837 | { |
826 | { |
838 | object *door; |
827 | object *door; |
839 | int i; |
828 | int i; |