|
|
1 | |
1 | /* |
2 | /* |
2 | CrossFire, A Multiplayer game for X-windows |
3 | CrossFire, A Multiplayer game for X-windows |
3 | |
4 | |
4 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | Copyright (C) 1992 Frank Tore Johansen |
6 | Copyright (C) 1992 Frank Tore Johansen |
… | |
… | |
42 | } |
43 | } |
43 | |
44 | |
44 | /* put the decor into the map. Right now, it's very primitive. */ |
45 | /* put the decor into the map. Right now, it's very primitive. */ |
45 | |
46 | |
46 | void |
47 | void |
47 | put_decor (maptile *map, char **maze, char *decorstyle, int decor_option, random_map_params * RP) |
48 | put_decor (maptile *map, char **maze, char *decorstyle, int decor_option, random_map_params *RP) |
48 | { |
49 | { |
49 | maptile *decor_map; |
50 | maptile *decor_map; |
50 | char style_name[256]; |
51 | char style_name[256]; |
51 | |
52 | |
52 | sprintf (style_name, "/styles/decorstyles"); |
53 | sprintf (style_name, "/styles/decorstyles"); |
… | |
… | |
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 = RANDOM () % NR_DECOR_OPTIONS + 1; |
60 | decor_option = RANDOM () % NR_DECOR_OPTIONS + 1; |
60 | switch (decor_option) |
61 | switch (decor_option) |
61 | { |
62 | { |
62 | case 0: |
63 | case 0: |
|
|
64 | break; |
|
|
65 | case 1: |
|
|
66 | { /* random placement of decor objects. */ |
|
|
67 | int number_to_place = RANDOM () % ((RP->Xsize * RP->Ysize) / 5); |
|
|
68 | int failures = 0; |
|
|
69 | object *new_decor_object; |
|
|
70 | |
|
|
71 | while (failures < 100 && number_to_place > 0) |
|
|
72 | { |
|
|
73 | int x, y; |
|
|
74 | |
|
|
75 | x = RANDOM () % (RP->Xsize - 2) + 1; |
|
|
76 | y = RANDOM () % (RP->Ysize - 2) + 1; |
|
|
77 | if (maze[x][y] == 0 && obj_count_in_map (map, x, y) < 2) |
|
|
78 | { /* empty */ |
|
|
79 | object *this_object; |
|
|
80 | |
|
|
81 | new_decor_object = pick_random_object (decor_map); |
|
|
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 */ |
|
|
87 | this_object->move_block = MOVE_BLOCK_DEFAULT; |
|
|
88 | insert_ob_in_map (this_object, map, NULL, 0); |
|
|
89 | number_to_place--; |
|
|
90 | } |
|
|
91 | else |
|
|
92 | failures++; |
|
|
93 | } |
63 | break; |
94 | break; |
64 | case 1: |
95 | } |
65 | { /* random placement of decor objects. */ |
96 | default: |
66 | int number_to_place = RANDOM () % ((RP->Xsize * RP->Ysize) / 5); |
97 | { /* place decor objects everywhere: tile the map. */ |
67 | int failures = 0; |
98 | int i, j; |
68 | object *new_decor_object; |
|
|
69 | |
99 | |
70 | while (failures < 100 && number_to_place > 0) |
100 | for (i = 1; i < RP->Xsize - 1; i++) |
|
|
101 | for (j = 1; j < RP->Ysize - 1; j++) |
71 | { |
102 | { |
72 | int x, y; |
103 | if (maze[i][j] == 0) |
73 | |
104 | { |
74 | x = RANDOM () % (RP->Xsize - 2) + 1; |
|
|
75 | y = RANDOM () % (RP->Ysize - 2) + 1; |
|
|
76 | if (maze[x][y] == 0 && obj_count_in_map (map, x, y) < 2) |
|
|
77 | { /* empty */ |
|
|
78 | object *this_object; |
105 | object *new_decor_object, *this_object; |
79 | |
106 | |
80 | new_decor_object = pick_random_object (decor_map); |
107 | new_decor_object = pick_random_object (decor_map); |
81 | this_object = arch_to_object (new_decor_object->arch); |
108 | this_object = arch_to_object (new_decor_object->arch); |
82 | new_decor_object->copy_to (this_object); |
109 | new_decor_object->copy_to (this_object); |
83 | this_object->x = x; |
110 | this_object->x = i; |
84 | this_object->y = y; |
111 | this_object->y = j; |
85 | /* it screws things up if decor can stop people */ |
112 | /* it screws things up if decor can stop people */ |
86 | this_object->move_block = MOVE_BLOCK_DEFAULT; |
113 | this_object->move_block = MOVE_BLOCK_DEFAULT; |
87 | insert_ob_in_map (this_object, map, NULL, 0); |
114 | insert_ob_in_map (this_object, map, NULL, 0); |
88 | number_to_place--; |
|
|
89 | } |
115 | } |
90 | else |
|
|
91 | failures++; |
|
|
92 | } |
116 | } |
93 | break; |
117 | break; |
94 | } |
118 | } |
95 | default: |
|
|
96 | { /* place decor objects everywhere: tile the map. */ |
|
|
97 | int i, j; |
|
|
98 | |
|
|
99 | for (i = 1; i < RP->Xsize - 1; i++) |
|
|
100 | for (j = 1; j < RP->Ysize - 1; j++) |
|
|
101 | { |
|
|
102 | if (maze[i][j] == 0) |
|
|
103 | { |
|
|
104 | object *new_decor_object, *this_object; |
|
|
105 | |
|
|
106 | new_decor_object = pick_random_object (decor_map); |
|
|
107 | this_object = arch_to_object (new_decor_object->arch); |
|
|
108 | new_decor_object->copy_to (this_object); |
|
|
109 | this_object->x = i; |
|
|
110 | this_object->y = j; |
|
|
111 | /* it screws things up if decor can stop people */ |
|
|
112 | this_object->move_block = MOVE_BLOCK_DEFAULT; |
|
|
113 | insert_ob_in_map (this_object, map, NULL, 0); |
|
|
114 | } |
|
|
115 | } |
|
|
116 | break; |
|
|
117 | } |
|
|
118 | } |
119 | } |
119 | } |
120 | } |