//stdCombos.zh
//
//This header is used to detect collision between various in-game objects and combos.
//Return INT means return location of combo that has tripped collision.
//
//v1.0 BETA


// Returns TRUE if there is a collision between FFC and a combo on screen.
bool ComboCollision (int loc, ffc f){
	int ax = (f->X);
	int ay = (f->Y);
	int bx = (f->X)+(f->EffectWidth);
	int by = (f->Y)+(f->EffectHeight);
	return RectCollision( ComboX(loc), ComboY(loc), (ComboX(loc)+16), (ComboY(loc)+16), ax, ay, bx, by);
}

// Returns INT if FFC collides with a combo of specific type
int ComboTypeCollision (int type, ffc f){
	for (int i=0; i<176; i++){
		if (Screen->ComboT[i]==type){
			if (ComboCollision(i, f)) return i;
		}
	}
	return -1;
}

// Returns INT if FFC collides with a combo which has specific placed flag
int ComboFlagCollision (int flag, ffc f){
	for (int i = 0; i<176; i++){
		if (Screen->ComboF[i]==flag){
			if (ComboCollision(i, f)) return i;
		}
	}
	return -1;
}

// Returns INT if FFC collides with a combo which has specific inherent flag. 
int ComboIFlagCollision (int flag, ffc f){
	for (int i = 0; i<176; i++){
		if (Screen->ComboI[i]==flag){
			if (ComboCollision(i, f)) return i;
		}
	}
	return -1;
}

// Returns INT if FFC collides with a combo which has specific either inherent or placed flag.
int ComboAnyFlagCollision (int flag, ffc f){
	for (int i = 0; i<176; i++){
		if (ComboFI(i, flag)){
			if (ComboCollision(i, f)) return i;
		}
	}
	return -1;
}

// Returns TRUE if there is a collision between Lweapon and a combo on screen.
bool ComboCollision (int loc, lweapon f){
	if (!(f->CollDetection)) return false;
	int ax = (f->X)+f->HitXOffset;
	int ay = (f->Y)+f->HitYOffset;
	int bx = (f->X)+f->HitWidth;
	int by = (f->Y)+f->HitHeight;
	return RectCollision( ComboX(loc), ComboY(loc), (ComboX(loc)+16), (ComboY(loc)+16), ax, ay, bx, by);
}

// Returns INT if Lweapon collides with a combo of specific type
int ComboTypeCollision (int type, lweapon f){
	for (int i=0; i<176; i++){
		if (Screen->ComboT[i]==type){
			if (ComboCollision(i, f)) return i;
		}
	}
	return -1;
}

// Returns INT if Lweapon collides with a combo which has specific placed flag
int ComboFlagCollision (int flag, lweapon f){
	for (int i = 0; i<176; i++){
		if (Screen->ComboF[i]==flag){
			if (ComboCollision(i, f)) return i;
		}
	}
	return -1;
}

// Returns INT if Lweapon collides with a combo which has specific inherent flag. 
int ComboIFlagCollision (int flag, lweapon f){
	for (int i = 0; i<176; i++){
		if (Screen->ComboI[i]==flag){
			if (ComboCollision(i, f)) return i;
		}
	}
	return -1;
}

// Returns INT if Lweapon collides with a combo which has specific either inherent or placed flag.
int ComboAnyFlagCollision (int flag, lweapon f){
	for (int i = 0; i<176; i++){
		if (ComboFI(i, flag)){
			if (ComboCollision(i, f)) return i;
		}
	}
	return -1;
}

// Returns TRUE if there is a collision between Eweapon and a combo on screen.
bool ComboCollision (int loc, eweapon f){
	int ax = (f->X)+(f->HitXOffset);
	int ay = (f->Y)+(f->HitYOffset);
	int bx = (f->X)+(f->HitWidth);
	int by = (f->Y)+(f->HitHeight);
	if (!(f->CollDetection)) return false;
	return RectCollision( ComboX(loc), ComboY(loc), (ComboX(loc)+16), (ComboY(loc)+16), ax, ay, bx, by);
}

// Returns INT if EWeapon collides with a combo of specific type
int ComboTypeCollision (int type, eweapon f){
	for (int i=0; i<176; i++){
		if (Screen->ComboT[i]==type){
			if (ComboCollision(i, f)) return i;
		}
	}
	return -1;
}

// Returns INT if EWeapon collides with a combo which has specific placed flag
int ComboFlagCollision (int flag, eweapon f){
	for (int i = 0; i<176; i++){
		if (Screen->ComboF[i]==flag){
			if (ComboCollision(i, f)) return i;
		}
	}
	return -1;
}

// Returns INT if EWeapon collides with a combo which has specific inherent flag.
int ComboIFlagCollision (int flag, eweapon f){
	for (int i = 0; i<176; i++){
		if (Screen->ComboI[i]==flag){
			if (ComboCollision(i, f)) return i;
		}
	}
	return -1;
}

// Returns INT if EWeapon collides with a combo which has specific either inherent or placed flag.
int ComboAnyFlagCollision (int flag, eweapon f){
	for (int i = 0; i<176; i++){
		if (ComboFI(i, flag)){
			if (ComboCollision(i, f)) return i;
		}
	}
	return -1;
}

