Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 247 248 [249] 250 251 ... 373

Author Topic: DFHack 0.34.11 r3  (Read 1019025 times)

ag

  • Bay Watcher
    • View Profile
Re: DFHack 0.34.11 r3
« Reply #3720 on: May 13, 2013, 02:51:52 am »

Logged

gchristopher

  • Bay Watcher
    • View Profile
Re: DFHack 0.34.11 r2
« Reply #3721 on: May 13, 2013, 02:55:14 am »

Question about makeown:

I used it on a dwarven caravan guard, but he's not listed as a citizen or member of anything (no blue text in his description). I can force him into a squad using DT and he'll follow station orders, but he won't go and train or put on a uniform, or in fact any clothes at all. He was wearing them at one point, but then dropped everything when I forced him into a squad. Removing him from the squad via DT doesn't make him wear anything either.

Is there any way of making him a full member of the fortress, or does makeown only work for making civilians?
I noticed that after tweak makeown, a caravan guard doesn't appear in Dwarf Therapist or in the military squads screen. The guards I was looking at didn't have historical figure entries, but it seems that if I create a minimal entry that associates the guard with the fortress, then they show up in Therapist and the squads screen.

Maybe this will fill in the gaps in behavior for converting caravan guards?

Here's the code to create the historical figure record. I looked at founders and babies for examples. It looks like the majority of the data is optional.
Code: [Select]
function create_hist_fig(unit)
  if unit.flags1.important_historical_figure == true then
    print("Already a historical figure.")
    return
  end
 
  new_fig_id = df.global.hist_figure_next_id

  new_hist_fig = df.historical_figure:new()
  new_hist_fig.profession = unit.profession
  new_hist_fig.race = unit.race
  new_hist_fig.caste = unit.caste
  new_hist_fig.sex = unit.sex
  new_hist_fig.appeared_year = unit.relations.birth_year
  new_hist_fig.born_year = unit.relations.birth_year
  new_hist_fig.born_seconds = unit.relations.birth_time
  new_hist_fig.curse_year = unit.relations.curse_year
  new_hist_fig.curse_seconds = unit.relations.curse_time
  new_hist_fig.anon_1 = unit.relations.anon_2
  new_hist_fig.anon_2 = unit.relations.anon_3
  new_hist_fig.old_year = unit.relations.old_year
  new_hist_fig.old_seconds = unit.relations.old_time
  new_hist_fig.died_year = -1
  new_hist_fig.died_seconds = 1
  new_hist_fig.name:assign(unit.name)
  new_hist_fig.civ_id = unit.civ_id
  new_hist_fig.population_id  = unit.population_id
  new_hist_fig.breed_id = -1
  new_hist_fig.unit_id = unit.id
  new_hist_fig.id = new_fig_id
 
  civ_link = df.histfig_entity_link_memberst:new()
  civ_link.entity_id = df.global.ui.civ_id
  civ_link.link_strength =  100
 
  fort_link = df.histfig_entity_link_memberst:new()
  fort_link.entity_id = df.global.ui.group_id
  fort_link.link_strength =  100
 
  new_hist_fig.entity_links:insert('#', civ_link)
  new_hist_fig.entity_links:insert('#', fort_link)
 
  df.global.world.history.figures:insert('#', new_hist_fig)
  df.global.hist_figure_next_id = df.global.hist_figure_next_id + 1
 
  unit.flags1.important_historical_figure = true
  unit.flags2.important_historical_figure = true
  unit.hist_figure_id = new_fig_id
  unit.hist_figure_id2 = new_fig_id
end

unit = dfhack.gui.getSelectedUnit()
create_hist_fig(unit)

I'm currently testing this for bugs and side-effects. Creating new data is probably pretty dangerous.
« Last Edit: May 13, 2013, 03:43:00 am by gchristopher »
Logged

ag

  • Bay Watcher
    • View Profile
Re: DFHack 0.34.11 r2
« Reply #3722 on: May 13, 2013, 03:09:17 am »

I'm currently testing this for bugs and side-effects. Creating new data is probably pretty dangerous.

For one, there is a df.global.hist_figure_next_id variable, and you must use that value and properly increment it afterwards. Also, to copy names, you can just do foo.name:assign(bar.name).
Logged

gchristopher

  • Bay Watcher
    • View Profile
Re: DFHack 0.34.11 r2
« Reply #3723 on: May 13, 2013, 03:22:34 am »

I'm currently testing this for bugs and side-effects. Creating new data is probably pretty dangerous.

For one, there is a df.global.hist_figure_next_id variable, and you must use that value and properly increment it afterwards. Also, to copy names, you can just do foo.name:assign(bar.name).
Thanks! Making both changes to the original post.

Looks like they also needed to be added to the fortress entity and civilization entity histfig_ids and his_figures lists. Once that is done:

More preliminary testing: they seem to respect labor orders and squads, will put on uniforms and train, and will attack when ordered.

Still failing: they are listed in the nobles screen, but assignments to noble positions don't work yet.
« Last Edit: May 14, 2013, 02:09:24 am by gchristopher »
Logged

0x517A5D

  • Bay Watcher
  • Hex Editor‬‬
    • View Profile
Re: DFHack 0.34.11 r3
« Reply #3724 on: May 13, 2013, 12:23:49 pm »

So, since I can't find any clear answer anywhere. Is there currently any way to change the number of embarking dwarf with this?

I don't think so.  There is a script (at hack/lua/plugins/dfusion/embark.lua) that looks like it has the capability, but it is not exposed to the user.

If you're comfortable hacking Lua code, you could probably pull the necessary code out of the CustomEmbark:SetEmbarkParty routine in that file.
Logged

Warmist

  • Bay Watcher
  • Master of unfinished jobs
    • View Profile
Re: DFHack 0.34.11 r3
« Reply #3725 on: May 13, 2013, 02:22:24 pm »

or use this: https://github.com/jjyg/dfhack/blob/master/scripts/startdwarf.rb
(paste it into startdwarf.rb in scripts dir)

TigerHunter

  • Bay Watcher
    • View Profile
Re: DFHack 0.34.11 r3
« Reply #3726 on: May 13, 2013, 05:25:55 pm »

Hi all. DF freezes my computer every so often (even when I limit the FPS to basically nothing), so I've taken to saving frequently. However, lately it's taken to freezing while I'm in the process of saving, corrupting the save and causing me to lose the game altogether.

To cope with this, I would like to edit DFHack's autosave script to automatically create a backup after the save is complete. Here's the code:
Code: [Select]
-- Makes the game immediately save the state.

if not dfhack.isMapLoaded() then
    qerror("World and map aren't loaded.")
end

local ui_main = df.global.ui.main
local flags4 = df.global.d_init.flags4

local function restore_autobackup()
    if ui_main.autosave_request and dfhack.isMapLoaded() then
        dfhack.timeout(10, 'frames', restore_autobackup)
    else
        flags4.AUTOBACKUP = true
    end
end

-- Request auto-save
ui_main.autosave_request = true

-- And since it will overwrite the backup, disable it temporarily
if flags4.AUTOBACKUP then
    flags4.AUTOBACKUP = false
    restore_autobackup()
end

print 'The game should save the state now.'

I know how to write the backup script in python, so the simplest way to accomplish this would be add in a line of code telling it to run the python interpreter on the .py file after turning autobackup back on. Is this possible? If not, would someone mind explaining the basic steps I would need to go through to make the lua script copy the save folder to a new directory?
Logged

Urist Da Vinci

  • Bay Watcher
  • [NATURAL_SKILL: ENGINEER:4]
    • View Profile
Re: DFHack 0.34.11 r3
« Reply #3727 on: May 13, 2013, 10:41:37 pm »

I suggest you read this document: https://github.com/peterix/dfhack/blob/master/Lua%20API.rst#material-info-lookup

Thanks!

Final product:
Code: (blooddel.lua) [Select]
local my_entity=df.historical_entity.find(df.global.ui.civ_id)
local sText=" "
local k=0
local v=1

for x,y in pairs(df.global.world.entities.all) do
my_entity=y
k=0
while k < #my_entity.resources.misc_mat.extracts.mat_index do
v=my_entity.resources.misc_mat.extracts.mat_type[k]
sText=dfhack.matinfo.decode(v,my_entity.resources.misc_mat.extracts.mat_index[k])
if (sText==nil) then
--LIQUID barrels
my_entity.resources.misc_mat.extracts.mat_type:erase(k)
my_entity.resources.misc_mat.extracts.mat_index:erase(k)
k=k-1
else
if(sText.material.id=="BLOOD") then
my_entity.resources.misc_mat.extracts.mat_type:erase(k)
my_entity.resources.misc_mat.extracts.mat_index:erase(k)
k=k-1
end
if(sText.material.id=="ICHOR") then
my_entity.resources.misc_mat.extracts.mat_type:erase(k)
my_entity.resources.misc_mat.extracts.mat_index:erase(k)
k=k-1
end
if(sText.material.id=="GOO") then
my_entity.resources.misc_mat.extracts.mat_type:erase(k)
my_entity.resources.misc_mat.extracts.mat_index:erase(k)
k=k-1
end
--VENOM
--POISON
--FLUID
--MILK
--EXTRACT

end
k=k+1
end
end

EDIT: for people who haven't been following my recent posts in this thread, the above script prevents all civilizations in the world from bringing blood, ichor, and "liquid" barrels in caravans. If used before embark (at the screen where you choose your site location), it prevents you from being able to embark with barrels of blood, considerably shortening the extracts list. It also shortens the list that you use to request extracts from the liaison.
« Last Edit: May 13, 2013, 10:47:18 pm by Urist Da Vinci »
Logged

scamtank

  • Bay Watcher
    • View Profile
Re: DFHack 0.34.11 r3
« Reply #3728 on: May 14, 2013, 10:31:16 am »

Final product:
Code: (blooddel.lua) [Select]
local my_entity=df.historical_entity.find(df.global.ui.civ_id)
local sText=" "
local k=0
local v=1

for x,y in pairs(df.global.world.entities.all) do
my_entity=y
k=0
while k < #my_entity.resources.misc_mat.extracts.mat_index do
v=my_entity.resources.misc_mat.extracts.mat_type[k]
sText=dfhack.matinfo.decode(v,my_entity.resources.misc_mat.extracts.mat_index[k])
if (sText==nil) then
--LIQUID barrels
my_entity.resources.misc_mat.extracts.mat_type:erase(k)
my_entity.resources.misc_mat.extracts.mat_index:erase(k)
k=k-1
else
if(sText.material.id=="BLOOD") then
my_entity.resources.misc_mat.extracts.mat_type:erase(k)
my_entity.resources.misc_mat.extracts.mat_index:erase(k)
k=k-1
end
if(sText.material.id=="ICHOR") then
my_entity.resources.misc_mat.extracts.mat_type:erase(k)
my_entity.resources.misc_mat.extracts.mat_index:erase(k)
k=k-1
end
if(sText.material.id=="GOO") then
my_entity.resources.misc_mat.extracts.mat_type:erase(k)
my_entity.resources.misc_mat.extracts.mat_index:erase(k)
k=k-1
end
--VENOM
--POISON
--FLUID
--MILK
--EXTRACT

end
k=k+1
end
end

EDIT: for people who haven't been following my recent posts in this thread, the above script prevents all civilizations in the world from bringing blood, ichor, and "liquid" barrels in caravans. If used before embark (at the screen where you choose your site location), it prevents you from being able to embark with barrels of blood, considerably shortening the extracts list. It also shortens the list that you use to request extracts from the liaison.

I'm really glad that you're here doing the things that you do. This little snag has ground my gears for so long.
Logged

Mr S

  • Bay Watcher
    • View Profile
Re: DFHack 0.34.11 r3
« Reply #3729 on: May 14, 2013, 01:31:51 pm »

