So, I was looking through the source earlier, and I was wondering if anyone had any thoughts or objections regarding adding a !is_sheltered flag to the random NPC spawn logic to make random NPCs only spawn outside. (I’m also wondering there are additional complications in the spawn code that I missed due to the way that NPCs seem to move when they’re outside the reality bubble.)
I know that NPCs are very much a work in progress, that tons of stuff is planned, and that the bottleneck is people to work on development. My motivation here is that I would be happy playing with random NPCs on in their current psychotic loot-piñata state, except that there really isn’t a good way to keep them from showing up inside your base and stealing your stuff. I completely get that in a post-apocalyptic scenario a lot of the tension comes from other people trying to take resources that you need to survive; My objection is that no matter how well you seal off the windows and build steel doors and trap your hallways, a random NPC will still probably show up inside your base/basement without having to traverse all of the barriers you put up, meaning that fortifying your base is largely pointless if you’re using static Z’s and have hordes off. (And hordes have their own problems right now.) The only fixes that I’ve heard either involve putting everything in crates, or blocking off all lines of sight to your storage areas, both of which make it really hard to have a usable workshop space.
As I understand it, if random NPCs only spawned outside, they’d still wander over and try to take your stuff if they saw it. It’s just that if you had metal doors and a trap hallway, they would probably ignore your base, or get themselves killed if they tried to get in.
Hm, i did not know that they could spawn like that.
I did not even ever think that they were spawned dynamically.
A quick fix for this would be to not make them spawn dynamically, and make them spawn statically. Though to avert them dying really stupidly we should spawn them in safe places, at least the majority. Hmm… i am throwing ideas here. This thing of spawning dynamically would lso be good lor wise, because supposedly after some time npcs should stop appearing, because they’d be mostly dead in the post apocalyptic scenario. Sorry to talk to myself, but i guess this could help. NPCs could still appear inside, but would not be a thing like what you said.
Currently, random NPC spawning system is incredibly crude - it picks a map side and a random point alongside this side and places the NPC there or in the nearest empty spot. It can even create NPCs in totally enclosed spaces (though not inside walls).
Though it would be cool if it didn’t totally prevent them from spawning underground. It should at least allow them to spawn on upstairs.
[quote=“Coolthulhu, post:3, topic:8926”]Sounds good to me.
Currently, random NPC spawning system is incredibly crude - it picks a map side and a random point alongside this side and places the NPC there or in the nearest empty spot. It can even create NPCs in totally enclosed spaces (though not inside walls).
Though it would be cool if it didn’t totally prevent them from spawning underground. It should at least allow them to spawn on upstairs.[/quote]
If I’m reading the code for npc::place_on_map() correctly, it appears to pick a random spot, then spiral around it until it finds an empty location. However, the function doesn’t seem to actually have a limit for how far it seeks; it’s just a while loop that keeps going until it finds an empty spot. It looks like combined with the overmap spawning code the game would hang if you excluded sheltered squares. Hmm.
It’s especially noticeable when you set up base in multi-tile buildings like megastores. I had one living in the NE corner of one for weeks just glued to the corner because they couldn’t figure out how to walk through walls, until I got bored of their shit and grenaded them.
Okay, I see what you’re saying a little better now, and of course it means that fixing it is a bit more complicated. It looks like the spawn_mon command picks a direction and a point along that direction like you said, but the code that is responsible for actually placing random NPCs in open space is the same code that places existing (and possibly already inside) NPCs when they become active, a few function calls deep. Should still be fixable without a complete overhaul, but I’d need to think about how to do it cleanly.
You could have it check proper locations at spawn_mon.
For example, if the chosen point is not OK, move clockwise (by some random step amount, not to spawn only wall-hugging NPCs), switching edges when current one “runs out” and bailing out if you wrap back to start. Bonus points if you also checked overmap tile type, not to spawn NPCs in open-air sections of mansions, prisons or public works.
Don’t be too concerned about performance - even if you checked all the points along the edges, it would be like, 500 checks, all of which could be simple array reads.
As for comparison, few versions ago NPC pathing to a point 20 tiles from them could easily make 1000 checks (existence of bashable furniture, terrain, vehicle etc.), possibly every turn. And spawn_mon won’t be invoked every turn.