ZoriaRPG

Streamlined: Tamamo's HoleLava and Platforms

Nov 20th, 2016
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.38 KB | None | 0 0
  1. /// Tamamo's Holes, Lava, and Platforms
  2. /// Combined together for ease of use, and streamlined for stack efficiency.
  3.  
  4. /// Global Constants, Arrays, and Variables
  5.  
  6. //Common Constant, only need to define once per script file.
  7. const int BIG_LINK                  = 0;   //Set this constant to 1 if using the Large Link Hit Box feature.
  8. const int DIAGONAL_MOVEMENT         = 1; //Enable the option and change this to 0 for nes movement.
  9.  
  10. //Constants used by Bottomless Pits & Lava.
  11. const int CT_HOLELAVA              = 128; //Combo type to use for pit holes and lava."No Ground Enemies by default"
  12. const int CF_PIT                   = 101;  //The combo flag to register combos as pits.
  13. const int CF_LAVA                  = 102;  //The combo flag to register combos as lava.
  14. const int WPS_LINK_FALL            = 89;  //The weapon sprite to display when Link falls into a pit. "Sprite 88 by default"
  15. const int WPS_LINK_LAVA            = 90;  //The weapon sprite to display when Link drowns in lava. "Sprite 89 by default"
  16. const int SFX_LINK_FALL            = 38;  //The sound to play when Link falls into a pit. "SFX_FALL by default"
  17. const int SFX_LINK_LAVA            = 55;  //The sound to play when Link drowns in Lava. "SFX_SPLASH by default.
  18. const int CMB_AUTOWARP             = 48;  //The first of your four transparent autowarp combos.
  19. const int HOLELAVA_DAMAGE          = 8;   //Damage in hit points to inflict on link. "One Heart Container is worth 16 hit points"
  20.  
  21. //Global variables used by Bottomless Pits & Lava.
  22.  
  23. float PitsLava[256];
  24. const int HL_FALLING = 0;
  25. const int HL_WARPING = 1;
  26. const int HL_ONPLATFORM = 3;
  27.  
  28. /// FFC Scripts
  29.  
  30. ffc script Holelava
  31. {
  32.     void run(int warp, bool position, int damage)
  33.     {
  34.         while(true)
  35.         {
  36.             while(!PitsLava[HL_WARPING] || OnPlatform()) Waitframe();
  37.             if(warp > 0)
  38.             {
  39.                 this->Data = CMB_AUTOWARP+warp-1;
  40.                 this->Flags[FFCF_CARRYOVER] = true;
  41.                 Waitframe();
  42.                 this->Data = FFCS_INVISIBLE_COMBO;
  43.                 this->Flags[FFCF_CARRYOVER] = false;
  44.                 Link->Z = Link->Y;
  45.                 PitsLava[HL_WARPING] = 0;
  46.                 Link->DrawXOffset -= Cond(Link->DrawXOffset < 0, -1000, 1000);
  47.                 Link->HitXOffset -= Cond(Link->HitXOffset < 0, -1000, 1000);
  48.                 Quit();
  49.             }
  50.             if(position)
  51.             {
  52.                 Link->X = this->X;
  53.                 Link->Y = this->Y;
  54.             }
  55.             else
  56.             {
  57.                 Link->X = this->InitD[6];
  58.                 Link->Y = this->InitD[7];
  59.             }
  60.             if(damage)
  61.             {
  62.                 Link->HP -= damage;
  63.                 Link->Action = LA_GOTHURTLAND;
  64.                 Link->HitDir = -1;
  65.                 Game->PlaySound(SFX_OUCH);
  66.             }
  67.             Link->DrawXOffset -= Cond(Link->DrawXOffset < 0, -1000, 1000);
  68.             Link->HitXOffset -= Cond(Link->HitXOffset < 0, -1000, 1000);
  69.             PitsLava[HL_WARPING] = 0;
  70.             Waitframe();
  71.         }
  72.     }
  73. }
  74.  
  75.  
  76. ffc script MovingPlatform {
  77.     void run(){
  78.         float oldx = this->X;
  79.         float oldy = this->Y;
  80.         float linkx;
  81.         float linky;
  82.         while(true){
  83.             if ( OnPlatform() == FFCNum(this) ){
  84.                 linkx += this->X - oldx;
  85.                 linky += this->Y - oldy;
  86.                 if ( linkx << 0 != 0 ) {
  87.                     Link->X += linkx << 0;
  88.                     linkx -= linkx << 0;
  89.                 }
  90.                 if ( linky << 0 != 0 ){
  91.                     Link->Y += linky << 0;
  92.                     linky -= linky << 0;
  93.                 }
  94.             }
  95.             else {
  96.                 linkx = 0;
  97.                 linky = 0;
  98.             }
  99.             oldx = this->X;
  100.             oldy = this->Y;
  101.             Waitframe();
  102.         }
  103.     }
  104. }
  105.  
  106.  
  107. /// Global Scripts
  108.  
  109. global script active{                          
  110.     void run(){
  111.         StartGhostZH();
  112.         while(true){
  113.             UpdateGhostZH1();
  114.             InitHoleLava();
  115.             NesMovementFix();
  116.             Waitdraw();
  117.             UpdateGhostZH2();
  118.             LREx1Ex2ItemSwitch();
  119.             MovingPlatforms();
  120.             RunHoleLava();
  121.             Waitframe();
  122.         }//end whileloop
  123.     }//end run
  124. }//end global slot2
  125.  
  126.  
  127. /// Global Functions
  128.  
  129. //Sets or returns if we are on a platform.
  130. int OnPlatform(){return PitsLava[HL_ONPLATFORM];}
  131. void OnPlatform(int a){ PitsLava[HL_ONPLATFORM] = a; }
  132.  
  133. //Used to determine if Link is on a Pit or Lava combo.
  134. int OnPitCombo()
  135. {
  136.     int comboLoc = ComboAt(Link->X+8, Link->Y + Cond(BIG_LINK==0, 12, 8));
  137.     if(Screen->ComboT[comboLoc] != CT_HOLELAVA)
  138.         return 0;
  139.     else if(Screen->ComboI[comboLoc] == CF_PIT || Screen->ComboI[comboLoc] == CF_LAVA)
  140.         return Screen->ComboI[comboLoc];
  141.     else if(Screen->ComboF[comboLoc] == CF_PIT || Screen->ComboF[comboLoc] == CF_LAVA)
  142.         return Screen->ComboF[comboLoc];
  143.     else
  144.         return 0;
  145. }
  146.  
  147.  
  148. //Snaps Link to the combo so he appears completely over pit and lava combos.
  149. void SnaptoGrid()
  150. {
  151.     int x = Link->X;
  152.     int y = Link->Y + Cond(BIG_LINK==0, 8, 0);
  153.     int comboLoc = ComboAt(x, y);
  154.  
  155.     //X Axis
  156.     if(Screen->ComboT[comboLoc] == CT_HOLELAVA && Cond(x % 16 == 0, true, Screen->ComboT[comboLoc+1] != CT_HOLELAVA))
  157.         Link->X = ComboX(comboLoc);
  158.     else if(Screen->ComboT[comboLoc+1] == CT_HOLELAVA && Cond(x % 16 == 0, true, Screen->ComboT[comboLoc] != CT_HOLELAVA))
  159.         Link->X = ComboX(comboLoc+1);
  160.     if(Cond(y % 16 == 0, false, Screen->ComboT[comboLoc+16] == CT_HOLELAVA) && Cond(x % 16 == 0, true, Screen->ComboT[comboLoc+17] != CT_HOLELAVA))
  161.         Link->X = ComboX(comboLoc+16);
  162.     else if(Cond(y % 16 == 0, false, Screen->ComboT[comboLoc+17] == CT_HOLELAVA) && Cond(x % 16 == 0, true, Screen->ComboT[comboLoc+16] != CT_HOLELAVA))
  163.         Link->X = ComboX(comboLoc+17);
  164.  
  165.     //Y Axis
  166.     if(Screen->ComboT[comboLoc] == CT_HOLELAVA && Cond(y % 16 == 0, true, Screen->ComboT[comboLoc+16] != CT_HOLELAVA))
  167.         Link->Y = ComboY(comboLoc);
  168.     else if(Screen->ComboT[comboLoc+16] == CT_HOLELAVA && Cond(y % 16 == 0, true, Screen->ComboT[comboLoc] != CT_HOLELAVA))
  169.         Link->Y = ComboY(comboLoc+16);
  170.     if(Cond(x % 16 == 0, false, Screen->ComboT[comboLoc+1] == CT_HOLELAVA) && Cond(y % 16 == 0, true, Screen->ComboT[comboLoc+17] != CT_HOLELAVA))
  171.         Link->Y = ComboY(comboLoc+1);
  172.     else if(Cond(x % 16 == 0, false, Screen->ComboT[comboLoc+17] == CT_HOLELAVA) && Cond(y % 16 == 0, true, Screen->ComboT[comboLoc+1] != CT_HOLELAVA))
  173.         Link->Y = ComboY(comboLoc+17);
  174. }
  175.  
  176. void LREx1Ex2ItemSwitch()
  177. {
  178.     if (Link->PressL && Link->Action != LA_SCROLLING)
  179.     {
  180.         Link->SelectBWeapon(DIR_LEFT);
  181.     }
  182.     if (Link->PressR && Link->Action != LA_SCROLLING)
  183.     {
  184.         Link->SelectBWeapon(DIR_RIGHT);
  185.     }
  186.     if (Link->PressEx1 && Link->Action != LA_SCROLLING)
  187.     {
  188.         Link->SelectAWeapon(DIR_LEFT);
  189.     }
  190.     if (Link->PressEx2 && Link->Action != LA_SCROLLING)
  191.     {
  192.         Link->SelectAWeapon(DIR_RIGHT);
  193.     }
  194. }
  195.  
  196. //Hole_Lava Init. Call before Waitdraw().
  197. void InitHoleLava(){
  198.     //Initialize variables used to store Link's strating position on Screen Init.
  199.             int olddmap = Game->GetCurDMap();
  200.             int oldscreen = Game->GetCurDMapScreen();
  201.             int startx = Link->X;
  202.             int starty = Link->Y;
  203.             int startdir = Link->Dir;
  204.  
  205.             //Clear global variables used by Bottomless pits.
  206.             PitsLava[HL_FALLING] = 0;
  207.             PitsLava[HL_WARPING] = 0;
  208. }
  209.  
  210. //Main Hole_Lava Rountine. Call after Waitdraw().
  211. void RunHoleLava(){
  212.     if(Link->Action != LA_SCROLLING)
  213.     {
  214.         Update_HoleLava(startx, starty, olddmap, oldscreen, startdir);
  215.         if(Link->Z==0 && !PitsLava[HL_FALLING] && (oldscreen != Game->GetCurDMapScreen() || olddmap != Game->GetCurDMap()))
  216.         {
  217.             olddmap = Game->GetCurDMap();
  218.             oldscreen = Game->GetCurDMapScreen();
  219.             startx = Link->X;
  220.             starty = Link->Y;
  221.             startdir = Link->Dir;
  222.         }
  223.     }
  224. }
  225.  
  226. //Handles Pit Combo Functionality.
  227. void Update_HoleLava(int x, int y, int dmap, int scr, int dir)
  228. {
  229.     lweapon hookshot = LoadLWeaponOf(LW_HOOKSHOT);
  230.     if(hookshot->isValid()) return;
  231.  
  232.     if(PitsLava[HL_FALLING])
  233.     {
  234.         if(IsSideview()) Link->Jump=0;
  235.         PitsLava[HL_FALLING]--;
  236.         if(PitsLava[HL_FALLING] == 1)
  237.         {
  238.             int buffer[] = "Holelava";
  239.             if(CountFFCsRunning(Game->GetFFCScript(buffer)))
  240.             {
  241.                 ffc f = Screen->LoadFFC(FindFFCRunning(Game->GetFFCScript(buffer)));
  242.                 PitsLava[HL_WARPING] = 1;
  243.                 if(f->InitD[1]==0)
  244.                 {
  245.                     f->InitD[6] = x;
  246.                     f->InitD[7] = y;
  247.                 }
  248.             }
  249.             else
  250.             {
  251.                 Link->X = x;
  252.                 Link->Y = y;
  253.                 Link->Dir = dir;
  254.                 Link->DrawXOffset -= Cond(Link->DrawXOffset < 0, -1000, 1000);
  255.                 Link->HitXOffset -= Cond(Link->HitXOffset < 0, -1000, 1000);
  256.                 Link->HP -= HOLELAVA_DAMAGE;
  257.                 Link->Action = LA_GOTHURTLAND;
  258.                 Link->HitDir = -1;
  259.                 Game->PlaySound(SFX_OUCH);
  260.                 if(Game->GetCurDMap()!=dmap || Game->GetCurDMapScreen()!=scr)
  261.                 Link->PitWarp(dmap, scr);
  262.             }
  263.             NoAction();
  264.             Link->Action = LA_NONE;
  265.         }
  266.     }
  267.     else if(Link->Z==0 && OnPitCombo() && !PitsLava[HL_WARPING] && !OnPlatform())
  268.     {
  269.         Link->DrawXOffset += Cond(Link->DrawXOffset < 0, -1000, 1000);
  270.         Link->HitXOffset += Cond(Link->HitXOffset < 0, -1000, 1000);
  271.         int comboflag = OnPitCombo();
  272.         SnaptoGrid();
  273.         Game->PlaySound(Cond(comboflag == CF_PIT, SFX_LINK_FALL, SFX_LINK_LAVA));
  274.         lweapon dummy = CreateLWeaponAt(LW_SCRIPT10, Link->X, Link->Y);
  275.         dummy->UseSprite(Cond(comboflag == CF_PIT, WPS_LINK_FALL, WPS_LINK_LAVA));
  276.         dummy->DeadState = dummy->NumFrames*dummy->ASpeed;
  277.         dummy->DrawXOffset = 0;
  278.         dummy->DrawYOffset = 0;
  279.         PitsLava[HL_FALLING] = dummy->DeadState;
  280.         NoAction();
  281.         Link->Action = LA_NONE;
  282.     }
  283. }
  284.  
  285. //Handles moving platforms
  286. void MovingPlatforms(){
  287.     OnPlatform(0);
  288.     if ( Link->Z == 0 ) {
  289.         int buffer[] = "MovingPlatform";
  290.         for(int i = 1; i <= 32; i++) {
  291.             ffc f = Screen->LoadFFC(i);
  292.             if(f->Script != Game->GetFFCScript(buffer)) continue;
  293.             if(Abs(Link->X + 8 - CenterX(f)) >= f->TileWidth*8) continue;
  294.             if(Abs(Link->Y + 12 - CenterY(f)) >= f->TileHeight*8) continue;
  295.             OnPlatform(FFCNum(f));
  296.             break;
  297.         }
  298.     }
  299. }
  300.  
  301. //Used if we are using NES movement
  302. void NesMovementFix(){
  303.     if(DIAGONAL_MOVEMENT==0 && (Link->InputUp || Link->InputDown)){
  304.         Link->InputLeft = false;
  305.         Link->InputRight = false;
  306.     }
  307. }
Add Comment
Please, Sign In to add comment