This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--a library for creation and modification of jobs | |
--TODO: workshop jobs/reactions and building specific jobs in general | |
local _ENV = mkmodule('hack.scripts.jobs') | |
local buildings = require('dfhack.buildings') | |
local tile_attrs = df.tiletype.attrs | |
--[=[ helper functions ]=] | |
local function findRef(vector,ref_type) | |
for k,v in ipairs(vector) do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<struct-type type-name='written_content' | |
instance-vector='$global.world.written_contents.all' key-field='id'> | |
<int32_t name='id'/> | |
<int32_t comment='pages before?'/> | |
<int32_t name='pages'/> | |
<stl-vector name='general_refs' pointer-type='general_ref'/> | |
<stl-vector type-name='int32_t'/> | |
<int32_t/> | |
<int32_t/> | |
<int32_t/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local wc=df.global.world.written_contents.all | |
local function alloc_wc_id() | |
local ret=df.global.written_content_next_id | |
df.global.written_content_next_id=df.global.written_content_next_id+1 | |
return ret | |
end | |
local function create_wc(hist_events) | |
local ret=df.written_content:new() | |
df.global.world.written_contents.all:insert("#",ret) | |
for k,v in ipairs(hist_events) do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local map={[[ | |
XXXXX | |
XZZZX | |
XZXZX | |
XZZZX | |
XXXXX | |
]], | |
[[ | |
YYY |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--scroll down to the end for configuration | |
ret={...} | |
ret=ret[1] | |
ret.materials={} | |
ret.buildings={} | |
ret.special={} | |
ret.items={} | |
ret.creatures={} | |
for k,v in pairs(ret) do | |
_ENV[k]=v |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local dwarf = 465 | |
local mass=15 | |
function count_alive( ) | |
local ret=0 | |
for k,v in ipairs(df.global.world.units.active) do | |
if not v.flags1.dead then | |
ret=ret+1 | |
end | |
end | |
return ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for _,dwarf in ipairs(df.global.world.units.active) do | |
if dfhack.units.isCitizen(dwarf) then | |
print(dfhack.TranslateName(dwarf.name)) | |
for _,pref in ipairs(dwarf.status.current_soul.preferences) do | |
printall(pref) | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local utils=require 'utils' | |
function add_to_group(entity,nemesis) | |
local hfig=nemesis.figure | |
hfig.entity_links:insert("#",{new=df.histfig_entity_link_memberst,entity_id=entity.id,link_strength=100}) | |
entity.nemesis:insert("#",nemesis) | |
utils.insert_sorted(entity.histfig_ids,hfig.id) | |
utils.insert_sorted(entity.nemesis_ids,nemesis.id) | |
entity.hist_figures:insert("#",hfig) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function add_xp(unit,skill_id,xp) | |
--get skill entry | |
local skills=unit.status.current_soul.skills | |
local s_entry=utils.binsearch(skills,skill_id,'id') | |
--does not exist so create skill entry | |
if not s_entry then | |
s_entry=df.unit_skill:new() | |
s_entry.id = skill_id | |
utils.insert_sorted(skills,s_entry,'id') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I had this idea of multirace forts for a while. After some digging found this nice pattern: all reads of global race were very simple "movsx reg,[ptr]" or "mov reg,[ptr]". Here pointer is constant (and known from our xmls) and register is one of x86 registers. So idea was to find ALL the places were it happens, and find next compare to units race (again, could be automatically deduced from structures to be 0x8c from start of unit) and replace with "return true" assembly variant. | |
That ofcourse made df burry all the birds as members of your race and do other strange stuff (no canibalism! that cow is also your friend) but let the elves and humans and etc perform jobs. Next step is do something smarter. | |
Next iteration had a table of allowed races (e.g. Dwarf, Human,Elf,Troll) and only those races would be concidered "smart enough to perform jobs", so each "cmp <unit_race>,<global_race>" got turned into "call [patched code]". | |
Now we have a problem. What is original unit race? The original code is "cmp <some_reg_th |
OlderNewer