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 Marc Alexander Lehmann / Robin Redeker / the Deliantra 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 | * Deliantra 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 |
… | |
… | |
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 | } |
158 | } |
159 | } |
159 | break; |
160 | break; |
160 | } |
161 | } |
|
|
162 | |
161 | default: |
163 | default: |
162 | { |
164 | { |
163 | int i, j, tries; |
165 | int i, j, tries; |
164 | object *chest; |
166 | object *chest; |
165 | object **doorlist; |
167 | object **doorlist; |
… | |
… | |
169 | while (i == -1 && tries < 100) |
171 | while (i == -1 && tries < 100) |
170 | { |
172 | { |
171 | i = rndm (RP->Xsize - 2) + 1; |
173 | i = rndm (RP->Xsize - 2) + 1; |
172 | j = rndm (RP->Ysize - 2) + 1; |
174 | j = rndm (RP->Ysize - 2) + 1; |
173 | find_enclosed_spot (map, &i, &j, RP); |
175 | find_enclosed_spot (map, &i, &j, RP); |
|
|
176 | |
174 | if (wall_blocked (map, i, j)) |
177 | if (wall_blocked (map, i, j)) |
175 | i = -1; |
178 | i = -1; |
|
|
179 | |
176 | tries++; |
180 | tries++; |
177 | } |
181 | } |
|
|
182 | |
178 | chest = place_chest (treasureoptions, i, j, map, style_map, num_treasures, RP); |
183 | chest = place_chest (treasureoptions, i, j, map, style_map, num_treasures, RP); |
|
|
184 | |
179 | if (!chest) |
185 | if (!chest) |
180 | return; |
186 | return; |
|
|
187 | |
181 | i = chest->x; |
188 | i = chest->x; |
182 | j = chest->y; |
189 | j = chest->y; |
183 | if (treasureoptions & (DOORED | HIDDEN)) |
190 | if (treasureoptions & (DOORED | HIDDEN)) |
184 | { |
191 | { |
185 | doorlist = surround_by_doors (map, layout, i, j, treasureoptions); |
192 | doorlist = surround_by_doors (map, layout, i, j, treasureoptions); |
… | |
… | |
203 | } |
210 | } |
204 | |
211 | |
205 | /* put a chest into the map, near x and y, with the treasure style |
212 | /* 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, |
213 | 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 */ |
214 | if the global variable "treasurestyle" is set to that treasure list's name */ |
208 | |
|
|
209 | object * |
215 | object * |
210 | place_chest (int treasureoptions, int x, int y, maptile *map, maptile *style_map, int n_treasures, random_map_params *RP) |
216 | place_chest (int treasureoptions, int x, int y, maptile *map, maptile *style_map, int n_treasures, random_map_params *RP) |
211 | { |
217 | { |
212 | object *the_chest; |
218 | object *the_chest; |
213 | int i, xl, yl; |
219 | int i, xl, yl; |
… | |
… | |
259 | |
265 | |
260 | /* stick a trap in the chest if required */ |
266 | /* stick a trap in the chest if required */ |
261 | if (treasureoptions & TRAPPED) |
267 | if (treasureoptions & TRAPPED) |
262 | { |
268 | { |
263 | maptile *trap_map = find_style ("/styles/trapstyles", "traps", -1); |
269 | maptile *trap_map = find_style ("/styles/trapstyles", "traps", -1); |
264 | object *the_trap; |
|
|
265 | |
270 | |
266 | if (trap_map) |
271 | if (trap_map) |
267 | { |
272 | { |
268 | the_trap = trap_map->pick_random_object (); |
273 | object *the_trap = trap_map->pick_random_object (); |
|
|
274 | |
269 | the_trap->stats.Cha = 10 + RP->difficulty; |
275 | the_trap->stats.Cha = 10 + RP->difficulty; |
270 | the_trap->level = bc_random ((3 * RP->difficulty) / 2); |
276 | the_trap->level = bc_random ((3 * RP->difficulty) / 2); |
|
|
277 | |
271 | if (the_trap) |
278 | if (the_trap) |
272 | { |
279 | { |
273 | object *new_trap; |
280 | object *new_trap = the_trap->arch->instance ();//TODO: why not clone? |
274 | |
281 | |
275 | new_trap = arch_to_object (the_trap->arch); |
|
|
276 | new_trap->copy_to (the_trap); |
|
|
277 | new_trap->x = x; |
282 | new_trap->x = x; |
278 | new_trap->y = y; |
283 | new_trap->y = y; |
279 | insert_ob_in_ob (new_trap, the_chest); |
284 | insert_ob_in_ob (new_trap, the_chest); |
280 | } |
285 | } |
281 | } |
286 | } |
… | |
… | |
481 | { |
486 | { |
482 | 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); |
483 | if (theMonsterToFind != NULL) |
488 | if (theMonsterToFind != NULL) |
484 | return theMonsterToFind; |
489 | return theMonsterToFind; |
485 | } |
490 | } |
|
|
491 | |
486 | return theMonsterToFind; |
492 | return theMonsterToFind; |
487 | } |
493 | } |
488 | |
|
|
489 | |
494 | |
490 | /* sets up some data structures: the _recursive form does the |
495 | /* sets up some data structures: the _recursive form does the |
491 | real work. */ |
496 | real work. */ |
492 | |
|
|
493 | object * |
497 | object * |
494 | find_monster_in_room (maptile *map, int x, int y, random_map_params *RP) |
498 | find_monster_in_room (maptile *map, int x, int y, random_map_params *RP) |
495 | { |
499 | { |
496 | char **layout2; |
500 | Layout layout2 (RP); |
497 | 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] = '#'; |
498 | |
509 | |
499 | theMonsterToFind = 0; |
510 | theMonsterToFind = 0; |
500 | layout2 = (char **) calloc (sizeof (char *), RP->Xsize); |
|
|
501 | /* allocate and copy the layout, converting C to 0. */ |
|
|
502 | for (i = 0; i < RP->Xsize; i++) |
|
|
503 | { |
|
|
504 | layout2[i] = (char *) calloc (sizeof (char), RP->Ysize); |
|
|
505 | for (j = 0; j < RP->Ysize; j++) |
|
|
506 | { |
|
|
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 | { |
|
|
516 | free (layout2[i]); |
|
|
517 | } |
|
|
518 | free (layout2); |
|
|
519 | |
514 | |
520 | return theMonsterToFind; |
515 | return theMonsterToFind; |
521 | } |
516 | } |
522 | |
517 | |
523 | /* 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 */ |
… | |
… | |
746 | if (tmp->type == DOOR || tmp->type == LOCKED_DOOR) |
741 | if (tmp->type == DOOR || tmp->type == LOCKED_DOOR) |
747 | return tmp; |
742 | return tmp; |
748 | return NULL; |
743 | return NULL; |
749 | } |
744 | } |
750 | |
745 | |
751 | |
|
|
752 | /* the workhorse routine, which finds the doors in a room */ |
746 | /* the workhorse routine, which finds the doors in a room */ |
753 | void |
747 | void |
754 | find_doors_in_room_recursive (char **layout, maptile *map, int x, int y, object **doorlist, int *ndoors, random_map_params *RP) |
748 | find_doors_in_room_recursive (char **layout, maptile *map, int x, int y, object **doorlist, int *ndoors, random_map_params *RP) |
755 | { |
749 | { |
756 | int i, j; |
750 | int i, j; |
… | |
… | |
770 | layout[x][y] = 1; |
764 | layout[x][y] = 1; |
771 | door = door_in_square (map, x, y); |
765 | door = door_in_square (map, x, y); |
772 | if (door) |
766 | if (door) |
773 | { |
767 | { |
774 | doorlist[*ndoors] = door; |
768 | doorlist[*ndoors] = door; |
|
|
769 | |
775 | if (*ndoors > 1022) /* eek! out of memory */ |
770 | if (*ndoors > 1022) /* eek! out of memory */ |
776 | { |
771 | { |
777 | LOG (llevError, "find_doors_in_room_recursive:Too many doors for memory allocated!\n"); |
772 | LOG (llevError, "find_doors_in_room_recursive:Too many doors for memory allocated!\n"); |
778 | return; |
773 | return; |
779 | } |
774 | } |
… | |
… | |
795 | |
790 | |
796 | /* find a random non-blocked spot in this room to drop a key. */ |
791 | /* find a random non-blocked spot in this room to drop a key. */ |
797 | object ** |
792 | object ** |
798 | find_doors_in_room (maptile *map, int x, int y, random_map_params *RP) |
793 | find_doors_in_room (maptile *map, int x, int y, random_map_params *RP) |
799 | { |
794 | { |
800 | char **layout2; |
|
|
801 | object **doorlist; |
|
|
802 | int i, j; |
795 | int i, j; |
803 | int ndoors = 0; |
796 | int ndoors = 0; |
804 | |
797 | |
805 | doorlist = (object **) calloc (sizeof (int), 1024); |
798 | object **doorlist = (object **)calloc (sizeof (int), 1024); |
806 | |
799 | |
807 | layout2 = (char **) calloc (sizeof (char *), RP->Xsize); |
800 | LayoutData layout2 (RP->Xsize, RP->Ysize); |
|
|
801 | layout2.clear (); |
|
|
802 | |
808 | /* allocate and copy the layout, converting C to 0. */ |
803 | /* allocate and copy the layout, converting C to 0. */ |
809 | for (i = 0; i < RP->Xsize; i++) |
804 | 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++) |
805 | for (j = 0; j < RP->Ysize; j++) |
813 | { |
806 | layout2[i][j] = wall_blocked (map, i, j) ? '#' : 0; |
814 | if (wall_blocked (map, i, j)) |
|
|
815 | layout2[i][j] = '#'; |
|
|
816 | } |
|
|
817 | } |
|
|
818 | |
807 | |
819 | /* setup num_free_spots and room_free_spots */ |
808 | /* setup num_free_spots and room_free_spots */ |
820 | 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); |
821 | |
810 | |
822 | /* deallocate the temp. layout */ |
|
|
823 | for (i = 0; i < RP->Xsize; i++) |
|
|
824 | free (layout2[i]); |
|
|
825 | |
|
|
826 | free (layout2); |
|
|
827 | return doorlist; |
811 | return doorlist; |
828 | } |
812 | } |
829 | |
|
|
830 | |
|
|
831 | |
813 | |
832 | /* locks and/or hides all the doors in doorlist, or does nothing if |
814 | /* locks and/or hides all the doors in doorlist, or does nothing if |
833 | opts doesn't say to lock/hide doors. */ |
815 | opts doesn't say to lock/hide doors. */ |
834 | |
|
|
835 | void |
816 | void |
836 | lock_and_hide_doors (object **doorlist, maptile *map, int opts, random_map_params *RP) |
817 | lock_and_hide_doors (object **doorlist, maptile *map, int opts, random_map_params *RP) |
837 | { |
818 | { |
838 | object *door; |
819 | object *door; |
839 | int i; |
820 | int i; |
… | |
… | |
874 | { |
855 | { |
875 | retrofit_joined_wall (map, door->x - 1, door->y, 0, RP); |
856 | retrofit_joined_wall (map, door->x - 1, door->y, 0, RP); |
876 | retrofit_joined_wall (map, door->x + 1, door->y, 0, RP); |
857 | retrofit_joined_wall (map, door->x + 1, door->y, 0, RP); |
877 | retrofit_joined_wall (map, door->x, door->y - 1, 0, RP); |
858 | retrofit_joined_wall (map, door->x, door->y - 1, 0, RP); |
878 | retrofit_joined_wall (map, door->x, door->y + 1, 0, RP); |
859 | retrofit_joined_wall (map, door->x, door->y + 1, 0, RP); |
|
|
860 | |
879 | door->face = wallface->face; |
861 | door->face = wallface->face; |
|
|
862 | |
880 | if (!QUERY_FLAG (wallface, FLAG_REMOVED)) |
863 | if (!QUERY_FLAG (wallface, FLAG_REMOVED)) |
881 | wallface->remove (); |
864 | wallface->remove (); |
|
|
865 | |
882 | wallface->destroy (); |
866 | wallface->destroy (); |
883 | } |
867 | } |
884 | } |
868 | } |
885 | } |
869 | } |
886 | } |
870 | } |