What's the "best" way to program branching story lines with NPC interactions, in a multi-location world

Started by
1 comment, last by LorenzoGatti 1 year, 8 months ago

my currently favored solution to the above problem is to have layered finite state machines [FSMs]. For example the top layer is a FSM that holds state about the current story 'chapter'. Each chapter is simply identified by an ID and a state in the ‘all-chapters’ FSM. All chapters FSM owns a set of chapter FSMs, one of which is activated, where the others are inactive. Each such chapter FSM owns a set of ‘location’ FSMs, one of which is current at any given time, depending on where the PC currently is located in the game world. For the chapter ‘Market Day’ the location FSM 'town square' would be different than the FSM for the same location during chapter ‘Execution Day’.

Drilling down to the location-FSMs, each of them owns a set of non-player-character[NPC]-FSMs, multiple of which can be currently active.

Viewed from the NPC, for a given NPC ‘Joan of Arc’ the NPC-FSM of, say the 'town square' location-FSM could be made up of completely different states than Joan's NPC-FSM of the location ‘Joan's hovel’. It could contain different dialog sequences or behaviors for Joan to act out. Also Joan's town square FSM during Execution Day would potentially be somewhat different to Joan's Market Day FSM.

Question: is this any good for modelling a fairly complex story based RPG game? Or am I missing something? Is there a better way to model something like this in code?

The one other way I could think of, doing this would lean more towards a big table of states, which can be looked up. But there I don't see how this would be manageable, without having big sections of branching code, always checking for many of the table's values.

Thanks for any tips.

Advertisement

For the chapter ‘Market Day’ the location FSM 'town square' would be different than the FSM for the same location during chapter ‘Execution Day’.

Drilling down to the location-FSMs, each of them owns a set of non-player-character[NPC]-FSMs, multiple of which can be currently active.

I'd expect a lot of quasi-duplicates: important characters and places , for instance, would appear in many chapters with similar content.

If the most important and most complex of your FSMs are the NPC ones, maybe they could be consolidated to have a single representation (instead of one for each of the many combinations of chapter and place where they could be present) and treat places and story chapters as inputs and global state:

  • If I am in the town square...
  • If it is market day...
  • If flag "the witch is dead" is set, as it should be by the end of chapter 2...
  • If a certain other character is at my location or within a day of travel...

Omae Wa Mou Shindeiru

This topic is closed to new replies.

Advertisement