Building a simple combat system: attacking without weapons

I’m attempting to set up a simple combat system in Inform 7 (at the moment I’ve largely based it upon a simplified version of David Ratliff’s Armed).

I’m having a problem with the code: Attacking it with is an action applying to one visible thing and one carried thing. which in almost all cases makes complete sense. If, however, I wanted the player to be able to able to attack with their fists (if not carrying anything more appropriate), or animals with their teeth, how would I go about that?

I’d also like to build in some kind of priority system, where if the player doesn’t specify what they want to attack with, the game assumes they want to use either the last used weapon, or the most appropriate. Is there a was to have one weapon ‘equipped’ so that this is the case? Having to type in ‘attack milkman with sword’ becomes a little tiring just because the player also carries a battered cod, but I’d like to keep the option of using the fish (or anything, really) to attack if that’s what they’d like to do.

Try this.

[spoiler][code]“Test”

The block attacking rule is not listed in the check attacking rulebook.

Attacking it with is an action applying to one visible thing and one carried thing. Understand “Attack [something] with [something preferably held]” as attacking it with.

A weapon is a kind of thing. The current weapon is a weapon that varies.

Yourself is either weaponless or weaponful. The player is weaponful.

Check attacking when a weapon is touchable and player is weaponful (this is the choose weapon to attack with rule):
let the chosen weapon be nothing;
if the current weapon is not nothing and the current weapon is touchable begin;
now the chosen weapon is the current weapon;
otherwise;
now the chosen weapon is a random touchable weapon;
end if;
say “(with [the chosen weapon])[command clarification break]”;
try attacking the noun with the chosen weapon instead.

Before attacking something with the player (this is the attack without weapons rule):
now the player is weaponless;
try attacking the noun instead.

Check attacking when the noun is not a person (this is the can’t attack non people rule): say “You can only attack people.” instead.

Check attacking it with when the noun is not a person (this is the can’t attack non people with something rule): say “You can only attack people.” instead.

Check attacking the player (this is the can’t attack self rule): say “You shouldn’t be attacking yourself. It goes against regulations.” instead.

Check attacking the player with (this is the can’t attack self with something rule): say “You shouldn’t be attacking yourself. It goes against regulations.” instead.

Carry out attacking (this is the standard carry out attacking rule): now the player is weaponful.

Carry out attacking it with (this is the standard carry out attacking it with rule): now the current weapon is the second noun.

Carry out attacking (this is the decrease life count when attacking rule): decrement the life count of the noun.

Carry out attacking it with (this is the decrease life count when attacking it with rule): decrement the life count of the noun.

Carry out attacking (this is the remove obliterated people when attacking rule): if the life count of the noun is zero, remove the noun from play.

Carry out attacking it with (this is the remove obliterated people when attacking it with rule): if the life count of the noun is zero, remove the noun from play.

Report attacking (this is the standard report attacking rule): say “You attack [the noun][if the life count of the noun is zero], obliterating them completely[end if].”.

Report attacking it with (this is the standard report attacking it with rule): say “You attack [the noun] with [the second noun][if the life count of the noun is zero], obliterating them completely[end if].”.

A person has a number called the life count. Understand “fist” and “teeth” as yourself.

The Testing Room is A Room. The axe, the sword and the club are weapons in the testing room.

The evil demon is a person in the testing room. The life count of the demon is 10.

Test me with “attack demon / attack demon with fist / attack demon / attack demon with sword / attack demon / attack demon with club / attack demon / attack demon with axe / attack demon / attack demon with teeth”.[/code][/spoiler]

Here you can attack with and without weapons.

Hope this helps.

Alternatively, you could define two actions, “attacking it with” and “bare-attacking”. Then have something like

Carry out bare-attacking:
if [pick a weapon however you like]:
try attacking the noun with W;
else:
try attacking the noun with the fists.

Surely it would be better to use the built in attacking action rather than defining a “bare-attacking” action so that you don’t need to redefine the grammar.

Also, “attacking the noun with the fists” would need the implementation of a fist object. Similarly with every other body part the player could possibly attack something with. It would be simpler to “attacking the noun with the player” and then have Inform understand “fist” and any other body parts as the player.

I like having clearly distinguished action names, so that I don’t confuse myself. Really, in this case, I would use the built-in attacking action and then add a “weapon-attacking it with” action.

Sure. In the interests of generality, the game should accept “ATTACK ORC WITH FIST”, and therefore “X FIST” and so on. Having all the body parts be a single object, or be represented by the player object, are reasonable alternatives depending on how your combat system works – I didn’t mean to rule them out; I was just giving an example.

I might have misunderstood the point of the “bare-attacking” action here. I was assuming that it deals with cases like “Attack [something]”, which the built-in attacking action usually deals with.

Maybe I was a little unclear here. My point was don’t forget to implement the fist object here. Alternatively, you could always divert to the no second noun version. Either way works.

Wow, thanks for that, climbingstairs. I managed to get what I wanted by using your example, and basically attacking with the player if the player didn’t carry an equipped thing. This meant I didn’t have to define a second action, either.

Could this be easily tweaked so that enemies can do the same thing with themselves if they don’t carry an equippied thing?

The most pertinent chunk of my code is:

[spoiler][code]Rule for supplying a missing second noun while attacking with:
if the player carries an equipped thing:
now the second noun is a random equipped thing carried by the player;
otherwise:
now the second noun is the player.

Definition: a thing is useless if it is not the player and it is not a weapon.

Report attacking something (called the target) with something (called the pigsticker) (this is the report attacking people rule):
if the target is a person begin;
if the target is dead begin;
say “With a final thrust of your [pigsticker], [the target] drops to the ground, dead.” instead;
end if;
if the pigsticker is at ease begin;
if the pigsticker is not the player begin;
try silently equipping the pigsticker;
end if;
end if;
say “You[if the pigsticker is useless] (somewhat strangely)[end if] attack [the target][if the pigsticker is not the player] with your [pigsticker][otherwise][one of] with your teeth[or] with your fists[or]with a kick[at random][end if]! [The target] yells out in pain. ([The target][apostrophe]s health: [present health of the target])[line break]”;
end if.[/code][/spoiler]

which works fine for the player, but no one else can do it.