Inform Recipes

© 2005,2006,2007 Jeremiah McCall – permission is granted for non-profit educational reproduction. Please credit the author. Feel free to link to this page but do not reproduce the contents on another webpage

Contents

Basic military units that follow orders.

This recipe creates a unit of British soldiers and a unit of colonial militia for a Battle of Lexington and Concord scenario. The game does very little, but it illustrates how a unit can be created that will follow the commands of the player.

Step 1: Creating the Military Unit.

Assume that the following set up of geography and placement people/things has been created:

The field is a room. “A dirt road crossing a grassy field. To the north, the buildings on the edge of the village of Lexington lie.”
Outskirts of Lexington is north of the field. “You are amidst the outer houses of Lexington proper. The road continues north is to the town center and runs south to a field.”
Center of Lexington is north of the Outskirts. “The town center of Lexington. There is a grassy place here where the villagers meet to discuss affairs and socialize.”
The British soldiers are in the field. John Parker is a man. John Parker is in the Center. The militia is in the Center.

Creating the Military Units

As with so many cases in Inform, we need to create a thing and then a set of properties for the thing. This time we will call the thing a force (our military unit). This military unit should have various properties in order to be an effective simulation. Several properties have been included for completeness but are not used in this recipe, accuracy, for example, and mood.

First, create the orders and the  force.

An order is a kind of value. march, load, ready, fire, rest, retreat are orders.
A force is a kind of thing. A force has an accuracy. A force has an order. A force has a mood. A force has a number called size.

The major disadvantage of creating a force as a kind of thing is that the user could actually take the force if desired; it would show up in her inventory, creating a nonsensical situation. To avoid this, override a command to pick up a force like so:

Instead of taking a force, say “That’s a strange command.”

Next, create the two forces needed in this case.

The British soldiers are a force. “A regiment of British soldiers.” The size of the British soldiers is 200. The order of the British soldiers is march. The description of the British soldiers is “A detachment of British regulars. Their current order is to [order of British soldiers]”.

The militia are a force. “Colonial militia.” The size of the militia is 75. The order of the militia is rest. The description of the militia is “A crowd of colonial militia. There are [size of militia]minutemen in the militia.”

Now we need to create some special actions to allow the player to order her troops. We’ll keep it simple and create three: fire, march, and at ease. To create a new action, we need to use the understand statement.

Understand “fire” as commanding fire. Commanding fire is an action applying to nothing.
Understand “march” as commanding march. Commanding march is an action applying to nothing.
Understand “at ease” as commanding rest. Commanding rest is an action applying to nothing.

Don’t forget, stating that an action applies to nothing simply means there is no direct object for the command. Since there is only one military unit, we do not need a direct object — the command always applies to the one unit of British regulars.

Now it’s time to write the code for carrying out these commands. All that is needed is to display text to the player indicating the order was received by the force, and change the order property of the force. Issuing orders does nothing else. We will write additional code for the force to actually carry out its current orders.

Carry out commanding rest:
say “At ease!”;
say “The soldiers quickly take on relaxed stances and begin to speak quietyly to one another.”;
Now the order of the British soldiers is rest.

Carry out commanding march:
say “March!”;
say “The soldiers shoulder their rifles and prepare to follow you.”;
Now the order of the British soldiers is march.

Carry out commanding fire:
say “FIRE!”;
say “The soldiers take aim and fire.”;
Now the order of the British soldiers is fire.

Now things get just a bit more complicated. Since the simulation needs to know what the current orders of a force after aevery turn, use the Every turn: statement.
Every turn: [make sure the player’s soldiers are following if they have been given the march order]
If the location of British soldiers is not the location of the player begin;
if the order of the British soldiers is march begin;
say “Your soldiers march along behind you to the rhythm of the snare drum and fife.”;
move the British soldiers to the location of the player;
end if;
end if;
[handle british firing if they have been ordered to fire]
If the order of the British soldiers is fire begin;
say “The muskets of the British soldiers crack and roar as smoke fills the air and lead flies toward the colonials.[line break][line break]”;
if a random chance of 1 in 2 succeeds begin; [50% chance of soldiers hitting]
let casualties be a random number between 1 and 5;
decrease the size of the militia by casualties;
say ” [casualties] of the colonial militia double over and fall to the ground.”;
end if;
end if.

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: