/*****************************************************************************
 * NPC Base
 ****************************************************************************/

class FriendlyShape : SquareMonster
{
	int frightcalmdown;

	const FRIGHTEN_TIME = 130; // 30-ish seconds. (this number is multiplied by 8 to get number of tics).

	Default
	{
		-COUNTKILL;
		+FRIENDLY;

		Health 100;
		Radius 16;
		Height 56;
		Mass 1000;
		Speed 8;
		PainChance 255;
		BloodColor "6f 00 6b";
		SeeSound "Blank";
		ActiveSound "Blank";
		PainSound "Blank";
		DeathSound "Blank";
	}
	States
	{
	Spawn:
		#### X 4 A_Look();
		Loop;
	See:
		#### A 0 A_JumpIf(bFrightened, "FrightenedSee");
		#### ABCD 4 A_Wander;
		Loop;
	FrightenedSee:
		#### H 0 SQ_FrightenCountdown();
		#### HIJK 2 A_Chase(NULL, NULL);
		Loop;
	Pain:
		#### E 4 SQ_Frighten();
		#### E 4 A_Pain();
		Goto See;
	Death:
	XDeath:
		#### E 0 A_NoBlocking();
		#### E 2 A_PlayerScream();
		#### E 2 A_SpawnItem("GibSpawnerNonPlayer");
		#### EE 0 A_SpawnItemEx(
			"GibEye",
			random[SquareGibRandom](-32,32), random[SquareGibRandom](-4,4), random[SquareGibRandom](4,12),
			random[SquareGibRandom](-4,4), random[SquareGibRandom](-4,4), random[SquareGibRandom](0,8),
			0
		);
		LEGS A 10;
		LEGS A -1 A_GiveToTarget("SquareVOFriends", 1);
		Stop;
	Death.Massacre:
		RIPM A 0 A_NoBlocking();
		RIPM A -1;
		Stop;
	}

	void SQ_Frighten()
	{
		self.frightcalmdown = FRIGHTEN_TIME;
		self.bStandStill = false;
		self.bFrightened = true;
	}

	state SQ_FrightenCountdown()
	{
		self.frightcalmdown--;
		if(self.frightcalmdown <= 0) {
			self.bFrightened = false;
			return ResolveState("See");
		}
		return ResolveState(null);
	}
}

/*****************************************************************************
 * Squares
 ****************************************************************************/

class FriendlySquare : FriendlyShape
{
	States
	{
	Spawn:
		SQUP X 0;
		Goto Super::Spawn;
	}
}

class FrightenedSquare : FriendlySquare
{
	States
	{
	Spawn:
		SQUP X 0 NoDelay SQ_Frighten();
		Goto Super::FrightenedSee;
	}
}

class FriendlySquareWorker : FriendlyShape
{
	States
	{
	Spawn:
		SQUH X 0;
		Goto Super::Spawn;
	}
}

class FrightenedSquareWorker : FriendlySquareWorker
{
	States
	{
	Spawn:
		SQUH X 0 NoDelay SQ_Frighten();
		Goto Super::FrightenedSee;
	}
}

/*****************************************************************************
 * Hexagons
 ****************************************************************************/

class FriendlyHexagon : FriendlyShape
{
	States
	{
	Spawn:
		HEXP X 0;
		Goto Super::Spawn;
	}
}

class FrightenedHexagon : FriendlyHexagon
{
	States
	{
	Spawn:
		HEXP X 0 NoDelay SQ_Frighten();
		Goto Super::FrightenedSee;
	}
}

class FriendlyHexagonWorker : FriendlyShape
{
	States
	{
	Spawn:
		HEXH X 0;
		Goto Super::Spawn;
	}
}

class FrightenedHexagonWorker : FriendlyHexagonWorker
{
	States
	{
	Spawn:
		HEXH X 0 NoDelay SQ_Frighten();
		Goto Super::FrightenedSee;
	}
}

/*****************************************************************************
 * Triangles
 ****************************************************************************/

class FriendlyTriangle : FriendlyShape
{
	States
	{
	Spawn:
		TRIP X 0;
		Goto Super::Spawn;
	}
}

class FrightenedTriangle : FriendlyTriangle
{
	States
	{
	Spawn:
		TRIP X 0 NoDelay SQ_Frighten();
		Goto Super::FrightenedSee;
	}
}

class FriendlyTriangleWorker : FriendlyShape
{
	States
	{
	Spawn:
		TRIH X 0;
		Goto Super::Spawn;
	}
}

class FrightenedTriangleWorker : FriendlyTriangleWorker
{
	States
	{
	Spawn:
		TRIH X 0 NoDelay SQ_Frighten();
		Goto Super::FrightenedSee;
	}
}
