Weapon and Armour Weight and Price

Discuss Daggerfall Unity and Daggerfall Tools for Unity.
Erisceres
Posts: 7
Joined: Thu Apr 21, 2022 12:49 pm

Weapon and Armour Weight and Price

Post by Erisceres »

I've been trying to get some proper understanding on the price of Daggerfall loot and hence its GP/kg for the sake of carrying worthwhile loot.

The relevant UESP page of Daggerfall items provides good concepts on how to make such judgements, but the maths and numbers are off and do not seem to reflect the true weight or price of Daggerfall items, making the provided tables and formulae unreliable.

I decided to have a look at the source files to get a better understanding of how the weight and prices are calculated. ItemTemplates.txt reveals the base weight and base price for every Daggerfall item. These values, particularly in relation to weapons and armour, are further modified in respect to the material of the weapon or armour.

ItemBuilder.cs provides the rest of the information on how the material calculations are made:

Code: Select all

// Weight multipliers by material type. Iron through Daedric. Weight is baseWeight * value / 4.
static readonly short[] weightMultipliersByMaterial = { 4, 5, 4, 4, 3, 4, 4, 2, 4, 5 };

// Value multipliers by material type. Iron through Daedric. Value is baseValue * ( 3 * value).
static readonly short[] valueMultipliersByMaterial = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 };
As we can see, provided are arrays of multipliers for the weight and price depending on the material (not including leather or chain; more on this later). Also, described in each comment, are provided the general formula for making the relevant calculations (though, the provided formula for calculating weight is somewhat simplified).

Code: Select all

/// <summary>
/// Sets properties for a weapon or piece of armor based on its material.
/// </summary>
/// <param name="item">Item to have its properties modified.</param>
/// <param name="material">Material to use to apply properties.</param>
/// <returns>DaggerfallUnityItem</returns>
public static DaggerfallUnityItem SetItemPropertiesByMaterial(DaggerfallUnityItem item, WeaponMaterialTypes material)
{
    item.value *= 3 * valueMultipliersByMaterial[(int)material];
    item.weightInKg = CalculateWeightForMaterial(item, material);
    item.maxCondition = item.maxCondition * conditionMultipliersByMaterial[(int)material] / 4;
    item.currentCondition = item.maxCondition;

    return item;
}

static float CalculateWeightForMaterial(DaggerfallUnityItem item, WeaponMaterialTypes material)
{
    int quarterKgs = (int)(item.weightInKg * 4);
    float matQuarterKgs = (float)(quarterKgs * weightMultipliersByMaterial[(int)material]) / 4;
    return Mathf.Round(matQuarterKgs) / 4;
}
We can see here that while the price formula effectively matches what is in the code, the weight formula is a little more complex:

(All calculations seem to be rounded to the nearest two decimal places.)
  1. Take the item base weight
  2. Multiply it by 4 (value is type int)
  3. Multiply this by the material weight multiplier
  4. Divide this by 4 (value is type float)
  5. Round to the nearest whole number (nearest even number if ending in .5, as per the functionality of Mathf.Round())
  6. Divide this by 4
Unless there is a good reason for it, the initial multiplication and division by 4 seems unnecessary.

Code: Select all

/// <summary>Set material and adjust armor stats accordingly</summary>
public static void ApplyArmorMaterial(DaggerfallUnityItem armor, ArmorMaterialTypes material)
{
    armor.nativeMaterialValue = (int)material;

    if (armor.nativeMaterialValue == (int)ArmorMaterialTypes.Leather)
    {
        armor.weightInKg /= 2;
    }
    else if (armor.nativeMaterialValue == (int)ArmorMaterialTypes.Chain)
    {
        armor.value *= 2;
    }
    else if (armor.nativeMaterialValue >= (int)ArmorMaterialTypes.Iron)
    {
        int plateMaterial = armor.nativeMaterialValue - 0x0200;
        armor = SetItemPropertiesByMaterial(armor, (WeaponMaterialTypes)plateMaterial);
    }

    armor.dyeColor = DaggerfallUnity.Instance.ItemHelper.GetArmorDyeColor(material);
}
For the weight of leather armour, the formula seems to be the base weight divided by 2 for the total weight, while chain just takes the base weight. The price of chain armour seems to be the base price multiplied by 2, while leather armour just takes the base price.

Overall, the weight calculations largely seem to match up with the weight values on loot in the game (mind that I haven't progressed beyond Privateer's Hold, the initial dungeon). However, some items don't match with the expected weight:
  • The iron wakazashi weighs 2.25 kg but the expected weight is 2 kg.
  • The iron shortsword weighs 2 kg but the expected weight is 2.5 kg.
  • The steel shortsword weighs 2.5 kg but the expected weight is 3 kg.
  • The silver wakazashi weighs 2.25 kg but the expected weight is 2 kg.
I haven't tested every possible item of armour or weapons to check every value, just the items I've collected as loot so far.

I'm wondering if my own calculations or formula is off or perhaps there are more elements in the code that I have missed causing the actual values to be different?

User avatar
pango
Posts: 3359
Joined: Wed Jul 18, 2018 6:14 pm
Location: France
Contact:

Re: Weapon and Armour Weight and Price

Post by pango »

Erisceres wrote: Thu Apr 21, 2022 2:11 pm Unless there is a good reason for it, the initial multiplication and division by 4 seems unnecessary.
I assume this comes from classic doing integer computations whenever possible for the sake of performance, so all weights are multiples of 0.25Kg (= expressed as n * 0.25Kg, or n/4 Kg)
Mastodon: @pango@fosstodon.org
When a measure becomes a target, it ceases to be a good measure.
-- Charles Goodhart

Erisceres
Posts: 7
Joined: Thu Apr 21, 2022 12:49 pm

Re: Weapon and Armour Weight and Price

Post by Erisceres »

pango wrote: Thu Apr 21, 2022 9:20 pmso all weights are multiples of 0.25Kg (= expressed as n * 0.25Kg, or n/4 Kg)
Interestingly, the leather gauntlets weigh 0.63 kg (both expected and confirmed) due to how the weight for leather is calculated. It seems to be the only item of all armours and weapons to not be a multiple of 0.25 kg.

Erisceres
Posts: 7
Joined: Thu Apr 21, 2022 12:49 pm

Re: Weapon and Armour Weight and Price

Post by Erisceres »

pango wrote: Thu Apr 21, 2022 9:20 pm I assume this comes from classic doing integer computations whenever possible for the sake of performance, so all weights are multiples of 0.25Kg
The final division by 4 makes sense in terms of making items weight as a multiple of 0.25 kg. The initial multiplication and division of 4 seems like they would only unnecessarily add to the processing and not be of benefit to performance.

EDIT: I can kind of see the logic by forcing an integer in case of values with decimal places, however, all of the base weights for weapons and armour are already multiples of 0.25 kg, so forcing an integer for the sake of rounding to a whole number is unnecessary in this case.
Last edited by Erisceres on Thu Apr 21, 2022 10:04 pm, edited 1 time in total.

Erisceres
Posts: 7
Joined: Thu Apr 21, 2022 12:49 pm

Re: Weapon and Armour Weight and Price

Post by Erisceres »

After some further testing, using the console to add a number of wakizashis and shortswords to my inventory of different materials, it seems that the base weight of the wakizashi and shortsword are 2.25 kg and 2 kg, respectively, regardless of the values in ItemTemplates.txt being 2 kg and 2.5 kg, respectively.

This is strange as one would expect the variables to be configured accordingly per that text file, but that is apparently not the case.

Erisceres
Posts: 7
Joined: Thu Apr 21, 2022 12:49 pm

Re: Weapon and Armour Weight and Price

Post by Erisceres »

Using the console to add items to my inventory, I have now confirmed the weight of every piece of armour and weapon, from materials leather to daedric.

With this information, I can confirm that the formula for calculating weight appears to be correct. What its apparently incorrect are some of the base weight values in ItemTemplates.txt. In that text file, the following base weights are given:
  • Shortsword 2.50 kg
  • Mace 4.50 kg
  • Warhammer 7.00 kg
  • Wakizashi 2.00 kg
  • Katana 2.50 kg
  • Dai-Katana 3.50 kg
In actuality, the real base weights appear to be:
  • Shortsword 2.00 kg
  • Mace 6.00 kg
  • Warhammer 8.50 kg
  • Wakizashi 2.25 kg
  • Katana 3.50 kg
  • Dai-Katana 5.50 kg
I'm unsure what the cause is behind this discrepancy as one would expect the values in the text file to be utilised in the game code accordingly. Further, this would suggest that this particular text file is not exactly a reliable source of information on the game's assets, including potential discrepancies in the base prices of each item and other parameters.

Erisceres
Posts: 7
Joined: Thu Apr 21, 2022 12:49 pm

Re: Weapon and Armour Weight and Price

Post by Erisceres »

It seems that back in [0.10.21] that iron warhammers had the expected weight of 7.00 kg:
viewtopic.php?t=3503

This seems to have changed since as now the weight of an iron warhammer is 8.50 kg.

User avatar
Hazelnut
Posts: 3016
Joined: Sat Aug 26, 2017 2:46 pm
Contact:

Re: Weapon and Armour Weight and Price

Post by Hazelnut »

Do you have my mod Roleplay & Realism: Items installed by any chance? Because the weights you're quoting seem to match the re-balanced weights my mod introduces. This is the entire reason that the mod is split from the original Roleplay & Realism mod package because there's no way to affect the overriding of item templates via mod settings - you either have the mod enabled and adjusted weights or not. The adjusted weights feed into the larger weapon balancing of speed and damage that the mod introduces.

Regarding the multiply by 4 stuff, yes this is a bit redundant in DFU but we've kept many fundamental formula just reverse engineered from classic which was written for speed on PCs back in the 90s where floating point was expensive and integer multiplication / division by powers of 2 could be sped up by bit shifting.

Hope this helps.
See my mod code for examples of how to change various aspects of DFU: https://github.com/ajrb/dfunity-mods

Erisceres
Posts: 7
Joined: Thu Apr 21, 2022 12:49 pm

Re: Weapon and Armour Weight and Price

Post by Erisceres »

Hazelnut wrote: Fri Apr 22, 2022 6:36 pm Do you have my mod Roleplay & Realism: Items installed by any chance? Because the weights you're quoting seem to match the re-balanced weights my mod introduces.
Ah, that makes sense then. Yes, I have that mod active. Thank you for clearing that up.

For clarification, did you change any of the base price or hitpoint values of any weapons or armour? I'm curious to know as I'm preparing tables of items and their values so that I can be informed about what loot to keep on my adventures.

User avatar
Ralzar
Posts: 2211
Joined: Mon Oct 07, 2019 4:11 pm
Location: Norway

Re: Weapon and Armour Weight and Price

Post by Ralzar »

You can see the tables for the changes here:

https://www.nexusmods.com/daggerfallunity/mods/61

Post Reply