Interior NPC Behaviour

Well, it has been another very busy week – I gave a talk on URR’s PCG and AI systems at nucl.ai in Vienna (and spent an afternoon sitting the sun outside a rather nice vegan cafe working on the secret project I’ve mentioned a few times, which continues to inch closer to the point where I can actually announce something) and I’ve also had a piece the 35th Anniversary of Rogue published in Paste Magazine (which you can read here) and another on the role of text and characters in classic roguelikes published in Imaginary Realities (here), but nevertheless significant progress has been made (though I anticipate this next week to be a full week of coding with nothing else, so we should have a major update in seven days).

Towns, Fortresses, Etc

NPCs can now pathfind sensibly around other places which aren’t city districts – they know where to spawn and how to behave in the crowd in fortresses, in towns, in slums, and also in hunter-gatherer encampments. In these cases they generally don’t use the roads, because having people pathfind on a road until they get close to their target, and then move off the road, magnifies pathfinding complexity immensely – what if they get near the target, but then the actual path from the end of the road to the target is long due to a wall (so they are physically proximate but the path to that proximate location is huge), and the complexity of the problem of making sure they take an efficient road path, followed by an efficient off-road path, is massive – so we’re ignoring it. Besides, particularly in towns I think this actually works quite effectively when roads look more like a form of aesthetic/spatial structuring of the town rather than literally what everyone uses to walk around, and fortresses tend not to have roads anyway unless there’s a river cutting through them. The right groups of NPCs now spawn in fortesses and elsewhere, of course, so we see lots of soldiers in fortresses, the poorest of the poor in slums, ordinary citizens in towns, and tribal peoples in hunter-gatherer territories. This is, however, making it clear that I need to return to clothing generation at some point soon and really get moving on the other algorithms for lower/middle class feudal clothing, and other clothing types too – it’s a huge job, and actually bigger than I thought, so I’m going to devote a solid week or two to that once I’m back from GDC Europe (if you’re there, come along to my talk!). Here’s a town brimming with activity:

Town Wandering

Inside/Outside

The big one – NPCs now actually go inside buildings (they previously despawned at the door, in essence) and if you then go into the building, you can then see that same NPC inside the building. If the building has already been spawned and exists, then the NPC will go about their business inside the building. Alternatively, if the building hasn’t yet been spawned, they are temporarily placed in “limbo” until one of two things happens. If the building is spawned (i.e. by the player stepping inside), then that NPC is granted a number of turns to move around in the building as if they had been moving around inside the whole time. Alternatively, if an NPC has “entered” a building that the player doesn’t spawn, then after a random length of time they will the leave the building and continue on their way. In this method we are left with no pointless NPCs milling around in “limbo”, ensures that the crowd is always centered on the player, and means that if you see NPCs going into a building, they will be inside. In this gif, an NPC has previously entered this tavern; we’ll now enter, causing the building to spawn, and then the NPC spawns and we see them take a seat, and then if we go outside, they’ll exit again after a certain point (at the end we then see another NPC enter). This basically means that regardless of the player’s actions and which parts of the map actually exist, the crowd’s actions always appear to make sense. A similar system will be needed once I start tracking the important and non-spawned NPCs around the world (rulers, merchants, etc).

Tavern

Inside Behaviour

NPCs will now create a list of potential “targets” within a building and will hang around at those targets for sensible amounts of time, and then when those timers end, they’ll either leave or go to something else within the building. This process depends on the building and the nature of a given target. For example, someone who goes into a tavern and sits on a chair to drink for a while will not then get up and move to another chair – they’ll either just stay on the chair, or get up and leave. By contrast, somebody in a cathedral might spend a lot of time sitting at one chair worshipping in front of an altar, then move to study the holy texts at a desk, then talk to a priest, then leave, etc. I’m working at the moment on finishing off this list of targets, and then also adding a second layer whereby the list of targets is modulated by the time of day; so people will tend to leave as its gets near night, or people in this houses will head to bed, etc. Here’s a gif of some inside behaviour in a tavern:

