What’s the best way to control the order in which the player and the NPCs act (specifically in a combat setting)? Kerkerkruip did it nicely by breaking each round of combat into a number of turns, but I’d prefer to do it all in a single turn since I don’t have a reaction phase.

Stick 'em all in a table, sort that table by initiative-score order, repeat through that table dealing with each character in turn? You’d need to do a little hackery to allow for the PC to interrupt the sequence without resetting it, unless you wanted the PC’s action to be delayed a la RoboRally, but that seems the most obvious way to do it.

Good idea…but I honestly can’t think of any way to handle the player’s order in that situation except a) make the player always go last and just move anyone who ought to go after him to the beginning of the next round or b) faking it by having the actions take place in their normal orders, but delaying reporting and resolving the actions until the very end (and then doing them in initiative order). The later would be both difficult and hacky.

Maybe I could use something like Command Prompt On Cue to make several turns in a row appear like one turn?

Well, what you ideally want is to have rounds overlapping with game turns, right? So you want a procedure a bit like this:

Every turn:
If the initiative table has no entries, start a new combat round. Determine which characters are involved, assign them each an initiative score, and then sort the table in initiative order. Then:

If the initiative table has some entries, run through them, executing each character in turn and removing them from the table; if that character is the PC, stop the action. (The combat round is still ongoing; it’s just been interrupted. The player takes their turn, and then we run the every turn rules again.)

Then throw in an end condition, some special cases, and I think you’re good. I mean, this is essentially what you call option a), but if that’s not okay then what’s your ideal condition? Either the player’s command is delayed, or it resolves immediately; either the combat round corresponds exactly to the game turn (and the player always goes first), or they overlap.

You could just use ATTACK but not have any actions that require reactions.

ATTACK doesn’t have a strict everyone-gets-to-act round however, and the initiative system means you sometimes get two turns in a row. If that won’t work for your situation then ATTACK isn’t a good fit.

Of course I will use the attack action if the player is attacking; the question is how to control the order in which the player and the NPCs act.

From a game mechanics perspective, the difference between the actions resolved immediately (player goes first/last) option and the actions resolved later option is that the latter contains concealed information–you choose your action before you know that the people ahead of you in initiative are doing. So, for instance, you might try to pick something up only to find that someone else has already taken it, or you might attack before realizing that the fight is going to be a lot tougher than you expected.

The former is probably the best option, though, simply because it’s vastly easier to program.

I meant the extension ATTACK, which is what Kerkerkruip is built on.

Yes, if you need code that will allow some of the NPCs to act before the PC does, and all within a single turn, than you could take some code from the beginning of the ATTACK extension. It messes with the turn sequence rules in several way that allow you to do this.

Sorry, my mistake–I wasn’t aware there was an ATTACK extension (since it isn’t listed in the main Inform extensions page). Shows how well I keep abreast of Inform news. I’ll have a look at it.

OK, I’ve roughed out an initiative system according to Maga’s method, but it doesn’t quite work because it currently gives the player two turns for every one turn of the NPCs: One turn at the player’s point in initiative and one turn when the initiative table is empty. I’m not sure how to fix this without risking an infinite loop.

[code]The dojo is a room.

Combat mode is a truth state that varies. Combat mode is usually false.

Before an actor attacking:
if combat mode is false:
now combat mode is true;
determine initiative.

To determine initiative:
blank out the whole of the Table of Initiative;
repeat with P running through people in the location:
choose a blank row in the table of Initiative;
now the character entry is P;
now the initiative entry is a random number between 1 and 100;
sort the Table of Initiative in reverse initiative order.

Table of Initiative
Character Initiative
a person a number
with 30 blank rows

Every turn while combat mode is true:
if the table of initiative is empty:
determine initiative;
repeat through the table of initiative:
if the character entry is not nothing:
say “[character entry] [initiative entry] [line break]”;
if the character entry is the player:
blank out the whole row;
[character would act here]
blank out the whole row.

The player is in the dojo.
Jin is a man in the dojo.
Mugen is a man in the dojo.
Fuu is a woman in the dojo.

Test me with “attack Mugen/z/z/z/z”.[/code]

Risk the infinite loop, because you know that the player’s turn will always kick in and interrupt it. Or am I missing something?

If you can wait a week then you can try the combat-less ATTACK that I’m working on now.

I really am not interested in using ATTACK; my rule set is so widely at variance from his that modifying it to fit my needs would probably be more difficult than finishing what I’ve got (complete except for initiative, AI, and response tables).

That’s why it might be working looking at, because it won’t have anything more than the system for turn management, and places to hook an AI in.