Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: RELATIONSHIP_ID's in DFHACK.  (Read 2449 times)

UselessMcMiner

  • Bay Watcher
  • praise jeebus
    • View Profile
RELATIONSHIP_ID's in DFHACK.
« on: December 04, 2018, 06:15:02 pm »

I was wondering if there was a list of relationship_id's that gui/family-affairs is using? I'm making a variation of the script to help make dwarves into friends but relationship_id.Friend doesn't work and causes an IndexError? Is there a string dump of the values?
Logged
Quote
The scouts have been fighting a giant capuchin for the past month now. They still haven't killed it.

Obsidian 1053

The Sentries are still fighting the capuchin. For two monthes they have done nothing but punch this monkey.

UselessMcMiner

  • Bay Watcher
  • praise jeebus
    • View Profile
Re: RELATIONSHIP_ID's in DFHACK.
« Reply #2 on: December 04, 2018, 08:33:20 pm »

Hey I found the proper ID but this line of code

Code: [Select]
local single = source.relationship_ids.Friend == -1
Causes this error
Code: [Select]
Cannot read field int32_t[].Friend: index out of bounds
Sorry i'm very new to this so sorry if its obvious.
Logged
Quote
The scouts have been fighting a giant capuchin for the past month now. They still haven't killed it.

Obsidian 1053

The Sentries are still fighting the capuchin. For two monthes they have done nothing but punch this monkey.

UselessMcMiner

  • Bay Watcher
  • praise jeebus
    • View Profile
Re: RELATIONSHIP_ID's in DFHACK.
« Reply #3 on: December 04, 2018, 09:06:26 pm »

I guess let me be more specific. It seems like lines 4 and 5 in this function create an IndexError. How do I handle relationships like friendships without creating an IndexError? I guess becauseunlike with spouses you can become friends with multiple people. So it breaks down pretty quickly.

Code: [Select]
function Marriage (source,target)
    local source_hf = df.historical_figure.find(source.hist_figure_id)
    local target_hf = df.historical_figure.find(target.hist_figure_id)
    source.relationship_ids.Friend = target.id
    target.relationship_ids.Friend = source.id

    local new_link = df.histfig_hf_link_spousest:new() -- adding hf link to source
    new_link.target_hf = target_hf.id
    new_link.link_strength = 100
    source_hf.histfig_links:insert('#',new_link)

    new_link = df.histfig_hf_link_spousest:new() -- adding hf link to target
    new_link.target_hf = source_hf.id
    new_link.link_strength = 100
    target_hf.histfig_links:insert('#',new_link)
end
Logged
Quote
The scouts have been fighting a giant capuchin for the past month now. They still haven't killed it.

Obsidian 1053

The Sentries are still fighting the capuchin. For two monthes they have done nothing but punch this monkey.

mifki

  • Bay Watcher
  • works secretly...
    • View Profile
    • mifki
Re: RELATIONSHIP_ID's in DFHACK.
« Reply #4 on: December 04, 2018, 11:04:11 pm »

Ah, right, unit.relationship_ids only stores some of the relationships, the first 10. I can't say right now where the remaining ones are stored.

PatrikLundell

  • Bay Watcher
    • View Profile
Re: RELATIONSHIP_ID's in DFHACK.
« Reply #5 on: December 05, 2018, 03:09:06 am »

Relations are stored in the hist fig in a rather messy logic.

This is a snippet of a script printing it (getting it wrong for married if they've been friends, as the relationship_ids aren't consulted):
Spoiler (click to show/hide)
Logged

UselessMcMiner

  • Bay Watcher
  • praise jeebus
    • View Profile
Re: RELATIONSHIP_ID's in DFHACK.
« Reply #6 on: December 05, 2018, 07:38:40 am »

So how should I modify my script? Because now i'm even more stuck.
Logged
Quote
The scouts have been fighting a giant capuchin for the past month now. They still haven't killed it.

Obsidian 1053

The Sentries are still fighting the capuchin. For two monthes they have done nothing but punch this monkey.

UselessMcMiner

  • Bay Watcher
  • praise jeebus
    • View Profile
Re: RELATIONSHIP_ID's in DFHACK.
« Reply #7 on: December 05, 2018, 04:07:36 pm »

