House

From Terraria Wiki
(Redirected from Home)
Jump to navigation Jump to search
A basic house with the dimensions of 9 (exterior width) × 7 (exterior height).

A house (or home) is a structure built by the player that town NPCs require in order to spawn, with one house required per NPC. A structure must meet several requirements in order to function as a house (see details below). The player can check if a structure meets the requirements, or assign NPCs to existing houses by using the housing menu. If a house occupied by an NPC is damaged in a way that makes it invalid, the NPC will move out and walk around the area until a suitable house is restored. If there are vacant houses available in the world, the NPC may move into one of them. If the NPC gets killed and does not have a home, they will not respawn until a new house becomes available.

If both a town NPC and their house is offscreen, they will teleport to their house during night, rain, Solar Eclipse, or Slime Rain(Desktop, Console and Mobile versions). The Old Man(Desktop, Console and Mobile versions) / all NPCs(Old-gen console and 3DS versions) will also teleport to their house if they are standing on Dungeon Bricks, regardless of time. The Old Man will consider the Dungeon point (the spawn point of the Old Man, i.e. the left of the two tiles on which he stands during night) as his home.[1][2]

The Guide will appear upon starting a regular new world, and if killed, he will require a house in order to respawn. The Old Man, the Traveling Merchant(Desktop, Console, Old-gen console and Mobile versions), and the Skeleton Merchant(Desktop, Console and Mobile versions) do not require houses.

Similarly, the Guide, Angler, Goblin Tinkerer, Tavernkeep(Desktop, Console and Mobile versions), Mechanic, Stylist, Wizard, Tax Collector(Desktop, Console and Mobile versions), and Golfer(Desktop, Console and Mobile versions) will each make their initial appearances regardless of available housing. Once initially found, each will require a suitable house before respawning.

Certain naturally-generated structures can serve as houses and may inadvertently attract NPCs if players have placed light sources within them. These can include Floating Island structures, and (Old-gen console and 3DS versions) Living Tree treasure rooms. NPCs can be moved from these to the player's structures using the housing menu.

The requirements for a player-selected Bed to work as a spawn point are similar to those for NPC housing, but weaker; players do not need furniture beyond the Bed. See the Beds page for full details.

Housing menu

Housing Menu Interface.png
(Desktop, Console and Mobile versions) Housing menu

The housing menu allows managing the placement of NPCs. It is accessed by pressing the small house button above the armor slots in the inventory. The player can check whether a given house is suitable for NPC use or not, as well as manually assign a house to a specific NPC.

(Desktop, Console and Mobile versions) To check whether a house is suitable for use, press the Use / Attack button on the "?" housing query mark and then press again anywhere inside the house. A status message indicating whether the house is suitable or not will be displayed. If it is not suitable, the game will show what the house is lacking. This alert prioritizes frame and walls, then furniture (door, light source, table, and chair). A generic "This is not valid housing." can indicate that the frame is not closed, or that there is no place for the NPC to stand (see below for details). If a solid block is queried, then "This is a solid block!" will be displayed.

Once a house is determined to be suitable, the player may assign an NPC to it by placing the corresponding NPC flag in it. Only the flags of existing NPCs will appear in the housing menu. For example, when first entering a new world, only the Guide's NPC flag is shown, and the NPC flags for other NPCs will only be shown when they have spawned in the world. On the Desktop version Desktop version, Console version Console version, and Mobile version Mobile version, NPC flags have two different appearances: solid red and red with a golden frame. NPCs that move in by their own will have a regular red flag. If they are assigned to a house, the banner will have a golden frame. This indicates that if the NPC currently inhabiting the home were to die, the replacement for that NPC would move into that specified home.

In the Old-gen console version Old-gen console version, the housing menu can be opened by pressing Inventory and navigating to the housing menu. To check whether a house is valid, press Quick Buff and the housing status of the house the player is standing in will be printed in chat. Press Inventory to show/hide NPC flags.

On the Nintendo 3DSNintendo 3DS version version, the housing menu can be opened by pressing its button on the touch screen. It only lights up and is possible to press when in valid housing. In the menu, the player can tap an NPC's flag to set housing. Press the Show/Hide Flags button to show/hide NPC flags.

When the player first meet the spawn conditions for an NPC, a random house will be assigned to them from existing empty suitable houses.

House validity evaluation

When NPCs are about to move in, the player assigns NPCs to houses via the housing menu, or the player uses the housing query on a house, a house validity evaluation is performed on the chosen house.

If the house validity evaluation is initiated by housing menu, certain status messages will appear to inform the player whether the house is suitable, or what made the house invalid.

Liquids will not affect the validity of a house.

Houses containing Stinkbug Blockers(Desktop, Console and Mobile versions) will never be valid, and will display respective status message when queried:

  • Stinkbug Blocker: "This room is infested by a stinkbug!"
  • Ghostly Stinkbug Blocker: "This room is infested by a ghostly stinkbug!"

The house validity evaluation can be divided into 3 phases: Frame, furniture, and properties.

Frame

In this phase, the game will try to determine the frame and the internal area of a house, and complete several checks to its structure.[3] The range of a house includes a "connected" internal area and the "frame" surrounding it, in details:

  • A tile can be "connected" in 8 directions, which means that tiles in the internal area have to be connected with each other in horizontal, vertical, or diagonal directions.
  • "Frame" refers to the tiles surrounding the internal tiles. The frame must be completely closed (i.e. the internal area is completely unconnected to any tiles outside). The frame can only be made up of solid tiles (solid blocks or platforms that are not actuated), Trap Doors, doors, or Tall Gates (only the tiles occupied when the doors are closed will count into the frame).

All tiles within the range of a house (both the frame and the internal area) have to meet the following requirements:

  • All tiles must be at least 10 tiles away from the true world edges.[4]
  • "Holes" that are 5 tiles or more in width/height are not permitted. A "hole" is a tile that is neither occupied by a valid solid tile nor a valid background wall.
    • Unsafe walls (such as naturally-occurring Dirt Walls) do not count as valid background walls.
    • Having holes in the background walls may sometimes allow enemies to spawn within the house. To create safer windows, place sections of Glass Wall instead.
  • A house must have at least 60 but fewer than 750 total tiles including the frame around it.
  • Below are status messages related with frame check:[5]
    • If the house is missing too many background walls: "This room is missing a wall"
    • If the house is too small: "This room is too small"
    • If the house is too big: "This room is too big"

After determining the frame of the house, the game will save two areas for subsequent checks:[6]

  • The entire house area. This contains all internal tiles and the frame. This is used for checking valid furniture.
  • The internal coordinates of the house. This contains the X coordinates of the left- and rightmost tile (X1 for left, X2 for right), and Y coordinates of the highest and lowest tile (Y1 for top, Y2 for bottom), after excluding all frame tiles. This is used for checking evil score and valid home tiles.
The entire house area (red) and a rectangle created with internal coordinates (yellow).

Minimal house sizes

A miniature 3×10 house.
A simple, valid house.

Given the minimum size of 60 tiles including the frame, a rectangular house must have at least one of the following dimensions:

Excluding ceiling, floor and walls Including ceiling, floor and walls
3 tiles wide × 10 tiles high[7] 5 tiles wide × 12 tiles high
4 tiles wide × 8 tiles high 6 tiles wide × 10 tiles high
5 tiles wide × 7 tiles high 7 tiles wide × 9 tiles high
6 tiles wide × 6 tiles high 8 tiles wide × 8 tiles high
7 tiles wide × 5 tiles high 9 tiles wide × 7 tiles high
8 tiles wide × 4 tiles high 10 tiles wide × 6 tiles high
10 tiles wide × 3 tiles high 12 tiles wide × 5 tiles high
13 tiles wide × 2 tiles high (Old-gen console and 3DS versions)[8] 15 tiles wide × 4 tiles high

Note that a house does not need to be rectangular. The dimensions above are merely examples.

Furniture

In this phase, the game will check for pieces of furniture in the entire house area.

In the range of a house, there must be at least one valid light source, one valid flat-surface item, one valid comfort item, and one valid entrance.[9] The smallest and most easily obtainable objects that meet the requirements are a Torch, a Work Bench, a Chair, and a Wood Platform. See below for list of all eligible items.[10]

  • Not every item that provides light will fulfill a house's light source requirement; in particular, no solid blocks, platforms, or walls qualify.
  • The entrance does not need to be usable by the NPC (e.g. NPCs cannot use Trap Doors) nor does it have to lead "outdoors" (e.g. an indoor platform also works).
  • Any type of each item listed below will fulfill the requirement. For example, a Torch of any color will work, as will any theme of chairs.
  • If a house is missing any of required furniture, it will be mentioned in the status message.[5]
    • For example, a house without any furniture will produce "This house is missing a light source, a door, a table, and a chair."
