// ====================================================================================================================================================================================
// UTILITIES
// ====================================================================================================================================================================================
bool SelectPressInput(int input){
if(input == 0) return Link->PressA;
else if(input == 1) return Link->PressB;
else if(input == 2) return Link->PressL;
else if(input == 3) return Link->PressR;
}
void SetInput(int input, bool state){
if(input == 0) Link->InputA = state;
else if(input == 1) Link->InputB = state;
else if(input == 2) Link->InputL = state;
else if(input == 3) Link->InputR = state;
}
// ..................................................................................................................................................................
float DistanceLink(float x, float y){
return Distance(CenterLinkX(), CenterLinkY(), x, y);
}
float DistanceLink(ffc f){
return Distance(CenterLinkX(), CenterLinkY(), CenterX(f), CenterY(f));
}
float DistanceLink(npc n){
return Distance(CenterLinkX(), CenterLinkY(), CenterX(n), CenterY(n));
}
float DistanceLink(lweapon l){
return Distance(CenterLinkX(), CenterLinkY(), CenterX(l), CenterY(l));
}
float DistanceLink(eweapon e){
return Distance(CenterLinkX(), CenterLinkY(), CenterX(e), CenterY(e));
}
// ..................................................................................................................................................................
void Update_HoleLava(int x, int y, int dmap, int scr, int dir){
lweapon hookshot = LoadLWeaponOf(LW_HOOKSHOT);
if(hookshot->isValid()) return;
if(Falling)
{
PegasusDash = false;
if(IsSideview()) Link->Jump=0;
Falling--;
if(Falling == 1)
{
int buffer[] = "Holelava";
if(CountFFCsRunning(Game->GetFFCScript(buffer)))
{
ffc f = Screen->LoadFFC(FindFFCRunning(Game->GetFFCScript(buffer)));
Warping = true;
if(f->InitD[1]==0)
{
f->InitD[6] = x;
f->InitD[7] = y;
}
}
else
{
Link->X = x;
Link->Y = y;
Link->Dir = dir;
Link->DrawXOffset -= Cond(Link->DrawXOffset < 0, -1000, 1000);
Link->HitXOffset -= Cond(Link->HitXOffset < 0, -1000, 1000);
Link->HP -= HOLELAVA_DAMAGE;
Link->Action = LA_GOTHURTLAND;
Link->HitDir = -1;
Game->PlaySound(SFX_OUCH);
if(Game->GetCurDMap()!=dmap || Game->GetCurDMapScreen()!=scr)
Link->PitWarp(dmap, scr);
}
NoAction();
Link->Action = LA_NONE;
}
}
else if(Link->Z==0 && OnPitCombo() && !Warping)
{
PegasusDash = false;
Link->DrawXOffset += Cond(Link->DrawXOffset < 0, -1000, 1000);
Link->HitXOffset += Cond(Link->HitXOffset < 0, -1000, 1000);
int comboflag = OnPitCombo();
SnaptoGrid();
Game->PlaySound(Cond(comboflag == CF_PIT, SFX_LINK_FALL, SFX_LINK_LAVA));
lweapon dummy = CreateLWeaponAt(LW_SCRIPT10, Link->X, Link->Y);
dummy->UseSprite(Cond(comboflag == CF_PIT, WPS_LINK_FALL, WPS_LINK_LAVA));
dummy->DeadState = dummy->NumFrames*dummy->ASpeed;
dummy->DrawXOffset = 0;
dummy->DrawYOffset = 0;
Falling = dummy->DeadState;
NoAction();
Link->Action = LA_NONE;
}
}
int OnPitCombo(){
int comboLoc = ComboAt(Link->X+8, Link->Y + Cond(BIG_LINK==0, 12, 8));
if(Screen->ComboT[comboLoc] != CT_HOLELAVA)
return 0;
else if(Screen->ComboI[comboLoc] == CF_PIT || Screen->ComboI[comboLoc] == CF_LAVA)
return Screen->ComboI[comboLoc];
else if(Screen->ComboF[comboLoc] == CF_PIT || Screen->ComboF[comboLoc] == CF_LAVA)
return Screen->ComboF[comboLoc];
else
return 0;
}
void SnaptoGrid(){
int x = Link->X;
int y = Link->Y + Cond(BIG_LINK==0, 8, 0);
int comboLoc = ComboAt(x, y);
//X Axis
if(Screen->ComboT[comboLoc] == CT_HOLELAVA && Cond(x % 16 == 0, true, Screen->ComboT[comboLoc+1] != CT_HOLELAVA))
Link->X = ComboX(comboLoc);
else if(Screen->ComboT[comboLoc+1] == CT_HOLELAVA && Cond(x % 16 == 0, true, Screen->ComboT[comboLoc] != CT_HOLELAVA))
Link->X = ComboX(comboLoc+1);
if(Cond(y % 16 == 0, false, Screen->ComboT[comboLoc+16] == CT_HOLELAVA) && Cond(x % 16 == 0, true, Screen->ComboT[comboLoc+17] != CT_HOLELAVA))
Link->X = ComboX(comboLoc+16);
else if(Cond(y % 16 == 0, false, Screen->ComboT[comboLoc+17] == CT_HOLELAVA) && Cond(x % 16 == 0, true, Screen->ComboT[comboLoc+16] != CT_HOLELAVA))
Link->X = ComboX(comboLoc+17);
//Y Axis
if(Screen->ComboT[comboLoc] == CT_HOLELAVA && Cond(y % 16 == 0, true, Screen->ComboT[comboLoc+16] != CT_HOLELAVA))
Link->Y = ComboY(comboLoc);
else if(Screen->ComboT[comboLoc+16] == CT_HOLELAVA && Cond(y % 16 == 0, true, Screen->ComboT[comboLoc] != CT_HOLELAVA))
Link->Y = ComboY(comboLoc+16);
if(Cond(x % 16 == 0, false, Screen->ComboT[comboLoc+1] == CT_HOLELAVA) && Cond(y % 16 == 0, true, Screen->ComboT[comboLoc+17] != CT_HOLELAVA))
Link->Y = ComboY(comboLoc+1);
else if(Cond(x % 16 == 0, false, Screen->ComboT[comboLoc+17] == CT_HOLELAVA) && Cond(y % 16 == 0, true, Screen->ComboT[comboLoc+1] != CT_HOLELAVA))
Link->Y = ComboY(comboLoc+17);
}
// ..................................................................................................................................................................
void PegasusBoots(){
lweapon mysword;
if(PegasusDash){
if(!PegasusCollision){
int loc = ComboAt(Link->X+8,Link->Y+8);
if( ((StoreInput == 1 && !Link->InputA) || (StoreInput == 2 && !Link->InputB))
|| StoreHP < Link->HP
|| Link->Action == LA_DROWNING || Link->Action == LA_SWIMMING
|| (!CanDrown && Screen->ComboT[TouchedComboLoc()] == CT_WATER) ){
PegasusDash = false;
DashCounter = 0;
}
//!!!!!!!!!!!! comment this out if not using Sideview Ladder script
if( Screen->ComboT[TouchedComboLoc()] == CT_SIDEVIEWLADDER || ComboFI(TouchedX(),TouchedY(),CF_LADDER) ){
PegasusDash = false;
DashCounter = 0;
}
if(!(GetEquipmentA() == I_ROCSFEATHER_INCREASER && Link->InputA) && !(GetEquipmentB() == I_ROCSFEATHER_INCREASER && Link->InputB))
NoAction();
if(DashCounter > 10){
if(Link->Dir == DIR_UP && DashCheck(Link->X+8,Link->Y+6,true) != 2){
Link->Y--;
Link->InputUp = true;
}
else if(Link->Dir == DIR_DOWN && DashCheck(Link->X+8,Link->Y+18,true) != 2){
Link->Y++;
Link->InputDown = true;
}
else if(Link->Dir == DIR_LEFT && DashCheck(Link->X,Link->Y+12,false) != 2){
Link->X--;
Link->InputLeft = true;
}
else if(Link->Dir == DIR_RIGHT && DashCheck(Link->X+16,Link->Y+12,false) != 2){
Link->X++;
Link->InputRight = true;
}
else{
PegasusCollision = true;
DashCounter = 0;
}
}//end DashCounter if
if(ComboFI(Link->X+8,Link->Y+8,CF_DASH) && Screen->ComboS[loc] == 1111b){
Screen->ComboD[loc]=INV_COMBO_ID;
if(Screen->ComboF[loc] == CF_DASH) Screen->ComboF[loc] = 0;
Game->PlaySound(SFX_PEGASUSBREAK);
}
lweapon Dust;
if(DashCounter%4 == 0){
for(int j=1;j<=Screen->NumLWeapons();j++){
Dust = Screen->LoadLWeapon(j);
if(Dust->ID != LW_SCRIPT10) continue;
if(Link->Dir < 1) Dust->Y-=3;
else if(Link->Dir < 2) Dust->Y+=3;
else if(Link->Dir < 3) Dust->X-=3;
else if(Link->Dir < 4) Dust->X+=3;
}//end for loop
Dust = Screen->CreateLWeapon(LW_SCRIPT10);
Dust->OriginalTile = T_DUST;
Dust->CSet = DustCSet;
Dust->Y = Link->Y+8;
Dust->X = Link->X;
Dust->NumFrames = DustAFrames;
Dust->ASpeed = DustASpeed;
Dust->DeadState = DustAFrames*DustASpeed;
}//end dust if
if(DashCounter%DashSFXLength == 0) Game->PlaySound(SFX_DASH);
//Item[91] = I_ROCSFEATHER
//Item[124] = Custom Item 2 I_ROCSFEATHER_INCREASER
if(Link->Item[91] && !Link->Item[124]){
Link->Item[124]=true;
}
if(LinkSwordEquip() > -1 && DashCounter>10){
mysword = LoadLWeaponOf(LW_SCRIPT3);
if(!mysword->isValid()){
mysword = Screen->CreateLWeapon(LW_SCRIPT3);
mysword->Damage = 8;
}
if(LinkSwordEquip()==I_SWORD4){
mysword->UseSprite(SPRITE_SWORD4);
}else if(LinkSwordEquip()==I_SWORD3){
mysword->UseSprite(SPRITE_SWORD3);
}else if(LinkSwordEquip()==I_SWORD2){
mysword->UseSprite(SPRITE_SWORD2);
}else{
mysword->UseSprite(SPRITE_SWORD1);
}//end sprite if
mysword->X = Link->X+InFrontX(Link->Dir, 6);
mysword->Y = Link->Y+InFrontY(Link->Dir, 6);
mysword->Dir = Link->Dir;
if(mysword->Dir < 2){
if(mysword->Dir == DIR_DOWN) mysword->Flip = 3;
}
else{
mysword->OriginalTile += 1;
mysword->Tile = mysword->OriginalTile;
if(mysword->Dir == DIR_LEFT) mysword->Flip = 1;
mysword->Y += 3;
}//end dir if
int loc = ComboAt(TouchedX()+InFrontX(mysword->Dir,4),TouchedY()+InFrontY(mysword->Dir,4));
bool playsound = true;
if(Screen->ComboT[loc] == CT_BUSH) Screen->ComboD[loc] = Screen->UnderCombo;
else if(Screen->ComboT[loc] == CT_TALLGRASS) Screen->ComboD[loc] = Screen->UnderCombo;
else if(Screen->ComboT[loc] == CT_BUSHNEXT) Screen->ComboD[loc] += 1;
else if(Screen->ComboT[loc] == CT_TALLGRASSNEXT) Screen->ComboD[loc] += 1;
else playsound = false;
if(playsound){
CreateGraphicAt(92,ComboX(loc),ComboY(loc));
Game->PlaySound(SFX_GRASSCUT);
ItemSetAt(IS_COMBOS,loc);
}//end playsound if
}
else{
Remove(mysword);
}//end mysword if
}//end !PegasusCollision if
else{ //is PegasusCollision
NoAction();
if(DashCounter == 1){
Screen->ClearSprites(SL_LWPNS);
Game->PlaySound(SFX_HITWALL);
Screen->Quake = 10;
}
else if(DashCounter == 10){
PegasusDash = false;
PegasusCollision = false;
DashCounter = 0;
}
if(Link->Dir == 0 && DashCheck(Link->X+8,Link->Y+6,true) == 0) Link->Y++;
else if(Link->Dir == 1 && DashCheck(Link->X+8,Link->Y+18,true) == 0) Link->Y--;
else if(Link->Dir == 2 && DashCheck(Link->X+18,Link->Y+8,false) == 0) Link->X++;
else if(Link->Dir == 3 && DashCheck(Link->X-2,Link->Y+8,false) == 0) Link->X--;
if(DashCounter < 5) Link->Z++;
}// end PegasusCollision if/else
DashCounter++;
}// end PegasusDash if
else{ // !PegasusDash
mysword = LoadLWeaponOf(LW_SCRIPT3);
Remove(mysword);
if(Link->Item[124]) Link->Item[124]=false;
}//end PegasusDash if/else
}//end function
int DashCheck(int x, int y, bool xy){
int xoffset; int yoffset;
bool Solid;
if(xy) xoffset = 4;
else yoffset = 3;
if(isSolid(x-xoffset,y-yoffset) || isSolid(x+xoffset,y+yoffset)) Solid = true;
if(Solid && DashSlash(x,y) ) Solid = false;
if(!Solid && !ComboFI(x-xoffset,y-yoffset,CF_DASH) && !ComboFI(x+xoffset,y+yoffset,CF_DASH)) return 0;
else if(Solid && (ComboFI(x-xoffset,y-yoffset,CF_DASH) || ComboFI(x+xoffset,y+yoffset,CF_DASH))) return 1;
else return 2;
}
bool DashSlash(int x, int y){
if(LinkSwordEquip() == -1) return false;
int loc;
loc = ComboAt(x, y);
if(Screen->ComboT[loc] == CT_BUSH || Screen->ComboT[loc] == CT_TALLGRASS ||
Screen->ComboT[loc] == CT_BUSHNEXT || Screen->ComboT[loc] == CT_TALLGRASSNEXT)
return true;
return false;
}
int LinkSwordEquip(){
itemdata itm = Game->LoadItemData( GetEquipmentA() );
if(itm->Family==IC_SWORD) return GetEquipmentA();
itm = Game->LoadItemData(GetEquipmentB());
if(itm->Family==IC_SWORD) return GetEquipmentB();
return -1;
}
// ..................................................................................................................................................................
int TouchedComboLoc(){
int loc;
loc = ComboAt( TouchedX(), TouchedY() );
return loc;
}
int TouchedX(){
int x;
if(Link->Dir == DIR_UP) x = Link->X+8;
else if(Link->Dir == DIR_DOWN) x = Link->X+8;
else if(Link->Dir == DIR_LEFT) x = Link->X-2;
else if(Link->Dir == DIR_RIGHT) x = Link->X+18;
return x;
}
int TouchedY(){
int y;
if(Link->Dir == DIR_UP) y = Link->Y+6;
else if(Link->Dir == DIR_DOWN) y = Link->Y+18;
else if(Link->Dir == DIR_LEFT) y = Link->Y+8;
else if(Link->Dir == DIR_RIGHT) y = Link->Y+8;
return y;
}
int CreateGraphicAt(int sprite, int x, int y){
eweapon e = Screen->CreateEWeapon(EW_SCRIPT1);
e->HitXOffset = 500;
e->UseSprite(sprite);
e->DeadState = e->NumFrames*e->ASpeed;
e->X = x;
e->Y = y;
return e->DeadState;
}
void ItemSetAt(int itemset,int loc){
npc e = Screen->CreateNPC(NPC_ITEMSET);
e->ItemSet = itemset;
if(e->isValid()){
e->X = loc%16*16;
e->Y = loc-loc%16;
}
e->HP = HP_SILENT;
}
bool isSolid(int x, int y){
if(x<0 || x>255 || y<0 || y>175) return false;
int mask=1111b;
if(x%16<8) mask&=0011b;
else mask&=1100b;
if(y%16<8) mask&=0101b;
else mask&=1010b;
return (!(Screen->ComboS[ComboAt(x, y)]&mask)==0);
}
// [ITEM] PEGASUS BOOTS -------------------------------------------------------------------------------------------------------------------------------------------
item script PegasusBoots
{
void run(){
if(ComboFI(Link->X+8,Link->Y+8,CF_DASH)) Quit();
if(Screen->ComboT[TouchedComboLoc()] == CT_WATER && !CanDrown) Quit();
if(Link->Action == LA_SWIMMING || Link->Action == LA_DROWNING) Quit();
//!!!!!!!!!! remove this if not using HoleLadder script
if(Falling) Quit();
//!!!!!!!!!! remove this if not using SideviewLadder script
if( Screen->ComboT[TouchedComboLoc()] == CT_SIDEVIEWLADDER || ComboFI(TouchedX(),TouchedY(),CF_LADDER) ) Quit();
PegasusDash = true;
if(Link->InputB && !Link->InputA) StoreInput = 2;
else if(Link->InputA && !Link->InputB) StoreInput = 1;
}
}