Page 1 of 1

Trying to understand the NPC, NPDTstruct52 and NPDTstruct12 / Bug #3278

Posted: 06 May 2018, 20:59
by AHSauge
Hi

I'm having a look at Bug #3278, and I'm trying the understand the structure behind NPC. The NPC structure contains NPDTstruct12 and NPDTstruct52, which both contain values for for instance Level and Gold.

Some questions
  1. Is there a reason these values are duplicated?
  2. If yes: Should the Gold value in NPDTstruct12 always be the same as in NPDTstruct52?
Assuming the Gold value should be the same in both structures. I see two options:
  1. Unify the structure a bit
  2. Setting for instance a new gold value always set it in both structures
Does anyone have a bit of input for me here?

Re: Trying to understand the NPC, NPDTstruct52 and NPDTstruct12 / Bug #3278

Posted: 07 May 2018, 09:04
by Zini
Not much. Not too familiar with this stuff either. These two data structures are taken directly from the ESM/ESP format. We probably shouldn't mess with that. As you can see in the load code only one can ever be present, but NPDTstruct12 still has several fields flagged as Unknown.

Re: Trying to understand the NPC, NPDTstruct52 and NPDTstruct12 / Bug #3278

Posted: 07 May 2018, 10:53
by NullCascade
In case it's of any help: These values are not duplicated in the original engine. When the game loads an NPDT (NPC Data struct) it can load it in 12, 20, 52, or 172 byte variants. I'm not entirely sure when the 20 - or 172-byte variants are used, never saw those breakpoints get hit. The data in memory as far as the original engine goes is in one block, as seen here.

The 52-byte variant just starts reading from the file into memory starting at 0x7C (level in my link above).

The 12-byte variant is pickier and only ever sets disposition (clamped 0-100), barter gold, and faction rank/index.

The unknown bytes in your structs are padding/junk, and not actually respected by the original engine.

Re: Trying to understand the NPC, NPDTstruct52 and NPDTstruct12 / Bug #3278

Posted: 07 May 2018, 10:57
by Zini
Thanks. That is very useful input. I need to retract my previous statement. With this new information it seems consolidating the data structures into a single one actually seems like the right course of action.

Re: Trying to understand the NPC, NPDTstruct52 and NPDTstruct12 / Bug #3278

Posted: 07 May 2018, 12:21
by AHSauge
Thank you both. This is very valuable input. I will see about restructuring it a bit.

Re: Trying to understand the NPC, NPDTstruct52 and NPDTstruct12 / Bug #3278

Posted: 07 May 2018, 17:55
by Greendogo
Interesting discussion.

What are some examples of NPCs that use the 12-byte variant? And what could possibly be stored in the 172-byte variant?

Re: Trying to understand the NPC, NPDTstruct52 and NPDTstruct12 / Bug #3278

Posted: 07 May 2018, 18:19
by NullCascade
Greendogo wrote: 07 May 2018, 17:55Interesting discussion.

What are some examples of NPCs that use the 12-byte variant? And what could possibly be stored in the 172-byte variant?
Looking at the save logic provides a bit more:

If the autocalc bit isn't set or OR it's the player, the full 52-byte variant is used when saving.

Otherwise (autocalc bit is set) the 12-byte variant is used. The other two variants exist in the load logic, but not the save logic as far as I can see. Either way even the 172-byte variant doesn't actually load anything new, and sets the same values as the 12-byte variant. It's probably a hold over from a previous version of the format used during development, perhaps when it was merged with MACH or something.

Re: Trying to understand the NPC, NPDTstruct52 and NPDTstruct12 / Bug #3278

Posted: 07 May 2018, 22:52
by AHSauge
So I changed the code a bit. Loading NPDTstruct12 now is just done into a temporary variable and then converted to NPDTstruct52. There reverse is done when saving (creating a temporary NPDTstruct12 to save based on the NPDTstruct52 object). This fixed all the uninitialized variables.
However, when unchecking "Auto Calc" we really should perform one round of auto calc to generate all values. There is some code here that could be adapted for that. I am however failing to understand where one would put that. Here is an option, but I get the distinct feeling this is intended for load/save, and not much more.
There is also the issue of where to initiate the auto calc from. Here is the only place I've found so far, but again, I don't get the feeling this is the right place to do it. Nor have I gotten at good understanding of how the event system is built up. I saw dataChanged is emitted somewhere, so I suppose some class could listen for that, but where would be an ideal place?

Re: Trying to understand the NPC, NPDTstruct52 and NPDTstruct12 / Bug #3278

Posted: 08 May 2018, 11:52
by Zini
I guess you mean running the auto calc in OpenMW-CS? I am considering not doing that. Auto calc may get de-hardcoded at some point, which means we won't be able to do it in OpenMW-CS anymore. Maybe better to not get users used to a feature that we will have to drop in the not too far future (also it would be a waste of developer time).

Re: Trying to understand the NPC, NPDTstruct52 and NPDTstruct12 / Bug #3278

Posted: 08 May 2018, 23:07
by AHSauge
Yes, but I see what you mean. No point in doing this now at least.