Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 193 194 [195] 196 197 ... 373

Author Topic: DFHack 0.34.11 r3  (Read 1457290 times)

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: DFHack 0.34.11 r2
« Reply #2910 on: February 02, 2013, 06:34:45 pm »

Any way to detect a creature's body size?

Found an answer myself--unit.body.blood_max returns a value that appears to be 1/10th the body size of the given creature.

WillowLuman

  • Bay Watcher
  • They/Them Life is weird
    • View Profile
Re: DFHack 0.34.11 r2
« Reply #2911 on: February 02, 2013, 07:11:26 pm »

So, if you use the marriage script, then the force pregnancy script, will it properly show who the father was in legends and get the gene info, instead of "identity of father was lost to history?"

Would make some epic legend mode stuff after adventure XD
Logged
Dwarf Souls: Prepare to Mine
Keep Me Safe - A Girl and Her Computer (Illustrated Game)
Darkest Garden - Illustrated game. - What mysteries lie in the abandoned dark?

Caldfir

  • Bay Watcher
    • View Profile
Re: DFHack 0.34.11 r2
« Reply #2912 on: February 02, 2013, 09:29:04 pm »

Here's a little script I just cooked up to give proper spouse/parent last names to dwarves in the fort (only works if spouse/parent is actually at the fort), for those who like having family names.  Valid arguments are nothing or 0 for a patriarchal lineage (wives and children get father/husband last name), or 1 for a matriarchal lineage (husbands and children get mother/wife last name).  I just cobbled this together, so it's nothing perfect, might be builtin dfhack functions to do some stuff that I did, but I don't know cause there's very little documentation I could find on the properties and methods associated with each class, so I just had to go by key,value pairs to find properties and worked from there.  If anyone wants to do any improvements to it, that's fine by me.  Not even sure this would actually change their names in legends or what since there seems to be a separate historical id.

Oh, and does anyone know how to update the names when viewing unit status without giving them a nick and then removing it in game?

Spoiler (click to show/hide)

Neat.  Been meaning to do something like this myself for a while now but haven't gotten around to it.  Should make figuring out what the family trees are in the fort a more tractable problem (one challenge I like to play with is giving each family/clan appropriately connected living quarters). 
Logged
where is up?

Lord_Phoenix

  • Bay Watcher
    • View Profile
Re: DFHack 0.34.11 r2
« Reply #2913 on: February 02, 2013, 09:36:39 pm »

Neat.  Been meaning to do something like this myself for a while now but haven't gotten around to it.  Should make figuring out what the family trees are in the fort a more tractable problem (one challenge I like to play with is giving each family/clan appropriately connected living quarters).

Just have to run it whenever migrants come or someone has a baby.  Though, if someone with a family has their father show up, it will change the entire last name of everyone in that family.
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: DFHack 0.34.11 r2
« Reply #2914 on: February 02, 2013, 11:50:39 pm »

Hmm. Apparently, blood values don't change with body size perc changes. Odd.

There has to be somewhere the body size is stored, even if it's just the sum of all body parts...
« Last Edit: February 02, 2013, 11:52:12 pm by Putnam »
Logged

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: DFHack 0.34.11 r2
« Reply #2915 on: February 03, 2013, 12:10:14 am »

So, if you use the marriage script, then the force pregnancy script, will it properly show who the father was in legends and get the gene info, instead of "identity of father was lost to history?"

Would make some epic legend mode stuff after adventure XD

Would be interesting to test, and I suspect it would work.  The parent ids and all should be set up, so DF should be able to piece it all together as needed.  If there are legends mode entries for marriages that's almost certainly not going to show up, but parentage should work.

Hmm. Apparently, blood values don't change with body size perc changes. Odd.

There has to be somewhere the body size is stored, even if it's just the sum of all body parts...

I'm curious about this too.  Seems like it has to be stored somewhere.  I really doubt DF is summing the size of all of the body parts every time it's needed, since that's very inefficient.
Logged
Through pain, I find wisdom.

WillowLuman

  • Bay Watcher
  • They/Them Life is weird
    • View Profile
Re: DFHack 0.34.11 r2
« Reply #2916 on: February 03, 2013, 01:30:27 am »

Marriage doesn't seem to be working in adventure mode, gives me

Code: [Select]
Cannot read field vector(historical_figure*).6965: index out of bounds.
Logged
Dwarf Souls: Prepare to Mine
Keep Me Safe - A Girl and Her Computer (Illustrated Game)
Darkest Garden - Illustrated game. - What mysteries lie in the abandoned dark?

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: DFHack 0.34.11 r2
« Reply #2917 on: February 03, 2013, 01:45:38 am »