Light sources

Light sources

Any item with a Tile ID of 4, 33, 34, 35, 42, 49, 92, 93, 95, 98, 100, 149, 173, 174, 270, 271, 316, 317, 318, 372, 405, 572, 581, 592, 646, or 660:

Flat-surface items

Flat-surface items

Any item with a Tile ID of 14, 18, 87, 88, 90, 101, 354, 355, 464, 469, or 487:

Comfort items

Comfort items

Any item with a Tile ID of 15, 79, 89, 102, 487, or 497:

Entry items

Entry items

Any item with a Tile ID of 10, 11, 19, 386, 387, 388, 389, 427, 435, 436, 437, 438, or 439:

Properties

In this phase, the house looks structurally valid, but there are three reasons it can still be rejected: If it is already occupied, if it is too close to or inside an evil biome, or if there is no place inside for the NPC to stand at night.

First, the game checks if the house is already occupied by another NPC. If it is, then the house is invalid and the status message "This housing is already occupied." will be displayed.

Otherwise, two properties of the house are checked to determine whether it is a valid house: one is the "evil score", the other is the "home tile score".[11]

Evil score

Then, start calculating the evil score.

Example of the evil score area (orange rectangle).
  • The area checked will be an area based on the internal coordinates of the house, extended outwards. The extended distances differ with versions, and in 1.4.4.9(Desktop, Console and Mobile versions) they are:[12]
    • Horizontal: Start from the leftmost/rightmost tiles within the range of a house, extend 46 tiles in both directions (from X1-46 to X2+46).
    • Vertical: Start from the highest/lowest tiles within the range of a house, extend 44 tiles in both directions (from Y1-44 to Y2+44).
  • If any of the four borders of the area checked is less than 5 tiles from the true world edge, then draw back the area to 5 tiles away from the edge.[13]
  • Calculate the total evil score of all valid tiles (including the actuated ones) within the area, see the table below for details:[14]
Tiles Impact to the score
Corrupt grassCorrupt grass +1 point for each tile
Ebonstone BlockEbonstone Block
Purple Ice BlockPurple Ice Block
Ebonsand BlockEbonsand Block
Ebonsandstone BlockEbonsandstone Block(Desktop, Console and Mobile versions)
Hardened Ebonsand BlockHardened Ebonsand Block(Desktop, Console and Mobile versions)
Corruption thorny bushesCorruption thorny bushes
Corruption Plants.png Corruption Plants
Vile MushroomVile Mushroom
Crimson grassCrimson grass
Crimstone BlockCrimstone Block
Red Ice BlockRed Ice Block
Crimsand BlockCrimsand Block
Crimsandstone BlockCrimsandstone Block(Desktop, Console and Mobile versions)
Hardened Crimsand BlockHardened Crimsand Block(Desktop, Console and Mobile versions)
Crimson thorny bushesCrimson thorny bushes(Desktop, Console and Mobile versions)
Hallowed grassHallowed grass −1 point for each tile
Pearlstone BlockPearlstone Block
Pink Ice BlockPink Ice Block
Pearlsand BlockPearlsand Block
Pearlsandstone BlockPearlsandstone Block(Desktop, Console and Mobile versions)
Hardened Pearlsand BlockHardened Pearlsand Block(Desktop, Console and Mobile versions)
Short Hallowed Plants.png Short Hallowed plants
Tall Hallowed Plants.png Tall Hallowed plants
(Each plant only counts as one tile, despite their sprites being two tiles in height.)
SunflowerSunflower −40 points each[15]
  • Final calculation: Evil score = Corruption tile score + Crimson tile score − Hallowed tile score − Sunflower score

If the evil score is at least 50, then the house is invalid, and the message "This housing is corrupted." will be displayed, and if the evil score is at least 300, the message "This is not valid housing." will be displayed instead. If an occupied house becomes Corrupted/Crimson'd, the NPC living there may move out and wander the area until a new house becomes available.

Home tile score

Then, start to check whether there is a valid "home tile" within the house. A home tile will be chosen from tiles within a rectangular area based on the internal coordinates of the house. The area starts at 1 tile from the left and rightmost tile, 2 tiles from the top, and extends 1 tile from the bottom (from X1+1 to X2-1, and from Y1+2 to Y2+1).[11]

