Advertisement
ZoriaRPG

ZScript: Fully Scripted Lockblocks

Nov 24th, 2016
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.75 KB | None | 0 0
  1. ////////////////////////////
  2. /// Scripted Lock Blocks ///
  3. /// v0.3 - 25-Nov-2016   ///
  4. /// By: ZoriaRPG         ///
  5. ////////////////////////////
  6.  
  7. //Main Settings
  8.  
  9. const int USE_CUSTOM_KEYS = 1; //If se to '1', the script will require a custom key type, tied to
  10.             //a script counter, configured below.
  11.  
  12. //User Settings
  13. const int CBM_LOCKBLOCK2 = 888; //The combo used by the special lockblock.
  14.  
  15. const int TIMER_WALK_UNLOCK = 50; //The number of frames that Link must push against the lockblock to open it.
  16. const int CR_LOCKBLOCKKEY = 7; //Script 1
  17. const int SFX_SPEC_LOCKBLOCK = 9; //The sound to play when unlocking a lockblock.
  18. const int CR_MAX_LOCKBLOCKKEY = 32; //The maximum number of special keys that Link may have. Used only with the item script.
  19.  
  20. const int SCREEN_D_SPECIALLOCKBLOCK = 7;
  21.  
  22. //In the event that you want to know how to script a key, too.
  23. item script SpecialLockBlockKey{
  24.     void run(){
  25.         if ( Game->MCounter[CR_LOCKBLOCKKEY] < CR_MAX_LOCKBLOCKKEY ) Game->MCounter[CR_LOCKBLOCKKEY] = CR_MAX_LOCKBLOCKKEY;
  26.         Game->Counter[CR_LOCKBLOCKKEY]++;
  27.     }
  28. }
  29.  
  30.  
  31. //Flags for up to four lock blocks.
  32. const int SPC_LOCK_1 = 0001b;
  33. const int SPC_LOCK_2 = 0010b;
  34. const int SPC_LOCK_3 = 0100b;
  35. const int SPC_LOCK_4 = 1000b;
  36.  
  37. ffc script SpecialLockBlock{
  38.     void run(int block){
  39.         int cmb;
  40.         int timer = TIMER_WALK_UNLOCK;
  41.         if ( Screen->D[SCREEN_D_SPECIALLOCKBLOCK] ) {
  42.             for ( int q = 0; q < 176; q++ ) {
  43.                 if ( LockBlockFlag(SPC_LOCK_1) && Screen->ComboD[q] == CBM_LOCKBLOCK2 ) Screen->ComboD[q]++;
  44.                 if ( LockBlockFlag(SPC_LOCK_2) && Screen->ComboD[q] == CBM_LOCKBLOCK2 + 2 ) Screen->ComboD[q]++;
  45.                 if ( LockBlockFlag(SPC_LOCK_3) && Screen->ComboD[q] == CBM_LOCKBLOCK2 + 4 ) Screen->ComboD[q]++;
  46.                 if ( LockBlockFlag(SPC_LOCK_4) && Screen->ComboD[q] == CBM_LOCKBLOCK2 + 6 ) Screen->ComboD[q]++;
  47.             }          
  48.         }
  49.         while ( true ) {
  50.            
  51.             if (
  52.                 ( !USE_CUSTOM_KEYS && ( Game->Counter[CR_KEYS] || Game->LKeys[Game->GetCurLevel()] ) ) ||
  53.                 ( USE_CUSTOM_KEYS && Game->Counter[CR_LOCKBLOCKKEY] ) )
  54.             {
  55.                 if ( Link->Dir == DIR_UP ){
  56.                     cmb = Screen->ComboD[ ___AdjacentCombo(ComboAt(Link->X+8, Link->Y+8),1) ];
  57.                    
  58.                     if ( cmb == CBM_LOCKBLOCK2 || cmb == CBM_LOCKBLOCK2 +2 || cmb == CBM_LOCKBLOCK2 + 4 || cmb == CBM_LOCKBLOCK2 +6 ) {
  59.                         if ( timer && Link->InputUp ) timer--;
  60.                         if ( timer <= 0 ) {
  61.                             Game->Counter[CR_LOCKBLOCKKEY]--;
  62.                             if ( SFX_SPEC_LOCKBLOCK ) Game->PlaySound(SFX_SPEC_LOCKBLOCK);
  63.                             Screen->ComboD[ ___AdjacentCombo(ComboAt(Link->X+8, Link->Y+8),1) ]++;
  64.                             if ( cmb == CBM_LOCKBLOCK2 ) {
  65.                                 LockBlockFlag(SPC_LOCK_1,true);
  66.                             }
  67.                             if ( cmb == CBM_LOCKBLOCK2 + 2 ) {
  68.                                 LockBlockFlag(SPC_LOCK_2,true);
  69.                             }
  70.                             if ( cmb == CBM_LOCKBLOCK2 + 4 ) {
  71.                                 LockBlockFlag(SPC_LOCK_3,true);
  72.                             }
  73.                             if ( cmb == CBM_LOCKBLOCK2 + 6 ) {
  74.                                 LockBlockFlag(SPC_LOCK_4,true);
  75.                             }
  76.                             timer = TIMER_WALK_UNLOCK;
  77.                             Link->InputUp = false;
  78.                         }
  79.                     }
  80.                     else timer = TIMER_WALK_UNLOCK;
  81.                 }
  82.                 else if ( Link->Dir == DIR_DOWN ){
  83.                     cmb = Screen->ComboD[ ___AdjacentCombo(ComboAt(Link->X+8, Link->Y+8),5) ];
  84.                    
  85.                     if ( cmb == CBM_LOCKBLOCK2 || cmb == CBM_LOCKBLOCK2 +2 || cmb == CBM_LOCKBLOCK2 + 4 || cmb == CBM_LOCKBLOCK2 +6 ) {
  86.                         if ( timer > 0 && Link->InputDown ) timer--;
  87.                         if ( timer <= 0 ) {
  88.                             Game->Counter[CR_LOCKBLOCKKEY]--;
  89.                             if ( SFX_SPEC_LOCKBLOCK ) Game->PlaySound(SFX_SPEC_LOCKBLOCK);
  90.                             Screen->ComboD[ ___AdjacentCombo(ComboAt(Link->X+8, Link->Y+8),5) ]++;
  91.                             if ( cmb == CBM_LOCKBLOCK2 ) {
  92.                                 LockBlockFlag(SPC_LOCK_1,true);
  93.                             }
  94.                             if ( cmb == CBM_LOCKBLOCK2 + 2 ) {
  95.                                 LockBlockFlag(SPC_LOCK_2,true);
  96.                             }
  97.                             if ( cmb == CBM_LOCKBLOCK2 + 4 ) {
  98.                                 LockBlockFlag(SPC_LOCK_3,true);
  99.                             }
  100.                             if ( cmb == CBM_LOCKBLOCK2 + 6 ) {
  101.                                 LockBlockFlag(SPC_LOCK_4,true);
  102.                             }
  103.                             timer = TIMER_WALK_UNLOCK;
  104.                             Link->InputDown = false;
  105.                         }
  106.                     }
  107.                     else timer = TIMER_WALK_UNLOCK;
  108.                 }
  109.                 else if ( Link->Dir == DIR_LEFT ) {
  110.                     cmb = Screen->ComboD[ ___AdjacentCombo(ComboAt(Link->X+8, Link->Y+8),7) ];
  111.                     if ( cmb == CBM_LOCKBLOCK2 || cmb == CBM_LOCKBLOCK2 +2 || cmb == CBM_LOCKBLOCK2 + 4 || cmb == CBM_LOCKBLOCK2 +6 ) {
  112.                         if ( timer > 0 && Link->InputLeft ) timer--;
  113.                         if ( timer <= 0 ) {
  114.                             Game->Counter[CR_LOCKBLOCKKEY]--;
  115.                             if ( SFX_SPEC_LOCKBLOCK ) Game->PlaySound(SFX_SPEC_LOCKBLOCK);
  116.                             Screen->ComboD[ ___AdjacentCombo(ComboAt(Link->X+8, Link->Y+8),7) ]++;
  117.                             if ( cmb == CBM_LOCKBLOCK2 ) {
  118.                                 LockBlockFlag(SPC_LOCK_1,true);
  119.                             }
  120.                             if ( cmb == CBM_LOCKBLOCK2 + 2 ) {
  121.                                 LockBlockFlag(SPC_LOCK_2,true);
  122.                             }
  123.                             if ( cmb == CBM_LOCKBLOCK2 + 4 ) {
  124.                                 LockBlockFlag(SPC_LOCK_3,true);
  125.                             }
  126.                             if ( cmb == CBM_LOCKBLOCK2 + 6 ) {
  127.                                 LockBlockFlag(SPC_LOCK_4,true);
  128.                             }
  129.                             timer = TIMER_WALK_UNLOCK;
  130.                             Link->InputLeft = false;
  131.                         }
  132.                     }
  133.                     else timer = TIMER_WALK_UNLOCK;
  134.                 }
  135.                 else if ( Link->Dir == DIR_RIGHT ) {
  136.                     cmb = Screen->ComboD[ ___AdjacentCombo(ComboAt(Link->X+8, Link->Y+8),3)];
  137.                     if ( cmb == CBM_LOCKBLOCK2 || cmb == CBM_LOCKBLOCK2 +2 || cmb == CBM_LOCKBLOCK2 + 4 || cmb == CBM_LOCKBLOCK2 +6 ) {
  138.                         if ( timer > 0 && Link->InputRight ) timer--;
  139.                         if ( timer <= 0 ) {
  140.                             Game->Counter[CR_LOCKBLOCKKEY]--;
  141.                             if ( SFX_SPEC_LOCKBLOCK ) Game->PlaySound(SFX_SPEC_LOCKBLOCK);
  142.                             Screen->ComboD[ ___AdjacentCombo(ComboAt(Link->X+8, Link->Y+8),3) ]++;
  143.                             if ( cmb == CBM_LOCKBLOCK2 ) {
  144.                                 LockBlockFlag(SPC_LOCK_1,true);
  145.                             }
  146.                             if ( cmb == CBM_LOCKBLOCK2 + 2 ) {
  147.                                 LockBlockFlag(SPC_LOCK_2,true);
  148.                             }
  149.                             if ( cmb == CBM_LOCKBLOCK2 + 4 ) {
  150.                                 LockBlockFlag(SPC_LOCK_3,true);
  151.                             }
  152.                             if ( cmb == CBM_LOCKBLOCK2 + 6 ) {
  153.                                 LockBlockFlag(SPC_LOCK_4,true);
  154.                             }
  155.                             timer = TIMER_WALK_UNLOCK;
  156.                             Link->InputRight = false;
  157.                         }
  158.                     }
  159.                     else timer = TIMER_WALK_UNLOCK;
  160.                    
  161.                 }
  162.                
  163.             }
  164.             else timer = TIMER_WALK_UNLOCK;
  165.             Waitframe();
  166.         }
  167.     }
  168.  
  169.     void LockBlockFlag(int flag, bool state){
  170.         if(state) Screen->D[SCREEN_D_SPECIALLOCKBLOCK] |= flag;
  171.         else Screen->D[SCREEN_D_SPECIALLOCKBLOCK] &= ~flag;
  172.     }
  173.  
  174.     bool LockBlockFlag(int flag){
  175.         return (Screen->D[SCREEN_D_SPECIALLOCKBLOCK]&flag) != 0;
  176.     }
  177.  
  178.     //Constants for AdjacentCombo()
  179.  
  180.     //const int CMB_UPLEFT    = 0;
  181.     //const int CMB_UP        = 1;
  182.     //const int CMB_UPRIGHT   = 2;
  183.     //const int CMB_RIGHT     = 3;
  184.     //const int CMB_DOWNRIGHT = 4;
  185.     //const int CMB_DOWN      = 5;
  186.     //const int CMB_DOWNLEFT  = 6;
  187.     //const int CMB_LEFT      = 7;
  188.     //const int CMB_LEFTUP    = 0; //Not 8, as those are dir + shield
  189.  
  190.     //Returns the Nuth combo index of a combo based on a central point, and a direction.
  191.     //For example, combo 22 + COMBO_UPRIGHT returns '7',
  192.     //as combo 7 is to the upper-right of combo 22.
  193.     int ___AdjacentCombo(int cmb, int dir){
  194.         int combooffsets[13]={-0x11,-0x10,-0x0F,1,0x11,0x10,0x0F,-1,-0x10};
  195.         if ( cmb % 16 == 0 ) combooffsets[9] = 1;
  196.         if ( (cmb & 15) == 1 ) combooffsets[10] = 1;
  197.         if ( cmb < 0x10 ) combooffsets[11] = 1; //if it's the top row
  198.         if ( cmb > 0xAF ) combooffsets[12] = 1; //if it's on the bottom row
  199.         if ( combooffsets[9] && ( dir == 7 || dir == 1 || dir == 4 || dir == 0 ) ) return 0; //if the left columb
  200.         if ( combooffsets[10] && ( dir == 3 || dir == 2 || dir == 4 ) ) return 0; //if the right column
  201.         if ( combooffsets[11] && ( dir == 2 || dir == 2 || dir == 1 ) ) return 0; //if the top row
  202.         if ( combooffsets[12] && ( dir == 5 || dir == 4 || dir == 6 ) ) return 0; //if the bottom row
  203.         else if ( cmb >= 0 && cmb <= 176 ) return cmb + combooffsets[dir];
  204.         else return -1;
  205.     }
  206. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement