avp_mod is an open source project powered by Assembla

Assembla offers free public and private SVN/Git repositories and project hosting with bug/issue tracking and collaboration tools.

Commitebd360ec63ec976c0...
/c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#include "system.h"
#include "stratdef.h"
#include "bh_snds.h"
#include "psndplat.h"
#include "bh_types.h"
#include <assert.h>
#include <stdlib.h>
#include <string.h>

void SoundBehaveInit(void* bhdata, STRATEGYBLOCK* sbptr)
{
    SOUND_TOOLS_TEMPLATE * stt = (SOUND_TOOLS_TEMPLATE *)bhdata;

    assert (sbptr && stt);

    SOUND_BEHAV_BLOCK * sbb = malloc (sizeof (SOUND_BEHAV_BLOCK));

    if(NULL != sbb)
    {
        sbptr->dataptr = sbb;
        sbb->sound_number = stt->sound_number;
        sbb->position = stt->position;
        sbb->inner_range = stt->inner_range;
        sbb->outer_range = stt->outer_range;
        sbb->max_volume = stt->max_volume;
        sbb->pitch = stt->pitch;

        sbb->sound_not_started = 1;

        sbb->wav_name = malloc (strlen (stt->sound_name) + 1);
        if(NULL == sbb->wav_name)
        {
            RemoveBehaviourStrategy(sbptr);
            return;
        }

        strcpy (sbb->wav_name, stt->sound_name);
        sbb->playing=stt->playing;
        sbb->loop = stt->loop;
        sbb->activ_no = SOUND_NOACTIVEINDEX;
    }
    else
    {
        RemoveBehaviourStrategy(sbptr);
    }
}

void SoundBehaveFun (STRATEGYBLOCK * sbptr)
{
    SOUND_BEHAV_BLOCK * sbb = (SOUND_BEHAV_BLOCK*)sbptr->dataptr;

    if(SID_NOSOUND == sbb->sound_number)
        return;

    int dist = VectorDistance(&PlayerStatus.DisplayBlock->ObWorld, &sbb->position);

    if (sbb->sound_not_started && PlayerStatus.DisplayBlock)
    {
        SOUND3DDATA s3d;

        if(sbb->playing)
        {
            //start playing the sound , but only if it is close enough

            if(dist <= sbb->outer_range)
            {
                s3d.position = sbb->position;
                s3d.inner_range = sbb->inner_range;
                s3d.outer_range = sbb->outer_range;
                s3d.velocity.vx = s3d.velocity.vy = s3d.velocity.vz = 0;

                Sound_Play ((SOUNDINDEX)sbb->sound_number, (sbb->loop ? "nelh" : "neh"), &s3d, &sbb->activ_no);

                if (sbb->activ_no != SOUND_NOACTIVEINDEX)
                {
                    Sound_ChangeVolume (sbb->activ_no, sbb->max_volume);
                    Sound_ChangePitch (sbb->activ_no, sbb->pitch);
                }
            }
        }

        sbb->sound_not_started = 0;
    }

    /* KJL 14:15:39 12/8/97 - kill any objects that are too far away */
    if(sbb->playing)
    {
        if(dist > sbb->outer_range)
        {
            //stop sound if it is playing

            if (sbb->activ_no != SOUND_NOACTIVEINDEX)
                Sound_Stop (sbb->activ_no);

            //not much point in restarting a non-looping sound, since it won't restart at the right place
            if(!sbb->loop && sbb->playing)
                sbb->playing = 0;

        return;
        }
    }

    if (sbb->activ_no == SOUND_NOACTIVEINDEX && (SID_NOSOUND != sbb->sound_number) && sbb->playing)
    {
        if(sbb->loop)
        {
            SOUND3DDATA s3d;

            s3d.position = sbb->position;
            s3d.inner_range = sbb->inner_range;
            s3d.outer_range = sbb->outer_range;
            s3d.velocity.vx = s3d.velocity.vy = s3d.velocity.vz = 0;

            Sound_Play((SOUNDINDEX)sbb->sound_number, (sbb->loop ? "nelh" : "neh"), &s3d, &sbb->activ_no);

            if (sbb->activ_no != SOUND_NOACTIVEINDEX)
            {
                Sound_ChangeVolume (sbb->activ_no, sbb->max_volume);
                Sound_ChangePitch (sbb->activ_no, sbb->pitch);
            }
        }
        else //sound has finished playing
        {
            sbb->playing = 0;
        }
    }
}

