In an action to determine adverse claims, a defendant in the defendant's answer may deny that the plaintiff has the estate, interest, lien, or encumbrance alleged in the complaint, coupled with allegations setting forth fully and particularly the origin, nature, and extent of the defendant's own claim to the property, and, if such defendant claims a lien, the original amount secured thereby and the date of the same, and the sum remaining due thereon, whether the same has been secured in any other way or not, and if so secured, the nature and extent of such security, or the defendant likewise may set forth the defendant's rights in the property as a counterclaim and may demand affirmative relief against the plaintiff and any codefendant, and in such case the defendant also may set forth a counterclaim and recovery from a plaintiff or a codefendant for permanent improvements made by the defendant or those under whom the defendant claims, holding under color of title in good faith adversely to the plaintiff or codefendant against whom the defendant seeks a recovery. Such counterclaim shall set forth among other things the value of the land aside from the improvements thereon, and, as accurately as practicable, the improvements upon the land and the value thereof, and in such case such defendant also may set forth as a counterclaim the defendant's demand for recovery of the value of the use and occupation of the premises and value of property wasted or removed therefrom. The answer shall be deemed served on codefendants by filing the same in the office of the clerk of court of the county where the action is pending at any time within twenty days after the service of summons on such defendant is complete. If affirmative relief is demanded against codefendants, the allegations constituting counterclaims shall be deemed controverted by all the parties, as upon a direct denial or avoidance, as the case may require, without further pleading.
N.D.C.C. § 32-17-08