The rectangle created with internal coordinates (yellow), and the area in which a home tile is chosen (cyan).
Example of areas to be checked.

Then, the tile has to fulfill the following requirements to be a vaild home tile. The purple block represents a candidate for the home tile in the image.

  • It is not a platform or a Bubble.
  • Itself and the tiles to the left and right to it (blue blocks) must be solid, unactuated tiles.
  • There are no objects that block entities from passing (actuated solid blocks are not allowed, but platforms are) in the 3×3 area directly above it (tiles in the green square).
  • There are no solid tiles among the 3 tiles directly above it (yellow tiles in the green square), and these 3 tiles are all in the range of the housing.

If there is a tile that meets these requirements, calculate the "home tile score" using the objects in the 5×4 area directly above it (red, white, yellow tiles). The "home tile score" starts at 50.

  • Most types of solid tiles (blocks, furnitures, etc.) in the area will affect the home tile score. Below is a list of excluded tiles:[16]
Excluded tiles

Any tile with a Tile ID of 3, 4, 73, 82, 83, 84, or 386:

  • For the first calculation, the tiles in the middle column (the 1×4 area directly above the tile; yellow tiles) will not be used, they only participate in the second calculation (see below).
    • The remaining 16 tiles (red, white tiles) will participate the first calculation:
    • −20 points for each tile occupied by a closed door or Tall Gate.
    • −20 points for each tile occupied by the hinge of an opened door (the tiles that a closed door occupies)[17] or opened Tall Gates.
    • −5 points for each unactuated solid tile.
    • +5 points for each tile occupied by other objects (or is not occupied at all).

After the first calculation, if the home tile score is 0 or lower, then the tile is invalid; if the home tile score is greater than 0, then continue to the second calculation:

  • If assigning a second NPC into the house, resulting in them sharing the house (a town NPC and a town pet(Desktop, Console and Mobile versions)), and the current tile is less than 3 tiles away from the existing NPC's home tile, then the score is set to 1.
  • If there are any type of regular chests (Trap Chests do not count, but Locked Chests do)[18] within the 5×4 area above (red, white, yellow tiles), then −30 points for each tile occupied by chests. If the score is below 1 after this calculation, set it to 1.
  • If there are solid tilesVerify within the 1×4 area above (yellow tiles), then −15 points for each tile.
  • If the final score is 0 or lower, then the tile is invalid.

There has to be at least one valid home tile in a house to serve as the standing point of NPCs, otherwise the message "This is not valid housing." will be displayed. The NPC flag will hang directly above the standing point. If there are multiple valid home tiles, then the tile with highest score and being nearest to the top left corner of the house will be selected[19]

It is possible for a town pet and a town NPC to share one single home tile if the house is small. However, the tile must pass a second check when assigning the second NPC into the house.[20]

Truffle

The Truffle NPC has an extra requirement for his house: its lowest tile (Y2) must be above surface, and it must have at least 100 tiles of Glowing Mushroom biome tiles in the area around it. The area is the same size as the area used for calculating the evil score.[21]

If attempting to move Truffle to a house that does not fulfill this requirement, the status message "This housing does not meet the requirements for a Truffle." will be displayed.

Achievements

Achievement No Hobo.png
No Hobo • “Build a house suitable enough for your first town NPC, such as the guide, to move into.”
Successfully get an NPC to move into your first House. (Desktop, Console and Mobile versions)
Category: Explorer Explorer
Achievement Real Estate Agent.png
Real Estate Agent • “Have all possible town NPCs living in your world.”
All town NPCs are housed in your world. (Desktop, Console and Mobile versions)
Category: Challenger Challenger
Achievement Home Sweet Home.png
Home Sweet Home • “The Guide has moved into your house”
Have the Guide move into a house. (Old-gen console version)
Achievement All in the Family.png
All in the Family • “Every NPC has moved into your house”
All town NPCs are housed in your world. (Old-gen console version)

Notes

