-- changes from advmode to fort safely and back (hopefully)
--[[Now to warn you about saving and loading in either game mode might lead
to some side issues, for saving in fort mode switching to adv mode needs the adv to be `bodyswap`
back in again. for Saving in Adv to switch to Fort mode you probably be safe-ish if the site.
isn't a nano fort or a site that isn't 3x3 small. otherwise the game will try to resize the map.
oh and switching to fort mode on any pre-gen site larger than 4x4 might implode one pc if
you don't have like 20 gigs of memory for the 16x16 embark size.
ok so this version of this script has be updated again so that caravans and visitors and migrants
could show up at any edge of the map... and maybe leave from any spot... of the z level you assign the site too.
should be warned while I mostly iron out the Caravan crash which ties into entities than anything that messes with plotinfo.
there still some unknowns left in the game
so uhh I probably should get to figuring out how to map the surface (properly) at some point...
should be said This is a modified copy of Warmist's Tofort script and this one is made for messing around the world.
there's a more Fort mode focus one called TopFort which dives into switching into player forts... and sometimes lord claimed campsites.
5/15/2024: rework the script to align to 50 new df structures and changed one designation clear function so it functions with out a cursor.
this wouldn't really work in 50 but maybe, there's potential chance of it working in the beta 51 build that has adv mode.
]]--
if df.global.gamemode==df.game_mode.ADVENTURE then
local adv=df.global.world.units.active[0]
local comp={}
local plotinfo=df.global.plotinfo
function advGlobalPos()
local wd=df.global.world.world_data
return wd.adv_region_x*16+wd.adv_emb_x,wd.adv_region_y*16+wd.adv_emb_y
end
--function inSite()
-- local tx,ty=advGlobalPos()
-- for k,v in pairs(df.global.world.world_data.sites) do
-- local tp2={v.global_min_x, v.global_min_y, v.global_max_x, v.global_max_y}
-- if tx>=tp2[1] and tx<=tp2[3] and
-- ty>=tp2[2] and ty<=tp2[4] then
-- return v
-- end
-- end
--end
--local site=inSite()
--if site==nil then
-- qerror("No site you are in found.")
--end
local nomad={}
local h_ent
--local test= tonumber(...)
if plotinfo.main.fortress_entity~=nil or plotinfo.main.fortress_site~=nil then
plotinfo.main.fortress_entity=nil
plotinfo.main.fortress_site=nil
end
nomad=df.global.world.entities.all[test]
--for k,v in pairs(df.global.world.history.figures[adv.hist_figure_id].entity_links) do
--if v~=histfig_entity_link_memberst and not v==nil then
--nomad=df.global.world.entities.all[v.entity_id]
--print(test)
--else if v==histfig_entity_link_memberst then
--nomad=df.global.world.history.figures[adv.hist_figure_id].entity_links[0]
--end
--end
--end
if plotinfo.main.fortress_entity==nil then
for k,v in pairs(df.global.world.entities.all) do
--if v.type==df.historical_entity_type.SiteGovernment and v.id==nomad.id then --maybe match race too?
if v.id==nomad.id then --maybe match race too?
if nomad.positions.own==nil then
break else
h_ent=v
break
end
end
if v.id~=nomad.id then
if v.type==df.historical_entity_type.SiteGovernment then
h_ent=v
end
end
end
if h_ent==nil then
qerror("Valid historical entity not found. sorry...")
end
plotinfo.main.fortress_entity=h_ent
else
h_ent=plotinfo.main.fortress_entity
end
function cleardesignate(adv)
local scorch=df.global.world.map.map_blocks
for k,v in pairs(scorch) do
if v.flags.designated==true then
v.flags.designated=false
end
for k2,v2 in pairs(v.designation) do
for k3,v3 in pairs(v2) do
if v3.dig>0 or v3.smooth>0 then
v3.dig=0
v3.smooth=0
end
end
end
end
dfhack.run_command('revflood')
end
function cleardesignate-old(adv)
local adv=df.global.world.units.active[0]
df.global.plotinfo.main.mode=10
df.global.selection_rect.start_x=0
df.global.selection_rect.start_y=0
df.global.selection_rect.start_z=610
df.global.selection_rect.end_x=-14300
df.global.selection_rect.end_y=9000
df.global.selection_rect.end_z=0
df.global.cursor.x=400
df.global.cursor.y=400
df.global.cursor.z=0
dfhack.gui.getCurViewscreen():feed_key(1)
df.global.cursor.x=adv.pos.x
df.global.cursor.y=adv.pos.y
df.global.cursor.z=adv.pos.z
dfhack.gui.getCurViewscreen():feed_key(1)
dfhack.run_command('revflood')
end
local carter={}
function addToEntity(entity,unit,addtoLead)
local nem=dfhack.units.getNemesis(unit)
local hfig=nem.figure
for k,v in pairs(hfig.entity_links) do
if v.entity_id==entity.id then break else
carter=true
end
end
if carter==true then
hfig.entity_links:insert("#",{new=df.histfig_entity_link_memberst,entity_id=entity.id,link_strength=100})
entity.nemesis_ids:insert("#",nem.id)
entity.nemesis:insert("#",nem)
entity.histfig_ids:insert("#",hfig.id)
entity.hist_figures:insert("#",hfig)
end
if addtoLead then
local lead_id
for k,v in pairs(entity.positions.own) do
if v.flags.IS_LEADER==true then
lead_id=v.id
break
end
end
if lead_id~=nil then
for k,v in pairs(entity.positions.assignments) do
if v.position_id==lead_id then
v.histfig=hfig.id
break
end
end
end
end
end
plotinfo.civ_id=adv.civ_id
plotinfo.race_id=adv.race
df.global.pause_state=true
plotinfo.unk_races:insert("#",adv.race)
plotinfo.site_id=site.id
if plotinfo.main.fortress_site==nil then plotinfo.main.fortress_site=site end
if site.entity_links==nil then site.entity_links:insert("#", {new=true, df.entity_site_link, target=site.id, entity_id=plotinfo.fortress_entity.id,entity_site_link_flags.residence, entity_site_link_flags.trade_partner }) end
plotinfo.group_id=h_ent.id
plotinfo.game_state=2
if #plotinfo.tasks.discovered_plants==0 then
df.global.plotinfo.tasks.discovered_creature_foods:insert("#",0)
df.global.plotinfo.tasks.discovered_creatures:insert("#",0)
df.global.plotinfo.tasks.discovered_plants:insert("#",0)
df.global.plotinfo.tasks.discovered_plant_foods:insert("#",0)
end
if #plotinfo.alerts.list==0 then
plotinfo.alerts.list:insert("#",{new=true,name="Dummy alert"})
plotinfo.alerts.next_id=1
end
local nem2=dfhack.units.getNemesis(adv)
local hfig2=nem2.figure
local nomad2=hfig2.entity_links[0]
local nomad3=hfig2.entity_links
local Test={}
for co2,mp2 in pairs(nomad3) do
--print(mp2.entity_id,h_ent.id)
if mp2.entity_id~=h_ent.id then Test=true else
Test=false
end
end
if Test==true then
addToEntity(h_ent,adv,true)
end
for co,mp in pairs(df.global.world.units.active) do
if mp.population_id==h_ent.id then
mp.flags2.resident=false
end
if mp.civ_id==h_ent.id or adv.civ_id==mp.civ_id then
mp.flags2.resident=false
end
if mp.relationship_ids.GroupLeader==adv.id then
local comp=mp
if test==true then
addToEntity(h_ent,comp,false)
end
end
end
function filleco(tbl,low,high)
for v =low, high do
tbl.general_items:insert("#",2)
end
tbl.weapons:insert("#",2)
tbl.armor:insert("#",2)
tbl.handwear:insert("#",2)
tbl.footwear:insert("#",2)
tbl.legwear:insert("#",2)
tbl.headwear:insert("#",2)
tbl.prepared_food:insert("#",2)
tbl.wood:insert("#",2)
tbl.thread_cloth:insert("#",2)
tbl.paper:insert("#",2)
tbl.parchment:insert("#",2)
tbl.bone:insert("#",2)
tbl.tooth:insert("#",2)
tbl.horn:insert("#",2)
tbl.pearl:insert("#",2)
tbl.shell:insert("#",2)
tbl.leather:insert("#",2)
tbl.silk:insert("#",2)
tbl.yarn:insert("#",2)
tbl.inorganic:insert("#",2)
tbl.meat:insert("#",2)
tbl.fish:insert("#",2)
tbl.plants:insert("#",2)
tbl.drinks:insert("#",2)
tbl.extract_animal:insert("#",2)
tbl.mill_animal:insert("#",2)
tbl.cheese_animal:insert("#",2)
tbl.extract_plant:insert("#",2)
tbl.mill_plant:insert("#",2)
tbl.cheese_plant:insert("#",2)
tbl.pets:insert("#",2)
end
function filleco2(tbl,low,high)
for v =low, high do
--tbl[v].unk1=site.pos.x
--tbl.unk1:insert("#",site.pos.x)
--tbl.unk2:insert("#",site.pos.y)
tbl.general_items:insert("#",nil)
--tbl[v].unk2=site.pos.y
end
tbl.weapons:insert("#",nil)
tbl.armor:insert("#",nil)
tbl.handwear:insert("#",nil)
tbl.footwear:insert("#",nil)
tbl.legwear:insert("#",nil)
tbl.headwear:insert("#",nil)
tbl.prepared_food:insert("#",nil)
tbl.wood:insert("#",nil)
tbl.thread_cloth:insert("#",nil)
tbl.paper:insert("#",nil)
tbl.parchment:insert("#",nil)
tbl.bone:insert("#",nil)
tbl.tooth:insert("#",nil)
tbl.horn:insert("#",nil)
tbl.pearl:insert("#",nil)
tbl.shell:insert("#",nil)
tbl.leather:insert("#",nil)
tbl.silk:insert("#",nil)
tbl.yarn:insert("#",nil)
tbl.inorganic:insert("#",nil)
tbl.meat:insert("#",nil)
tbl.fish:insert("#",nil)
tbl.plants:insert("#",nil)
tbl.drinks:insert("#",nil)
tbl.extract_animal:insert("#",nil)
tbl.mill_animal:insert("#",nil)
tbl.cheese_animal:insert("#",nil)
tbl.extract_plant:insert("#",nil)
tbl.mill_plant:insert("#",nil)
tbl.cheese_plant:insert("#",nil)
tbl.pets:insert("#",nil)
end
function fill(tbl,low,high)
for v =low, high do
tbl:insert("#",0)
tbl:insert("#",v)
tbl:insert("#",143)
tbl:insert("#",v)
end
end
function fill2(tbl,low,high)
for v =low, high do
tbl:insert("#",v)
tbl:insert("#",143)
tbl:insert("#",v)
tbl:insert("#",0)
end
end
function fillz(tbl,low,high)
for v =low, high do
tbl:insert("#",adv.pos.z)
tbl:insert("#",adv.pos.z)
tbl:insert("#",adv.pos.z)
tbl:insert("#",adv.pos.z)
end
end
function fillunk(tbl,low,high)
for v =low, high do
tbl[v].unk1=site.pos.x
tbl[v].unk2=site.pos.y
end
end
function fillanimal(tbl,low,high)
for v =low, high do
tbl:insert("#",1)
end
end
function fillstone(tbl,low,high)
for v =low, high do
tbl:insert("#",0)
end
end
function fillTrain(tbl,tbl2,low,high)
for v =low, high do
tbl2:insert("#",0)
tbl:insert("#",5)
end
end
function mapcheck2()
fill(df.global.plotinfo.unk_mapedge_x,0,143)
fill2(df.global.plotinfo.unk_mapedge_y,0,143)
fillz(df.global.plotinfo.unk_mapedge_z,0,143)
fill(df.global.plotinfo.map_edge.surface_x,0,143)
fill2(df.global.plotinfo.map_edge.surface_y,0,143)
fillz(df.global.plotinfo.map_edge.surface_z,0,143)
for _,Lay in pairs(df.global.plotinfo.map_edge.layer_x) do
fill(Lay,0,143)
end
for _,Lay in pairs(df.global.plotinfo.map_edge.layer_y) do
fill2(Lay,0,143)
end
for _,Lay in pairs(df.global.plotinfo.map_edge.layer_z) do
fillz(Lay,0,143)
end
end
function sigh()
mapcheck()
mapcheck2()
for k,v in pairs(df.global.plotinfo.unk_mapedge_x) do
end
for k,v in pairs(df.global.plotinfo.map_edge.surface_z) do
df.global.plotinfo.map_edge.surface_z[k]=adv.pos.z
--v=152
end
end
function mapcheck()
fillunk(df.global.plotinfo.unk2a8c[0],0,143)
fillunk(df.global.plotinfo.unk2a8c[1],0,143)
fillunk(df.global.plotinfo.unk2a8c[2],0,143)
fillunk(df.global.plotinfo.unk2a8c[3],0,143)
end
Tab={}
Tab2={}
for k,Lay2 in pairs(df.global.plotinfo.map_edge.layer_z) do
for k2,Lay3 in pairs(df.global.plotinfo.unk2a8c[0]) do
if k then break else
Tab:insert("#",k)
end
Tab2:insert("#",k2)
return Tab,Tab2
end
end
if #df.global.plotinfo.map_edge.layer_z[0] == 0 then
print("map edge empty proceed to fill")
sigh()
else
print("welp map edge currently full")
end
if plotinfo.main.fortress_entity.squads==0 then
for Sqa,Ds in pairs (df.global.world.squads.all) do
if Ds.entity_id==plotinfo.main.fortress_entity.id then
plotinfo.main.fortress_entity.squads:insert("#",{new=true,Ds})
end
end
end
if #plotinfo.tasks.discovered_plants==0 then
--for k,Lay2 in ipairs(df.global.world.raws.creatures.all) do
--return k
--end
local Anim=#df.global.world.raws.creatures.all
local Plan=#df.global.world.raws.plants.all
fillanimal(df.global.plotinfo.tasks.discovered_creatures,0,Anim)
fillanimal(df.global.plotinfo.tasks.discovered_creature_foods,0,Anim)
fillanimal(df.global.plotinfo.tasks.discovered_plants,0,Plan)
fillanimal(df.global.plotinfo.tasks.discovered_plant_foods,0,Plan)
--for k,Lay2 in ipairs(df.global.world.raws.plants.all) do
--return k
--end
--end
end
function fillTrain(tbl,tbl2,low,high)
for v =low, high do
tbl2:insert("#",0)
tbl:insert("#",5)
end
end
if #plotinfo.kitchen.item_types==0 then
plotinfo.kitchen.item_types:insert("#",0)
plotinfo.kitchen.item_subtypes:insert("#",0)
plotinfo.kitchen.mat_types:insert("#",0)
plotinfo.kitchen.mat_indices:insert("#",0)
plotinfo.kitchen.exc_types:insert("#",0)
end
if #plotinfo.infiltrator_histfigs==0 then
plotinfo.infiltrator_histfigs:insert("#",0)
plotinfo.infiltrator_histfigs:insert("#",0)
plotinfo.infiltrator_years:insert("#",0)
plotinfo.infiltrator_years:insert("#",0)
plotinfo.infiltrator_years_ticks:insert("#",0)
plotinfo.infiltrator_years_ticks:insert("#",0)
end
if #plotinfo.economic_stone==0 then
for k,Lay2 in ipairs(df.global.world.raws.inorganics) do
fillstone(df.global.plotinfo.economic_stone,0,k)
--return k
end
end
if #plotinfo.economy_prices.price_adjustment.general_items==0 then
filleco(df.global.plotinfo.economy_prices.price_adjustment,0,114)
filleco2(df.global.plotinfo.economy_prices.price_setter,0,114)
end
--fix training info
if h_ent.training_knowledge == nil then
h_ent.training_knowledge={new=true}
end
if #plotinfo.main.fortress_entity.training_knowledge.level==0 then
local Anim=#df.global.world.raws.creatures.all
fillTrain(plotinfo.main.fortress_entity.training_knowledge.level,plotinfo.main.fortress_entity.training_knowledge.unk_10,0,Anim-1)
end
df.global.gamemode=df.game_mode.DWARF
df.global.gametype=df.game_type.DWARF_MAIN
if df.global.gview.view.child.child==nil then df.global.gview.view.child=df.viewscreen_dwarfmodest:new()
df.global.gview.view.child.parent=df.global.gview.view
end
cleardesignate()
print("Mode change complete.")
else
local adv=dfhack.gui.getSelectedUnit(true)
if adv then
--swap units...
end
df.global.gamemode=df.game_mode.ADVENTURE
df.global.gametype=df.game_type.ADVENTURE_MAIN
df.global.gview.view.child=df.viewscreen_dwarfmodest:new()
df.global.gview.view.child.parent=df.global.gview.view
print("Mode change complete.")
end
ok made some more modifications to warmist's tofort script in hopes of dfhack using beta testers of adv mode could ... have fun with switching into one of their dwarves and go on an adventure... or something, maybe even just swap into fort mode from adv mode and finally butcher the game you caught. this is basically untested in 51 and possibly Very unstable as I have no idea if this works in 51, kinda hope it does.
oh and probably make a backup of your saves before messing with this.
edit: ok so recently learn of the unit active 0 slot change and had to touch up this script still kinda in the blind on 51 structures.