Advertisement
ZoriaRPG

KnockbackSolidity.zs : Stop Link Knockback from Phasing through Barriers

Feb 15th, 2018
326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.16 KB | None | 0 0
  1. // A function to prevent Link from phasing through solid
  2. // combos, 'solid' ffc, and through water, if knocked back.
  3. // Prevention of hookshot and ladder spots is here, but
  4. // disabled, as this *should* be handled by the ZC engine
  5. // internally.
  6.  
  7. const int CF_NO_KNOCKBACK = 101; //Generic flag to prevent knockback on a square.
  8.  
  9. void KnockbackSolidity
  10. {
  11.      int x, int y;
  12.      if ( Link->HitDir > -1 )
  13.      {
  14.           switch(Link->HitDir)
  15.           {
  16.                case DIR_LEFT:
  17.                {
  18.                     x = Link->X-1; y = Link->Y+8; break;
  19.                }
  20.                case DIR_RIGHT:
  21.                {
  22.                     x = Link->X+17; y = Link->Y+8; break;
  23.                }
  24.                case DIR_UP:
  25.                {
  26.                     x = Link->X+8; y = Link->Y+7; break;
  27.                }
  28.                case DIR_DOWN:
  29.                {
  30.                     x = Link->X-1; y = Link->Y+8; break;
  31.                }
  32.                default: return;
  33.                // Any other direction is invalid, and is never set by the ZC engine,
  34.                // so, it must be set by a script, and likely has its own, custom handling.
  35.           }
  36.           if ( Screen->isSolid(x,y) )
  37.           {
  38.                Link->HitDir = -1;
  39.           }
  40.           if ( IsSolidFFC(x,y) )
  41.           {
  42.                Link->HitDir = -1;
  43.           }
  44.           if ( Screen->ComboF[ComboAt(x,y)] == CF_NO_KNOCKBACK )
  45.           {
  46.                Link->HitDir = -1;
  47.           }
  48.           if ( Screen->ComboI[ComboAt(x,y)] == CF_NO_KNOCKBACK )
  49.           {
  50.                Link->HitDir = -1;
  51.           }
  52.           if ( Link->Action == LA_GOTHURTLAND )
  53.           {
  54.                if ( Screen->ComboT[ComboAt(x,y)] == CT_WATER )
  55.                {
  56.                     Link->HitDir = -1;
  57.                }    
  58.                /*
  59.                if ( Screen->ComboT[ComboAt(x,y)] == CT_LADDER  )
  60.                {
  61.                     Link->HitDir = -1;
  62.                }      
  63.                if ( Screen->ComboT[ComboAt(x,y)] == CT_LADDER_HOOKSHOT  )
  64.                {
  65.                     Link->HitDir = -1;
  66.                }    
  67.                if ( Screen->ComboF[ComboAt(x,y)] == CF_LADDER  )
  68.                {
  69.                     Link->HitDir = -1;
  70.                }    
  71.                if ( Screen->ComboF[ComboAt(x,y)] == CF_LADDER_HOOKSHOT  )
  72.                {
  73.                     Link->HitDir = -1;
  74.                }    
  75.           */
  76.           }
  77.           else //Link is swimming
  78.           {
  79.           if ( Screen->ComboT[ComboAt(x,y)] != CT_WATER )
  80.                {
  81.                     Link->HitDir = -1;
  82.                }
  83.           }
  84.      }
  85. }
  86.  
  87. // Utility function to check for ffc solidity at an arbitrary pixel.
  88. // There *must* be a faster way to do this...
  89. bool IsSolidFFC(int x, int y)
  90. {
  91.      ffc f; int q = 1;
  92.      for ( ; q < 33; ++q )
  93.      {
  94.           f = Screen->LoadFFC(q);
  95.           if ( f->Flags&FFCF_SOLID )
  96.           {
  97.                if ( RectCollision(f->X, f->Y, f->X+f->EffectWidth, f->Y+f->EffectHeight, x, y, x, y) )
  98.                {
  99.                     return true;
  100.                }
  101.           }
  102.           return false;
  103.      }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement