Bad attitude but timely, correct service: good tip. (You don't need to be my friend if you get my order right and get my food to me when I'm ready to eat it.)
Good attitude but flawed service: good tip. (If the kitchen is screwed up, but you are doing your best to make things work out, it's not your fault. If you do make a mistake, but apologize and work hard to correct it, that's okay too.)
Bad (or indifferent) attitude and flawed service: not a good tip.
As an example, we recently ate at a Chili's. If you've been to a Chili's, you know that, in general, they focus on table turnover, and if there is an error in timing, it is usually that food comes out too quickly rather than not quickly enough. 30 minutes pass after ordering, we ask our mostly absent waiter when the food might be out. 40 minutes, we ask again. Burgers come out, no fries (apparently, none were ready). He comes back to check on us, we remind him there are no fries. End of the meal: no fries. We sit around for a few minutes after the busboy clears our table, and then have to ask for the check. No apology. Nothing offered for the fries that never came. And, to add insult to injury, he had the nerve to ask me if I needed change.
Needless to say, I was not in a giving mood by the end of the meal.