00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00034 #include <global.h>
00035 #include <random_map.h>
00036 #include <rproto.h>
00037
00039 #define NR_DECOR_OPTIONS 1
00040
00051 int obj_count_in_map(mapstruct *map, int x, int y) {
00052 int count = 0;
00053 object *tmp;
00054
00055 for (tmp = GET_MAP_OB(map, x, y); tmp != NULL; tmp = tmp->above)
00056 count++;
00057 return count;
00058 }
00059
00076 void put_decor(mapstruct *map, char **maze, char *decorstyle, int decor_option, RMParms *RP) {
00077 mapstruct *decor_map;
00078 char style_name[256];
00079
00080 snprintf(style_name, sizeof(style_name), "/styles/decorstyles");
00081
00082 decor_map = find_style(style_name, decorstyle, -1);
00083 if (decor_map == NULL)
00084 return;
00085
00086
00087 if (decor_option == 0)
00088 decor_option = RANDOM()%NR_DECOR_OPTIONS+1;
00089
00090 switch (decor_option) {
00091 case 0:
00092 break;
00093
00094 case 1: {
00095 int number_to_place = RANDOM()%((RP->Xsize*RP->Ysize)/5);
00096 int failures = 0;
00097 object *new_decor_object;
00098
00099 while (failures < 100 && number_to_place > 0) {
00100 int x, y;
00101
00102 x = RANDOM()%(RP->Xsize-2)+1;
00103 y = RANDOM()%(RP->Ysize-2)+1;
00104 if (maze[x][y] == 0 && obj_count_in_map(map, x, y) < 2) {
00105 object *this_object;
00106
00107 new_decor_object = pick_random_object(decor_map);
00108 this_object = arch_to_object(new_decor_object->arch);
00109 copy_object(new_decor_object, this_object);
00110 this_object->x = x;
00111 this_object->y = y;
00112
00113 this_object->move_block = MOVE_BLOCK_DEFAULT;
00114 insert_ob_in_map(this_object, map, NULL, 0);
00115 number_to_place--;
00116 } else
00117 failures++;
00118 }
00119 break;
00120 }
00121
00122 default: {
00123 int i, j;
00124
00125 for (i = 1; i < RP->Xsize-1; i++)
00126 for (j = 1; j < RP->Ysize-1; j++) {
00127 if (maze[i][j] == 0) {
00128 object *new_decor_object, *this_object;
00129
00130 new_decor_object = pick_random_object(decor_map);
00131 this_object = arch_to_object(new_decor_object->arch);
00132 copy_object(new_decor_object, this_object);
00133 this_object->x = i;
00134 this_object->y = j;
00135
00136 this_object->move_block = MOVE_BLOCK_DEFAULT;
00137 insert_ob_in_map(this_object, map, NULL, 0);
00138 }
00139 }
00140 break;
00141 }
00142 }
00143 }