Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 210 211 [212] 213 214 ... 373

Author Topic: DFHack 0.34.11 r3  (Read 1458155 times)

yovannyX

  • Bay Watcher
    • View Profile
Re: DFHack 0.34.11 r2
« Reply #3165 on: March 10, 2013, 09:49:11 am »

hello
i really like df hack, it kinda makes the game playable for me
im playing with the masterworks mod, and i notice it doesnt have many scripts.
is there a way to find all scripts in one place?
also, i wanna know if theres a script for:
-making pets have babies
-making said babies grow up fast
hope someone can help me
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: DFHack 0.34.11 r2
« Reply #3166 on: March 10, 2013, 01:28:38 pm »

Define "doesn't have many scripts".

EDIT: agh, the lua API doesn't have any of the maps functions I need to not have fucked up teleporting!

It has:

ensureTileBlock
getGlobalInitFeature
isValidTilePos
getTileBiomeRgn
getSize
spawnFlow
getTileSize
getRegionBiome
canWalkBetween
getTileBlock
getLocalInitFeature
enableBlockUpdates
getBlock
« Last Edit: March 10, 2013, 02:41:55 pm by Putnam »
Logged

Quietust

  • Bay Watcher
  • Does not suffer fools gladly
    • View Profile
    • QMT Productions
Re: DFHack 0.34.11 r2
« Reply #3167 on: March 10, 2013, 03:36:45 pm »

If you want to teleport units without leaving glitches in the occupancy flags, the only function you really need is getBlock - from there, you can index into the 'occupancy' array and set/clear the appropriate flags.
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.

sayke

  • Bay Watcher
    • View Profile
Re: DFHack 0.34.11 r2
« Reply #3168 on: March 10, 2013, 03:46:44 pm »

Hey all -

I was wondering about the current status of the effort on DFHack r3! It sounded like various folks were working on a whole range of fantastically powerful features, but I haven't heard anything for a while!

I just wanted to thank everybody for their hard work, and wish all concerned all the best of luck as they keep clanking away on this - I know it's tricky stuff and I wish I was a really good programmer so I could help out =D Cheers!
Logged
i play the incredibly awesome Masterwork DF mod - a wonderful blend of simplicity and new features that actually improves FPS!

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: DFHack 0.34.11 r2
« Reply #3169 on: March 10, 2013, 04:15:27 pm »

If you want to teleport units without leaving glitches in the occupancy flags, the only function you really need is getBlock - from there, you can index into the 'occupancy' array and set/clear the appropriate flags.

Okay, good!

yovannyX

  • Bay Watcher
    • View Profile
Re: DFHack 0.34.11 r2
« Reply #3170 on: March 10, 2013, 05:52:15 pm »

oh, nevermind my original comment, i figured it out how to acceses de scripts, and added a few, hoppefully i did it correctly

i have one little question,

when i use dfusion's embark and friendship for my world,to the migrants will appear randomized already or i have to enable something in dfusion?
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: DFHack 0.34.11 r2
« Reply #3171 on: March 10, 2013, 06:55:55 pm »

Bah. I'm trying to implement a version of this code that I wrote that will work automatically (as opposed to requiring the user to activate the script in the console):

Code: [Select]
-- Checks if creature has an item equipped with a special syndrome and applies item's syndrome if it is.

local function getMaterial(item)
if item.item.mat_type~=0 then return nil end --Can't find out how to get leather and such out, which is annoying but definitely not crippling, unless you want magic dragon scale'
return df.global.world.raws.inorganics[item.item.mat_index]
end

local function getSyndrome(material)
if #material.material.syndrome>0 then return material.material.syndrome[0] end
return nil
end

local function syndromeIsDfHackSyndrome(syndrome)
for k,v in ipairs(syndrome.syn_class) do
if v.value=="DFHACK_ITEM_SYNDROME" then
return true
end
end
return false
end

