Difference between revisions of "Manual:Game Mechanics/Combat"
(Created page with "Combat Melee & Spells The dynamics have changed since DIKU II for the purposes of being more responsive to your actual level/skill/abilities. The effect is that mobs will bec...") |
(checked against the current code (wiki review 2026-11-15)) |
||
| Line 1: | Line 1: | ||
| − | Combat | + | This page explains how a fight is worked out: rounds and attacks, the roll for each blow, damage, shields, armour, and what happens when hit points run out. The code is in <code>vme/src/combat.cpp</code> (rounds), <code>fight.cpp</code> (blows and damage), <code>experience.cpp</code> (the hit roll, shields, <code>consider</code>) and <code>skills.cpp</code> (damage tables). The players' side is in [[Help/Combat|help combat]] and [[Help/Kill|help kill]]. |
| − | + | == Starting and stopping == | |
| + | <code>kill</code> (or a skill such as <code>kick</code>, or an attack spell) starts a fight: both sides fight until one falls, dies or flees, or they are no longer in the same place. A character can fight several opponents, but hits one of them at a time; changing who they hit takes most of a round. Players can only fight each other when both have signed the Book of Blood ([[Help/Bob|help bob]]), and a room with <code>safe_room@function</code> refuses attacks altogether (see [[Manual:Game Mechanics/Rooms#Safe rooms|Rooms]]). | ||
| − | + | When someone falls stunned or worse, the fight stops for both; whoever wants to finish them off must attack again. | |
| − | + | == Rounds == | |
| − | + | A combat round comes every 3 seconds (<code>PULSE_VIOLENCE</code>). In each round every fighter has 12 units of time (<code>SPEED_DEFAULT</code>), and everything they do in the fight spends some: | |
| − | The | + | * a blow takes the weapon's speed from <code>vme/etc/weapons.def</code>: 9 for two-handed weapons, 7 for one-handed ones, 4 for light weapons such as the dagger, and 4 for natural attacks (2, but 4 is the least a blow takes); |
| + | * a skill or command typed during the fight takes its <code>turns</code> from <code>vme/etc/commands.def</code> (kick takes 6, half a round), and a spell its <code>turns</code> from <code>spells.def</code> (a full round unless the spell says otherwise). When the fighter has no time left this round, the command waits for the next; | ||
| + | * a fumble costs another half round (6 units), and changing whom you hit 9 units. | ||
| + | Time spent beyond the 12 is taken from the next round. | ||
| + | |||
| + | How many blows a fighter gets depends on their <code>speed</code>: 12 is normal, lower is faster (4 to 200). At normal speed a fighter strikes once a round, or twice when fighting with two weapons, but only if both blows fit in the 12 units: with two one-handed weapons (7 + 7) only one does; with a light weapon in one hand (7 + 4) both do. Faster fighters get more blows, and each takes less time: | ||
| + | {| class="wikitable" | ||
| + | ! Speed !! 12 !! 8 !! 6 !! 5 !! 4 | ||
| + | |- | ||
| + | | Blows per round (one weapon) || 1 || 1 || 2 || 2 || 2 (players), 3 (monsters) | ||
| + | |} | ||
| + | That is 1 × 12 / speed, rounded down, at most 2 for players and 3 for monsters. Haste spells and <code>SPEED_TRANSFER</code> items make a character faster. A speed above 12 doesn't give fewer blows: a fighter whose blow still fits in the round strikes every round, and one whose blow no longer fits (above speed 35 with a natural attack, 20 with a one-handed weapon, 16 with a two-handed one) never strikes at all. | ||
| + | |||
| + | == A blow == | ||
| + | Each blow is worked out in <code>one_hit()</code> in <code>fight.cpp</code>. | ||
| + | |||
| + | === Where it lands === | ||
| + | A roll of 2d8 picks the place: body 34%, legs 28%, arms 23%, and head, hands and feet 5% each. The armour worn there is the armour that counts for this blow. With none, the defender's natural armour counts (clothes for a player), with no bonus. | ||
| + | |||
| + | === The hit roll === | ||
| + | First the attack bonus (<code>melee_bonus()</code> in <code>experience.cpp</code>): | ||
| + | |||
| + | bonus = 2 × (attack ability - defender's dexterity) | ||
| + | + 2 × (attacker's weapon skill - defender's weapon defence) | ||
| + | + attacker's bonuses - defender's bonuses | ||
| + | |||
| + | and at least -50. Then: | ||
| + | |||
| + | result = bonus + open-ended 1d100 (+ the bonus of a skill such as kick) | ||
| + | |||
| + | {| class="wikitable" | ||
| + | ! Part !! What it is | ||
| + | |- | ||
| + | | attack ability || the average of the three abilities the weapon uses (most weapons: strength, strength, dexterity) | ||
| + | |- | ||
| + | | defender's dexterity || after armour has lowered it (see [[Manual:Game Mechanics/Abilities#Armour and dexterity|Abilities]]) | ||
| + | |- | ||
| + | | weapon skill || a player's skill in the weapon, or in its family if that is higher, or -25 with neither; a monster's skill in the family | ||
| + | |- | ||
| + | | weapon defence || a player's best of: half their skill in the attacker's weapon, or their skill in its family; a monster's half skill in the family | ||
| + | |- | ||
| + | | attacker's bonuses || | ||
| + | * the monster's <code>offensive</code> value (for a player 0, unless a god or a DIL changes it); | ||
| + | * the weapon's craftsmanship and magic (-20 to +20 each, see [[Manual:Game Mechanics/Objects|Objects]]); | ||
| + | * +25 if the defender can't see the attacker; | ||
| + | * against a race the weapon slays: +50, and 1 more for each level the defender is above 50; | ||
| + | * with two weapons: -(25 - two weapon style / 4) for the main weapon and -(50 - two weapon style / 4) for the second, never above 0; a monster uses its dexterity for the skill. | ||
| + | |- | ||
| + | | defender's bonuses || | ||
| + | * the monster's <code>defensive</code> value; | ||
| + | * the craftsmanship and magic of the armour where the blow lands; | ||
| + | * +25 if the attacker can't see the defender; | ||
| + | * +20 for protection from evil against an evil attacker, protection from good against a good one; | ||
| + | * -25 if the defender isn't fighting the attacker: fighting someone else, or not fighting yet. | ||
| + | |} | ||
| + | A defender who is asleep, stunned or worse doesn't defend: the bonus is 2 × attack ability + 2 × weapon skill + the attacker's bonuses, and the result is at least 100. | ||
| + | |||
| + | A monster above level 50 has its roll multiplied by (level - 30) / 25; see [[Manual:Game Mechanics/Monsters#Level|Monsters]]. | ||
| + | |||
| + | === Fumbles === | ||
| + | If the attacker wields a weapon and the roll (before the bonus) is at most the weapon's <code>fumble</code> value in <code>weapons.def</code>, the blow is a fumble: it misses and costs half a round. A long sword fumbles on 7 or less, a dagger on 2 or less. | ||
| + | |||
| + | === Damage === | ||
| + | A result below 0 is a miss. From 0 up it is a hit, and the result is looked up in the weapon's damage table, in the column of the armour where the blow landed. Each entry is {''offset'', ''base'', ''step''}: | ||
| + | |||
| + | damage = base + (result - offset) / step, or 0 if the result is below the offset | ||
| + | |||
| + | A hit for 0 damage glances off the armour. A long sword against chain is {50, 4, 9}: a result of 50 does 4 damage, 104 does 10, 158 does 16. The tables for each weapon are in <code>weapons.def</code>; see [[Manual:Game Mechanics/Objects#Weapons|Objects]] for some. | ||
| + | |||
| + | * A slaying weapon against its race adds a fifth to the result after the hit. | ||
| + | * A natural attack (a monster's claw, a player's fist) is weaker for a light attacker: the result is cut to 50% for a tiny one (up to 5 pounds), 60% small (to 40), 70% medium (to 160), 80% large (to 500), and stays whole for a huge one. | ||
| + | * There is no upper limit to the damage. | ||
| + | |||
| + | === Shields === | ||
| + | After a hit, a defender who is awake and has a shield tries to put it in the way. The chance depends on the size of the shield, its craftsmanship and magic, and the shield skill of both sides. Against most weapons a block stops the blow entirely and the shield takes the damage; against the morning star and the flail the shield only takes a part away; against the whip it is useless. The numbers are on [[Manual:Game Mechanics/Objects#Shields|Objects]]. | ||
| + | |||
| + | === An example === | ||
| + | A fighter with strength 40 and dexterity 30 (attack ability (40 + 40 + 30) / 3 = 36) and 40 in long sword attacks with a good long sword (craftsmanship +5 in the game). The defender wears a plain chain shirt, has dexterity 30 after the shirt has lowered it, and 20 in swords (a defence of 20). | ||
| + | |||
| + | bonus = 2 × (36 - 30) + 2 × (40 - 20) + 5 - 0 = 57 | ||
| + | |||
| + | A blow to the body, in the chain shirt, with a roll of 50: 57 + 50 = 107, which does 4 + (107 - 50) / 9 = 10 damage. A roll of 5 does 5, a roll of 95 does 15. A defender with 110 hit points lasts about 11 rounds. <code>wstat <attacker> combat <defender></code> shows such a breakdown for two real characters (see [[Wizhelp/Wstat|wstat]]). | ||
| + | |||
| + | == Wear on equipment == | ||
| + | Each blow wears the weapon that struck and the armour that was hit, and a block wears the shield. Craftsmanship decides how much an item can take; when it is used up the item breaks. See [[Manual:Game Mechanics/Objects#Wear and breaking|Objects]]. | ||
| + | |||
| + | == Hit points and positions == | ||
| + | Damage takes hit points away (<code>damage()</code> and <code>update_pos()</code> in <code>fight.cpp</code>): | ||
| + | {| class="wikitable" | ||
| + | ! Hit points !! Position | ||
| + | |- | ||
| + | | 1 and up || fighting, or whatever they were doing | ||
| + | |- | ||
| + | | 0 to -2 || stunned: gets up again as hit points come back | ||
| + | |- | ||
| + | | -3 to -5 || incapacitated: loses 1 hit point every 30 seconds | ||
| + | |- | ||
| + | | -6 to -10 || mortally wounded: loses 2 hit points every 30 seconds | ||
| + | |- | ||
| + | | -11 or less || dead | ||
| + | |} | ||
| + | A blow that does more than a fifth of the victim's maximum makes them scream. A sleeping victim who is hurt wakes up. | ||
| + | |||
| + | A player in wimpy mode ([[Help/Wimpy|help wimpy]]) flees by themselves when a blow takes more than a quarter of the hit points they have left, or when they are below a quarter of their maximum. A player who has lost their connection flees when hit. | ||
| + | |||
| + | == Fleeing == | ||
| + | <code>flee</code> costs 20 endurance and runs through a random exit. The flee skill, dexterity and brain against the opponent's dexterity and brain decide how it goes: a bad try gives the opponent a free blow, a very bad one can leave the character in a panic, still fighting. See [[Manual:Game Mechanics/Skills#Fleeing|Skills]] and [[Help/Fleeing|help fleeing]]. | ||
| + | |||
| + | == Death == | ||
| + | A character that dies leaves a corpse with everything they carried. The killer, and the group with them, get the monster's experience (see [[Manual:Game Mechanics/Levels#Experience from a kill|Levels]]); a player who dies loses some experience ([[Manual:Game Mechanics/Levels#Losing experience|Levels]], [[Help/Die|help death]]). Killing a player gives no experience, and killing someone protected by the law is a crime. | ||
| + | |||
| + | == Spells in a fight == | ||
| + | An attack spell is worked out much like a blow (<code>spell_bonus()</code> in <code>experience.cpp</code>, <code>spell_offensive()</code> in <code>magic.cpp</code>): | ||
| + | |||
| + | bonus = 2 × (caster's magic or divine - target's brain) | ||
| + | + 2 × (caster's skill in the spell - target's defence against it) | ||
| + | + caster's bonuses - target's bonuses | ||
| + | |||
| + | at least -50, plus an open-ended roll, looked up in the spell's damage table in <code>vme/etc/spells.def</code>. The spell uses magic or divine as the spell's <code>realm</code> says. The target's defence is the best of half their skill in that spell and their skill in its sphere (for a monster, half its sphere skill). The caster gets their <code>offensive</code> value, +50 with both hands free (no weapon and no shield), and -25 if they can't see the target; the target gets their <code>defensive</code> value, the craftsmanship and magic of the armour where the spell lands, and +25 for protection from good or evil. A target who is asleep doesn't defend: only the bonuses count against the caster's ability and skill. The target's shield can block or soften the spell as it does a blow, as <code>spells.def</code> says for each spell. <code>wstat <caster> splcombat <target> <spell></code> shows the breakdown. | ||
| + | |||
| + | == Consider == | ||
| + | <code>consider</code> (a skill; a player must have practised it) estimates how many rounds the other would need to kill you: it works out the damage of rolls of 5, 50 and 95 against your body, takes the average, and divides your maximum hit points by it. It doesn't count spells, breath, helpers, or how often blows miss. | ||
| + | {| class="wikitable" | ||
| + | ! Rounds !! Message | ||
| + | |- | ||
| + | | 1 || RUN AWAY! | ||
| + | |- | ||
| + | | 2 || You ARE mad! | ||
| + | |- | ||
| + | | 3 || Very risky indeed! | ||
| + | |- | ||
| + | | 4 || Quite a risk. | ||
| + | |- | ||
| + | | 5 || Perhaps you would have time to flee. | ||
| + | |- | ||
| + | | 6 to 7 || You got a fair chance of fleeing. | ||
| + | |- | ||
| + | | 8 to 10 || You got a very good chance of fleeing. | ||
| + | |- | ||
| + | | 11 or more || Plenty of time to flee. | ||
| + | |} | ||
| + | A monster 10 or more levels above the player is also "probably out of your league". A god sees the number of rounds both ways and the breakdown. See [[Help/Consider|help consider]]. | ||
Latest revision as of 06:27, 15 November 2026
This page explains how a fight is worked out: rounds and attacks, the roll for each blow, damage, shields, armour, and what happens when hit points run out. The code is in vme/src/combat.cpp (rounds), fight.cpp (blows and damage), experience.cpp (the hit roll, shields, consider) and skills.cpp (damage tables). The players' side is in help combat and help kill.
Contents
Starting and stopping
kill (or a skill such as kick, or an attack spell) starts a fight: both sides fight until one falls, dies or flees, or they are no longer in the same place. A character can fight several opponents, but hits one of them at a time; changing who they hit takes most of a round. Players can only fight each other when both have signed the Book of Blood (help bob), and a room with safe_room@function refuses attacks altogether (see Rooms).
When someone falls stunned or worse, the fight stops for both; whoever wants to finish them off must attack again.
Rounds
A combat round comes every 3 seconds (PULSE_VIOLENCE). In each round every fighter has 12 units of time (SPEED_DEFAULT), and everything they do in the fight spends some:
- a blow takes the weapon's speed from
vme/etc/weapons.def: 9 for two-handed weapons, 7 for one-handed ones, 4 for light weapons such as the dagger, and 4 for natural attacks (2, but 4 is the least a blow takes); - a skill or command typed during the fight takes its
turnsfromvme/etc/commands.def(kick takes 6, half a round), and a spell itsturnsfromspells.def(a full round unless the spell says otherwise). When the fighter has no time left this round, the command waits for the next; - a fumble costs another half round (6 units), and changing whom you hit 9 units.
Time spent beyond the 12 is taken from the next round.
How many blows a fighter gets depends on their speed: 12 is normal, lower is faster (4 to 200). At normal speed a fighter strikes once a round, or twice when fighting with two weapons, but only if both blows fit in the 12 units: with two one-handed weapons (7 + 7) only one does; with a light weapon in one hand (7 + 4) both do. Faster fighters get more blows, and each takes less time:
| Speed | 12 | 8 | 6 | 5 | 4 |
|---|---|---|---|---|---|
| Blows per round (one weapon) | 1 | 1 | 2 | 2 | 2 (players), 3 (monsters) |
That is 1 × 12 / speed, rounded down, at most 2 for players and 3 for monsters. Haste spells and SPEED_TRANSFER items make a character faster. A speed above 12 doesn't give fewer blows: a fighter whose blow still fits in the round strikes every round, and one whose blow no longer fits (above speed 35 with a natural attack, 20 with a one-handed weapon, 16 with a two-handed one) never strikes at all.
A blow
Each blow is worked out in one_hit() in fight.cpp.
Where it lands
A roll of 2d8 picks the place: body 34%, legs 28%, arms 23%, and head, hands and feet 5% each. The armour worn there is the armour that counts for this blow. With none, the defender's natural armour counts (clothes for a player), with no bonus.
The hit roll
First the attack bonus (melee_bonus() in experience.cpp):
bonus = 2 × (attack ability - defender's dexterity)
+ 2 × (attacker's weapon skill - defender's weapon defence)
+ attacker's bonuses - defender's bonuses
and at least -50. Then:
result = bonus + open-ended 1d100 (+ the bonus of a skill such as kick)
| Part | What it is |
|---|---|
| attack ability | the average of the three abilities the weapon uses (most weapons: strength, strength, dexterity) |
| defender's dexterity | after armour has lowered it (see Abilities) |
| weapon skill | a player's skill in the weapon, or in its family if that is higher, or -25 with neither; a monster's skill in the family |
| weapon defence | a player's best of: half their skill in the attacker's weapon, or their skill in its family; a monster's half skill in the family |
| attacker's bonuses |
|
| defender's bonuses |
|
A defender who is asleep, stunned or worse doesn't defend: the bonus is 2 × attack ability + 2 × weapon skill + the attacker's bonuses, and the result is at least 100.
A monster above level 50 has its roll multiplied by (level - 30) / 25; see Monsters.
Fumbles
If the attacker wields a weapon and the roll (before the bonus) is at most the weapon's fumble value in weapons.def, the blow is a fumble: it misses and costs half a round. A long sword fumbles on 7 or less, a dagger on 2 or less.
Damage
A result below 0 is a miss. From 0 up it is a hit, and the result is looked up in the weapon's damage table, in the column of the armour where the blow landed. Each entry is {offset, base, step}:
damage = base + (result - offset) / step, or 0 if the result is below the offset
A hit for 0 damage glances off the armour. A long sword against chain is {50, 4, 9}: a result of 50 does 4 damage, 104 does 10, 158 does 16. The tables for each weapon are in weapons.def; see Objects for some.
- A slaying weapon against its race adds a fifth to the result after the hit.
- A natural attack (a monster's claw, a player's fist) is weaker for a light attacker: the result is cut to 50% for a tiny one (up to 5 pounds), 60% small (to 40), 70% medium (to 160), 80% large (to 500), and stays whole for a huge one.
- There is no upper limit to the damage.
Shields
After a hit, a defender who is awake and has a shield tries to put it in the way. The chance depends on the size of the shield, its craftsmanship and magic, and the shield skill of both sides. Against most weapons a block stops the blow entirely and the shield takes the damage; against the morning star and the flail the shield only takes a part away; against the whip it is useless. The numbers are on Objects.
An example
A fighter with strength 40 and dexterity 30 (attack ability (40 + 40 + 30) / 3 = 36) and 40 in long sword attacks with a good long sword (craftsmanship +5 in the game). The defender wears a plain chain shirt, has dexterity 30 after the shirt has lowered it, and 20 in swords (a defence of 20).
bonus = 2 × (36 - 30) + 2 × (40 - 20) + 5 - 0 = 57
A blow to the body, in the chain shirt, with a roll of 50: 57 + 50 = 107, which does 4 + (107 - 50) / 9 = 10 damage. A roll of 5 does 5, a roll of 95 does 15. A defender with 110 hit points lasts about 11 rounds. wstat <attacker> combat <defender> shows such a breakdown for two real characters (see wstat).
Wear on equipment
Each blow wears the weapon that struck and the armour that was hit, and a block wears the shield. Craftsmanship decides how much an item can take; when it is used up the item breaks. See Objects.
Hit points and positions
Damage takes hit points away (damage() and update_pos() in fight.cpp):
| Hit points | Position |
|---|---|
| 1 and up | fighting, or whatever they were doing |
| 0 to -2 | stunned: gets up again as hit points come back |
| -3 to -5 | incapacitated: loses 1 hit point every 30 seconds |
| -6 to -10 | mortally wounded: loses 2 hit points every 30 seconds |
| -11 or less | dead |
A blow that does more than a fifth of the victim's maximum makes them scream. A sleeping victim who is hurt wakes up.
A player in wimpy mode (help wimpy) flees by themselves when a blow takes more than a quarter of the hit points they have left, or when they are below a quarter of their maximum. A player who has lost their connection flees when hit.
Fleeing
flee costs 20 endurance and runs through a random exit. The flee skill, dexterity and brain against the opponent's dexterity and brain decide how it goes: a bad try gives the opponent a free blow, a very bad one can leave the character in a panic, still fighting. See Skills and help fleeing.
Death
A character that dies leaves a corpse with everything they carried. The killer, and the group with them, get the monster's experience (see Levels); a player who dies loses some experience (Levels, help death). Killing a player gives no experience, and killing someone protected by the law is a crime.
Spells in a fight
An attack spell is worked out much like a blow (spell_bonus() in experience.cpp, spell_offensive() in magic.cpp):
bonus = 2 × (caster's magic or divine - target's brain)
+ 2 × (caster's skill in the spell - target's defence against it)
+ caster's bonuses - target's bonuses
at least -50, plus an open-ended roll, looked up in the spell's damage table in vme/etc/spells.def. The spell uses magic or divine as the spell's realm says. The target's defence is the best of half their skill in that spell and their skill in its sphere (for a monster, half its sphere skill). The caster gets their offensive value, +50 with both hands free (no weapon and no shield), and -25 if they can't see the target; the target gets their defensive value, the craftsmanship and magic of the armour where the spell lands, and +25 for protection from good or evil. A target who is asleep doesn't defend: only the bonuses count against the caster's ability and skill. The target's shield can block or soften the spell as it does a blow, as spells.def says for each spell. wstat <caster> splcombat <target> <spell> shows the breakdown.
Consider
consider (a skill; a player must have practised it) estimates how many rounds the other would need to kill you: it works out the damage of rolls of 5, 50 and 95 against your body, takes the average, and divides your maximum hit points by it. It doesn't count spells, breath, helpers, or how often blows miss.
| Rounds | Message |
|---|---|
| 1 | RUN AWAY! |
| 2 | You ARE mad! |
| 3 | Very risky indeed! |
| 4 | Quite a risk. |
| 5 | Perhaps you would have time to flee. |
| 6 to 7 | You got a fair chance of fleeing. |
| 8 to 10 | You got a very good chance of fleeing. |
| 11 or more | Plenty of time to flee. |
A monster 10 or more levels above the player is also "probably out of your league". A god sees the number of rounds both ways and the breakdown. See help consider.