So, let me get this straight...
To trigger "Town Music" and to stop enemy spawns, I need 3 NPCs in an area.
But, to get happiness and pylons to work, I need no more than 2 NPCs near each other.
This doesn't make a load of sense.
Is there something I'm missing here? It seems really weird to make Pylons and Towns be mutually exclusive to one another.
That's because they're not. You got several things wrong.
First, the ability for Pylons to
work is not tied to Happiness. Happiness is only tied to whether you can
buy a Pylon, not use them. So if you want a Cavern Pylon, all you need to do is stick a single NPC who sells stuff and like the Underground in an underground house by themselves. Once they appear in their house, you can buy the Pylon and do whatever you want.
Pylons only need two housed NPCs near it in order to function. How happy those NPCs are is
irrelevant.
The second thing you got wrong is NPC distance. There are two distainces that matter: 25 squares (short) and ~120 squares (long).
More than two NPCs within short range of each other will cancel out the happiness bonus for them (but again, that does not affect Pylons). You can have more NPCs than two in the same general area, but to maintain happiness, you have to move pairs of them out of short range of each other.
The Town Biome happens when you have 3 or more NPCs in an area, not the short happiness range. So you can have happy NPCs within a Town, so long as pairs of them are farther than 25 squares apart.
The long range mentioned above means that you start building unhappiness for each NPC past 4 that are within 120 squares of each other. So optimally, a Town should contain at most 4 NPCs.
EDIT: Also the wiki claims 2 NPCs will stop spawns and give Town Music, but I can verify that the wiki is wrong, as I have my guide and the merchant in the forest and I'm getting zombies trying to beat the door down and normal night theme is playing.
It may be (just a guess) that an active Pylon counts as a third NPC for Town purposes.
Weird, because I had a Forest Town of Guide, Merchant, and Nurse.
The Merchant likes the Forest and the Nurse (which is two likes and zero dislikes), but yet would not sell me the Pylon until I moved the Nurse to the Ocean.
That makes sense if two of them were within 25 squares of the Merchant. That would cancel out the 90% Happiness buff from being away from other people. And while the Merchant likes the Forest and likes the Nurse, 0.9*0.95 is only 0.855, which is larger than the 85% bonus you need to get someone to sell a Pylon.
Basically, to get a Pylon, you
need either the solitary buff or an NPC that the character loves (in addition to the preferred biome). And since the Merchant doesn't have a "love", you need to make sure that only one other character is with 25 squares of the Merchant.