Hmm, it's possible that I'm making some bad assumptions in the way it looks up the historical figure.  It currently uses the historical figure id as the index into the array, which worked perfectly fine in my testing.  It's possible adventure mode doesn't load all of the historical figures at once?  Or it's possible that the id doesn't always equal the index.

If that's the case, the part where it sets the historical figure should be replaced with a loop through the historical figures and comparing to the ids until it finds the one that matches.  I'll be working on it and related stuff in the next couple of days, so if you can't figure it out by then I'll post a version that should be more correct.
Logged
Through pain, I find wisdom.

WillowLuman

  • Bay Watcher
  • They/Them Life is weird
    • View Profile
Re: DFHack 0.34.11 r2
« Reply #2918 on: February 03, 2013, 01:46:58 am »

Have you tested it on more than 1 world?
Logged
Dwarf Souls: Prepare to Mine
Keep Me Safe - A Girl and Her Computer (Illustrated Game)
Darkest Garden - Illustrated game. - What mysteries lie in the abandoned dark?

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: DFHack 0.34.11 r2
« Reply #2919 on: February 03, 2013, 01:54:13 am »

Nope, just one embark on one world.  I wouldn't be surprised at all if it just happened to conveniently work on that one embark.  In fact, later embarks may well break it.  Fixing the code should be fairly straightforward.  I may get to it tonight.
Logged
Through pain, I find wisdom.

WillowLuman

  • Bay Watcher
  • They/Them Life is weird
    • View Profile
Re: DFHack 0.34.11 r2
« Reply #2920 on: February 03, 2013, 01:58:02 am »

It's just, that 6965 seems oddly specific, possibly derived from some data unique to that world.
Logged
Dwarf Souls: Prepare to Mine
Keep Me Safe - A Girl and Her Computer (Illustrated Game)
Darkest Garden - Illustrated game. - What mysteries lie in the abandoned dark?

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: DFHack 0.34.11 r2
« Reply #2921 on: February 03, 2013, 02:03:56 am »

Oh, no, it's not.  That's the historical figure id of whoever you told it to marry.  That's specific to each world and whoever it is for.  In this case, that just means that one of the two you were trying to marry had a historical figure id of 6965, but the number of historical figures currently in DF's memory is less than 6965.  That could be either because DF doesn't load them all in adventure mode, or because they lose the 1-to-1 relationship of index associated to historical figure id I was relying on.  That worked in my world, but worlds that have actually had gameplay happen in them may invalidate that.

Edit: Here's the updated script.  It has a lot more error checking, does a proper look up for the historical figures, and uses the core suspension call to reduce the risk of the game crashing.  Still seems to work fine in my world, testing in others would be great though.

Code: [Select]
-- Marries two specified creatures

local args = {...}

function marry (unit_id1, unit_id2)

local victim1, historic_victim1
local victim2, historic_victim2

for key, value in pairs(df.global.world.units.all) do
-- The arguments are strings, but the structs contain numbers
if value.id == unit_id1 then
victim1 = value
end
if value.id == unit_id2 then
victim2 = value
end
end

if df.isnull(victim1) then
print('The first unit was not found.')
return
end
if df.isnull(victim2) then
print('The second unit was not found.')
return
end

print("Marrying " .. victim1.name.nickname .. " and " .. victim2.name.nickname)

for key, value in pairs(df.global.world.history.figures) do
if value.id == victim1.hist_figure_id then
historic_victim1 = value
end
if value.id == victim2.hist_figure_id then
historic_victim2 = value
end
end

if df.isnull(historic_victim1) then
print('The historical figure for the first unit was not found.')
return
end
if df.isnull(historic_victim2) then
print('The historical figure for the second unit was not found.')
return
end

local new_link1 = df.histfig_hf_link_spousest:new()
local new_link2 = df.histfig_hf_link_spousest:new()

-- Not documented, but this is the historical figure id
new_link1.anon_1 = victim2.hist_figure_id
new_link1.link_strength = 100

new_link2.anon_1 = victim1.hist_figure_id
new_link2.link_strength = 100

local link_count1 = #historic_victim1.histfig_links
local link_count2 = #historic_victim2.histfig_links

historic_victim1.histfig_links:resize(link_count1 + 1)
historic_victim1.histfig_links[link_count1] = new_link1
historic_victim2.histfig_links:resize(link_count2 + 1)
historic_victim2.histfig_links[link_count2] = new_link2

victim1.relations.spouse_id = victim2.id
victim2.relations.spouse_id = victim1.id
end

if df.isnull(args[1]) or df.isnull(args[2]) then
print('You must pass in two unit ids.')
return
end

dfhack.with_suspend(marry, tonumber(args[1]), tonumber(args[2]))

Edit2: Here's a script for divorcing units:

Code: [Select]
-- Divorces a creature from its spouse and / or lover.  Run this per creature in a relationship.

local args = {...}

