46 #define CONCENTRATED 1
54 #define LAST_OPTION 64
57 #define NO_PASS_DOORS 0
102 char styledirname[256];
103 char stylefilepath[256];
109 if (!strcmp(treasure_style,
"none"))
111 if (treasureoptions <= 0)
115 if ((treasureoptions&
RICH) && (treasureoptions&
SPARSE)) {
117 treasureoptions -= 1;
119 treasureoptions -= 2;
123 if (treasureoptions&
SPARSE)
125 else if (treasureoptions&RICH)
130 if (num_treasures <= 0)
134 snprintf(styledirname,
sizeof(styledirname),
"%s",
"/styles/treasurestyles");
135 snprintf(stylefilepath,
sizeof(stylefilepath),
"%s/%s", styledirname, treasure_style);
136 style_map =
find_style(styledirname, treasure_style, -1);
148 for (i = 0; i < RP->
Xsize; i++) {
149 for (j = 0; j < RP->
Ysize; j++) {
150 if (layout[i][j] ==
'C' || layout[i][j] ==
'>') {
158 chest =
place_chest(treasureoptions, i, j, map, style_map, num_treasures/tdiv, RP);
178 while (i == -1 && tries < 100) {
179 i = RANDOM()%(RP->
Xsize-2)+1;
180 j = RANDOM()%(RP->
Ysize-2)+1;
186 chest =
place_chest(treasureoptions, i, j, map, style_map, num_treasures, RP);
201 for (ti = 0; ti < num_treasures; ti++) {
202 i = RANDOM()%(RP->
Xsize-2)+1;
203 j = RANDOM()%(RP->
Ysize-2)+1;
204 place_chest(treasureoptions, i, j, map, style_map, 1, RP);
256 the_chest->
stats.
hp = n_treasures;
282 if ((treasureoptions&
KEYREQUIRED) && n_treasures > 1) {
285 snprintf(keybuf,
sizeof(keybuf),
"%d", (
int)RANDOM());
320 if (lx >= 0 && ly >= 0 && lx < RP->Xsize && ly < RP->Ysize)
323 object *the_monster =
GET_MAP_OB(map, lx, ly);
364 object *the_keymaster;
378 the_keymaster = NULL;
379 while (tries < 15 && the_keymaster == NULL) {
380 i = (RANDOM()%(RP->
Xsize-2))+1;
381 j = (RANDOM()%(RP->
Ysize-2))+1;
386 if (the_keymaster == NULL) {
390 for (tries = 0; tries < 15 && freeindex == -1; tries++) {
391 kx = (RANDOM()%(RP->
Xsize-2))+1;
392 ky = (RANDOM()%(RP->
Ysize-2))+1;
395 if (freeindex != -1) {
408 if (the_keymaster == NULL)
418 while (distance < 5) {
439 if (the_keymaster == NULL) {
470 if (!(x >= 0 && y >= 0 && x < RP->Xsize && y < RP->Ysize))
474 if (layout[x][y] != 0)
491 for (i = RANDOM()%8, j = 0; j < 8; i++, j++) {
493 if (the_monster != NULL)
516 object *theMonsterToFind;
518 layout2 = (
char **)calloc(
sizeof(
char *), RP->
Xsize);
520 for (i = 0; i < RP->
Xsize; i++) {
521 layout2[i] = (
char *)calloc(
sizeof(
char), RP->
Ysize);
522 for (j = 0; j < RP->
Ysize; j++) {
530 for (i = 0; i < RP->
Xsize; i++) {
535 return theMonsterToFind;
563 if (!(x >= 0 && y >= 0 && x < RP->Xsize && y < RP->Ysize))
567 if (layout[x][y] != 0)
577 for (i = RANDOM()%8, j = 0; j < 8; i++, j++) {
609 layout2 = (
char **)calloc(
sizeof(
char *), RP->
Xsize);
611 for (i = 0; i < RP->
Xsize; i++) {
612 layout2[i] = (
char *)calloc(
sizeof(
char), RP->
Ysize);
613 for (j = 0; j < RP->
Ysize; j++) {
629 for (i = 0; i < RP->
Xsize; i++) {
666 if (sindex == 7 || sindex == 11 || sindex == 13 || sindex == 14) {
682 if (sindex == 3 || sindex == 5 || sindex == 9 || sindex == 6 || sindex == 10 || sindex == 12) {
757 const char *doors[2];
760 doorlist = (
object **)calloc(9,
sizeof(
object *));
764 doors[0] =
"locked_door2";
765 doors[1] =
"locked_door1";
772 for (i = 1; i < 9; i++) {
776 || layout[x1][y1] ==
'>') {
777 object *new_door =
create_archetype((freearr_x[i] == 0) ? doors[1] : doors[0]);
779 new_door->
x = x+freearr_x[i];
780 new_door->
y = y+freearr_y[i];
783 doorlist[ndoors_made] = new_door;
829 if (!(x >= 0 && y >= 0 && x < RP->Xsize && y < RP->Ysize))
833 if (layout[x][y] == 1)
837 if (layout[x][y] ==
'#') {
841 doorlist[*ndoors] = door;
843 LOG(
llevError,
"find_doors_in_room_recursive:Too many doors for memory allocated!\n");
851 for (i = RANDOM()%8, j = 0; j < 8; i++, j++) {
877 doorlist = (
object **)calloc(
sizeof(
int), 256);
880 layout2 = (
char **)calloc(
sizeof(
char *), RP->
Xsize);
882 for (i = 0; i < RP->
Xsize; i++) {
883 layout2[i] = (
char *)calloc(
sizeof(
char), RP->
Ysize);
884 for (j = 0; j < RP->
Ysize; j++) {
894 for (i = 0; i < RP->
Xsize; i++) {
917 for (i = 1; i <= 8; i++) {
958 for (i = 0, door = doorlist[0]; doorlist[i] != NULL; i++) {
964 new_door->
x = door->
x;
965 new_door->
y = door->
y;
968 doorlist[i] = new_door;
971 snprintf(keybuf, 256,
"%d", (
int)RANDOM());
975 for (i = 0; doorlist[i] != NULL; i++)
981 for (i = 0, door = doorlist[0]; doorlist[i] != NULL; i++) {
986 if (wallface != NULL) {
static void find_spot_in_room_recursive(char **layout, int x, int y, RMParms *RP, free_spots_struct *spots)
int get_map_flags(mapstruct *oldmap, mapstruct **newmap, sint16 x, sint16 y, sint16 *nx, sint16 *ny)
archetype * find_archetype(const char *name)
object ** find_doors_in_room(mapstruct *map, int x, int y, RMParms *RP)
void find_enclosed_spot(mapstruct *map, int *cx, int *cy, RMParms *RP)
void find_doors_in_room_recursive(char **layout, mapstruct *map, int x, int y, object **doorlist, int *ndoors, RMParms *RP)
void remove_monsters(int x, int y, mapstruct *map)
void lock_and_hide_doors(object **doorlist, mapstruct *map, int opts, RMParms *RP)
void place_treasure(mapstruct *map, char **layout, char *treasure_style, int treasureoptions, RMParms *RP)
treasurelist * find_treasurelist(const char *name)
int number_of_free_spots_in_room
void free_string(sstring str)
struct free_spots_struct free_spots_struct
int keyplace(mapstruct *map, int x, int y, char *keycode, int door_flag, int n_keys, RMParms *RP)
struct treasureliststruct * randomitems
short freearr_x[SIZEOFFREE]
int find_spot_in_room(mapstruct *map, int x, int y, int *kx, int *ky, RMParms *RP)
#define OUT_OF_REAL_MAP(M, X, Y)
int distance(const object *ob1, const object *ob2)
object * pick_random_object(mapstruct *style)
short freearr_y[SIZEOFFREE]
void remove_ob(object *op)
object * create_archetype(const char *name)
long unsigned int total_map_hp
int surround_flag3(mapstruct *map, int i, int j, RMParms *RP)
object * find_closest_monster(mapstruct *map, int x, int y, RMParms *RP)
int find_first_free_spot(const object *ob, mapstruct *m, int x, int y)
char dungeon_name[RM_SIZE]
object * retrofit_joined_wall(mapstruct *the_map, int i, int j, int insert_flag, RMParms *RP)
static object ** surround_by_doors(mapstruct *map, char **layout, int x, int y, int opts)
object * find_monster_in_room(mapstruct *map, int x, int y, RMParms *RP)
object * place_chest(int treasureoptions, int x, int y, mapstruct *map, mapstruct *style_map, int n_treasures, RMParms *RP)
#define GET_MAP_MOVE_BLOCK(M, X, Y)
#define SQUARE_SPIRAL_LAYOUT
#define QUERY_FLAG(xyz, p)
static void remove_adjacent_doors(object *door)
object * insert_ob_in_ob(object *op, object *where)
static object * door_in_square(mapstruct *map, int x, int y)
object * insert_ob_in_map(object *op, mapstruct *m, object *originator, int flag)
int wall_blocked(mapstruct *m, int x, int y)
#define MOVE_BLOCK_DEFAULT
static const flag_definition flags[]
#define GET_MAP_FLAGS(M, X, Y)
int snprintf(char *dest, int max, const char *format,...)
sstring add_string(const char *str)
#define GET_MAP_OB(M, X, Y)
void LOG(LogLevel logLevel, const char *format,...)
mapstruct * find_style(const char *dirname, const char *stylename, int difficulty)
void copy_object(object *op2, object *op)
void free_object(object *ob)
object * arch_to_object(archetype *at)
object * find_monster_in_room_recursive(char **layout, mapstruct *map, int x, int y, RMParms *RP)