11#include " zNPCSndTable.h"
2- #include " zNPCGoalVillager.h"
32
3+ #include " iSnd.h"
44#include " xString.h"
5+ #include " xutil.h"
6+ #include " zGameExtras.h"
7+ #include " zNPCSndLists.h"
58
6- #include < types.h >
9+ #define SND_COUNT 26
710
8- static char * g_strz_sndgroup[26 ];
9- static unsigned int g_hash_sndgroup[26 ];
10- static float g_tmrz_sndplay[26 ];
11+ static U32 g_hash_sndgroup[SND_COUNT];
12+ static F32 g_tmrz_sndplay[SND_COUNT] = {};
13+ static char * g_strz_sndgroup[SND_COUNT] = {
14+ " ListEnd" , " Encounter" , " Clanking" , " Exclaim" , " Ouch" , " Cheering" , " Respawn" ,
15+ " Alert" , " Dizzy" , " Dance" , " Laugh" , " Attack" , " Punch" , " WepLaunch" ,
16+ " Lightning" , " WarnBang" , " Death" , " DeathJelly" , " Bonked" , " Unbonked" , " TikiStack" ,
17+ " TikiExplode" , " TikiThunder" , " XSfxTalk" , " OneLiner" , " OneLinerToo"
18+ };
1119
1220void NPCS_Startup ()
1321{
14- for (int i = 0 ; i < (int )(sizeof (g_strz_sndgroup) / sizeof (char *)); i++)
22+ for (S32 i = 0 ; i < (S32 )(sizeof (g_strz_sndgroup) / sizeof (char *)); i++)
1523 {
1624 g_hash_sndgroup[i] = xStrHash (g_strz_sndgroup[i]);
1725 }
@@ -21,22 +29,27 @@ void NPCS_Shutdown()
2129{
2230}
2331
24- int NPCS_SndOkToPlay (en_NPC_SOUND sndtype )
32+ void NPCS_SndTimersUpdate (F32 dt )
2533{
26- if (sndtype == NPC_STYP_BOGUS)
34+ // non-matching: only producing one lfs instruction for -1.0f
35+ for (S32 i = 0 ; i < SND_COUNT; i++)
2736 {
28- return 1 ;
37+ g_tmrz_sndplay[i] = MAX (g_tmrz_sndplay[i] - dt, - 1 . 0f ) ;
2938 }
30- if (sndtype == NPC_STYP_LISTEND)
39+ }
40+
41+ void NPCS_SndTimersReset ()
42+ {
43+ // non-matching: missing lfs for -1.0f
44+ for (S32 i = 0 ; i < SND_COUNT; i++)
3145 {
32- return 0 ;
46+ g_tmrz_sndplay[i] = - 1 . 0f ;
3347 }
34- return g_tmrz_sndplay[sndtype] < 0 .0f ;
3548}
3649
37- void NPCS_SndTypePlayed (en_NPC_SOUND sndtype, float delayNext)
50+ void NPCS_SndTypePlayed (en_NPC_SOUND sndtype, F32 delayNext)
3851{
39- float tym = 2 .0f ;
52+ F32 tym = 2 .0f ;
4053
4154 switch (sndtype)
4255 {
@@ -58,3 +71,169 @@ void NPCS_SndTypePlayed(en_NPC_SOUND sndtype, float delayNext)
5871
5972 g_tmrz_sndplay[sndtype] = tym;
6073}
74+
75+ S32 NPCS_SndOkToPlay (en_NPC_SOUND sndtype)
76+ {
77+ if (sndtype == NPC_STYP_BOGUS)
78+ {
79+ return 1 ;
80+ }
81+ if (sndtype == NPC_STYP_LISTEND)
82+ {
83+ return 0 ;
84+ }
85+ return g_tmrz_sndplay[sndtype] < 0 .0f ;
86+ }
87+
88+ void NPCS_SndTablePrepare (NPCSndTrax* trax)
89+ {
90+ while (trax->typ_sound != NPC_STYP_LISTEND)
91+ {
92+ U32 sound_hash = xStrHash (trax->nam_sound );
93+ if (sound_hash != 0 && iSndLookup (sound_hash) != NULL )
94+ {
95+ trax->aid_sound = sound_hash;
96+ }
97+ else
98+ {
99+ trax->aid_sound = 0 ;
100+ }
101+ trax++;
102+ }
103+ }
104+
105+ NPCSndProp* NPCS_SndFindProps (en_NPC_SOUND sndtype)
106+ {
107+ NPCSndProp* sprop = g_sndProps;
108+ while (sprop->sndtype != NPC_STYP_LISTEND)
109+ {
110+ if (sprop->sndtype == sndtype)
111+ {
112+ break ;
113+ }
114+ sprop++;
115+ }
116+ return sprop;
117+ }
118+
119+ en_NPC_SOUND NPCS_SndTypeFromHash (U32 aid_snd, NPCSndTrax* cust, NPCSndTrax* share)
120+ {
121+ // non-matching
122+ en_NPC_SOUND da_type = NPC_STYP_BOGUS;
123+ NPCSndTrax* trax;
124+
125+ for (S32 i = 0 ; i <= 3 ; i++)
126+ {
127+ if (i == 0 )
128+ {
129+ trax = cust;
130+ }
131+ else if (i == 1 )
132+ {
133+ trax = share;
134+ }
135+ else if (i == 2 )
136+ {
137+ trax = g_sndTrax_General;
138+ }
139+ else
140+ {
141+ trax = g_sndTrax_Universal;
142+ }
143+
144+ if (trax != NULL )
145+ {
146+ for (; trax->typ_sound != NPC_STYP_LISTEND; trax = trax + 1 )
147+ {
148+ if (trax->aid_sound == aid_snd)
149+ {
150+ da_type = trax->typ_sound ;
151+
152+ return da_type;
153+ }
154+ }
155+ }
156+ }
157+
158+ return da_type;
159+ }
160+
161+ // WIP
162+ U32 NPCS_SndPickSimilar (en_NPC_SOUND sndtype, NPCSndTrax* cust, NPCSndTrax* share)
163+ {
164+ S32 cnt = 0 ;
165+ S32 list[32 ] = {};
166+ F32 wts[32 ] = { 1 .0f };
167+
168+ for (S32 si = 0 ; si < 4 ; si++)
169+ {
170+ NPCSndTrax* trax;
171+ F32 weight;
172+
173+ if (si == 0 )
174+ {
175+ trax = cust;
176+ weight = 2 .0f ;
177+ }
178+ else if (si == 1 )
179+ {
180+ trax = share;
181+ weight = 1 .5f ;
182+ }
183+ else
184+ {
185+ if (cnt >= 5 )
186+ {
187+ trax = NULL ;
188+ weight = 0 .0f ;
189+ }
190+ else if (si == 2 )
191+ {
192+ trax = g_sndTrax_General;
193+ weight = 1 .0f ;
194+ }
195+ else
196+ {
197+ trax = g_sndTrax_Universal;
198+ weight = 1 .0f ;
199+ }
200+ }
201+
202+ if (trax == NULL )
203+ {
204+ continue ;
205+ }
206+
207+ bool in_group = false ;
208+ for (; trax->typ_sound != NPC_STYP_LISTEND; trax++)
209+ {
210+ if (trax->typ_sound == sndtype)
211+ {
212+ in_group = true ;
213+ if (trax->aid_sound != 0 && cnt < 32 )
214+ {
215+ wts[cnt] = weight;
216+ list[cnt] = trax->aid_sound ;
217+ cnt++;
218+ }
219+ }
220+ else if (in_group)
221+ {
222+ break ;
223+ }
224+
225+ if (cnt >= 32 )
226+ {
227+ break ;
228+ }
229+ }
230+ }
231+
232+ if (cnt > 0 )
233+ {
234+ xUtil_wtadjust (wts, cnt, 1 .0f );
235+ return xUtil_choose (list, cnt, wts);
236+ }
237+
238+ return 0 ;
239+ }
0 commit comments