ZoriaRPG

NPC.zh

Dec 6th, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.68 KB | None | 0 0
  1. //NPC.ZH
  2. //An attempt to port guys.cpp functions to ZScript
  3. //for use by npc scripts
  4.  
  5.  
  6. bool isjumper(npc n)
  7. {
  8.     switch(n->family)
  9.     {
  10.         case NPCT_ROCK:
  11.         case NPCT_TEKTITE:
  12.             return true;
  13.        
  14.         case NPCT_WALK:
  15.             if(n->Attributes[8] == NPCA_WALK_WS_VIRE ) return true;
  16.             else if(n->Attributes[8] == NPCA_WALK_WS_POLSVOICE ) return true;
  17.             return false;
  18.  
  19.         default: return false;
  20.     }
  21. }
  22.  
  23.  
  24. bool isfixedtogrid(npc n)
  25. {
  26.     switch(n->family)
  27.     {
  28.         case NPCT_WALK:
  29.         case NPCT_LEEVER:
  30.         case NPCT_ZORA:
  31.         case NPCT_DODONGO:
  32.         case NPCT_GANON:
  33.         case NPCT_ROCK:
  34.         case NPCT_GLEEOK:
  35.         case NPCT_AQUAMENTUS:
  36.         case NPCT_LANMOLA:
  37.         return true;
  38.    
  39.         default: return false;
  40.     }
  41. }
  42.  
  43. // Can't fall, can have Z value.
  44. bool isflier(npc n)
  45. {
  46.     switch(n->family) //id&0x0FFF)
  47.     {
  48.         case NPCT_PEAHAT:
  49.         case eeKEESE:
  50.         case eePATRA:
  51.         case eeFAIRY:
  52.         case eeGHINI:
  53.    
  54.         // Could theoretically have their Z set by a script
  55.         //case eeFIRE: //this is 'NPCT_OTHER'
  56.             return true;
  57.         default: return false;
  58.  
  59.     }
  60. }
  61.  
  62. bool never_in_air(npc n)
  63. {
  64.     switch(n->family)
  65.     {
  66.         case NPCT_MANHANDLA:
  67.         case NPCT_MOLDORM:
  68.         case NPCT_LANMOLA:
  69.         case NPCT_GLEEOK:
  70.         case NPCT_ZORA:
  71.         case NPCT_LEEVER:
  72.         case NPCT_AQUAMENTUS:
  73.         case NPCT_ROCK:
  74.         case NPCT_GANON:
  75.         case NPCT_TRAP:
  76.         case NPCT_PROJECTILE:
  77.         case NPCT_SPINTILE:
  78.         return true;
  79.        
  80.         default: return false;
  81.     }
  82. }
  83.  
  84. bool canfall(npc n)
  85. {
  86.     /*
  87.     switch(n->amily)
  88.     {
  89.         case eeGUY:
  90.         {
  91.             if(id < eOCTO1S)
  92.             return false;
  93.            
  94.             switch(guysbuf[id&0xFFF].misc10)
  95.             {
  96.                 case 1:
  97.                 case 2:
  98.                 return true;
  99.            
  100.                 case 0:
  101.                 case 3:
  102.                 default:
  103.                 return false;
  104.             }
  105.        
  106.         case eeGHOMA:
  107.         case eeDIG:
  108.             return false;
  109.         }
  110.     }
  111.     */
  112.     if ( never_in_air(n) ) return false;
  113.     if ( isflier(n) ) return false;
  114.     if ( isjumper(n) ) return false;
  115.     return true;
  116. }
  117.  
  118. // returns true if next step is ok, false if there is something there
  119. bool canmove(npc n, int ndir, float step,int special,int dx1,int dy1,int dx2,int dy2)
  120. {
  121.     bool ok;
  122.     int dx = 0, dy = 0;
  123.     int sv = 8;
  124.    
  125.     step += 0.5; // Make the ints round; doesn't seem to cause any problems.
  126.    
  127.     switch(ndir)
  128.     {
  129.     case 8:
  130.     case DIR_UP:
  131.         if(canfall(id) && tmpscr->flags7&fSIDEVIEW)
  132.             return false;
  133.            
  134.         dy = dy1-step;
  135.         special = (special==spw_clipbottomright)?spw_none:special;
  136.         ok = !m_walkflag(n->X,n->Y+dy,special, n->X, n->Y) && !flyerblocked(n->X,n->Y+dy, special);
  137.         break;
  138.        
  139.     case 12:
  140.     case DIR_DOWN:
  141.         if(canfall(id) && tmpscr->flags7&fSIDEVIEW)
  142.             return false;
  143.            
  144.         dy = dy2+step;
  145.         ok = !m_walkflag(n->X,n->Y+dy,special, n->X, n->Y) && !flyerblocked(n->X,n->Y+dy, special);
  146.         break;
  147.        
  148.     case 14:
  149.     case DIR_LEFT:
  150.         dx = dx1-step;
  151.         sv = ((tmpscr->flags7&fSIDEVIEW)?7:8);
  152.         special = (special==spw_clipbottomright||special==spw_clipright)?spw_none:special;
  153.         ok = !m_walkflag(n->X+dx,n->Y+sv,special, n->X, n->Y) && !flyerblocked(n->X+dx,n->Y+8, special);
  154.         break;
  155.        
  156.     case 10:
  157.     case DIR_RIGHT:
  158.         dx = dx2+step;
  159.         sv = ((tmpscr->flags7&fSIDEVIEW)?7:8);
  160.         ok = !m_walkflag(n->X+dx,n->Y+sv,special, n->X, n->Y) && !flyerblocked(n->X+dx,n->Y+8, special);
  161.         break;
  162.        
  163.     case 9:
  164.     case DIR_RIGHTUP:
  165.         dx = dx2+step;
  166.         dy = dy1-step;
  167.         ok = !m_walkflag(n->X,n->Y+dy,special, n->X, n->Y) && !m_walkflag(n->X+dx,n->Y+sv,special, n->X, n->Y) &&
  168.              !flyerblocked(n->X,n->Y+dy, special) && !flyerblocked(n->X+dx,n->Y+8, special);
  169.         break;
  170.        
  171.     case 11:
  172.     case r_down:
  173.         dx = dx2+step;
  174.         dx = dy2+step;
  175.         ok = !m_walkflag(n->X,n->Y+dy,special, n->X, n->Y) && !m_walkflag(n->X+dx,n->Y+sv,special, n->X, n->Y) &&
  176.              !flyerblocked(n->X,n->Y+dy, special) && !flyerblocked(n->X+dx,n->Y+8, special);
  177.         break;
  178.        
  179.     case 13:
  180.     case DIR_LEFTDOWN:
  181.         dx = dx1-step;
  182.         dy = dy2+step;
  183.         ok = !m_walkflag(n->X,n->Y+dy,special, n->X, n->Y) && !m_walkflag(n->X+dx,n->Y+sv,special, n->X, n->Y) &&
  184.              !flyerblocked(n->X,n->Y+dy, special) && !flyerblocked(n->X+dx,n->Y+8, special);
  185.         break;
  186.        
  187.     case 15:
  188.     case DIR_LEFTUP:
  189.         dx = dx1-step;
  190.         dy = dy1-step;
  191.         ok = !m_walkflag(n->X,n->Y+dy,special, n->X, n->Y) && !m_walkflag(n->X+dx,n->Y+sv,special, n->X, n->Y) &&
  192.              !flyerblocked(n->X,n->Y+dy, special) && !flyerblocked(n->X+dx,n->Y+8, special);
  193.         break;
  194.        
  195.     default:
  196.         db=99;
  197.         return true;
  198.     }
  199.    
  200.     return ok;
  201. }
Add Comment
Please, Sign In to add comment