calculating needed buildings works