The maze book for programmers!
mazesforprogrammers.com

Algorithms, circle mazes, hex grids, masking, weaving, braiding, 3D and 4D grids, spheres, and more!

DRM-Free Ebook

The Buckblog

assorted ramblings by Jamis Buck

Generators and Timelines

8 February 2004 — 2-minute read

In my rpg/software/NPCGenerator blog entry, I listed seven essential features/aspects of any NPC generator that would enjoy long-term success and popularity. In this entry I will mention, at a very high level, one possible implementation that would fulfill (specifically) the second criteria, namely making the generator goal-directed and incremental.

Timelines

This proposal introduces the concept of a timeline, which is (at its simplest) a sequence of events. Each event in a timeline is associated with a specific moment in time.

Events may be anything that the generator (or the user of the generator) wishes to record:

  • the physical location of the character at that point in time
  • the day on which a particular NPC was encountered by the character
  • the moment at which a new level was gained
  • when a particular curse or blessing was recieved, removed, or expired
  • when a new item was discovered and/or equipped

An event may or may not have any direct effect on the “state” of the character (ie, their current hit points, skill set, equipped items, movement rate, etc.). Those that do not are most likely simple strings that describe the event that took place (ie, the day on which a particular NPC was encountered). However, those that do affect the character’s state will consist of all of the new attribute changes (ie, equipment state, total hit points, new skills, to-hit bonuses, etc.).

What you have, then, is a timeline that describes each point-in-time that a character’s state changed, whether it was due to the gaining of a new level, or the reception of a curse, or the donning of a magical item.

Converting a Timeline to a Character

Once you have a timeline, it is simply a matter of accumulating the modifiers from each event, sequentially, into a new entity, the character. If you want a snapshot of what the character was like at a given point in time, you only accumulate the attributes up to that point.

It’s a little trickier than that, actually, since modifiers granted later may make it as if a modifier granted earlier never existed. In this case, a two-pass approach may be best: run through the timeline once, copying modifiers into a temporary timeline. When a modifier eliminates other modifiers, remove them from the temporary one. Then, accumulate the remaining modifiers in the temporary timeline into the final character.

Other Applications

The timeline approach works well for generating any sort of entity that may change over time: a treasure hoard, a community (be it a village or a kingdom, or even a world), a character, a history, or even a dungeon. All it takes is to identify the possible modifiers and how they may modify both the entity in question, and other modifiers. (Of course, saying “all it takes” is deceptively belittling—this would actually be the toughest part of the project.)

Reader Comments

I've been toying with the idea if a Python or Ruby-based MU*. Such a tool would be neat to provide as a feature in such a beast, I think.