• R/O
  • SSH
  • HTTPS

xangband: Commit


Commit MetaInfo

Revision1899 (tree)
Zeit2013-03-19 04:11:01
Autoriks

Log Message

Add BGM functions. Apply it to main-win.c

Ändern Zusammenfassung

Diff

--- TinyAngband/trunk/lib/xtra/music/Makefile.am (revision 1898)
+++ TinyAngband/trunk/lib/xtra/music/Makefile.am (revision 1899)
@@ -1,4 +1,4 @@
11 ## Makefile.am -- Process this file with automake to process Makefile.in
22
33 EXTRA_DIST = \
4- delete.me
4+ music.cfg
--- TinyAngband/trunk/src/util.c (revision 1898)
+++ TinyAngband/trunk/src/util.c (revision 1899)
@@ -1664,7 +1664,40 @@
16641664 }
16651665
16661666
1667+/*
1668+ * Hack -- Make a bgm
1669+ */
1670+void bgm(int val)
1671+{
1672+ /* No sound */
1673+ if (!use_sound) return;
16671674
1675+ /* Make a bgm (if allowed) */
1676+ Term_xtra(TERM_XTRA_MUSIC, val);
1677+}
1678+
1679+void bgm_dungeon(void)
1680+{
1681+ if ((dun_level == quest[QUEST_MORGOTH].level) &&
1682+ (quest[QUEST_MORGOTH].status == QUEST_STATUS_TAKEN))
1683+ {
1684+ bgm(BGM_MORGOTH);
1685+ }
1686+ else if ((dun_level == quest[QUEST_SAURON].level) &&
1687+ (quest[QUEST_SAURON].status == QUEST_STATUS_TAKEN))
1688+ {
1689+ bgm(BGM_SAURON);
1690+ }
1691+ else if (p_ptr->inside_quest)
1692+ {
1693+ bgm(BGM_QUEST);
1694+ }
1695+ else if (dun_level >= 20) bgm(BGM_ABYSS);
1696+ else if (dun_level > 0) bgm(BGM_DUNGEON);
1697+ else if (dun_level == 0) bgm(BGM_TOWN);
1698+}
1699+
1700+
16681701 /*
16691702 * Helper function called only from "inkey()"
16701703 *
--- TinyAngband/trunk/src/dungeon.c (revision 1898)
+++ TinyAngband/trunk/src/dungeon.c (revision 1899)
@@ -4142,6 +4142,9 @@
41424142 /* Prevent insta-death */
41434143 if (p_ptr->energy_need > 0 && dun_level) p_ptr->energy_need = 0;
41444144
4145+ /* BGM */
4146+ bgm_dungeon();
4147+
41454148 /* Main loop */
41464149 while (TRUE)
41474150 {
--- TinyAngband/trunk/src/xtra2.c (revision 1898)
+++ TinyAngband/trunk/src/xtra2.c (revision 1899)
@@ -506,6 +506,7 @@
506506 #else
507507 msg_print("You just completed your quest!");
508508 #endif
509+ bgm_dungeon();
509510 sound(SOUND_LEVEL); /* (Sound substitute) No quest sound */
510511 msg_print(NULL);
511512 }
@@ -967,6 +968,9 @@
967968 /* Redraw the "title" */
968969 p_ptr->redraw |= (PR_TITLE);
969970
971+ /* BGM */
972+ bgm(BGM_WINNER);
973+
970974 /* Congratulations */
971975 #ifdef JP
972976 msg_print("*** おめでとう ***");
@@ -985,7 +989,6 @@
985989 #else
986990 msg_print("You may retire (commit suicide) when you are ready.");
987991 #endif
988-
989992 }
990993 }
991994
--- TinyAngband/trunk/src/files.c (revision 1898)
+++ TinyAngband/trunk/src/files.c (revision 1899)
@@ -5736,6 +5736,9 @@
57365736 center_string(buf, tmp);
57375737 put_str(buf, 17, 11);
57385738
5739+ /* BGM */
5740+ bgm(BGM_DEAD);
5741+
57395742 #ifdef JP
57405743 msg_format("さようなら、%s!", player_name);
57415744 #else
--- TinyAngband/trunk/src/z-term.h (revision 1898)
+++ TinyAngband/trunk/src/z-term.h (revision 1899)
@@ -261,6 +261,7 @@
261261 #define TERM_XTRA_ALIVE 11 /* Change the "hard" level (optional) */
262262 #define TERM_XTRA_LEVEL 12 /* Change the "soft" level (optional) */
263263 #define TERM_XTRA_DELAY 13 /* Delay some milliseconds (optional) */
264+#define TERM_XTRA_MUSIC 14 /* Make a music (optional) */
264265
265266
266267 /**** Available Variables ****/
--- TinyAngband/trunk/src/variable.c (revision 1898)
+++ TinyAngband/trunk/src/variable.c (revision 1899)
@@ -730,7 +730,26 @@
730730 };
731731
732732
733+/*
734+ * Standard Bgm Names
735+ */
736+const cptr angband_bgm_name[BGM_MAX] =
737+{
738+ "",
739+ "town",
740+ "store",
741+ "building",
742+ "dungeon",
743+ "abyss",
744+ "quest",
745+ "sauron",
746+ "morgoth",
747+ "winner",
748+ "dead",
749+ "title"
750+};
733751
752+
734753 /*
735754 * The array of "cave grids" [MAX_WID][MAX_HGT].
736755 * Not completely allocated, that would be inefficient
--- TinyAngband/trunk/src/store.c (revision 1898)
+++ TinyAngband/trunk/src/store.c (revision 1899)
@@ -3064,6 +3064,9 @@
30643064 /* Do not leave */
30653065 leave_store = FALSE;
30663066
3067+ /* BGM */
3068+ bgm(BGM_STORE);
3069+
30673070 /* Interact with player */
30683071 while (!leave_store)
30693072 {
@@ -3254,6 +3257,9 @@
32543257
32553258 /* Window stuff */
32563259 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
3260+
3261+ /* BGM */
3262+ bgm_dungeon();
32573263 }
32583264
32593265
--- TinyAngband/trunk/src/defines.h (revision 1898)
+++ TinyAngband/trunk/src/defines.h (revision 1899)
@@ -3312,7 +3312,35 @@
33123312 */
33133313 #define SOUND_MAX 150
33143314
3315+
3316+/*** Bgm constants ***/
33153317 /*
3318+ * Mega-Hack -- some primitive sound support (see "main-win.c")
3319+ *
3320+ * Some "sound" constants for "Term_xtra(TERM_XTRA_SOUND, val)"
3321+ */
3322+#define BGM_MUTE 0
3323+#define BGM_TOWN 1
3324+#define BGM_STORE 2
3325+#define BGM_BUILDING 3
3326+#define BGM_DUNGEON 4
3327+#define BGM_ABYSS 5
3328+#define BGM_QUEST 6
3329+#define BGM_SAURON 7
3330+#define BGM_MORGOTH 8
3331+#define BGM_WINNER 9
3332+#define BGM_DEAD 10
3333+#define BGM_TITLE 11
3334+
3335+/*
3336+ * Mega-Hack -- maximum known sounds
3337+ */
3338+#define BGM_MAX 12
3339+
3340+
3341+
3342+
3343+/*
33163344 * Hack -- attempt to reduce various values
33173345 */
33183346 #ifdef ANGBAND_LITE
--- TinyAngband/trunk/src/bldg.c (revision 1898)
+++ TinyAngband/trunk/src/bldg.c (revision 1899)
@@ -3187,6 +3187,9 @@
31873187 show_building(bldg);
31883188 leave_bldg = FALSE;
31893189
3190+ /* BGM */
3191+ bgm(BGM_BUILDING);
3192+
31903193 while (!leave_bldg)
31913194 {
31923195 validcmd = FALSE;
@@ -3246,4 +3249,7 @@
32463249
32473250 /* Window stuff */
32483251 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
3252+
3253+ /* BGM */
3254+ bgm_dungeon();
32493255 }
--- TinyAngband/trunk/src/main-win.c (revision 1898)
+++ TinyAngband/trunk/src/main-win.c (revision 1899)
@@ -74,6 +74,9 @@
7474
7575 #include "angband.h"
7676 #include <windows.h>
77+#ifdef USE_SOUND
78+#include <MMSystem.h>
79+#endif
7780
7881
7982 #ifdef WINDOWS
@@ -556,6 +559,8 @@
556559 * An array of sound file names
557560 */
558561 static cptr sound_file[SOUND_MAX][SAMPLE_MAX];
562+static cptr bgm_file[BGM_MAX][SAMPLE_MAX];
563+static char mci_device_name[256];
559564
560565 #endif /* USE_SOUND */
561566
@@ -580,13 +585,11 @@
580585 */
581586 static cptr ANGBAND_DIR_XTRA_GRAF;
582587 static cptr ANGBAND_DIR_XTRA_SOUND;
588+static cptr ANGBAND_DIR_XTRA_MUSIC;
583589 static cptr ANGBAND_DIR_XTRA_HELP;
584590 #ifndef JP
585591 static cptr ANGBAND_DIR_XTRA_FONT;
586592 #endif
587-#ifdef USE_MUSIC
588-static cptr ANGBAND_DIR_XTRA_MUSIC;
589-#endif /* 0 */
590593
591594 /*
592595 * The "complex" color values
@@ -1399,7 +1402,7 @@
13991402 /* Access the sound.cfg */
14001403 path_build(ini_path, sizeof(ini_path), ANGBAND_DIR_XTRA_SOUND, "sound.cfg");
14011404
1402- for (i = 0; i < SOUND_MAX; i++)
1405+ for (i = 1; i < SOUND_MAX; i++)
14031406 {
14041407 GetPrivateProfileString("Sound", angband_sound_name[i], "", tmp, 1024, ini_path);
14051408
@@ -1417,6 +1420,84 @@
14171420 }
14181421 }
14191422
1423+#ifdef USE_MUSIC
1424+static int current_bgm = BGM_MUTE;
1425+
1426+static errr OpenBgm(cptr filename)
1427+{
1428+ errr err = -1;
1429+ cptr mci_command;
1430+
1431+ if (mci_device_name[0] != '\0')
1432+ {
1433+ mci_command = format("open \"%s\" type %s alias AngbandBGM", filename, mci_device_name);
1434+ err = mciSendString(mci_command, NULL, 0, NULL);
1435+ }
1436+
1437+ if (err != 0)
1438+ {
1439+ mci_command = format("open \"%s\" alias AngbandBGM", filename);
1440+ err = mciSendString(mci_command, NULL, 0, NULL);
1441+ }
1442+
1443+ return err;
1444+}
1445+
1446+static void StopBgm()
1447+{
1448+ if (current_bgm != BGM_MUTE)
1449+ {
1450+ mciSendString("stop AngbandBGM", NULL, 0, NULL);
1451+ current_bgm = BGM_MUTE;
1452+ }
1453+}
1454+
1455+static void CloseBgm()
1456+{
1457+ StopBgm();
1458+ mciSendString("close AngbandBGM", NULL, 0, NULL);
1459+}
1460+
1461+static errr PlayBgm(bool again)
1462+{
1463+ errr err = 0;
1464+ if (again) err = mciSendString("seek AngbandBGM to start", NULL, 0, NULL);
1465+ if (err == 0) err = mciSendString("play AngbandBGM notify", NULL, 0, data[0].w);
1466+
1467+ return err;
1468+}
1469+
1470+static void load_bgm_prefs(void)
1471+{
1472+ int i, j, num;
1473+ char tmp[1024];
1474+ char ini_path[1024];
1475+ char bgm_path[1024];
1476+ char *zz[SAMPLE_MAX];
1477+
1478+ /* Access the sound.cfg */
1479+ path_build(ini_path, sizeof(ini_path), ANGBAND_DIR_XTRA_MUSIC, "music.cfg");
1480+
1481+ for (i = 1; i < BGM_MAX; i++)
1482+ {
1483+ GetPrivateProfileString("Music", angband_bgm_name[i], "", tmp, 1024, ini_path);
1484+
1485+ num = tokenize_whitespace(tmp, SAMPLE_MAX, zz);
1486+
1487+ for (j = 0; j < num; j++)
1488+ {
1489+ /* Access the sound */
1490+ path_build(bgm_path, sizeof(bgm_path), ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1491+
1492+ /* Save the sound filename, if it exists */
1493+ if (check_file(bgm_path))
1494+ bgm_file[i][j] = string_make(zz[j]);
1495+ }
1496+ }
1497+
1498+ GetPrivateProfileString("Device", mci_device_name, "", tmp, 256, ini_path);
1499+}
1500+#endif /* USE_MUSIC */
14201501 #endif /* USE_SOUND */
14211502
14221503
@@ -1719,6 +1800,7 @@
17191800 {
17201801 /* Load the prefs */
17211802 load_sound_prefs();
1803+ load_bgm_prefs();
17221804
17231805 /* Sound available */
17241806 can_use_sound = TRUE;
@@ -1727,6 +1809,7 @@
17271809 /* Result */
17281810 return (can_use_sound);
17291811 }
1812+
17301813 #endif /* USE_SOUND */
17311814
17321815
@@ -2118,19 +2201,26 @@
21182201 if (use_sound != arg_sound)
21192202 {
21202203 /* Initialize (if needed) */
2121- if (arg_sound && !init_sound())
2204+ if (arg_sound)
21222205 {
2123- /* Warning */
2124-#ifdef JP
2125- plog("サウンドを初期化できません!");
2126-#else
2127- plog("Cannot initialize sound!");
2128-#endif
2206+ if (!init_sound())
2207+ {
2208+ /* Warning */
2209+ plog(_("サウンドを初期化できません!", "Cannot initialize sound!"));
21292210
2130-
2131- /* Cannot enable */
2132- arg_sound = FALSE;
2211+ /* Cannot enable */
2212+ arg_sound = FALSE;
2213+ }
21332214 }
2215+ else
2216+ {
2217+#ifdef USE_MUSIC
2218+ if (current_bgm != BGM_MUTE)
2219+ {
2220+ CloseBgm();
2221+ }
2222+#endif
2223+ }
21342224
21352225 /* Change setting */
21362226 use_sound = arg_sound;
@@ -2354,6 +2444,51 @@
23542444
23552445
23562446 /*
2447+ * Hack -- make a music
2448+ */
2449+static errr Term_xtra_win_music(int v)
2450+{
2451+ int i;
2452+ errr err;
2453+ char buf[1024];
2454+
2455+ /* Sound disabled */
2456+ if (!use_sound) return (1);
2457+
2458+ /* Illegal sound */
2459+ if ((v < 0) || (v >= BGM_MAX)) return (1);
2460+
2461+#ifdef USE_MUSIC
2462+ if (v == current_bgm) return (0);
2463+
2464+ CloseBgm();
2465+ if (v == BGM_MUTE) return (0);
2466+
2467+ /* Count the samples */
2468+ for (i = 0; i < SAMPLE_MAX; i++)
2469+ {
2470+ if (!bgm_file[v][i])
2471+ break;
2472+ }
2473+
2474+ /* No sample */
2475+ if (i == 0) return (1);
2476+
2477+ /* Build the path */
2478+ path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_MUSIC, bgm_file[v][randint0(i)]);
2479+ if (OpenBgm(buf) != 0) return (0);
2480+ if ((err = PlayBgm(FALSE)) == 0) current_bgm = v;
2481+ return (err);
2482+#else /* USE_MUSIC */
2483+
2484+ /* Oops */
2485+ return (1);
2486+
2487+#endif /* USE_MUSIC */
2488+}
2489+
2490+
2491+/*
23572492 * Delay for "x" milliseconds
23582493 */
23592494 static int Term_xtra_win_delay(int v)
@@ -2445,6 +2580,12 @@
24452580 {
24462581 return (Term_xtra_win_delay(v));
24472582 }
2583+
2584+ /* Make a special sound */
2585+ case TERM_XTRA_MUSIC:
2586+ {
2587+ return (Term_xtra_win_music(v));
2588+ }
24482589 }
24492590
24502591 /* Oops */
@@ -5169,6 +5310,15 @@
51695310
51705311 break;
51715312 }
5313+#ifdef USE_MUSIC
5314+ case MM_MCINOTIFY:
5315+ {
5316+ if (wParam == MCI_NOTIFY_SUCCESSFUL)
5317+ {
5318+ PlayBgm(TRUE);
5319+ }
5320+ }
5321+#endif
51725322 }
51735323
51745324 return DefWindowProc(hWnd, uMsg, wParam, lParam);
@@ -5618,6 +5768,10 @@
56185768 /* bg */
56195769 delete_bg();
56205770
5771+#ifdef USE_MUSIC
5772+ if (use_sound) CloseBgm();
5773+#endif
5774+
56215775 if (hPal) DeleteObject(hPal);
56225776
56235777 UnregisterClass(AppName, hInstance);
@@ -6022,6 +6176,13 @@
60226176 /* Did the user double click on a save file? */
60236177 if(!chuukei_server) check_for_save_file(lpCmdLine);
60246178
6179+#ifdef USE_MUSIC
6180+ /* Title Bgm */
6181+ use_sound = arg_sound;
6182+ load_bgm_prefs();
6183+ Term_xtra_win_music(BGM_TITLE);
6184+#endif
6185+
60256186 /* Prompt the user */
60266187 #ifdef JP
60276188 prt("[ファイル] メニューの [新規] または [開く] を選択してください。", 23, 8);
--- TinyAngband/trunk/src/z-config.h (revision 1898)
+++ TinyAngband/trunk/src/z-config.h (revision 1899)
@@ -392,7 +392,9 @@
392392 /*
393393 * OPTION: Allow the use of "music" in various places
394394 */
395-/* #define USE_MUSIC */
395+#ifdef USE_SOUND
396+#define USE_MUSIC
397+#endif
396398
397399 #endif /* USE_SPECIAL */
398400
--- TinyAngband/trunk/src/externs.h (revision 1898)
+++ TinyAngband/trunk/src/externs.h (revision 1899)
@@ -353,6 +353,7 @@
353353 extern char angband_term_name[8][16];
354354 extern byte angband_color_table[256][4];
355355 extern char angband_sound_name[SOUND_MAX][19];
356+extern const cptr angband_bgm_name[];
356357 extern cave_type *cave[MAX_HGT];
357358 extern object_type *o_list;
358359 extern monster_type *m_list;
@@ -1073,6 +1074,8 @@
10731074 extern void flush(void);
10741075 extern void bell(void);
10751076 extern void sound(int num);
1077+extern void bgm(int num);
1078+extern void bgm_dungeon(void);
10761079 extern void move_cursor(int row, int col);
10771080 extern void text_to_ascii(char *buf, cptr str);
10781081 extern void ascii_to_text(char *buf, cptr str);
Show on old repository browser