Page 1 of 1

Book prices

Posted: Wed Dec 05, 2018 3:16 am
by numidium3rd
I've been trying to figure out how Daggerfall sets the prices for books. Here's what I've found so far:
[*]Each book's maximum price is defined at offset 0xE0 in its file (2 bytes).
[*]In-game book prices seem to be defined by a RNG of some sort. I've tried starting multiple new games and the prices remain consistent. Therefore, we can assume the seed is the same every time.

Has anyone else looked into this before? If so, please share your insights.

Re: Book prices

Posted: Fri Dec 07, 2018 11:48 am
by R.D.
I've got the book worth values figured out.

Book worth is gotten like:

Code: Select all

DFRandom.Seed = (first 4 bytes of book file as a uint);
int worth = DFRandom.random_range_inclusive(300, 800);
Each book file has its title at the beginning, so it's the first 4 characters of the title that determine the worth.

Example: For "Notes for Redguard History", the first 4 characters are "Note", or 4E 6F 74 65, which is 1702129486 in decimal. Feed that in to the above as the random seed and you'll get the result, 597 gold.

Re: Book prices

Posted: Fri Dec 07, 2018 3:24 pm
by Hazelnut
I actually thought we'd already handled this with the mercantile code formulas, but that's based on the fixed cost for all books in item templates.

Now I realise that the base price varies I will get that implemented ASAP. As ever, thanks for the classic algorithm info Allofich!

Re: Book prices

Posted: Fri Dec 07, 2018 10:36 pm
by numidium3rd
Thanks, Allofich! Interesting that the "price" value isn't factored into the books' prices at all. I got that tidbit from UESP. Either the field is for something else (I can't imagine what) or Bethesda decided not to use it. Either way, much appreciated.

Re: Book prices

Posted: Sat Dec 08, 2018 1:19 am
by Interkarma
R.D. wrote: Fri Dec 07, 2018 11:48 am I've got the book worth values figured out.

Book worth is gotten like:

Code: Select all

DFRandom.Seed = (first 4 bytes of book file as a uint);
int worth = DFRandom.random_range_inclusive(300, 800);
Each book file has its title at the beginning, so it's the first 4 characters of the title that determine the worth.

Example: For "Notes for Redguard History", the first 4 characters are "Note", or 4E 6F 74 65, which is 1702129486 in decimal. Feed that in to the above as the random seed and you'll get the result, 597 gold.
You are a genius mate. Hats off to you. Wow! :shock:

Re: Book prices

Posted: Sat Dec 08, 2018 5:46 pm
by Hazelnut
Allofich, can you confirm that the Price field identified on https://en.uesp.net/wiki/Daggerfall:Book_format has no bearing on the value?

I've modified BookFile to use the method you posted instead of the bytes 0xe0-e3 which that page says is an unsigned long (UInt32) of Price, but I would like to check this is correct.

EDIT: I tested another couple and the values match classic. Kind of wierd because every book title starting with "The " has the same value.

So, UESP is wrong or this data just wasn't used in the final game. UESP is correct that the field mostly has value 1000, but also values of 10, 300, 400, 5000, and 10000 are allocated to some books. My first thought was it might have been intended as a multiplier, but that's unlikely with the high value of 10k I think. We'll probably never know what it was for. :)


I was also wondering if the rarity field from that page should affect the random generation of books? Sounds like it should, but maybe it's another unused data element?