// Returns TRUE if there is a collision between NPC and a combo on screen.
bool ComboCollision (int loc, npc f){
	int ax = (f->X)+(f->HitXOffset);
	int ay = (f->Y)+(f->HitYOffset);
	int bx = (f->X)+(f->HitWidth);
	int by = (f->Y)+(f->HitHeight);
	if (!(f->CollDetection)) return false;
	return RectCollision( ComboX(loc), ComboY(loc), (ComboX(loc)+16), (ComboY(loc)+16), ax, ay, bx, by);
}

// Returns INT if NPC collides with a combo of specific type
int ComboTypeCollision (int type, npc f){
	for (int i=0; i<176; i++){
		if (Screen->ComboT[i]==type){
			if (ComboCollision(i, f)) return i;
		}
	}
	return -1;
}

// Returns INT if NPC collides with a combo which has specific inherent flag.
int ComboFlagCollision (int flag, npc f){
	for (int i = 0; i<176; i++){
		if (Screen->ComboF[i]==flag){
			if (ComboCollision(i, f)) return i;
		}
	}
	return -1;
}

// Returns INT if NPC collides with a combo which has specific inherent flag.
int ComboIFlagCollision (int flag, npc f){
	for (int i = 0; i<176; i++){
		if (Screen->ComboI[i]==flag){
			if (ComboCollision(i, f)) return i;
		}
	}
	return -1;
}

// Returns INT if EWeapon collides with a combo which has specific either inherent or placed flag.
int ComboAnyFlagCollision (int flag, npc f){
	for (int i = 0; i<176; i++){
		if (ComboFI(i, flag)){
			if (ComboCollision(i, f)) return i;
		}
	}
	return -1;
}

//Returns TRUE if there is a collision between Link and the combo.
bool LinkComboCollision(int loc, int sens){
	int ax = Link->X;
	int ay = Link->Y;
	int bx = (Link->X)+(Link->HitWidth);
	int by = (Link->Y)+(Link->HitHeight);
	if(!(RectCollision( ComboX(loc), ComboY(loc), (ComboX(loc)+16), (ComboY(loc)+16), ax, ay, bx, by))) return false;
	else if (!(Distance(CenterLinkX(), CenterLinkY(), (ComboX(loc)+8), (ComboY(loc)+8)) < (sens+8))) return false;
	else return true;
}

//Same as LinkComboCollision, but only bottom half is checked.
bool LinkComboStepped(int loc, int sens){
	int ax = Link->X;
	int ay = (Link->Y)+8;
	int bx = (Link->X)+(Link->HitWidth);
	int by = (Link->Y)+((Link->HitHeight)/2);
	if(!(RectCollision( ComboX(loc), ComboY(loc), (ComboX(loc)+16), (ComboY(loc)+16), ax, ay, bx, by))) return false;
	else if (!(Distance(CenterLinkX(), CenterLinkY(), (ComboX(loc)+8), (ComboY(loc)+8)) < (sens+8))) return false;
	else return true;
}

//Returns INT if Link touches any combo of specific type.
int LinkComboTypeCollision(int type, int sens){
	for(int i = 0; i < 176; i++){
		if (Screen->ComboT[i]==type){
			if (LinkComboCollision(i, sens)) return i;
		}
	}
	return -1;
}

//Returns INT if Link steps on any combo of specific type.
int LinkComboTypeStepped(int type, int sens){
	for(int i = 0; i < 176; i++){
		if (Screen->ComboT[i]==type){
			if (LinkComboStepped(i, sens)) return i;
		}
	}
	return -1;
}


//Returns INT if Link touches any combo with specific placed flag.
int LinkComboFlagCollision(int flag, int sens){
	for(int i = 0; i < 176; i++){
		if (Screen->ComboF[i]==flag){
			if (LinkComboCollision(i, sens)) return i;
		}
	}
	return -1;
}

//Returns INT if Link steps on any combo with specific placed flag.
int LinkComboFlagStepped(int flag, int sens){
	for(int i = 0; i < 176; i++){
		if (Screen->ComboF[i]==flag){
			if (LinkComboStepped(i, sens)) return i;
		}
	}
	return -1;
}

//Returns INT if Link touches any combo with specific inherent flag.
int LinkComboIFlagCollision(int flag, int sens){
	for(int i = 0; i < 176; i++){
		if (Screen->ComboI[i]==flag){
			if (LinkComboCollision(i, sens)) return i;
		}
	}
	return -1;
}

//Returns INT if Link steps on any combo with specific inherent flag.
int LinkComboIFlagStepped(int flag, int sens){
	for(int i = 0; i < 176; i++){
		if (Screen->ComboI[i]==flag){
			if (LinkComboStepped(i, sens)) return i;
		}
	}
	return -1;
}

//Returns INT if Link touches any combo with specific either inherent or placed flag.
int LinkComboAnyFlagCollision(int flag, int sens){
	for(int i = 0; i < 176; i++){
		if (ComboFI(i, flag)){
			if (LinkComboCollision(i, sens)) return i;
		}
	}
	return -1;
}

//Returns INT if Link steps on any combo with specific either inherent or placed flag.
int LinkComboAnyFlagStepped(int flag, int sens){
	for(int i = 0; i < 176; i++){
		if (ComboFI(i, flag)){
			if (LinkComboStepped(i, sens)) return i;
		}
	}
	return -1;
}