Two examples of houses with no empty wall. NPCs cannot move into these houses on their own, and must be assigned by a player.
  • Increasing the empty wall area (i.e. tiles with only background walls and without other solid blocks/background objects) of empty houses in the worlds allows NPCs to move in faster. Also, using Sandstone Brick Walls for houses will increase the time for NPCs to move in.[22]
    • This means that a house with no empty wall area can only be assigned by a player.
  • Houses may be attached together and share common walls, floors, ceilings, and doors. What looks to the player like a multi-room house or apartment complex looks to the NPCs like a collection of independent houses.
  • Nearly any NPC house will qualify for a player to place and use a Bed as their spawn point, so long as the tiles immediately above the bed are clear (see the Beds page for full details). The Bed also counts as a comfort item.
  • If a house with an assigned NPC is destroyed or any of its requirements are invalidated, the NPC will wander the area until a valid house becomes available again. If killed, the NPC will respawn once a valid house is available.
  • An NPC will not spawn within its house if that house is on the visible screen at the time, and may walk around the area outside instead. At night, when it rains, and during any event, NPCs will be automatically placed inside their houses if the player travels several screens away, or if the player uses any Magic Mirror or the Teleporter.
  • The edges of the world do not count as part of the frame of a house.
  • If a background wall has been converted by biome spread (e.g. Stone Wall to Pearlstone Wall), the house will become invalid as the converted wall is considered unsafe.

Tips