I, for one, enjoy adding [EDIBLE_COOKED] to blood and having my dorfs make black pudding.  Of course, YMMV.
Logged

0x517A5D

  • Bay Watcher
  • Hex Editor‬‬
    • View Profile
Re: DFHack 0.34.11 r3
« Reply #3730 on: May 14, 2013, 02:13:08 pm »

I've got a dfhack-internals question for peterix or anyone else who knows.

The sample plugin skeleton.cpp has a comment that dfhack console commands are called from a different thread than the main DF thread.

Is this only true of the console commands?  Or do plugin_* run in a different thread?

I assume that vtable hooks must run in DF's main thread, at least.


(I know, I know, I should write test code and figure it out myself.  DFHack is dauntingly complex, and I'm trying to get a handle on how it all fits together.)
Logged

Kurik Amudnil

  • Bay Watcher
    • View Profile
Re: DFHack 0.34.11 r3
« Reply #3731 on: May 14, 2013, 06:32:26 pm »

I am working on a script to display information about a unit such as birth day (civ members/pets), max age (currently as an average), body size estimate,  milkable, and grazer info.  I have it respecting assumed identities for the birth/age/name and can display animals with/without "Stray".

However, I am having some trouble figuring out how to determine that a unit is supposed to have "Corpse" in the name.  Black Mamba Man Corpse comes out as Black Mamba Man.  Since the zombie looks very similar to vampires in code I don't know what to base the decision to tack on "corpse" to the name/profession.  I am also curious as to how many other name/profession modifications I might need for units such as necromancers, ghosts, demons, clowns, husks, etc

I would also like to show "missing" units as missing with perhaps the time they were reported missing, but I am uncertain if the game records that date.  If it also recorded a last known location I might want to allow centering on that location.

I am also currently trying to print the basic description provided by the caste definition but am finding it difficult to find the printable width of my lua screen / widget so that I can insert appropriate NEWLINE breaks.  I am probably trying to perform that logic in the wrong place (:init of my framed screen class).  I think I ought to break up the info chunks into their own individual widget labels too.

I am currently calling it more-unit-info.lua and binding it to Alt-I but eventually it might be able to duplicate the "thoughts and preferences" screen so maybe another name would be more appropriate.
My Current Draft:
Spoiler (click to show/hide)
« Last Edit: May 14, 2013, 07:04:35 pm by Kurik Amudnil »
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: DFHack 0.34.11 r3
« Reply #3732 on: May 14, 2013, 06:47:36 pm »

The first thing I can think of is that zombies don't have souls.

Kurik Amudnil

  • Bay Watcher
    • View Profile
Re: DFHack 0.34.11 r3
« Reply #3733 on: May 14, 2013, 07:13:31 pm »

The first thing I can think of is that zombies don't have souls.

The example zombies I have in my fort are from the curious structure in the bottom cavern, and a quick peak shows that they do have a current_soul reference

dfhack.TranslateName( unit ) returns ""
dfhack.units.getProfessionName(unit) returns "Black Mamba Man"
game displays "Black Mamba Man Corpse"

*edit

found a reference in unit.enemy.undead on my "Corpse" zombies and not my vampire so I can use that for now.  I may need to make changes once I get examples for the other types of undead (zombies, husks, murked, reanimated, etc)

also found unit.flags1.zombie .  I don't know how I missed that one before, but strangely these "Corpse" are flags1.zombie == false.

on another note:  unit.flags3.unk21 == missing
« Last Edit: May 15, 2013, 03:50:10 am by Kurik Amudnil »
Logged

ag

  • Bay Watcher
    • View Profile
Re: DFHack 0.34.11 r3
« Reply #3734 on: May 15, 2013, 04:42:09 am »

also found unit.flags1.zombie .  I don't know how I missed that one before, but strangely these "Corpse" are flags1.zombie == false.
on another note:  unit.flags3.unk21 == missing

That zombie flag is obsolete and not used any more. Also, if you mean discovered/not discovered death, it is stored in a completely different object.
Logged
Pages: 1 ... 247 248 [249] 250 251 ... 373