Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //NPC.ZH
- //An attempt to port guys.cpp functions to ZScript
- //for use by npc scripts
- //Special Walk Styles //values are arbitrary. -Z
- define spw_wizzrobe = 1000;
- define spw_floater = 1001;
- define spw_door = 1002; //can walk in a doorway
- define spw_clipbottomright = 1003; //clip options
- define spw_clipright = 1004; //clip options
- define spw_halfstep = 1005;
- define spw_water = 1006;
- bool isjumper(npc n)
- {
- switch(n->family)
- {
- case NPCT_ROCK:
- case NPCT_TEKTITE:
- return true;
- case NPCT_WALK:
- if(n->Attributes[8] == NPCA_WALK_WS_VIRE ) return true;
- else if(n->Attributes[8] == NPCA_WALK_WS_POLSVOICE ) return true;
- return false;
- default: return false;
- }
- }
- bool isfixedtogrid(npc n)
- {
- switch(n->family)
- {
- case NPCT_WALK:
- case NPCT_LEEVER:
- case NPCT_ZORA:
- case NPCT_DODONGO:
- case NPCT_GANON:
- case NPCT_ROCK:
- case NPCT_GLEEOK:
- case NPCT_AQUAMENTUS:
- case NPCT_LANMOLA:
- return true;
- default: return false;
- }
- }
- // Can't fall, can have Z value.
- bool isflier(npc n)
- {
- switch(n->family) //id&0x0FFF)
- {
- case NPCT_PEAHAT:
- case eeKEESE:
- case eePATRA:
- case eeFAIRY:
- case eeGHINI:
- // Could theoretically have their Z set by a script
- //case eeFIRE: //this is 'NPCT_OTHER'
- return true;
- default: return false;
- }
- }
- bool never_in_air(npc n)
- {
- switch(n->family)
- {
- case NPCT_MANHANDLA:
- case NPCT_MOLDORM:
- case NPCT_LANMOLA:
- case NPCT_GLEEOK:
- case NPCT_ZORA:
- case NPCT_LEEVER:
- case NPCT_AQUAMENTUS:
- case NPCT_ROCK:
- case NPCT_GANON:
- case NPCT_TRAP:
- case NPCT_PROJECTILE:
- case NPCT_SPINTILE:
- return true;
- default: return false;
- }
- }
- bool canfall(npc n)
- {
- /*
- switch(n->amily)
- {
- case eeGUY:
- {
- if(id < eOCTO1S)
- return false;
- switch(guysbuf[id&0xFFF].misc10)
- {
- case 1:
- case 2:
- return true;
- case 0:
- case 3:
- default:
- return false;
- }
- case eeGHOMA:
- case eeDIG:
- return false;
- }
- }
- */
- if ( never_in_air(n) ) return false;
- if ( isflier(n) ) return false;
- if ( isjumper(n) ) return false;
- return true;
- }
- int COMBOTYPE(int x, int y)
- {
- return ( Screen->ComboT[ComboAt(x,y)] );
- }
- // Returns true iff a combo type or flag precludes enemy movement.
- bool groundblocked(int dx, int dy)
- {
- if ( COMBOTYPE(dx,dy)==CT_PIT )
- COMBOTYPE(dx,dy)==CT_PITB
- COMBOTYPE(dx,dy)==CT_PITC
- COMBOTYPE(dx,dy)==CT_PITD
- COMBOTYPE(dx,dy)==CT_PITR
- combodata cd = Game->LoadComboData(Screen->ComboT[ComboAt(x,y));
- if ( (cd->BlockNPC&1) ) return true;
- // Block enemies type and block enemies flags
- //combo_class_buf[COMBOTYPE(dx,dy)].block_enemies&1 ||
- if ( Screen->ComboF[ComboAt(x,y)] == mfNOENEMY ) return true;
- if ( Screen->ComboI[ComboAt(x,y)] == mfNOENEMY ) return true;
- if ( Screen->ComboF[ComboAt(x,y)] == mfNOGROUNDENEMY ) return true;
- if ( Screen->ComboI[ComboAt(x,y)] == mfNOGROUNDENEMY ) return true;
- if ( (cd->Ladder&1) && (cd->Water != 0) ) return true;
- //ADD THIS When we can read QRs by script.
- //if ( GetFFRule(qr_DROWN) && !isSideView() && (cd->Water != 0) ) return true;
- // Check for ladder-only combos which aren't dried water
- //(combo_class_buf[COMBOTYPE(dx,dy)].ladder_pass&1 && !iswater_type(COMBOTYPE(dx,dy))) ||
- // Check for drownable water
- //(get_bit(quest_rules,qr_DROWN) && !(tmpscr->flags7&fSIDEVIEW) && (iswater(MAPCOMBO(dx,dy))));
- }
- bool m_walkflag(int dx,int dy,int special, int x, int y) //int x=-1000, int y=-1000)
- {
- int yg = 0;
- if ( special==spw_floater ) yg = 8
- //When we can read quest rules by script.
- int nb = 16;
- //int nb = get_bit(quest_rules, qr_NOBORDER) ? 16 : 0;
- if( dx < 16-nb ) return true;
- if ( dy < Max(16-yg-nb,0) ) return true;
- if ( dx >= 240 + nb ) return true;
- if ( dy >= 160 + nb ) return true;
- if(IsDungeon() || special==spw_wizzrobe)
- {
- if((x>=32 && dy<32-yg) || (y>-1000 && y<=144 && dy>=144))
- return true;
- if((x>=32 && dx<32) || (x>-1000 && x<224 && dx>=224))
- if(special!=spw_door) // walk in door way
- return true;
- }
- switch(special)
- {
- case spw_clipbottomright:
- if(dy>=128 || dx>=208) return true;
- case spw_clipright:
- break; //if(x>=208) return true; break;
- case spw_wizzrobe: // fall through
- case spw_floater: // Special case for fliers and wizzrobes - hack!
- {
- if(IsDungeon())
- {
- if(dy < 32-yg || dy >= 144) return true;
- if(dx < 32 || dx >= 224) return true;
- }
- return false;
- }
- default: break;
- }
- if ( special==spw_halfstep ) dx &= ~7;
- else dx &= ~15;
- //dx&=(special==spw_halfstep)?(~7):(~15);
- if ( special==spw_halfstep || isSideView() ) dy &= ~7;
- else dy &= ~15;
- //dy&=(special==spw_halfstep || tmpscr->flags7&fSIDEVIEW)?(~7):(~15);
- //water-WALKFLAG IS TOO COMPLEX for me to implement right now, so I'm skipping this.
- //if(special==spw_water)
- // return (water_walkflag(dx,dy+8,1) || water_walkflag(dx+8,dy+8,1));
- if ( Screen->ComboS[ComboAt(dx,dy+8)] ) return true;
- if ( Screen->ComboS[ComboAt(dx+8,dy+8)] ) return true;
- //return _walkflag(dx,dy+8,1) || _walkflag(dx+8,dy+8,1) ||
- if ( groundblocked(dx,dy+8) ) return true;
- if ( groundblocked(dx+8,dy+8) ) return true;
- return false;
- }
- // Returns true iff enemy is floating and blocked by a combo type or flag.
- bool flyerblocked(int dx, int dy, int special)
- {
- combodata cd = Game->LoadComboData(Screen->ComboD[ComboAt(dx,dy)]);
- if (special==spw_floater)
- {
- if ( COMBOTYPE(dx,dy)==cNOFLYZONE ) return true;
- if ( (cd->BlockNPC&4) ) return true;
- if ( Screen->ComboF[ComboAt(dx,dy)] == mfNOENEMY ) return true;
- if ( Screen->ComboI[ComboAt(dx,dy)] == mfNOENEMY ) return true;
- }
- return false;
- }
- bool tooclose(int x,int y,int max_dist)
- {
- if (abs(Link->X-x)< max_dist )
- {
- if ( abs(Link->Y-y) < max_dist ) return true;
- }
- return false;
- }
- ///////////////
- // returns true if next step is ok, false if there is something there
- bool canmove(npc n, int ndir, float step,int special,int dx1,int dy1,int dx2,int dy2)
- {
- bool ok;
- int dx = 0, dy = 0;
- int sv = 8;
- step += 0.5; // Make the ints round; doesn't seem to cause any problems.
- switch(ndir)
- {
- case 8:
- case DIR_UP:
- if(canfall(id) && tmpscr->flags7&fSIDEVIEW)
- return false;
- dy = dy1-step;
- special = (special==spw_clipbottomright)?spw_none:special;
- ok = !m_walkflag(n->X,n->Y+dy,special, n->X, n->Y) && !flyerblocked(n->X,n->Y+dy, special);
- break;
- case 12:
- case DIR_DOWN:
- if(canfall(id) && tmpscr->flags7&fSIDEVIEW)
- return false;
- dy = dy2+step;
- ok = !m_walkflag(n->X,n->Y+dy,special, n->X, n->Y) && !flyerblocked(n->X,n->Y+dy, special);
- break;
- case 14:
- case DIR_LEFT:
- dx = dx1-step;
- sv = ((tmpscr->flags7&fSIDEVIEW)?7:8);
- special = (special==spw_clipbottomright||special==spw_clipright)?spw_none:special;
- ok = !m_walkflag(n->X+dx,n->Y+sv,special, n->X, n->Y) && !flyerblocked(n->X+dx,n->Y+8, special);
- break;
- case 10:
- case DIR_RIGHT:
- dx = dx2+step;
- sv = ((tmpscr->flags7&fSIDEVIEW)?7:8);
- ok = !m_walkflag(n->X+dx,n->Y+sv,special, n->X, n->Y) && !flyerblocked(n->X+dx,n->Y+8, special);
- break;
- case 9:
- case DIR_RIGHTUP:
- dx = dx2+step;
- dy = dy1-step;
- 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) &&
- !flyerblocked(n->X,n->Y+dy, special) && !flyerblocked(n->X+dx,n->Y+8, special);
- break;
- case 11:
- case r_down:
- dx = dx2+step;
- dx = dy2+step;
- 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) &&
- !flyerblocked(n->X,n->Y+dy, special) && !flyerblocked(n->X+dx,n->Y+8, special);
- break;
- case 13:
- case DIR_LEFTDOWN:
- dx = dx1-step;
- dy = dy2+step;
- 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) &&
- !flyerblocked(n->X,n->Y+dy, special) && !flyerblocked(n->X+dx,n->Y+8, special);
- break;
- case 15:
- case DIR_LEFTUP:
- dx = dx1-step;
- dy = dy1-step;
- 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) &&
- !flyerblocked(n->X,n->Y+dy, special) && !flyerblocked(n->X+dx,n->Y+8, special);
- break;
- default:
- db=99;
- return true;
- }
- return ok;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement