Add BGM functions. Apply it to main-win.c
@@ -1,4 +1,4 @@ | ||
1 | 1 | ## Makefile.am -- Process this file with automake to process Makefile.in |
2 | 2 | |
3 | 3 | EXTRA_DIST = \ |
4 | - delete.me | |
4 | + music.cfg |
@@ -1664,7 +1664,40 @@ | ||
1664 | 1664 | } |
1665 | 1665 | |
1666 | 1666 | |
1667 | +/* | |
1668 | + * Hack -- Make a bgm | |
1669 | + */ | |
1670 | +void bgm(int val) | |
1671 | +{ | |
1672 | + /* No sound */ | |
1673 | + if (!use_sound) return; | |
1667 | 1674 | |
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 | + | |
1668 | 1701 | /* |
1669 | 1702 | * Helper function called only from "inkey()" |
1670 | 1703 | * |
@@ -4142,6 +4142,9 @@ | ||
4142 | 4142 | /* Prevent insta-death */ |
4143 | 4143 | if (p_ptr->energy_need > 0 && dun_level) p_ptr->energy_need = 0; |
4144 | 4144 | |
4145 | + /* BGM */ | |
4146 | + bgm_dungeon(); | |
4147 | + | |
4145 | 4148 | /* Main loop */ |
4146 | 4149 | while (TRUE) |
4147 | 4150 | { |
@@ -506,6 +506,7 @@ | ||
506 | 506 | #else |
507 | 507 | msg_print("You just completed your quest!"); |
508 | 508 | #endif |
509 | + bgm_dungeon(); | |
509 | 510 | sound(SOUND_LEVEL); /* (Sound substitute) No quest sound */ |
510 | 511 | msg_print(NULL); |
511 | 512 | } |
@@ -967,6 +968,9 @@ | ||
967 | 968 | /* Redraw the "title" */ |
968 | 969 | p_ptr->redraw |= (PR_TITLE); |
969 | 970 | |
971 | + /* BGM */ | |
972 | + bgm(BGM_WINNER); | |
973 | + | |
970 | 974 | /* Congratulations */ |
971 | 975 | #ifdef JP |
972 | 976 | msg_print("*** おめでとう ***"); |
@@ -985,7 +989,6 @@ | ||
985 | 989 | #else |
986 | 990 | msg_print("You may retire (commit suicide) when you are ready."); |
987 | 991 | #endif |
988 | - | |
989 | 992 | } |
990 | 993 | } |
991 | 994 |
@@ -5736,6 +5736,9 @@ | ||
5736 | 5736 | center_string(buf, tmp); |
5737 | 5737 | put_str(buf, 17, 11); |
5738 | 5738 | |
5739 | + /* BGM */ | |
5740 | + bgm(BGM_DEAD); | |
5741 | + | |
5739 | 5742 | #ifdef JP |
5740 | 5743 | msg_format("さようなら、%s!", player_name); |
5741 | 5744 | #else |
@@ -261,6 +261,7 @@ | ||
261 | 261 | #define TERM_XTRA_ALIVE 11 /* Change the "hard" level (optional) */ |
262 | 262 | #define TERM_XTRA_LEVEL 12 /* Change the "soft" level (optional) */ |
263 | 263 | #define TERM_XTRA_DELAY 13 /* Delay some milliseconds (optional) */ |
264 | +#define TERM_XTRA_MUSIC 14 /* Make a music (optional) */ | |
264 | 265 | |
265 | 266 | |
266 | 267 | /**** Available Variables ****/ |
@@ -730,7 +730,26 @@ | ||
730 | 730 | }; |
731 | 731 | |
732 | 732 | |
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 | +}; | |
733 | 751 | |
752 | + | |
734 | 753 | /* |
735 | 754 | * The array of "cave grids" [MAX_WID][MAX_HGT]. |
736 | 755 | * Not completely allocated, that would be inefficient |
@@ -3064,6 +3064,9 @@ | ||
3064 | 3064 | /* Do not leave */ |
3065 | 3065 | leave_store = FALSE; |
3066 | 3066 | |
3067 | + /* BGM */ | |
3068 | + bgm(BGM_STORE); | |
3069 | + | |
3067 | 3070 | /* Interact with player */ |
3068 | 3071 | while (!leave_store) |
3069 | 3072 | { |
@@ -3254,6 +3257,9 @@ | ||
3254 | 3257 | |
3255 | 3258 | /* Window stuff */ |
3256 | 3259 | p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON); |
3260 | + | |
3261 | + /* BGM */ | |
3262 | + bgm_dungeon(); | |
3257 | 3263 | } |
3258 | 3264 | |
3259 | 3265 |
@@ -3312,7 +3312,35 @@ | ||
3312 | 3312 | */ |
3313 | 3313 | #define SOUND_MAX 150 |
3314 | 3314 | |
3315 | + | |
3316 | +/*** Bgm constants ***/ | |
3315 | 3317 | /* |
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 | +/* | |
3316 | 3344 | * Hack -- attempt to reduce various values |
3317 | 3345 | */ |
3318 | 3346 | #ifdef ANGBAND_LITE |
@@ -3187,6 +3187,9 @@ | ||
3187 | 3187 | show_building(bldg); |
3188 | 3188 | leave_bldg = FALSE; |
3189 | 3189 | |
3190 | + /* BGM */ | |
3191 | + bgm(BGM_BUILDING); | |
3192 | + | |
3190 | 3193 | while (!leave_bldg) |
3191 | 3194 | { |
3192 | 3195 | validcmd = FALSE; |
@@ -3246,4 +3249,7 @@ | ||
3246 | 3249 | |
3247 | 3250 | /* Window stuff */ |
3248 | 3251 | p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON); |
3252 | + | |
3253 | + /* BGM */ | |
3254 | + bgm_dungeon(); | |
3249 | 3255 | } |
@@ -74,6 +74,9 @@ | ||
74 | 74 | |
75 | 75 | #include "angband.h" |
76 | 76 | #include <windows.h> |
77 | +#ifdef USE_SOUND | |
78 | +#include <MMSystem.h> | |
79 | +#endif | |
77 | 80 | |
78 | 81 | |
79 | 82 | #ifdef WINDOWS |
@@ -556,6 +559,8 @@ | ||
556 | 559 | * An array of sound file names |
557 | 560 | */ |
558 | 561 | static cptr sound_file[SOUND_MAX][SAMPLE_MAX]; |
562 | +static cptr bgm_file[BGM_MAX][SAMPLE_MAX]; | |
563 | +static char mci_device_name[256]; | |
559 | 564 | |
560 | 565 | #endif /* USE_SOUND */ |
561 | 566 |
@@ -580,13 +585,11 @@ | ||
580 | 585 | */ |
581 | 586 | static cptr ANGBAND_DIR_XTRA_GRAF; |
582 | 587 | static cptr ANGBAND_DIR_XTRA_SOUND; |
588 | +static cptr ANGBAND_DIR_XTRA_MUSIC; | |
583 | 589 | static cptr ANGBAND_DIR_XTRA_HELP; |
584 | 590 | #ifndef JP |
585 | 591 | static cptr ANGBAND_DIR_XTRA_FONT; |
586 | 592 | #endif |
587 | -#ifdef USE_MUSIC | |
588 | -static cptr ANGBAND_DIR_XTRA_MUSIC; | |
589 | -#endif /* 0 */ | |
590 | 593 | |
591 | 594 | /* |
592 | 595 | * The "complex" color values |
@@ -1399,7 +1402,7 @@ | ||
1399 | 1402 | /* Access the sound.cfg */ |
1400 | 1403 | path_build(ini_path, sizeof(ini_path), ANGBAND_DIR_XTRA_SOUND, "sound.cfg"); |
1401 | 1404 | |
1402 | - for (i = 0; i < SOUND_MAX; i++) | |
1405 | + for (i = 1; i < SOUND_MAX; i++) | |
1403 | 1406 | { |
1404 | 1407 | GetPrivateProfileString("Sound", angband_sound_name[i], "", tmp, 1024, ini_path); |
1405 | 1408 |
@@ -1417,6 +1420,84 @@ | ||
1417 | 1420 | } |
1418 | 1421 | } |
1419 | 1422 | |
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 */ | |
1420 | 1501 | #endif /* USE_SOUND */ |
1421 | 1502 | |
1422 | 1503 |
@@ -1719,6 +1800,7 @@ | ||
1719 | 1800 | { |
1720 | 1801 | /* Load the prefs */ |
1721 | 1802 | load_sound_prefs(); |
1803 | + load_bgm_prefs(); | |
1722 | 1804 | |
1723 | 1805 | /* Sound available */ |
1724 | 1806 | can_use_sound = TRUE; |
@@ -1727,6 +1809,7 @@ | ||
1727 | 1809 | /* Result */ |
1728 | 1810 | return (can_use_sound); |
1729 | 1811 | } |
1812 | + | |
1730 | 1813 | #endif /* USE_SOUND */ |
1731 | 1814 | |
1732 | 1815 |
@@ -2118,19 +2201,26 @@ | ||
2118 | 2201 | if (use_sound != arg_sound) |
2119 | 2202 | { |
2120 | 2203 | /* Initialize (if needed) */ |
2121 | - if (arg_sound && !init_sound()) | |
2204 | + if (arg_sound) | |
2122 | 2205 | { |
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!")); | |
2129 | 2210 | |
2130 | - | |
2131 | - /* Cannot enable */ | |
2132 | - arg_sound = FALSE; | |
2211 | + /* Cannot enable */ | |
2212 | + arg_sound = FALSE; | |
2213 | + } | |
2133 | 2214 | } |
2215 | + else | |
2216 | + { | |
2217 | +#ifdef USE_MUSIC | |
2218 | + if (current_bgm != BGM_MUTE) | |
2219 | + { | |
2220 | + CloseBgm(); | |
2221 | + } | |
2222 | +#endif | |
2223 | + } | |
2134 | 2224 | |
2135 | 2225 | /* Change setting */ |
2136 | 2226 | use_sound = arg_sound; |
@@ -2354,6 +2444,51 @@ | ||
2354 | 2444 | |
2355 | 2445 | |
2356 | 2446 | /* |
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 | +/* | |
2357 | 2492 | * Delay for "x" milliseconds |
2358 | 2493 | */ |
2359 | 2494 | static int Term_xtra_win_delay(int v) |
@@ -2445,6 +2580,12 @@ | ||
2445 | 2580 | { |
2446 | 2581 | return (Term_xtra_win_delay(v)); |
2447 | 2582 | } |
2583 | + | |
2584 | + /* Make a special sound */ | |
2585 | + case TERM_XTRA_MUSIC: | |
2586 | + { | |
2587 | + return (Term_xtra_win_music(v)); | |
2588 | + } | |
2448 | 2589 | } |
2449 | 2590 | |
2450 | 2591 | /* Oops */ |
@@ -5169,6 +5310,15 @@ | ||
5169 | 5310 | |
5170 | 5311 | break; |
5171 | 5312 | } |
5313 | +#ifdef USE_MUSIC | |
5314 | + case MM_MCINOTIFY: | |
5315 | + { | |
5316 | + if (wParam == MCI_NOTIFY_SUCCESSFUL) | |
5317 | + { | |
5318 | + PlayBgm(TRUE); | |
5319 | + } | |
5320 | + } | |
5321 | +#endif | |
5172 | 5322 | } |
5173 | 5323 | |
5174 | 5324 | return DefWindowProc(hWnd, uMsg, wParam, lParam); |
@@ -5618,6 +5768,10 @@ | ||
5618 | 5768 | /* bg */ |
5619 | 5769 | delete_bg(); |
5620 | 5770 | |
5771 | +#ifdef USE_MUSIC | |
5772 | + if (use_sound) CloseBgm(); | |
5773 | +#endif | |
5774 | + | |
5621 | 5775 | if (hPal) DeleteObject(hPal); |
5622 | 5776 | |
5623 | 5777 | UnregisterClass(AppName, hInstance); |
@@ -6022,6 +6176,13 @@ | ||
6022 | 6176 | /* Did the user double click on a save file? */ |
6023 | 6177 | if(!chuukei_server) check_for_save_file(lpCmdLine); |
6024 | 6178 | |
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 | + | |
6025 | 6186 | /* Prompt the user */ |
6026 | 6187 | #ifdef JP |
6027 | 6188 | prt("[ファイル] メニューの [新規] または [開く] を選択してください。", 23, 8); |
@@ -392,7 +392,9 @@ | ||
392 | 392 | /* |
393 | 393 | * OPTION: Allow the use of "music" in various places |
394 | 394 | */ |
395 | -/* #define USE_MUSIC */ | |
395 | +#ifdef USE_SOUND | |
396 | +#define USE_MUSIC | |
397 | +#endif | |
396 | 398 | |
397 | 399 | #endif /* USE_SPECIAL */ |
398 | 400 |
@@ -353,6 +353,7 @@ | ||
353 | 353 | extern char angband_term_name[8][16]; |
354 | 354 | extern byte angband_color_table[256][4]; |
355 | 355 | extern char angband_sound_name[SOUND_MAX][19]; |
356 | +extern const cptr angband_bgm_name[]; | |
356 | 357 | extern cave_type *cave[MAX_HGT]; |
357 | 358 | extern object_type *o_list; |
358 | 359 | extern monster_type *m_list; |
@@ -1073,6 +1074,8 @@ | ||
1073 | 1074 | extern void flush(void); |
1074 | 1075 | extern void bell(void); |
1075 | 1076 | extern void sound(int num); |
1077 | +extern void bgm(int num); | |
1078 | +extern void bgm_dungeon(void); | |
1076 | 1079 | extern void move_cursor(int row, int col); |
1077 | 1080 | extern void text_to_ascii(char *buf, cptr str); |
1078 | 1081 | extern void ascii_to_text(char *buf, cptr str); |