Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 212 213 [214] 215 216 ... 244

Author Topic: DFHack 50.14-r1.1  (Read 893948 times)

PatrikLundell

  • Bay Watcher
    • View Profile
Re: DFHack 0.47.05-r6
« Reply #3195 on: August 09, 2022, 07:09:23 am »

@doublestrafe:

The key to finding info from the DF data structures is to gradually learn how they're structured so you can make educated guesses as which place to look for the info you want. gui/gm-editor is a very good tool for that.

df.global.world.world_data.name is (presumably) a name, and I would expect it to be the name of the world. You'd need the DFHack operation to unpack the name (too long since I did anything with DFHack, so I'd have to locate it in some script or look at the documentation if I was to say what it is).

df.global.world.world_data.active_site is the current fortress in a vector of size 1. The first element of the the structure in that vector is a name, which should be the name of the fortress. Again, you'd need to use the operation to extract a string from it (and a boolean is used to specify if the string should be English or the "native" language).
As an aside, this same entry is also found in the vector containing all sites (because the vector entries are references to the data, not the data itself, so it's not a duplication), so you could find it there by looking for the type being PlayerFortress, but you'd get all of them if you have embarked multiple times in the same world.

Hope that's clear enough for you to find what you need.
Logged

lethosor

  • Bay Watcher
    • View Profile
Re: DFHack 0.47.05-r6
« Reply #3196 on: August 10, 2022, 12:39:37 am »

But I've run into another problem with the gamelog.txt, which is that it doesn't care at all what save you're running from. Everything from every fort goes in willy-nilly. So I thought, while I'm writing a timestamp, why not write the name of the fortress? How hard can that be?
It depends on what you mean by "name of the fortress". Patrik's suggestion of "world.world_data.name" is the in-game name that you see on the right side of the screen in the "load game" menu, among other places. If you want the folder, that is "world.cur_savegame.save_dir" (and if you want the full path, use "dfhack.getSavePath()" in Lua).

Quote
I am at an utter loss here. I had been able to find df.global.cur_year only because timestream uses it--I learned a lot from timestream, actually. And I found where it came from, in https://github.com/DFHack/df-structures/blob/master/df.globals.xml (had to go online--despite the Lua API docs' assurance, \hack\library\xml only contains how-to-update and SYNTAX). There are some interesting things there, but not, as far as I can tell, the name of the fortress.

Really, this is a more general question, though I really do want to know how to return the fortress name, or at least the world name. But how do you find what you're looking for in the dozens of xml files? Is it just a question of sheer dogged perseverance and trial and error?
I second the recommendation to use gui/gm-editor. Specifically, you can start with "gui/gm-editor df.global". A lot of game-specific stuff is under "world", and a lot of other things are under "ui". Those are probably the biggest two. You can get to globals directly with just their name, e.g. "gui/gm-editor world".

If you prefer a text-based UI, you can also run "lua" and navigate through an interpreter. I do this a lot, using the "~" shortcut for printall().

I can see why the documentation telling you to look in library/xml could be confusing - what it means is to look at that path in the DFHack source code, i.e. https://github.com/dfhack/dfhack -> library -> xml (or locally), which takes you to https://github.com/dfhack/df-structures (so you found the right XML files eventually). Based on the wording in that paragraph, I am pretty confident that it pre-dates any sort of generated+hosted documentation. Our intra-documentation links should always be actual links, not references to paths that you have to follow manually (if you find an exception, please let us know!). In fact, even the external link in that paragraph, if followed, takes you to https://github.com/DFHack/df-structures

As for how I find things: I usually guess a couple names, and then search through the files locally. All types are defined in df.*.xml files. As an example, searching for "cur_savegame.save_dir": the field name likely contains the word "save", so grepping for "save" gives 98 results. Of those, 43 are "save_version", which I can rule out immediately. I can also be pretty sure this is a global, so I can rule out any files that primarily define non-global objects (such as df.viewscreen.xml, df.*raws.xml). At this point, I have 25 results that are part of an XML tag (not a comment), and the one I'm looking for happens to be the last one alphabetically:
Code: [Select]
df.world.xml:1512:            <stl-string name='save_dir'/>

A text search for "name" unfortunately gives an unreasonable number of results, because "name" is also the attribute used to name every field, type, etc.

Usually people are happy to point you to the right spot for questions about fields, and over time, people tend to get a feeling for where things are likely to be (I say "likely" because DF is not always consistent with itself). We have a Discord server as well (https://docs.dfhack.org/en/latest/docs/Support.html) where response rates vary but tend to be quick.
« Last Edit: August 10, 2022, 12:41:22 am by lethosor »
Logged
DFHack - Dwarf Manipulator (Lua) - DF Wiki talk

There was a typo in the siegers' campfire code. When the fires went out, so did the game.

doublestrafe

  • Bay Watcher
  • [PONY_DEPENDENT]
    • View Profile
Re: DFHack 0.47.05-r6
« Reply #3197 on: August 10, 2022, 02:30:12 am »

Thanks! PatrickLundell's help was the first thing I needed...but it took me a long time to figure that out. I'd only ever used gm-editor to play God with dwarves' very souls, and it took me a significant chunk of the day to figure out how to use it to look at anything else. (The example in the docs that uses it to look at all the items was a clue--I glazed over it a little because I knew how to look at items, and it took longer than it should have to realize that the command in the example was formatted just like what Patrick gave me.) Right now, my script is doing what I want it to do, despite the fact that finishing it generated a huge list of would-be-nice to-dos. Think I'll take a little break before I burn myself out, though. After all these years, coding projects still feel like a fey mood.

Of course, having the names of a couple of the df.global.world* commands is a huge help anyway, because searching on them pulls up other scripts that people have used them in.

I was going to complain about searching for "name" earlier but I figured I'd been whiny enough.

Discord! Good to know! It feels a little weird conversing on such general topics in the single dfhack thread. Dfhack is just so big, because half the questions are actually about Dwarf Fortress, but dfhack is the only way to get to where you can even ask the question.

One more question:

@doublestrafe:

You'd need the DFHack operation to unpack the name (too long since I did anything with DFHack, so I'd have to locate it in some script or look at the documentation if I was to say what it is).
Are you saying that there's documentation on what some of these are? If so, and you don't just mean the API docs, any pointers?
Logged

PatrikLundell

  • Bay Watcher
    • View Profile
Re: DFHack 0.47.05-r6
« Reply #3198 on: August 10, 2022, 03:07:16 am »

I'm feeling slightly less lazy today than yesterday, so I spent a few minutes locating an example of the command:
"dfhack.TranslateName (df.global.world.world_data.rivers [current_river].name, true)"
The first parameter is the name field of whatever you want the name of, and the second parameter is whether it should be in the "native" language (basically dwarven, elven, or goblin) or English (in this case it's the name if a river).

While trying to get to grips with gui/gm-editor was probably frustrating, I think it's probably time well spent (doesn't mean resting isn't in order). The "documentation" I was referring to was indeed the API documentation.
Logged

Jostino

  • Bay Watcher
  • dig dig dig in the deepy shadows
    • View Profile
Re: DFHack 0.47.05-r6
« Reply #3199 on: August 16, 2022, 04:40:47 am »

I don't know if is something already happened to someone, but I experienced this event with the "reveal" command.
(I've already posted in the bi-weekly thread on reddit and I received already some answers about, but I would share here also, if I can)

I revealed the map, then I saved the game. Game crashed, I loaded the game, but the map was still all visible, and it wasn't possible to use the unreveal command on DFHack, because is not allowed while the map is not revealed (even if it is actually).
Logged

Rumrusher

  • Bay Watcher
  • current project : searching...
    • View Profile
Re: DFHack 0.47.05-r6
« Reply #3200 on: August 16, 2022, 06:34:43 am »

I don't know if is something already happened to someone, but I experienced this event with the "reveal" command.
(I've already posted in the bi-weekly thread on reddit and I received already some answers about, but I would share here also, if I can)

I revealed the map, then I saved the game. Game crashed, I loaded the game, but the map was still all visible, and it wasn't possible to use the unreveal command on DFHack, because is not allowed while the map is not revealed (even if it is actually).
at that point you use revflood to fill in the rest of the map and hopefully fix the issue.



so kinda hit an roadblock on the modifications of tofort where I think I mostly got most of the crashes out But the one that ties into Advfort crashing if you do foraging which means there some Fort mode data that is missing in Adv mode that would cause DF to crash if ran.
also went into a bit more disjointed detail on this topic in the spoiler.
Logged
I thought I would I had never hear my daughter's escapades from some boy...
DAMN YOU RUMRUSHER!!!!!!!!
"body swapping and YOU!"
Adventure in baby making!Adv Homes

Jostino

  • Bay Watcher
  • dig dig dig in the deepy shadows
    • View Profile
Re: DFHack 0.47.05-r6
« Reply #3201 on: August 16, 2022, 12:24:31 pm »

I don't know if is something already happened to someone, but I experienced this event with the "reveal" command.
(I've already posted in the bi-weekly thread on reddit and I received already some answers about, but I would share here also, if I can)

I revealed the map, then I saved the game. Game crashed, I loaded the game, but the map was still all visible, and it wasn't possible to use the unreveal command on DFHack, because is not allowed while the map is not revealed (even if it is actually).
at that point you use revflood to fill in the rest of the map and hopefully fix the issue.

Solved with revflood! Thanks!
Logged

Rumrusher

  • Bay Watcher
  • current project : searching...
    • View Profile
Re: DFHack 0.47.05-r6
« Reply #3202 on: August 26, 2022, 11:40:23 am »


ok so after intense testing and rage, and stress I finally got around to a mostly some what stable version of warmist's tofort with viewscreen switching implementation.

Code: ("tofort-v15.lua") [Select]
-- changes from advmode to fort safely and back (hopefully)
--[[Now to warn you about saving and loading in either game mode might lead
    to some side issues, for saving in fort mode switching to adv mode needs the adv to be `bodyswap`
    back in again. for Saving in Adv to switch to Fort mode you probably be safe-ish if the site.
    isn't a nano fort or a site that isn't 3x3 small. otherwise the game will try to resize the map.
    oh and switching to fort mode on any pre-gen site larger than 4x4 might implode one pc if
    you don't have like 20 gigs of memory for the 16x16 embark size.

ok so this version of this script has be updated so that caravans and visitors and migrants
could show up at any edge of the map... and maybe leave from any spot... of the z level you assign the site too.
should be warned if a caravan decides to exit not from the assign z level you set like above or below the plane the game will crash.
so uhh I probably should get to figuring out how to map the surface at some point...]]--

if df.global.gamemode==df.game_mode.ADVENTURE then
local adv=df.global.world.units.active[0]
local comp={}
local ui=df.global.ui

function advGlobalPos()
    local wd=df.global.world.world_data
    return wd.adv_region_x*16+wd.adv_emb_x,wd.adv_region_y*16+wd.adv_emb_y
end
--[[function inSite()
    local tx,ty=advGlobalPos()
    for k,v in pairs(df.global.world.world_data.sites) do
        local tp={v.pos.x,v.pos.y}
        if tx>=tp[1]*16+v.rgn_min_x and tx<=tp[1]*16+v.rgn_max_x and
            ty>=tp[2]*16+v.rgn_min_y and ty<=tp[2]*16+v.rgn_max_y then
            return v
        end
    end
end]]--
function inSite()
    local tx,ty=advGlobalPos()
    for k,v in pairs(df.global.world.world_data.sites) do
        local tp2={v.global_min_x, v.global_min_y, v.global_max_x, v.global_max_y}
        if tx>=tp2[1] and tx<=tp2[3] and
            ty>=tp2[2] and ty<=tp2[4] then
            return v
        end
    end
end
local site=inSite()
if site==nil then
    qerror("No site you are in found.")
end
local nomad={}
local h_ent
if ui.main.fortress_entity~=nil or ui.main.fortress_site~=nil then
ui.main.fortress_entity=nil
ui.main.fortress_site=nil
end
    --[[for k,v in pairs(df.global.world.history.figures[adv.hist_figures_id].entity_links) do
if v==df.histfig_entity_link_positionst then
nomad=v.entity_id
break
end
end]]--
for k,v in pairs(df.global.world.history.figures[adv.hist_figure_id].entity_links) do
if v~=histfig_entity_link_memberst and not v==nil then
nomad=df.global.world.entities.all[v.entity_id]
print(v.entity_id)
else if v==histfig_entity_link_memberst then
nomad=df.global.world.history.figures[adv.hist_figure_id].entity_links[0]
end
end
end

if ui.main.fortress_entity==nil then
    for k,v in pairs(df.global.world.entities.all) do
        --if v.type==df.historical_entity_type.SiteGovernment and v.id==nomad.id then --maybe match race too?
        if v.id==nomad.id then --maybe match race too?
            if nomad.positions.own==nil then
break else
h_ent=v
            break
        end
        end
if v.id~=nomad.id then
if v.type==df.historical_entity_type.SiteGovernment then

h_ent=v
end
end
    end
    if h_ent==nil then
        qerror("Valid historical entity not found. sorry...")
    end
    ui.main.fortress_entity=h_ent
else
    h_ent=ui.main.fortress_entity
end
function cleardesignate(adv)
local adv=df.global.world.units.active[0]
df.global.ui.main.mode=10
df.global.selection_rect.start_x=0
df.global.selection_rect.start_y=0
df.global.selection_rect.start_z=610
df.global.selection_rect.end_x=-14300
df.global.selection_rect.end_y=9000
df.global.selection_rect.end_z=0
df.global.cursor.x=400
df.global.cursor.y=400
df.global.cursor.z=0
dfhack.gui.getCurViewscreen():feed_key(1)
df.global.cursor.x=adv.pos.x
df.global.cursor.y=adv.pos.y
df.global.cursor.z=adv.pos.z
dfhack.gui.getCurViewscreen():feed_key(1)
dfhack.run_command('revflood')

end
local carter={}
function addToEntity(entity,unit,addtoLead)
    local nem=dfhack.units.getNemesis(unit)
    local hfig=nem.figure
        for k,v in pairs(hfig.entity_links) do
--print(v.entity_id,entity.id)
if v.entity_id==entity.id then break else
carter=true
end
end
if carter==true then
hfig.entity_links:insert("#",{new=df.histfig_entity_link_memberst,entity_id=entity.id,link_strength=100})
    entity.nemesis_ids:insert("#",nem.id)
    entity.nemesis:insert("#",nem)
    entity.histfig_ids:insert("#",hfig.id)
    entity.hist_figures:insert("#",hfig)
end
    if addtoLead then
        local lead_id
        for k,v in pairs(entity.positions.own) do
            if v.flags.IS_LEADER==true then
                lead_id=v.id
                break
            end
        end
        if lead_id~=nil then
            for k,v in pairs(entity.positions.assignments) do
                if v.position_id==lead_id  then
                        v.histfig=hfig.id
                    break
                end
            end
        end
    end
end

ui.civ_id=adv.civ_id
ui.race_id=adv.race
df.global.pause_state=true


ui.unk_races:insert("#",adv.race)
ui.site_id=site.id
if ui.main.fortress_site==nil then ui.main.fortress_site=site end
if site.entity_links==nil then site.entity_links:insert("#", {new=true, df.entity_site_link, target=site.id, entity_id=ui.fortress_entity.id,entity_site_link_flags.residence, entity_site_link_flags.trade_partner }) end
ui.group_id=h_ent.id
ui.game_state=2


if #ui.tasks.discovered_plants==0 then
df.global.ui.tasks.discovered_creature_foods:insert("#",0)
df.global.ui.tasks.discovered_creatures:insert("#",0)
df.global.ui.tasks.discovered_plants:insert("#",0)
df.global.ui.tasks.discovered_plant_foods:insert("#",0)
end
if #ui.alerts.list==0 then
    ui.alerts.list:insert("#",{new=true,name="Dummy alert"})
    ui.alerts.next_id=1
end


    local nem2=dfhack.units.getNemesis(adv)
    local hfig2=nem2.figure
    local nomad2=hfig2.entity_links[0]
    local nomad3=hfig2.entity_links
    local Test={}
    for co2,mp2 in pairs(nomad3) do
--print(mp2.entity_id,h_ent.id)
        if mp2.entity_id~=h_ent.id then Test=true else
            Test=false
            end
        end   
        if Test==true then
            addToEntity(h_ent,adv,true)
        end
    for co,mp in pairs(df.global.world.units.active) do
        if mp.relationship_ids.GroupLeader==adv.id then
            local comp=mp
        if test==true then
            addToEntity(h_ent,comp,false)
        end
    end
end

function sigh()
 mapcheck()
for k,v in pairs(df.global.ui.map_edge.surface_z) do
df.global.ui.map_edge.surface_z[k]=adv.pos.z
--v=152
end
end
function mapcheck()
for k,v in pairs(df.global.ui.unk2a8c[0]) do
if v.unk1==0 then
v.unk1=12
v.unk2=12
end
if df.global.ui.unk_mapedge_x~=nil then
df.global.ui.unk_mapedge_x:insert("#","0")
df.global.ui.unk_mapedge_x:insert("#",math.random(0,143))
df.global.ui.unk_mapedge_x:insert("#","143")
df.global.ui.unk_mapedge_x:insert("#",math.random(0,143))
df.global.ui.unk_mapedge_y:insert("#",math.random(0,143))
df.global.ui.unk_mapedge_y:insert("#","0")
df.global.ui.unk_mapedge_y:insert("#",math.random(0,143))
df.global.ui.unk_mapedge_y:insert("#","143")
df.global.ui.unk_mapedge_z:insert("#",adv.pos.z)
df.global.ui.unk_mapedge_z:insert("#",adv.pos.z)
df.global.ui.map_edge.surface_x:insert("#",0)
df.global.ui.map_edge.surface_x:insert("#",math.random(0,143))
df.global.ui.map_edge.surface_y:insert("#",math.random(0,143))
df.global.ui.map_edge.surface_y:insert("#",0)

df.global.ui.map_edge.surface_x:insert("#",143)
df.global.ui.map_edge.surface_x:insert("#",math.random(0,143))
df.global.ui.map_edge.surface_y:insert("#",math.random(0,143))
df.global.ui.map_edge.surface_y:insert("#",143)
df.global.ui.map_edge.surface_z:insert("#",adv.pos.z)
df.global.ui.map_edge.surface_z:insert("#",adv.pos.z)
df.global.ui.map_edge.surface_z:insert("#",adv.pos.z)
df.global.ui.map_edge.surface_z:insert("#",adv.pos.z)
for _,Lay in pairs(df.global.ui.map_edge.layer_x) do
Lay:insert("#",math.random(0,143))
end
for _,Lay in pairs(df.global.ui.map_edge.layer_y) do
Lay:insert("#",math.random(0,143))
end
for _,Lay in pairs(df.global.ui.map_edge.layer_z) do
Lay:insert("#",adv.pos.z)
end
end
end
end
Tab={}
Tab2={}
for k,Lay2 in pairs(df.global.ui.map_edge.layer_z) do
for k2,Lay3 in pairs(df.global.ui.unk2a8c[0]) do
if k then break else
Tab:insert("#",k)
end
Tab2:insert("#",k2)
return Tab,Tab2
end
end
if #df.global.ui.map_edge.layer_z[0] == 0 then
print("map edge empty proceed to fill")
sigh()
 else
print("welp map edge currently full")
 end


if #ui.kitchen.item_types==0 then
ui.kitchen.item_types:insert("#",0)
ui.kitchen.item_subtypes:insert("#",0)
ui.kitchen.mat_types:insert("#",0)
ui.kitchen.mat_indices:insert("#",0)
ui.kitchen.exc_types:insert("#",0)
end
if #ui.unk_9==0 then
ui.unk_9:insert("#",0)
ui.unk_9:insert("#",0)
ui.unk_10:insert("#",0)
ui.unk_10:insert("#",0)
ui.unk_11:insert("#",0)
ui.unk_11:insert("#",0)
end
--fix training info
if h_ent.training_knowledge == nil then
    h_ent.training_knowledge={new=true}
end
df.global.gamemode=df.game_mode.DWARF
df.global.gametype=df.game_type.DWARF_MAIN
if df.global.gview.view.child.child==nil then df.global.gview.view.child=df.viewscreen_dwarfmodest:new()
df.global.gview.view.child.parent=df.global.gview.view
 end
 cleardesignate()
    print("Mode change complete.")
else
    local adv=dfhack.gui.getSelectedUnit(true)
    if adv then
        --swap units...
    end
    df.global.gamemode=df.game_mode.ADVENTURE
    df.global.gametype=df.game_type.ADVENTURE_MAIN
df.global.gview.view.child=df.viewscreen_dungeonmodest:new()
df.global.gview.view.child.parent=df.global.gview.view
    print("Mode change complete.")
end
ok so mapedge-z is used for when you're exploring the world and to prevent shifting to a site and noticing all the visitors are now underground due to being in a higher location than the last time you used the tofort(as tofort only fills in the map edge once and stops once it checks to see it's filled)
Code: ("mapedge-z.lua") [Select]
adv=df.global.world.units.active[0]
for _,Lay in pairs(df.global.ui.map_edge.layer_z) do
Lay=adv.pos.z
end
for _,Lay in pairs(df.global.ui.unk_mapedge_z) do
Lay=adv.pos.z
end
for _,Lay in pairs(df.global.ui.map_edge.surface_z) do
Lay=adv.pos.z
end
Spoiler: "v14" (click to show/hide)

ok so with this modified script of warmist's old tofort script you can probably safely* switch between adv mode and fort mode.
*so far from what I tested be advise to back up any saves when using any of my scripts. if I remember you probably shouldn't have advfort active while running this or it will throw a monkey wrench into the script and you need to re-run it again to get it to work properly.


hope folks have fun with this more than the tireless testing I had to go through.

edit: oh yeah there this one weird quirk with syndromes that freezes the timer that I noticed with bogeymen going from adv mode to fort mode it's temporary as I notice it reverting the bogeymen back when I swap back to adv mode and fast traveled but heads up if you use mods that rely on timers using this script


edit 2: ok so went back and edited the script after figuring out a way to do mapedges so the latest version has migrant and visitor support... kinda but it also kinda bloaty and set to camp size for the map edge so I don't know how well this would work on different map sizes.
oh  probably best to set up a fort and or camp at a location that is flat and even as I haven't sanity check for all zlevel surfaces
« Last Edit: September 03, 2022, 01:14:02 pm by Rumrusher »
Logged
I thought I would I had never hear my daughter's escapades from some boy...
DAMN YOU RUMRUSHER!!!!!!!!
"body swapping and YOU!"
Adventure in baby making!Adv Homes

Gimli-McGloinFace

  • Escaped Lunatic
    • View Profile
Re: DFHack 0.47.05-r6
« Reply #3203 on: September 01, 2022, 06:32:42 pm »

So I posted a suggestion to DF Suggestions for a feature I feel would help Military RP a bit, but now I'm thinking it might be possible to make a script for dfhack to do it myself. Is this possible and is there any tutorials on where to begin, I have no experience but it could make for a !fun! mega-project haha.
Logged

myk

  • Bay Watcher
    • View Profile
Re: DFHack 0.47.05-r6
« Reply #3204 on: September 01, 2022, 07:22:57 pm »

There is a lot of potential for DFHack to help with organizing and managing the military, but I'd be wary of starting something large this close to the steam release. Military mechanics might change and invalidate your work. However, of you can choose a small, focused project, we'd be happy to help you get it off the ground. You'll find more active DFHack discussion on the DFHack discord server.
Logged

Gimli-McGloinFace

  • Escaped Lunatic
    • View Profile
Re: DFHack 0.47.05-r6
« Reply #3205 on: September 02, 2022, 07:36:25 am »

TBH if any update invalidated my work I'd be happy I guess since my thing would be in the official version. I think my idea is quite simple but I've no idea in practice how difficult it would be to implement. I'll link the full suggestion here: http://www.bay12forums.com/smf/index.php?topic=180252.msg8402347#msg8402347

Basically I was imagining a macro of a sort (trying the built in macro system is hit or miss for this since I'm relying on when I press Q after the hotkey press it doesn't always start in the same place) that checks when a new month ends and goes through certain barracks of a specific name and resets sleeping positions.
Logged

myk

  • Bay Watcher
    • View Profile
Re: DFHack 0.47.05-r6
« Reply #3206 on: September 02, 2022, 12:27:36 pm »

If it's expressible with a macro, you'd probably be better off using a quickfort blueprint to make the changes, and run it on a timer to execute once per season (or on the first of the month of you want monthly).

You can write some light Lua code to detect when the season/month starts, but ideally you could modify the repeat utility to do the calculations for you.

So, the final form of your project could be a command that looks something like this:

Code: [Select]
repeat --name barracks-beds --onday 1 --timeUnits months --command [ quickfort run swap_barracks_beds.csv --cursor=26,54,137 ]
You just would need to put the right coordinates in the quickfort cursor param (or write some code to autodetect position based on a particularly named bed or something)

So, implementation:
1) modify repeat.lua to support the --onday parameter
2) represent your macro in a quickfort blueprint
3) either find the correct cursor position manually with the position command or come up with an autodetection strategy

Relevant docs:
Repeat: https://docs.dfhack.org/en/stable/docs/_auto/base.html#repeat
Quickfort (what you want is a "query" blueprint): https://docs.dfhack.org/en/stable/docs/_auto/base.html#quickfort
Also the blueprint guide: https://docs.dfhack.org/en/stable/docs/guides/quickfort-user-guide.html#creating-blueprints

If you don't want to be constrained by a particular barracks layout, you can dynamically generate a quickfort blueprint based on scanning the map and then apply the changes via the programmatic quickfort API:

Code: [Select]
local quickfort = reqscript('quickfort')
quickfort.apply_blueprint{mode='query', data=myblueprintdata}
« Last Edit: September 02, 2022, 12:44:44 pm by myk »
Logged

Gimli-McGloinFace

  • Escaped Lunatic
    • View Profile
Re: DFHack 0.47.05-r6
« Reply #3207 on: September 03, 2022, 09:26:17 am »

Thank you, had a good look at all that stuff, I don't know any LUA or programming so would learning python help me at all with this wee project?
If I manage to wrap my head around this well enough, (I don't know even where to begin, where to even write code, my experience is copy and paste to get things working on Ubuntu) my plan is then to make 16 quickfort query blueprints (4 for each barracks, 1 per squad set) then have it so that all 4 Squad-1s get sets on 01/01, 05/01, 09/01, then all 4 Squad-2s on 02/01, 06/01, 09/01.
If possible I was hoping to make a check thing for if there is a siege then reset the beds daily but after some !science! research the beds don't reset instantly as you go through the squads pressing Z twice on all the squad, the squad must be unassigned long enough for the next squad to take the bed or as soon as you reactivate the sleep status it defaults to who had it last. So without good luck and the odd dwarf sleeping on the floor or 160 all at once now and again this won't work how I imagine for sieges.
So I ripped up my ceiling last night and installed another floor of sleeping barracks just for siege time(empty at all other time). If possible is there a checker that activates when its siege time, depending on which month it is will activate the remaining squads on these barracks. I think it should be possible using the quickfort query blueprint, I would just need it to activate preferably when I set Squads to specific Alerts or when a siege is detected.

Logged

myk

  • Bay Watcher
    • View Profile
Re: DFHack 0.47.05-r6
« Reply #3208 on: September 03, 2022, 02:45:43 pm »

That all looks perfectly doable, but it will take a bit of scripting. Python, unfortunately, won't be of much help here. DFHack scripts are written in Lua. Lua is easier than most languages to learn. The Lua language guide is very approachable. Also, there are a lot of Lua scripts distributed with DFHack that you can look at for guidance and examples.

Here is a possible approach:
First, write the quickfort blueprints and manually apply them with gui/quickfort to test.
Then, once the blueprints are tested, start experimenting with Lua. Read the language guide, and then look at how some other scripts use DFHack to do similar things. autounsuspend.lua runs a daily check, which you could modify to detect the first day of the month and take the appropriate action. autounsuspend also runs another script, which you can modify to run quickfort to apply the correct blueprint for the current month. Siren.lua has some code that you can use for detecting sieges.

Make a new directory in your home directory for your script, and register the directory with DFHack by editing the dfhack-config/script-paths.txt file. For example, my script-paths.txt file has the following line: +/home/myk/src/dfhack-scripts. Then you can run your script by name from the DFHack terminal.
Logged

doublestrafe

  • Bay Watcher
  • [PONY_DEPENDENT]
    • View Profile
Re: DFHack 0.47.05-r6
« Reply #3209 on: September 04, 2022, 01:14:45 pm »

Is dfhack.world.cur_year_tick_advmode working as intended? Instead of giving the number of adventure mode ticks from the beginning of the year like dfhack.world.cur_year_tick, it's giving the number of ticks since the adventurer was created. There doesn't seem to be an obvious tick counter that can be used to find the current time in adventure mode.
Logged
Pages: 1 ... 212 213 [214] 215 216 ... 244