var g_waterdrain = 0.04;
var g_waterdamage = 0.03;

var water_fireable = new Array();



function InWater(num)
{

	var t_layer;
  if (entities[num].vy > 2)
  {
    entities[num].vy-=1;
    
	}
    
  if (num==0)
  {
		if (g_fall_counter > 0)
		{
			g_fall_counter--;
			if (entities[num].vy <= 1)
				g_fall_counter = 0;
		}

		if (IsKeyPressed(CKEY_W) && entities[num].vy > -3 && entities[num].hp > 0)
		{
			t_layer = GetPersonIDLayer(entities[num].id1);
			SetPersonIDLayer(entities[num].id1, 0);

			if (IsPersonIDObstructed(entities[num].id1, entities[num].x, entities[num].y-1)==false)
				entities[num].vy-=0.75;

			SetPersonIDLayer(entities[num].id1, t_layer);

		}
  
  
		if ( IsXYInWater(entities[0].x,entities[0].y-8))
		{
			entities[0].stam-=g_waterdrain;
			if (entities[0].stam <  0)
			{
				entities[0].stam = 0;
				RemovePlayerHP(g_waterdamage, false);
			}
		}
  }


}


function IsEntityInWater(num)
{
	if (entities[num].type == 8 && entities[num].hp<= 0)
		return false;
	return IsXYInWater(entities[num].x,entities[num].y)
}

function IsEntityOnWater(num)
{
	if (entities[num].type == 8 && entities[num].hp<= 0)
		return false;

	if (IsXYInWater(entities[num].x,entities[num].y) == false && IsXYInWater(entities[num].x,entities[num].y+1) == true)
	{
		return true;
	}
	return false;
}

function IsXYInWater(x,y)
{
		var wx = Math.floor(x/GetTileWidth());
		var wy = Math.floor((y-4)/GetTileHeight());
		
		if (wx < 0 || wx>=GetLayerWidth(0) || wy < 0 || wy>=GetLayerHeight(0))
			return false;
		var wtile = GetTile(wx,wy, 6);
		
		if (wtile >= 1055 && wtile < 1158)
		{
			return true;
		}
		return false;
}