ZoriaRPG

Music.zh (v1.3.0, 3rd July, 2017)

Jul 3rd, 2017
122
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ///////////////////////////////
  2. /// Music.zh                ///
  3. /// v1.3.0 - 3rd July, 2017 ///
  4. /// By: ZoriaRPG            ///
  5. ////////////////////////////////////////////////////////////////////////////////////////////////////
  6. /// A series of FFCs, and utility functions for playing MIDIs, Enhanced Music, and Sound Effects ///
  7. ////////////////////////////////////////////////////////////////////////////////////////////////////
  8.  
  9. //import "std.zh"
  10. //import "string.zh"
  11.  
  12. const int MIDI_DEFEATBOSS = 0; //Set to default midi to play for Victory Music.
  13.                 //ZC will use this if enhanced Victory music is not available.
  14.                
  15. const int DEFAULT_BOSS_MUSIC = 0; //Sets a default boss music file to play.
  16.                
  17. ///////////////
  18. /// SCRIPTS ///
  19. ///////////////
  20.  
  21.  
  22. /////////////////////
  23. /// Sound Effects ///
  24. /////////////////////
  25.  
  26. // Ties SFX to an item, that is otherwise normally hardcoded. used for the Sonic Wand in LoE.
  27.  
  28. item script playSound{
  29.     void run(int sfx){
  30.         Game->PlaySound(sfx);
  31.     }
  32. }
  33.  
  34. /////////////////
  35. /// MIDI Only ///
  36. /////////////////
  37.  
  38. //Plays MIDI specified at D0. Place on a screen, to change the MIDI for that screen, only.
  39. //Plays at all times on that screen, and uses no conditions.
  40.  
  41. ffc script playMIDI{
  42.     void run(int midiNumber){
  43.         Game->PlayMIDI(midiNumber);
  44.     }
  45. }
  46.  
  47. /////////////////////////
  48. /// Conditional MIDIs ///
  49. /////////////////////////
  50.  
  51.  
  52.  
  53. //play a MIDI while an enemy with a specific ID is on-screen
  54.  
  55. ffc script NPC_MIDI{
  56.     void run(int npc_ID, int midi){
  57.         //int originalMIDi = //share these two
  58.         //int originalMusic[3] = //midi, enh music, track
  59.         //store the normal midi or music
  60.         //check for the npc and while it is on-screen
  61.         //change the midi
  62.        
  63.         //if it dies, change back
  64.         int q[4]; npc n; bool found;
  65.         int enh_music[256] = {0};
  66.         Game->GetDMapMusicFilename(Game->GetCurDMap(), enh_music);
  67.        
  68.         int enh_trk = Game->GetDMapMusicTrack(Game->GetCurDMap());
  69.         for ( q[0] = 0; q[0] < 256; q[0]++ ) { if ( enh_music[q] == ' ' ) enh_music[q] = 0; } //kill the space.
  70.         bool enhanced =  ( enh_music[0] != 0 ); //is the dmap music enhanced?
  71.        
  72.         int originalmusic = Game->DMapMIDI[Game->GetCurDMap()];
  73.         while(true){
  74.             for ( q[0] = Screen->NumNPCs(); q[0] > 0; q[0]-- ) {
  75.                 n = Screen->LoadNPC(q);
  76.                 if ( n->ID == npc_ID ) {
  77.                     q[1] = 1; break;
  78.                 }
  79.                 q[1] = 0;
  80.             }
  81.             if ( q[1] ) {
  82.                 if ( !q[2] ) {
  83.                     Game->DMapMIDI[Game->GetCurDMap()] = midi;
  84.                     q[2] = 1;
  85.                 }
  86.             }
  87.             if ( q[2] ) {
  88.                 if ( !q[1] ) { //the enemy died.
  89.                     if ( enhanced ) Game->PlayEnhancedMusic(enh_music, enh_trk);
  90.                     if ( !enhanced ) Game->DMapMIDI[Game->GetCurDMap()] = originalmusic;
  91.                 }
  92.             }
  93.             Waitframe();
  94.         }
  95.            
  96.     }
  97. }
  98.  
  99. //play enhanced music while an enemy with a specific ID is on-screen
  100.  
  101. ffc script NPC_Music{
  102.     void run(int npc_ID, int music_string, int track){
  103.         //int originalMIDi = //share these two
  104.         //int originalMusic[3] = //midi, enh music, track
  105.         //store the normal midi or music
  106.         //check for the npc and while it is on-screen
  107.         //change the midi
  108.        
  109.         //if it dies, change back
  110.         int q[4]; npc n; bool found;
  111.         int enh_music[256] = {0};
  112.         Game->GetDMapMusicFilename(Game->GetCurDMap(), enh_music);
  113.         for ( q[0] = 0; q[0] < 256; q[0]++ ) { if ( enh_music[q] == ' ' ) enh_music[q] = 0; } //kill the space.
  114.         int enh_trk = Game->GetDMapMusicTrack(Game->GetCurDMap());
  115.        
  116.         bool enhanced =  ( enh_music[0] != 0 ); //is the dmap music enhanced?
  117.        
  118.         int originalmusic = Game->DMapMIDI[Game->GetCurDMap()];
  119.         while(true){
  120.             for ( q[0] = Screen->NumNPCs(); q[0] > 0; q[0]-- ) {
  121.                 n = Screen->LoadNPC(q);
  122.                 if ( n->ID == npc_ID ) {
  123.                     q[1] = 1; break;
  124.                 }
  125.                 q[1] = 0;
  126.             }
  127.             if ( q[1] ) {
  128.                 if ( !q[2] ) {
  129.                     PlayEnhMusicFile(music_string, track);
  130.                     q[2] = 1;
  131.                 }
  132.             }
  133.             if ( q[2] ) {
  134.                 if ( !q[1] ) { //the enemy died.
  135.                     if ( enhanced ) Game->PlayEnhancedMusic(enh_music, enh_trk);
  136.                     if ( !enhanced ) Game->DMapMIDI[Game->GetCurDMap()] = originalmusic;
  137.                 }
  138.             }
  139.             Waitframe();
  140.         }
  141.            
  142.     }
  143. }
  144.  
  145. // These scripts will play MIDI files based on conditions set in the script args.
  146.  
  147. // D0: MIDI file to play while boss is on the screen.
  148. // D1: The Screen Register (Screen->D[reg]) to use.
  149. // D2: Victory MIDI to play when boss is defeated. If set to 0, the MIDI set by constant MIDI_DEFEATBOSS plays.
  150. // D3: The duration of the victory music.
  151. //
  152. //  If set to 0, the track will not play.
  153. //  If set to greater than 0, the track will play for a specific duration, as follows:
  154. //  To set using minutes, and seconds, set up minutes as the integer portion of the arg, and seconds as the decimal portion:
  155. //      e.g. 00005.0260 is 5 mins, 26 seconds.
  156. //      This works to a fineness of 1/10 second, so 00010.0136 is 10 minutes, 13.6 seconds.
  157. //  If you wish to specify the duration in frames, set the ten-thousands place to '1', and the rest of the value to the number of frames.
  158. //  e.g. 10526.1023 = 5,261,023 frames.
  159. //  e.g. 10001.3591 = 13,591 frames.
  160. //
  161. // D4: The enemy ID of the 'boss':
  162. //
  163. //  A value of zero here, instructs the FFC not to change the Screen->D[reg] value. Leave this at zero, if the enemy does this.
  164. //  Otherwise, set this to -1 (negative one) if you want the Victory music to play when all screen NPCs are dead...or...
  165. //  a positive value matching an enemy ID that is on the screen, if you want to play the Victory music when all enemies with that ID are dead.
  166.  
  167.  
  168. ffc script BossMusic{
  169.     void run(int bossMIDI, int reg, int victoryMIDI, int vict_dur, int enem){
  170.         Waitframes(6);
  171.         int curScreen = Game->GetCurScreen();
  172.         int dat = Game->GetScreenD(curScreen,reg);
  173.         if ( dat == 0 ) {
  174.             if ( bossMIDI > 0 ) {
  175.                 Game->PlayMIDI(bossMIDI);
  176.             }
  177.             else {
  178.                 Game->PlayMIDI(DEFAULT_BOSS_MUSIC);
  179.             }
  180.         }
  181.         int curDMap = Game->GetCurDMap();
  182.         int stdMIDI = Game->DMapMIDI[curDMap];
  183.        
  184.  
  185.         int VictoryClockMethod = _GetDigit(vict_dur, 4);
  186.         int dur;
  187.        
  188.         if ( VictoryClockMethod == 0 ) {
  189.             dur = MusicFrames(vict_dur); //Convert victory music into frames.
  190.         }
  191.        
  192.         if ( VictoryClockMethod > 0 ) {
  193.             dur = _GetPartialArg(vict_dur,3,8); //Use the full value of loopBossMusic as frame in int.
  194.         }
  195.        
  196.         while(true){
  197.             dat = Game->GetScreenD(curScreen,reg);
  198.            
  199.             if ( enem == -1 && !Screen->NumNPCs() ) {
  200.                 Game->SetScreenD(curScreen,reg,1);
  201.             }
  202.             if ( enem == 0 ) {
  203.                 //Should we do anything special?
  204.                 //A zero value is intended to be used if we don;t want the FFC to set Screen->D to 1.
  205.                 //-1 if we do it based on all enemies being dead.
  206.                 //A positive value trips it if there are no enemies of that ID on the screen.
  207.             }
  208.        
  209.             if ( enem > 0 && !NumNPCsOf(enem) ){
  210.                 Game->SetScreenD(curScreen,reg,1);
  211.             }
  212.            
  213.             dat = Game->GetScreenD(curScreen,reg);
  214.            
  215.            
  216.             if ( dat > 0 ) {
  217.                 if ( dur > 0 ) {
  218.                     if ( victoryMIDI > 0 ) {
  219.                         Game->PlayMIDI(MIDI_DEFEATBOSS);
  220.                     }
  221.                     else {
  222.                         Game->PlayMIDI(MIDI_DEFEATBOSS);
  223.                     }
  224.                     for ( int q = 0; q <= dur; q++ ) {
  225.                         Waitframe();
  226.                     }
  227.                 }
  228.                 Game->PlayMIDI(stdMIDI);
  229.             }
  230.             Waitframe();
  231.         }
  232.     }
  233. }
  234.            
  235. //////////////////////         
  236. /// Enhanced Music ///
  237. //////////////////////
  238.  
  239. /// These scripts will play 'enhanced music', using values set in script args.
  240. /// If an enhanced music file is not available (e.g. the player does not have it, or elects
  241. /// not to use it, then they will play a back-up MIDI file, also set by script args.
  242.  
  243. // D0: MIDI number to default to for this boss, if no enhanced music is available.
  244. //  Split argument, high and low at decimal point:
  245. //  #####.xxxx -> Backup MIDI file to play if enhanced BOSS music is not available.
  246. //  xxxxx.#### -> Backup MIDI file to play if enhanced VICTORY music is not available.
  247. // D1: Screen->D reg to set/check.
  248. // D2: The duration of the victory music.
  249. //  If set to 0, the track will not play.
  250. //  If set to greater than 0, the track will play for a specific duration, as follows:
  251. //  To set using minutes, and seconds, set up minutes as the integer portion of the arg, and seconds as the decimal portion:
  252. //      e.g. 00005.0260 is 5 mins, 26 seconds.
  253. //      This works to a fineness of 1/10 second, so 00010.0136 is 10 minutes, 13.6 seconds.
  254. //  If you wish to specify the duration in frames, set the ten-thousands place to '1', and the rest of the value to the number of frames.
  255. //  e.g. 10526.1023 = 5,261,023 frames.
  256. //  e.g. 10001.3591 = 13,591 frames.
  257. //
  258. // D3: The STRING number, and track number, for Boss Music. Split arg, high and low at decimal point:
  259. //  #####.xxxx -> The file number.
  260. //  xxxxx.#### -> The track number to play.
  261. //  Uses string ID from internal strings table.
  262. // D4: The STRING number, and track number, for Victory Music. Split arg, high and low at decimal point:
  263. //  #####.xxxx -> The file number.
  264. //  xxxxx.#### -> The track number to play.
  265. //  Uses string ID from internal strings table.
  266. // D5: The point in the track to pause, then loop
  267. //
  268. //  If set to 0, the track with loop only when it ends.
  269. //  If set to greater than 0, the track will loop befor eit ends, as follows:
  270. //  To loop by setting minutes, and seconds, set up minutes as the integer portion of the arg, and seconds as the decimal portion:
  271. //      e.g. 00005.0260 is 5 mins, 26 seconds.
  272. //      This works to a fineness of 1/10 second, so 00010.0136 is 10 minutes, 13.6 seconds.
  273. //  If you wish to specify the loop in frames, set the ten-thousands place to '1', and the rest of the value to the number of frames.
  274. //  e.g. 10526.1023 = 5,261,023 frames.
  275. //  e.g. 10001.3591 = 13,591 frames.
  276. //
  277. // D6: This value instructs the FFC to set Screen->D[reg] = 1 when enemies are dead.
  278. //  A value of zero here, instructs the FFC not to change the Screen->D[reg] value. Leave this at zero, if the enemy does this.
  279. //  Otherwise, set this to -1 (negative one) if you want the Victory music to play when all screen NPCs are dead...or...
  280. //  a positive value matching an enemy ID that is on the screen, if you want to play the Victory music when all enemies with that ID are dead.
  281. //
  282. // D7: If set to '1' or above, this will trace informationt o allegro.log for you as debug datum.
  283.  
  284.  
  285. //Version 0.44 - Strings set by String Table (ZQuest String Editor, not hardcoded)
  286.  
  287. ffc script BossMusicEnhanced_InternalStrings{
  288.     //Credit Moosh for reminding me that reading internal strings in the string table is a thing.
  289.     void run(int midiNumber_victoryMidiNumber, int reg, int vict_dur, float musicBoss_trkBoss, float musicVictory_trkVictory, float loopBossMusic, int enem, int debug){
  290.         int curScreen = Game->GetCurScreen();
  291.         int curDMAP = Game->GetCurDMap();
  292.         int curDmap = Game->GetCurDMap();
  293.         int dat = Game->GetScreenD(curScreen,reg);
  294.         int stdMIDI = Game->DMapMIDI[curDMAP];
  295.        
  296.         int dmapMusicBuffer[512]=" ";
  297.         Game->GetDMapMusicFilename(curDMAP, dmapMusicBuffer);
  298.        
  299.         int midiNumber = _GetHighArgument(midiNumber_victoryMidiNumber); //#####.xxxx
  300.         int victoryMIDI = _GetLowArgument(midiNumber_victoryMidiNumber); //xxxxx.####
  301.        
  302.         int musicBoss = _GetHighArgument(musicBoss_trkBoss); //#####.xxxx
  303.         int trkBoss = _GetLowArgument(musicBoss_trkBoss); //xxxxx.####
  304.        
  305.         int musicVictory = _GetHighArgument(musicVictory_trkVictory);
  306.         int mv[]="musicVictory = "; TraceS(mv); Trace(musicVictory);
  307.         int trkVictory = _GetLowArgument(musicVictory_trkVictory); //xxxxx.####
  308.        
  309.         int dmapTrack = Game->GetDMapMusicTrack(curDMAP);
  310.         int q;
  311.        
  312.         int boss_buffer[255]=" "; //two-digit number, plus four-digit extension, plus NULL.
  313.         int victory_buffer[255]=" "; //Buffer for Victory Music Filename.
  314.        
  315.         Game->GetMessage(musicVictory, victory_buffer);
  316.         Game->GetMessage(musicBoss, boss_buffer);
  317.        
  318.        
  319.         //Print filenames to allegro.log.
  320.         if ( debug ) {
  321.             int loading[]="Attempting to load file: ";
  322.             TraceNL();
  323.             TraceS(loading);
  324.             TraceNL();
  325.             TraceS(boss_buffer);
  326.             TraceNL();
  327.             TraceS(loading);
  328.             TraceNL();
  329.             TraceS(victory_buffer);
  330.             TraceNL();
  331.         }
  332.        
  333.         int playingBoss[]="Playing Boss Music";
  334.         int playingVictory[]="Playing Victory Music";
  335.         int errLoading[]="Error loading track.";
  336.        
  337.         int LoopClockMethod = _GetDigit(loopBossMusic, 4);
  338.         //Convert mins and seconds.
  339.        
  340.         int BossMusicDuration;
  341.         if ( LoopClockMethod == 0 ) {
  342.             BossMusicDuration = MusicFrames(loopBossMusic); //Convert loopBossMusic into time.
  343.         }
  344.         if ( LoopClockMethod > 0 ) {
  345.             BossMusicDuration = _GetPartialArg(loopBossMusic,3,8); //Use the full value of loopBossMusic as frame in int.
  346.         }
  347.        
  348.         int VictoryClockMethod = _GetDigit(vict_dur, 4);
  349.         int dur;
  350.        
  351.         if ( VictoryClockMethod == 0 ) {
  352.             dur = MusicFrames(vict_dur); //Convert victory music into frames.
  353.         }
  354.        
  355.         if ( VictoryClockMethod > 0 ) {
  356.             dur = _GetPartialArg(vict_dur,3,8); //Use the full value of loopBossMusic as frame in int.
  357.         }
  358.         for ( q  = 0; q < 256; q++ ) { if ( boss_buffer[q] == ' ' ) boss_buffer[q] = 0; } //kill the space.
  359.         for ( q  = 0; q < 256; q++ ) { if ( victory_buffer[q] == ' ' ) victory_buffer[q] = 0; } //kill the space.
  360.         bool playing = false;
  361.        
  362.         while(true){
  363.             Waitframes(5);
  364.             dat = Game->GetScreenD(curScreen,reg);
  365.             Waitframes(6); //Wait for enemies to spawn.
  366.             //Set Screen->D[reg] = 1 if the enemy is dead.
  367.             if ( enem == -1 && !Screen->NumNPCs() ) {
  368.                 Game->SetScreenD(curScreen,reg,1);
  369.             }
  370.             if ( enem == 0 ) {
  371.                 //Should we do anything special?
  372.                 //A zero value is intended to be used if we don't want the FFC to set Screen->D to 1.
  373.                 //-1 if we do it based on all enemies being dead.
  374.                 //A positive value trips it if there are no enemies of that ID on the screen.
  375.             }
  376.        
  377.             if ( enem > 0 && !NumNPCsOf(enem) ){
  378.                 Game->SetScreenD(curScreen,reg,1);
  379.             }
  380.            
  381.             dat = Game->GetScreenD(curScreen,reg);
  382.                    
  383.             if ( dat == 0 && loopBossMusic == 0 && !playing ){
  384.                 Game->PlayEnhancedMusic(boss_buffer, trkBoss);
  385.                 TraceS(playingBoss);
  386.            
  387.                 if ( ! Game->PlayEnhancedMusic(boss_buffer, trkBoss) ) {
  388.                     TraceS(errLoading);
  389.                     if ( midiNumber > 0 ) {
  390.                         Game->PlayMIDI(midiNumber); //Play MIDI if enhanced music is not available.
  391.                     }
  392.                     else {
  393.                         Game->PlayMIDI(DEFAULT_BOSS_MUSIC); //Play default music if midiNumber is set to '0'.
  394.                     }
  395.                        
  396.                 }
  397.                 playing = true;
  398.             }
  399.            
  400.             if ( dat == 0 && loopBossMusic > 0 ){
  401.  
  402.                 //set up music loop
  403.                 for ( int q = BossMusicDuration; q >=0; q-- ){
  404.                     if ( q == BossMusicDuration && dat == 0 ) {
  405.                        
  406.                         Game->PlayEnhancedMusic(boss_buffer, trkBoss);
  407.                         TraceS(playingBoss);
  408.                         if ( ! Game->PlayEnhancedMusic(boss_buffer, trkBoss) ) {
  409.                             TraceS(errLoading);
  410.                             Game->PlayMIDI(midiNumber); //Play MIDI if enhanced music is not available.
  411.                         }
  412.                     }
  413.                     if ( enem == -1 && !Screen->NumNPCs() ) {
  414.                         Game->SetScreenD(curScreen,reg,1);
  415.                     }
  416.                     if ( enem == 0 ) {
  417.                         //Should we do anything special?
  418.                         //A zero value is intended to be used if we don;t want the FFC to set Screen->D to 1.
  419.                         //-1 if we do it based on all enemies being dead.
  420.                         //A positive value trips it if there are no enemies of that ID on the screen.
  421.                     }
  422.                     if ( enem > 0 && !NumNPCsOf(enem) ){
  423.                         Game->SetScreenD(curScreen,reg,1);
  424.                     }
  425.                     dat = Game->GetScreenD(curScreen,reg);
  426.                     if ( dat > 0 ) {
  427.                         break;
  428.                     }
  429.                     Waitframe();
  430.                
  431.                 }
  432.             }
  433.            
  434.             if ( dat == 0 && loopBossMusic == 0 && !playing ){
  435.  
  436.                 Game->PlayEnhancedMusic(boss_buffer, trkBoss);
  437.                 TraceS(playingBoss);
  438.                 if ( ! Game->PlayEnhancedMusic(boss_buffer, trkBoss) ) {
  439.                     TraceS(errLoading);
  440.                     if ( midiNumber > 0 ) {
  441.                         Game->PlayMIDI(midiNumber); //Play MIDI if enhanced music is not available.
  442.                     }
  443.                     else {
  444.                         Game->PlayMIDI(DEFAULT_BOSS_MUSIC); //Plays default if not specified.
  445.                     }
  446.                 }
  447.                 playing = true;
  448.                
  449.             }
  450.            
  451.             dat = Game->GetScreenD(curScreen,reg);
  452.             if ( dat > 0 ) {
  453.                 if ( dur > 0 ) {
  454.                     Game->PlayEnhancedMusic(victory_buffer, trkVictory);
  455.                     TraceS(playingVictory);
  456.                     if ( ! Game->PlayEnhancedMusic(victory_buffer, trkVictory) ) {
  457.                         TraceS(errLoading);
  458.                         if ( victoryMIDI > 0 ) {
  459.                             Game->PlayMIDI(victoryMIDI);
  460.                         }
  461.                         else {
  462.                             Game->PlayMIDI(MIDI_DEFEATBOSS); //Plays default if Victory MIDI not specified.
  463.                         }
  464.                        
  465.                     }
  466.                     for ( int q = 0; q <= dur; q++ ) {
  467.                         Waitframe(); //Pause for duration of victory music.
  468.                     }
  469.                 }
  470.                 Game->PlayEnhancedMusic(dmapMusicBuffer, dmapTrack);
  471.                 if ( ! Game->PlayEnhancedMusic(dmapMusicBuffer, dmapTrack) ) {
  472.                     Game->PlayMIDI(stdMIDI);
  473.                 }
  474.                 Quit();
  475.             }
  476.             Waitframe();
  477.         }
  478.        
  479.     }
  480. }
  481.  
  482. // D0: MIDI number to default to for this boss, if no enhanced music is available.
  483. //  Split argument, high and low at decimal point:
  484. //  #####.xxxx -> Backup MIDI file to play if enhanced BOSS music is not available.
  485. //  xxxxx.#### -> Backup MIDI file to play if enhanced VICTORY music is not available.
  486. // D1: Screen->D reg to set/check.
  487. // D2: Set to a value of '1' or higher, to use durations.
  488. // D3: Sets file type for both enhanced music tracks. Split argument, high and low at decimal point:
  489. //  xxx##.xxxx -> Type for Boss Music file
  490. //  xxxxx.xx## -> Type for Victory Music file
  491. // D4: The file number, and track number, for Boss Music. Split arg, high and low at decimal point:
  492. //  #####.xxxx -> The file number.
  493. //  xxxxx.#### -> The track number to play.
  494. // D5: The file number, and track number, for Victory Music. Split arg, high and low at decimal point:
  495. //  #####.xxxx -> The file number.
  496. //  xxxxx.#### -> The track number to play.
  497. // D6: The point in the track to pause, then loop.
  498. //
  499. //  If set to 0, the track with loop only when it ends.
  500. //  If set to greater than 0, the track will loop befor eit ends, as follows:
  501. //  To loop by setting minutes, and seconds, set up minutes as the integer portion of the arg, and seconds as the decimal portion:
  502. //      e.g. 00005.0260 is 5 mins, 26 seconds.
  503. //      This works to a fineness of 1/10 second, so 00010.0136 is 10 minutes, 13.6 seconds.
  504. //  If you wish to specify the loop in frames, set the ten-thousands place to '1', and the rest of the value to the number of frames.
  505. //  e.g. 10526.1023 = 5,261,023 frames.
  506. //  e.g. 10001.3591 = 13,591 frames.
  507. //
  508. // D7: This value instructs the FFC to set Screen->D[reg] = 1 when enemies are dead.
  509. //  #####.xxxx -> A value of zero here, instructs the FFC not to change the Screen->D[reg] value. Leave this at zero, if the enemy does this.
  510. //  Otherwise, set this to -1 (negative one) if you want the Victory music to play when all screen NPCs are dead...or...
  511. //  a positive value matching an enemy ID that is on the screen, if you want to play the Victory music when all enemies with that ID are dead.
  512. //  xxxxx.#### -> Set to '1' or higher to enable debugging reports to allegro.log.
  513. // 
  514.  
  515. //Version 0.44 (Numbered Files)
  516.  
  517. ffc script BossMusicEnhanced{
  518.     void run(int midiNumber_victoryMidiNumber, int reg, int victoryDur, float musicType_musicTypeVictory, float musicBoss_trkBoss, float musicVictory_trkVictory, float loopBossMusic, int enem_debug){
  519.         int curScreen = Game->GetCurScreen();
  520.         int curDMAP = Game->GetCurDMap();
  521.         int curDmap = Game->GetCurDMap();
  522.         int dat = Game->GetScreenD(curScreen,reg);
  523.         int stdMIDI = Game->DMapMIDI[curDMAP]; 
  524.         int enem = _GetHighArgument(enem_debug);
  525.         int debug= _GetLowArgument(enem_debug);
  526.        
  527.         int dmapMusicBuffer[512]=" ";
  528.         Game->GetDMapMusicFilename(curDMAP, dmapMusicBuffer);
  529.        
  530.         int midiNumber = _GetHighArgument(midiNumber_victoryMidiNumber); //#####.xxxx
  531.         int victoryMIDI = _GetLowArgument(midiNumber_victoryMidiNumber); //xxxxx.####
  532.        
  533.         int musicType = _GetHighArgument(musicType_musicTypeVictory); //xxx##.xxxx
  534.         int musicType_Victory = _GetLowArgument(musicType_musicTypeVictory); //xxxxx.xx##
  535.        
  536.         int musicBoss = _GetHighArgument(musicBoss_trkBoss); //#####.xxxx
  537.         int trkBoss = _GetLowArgument(musicBoss_trkBoss); //xxxxx.####
  538.        
  539.         int musicVictory = _GetHighArgument(musicVictory_trkVictory); //#####.xxxx
  540.         int trkVictory = _GetLowArgument(musicVictory_trkVictory); //xxxxx.####
  541.        
  542.         int dmapTrack = Game->GetDMapMusicTrack(curDMAP);
  543.         int mp3[]=".mp3";
  544.         int vgm[]=".vgm";
  545.         int nsf[]=".nsf";
  546.         int ogg[]=".ogg";
  547.         int s3m[]=".s3m";
  548.         int mod[]=".mod";
  549.         int spc[]=".spc";
  550.         int gym[]=".gym";
  551.         int gbs[]=".gbs";
  552.         int it_format[]=".it";
  553.         int xm[]=".xm";
  554.        
  555.         int boss_buffer[7]=" "; //two-digit number, plus four-digit extension, plus NULL.
  556.         int victory_buffer[7]=" "; //Buffer for Victory Music Filename.
  557.         int strBoss[2]=" "; //The two digit value of musicBoss arg.
  558.         int strVictory[2]=" "; //The two digit value of musicVictory is stored here.
  559.         //int bossMusic[]=" "; //Must read value from enhBoss, append .mp3 to it, and
  560.        
  561.        
  562.         ///Set up Boss Music Filename String
  563.         itoa(strBoss, musicBoss); //Copy the value of arg musicBoss into string strBoss.   
  564.         strncpy(boss_buffer, strBoss, 2); //Copy filename (two-digit number) to buffer.
  565.         if ( musicType == 0 ) strcat(boss_buffer, mp3); //Append datatype to buffer (MP3)
  566.         else if ( musicType == 1 ) strcat(boss_buffer, vgm); //Append datatype to buffer ( Video Game Music format)
  567.         else if ( musicType == 2 ) strcat(boss_buffer, nsf); //Append datatype to buffer ( NES Sound File )
  568.         else if ( musicType == 3 ) strcat(boss_buffer, ogg); //Append datatype to buffer ( The Xiph.org open music format )
  569.         else if ( musicType == 4 ) strcat(boss_buffer, s3m); //Append datatype to buffer ( ScreamTracker 3 module file )
  570.         else if ( musicType == 5 ) strcat(boss_buffer, mod); //Append datatype to buffer ( Tracker Module file )
  571.         else if ( musicType == 6 ) strcat(boss_buffer, spc); //Append datatype to buffer ( Super NES / SuFami soound file )
  572.         else if ( musicType == 7 ) strcat(boss_buffer, gym); //Append datatype to buffer ( Genesis / Megadrive sound file )
  573.         else if ( musicType == 8 ) strcat(boss_buffer, gbs); //Append datatype to buffer ( Gameboy sound file )
  574.         else if ( musicType == 9 ) strcat(boss_buffer, it_format); //Append datatype to buffer ( Impulse Tracker audio file )
  575.         else if ( musicType == 10 ) strcat(boss_buffer, xm); //Append datatype to buffer ( Triton FastTracker 2 'Extended Module' format }
  576.         ///Other formats.
  577.        
  578.         //Set up Victory Music Filename String
  579.         itoa(strVictory, musicVictory); //Copy the value of arg musicVictory into string strVictory.
  580.         strncpy(victory_buffer, strVictory, 2); //Copy filename (two-digit number) to buffer.
  581.         if ( musicType_Victory == 0 ) strcat(victory_buffer, mp3); //Append datatype to buffer (MP3)
  582.         else if ( musicType_Victory == 1 ) strcat(victory_buffer, vgm); //Append datatype to buffer ( Video Game Music format)
  583.         else if ( musicType_Victory == 2 ) strcat(victory_buffer, nsf); //Append datatype to buffer ( NES Sound File )
  584.         else if ( musicType_Victory == 3 ) strcat(victory_buffer, ogg); //Append datatype to buffer ( The Xiph.org open music format )
  585.         else if ( musicType_Victory == 4 ) strcat(victory_buffer, s3m); //Append datatype to buffer ( ScreamTracker 3 module file )
  586.         else if ( musicType_Victory == 5 ) strcat(victory_buffer, mod); //Append datatype to buffer ( Tracker Module file )
  587.         else if ( musicType_Victory == 6 ) strcat(victory_buffer, spc); //Append datatype to buffer ( Super NES / SuFami soound file )
  588.         else if ( musicType_Victory == 7 ) strcat(victory_buffer, gym); //Append datatype to buffer ( Genesis / Megadrive sound file )
  589.         else if ( musicType_Victory == 8 ) strcat(victory_buffer, gbs); //Append datatype to buffer ( Gameboy sound file )
  590.         else if ( musicType_Victory == 9 ) strcat(victory_buffer, it_format); //Append datatype to buffer ( Impulse Tracker audio file )
  591.         else if ( musicType_Victory == 10 ) strcat(victory_buffer, xm); //Append datatype to buffer ( Triton FastTracker 2 'Extended Module' format }
  592.         ///Other formats.
  593.        
  594.        
  595.         //Print filenames to allegro.log.
  596.         if ( debug ) {
  597.             int loading[]="Attempting to load file: ";
  598.             TraceNL();
  599.             TraceS(loading);
  600.             TraceNL();
  601.             TraceS(boss_buffer);
  602.             TraceNL();
  603.             TraceS(loading);
  604.             TraceNL();
  605.             TraceS(victory_buffer);
  606.             TraceNL();
  607.         }
  608.        
  609.         int playingBoss[]="Playing Boss Music";
  610.         int playingVictory[]="Playing Victory Music";
  611.         int errLoading[]="Error loading track.";
  612.        
  613.         int LoopClockMethod = _GetDigit(loopBossMusic, 4);
  614.         //Convert mins and seconds.
  615.        
  616.        
  617.         int BossMusicDuration;
  618.         if ( LoopClockMethod == 0 ) {
  619.             BossMusicDuration = MusicFrames(loopBossMusic); //Convert loopBossMusic into time.
  620.         }
  621.         if ( LoopClockMethod > 0 ) {
  622.             BossMusicDuration = _GetPartialArg(loopBossMusic,3,8); //Use the full value of loopBossMusic as frame in int.
  623.         }
  624.        
  625.         int VictoryDuration;
  626.         int VictoryDurMethod = _GetDigit(victoryDur, 4);
  627.         if ( VictoryDurMethod == 0 ) {
  628.             VictoryDuration = MusicFrames(victoryDur); //Convert loopBossMusic into time.
  629.         }
  630.         if ( VictoryDurMethod > 0 ) {
  631.             VictoryDuration = _GetPartialArg(victoryDur,3,8); //Use the full value of loopBossMusic as frame in int.
  632.         }
  633.        
  634.        
  635.         bool playing = false;
  636.        
  637.         while(true){
  638.             dat = Game->GetScreenD(curScreen,reg);
  639.             Waitframes(6); //Wait for enemies to spawn.
  640.             //Set Screen->D[reg] = 1 if the enemy is dead.
  641.             if ( enem == -1 && !Screen->NumNPCs() ) {
  642.                 Game->SetScreenD(curScreen,reg,1);
  643.             }
  644.             if ( enem == 0 ) {
  645.                 //Should we do anything special?
  646.                 //A zero value is intended to be used if we don;t want the FFC to set Screen->D to 1.
  647.                 //-1 if we do it based on all enemies being dead.
  648.                 //A positive value trips it if there are no enemies of that ID on the screen.
  649.             }
  650.        
  651.             if ( enem > 0 && !NumNPCsOf(enem) ){
  652.                 Game->SetScreenD(curScreen,reg,1);
  653.             }
  654.            
  655.             dat = Game->GetScreenD(curScreen,reg);
  656.                    
  657.             if ( dat == 0 && loopBossMusic == 0 && !playing ){
  658.                 Game->PlayEnhancedMusic(boss_buffer, trkBoss);
  659.                 TraceS(playingBoss);
  660.            
  661.                 if ( ! Game->PlayEnhancedMusic(boss_buffer, trkBoss) ) {
  662.                     TraceS(errLoading);
  663.                     if ( midiNumber > 0 ) {
  664.                         Game->PlayMIDI(midiNumber); //Play MIDI if enhanced music is not available.
  665.                     }
  666.                     else {
  667.                         Game->PlayMIDI(DEFAULT_BOSS_MUSIC);  //Play default if not assigned.
  668.                     }
  669.                        
  670.                 }
  671.  
  672.                 playing = true;
  673.             }
  674.            
  675.             if ( dat == 0 && loopBossMusic > 0 ){
  676.  
  677.                 //set up music loop
  678.                 for ( int q = BossMusicDuration; q >=0; q-- ){
  679.                     if ( q == BossMusicDuration && dat == 0 ) {
  680.                        
  681.                         Game->PlayEnhancedMusic(boss_buffer, trkBoss);
  682.                         TraceS(playingBoss);
  683.                         if ( ! Game->PlayEnhancedMusic(boss_buffer, trkBoss) ) {
  684.                             TraceS(errLoading);
  685.                             if ( midiNumber > 0 ) {
  686.                                 Game->PlayMIDI(midiNumber); //Play MIDI if enhanced music is not available.
  687.                             }
  688.                             else {
  689.                                 Game->PlayMIDI(DEFAULT_BOSS_MUSIC); //Play default if not assigned.
  690.                             }
  691.                         }
  692.                     }
  693.                     if ( enem == -1 && !Screen->NumNPCs() ) {
  694.                         Game->SetScreenD(curScreen,reg,1);
  695.                     }
  696.                     if ( enem == 0 ) {
  697.                         //Should we do anything special?
  698.                         //A zero value is intended to be used if we don;t want the FFC to set Screen->D to 1.
  699.                         //-1 if we do it based on all enemies being dead.
  700.                         //A positive value trips it if there are no enemies of that ID on the screen.
  701.                     }
  702.                     if ( enem > 0 && !NumNPCsOf(enem) ){
  703.                         Game->SetScreenD(curScreen,reg,1);
  704.                     }
  705.                     dat = Game->GetScreenD(curScreen,reg);
  706.                     if ( dat > 0 ) {
  707.                         break;
  708.                     }
  709.                     Waitframe();
  710.                
  711.                 }
  712.             }
  713.            
  714.             if ( dat == 0 && loopBossMusic == 0 && !playing ){
  715.  
  716.                 Game->PlayEnhancedMusic(boss_buffer, trkBoss);
  717.                 TraceS(playingBoss);
  718.                 if ( ! Game->PlayEnhancedMusic(boss_buffer, trkBoss) ) {
  719.                     TraceS(errLoading);
  720.                     if ( midiNumber > 0 ) {
  721.                         Game->PlayMIDI(midiNumber); //Play MIDI if enhanced music is not available.
  722.                     }
  723.                     else {
  724.                         Game->PlayMIDI(DEFAULT_BOSS_MUSIC); //Play default if not assigned.
  725.                     }
  726.                 }
  727.                 playing = true;
  728.                
  729.             }
  730.            
  731.             dat = Game->GetScreenD(curScreen,reg);
  732.             if ( dat > 0 ) {
  733.                 if ( VictoryDuration > 0 ) {
  734.                     Game->PlayEnhancedMusic(victory_buffer, trkVictory);
  735.                     TraceS(playingVictory);
  736.                     if ( ! Game->PlayEnhancedMusic(victory_buffer, trkVictory) ) {
  737.                         TraceS(errLoading);
  738.                         if ( victoryMIDI > 0 ) {
  739.                             Game->PlayMIDI(victoryMIDI);
  740.                         }
  741.                         else {
  742.                             Game->PlayMIDI(MIDI_DEFEATBOSS);
  743.                         }
  744.                        
  745.                     }
  746.                     for ( int q = 0; q <= VictoryDuration; q++ ) {
  747.                         Waitframe(); //Pause for duration of victory music.
  748.                     }
  749.                 }
  750.                 Game->PlayEnhancedMusic(dmapMusicBuffer, dmapTrack);
  751.                 if ( ! Game->PlayEnhancedMusic(dmapMusicBuffer, dmapTrack) ) {
  752.                     Game->PlayMIDI(stdMIDI);
  753.                 }
  754.                 Quit();
  755.             }
  756.             Waitframe();
  757.         }
  758.        
  759.     }
  760. }
  761.  
  762. /////////////////
  763. /// FUNCTIONS ///
  764. /////////////////
  765.  
  766. //Pass a float to either of these, to convert raw float into mins and seconds as:
  767. // #####.xxxx = # mins x seconds. Example:
  768. // 00003.0050 = 3 mins, 5 seconds.
  769. // 00001.0012 = 1 minute, 5.2 seconds.
  770.  
  771. //Timers are functional to a total clock of 3579 seconds (59 mins, 39 seconds).
  772.  
  773. int MusicSeconds(float seconds){
  774.         int music_seconds = _GetLowArgument(seconds);
  775.         return music_seconds * 6;
  776. }
  777.    
  778. int MusicMinutes(float mins){
  779.         int music_minutes = _GetHighArgument(mins);
  780.         return music_minutes * 360;
  781. }
  782.        
  783. //Returns total time in frames, so that ZC understands it.
  784.  
  785. int MusicFrames(float val){
  786.     int mins = MusicMinutes(val);
  787.     int seconds = MusicSeconds(val);
  788.     return mins+seconds;
  789. }
  790.  
  791.  
  792. int _GetRemainderAsInt(int v) {
  793.         int r = (v - (v << 0)) * 10000;
  794.         return r;
  795.     }
  796.  
  797. // This function breaks up the value of an argument into individual digits. It is combined with the function GetDigit below.
  798.  
  799.  
  800. int _GetDigit(int n, int place){ //GetDigit and related functions by Gleeok
  801.     place = Clamp(place, -4, 4);
  802.     if(place < 0){
  803.         n = _GetRemainderAsInt(n);
  804.         place += 4;
  805.     }
  806.  
  807.     int r = ((n / Pow(10, place)) % 10) << 0;
  808.     return r;
  809. }
  810.  
  811. int _GetHighArgument(int arg) {
  812.     return arg >> 0;
  813. }
  814.  
  815. int _GetLowArgument(int arg) {
  816.     return (arg - (arg >> 0)) * 10000;
  817. }
  818.  
  819. int _GetPartialArg(int arg, int place, int num){
  820.     place = Clamp(place, -4, 4);
  821.     int r;
  822.     int adj = 1;
  823.     for(int i = num-1; i > -1; i--){
  824.         if(place - i < -4) continue;
  825.         r += _GetDigit(arg, place - i) * adj;
  826.         adj *= 10;
  827.     }
  828.     return r;
  829. }
  830.  
  831.  
  832. // Plays enhanced music file by reading the string 'str_id' from Quest->Strings, at a specified track 'track_id'.
  833. // If track_id is positive, it uses this track.
  834. // If track_id is negative, it uses the message string equal to the inverse value (so -20 is string ID 20)
  835. //  to set the track ID.
  836. // Returns true if playing, false otherwise.
  837. bool PlayEnhMusicFile(int str_id, int track_id){
  838.     int musicBuffer[256]=" ";
  839.     int track_buffer[256]=" "; int q; int trk;
  840.     Game->GetMessage(str_id, musicBuffer);
  841.     if ( track_id < 0 ) {
  842.         Game->GetMessage((track_id * -1), track_buffer);
  843.         for ( q = 0; q < 256; q++ ) { if ( track_buffer[q] == ' ' ) track_buffer[q] = 0; } //Kill GetMessage trailing spaces.
  844.         trk = atoi(track_buffer);
  845.     }
  846.     else trk = track_id;
  847.    
  848.     //Kill GetMessage trailing spaces.
  849.     for ( q = 0; q < 256; q++ ) { if ( musicBuffer[q] == ' ' ) musicBuffer[q] = 0; }
  850.     return ( Game->PlayEnhancedMusic(musicBuffer, trk) );
  851. }
  852.  
  853. int Legacy_PlayEnhMusicFile(int str_id, int track_id) { if ( PlayEnhMusicFile(str_id, track_id) ) return 1; return 0; }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×