local function assignSyndrome(target,syn_id) --taken straight from here, but edited so I can understand it better: https://gist.github.com/warmist/4061959/
    if target==nil then
        qerror("Not a valid target") --this probably won't happen :V
    end
    local newSyndrome=df.unit_syndrome:new()
    local target_syndrome=df.syndrome.find(syn_id)
    newSyndrome.type=target_syndrome.id
    --newSyndrome.year=
    --newSyndrome.year_time=
    newSyndrome.ticks=1
    newSyndrome.unk1=1
    for k,v in ipairs(target_syndrome.ce) do
        local sympt=df.unit_syndrome.T_symptoms:new()
        sympt.ticks=1
        sympt.flags=2
        newSyndrome.symptoms:insert("#",sympt)
    end
    target.syndromes.active:insert("#",newSyndrome)
end

local function findItems()
for _uid,unit in ipairs(df.global.world.units.all) do
for _,item in ipairs(unit.inventory) do
if getMaterial(item)~=nil then
local syndrome = getSyndrome(getMaterial(item))
if syndromeIsDfHackSyndrome(syndrome) then assignSyndrome(unit,syndrome.id) end
end
end
end
end

findItems()

I'm mainly having build issues with my C++ code, but I'm 90% sure my cobbled-together C++ code won't build anyway, especially since the code relies entirely on 1. Functions I don't know how to use and 2. functions I'm not sure exist:

Code: [Select]
#include "PluginManager.h"
#include "Export.h"
#include "DataDefs.h"
#include "Core.h"

#include "modules/EventManager.h"

#include "df/creature_raw.h"
#include "df/global_objects.h"
#include "df/item.h"
#include "df/syndrome.h"
#include "df/unit_syndrome.h"
#include "df/ui.h"
#include "df/unit.h"
#include "df/general_ref.h"
#include "df/general_ref_type.h"

#include <string>
#include <vector>
#include <unordered_set>
#include <unordered_map>

using namespace std;
using namespace DFHack;

/*Using this plugin:

Armor with a material that has [SYN_CLASS:DFHACK_ITEM_SYNDROME] will affect the person who wears it.
For example:
//////////////////////////////////////////////
//Simple example syndrome that will cause the equipper to take half damage
    [SYNDROME]
        [SYN_CLASS:DFHACK_ITEM_SYNDROME]
        [CE_MATERIAL_FORCE_MULTIPLIER:MAT_MULT:NONE:NONE:1:2]
//////////////////////////////////////////////
*/

//Code is mostly taken from autoSyndrome.

bool enabled = true;

command_result itemSyndrome(color_ostream& out, vector<string>& parameters);

DFhackCExport command_result plugin_init(color_ostream& out, vector<PluginCommand> &commands) {
    commands.push_back(PluginCommand("itemSyndrome", "Automatically give units syndromes when they wear certain materials on armors specified in the raws\n", &itemSyndrome, false,
        "itemSyndrome:\n"
        "  itemSyndrome 0 //disable\n"
        "  itemSyndrome 1 //enable\n"
        "  itemSyndrome disable //disable\n"
        "  itemSyndrome enable //enable\n"
        "\n"
        "itemSyndrome looks for units wearing armor or holding weapons that are made of a material with a syndrome that has a certain SYN_CLASS, causing the creature who equips that item to gain the syndrome.\n"
        "\n"
        "Requirement:\n"
        "  1) The armor worn must have a material that has a syndrome with the class \"DFHACK_ARMOR_SYNDROME\"\n"
        "\n"
        "When this conditions are met, the unit wearing the armor will become afflicted with all applicable syndromes associated with the material of the armor, or stones. It should correctly check for whether the creature or caste is affected or immune, and it should also correctly account for affected and immune creature classes.\n"
        ));
    return CR_OK;
}

DFHACK_PLUGIN("itemSyndrome");

DFhackCExport command_result plugin_shutdown ( color_ostream &out )
{
    enabled = false;
    return CR_OK;
}

DFhackCExport command_result plugin_onupdate(color_ostream &out) //Copy+pasted from some of Falconne's code because I'm not that good at this :V
{
    if (!enabled)
        return CR_OK;

    // Every 150 frames check for syndromes
    static unsigned cnt = 0;
    if ((++cnt % 150) != 0 && first_update_done)
        return CR_OK;
    if (!first_update_done)
    {
        last_frame_count = world->frame_counter;
        run_script(utility/itemsyndrome)
        first_update_done = true;
    }

    return CR_OK;
}

The lua code works for a fact; the C++ code--again, 20% build problems, 80% "I have no idea what I'm doing".
« Last Edit: March 10, 2013, 06:58:20 pm by Putnam »
Logged

falconne

  • Bay Watcher
    • View Profile
Re: DFHack 0.34.11 r2
« Reply #3172 on: March 11, 2013, 12:16:23 am »

I'm mainly having build issues with my C++ code, but I'm 90% sure my cobbled-together C++ code won't build anyway, especially since the code relies entirely on 1. Functions I don't know how to use and 2. functions I'm not sure exist:

I can't speak for the build errors yet as I'm at work and can't compile that to see, but I can suggest a change to the onupdate function you got from my code, to make it work better for what what you need:

Code: [Select]
DFhackCExport command_result plugin_onupdate (color_ostream &out)
{
    if(!Maps::IsValid())
        return CR_OK;

    static decltype(world->frame_counter) last_frame_count = 0;
   
    bool is_paused = Core::getInstance().getWorld()->ReadPauseState();
    if (is_paused)
        return CR_OK;

    if (world->frame_counter - last_frame_count < 150)
        return CR_OK;

    last_frame_count = world->frame_counter;

    ... DO STUFF ...

    return CR_OK;
}
Logged
Utility plugins for DFHack, for improving Dwarf Fortress' user interface.

Laggy

  • Bay Watcher
    • View Profile
Re: DFHack 0.34.11 r2
« Reply #3173 on: March 11, 2013, 01:27:55 am »

Is there some kind of reference somewhere for the data structures available to lua from the game?  Looking through a few example scripts, I saw things like df.global.world.units.all for a table with all the units in it.  But where did it come from?!  I can't seem to find any reference lists anywhere :(
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: DFHack 0.34.11 r2
« Reply #3174 on: March 11, 2013, 02:30:30 am »

library/xml in the github.

I mostly use printall(table), though...

Warmist

  • Bay Watcher
  • Master of unfinished jobs
    • View Profile
Re: DFHack 0.34.11 r2
« Reply #3175 on: March 11, 2013, 05:24:57 am »

@Putnam: i just remembered that there is onupdate in lua (or similar thing anyway...):
https://github.com/warmist/dfhack/blob/master/Lua%20API.rst#id30
Namely: dfhack.timeout(time,mode,callback). Setting it up like: dfhack.timeout(150,'ticks',callback) would work. Also if combined with:
Code: [Select]
dfhack.onStateChange.foo = function(code)
if code==SC_MAP_LOADED then --not sure if SC_MAP_LOADED or SC_WORLD_LOADED
dfhack.timeout(150,'ticks',callback) --disables if map/world is unloaded automatically
end
--and then in callback

function callback()
-- real stuff that does whatever
--
--
dfhack.timeout(150,'ticks',callback)
end

Laggy

  • Bay Watcher
    • View Profile
Re: DFHack 0.34.11 r2
« Reply #3176 on: March 11, 2013, 11:59:50 am »

library/xml in the github.

I mostly use printall(table), though...
Thanks!  I had already checked out the git repository (yea yea, I'm used to SVN, its called checkout there :P) but the library/xml folder wasn't populated.  I didn't realized I had to run a sub-module Update as well.

Also, after a bit of searching, i found the built in lua-interpreter.  That definitely makes things easier for playing around!  (fun fact:  for _,item in ipairs(df.global.world.items.all) do printall(item) end ---- in a fort with 50k items takes a while!)
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: DFHack 0.34.11 r2
« Reply #3177 on: March 11, 2013, 12:02:25 pm »

Back before I removed all my god tiers, I did a printall for the raws for every creature in the game. It took two minutes :P

Laggy

  • Bay Watcher
    • View Profile
Re: DFHack 0.34.11 r2
« Reply #3178 on: March 11, 2013, 12:14:19 pm »

Only 2?  Weak!  That printall up there took at least 5.  Maybe more, I didn't actually time it.
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: DFHack 0.34.11 r2
« Reply #3179 on: March 11, 2013, 12:46:15 pm »

Is there any way to check if a syndrome that a unit is affected by is the same as one on a material? They're stored really damn differently. If not, it'd be pretty easy to just make modders have their syndrome end at 150.
Pages: 1 ... 210 211 [212] 213 214 ... 373