|
|
1 | |
1 | /* |
2 | /* |
2 | * static char *rcsid_decor_ = |
3 | * static char *rcsid_decor_ = |
3 | * "$Id: decor.C,v 1.1 2006/08/13 17:16:03 elmex Exp $"; |
4 | * "$Id: decor.C,v 1.2 2006/09/10 16:06:37 root Exp $"; |
4 | */ |
5 | */ |
5 | |
6 | |
6 | /* |
7 | /* |
7 | CrossFire, A Multiplayer game for X-windows |
8 | CrossFire, A Multiplayer game for X-windows |
8 | |
9 | |
… | |
… | |
33 | |
34 | |
34 | #define NR_DECOR_OPTIONS 1 |
35 | #define NR_DECOR_OPTIONS 1 |
35 | |
36 | |
36 | /* return a simple count of objects in the map at x,y. */ |
37 | /* return a simple count of objects in the map at x,y. */ |
37 | |
38 | |
|
|
39 | int |
38 | int obj_count_in_map(mapstruct *map,int x,int y) { |
40 | obj_count_in_map (mapstruct *map, int x, int y) |
|
|
41 | { |
39 | int count=0; |
42 | int count = 0; |
40 | object *tmp; |
43 | object *tmp; |
|
|
44 | |
41 | for(tmp=get_map_ob(map,x,y);tmp!=NULL;tmp=tmp->above) |
45 | for (tmp = get_map_ob (map, x, y); tmp != NULL; tmp = tmp->above) |
42 | count++; |
46 | count++; |
43 | return count; |
47 | return count; |
44 | } |
48 | } |
|
|
49 | |
45 | /* put the decor into the map. Right now, it's very primitive. */ |
50 | /* put the decor into the map. Right now, it's very primitive. */ |
46 | |
51 | |
|
|
52 | void |
47 | void put_decor(mapstruct *map,char **maze,char *decorstyle,int decor_option,RMParms *RP) { |
53 | put_decor (mapstruct *map, char **maze, char *decorstyle, int decor_option, RMParms * RP) |
|
|
54 | { |
48 | mapstruct *decor_map; |
55 | mapstruct *decor_map; |
49 | char style_name[256]; |
56 | char style_name[256]; |
50 | |
57 | |
51 | sprintf(style_name,"/styles/decorstyles"); |
58 | sprintf (style_name, "/styles/decorstyles"); |
52 | |
59 | |
53 | decor_map = find_style(style_name,decorstyle,-1); |
60 | decor_map = find_style (style_name, decorstyle, -1); |
54 | if(decor_map == NULL) return; |
61 | if (decor_map == NULL) |
|
|
62 | return; |
55 | /* pick a random option, only 1 option right now. */ |
63 | /* pick a random option, only 1 option right now. */ |
56 | if(decor_option==0) |
64 | if (decor_option == 0) |
57 | decor_option = RANDOM() % NR_DECOR_OPTIONS +1; |
65 | decor_option = RANDOM () % NR_DECOR_OPTIONS + 1; |
58 | switch(decor_option) { |
66 | switch (decor_option) |
59 | case 0: break; |
67 | { |
60 | case 1: { /* random placement of decor objects. */ |
68 | case 0: |
|
|
69 | break; |
|
|
70 | case 1: |
|
|
71 | { /* random placement of decor objects. */ |
61 | int number_to_place = RANDOM() % ( (RP->Xsize *RP->Ysize) / 5); |
72 | int number_to_place = RANDOM () % ((RP->Xsize * RP->Ysize) / 5); |
62 | int failures=0; |
73 | int failures = 0; |
63 | object *new_decor_object; |
74 | object *new_decor_object; |
|
|
75 | |
64 | while(failures < 100 && number_to_place > 0) { |
76 | while (failures < 100 && number_to_place > 0) |
|
|
77 | { |
65 | int x,y; |
78 | int x, y; |
|
|
79 | |
66 | x = RANDOM() % (RP->Xsize-2) +1; |
80 | x = RANDOM () % (RP->Xsize - 2) + 1; |
67 | y = RANDOM() % (RP->Ysize-2) +1; |
81 | y = RANDOM () % (RP->Ysize - 2) + 1; |
68 | if(maze[x][y]==0 && obj_count_in_map(map,x,y)<2) { /* empty */ |
82 | if (maze[x][y] == 0 && obj_count_in_map (map, x, y) < 2) |
|
|
83 | { /* empty */ |
69 | object *this_object; |
84 | object *this_object; |
|
|
85 | |
70 | new_decor_object = pick_random_object(decor_map); |
86 | new_decor_object = pick_random_object (decor_map); |
71 | this_object = arch_to_object(new_decor_object->arch); |
87 | this_object = arch_to_object (new_decor_object->arch); |
72 | copy_object(new_decor_object,this_object); |
88 | copy_object (new_decor_object, this_object); |
73 | this_object->x = x; |
89 | this_object->x = x; |
74 | this_object->y = y; |
90 | this_object->y = y; |
75 | /* it screws things up if decor can stop people */ |
91 | /* it screws things up if decor can stop people */ |
76 | this_object->move_block = MOVE_BLOCK_DEFAULT; |
92 | this_object->move_block = MOVE_BLOCK_DEFAULT; |
77 | insert_ob_in_map(this_object,map,NULL,0); |
93 | insert_ob_in_map (this_object, map, NULL, 0); |
78 | number_to_place--; |
94 | number_to_place--; |
79 | } |
95 | } |
80 | else |
96 | else |
81 | failures++; |
97 | failures++; |
|
|
98 | } |
|
|
99 | break; |
82 | } |
100 | } |
|
|
101 | default: |
|
|
102 | { /* place decor objects everywhere: tile the map. */ |
|
|
103 | int i, j; |
|
|
104 | |
|
|
105 | for (i = 1; i < RP->Xsize - 1; i++) |
|
|
106 | for (j = 1; j < RP->Ysize - 1; j++) |
|
|
107 | { |
|
|
108 | if (maze[i][j] == 0) |
|
|
109 | { |
|
|
110 | object *new_decor_object, *this_object; |
|
|
111 | |
|
|
112 | new_decor_object = pick_random_object (decor_map); |
|
|
113 | this_object = arch_to_object (new_decor_object->arch); |
|
|
114 | copy_object (new_decor_object, this_object); |
|
|
115 | this_object->x = i; |
|
|
116 | this_object->y = j; |
|
|
117 | /* it screws things up if decor can stop people */ |
|
|
118 | this_object->move_block = MOVE_BLOCK_DEFAULT; |
|
|
119 | insert_ob_in_map (this_object, map, NULL, 0); |
|
|
120 | } |
|
|
121 | } |
83 | break; |
122 | break; |
|
|
123 | } |
84 | } |
124 | } |
85 | default: { /* place decor objects everywhere: tile the map. */ |
|
|
86 | int i,j; |
|
|
87 | for(i=1;i<RP->Xsize-1;i++) for(j=1;j<RP->Ysize-1;j++) { |
|
|
88 | if(maze[i][j]==0) { |
|
|
89 | object *new_decor_object, *this_object; |
|
|
90 | |
|
|
91 | new_decor_object = pick_random_object(decor_map); |
|
|
92 | this_object = arch_to_object(new_decor_object->arch); |
|
|
93 | copy_object(new_decor_object,this_object); |
|
|
94 | this_object->x = i; |
|
|
95 | this_object->y = j; |
|
|
96 | /* it screws things up if decor can stop people */ |
|
|
97 | this_object->move_block = MOVE_BLOCK_DEFAULT; |
|
|
98 | insert_ob_in_map(this_object,map,NULL,0); |
|
|
99 | } |
|
|
100 | } |
|
|
101 | break; |
|
|
102 | } |
|
|
103 | } |
|
|
104 | } |
125 | } |