I think its very simple but also very complex
The capital gains is based on the difference between the cadastral value when bought and when sold, minus allowable (IVA included) expenses and taxes.
If you buy a plot of land for €50,000 and sell a house on the same plot for €300,000 and it cost you €100,000 to build inc taxes and expenses, then you have made a capital gain of €150,000.
Therefore the 18% would be paid on this amount, UNLESS you were a resident and it was your primary residence, in which case provifing you paid all the gain into another property you would not have to pay any capital gains tax at all (in my understanding)