void StartPlacedSoundPlaying(STRATEGYBLOCK* sbptr)
{
    assert(sbptr);
    assert(sbptr->type == I_BehaviourPlacedSound);
    SOUND_BEHAV_BLOCK * sbb = (SOUND_BEHAV_BLOCK*)sbptr->dataptr;

    if(SID_NOSOUND == sbb->sound_number)
        return;

    if(!sbb->playing)
    {
        //if sound is within range start it
        int dist = VectorDistance(&PlayerStatus.DisplayBlock->ObWorld, &sbb->position);

        if(dist < sbb->outer_range)
        {
            SOUND3DDATA s3d;

            s3d.position = sbb->position;
            s3d.inner_range = sbb->inner_range;
            s3d.outer_range = sbb->outer_range;
            s3d.velocity.vx = s3d.velocity.vy = s3d.velocity.vz = 0;

            Sound_Play ((SOUNDINDEX)sbb->sound_number, (sbb->loop ? "nelh" : "neh"), &s3d, &sbb->activ_no);

            if (sbb->activ_no != SOUND_NOACTIVEINDEX)
            {
                Sound_ChangeVolume (sbb->activ_no, sbb->max_volume);
                Sound_ChangePitch (sbb->activ_no, sbb->pitch);
            }
        }
        sbb->playing = 1;
    }
}

void StopPlacedSoundPlaying(STRATEGYBLOCK* sbptr)
{
    assert(sbptr);
    assert(sbptr->type == I_BehaviourPlacedSound);
    SOUND_BEHAV_BLOCK * sbb = (SOUND_BEHAV_BLOCK*)sbptr->dataptr;

    if(SID_NOSOUND == sbb->sound_number)
        return;

    if(sbb->playing)
    {
        sbb->playing = 0;

        if (sbb->activ_no != SOUND_NOACTIVEINDEX)
            Sound_Stop (sbb->activ_no);
    }
}

/*--------------------**
** Loading and Saving **
**--------------------*/
#include "savegame.h"
typedef struct placed_sound_save_block
{
    SAVE_BLOCK_STRATEGY_HEADER header;

    int playing;

} PLACED_SOUND_SAVE_BLOCK;

//defines for load/save macros
#define SAVELOAD_BLOCK block
#define SAVELOAD_BEHAV sbb

void LoadStrategy_PlacedSound(SAVE_BLOCK_STRATEGY_HEADER* header)
{
    PLACED_SOUND_SAVE_BLOCK* block = (PLACED_SOUND_SAVE_BLOCK*) header;

    //check the size of the save block
    if(header->size != sizeof(*block))
        return;

    //find the existing strategy block
    STRATEGYBLOCK* sbPtr = FindSBWithName(header->SBname);

    if(!sbPtr)
        return;

    //make sure the strategy found is of the right type
    if(sbPtr->type != I_BehaviourPlacedSound)
        return;

    SOUND_BEHAV_BLOCK * sbb = (SOUND_BEHAV_BLOCK *)sbPtr->dataptr;

    //start copying stuff
    COPYELEMENT_LOAD(playing)

    sbb->sound_not_started = 0;
    Load_SoundState(&sbb->activ_no);
}

void SaveStrategy_PlacedSound(STRATEGYBLOCK* sbPtr)
{
    PLACED_SOUND_SAVE_BLOCK* block;
    SOUND_BEHAV_BLOCK * sbb = (SOUND_BEHAV_BLOCK *)sbPtr->dataptr;

    GET_STRATEGY_SAVE_BLOCK(block,sbPtr);

    //start copying stuff
    COPYELEMENT_SAVE(playing)

    Save_SoundState(&sbb->activ_no);
}
Ajax-loader Loading, please wait...