• Register
Post news RSS The Antepenultimate AI Update for URR 0.8

Another AI update - farmers, innkeeps, monks, and a huge host of bugs fixed!

Posted by on

I was going to publish this update yesterday, but I decided to leave it until today so that we could hopefully have all the monastery stuff done. Almost all of the monasteries’ AI now works correctly, along with the other stuff, which means next week’s update will be on castles and everything else that needs doing in the interim. This update looks at monasteries and a ton of extra work on innkeeps and farmers, and a pretty exciting selection of bugs that came up in the process, the combination of which prevented me from also getting castles done this weekend (in the UK we have a four-day easter weekend, so I’ve been coding all Friday and today as well as Sat/Sun/Mon). What all of this means is that in a fortnight from today, I should be releasing the playtesting release. It’s just castles and a few monastery issues to go, and then clearing and neatening some things up, then we’re (finally) good to go to move onto speech. Thanks to everyone for sticking with me this long – it has been tough, but we are so close to having all the AI stuff working for the playtesting release. If you want to be part of the interim playtest, you can still email me at my first name at this domain. For those who haven’t seen me mention this before, this is not 0.8, but rather an interim closed playtesting release for making sure that all the AI stuff is working correctly. For now, though, here’s a summary of all the final AI stuff implemented this week:


Monasteries and castles were always going to be two of the hardest areas to make work perfectly. Castles are complex because they have so many different classes of NPC going about their day and many different floors, whilst monasteries were always going to be challenging because they can contain many buildings – the monastery itself, a nearly religious building for worship, and potentially delegate housing if in a democratic nation that allows its monasteries to have delegates – and the schedules of the monks include interior and exterior behaviours within the monastery (studying), within the religious building (prayer), and outside (tending to the vegetable garden). Additionally, monasteries are an area with a tiny number of important NPCs (i.e. a couple of the monks) and a large number of semi-important NPCs who should be indistinguishable from the other monks (i.e. the rest of the monks), and these categories need to work correctly despite having quite different code with regards to their scheduling. I’ll be working on all the NPC schedules we need in castles this coming week, but as far as I can tell monasteries are now all working correctly! Here are some examples – you’ve seen lots of monks before, but they now tend their vegetable gardens correctly, and head to bed correctly, although there remain a few minor issues that need resolving for next week…



And a monk (I’m using “monk” for women and men, since “nun” has a lot of connotations that are distinct from monk) in such a monastery:


More Farmers and Innkeeps

As is becoming a pattern, it turned out that farmers and innkeeps were not working perfectly. The issue with the former was in matching up both important and non-important farmers in their homes at the appropriate times in their schedules (e.g. night) and then making sure those farmers are the ones that start farming in the day, instead of spawning a second copy. Later issues were then discovered with various combinations of being in buildings, out of buildings, being important, being unimportant, etc, including a few weird errors that arose because “Farmhouse” wasn’t in a few places it should be in order to acknowledge it as a potential type of house for an NPC.

The issue with the latter was that although 95% of the ambassador code was usable, I had forgotten that the usual movement for innkeeps (wandering around behind the counter) uses a very different chunk of code from ambassadors (wandering around their embassy and sitting at chairs and talking to people), which meant that innkeeps, if they had just been awoken and then the player entered and therefore spawned the building, it would often place them outside the bar’s counter and get them wandering around their own tavern instead of serving drinks! I’ve now fixed all of this nonsense.



A huge number of bugs were resolved this week. For some reason, wandering NPCs who enter a building whilst the player is outside and the building is not spawned, and then the player enters and spawns that building, were not behaving properly and were causing the game to crash by attempting to path outside the building. I don’t understand what caused this, since I don’t think I changed any code that deals with that stuff, or even any code related to that stuff, but either way, it’s now fixed; fixed by dealing with the effect instead of finding the cause, but fixed regardless.

Then we had another very weird bug which took a while to track down, but basically if you moved onto the same tile as a sleeping NPC, on a different floor, and that NPC was of a specific class and had been spawned in a particular way, they would move onto the staircase down, and then just sit there doing nothing. Turned out this was an incredibly old line of code that wasn’t fit to handle buildings of multiple floors, and just needed a single line added, but that took a good few hours to hunt down…

Another bug emerged whereby when you went up a staircase, if you then immediately tried to move onto a tile which was occupied by another NPC, and that NPC wasn’t moving, you could switch places with them. This one meant that, in effect, you could transfer someone off their bed, whilst sleeping, and put them on the staircase. Very silly. Like the first in this list, I’m still not completely sure what caused this, but I’ve fixed it regardless by adding a special line of code that prevents you doing a “force switch” with another NPC so long as you’re on a staircase, since the staircase definitely creates the problem.

I also ran into a really strange bug involving the corners of city walls placed outside those walls. If you were going from Map Grid XlY to Map Grid X,Y-1 and there was a city on Map Grid X+1,Y or Map Grid X+1,Y-1, then the game would check whether you could path to the corner of the map grid (as it should), but rather than concluding that this couldn’t be pathed to (on account of being city wall), it instead concluded it could be pathed to with a path time of 0 moves. As in, it defaulted to 0 as the “error” path length, rather than 9999 or some equivalent. This took a while to find since it has been a long time since I’ve handled the code for keeping track of the time it takes the player to move around the map, but has now been fixed, and no longer teleports the player into impossible corners if they then instantly re-enter a map grid after travelling out of it, and there’s a city wall in the corner.

Another bug emerged where it turned out that moving from map grid to map grid on foot, if the player was outside a city, caused the important NPCs to mysteriously vanish into oblivion. This was because I had originally codded it on the assumption – falsely, but it just didn’t occur to me – that only cities would have important NPCs… but of course monasteries, farms, towns and so forth do as well. This meant that when you simply walked from grid to grid, it didn’t think to check in on important NPCs because the player wasn’t going through a city gate, and everything was tethered to the gates. This was a quick copy-paste job to call the same “Check what important NPCs are doing” function when going over map grids, and as far as I can tell, that should have done it.

Honestly, a ton of this week has been on bug-fixing. It’s a real case of two steps forward, one step back: I code a bunch of new AI stuff, and then discover loads of weird new bugs in the process, spawned from the massive complexity of URR 0.8. Still, there can’t be that many bugs left now… right?

And finally, since this is a relatively screenshot-light entry, some NPCs from a nation I ran into during the process of playtesting. See you all next week for finished monastery AI, and hopefully the completion of the biggest challenge of all – CASTLES.



I really like how much detail you put into your posts, can't wait to see the finished game.

Reply Good karma Bad karma+1 vote
UltimaRatioRegum Author

Thanks! :)

Reply Good karma+2 votes

Uuh uuuh! So much great new stuff!

Will there be different kinds of monasteries with different specialities like making wine or like carpentry or stone working or some other craft for making sacred items? Statues and such for example that could contribute to the upkeep of the monastery.

Reply Good karma Bad karma+1 vote
UltimaRatioRegum Author

Haha, thanks! Yes, definitely, but not in this release :).

Reply Good karma+1 vote
Post a comment
Sign in or join with:

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.