Book prices

Discuss coding questions, pull requests, and implementation details.
Post Reply
numidium3rd
Posts: 12
Joined: Sun Mar 25, 2018 12:34 am

Book prices

Post by numidium3rd » Wed Dec 05, 2018 3:16 am

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.

R.D.
Posts: 319
Joined: Fri Oct 07, 2016 10:41 am

Re: Book prices

Post by R.D. » 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.

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

Re: Book prices

Post by Hazelnut » Fri Dec 07, 2018 3:24 pm

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!

numidium3rd
Posts: 12
Joined: Sun Mar 25, 2018 12:34 am

Re: Book prices

Post by numidium3rd » Fri Dec 07, 2018 10:36 pm

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.

User avatar
Interkarma
Posts: 3582
Joined: Sun Mar 22, 2015 1:51 am

Re: Book prices

Post by Interkarma » Sat Dec 08, 2018 1:19 am

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:

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

Re: Book prices

Post by Hazelnut » Sat Dec 08, 2018 5:46 pm

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?

Post Reply