8 static Bottom_settings bottom_settings;
9 static AquariumData *ad;
13 Bottom_settings *bottom_get_settings_ptr(void)
15 return &bottom_settings;
18 void bottom_init(void)
21 SA_Image bottom_stuff;
23 Bottom bottom_items[NUMOFBOTTOMITEMS] = {
24 {"bottom/plant1.png", 0},
25 {"bottom/plant2.png", 0},
26 {"bottom/plant3.png", 0},
27 {"bottom/plant4.png", 0},
28 {"bottom/plant5.png", 0},
29 {"bottom/plant6.png", 0},
30 {"bottom/plant7.png", 0},
31 {"bottom/plant9.png", 0},
32 {"bottom/plant10.png", 0},
33 {"bottom/smallstone1.png", 0},
34 {"bottom/smallstone3.png", 0},
35 {"bottom/stone1.png", 0},
36 {"bottom/stone2.png", 0},
37 {"bottom/stone3.png", 0},
38 {"bottom/weirdplant.png", 0},
39 {"bottom/weirdplant2.png", 0},
40 {"bottom/octo1.png", 0},
41 {"bottom/bigplant.png", 0}
44 char *bottom_image_files[] = {
52 int start_sea_floor_x, start_sea_floor_y;
54 int curr_sea_floor_height;
55 int i,j,k,l,jj, step_max, current_loc,x=0;
56 int old_height=0,old_x=0, old_current_loc=0, bx[10], bw[10], nfa;
58 Fish_settings *fish_settings;
60 ad = aquarium_get_settings_ptr();
62 fishes = fish_get_fishes_ptr();
64 fish_settings = fish_get_settings_ptr();
67 if(!bottom_settings.have_sea_floor)
70 i = g_rand_int_range(ad->rnd, 0, NUMBOTTOMIMAGES);
72 load_image_n_scale(bottom_image_files[i], &sea_floor, 1, bottom_settings.scale);
74 start_sea_floor_x = g_rand_int_range(ad->rnd, 0, sea_floor.width);
76 curr_sea_floor_height = sea_floor.height - g_rand_int_range(ad->rnd, 0, sea_floor.height*4/5);
78 if(curr_sea_floor_height == 0)
79 curr_sea_floor_height = 1;
82 start_sea_floor_y = ad->ymax - curr_sea_floor_height;
85 for(i = (start_sea_floor_x - sea_floor.width); i < ad->xmax; i += sea_floor.width)
86 draw_image_bg(i, start_sea_floor_y, 0, 0, &sea_floor);
90 /* Number of plants and stones default max 15 */
92 if(bottom_settings.random_plants)
93 j = g_rand_int_range(ad->rnd, 1, bottom_settings.max_plants+1);
95 j = bottom_settings.max_plants;
97 step_max = curr_sea_floor_height / j;
99 /* The smallest stone/plant is 32 high */
100 current_loc = ad->ymax - curr_sea_floor_height + 10;
101 //printf("Curr loc: %d %d %d\n", current_loc, ad->ymax, curr_sea_floor_height);
103 /* See if we have a bottom dweller and or a hacktorn*/
106 for(i = 0;i < fish_settings->num_fish; i++){
107 if(fishes[i].type == BDWELLER || fishes[i].type == HAWTHORNE){
109 for(jj = 0; jj < 10; jj++){
110 if(ad->xmax-fishes[i].width == 0)
113 x = g_rand_int_range(ad->rnd, 0, ad->xmax - fishes[i].width);
115 for(l = 0; l < nfa; l++)
116 if(x > bx[l] && x < (bx[l]+bw[l]))
120 /* Do just 10 athempts to place a bottom fish, if not sucessfull,
121 then try next fish */
123 /* Make sure the fish is outside the picture. */
124 fishes[i].tx = 2 * ad->xmax;
130 bw[nfa] = fishes[i].width;
131 fishes[i].tx = bx[nfa];
132 /* (int)(20*(float)scale/100)*/
133 fishes[i].y = current_loc + curr_sea_floor_height / 3 + g_rand_int_range(ad->rnd, 0, curr_sea_floor_height) + ad->viewpoint_start_y - 30;
134 if(fishes[i].type == BDWELLER)
135 fishes[i].fast_frame_change = 0.02;
137 fishes[i].fast_frame_change = 0.07;
139 fishes[i].speed_mul = 0.0001;
145 /* Freeing sea floor. Not needed any longer */
146 g_object_unref(sea_floor.pixbuf);
149 for(i = 0; i < j; i++){
150 k=g_rand_int_range(ad->rnd, 0, NUMOFBOTTOMITEMS);
153 load_image_n_scale(bottom_items[k].image, &bottom_stuff,
154 1, (bottom_settings.scale / 2) + (g_rand_int_range(ad->rnd, 0, bottom_settings.scale / 2) * bottom_settings.scale / 100));
156 /* from -15 to ad.xmax+15 */
159 for(jj = 0; jj < 10; jj++){
160 x = g_rand_int_range(ad->rnd, 0, ad->xmax + 30) - 15;
161 for(l = 0;l < nfa; l++)
162 if(x > (bx[l] - bottom_stuff.width) && x < (bx[l] + bw[l])) break;
168 x = g_rand_int_range(ad->rnd, 0, ad->xmax + 30) - 15;
170 /* If we fail to put plants too many times.. */
171 if(jj == 10) continue;
173 /* Are they too close? */
174 if(abs(x - old_x) < bottom_stuff.width)
175 if((old_current_loc + old_height) > (bottom_stuff.height + current_loc)){
176 current_loc = old_current_loc + old_height - bottom_stuff.height + 5;
180 draw_image_bg(x, current_loc-bottom_stuff.height + 4,
181 0, g_rand_int_range(ad->rnd, 0, 2),
184 old_current_loc = current_loc;
185 current_loc += g_rand_int_range(ad->rnd, 0, step_max);
187 old_height = bottom_stuff.height;
190 g_object_unref(bottom_stuff.pixbuf);
192 bottom_stuff.image = NULL;
198 void bottom_exit(void)