Ok so clearly the issue is something else that i've figured out. I'll make a seperate post about it because it's a lot different compared to the other issue. Thanks a lot mifki and  PatrikLundell! And Patrik the issue is the fact that dwarves can have multiple Friends but only one Spouse so friends are somewhere else. I'll get some help in trying to find it.
Logged
Quote
The scouts have been fighting a giant capuchin for the past month now. They still haven't killed it.

Obsidian 1053

The Sentries are still fighting the capuchin. For two monthes they have done nothing but punch this monkey.

PatrikLundell

  • Bay Watcher
    • View Profile
Re: RELATIONSHIP_ID's in DFHACK.
« Reply #8 on: December 05, 2018, 04:51:08 pm »

The script snippet I posted uses the "somewhere else": it's in the hist fig, not the unit. "hf" is the hist fig, and "info.relationships" is where relationships are stored. The hf relationship structure is a vector of variable size (to allow for a bazillion passing acquaintances with visitors), and the function at the top of the snippet is used to sort the elements of this structure in the same order as DF does when displaying it.
As can be seen, the data isn't organized in a particularly user friendly manner...
Logged

UselessMcMiner

  • Bay Watcher
  • praise jeebus
    • View Profile
Re: RELATIONSHIP_ID's in DFHACK.
« Reply #9 on: December 05, 2018, 06:25:36 pm »

I guess my big question is how can I modify it? Will that code snippet be enough do you think?

EDIT: I guess how complicated will it be to edit a historical figure's relationships?
« Last Edit: December 05, 2018, 06:46:54 pm by UselessMcMiner »
Logged
Quote
The scouts have been fighting a giant capuchin for the past month now. They still haven't killed it.

Obsidian 1053

The Sentries are still fighting the capuchin. For two monthes they have done nothing but punch this monkey.

PatrikLundell

  • Bay Watcher
    • View Profile
Re: RELATIONSHIP_ID's in DFHACK.
« Reply #10 on: December 06, 2018, 03:48:40 am »

I would expect it's a matter of inserting a new element in the vector and filling it with the appropriate field values. However, if I remember correctly, there is a bunch of fields which haven't been identified, and I have no idea of whether those are important or not.
Logged

UselessMcMiner

  • Bay Watcher
  • praise jeebus
    • View Profile
Re: RELATIONSHIP_ID's in DFHACK.
« Reply #11 on: December 06, 2018, 08:16:40 am »

Sorry for asking but what is a vector? I have only just started programming and sorry if its a stupid question. And also where is f1.attitude located? In the historical id file right?
Logged
Quote
The scouts have been fighting a giant capuchin for the past month now. They still haven't killed it.

Obsidian 1053

The Sentries are still fighting the capuchin. For two monthes they have done nothing but punch this monkey.

PatrikLundell

  • Bay Watcher
    • View Profile
Re: RELATIONSHIP_ID's in DFHACK.
« Reply #12 on: December 06, 2018, 01:49:49 pm »

A vector in this context is a C(++) structure that contains a "list" of elements of some C(++) type. It's somewhat similar to an array (in C terminology). A vector contains information about how long it is in a "header" structure, and it's capable of being extended or shrunk. DFHack maps DF's vectors onto Lua lists, allowing you to iterate over them (as well as modifying their lengths).

"f1" isn't located anywhere: it's a parameter to the friend_lt function, and if you look at the call to friend_lt you'll find that f1 and f2 are friends [k] and friends [l] respectively. "friends", in its turn, is a Lua vector the script builds for its own use (table.insert...), and the elements of that vector are populated by the iterator variable "relation" (using the peculiar Lua "ipairs" iterator construct). "relation", in turn, takes the value of "hf.info.relationships.list [k]", which is the value of each of the elements (in turn) of the DF vector that's part of the "hf.info.relationships.info" vector. Thus, that is the vector you're looking for.

I'm not sure this is the best place to learn Lua scripting, as manipulation of pointers in an incorrect manner is a good way to get DF to crash (and there are a whole lot of incorrect ways, and only a few correct ones). This is in addition to leaking memory by allocating memory and not freeing it afterwards (Lua is supposed to do that for its own data [although I'm skeptic and not sure it works correctly], but C(++) is inherently unsafe and all safety of almost any kind has to be added manually (or by using classes that add them, in which case you would be better off using a high level language that had safety built in).
Logged