ZoriaRPG icon

KnockbackSolidity.zs : Stop Link Knockback from Phasing through Barriers

ZoriaRPG | PRO | 02/15/18 01:19:08 PM UTC | 0 ⭐ | 614 👁️ | Never ⏰ | []
C++ |

3.16 KB

|

None

|

0 👍

/

0 👎

// A function to prevent Link from phasing through solid
// combos, 'solid' ffc, and through water, if knocked back.
// Prevention of hookshot and ladder spots is here, but 
// disabled, as this *should* be handled by the ZC engine
// internally.
 
const int CF_NO_KNOCKBACK = 101; //Generic flag to prevent knockback on a square.
 
void KnockbackSolidity
{
     int x, int y;
     if ( Link->HitDir > -1 )
     {
          switch(Link->HitDir)
          {
               case DIR_LEFT:
               {
                    x = Link->X-1; y = Link->Y+8; break;
               }
               case DIR_RIGHT:
               {
                    x = Link->X+17; y = Link->Y+8; break;
               }
               case DIR_UP:
               {
                    x = Link->X+8; y = Link->Y+7; break;
               }
               case DIR_DOWN:
               {
                    x = Link->X-1; y = Link->Y+8; break;
               }
               default: return; 
               // Any other direction is invalid, and is never set by the ZC engine,
               // so, it must be set by a script, and likely has its own, custom handling.
          }
          if ( Screen->isSolid(x,y) )
          {
               Link->HitDir = -1;
          }
          if ( IsSolidFFC(x,y) )
          {
               Link->HitDir = -1;
          }
          if ( Screen->ComboF[ComboAt(x,y)] == CF_NO_KNOCKBACK )
          {
               Link->HitDir = -1;
          }
          if ( Screen->ComboI[ComboAt(x,y)] == CF_NO_KNOCKBACK )
          {
               Link->HitDir = -1;
          }
          if ( Link->Action == LA_GOTHURTLAND )
          {
               if ( Screen->ComboT[ComboAt(x,y)] == CT_WATER )
               {
                    Link->HitDir = -1;
               }    
               /*
               if ( Screen->ComboT[ComboAt(x,y)] == CT_LADDER  )
               {
                    Link->HitDir = -1;
               }       
               if ( Screen->ComboT[ComboAt(x,y)] == CT_LADDER_HOOKSHOT  )
               {
                    Link->HitDir = -1;
               }     
               if ( Screen->ComboF[ComboAt(x,y)] == CF_LADDER  )
               {
                    Link->HitDir = -1;
               }     
               if ( Screen->ComboF[ComboAt(x,y)] == CF_LADDER_HOOKSHOT  )
               {
                    Link->HitDir = -1;
               }     
          */
          }
          else //Link is swimming
          {
          if ( Screen->ComboT[ComboAt(x,y)] != CT_WATER )
               {
                    Link->HitDir = -1;
               }
          } 
     }
}
 
// Utility function to check for ffc solidity at an arbitrary pixel.
// There *must* be a faster way to do this...
bool IsSolidFFC(int x, int y)
{
     ffc f; int q = 1;
     for ( ; q < 33; ++q )
     {
          f = Screen->LoadFFC(q);
          if ( f->Flags&FFCF_SOLID )
          {
               if ( RectCollision(f->X, f->Y, f->X+f->EffectWidth, f->Y+f->EffectHeight, x, y, x, y) )
               {
                    return true;
               }
          }
          return false;
     }
}

Comments