Manual:Zone Manual/The NPC Section/NPC macros
Contents
NPC macros
Several NPC fields are hard to set by hand: the abilities and skills must add up
to 100, and the natural attack and armour belong together. The macros on this
page set them in one line. They, and the monster templates built from them, come
with #include <macros.h>, which every zone starts with; you don't
include anything else. The macros are in vme/include/wmacros.h and
bottom.h, the templates in the other headers listed
below. If you want to see what a macro turns into, run
vmc -p on your zone: it prints the zone after the preprocessor.
Macros overwrite fields set before them, so put a template or macro first and the fields you want to change after it.
Natural attack and armour: NATURAL_DEF
The natural attack is how the NPC hits when it has no weapon; the natural armour
is how well its body protects it when it wears no armour. A metal cat claws and
is as hard as plate; a dog bites and has a leather-like hide. From
wmacros.h:
#define NATURAL_DEF(weapon_category, armour_category) \ armour armour_category \ attack weapon_category
The natural attacks are in values.h. Humanoids have
WPN_FIST (the default), WPN_KICK,
WPN_KNEE, WPN_ELBOW and WPN_CLAW.
Creatures have bites, stings, claws, crushes and kicks in five sizes; a larger
size hits harder (the damage tables are in vme/etc/weapons.def):
WPN_BITE_TINY WPN_BITE_SMALL WPN_BITE_MEDIUM WPN_BITE_LARGE WPN_BITE_HUGE WPN_STING_TINY WPN_STING_SMALL WPN_STING_MEDIUM WPN_STING_LARGE WPN_STING_HUGE WPN_CLAW_TINY WPN_CLAW_SMALL WPN_CLAW_MEDIUM WPN_CLAW_LARGE WPN_CLAW_HUGE WPN_CRUSH_TINY WPN_CRUSH_SMALL WPN_CRUSH_MEDIUM WPN_KICK_TINY WPN_KICK_SMALL WPN_KICK_MEDIUM WPN_KICK_LARGE WPN_KICK_HUGE
WPN_BITE, WPN_STING and WPN_CRUSH are the
medium sizes; WPN_CLAW and WPN_KICK are the small ones
(and the humanoid claw and kick).
Use these natural attacks only. vmc accepts an attack type only if
its number is from WPN_FIST (34) to 124, and stops with "Illegal
hand attack type" otherwise. That rejects most weapon types (a long sword is 17)
and also WPN_CRUSH_LARGE and WPN_CRUSH_HUGE (125 and
126). The numbers are in
weapon definitions in values.h.
The NPC's weight also counts. A natural attack does less damage the lighter the attacker is; the hit is scaled before it is looked up in the damage table:
| Weight (pounds) | Size | Hit counts for |
|---|---|---|
| 0–5 | tiny | 50% |
| 6–40 | small | 60% |
| 41–160 | medium | 70% |
| 161–500 | large | 80% |
| over 500 | huge | 100% |
An NPC without weight weighs 120 pounds, so it is medium. A
dragon needs a dragon's weight to hit like one. The weight doesn't matter when
the NPC wields a weapon.
The armour types, from vme.h, are the same as for armour objects:
#define ARM_CLOTHES 0 /* Naked / clothes is only protection */ #define ARM_LEATHER 1 /* A soft flexible leather base armour */ #define ARM_HLEATHER 2 /* A hard unflexible leather base armour */ #define ARM_CHAIN 3 /* A flexible armour composed of interlocking rings */ #define ARM_PLATE 4 /* An unflexible plate armour. */
An NPC without armour has ARM_HLEATHER.
// a metal cat NATURAL_DEF(WPN_CLAW_MEDIUM, ARM_PLATE) // an ordinary dog NATURAL_DEF(WPN_BITE_SMALL, ARM_LEATHER)
Offensive and defensive bonus: ATTACK_DEFENSE
Sometimes an NPC should be stronger than its level and skills make it. The offensive bonus is added to its attack rolls, the defensive bonus to its defence rolls. Both default to 0 and may be -1000..1000; the higher the offensive bonus, the harder it hits, and the higher the defensive bonus, the harder it is to hit. The dragon templates use +100 for both.
#define ATTACK_DEFENSE(attack, defense) \ offensive attack \ defensive defense
// hits hard and is hard to hit ATTACK_DEFENSE(200, 200)
Abilities: MSET_ABILITY
You don't give an NPC's abilities as numbers. You give the share, in per cent,
that each ability gets of the points an NPC of its level has, and
vmc works out the numbers. The eight shares must add up to 100:
#define MSET_ABILITY(str,dex,con,hpp,bra,cha,mag,div) \
ability[ABIL_STR] str \
ability[ABIL_DEX] dex \
ability[ABIL_CON] con \
ability[ABIL_HP] hpp \
ability[ABIL_BRA] bra \
ability[ABIL_MAG] mag \
ability[ABIL_DIV] div \
ability[ABIL_CHA] cha
The arguments are strength, dexterity, constitution, hit points, brain, charisma, magic and divine power, in that order. What each ability does is described in Abilities. The HP ability gives the NPC its hit points: 10 + 3 for each point.
MSET_ABILITY(25,15,10,15,10,5,20,0) // 25+15+10+15+10+5+20+0 = 100
An NPC without MSET_ABILITY gets STR 40, DEX 30, CON 10, HP 15,
BRA 3, CHA 2.
The number of points grows with the level. vmc -v prints what each
NPC got. For seven NPCs with the line above, named after their levels, it
shows (the HIT column is the hit points):
STR DEX CON HIT BRA CHA MAG DIV lvl1 2 1 0 13 0 0 1 0 lvl10 17 12 9 46 9 4 15 0 lvl25 43 31 24 103 24 12 37 0 lvl50 85 61 48 193 48 24 73 0 lvl100 170 122 96 376 96 48 146 0 lvl150 255 183 144 559 144 72 219 0 lvl199 338 243 191 739 191 95 291 0
No ability or skill can be higher than 500. A share that would give more is cut
to 500, and vmc warns. For the NPCs above it printed
"lvl150 - A weapon skill exceeds 662 points." and the same for level 199: they
have the default 100% in one weapon group. At high levels, spread the shares
more evenly.
Weapon and spell skills: MSET_WEAPON and MSET_SPELL
NPCs know weapons and spells by group, not one by one as players do. An NPC with
skill 25 in the sword group fights, and defends, with every sword-like weapon at
skill 25. Spell groups work the same way: they are the NPC's skill when it
casts a spell of that group, and its resistance when such a spell is cast at
it. NPCs have no other skills. As with abilities, you give shares in per cent,
and vmc works out the points from the level.
The weapon shares and the spell shares together must add up to 100. An NPC without these macros has 100 in the unarmed group and nothing else.
#define MSET_WEAPON(axe_ham, sword, club_mace, pole, unarmed, special) \
weapon[WPN_AXE_HAM] axe_ham \
weapon[WPN_SWORD] sword \
weapon[WPN_CLUB_MACE] club_mace \
weapon[WPN_POLEARM] pole \
weapon[WPN_UNARMED] unarmed \
weapon[WPN_SPECIAL] special
| Argument | Group |
|---|---|
| axe_ham | axes and hammers |
| sword | swords, daggers, rapiers and the like |
| club_mace | clubs, maces, flails, morning stars |
| pole | quarterstaffs, spears, halberds, tridents, scythes and other pole weapons |
| unarmed | fists, kicks, bites, claws, stings, crushes: the natural attacks |
| special | whips, bows, crossbows and slings |
#define MSET_SPELL(div, pro, det, sum, cre, min, hea, col, cel, int, ext) \
spell[SPL_DIVINE] div \
spell[SPL_PROTECTION] pro \
spell[SPL_DETECTION] det \
spell[SPL_SUMMONING] sum \
spell[SPL_CREATION] cre \
spell[SPL_MIND] min \
spell[SPL_HEAT] hea \
spell[SPL_COLD] col \
spell[SPL_CELL] cel \
spell[SPL_INTERNAL] int \
spell[SPL_EXTERNAL] ext
| Argument | Group |
|---|---|
| div | divine |
| pro | protection |
| det | detection |
| sum | summoning |
| cre | creation |
| min | mind |
| hea | heat (fire) |
| col | cold (frost) |
| cel | cell (electricity) |
| int | internal (poison) |
| ext | external (acid) |
Which group a weapon or spell belongs to is its sphere in
vme/etc/weapons.def and vme/etc/spells.def; see also
Spell definitions in values.h.
A legal setting, 75% weapons and 25% spells:
// 75% in all, club and mace first MSET_WEAPON(10,10,25,5,20,5) // 25% in all, fire first MSET_SPELL(3,0,0,3,0,3,7,3,2,2,2)
Remember that the groups are defence as well as attack. An orc with 0% in the club and mace group has no weapon skill to defend itself against a flail, and an NPC with 0% in the fire group has no resistance to fire spells.
Height and weight by level: SETHEIGHT and SETWEIGHT
The templates make a higher-level creature bigger. From bottom.h:
#define SETHEIGHT(MLVL,minh,maxh) \ height (((((maxh-minh)+1)*((MLVL*100)/199))/100)+minh) #define SETWEIGHT(MLVL,minw,maxw) \ weight (((((maxw-minw)+1)*((MLVL*100)/199))/100)+minw)
At level 0 the NPC gets the minimum, at level 199 the maximum, and in between a share by level. Height is in centimetres, weight in pounds.
SETHEIGHT(40, 150, 200) // a level 40 humanoid of 150 to 200 cm: 160 cm
Monster templates
The template headers contain over two thousand ready-made NPCs. A template sets race, level, sex, size, natural attack and armour, abilities, weapon and spell skills, alignment and often experience and flags, and some add DIL programs (aggression, combat magic). You add the names and descriptions and whatever you want different.
bldragon
M_DRAGON_BLACK_MEDIUM(70, SEX_MALE)
title "a black dragon"
descr "A big ugly black dragon is clawing the ground here."
names {"big ugly black dragon", "ugly black dragon", "big black dragon",
"black dragon", "dragon"}
alignment -900
end
Because macros overwrite the fields before them, the template comes first:
alignment -900 after it replaces the template's -750. Flags are
the exception; a romflags or flags line adds to the
template's. An MSET_WEAPON or MSET_SPELL after a
template replaces only that group, so it must keep the template's split:
M_HUMAN_WARRIOR_SWORD puts 85% in weapons and 15% in spells, so a
new MSET_WEAPON after it must add up to 85.
| Header | Templates |
|---|---|
mhumanoid.h
|
People. M_AVG_<RACE>(level, sex);
|
chumanoid.h
|
The same people as children: C_AVG_<RACE>, C_<RACE>_WARRIOR_... and so on.
|
monster.h
|
Animals: M_BEAR_<SIZE>(level, sex), M_RAT_<SIZE>, ...
|
fantasy.h
|
Fantasy creatures: dragons, demons, undead, ... |
plant.h
|
Plants. |
aquatic.h
|
Sea creatures. |
For creatures the size in the name goes with a range of levels (from the comment
in macros.h): TINY 1–25, SMALL 26–50,
MEDIUM 51–75, LARGE 76–100, XLARGE
101–125, GODLY 125–199. A _MAD template is aggressive
and often poisonous.
The arguments differ from template to template, so grep the header for the
exact name before you use one; the comment at the top of macros.h
explains the argument names. A few dozen templates that no zone uses don't
compile: the abilities of M_KOBOLD_THIEF_* and
M_IVY_* don't add up to 100, and M_SPRITE_MEDIUM has a
syntax error, for example.
If you make a general monster that others could use, write it as a template in the right header, built from the macros on this page, and offer it to the project.
For an NPC built from these macros step by step, see Building your first NPC.