9a76eea2f5a4966f140916a40d0f5bf4b00fb01becea45defab258134a175bcf8a178f1ac7e4243e
21
    SOUNDINDEX last_sound;
21
    SOUNDINDEX last_sound;
22
};
22
};
23
 
23
 
24
struct ScreamVoiceType
 
 
25
{
 
 
26
    struct ScreamSoundCategory* category;
 
 
27
};
 
 
28
 
 
 
29
struct CharacterSoundEffects
24
struct CharacterSoundEffects
30
{
25
{
31
    int num_voice_types;
26
    int num_voice_types;
32
    int num_voice_cats;
27
    int num_voice_cats;
33
    struct ScreamVoiceType* voice_types;
28
 
 
 
29
    struct
 
 
30
    {
 
 
31
        struct ScreamSoundCategory* category;
 
 
32
 
 
 
33
    } *voice_types;
 
 
34
 
34
    SOUNDINDEX global_last_sound;
35
    SOUNDINDEX global_last_sound;
 
 
36
    const char *data_file;
 
 
37
    const char *directory;
35
};
38
};
36
 
39
 
37
static struct CharacterSoundEffects MarineSounds =    {5, 15, 0, SID_NOSOUND};
40
static struct CharacterSoundEffects MarineSounds =    {0, 0, NULL, SID_NOSOUND, "marsound.dat", "marinevoice"};
38
static struct CharacterSoundEffects AlienSounds =    {3,  9, 0, SID_NOSOUND};
41
static struct CharacterSoundEffects AlienSounds =    {0, 0, NULL, SID_NOSOUND, "aliensound.dat", "alienvoice"};
39
static struct CharacterSoundEffects PredatorSounds =    {1,  9, 0, SID_NOSOUND};
42
static struct CharacterSoundEffects PredatorSounds =    {0, 0, NULL, SID_NOSOUND, "predsound.dat", "predatorvoice"};
40
static struct CharacterSoundEffects QueenSounds =    {1,  3, 0, SID_NOSOUND};
43
static struct CharacterSoundEffects QueenSounds =    {0, 0, NULL, SID_NOSOUND, "queensound.dat", "queenvoice"};
41
 
44
 
42
static int load_scream_sounds(const char *path, const char * file_name)
45
static int load_scream_sounds(const char *path, const char * file_name)
43
{
46
{
...
 
...
 
56
 
59
 
57
    if ( i < SID_ENDOF_SCREAMSLOTS)
60
    if ( i < SID_ENDOF_SCREAMSLOTS)
58
    {
61
    {
59
        if (!GameSounds[i].loaded && LoadWavFile(i, path, file_name))
62
        char full_path[50];
 
 
63
        sprintf(full_path, "npc%c%s", DIR_SEPARATOR, path);
 
 
64
        if (!GameSounds[i].loaded && LoadWavFile(i, full_path, file_name))
60
            return i;
65
            return i;
61
    }
66
    }
62
 
67
 
63
return SID_NOSOUND;
68
return SID_NOSOUND;
64
}
69
}
65
 
70
 
66
static void LoadSounds(struct CharacterSoundEffects *testus, const char *data_file, const char *directory)
71
static void LoadSoundsFromFile(struct CharacterSoundEffects *testus)
67
{
72
{
68
    if(testus->voice_types)
73
    char file_path[50];
69
        return;
74
    sprintf(file_path, "fastfile%c%s", DIR_SEPARATOR, testus->data_file);
70
 
75
 
71
    FILE *file = OpenGameFile(data_file, 1, FILETYPE_GAMEDATA);
76
    FILE *file = OpenGameFile(file_path, 1, FILETYPE_GAMEDATA);
72
 
77
 
73
    if(file == NULL)
78
    if(file == NULL)
74
    {
79
    {
75
        printf("Failed to open %s\n", data_file);
80
        printf("Failed to open %s\n", testus->data_file);
76
        return;
81
        return;
77
    }
82
    }
78
 
83
 
...
 
...
 
90
        int i;
95
        int i;
91
        char* bufpos = buffer + 8;
96
        char* bufpos = buffer + 8;
92
 
97
 
93
        //num_voice_types = *(int*)bufpos;
98
        testus->num_voice_types = *(int*)bufpos;
94
        bufpos += 4;
99
        bufpos += 4;
95
        //num_voice_cats = *(int*)bufpos;
100
        testus->num_voice_cats = *(int*)bufpos;
96
        bufpos += 4;
101
        bufpos += 4;
97
 
102
 
98
        testus->voice_types = malloc(testus->num_voice_types * sizeof(struct ScreamVoiceType));
103
        testus->voice_types = malloc(testus->num_voice_types * sizeof(*testus->voice_types));
99
 
104
 
100
        for(i=0; i < testus->num_voice_types; i++)    
105
        for(i=0; i < testus->num_voice_types; i++)    
101
        {
106
        {
...
 
...
 
131
                    //bufpos += 4;
136
                    //bufpos += 4;
132
                    bufpos += 8;
137
                    bufpos += 8;
133
 
138
 
134
                    sound->sound_number = (SOUNDINDEX) load_scream_sounds(directory, file_name);
139
                    sound->sound_number = (SOUNDINDEX) load_scream_sounds(testus->directory, file_name);
135
 
140
 
136
                    if(SID_NOSOUND != sound->sound_number)
141
                    if(SID_NOSOUND != sound->sound_number)
137
                        k++;
142
                        k++;
...
 
...
 
145
    free(buffer);
150
    free(buffer);
146
}
151
}
147
 
152
 
148
void UnloadSounds(struct CharacterSoundEffects * testus)
153
static void FreeSoundStruct(struct CharacterSoundEffects * testus)
149
{
154
{
150
    if(testus->voice_types)
155
    if(testus->voice_types)
151
    {
156
    {
...
 
...
 
171
    }
176
    }
172
}
177
}
173
 
178
 
174
static void PlaySound(struct CharacterSoundEffects * testus, int VoiceType, int SoundCategory, int PitchShift, int* ExternalRef, VECTORCH* Location)
179
void SpeciesSound(int VoiceType, int SoundCategory, int PitchShift, int *ExternalRef, VECTORCH* Location, enum SPECIES_SOUND species)
175
{
180
{
176
//    assert(Location);
181
    struct CharacterSoundEffects * testus;
 
 
182
 
 
 
183
    switch(species)
 
 
184
    {
 
 
185
        case ALIEN_SOUND:
 
 
186
            testus = &AlienSounds;
 
 
187
        break;
 
 
188
        case HUMAN_SOUND:
 
 
189
            testus = &MarineSounds;
 
 
190
        break;
 
 
191
        case PREDATOR_SOUND:
 
 
192
            testus = &PredatorSounds;
 
 
193
        break;
 
 
194
        case QUEEN_SOUND:
 
 
195
            testus = &QueenSounds;
 
 
196
    }
 
 
197
 
 
 
198
    if(ExternalRef && (*ExternalRef != SOUND_NOACTIVEINDEX))
 
 
199
        return; //already playing a sound
177
 
200
 
178
    if(!testus->voice_types || VoiceType < 0 || VoiceType >= testus->num_voice_types)
201
    if(!testus->voice_types || VoiceType < 0 || VoiceType >= testus->num_voice_types)
179
        return;
202
        return;
...
 
...
 
181
    if(SoundCategory < 0 || SoundCategory >= testus->num_voice_cats)
204
    if(SoundCategory < 0 || SoundCategory >= testus->num_voice_cats)
182
        return;
205
        return;
183
 
206
 
184
    if(ExternalRef && (*ExternalRef != SOUND_NOACTIVEINDEX))
 
 
185
        return; //already playing a sound
 
 
186
 
 
 
187
    struct ScreamSoundCategory* cat = &testus->voice_types[VoiceType].category[SoundCategory];
207
    struct ScreamSoundCategory* cat = &testus->voice_types[VoiceType].category[SoundCategory];
188
    //make sure there are some sound for this category
208
    //make sure there are some sound for this category
189
 
209
 
...
 
...
 
213
 
233
 
214
    struct ScreamSound* sound = &cat->sounds[index];
234
    struct ScreamSound* sound = &cat->sounds[index];
215
 
235
 
216
    int pitch = sound->pitch+PitchShift;
236
    int pitch = sound->pitch + PitchShift;
217
 
237
 
218
    if(Location)
238
    if(Location)
219
        Sound_Play((SOUNDINDEX)sound->sound_number, "dvpe", Location, sound->volume, pitch, ExternalRef);
239
        Sound_Play((SOUNDINDEX)sound->sound_number, "vpescd", sound->volume, pitch, ExternalRef, (int)species, SoundCategory, Location);
220
    else
240
    else
221
        Sound_Play((SOUNDINDEX)sound->sound_number, "vpe", sound->volume, pitch, ExternalRef);
241
        Sound_Play((SOUNDINDEX)sound->sound_number, "vpesc",  sound->volume, pitch, ExternalRef, (int)species, SoundCategory);
222
 
242
 
223
    //take note of the last sound played
243
    //take note of the last sound played
224
    testus->global_last_sound = cat->last_sound = (SOUNDINDEX)sound->sound_number;
244
    testus->global_last_sound = cat->last_sound = (SOUNDINDEX)sound->sound_number;
225
}
245
}
226
 
246
 
227
void UnloadScreamSounds()
247
void UnloadSounds()
228
{
 
 
229
    UnloadSounds(&MarineSounds);
 
 
230
    UnloadSounds(&AlienSounds);
 
 
231
    UnloadSounds(&PredatorSounds);
 
 
232
    UnloadSounds(&QueenSounds);
 
 
233
}
 
 
234
 
 
 
235
void LoadMarineScreamSounds()
 
 
236
{
 
 
237
    LoadSounds(&MarineSounds, "fastfile/marsound.dat", "npc/marinevoice");
 
 
238
}
 
 
239
 
 
 
240
void LoadAlienScreamSounds()
 
 
241
{
 
 
242
    LoadSounds(&AlienSounds, "fastfile/aliensound.dat", "npc/alienvoice");
 
 
243
}
 
 
244
 
 
 
245
void LoadPredatorScreamSounds()
 
 
246
{
 
 
247
    LoadSounds(&PredatorSounds, "fastfile/predsound.dat", "npc/predatorvoice");
 
 
248
}
 
 
249
 
 
 
250
void LoadQueenScreamSounds()
 
 
251
{
 
 
252
    LoadSounds(&QueenSounds, "fastfile/queensound.dat", "npc/queenvoice");
 
 
253
}
 
 
254
 
 
 
255
void PlayMarineScream(int VoiceType, int SoundCategory, int PitchShift, int* ExternalRef, VECTORCH* Location)
 
 
256
{
 
 
257
    PlaySound(&MarineSounds, VoiceType, SoundCategory, PitchShift, ExternalRef, Location);
 
 
258
}
 
 
259
 
 
 
260
void PlayAlienSound(int VoiceType, int SoundCategory, int PitchShift, int* ExternalRef, VECTORCH* Location)
 
 
261
{
 
 
262
    PlaySound(&AlienSounds, VoiceType, SoundCategory, PitchShift, ExternalRef, Location);
 
 
263
}
 
 
264
 
 
 
265
void PlayPredatorSound(int VoiceType, int SoundCategory, int PitchShift, int* ExternalRef, VECTORCH* Location)
 
 
266
{
248
{
267
    PlaySound(&PredatorSounds, VoiceType, SoundCategory, PitchShift, ExternalRef, Location);
249
    FreeSoundStruct(&MarineSounds);
 
 
250
    FreeSoundStruct(&AlienSounds);
 
 
251
    FreeSoundStruct(&PredatorSounds);
 
 
252
    FreeSoundStruct(&QueenSounds);
268
}
253
}
269
 
254
 
270
void PlayQueenSound(int VoiceType, int SoundCategory, int PitchShift, int* ExternalRef, VECTORCH* Location)
255
void LoadSounds()
271
{
256
{
272
    PlaySound(&QueenSounds, VoiceType, SoundCategory, PitchShift, ExternalRef, Location);
257
    LoadSoundsFromFile(&MarineSounds);
 
 
258
    LoadSoundsFromFile(&AlienSounds);
 
 
259
    LoadSoundsFromFile(&PredatorSounds);
 
 
260
    LoadSoundsFromFile(&QueenSounds);
273
}
261
}