Saturday, February 23, 2019

Enumerated Values

So here is a very simple story that I'm going to use for now, but over time I'll make refinements to it as I post more.

Concealment is a kind of value. 
Concealment are none, fairly, mostly, and completely.
Concealment is usually none.
A person has a concealment.

When play begins:
    Cover is blown in eight turns from now;
    Now concealment of the player is none.

[ROOMS]

The Employee Break Area is a room. "A break room that is clearly for employees of some company.  The walls are littered with information about minimum wage, HR regulations, and so on.[if unvisited]  You aren't exactly sure how you have come to get here, but you hear voices...  Not good voices, coming from the distance and growing closer.[otherwise]  Those voices continue to get closer.[end if]  To the east and west you see a door."

The Employee Closet is a room. "You enter the closet.  It's small and dusty, but you feel that you might be able to hide in here.  You notice the floor is somewhat uneven as you back up slowly into the closet and close the door."

The Employee Bathroom is a room. "You enter the bathroom.  It's quite roomy and you can see a lock on the door.  Clearly you could hide out in here, but for how long?  You feel a breeze coming from a half a foot high vent that is at floor level."

The Hiding Area is a room. "You creep down into the floor and into the open area underneath the closet.[if unvisited]  You feel around and feel small bars of metal, but are unable to properly identify what the metal is.  You attempt to pick up one of the small bars and notice that it has immense weight.[end if]  You slide the boarding back over the hole."

The Vent Shaft is a room.  "You crawl into the venting area.  The pipe narrows too much to go any further than maybe eight feet.  However, you turn around crawl backwards into the venting and pull the grate back over the vent."

[DIRECTIONS]

The Employee Closet is west of The Employee Break Area.

The Employee Bathroom is east of The Employee Break Area.

The Hiding Area is below the Employee Closet.

The Vent Shaft is east of The Employee Bathroom.

[CONCEALMENT]
After going to The Employee Break Area:
    Now concealment of the player is none;
    Continue the action.
    
After going to The Employee Closet:
    Now concealment of the player is fairly;
    Continue the action.
    
After going to the Employee Bathroom:
    Now concealment of the player is mostly;
    Continue the action.
    
After going to the Hiding Area:
    Now concealment of the player is mostly;
    Continue the action.
    
After going to the Vent Shaft:
    Now concealment of the player is completely;
    Continue the action.

[EVENTS]
At the time when cover is blown:
    If concealment of the player is none:
        End the story saying "No effort was made to hide from the voices.  Instead you thought you might be able to fight them off.  Turns out you were wrong.";
    If concealment of the player is fairly:
        End the story saying "You at least tried...  However, now you realize you could have done way better.";
    If concealment of the player is mostly:
        If the player is in The Hiding Area:
            End the story saying "Foolish, you hid yourself in the same place they we're hiding their gold.";
        Otherwise:
            End the story saying "A good effort to hide from the voices, but in the end it was not enough.";
    If concealment of the player is completely:
        End the story finally saying "Great job you hid form them!!".
        
    
Test me with "e/e/z/z/z/z/z/z/z".

If you've ever heard of the programming term enumerations then you'll already be familiar with the concept that I'm going to be covering here. Let's take a look at the first four lines of this story. We are defining a new kind of value called concealment on the first line. The next line indicates that there are only four valid values for concealment. None, fairly, mostly, and completely. The third line indicates a default value that will be automatically assigned. The default value is none, which makes sense, by default you aren't hiding from someone. However, the default is important here because of the fourth and final line I'll be covering. We are taking the built in kind called person and adding the ability to define a concealment to it. That means every single person by default in your story will have a concealment value. Now you might not test that value against every single person in your story, but what happens when you create a person that ultimately will have that value tested? Here is where the default value is the saving grace for us from potential future mistakes. By default concealment will be none and we will have to explicitly set the concealment on our people.

These kinds of enumerated values like concealment are great for implementing all kinds of distinct but somewhat related kinds. You might have food that can either be good, bad, spoiled, or poisoned. Or you might have a powder that can exploded, puff of smoke, or do nothing. Or you might have a guard that has not noticed you, is somewhat alert, on guard, or fully aware of your presence. There's also ways to "increment" that value upwards or downwards, but I'll have to circle back on that in my next post.

No comments:

Post a Comment

Implementing Help in a Story