Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 338 339 [340] 341 342 ... 373

Author Topic: DFHack 0.34.11 r3  (Read 1443722 times)

Warmist

  • Bay Watcher
  • Master of unfinished jobs
    • View Profile
Re: DFHack 0.34.11 r3
« Reply #5085 on: January 09, 2014, 02:21:58 pm »

Looking at trying my hand with LUA and trying to do something better with Adventure Mode inventory management.  Is there anything in DFHack that can bootstrap me into getting a list of the adventurer's inventory?
I started a new thread: here

Cocoprimate

  • Bay Watcher
    • View Profile
Re: DFHack 0.34.11 r3
« Reply #5086 on: January 09, 2014, 11:49:14 pm »

Is there anyway I can use DFHack to play adventure mode with one of the dwarfs from my fortress?
Logged
The story of Aban Diamondtowns the Charms of Society, dwarf legend, and his descent into the depths. (SPOILER)
http://www.bay12forums.com/smf/index.php?topic=79229.0

Broken

  • Bay Watcher
    • View Profile
Re: DFHack 0.34.11 r3
« Reply #5087 on: January 11, 2014, 12:58:20 pm »

Is there anyway I can use DFHack to play adventure mode with one of the dwarfs from my fortress?

yes, there is, although not bug free by far.

1: Type Mode set
2: Type 2. This puts the game in arena mode.
3: Whitouth unpausing (In arena mode everybody is enemy of everybody) Select the creature you want. Dwarfs, FBs, even ghosts. Anything
    is fair game.
4: Type Mode set again
5: Type 1 to select adventurer mode.

Voila, your adventurer is free to roam the world.
Logged
Quote
In a hole in the ground there lived a dwarf. Not a nasty, dirty, wet hole, filled with the ends of worms and an oozy smell, nor yet a dry, bare, sandy hole with nothing in it to sit down on or to eat: it was a dwarf fortress, and that means magma.
Dwarf fortress: Tales of terror and inevitability

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Re: DFHack 0.34.11 r3
« Reply #5088 on: January 11, 2014, 02:16:33 pm »

Warmist did send me a new version of spawnunit for dfhack r4, which allows spawned units to use interactions and join military squads. I thought I better share it. :)

The entire implications of making the spawned units historical figures is not tested in the long run, so use with care.
Code: [Select]
--create unit at pointer or given location. Usage e.g. "spawnunit DWARF 0 Dwarfy"
 
--Made by warmist, but edited by Putnam for the dragon ball mod to be used in reactions
 
--note that it's extensible to any autosyndrome reaction to spawn anything due to this; to use in autosyndrome, you want \COMMAND spawnunit CREATURE caste_number name \LOCATION
 
args={...}
function getCaste(race_id,caste_id)
    local cr=df.creature_raw.find(race_id)
    return cr.caste[caste_id]
end
function genBodyModifier(body_app_mod)
    local a=math.random(0,#body_app_mod.ranges-2)
    return math.random(body_app_mod.ranges[a],body_app_mod.ranges[a+1])
end
function getBodySize(caste,time)
    --todo real body size...
    return caste.body_size_1[#caste.body_size_1-1] --returns last body size
end
function genAttribute(array)
    local a=math.random(0,#array-2)
    return math.random(array[a],array[a+1])
end
function norm()
    return math.sqrt((-2)*math.log(math.random()))*math.cos(2*math.pi*math.random())
end
function normalDistributed(mean,sigma)
    return mean+sigma*norm()
end
function clampedNormal(min,median,max)
    local val=normalDistributed(median,math.sqrt(max-min))
    if val<min then return min end
    if val>max then return max end
    return val
end
function makeSoul(unit,caste)
    local tmp_soul=df.unit_soul:new()
    tmp_soul.unit_id=unit.id
    tmp_soul.name:assign(unit.name)
    tmp_soul.race=unit.race
    tmp_soul.sex=unit.sex
    tmp_soul.caste=unit.caste
    --todo skills,preferences,traits.
    local attrs=caste.attributes
    for k,v in pairs(attrs.ment_att_range) do
       local max_percent=attrs.ment_att_cap_perc[k]/100
       local cvalue=genAttribute(v)
       tmp_soul.mental_attrs[k]={value=cvalue,max_value=cvalue*max_percent}
    end
    for k,v in pairs(tmp_soul.traits) do
        local min,mean,max
        min=caste.personality.a[k]
        mean=caste.personality.b[k]
        max=caste.personality.c[k]
        tmp_soul.traits[k]=clampedNormal(min,mean,max)
    end
    unit.status.souls:insert("#",tmp_soul)
    unit.status.current_soul=tmp_soul
end
function CreateUnit(race_id,caste_id)
    local race=df.creature_raw.find(race_id)
    if race==nil then error("Invalid race_id") end
    local caste=getCaste(race_id,caste_id)
    local unit=df.unit:new()
    unit.race=race_id
    unit.caste=caste_id
    unit.id=df.global.unit_next_id
    df.global.unit_next_id=df.global.unit_next_id+1
unit.relations.old_year=df.global.cur_year-5 -- everybody will be 15 years old
    if caste.misc.maxage_max==-1 then
        unit.relations.old_year=-1
    else
        unit.relations.old_year=df.global.cur_year+math.random(caste.misc.maxage_min,caste.misc.maxage_max)
    end
    unit.sex=caste.gender
local num_inter=#caste.body_info.interactions  -- new for interactions
unit.curse.anon_4:resize(num_inter) -- new for interactions
unit.curse.anon_5:resize(num_inter) -- new for interactions
    local body=unit.body
   
    body.body_plan=caste.body_info
    local body_part_count=#body.body_plan.body_parts
    local layer_count=#body.body_plan.layer_part
    --components
    unit.relations.birth_year=df.global.cur_year-15
    --unit.relations.birth_time=??
   
    --unit.relations.old_time=?? --TODO add normal age
    local cp=body.components
    cp.body_part_status:resize(body_part_count)
    cp.numbered_masks:resize(#body.body_plan.numbered_masks)
    for num,v in ipairs(body.body_plan.numbered_masks) do
        cp.numbered_masks[num]=v
    end
   
    cp.layer_status:resize(layer_count)
    cp.layer_wound_area:resize(layer_count)
    cp.layer_cut_fraction:resize(layer_count)
    cp.layer_dent_fraction:resize(layer_count)
    cp.layer_effect_fraction:resize(layer_count)
    local attrs=caste.attributes
    for k,v in pairs(attrs.phys_att_range) do
        local max_percent=attrs.phys_att_cap_perc[k]/100
        local cvalue=genAttribute(v)
        unit.body.physical_attrs[k]={value=cvalue,max_value=cvalue*max_percent}
        --unit.body.physical_attrs:insert(k,{new=true,max_value=genMaxAttribute(v),value=genAttribute(v)})
    end
 
    body.blood_max=getBodySize(caste,0) --TODO normal values
    body.blood_count=body.blood_max
    body.infection_level=0
    unit.status2.body_part_temperature:resize(body_part_count)
    for k,v in pairs(unit.status2.body_part_temperature) do
        unit.status2.body_part_temperature[k]={new=true,whole=10067,fraction=0}
       
    end
    --------------------
    local stuff=unit.enemy
    stuff.body_part_878:resize(body_part_count) -- all = 3
    stuff.body_part_888:resize(body_part_count) -- all = 3
    stuff.body_part_relsize:resize(body_part_count) -- all =0
 
    --TODO add correct sizes. (calculate from age)
    local size=caste.body_size_2[#caste.body_size_2-1]
    body.size_info.size_cur=size
    body.size_info.size_base=size
    body.size_info.area_cur=math.pow(size,0.666)
    body.size_info.area_base=math.pow(size,0.666)
    body.size_info.area_cur=math.pow(size*10000,0.333)
    body.size_info.area_base=math.pow(size*10000,0.333)
   
    stuff.were_race=race_id
    stuff.were_caste=caste_id
    stuff.normal_race=race_id
    stuff.normal_caste=caste_id
    stuff.body_part_8a8:resize(body_part_count) -- all = 1
    stuff.body_part_base_ins:resize(body_part_count)
    stuff.body_part_clothing_ins:resize(body_part_count)
    stuff.body_part_8d8:resize(body_part_count)
    unit.recuperation.healing_rate:resize(layer_count)
    --appearance
   
    local app=unit.appearance
    app.body_modifiers:resize(#caste.body_appearance_modifiers) --3
    for k,v in pairs(app.body_modifiers) do
        app.body_modifiers[k]=genBodyModifier(caste.body_appearance_modifiers[k])
    end
    app.bp_modifiers:resize(#caste.bp_appearance.modifier_idx) --0
    for k,v in pairs(app.bp_modifiers) do
        app.bp_modifiers[k]=genBodyModifier(caste.bp_appearance.modifiers[caste.bp_appearance.modifier_idx[k]])
    end
    --app.unk_4c8:resize(33)--33
    app.tissue_style:resize(#caste.bp_appearance.style_part_idx)
    app.tissue_style_civ_id:resize(#caste.bp_appearance.style_part_idx)
    app.tissue_style_id:resize(#caste.bp_appearance.style_part_idx)
    app.tissue_style_type:resize(#caste.bp_appearance.style_part_idx)
    app.tissue_length:resize(#caste.bp_appearance.style_part_idx)
    app.genes.appearance:resize(#caste.body_appearance_modifiers+#caste.bp_appearance.modifiers) --3
    app.genes.colors:resize(#caste.color_modifiers*2) --???
    app.colors:resize(#caste.color_modifiers)--3
   
    makeSoul(unit,caste)
   
    df.global.world.units.all:insert("#",unit)
    df.global.world.units.active:insert("#",unit)
    --todo set weapon bodypart
   
    local num_inter=#caste.body_info.interactions
    unit.curse.anon_5:resize(num_inter)
    return unit
end
function findRace(name)
    for k,v in pairs(df.global.world.raws.creatures.all) do
        if v.creature_id==name then
            return k
        end
    end
    qerror("Race:"..name.." not found!")
end

function createFigure(trgunit,he)
    local hf=df.historical_figure:new()
    hf.id=df.global.hist_figure_next_id
    hf.race=trgunit.race
    hf.caste=trgunit.caste
hf.profession = trgunit.profession
hf.sex = trgunit.sex
    df.global.hist_figure_next_id=df.global.hist_figure_next_id+1
hf.appeared_year = df.global.cur_year

hf.born_year = trgunit.relations.birth_year
hf.born_seconds = trgunit.relations.birth_time
hf.curse_year = trgunit.relations.curse_year
hf.curse_seconds = trgunit.relations.curse_time
hf.birth_year_bias = trgunit.relations.birth_year_bias
hf.birth_time_bias = trgunit.relations.birth_time_bias
hf.old_year = trgunit.relations.old_year
hf.old_seconds = trgunit.relations.old_time
hf.died_year = -1
hf.died_seconds = -1
hf.name:assign(trgunit.name)
hf.civ_id = trgunit.civ_id
hf.population_id = trgunit.population_id
hf.breed_id = -1
hf.unit_id = trgunit.id

    df.global.world.history.figures:insert("#",hf)

hf.info = df.historical_figure_info:new()
hf.info.unk_14 = df.historical_figure_info.T_unk_14:new() -- hf state?
--unk_14.region_id = -1; unk_14.beast_id = -1; unk_14.unk_14 = 0
hf.info.unk_14.unk_18 = -1; hf.info.unk_14.unk_1c = -1
-- set values that seem related to state and do event
--change_state(hf, dfg.ui.site_id, region_pos)


--lets skip skills for now
--local skills = df.historical_figure_info.T_skills:new() -- skills snap shot
-- ...
--info.skills = skills


he.histfig_ids:insert('#', hf.id)
he.hist_figures:insert('#', hf)

trgunit.flags1.important_historical_figure = true
trgunit.flags2.important_historical_figure = true
trgunit.hist_figure_id = hf.id
trgunit.hist_figure_id2 = hf.id
   
    hf.entity_links:insert("#",{new=df.histfig_entity_link_memberst,entity_id=trgunit.civ_id,link_strength=100})
    --add entity event
    local hf_event_id=df.global.hist_event_next_id
    df.global.hist_event_next_id=df.global.hist_event_next_id+1
    df.global.world.history.events:insert("#",{new=df.history_event_add_hf_entity_linkst,year=trgunit.relations.birth_year,
        seconds=trgunit.relations.birth_time,id=hf_event_id,civ=hf.civ_id,histfig=hf.id,link_type=0})
    return hf
end
function createNemesis(trgunit,civ_id)
    local id=df.global.nemesis_next_id
    local nem=df.nemesis_record:new()
local he=df.historical_entity.find(civ_id)
    nem.id=id
    nem.unit_id=trgunit.id
    nem.unit=trgunit
    nem.flags:resize(1)
    --not sure about these flags...
    nem.flags[4]=true
    nem.flags[5]=true
    nem.flags[6]=true
    nem.flags[7]=true
    nem.flags[8]=true
    nem.flags[9]=true
    --[[for k=4,8 do
        nem.flags[k]=true
    end]]
    df.global.world.nemesis.all:insert("#",nem)
    df.global.nemesis_next_id=id+1
    trgunit.general_refs:insert("#",{new=df.general_ref_is_nemesisst,nemesis_id=id})
    trgunit.flags1.important_historical_figure=true
   
    nem.save_file_id=he.save_file_id

    he.nemesis_ids:insert("#",id)
he.nemesis:insert("#",nem)
    nem.member_idx=he.next_member_idx
    he.next_member_idx=he.next_member_idx+1
    --[[ local gen=df.global.world.worldgen
    gen.next_unit_chunk_id
    gen.next_unit_chunk_offset
    ]]
    nem.figure=createFigure(trgunit,he)
end

function PlaceUnit(race,caste,name,position,civ_id)



    local pos=position or copyall(df.global.cursor)
    if pos.x==-30000 then
        qerror("Point your pointy thing somewhere")
    end
    race=findRace(race)


    local u=CreateUnit(race,tonumber(caste) or 0)
    u.pos:assign(pos)

    if name then
        u.name.first_name=name
        u.name.has_name=true
    end
    u.civ_id=civ_id or df.global.ui.civ_id

   
    local desig,ocupan=dfhack.maps.getTileFlags(pos)
    if ocupan.unit then
        ocupan.unit_grounded=true
        u.flags1.on_ground=true
    else
        ocupan.unit=true
    end
   
    if df.historical_entity.find(u.civ_id) ~= nil  then
        createNemesis(u,u.civ_id)
    end
end

local argPos
 
if #args>3 then
    argPos={}
    argPos.x=args[4]
    argPos.y=args[5]
    argPos.z=args[6]
end
 
PlaceUnit(args[1],args[2],args[3],argPos) --Creature (ID), caste (number), name, x,y,z , civ_id(-1 for enemy, optional) for spawn.
Logged
::: ☼Meph Tileset☼☼Map Tileset☼- 32x graphic sets with TWBT :::
::: ☼MASTERWORK DF☼ - A comprehensive mod pack now on Patreon - 250.000+ downloads and counting :::
::: WorldBicyclist.com - Follow my bike tours around the world - 148 countries visited :::

Sutremaine

  • Bay Watcher
  • [ETHIC:ATROCITY: PERSONAL_MATTER]
    • View Profile
Re: DFHack 0.34.11 r3
« Reply #5089 on: January 11, 2014, 04:56:23 pm »

How do I find a dwarf's cleanliness value?
Logged
I am trying to make chickens lay bees as eggs. So far it only produces a single "Tame Small Creature" when a hen lays bees.
Honestly at the time, I didn't see what could go wrong with crowding 80 military Dwarves into a small room with a necromancer for the purpose of making bacon.

Urist Da Vinci

  • Bay Watcher
  • [NATURAL_SKILL: ENGINEER:4]
    • View Profile
Re: DFHack 0.34.11 r3
« Reply #5090 on: January 11, 2014, 09:47:35 pm »

1. two ways possible: simple move (boring), making them projectiles, aka throwing them (that should be fun)
...

1. Would making them projectiles really be possible? That would open a whole new set of spell possibilities.
...
I know I have said this before, but I REALLY need to learn DFHack, right now I am reliant on all of you. Any tips on how to get started? Right now I am just looking over all the different scripts that have been written, but it's not really sinking in.
1. i could type it out (need that for one of my own things) also some testing needed to make sure how this would work
...

A few pages ago, I posted a "cause death" script in this thread. One of the deaths was a script that turns the creature into a projectile and slams it into the floor at high speed, exploding it into chunks. You could just use different x,y,z velocities to fling the creature in another direction.  :)

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Re: DFHack 0.34.11 r3
« Reply #5091 on: January 12, 2014, 02:17:26 am »

Urist Da Vinci: I didnt even see that. Nice, I might be able to use it for warlock spells. :)

Wait a second. Wouldnt the warmist work on powered workshop and that gravity script allow for a new trap-workshop? Unit walk on a workshop tile, gets launched into the air?

You could even make elevators that way, using timed hatches.
« Last Edit: January 12, 2014, 03:03:15 am by Meph »
Logged
::: ☼Meph Tileset☼☼Map Tileset☼- 32x graphic sets with TWBT :::
::: ☼MASTERWORK DF☼ - A comprehensive mod pack now on Patreon - 250.000+ downloads and counting :::
::: WorldBicyclist.com - Follow my bike tours around the world - 148 countries visited :::

Mr Space Cat

  • Bay Watcher
  • inactive, changed accounts. sig for info
    • View Profile
Re: DFHack 0.34.11 r3
« Reply #5092 on: January 12, 2014, 05:30:16 pm »

Switching from Masterwork DF to Accelerated DF+Modest Mod. I don't know if Accelerated DF's DFHack includes the fix for the growth bug with fortress-born creatures. Upon running DF, DFHack doesn't enable any "tweak" that sounds like it fixes growth.

How would I go about adding the fix to DFHack? I'm really really really unfamiliar with DFHack.
Logged
Made a new account that I use instead of this one. Don't message this one, I'm probably not gonna use it.

New account: Spehss _

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Re: DFHack 0.34.11 r3
« Reply #5093 on: January 12, 2014, 05:35:19 pm »

Go to hack/scripts/growthbug.rb, copy it into the hack/scripts folder in the Accelerated mod, open dfhack.init in your Dwarf Fortress folder, add the new line 'fix/growthbug enable' without the '', and you are all set. Thats it, everything else is done automatically.
Logged
::: ☼Meph Tileset☼☼Map Tileset☼- 32x graphic sets with TWBT :::
::: ☼MASTERWORK DF☼ - A comprehensive mod pack now on Patreon - 250.000+ downloads and counting :::
::: WorldBicyclist.com - Follow my bike tours around the world - 148 countries visited :::

Mr Space Cat

  • Bay Watcher
  • inactive, changed accounts. sig for info
    • View Profile
Re: DFHack 0.34.11 r3
« Reply #5094 on: January 12, 2014, 06:38:04 pm »

Got it working, thanks. I didn't even think of just copying the script from Masterwork's files into Accelerated.
Logged
Made a new account that I use instead of this one. Don't message this one, I'm probably not gonna use it.

New account: Spehss _

Roses

  • Bay Watcher
    • View Profile
Re: DFHack 0.34.11 r3
« Reply #5095 on: January 13, 2014, 12:08:15 am »

Trying my hand at DFHack and just have a little question.

I would like a script that checks for all units in a range of area on the map and was wondering if there was any easy or clever way of doing it? I think it should work by just using dfhack.maps.getTileFlags(x,y,z) and then check which tiles are occupied and get the unit ID from there, but was just wondering if the more experienced people might have a better idea before I try this method.

Also, is it possible to check a creatures classes and syndrome classes within DFHack?

EDIT: Also also, for dfhack.timeout(time,mode,callback), is the callback treated as a command line input or something else? (Am I write in thinking I can write a script to change a flag on a unit and then a specific amount of time later I can change the flag back?)
« Last Edit: January 13, 2014, 12:29:04 pm by Roses »
Logged

Sutremaine

  • Bay Watcher
  • [ETHIC:ATROCITY: PERSONAL_MATTER]
    • View Profile
Re: DFHack 0.34.11 r3
« Reply #5096 on: January 13, 2014, 01:13:09 pm »

Where can you find a list of all the counters and things used by DFHack? I'm trying to write a script that turns complex and overlapping fractures into simple ones, but I don't know where to start.
Logged
I am trying to make chickens lay bees as eggs. So far it only produces a single "Tame Small Creature" when a hen lays bees.
Honestly at the time, I didn't see what could go wrong with crowding 80 military Dwarves into a small room with a necromancer for the purpose of making bacon.

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: DFHack 0.34.11 r3
« Reply #5097 on: January 13, 2014, 02:35:07 pm »

You mean this?  df-structures

I find it difficult to read it sometimes, so I oftentimes just printall(something) within the Lua interface to see what is available and defined.  Some things you'll want or need the link above for though, like enums.

And, unless it's changed recently, I think a lot of the healthcare stuff was still undocumented.  If that's still true, you may not be able to do what you want without figuring out what those fields are yourself.
Logged
Through pain, I find wisdom.

Roses

  • Bay Watcher
    • View Profile
Re: DFHack 0.34.11 r3
« Reply #5098 on: January 13, 2014, 04:08:14 pm »

Here is a sample spell that I put together from looking at other peoples scripts. It casts a cyclone that tosses around all creatures within a specified radius with a specified force. Usage is [SYN_CLASS:\COMMAND][SYN_CLASS:cyclone][SYN_CLASS:\UNIT_ID][SYN_CLASS:radius][SYN_CLASS:strength] where radius and strength are any positive integer. The actual strength of the wind is based on the size of the creature, with small creatures being tossed around like mad and larger creatures hardly moving.

I am sure there are some bugs with it, but it seemed to work fine in adventure mode testing. I am planning to release many of the new things I am doing all together, but figured I would release my first just to show my appreciation for everyones help.

Spoiler: cyclone.lua (click to show/hide)
« Last Edit: January 13, 2014, 07:15:12 pm by Roses »
Logged

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Re: DFHack 0.34.11 r3
« Reply #5099 on: January 13, 2014, 07:19:05 pm »

Very much looking forward to it. :) Did you manage to get your water/magma-source spells to work?
Logged
::: ☼Meph Tileset☼☼Map Tileset☼- 32x graphic sets with TWBT :::
::: ☼MASTERWORK DF☼ - A comprehensive mod pack now on Patreon - 250.000+ downloads and counting :::
::: WorldBicyclist.com - Follow my bike tours around the world - 148 countries visited :::
Pages: 1 ... 338 339 [340] 341 342 ... 373