freeslot("MT_BM_WRECKER", "S_BM_WRECKER_STAND", "S_BM_WRECKER_FLOAT", "S_BM_WRECKER_STARTATTACK", "S_BM_WRECKER_FALLATATTACK", "S_BM_WRECKER_ATTACK", "S_BM_WRECKER_FINISHATTACK", "S_BM_WRECKER_RELOAD", "S_BM_WRECKER_PAIN", "SPR_BMB1", "S_BM_WRECKER_RANDOM1", "S_BM_WRECKER_SUPERATTACK", "S_BM_WRECKER_SUPERSTARTATTACK", "S_BM_WRECKER_SUPERFINISHATTACK", "S_BM_WRECKER_RELOAD1", "S_BM_WRECKER_HOT", "S_BM_WRECKER_RELOAD2", "S_BM_WRECKER_RELOAD3", "S_BM_WRECKER_RELOAD4", "S_BM_WRECKER_RELOAD5", "S_BM_WRECKER_RELOAD6", "S_BM_WRECKER_RELOAD7")

addHook("MobjThinker", function(boss)
	if boss
	and boss.valid
	and boss.health
	and boss.type == MT_BM_WRECKER
		boss.scale = 57000
		if (boss.state == S_BM_WRECKER_RELOAD)
		boss.angle = R_PointToAngle2(boss.x, boss.y, boss.target.x, boss.target.y)
		boss.momz = 1*FRACUNIT
		boss.scale = 57000
		if (boss.flags & MF_PAIN)
		boss.flags = $1 & ~MF_PAIN
		end
		end
		if (boss.state == S_BM_WRECKER_RELOAD1)
		boss.angle = R_PointToAngle2(boss.x, boss.y, boss.target.x, boss.target.y)
		boss.momz = 1*FRACUNIT
		end
		if (boss.state == S_BM_WRECKER_RELOAD2)
		boss.angle = R_PointToAngle2(boss.x, boss.y, boss.target.x, boss.target.y)
		boss.momz = 1*FRACUNIT
		end
		if (boss.state == S_BM_WRECKER_RELOAD3)
		boss.angle = R_PointToAngle2(boss.x, boss.y, boss.target.x, boss.target.y)
		boss.momz = 2*FRACUNIT
		end
		if (boss.state == S_BM_WRECKER_RELOAD4)
		boss.angle = R_PointToAngle2(boss.x, boss.y, boss.target.x, boss.target.y)
		boss.momz = 2*FRACUNIT
		end
		if (boss.state == S_BM_WRECKER_RELOAD5)
		boss.angle = R_PointToAngle2(boss.x, boss.y, boss.target.x, boss.target.y)
		boss.momz = 2*FRACUNIT
		end
		if (boss.state == S_BM_WRECKER_RELOAD6)
		boss.angle = R_PointToAngle2(boss.x, boss.y, boss.target.x, boss.target.y)
		boss.momz = 2*FRACUNIT
		end
		if (boss.state == S_BM_WRECKER_RELOAD7)
		boss.angle = R_PointToAngle2(boss.x, boss.y, boss.target.x, boss.target.y)
		if (boss.flags & MF_NOGRAVITY)
		boss.flags = $1 & ~MF_NOGRAVITY
		end
		end
		if (boss.state == S_BM_WRECKER_HOT)
		boss.angle = R_PointToAngle2(boss.x, boss.y, boss.target.x, boss.target.y)
		end
		if (boss.state == S_BM_WRECKER_STARTATTACK)
		boss.momz = 0
		boss.momx = 0
		boss.momy = 0
		boss.angle = R_PointToAngle2(boss.x, boss.y, boss.target.x, boss.target.y)
		P_SetObjectMomZ(boss, 8*FRACUNIT)
		if not S_SoundPlaying(boss, sfx_cdfm39)
		S_StartSound(boss, sfx_cdfm39)
		end
		if (boss.flags & MF_SHOOTABLE)
		boss.flags = $1 & ~MF_SHOOTABLE
		end
		end
		if (boss.state == S_BM_WRECKER_FALLATATTACK)
			for boss in mobjs.iterate()
				if boss
				and boss.valid
				and boss.health
				and boss.type == MT_BM_WRECKER
					if P_IsObjectOnGround(boss)
					and (boss.state == S_BM_WRECKER_FALLATATTACK)
					boss.state = S_BM_WRECKER_ATTACK
					end
				end
			end
		end
		if (boss.state == S_BM_WRECKER_ATTACK)
		boss.angle = boss.angle+ANG10
		P_SpawnGhostMobj(boss)
			if P_IsObjectOnGround(boss)
			P_Earthquake(boss, boss, 120*FRACUNIT)
			local jumpheight = P_RandomRange(8,14)*FRACUNIT
			P_SetObjectMomZ(boss, jumpheight)
			local bmwinstathrust = P_RandomRange(10,20)*FRACUNIT
			P_InstaThrust(boss, R_PointToAngle2(boss.x, boss.y, boss.target.x, boss.target.y), bmwinstathrust)
			S_StartSound(boss, sfx_s3k49)
			end
		end
		if (boss.state == S_BM_WRECKER_FINISHATTACK)
			for boss in mobjs.iterate()
				if boss
				and boss.valid
				and boss.health
				and boss.type == MT_BM_WRECKER
					boss.momx = 0
					boss.momy = 0
					P_SetObjectMomZ(boss, -12*FRACUNIT)
					if P_IsObjectOnGround(boss)
					and (boss.state == S_BM_WRECKER_FINISHATTACK)
					boss.state = S_BM_WRECKER_RANDOM1
				end
			end
		end
		end
		if (boss.state == S_BM_WRECKER_SUPERSTARTATTACK)
		boss.momz = 0
		boss.momx = 0
		boss.momy = 0
		boss.angle = R_PointToAngle2(boss.x, boss.y, boss.target.x, boss.target.y)
		boss.scale = 62500
		P_SetObjectMomZ(boss, 8*FRACUNIT)
		if not S_SoundPlaying(boss, sfx_cdfm39)
		S_StartSound(boss, sfx_cdfm39)
		end
		if (boss.flags & MF_SHOOTABLE)
		boss.flags = $1 & ~MF_SHOOTABLE
		end
		end
		if (boss.state == S_BM_WRECKER_SUPERATTACK)
		boss.angle = boss.angle+ANG20
		P_SpawnGhostMobj(boss)
		boss.scale = 70000
			if P_IsObjectOnGround(boss)
			local sjumpheight = P_RandomRange(10,14)*FRACUNIT
			P_SetObjectMomZ(boss, sjumpheight)
			local forceradius = P_RandomRange(300,420)*FRACUNIT //no nice and nice
			P_Earthquake(boss, boss, forceradius)
			S_StartSound(boss, sfx_rocks1)
			local sbmwinstathrust = P_RandomRange(15,30)*FRACUNIT
			P_InstaThrust(boss, R_PointToAngle2(boss.x, boss.y, boss.target.x, boss.target.y), sbmwinstathrust)
			S_StartSound(boss, sfx_s3k49)
			end
		end
		if (boss.state == S_BM_WRECKER_SUPERFINISHATTACK)
			for boss in mobjs.iterate()
				if boss
				and boss.valid
				and boss.health
				and boss.type == MT_BM_WRECKER
					boss.momx = 0
					boss.momy = 0
					boss.scale = 62500
					P_SetObjectMomZ(boss, -12*FRACUNIT)
					if P_IsObjectOnGround(boss)
					and (boss.state == S_BM_WRECKER_SUPERFINISHATTACK)
					boss.state = S_BM_WRECKER_HOT
					P_Earthquake(boss, boss, 420*FRACUNIT) //nice
				end
			end
		end
		end
		if (boss.state == S_BM_WRECKER_DEAD1)
		boss.angle = R_PointToAngle2(boss.x, boss.y, boss.target.x, boss.target.y)
		boss.momz = 8*FRACUNIT
		end
		if (boss.state == S_BM_WRECKER_PAIN)
			if boss.tics > 35
			P_InstaThrust(boss, R_PointToAngle2(boss.x, boss.y, boss.target.x, boss.target.y), -20*FRACUNIT)
			end
			if P_IsObjectOnGround(boss)
			P_SetObjectMomZ(boss, 10*FRACUNIT)
			S_StartSound(boss, sfx_bnce1)
			if (boss.flags & MF_SHOOTABLE)
			boss.flags = $1 & ~MF_SHOOTABLE
			end
			end
		end
	end
end, MT_BM_WRECKER)