import "std.zh"
import "string.zh"
import "ffcscript.zh"
import "ghost.zh"
//Test if one location is between two others.
//D0- Location to test
//D1- Lower bound
//D2- Higher bound
bool Between(int loc,int greaterthan, int lessthan){
if(loc>=greaterthan && loc<=lessthan)return true;
return false;
}
//Gale Fruit
const int GALE_FRUIT_SCRIPT = 4;//Script run by gale fruit.
const int GALE_COMBO = 83;//Combo of moving gale.
const int GALE_PORTAL_COMBO = 696;//Combo of unopened portal.
const int GALE_WARP_COMBO = 936;//Combo of opened portal.
const int GALE_SFX = 59;//Sound to make when using item.
const int GALE_WARP_SFX = 83;//Sound to make when warping.
const int GALE_WARP_MISC_INDEX = 0;//Misc ffc index to store X coords in.
//Test if this combo is a warp entry.
bool IsEntry(int loc){
if(Between(Screen->ComboF[loc],CF_SECRETS01,CF_SECRETS08)
&& Screen->ComboT[loc]==CT_SCRIPT1)return true;
return false;
}
//Test if this combo is warp exit.
bool IsExit(int loc){
if(Between(Screen->ComboF[loc],CF_SECRETS09,CF_SECRETS16)
&& Screen->ComboT[loc]==CT_SCRIPT1)return true;
return false;
}
item script Gale_Fruit{
void run(){
Game->PlaySound(GALE_SFX);//Play a sound.
//Launch ffc script.
int args[8];
ffc launch = RunFFCScriptOrQuit(GALE_FRUIT_SCRIPT, args);
}
}
ffc script GaleFruit{
void run(){
int i;
this->Data = GALE_COMBO;
this->Misc[GALE_WARP_MISC_INDEX]= -1;
//Put in front of Link.
this->X = Link->X+ InFrontX(Link->Dir,2);
this->Y = Link->Y+ InFrontY(Link->Dir,2);
//Save coords for entry and exit.
int EntryX[8];
int EntryY[8];
int ExitX[8];
int ExitY[8];
//Determine value of coords.
for ( i = 0; i < 175; i++ ){
if(IsEntry(i)){
if(Screen->ComboF[i]==CF_SECRETS01){
EntryX[0] = ComboX(i);
EntryY[0] = ComboY(i);
}
else if(Screen->ComboF[i]==CF_SECRETS02){
EntryX[1] = ComboX(i);
EntryY[1] = ComboY(i);
}
else if(Screen->ComboF[i]==CF_SECRETS03){
EntryX[2] = ComboX(i);
EntryY[2] = ComboY(i);
}
else if(Screen->ComboF[i]==CF_SECRETS04){
EntryX[3] = ComboX(i);
EntryY[3] = ComboY(i);
}
else if(Screen->ComboF[i]==CF_SECRETS05){
EntryX[4] = ComboX(i);
EntryY[4] = ComboY(i);
}
else if(Screen->ComboF[i]==CF_SECRETS06){
EntryX[5] = ComboX(i);
EntryY[5] = ComboY(i);
}
else if(Screen->ComboF[i]==CF_SECRETS07){
EntryX[6] = ComboX(i);
EntryY[6] = ComboY(i);
}
else if(Screen->ComboF[i]==CF_SECRETS08){
EntryX[7] = ComboX(i);
EntryY[7] = ComboY(i);
}
}
if(IsExit(i)){
if(Screen->ComboF[i]==CF_SECRETS09){
ExitX[0] = ComboX(i);
ExitY[0] = ComboY(i);
}
else if(Screen->ComboF[i]==CF_SECRETS10){
ExitX[1] = ComboX(i);
ExitY[1] = ComboY(i);
}
else if(Screen->ComboF[i]==CF_SECRETS11){
ExitX[2] = ComboX(i);
ExitY[2] = ComboY(i);
}
else if(Screen->ComboF[i]==CF_SECRETS12){
ExitX[3] = ComboX(i);
ExitY[3] = ComboY(i);
}
else if(Screen->ComboF[i]==CF_SECRETS13){
ExitX[4] = ComboX(i);
ExitY[4] = ComboY(i);
}
else if(Screen->ComboF[i]==CF_SECRETS14){
ExitX[5] = ComboX(i);
ExitY[5] = ComboY(i);
}
else if(Screen->ComboF[i]==CF_SECRETS15){
ExitX[6] = ComboX(i);
ExitY[6] = ComboY(i);
}
else if(Screen->ComboF[i]==CF_SECRETS16){
ExitX[7] = ComboX(i);
ExitY[7] = ComboY(i);
}
}
}
int SavedDir = Link->Dir;//Remember what direction Link was facing.
bool Moving = true;//The gale is moving.
bool Warping = false;//You're not warping yet.
//Set speed of movement.
if(SavedDir==DIR_UP){
this->Vy = -1;
this->Vx = 0;
}
else if(SavedDir == DIR_DOWN){
this->Vy = 1;
this->Vx = 0;
}
else if(SavedDir == DIR_LEFT){
this->Vx = -1;
this->Vy = 0;
}
else{
this->Vx= 1;
this->Vy = 0;
}
//Moving now.
while(Moving){
for(i=0;i<7;i++){
//The ffc has met a portal entry.
//Change to a warp.
if(Between(this->X+8,EntryX[i],EntryX[i]+16) && Between(this->Y+8,EntryY[i],EntryY[i]+16)){
Screen->ComboD[ComboAt(EntryX[i],EntryY[i])]= GALE_WARP_COMBO;
Screen->ComboD[ComboAt(ExitX[i],ExitY[i])]= GALE_WARP_COMBO;
this->Misc[GALE_WARP_MISC_INDEX]= i;
}
else if(Between(this->X+8,ExitX[i],ExitX[i]+16) && Between(this->Y+8,ExitY[i],ExitY[i]+16)){
Screen->ComboD[ComboAt(EntryX[i],EntryY[i])]= GALE_WARP_COMBO;
Screen->ComboD[ComboAt(ExitX[i],ExitY[i])]= GALE_WARP_COMBO;
this->Misc[GALE_WARP_MISC_INDEX]= i;
}
}
//The ffc has gone off the screen. Kill it.
if(this->X<0||this->Y<0||this->X>256||this->Y>176)Quit();
//A warp portal exists.
if(this->Misc[GALE_WARP_MISC_INDEX]!=-1){
Moving = false;//Stop moving.
Warping = true;//Start warping.
//Kill momentum.
this->Vx = 0;
this->Vy = 0;
this->Data = GH_INVISIBLE_COMBO;
}
Waitframe();
}
//Time to warp.
while(Warping){
Screen->DrawCombo(1, ExitX[this->Misc[GALE_WARP_MISC_INDEX]], ExitY[this->Misc[GALE_WARP_MISC_INDEX]], GALE_COMBO, 1, 1, -1, -1, -1, 0, 0, 0, -1, 0, true, 128);
Screen->DrawCombo(1, EntryX[this->Misc[GALE_WARP_MISC_INDEX]], EntryY[this->Misc[GALE_WARP_MISC_INDEX]], GALE_COMBO, 1, 1, -1, -1, -1, 0, 0, 0, -1, 0, true, 128);
//Link has stepped on a warp tile.
if(Between(Link->X+8,EntryX[this->Misc[GALE_WARP_MISC_INDEX]],EntryX[this->Misc[GALE_WARP_MISC_INDEX]]+16)
&& Between(Link->Y+8,EntryY[this->Misc[GALE_WARP_MISC_INDEX]],EntryY[this->Misc[GALE_WARP_MISC_INDEX]]+16)
&& Screen->ComboD[ComboAt(EntryX[this->Misc[GALE_WARP_MISC_INDEX]],EntryY[this->Misc[GALE_WARP_MISC_INDEX]])]==GALE_WARP_COMBO){
//Change combo appearance.
Screen->ComboD[ComboAt(EntryX[this->Misc[GALE_WARP_MISC_INDEX]],EntryY[this->Misc[GALE_WARP_MISC_INDEX]])]= GALE_PORTAL_COMBO;
Screen->ComboD[ComboAt(ExitX[this->Misc[GALE_WARP_MISC_INDEX]],ExitY[this->Misc[GALE_WARP_MISC_INDEX]])]= GALE_PORTAL_COMBO;
//Move Link to exit warp.
Link->X = ExitX[this->Misc[GALE_WARP_MISC_INDEX]];
Link->Y = ExitY[this->Misc[GALE_WARP_MISC_INDEX]];
Game->PlaySound(GALE_WARP_SFX);//Play a sound.
Warping = false;//Not warping.
}
else if(Between(Link->X+8,ExitX[this->Misc[GALE_WARP_MISC_INDEX]],ExitX[this->Misc[GALE_WARP_MISC_INDEX]]+16)
&& Between(Link->Y+8,ExitY[this->Misc[GALE_WARP_MISC_INDEX]],ExitY[this->Misc[GALE_WARP_MISC_INDEX]]+16)
&& Screen->ComboD[ComboAt(ExitX[this->Misc[GALE_WARP_MISC_INDEX]],ExitY[this->Misc[GALE_WARP_MISC_INDEX]])]==GALE_WARP_COMBO){
//Change combo appearance.
Screen->ComboD[ComboAt(EntryX[this->Misc[GALE_WARP_MISC_INDEX]],EntryY[this->Misc[GALE_WARP_MISC_INDEX]])]= GALE_PORTAL_COMBO;
Screen->ComboD[ComboAt(ExitX[this->Misc[GALE_WARP_MISC_INDEX]],ExitY[this->Misc[GALE_WARP_MISC_INDEX]])]= GALE_PORTAL_COMBO;
//Move Link to exit warp.
Link->X = EntryX[this->Misc[GALE_WARP_MISC_INDEX]];
Link->Y = EntryY[this->Misc[GALE_WARP_MISC_INDEX]];
Game->PlaySound(GALE_WARP_SFX);//Play a sound.
Warping = false;//Not warping.
}
Waitframe();
}
//Kill the ffc.
this->Data = 0;
Quit();
}
}