Sunday 19 September 2010

Designing a Magic System Redux - Part Three (Magic Items)

You are encouraged to read parts one and two of this article series, and are strongly encouraged to read the original Designing a Magic System series of articles if you have not already done so. This article also incorporates most of the text from another blog post which you may want to refer to the comments of.

I've been working on adding items with multiple 'pvals' to Unangband, and this is probably the most wide ranging set of changes I've made to the code since I began developing.

In Angband-speak, a pval is the value associated with a particular magic item flag: the +3 in a ring of Strength +3. Angband and many variants only allow you to have one numeric value per item, which was also historically overloaded with additional meanings such as the number of charges a wand would have. I've separated out that meaning (there is now a separate charge value) - and I'm now in the process of allowing items with multiple different numeric values e.g. a ring of Strength (+3) and Size (+7).

I'm not the first variant to have done this: so I'm taking an approach similar to Sangband, where the pvals are represented by a small numeric array of values, and then the flags to which pvals can apply become a bit array. So you end up with a situation where you might have pval[1] which is +3, and pval_flag[1] which is Strength, which in combination mean Strength +3.

The alternative is to have an integer array equal to the size of the possible different flags: the example here would be pval[STRENGTH_INDEX]=3. This obviously uses up a lot more memory and storage for each item, but with modern computers, the performance impact would be negligible. I've chosen the Sangband approach as much as a design constraint as a technical constraint - I have a hunch that people will have problems comparing two items which have more than 7-10 different discrete numeric values.

I have made a decision which increases the amount of code I've had to alter but should make it simpler long term, by also making item abilities such as to-hit bonus and to-damage bonus, weight and armour class, included in the pval framework I'm developing. To make this clearer, I've retitled them avals, short for ability values. An item now has abilities, associated with avals and which vary over an integer range, and flags, which are either on or off.

One possible abuse of the ability to use Angband items in multiple ways is the ability to throw ammunition instead of shooting it from a bow or crossbow. Ammunition is light, which means you can carry a lot of it, and throwing it is 'abusive' because the damage bonus that is applied to firing ammunition is also applied to thrown ammunition, without penalty. This is exacerbated in Unangband because the damage bonus was until the latest version counted twice for thrown weapons and not multiplied by missile launchers, which meant that throwing an arrow (+9,+9) may be more effective than firing it from a longbow.

The damage bonus in this example is insensitive to it's context - it is applied equally when the item is thrown, set in a trap, or fired from a missile weapon. And if you think the ammunition example could in some way be construed as sensible, consider that the damage bonus a bow applies to arrows fired from it, would also be applied if you threw the bow instead.

At the moment, I'm changing this: damage bonuses will be able to be context sensitive - a weapon that adds damage while fighting, won't necessarily benefit shooting, but may, for example, benefit being used in a trap.

I have the flexibility to allow missile weapons with incredibly good trap damage but no shooting damage bonus, but it is unlikely that a player would ever choose such a weapon over a missile weapon with superior shooting damage and no benefit in traps. Whereas if the weapon was multi-functional, it is more possible the player will attempt to take advantage of 'free' additional functionality at some point. I can do either approach with the approximately same level of cleanliness in the code: it is a data design issue, rather than code overhead cost.

There is a separate but related question about worn vs. wielded items. If a sword improves your ability to fight with it, does it also improve your ability to fight with another weapon if you hold it in your off-hand or even just strap it to your body? In particular, if you get one more blow per round with it, do you get that blow if it would be from another weapon?

On consideration, there are two related ways of thinking about magic items: firstly, how the abilities (avals) accumulate if the character is using multiple items which have this ability, and secondly whether the player inherits the power (ability, flag) of the magic item at all.

The simplest example is weight: if a character picks up two objects, both of which have weight, how is the character's overall encumbrance affected? This example is seemingly straight forward: the weight of the two objects is added together to give the total encumbrance.

But what if we measured encumbrance as the sum of weight, plus volume, plus length, which may be a more realistic way to model how difficult it is an item to carry? It may be possible to stack the two items side by side, so that the length of the total isn't the sum of the longest axis of each of them. So even this simple example can be complicated through extrapolation.

Then there is the problem of accumulating numeric values. +3 to hit, and +6 to hit is seemingly straight forward (+9 to hit), but how does one item which gives 50% resistance to fire, add to another item which gives 33% resistance to fire? Should it be additive, so that the player gets 83% resistance to fire? Or multiplicative, so that the player gets 66% resistance (1- (1-.5) * (1-.33))? I am a big fan of geometrical progression for resistances - because they provide a big impact initially which tapers off, but is still useful when added together. In the most straight forward geometrical progression scheme, level 1 resistance gives 50% resistance (1/2), level 2 gives 66% resistance (2/3), level 3 gives 75% resistance (3/4) and so on.

This also depends how you model fire damage to start with. What does 50 hp fire damage actually mean? Is 100 hp fire damage twice as hot? In which case, if you are modeling resistance to fire damage as ability to tolerate a temperature range, someone with 50 resistance may be able to ignore 50 hp completely, but take 50 hp damage from a 100 hp attack.

