ZoriaRPG

Music.zh v1.2

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

×