class AngleFish : SquareMonster
{
	Default
	{
		Health 30;
		Radius 16;
		Height 32;
		MaxStepHeight 0;
		Damage 2;
		Speed 6;
		FastSpeed 10;
		+MISSILEMORE;
		+FLOAT;
		+NOGRAVITY;
		-COUNTKILL;
		BloodColor "c5 73 55";
		ActiveSound "anglefish/active";
		DeathSound "anglefish/death";
		MeleeRange 80;
		Obituary "$OB_ANGLEFISH";
	}
	States
	{
	Spawn:
		ANGL A 1 A_Look();
		Loop;
	See:
		ANGL A 1 SQ_WaterCheck();
		ANGL A 1 SQ_AnglefishChase();
		ANGL A 0 SQ_SpawnBubble(192);
		Loop;
	Missile:
		ANGL A 10 A_FaceTarget();
		ANGL B 1 SQ_AnglefishChargeStart();
		ANGL BBBB 1 SQ_WaterCheck();
		ANGL B 1 SQ_AnglefishCharge();
		ANGL BBBB 1 SQ_WaterCheck();
		ANGL A 1 SQ_AnglefishBite();
		ANGL AAAA 1 SQ_WaterCheck();
		ANGL A 1 SQ_AnglefishCharge();
		ANGL AAAA 1 SQ_WaterCheck();
		ANGL A 0 A_Jump(16, "See");
		Loop;
	Surface:
		ANGL A 0 SQ_PauseSwimming();
		ANGL AAAA 6 A_Wander();
		ANGL A 0 SQ_ResumeSwimming();
		Goto See;
	Pain:
		ANGL C 4 SQ_SpawnBubble();
		Goto See;
	Death:
		ANGL C 2 A_Scream();
		ANGL C 2 A_SpawnItem("GibSpawnerAngleFish");
		Stop;
	}
/*
	override void Tick()
	{
		// [XA] At some point I want to re-refactor this to use this method.
		//      I'll need to add a "fish out of water" state first, and this
		//      is a behavior change, so that goes into the "do later" bucket.
		super.Tick();
		if(waterlevel <= 2) {
			self.vel.z = -5;
		}
	}
*/
	void SQ_SpawnBubble(int failchance = 0)
	{
		// [XA] I may elevate this to SquareActor if the parameters are uber-common.
		A_SpawnItemEx("Bubble1", 0, 0, 0, frandom[SquareEffectRandom](-0.5, 0.5), frandom[SquareEffectRandom](-0.5, 0.5), random[SquareEffectRandom](1,3), 0, 0, failchance);
	}

	state SQ_WaterCheck()
	{
		if(waterlevel <= 2) {
			return ResolveState("Surface");
		}
		return null;
	}

	state SQ_AnglefishChase()
	{
		self.bFloat = true; // in case a target was lost/regained in the Surface state.
		A_Chase();
		return SQ_WaterCheck();
	}

	state SQ_AnglefishChargeStart()
	{
		A_Stop();
		A_PlaySound("anglefish/charge");
		A_Recoil(-10);
		return SQ_WaterCheck();
	}

	state SQ_AnglefishCharge()
	{
		A_Recoil(-10);
		return SQ_WaterCheck();
	}

	state SQ_AnglefishBite()
	{
		A_Recoil(-10);
		A_CustomMeleeAttack(3*random(1,8), "anglefish/melee");
		return SQ_WaterCheck();
	}

	void SQ_PauseSwimming()
	{
		self.bNoPain = true;
		self.bFloat = false;
		self.vel = (0, 0, -5);
	}

	void SQ_ResumeSwimming()
	{
		self.bNoPain = false;
		self.bFloat = true;
	}
}
