Advertisement
ZoriaRPG

Follower Script for JudasRising

Apr 10th, 2019
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.41 KB | None | 0 0
  1. /////////////////////////////
  2. /// Zelda 3 Follower      ///
  3. /// v0.4                  ///
  4. /// 10th April, 2019      ///
  5. /// By: ZoriaRPG          ///
  6. /// Made for: JudasRising ///
  7. /////////////////////////////
  8. // v0.1 : Initial
  9. // v0.2 : Changed hardcoded > 3 frame cap to use FOLLOWER_MAX_FRAME in drawing loops.
  10. // v0.3 : Fix scrolling positions and positions onContinue
  11. // v0.4 : The follower's tile is now set by the combo of the ffc 'GetZelda'. (It's combo tile, -4.)
  12. //      : Added the ability for the follower to play a message, and give an item to Link, when Link
  13. //      : delivers them to their destination.
  14. //  : Added the ability to show a message when you collect the npc.
  15.  
  16. int Follower[128] = {-1, -1};
  17.  
  18. const int FOLLOWER_ZELDA_MIDI_DURATION = 300;
  19. const int FOLLOWER_ZELDA_MIDI = 1;
  20. const int FOLLOWER_MAX_FRAME = 3; //4-frame walking animation
  21. //const int FOLLOWER_BASE_TILE = 8600; //An octorock
  22. const int FOLLOWER_CSET = 2; //Blue
  23.  
  24. const int FOLLOWER_MIDI_TIMER   = 0;
  25. const int FOLLOWER_RESCUED  = 1;
  26. const int FOLLOWER_ACTIVE   = 2;
  27. const int FOLLOWER_UPDATE   = 3;
  28. const int FOLLOWER_FRAME    = 4;
  29. const int FOLLOWER_SUBFRAME     = 5;
  30.  
  31. const int FOLLOWER_ORIG_MIDI    = 6;
  32. const int FOLLOWER_BASE_TILE = 7;
  33.  
  34. void FollowerContinue()
  35. {
  36.     for ( int q = FOLLOWER_X; q <= FOLLOWER_X20; ++q )
  37.     {
  38.         Follower[q] = Link->X;
  39.     }
  40.     for ( int q = FOLLOWER_Y; q <= FOLLOWER_Y20; ++q )
  41.     {
  42.         Follower[q] = Link->Y;
  43.     }
  44.     for ( int q = FOLLOWER_DIR; q <= FOLLOWER_DIR20; ++q )
  45.     {
  46.         Follower[q] = Link->Dir;
  47.     }
  48. }
  49.  
  50. void FollowerScroll()
  51. {
  52.     if ( Link->Action != LA_SCROLLING ) return;
  53.     for ( int q = FOLLOWER_X; q <= FOLLOWER_X20; ++q )
  54.     {
  55.         Follower[q] = Link->X;
  56.     }
  57.     for ( int q = FOLLOWER_Y; q <= FOLLOWER_Y20; ++q )
  58.     {
  59.         Follower[q] = Link->Y;
  60.     }
  61.     for ( int q = FOLLOWER_DIR; q <= FOLLOWER_DIR20; ++q )
  62.     {
  63.         Follower[q] = Link->Dir;
  64.     }
  65. }
  66.  
  67. const int FOLLOWER_X        = 10;
  68. const int FOLLOWER_X1       = 11;
  69. const int FOLLOWER_X2       = 12;
  70. const int FOLLOWER_X3       = 13;
  71. const int FOLLOWER_X4       = 14;
  72. const int FOLLOWER_X5       = 15;
  73. const int FOLLOWER_X6       = 16;
  74. const int FOLLOWER_X7       = 17;
  75. const int FOLLOWER_X8       = 19;
  76. const int FOLLOWER_X9       = 20;
  77. const int FOLLOWER_X10      = 21;
  78. const int FOLLOWER_X11      = 22;
  79. const int FOLLOWER_X12      = 23;
  80. const int FOLLOWER_X13      = 23;
  81. const int FOLLOWER_X14      = 24;
  82. const int FOLLOWER_X15      = 26;
  83. const int FOLLOWER_X16      = 27;
  84. const int FOLLOWER_X17      = 28;
  85. const int FOLLOWER_X18      = 29;
  86. const int FOLLOWER_X19      = 30;
  87. const int FOLLOWER_X20      = 31;
  88.  
  89. const int FOLLOWER_Y        = 40;
  90. const int FOLLOWER_Y1       = 41;
  91. const int FOLLOWER_Y2       = 42;
  92. const int FOLLOWER_Y3       = 43;
  93. const int FOLLOWER_Y4       = 44;
  94. const int FOLLOWER_Y5       = 45;
  95. const int FOLLOWER_Y6       = 46;
  96. const int FOLLOWER_Y7       = 47;
  97. const int FOLLOWER_Y8       = 48;
  98. const int FOLLOWER_Y9       = 49;
  99. const int FOLLOWER_Y10      = 50;
  100. const int FOLLOWER_Y11      = 51;
  101. const int FOLLOWER_Y12      = 52;
  102. const int FOLLOWER_Y13      = 53;
  103. const int FOLLOWER_Y14      = 54;
  104. const int FOLLOWER_Y15      = 55;
  105. const int FOLLOWER_Y16      = 56;
  106. const int FOLLOWER_Y17      = 57;
  107. const int FOLLOWER_Y18      = 58;
  108. const int FOLLOWER_Y19      = 59;
  109. const int FOLLOWER_Y20      = 60;
  110.  
  111. const int FOLLOWER_DIR      = 70;
  112. const int FOLLOWER_DIR1     = 71;
  113. const int FOLLOWER_DIR2     = 72;
  114. const int FOLLOWER_DIR3     = 73;
  115. const int FOLLOWER_DIR4     = 74;
  116. const int FOLLOWER_DIR5     = 75;
  117. const int FOLLOWER_DIR6     = 76;
  118. const int FOLLOWER_DIR7     = 77;
  119. const int FOLLOWER_DIR8     = 78;
  120. const int FOLLOWER_DIR9     = 79;
  121. const int FOLLOWER_DIR10    = 80;
  122. const int FOLLOWER_DIR11    = 81;
  123. const int FOLLOWER_DIR12    = 82;
  124. const int FOLLOWER_DIR13    = 83;
  125. const int FOLLOWER_DIR14    = 84;
  126. const int FOLLOWER_DIR15    = 85;
  127. const int FOLLOWER_DIR16    = 86;
  128. const int FOLLOWER_DIR17    = 87;
  129. const int FOLLOWER_DIR18    = 88;
  130. const int FOLLOWER_DIR19    = 89;
  131. const int FOLLOWER_DIR20    = 90;
  132.  
  133. ffc script GetZelda
  134. {
  135.     void run(int sfx, int msg)
  136.     {
  137.         ffc f = Screen->LoadFFC(this->Link);
  138.         while(1)
  139.         {
  140.             if ( Collision(this) && Follower[FOLLOWER_RESCUED] < 0)
  141.             {
  142.                 //f->Data = 0;
  143.                 Follower[FOLLOWER_RESCUED] = 2;
  144.                 Game->PlaySound(sfx);
  145.                 Follower[FOLLOWER_BASE_TILE] = Game->ComboTile(f->Data)-4;
  146.                 if ( msg ) Screen->Message(msg);
  147.                
  148.                 //break;//Quit();
  149.             }
  150.             if ( Follower[FOLLOWER_ACTIVE] > 15 )
  151.             {
  152.                 f->Data = 0;
  153.             }
  154.             Waitframe();
  155.         }
  156.     }
  157. }
  158.  
  159. global script the_follower
  160. {
  161.     void run()
  162.     {
  163.         FollowerContinue();
  164.         while(1)
  165.         {
  166.             RescueZelda(FOLLOWER_ZELDA_MIDI, FOLLOWER_ZELDA_MIDI_DURATION);
  167.             DrawFollower();
  168.             FollowerScroll();
  169.             Waitdraw();
  170.             Waitframe();
  171.         }
  172.     }
  173. }
  174.  
  175. void RescueZelda(int follower_midi, int dur)
  176. {
  177.     if ( Follower[FOLLOWER_RESCUED] < 2 ) return;
  178.    
  179.     --Follower[FOLLOWER_RESCUED];
  180.     if ( !dur ) dur = FOLLOWER_ZELDA_MIDI_DURATION;
  181.     if ( !follower_midi ) follower_midi = FOLLOWER_ZELDA_MIDI;
  182.     Follower[FOLLOWER_ACTIVE] = 1;
  183.     if ( Follower[FOLLOWER_MIDI_TIMER] == -1 )
  184.     {
  185.        
  186.         Follower[FOLLOWER_ORIG_MIDI] = Game->DMapMIDI[Game->GetCurDMap()];
  187.         Follower[FOLLOWER_MIDI_TIMER] = dur;
  188.         Game->PlayMIDI(follower_midi);
  189.     }
  190.     else
  191.     {
  192.         --Follower[FOLLOWER_MIDI_TIMER];
  193.         if ( Follower[FOLLOWER_MIDI_TIMER] < 1 )
  194.         {
  195.             Game->PlayMIDI(Follower[FOLLOWER_ORIG_MIDI]);
  196.             Follower[FOLLOWER_MIDI_TIMER] = 0;
  197.         }
  198.     }
  199.  
  200. }  
  201.  
  202. bool PressedDPad()
  203. {
  204.     if ( Link->InputUp ) return true;
  205.     if ( Link->InputDown ) return true;
  206.     if ( Link->InputLeft ) return true;
  207.     if ( Link->InputRight ) return true;
  208.     if ( Link->PressUp ) return true;
  209.     if ( Link->PressDown ) return true;
  210.     if ( Link->PressLeft ) return true;
  211.     if ( Link->PressRight ) return true;
  212.     return false;
  213. }
  214.  
  215. //Zelda follows in Link's path with an 8 frame delay before updating
  216. void DrawFollower()
  217. {
  218.     if ( !Follower[FOLLOWER_ACTIVE] ) return;
  219.     if ( PressedDPad() )
  220.     {
  221.         ++Follower[FOLLOWER_ACTIVE];
  222.         if ( Follower[FOLLOWER_ACTIVE] > 100000 ) Follower[FOLLOWER_ACTIVE] = 8; //Don't roll over
  223.        
  224.     }
  225.    
  226.    
  227.        
  228.     if ( Link->Action == LA_GOTHURTLAND ) return; //Don't update if Link was hurt and pushed back.
  229.  
  230.     if ( PressedDPad() )
  231.     {
  232.         ++Follower[FOLLOWER_SUBFRAME];
  233.         if ( Follower[FOLLOWER_SUBFRAME]&1 )
  234.         {
  235.             ++Follower[FOLLOWER_FRAME];
  236.             if ( Follower[FOLLOWER_FRAME] > FOLLOWER_MAX_FRAME ) Follower[FOLLOWER_FRAME] = 0;
  237.         }
  238.        
  239.         Follower[FOLLOWER_X] = Link->X;
  240.         Follower[FOLLOWER_Y] = Link->Y;
  241.         Follower[FOLLOWER_DIR] = Link->Dir;
  242.         for ( int q = FOLLOWER_X12; q >= FOLLOWER_X; --q )
  243.         {
  244.             Follower[q] = Follower[q-1];
  245.         }
  246.         for ( int q = FOLLOWER_Y12; q >= FOLLOWER_Y; --q )
  247.         {
  248.             Follower[q] = Follower[q-1];
  249.         }
  250.         for ( int q = FOLLOWER_DIR12; q >= FOLLOWER_DIR; --q )
  251.         {
  252.             Follower[q] = Follower[q-1];
  253.         }
  254.    
  255.     }
  256.     if ( Follower[FOLLOWER_ACTIVE] < 16 ) return; //Wait 8 frames to begin.
  257.     //Draw tiles
  258.     int the_tile;
  259.      
  260.     the_tile = Follower[FOLLOWER_BASE_TILE] + (Follower[FOLLOWER_DIR12]*4) + Follower[FOLLOWER_FRAME];
  261.     //Based on X, Y, Dir and Frame
  262.     Screen->FastTile(2, Follower[FOLLOWER_X12], Follower[FOLLOWER_Y12],
  263.                 the_tile, FOLLOWER_CSET, 128 );
  264.    
  265.    
  266.     //...then Update the frame
  267.    
  268.    
  269.    
  270. }
  271.  
  272. void LeaveZeldabehind(ffc follower)
  273. {
  274.     Follower[FOLLOWER_ACTIVE] = 0;
  275. }
  276.  
  277.  
  278. const int FOLLOWER_REGISTER = 1;
  279. const int FOLLOWER_SHOWED_MESSAGE = 10b;
  280. const int FOLLOWER_GAVE_ITEM = 1b;
  281. ffc script SanctuaryZelda
  282. {
  283.     void run(int msg, int itm)
  284.     {
  285.         this->Data = CMB_INVISIBLE;
  286.         //bool matched = false;
  287.         //if ( Follower[FOLLOWER_ACTIVE] ) this->Data = CMB_INVISIBLE;
  288.         if ( Follower[FOLLOWER_ACTIVE] ) Follower[FOLLOWER_ACTIVE] = 0;
  289.         //else ;
  290.         int the_tile; bool playedmsg = false;
  291.        
  292.         while ( 1 ) //Follower[FOLLOWER_X12] != this->X && Follower[FOLLOWER_Y12] != this->Y )
  293.         {
  294.             if ( Follower[FOLLOWER_X12] < this->X ) { ++Follower[FOLLOWER_X12]; Follower[FOLLOWER_DIR12] = DIR_RIGHT; }
  295.             if ( Follower[FOLLOWER_X12] > this->X ) { --Follower[FOLLOWER_X12]; Follower[FOLLOWER_DIR12] = DIR_LEFT; }
  296.            
  297.             if ( Follower[FOLLOWER_Y12] < this->Y ) { ++Follower[FOLLOWER_Y12]; Follower[FOLLOWER_DIR12] = DIR_DOWN; }
  298.             if ( Follower[FOLLOWER_Y12] > this->Y ) { --Follower[FOLLOWER_Y12]; Follower[FOLLOWER_DIR12] = DIR_UP; }
  299.             ++Follower[FOLLOWER_FRAME];
  300.             if ( Follower[FOLLOWER_FRAME] > FOLLOWER_MAX_FRAME ) Follower[FOLLOWER_FRAME] = 0;
  301.             the_tile = Follower[FOLLOWER_BASE_TILE] + (Follower[FOLLOWER_DIR12]*4) + Follower[FOLLOWER_FRAME];
  302.             if ( Follower[FOLLOWER_X12] == this->X && Follower[FOLLOWER_Y12] == this->Y ) { Follower[FOLLOWER_DIR12] = DIR_DOWN; Follower[FOLLOWER_FRAME] = 0; }
  303.             WatiframesDrawZelda(2,Follower[FOLLOWER_X12],Follower[FOLLOWER_Y12],the_tile);
  304.             if ( Follower[FOLLOWER_X12] == this->X )
  305.             {
  306.                 if ( Follower[FOLLOWER_Y12] == this->Y )
  307.                 {
  308.                     if ( msg )
  309.                     {
  310.                         if ( !(Screen->D[FOLLOWER_REGISTER]&FOLLOWER_SHOWED_MESSAGE) )
  311.                         {
  312.                            
  313.                            
  314.                             Screen->D[FOLLOWER_REGISTER] |= FOLLOWER_SHOWED_MESSAGE;
  315.                             Screen->Message(msg);
  316.                         }
  317.                     }
  318.                     if ( itm )
  319.                     {
  320.                         if ( !(Screen->D[FOLLOWER_REGISTER]&FOLLOWER_GAVE_ITEM) )
  321.                         {
  322.                            
  323.                            
  324.                             Screen->D[FOLLOWER_REGISTER] |= FOLLOWER_GAVE_ITEM;
  325.                             item giveit = Screen->CreateItem(itm);
  326.                             giveit->X = Link->X;
  327.                             giveit->Y = Link->Y;
  328.                             giveit->Pickup = IP_HOLDUP;
  329.                            
  330.                         }
  331.                     }
  332.                 }
  333.             }
  334.         }
  335.        
  336.     }
  337.     void WatiframesDrawZelda(int num, int x, int y, int til)
  338.     {
  339.         for (; num >= 0; --num)
  340.         {
  341.             Screen->FastTile(2, x, y, til, FOLLOWER_CSET, 128 );
  342.             Waitframe();
  343.         }
  344.     }
  345. }
  346.  
  347. global script FollowerResume
  348. {
  349.     void run()
  350.     {
  351.         //int ss[]="Running onContinue";
  352.         //TraceS(ss);
  353.         FollowerContinue();
  354.     }
  355. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement