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

Involved development of the OpenMW construction set.
Post Reply
AHSauge
Posts: 7
Joined: 03 Aug 2017, 17:29
Location: Norway
Github profile: https://github.com/AHSauge

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

Post by AHSauge » 06 May 2018, 20:59

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?

User avatar
Zini
Posts: 5217
Joined: 06 Aug 2011, 15:16

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

Post by Zini » 07 May 2018, 09:04

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.

NullCascade
Posts: 42
Joined: 16 Jan 2012, 07:58
Github profile: https://github.com/NullCascade/

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

Post by NullCascade » 07 May 2018, 10:53

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.
MWSE 2.x lead.

User avatar
Zini
Posts: 5217
Joined: 06 Aug 2011, 15:16

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

Post by Zini » 07 May 2018, 10:57

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.

AHSauge
Posts: 7
Joined: 03 Aug 2017, 17:29
Location: Norway
Github profile: https://github.com/AHSauge

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

Post by AHSauge » 07 May 2018, 12:21

Thank you both. This is very valuable input. I will see about restructuring it a bit.

User avatar
Greendogo
Posts: 1347
Joined: 26 Aug 2011, 02:04

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

Post by Greendogo » 07 May 2018, 17:55

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?

NullCascade
Posts: 42
Joined: 16 Jan 2012, 07:58
Github profile: https://github.com/NullCascade/

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

Post by NullCascade » 07 May 2018, 18:19

Greendogo wrote:
07 May 2018, 17:55
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?
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.
MWSE 2.x lead.

AHSauge
Posts: 7
Joined: 03 Aug 2017, 17:29
Location: Norway
Github profile: https://github.com/AHSauge

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

Post by AHSauge » 07 May 2018, 22:52

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?

User avatar
Zini
Posts: 5217
Joined: 06 Aug 2011, 15:16

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

Post by Zini » 08 May 2018, 11:52

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).

AHSauge
Posts: 7
Joined: 03 Aug 2017, 17:29
Location: Norway
Github profile: https://github.com/AHSauge

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

Post by AHSauge » 08 May 2018, 23:07

Yes, but I see what you mean. No point in doing this now at least.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest