1
\$\begingroup\$

I'm writing my first game. It's an adventure-RPG in the style of Starflight. I'm thinking about how to represent game state. There are three obvious parts of game state: dialog, combat, and story/quest.

I could have three separate data structures, but some state elements don't fall clearly into a single jurisdiction. For example, maybe a quest requires that you damage several ships without destroying them. Quest directives are generally story elements, and ship damage is an element of combat, so in this case a collection of combat elements is equivalent to a story element.

You might suggest a workaround where the quest element is separate, and isn't updated until combat ends. This is limited, though. What if a particular ship is supposed to spawn during combat once the quest directive is met? Now you have a dependence between elements in two different data structures -- elements that represent essentially the same piece of information.

This might lead me to a use a monolithic structure that houses all state elements, but intuitively this strikes me as sloppy and error-prone.

So how is it generally done?

\$\endgroup\$
4
\$\begingroup\$

This is sort of open ended, but I would generally recommend that you have a list of open quests, separate from your other state.

When something interesting happens, you generate an event that describes what happened ("player ship took 9 points damage from enemy Foo"), and pass that event through your quest queue - each quest would then decide if it cared about the event, and would react accordingly. Depending on your implementation language, you can have an event hierarchy to let you decide how to react - for example, you could have a "combat" event (if a quest cared about any hostilities to break a truce), then a "combat damage" or "combat miss" set (to trigger an ally's help, or give bonus points to the player for avoiding damage), etc.

In your example case, once a quest was satisfied by seeing a particular event, you could simply spawn your ship.

This sort of de-coupling has proved useful on a number of shipping titles.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.