Taverntime

As you can see, more people currently leave than enter; I’m working on balancing these two algorithms at the moment so we have a steady flow of entering/leaving whatever structure the player might happen to be in at the time.

Sorry also about the relative lack of images this week: a huge amount of this week’s work has just been improving pathfinding, improving how NPCs move and behave, a lot of technical improvement on saving/loading and managing buildings and floors and buildings which are/aren’t spawned, etc, so there aren’t that many pictures to show. I hope for more next time!

What now?

Making the interior behaviour sensible and interesting for all NPCs, giving buildings a “maximum” number of people they can hold, adding day/night differences, fixing the massive number of edge cases which are slowly building up… etc. More next week!

Be Sociable, Share!

15 thoughts on “Interior NPC Behaviour

  1. I can keep secrets too !! TELL US !!

    Otherwise, it’s incredible how the game seems to be going, improving and how you are focused on it. I really admire your work and dedication, it’s incredible.
    If 2016 IRDC will happens in Paris, hell yeah I’ll come !

  2. Damn, I love how is it progressing.

    Hey, have you thought what happened if all houses are claimed and an NPC wants to go into a house?

    Also maybe If you spend much time in a place, NPCs would start to be spawned from the pool that spawned at first rather than generating new ones?
    That’d be kind of useless and generally overlooked but I felt I had to suggest it.

    • Thanks! I do not believe that will *ever* happen (the numbers here are huge) but I have put it on my list of things to handle if need be. It’ll just delete NPCs from ancient houses/buildings and repopulate those, starting with the ones the player hasn’t paid attention to in ages. With that said, it will literally never happen; the weighting on the various pathfinding and crowd spawning/de-spawning algorithms would never allow it. I think.

      Nope, they will continue to vary!

  3. The potential target list is a very clever solution to handle npcs. Are there any precedents for this behaviour in games? I suppose some games like roller coaster tycoon use this solution?

    • I think that style of game might be the only one (though do some Sims games have similar code? I don’t know). The game also differs the system for some buildings, so in a gallery an NPC can move from one chair to another, but in a tavern they can only move from chair to door (i.e. people don’t generally change where they sit a lot in a tavern, but in a gallery one might reasonably move between different exhibitions and sit down at each one)!

  4. I like that NPCs in towns don’t strictly follow the roads, but it might be nice if they followed them a little bit more. Currently it looks too random/chaotic to me, since people do tend to follow roads. Perhaps decreasing the cost of road tiles in their (non-combat) pathfinding algorithm could achieve that effect.

    Another idea could be to make it so each time an NPC walks on a tile, there’s a chance the foliage level goes down (ie shrub to grass, or grass to dirt), so that dirt paths naturally form where NPCs tend to take shortcuts. Not sure if that would end up being aesthetically pleasing or horrid…

    • Thanks! Heh, I thought “is that Austin’s piece?”, and sure enough it was. His work is great. Secret project – yes! As soon as pen has been put to paper, I can announce it. Though actually… I now think that, more realistically, we might be looking at a few weeks on that. So I’ll shut up about it and just announce when there is something to announce…

  5. Looks good, do lower status NPCs avoid higher status NPCs? A lord isn’t going to step out of the way so a peasant may pass by, well I suppose it depends how charitable the lord is and how much he respects the common clay.

    Or perhaps the mob will stop and prostrate itself when the Sultan is carried past on his litter.

    • This is a great point, and something I hadn’t considered. Currently the first NPC to move is always the one that steps out the way, but I like the idea of making an NPC property willing_to_move or something like that, or maybe different ranks of willingness_to_move so that those of higher rank will always have those of lower rank move, not the reverse. And I *love* the idea of having crowd actions alter when an important NPC is passing through! They all line up at the side of the road, or shout praise (or insults), or pray, or whatever. Will definitely add this.

Leave a Reply

Your email address will not be published. Required fields are marked *