diff --git a/plugins/lua/dfusion/adv_tools.lua b/plugins/lua/dfusion/adv_tools.lua index 4440a4b2f..31e83b234 100644 --- a/plugins/lua/dfusion/adv_tools.lua +++ b/plugins/lua/dfusion/adv_tools.lua @@ -48,5 +48,69 @@ function Reincarnate(trg_unit,swap_soul) --only for adventurer i guess end end menu:add("Reincarnate",Reincarnate,{{df.unit,"optional"}})-- bool, optional - -return _ENV \ No newline at end of file +function change_adv(unit,nemesis) + if nemesis==nil then + nemesis=true --default value is nemesis switch too. + end + if unit==nil then + unit=getCreatureAtPointer() + end + if unit==nil then + error("Invalid unit!") + end + local other=df.global.world.units.active + local unit_indx + for k,v in pairs(other) do + if v==unit then + unit_indx=k + break + end + end + if unit_indx==nil then + error("Unit not found in array?!") --should not happen + end + other[unit_indx]=other[0] + other[0]=unit + if nemesis then --basicly copied from advtools plugin... + local nem=getNemesis(unit) + local other_nem=getNemesis(other[unit_indx]) + if other_nem then + other_nem.flags[0]=false + other_nem.flags[1]=true + end + if nem then + nem.flags[0]=true + nem.flags[2]=true + for k,v in pairs(df.global.world.nemesis.all) do + if v.id==nem.id then + df.global.ui_advmode.player_id=k + end + end + else + error("Current unit does not have nemesis record, further working not guaranteed") + end + end +end +menu:add("Change adventurer",change_adv) +function log_pos() + local adv=df.global.world.units.active[0] + + local wmap=df.global.world.map + local sub_pos={x=adv.pos.x,y=adv.pos.y,z=adv.pos.z} + local region_pos={x=wmap.region_x,y=wmap.region_y,z=wmap.region_z} + local pos={x=sub_pos.x+region_pos.x*48,y=sub_pos.y+region_pos.y*48,z=sub_pos.z+region_pos.z} + local state + if adv.flags1.dead then + state="dead" + else + state="live n kicking" + end + local message=string.format("%s %s at pos={%d,%d,%d} region={%d,%d,%d}",dfhack.TranslateName(adv.name),state,pos.x,pos.y,pos.z,region_pos.x,region_pos.y,region_pos.z) + print(message) + local path="deaths_"..df.global.world.cur_savegame.save_dir..".txt" + local f=io.open(path,"a") + f:write(message) + f:close() +end +menu:add("Log adventurers position",log_pos) +return _ENV diff --git a/plugins/lua/dfusion/tools.lua b/plugins/lua/dfusion/tools.lua new file mode 100644 index 000000000..9ddfb8e45 --- /dev/null +++ b/plugins/lua/dfusion/tools.lua @@ -0,0 +1,164 @@ +local _ENV = mkmodule('plugins.dfusion.tools') +local dfu=require("plugins.dfusion") +local ms=require "memscan" +menu=dfu.SimpleMenu() +function setrace(name) --TODO FIX + RaceTable=BuildNameTable() + print("Your current race is:"..GetRaceToken(df.global.ui.race_id)) + local id + if name == nil then + print("Type new race's token name in full caps (q to quit):") + repeat + entry=getline() + if entry=="q" then + return + end + id=RaceTable[entry] + until id~=nil + else + id=RaceTable[name] + if id==nil then + error("Name not found!") + end + end + df.global.ui.race_id=id +end +menu:add("Set current race",setrace) +function GiveSentience(names) --TODO FIX + RaceTable=RaceTable or BuildNameTable() --slow.If loaded don't load again + if names ==nil then + ids={} + print("Type race's token name in full caps to give sentience to:") + repeat + entry=getline() + id=RaceTable[entry] + until id~=nil + table.insert(ids,id) + else + ids={} + for _,name in pairs(names) do + id=RaceTable[name] + table.insert(ids,id) + end + end + for _,id in pairs(ids) do + local races=df.global.world.raws.creatures.all + + local castes=races[id].caste + print(string.format("Caste count:%i",castes.size)) + for i =0,#castes-1 do + + print("Caste name:"..castes[i].caste_id.."...") + + local flags=castes[i].flags + --print(string.format("%x",flagoffset)) + if flags.CAN_SPEAK then + print("\tis sentient.") + else + print("\tnon sentient. Allocating IQ...") + flags.CAN_SPEAK=true + end + end + end +end +menu:add("Give Sentience",GiveSentience) +function MakeFollow(unit,trgunit) + if unit == nil then + unit=dfhack.gui.getSelectedUnit() + end + if unit== nil then + error("Invalid creature") + end + if trgunit==nil then + trgunit=df.global.world.units.active[0] + end + unit.relations.group_leader_id=trgunit.id + local u_nem=getNemesis(unit) + local t_nem=getNemesis(trgunit) + if u_nem then + u_nem.group_leader_id=t_nem.id + end + if t_nem and u_nem then + t_nem.companions:insert(#t_nem.companions,u_nem.id) + end +end +menu:add("Make creature follow",MakeFollow) +function project(unit,trg) --TODO add to menu? + if unit==nil then + unit=getCreatureAtPointer() + end + + if unit==nil then + error("Failed to project unit. Unit not selected/valid") + end + -- todo: add projectile to world, point to unit, add flag to unit, add gen-ref to projectile. + local p=df.proj_unitst:new() + local startpos={x=unit.pos.x,y=unit.pos.y,z=unit.pos.z} + p.origin_pos=startpos + p.target_pos=trg + p.cur_pos=startpos + p.prev_pos=startpos + p.unit=unit + --- wtf stuff + p.unk14=100 + p.unk16=-1 + p.unk23=-1 + p.fall_delay=5 + p.fall_counter=5 + p.collided=true + -- end wtf + local citem=df.global.world.proj_list + local maxid=1 + local newlink=df.proj_list_link:new() + newlink.item=p + while citem.item~= nil do + if citem.item.id>maxid then maxid=citem.item.id end + if citem.next ~= nil then + citem=citem.next + else + break + end + end + p.id=maxid+1 + newlink.prev=citem + citem.next=newlink + local proj_ref=df.general_ref_projectile:new() + proj_ref.projectile_id=p.id + unit.refs:insert(#unit.refs,proj_ref) + unit.flags1.projectile=true +end +function empregnate(unit) + if unit==nil then + unit=getSelectedUnit() + end + + if unit==nil then + unit=getCreatureAtPos(getxyz()) + end + + if unit==nil then + error("Failed to empregnate. Unit not selected/valid") + end + if unit.curse then + unit.curse.add_tags2.STERILE=false + end + local genes = unit.appearance.genes + if unit.relations.pregnancy_ptr == nil then + print("creating preg ptr.") + if false then + print(string.format("%x %x",df.sizeof(unit.relations:_field("pregnancy_ptr")))) + return + end + unit.relations.pregnancy_ptr = { new = true, assign = genes } + end + local ngenes = unit.relations.pregnancy_ptr + if #ngenes.appearance ~= #genes.appearance or #ngenes.colors ~= #genes.colors then + print("Array sizes incorrect, fixing.") + ngenes:assign(genes); + end + print("Setting preg timer.") + unit.relations.pregnancy_timer=10 + unit.relations.pregnancy_mystery=1 +end +menu:add("Empregnate",empregnate) +return _ENV \ No newline at end of file diff --git a/scripts/dfusion.lua b/scripts/dfusion.lua index 4fee0438e..79f9fd953 100644 --- a/scripts/dfusion.lua +++ b/scripts/dfusion.lua @@ -4,8 +4,11 @@ local myos=dfhack.getOSType() args={...} mainmenu=dfu.SimpleMenu() function runsave() - print("doing file:"..df.global.world.cur_savegame.save_dir) + local path=string.format("data/save/%s/dfhack.lua",df.global.world.cur_savegame.save_dir) + print("doing file:"..path) + loadfile(path)() end mainmenu:add("Run save script",runsave) mainmenu:add("Adventurer tools",require("plugins.dfusion.adv_tools").menu) +mainmenu:add("Misc tools",require("plugins.dfusion.tools").menu) mainmenu:display() \ No newline at end of file