1 /*
2  * Triplane Classic - a side-scrolling dogfighting game.
3  * Copyright (C) 1996,1997,2009  Dodekaedron Software Creations Oy
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  *
18  * tjt@users.sourceforge.net
19  */
20 
21 #include "world/tripaudio.h"
22 #include "settings.h"
23 #include "world/plane.h"
24 #include "triplane.h"
25 #include "util/wutil.h"
26 
27 sb_mod_file *triplane_mod;
28 sb_mod_file *aces_mod;
29 
30 sb_sample *sample_itexp[3];
31 sb_sample *sample_bomb[4];
32 sb_sample *sample_hitti;
33 sb_sample *sample_konsu[4];
34 sb_sample *sample_propelli;
35 sb_sample *sample_hit[4];
36 sb_sample *sample_aagun;
37 sb_sample *sample_splash[3];
38 sb_sample *sample_spcrash;
39 sb_sample *sample_hurr;
40 sb_sample *sample_itshot;
41 sb_sample *sample_crash[2];
42 sb_sample *sample_alku;
43 sb_sample *sample_die[9];
44 
45 int alku_sample_over = 0;
46 int sfx_loaded = 0;
47 int music_loaded = 0;
48 
kkbase_sound(int type,int kkbase_x)49 void kkbase_sound(int type, int kkbase_x) {
50     if (config.ground_i_sounds && config.sound_on && config.sfx_on) {
51         if (type)
52             play_2d_sample(sample_itshot, player_x_8[solo_country], kkbase_x);
53         else
54             play_2d_sample(sample_aagun, player_x_8[solo_country], kkbase_x);
55     }
56 }
57 
itgun_sound(int itgun_x)58 void itgun_sound(int itgun_x) {
59     if (config.ground_i_sounds && config.sound_on && config.sfx_on) {
60         play_2d_sample(sample_itexp[wrandom(3)], player_x_8[solo_country], itgun_x);
61     }
62 }
63 
load_all_samples(void)64 void load_all_samples(void) {
65     int l;
66 
67     sample_itexp[0] = sample_load("Itexp1");
68     sample_itexp[0]->left_volume = SAMPLE_VOLUME;
69     sample_itexp[0]->right_volume = SAMPLE_VOLUME;
70 
71     sample_itexp[1] = sample_load("Itexp2");
72     sample_itexp[1]->left_volume = SAMPLE_VOLUME;
73     sample_itexp[1]->right_volume = SAMPLE_VOLUME;
74 
75     sample_itexp[2] = sample_load("Itexp3");
76     sample_itexp[2]->left_volume = SAMPLE_VOLUME;
77     sample_itexp[2]->right_volume = SAMPLE_VOLUME;
78 
79     sample_bomb[1] = sample_load("Bomb1");
80     sample_bomb[1]->left_volume = SAMPLE_VOLUME;
81     sample_bomb[1]->right_volume = SAMPLE_VOLUME;
82 
83     sample_bomb[2] = sample_load("Bomb2");
84     sample_bomb[2]->left_volume = SAMPLE_VOLUME;
85     sample_bomb[2]->right_volume = SAMPLE_VOLUME;
86 
87     sample_bomb[3] = sample_load("Bomb3");
88     sample_bomb[3]->left_volume = SAMPLE_VOLUME;
89     sample_bomb[3]->right_volume = SAMPLE_VOLUME;
90 
91     sample_konsu[1] = sample_load("Guns1");
92     sample_konsu[1]->left_volume = SAMPLE_VOLUME;
93     sample_konsu[1]->right_volume = SAMPLE_VOLUME;
94 
95     sample_konsu[2] = sample_load("Guns2");
96     sample_konsu[2]->left_volume = SAMPLE_VOLUME;
97     sample_konsu[2]->right_volume = SAMPLE_VOLUME;
98 
99     sample_konsu[3] = sample_load("Guns3");
100     sample_konsu[3]->left_volume = SAMPLE_VOLUME;
101     sample_konsu[3]->right_volume = SAMPLE_VOLUME;
102 
103     sample_hit[0] = sample_load("Hit1");
104     sample_hit[0]->left_volume = SAMPLE_VOLUME;
105     sample_hit[0]->right_volume = SAMPLE_VOLUME;
106 
107     sample_hit[1] = sample_load("Hit2");
108     sample_hit[1]->left_volume = SAMPLE_VOLUME;
109     sample_hit[1]->right_volume = SAMPLE_VOLUME;
110 
111     sample_hit[2] = sample_load("Hit3");
112     sample_hit[2]->left_volume = SAMPLE_VOLUME;
113     sample_hit[2]->right_volume = SAMPLE_VOLUME;
114 
115     sample_hit[3] = sample_load("Hit4");
116     sample_hit[3]->left_volume = SAMPLE_VOLUME;
117     sample_hit[3]->right_volume = SAMPLE_VOLUME;
118 
119     sample_aagun = sample_load("Aagun");
120     sample_aagun->left_volume = SAMPLE_VOLUME;
121     sample_aagun->right_volume = SAMPLE_VOLUME;
122 
123     sample_splash[0] = sample_load("Spla1");
124     sample_splash[0]->left_volume = SAMPLE_VOLUME;
125     sample_splash[0]->right_volume = SAMPLE_VOLUME;
126 
127     sample_splash[1] = sample_load("Spla2");
128     sample_splash[1]->left_volume = SAMPLE_VOLUME;
129     sample_splash[1]->right_volume = SAMPLE_VOLUME;
130 
131     sample_splash[2] = sample_load("Spla3");
132     sample_splash[2]->left_volume = SAMPLE_VOLUME;
133     sample_splash[2]->right_volume = SAMPLE_VOLUME;
134 
135     sample_hurr = sample_load("Hurr");
136     sample_hurr->left_volume = SAMPLE_VOLUME;
137     sample_hurr->right_volume = SAMPLE_VOLUME;
138 
139     sample_itshot = sample_load("Itshot");
140     sample_itshot->left_volume = SAMPLE_VOLUME;
141     sample_itshot->right_volume = SAMPLE_VOLUME;
142 
143     sample_spcrash = sample_load("Spcra1");
144     sample_spcrash->left_volume = SAMPLE_VOLUME;
145     sample_spcrash->right_volume = SAMPLE_VOLUME;
146 
147     sample_crash[0] = sample_load("Crash1");
148     sample_crash[0]->left_volume = SAMPLE_VOLUME;
149     sample_crash[0]->right_volume = SAMPLE_VOLUME;
150 
151     sample_crash[1] = sample_load("Crash2");
152     sample_crash[1]->left_volume = SAMPLE_VOLUME;
153     sample_crash[1]->right_volume = SAMPLE_VOLUME;
154 
155     sample_alku = sample_load("Alku");
156     sample_alku->left_volume = 32;
157     sample_alku->right_volume = 32;
158 
159     sample_die[0] = sample_load("Die1");
160     sample_die[1] = sample_load("Die2");
161     sample_die[2] = sample_load("Die3");
162     sample_die[3] = sample_load("Die4");
163     sample_die[4] = sample_load("Die5");
164     sample_die[5] = sample_load("Die6");
165     sample_die[6] = sample_load("Die7");
166     sample_die[7] = sample_load("Die8");
167     sample_die[8] = sample_load("Die9");
168 
169     for (l = 0; l < 9; l++) {
170         sample_die[l]->left_volume = SAMPLE_VOLUME - 8;
171         sample_die[l]->right_volume = SAMPLE_VOLUME - 8;
172     }
173 }
174 
load_sfx(void)175 void load_sfx(void) {
176     sfx_loaded = 1;
177     load_all_samples();
178 }
179 
load_music(void)180 void load_music(void) {
181     music_loaded = 1;
182 
183     triplane_mod = sdl_load_mod_file("music1");
184     aces_mod = sdl_load_mod_file("maces");
185 }
186 
clear_sfx(void)187 void clear_sfx(void) {
188     int l;
189 
190     sfx_loaded = 0;
191 
192     sdl_free_sample(sample_itexp[0]);
193     sdl_free_sample(sample_itexp[1]);
194     sdl_free_sample(sample_itexp[2]);
195     sdl_free_sample(sample_bomb[1]);
196     sdl_free_sample(sample_bomb[2]);
197     sdl_free_sample(sample_bomb[3]);
198     sdl_free_sample(sample_konsu[1]);
199     sdl_free_sample(sample_konsu[2]);
200     sdl_free_sample(sample_konsu[3]);
201     sdl_free_sample(sample_hit[0]);
202     sdl_free_sample(sample_hit[1]);
203     sdl_free_sample(sample_hit[2]);
204     sdl_free_sample(sample_hit[3]);
205     sdl_free_sample(sample_aagun);
206     sdl_free_sample(sample_splash[0]);
207     sdl_free_sample(sample_splash[1]);
208     sdl_free_sample(sample_splash[2]);
209     sdl_free_sample(sample_hurr);
210     sdl_free_sample(sample_spcrash);
211     sdl_free_sample(sample_itshot);
212     sdl_free_sample(sample_crash[0]);
213     sdl_free_sample(sample_crash[1]);
214     sdl_free_sample(sample_alku);
215 
216     for (l = 0; l < 9; l++) {
217         sdl_free_sample(sample_die[l]);
218 
219 
220     }
221 }
222 
223 
clear_music(void)224 void clear_music(void) {
225     music_loaded = 0;
226     sdl_free_mod_file(triplane_mod);
227     sdl_free_mod_file(aces_mod);
228 }
229