//Lava Ring Tumble By Sonic1983

local ring_table = {
MT_RING,
MT_FLINGRING,
MT_REDTEAMRING,
MT_BLUETEAMRING
}

local function P_MobjSlope(standingslope, mo)
	if standingslope
		//if not (standingslope.flags & SL_NOPHYSICS)
			//if not (mo.flags & (MF_NOCLIPHEIGHT|MF_NOGRAVITY))
			local thrust = sin(standingslope.zangle)*3/2*(mo.eflags & MFE_VERTICALFLIP and 1 or -1)
				if (mo.momx or mo.momy)
				thrust = FixedMul(thrust, FRACUNIT+P_AproxDistance(mo.momx, mo.momy)/16)
				end
			thrust = FixedMul(thrust, abs(P_GetMobjGravity(mo)))
			thrust = FixedMul(thrust, FixedDiv(16*FRACUNIT, 29*FRACUNIT/32))
			P_Thrust(mo, standingslope.xydirection, thrust)
			mo.momz = mo.momz-mo.momz/4
			//end
		//end
	end
end

for k, v in ipairs(ring_table)
	addHook("MobjDeath", function(mo, inf, source, dmgtype)
		if mapheaderinfo[gamemap].lavaringtumble
			if mo
			and mo.valid
			//and mo.health
				if dmgtype == DMG_FIRE //LAVA DETECTED
				local sector = mo.subsector.sector
					for rover in sector.ffloors()
						if rover
						and rover.valid
							//if mo.z <= rover.topheight
							//and mo.z >= rover.bottomheight
							if P_InsideANonSolidFFloor(mo, rover)
								if P_CheckSolidLava(mo, rover)
									if (mo.flags2 & MF2_OBJECTFLIP)
										if rover.b_slope
										mo.z = P_GetZAt(rover.b_slope, mo.x, mo.y)-FixedMul(mo.height, mo.scale)
										P_MobjSlope(rover.b_slope, mo)
										else
										mo.z = rover.bottomheight-FixedMul(mo.height, mo.scale)
										end
									else
										if rover.t_slope
										mo.z = P_GetZAt(rover.t_slope, mo.x, mo.y)
										P_MobjSlope(rover.t_slope, mo)
										else
										mo.z = rover.topheight
										end
									end
								mo.momz = -FixedMul(mo.momz, FixedDiv(17*FRACUNIT,20*FRACUNIT))
								mo.eflags = $1|MFE_JUSTHITFLOOR
								end
							end
						end
					end
				mo.flags = mo.info.flags|MF_SPECIAL
				mo.health = 1
				return true
				end
			end
		end
	end, v)
end