… | |
… | |
27 | |
27 | |
28 | #define NR_DECOR_OPTIONS 1 |
28 | #define NR_DECOR_OPTIONS 1 |
29 | |
29 | |
30 | /* return a simple count of objects in the map at x,y. */ |
30 | /* return a simple count of objects in the map at x,y. */ |
31 | |
31 | |
32 | int |
32 | static int |
33 | obj_count_in_map (maptile *map, int x, int y) |
33 | obj_count_in_map (maptile *map, int x, int y) |
34 | { |
34 | { |
35 | int count = 0; |
35 | int count = 0; |
36 | object *tmp; |
36 | object *tmp; |
37 | |
37 | |
38 | for (tmp = GET_MAP_OB (map, x, y); tmp != NULL; tmp = tmp->above) |
38 | for (tmp = map->at (x, y).bot; tmp; tmp = tmp->above) |
39 | count++; |
39 | ++count; |
|
|
40 | |
40 | return count; |
41 | return count; |
41 | } |
42 | } |
42 | |
43 | |
43 | /* put the decor into the map. Right now, it's very primitive. */ |
44 | /* put the decor into the map. Right now, it's very primitive. */ |
44 | |
45 | |
… | |
… | |
54 | if (!decor_map) |
55 | if (!decor_map) |
55 | return; |
56 | return; |
56 | |
57 | |
57 | /* pick a random option, only 1 option right now. */ |
58 | /* pick a random option, only 1 option right now. */ |
58 | if (decor_option == 0) |
59 | if (decor_option == 0) |
59 | decor_option = rndm (NR_DECOR_OPTIONS) + 1; |
60 | decor_option = rmg_rndm (NR_DECOR_OPTIONS) + 1; |
60 | |
61 | |
61 | switch (decor_option) |
62 | switch (decor_option) |
62 | { |
63 | { |
63 | case 0: |
64 | case 0: |
64 | break; |
65 | break; |
|
|
66 | |
65 | case 1: |
67 | case 1: |
66 | { /* random placement of decor objects. */ |
68 | { /* random placement of decor objects. */ |
67 | int number_to_place = rndm (RP->Xsize * RP->Ysize / 5); |
69 | int number_to_place = rmg_rndm (RP->Xsize * RP->Ysize / 5); |
68 | int failures = 0; |
70 | int failures = 0; |
69 | object *new_decor_object; |
|
|
70 | |
71 | |
71 | while (failures < 100 && number_to_place > 0) |
72 | while (failures < 100 && number_to_place > 0) |
72 | { |
73 | { |
73 | int x, y; |
74 | coroapi::cede_to_tick (); |
74 | |
75 | |
75 | x = rndm (RP->Xsize - 2) + 1; |
76 | int x = rmg_rndm (RP->Xsize - 2) + 1; |
76 | y = rndm (RP->Ysize - 2) + 1; |
77 | int y = rmg_rndm (RP->Ysize - 2) + 1; |
|
|
78 | |
77 | if (maze[x][y] == 0 && obj_count_in_map (map, x, y) < 2) |
79 | if (maze[x][y] == 0 && obj_count_in_map (map, x, y) < 2) |
78 | { /* empty */ |
80 | { |
79 | object *this_object; |
|
|
80 | |
|
|
81 | new_decor_object = decor_map->pick_random_object (); |
81 | object *this_object = decor_map->pick_random_object (rmg_rndm)->clone (); |
82 | this_object = arch_to_object (new_decor_object->arch); |
|
|
83 | new_decor_object->copy_to (this_object); |
|
|
84 | this_object->x = x; |
|
|
85 | this_object->y = y; |
|
|
86 | /* it screws things up if decor can stop people */ |
82 | /* it screws things up if decor can stop people */ |
87 | this_object->move_block = 0; |
83 | this_object->move_block = 0; |
88 | insert_ob_in_map (this_object, map, NULL, 0); |
84 | map->insert (this_object, x, y, 0, 0); |
|
|
85 | |
89 | number_to_place--; |
86 | number_to_place--; |
90 | } |
87 | } |
91 | else |
88 | else |
92 | failures++; |
89 | failures++; |
93 | } |
90 | } |
94 | break; |
91 | break; |
95 | } |
92 | } |
|
|
93 | |
96 | default: |
94 | default: |
97 | { /* place decor objects everywhere: tile the map. */ |
95 | { /* place decor objects everywhere: tile the map. */ |
98 | int i, j; |
96 | int i, j; |
99 | |
97 | |
100 | for (i = 1; i < RP->Xsize - 1; i++) |
98 | for (i = 1; i < RP->Xsize - 1; i++) |
101 | for (j = 1; j < RP->Ysize - 1; j++) |
99 | for (j = 1; j < RP->Ysize - 1; j++) |
102 | { |
100 | { |
103 | if (maze[i][j] == 0) |
101 | if (maze[i][j] == 0) |
104 | { |
102 | { |
105 | object *new_decor_object, *this_object; |
103 | object *this_object = decor_map->pick_random_object (rmg_rndm)->clone (); |
106 | |
104 | |
107 | new_decor_object = decor_map->pick_random_object (); |
|
|
108 | this_object = arch_to_object (new_decor_object->arch); |
|
|
109 | new_decor_object->copy_to (this_object); |
|
|
110 | this_object->x = i; |
105 | this_object->x = i; |
111 | this_object->y = j; |
106 | this_object->y = j; |
112 | /* it screws things up if decor can stop people */ |
107 | /* it screws things up if decor can stop people */ |
113 | this_object->move_block = 0; |
108 | this_object->move_block = 0; |
|
|
109 | |
114 | insert_ob_in_map (this_object, map, NULL, 0); |
110 | insert_ob_in_map (this_object, map, NULL, 0); |
115 | } |
111 | } |
116 | } |
112 | } |
117 | break; |
113 | break; |
118 | } |
114 | } |
119 | } |
115 | } |
120 | } |
116 | } |
|
|
117 | |