Advertisement
ZoriaRPG

Old Barriers Script, Cleanup, v2 (for Nightmere)

Feb 2nd, 2018
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 10.13 KB | None | 0 0
  1. const int CMB_FFC_INVIS = 1; //Combo higher than ID 0 with an invisible tile.
  2.  
  3. // ID's of barrier-related combos
  4. // Barriers in raised state
  5. const int BARRIER_A_RAISED           = 15036;
  6. const int BARRIER_B_RAISED           = 15038;
  7.  
  8. // Barriers in lowered state
  9. const int BARRIER_A_LOWERED          = 15037;
  10. const int BARRIER_B_LOWERED          = 15039;
  11.  
  12. // Barriers animating to raised state
  13. const int BARRIER_A_ANIMRAISE        = 15041;
  14. const int BARRIER_B_ANIMRAISE        = 15043;
  15.  
  16. // Barriers animating to lowered state
  17. const int BARRIER_A_ANIMLOWER        = 15040;
  18. const int BARRIER_B_ANIMLOWER        = 15042;
  19.  
  20. // Raised barriers that Link can walk on
  21. const int BARRIER_A_WALKABLE         = 15044;
  22. const int BARRIER_B_WALKABLE         = 15045;
  23.  
  24. // Barrier switches
  25. const int BARRIER_A_SWITCH           = 15046;
  26. const int BARRIER_B_SWITCH           = 15047;
  27.  
  28. const int BARRIER_SWITCH_DUMMY = 191; // ID of a switch hit detection dummy enemy
  29. const int BARRIER_SWITCH_DUMMY_HP = 32767;
  30.  
  31. // Global array to store the state of barriers per dmap
  32. // If you have more than 16 dmaps you can change the capacity in the []'s
  33. // You may change the states in other scripts, but the changes will not be visible
  34. // until there is a new screen, so set them before Barriers_NewScreen() is called.
  35. bool barriers[255]; // false = blue barriers raised, true = red barriers raised
  36.  
  37.  
  38. const int ffcNumber = 32; //The number of the FFC used.  This script will "hijack" this one, so don't use it for anything else on screens when you expect the player to have a follower.
  39. const int firstFollowerCombo = 23568; //combo of the first combo.  In order, the concecutive combos must be "still up", "still down", "still left", "still right", "moving up", "moving down", "moving left", "moving right".
  40. const int csetOfFollower = 11;
  41. const int reqItem = 158; //Item that makes the FFC follower follow you
  42. const int BAR_PASTX = 14;
  43. const int BAR_PASTY = 14;
  44.    
  45. global script slot2
  46. {
  47.     void run()
  48.     {
  49.     // Initialize variables used to listen on screen changes
  50.         int curscreen = -1;
  51.         bool firstCheck = false; //leave this alone
  52.         ffc follower;
  53.    
  54.         int followerX[15];
  55.         int followerY[15];
  56.  
  57.         int switch_index;
  58.  
  59.         while (true)
  60.         {
  61.             _Do_Barriers();
  62.             _Follower();
  63.                
  64.  
  65.            
  66.             Waitdraw();
  67.             Waitframe();
  68.         }
  69.     }
  70. }
  71.  
  72.  
  73. // Function that makes preparations for barriers on each screen and starts an FFC script
  74. void Barriers_NewScreen()
  75. {
  76.     int cd; int cd2; int i; int j;
  77.     // Search for a barrier-related combo
  78.     for (i = 0; i <= 175; ++i)
  79.     {
  80.         cd = Screen->ComboD[i];
  81.         if (cd == BARRIER_A_RAISED || cd == BARRIER_A_LOWERED || cd == BARRIER_A_SWITCH ||
  82.             cd == BARRIER_B_RAISED || cd == BARRIER_B_LOWERED || cd == BARRIER_B_SWITCH)
  83.         {
  84.             // A barrier-related combo was found
  85.  
  86.             // Make initial changes to combos
  87.             if (barriers[Game->GetCurLevel()])
  88.             {
  89.                 for (j = i; j <= 175; ++j)
  90.                 {
  91.                     cd2 = Screen->ComboD[j];
  92.                     if (cd2 == BARRIER_A_RAISED) Screen->ComboD[j] = BARRIER_A_LOWERED;
  93.                     else if (cd2 == BARRIER_B_LOWERED) Screen->ComboD[j] = BARRIER_B_RAISED;
  94.                     else if (cd2 == BARRIER_A_SWITCH) Screen->ComboD[j] = BARRIER_B_SWITCH;
  95.                 }
  96.             }
  97.             else
  98.             {
  99.                 for (j = i; j <= 175; ++j)
  100.                 {
  101.                     cd2 = Screen->ComboD[j];
  102.                     if (cd2 == BARRIER_B_RAISED) Screen->ComboD[j] = BARRIER_B_LOWERED;
  103.                     else if (cd2 == BARRIER_A_LOWERED) Screen->ComboD[j] = BARRIER_A_RAISED;
  104.                     else if (cd2 == BARRIER_B_SWITCH) Screen->ComboD[j] = BARRIER_A_SWITCH;
  105.                 }
  106.             }
  107.    
  108.             // So run FFCscript to control barriers
  109.             int fif[]="Barriers";
  110.             ffc f = Screen->LoadFFC(ffcNumber);
  111.             f->Script = Game->GetFFCScript(fif);
  112.             f->Data = CMB_FFC_INVIS;
  113.             f->X = -100;
  114.             f->Y = -100;
  115.             f->Flags[FFCF_PRELOAD] = true;
  116.             break;
  117.         }
  118.     }
  119. }
  120.  
  121. // This lets you toggle barriers on any dmap
  122. bool ToggleBarriers(int dmap)
  123. {
  124.     if (dmap == Game->GetCurLevel()) ToggleBarriers();
  125.     else barriers[dmap] = !barriers[dmap];
  126.     return barriers[dmap];
  127. }
  128.  
  129. // This toggles barriers on the current dmap
  130. bool ToggleBarriers()
  131. {
  132.     int cd;
  133.     int curdmap = Game->GetCurLevel();
  134.     if (!barriers[curdmap])
  135.     {
  136.         barriers[curdmap] = true;
  137.         for (int i = 0; i <= 175; ++i)
  138.         {
  139.             cd = Screen->ComboD[i];
  140.             if (cd == BARRIER_A_RAISED || cd == BARRIER_A_WALKABLE || cd == BARRIER_A_ANIMRAISE)
  141.             {
  142.                 Screen->ComboD[i] = BARRIER_A_ANIMLOWER;
  143.             }
  144.             else if (cd == BARRIER_B_LOWERED || cd == BARRIER_B_ANIMLOWER)
  145.             {
  146.                 Screen->ComboD[i] = BARRIER_B_ANIMRAISE;
  147.             }
  148.             else if (cd == BARRIER_A_SWITCH)
  149.             {
  150.                 Screen->ComboD[i] = BARRIER_B_SWITCH;
  151.             }
  152.         }
  153.     }
  154.     else
  155.     {
  156.         barriers[curdmap] = false;
  157.         for (int i = 0; i <= 175; ++i)
  158.         {
  159.             cd = Screen->ComboD[i];
  160.             if (cd == BARRIER_B_RAISED || cd == BARRIER_B_WALKABLE || cd == BARRIER_B_ANIMRAISE) #
  161.             {
  162.                 Screen->ComboD[i] = BARRIER_B_ANIMLOWER;
  163.             }
  164.             else if (cd == BARRIER_A_LOWERED || cd == BARRIER_A_ANIMLOWER)
  165.             {
  166.                 Screen->ComboD[i] = BARRIER_A_ANIMRAISE;
  167.             }
  168.             else if (cd == BARRIER_B_SWITCH)
  169.             {
  170.                 Screen->ComboD[i] = BARRIER_A_SWITCH;
  171.             }
  172.         }
  173.     }
  174.  
  175.     return barriers[curdmap];
  176. }
  177.  
  178. // This script controls barriers on the screen
  179. // The FFC is automatically created by Barriers_NewScreen()
  180. ffc script Barriers
  181. {
  182.     void run()
  183.     {
  184.  
  185.         // Initialize storage for bswitch hit dummies
  186.         int bswitch_count;
  187.         npc bswitch[8]; int i; int j;
  188.  
  189.         for (i = 0; i <= 175; ++i)
  190.         {
  191.             if (Screen->ComboD[i] == BARRIER_A_SWITCH || Screen->ComboD[i] == BARRIER_B_SWITCH)
  192.             {
  193.                 npc bs = CreateNPCAt(BARRIER_SWITCH_DUMMY, ComboX(i), ComboY(i));
  194.                 bs->HitWidth = 8; // Smaller hit box to avoid annoying collisions with Link
  195.                 bs->HitHeight = 8;
  196.                 bs->HP = BARRIER_SWITCH_DUMMY_HP;
  197.                 bswitch[bswitch_count++] = bs;
  198.             }
  199.         }
  200.  
  201.         // Change raised barriers to walkable ones if Link enters screen on a raised barrier
  202.         int lcombo = LinkOnComboD();
  203.         bool onbarrier = (lcombo == BARRIER_A_RAISED || lcombo == BARRIER_B_RAISED);
  204.         if (onbarrier)
  205.         {
  206.             for (i = 0; i < 176; ++i)
  207.             {
  208.                 if (Screen->ComboD[i] == BARRIER_A_RAISED)
  209.                 {
  210.                     Screen->ComboD[i] = BARRIER_A_WALKABLE;
  211.                 }
  212.                 else if (Screen->ComboD[i] == BARRIER_B_RAISED)
  213.                 {
  214.                     Screen->ComboD[i] = BARRIER_B_WALKABLE;
  215.                 }
  216.             }
  217.         }
  218.  
  219.  
  220.         while (true)
  221.         {
  222.  
  223.             // Detect hits on bswitches, and change combos accordingly
  224.             for (j = 0; j < bswitch_count; ++j)
  225.             {
  226.                 if (bswitch[j]->HP < BARRIER_SWITCH_DUMMY_HP)
  227.                 {
  228.                     bswitch[j]->HP = BARRIER_SWITCH_DUMMY_HP;
  229.                     ToggleBarriers();
  230.                     break; //break so that only one bswitch hit may register per frame
  231.                 }
  232.             }
  233.  
  234.  
  235.             // Make barriers walkable if Link is on raised barriers, or unwalkable if not
  236.             lcombo = LinkOnComboD();
  237.             if (!onbarrier && (lcombo == BARRIER_A_RAISED || lcombo == BARRIER_B_RAISED))
  238.             {
  239.                 onbarrier = true;
  240.                 for (i = 0; i <= 175; ++i)
  241.                 {
  242.                     if (Screen->ComboD[i] == BARRIER_A_RAISED)
  243.                     {
  244.                         Screen->ComboD[i] = BARRIER_A_WALKABLE;
  245.                     }
  246.                     else if (Screen->ComboD[i] == BARRIER_B_RAISED)
  247.                     {
  248.                         Screen->ComboD[i] = BARRIER_B_WALKABLE;
  249.                     }
  250.                 }
  251.             }
  252.             else if (onbarrier && !(lcombo == BARRIER_A_WALKABLE || lcombo == BARRIER_B_WALKABLE))
  253.             {
  254.                 onbarrier = false;
  255.                 for (i = 0; i <= 175; ++i)
  256.                 {
  257.                     if (Screen->ComboD[i] == BARRIER_A_WALKABLE)
  258.                     {
  259.                         Screen->ComboD[i] = BARRIER_A_RAISED;
  260.                     }
  261.                     else if (Screen->ComboD[i] == BARRIER_B_WALKABLE)
  262.                     {
  263.                         Screen->ComboD[i] = BARRIER_B_RAISED;
  264.                     }
  265.                 }
  266.             }
  267.  
  268.             Waitframe();
  269.         }
  270.     }
  271. }
  272.  
  273.  
  274.  
  275. // A utility function that returns the ID of the combo that Link appears to stand on
  276. int LinkOnComboD() {
  277.     return Screen->ComboD[ComboAt(Link->X+8, Link->Y+13)];
  278. }
  279.  
  280. void _Follower()
  281. {
  282.     if(Link->Item[reqItem])
  283.     {
  284.         if(Link->Action != LA_SCROLLING && follower->Data==0)
  285.         {
  286.             follower = Screen->LoadFFC(ffcNumber);
  287.             follower->Data = firstFollowerCombo;
  288.             follower->CSet = csetOfFollower;
  289.  
  290.             followerX[BAR_PASTX] = Link->X;
  291.             follower->X = Link->X;
  292.             followerY[BAR_PASTY] = Link->Y;
  293.             follower->Y = Link->Y;
  294.  
  295.             for ( int i = 0; i < 13; i++ )
  296.             {
  297.                 followerX[i] = Link->X;
  298.                 followerY[i] = Link->Y;
  299.             }
  300.  
  301.             firstCheck = true;
  302.         }
  303.         if(Link->Action != LA_SCROLLING)
  304.         {
  305.             if((Link->InputUp || Link->InputDown || Link->InputRight || Link->InputLeft)&&(!(Link->InputA || Link->InputB)))
  306.             {
  307.                 followerX[BAR_PASTX] = follower->X;
  308.                 follower->X = followerX[0];
  309.                 for(switch_index=0; switch_index<12; switch_index++)
  310.                 {
  311.                     followerX[switch_index] = followerX[switch_index + 1];
  312.                 }
  313.                 followerX[12] = Link->X;
  314.  
  315.                 followerY[BAR_PASTY] = follower->Y;
  316.                 follower->Y = followerY[0];
  317.                 for(switch_index=0; switch_index<12; switch_index++)
  318.                 {
  319.                     followerY[switch_index] = followerY[switch_index + 1];
  320.                 }
  321.                 followerY[12] = Link->Y;
  322.             }
  323.  
  324.             if(follower->Y > followerY[BAR_PASTY])
  325.             {
  326.                 follower->Data = firstFollowerCombo + 5;
  327.             }
  328.             else if(follower->Y < followerY[BAR_PASTY])
  329.             {
  330.                 follower->Data = firstFollowerCombo + 4;
  331.             }
  332.             else if(follower->X > followerX[BAR_PASTX])
  333.             {
  334.                 follower->Data = firstFollowerCombo + 7;
  335.             }
  336.             else if(follower->X < followerX[BAR_PASTX])
  337.             {
  338.                 follower->Data = firstFollowerCombo + 6;
  339.             }
  340.  
  341.             if(!(Link->InputUp || Link->InputDown || Link->InputRight || Link->InputLeft))
  342.             {
  343.                 if((follower->Data == (firstFollowerCombo + 4))||(follower->Data == (firstFollowerCombo + 5))||(follower->Data == (firstFollowerCombo + 6))||(follower->Data == (firstFollowerCombo + 7)))
  344.                 {
  345.                     follower->Data = follower->Data - 4;
  346.                 }
  347.                 else if((follower->Data == (firstFollowerCombo + 3))||(follower->Data == (firstFollowerCombo + 2))||(follower->Data == (firstFollowerCombo + 1))||(follower->Data == (firstFollowerCombo)))
  348.                 {
  349.                     //empty else if ??? -Z
  350.                 }
  351.                 else
  352.                 {
  353.                     follower->Data = firstFollowerCombo;
  354.                 }
  355.             }
  356.         }
  357.         if(Link->Action == LA_SCROLLING)
  358.         {
  359.             firstCheck = false;
  360.         }
  361.     }
  362. }
  363.  
  364. void _Do_Barriers()
  365. {
  366.     // Keep track of screen changes
  367.     // Run a Barrier script on every screen change
  368.     if (Game->GetCurScreen() != curscreen)
  369.     {
  370.         curscreen = Game->GetCurScreen();
  371.         Barriers_NewScreen();
  372.     }
  373. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement