start to add some SOUND_TRIGGER_ACHIEVEMENTS code

Start to add supporting code to windsound and macsound. The latter
remains commented out because I haven't had a chance to try
it on macOS yet.

In order to test it out, I added two more stock sounds:
sa2_xplevelup and sa2_xpleveldown.
This commit is contained in:
nhmall
2023-02-04 14:28:59 -05:00
parent 9fd87db543
commit 36ca64acdb
17 changed files with 13684 additions and 21 deletions

View File

@@ -335,8 +335,8 @@ enum ambiences {
};
enum achievements_arg2 {
sa2_splashscreen, sa2_newgame_nosplash, sa2_restoregame,
sa2_xplevelup, sa2_xpleveldown
sa2_zero_invalid, sa2_splashscreen, sa2_newgame_nosplash, sa2_restoregame,
sa2_xplevelup, sa2_xpleveldown, number_of_sa2_entries
};
/*

View File

@@ -39,7 +39,8 @@ static int affiliate(int32_t seid, const char *soundname);
struct sound_procs macsound_procs = {
SOUNDID(macsound),
SOUND_TRIGGER_HEROMUSIC | SOUND_TRIGGER_SOUNDEFFECTS,
SOUND_TRIGGER_HEROMUSIC | SOUND_TRIGGER_SOUNDEFFECTS
| SOUND_TRIGGER_ACHIEVEMENTS,
macsound_init_nhsound,
macsound_exit_nhsound,
macsound_achievement,
@@ -60,14 +61,6 @@ macsound_exit_nhsound(const char *reason UNUSED)
{
/* Close / Terminate external sound library */
}
/* fulfill SOUND_TRIGGER_ACHIEVEMENTS */
static void
macsound_achievement(schar ach1 UNUSED, schar ach2 UNUSED, int32_t repeat UNUSED)
{
}
static void
@@ -77,7 +70,7 @@ macsound_ambience(int32_t ambienceid UNUSED, int32_t ambience_action UNUSED,
}
/* magic number 47 is the current number of sound_ files to include */
#define EXTRA_SOUNDS 47
#define EXTRA_SOUNDS (47 + number_of_sa2_entries)
static int32_t affiliation[number_of_se_entries + EXTRA_SOUNDS] = { 0 };
static NSString *soundstring[number_of_se_entries + EXTRA_SOUNDS];
@@ -119,6 +112,9 @@ macsound_soundeffect(char *desc UNUSED, int32_t seid, int volume UNUSED)
#define WAVEMUSIC_SOUNDS
/* This is the number of sound_ files that support WAVEMUSIC_SOUNDS */
static const int wavemusic_sound_count = 94;
/* fulfill SOUND_TRIGGER_HEROMUSIC */
static void macsound_hero_playnotes(int32_t instrument,
const char *str, int32_t vol UNUSED)
@@ -221,6 +217,62 @@ static void macsound_hero_playnotes(int32_t instrument,
#endif
}
/* #define ACHIEVEMENT_SOUNDS */
/* fulfill SOUND_TRIGGER_ACHIEVEMENTS */
static void
macsound_achievement(schar ach1 UNUSED, schar ach2 UNUSED, int32_t repeat UNUSED)
{
#ifdef ACHIEVEMENT_SOUNDS
char resourcename[120];
uint32_t pseudo_seid, pseudo_seid_base;
if (ach1 == 0 && ach2 == 0)
return;
resourcename[0] = '\0';
pseudo_seid_base = 0;
if (ach1 == 0) {
int sa2 = (int) ach2;
if (sa2 > sa2_zero_invalid && sa2 < number_of_sa2_entries) {
switch(sa2) {
case sa2_splashscreen:
Strcpy(resourcename, "sa2_splashscreen");
break;
case sa2_newgame_nosplash:
Strcpy(resourcename, "sa2_newgame_nosplash");
break;
case sa2_restoregame:
Strcpy(resourcename, "sa2_restoregame");
break;
case sa2_xplevelup:
Strcpy(resourcename, "sa2_xplevelup");
break;
case sa2_xpleveldown:
Strcpy(resourcename, "sa2_xpleveldown");
break;
}
if (resourcename[0] == '\0')
return;
/* get past se_ entries and the wavemusic entries */
pseudo_seid_base += (number_of_se_entries + wavemusic_sound_count);
pseudo_seid = pseudo_seid_base + sa2;
if (!affiliation[pseudo_seid]) {
affiliate(pseudo_seid, resourcename);
}
if (affiliation[pseudo_seid]) {
if ([seSound[pseudo_seid] isPlaying])
[seSound[pseudo_seid] stop];
[seSound[pseudo_seid] play];
}
}
}
#endif
}
/* fulfill SOUND_TRIGGER_USERSOUNDS */
static void
macsound_play_usersound(char *filename UNUSED, int volume UNUSED, int idx UNUSED)

View File

@@ -149,4 +149,24 @@ Description of modifications made to the original:
- .572 seconds
File: sa2_xplevelup.wav
Source: https://freesound.org/people/UsuarioLeal/sounds/446464/
Original: download/446464__usuarioleal__21-xilofono.wav
By: https://freesound.org/people/UsuarioLeal/
License: http://creativecommons.org/publicdomain/zero/1.0/
Download Date: February 4, 2023
Description of modifications made to the original:
- No changes
- 1.204 seconds
File: sa2_xpleveldown.wav
Source: https://freesound.org/people/Casonika/sounds/546734/download/
Original: 546734__casonika__violin-pluck-starting-c2-fast-descending-effect.wav
By: https://freesound.org/people/Casonika/
License: https://creativecommons.org/licenses/by/4.0/
Download Date: February 4, 2023
Description of modifications made to the original:
- 00h00m02.182s to 00h00m03.008s as selection.
- Saved selection to file named sa2_xpleveldown.wav
- .826 seconds

3244
sound/wav/sa2_xpleveldown.uu Normal file

File diff suppressed because it is too large Load Diff

10276
sound/wav/sa2_xplevelup.uu Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -63,6 +63,8 @@ set UU=..\..\util\uudecode.exe
%UU% sound_Wooden_Harp_E.uu
%UU% sound_Wooden_Harp_F.uu
%UU% sound_Wooden_Harp_G.uu
%UU% sa2_xpleveldown.uu
%UU% sa2_xplevelup.uu
set UU=

View File

@@ -60,4 +60,6 @@ uudecode sound_Wooden_Harp_D.uu
uudecode sound_Wooden_Harp_E.uu
uudecode sound_Wooden_Harp_F.uu
uudecode sound_Wooden_Harp_G.uu
uudecode sa2_xpleveldown.uu
uudecode sa2_xplevelup.uu

View File

@@ -33,7 +33,8 @@ static void maybe_preinsert_directory(int32_t, char *, char *, size_t);
struct sound_procs windsound_procs = {
SOUNDID(windsound),
SOUND_TRIGGER_USERSOUNDS | SOUND_TRIGGER_SOUNDEFFECTS
| SOUND_TRIGGER_HEROMUSIC | SOUND_TRIGGER_AMBIENCE,
| SOUND_TRIGGER_HEROMUSIC | SOUND_TRIGGER_AMBIENCE
| SOUND_TRIGGER_ACHIEVEMENTS,
windsound_init_nhsound,
windsound_exit_nhsound,
windsound_achievement,
@@ -57,6 +58,54 @@ windsound_exit_nhsound(const char *reason)
static void
windsound_achievement(schar ach1, schar ach2, int32_t repeat)
{
int reslt = 0;
const char *filename;
char resourcename[120], buf[PATHLEN];
int findsound_approach = sff_base_only;
DWORD fdwsound = SND_NODEFAULT;
char *exedir = (char *) 0;
adjust_soundargs_for_compiler(&findsound_approach, &fdwsound, &exedir);
maybe_preinsert_directory(findsound_approach, exedir, buf, sizeof buf);
fdwsound |= SND_ASYNC;
if (ach1 == 0 && ach2 == 0)
return;
resourcename[0] = '\0';
if (ach1 == 0) {
int sa2 = (int) ach2;
if (sa2 > sa2_zero_invalid && sa2 < number_of_sa2_entries) {
switch(sa2) {
case sa2_splashscreen:
Strcpy(resourcename, "sa2_splashscreen");
break;
case sa2_newgame_nosplash:
Strcpy(resourcename, "sa2_newgame_nosplash");
break;
case sa2_restoregame:
Strcpy(resourcename, "sa2_restoregame");
break;
case sa2_xplevelup:
Strcpy(resourcename, "sa2_xplevelup");
break;
case sa2_xpleveldown:
Strcpy(resourcename, "sa2_xpleveldown");
break;
}
}
}
if (resourcename[0] == '\0')
return;
adjust_soundargs_for_compiler(&findsound_approach, &fdwsound, &exedir);
/* the final, or only, one is played ASYNC */
maybe_preinsert_directory(findsound_approach, exedir, buf, sizeof buf);
filename = base_soundname_to_filename(resourcename,
buf, sizeof buf, findsound_approach);
if (filename) {
reslt = PlaySound(filename, NULL, fdwsound);
}
}
static void
@@ -239,7 +288,7 @@ adjust_soundargs_for_compiler(
static void
maybe_preinsert_directory(int32_t findsound_approach, char *exedir, char *buf, size_t sz)
{
int largest_se_basename = 35;
int largest_basename = 35;
/* findsound_approach = sff_havdir_append_rest means a directory name will be
* inserted into the begining of buf and the remaining parts of the
@@ -250,7 +299,7 @@ maybe_preinsert_directory(int32_t findsound_approach, char *exedir, char *buf, s
if (findsound_approach == sff_havedir_append_rest) {
if (exedir) {
if (strlen(exedir) < (sz - largest_se_basename))
if (strlen(exedir) < (sz - largest_basename))
Strcpy(buf, exedir);
else
*buf = '\0';

View File

@@ -626,8 +626,12 @@ init_sound_and_display_gamewindows(void)
activate_chosen_soundlib();
SoundAchievement(0, sa2_splashscreen, 0);
/* ToDo: new splash screen invocation will go here */
if (iflags.wc_splash_screen && !flags.randomall) {
SoundAchievement(0, sa2_splashscreen, 0);
/* ToDo: new splash screen invocation will go here */
} else {
SoundAchievement(0, sa2_newgame_nosplash, 0);
}
WIN_MESSAGE = create_nhwindow(NHW_MESSAGE);
if (VIA_WINDOWPORT()) {

View File

@@ -227,6 +227,7 @@ losexp(
/* remove intrinsic abilities */
adjabil(u.ulevel + 1, u.ulevel);
livelog_printf(LL_MINORAC, "lost experience level %d", u.ulevel + 1);
SoundAchievement(0, sa2_xpleveldown, 0);
} else {
if (drainer) {
gk.killer.format = KILLED_BY;
@@ -344,7 +345,7 @@ pluslvl(
if (u.ulevelmax < u.ulevel)
u.ulevelmax = u.ulevel;
adjabil(u.ulevel - 1, u.ulevel); /* give new intrinsics */
SoundAchievement(0, sa2_xplevelup, 0);
old_ach_cnt = count_achievements();
newrank = xlev_to_rank(u.ulevel);
if (newrank > oldrank)

View File

@@ -21,7 +21,8 @@ SNDWAVS = se_squeak_A se_squeak_B se_squeak_B_flat se_squeak_C se_squeak_D \
sound_Wooden_Harp_C sound_Wooden_Harp_D sound_Wooden_Harp_E \
sound_Wooden_Harp_F sound_Wooden_Harp_G sound_Magic_Flute_A \
sound_Magic_Flute_B sound_Magic_Flute_C sound_Magic_Flute_D \
sound_Magic_Flute_E sound_Magic_Flute_F sound_Magic_Flute_G
sound_Magic_Flute_E sound_Magic_Flute_F sound_Magic_Flute_G \
sa2_xpleveldown sa2_xplevelup
WAVS = $(addprefix $(WAVDIR)/, $(addsuffix .wav, $(SNDWAVS)))
endif # NEEDS_WAV

View File

@@ -865,7 +865,8 @@ WAVLIST = se_squeak_A se_squeak_B se_squeak_B_flat se_squeak_C \
sound_Wooden_Harp_A sound_Wooden_Harp_B \
sound_Wooden_Harp_C sound_Wooden_Harp_D \
sound_Wooden_Harp_E sound_Wooden_Harp_F \
sound_Wooden_Harp_G
sound_Wooden_Harp_G sa2_xplevelup sa2_xpleveldown
WAVS = $(addprefix $(SNDWAVDIR)/, $(addsuffix .wav, $(WAVLIST)))
ifeq "$(HAVE_SOUNDLIB)" "Y"

View File

@@ -788,7 +788,8 @@ WAVS = $(SndWavDir)\se_squeak_A.wav $(SndWavDir)\se_squeak_B.wav \
$(SndWavDir)\sound_Wooden_Harp_A.wav $(SndWavDir)\sound_Wooden_Harp_B.wav \
$(SndWavDir)\sound_Wooden_Harp_C.wav $(SndWavDir)\sound_Wooden_Harp_D.wav \
$(SndWavDir)\sound_Wooden_Harp_E.wav $(SndWavDir)\sound_Wooden_Harp_F.wav \
$(SndWavDir)\sound_Wooden_Harp_G.wav
$(SndWavDir)\sound_Wooden_Harp_G.wav $(SndWavDir)\sa2_xpleveldown.wav \
$(SndWavDir)\sa2_xplevelup.wav
!IF "$(HAVE_SOUNDLIB)" == "Y"
!IF "$(NEED_USERSOUNDS)" == "Y"
@@ -2145,6 +2146,8 @@ $(SndWavDir)\sound_Wooden_Harp_D.wav: $(SndWavDir)\sound_Wooden_Harp_D.uu $(U)uu
$(SndWavDir)\sound_Wooden_Harp_E.wav: $(SndWavDir)\sound_Wooden_Harp_E.uu $(U)uudecode.exe
$(SndWavDir)\sound_Wooden_Harp_F.wav: $(SndWavDir)\sound_Wooden_Harp_F.uu $(U)uudecode.exe
$(SndWavDir)\sound_Wooden_Harp_G.wav: $(SndWavDir)\sound_Wooden_Harp_G.uu $(U)uudecode.exe
$(SndWavDir)\sa2_xpleveldown.wav: $(SndWavDir)\sa2_xpleveldown.uu $(U)uudecode.exe
$(SndWavDir)\sa2_xplevelup.wav: $(SndWavDir)\sa2_xplevelup.uu $(U)uudecode.exe
#===============================================================================
# Housekeeping

View File

@@ -105,6 +105,8 @@ sound_Wooden_Harp_D WAVE "sound_Wooden_Harp_D.wav"
sound_Wooden_Harp_E WAVE "sound_Wooden_Harp_E.wav"
sound_Wooden_Harp_F WAVE "sound_Wooden_Harp_F.wav"
sound_Wooden_Harp_G WAVE "sound_Wooden_Harp_G.wav"
sa2_xpleveldown WAVE "sa2_xpleveldown.wav"
sa2_xplevelup WAVE "sa2_xplevelup.wav"
#endif
/*console.rc*/"

View File

@@ -212,6 +212,8 @@
<UUFiles Include = "$(SndWavDir)sound_Wooden_Harp_E.uu"/>
<UUFiles Include = "$(SndWavDir)sound_Wooden_Harp_F.uu"/>
<UUFiles Include = "$(SndWavDir)sound_Wooden_Harp_G.uu"/>
<UUFiles Include = "$(SndWavDir)sa2_xpleveldown.uu"/>
<UUFiles Include = "$(SndWavDir)sa2_xplevelup.uu"/>
</ItemGroup>
<ItemGroup>
<IconFiles Include = "$(WinWin32Dir)nethack.ico"/>

View File

@@ -72,6 +72,8 @@
<Exec Command="&quot;$(ToolsDir)uudecode.exe&quot; &quot;$(SndWavDir)sound_Wooden_Harp_E.uu&quot;" WorkingDirectory="$(SndWavDir)"/>
<Exec Command="&quot;$(ToolsDir)uudecode.exe&quot; &quot;$(SndWavDir)sound_Wooden_Harp_F.uu&quot;" WorkingDirectory="$(SndWavDir)"/>
<Exec Command="&quot;$(ToolsDir)uudecode.exe&quot; &quot;$(SndWavDir)sound_Wooden_Harp_G.uu&quot;" WorkingDirectory="$(SndWavDir)"/>
<Exec Command="&quot;$(ToolsDir)uudecode.exe&quot; &quot;$(SndWavDir)sa2_xpleveldown.uu&quot;" WorkingDirectory="$(SndWavDir)"/>
<Exec Command="&quot;$(ToolsDir)uudecode.exe&quot; &quot;$(SndWavDir)sa2_xplevelup.uu&quot;" WorkingDirectory="$(SndWavDir)"/>
</Target>
<Target Name="Clean">
<Delete Files="@(IconFiles);@(BmpFiles);@(RecordFiles)"/>

View File

@@ -452,6 +452,8 @@ sound_Wooden_Harp_D WAVE "sound_Wooden_Harp_D.wav"
sound_Wooden_Harp_E WAVE "sound_Wooden_Harp_E.wav"
sound_Wooden_Harp_F WAVE "sound_Wooden_Harp_F.wav"
sound_Wooden_Harp_G WAVE "sound_Wooden_Harp_G.wav"
sa2_xpleveldown WAVE "sa2_xpleveldown.wav"
sa2_xplevelup WAVE "sa2_xplevelup.wav"
#endif
#endif // English (United States) resources
/////////////////////////////////////////////////////////////////////////////