| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include <assert.h> |
| 20 |
#include <stdlib.h> |
| 21 |
|
| 22 |
#include "global.h" |
| 23 |
#include "random_map.h" |
| 24 |
#include "rproto.h" |
| 25 |
|
| 26 |
|
| 27 |
#define NR_DECOR_OPTIONS 1 |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
int obj_count_in_map(mapstruct *map, int x, int y) |
| 40 |
{ |
| 41 |
int count = 0; |
| 42 |
|
| 43 |
FOR_MAP_PREPARE(map, x, y, tmp) |
| 44 |
count++; |
| 45 |
FOR_MAP_FINISH(); |
| 46 |
return count; |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
void put_decor(mapstruct *map, char **maze, char *decorstyle, int decor_option, RMParms *RP) |
| 66 |
{ |
| 67 |
mapstruct *decor_map; |
| 68 |
|
| 69 |
decor_map = find_style("/styles/decorstyles", decorstyle, -1); |
| 70 |
if (decor_map == NULL) { |
| 71 |
return; |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
if (decor_option == 0) { |
| 76 |
decor_option = RANDOM()%NR_DECOR_OPTIONS+1; |
| 77 |
} |
| 78 |
|
| 79 |
assert(decor_option != 0); |
| 80 |
|
| 81 |
switch (decor_option) { |
| 82 |
case 1: { |
| 83 |
int number_to_place = RANDOM()%((RP->Xsize*RP->Ysize)/5); |
| 84 |
int failures = 0; |
| 85 |
object *new_decor_object; |
| 86 |
|
| 87 |
while (failures < 100 && number_to_place > 0) { |
| 88 |
int x, y; |
| 89 |
|
| 90 |
x = RANDOM()%(RP->Xsize-2)+1; |
| 91 |
y = RANDOM()%(RP->Ysize-2)+1; |
| 92 |
if (maze[x][y] == 0 && obj_count_in_map(map, x, y) < 2) { |
| 93 |
object *this_object; |
| 94 |
|
| 95 |
new_decor_object = pick_random_object(decor_map); |
| 96 |
this_object = arch_to_object(new_decor_object->arch); |
| 97 |
object_copy(new_decor_object, this_object); |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
object_insert_in_map_at(this_object, map, NULL, 0, x, y); |
| 105 |
number_to_place--; |
| 106 |
} else { |
| 107 |
failures++; |
| 108 |
} |
| 109 |
} |
| 110 |
break; |
| 111 |
} |
| 112 |
|
| 113 |
default: { |
| 114 |
int i, j; |
| 115 |
|
| 116 |
for (i = 1; i < RP->Xsize-1; i++) |
| 117 |
for (j = 1; j < RP->Ysize-1; j++) { |
| 118 |
if (maze[i][j] == 0) { |
| 119 |
object *new_decor_object, *this_object; |
| 120 |
|
| 121 |
new_decor_object = pick_random_object(decor_map); |
| 122 |
this_object = arch_to_object(new_decor_object->arch); |
| 123 |
object_copy(new_decor_object, this_object); |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
object_insert_in_map_at(this_object, map, NULL, 0, i, j); |
| 131 |
} |
| 132 |
} |
| 133 |
break; |
| 134 |
} |
| 135 |
} |
| 136 |
} |