An infinite house. It no longer works as of 1.3.1(Desktop, Console and Mobile versions), but it should still work for the Old-gen console version Old-gen console version and Nintendo 3DSNintendo 3DS version version.
A valid house with minimum walls.
  • Houses in the Corruption or Crimson biomes are usually invalid. This could make purchasing items with biome requirements (most notably for the Painter) harder. For these circumstances, one can use a King Statue or a Queen Statue to teleport the NPCs and purchase these items.
    • If one does not have access to King or Queen Statues, building a house just outside of the evil score detection range but still within the evil biome (the evil biome's background should be visible) will create a valid house within said biome.
  • Actuators can be used with Blue, Brown, Gray, and Lihzahrd Pressure Plates to allow players entry but prevent enemies from entering or NPCs from leaving. However, if an actuated wall is left open, it can make the house invalid until it is made solid again.
    • Trap Doors can also be used, as neither enemies nor NPCs can open them.
    • On the Desktop version Desktop version, Console version Console version, and Mobile version Mobile version, it is very useful and convenient to use a "Player Above" sensor instead of pressure plates. Not only does this save some usable floor space, but avoids having the opening accidentally left open by an accidental misstep. Warning: The sensor itself is not a valid block for the house frame; if it is used as part of the floor, ceiling, or side walls (including corners), the house will not be valid.
  • On the Old-gen console version Old-gen console and 3DSNintendo 3DS version versions, if a house is built at the world's original spawn point, it is best not to place any solid objects or blocks where characters appear; when the player teleports back or respawns, any blocks or furniture where they appear will be broken, which can invalidate the house.
  • If absolutely necessary (e.g. on 3DSNintendo 3DS version, where there is no housing menu), players can force an NPC into a particular house by destroying all the others.
  • As long as the house meets the size criteria, it can be any shape, not just rectangles and squares (e.g. a dome-shaped house would still be viable).
  • It is a wise decision to build "spare" houses beyond the current number of NPCs:
    • Any new NPCs can move in as soon as they are spawned or found (perhaps unexpectedly).
    • Especially when entering Hardmode, some houses may be invalidated by Corruption or Crimson; having spares will help avoid NPCs being left homeless.
    • (Desktop, Console and Mobile versions) Having extras at each base will help with shuffling NPCs around to manage happiness, and/or make sure pylons remain usable.
  • When building homes underground, Sticky Bombs or Scarab Bombs(Desktop, Console and Mobile versions) are a good choice, as they are accurate and break background walls for easier wall placement.
  • While it may be tempting to tuck all the NPCs into small houses, this will leave little room for decoration or even equipment. Many crafting stations are 3 tiles wide by 3 high, and as the game progresses, a player can obtain paintings and animal skins up to 6 tiles wide by 4 high, and potted plants that are 3 tiles wide and up to 6 high.
  • Houses are good places for players to indulge their creativity. It can be entertaining to provide NPCs with decorated and themed homes, even if they would be satisfied with empty cells. The NPC happiness system(Desktop, Console and Mobile versions) builds on this source of entertainment, by giving NPCs preferences for their house's location and proximity to houses of other NPCs. That said, NPC happiness is not affected by a house's appearance or decoration, leaving the player with a free hand.

Trivia

  • A house that has tiles within 5 tiles from the true edge of the world is considered invalid with the message "We need better text for this!!!" However, it is impossible to achieve the condition without editing the world externally, as the distance between the visible world edge and true world edge is 41 or 42 tiles.

See also

History

  • Desktop 1.3.5.3: Fixed an error when trying to use the room query on an unfit room in certain languages.
  • Desktop 1.3.5: NPCs who are manually assigned to a room will have their successor attempt to move in when the original is killed.
  • Desktop 1.2.4.1: Opening doors will once again cause a house to be unsuitable, but only if two doors are opened into the same house (depends on the size of the house).
  • Desktop 1.2: Fixed a bug that would cause a suitable house to be unsuitable.
  • Desktop 1.1: There is now a housing menu (a built-in interface) for checking if a house is valid for being moved into, and for assigning NPCs to specific houses.

References

  1. Information taken from the Desktop version Desktop 1.4.4.7 source code, method AI_007_TownEntities() in Terraria.NPC.cs. There may be inaccuracies, as the current Desktop version Desktop version is 1.4.4.9.
  2. Information taken from the Desktop version Desktop 1.2.4.1 source code, method AI() in Terraria.NPC.cs.
  3. Information taken from the Desktop version Desktop 1.4.4.9 source code, method StartRoomCheck() in Terraria.WorldGen.cs.
  4. The distance between the visible in-game world edge and the true world edge is 41 tiles for top and left edges and 42 tiles for bottom and right edges, so this should not be triggered during normal gameplay.
  5. 5.0 5.1 Information taken from the Desktop version Desktop 1.4.4.9 source code, method MoveTownNPC() in Terraria.WorldGen.cs.
  6. Information taken from the Desktop version Desktop 1.4.4.9 source code, method CheckRoom() in Terraria.WorldGen.cs.
  7. Only possible when using a Work Bench instead of a table.
  8. Only possible when using platforms as a ceiling. No longer possible on Desktop, Console, and Mobile.
  9. Information taken from the Desktop version Desktop 1.4.4.9 source code, method RoomNeeds() in Terraria.WorldGen.cs.
  10. Information taken from the Desktop version Desktop 1.4.4.9 source code, class RoomNeeds in Terraria.ID.Sets.cs.
  11. 11.0 11.1 Information taken from the Desktop version Desktop 1.4.4.9 source code, method ScoreRoom() in Terraria.WorldGen.cs.
  12. Information taken from the Desktop version Desktop 1.4.4.9 source code, method Housing_GetTestedRoomBounds() in Terraria.WorldGen.cs.
  13. Note that this is possible during a normal gameplay, as the extended distance is farther than the distance between the visible world edge and the true world edge (41 tiles).
  14. Information taken from the Desktop version Desktop 1.4.4.9 source code, method GetTileTypeCountByCategory() in Terraria.WorldGen.cs.
  15. Each tile counts as −5 points, while each Sunflower takes up 8 tiles.
  16. Information taken from the Desktop version Desktop 1.4.4.9 source code, field IgnoredInHouseScore in Terraria.ID.TileID.Sets.cs.
  17. Information taken from the Desktop version Desktop 1.4.4.9 source code, method IsOpenDoorAnchorFrame() in Terraria.WorldGen.cs.
  18. Information taken from the Desktop version Desktop 1.4.4.9 source code, field BasicChest in Terraria.ID.TileID.Sets.cs.
  19. The game will check the tiles from top to bottom, and left to right. If detected a tile with higher score than any checked tiles, then it will be reserved as the home tile; if a tile's score is lower than or equal to the previous score, then it will be skipped. So, when multiple tiles are tied with each other, the topmost and leftmost tile will be selected as the home tile.
  20. The existing home tile can be rendered invalid by the second calculation in home tile score check, so not all small house setups is able to accommodate two NPCs.
  21. Information taken from the Desktop version Desktop 1.4.4.9 source code, method CheckSpecialTownNPCSpawningConditions() in Terraria.WorldGen.cs.
  22. Information taken from the Desktop version Desktop 1.4.4.9 source code, methods TrySpawningTownNPC() in Terraria.WorldGen.cs and SpawnTownNPC() in Terraria.WorldGen.cs. For any other valid housing walls, the move in chance is 1/1 (100%), while Sandstone Brick Walls have a chance of 1/4 (25%).