When an action or cross-complaint is brought pursuant to Section 871.3, the court may, subject to Section 871.4, effect such an adjustment of the rights, equities, and interests of the good faith improver, the owner of the land, and other interested parties (including, but not limited to, lessees, lienholders, and encumbrancers) as is consistent with substantial justice to the parties under the circumstances of the particular case. The relief granted shall protect the owner of the land upon which the improvement was constructed against any pecuniary loss but shall avoid, insofar as possible, enriching him unjustly at the expense of the good faith improver. In protecting the owner of the land against pecuniary loss, the court shall take into consideration the expenses the owner of the land has incurred in the action in which relief under this chapter is sought, including but not limited to reasonable attorney fees. In determining the appropriate form of relief under this section, the court shall take into consideration any plans the owner of the land may have for the use or development of the land upon which the improvement was made and his need for the land upon which the improvement was made in connection with the use or development of other property owned by him.
(Amended by Stats. 1974, Ch. 244.)