#define  COMMON_VEHI_H aaa
//----------------------------------------------------------------------------
//  @brief
//        обработка пересечения с битой и прочее
//        

//  @ingroup
    
//  2006Oct17 created. Zmanovsky Peter.
//  (C) 2006    Sigma-Team
//-----------------------------------------------------------------------------

#ifndef CONST_VEHI_H
	#include "maps\const_vehi.lgc"
#endif

//------------------------------------------------------------------------------------------
//следующие функции возвращают границы для использования в FirstInBox
GetFIB_X1() { return GetX(PlayerVehi) - 150; }
GetFIB_X2() { return GetX(PlayerVehi) + 150; }
GetFIB_Y1() { return GetY(PlayerVehi)-GetZ(PlayerVehi) - 100; }
GetFIB_Y2() { return GetY(PlayerVehi)-GetZ(PlayerVehi) + 100; }

//------------------------------------------------------------------------------------------
IntersectWithVehi(int unit, bool bCheckZ, bool bIncYSize)
{
	if(!unit || !PlayerVehi)
		return false;
	//
    int shield; shield = Action(PlayerVehi, ACT_GET_LINK);
	int size_x; size_x = GetVidData(GetUnitVid(shield), VID_SIZE_X)/2;
	int size_y; size_y = GetVidData(GetUnitVid(shield), VID_SIZE_Y)/2;
	size_x += GetVidData(GetUnitVid(unit), VID_SIZE_X)/2;
	size_y += GetVidData(GetUnitVid(unit), VID_SIZE_Y)/2;
	if(bIncYSize)
		size_y += 15;
	//
	int unitY; unitY = GetY(unit);
	int vehiY; vehiY = GetY(shield);
	if(bCheckZ)
	{
		unitY = unitY -GetZ(unit);
		vehiY = vehiY -GetZ(shield);
	}
	//
    if( unitY >= vehiY-size_y && unitY <= vehiY+size_y
     && GetX(unit) >= GetX(shield)-size_x && GetX(unit) <= GetX(shield)+size_x )
    {
		return true;
	}
	//
	return false;
}


//------------------------------------------------------------------------------------------
IntersectObjObj(int unit1, int unit2, bool bCheckZ)
{
	if(!unit1 || !unit2)
		return false;
	//
	int size_x; size_x = GetVidData(GetUnitVid(unit1), VID_SIZE_X)/2;
	int size_y; size_y = GetVidData(GetUnitVid(unit1), VID_SIZE_Y)/2;
	size_x += GetVidData(GetUnitVid(unit2), VID_SIZE_X)/2;
	size_y += GetVidData(GetUnitVid(unit2), VID_SIZE_Y)/2;
	//
	int unit1Y; unit1Y = GetY(unit1);
	int unit2Y; unit2Y = GetY(unit2);
	if(bCheckZ)
	{
		unit1Y = unit1Y - GetZ(unit1);
		unit2Y = unit2Y - GetZ(unit2);
	}
	//
    if( unit2Y >= unit1Y-size_y && unit2Y <= unit1Y+size_y
     && GetX(unit2) >= GetX(unit1)-size_x && GetX(unit2) <= GetX(unit1)+size_x )
    {
		return true;
	}
	//
	return false;
}


//------------------------------------------------------------------------------------------
InitPhysics()
{
	iff(1)
	{
		Call_ii(EXT_SETVEHIRADIUS, HORIZ_RADIUS_DEFAULT, VERT_RADIUS_DEFAULT);
		Call_ii(EXT_SetPhys2, EDGE_BOUNCE_ANGLE, BOUNCE_AREAS_CNT);
	}
}


//------------------------------------------------------------------------------------------
DamageVehiByBullet(int iVid)
{
	bool ret; ret = false;
	int unit2;
	if(PlayerVehi)
	{
		unit2 = FindNearestSprite(GETSPRITE_VID+iVid, GetX(PlayerVehi), GetY(PlayerVehi)-GetZ(PlayerVehi), 200);
		if(unit2 && IntersectWithVehi(unit2, true, true))
		{
			Action(unit2, ANI_DEATH);
			ret = true;
		}
	}
	//
	return ret;
}


//------------------------------------------------------------------------------------------
FreezeVehi(int iTime)
{
	if(!giFreezeEffect)
		giFreezeEffect = CreateEffect(PlayerVehi, 432, 15);
	giUnFreezeTime = GetTime() + iTime;
}


//------------------------------------------------------------------------------------------
UnFreezeVehiIfNeed()
{
	bool bDelEffect = false;
	//
	if(!PlayerVehi)
		bDelEffect = true;

	//если пришло время разморозить
	if(giUnFreezeTime && giUnFreezeTime <= GetTime())
	{
		giUnFreezeTime = 0;
		bDelEffect = true;
	}

	//убиваем заморозку за некоторое время до разморозки
	if(giFreezeEffect && giUnFreezeTime-200 <= GetTime())
		bDelEffect = true;

	//
	if(bDelEffect && giFreezeEffect)
	{
		Action(giFreezeEffect, ANI_DEATH);
		giFreezeEffect = 0;
	}
}

