Skip to content

Instantly share code, notes, and snippets.

View warmist's full-sized avatar
💭
Making a game or sth

Warmist warmist

💭
Making a game or sth
View GitHub Profile
@warmist
warmist / jobs.lua
Created February 25, 2014 20:35
a jobs module for creating/assigning jobs
--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
<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/>
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
@warmist
warmist / constructor.lua
Created April 23, 2014 14:46
Not finished, do not use in releases...
local map={[[
XXXXX
XZZZX
XZXZX
XZZZX
XXXXX
]],
[[
YYY
--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
@warmist
warmist / fun.lua
Created July 5, 2014 08:07
Arena testing thingy.
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
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
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
@warmist
warmist / add_xp.lua
Created January 18, 2015 15:42
add_xp
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')
@warmist
warmist / info.txt
Created January 26, 2015 16:52
Info about friendship. Or how it is crazy stuff that nobody does...
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