Wednesday, January 30, 2013

January Update: Commoner AI

January has a large update, so I've broken it into two parts so your eyes don't glaze over reading. :-)  The first part is about the commoner ai.

I started testing Crimmor with commoners running my commoner ai, and discovered performance with as many commoners as I wanted was terrible. Miserably terrible. Horrific. I was actually causing spontaneous crashes because of high memory usage. For me, this was happening around 1.5 gigs of memory in use. For comparison, Storm of Zehir uses up to around 900 megs on my pc.

I had Crimmor as one big module, something I had wanted so that once the game loads the player can move around the city with minimal loading. So I split Crimmor into 6 modules, each of moderate (15-20 area) size, one module for each ward of the city and one module for the few areas outside the city.

At the end of that, my campaign was still crashing from memory usage, so I had to address the commoner ai directly. I decided to have my commoners adopt specific activities instead of dynamically deciding, and only change twice a day, to go home at night and wake up in the morning. So I wrote up activity specific heartbeat scripts for commoners covering the 20 or so activities I felt would be most common from the commoner ai. (released at

These new generic activity heartbeats actually support combat, so they can be used for enemies, and many only require setting a heartbeat, so they are even easier to set up than the full commoner ai. It's a major addition to my existing commoner ai. You can now easily have your orcs eating dinner when the player walks in, and they will get up and attack :-)

Anyway, these new heartbeats brought Crimmor's memory usage back down to a reasonable level, typically 1 to 1.2 gig, and my crashes have ended. It's still higher than other modules because I have a lot of things going on ai wise, lots of city folk. I may still write custom versions of these scripts to include the Brian Meyer's CSL if that's necessary to make the city as crowded as I want, as his CSL ai can handle hundreds on npcs in combat simultaneously.