function divorce (unit_id)

local victim, historic_victim

for key, value in pairs(df.global.world.units.all) do
-- The arguments are strings, but the structs contain numbers
if value.id == unit_id then
victim = value
end
end

if df.isnull(victim) then
print('The unit was not found.')
return
end

if victim.relations.spouse_id == -1 and victim.relations.lover_id == -1 then
print('Warning: the unit has no lover or spouse, nothing to do.')
return
end

print("Divorcing " .. victim.name.nickname)

for key, value in pairs(df.global.world.history.figures) do
if value.id == victim.hist_figure_id then
historic_victim = value
end
end

if df.isnull(historic_victim) then
print('The historical figure for the unit was not found.')
return
end

local link_count = #historic_victim.histfig_links

-- Remove the spouse hf link, if it exists
for key, value in pairs(historic_victim.histfig_links) do
if df.histfig_hf_link_spousest:is_instance(value) then
if key ~= link_count -1 then
-- Moves the spouse entry to the end of the list, then resizes the list to size - 1, erasing it
historic_victim.histfig_links[key] = historic_victim.histfig_links[link_count - 1]
end

historic_victim.histfig_links:resize(link_count - 1)
link_count = link_count - 1
value:delete()

break
end
end

-- Remove the lover hf link, if it exists
for key, value in pairs(historic_victim.histfig_links) do
if df.histfig_hf_link_loverst:is_instance(value) then
if key ~= link_count -1 then
-- Moves the lover entry to the end of the list, then resizes the list to size - 1, erasing it
historic_victim.histfig_links[key] = historic_victim.histfig_links[link_count - 1]
end

historic_victim.histfig_links:resize(link_count - 1)
link_count = link_count - 1
value:delete()

break
end
end

victim.relations.spouse_id = -1
victim.relations.lover_id = -1
end

if df.isnull(args[1]) then
print('You must pass in a unit id.')
return
end

dfhack.with_suspend(divorce, tonumber(args[1]))

The format is similar, except you run:

Code: [Select]
divorce unit_id
It just takes one unit id at a time.  Yes, you can have one directional relationships this way.  It also removes lover links, so you can remove these from dwarves who have a lover die, and they should be able to pick up another later.  Or, if their spouse dies they can pick up another.

Tested and working on my world, but again, testing in others would be nice.
« Last Edit: February 03, 2013, 03:13:16 am by Telgin »
Logged
Through pain, I find wisdom.

ag

  • Bay Watcher
    • View Profile
Re: DFHack 0.34.11 r2
« Reply #2922 on: February 03, 2013, 03:38:10 am »

Edit: Here's the updated script.  It has a lot more error checking, does a proper look up for the historical figures, and uses the core suspension call to reduce the risk of the game crashing.  Still seems to work fine in my world, testing in others would be great though.

There is nothing proper in linear loops :P. Use df.historical_figure.find(id) and df.unit.find(id). Also, if run from hack/script/ and not via legacy dfusion, core is always already suspended.
« Last Edit: February 03, 2013, 04:03:28 am by ag »
Logged

Lord_Phoenix

  • Bay Watcher
    • View Profile
Re: DFHack 0.34.11 r2
« Reply #2923 on: February 03, 2013, 06:28:41 am »

Oh, no, it's not.  That's the historical figure id of whoever you told it to marry.  That's specific to each world and whoever it is for.  In this case, that just means that one of the two you were trying to marry had a historical figure id of 6965, but the number of historical figures currently in DF's memory is less than 6965.  That could be either because DF doesn't load them all in adventure mode, or because they lose the 1-to-1 relationship of index associated to historical figure id I was relying on.  That worked in my world, but worlds that have actually had gameplay happen in them may invalidate that.

I noticed in my fort when messing about with the renaming script I made that the keys on the list of hist fig ids stopped around 96000, but all the dwarves in the fort had hist fig ids in the 120000-140000 range.
Logged

Quietust

  • Bay Watcher
  • Does not suffer fools gladly
    • View Profile
    • QMT Productions
Re: DFHack 0.34.11 r2
« Reply #2924 on: February 03, 2013, 09:12:20 am »

Looking at the "marry" and "divorce" scripts, you're missing one important thing: historical events; the 'marry' script should add a pair of history_event_add_hf_hf_linkst entries so Legends will report them having been married, and the 'divorce' script should similarly add a pair of history_event_remove_hf_hf_linkst entries (which, if I recall correctly, will actually show up as "X divorced Y" in Legends mode).
Logged
P.S. If you don't get this note, let me know and I'll write you another.
It's amazing how dwarves can make a stack of bones completely waterproof and magmaproof.
It's amazing how they can make an entire floodgate out of the bones of 2 cats.
Pages: 1 ... 193 194 [195] 196 197 ... 373