Madonna's obsessed fan is about to go to trial against NYC, but he's counting on the city folding and handing him millions before it comes to that.

Robert Linhart -- who was busted for camping out in front of Madonna's pad and refusing to leave -- is suing the city, claiming NYPD officers roughed him up during the arrest. He originally wanted $5 million, but now says he'll settle for $3 mil.

It's coming down to the wire ... jury selection's scheduled to start Monday, but Linhart and his attorney, Peter Gleason, are still confident prosecutors will make an offer. Linhart claims he'll donate $1 mil of the settlement to hurricane victims.

We're guessing prosecutors don't give a crap about his benevolence, but the clock is ticking.