# Dressing Outrageously for Success in Mask of the Rose

*This month's development blog is from Failbetter programmer and principal developer on Mask of the Rose, Séamus Ó Buadhacháin*

I'm not sure Mask of the Rose would be a Failbetter game if you couldn't dress yourself outrageously to make a difficult task easier. As Emily has written, Mask is deterministic in places where our previous games have used randomness: success in a given challenge depends not on a die roll but a combination of variables affected by the choices you've made. But your outfit certainly still matters: present yourself as an avatar of the law, for example, and prepare for difficulty ingratiating yourself with people on the other side of it.

Communicating this kind of effect to players is, of course, a pretty crucial part of any outfit system, and there are some fairly standard ways of doing so. We've presented the effect of your wardrobe in our previous games in traditional RPG fashion: if carrying around an unexploded mine helps you win arguments, or having an incognito princess aboard your locomotive makes it easier to get along with space-faring bohemians, this is explained to the player with visible changes to the underlying variables that are being modified: the relevant number goes up or down. It's a tried and true system and it's especially well suited to games with random challenges and a lot of stats to track.

Mask is designed as a chattier, intimate experience, and quite early on in development we decided that the wardrobe view should work towards this design goal too. There are still a dizzying number of variables at work driving any interaction, but baldly describing a given hat as +1 Coquettish didn't seem to fit the theme quite so well this time. So, as you'll have seen if you've played the demo, when you put on a set of outfit items, the wardrobe view talks back to you instead: your own player character telling you, in English, how you're likely to come across when you leave the attic room you call home.

This is something we could really only pull off with Mask's comparatively tight scope. (It would certainly be entirely out of the question in Fallen London, for example, where some back-of-the-envelope maths suggests there are around 120 billion outfit combinations.) Even in Mask, though, the number of potential outfit combinations is comfortably in the thousands, far beyond what's reasonable to ask a team of writers to describe one by one. Handling combinatorial explosions like this requires a certain amount of algorithmic deftness. Or, to put it another way, we have to cheat a bit.

Our particular style of cheating borrows from formal language theory. The underlying model for outfit descriptions is a grammar: a set of x → y rules for replacing something on the left-hand side of the rule (x) with something on the right-hand side (y). Suppose we just want to let the player pick a choice of hat, and to describe it. The rules for describing hats might look like this, with the hat in question on the left-hand side and its description on the right:

- ordinary hat → "a perfectly fine hat"
- fancy hat → "a fabulous choice of headwear"
- hideous hat → "quite a… novel and fascinating hat"
- no hat → "a very brave choice, not to wear a hat"

With a certain amount of care in how we frame it, we can embed this hat-description rule into a longer text in such a way that we will always generate a well-formed sentence if we replace it; a template, in other words:

That's [hat-description]! You're sure to make a splash.

When we want to talk back to the player, it's pretty straightforward: check what they're wearing; find a rule that matches what they're wearing; and substitute in the right-hand side of the rule. If the player's wearing an ordinary hat, for example, we can replace [hat-description] with the right-hand side of the rule for describing an ordinary hat:

That's a perfectly fine hat! You're sure to make a splash.

This is a pretty basic system, certainly, but we're off to a decent start. If we now let the player change shoes, and add some rules for describing shoes…

- fancy shoes → "What lovely shoes!"
- ugly shoes → "Your shoes are quite… remarkable!"
- no shoes → "I do hear bare feet are quite en vogue."

…we can update our top-level outfit description to embed a shoes-description rule as well:

That's [hat-description]! [shoes-description]

Let's say the player is wearing a hideous hat, and no shoes. Expanding this new outfit rule step by step — hat, then shoes — produces first (by finding a matching hat rule)

That's quite a… novel and fascinating hat! [shoes-description]

and then (by finding a matching shoes rule)

That's quite a… novel and fascinating hat! I do hear bare feet are quite en vogue.

We might not be being terribly candid, but we've managed to produce a coherent opinion. (The Mask PC's internal monologue is more honest.) Any combination of hat and shoes should work: find a matching hat-description; find a matching shoes-description; fill out the template. The results will tend to look suspiciously similar, tipping our hand to the algorithmic work going on behind the scenes, but we can do something about that later.

You may have already noticed a quietly important property of this approach: by writing 4 + 3 = 7 rules (plus a top-level outfit-description rule), we're able to describe 4 × 3 = 12 different outfit combinations. Another pair of shoes would increase this to 16, but we'd only need to write one more rule. This will continue to scale as we add more outfit items: strictly speaking, we only need a linearly-increasing number of rules to describe a geometrically-increasing set of combinations. This becomes especially handy when we go beyond just hats and shoes to describe, say, the player's coat or gloves, and the extra multiplicative terms cause the number of potential combinations to grow even more quickly.

This efficiency gives us some breathing room to finesse the system. One thing we can do to make our system fancier is add some rules for special cases: noteworthy combinations of particular items, for example. Let's add some [shoes-description] rules to apply when the player is wearing a particular kind of hat as well:

- (ugly shoes, hideous hat) → "And the shoes match perfectly!"
- (ugly shoes, fancy hat) → "And the shoes make a delightful contrast!"

If we agree, when looking for a rule, to always pick the rule that matches the largest number of items in the player's outfit, then we'll pick these if (and only if) the player is wearing both items, and our outfit description for (ugly shoes, hideous hat) will expand, step by step:

That's [hat-description]! [shoes-description]

That's quite a… novel and fascinating hat! [shoes-description]

That's quite a… novel and fascinating hat! And the shoes match perfectly!

We can write some more specific [hat-description] rules, too; and, in fact, we can write some extremely specific top-level outfit rules, for outfit combinations that are so outré that the entire structure of the description template ought to change. It's a very effective way to start getting that sameness we observed earlier out of the system; with a few dozen such rules, we can produce good descriptions for thousands of combinations. (A number of unusual special cases are handled like this in the Mask demo, and it might be rewarding to revisit the wardrobe with this in mind.)

We're still not done in terms of what's possible, either: we can add multiple rules of equal specificity and choose randomly between them, to provide even more variation. And, while so far we've restricted ourselves to just using what the player is currently wearing, we don't strictly need to: we can also consider things that have previously happened. Any aspect of the game state that can be expressed in a similar way can be fed into our system, if we want. So there's really nothing stopping us from writing rules like this:

- (hideous hat, player-has-met-the-aliens) → "a novel and fascinating hat, quite improved by the scorch marks from the aliens' death rays"

(Well, nothing but considerations of taste in narrative design, perhaps.)

In fact, this last idea — that you can take arbitrary bits of a game's state, pass it through a set of grammar rules, and produce coherent, meaningful textual content — is extremely powerful in the right hands. Once the technical pipework for describing outfits is in place, it's easy to generalise it and apply it wherever it's useful.

This has enabled us to give Mask's text some real dynamism. We've used it for a number of other gameplay systems in Mask, some of which are already at work in the demo and some of which are under development for launch. It's been extremely rewarding to work on and test internally; I hope you enjoy the finished product!