Specific versus damage bonuses are another tricky component to balance. In Angband, weapons have the ability to slay particular types of monsters for double, triple or higher damage, or branded with an element which does additional damage from fire, cold and so on. The Angband approach is to use the highest multiplier, rather than add the multipliers together. This is simplifies the creature design process as the designer is free to create a creature which is a hybrid of e.g. dragon and undead, without having to worry about this creature taking more damage from the weapon which is effective against both dragons and undead than against creatures which are just either dragon or undead.

The same applies to brands, even though we could model a weapon with multiple brands as doing both extra extra fire damage (which creatures immune to fire ignore) and extra cold damage (which creatures immune to cold ignore). If we treat this weapon as doing extra damage from each element, instead of picking the highest multiplier, creatures which are neither immune to cold or fire would take both sets of damage, which would make weapons with multiple brands much more effective than weapons with multiple slays.

But should this 'highest multiplier' approach be used across multiple items where e.g. a character could have a weapon with a fire brand, and also a ring which imparts a fire brand to the weapon. If yes, then there is no benefit to specialising in fire-based equipment, while there are plenty of draw backs. If no, and the multipliers add together, you have to balance for the maximum per item multiplier is multiplied by the number of possible items that the player can gain benefit from at the same time. Be sure to come up with a good reason for being unable to wear a ring on each finger and toe, and pierced through any available flap of skin.

With the inheritance question, it is clear some abilities are straight forward: they should be applied to the player if the item is equipped (fire resistance), or only apply to the object in question (proof against destruction by fire). It is specifically the 'use the item in question to perform a task' abilities which are not so clear. Take the ability to increase the amount of damage the player does.

As I highlighted earlier, it makes no sense to have the bow's damage bonus apply to the weapon when throwing it. So to address this, damage gets separated into 'damage while shooting', 'damage while setting traps' and so on. These are simple enough to apply to the player: or are they?

The dual wield problem, when a character is using a sword in his primary hand, and a dagger in his secondary, show that this is not necessarily straight forward. Does the dagger's 'damage while fighting' apply to attacks with the sword? In all likelihood, not (If you disagree, replace damage with fire brand. Does the dagger's fire brand also brand blows from the sword?). So we have to consider 'damage while fighting' as a specific property of the item, which we add at the time the item is used, as opposed to inherited by the player.

But this means that the same item ability is used in two different ways: an amulet of 'damage while fighting' is inherited by the player, but a dagger of 'damage while fighting' is only applied when we use the dagger. In which case, it may be simpler for some items to have a straight 'damage bonus', which is used whenever the item is being used, but not inherited by the player at all, whereas other items have a specific 'damage while shooting' bonus, which applies only when the item is being fired.

(I'm going to complicate this by also having rings apply some abilities only to items wielded in the hand they are worn on. This will be the left-hand for shooting and secondary weapons, and the right-hand for primary weapons.)

In the part five, I'll look at how Unangband evaluates the relative power of magic items, taking into account the inheritance or non-inheritance of various flags while keeping the above issues in mind.

But first, in part four, I'll take another look at skill acquisition.


kaypy said...

So no more continual_light + high_pvalue_item abuse? But I liked my Rings Of Speed And Absurd Visual Range... 8-)

The left-hand for shooting weapons doesn't make so much sense for me. Is that just needed-for-game-balance-dont-ask-too-many-questions?

To ask more questions regardless of whether I ought to: Should 2-handed weapons take advantage of both rings? I seem to recall larger weapons are still underutilized, so this might be good balance as well as make sense...

Andrew Doull said...

If you're firing a bow, you hold the bow part in your off hand...

And yes on the two weapon front.

VRBones said...

I haven't played too much with traps, but wouldn't they simply require a wieldable weapon (trap implements a swinging motion within 1 square) or a shootable ammo (projectile based trap design aimed in a direction)? I had always pictured the trap components to give an automated use of the item, not having the item purpose-built for a trap. Maybe the trap-setting ability/components needs to have a designation of the type of ammo needed (or multiple types) with the multiplier imbued.

Maybe ammo could get away with only one damage/aiming multiplier for the intended firing mechanism (thrown / bow / crossbow) and ignore it for other types, but if you're building a double array anyway it's probably not worth worrying about as it MAY be useful to have an ammo that can be used in multiple firing types, however unlikely.

Just had a thought: Enchanting items will be a tad more tricky too. I'd hate to enchant arrows to find out they've increased their crossbow effectiveness instead. Actually I guess it'll just be another layer of selection as to where the pval goes...

Unknown said...

Archery effecting rings really should be worn on the dominant hand.

Two draw types use something that would reasonably use the ring slot.

The Mediterranean draw uses

The Mongolian draw uses

The remaining pinch draw cannot be used to draw a stiff bow fully without exceptional hand strength.

If gauntlets are ever split into separate left and right items archery gauntlets are also worn on the dominant hand.

The dominant hand is also the hand in contact with the arrow. A ring of acid making your bow acidic will accomplish far less than one making the arrow acidic.

Sid Menon said...


Doesn't the bow elementalize the arrow? I thought the advantage of a Ring of Acid Arrow/Bolt/etc. would treat the bow itself as a conduit for the ring's magic.

I suppose this is a fiction-level discussion for a gameplay consideration in a game with minimal narrative emphasis.