Happiness in Fallout 4 is rather frustrating.
- If you're certain that all your settlers' needs have been met (listed in full post below), synths may have replaced some of your settlers. Kill the synth, and your settlement happiness will go up.
- You might also have a negative modifier being applied to your total happiness score based on a settlement-related quest or recent settler death. To offset this, and any other happiness-related bugs that may be present, add bars, clinics, and animals like the Junkyard Dog, Gorilla, or Cats (if you have the DLC).
- If you're focused on getting one settlement to 100% quickly, make sure it has no children, and no robots (so Graygarden is not a good idea).
And while I can't seem to find solid evidence that staying in the settlement is required, players have reported that happiness sometimes decreases when leaving the settlement. If you're trying to go for that coveted 100%, stay in the settlement. When you see the happiness go up, sleep until the next day, then repeat. I got the Benevolent Leader trophy without doing this, but I thought it was worth mentioning nonetheless.
Here's the math behind the settlement happiness "score", which you can find in the
scripts/workshopscript.pex (taken from this reddit post by /u/DerCapac):
- Is there 1 food for the settler? If yes add 20 happiness (
- Is there 1 water for the settler? If yes add 20 happiness (
- Is there a bed for the settler? If yes add 10 happiness (
- Is the bed placed in a roofed area? If yes add 10 happiness (
- Is the safety rating equal or higher to the total population? If yes add 20 happiness (
This makes a total of 80 happiness per settler.
However, these only apply to human settlers. Your settlers can be replaced by synths, which have a fixed happiness of 50. Robots also have a fixed happiness of 50. To find out if your settlement has synths, save the game, then start killing your settlers -- if their body has a synth component in its inventory, that settler was a synth. Reload your previous save, and kill that one (or however many synth settlers you found). Beware, other settlers may aggro you if you kill a synth "settler".
As you mentioned, stores provide bonus happiness. Bars and clinics provide the most happiness (large bar provides 40 happiness, large clinic provides 30).
If you acquire a Junkyard Dog or Gorilla, that will increase happiness as well, adding 10 and 20 bonus happiness respectively. If you have the Wasteland Workshop DLC, cats add happiness as well (a town full of cats is how I managed to get the Benevolent Leader trophy).
The resulting value is divided through the total number of settlers living in the settlement. If all of your settlers' needs are
fulfilled, this means that we end up with a happiness value of 80 plus
the bonus happiness of all stores divided by the number of settlers.
This reddit post also describes a happiness modifier applied after this calculation is made, based on settlement-related quests and settler deaths, both of which normally have a negative impact. The modifier is capped between -50 and +20, and the modifier is reduced by 20% each day.
After all of these calculations and modifiers are applied, you have the final value. The settlement's happiness will go up 20% each day until it reaches the calculated happiness value.
Various players have reported a bug where settler happiness either goes down, or does not do the normal 20% increase while you are not in the settlement -- however, none of the script files seem to explain this phenomenon. Nevertheless, it's worth taking into consideration. People have also reported that unemployed settlers (which includes those assigned to a supply line, and children) result in unhappiness, but there doesn't seem to be any proof in the scripts for that either. I'll update this answer if anyone has evidence otherwise.