Guide:NPC Happiness

 WORK IN PROGRESS, REWRITING ALL OF THIS OUTDATED STUFF 

The NPC happiness mechanic poses a complex puzzle to avoid paying excessively high prices. Manys who like each others' company prefer different biomes, and some NPCs like another but are disliked or hated in return. Additionally, purchasing pylons in order to set up a network is impossible without putting thought into NPC happiness.

There are several different ways to address the situation, this guide is intended to discuss them. This section shows an optimal, static housing setup which leaves each NPC at a very high happiness value by exploiting certain mechanics of the system.

Happiness overview
An NPC's "happiness" is less of a score, but rather more helpfully can be thought of as a multiplier. In basic conditions, with no positive or negative factors, an NPC has a happiness multiplier of 100%. Each positive and negative factor is multiplied together to form the final total. Of note is that a smaller multiplier is better; an easy way to remember this is that, for NPCs which sell things, the multiplier is applied as a discount to item prices.

The table shown here gives a full overview of the multipliers; for our purposes, here's a summary of the important bits:


 * Happiness is positively effected by crowding, biome preference, and NPC preference. A lack of crowding multiplies the total by 95%, a loved biome or NPC multiplies by 88%, and a liked biome or NPC multiplies by 94%.
 * At the end of the calculation, happiness is rounded to the nearest whole number and capped at a minimum of 75%. Though this may seem like the goal to shoot for with all NPCs, for some of them, it is simply impossible due to them not liking or loving enough NPCs. Below, each NPC in the game is sorted into groups with a shared number of preferences.
 * Santa Claus has a loved biome, no loved NPCs, and no liked NPCs. His minimum multiplier is 83.6%, rounded up to 84%.
 * The Guide, Merchant, Dye Trader, Dryad, and Witch Doctor. Each has a liked biome, no loved NPCs, and two liked NPCs. Their minimum multiplier is 78.90548%, rounded up to 79%.
 * The Cyborg and Angler. Each has a liked biome, no loved NPCs, and three liked NPCs. Living with all of them prevents them from gaining the "no crowding" bonus. As such, their minimum multiplier is 78.074896%, rounded down to 78%.
 * The Zoologist, Tax Collector, Mechanic, Arms Dealer, Steampunker, Painter, Pirate, Stylist, Demolitionist, Goblin Tinkerer, Clothier, Wizard, Nurse, Tavernkeep, and Truffle. Each has a liked biome, one loved NPC and one liked NPC, resulting in each of them having a minimum achievable multiplier of 73.86896%, rounded up to 74%, then capped at 75%.
 * The Golfer has a liked biome, one loved NPC, and two liked NPCs. Living with all of them prevents him from gaining the "no crowding" bonus. As such, his minimum multiplier is 73.091392%, rounded down to 73%, then capped at 75%.
 * The Party Girl has a liked biome, two loved NPCs, and one liked NPC. Living with all of them prevents her from gaining the "no crowding" bonus. As such, her minimum multiplier is 68.425984%, rounded down to 68%, then capped at 75%.
 * The Princess has no biome preference and loves all NPCs. She also does not receive the "no crowding" bonus, nor the crowded penalty. As such, her theoretical maximum score (before being capped) would involve having literally every NPC in the game be her neighbor, which would result in 25 88% multipliers stacking together for minimum multiplier of 4.093236176%, rounded down to 4%, then capped at 75%.
 * With NPCs whose theoretical minimum is below 75%, one needn't achieve all of their positive factors, only enough to get below 75%. NPCs with minimums above 75%, however, have no such wiggle room.
 * A multiplier of 85% or lower is required for an NPC to sell a Pylon.

Observations
A few useful observations are needed to make the following solutions possible:
 * An NPC can be neighbors with two NPCs without having those two NPCs be considered neighbors with each other. This can be achieved by positioning them in a line, like a street with houses on it. This is called a "chain" relationship. When a chain loops in on itself, this is a cycle. Even more complex webs of neighboring can be achieved. The necessary positioning can be finicky and frustrating to achieve, but is indeed possible.
 * As of 1.4.3.3 ( players), if an NPC is in multiple biomes at once, and one of them is a biome they like, then even if another biome is one they don't like, they will react to the presence of their preferred biome, and only said biome. We can combine this with the fact that most biomes can coexist—for the purposes of housing, at least—and it means that the problem of two NPCs loving/liking each other is effectively removed aside from when dealing with NPCs who prefer the Forest. In this case, we must set the houses up such that each one is on the opposite side of a biome "border". Unfortunately for players, this border strategy must be used every time, instead of hybrid biomes. The below strategies will work, but each time the solution says to use a hybrid biome, you must have the houses be built on a border instead.
 * The Guide's happiness has absolutely no bearing on any system involving him. As such, there is no practical reason to make him happy.



The Love Strategy
As a general guideline, this solution attempts to have every NPC uncrowded, in a biome they like, and with a loved NPC, hence the "love strategy" name. This achieves a 78% modifier, only 3% off from the theoretical minimum. This is so close to the theoretical minimum as to be good enough for most people. For NPCs without loved NPCs, the goal for them is to neighbor 2 liked NPCs instead, as this grants a modifier almost equal to one loved NPC.

This ends up linking almost every NPC in the game in one large structure, aside from the Mechanic and the Goblin Tinkerer. They can be placed entirely separately in an Underground Tundra. As for the others, this gets a bit more complicated. There's a few problems with this structure (aside from it looking like a two-legged spider wearing a fez on its top and bottom): its size, and its complexity. Its size is a problem, firstly, as it means that nearly all NPCs in the game will be living (in the scale of a whole world) very close to each other, restricting the range of pylons greatly. As such, you'll probably want to slice this structure into pieces to allow for multiple villages to use pylons within. This will, of course, come with a happiness penalty, but it does address both the size and complexity problem. That being said, the below guide is written as if you are building the whole network as shown above; make modifications to your own taste.

Firstly, one thing which stands out is the main loop at the center of the structure. This loop is: Nurse, Arms Dealer, Dye Trader, Painter, Dryad, Witch Doctor, Zoologist, Party Girl, Wizard, Golfer, Merchant, and so on. This also forms a biome loop of Hallow, Desert, Jungle, Forest, Hallow, Forest. This then raises two questions: how do we form a loop of houses, and how do we form a loop of biomes, without any NPCs being neighbors when we don't want them to be, and without any NPCs being in biomes they're not supposed to be in?

The structure of the houses is deceptively simple: a literal loop will work, which is to say, make the houses be in a circle. An NPC determines if they are neighboring other NPCs in a 49x49 square centered on the NPC's home tile, which can also be seen as 25 tiles out in each cardinal direction (including the home tile itself). The exact positioning depends on what shape and size you want each NPC's home to be. Moreover, there's a fair amount of wiggle room given the NPC's neighboring detection range; you needn't form a perfect circle.

The offshoots can be handled in a similar way, just by mimicking the structure of the graph.

Non-mutual relationships
Unfortunately, even with these, non-mutual neighboring preferences form cracks in any static housing system (see here for a way to address these with a dynamic system):


 * The Tax Collector requires all four possible positive factors in order to reach his minimum of 75%. Unfortunately, this comes at the detriment of a 106% multiplier to the Merchant and a 112% multiplier to the Party Girl. The Merchant is already incapable of reaching 75%, and with the 106% multiplier added, even with all his bonuses the lowest he can reach is 88%. The Party Girl, in her preferred biome with her two loved NPCs and one like NPC (and sans the "no crowding" bonus, as that's 3 total neighbors), can counteract the negative multiplier almost entirely, ending up with a final modifier of, quite unfortunately, 76%. All together, this requires you to make a choice of which NPC's happiness is more important to you: the Tax Collector, or the Merchant and Party Girl, as it is simply impossible to make all of them simultaneously maximally happy.
 * A very similar situation occurs with the Clothier and Truffle. The Clothier must be neighbors with the Truffle in order to be fully happy, but this gives the Truffle a 106% multiplier, making his minimum 82%. Again, it is impossible for these two to be fully happy at the same time.

Dynamic adjustment
The above strategy can be slightly tweaked to achieve a more perfect arrangement... with the caveat that the system will require you to change where an NPC lives on the fly every time you want to talk to them. Unwieldy, inconvenient, and even more effort on top of the above, but if you're truly searching for perfection, here it is: