actor ExplosiveBarrelRB replaces ExplosiveBarrel
{
	Health 20
	Radius 10
	Height 48
	Speed 20
	PainChance 256
	+SOLID
	+SHOOTABLE
	+NOBLOOD
	+ACTIVATEMCROSS
	+DONTGIB
	+NOICEDEATH
	+OLDRADIUSDMG
	DeathSound "world/barrelx"
	BounceSound "runball/footstep"
	WallBounceSound "runball/jump"
	Obituary "$OB_BARREL"
    var int user_transformed;
	States
	{
		Spawn:
			BAR1 A 0
			TNT1 A 0 A_JumpIf(health <= 0, "Look")
			TNT1 A 0 ACS_NamedExecuteWithResult("MantainBarrelRunBall")
			TNT1 A 0 A_Jump(256, "Look")
		Look:
			TNT1 A 0 A_SetUserVar("user_transformed", 0)
		LookLoop:
			BAR1 AB 6
			TNT1 A 0 A_ChangeFlag("NOPAIN", !CallACS("CheckBarrelRunBallCanTransform"))
			TNT1 A 0 A_ChangeFlag("ISMONSTER", CallACS("CheckShouldTargetBarrelRunBalls"))
			TNT1 A 0 A_JumpIf(CallACS("CheckBarrelRunBallCanTransform") == 0 || random(0, 255) < 128, "LookLoop")
			TNT1 A 0 A_LookEx(0, 0, 512, 512, 360, "Transform")
			Loop
		Transform:
			TNT1 A 0 A_SetUserVar("user_transformed", 1)
			TNT1 A 0 ACS_NamedExecuteWithResult("RBTransformationAndThrustEffect")
			goto Jump
		Jump:
			EBRB QR 6 A_JumpIf(velz <= 0, "Fall")
			loop
		Fall:
			EBRB UV 6 A_CheckFloor("Land")
			loop
		Land:
			TNT1 A 0 ACS_NamedExecuteWithResult("PlayRunBallLandingSound")
			EBRB "YZ[" 4
			goto See
		Idle:
			EBRB A random(0, 1)
			TNT1 A 0 A_JumpIf(CallACS("CheckBarrelRunBallCanTransform") == 0, "Look")
			TNT1 A 0 A_ChangeFlag("ISMONSTER", CallACS("CheckShouldTargetBarrelRunBalls"))
			TNT1 A 0 A_Look
			TNT1 A 0 A_Jump(256, "SeeWander")
		See:
			EBRB A random(0, 1)
			TNT1 A 0 A_JumpIf(CallACS("CheckBarrelRunBallCanTransform") == 0, "Look")
			TNT1 A 0 A_ChangeFlag("ISMONSTER", CallACS("CheckShouldTargetBarrelRunBalls"))
			TNT1 A 0 A_JumpIf(CallACS("CheckBarrelRunBallWander") == 1, "SeeWander")
			TNT1 A 0 A_JumpIf(CallACS("CheckBarrelRunBallMelee") == 0, "SeeNoMelee")
			TNT1 A 0 A_Jump(256, "SeeUsual")
		SeeUsual:
			EBRB ABCDEFGH 1 A_Chase
			TNT1 A 0 ACS_NamedExecuteWithResult("PlayRunBallFootstepSound")
			EBRB IJKLMNOP 1 A_Chase
			TNT1 A 0 ACS_NamedExecuteWithResult("PlayRunBallFootstepSound")
			TNT1 A 0 A_Jump(256, "See")
		SeeWander:
			EBRB ABCDEFGH 1 A_Wander
			TNT1 A 0 ACS_NamedExecuteWithResult("PlayRunBallFootstepSound")
			EBRB IJKLMNOP 1 A_Wander
			TNT1 A 0 ACS_NamedExecuteWithResult("PlayRunBallFootstepSound")
			TNT1 A 0 A_Jump(256, "See")
		SeeNoMelee:
			EBRB ABCDEFGH 1 A_Chase("")
			TNT1 A 0 ACS_NamedExecuteWithResult("PlayRunBallFootstepSound")
			EBRB IJKLMNOP 1 A_Chase("")
			TNT1 A 0 ACS_NamedExecuteWithResult("PlayRunBallFootstepSound")
			TNT1 A 0 A_Jump(256, "See")
		Melee:
			TNT1 A 0 A_Die
			stop
		Pain:
			TNT1 A 0 A_JumpIf(CallACS("CheckBarrelRunBallCanTransform") && user_transformed == 0, "Transform")
			EBRB X 8 A_Pain
			TNT1 A 0 A_Jump(256, "See")
		Death:
			BEXP A 0 A_JumpIf(user_transformed != 0, "DeathTransformed")
			goto DeathActual
		DeathTransformed:
			EBRD A 0
		DeathActual:
			"####" A 5 Bright
			"####" B 5 Bright A_Scream
			"####" C 5 Bright
			"####" D 5 Bright A_Explode
			"####" E 10 Bright
			TNT1 A 1050 Bright A_BarrelDestroy
			TNT1 A 5 A_Respawn
			Wait
	}
}