top expert

a biting cat website

doing things in order

alright, now what?

Last time, we discussed ways for getting an ordered list of combatants into a table. This was my approach to determining what ttrpg systems sometimes call “initiative.” In other words, in an IF system of turn-based combat, this was a means for determining the order in which all persons present—player and NPCs alike—act.

The previous post produced a table like this:

table of initiative
(row 1) | 1 | yourself | 12 | true |
(row 2) | 2 | groaner | 10 | true |
(row 3) | 3 | gurgler | 7 | true |
(row 4) | -- -- -- --
(row 5) | -- -- -- --
(row 6) | -- -- -- --

The idea is that the order runs top to bottom. There are some stats and mechanics behind the generation of this table content. Have a look at the previous post if you missed it!

Talking through things here, today, I believe we can only arrive at a rough idea of how things will play out. The main question for today is, in terms of orchestrating things, how can we realize the order established by the table of initiative?

The turn of an Inform game unwinds in response to a player’s typed command. Action processing is largely the prosecution of actions generated by the player’s command. If the player loses initiative, which they inevitably must in a balanced system, then we must arrange for the other actors—enemy combatants in this scenario—to act before the player. To set that in motion, we need to determine initiative before that.

As a thought exercise, we might imagine calculating it before action processing even begins. If we consult one of my favorite Inform artifacts, (bonus: or look at my Basic Inform and Standard Rules megathread), we see that action processing is initiated by the appropriately-named generate action rule. If we really wanted to get in front of everything, we could say something like this:

the turn order setting rule is listed before the generate action rule in the turn sequence rules.

this is the turn order setting rule:
now turn initialization ready is true;
if there is an enemy in the location:
follow the initiative rules;
continue the action;

This would, in fact, happen before anybody does anything! However, let’s consider: what if we want the player’s actions to affect their initiative? For instance, a player engaging in combat might have a standard initiative roll, but a player digging through a rucksack might suffer a penalty. This is purely conceptual. I have no specific penalty in mind, but if we did want to let the player’s chosen action influence initiative outcomes, we won’t be checking that before the generate action rule is processed. Let’s run a small experiment.

lab is a room.

the pointless rule is listed first in the action-processing rules.

this is the pointless rule:
say the current action;

This will yield the following at startup:

Welcome
An Interactive Fiction
Release 1 / Serial number 261013 / Inform 7 v10.1.2 / D

looking
lab

>

Let’s start with performing our initiative checks at the start of the action-processing rules, then.

the turn order setting rule is listed first in the action-processing rules.

Whew. OK, we have our list. How do we handle enemy actions that come before the player’s action? Let’s make another rulebook. My general approach these days is that if I’m making a rule, I might as well make a rulebook. This leaves me space to change my mind or make exceptions. Here’s my attempt:

lost initiative is a rulebook;

a lost initiative rule:
repeat through the table of initiative:
if combatant entry is the player:
rule succeeds;
let c be combatant entry;
let w be the equipped weapon of combatant entry;
let the next action be c attacking the player with w;
try the next action;
now pending entry is false;

Here, we repeat through our initiative table, starting at the top. This is only for enemies that act before the player, so the rulebook halts (succeeds) once the player’s row is reached.

In the meantime, the program does a bit of formatting to construct an action that Inform will easily digest. Our next action variable is built from the combatant table entry as well as the equipped weapon property assigned to characters in-game. Once we have all that together, we can assign the current combatant what Inform refers to as a “spontaneous action”.

Must we do it this way? No, instead of having actors perform actual actions, we could cook up rulebooks and run through them. However, if we have an “attacking it with” action that everyone is performing more or less the same, we may find it convenient to stick with actions.

Where should this rule go? I think further testing and experimentation is in order, but I think that I’ll start with a first before rule.

first before doing something:
follow the lost initiative rules;

This next part should be easy: the player acts. This is what we’re used to. But what about any leftover enemies? I think I’ll experiment with something similar:

first every turn when there is an enemy in the location (this is the enemy lost initiative handler rule):
follow the enemy follow up rules;

Why every turn phase, and not after? I think we really ought to wait for all of the player’s action to process. Our own custom attacking it with action may have no report rules, for instance, but lots of standard actions do. If the player decides to take something rather than attack, we don’t want messages getting garbled up. Let’s wait until the turn has concluded.

Our follow-up rule ought to look quite familiar. The main distinction is that it checks for combatants with a pending entry of true. Any enemies still pending will get their turn. This is how it looks for me at the moment:

enemy follow up is a rulebook.

an enemy follow up rule:
repeat through the table of initiative:
if pending entry is true:
let c be combatant entry;
let w be the equipped weapon of c;
let the next action be c attacking the player with c;
try the next action;
now pending entry is false;

If there’s anyone left, things will start all over again on the next turn. There’s a lot that hasn’t been fleshed out here. In fact, this is all quite exploratory. Does it work? So far! But Spring Thing is a long ways away.

Combatants:
>| Financier
> | Trustee and a geneticist

>financier

❤ June inflicts 5 points of damage on the financier.
↠ The genetic scientist wishes to study June! It is ready to sample her blood!
↠ The trustee lumbers forward, slobbering! It's so close, June can smell it!
⚔ The financier tries to report you to HR, but nothing happens.

Combatants:
>| Trustee, a geneticist, and a financier

>attack financier

☠ June calls in the financier's loan, shutting it down for good.
⚔ The genetic scientist draws blood, dealing 2 damage.
⚔ The trustee trips around ineffectually.

☁ The financier evaporates in a cloud of stinky black smoke. Such is the fate of those afflicted with Inherent Depravity.

Combatants:
>| Trustee and a geneticist

I hope reading about my efforts to figure out a combat system has been helpful! I may post more about this project in the future.

Leave a Reply